@import url('https://fonts.googleapis.com/css2?family=Fraunces:ital,opsz,wght@0,9..144,300;0,9..144,400;0,9..144,600;0,9..144,700;0,9..144,800;1,9..144,300&family=Instrument+Sans:wght@400;500;600;700&family=JetBrains+Mono:wght@400;500;700&display=swap');

:root {
    /* Color Palette */
    --bg-app: #0a0a0a;
    --bg-sidebar: #051515;
    --bg-card: rgba(10, 25, 25, 0.85);
    --bg-card-hover: rgba(15, 35, 35, 0.95);

    --border-subtle: rgba(80, 210, 193, 0.12);
    --border-focus: rgba(80, 210, 193, 0.5);

    --primary: #50d2c1;
    --primary-glow: rgba(80, 210, 193, 0.3);
    --accent: #FFB454;

    --success: #10b981;
    --success-bg: rgba(16, 185, 129, 0.1);
    --danger: #f43f5e;
    --danger-bg: rgba(244, 63, 94, 0.1);

    --text-primary: #f7f6f3;
    --text-secondary: #b8c4c3;
    --text-tertiary: #7a9190;

    /* Gradients */
    --gradient-brand: linear-gradient(135deg, #50d2c1 0%, #2dd4bf 100%);
    --gradient-surface: linear-gradient(180deg, rgba(10, 25, 25, 0.7) 0%, rgba(5, 21, 21, 0.7) 100%);

    /* Dimensions */
    --sidebar-width: 260px;
    --header-height: 70px;

    /* Effects */
    --radius-sm: 6px;
    --radius-md: 12px;
    --radius-lg: 16px;
    --shadow-sm: 0 1px 2px 0 rgba(0, 0, 0, 0.05);
    --shadow-md: 0 4px 6px -1px rgba(0, 0, 0, 0.1);
    --shadow-hover: 0 10px 15px -3px rgba(0, 0, 0, 0.15), 0 4px 6px -4px rgba(0, 0, 0, 0.1);
    --glass: blur(8px);

    /* Fonts */
    --font-heading: 'Fraunces', serif;
    --font-body: 'Instrument Sans', sans-serif;
}

/* Custom Scrollbar */
::-webkit-scrollbar {
    width: 6px;
    height: 6px;
}

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

::-webkit-scrollbar-thumb {
    background: rgba(148, 163, 184, 0.2);
    border-radius: 10px;
}

::-webkit-scrollbar-thumb:hover {
    background: rgba(148, 163, 184, 0.4);
}

/* Reset */
* {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
}

body {
    font-family: var(--font-body);
    background: var(--bg-app);
    color: var(--text-primary);
    font-size: 14px;
    line-height: 1.6;
    overflow-x: hidden;
    max-width: 100vw;
    min-height: 100vh;
    display: flex;
}

/* Typography */
h1,
h2,
h3,
h4 {
    font-family: var(--font-heading);
    font-weight: 600;
    color: var(--text-primary);
    margin-bottom: 1rem;
}

h1 {
    font-size: 2rem;
    letter-spacing: -0.02em;
}

h2 {
    font-size: 1.5rem;
    letter-spacing: -0.01em;
}

h3 {
    font-size: 1.125rem;
}

.text-xs {
    font-size: 0.75rem;
}

.text-sm {
    font-size: 0.875rem;
}

.text-muted {
    color: var(--text-secondary);
}

.text-mono {
    font-family: 'JetBrains Mono', monospace;
}

/* Interactive */
a {
    color: inherit;
    text-decoration: none;
    transition: 0.2s;
}

button {
    font-family: inherit;
    border: none;
    cursor: pointer;
    transition: 0.2s;
}

/* Layout: Sidebar & Main */
.app-wrapper {
    display: flex;
    width: 100%;
    max-width: 100vw;
    overflow-x: hidden;
}

.sidebar {
    width: var(--sidebar-width);
    background: var(--bg-sidebar);
    border-right: 1px solid var(--border-subtle);
    height: 100vh;
    position: fixed;
    top: 0;
    left: 0;
    padding: 1.5rem;
    display: flex;
    flex-direction: column;
    z-index: 50;
    overflow-y: auto;
    scrollbar-width: thin;
    scrollbar-color: var(--primary) transparent;
    transition: transform 0.3s ease;
}

.sidebar::-webkit-scrollbar {
    width: 4px;
}

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

.sidebar::-webkit-scrollbar-thumb {
    background: var(--primary);
    border-radius: 10px;
}

.main-content {
    flex: 1;
    margin-left: var(--sidebar-width);
    min-height: 100vh;
    padding: 2rem;
    /* Clamp to viewport so nothing bleeds off-screen */
    max-width: calc(100vw - var(--sidebar-width));
    overflow-x: hidden;
    transition: margin-left 0.3s ease;
}

#mobile-toggle {
    display: none;
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    z-index: 60;
    background: var(--bg-app);
    padding: 0.75rem 1rem;
    border-bottom: 1px solid var(--border-subtle);
    backdrop-filter: var(--glass);
    -webkit-backdrop-filter: var(--glass);
}

/* Components: Sidebar */
.brand {
    font-size: 1.25rem;
    font-weight: 700;
    margin-bottom: 3rem;
    display: flex;
    align-items: center;
    gap: 0.75rem;
    color: var(--text-primary);
}

.brand svg {
    color: var(--primary);
}

.nav-menu {
    list-style: none;
    display: flex;
    flex-direction: column;
    gap: 0.5rem;
}

.nav-item {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    padding: 0.75rem 1rem;
    color: var(--text-secondary);
    border-radius: var(--radius-sm);
    font-size: 0.95rem;
    font-weight: 500;
}

.nav-item:hover {
    background: rgba(255, 255, 255, 0.03);
    color: var(--text-primary);
}

.nav-item.active {
    background: var(--gradient-brand);
    color: white;
    box-shadow: 0 4px 12px var(--primary-glow);
}

/* Components: Cards */
.card {
    background: var(--bg-card);
    border: 1px solid var(--border-subtle);
    border-radius: var(--radius-md);
    padding: 1.5rem;
    backdrop-filter: var(--glass);
    transition: all 0.25s cubic-bezier(0.4, 0, 0.2, 1);
    box-shadow: var(--shadow-sm);
}

.card:hover {
    border-color: rgba(80, 210, 193, 0.35);
    transform: translateY(-2px);
    background: var(--bg-card-hover);
    box-shadow: var(--shadow-hover);
}

/* Components: Stats Grid */
.stat-card {
    display: flex;
    flex-direction: column;
}

.stat-label {
    font-size: 0.875rem;
    color: var(--text-secondary);
    margin-bottom: 0.5rem;
}

.stat-value {
    font-size: 1.75rem;
    font-weight: 700;
    letter-spacing: -0.02em;
}

.stat-trend {
    font-size: 0.875rem;
    margin-top: 0.5rem;
    display: flex;
    align-items: center;
    gap: 0.25rem;
}

/* Components: Heatmap */
.heatmap-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(100px, 1fr));
    gap: 0.75rem;
}

.heatmap-cell {
    border-radius: var(--radius-sm);
    padding: 0.75rem;
    transition: transform 0.2s, box-shadow 0.2s;
    cursor: default;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    height: 100%;
}

.heatmap-cell:hover {
    transform: translateY(-2px);
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.2);
    z-index: 10;
}

/* Components: Tables */
.table-container {
    width: 100%;
    overflow-x: auto;
    border-radius: var(--radius-md);
    border: 1px solid var(--border-subtle);
    background: var(--bg-card);
    -webkit-overflow-scrolling: touch;
}

.data-table {
    width: 100%;
    min-width: 600px;
    border-collapse: separate;
    border-spacing: 0;
    font-size: 0.875rem;
}

.data-table th {
    text-align: left;
    padding: 0.875rem 1rem;
    color: var(--text-secondary);
    font-weight: 600;
    font-size: 0.75rem;
    text-transform: uppercase;
    letter-spacing: 0.05em;
    border-bottom: 1px solid var(--border-subtle);
    background: rgba(5, 21, 21, 0.97);
    white-space: nowrap;
    position: sticky;
    top: 0;
    z-index: 10;
    backdrop-filter: blur(8px);
}

.data-table td {
    padding: 0.875rem 1rem;
    border-bottom: 1px solid rgba(148, 163, 184, 0.05);
    color: var(--text-primary);
    transition: background-color 0.15s ease;
}

.data-table tbody tr {
    transition: background-color 0.2s ease;
}

.data-table tbody tr:hover td {
    background: rgba(255, 255, 255, 0.03);
}

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

/* Utilities */
.text-left {
    text-align: left !important;
}

.text-center {
    text-align: center !important;
}

.text-right {
    text-align: right !important;
}

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

.text-danger {
    color: var(--danger);
}

.bg-success {
    background: var(--success-bg);
    color: var(--success);
    padding: 2px 8px;
    border-radius: 4px;
}

.bg-danger {
    background: var(--danger-bg);
    color: var(--danger);
    padding: 2px 8px;
    border-radius: 4px;
}

.mb-8 {
    margin-bottom: 2rem;
}

/* Flex & Grid Utilities */
.flex-column {
    display: flex;
    flex-direction: column;
}

.flex-row {
    display: flex;
    flex-direction: row;
}

.flex-center {
    display: flex;
    align-items: center;
    justify-content: center;
}

.flex-between {
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.gap-1 {
    gap: 0.25rem;
}

.gap-2 {
    gap: 0.5rem;
}

.gap-3 {
    gap: 0.75rem;
}

.gap-4 {
    gap: 1rem;
}

.gap-6 {
    gap: 1.5rem;
}

.gap-8 {
    gap: 2rem;
}

/* Margin Utilities */
.mt-1 {
    margin-top: 0.25rem;
}

.mt-2 {
    margin-top: 0.5rem;
}

.mt-3 {
    margin-top: 0.75rem;
}

.mt-4 {
    margin-top: 1rem;
}

.mt-6 {
    margin-top: 1.5rem;
}

.mt-8 {
    margin-top: 2rem;
}

.mb-1 {
    margin-bottom: 0.25rem;
}

.mb-2 {
    margin-bottom: 0.5rem;
}

.mb-3 {
    margin-bottom: 0.75rem;
}

.mb-4 {
    margin-bottom: 1rem;
}

.mb-6 {
    margin-bottom: 1.5rem;
}

@media (min-width: 1280px) {
    .xl\:mt-0 {
        margin-top: 0 !important;
    }
}

.rounded-lg {
    border-radius: var(--radius-lg);
}

.p-3 {
    padding: 0.75rem;
}

/* Updated Responsive Grids */
.grid {
    display: grid;
    gap: 1rem;
}

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

/* 2 cols at 480px for small phones */
@media (min-width: 480px) {
    .grid-2 {
        grid-template-columns: repeat(2, 1fr);
    }

    .grid-4,
    .grid-5 {
        grid-template-columns: repeat(2, 1fr);
    }
}

@media (min-width: 640px) {
    .grid-2 {
        grid-template-columns: repeat(2, 1fr);
    }
}

@media (min-width: 768px) {
    .grid-3 {
        grid-template-columns: repeat(3, 1fr);
    }

    .grid {
        gap: 1.5rem;
    }
}

@media (min-width: 1024px) {
    .grid-4 {
        grid-template-columns: repeat(4, 1fr);
    }

    .grid-5 {
        grid-template-columns: repeat(5, 1fr);
    }

    .grid {
        gap: 2rem;
    }
}

.hidden-mobile {
    display: none !important;
}

@media (min-width: 768px) {
    .hidden-mobile {
        display: block !important;
    }

    th.hidden-mobile,
    td.hidden-mobile {
        display: table-cell !important;
    }
}

.stack-mobile {
    flex-direction: column !important;
    gap: 0.75rem;
    align-items: flex-start !important;
}

@media (min-width: 768px) {
    .stack-mobile {
        flex-direction: row !important;
        align-items: center !important;
        gap: 0;
    }
}

/* Buttons & Forms */
.btn {
    padding: 0.75rem 1.25rem;
    border-radius: var(--radius-sm);
    font-weight: 500;
    font-size: 0.9rem;
    display: inline-flex;
    align-items: center;
    gap: 0.5rem;
    justify-content: center;
}

.btn-primary {
    background: var(--gradient-brand);
    color: #0a0a0a;
    box-shadow: 0 2px 10px rgba(80, 210, 193, 0.25);
}

.btn-primary:hover {
    opacity: 0.9;
    transform: translateY(-1px);
}

.btn-sidebar {
    width: 100%;
    justify-content: center;
    background: rgba(255, 255, 255, 0.05);
    border: 1px solid var(--border-subtle);
    color: var(--text-secondary);
    transition: all 0.2s;
}

.btn-sidebar:hover {
    background: var(--bg-card-hover);
    color: var(--text-primary);
    border-color: rgba(80, 210, 193, 0.5);
}

.form-input {
    width: 100%;
    background: rgba(15, 23, 42, 0.5);
    border: 1px solid var(--border-subtle);
    padding: 0.75rem;
    border-radius: var(--radius-sm);
    color: var(--text-primary);
    font-family: inherit;
    transition: 0.2s;
}

.form-input:focus {
    outline: none;
    border-color: var(--primary);
    box-shadow: 0 0 0 3px var(--primary-glow);
}

/* Modal */
.modal-overlay {
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.7);
    backdrop-filter: blur(4px);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 100;
}

.modal-box {
    background: #0a1a1a;
    border: 1px solid var(--border-subtle);
    padding: 2rem;
    border-radius: var(--radius-lg);
    width: 92%;
    max-width: 450px;
    max-height: 90vh;
    overflow-y: auto;
    box-shadow: 0 20px 25px -5px rgba(0, 0, 0, 0.5);
}

/* Mobile Responsive Refined */
@media (max-width: 1024px) {
    .sidebar {
        transform: translateX(-100%);
        box-shadow: 20px 0 50px rgba(0, 0, 0, 0.5);
    }

    .main-content {
        margin-left: 0;
        padding: 4.5rem 1rem 1.5rem 1rem;
        /* top padding accounts for fixed mobile header */
        max-width: 100%;
        width: 100vw;
    }

    .sidebar.open {
        transform: translateX(0);
        opacity: 1;
    }

    #mobile-toggle {
        display: flex;
        align-items: center;
        gap: 1rem;
    }
}

@media (max-width: 480px) {
    .main-content {
        padding: 4.5rem 0.75rem 1.5rem 0.75rem;
    }

    .modal-box {
        padding: 1.25rem;
        width: 96%;
        border-radius: var(--radius-md);
    }

    .stat-value {
        font-size: 1.25rem !important;
    }

    h1 {
        font-size: 1.4rem;
    }

    h2 {
        font-size: 1.2rem;
    }

    h3 {
        font-size: 1rem;
    }

    .card {
        padding: 1rem;
    }
}

.sidebar-overlay {
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.5);
    z-index: 45;
    display: none;
    backdrop-filter: blur(2px);
    -webkit-backdrop-filter: blur(2px);
}

/* Overlay is shown via JS class toggle on the overlay element itself */
.sidebar-overlay.active {
    display: block;
}

/* Layout: Dashboard Grid */
.dashboard-grid {
    display: grid;
    grid-template-columns: 1fr;
    gap: 1.5rem;
}

@media (min-width: 1024px) {
    .dashboard-grid {
        grid-template-columns: repeat(12, 1fr);
    }

    .card-calculator {
        grid-column: span 4;
    }

    .card-heatmap {
        grid-column: span 8;
    }
}

/* UI/UX Enhancements */
.icon-box {
    width: 48px;
    height: 48px;
    border-radius: var(--radius-md);
    background: rgba(255, 255, 255, 0.03);
    border: 1px solid var(--border-subtle);
    display: flex;
    align-items: center;
    justify-content: center;
    color: var(--text-secondary);
    font-size: 1.25rem;
    transition: 0.2s;
}

.card:hover .icon-box {
    background: var(--primary-glow);
    color: white;
    border-color: var(--primary);
}

.progress-track {
    width: 100%;
    height: 6px;
    background: rgba(255, 255, 255, 0.05);
    border-radius: 10px;
    overflow: hidden;
}

.progress-fill {
    height: 100%;
    border-radius: 10px;
    transition: width 0.5s ease;
}

.badge {
    padding: 0.25rem 0.5rem;
    border-radius: var(--radius-sm);
    font-size: 0.75rem;
    font-weight: 600;
    letter-spacing: 0.02em;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    white-space: nowrap;
}

.badge-soft {
    background: rgba(255, 255, 255, 0.05);
    color: var(--text-secondary);
    border: 1px solid var(--border-subtle);
}

.badge-success {
    background: var(--success-bg);
    color: var(--success);
    border: 1px solid rgba(16, 185, 129, 0.2);
}

.badge-danger {
    background: var(--danger-bg);
    color: var(--danger);
    border: 1px solid rgba(244, 63, 94, 0.2);
}

.badge-neutral {
    background: rgba(148, 163, 184, 0.1);
    color: var(--text-secondary);
    border: 1px solid var(--border-subtle);
}

/* Animations */
@keyframes fadeIn {
    from {
        opacity: 0;
        transform: translateY(10px);
    }

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

.animate-fade-in {
    animation: fadeIn 0.4s ease-out forwards;
}

@keyframes pulse-soft {

    0%,
    100% {
        opacity: 1;
    }

    50% {
        opacity: 0.5;
    }
}

.animate-pulse {
    animation: pulse-soft 2s cubic-bezier(0.4, 0, 0.6, 1) infinite;
}

/* Compact Trade Card (Sidebar Style) */
.compact-trade-card {
    background: rgba(255, 255, 255, 0.02);
    border: 1px solid var(--border-subtle);
    border-radius: var(--radius-sm);
    padding: 12px;
    transition: 0.2s;
    margin-bottom: 0.75rem;
}

.compact-trade-card:hover {
    background: rgba(80, 210, 193, 0.04);
    transform: translateX(2px);
    border-color: rgba(80, 210, 193, 0.25);
}

.compact-row {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 8px;
}

.compact-row:last-child {
    margin-bottom: 0;
}

.compact-label {
    font-size: 0.7rem;
    color: var(--text-secondary);
    text-transform: uppercase;
    letter-spacing: 0.05em;
}

.compact-value {
    font-family: 'JetBrains Mono', monospace;
    font-size: 0.85rem;
}

/* Utility: Hidden */
.hidden {
    display: none !important;
}

/* Utility: Font weight */
.font-bold {
    font-weight: 700;
}

.font-mono {
    font-family: 'JetBrains Mono', monospace;
}

/* Utility: bg-danger-soft for error boxes */
.bg-danger-soft {
    background: rgba(244, 63, 94, 0.08);
}

.border-danger-subtle {
    border-color: rgba(244, 63, 94, 0.25);
}

.rounded {
    border-radius: var(--radius-sm);
}

/* ── Progress bar ───────────────────────────────────── */
.progress-track {
    width: 100%;
    height: 6px;
    background: rgba(255, 255, 255, 0.08);
    border-radius: 999px;
    overflow: hidden;
}

.progress-fill {
    height: 100%;
    border-radius: 999px;
    transition: width 0.4s ease;
}

.bg-success {
    background: var(--success);
}

.bg-danger {
    background: var(--danger);
}

/* ── Badge variants ─────────────────────────────────── */
.badge {
    display: inline-block;
    padding: 0.2rem 0.55rem;
    border-radius: var(--radius-sm);
    font-size: 0.7rem;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.04em;
}

.badge-success {
    background: var(--success-bg);
    color: var(--success);
    border: 1px solid rgba(16, 185, 129, 0.25);
}

.badge-danger {
    background: var(--danger-bg);
    color: var(--danger);
    border: 1px solid rgba(244, 63, 94, 0.25);
}

.badge-soft {
    background: rgba(80, 210, 193, 0.1);
    color: var(--primary);
    border: 1px solid rgba(80, 210, 193, 0.2);
}

/* ── Heatmap ────────────────────────────────────────── */
.session-cell {
    width: 38px;
    min-width: 38px;
    height: 32px;
    border-radius: 4px;
    text-align: center;
    vertical-align: middle;
    transition: opacity 0.2s;
    padding: 0;
}

.session-cell:hover {
    opacity: 0.75;
}

.heatmap-positive {
    background: rgba(16, 185, 129, 0.55);
}

.heatmap-negative {
    background: rgba(244, 63, 94, 0.55);
}

.heatmap-neutral {
    background: rgba(148, 163, 184, 0.08);
}

/* ── Time-range tab active state ────────────────────── */
.btn-primary {
    background: var(--primary) !important;
    color: #fff !important;
    border-color: var(--primary) !important;
}

/* ── Utility sizes ──────────────────────────────────── */
.text-xl {
    font-size: 1.5rem;
}

.mt-2 {
    margin-top: 0.5rem;
}

.mt-8 {
    margin-top: 2rem;
}

/* ── Loading spinner ─────────────────────────────────── */
.spinner {
    width: 24px;
    height: 24px;
    border: 3px solid var(--border, rgba(255,255,255,0.15));
    border-top-color: var(--primary, #50d2c1);
    border-radius: 50%;
    animation: spin 0.8s linear infinite;
    flex-shrink: 0;
}

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

.spinner-wrap {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 0.75rem;
    padding: 1.5rem;
}

/* ── Empty state ─────────────────────────────────────── */
.empty-state {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    padding: 3rem 1rem;
    text-align: center;
    color: var(--text-muted, #94a3b8);
    gap: 0.75rem;
}

.empty-state svg {
    opacity: 0.35;
}

/* ── Liquidation distance legend ─────────────────────── */
.liq-legend {
    display: flex;
    gap: 1rem;
    flex-wrap: wrap;
    font-size: 0.75rem;
    color: var(--text-muted, #94a3b8);
    margin-bottom: 0.5rem;
}

/* ── Inline badge for ws-status ─────────────────────── */
.badge-danger {
    background: rgba(244, 63, 94, 0.15) !important;
    color: #f43f5e !important;
    border: 1px solid rgba(244, 63, 94, 0.3) !important;
}

/* ── Mobile: touch targets ───────────────────────────── */
.btn {
    min-height: 44px;
}
.nav-item {
    min-height: 44px;
}

/* ── Mobile: stat-value scaling for tablets ──────────── */
@media (max-width: 768px) {
    .stat-value {
        font-size: 1.35rem;
    }
}

/* ── text-3xl utility — responsive ──────────────────── */
.text-3xl {
    font-size: 3rem;
}
@media (max-width: 640px) {
    .text-3xl {
        font-size: 1.75rem !important;
    }
}

/* ── Filter bar: wraps cleanly on any screen width ───── */
.filter-bar {
    display: flex;
    flex-wrap: wrap;
    gap: 0.5rem;
    align-items: center;
}
.filter-bar select,
.filter-bar input[type="number"] {
    flex: 1 1 auto;
    min-width: 0;
    width: auto;
}
@media (max-width: 640px) {
    .filter-bar select,
    .filter-bar input[type="number"] {
        flex: 1 1 calc(50% - 0.25rem);
    }
}

/* ════════════════════════════════════════════════════════════════════════
   DASHBOARD REDESIGN COMPONENTS  (shared by every page — reuses :root tokens)
   ════════════════════════════════════════════════════════════════════════ */

/* ── Safe-area / notch support for installed PWA ──────────────────────── */
.sidebar {
    padding-top: calc(1.5rem + env(safe-area-inset-top, 0px));
    padding-bottom: calc(1.5rem + env(safe-area-inset-bottom, 0px));
}

/* ── Sidebar nav groups ──────────────────────────────────────────────── */
.nav-group {
    margin-top: 1.25rem;
}
.nav-group:first-of-type {
    margin-top: 0;
}
.nav-group-label {
    font-size: 0.68rem;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.09em;
    color: var(--text-tertiary);
    padding: 0 1rem;
    margin-bottom: 0.4rem;
}
.nav-item svg {
    flex-shrink: 0;
}
.nav-item.active svg {
    color: #fff;
}

/* ── Page header (title + subtitle + actions) ────────────────────────── */
.page-header {
    display: flex;
    flex-wrap: wrap;
    align-items: flex-end;
    justify-content: space-between;
    gap: 1rem;
    margin-bottom: 1.75rem;
}
.page-heading {
    min-width: 0;
}
.page-title {
    font-family: var(--font-heading);
    font-weight: 700;
    font-size: clamp(1.5rem, 3.5vw, 2rem);
    line-height: 1.15;
    letter-spacing: -0.02em;
    margin: 0;
    display: flex;
    align-items: center;
    gap: 0.6rem;
}
.page-subtitle {
    color: var(--text-secondary);
    font-size: 0.92rem;
    margin-top: 0.35rem;
}
.page-actions {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: 0.6rem;
}

/* ── KPI grid (intrinsically responsive — no breakpoints needed) ─────── */
.kpi-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(165px, 1fr));
    gap: 1rem;
    margin-bottom: 1.75rem;
}
.kpi-card {
    background: var(--bg-card);
    border: 1px solid var(--border-subtle);
    border-radius: var(--radius-md);
    padding: 1.1rem 1.25rem;
    display: flex;
    flex-direction: column;
    gap: 0.35rem;
    min-width: 0;
    transition: border-color 0.2s, transform 0.2s;
}
.kpi-card:hover {
    border-color: rgba(80, 210, 193, 0.35);
    transform: translateY(-2px);
}
.kpi-top {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 0.5rem;
}
.kpi-label {
    font-size: 0.72rem;
    text-transform: uppercase;
    letter-spacing: 0.06em;
    color: var(--text-tertiary);
    font-weight: 600;
}
.kpi-ico {
    width: 30px;
    height: 30px;
    border-radius: 8px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    background: rgba(80, 210, 193, 0.1);
    color: var(--primary);
    flex-shrink: 0;
}
.kpi-value {
    font-family: var(--font-heading);
    font-weight: 700;
    font-size: clamp(1.25rem, 2.6vw, 1.6rem);
    letter-spacing: -0.02em;
    line-height: 1.1;
    word-break: break-word;
}
.kpi-sub {
    font-size: 0.78rem;
    color: var(--text-tertiary);
}
.tone-up { color: var(--success); }
.tone-down { color: var(--danger); }
.tone-muted { color: var(--text-tertiary); }

/* ── Panel (the standard section container) ──────────────────────────── */
.panel {
    background: var(--bg-card);
    border: 1px solid var(--border-subtle);
    border-radius: var(--radius-lg);
    margin-bottom: 1.5rem;
    overflow: hidden;
}
.panel-header {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    justify-content: space-between;
    gap: 0.75rem;
    padding: 1.1rem 1.35rem;
    border-bottom: 1px solid var(--border-subtle);
}
.panel-title {
    font-family: var(--font-heading);
    font-weight: 600;
    font-size: 1.02rem;
    margin: 0;
    display: flex;
    align-items: center;
    gap: 0.55rem;
}
.panel-actions {
    display: flex;
    flex-wrap: wrap;
    gap: 0.5rem;
    align-items: center;
}
.panel-body {
    padding: 1.35rem;
}
.panel-body.flush { padding: 0; }

/* A plain content grid for arranging panels side by side */
.panel-grid {
    display: grid;
    grid-template-columns: 1fr;
    gap: 1.5rem;
    margin-bottom: 1.5rem;
}
@media (min-width: 1024px) {
    .panel-grid.cols-2 { grid-template-columns: 1fr 1fr; }
    .panel-grid.cols-3 { grid-template-columns: 1fr 1fr 1fr; }
    .panel-grid.sidebar-left { grid-template-columns: 380px 1fr; }
    .panel-grid.sidebar-right { grid-template-columns: 1fr 380px; }
    .panel-grid > .panel { margin-bottom: 0; }
}

/* ── Segmented control (time-range tabs, view toggles) ───────────────── */
.seg {
    display: inline-flex;
    background: rgba(5, 21, 21, 0.6);
    border: 1px solid var(--border-subtle);
    border-radius: 10px;
    padding: 3px;
    gap: 2px;
    flex-wrap: wrap;
}
.seg-item {
    appearance: none;
    background: none;
    border: none;
    color: var(--text-secondary);
    font-size: 0.82rem;
    font-weight: 600;
    padding: 0.45rem 0.85rem;
    border-radius: 7px;
    cursor: pointer;
    text-decoration: none;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    min-height: 36px;
    transition: 0.15s;
}
.seg-item:hover {
    color: var(--text-primary);
}
.seg-item.active {
    background: var(--gradient-brand);
    color: #0a0a0a;
    box-shadow: 0 2px 8px rgba(80, 210, 193, 0.3);
}

/* ── Chart wrapper (keeps charts inside their box on every screen) ───── */
.chart-wrap {
    position: relative;
    width: 100%;
    height: 320px;
}
.chart-wrap.sm { height: 240px; }
.chart-wrap.lg { height: 380px; }
.chart-wrap canvas {
    max-width: 100% !important;
}
@media (max-width: 640px) {
    .chart-wrap { height: 260px; }
    .chart-wrap.lg { height: 300px; }
}

/* ── Responsive table → cards helpers ────────────────────────────────── */
/* !important so these win over component display rules like .dcards{display:flex}
   regardless of source order. */
.show-desktop { display: none !important; }
.show-mobile { display: block; }
@media (min-width: 820px) {
    .show-desktop { display: block !important; }
    .show-mobile { display: none !important; }
}

/* Stacked data cards used as the mobile fallback for any table */
.dcards {
    display: flex;
    flex-direction: column;
    gap: 0.75rem;
}
.dcard {
    background: rgba(255, 255, 255, 0.02);
    border: 1px solid var(--border-subtle);
    border-radius: var(--radius-md);
    padding: 0.9rem 1rem;
}
.dcard-head {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 0.5rem;
    margin-bottom: 0.6rem;
    padding-bottom: 0.6rem;
    border-bottom: 1px solid var(--border-subtle);
}
.dcard-row {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 0.75rem;
    padding: 0.2rem 0;
    font-size: 0.85rem;
}
.dcard-row .k {
    color: var(--text-tertiary);
    font-size: 0.72rem;
    text-transform: uppercase;
    letter-spacing: 0.05em;
}
.dcard-row .v {
    font-family: 'JetBrains Mono', monospace;
    text-align: right;
}

/* ── Body scroll-lock when the mobile drawer is open ─────────────────── */
body.nav-open {
    overflow: hidden;
}

/* ── Mobile refinements (≤640px) ─────────────────────────────────────── */
@media (max-width: 640px) {
    /* Stop iOS auto-zoom on focus by keeping inputs ≥16px */
    .form-input,
    input[type="text"],
    input[type="number"],
    input[type="date"],
    input[type="search"],
    select,
    textarea {
        font-size: 16px;
    }
    .page-header {
        align-items: flex-start;
    }
    .page-actions {
        width: 100%;
    }
    .panel-body {
        padding: 1rem;
    }
    .seg {
        width: 100%;
        justify-content: stretch;
    }
    .seg-item {
        flex: 1 1 auto;
    }
}

/* Account for notch on the fixed mobile top bar + drawer */
@media (max-width: 1024px) {
    #mobile-toggle {
        padding-top: calc(0.75rem + env(safe-area-inset-top, 0px));
    }
    .main-content {
        padding-top: calc(4.5rem + env(safe-area-inset-top, 0px));
    }
}