/* ────────────────────────────────────────────────────────
   Design tokens
──────────────────────────────────────────────────────── */
:root {
    --font: "Poppins", "Segoe UI", system-ui, -apple-system, sans-serif;
    --font-mono: "JetBrains Mono", monospace;
    --radius: 8px;
    --radius-sm: 6px;
    --radius-xs: 4px;
    --transition: 0.18s ease;
    --sidebar-width: 288px;
    --mobile-bar-h: 52px;
    --app-bar-h: 46px;
    /* chart layout — overridden by JS */
    --grid-cols: 3;
    --chart-h: 220px;
    --chart-h-tall: calc(var(--chart-h) * 2 + 1rem);
}

[data-theme="dark"] {
    --bg: #0b0920;
    --surface: #110e2a;
    --surface-2: #1a1635;
    --surface-3: #231e42;
    --text: #e8e4ff;
    --text-2: #8e88b8;
    --muted: #5c5690;
    --border: rgba(195, 255, 0, 0.1);
    --border-subtle: rgba(195, 255, 0, 0.05);
    --accent: #C3FF00;
    --accent-hover: #b3e600;
    --accent-bg: rgba(195, 255, 0, 0.08);
    --danger: #f85149;
    --danger-bg: rgba(248, 81, 73, 0.12);
    --danger-border: rgba(248, 81, 73, 0.3);
    --success: #3fb950;
    --chart-grid: rgba(255, 255, 255, 0.05);
    --chart-tick: #8e88b8;
    --shadow-sm: 0 1px 2px rgba(0, 0, 0, 0.4);
    --shadow: 0 4px 20px rgba(0, 0, 0, 0.5);
    --brand-grad: linear-gradient(135deg, #3fb950 0%, #C3FF00 100%);
}

/* ────────────────────────────────────────────────────────
   Reset & base
──────────────────────────────────────────────────────── */
*,
*::before,
*::after {
    box-sizing: border-box;
}

html,
body {
    margin: 0;
    min-height: 100%;
    font-family: var(--font);
    background: var(--bg);
    color: var(--text);
    transition: background var(--transition), color var(--transition);
    -webkit-font-smoothing: antialiased;
    overflow-x: hidden;
}

.sr-only {
    position: absolute;
    width: 1px;
    height: 1px;
    padding: 0;
    margin: -1px;
    overflow: hidden;
    clip: rect(0, 0, 0, 0);
    border: 0;
}

.hidden {
    display: none !important;
}

/* ────────────────────────────────────────────────────────
   App Bar (Top navigation)
   ──────────────────────────────────────────────────────── */
.app-bar {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    height: var(--app-bar-h);
    background: #060515;
    border-bottom: 1px solid rgba(195, 255, 0, 0.15);
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0 1rem;
    z-index: 500;
    backdrop-filter: blur(8px);
}

.app-bar-left {
    display: flex;
    align-items: center;
    gap: 0.75rem;
}

.m-back-link {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    color: var(--text-2);
    text-decoration: none;
    font-size: 11px;
    font-weight: 600;
    padding: 4px 10px;
    border: 1px solid rgba(195, 255, 0, 0.2);
    border-radius: 20px;
    transition: all 0.25s;
    text-transform: lowercase;
}

.m-back-link:hover {
    border-color: var(--accent);
    color: var(--accent);
    background: rgba(195, 255, 0, 0.05);
}

.lang-select {
    background: var(--surface-2);
    border: 1px solid var(--border);
    color: var(--text);
    font-size: 11px;
    font-weight: 600;
    padding: 3px 6px;
    border-radius: 4px;
    cursor: pointer;
    outline: none;
    transition: border-color 0.2s;
}

.lang-select:hover {
    border-color: var(--accent);
}

.m-brand-text {
    font-size: 12px;
    font-weight: 700;
    letter-spacing: 0.02em;
    color: var(--text);
}

.app-bar-right span[data-i18n] {
    opacity: 0.8;
    font-weight: 500;
}

/* ────────────────────────────────────────────────────────
   Mobile top bar
   ──────────────────────────────────────────────────────── */
.mobile-bar {
    display: none;
    position: fixed;
    top: var(--app-bar-h);
    left: 0;
    right: 0;
    height: var(--mobile-bar-h);
    background: var(--surface);
    border-bottom: 1px solid var(--border);
    z-index: 300;
    align-items: center;
    justify-content: space-between;
    padding: 0 0.75rem;
    gap: 0.5rem;
}

.mobile-title {
    font-weight: 700;
    font-size: 0.95rem;
    letter-spacing: -0.02em;
    flex: 1;
    text-align: center;
}

.btn-hamburger {
    width: 2.5rem;
    height: 2.5rem;
    border: none;
    background: transparent;
    color: var(--text);
    cursor: pointer;
    border-radius: var(--radius-xs);
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
    transition: background var(--transition);
    touch-action: manipulation;
}

.btn-hamburger:hover {
    background: var(--surface-2);
}

/* ────────────────────────────────────────────────────────
   Sidebar overlay (mobile)
──────────────────────────────────────────────────────── */
.sidebar-overlay {
    display: none;
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.55);
    z-index: 190;
    backdrop-filter: blur(2px);
    -webkit-backdrop-filter: blur(2px);
    opacity: 0;
    transition: opacity var(--transition);
}

/* ────────────────────────────────────────────────────────
   App shell
──────────────────────────────────────────────────────── */
.app {
    display: flex;
    min-height: 100vh;
    padding-top: var(--app-bar-h);
}

.mobile-sidebar-nav { display: none !important; }

/* ────────────────────────────────────────────────────────
   Sidebar
   ──────────────────────────────────────────────────────── */
.sidebar {
    width: var(--sidebar-width);
    flex-shrink: 0;
    background: var(--surface);
    border-right: 1px solid var(--border);
    position: sticky;
    top: var(--app-bar-h);
    height: calc(100vh - var(--app-bar-h));
    overflow-y: auto;
}

.sidebar-inner {
    display: flex;
    flex-direction: column;
    gap: 1.25rem;
    padding: 1.25rem 1rem;
    min-height: 100%;
}

.brand {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    padding-bottom: 0.1rem;
}

.brand-mark {
    width: 38px;
    height: 38px;
    border-radius: 10px;
    background: var(--brand-grad);
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
    box-shadow: 0 2px 8px rgba(37, 99, 235, 0.4);
}

.brand-mark svg {
    width: 20px;
    height: 20px;
}

.brand-title {
    font-weight: 700;
    font-size: 0.97rem;
    letter-spacing: -0.025em;
    line-height: 1.2;
}

.brand-sub {
    font-size: 0.7rem;
    color: var(--muted);
    margin-top: 0.1rem;
}

/* Close button — mobile only */
.btn-sidebar-close {
    display: none;
    margin-left: auto;
    width: 2rem;
    height: 2rem;
    border: none;
    background: transparent;
    color: var(--muted);
    cursor: pointer;
    border-radius: var(--radius-xs);
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
    transition: background var(--transition), color var(--transition);
}

.btn-sidebar-close:hover {
    background: var(--surface-2);
    color: var(--text);
}

/* Upload zone */
.upload-zone {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 0.4rem;
    border: 2px dashed var(--border);
    border-radius: var(--radius);
    padding: 1.1rem 0.75rem;
    text-align: center;
    cursor: pointer;
    transition: border-color var(--transition), background var(--transition);
    background: var(--surface-3);
    -webkit-tap-highlight-color: transparent;
    touch-action: manipulation;
}

.upload-zone:hover,
.upload-zone:focus-within,
.upload-zone.dragover {
    border-color: var(--accent);
    background: var(--accent-bg);
}

.upload-icon-wrap {
    width: 2.2rem;
    height: 2.2rem;
    border-radius: 50%;
    background: var(--surface-2);
    display: flex;
    align-items: center;
    justify-content: center;
    color: var(--accent);
}

.upload-text {
    font-weight: 600;
    font-size: 0.9rem;
    color: var(--text);
}

.upload-hint {
    font-size: 0.72rem;
    color: var(--muted);
    line-height: 1.4;
}

/* Upload status */
.upload-status {
    display: flex;
    align-items: center;
    gap: 0.6rem;
    font-size: 0.83rem;
    color: var(--muted);
    padding: 0.5rem 0.65rem;
    border-radius: var(--radius-sm);
    background: var(--surface-2);
}

.upload-spinner {
    width: 14px;
    height: 14px;
    border: 2px solid var(--border);
    border-top-color: var(--accent);
    border-radius: 50%;
    animation: spin 0.7s linear infinite;
}

@keyframes spin {
    to {
        transform: rotate(360deg);
    }
}

/* Flight history */
.sidebar-section {
    flex: 1;
    min-height: 0;
    display: flex;
    flex-direction: column;
    gap: 0.5rem;
}

.sidebar-heading {
    font-size: 0.7rem;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.08em;
    color: var(--muted);
}

.flight-list {
    list-style: none;
    margin: 0;
    padding: 0;
    overflow-y: auto;
    flex: 1;
    display: flex;
    flex-direction: column;
    gap: 0.3rem;
    max-height: 460px;
}

.flight-item {
    display: flex;
    align-items: stretch;
    border-radius: var(--radius-sm);
    overflow: hidden;
    border: 1px solid var(--border-subtle);
    transition: border-color var(--transition);
}

.flight-item.active {
    border-color: var(--accent);
    background: var(--accent-bg);
}

.flight-select {
    flex: 1;
    min-width: 0;
    text-align: left;
    padding: 0.6rem 0.7rem;
    border: none;
    background: transparent;
    color: var(--text);
    font-size: 0.8rem;
    cursor: pointer;
    line-height: 1.3;
    transition: background var(--transition);
    -webkit-tap-highlight-color: transparent;
    touch-action: manipulation;
}

.flight-select:hover {
    background: var(--surface-2);
}

.flight-item.active .flight-select:hover {
    background: transparent;
}

.flight-name {
    display: block;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    font-weight: 500;
    max-width: 100%;
}

.flight-meta {
    display: block;
    font-size: 0.67rem;
    color: var(--muted);
    margin-top: 0.15rem;
}

.flight-delete {
    flex-shrink: 0;
    width: 2.5rem;
    border: none;
    background: transparent;
    color: var(--muted);
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: background var(--transition), color var(--transition);
    border-left: 1px solid var(--border-subtle);
    -webkit-tap-highlight-color: transparent;
}

.flight-delete:hover {
    background: var(--danger-bg);
    color: var(--danger);
}

.empty-hint {
    font-size: 0.82rem;
    color: var(--muted);
    margin: 0;
    line-height: 1.5;
}

/* ────────────────────────────────────────────────────────
   Main content
──────────────────────────────────────────────────────── */
.main {
    flex: 1;
    min-width: 0;
    padding: 1.5rem 1.75rem 2.5rem;
    display: flex;
    flex-direction: column;
}

/* Toolbar */
.toolbar {
    display: flex;
    flex-wrap: wrap;
    align-items: flex-start;
    justify-content: space-between;
    gap: 0.75rem;
    margin-bottom: 1rem;
}

.page-title {
    margin: 0;
    font-size: 1.5rem;
    font-weight: 700;
    letter-spacing: -0.035em;
    line-height: 1.2;
}

.subtitle {
    margin: 0.3rem 0 0;
    color: var(--muted);
    font-size: 0.88rem;
    line-height: 1.5;
}

.toolbar-right {
    display: flex;
    align-items: flex-end;
    gap: 0.5rem;
    flex-wrap: wrap;
}

.field-inline {
    display: flex;
    flex-direction: column;
    gap: 0.22rem;
}

.field-label {
    font-size: 0.67rem;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.07em;
    color: var(--muted);
}

.select {
    min-width: 145px;
    padding: 0.45rem 0.65rem;
    border-radius: var(--radius-sm);
    border: 1px solid var(--border);
    background: var(--surface);
    color: var(--text);
    font-size: 0.85rem;
    font-family: inherit;
    cursor: pointer;
    transition: border-color var(--transition);
    appearance: auto;
}

.select:focus {
    outline: 2px solid var(--accent);
    outline-offset: 1px;
}

/* Buttons */
.btn {
    font-family: inherit;
    font-size: 0.82rem;
    cursor: pointer;
    border-radius: var(--radius-sm);
    border: 1px solid transparent;
    display: inline-flex;
    align-items: center;
    gap: 0.4rem;
    white-space: nowrap;
    transition: border-color var(--transition), background var(--transition), color var(--transition), opacity var(--transition);
    -webkit-tap-highlight-color: transparent;
    touch-action: manipulation;
}

.btn:disabled {
    opacity: 0.4;
    cursor: not-allowed;
}

.btn-ghost {
    padding: 0.46rem 0.7rem;
    background: var(--surface);
    border-color: var(--border);
    color: var(--text-2);
}

.btn-ghost:not(:disabled):hover {
    border-color: var(--accent);
    color: var(--accent);
}

.btn-icon {
    padding: 0.46rem 0.6rem;
}

/* Theme icon */
.theme-icon {
    width: 1.05rem;
    height: 1.05rem;
    border-radius: 50%;
    display: block;
    transition: background var(--transition);
}

[data-theme="dark"] .theme-icon {
    background: radial-gradient(circle at 30% 30%, #fde68a 0%, #f59e0b 45%, #1e293b 45%);
    box-shadow: inset -2px -2px 0 rgba(0, 0, 0, 0.2);
}

[data-theme="light"] .theme-icon {
    background: radial-gradient(circle at 68% 28%, #f8fafc 0%, #e2e8f0 45%, #0f172a 45%);
}

/* Banners */
.banner {
    padding: 0.7rem 1rem;
    border-radius: var(--radius-sm);
    margin-bottom: 1rem;
    font-size: 0.88rem;
    line-height: 1.5;
    border: 1px solid transparent;
}

.banner-error {
    background: var(--danger-bg);
    color: var(--danger);
    border-color: var(--danger-border);
}

/* Stats strip */
.stats-strip {
    display: flex;
    gap: 1rem 1.5rem;
    flex-wrap: wrap;
    margin-bottom: 0.85rem;
    padding: 0.75rem 0.85rem;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
}

.stat-item {
    display: flex;
    flex-direction: column;
    gap: 0.1rem;
}

.stat-label {
    font-size: 0.62rem;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.07em;
    color: var(--muted);
}

.stat-value {
    font-size: 0.86rem;
    font-weight: 600;
    color: var(--text);
}

/* ────────────────────────────────────────────────────────
   View controls bar
──────────────────────────────────────────────────────── */
.view-controls {
    display: flex;
    align-items: center;
    gap: 1.25rem;
    flex-wrap: wrap;
    margin-bottom: 1rem;
    padding: 0.5rem 0.85rem;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
}

.vc-group {
    display: flex;
    align-items: center;
    gap: 0.55rem;
}

.vc-group-height {
    flex: 1;
    min-width: 220px;
}

.vc-label {
    font-size: 0.68rem;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.07em;
    color: var(--muted);
    white-space: nowrap;
}

/* Segmented column control */
.seg-ctrl {
    display: flex;
    border: 1px solid var(--border);
    border-radius: var(--radius-xs);
    overflow: hidden;
}

.seg-btn {
    width: 2.1rem;
    height: 1.9rem;
    border: none;
    background: var(--surface-2);
    color: var(--muted);
    font-size: 0.82rem;
    font-weight: 600;
    font-family: inherit;
    cursor: pointer;
    transition: background var(--transition), color var(--transition);
    border-right: 1px solid var(--border);
    -webkit-tap-highlight-color: transparent;
    touch-action: manipulation;
}

.seg-btn:last-child {
    border-right: none;
}

.seg-btn:hover {
    background: var(--surface-3);
    color: var(--text);
}

.seg-btn[aria-pressed="true"] {
    background: var(--accent);
    color: #0b0920;
    /* Dark text for neon background */
}

/* Height slider row */
.vc-slider-row {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    flex: 1;
}

.vc-step-btn {
    width: 1.7rem;
    height: 1.7rem;
    border: 1px solid var(--border);
    border-radius: var(--radius-xs);
    background: var(--surface-2);
    color: var(--muted);
    cursor: pointer;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
    transition: border-color var(--transition), background var(--transition), color var(--transition);
    -webkit-tap-highlight-color: transparent;
}

.vc-step-btn:hover {
    border-color: var(--accent);
    color: var(--accent);
    background: var(--accent-bg);
}

.slider {
    flex: 1;
    min-width: 80px;
    height: 4px;
    -webkit-appearance: none;
    appearance: none;
    background: var(--border);
    border-radius: 2px;
    outline: none;
    cursor: pointer;
    accent-color: var(--accent);
}

.slider::-webkit-slider-thumb {
    -webkit-appearance: none;
    appearance: none;
    width: 16px;
    height: 16px;
    border-radius: 50%;
    background: var(--accent);
    cursor: pointer;
    box-shadow: 0 1px 4px rgba(0, 0, 0, 0.25);
}

.slider::-moz-range-thumb {
    width: 16px;
    height: 16px;
    border-radius: 50%;
    background: var(--accent);
    cursor: pointer;
    border: none;
    box-shadow: 0 1px 4px rgba(0, 0, 0, 0.25);
}

.vc-height-val {
    font-size: 0.78rem;
    font-weight: 600;
    color: var(--text-2);
    min-width: 3.5rem;
    text-align: right;
    white-space: nowrap;
}

/* ────────────────────────────────────────────────────────
   Empty state
──────────────────────────────────────────────────────── */
.empty-state {
    flex: 1;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    text-align: center;
    gap: 1rem;
    padding: 4rem 2rem;
    color: var(--muted);
}

.empty-state-icon {
    width: 5rem;
    height: 5rem;
    opacity: 0.18;
    color: var(--text);
}

.empty-state-icon svg {
    width: 100%;
    height: 100%;
}

.empty-state-title {
    margin: 0;
    font-size: 1.1rem;
    font-weight: 600;
    color: var(--text-2);
    opacity: 0.7;
}

.empty-state-text {
    margin: 0;
    font-size: 0.88rem;
    max-width: 38ch;
    line-height: 1.6;
}

/* ────────────────────────────────────────────────────────
   Charts section
──────────────────────────────────────────────────────── */
.charts-section {
    animation: fadeIn 0.3s ease;
}

@keyframes fadeIn {
    from {
        opacity: 0;
        transform: translateY(6px);
    }

    to {
        opacity: 1;
        transform: translateY(0);
    }
}

/* Grid — columns and height driven by CSS vars set from JS */
.chart-grid {
    display: grid;
    grid-template-columns: repeat(var(--grid-cols), minmax(0, 1fr));
    gap: 0.9rem;
    align-items: start;
    width: 100%;
    min-width: 0;
    container-type: inline-size;
    container-name: chartgrid;
}

.chart-grid > * {
    min-width: 0;
}

/* XY trajectory spans 2 rows only when cols = 3 (class toggled by JS) */
.chart-card-span-rows.span-active {
    grid-column: 3;
    grid-row: 1 / span 2;
}

/* When the grid is too narrow for a dedicated 3rd track, let XY use full width */
@container chartgrid (max-width: 52rem) {
    .chart-card-span-rows.span-active {
        grid-column: 1 / -1;
        grid-row: auto;
    }
}

/* Fallback when container queries are not supported */
@media (max-width: 52rem) {
    .chart-card-span-rows.span-active {
        grid-column: 1 / -1;
        grid-row: auto;
    }
}

/* Chart card */
.chart-card {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 0.85rem 0.9rem 0.6rem;
    box-shadow: var(--shadow-sm);
    display: flex;
    flex-direction: column;
    transition: box-shadow var(--transition), border-color var(--transition);
}

.chart-card:hover {
    border-color: var(--accent);
    box-shadow: var(--shadow);
}

/* Card header */
.chart-card-head {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 0.5rem;
    margin-bottom: 0.55rem;
    min-height: 1.8rem;
}

.chart-title {
    margin: 0;
    font-size: 0.82rem;
    font-weight: 600;
    color: var(--text-2);
    letter-spacing: -0.01em;
    flex: 1;
    min-width: 0;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

/* Chart action buttons */
.chart-actions {
    display: flex;
    align-items: center;
    gap: 0.25rem;
    flex-shrink: 0;
    opacity: 0;
    transition: opacity var(--transition);
}

.chart-card:hover .chart-actions,
.chart-card:focus-within .chart-actions {
    opacity: 1;
}

/* On touch devices always show chart actions */
@media (hover: none) {
    .chart-actions {
        opacity: 1;
    }
}

.btn-chart-icon {
    width: 1.8rem;
    height: 1.8rem;
    border: 1px solid var(--border);
    border-radius: var(--radius-xs);
    background: var(--surface-2);
    color: var(--muted);
    cursor: pointer;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    transition: border-color var(--transition), background var(--transition), color var(--transition);
    -webkit-tap-highlight-color: transparent;
    touch-action: manipulation;
}

.btn-chart-icon:hover {
    border-color: var(--accent);
    color: var(--accent);
    background: var(--accent-bg);
}

.btn-chart-dl:hover {
    border-color: var(--success);
    color: var(--success);
    background: rgba(22, 163, 74, 0.08);
}

[data-theme="dark"] .btn-chart-dl:hover {
    background: rgba(74, 222, 128, 0.1);
}

/* Chart canvas wrap — height controlled by JS */
.chart-wrap {
    position: relative;
    flex: none;
    /* Prevent flex growing beyond fixed height */
    height: var(--chart-h);
    max-height: var(--chart-h);
    overflow: hidden;
}

.chart-wrap-tall {
    height: var(--chart-h-tall);
    max-height: var(--chart-h-tall);
}

.chart-wrap canvas {
    display: block;
    max-width: 100%;
}

/* Chart hint */
.chart-hint {
    margin: 0.35rem 0 0;
    font-size: 0.65rem;
    color: var(--muted);
    opacity: 0.55;
    text-align: right;
}

/* Battery empty state */
#card-battery .empty-hint {
    display: flex;
    align-items: center;
    justify-content: center;
    text-align: center;
    padding: 1rem;
    min-height: 100px;
}

/* ────────────────────────────────────────────────────────
   Scrollbars
──────────────────────────────────────────────────────── */
.flight-list::-webkit-scrollbar,
.sidebar::-webkit-scrollbar {
    width: 4px;
}

.flight-list::-webkit-scrollbar-track,
.sidebar::-webkit-scrollbar-track {
    background: transparent;
}

.flight-list::-webkit-scrollbar-thumb,
.sidebar::-webkit-scrollbar-thumb {
    background: var(--border);
    border-radius: 4px;
}

/* ────────────────────────────────────────────────────────
   Responsive — tablet / small laptop (≤1024px)
──────────────────────────────────────────────────────── */
@media (max-width: 1024px) {
    .main {
        padding: 1.1rem min(1.5rem, 4vw) 2rem;
        padding-left: max(1rem, env(safe-area-inset-left, 0px));
        padding-right: max(1rem, env(safe-area-inset-right, 0px));
        padding-bottom: max(1.5rem, env(safe-area-inset-bottom, 0px));
    }

    .app {
        min-width: 0;
    }

    .page-title {
        font-size: clamp(1.15rem, 2.8vw, 1.45rem);
    }

    .subtitle {
        font-size: clamp(0.78rem, 1.8vw, 0.88rem);
    }

    .toolbar {
        align-items: flex-start;
    }

    .toolbar-right {
        flex: 1 1 auto;
        justify-content: flex-end;
        max-width: 100%;
    }

    .select {
        min-width: min(145px, 42vw);
    }

    /* Fluid columns: adapts when the window is narrower than N × chart min width */
    #chart-grid {
        grid-template-columns: repeat(auto-fill, minmax(min(100%, 236px), 1fr)) !important;
    }

    .view-controls {
        gap: 0.65rem 1rem;
    }

    .vc-group-height {
        flex: 1 1 240px;
        min-width: min(100%, 200px);
    }

    .stats-strip {
        gap: 0.65rem 1rem;
    }

    .chart-card-head {
        flex-wrap: wrap;
        row-gap: 0.35rem;
    }

    .chart-title {
        white-space: normal;
        overflow: visible;
        text-overflow: unset;
        line-height: 1.25;
    }
}

/* ────────────────────────────────────────────────────────
   Responsive — tablet (≤1280px)
──────────────────────────────────────────────────────── */
@media (max-width: 1280px) {

    /* Toolbar button labels hidden to save space */
    .btn-label {
        display: none;
    }
}

/* ────────────────────────────────────────────────────────
   Responsive — mobile (≤800px)
   ──────────────────────────────────────────────────────── */
@media (max-width: 800px) {

    /* Hide desktop app-bar entirely to save vertical space */
    .app-bar {
        display: none;
    }

    /* Primary mobile header - MUST BE FIXED TO TOP */
    .mobile-bar {
        display: flex;
        position: fixed;
        top: 0;
        left: 0;
        right: 0;
        z-index: 1500;
        height: 52px;
        background: #0b0920;
        border-bottom: 1px solid rgba(255, 255, 255, 0.06);
        padding: 0 max(0.75rem, env(safe-area-inset-right, 0px)) 0 max(0.75rem, env(safe-area-inset-left, 0px));
        padding-top: env(safe-area-inset-top, 0px);
        min-height: calc(52px + env(safe-area-inset-top, 0px));
        align-items: center;
        justify-content: center;
        /* Center content */
    }

    .btn-hamburger {
        position: absolute;
        left: max(0.75rem, env(safe-area-inset-left, 0px));
    }

    .mobile-title {
        font-size: 0.85rem;
        font-weight: 600;
        color: #fff;
        text-transform: uppercase;
        letter-spacing: 0.5px;
    }

    /* Content starts below mobile bar + notch */
    .app {
        padding-top: calc(52px + env(safe-area-inset-top, 0px));
    }

    /* Sidebar drawer polish */
    .sidebar {
        position: fixed;
        top: 0;
        left: calc(-1 * var(--sidebar-width));
        height: 100%;
        z-index: 2000;
        transition: left 0.3s cubic-bezier(0.4, 0, 0.2, 1);
        background: #0b0920;
    }

    .sidebar.sidebar-open {
        left: 0;
        box-shadow: 20px 0 60px rgba(0, 0, 0, 0.9);
        padding-bottom: max(1.25rem, env(safe-area-inset-bottom, 0px));
    }

    /* Overlay fix */
    .sidebar-overlay {
        z-index: 1800;
        background: rgba(0, 0, 0, 0.7);
        backdrop-filter: blur(2px);
    }

    .sidebar-overlay.overlay-visible {
        display: block;
        opacity: 1;
    }

    /* Close button must be visible */
    .btn-sidebar-close {
        display: flex !important;
        z-index: 2100;
    }

    .mobile-sidebar-nav {
        margin-top: auto;
        padding: 1.5rem 1rem;
        border-top: 1px solid rgba(255, 255, 255, 0.1);
        background: rgba(255, 255, 255, 0.02);
    }

    .lang-select-sidebar {
        width: 100%;
        background: rgba(255, 255, 255, 0.08);
        color: #fff;
        border: 1px solid rgba(255, 255, 255, 0.15);
        padding: 10px;
        border-radius: 8px;
        font-family: inherit;
        outline: none;
        margin-top: 0.5rem;
    }

    .sidebar-link {
        display: flex;
        align-items: center;
        gap: 10px;
        padding: 10px;
        color: #fff;
        background: rgba(255, 255, 255, 0.05);
        border-radius: 8px;
        text-decoration: none;
        font-size: 14px;
        margin-bottom: 1.2rem;
    }

    /* COMPACT VIEW CONTROLS — no vertical flex-grow (was stretching the slider row) */
    .view-controls {
        flex-direction: column;
        align-items: stretch;
        gap: 0.45rem;
        padding: 0.5rem 0.65rem;
        margin-bottom: 0.8rem;
        background: rgba(255, 255, 255, 0.03);
        border-radius: 12px;
        border: 1px solid rgba(255, 255, 255, 0.05);
    }

    /* Hide Columns on mobile (First group) */
    .view-controls > .vc-group:not(.vc-group-height) { display: none !important; }

    .mobile-sidebar-nav {
        display: block !important;
    }

    .vc-group-height {
        width: 100%;
        flex: 0 0 auto;
        min-height: 0;
    }

    .vc-group {
        width: 100%;
        justify-content: space-between;
    }

    .vc-label {
        font-size: 11px;
        text-transform: uppercase;
        letter-spacing: 0.8px;
        opacity: 0.7;
    }

    .vc-slider-row {
        gap: 0.4rem;
        flex: 1;
        min-width: 0;
    }

    .slider {
        flex: 1;
        min-width: 0;
        height: 4px;
    }

    .vc-height-val {
        font-size: 10px;
        min-width: 42px;
        text-align: right;
        opacity: 0.9;
        white-space: nowrap;
    }

    .vc-step-btn {
        width: 32px;
        height: 32px;
        background: rgba(255, 255, 255, 0.05);
    }

    /* COMPACT CHARTS */
    .chart-grid {
        gap: 0.8rem !important;
        grid-template-columns: 1fr !important;
    }

    /* XY card uses grid-column: 3 on desktop — invalid in 1-col layout */
    .chart-card-span-rows.span-active {
        grid-column: 1 / -1 !important;
        grid-row: auto !important;
    }

    .chart-card {
        padding: 0.75rem;
        border-radius: 14px;
        background: rgba(15, 13, 40, 0.5);
    }

    .chart-card-head {
        margin-bottom: 0.6rem;
    }

    .chart-title {
        font-size: 0.85rem;
        font-weight: 500;
    }

    .chart-hint {
        display: none;
    }

    /* Save space on mobile */
    .btn-chart-icon {
        width: 28px;
        height: 28px;
        background: rgba(255, 255, 255, 0.04);
    }

    /* STATS STRIP - Compact horizontal pill list */
    .stats-strip {
        display: flex;
        gap: 0.75rem;
        padding: 0.8rem 1.25rem 0.8rem;
        margin-bottom: 0.8rem;
        overflow-x: auto;
        flex-wrap: nowrap !important;
        -webkit-overflow-scrolling: touch;
    }

    .stats-strip::-webkit-scrollbar {
        display: block;
        height: 3px;
    }

    .stats-strip::-webkit-scrollbar-track {
        background: rgba(255, 255, 255, 0.05);
        margin: 0 1.25rem;
        border-radius: 10px;
    }

    .stats-strip::-webkit-scrollbar-thumb {
        background: var(--accent);
        border-radius: 10px;
    }

    .stat-item {
        padding: 0.6rem 0.8rem;
        background: rgba(255, 255, 255, 0.04);
        border-radius: 10px;
        min-width: 110px;
        flex-shrink: 0;
        border: 1px solid rgba(255, 255, 255, 0.03);
    }

    .stat-label {
        font-size: 10px;
        margin-bottom: 4px;
        opacity: 0.6;
    }

    .stat-value {
        font-size: 0.9rem;
        font-weight: 600;
    }

    /* Toolbar cleanup */
    .toolbar {
        gap: 0.4rem;
        margin-bottom: 0.8rem;
    }

    .page-title {
        font-size: 1.15rem;
    }

    .subtitle {
        font-size: 0.8rem;
        margin-top: 2px;
        opacity: 0.7;
    }

    .toolbar-right {
        display: none;
    }

    /* Settings are redundant here for mobile */
}

/* Very small screens */
@media (max-width: 380px) {
    .main {
        padding: 0.5rem;
    }

    .stat-item {
        min-width: 100px;
    }
}