/* =============================================================================
   Trem-Tipo Optimizer — Design System
   Dark theme, modern, glassmorphism
   ============================================================================= */

@import url('https://fonts.googleapis.com/css2?family=Inter:wght@300;400;500;600;700;800&family=JetBrains+Mono:wght@400;500&display=swap');

/* ---------------------------------------------------------------------------
   CSS Custom Properties
   --------------------------------------------------------------------------- */

:root {
    /* Brand Colors (Novas Variáveis Adicionadas) */
    --rail-blue: #1e40af; /* Azul Ferroviário Clássico */
    --rail-blue-light: #2563eb; /* Azul mais vibrante para ações */
    --rail-dark: #0f172a; /* Slate 900 */

    /* Background layers - Migração Escuro -> Claro (Slate) */
    --bg-deep: #f1f5f9; /* Fundo base da página (Slate 100) */
    --bg-base: #f8fafc; /* Fundo mais claro (Slate 50) */
    --bg-surface: #ffffff; /* Fundo de cartões (White) */
    --bg-elevated: #ffffff; 
    --bg-hover: #f1f5f9; /* Slate 100 para hovers */

    /* Glassmorphism (Ajustado para Light Mode) */
    --glass-bg: rgba(255, 255, 255, 0.9);
    --glass-border: rgba(226, 232, 240, 0.8); /* Slate 200 opaco */
    --glass-shadow: 0 1px 2px 0 rgba(0, 0, 0, 0.05); /* Sombra mais sutil */

    /* Accent & Action (Baseado no Tailwind Azul) */
    --accent: #2563eb;
    --accent-glow: rgba(37, 99, 235, 0.25);
    --accent-hover: #1d4ed8;
    --accent-muted: rgba(37, 99, 235, 0.15);

    /* Warning / Danger / Success */
    --warning: #f59e0b; /* Amber 500 */
    --danger: #ef4444; /* Red 500 */
    --success: #10b981; /* Emerald 500 */

    /* Text - Escurecidos para contrastar no fundo claro */
    --text-primary: #0f172a; /* Slate 900 (Títulos) */
    --text-secondary: #475569; /* Slate 600 (Textos Comuns) */
    --text-muted: #94a3b8; /* Slate 400 (Labels/Hints) */

    /* Borders (Nova Variável Sugerida) */
    --border: #e2e8f0; /* Slate 200 */
    --border-light: #f1f5f9; /* Slate 100 */

    /* Sizing (Alinhado aos arredondamentos do Tailwind) */
    --radius-sm: 6px;
    --radius-md: 8px; 
    --radius-lg: 12px;
    --radius-xl: 16px;

    /* Transitions */
    --transition-fast: 150ms cubic-bezier(0.4, 0, 0.2, 1);
    --transition-base: 250ms cubic-bezier(0.4, 0, 0.2, 1);
    --transition-slow: 400ms cubic-bezier(0.4, 0, 0.2, 1);
}

/* ---------------------------------------------------------------------------
   Reset & Base
   --------------------------------------------------------------------------- */

*,
*::before,
*::after {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

html {
    font-size: 15px;
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
}

body {
    font-family: 'Inter', -apple-system, BlinkMacSystemFont, sans-serif;
    background-color: var(--bg-deep); /* Slate 100 */
    color: var(--text-primary);
    line-height: 1.6;
    min-height: 100vh;
    overflow-x: hidden;
    -webkit-font-smoothing: antialiased;
}

/* ---------------------------------------------------------------------------
   Layout
   --------------------------------------------------------------------------- */

.app-container {
    min-height: 100vh;
    position: relative;
    z-index: 1;
    display: flex;
    flex-direction: column;
}

/* ---------------------------------------------------------------------------
   Topbar Header (Nova Estrutura de Navegação Superior)
   --------------------------------------------------------------------------- */

.topbar {
    background: #ffffff;
    border-bottom: 1px solid var(--border);
    position: sticky;
    top: 0;
    z-index: 50;
    height: 64px;
}

.topbar-container {
    width: 100%;
    padding: 0 24px;
    height: 100%;
    display: flex;
    align-items: center;
    justify-content: space-between;
}

.topbar-brand {
    display: flex;
    align-items: center;
    gap: 24px;
}

.brand-info {
    display: flex;
    align-items: center;
    gap: 8px;
}

.brand-icon {
    background: var(--rail-blue-light);
    padding: 6px;
    border-radius: var(--radius-md);
    box-shadow: 0 1px 2px rgba(0,0,0,0.05);
}

.brand-icon svg {
    width: 24px;
    height: 24px;
    color: white;
}

.brand-text h1 {
    font-size: 1.1rem;
    font-weight: 700;
    line-height: 1;
    color: var(--text-primary);
    letter-spacing: -0.02em;
}

.brand-text p {
    font-size: 0.65rem;
    color: var(--text-muted);
    text-transform: uppercase;
    font-weight: 600;
    letter-spacing: 0.1em;
    margin-top: 4px;
}

/* Nav */
.topbar-nav {
    display: flex;
    align-items: center;
    gap: 4px;
    height: 64px;
}

.topbar-nav-item {
    padding: 0 16px;
    height: 100%;
    display: flex;
    align-items: center;
    font-size: 0.88rem;
    font-weight: 500;
    color: var(--text-secondary);
    cursor: pointer;
    transition: all var(--transition-fast);
    border-bottom: 3px solid transparent;
}

.topbar-nav-item:hover {
    color: var(--rail-blue-light);
}

.topbar-nav-item.active {
    color: var(--rail-blue);
    font-weight: 600;
}

/* Actions */
.topbar-actions {
    display: flex;
    align-items: center;
    gap: 16px;
}

/* Geometry Badge inside Actions */
.geometry-badge {
    display: flex;
    align-items: center;
    padding: 8px 24px;
    background: #ffffff;
    border-radius: 9999px;
    border: 1px solid var(--border);
    transition: all var(--transition-fast);
    cursor: pointer;
    box-shadow: 0 1px 2px rgba(0,0,0,0.05);
}

.geometry-badge.has-geo {
    background: #eefdf5;
    border-color: #d1fae5;
}

.geometry-badge .geo-info {
    display: flex;
    align-items: center;
    gap: 6px;
    line-height: 1;
}

.geometry-badge.has-geo .geo-name {
    color: #065f46;
}

.geometry-badge .geo-name {
    color: var(--text-primary);
    font-size: 0.85rem;
    font-weight: 700;
    text-transform: uppercase;
    max-width: 350px;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.geometry-badge:hover {
    background: var(--bg-hover);
    border-color: var(--border);
}

/* Main Content */
.main-content {
    max-width: 1280px;
    margin: 0 auto;
    padding: 32px 16px;
    width: 100%;
    min-height: calc(100vh - 64px);
}

/* ---------------------------------------------------------------------------
   Layout com Sidebar Interna
   --------------------------------------------------------------------------- */

.page-with-sidebar {
    display: flex;
    gap: 32px;
    align-items: flex-start;
}

.inner-sidebar {
    width: 280px;
    flex-shrink: 0;
    position: sticky;
    top: 88px;
    display: flex;
    flex-direction: column;
    gap: 20px;
}

.inner-content {
    flex: 1;
    min-width: 0;
}

.sidebar-widget {
    background: #ffffff;
    border: 1px solid var(--border);
    border-radius: var(--radius-lg);
    padding: 20px;
    box-shadow: 0 1px 3px 0 rgba(0, 0, 0, 0.05);
}

.sidebar-widget-title {
    font-size: 0.72rem;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.05em;
    color: var(--text-muted);
    margin-bottom: 16px;
    display: flex;
    align-items: center;
    gap: 10px;
}

.sidebar-widget-title svg {
    color: var(--rail-blue-light);
}

.sidebar-action-btn {
    width: 100%;
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 12px 16px;
    background: #ffffff;
    border: 1px solid var(--border);
    border-radius: var(--radius-md);
    color: var(--text-primary);
    font-size: 0.88rem;
    font-weight: 500;
    cursor: pointer;
    transition: all var(--transition-fast);
}

.sidebar-action-btn:hover {
    background: var(--bg-hover);
    border-color: var(--rail-blue-light);
    color: var(--rail-blue-light);
    transform: translateX(4px);
}

.sidebar-action-btn svg {
    width: 18px;
    height: 18px;
}

.page-header {
    margin-bottom: 28px;
}

.page-header h2 {
    font-size: 1.6rem;
    font-weight: 700;
    letter-spacing: -0.02em;
    margin-bottom: 4px;
}

.page-header .subtitle {
    color: var(--text-secondary);
    font-size: 0.88rem;
}

/* ---------------------------------------------------------------------------
   Cards & Panels
   --------------------------------------------------------------------------- */

.card {
    background: var(--bg-surface);
    border: 1px solid var(--border);
    border-radius: var(--radius-lg);
    padding: 24px;
    box-shadow: var(--glass-shadow);
    transition: border-color var(--transition-base), box-shadow var(--transition-base);
}

.card:hover {
    border-color: var(--rail-blue-light);
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.05);
}

.card-title {
    font-size: 0.78rem;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.06em;
    color: var(--text-muted);
    margin-bottom: 16px;
}

/* ---------------------------------------------------------------------------
   Form Elements
   --------------------------------------------------------------------------- */

/* Sidebar Geometry Items */
.geo-item-sidebar {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 10px 12px;
    border-radius: var(--radius-md);
    transition: all var(--transition-fast);
    cursor: pointer;
    border: 1px solid transparent;
}

.geo-item-sidebar:hover {
    background: var(--bg-hover);
}

.geo-item-sidebar.active {
    background: var(--accent-muted);
    border-color: var(--accent-glow);
}

.geo-item-sidebar .geo-name-label {
    font-size: 0.85rem;
    font-weight: 500;
    color: var(--text-primary);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    flex: 1;
}

.check-btn {
    width: 24px;
    height: 24px;
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: 50%;
    border: 1.5px solid var(--border);
    color: var(--text-muted);
    transition: all var(--transition-base);
    flex-shrink: 0;
    margin-left: 8px;
}

.check-btn svg {
    width: 14px;
    height: 14px;
    stroke-width: 3;
}

.geo-item-sidebar.active .check-btn {
    background: var(--success);
    border-color: var(--success);
    color: white;
    transform: scale(1.1);
    box-shadow: 0 0 8px rgba(16, 185, 129, 0.4);
}

.sidebar-widget-content {
    display: flex;
    flex-direction: column;
    gap: 4px;
    max-height: 400px;
    overflow-y: auto;
    margin: 0 -4px;
    padding: 0 4px;
}

.form-label {
    display: block;
    font-size: 0.8rem;
    font-weight: 500;
    color: var(--text-secondary);
    margin-bottom: 6px;
}

.form-input,
.form-select {
    width: 100%;
    padding: 10px 14px;
    background: var(--bg-base);
    border: 1px solid var(--border);
    border-radius: var(--radius-md);
    color: var(--text-primary);
    font-family: inherit;
    font-size: 0.88rem;
    transition: all var(--transition-fast);
    outline: none;
}

.form-input:focus,
.form-select:focus {
    border-color: var(--accent);
    box-shadow: 0 0 0 3px var(--accent-muted);
}

.form-select {
    cursor: pointer;
    appearance: none;
    background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='12' viewBox='0 0 12 12'%3E%3Cpath d='M3 4.5L6 7.5L9 4.5' stroke='%236b7280' stroke-width='1.5' fill='none'/%3E%3C/svg%3E");
    background-repeat: no-repeat;
    background-position: right 12px center;
    padding-right: 36px;
}

.form-row {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(140px, 1fr));
    gap: 14px;
}

.form-hint {
    font-size: 0.72rem;
    color: var(--text-muted);
    margin-top: 4px;
}

/* Checkbox / multi-select for wagon types */
.checkbox-group {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
}

.checkbox-chip {
    display: flex;
    align-items: center;
    gap: 6px;
    padding: 6px 14px;
    background: var(--bg-base);
    border: 1px solid var(--border);
    border-radius: 100px;
    cursor: pointer;
    font-size: 0.82rem;
    color: var(--text-secondary);
    transition: all var(--transition-fast);
    user-select: none;
}

.checkbox-chip:hover {
    border-color: var(--accent);
    color: var(--text-primary);
}

.checkbox-chip.checked {
    background: var(--accent-muted);
    border-color: var(--accent);
    color: var(--accent);
}

.checkbox-chip input {
    display: none;
}

/* ---------------------------------------------------------------------------
   Buttons
   --------------------------------------------------------------------------- */

.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    padding: 11px 24px;
    border: none;
    border-radius: var(--radius-md);
    font-family: inherit;
    font-size: 0.88rem;
    font-weight: 600;
    cursor: pointer;
    transition: all var(--transition-fast);
    outline: none;
    position: relative;
    overflow: hidden;
}

.btn-primary {
    background: var(--rail-dark);
    color: #ffffff;
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.1);
    text-transform: uppercase;
    letter-spacing: 0.05em;
    font-size: 0.8rem;
}

.btn-primary:hover {
    transform: translateY(-1px);
    background: #1e293b;
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.15);
}

.btn-primary:active {
    transform: translateY(0);
}

.btn-primary:disabled {
    opacity: 0.5;
    cursor: not-allowed;
    transform: none;
    box-shadow: none;
}

.btn-secondary {
    background: var(--bg-surface);
    color: var(--text-primary);
    border: 1px solid var(--border);
}

.btn-secondary:hover {
    background: var(--bg-hover);
    border-color: var(--border);
    color: var(--rail-blue);
}

/* Sub-Tabs */
.sub-tabs {
    display: flex;
    gap: 16px;
    border-bottom: 2px solid var(--border);
    margin-bottom: 24px;
}

.sub-tab-btn {
    padding: 12px 16px;
    font-size: 0.88rem;
    font-weight: 500;
    color: var(--text-secondary);
    background: none;
    border: none;
    cursor: pointer;
    transition: all var(--transition-fast);
    margin-bottom: -2px;
    border-bottom: 2px solid transparent;
}

.sub-tab-btn:hover {
    color: var(--rail-blue-light);
}

.sub-tab-btn.active {
    color: var(--rail-blue);
    font-weight: 600;
    border-bottom-color: var(--rail-blue);
}

.btn-sm {
    padding: 7px 16px;
    font-size: 0.8rem;
}

/* Loading spinner inside button */
.btn .spinner {
    width: 16px;
    height: 16px;
    border: 2px solid transparent;
    border-top-color: currentColor;
    border-radius: 50%;
    animation: spin 0.6s linear infinite;
    display: none;
}

.btn.loading .spinner {
    display: inline-block;
}

.btn.loading .btn-text {
    opacity: 0.5;
}

@keyframes spin {
    to {
        transform: rotate(360deg);
    }
}

/* ---------------------------------------------------------------------------
   Result Big Number
   --------------------------------------------------------------------------- */

.result-hero {
    text-align: center;
    padding: 32px 24px;
    margin-bottom: 24px;
}

.result-hero .big-number {
    font-size: 4.5rem;
    font-weight: 800;
    color: var(--accent);
    line-height: 1;
    letter-spacing: -0.04em;
    text-shadow: 0 0 40px var(--accent-glow);
    margin-bottom: 4px;
}

.result-hero .big-label {
    font-size: 0.88rem;
    color: var(--text-secondary);
    font-weight: 500;
}

/* ---------------------------------------------------------------------------
   KPI Grid
   --------------------------------------------------------------------------- */

.kpi-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(150px, 1fr));
    gap: 14px;
    margin-bottom: 24px;
}

.kpi-card {
    background: var(--bg-surface);
    border: 1px solid var(--glass-border);
    border-radius: var(--radius-md);
    padding: 16px;
    text-align: center;
}

.kpi-card .kpi-value {
    font-size: 1.35rem;
    font-weight: 700;
    color: var(--text-primary);
    font-family: 'JetBrains Mono', monospace;
}

.kpi-card .kpi-label {
    font-size: 0.72rem;
    color: var(--text-muted);
    margin-top: 4px;
    text-transform: uppercase;
    letter-spacing: 0.04em;
}

/* ---------------------------------------------------------------------------
   Tables
   --------------------------------------------------------------------------- */

.table-wrapper {
    overflow-x: auto;
    border-radius: var(--radius-md);
    border: 1px solid var(--glass-border);
}

.data-table {
    width: 100%;
    border-collapse: collapse;
    font-size: 0.82rem;
}

.data-table th {
    padding: 10px 14px;
    text-align: left;
    font-weight: 600;
    font-size: 0.72rem;
    text-transform: uppercase;
    letter-spacing: 0.05em;
    color: var(--text-muted);
    background: var(--bg-surface);
    border-bottom: 1px solid var(--glass-border);
    white-space: nowrap;
}

.data-table td {
    padding: 9px 14px;
    border-bottom: 1px solid hsla(220, 20%, 18%, 0.5);
    color: var(--text-primary);
    font-family: 'JetBrains Mono', monospace;
    font-size: 0.8rem;
    white-space: nowrap;
}

.data-table tr:last-child td {
    border-bottom: none;
}

.data-table tr:hover td {
    background: var(--bg-hover);
}

.data-table .critical {
    color: var(--danger);
    font-weight: 600;
}

.data-table .best {
    color: var(--success);
    font-weight: 600;
}

/* ---------------------------------------------------------------------------
   Tab content visibility
   --------------------------------------------------------------------------- */

.tab-panel {
    display: none;
    animation: fadeIn 0.3s ease;
}

.tab-panel.active {
    display: block;
}

@keyframes fadeIn {
    from {
        opacity: 0;
        transform: translateY(8px);
    }

    to {
        opacity: 1;
        transform: translateY(0);
    }
}

/* ---------------------------------------------------------------------------
   Profile chart
   --------------------------------------------------------------------------- */

.chart-container {
    position: relative;
    width: 100%;
    background: var(--bg-surface);
    border: 1px solid var(--glass-border);
    border-radius: var(--radius-lg);
    overflow: hidden;
}

.chart-container canvas {
    display: block;
    width: 100%;
}

.chart-legend {
    display: flex;
    gap: 20px;
    padding: 12px 20px;
    border-top: 1px solid var(--glass-border);
    font-size: 0.78rem;
    color: var(--text-secondary);
}

.chart-legend .legend-item {
    display: flex;
    align-items: center;
    gap: 6px;
}

.chart-legend .legend-dot {
    width: 10px;
    height: 10px;
    border-radius: 3px;
    flex-shrink: 0;
}

/* ---------------------------------------------------------------------------
   Optimization grouped table
   --------------------------------------------------------------------------- */

.opt-group {
    margin-bottom: 24px;
}

.opt-group-header {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 12px 16px;
    background: var(--bg-surface);
    border: 1px solid var(--glass-border);
    border-radius: var(--radius-md) var(--radius-md) 0 0;
}

.opt-group-header .wagon-badge {
    padding: 3px 12px;
    background: var(--accent-muted);
    border: 1px solid var(--accent);
    border-radius: 100px;
    font-size: 0.78rem;
    font-weight: 600;
    color: var(--accent);
    font-family: 'JetBrains Mono', monospace;
}

.opt-group-header .wagon-info {
    font-size: 0.8rem;
    color: var(--text-secondary);
}

.opt-group .table-wrapper {
    border-top: none;
    border-radius: 0 0 var(--radius-md) var(--radius-md);
}

/* Best result banner */
.best-banner {
    display: flex;
    align-items: center;
    gap: 16px;
    padding: 20px 24px;
    background: linear-gradient(135deg, hsla(175, 60%, 40%, 0.15), hsla(200, 60%, 40%, 0.08));
    border: 1px solid hsla(175, 60%, 48%, 0.3);
    border-radius: var(--radius-lg);
    margin-bottom: 24px;
}

.best-banner .trophy {
    font-size: 2rem;
}

.best-banner .best-info h3 {
    font-size: 1rem;
    font-weight: 700;
    color: var(--accent);
    margin-bottom: 2px;
}

.best-banner .best-info p {
    font-size: 0.84rem;
    color: var(--text-secondary);
}

/* ---------------------------------------------------------------------------
   Upload area
   --------------------------------------------------------------------------- */

.upload-area {
    background: var(--glass-bg);
    backdrop-filter: blur(16px);
    -webkit-backdrop-filter: blur(16px);
    border: 2px dashed var(--border);
    border-radius: var(--radius-lg);
    padding: 48px 32px;
    text-align: center;
    cursor: pointer;
    transition: all var(--transition-base);
    margin-bottom: 24px;
    box-shadow: var(--glass-shadow);
}

.upload-area:hover {
    border-color: var(--accent);
    background: var(--accent-muted);
}

.upload-area .upload-icon {
    font-size: 2.5rem;
    margin-bottom: 8px;
}

.upload-area .upload-text {
    color: var(--text-secondary);
    font-size: 0.88rem;
}

.upload-area .upload-hint {
    color: var(--text-muted);
    font-size: 0.75rem;
    margin-top: 4px;
}

/* ---------------------------------------------------------------------------
   Tooltip
   --------------------------------------------------------------------------- */

.chart-tooltip {
    position: absolute;
    background: var(--bg-elevated);
    border: 1px solid var(--glass-border);
    border-radius: var(--radius-sm);
    padding: 8px 12px;
    font-size: 0.75rem;
    color: var(--text-primary);
    pointer-events: none;
    opacity: 0;
    transition: opacity var(--transition-fast);
    z-index: 100;
    white-space: nowrap;
    box-shadow: var(--glass-shadow);
}

.chart-tooltip.visible {
    opacity: 1;
}

/* ---------------------------------------------------------------------------
   Loading overlay
   --------------------------------------------------------------------------- */

.loading-overlay {
    display: none;
    position: absolute;
    inset: 0;
    background: hsla(220, 25%, 6%, 0.7);
    backdrop-filter: blur(4px);
    border-radius: inherit;
    z-index: 5;
    align-items: center;
    justify-content: center;
}

.loading-overlay.active {
    display: flex;
}

.loading-overlay .loader {
    width: 36px;
    height: 36px;
    border: 3px solid var(--glass-border);
    border-top-color: var(--accent);
    border-radius: 50%;
    animation: spin 0.7s linear infinite;
}

/* ---------------------------------------------------------------------------
   Responsive
   --------------------------------------------------------------------------- */

@media (max-width: 900px) {
    .sidebar {
        width: 64px;
        min-width: 64px;
    }

    .sidebar-header h1,
    .sidebar-header .version,
    .nav-item span,
    .sidebar-footer,
    .nav-label {
        display: none;
    }

    .sidebar-header {
        padding: 16px;
        display: flex;
        justify-content: center;
    }

    .nav-item {
        justify-content: center;
        padding: 12px;
    }

    .nav-item .nav-icon {
        font-size: 1.3rem;
    }

    .main-content {
        margin-left: 64px;
        padding: 24px 20px;
    }
}

/* ---------------------------------------------------------------------------
   Scrollbar
   --------------------------------------------------------------------------- */

::-webkit-scrollbar {
    width: 6px;
    height: 6px;
}

::-webkit-scrollbar-track {
    background: transparent;
}

::-webkit-scrollbar-thumb {
    background: hsla(220, 15%, 35%, 0.5);
    border-radius: 3px;
}

::-webkit-scrollbar-thumb:hover {
    background: hsla(220, 15%, 45%, 0.6);
}

/* ---------------------------------------------------------------------------
   Layout helpers
   --------------------------------------------------------------------------- */

.grid-2 {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 20px;
}

.grid-3 {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 20px;
}

.grid-2-1 {
    display: grid;
    grid-template-columns: 2fr 1fr;
    gap: 20px;
}

.mb-16 {
    margin-bottom: 16px;
}

.mb-24 {
    margin-bottom: 24px;
}

.mt-16 {
    margin-top: 16px;
}

.mt-24 {
    margin-top: 24px;
}

@media (max-width: 1100px) {

    .grid-2,
    .grid-2-1 {
        grid-template-columns: 1fr;
    }
}

/* ---------------------------------------------------------------------------
   Sub-menu (Árvore)
   --------------------------------------------------------------------------- */

.nav-group {
    margin-bottom: 2px;
}

.nav-sub-menu {
    display: none;
    flex-direction: column;
    padding-left: 20px;
    margin-top: 4px;
}

.nav-group.active .nav-sub-menu {
    display: flex;
}

.nav-sub-item {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 8px 14px;
    border-radius: var(--radius-md);
    cursor: pointer;
    color: var(--text-secondary);
    font-size: 0.85rem;
    font-weight: 400;
    transition: all var(--transition-fast);
    user-select: none;
    position: relative;
}



.nav-sub-item:hover {
    background: var(--bg-hover);
    color: var(--text-primary);
}

.nav-sub-item.active {
    background: var(--accent-muted);
    color: var(--accent);
}

.nav-sub-item .nav-icon {
    font-size: 0.75rem;
    color: var(--glass-border);
    font-family: 'JetBrains Mono', monospace;
    width: auto;
    margin-right: -4px;
}

.nav-sub-item.active .nav-icon,
.nav-sub-item:hover .nav-icon {
    color: inherit;
}

/* ---------------------------------------------------------------------------
   Memorial de Cálculo - Controles de Card
   --------------------------------------------------------------------------- */

.card.locked {
    border-color: var(--success);
    background: hsla(145, 65%, 50%, 0.05);
    /* Fundo verdinho leve */
    box-shadow: 0 4px 16px hsla(145, 65%, 50%, 0.1);
}

.card.locked .form-input,
.card.locked .form-select {
    pointer-events: none;
    opacity: 0.7;
    border-color: transparent;
    background: hsla(220, 20%, 20%, 0.5);
}

.card-header-flex {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 16px;
}

.card-header-flex .card-title {
    margin-bottom: 0;
}

.btn-icon {
    width: 32px;
    height: 32px;
    border-radius: 50%;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    background: var(--bg-surface);
    border: 1px solid var(--glass-border);
    color: var(--text-secondary);
    cursor: pointer;
    transition: all var(--transition-fast);
}

.btn-icon:hover {
    color: var(--text-primary);
    border-color: var(--accent);
}

.btn-icon.checked {
    background: var(--success);
    color: hsl(220, 25%, 8%);
    border-color: var(--success);
    box-shadow: 0 0 10px hsla(145, 65%, 50%, 0.4);
}

.info-display {
    margin-top: 16px;
    padding-top: 16px;
    border-top: 1px dashed var(--glass-border);
    font-size: 0.8rem;
    color: var(--text-secondary);
}

.info-display p {
    margin-bottom: 4px;
    display: flex;
    justify-content: space-between;
}

.info-display p strong {
    color: var(--text-primary);
    font-family: 'JetBrains Mono', monospace;
    font-weight: 500;
}

.stepper-group {
    display: flex;
    align-items: center;
    gap: 8px;
}

.stepper-group input {
    text-align: center;
    width: 80px;
    -moz-appearance: textfield;
    /* Firefox */
    appearance: textfield;
}

/* Remover spinner nativo em browsers webkit (Chrome, Edge, Safari) */
.stepper-group input::-webkit-outer-spin-button,
.stepper-group input::-webkit-inner-spin-button {
    -webkit-appearance: none;
    appearance: none;
    margin: 0;
}

/* Deixar os inputs e botoes do card locked desabilitados pro mouse */
.card.locked .form-control,
.card.locked .form-select,
.card.locked .form-input,
.card.locked .btn {
    pointer-events: none;
    opacity: 0.6;
    user-select: none;
}

/* ═══════ MEMORIAL DE CÁLCULO STEP PANELS ═══════ */

.step-panel {
    animation: slideUp 0.4s ease-out;
}

@keyframes slideUp {
    from {
        opacity: 0;
        transform: translateY(20px);
    }

    to {
        opacity: 1;
        transform: translateY(0);
    }
}

.kpi-grid {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 8px;
    margin-top: 16px;
}

.kpi-card {
    background: var(--bg-base);
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    text-align: center;
    display: flex;
    flex-direction: column;
    justify-content: center;
}

.kpi-value {
    font-weight: 700;
    line-height: 1.2;
    margin-bottom: 4px;
}

.kpi-label {
    font-size: 0.75rem;
    color: var(--text-secondary);
    text-transform: uppercase;
    letter-spacing: 0.5px;
}

.result-hero {
    text-align: center;
    display: flex;
    flex-direction: column;
    justify-content: center;
    align-items: center;
}

.big-number {
    font-weight: 800;
    line-height: 1;
    margin-bottom: 4px;
}

.big-label {
    font-size: 0.85rem;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.5px;
}

/* ═══════ ETAPA 1 DIAGRAMA LOCOMOTIVA ═══════ */

.loco-physics-diagram {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 16px;
    width: 100%;
}

.force-group-backward {
    display: flex;
    flex-direction: column;
    align-items: flex-end;
    gap: 8px;
}

.force-arrow {
    display: flex;
    align-items: center;
    background: var(--bg-surface);
    border: 1px dashed var(--border);
    padding: 8px 16px;
    border-radius: var(--radius-sm);
    font-size: 0.9rem;
    gap: 8px;
    font-weight: 500;
}

.force-arrow.clickable:hover {
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.15);
    filter: brightness(1.1);
}

.force-arrow.backward {
    border-color: #ef4444;
    color: #ef4444;
    background: hsla(0, 84%, 60%, 0.05);
}

.force-arrow.forward {
    border-color: var(--accent);
    color: var(--accent);
    background: hsla(190, 70%, 48%, 0.05);
}

.arrow-symbol {
    font-weight: 800;
    font-size: 1.2rem;
}

.loco-box {
    background: var(--bg-surface);
    border: 2px solid var(--border);
    border-radius: 12px;
    padding: 12px 16px;
    box-shadow: 0 8px 16px rgba(0, 0, 0, 0.1);
    position: relative;
    z-index: 2;
}

/* ---------------------------------------------------------------------------
   Validation Console (Upload)
   --------------------------------------------------------------------------- */

.validation-console {
    background: var(--bg-base);
    border: 1px solid var(--border);
    border-radius: var(--radius-md);
    padding: 16px;
    font-family: 'JetBrains Mono', monospace;
    font-size: 0.85rem;
    max-height: 300px;
    overflow-y: auto;
    margin-bottom: 24px;
    box-shadow: inset 0 2px 4px rgba(0, 0, 0, 0.05);
}

.console-line {
    margin-bottom: 4px;
    line-height: 1.4;
    white-space: pre-wrap;
}

.console-warn {
    color: var(--warning);
}

.console-crit {
    color: var(--danger);
    font-weight: 600;
}

.console-success {
    color: var(--success);
}

/* Tooltip for disabled button */
[data-tooltip] {
    position: relative;
}

[data-tooltip]:disabled:hover::after {
    content: attr(data-tooltip);
    position: absolute;
    bottom: 100%;
    left: 50%;
    transform: translateX(-50%);
    background: var(--bg-surface);
    color: var(--text-primary);
    padding: 8px 12px;
    border-radius: 6px;
    font-size: 0.75rem;
    white-space: nowrap;
    z-index: 1000;
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.5);
    border: 1px solid var(--glass-border);
    margin-bottom: 10px;
    pointer-events: none;
    text-transform: none;
    font-weight: 400;
}

[data-tooltip]:disabled:hover::before {
    content: '';
    position: absolute;
    bottom: 100%;
    left: 50%;
    transform: translateX(-50%);
    border: 6px solid transparent;
    border-top-color: var(--border);
    margin-bottom: -2px;
    z-index: 1000;
    pointer-events: none;
}

/* ═══════ IMPORT LAYOUT REFINEMENTS ═══════ */

.import-actions-row {
    display: flex;
    gap: 24px;
    align-items: stretch;
    margin-top: 24px;
}

.import-actions-row>div {
    flex: 1;
    min-width: 0;
}

#upload-actions {
    display: flex;
    padding: 24px;
    height: 100%;
    /* Match height in stretch align */
    min-height: 160px;
    /* Base altura para equilibrar */
}

.validation-card {
    display: flex;
    flex-direction: column;
    height: 100%;
}

.validation-console {
    background: var(--bg-base);
    border: 1px solid var(--border);
    border-radius: var(--radius-md);
    padding: 16px;
    font-family: 'JetBrains Mono', monospace;
    font-size: 0.82rem;
    max-height: 200px;
    /* Reduced to fit better side-by-side */
    overflow-y: auto;
    margin-bottom: 0;
    box-shadow: inset 0 2px 4px rgba(0, 0, 0, 0.05);
}

/* ---------------------------------------------------------------------------
   Toast Notifications
   --------------------------------------------------------------------------- */

#toast-container {
    position: fixed;
    top: 24px;
    right: 24px;
    z-index: 9999;
    display: flex;
    flex-direction: column;
    gap: 12px;
    pointer-events: none;
}

.toast {
    pointer-events: auto;
    min-width: 320px;
    max-width: 450px;
    background: var(--glass-bg);
    backdrop-filter: blur(20px);
    -webkit-backdrop-filter: blur(20px);
    border: 1px solid var(--glass-border);
    border-radius: var(--radius-md);
    padding: 16px 20px;
    box-shadow: 0 12px 40px hsla(0, 0%, 0%, 0.4);
    display: flex;
    align-items: center;
    gap: 14px;
    animation: toast-in 0.4s cubic-bezier(0.18, 0.89, 0.32, 1.28) forwards;
    transition: all var(--transition-base);
}

.toast.removing {
    animation: toast-out 0.3s ease forwards;
}

@keyframes toast-in {
    from {
        opacity: 0;
        transform: translateX(100%) scale(0.9);
    }
    to {
        opacity: 1;
        transform: translateX(0) scale(1);
    }
}

@keyframes toast-out {
    from {
        opacity: 1;
        transform: scale(1);
    }
    to {
        opacity: 0;
        transform: scale(0.8);
    }
}

.toast-icon {
    width: 28px;
    height: 28px;
    border-radius: 8px;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 1.1rem;
    flex-shrink: 0;
}

.toast-content {
    flex: 1;
}

.toast-title {
    font-weight: 700;
    font-size: 0.9rem;
    color: var(--text-primary);
    margin-bottom: 2px;
}

.toast-message {
    font-size: 0.8rem;
    color: var(--text-secondary);
    line-height: 1.4;
}

/* Toast Variants */
.toast-success .toast-icon {
    background: hsla(145, 65%, 50%, 0.15);
    color: var(--success);
    border: 1px solid hsla(145, 65%, 50%, 0.3);
}

.toast-error .toast-icon {
    background: hsla(0, 75%, 60%, 0.15);
    color: var(--danger);
    border: 1px solid hsla(0, 75%, 60%, 0.3);
}

.toast-warning .toast-icon {
    background: hsla(38, 92%, 60%, 0.15);
    color: var(--warning);
    border: 1px solid hsla(38, 92%, 60%, 0.3);
}

.toast-info .toast-icon {
    background: var(--accent-muted);
    color: var(--accent);
    border: 1px solid var(--accent-glow);
}
