/* ============================================
   QUATARLY DASHBOARD — DESIGN SYSTEM & STYLES
   ============================================ */

/* ----- CSS Custom Properties ----- */
:root {
    /* Surfaces */
    --bg-primary: #0a0a0b;
    --bg-secondary: #111113;
    --bg-card: #141416;
    --bg-card-hover: #1a1a1e;
    --bg-elevated: #1c1c20;
    --bg-input: #0e0e10;

    /* Borders */
    --border-subtle: rgba(255, 255, 255, 0.06);
    --border-default: rgba(255, 255, 255, 0.08);
    --border-strong: rgba(255, 255, 255, 0.12);
    --border-accent: rgba(255, 165, 0, 0.25);

    /* Text */
    --text-primary: #e8e8ed;
    --text-secondary: #8e8e93;
    --text-tertiary: #636366;
    --text-accent: #f5a623;

    /* Accents */
    --accent-primary: #f5a623;
    --accent-primary-dim: rgba(245, 166, 35, 0.15);
    --accent-green: #34c759;
    --accent-green-dim: rgba(52, 199, 89, 0.15);
    --accent-red: #ff453a;
    --accent-red-dim: rgba(255, 69, 58, 0.15);
    --accent-blue: #0a84ff;
    --accent-blue-dim: rgba(10, 132, 255, 0.12);
    --accent-purple: #bf5af2;
    --accent-cyan: #64d2ff;
    --accent-orange: #ff9f0a;

    /* Chart colors */
    --color-input: #0a84ff;
    --color-output: #34c759;
    --color-cached: #ff9f0a;
    --color-reasoning: #bf5af2;

    /* Layout */
    --radius-sm: 8px;
    --radius-md: 12px;
    --radius-lg: 16px;
    --radius-xl: 20px;

    /* Shadows */
    --shadow-card: 0 1px 3px rgba(0,0,0,0.3), 0 0 0 1px var(--border-subtle);
    --shadow-card-hover: 0 4px 12px rgba(0,0,0,0.4), 0 0 0 1px var(--border-default);
    --shadow-glow-amber: 0 0 40px rgba(245, 166, 35, 0.08);

    /* Transitions */
    --transition-fast: 150ms ease;
    --transition-default: 250ms ease;
    --transition-smooth: 350ms cubic-bezier(0.4, 0, 0.2, 1);
}

/* ----- Reset & Base ----- */
*, *::before, *::after {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

html {
    font-size: 14px;
    scroll-behavior: smooth;
    color-scheme: dark;
}

body {
    font-family: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
    background: var(--bg-primary);
    color: var(--text-primary);
    line-height: 1.5;
    min-height: 100vh;
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
    overflow-x: hidden;
}

/* ----- Screens ----- */
.screen {
    display: none;
}
.screen.active {
    display: block;
}

/* ============================================
   LOGIN SCREEN
   ============================================ */
#login-screen {
    display: none;
    justify-content: center;
    align-items: center;
    min-height: 100vh;
    position: relative;
    overflow: hidden;
}
#login-screen.active {
    display: flex;
}

.login-bg-glow {
    position: absolute;
    top: 30%;
    left: 50%;
    width: 600px;
    height: 600px;
    transform: translate(-50%, -50%);
    background: radial-gradient(circle, rgba(245,166,35,0.06) 0%, transparent 70%);
    pointer-events: none;
    animation: pulse-glow 4s ease-in-out infinite;
}

@keyframes pulse-glow {
    0%, 100% { opacity: 0.5; transform: translate(-50%, -50%) scale(1); }
    50% { opacity: 1; transform: translate(-50%, -50%) scale(1.1); }
}

.login-container {
    width: 100%;
    max-width: 420px;
    padding: 48px 36px;
    background: var(--bg-card);
    border: 1px solid var(--border-default);
    border-radius: var(--radius-xl);
    box-shadow: var(--shadow-card), var(--shadow-glow-amber);
    text-align: center;
    position: relative;
    z-index: 1;
    animation: slide-up 0.6s var(--transition-smooth);
}

@keyframes slide-up {
    from { opacity: 0; transform: translateY(30px); }
    to { opacity: 1; transform: translateY(0); }
}

.login-icon {
    width: 64px;
    height: 64px;
    margin: 0 auto 20px;
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: var(--radius-lg);
    background: var(--accent-primary-dim);
    color: var(--accent-primary);
    border: 1px solid rgba(245,166,35,0.15);
}

.login-title {
    font-size: 1.6rem;
    font-weight: 700;
    margin-bottom: 32px;
    color: var(--text-primary);
    letter-spacing: -0.02em;
}

.login-form {
    text-align: left;
}

.login-label {
    display: block;
    font-size: 0.8rem;
    font-weight: 600;
    color: var(--text-secondary);
    text-transform: uppercase;
    letter-spacing: 0.06em;
    margin-bottom: 8px;
}

.login-input {
    width: 100%;
    padding: 14px 16px;
    background: var(--bg-input);
    border: 1px solid var(--border-default);
    border-radius: var(--radius-md);
    color: var(--text-primary);
    font-family: 'JetBrains Mono', monospace;
    font-size: 0.95rem;
    transition: border-color var(--transition-fast), box-shadow var(--transition-fast);
    outline: none;
}

.login-input:focus {
    border-color: var(--accent-primary);
    box-shadow: 0 0 0 3px var(--accent-primary-dim);
}

.login-input::placeholder {
    color: var(--text-tertiary);
}

.login-error {
    min-height: 28px;
    padding-top: 8px;
    font-size: 0.82rem;
    color: var(--accent-red);
    font-weight: 500;
}

.login-btn {
    width: 100%;
    padding: 14px;
    border: none;
    border-radius: var(--radius-md);
    background: linear-gradient(135deg, var(--accent-primary) 0%, #e8940a 100%);
    color: #0a0a0b;
    font-family: 'Inter', sans-serif;
    font-size: 0.95rem;
    font-weight: 700;
    cursor: pointer;
    transition: opacity var(--transition-fast), transform var(--transition-fast);
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
}

.login-btn:hover {
    opacity: 0.92;
    transform: translateY(-1px);
}

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

.login-btn:disabled {
    opacity: 0.6;
    cursor: not-allowed;
    transform: none;
}

.spinner {
    width: 20px;
    height: 20px;
    animation: spin 0.8s linear infinite;
}

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

/* ============================================
   DASHBOARD SCREEN
   ============================================ */
#dashboard-screen {
    padding: 24px;
    max-width: 1200px;
    margin: 0 auto;
    animation: fade-in 0.4s ease;
}

@keyframes fade-in {
    from { opacity: 0; }
    to { opacity: 1; }
}

/* ----- Header ----- */
.dash-header {
    display: grid;
    grid-template-columns: 1fr auto auto;
    align-items: center;
    gap: 20px;
    margin-bottom: 8px;
}

.dash-header-label {
    font-size: 0.7rem;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.1em;
    color: var(--text-tertiary);
}

.dash-header-title {
    font-size: 1.35rem;
    font-weight: 700;
    letter-spacing: -0.01em;
    color: var(--text-primary);
    margin-top: 4px;
}

.dash-header-sub {
    font-size: 0.8rem;
    color: var(--text-tertiary);
    margin-top: 2px;
    font-family: 'JetBrains Mono', monospace;
}

.dash-header-actions {
    display: flex;
    align-items: center;
    gap: 8px;
}

.time-filters {
    display: flex;
    background: var(--bg-card);
    border-radius: var(--radius-sm);
    border: 1px solid var(--border-subtle);
    overflow: hidden;
}

.tf-btn {
    padding: 8px 14px;
    border: none;
    background: transparent;
    color: var(--text-secondary);
    font-family: 'Inter', sans-serif;
    font-size: 0.75rem;
    font-weight: 500;
    cursor: pointer;
    transition: all var(--transition-fast);
    white-space: nowrap;
}

.tf-btn:hover {
    color: var(--text-primary);
    background: var(--bg-elevated);
}

.tf-btn.active {
    background: var(--accent-primary);
    color: #0a0a0b;
    font-weight: 600;
}

.icon-btn {
    width: 38px;
    height: 38px;
    border: 1px solid var(--border-subtle);
    border-radius: var(--radius-sm);
    background: var(--bg-card);
    color: var(--text-secondary);
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    transition: all var(--transition-fast);
}

.icon-btn:hover {
    color: var(--text-primary);
    background: var(--bg-elevated);
    border-color: var(--border-default);
}

.icon-btn.spinning svg {
    animation: spin 0.6s linear;
}

.logout-btn:hover {
    color: var(--accent-red);
    border-color: rgba(255,69,58,0.3);
}

.dash-updated {
    font-size: 0.72rem;
    color: var(--text-tertiary);
    margin-bottom: 20px;
}

/* ----- Stats Row ----- */
.stats-row {
    display: grid;
    grid-template-columns: minmax(0, 1fr) minmax(0, 1fr);
    gap: 16px;
    margin-bottom: 16px;
}

.stat-card {
    background: var(--bg-card);
    border: 1px solid var(--border-subtle);
    border-radius: var(--radius-md);
    padding: 20px;
    position: relative;
    overflow: hidden;
    min-width: 0;
    transition: border-color var(--transition-fast), box-shadow var(--transition-fast);
}

.stat-card:hover {
    border-color: var(--border-default);
    box-shadow: var(--shadow-card-hover);
}

.stat-card.accent-blue {
    border-color: rgba(10, 132, 255, 0.12);
}

.stat-card.accent-blue:hover {
    border-color: rgba(10, 132, 255, 0.25);
}

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

.stat-label {
    font-size: 0.7rem;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.08em;
    color: var(--text-tertiary);
}

.stat-copy-btn {
    width: 28px;
    height: 28px;
    border: none;
    border-radius: 6px;
    background: transparent;
    color: var(--text-tertiary);
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    opacity: 0;
    transition: opacity var(--transition-fast), background var(--transition-fast);
}

.stat-card:hover .stat-copy-btn {
    opacity: 1;
}

.stat-copy-btn:hover {
    background: var(--bg-elevated);
    color: var(--text-secondary);
}

.stat-value {
    font-size: 2rem;
    font-weight: 800;
    letter-spacing: -0.03em;
    color: var(--text-primary);
    line-height: 1.2;
}

.stat-breakdown {
    display: flex;
    gap: 12px;
    margin-top: 6px;
    font-size: 0.78rem;
    color: var(--text-secondary);
}

.stat-success {
    color: var(--accent-green);
}

.stat-failure {
    color: var(--accent-red);
}

.sparkline {
    width: 100%;
    height: 40px;
    margin-top: 12px;
    display: block;
    max-height: 40px;
}

/* ----- Cost Card ----- */
.cost-card {
    margin-bottom: 16px;
}

.cost-value {
    font-size: 2.4rem;
    background: linear-gradient(135deg, var(--accent-primary), #ffcc00);
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    background-clip: text;
}

.cost-bar-container {
    height: 6px;
    background: var(--bg-elevated);
    border-radius: 3px;
    margin-top: 12px;
    overflow: hidden;
}

.cost-bar {
    height: 100%;
    background: linear-gradient(90deg, var(--accent-primary), #ffcc00);
    border-radius: 3px;
    transition: width 1s var(--transition-smooth);
    width: 0%;
}

/* ----- Credits Section ----- */
.credits-section {
    background: var(--bg-card);
    border: 1px solid var(--border-subtle);
    border-radius: var(--radius-md);
    padding: 24px;
    margin-bottom: 16px;
}

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

.section-title {
    font-size: 0.8rem;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.08em;
    color: var(--text-secondary);
}

.credits-grid {
    display: grid;
    grid-template-columns: repeat(4, 1fr);
    gap: 12px;
    margin-bottom: 20px;
}

.credit-item {
    background: var(--bg-elevated);
    border-radius: var(--radius-sm);
    padding: 14px 16px;
    border: 1px solid var(--border-subtle);
}

.credit-item.highlight {
    border-color: var(--accent-primary);
    background: var(--accent-primary-dim);
}

.credit-label {
    display: block;
    font-size: 0.68rem;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.08em;
    color: var(--text-tertiary);
    margin-bottom: 6px;
}

.credit-value {
    display: block;
    font-size: 1.15rem;
    font-weight: 700;
    color: var(--text-primary);
    font-family: 'JetBrains Mono', monospace;
}

.credit-item.highlight .credit-value {
    color: var(--accent-primary);
}

.credits-bar-container {
    height: 8px;
    background: var(--bg-elevated);
    border-radius: 4px;
    display: flex;
    overflow: hidden;
    margin-bottom: 8px;
}

.credits-bar-used {
    height: 100%;
    background: linear-gradient(90deg, var(--accent-red), var(--accent-orange));
    transition: width 1s var(--transition-smooth);
}

.credits-bar-remaining {
    height: 100%;
    background: var(--accent-green);
    transition: width 1s var(--transition-smooth);
}

.credits-bar-legend {
    display: flex;
    justify-content: flex-end;
    gap: 4px;
    font-size: 0.75rem;
    color: var(--text-tertiary);
    font-family: 'JetBrains Mono', monospace;
}

/* Model Weights Tags */
.model-weights {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
    margin-top: 20px;
    padding-top: 20px;
    border-top: 1px solid var(--border-subtle);
}

.mw-tag {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    padding: 6px 12px;
    background: var(--bg-elevated);
    border: 1px solid var(--border-subtle);
    border-radius: 20px;
    font-size: 0.72rem;
    font-weight: 500;
    color: var(--text-secondary);
    font-family: 'JetBrains Mono', monospace;
    transition: all var(--transition-fast);
    cursor: default;
}

.mw-tag:hover {
    border-color: var(--border-strong);
    background: var(--bg-card-hover);
    color: var(--text-primary);
}

.mw-tag-weight {
    color: var(--accent-primary);
    font-weight: 600;
}

/* ----- Charts ----- */
.charts-row {
    display: grid;
    grid-template-columns: minmax(0, 1fr) minmax(0, 1fr);
    gap: 16px;
    margin-bottom: 16px;
    overflow: hidden;
}

.chart-card {
    background: var(--bg-card);
    border: 1px solid var(--border-subtle);
    border-radius: var(--radius-md);
    padding: 20px;
    transition: border-color var(--transition-fast);
    overflow: hidden;
    min-width: 0;
}

.chart-card:hover {
    border-color: var(--border-default);
}

.chart-card.full-width {
    margin-bottom: 16px;
}

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

.chart-toggle {
    display: flex;
    background: var(--bg-elevated);
    border-radius: 6px;
    overflow: hidden;
    border: 1px solid var(--border-subtle);
    flex-shrink: 0;
}

.ct-btn {
    padding: 6px 14px;
    border: none;
    background: transparent;
    color: var(--text-tertiary);
    font-family: 'Inter', sans-serif;
    font-size: 0.72rem;
    font-weight: 500;
    cursor: pointer;
    transition: all var(--transition-fast);
}

.ct-btn:hover {
    color: var(--text-secondary);
}

.ct-btn.active {
    background: var(--accent-primary);
    color: #0a0a0b;
    font-weight: 600;
}

.chart-legend {
    display: flex;
    flex-wrap: wrap;
    gap: 16px;
    margin-bottom: 16px;
    padding-bottom: 12px;
    border-bottom: 1px solid var(--border-subtle);
}

.legend-dot {
    font-size: 0.75rem;
    color: var(--text-secondary);
}

.legend-dot::first-letter {
    color: var(--dot-color);
}

.chart-container {
    height: 220px;
    position: relative;
    width: 100%;
    overflow: hidden;
}

.chart-container canvas {
    width: 100% !important;
    height: 100% !important;
}

.chart-container-tall {
    height: 300px;
}

/* Chart no-data overlay */
.chart-no-data {
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 0.85rem;
    color: var(--text-tertiary);
    font-weight: 500;
    background: var(--bg-card);
    border-radius: var(--radius-sm);
    letter-spacing: 0.02em;
}

/* ----- Model Usage ----- */
.model-usage-section {
    margin-bottom: 16px;
}

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

.model-usage-total {
    font-size: 0.78rem;
    color: var(--text-tertiary);
    font-family: 'JetBrains Mono', monospace;
}

.model-usage-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(280px, 1fr));
    gap: 12px;
}

.mu-card {
    background: var(--bg-card);
    border: 1px solid var(--border-subtle);
    border-radius: var(--radius-md);
    padding: 18px;
    transition: all var(--transition-fast);
    cursor: default;
}

.mu-card:hover {
    border-color: var(--border-default);
    box-shadow: var(--shadow-card-hover);
}

.mu-card-header {
    display: flex;
    justify-content: space-between;
    align-items: flex-start;
    margin-bottom: 12px;
}

.mu-model-name {
    font-size: 0.85rem;
    font-weight: 600;
    color: var(--text-primary);
    font-family: 'JetBrains Mono', monospace;
    word-break: break-all;
}

.mu-req-count {
    font-size: 1.2rem;
    font-weight: 800;
    color: var(--text-primary);
    white-space: nowrap;
    margin-left: 12px;
}

.mu-req-pct {
    font-size: 0.72rem;
    color: var(--text-tertiary);
    font-weight: 500;
}

.mu-details {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 6px;
    font-size: 0.72rem;
}

.mu-detail {
    display: flex;
    justify-content: space-between;
}

.mu-detail-label {
    color: var(--text-tertiary);
    text-transform: uppercase;
    font-weight: 600;
    letter-spacing: 0.04em;
}

.mu-detail-value {
    color: var(--text-secondary);
    font-family: 'JetBrains Mono', monospace;
    font-weight: 500;
}

.mu-bar-container {
    height: 4px;
    background: var(--bg-elevated);
    border-radius: 2px;
    margin-top: 12px;
    overflow: hidden;
}

.mu-bar {
    height: 100%;
    border-radius: 2px;
    transition: width 1s var(--transition-smooth);
}

/* ----- Sub Keys Section ----- */
.subkeys-section {
    margin-bottom: 40px;
}

.subkeys-count {
    font-size: 0.78rem;
    color: var(--text-tertiary);
    font-family: 'JetBrains Mono', monospace;
}

.subkeys-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(300px, 1fr));
    gap: 12px;
}

.sk-card {
    background: var(--bg-card);
    border: 1px solid var(--border-subtle);
    border-radius: var(--radius-md);
    padding: 18px;
    display: flex;
    align-items: center;
    gap: 14px;
    transition: all var(--transition-fast);
}

.sk-card:hover {
    border-color: var(--border-default);
    box-shadow: var(--shadow-card-hover);
}

.sk-status {
    width: 10px;
    height: 10px;
    border-radius: 50%;
    flex-shrink: 0;
}

.sk-status.active {
    background: var(--accent-green);
    box-shadow: 0 0 8px rgba(52,199,89,0.4);
    animation: pulse-dot 2s infinite;
}

.sk-status.inactive {
    background: var(--accent-red);
}

@keyframes pulse-dot {
    0%, 100% { box-shadow: 0 0 4px rgba(52,199,89,0.3); }
    50% { box-shadow: 0 0 12px rgba(52,199,89,0.6); }
}

.sk-info {
    flex: 1;
    min-width: 0;
}

.sk-label {
    font-size: 0.9rem;
    font-weight: 600;
    color: var(--text-primary);
}

.sk-key {
    font-size: 0.72rem;
    font-family: 'JetBrains Mono', monospace;
    color: var(--text-tertiary);
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    margin-top: 2px;
}

.sk-date {
    font-size: 0.7rem;
    color: var(--text-tertiary);
    white-space: nowrap;
}

/* ============================================
   RESPONSIVE
   ============================================ */

/* ============================================
   RESPONSIVE — TABLETS (≤ 768px)
   ============================================ */
@media (max-width: 768px) {
    html {
        font-size: 13px;
    }

    #dashboard-screen {
        padding: 14px;
    }

    .dash-header {
        grid-template-columns: 1fr auto;
        gap: 12px;
    }

    .dash-header-left {
        grid-column: 1;
    }

    .dash-header-actions {
        grid-column: 2;
        justify-self: end;
    }

    .time-filters {
        grid-column: 1 / 3;
        width: 100%;
    }

    /* Horizontal scroll for time filters on tablet/phone */
    .time-filters {
        overflow-x: auto;
        -webkit-overflow-scrolling: touch;
        scrollbar-width: none;
        flex-wrap: nowrap;
        max-width: 100%;
    }
    .time-filters::-webkit-scrollbar {
        display: none;
    }

    .stats-row {
        grid-template-columns: 1fr;
    }

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

    .charts-row {
        grid-template-columns: 1fr;
    }

    .chart-container {
        height: 180px;
    }

    .chart-container-tall {
        height: 220px;
    }

    .model-usage-grid {
        grid-template-columns: 1fr;
    }

    .subkeys-grid {
        grid-template-columns: 1fr;
    }

    .chart-header {
        flex-direction: row;
        align-items: center;
    }
}

/* ============================================
   RESPONSIVE — PHONES (≤ 480px)
   ============================================ */
@media (max-width: 480px) {
    html {
        font-size: 12.5px;
    }

    #dashboard-screen {
        padding: 12px;
        /* Safe area for phones with notches */
        padding-bottom: calc(12px + env(safe-area-inset-bottom, 0px));
    }

    .login-container {
        margin: 12px;
        padding: 28px 20px;
        border-radius: var(--radius-lg);
    }

    .login-title {
        font-size: 1.4rem;
        margin-bottom: 24px;
    }

    .login-icon {
        width: 52px;
        height: 52px;
    }

    .login-input {
        padding: 12px 14px;
        font-size: 0.9rem;
    }

    .login-btn {
        padding: 12px;
    }

    /* Header compact */
    .dash-header-title {
        font-size: 1.15rem;
    }

    /* Time filter pills — scrollable row */
    .tf-btn {
        padding: 7px 12px;
        font-size: 0.7rem;
        flex-shrink: 0;
    }

    .icon-btn {
        width: 34px;
        height: 34px;
    }

    /* Stat cards */
    .stat-card {
        padding: 16px;
    }

    .stat-value {
        font-size: 1.6rem;
    }

    .stat-breakdown {
        font-size: 0.72rem;
        gap: 8px;
    }

    .sparkline {
        height: 32px;
        max-height: 32px;
        margin-top: 8px;
    }

    /* Cost */
    .cost-value {
        font-size: 1.8rem;
    }

    /* Credits */
    .credits-section {
        padding: 16px;
    }

    .credits-grid {
        grid-template-columns: 1fr 1fr;
        gap: 8px;
    }

    .credit-item {
        padding: 10px 12px;
    }

    .credit-value {
        font-size: 1rem;
    }

    /* Model weight tags — smaller, tighter */
    .model-weights {
        gap: 6px;
        margin-top: 14px;
        padding-top: 14px;
    }

    .mw-tag {
        padding: 4px 8px;
        font-size: 0.65rem;
        gap: 4px;
    }

    /* Charts smaller on phone */
    .chart-card {
        padding: 14px;
    }

    .chart-container {
        height: 160px;
    }

    .chart-container-tall {
        height: 200px;
    }

    .chart-toggle {
        border-radius: 5px;
    }

    .ct-btn {
        padding: 5px 10px;
        font-size: 0.68rem;
    }

    .chart-legend {
        gap: 10px;
        font-size: 0.68rem;
    }

    /* Model usage cards */
    .mu-card {
        padding: 14px;
    }

    .mu-model-name {
        font-size: 0.78rem;
    }

    .mu-req-count {
        font-size: 1rem;
    }

    /* Sub keys */
    .sk-card {
        padding: 14px;
        gap: 10px;
    }

    .section-title {
        font-size: 0.72rem;
    }
}

/* ============================================
   RESPONSIVE — VERY SMALL PHONES (≤ 360px)
   ============================================ */
@media (max-width: 360px) {
    html {
        font-size: 12px;
    }

    #dashboard-screen {
        padding: 8px;
    }

    .login-container {
        margin: 8px;
        padding: 24px 16px;
    }

    .stat-value {
        font-size: 1.4rem;
    }

    .cost-value {
        font-size: 1.5rem;
    }

    .credits-grid {
        grid-template-columns: 1fr;
    }

    .credit-value {
        font-size: 0.9rem;
    }

    .chart-container {
        height: 140px;
    }

    .chart-container-tall {
        height: 170px;
    }

    .mw-tag {
        font-size: 0.6rem;
        padding: 3px 6px;
    }
}

/* ----- Scrollbar ----- */
::-webkit-scrollbar {
    width: 8px;
}
::-webkit-scrollbar-track {
    background: var(--bg-primary);
}
::-webkit-scrollbar-thumb {
    background: var(--bg-elevated);
    border-radius: 4px;
}
::-webkit-scrollbar-thumb:hover {
    background: var(--text-tertiary);
}

/* ----- Selection ----- */
::selection {
    background: var(--accent-primary-dim);
    color: var(--accent-primary);
}

/* Loading shimmer for cards */
.shimmer {
    position: relative;
    overflow: hidden;
}

.shimmer::after {
    content: '';
    position: absolute;
    top: 0; left: -100%; right: 0; bottom: 0;
    width: 200%;
    background: linear-gradient(90deg, transparent, rgba(255,255,255,0.03), transparent);
    animation: shimmer 2s infinite;
}

@keyframes shimmer {
    0% { transform: translateX(-50%); }
    100% { transform: translateX(50%); }
}

/* ============================================
   SKELETON LOADERS
   ============================================ */

/* Shimmer Keyframes */
@keyframes skeleton-shimmer {
    0% {
        background-position: 200% 0;
    }
    100% {
        background-position: -200% 0;
    }
}

/* Stat card loading state */
.stat-card.loading .stat-value {
    position: relative;
    color: transparent !important;
    pointer-events: none;
    user-select: none;
    border-radius: var(--radius-sm);
    height: 38px;
    margin-bottom: 8px;
    background: linear-gradient(90deg, var(--bg-elevated) 25%, var(--bg-card-hover) 50%, var(--bg-elevated) 75%);
    background-size: 200% 100%;
    animation: skeleton-shimmer 1.5s infinite linear;
    width: 140px;
}

.stat-card.loading .stat-breakdown {
    position: relative;
    color: transparent !important;
    pointer-events: none;
    user-select: none;
    border-radius: 4px;
    height: 16px;
    background: linear-gradient(90deg, var(--bg-elevated) 25%, var(--bg-card-hover) 50%, var(--bg-elevated) 75%);
    background-size: 200% 100%;
    animation: skeleton-shimmer 1.5s infinite linear;
    width: 180px;
}

.stat-card.loading .sparkline {
    position: relative;
    pointer-events: none;
    border-radius: var(--radius-sm);
    background: linear-gradient(90deg, var(--bg-elevated) 25%, var(--bg-card-hover) 50%, var(--bg-elevated) 75%);
    background-size: 200% 100%;
    animation: skeleton-shimmer 1.5s infinite linear;
    height: 40px;
    opacity: 0.7;
}

.stat-card.loading .stat-copy-btn {
    display: none !important;
}

/* Chart card loading state */
.chart-card.loading .chart-container {
    position: relative;
    pointer-events: none;
    border-radius: var(--radius-md);
    background: linear-gradient(90deg, var(--bg-elevated) 25%, var(--bg-card-hover) 50%, var(--bg-elevated) 75%);
    background-size: 200% 100%;
    animation: skeleton-shimmer 1.5s infinite linear;
}

.chart-card.loading canvas {
    opacity: 0 !important;
    pointer-events: none;
}

.chart-card.loading .chart-toggle,
.chart-card.loading .chart-legend {
    opacity: 0.4;
    pointer-events: none;
}

/* Skeleton Model Cards */
.mu-card.loading-skeleton-card {
    pointer-events: none;
    border-color: var(--border-subtle);
}

.skeleton-line {
    border-radius: 4px;
    background: linear-gradient(90deg, var(--bg-elevated) 25%, var(--bg-card-hover) 50%, var(--bg-elevated) 75%);
    background-size: 200% 100%;
    animation: skeleton-shimmer 1.5s infinite linear;
}

.skeleton-title-line {
    height: 18px;
    width: 60%;
    margin-bottom: 16px;
}

.skeleton-details {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 12px;
    margin-bottom: 16px;
}

.skeleton-detail-line {
    height: 12px;
    border-radius: 3px;
    background: linear-gradient(90deg, var(--bg-elevated) 25%, var(--bg-card-hover) 50%, var(--bg-elevated) 75%);
    background-size: 200% 100%;
    animation: skeleton-shimmer 1.5s infinite linear;
}

.skeleton-bar-line {
    height: 6px;
    width: 100%;
    border-radius: 3px;
}
