/* ============================================================
   SnowCharts — Design System
   Aesthetic: Industrial-precision meets arctic clarity
   ============================================================ */

/* ── CSS Variables (Light Theme) ──────────────────────────── */
:root {
    /* Surface */
    --bg-root: #F4F5F7;
    --bg-surface: #FFFFFF;
    --bg-elevated: #FFFFFF;
    --bg-sidebar: #0F1419;
    --bg-hover: rgba(0, 0, 0, 0.04);
    --bg-active: rgba(59, 130, 246, 0.08);

    /* Text */
    --text-primary: #111827;
    --text-secondary: #6B7280;
    --text-tertiary: #9CA3AF;
    --text-inverse: #F9FAFB;
    --text-sidebar: #D1D5DB;
    --text-sidebar-active: #FFFFFF;

    /* Accent */
    --accent: #2563EB;
    --accent-hover: #1D4ED8;
    --accent-soft: rgba(37, 99, 235, 0.1);
    --accent-glow: rgba(37, 99, 235, 0.25);

    /* Semantic */
    --success: #059669;
    --warning: #D97706;
    --danger: #DC2626;
    --info: #0891B2;

    /* Border */
    --border: #E5E7EB;
    --border-strong: #D1D5DB;

    /* Shadows */
    --shadow-sm: 0 1px 2px rgba(0, 0, 0, 0.05);
    --shadow-md: 0 4px 12px rgba(0, 0, 0, 0.07);
    --shadow-lg: 0 12px 40px rgba(0, 0, 0, 0.1);
    --shadow-card: 0 1px 3px rgba(0, 0, 0, 0.04), 0 1px 2px rgba(0, 0, 0, 0.06);

    /* Layout */
    --sidebar-width: 260px;
    --topbar-height: 60px;
    --radius: 10px;
    --radius-sm: 6px;

    /* Typography */
    --font-sans: 'DM Sans', -apple-system, BlinkMacSystemFont, sans-serif;
    --font-mono: 'JetBrains Mono', 'Fira Code', monospace;

    /* Transitions */
    --transition: 200ms cubic-bezier(0.4, 0, 0.2, 1);
    --transition-slow: 400ms cubic-bezier(0.4, 0, 0.2, 1);
}

/* ── Dark Theme ───────────────────────────────────────────── */
[data-theme="dark"] {
    --bg-root: #0B0E14;
    --bg-surface: #151922;
    --bg-elevated: #1C2130;
    --bg-sidebar: #0B0E14;
    --bg-hover: rgba(255, 255, 255, 0.05);
    --bg-active: rgba(96, 165, 250, 0.12);

    --text-primary: #E5E7EB;
    --text-secondary: #9CA3AF;
    --text-tertiary: #6B7280;
    --text-inverse: #111827;
    --text-sidebar: #9CA3AF;
    --text-sidebar-active: #FFFFFF;

    --accent: #60A5FA;
    --accent-hover: #93BBFD;
    --accent-soft: rgba(96, 165, 250, 0.15);
    --accent-glow: rgba(96, 165, 250, 0.3);

    --border: #1F2937;
    --border-strong: #374151;

    --shadow-sm: 0 1px 2px rgba(0, 0, 0, 0.3);
    --shadow-md: 0 4px 12px rgba(0, 0, 0, 0.4);
    --shadow-lg: 0 12px 40px rgba(0, 0, 0, 0.5);
    --shadow-card: 0 1px 3px rgba(0, 0, 0, 0.2), 0 0 0 1px rgba(255, 255, 255, 0.03);
}

/* ── Reset ────────────────────────────────────────────────── */
*, *::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: var(--font-sans);
    background: var(--bg-root);
    color: var(--text-primary);
    display: flex;
    min-height: 100vh;
    overflow-x: hidden;
}

/* ── Sidebar ──────────────────────────────────────────────── */
.sidebar {
    width: var(--sidebar-width);
    min-height: 100vh;
    background: var(--bg-sidebar);
    display: flex;
    flex-direction: column;
    position: fixed;
    left: 0;
    top: 0;
    bottom: 0;
    z-index: 100;
    transition: transform var(--transition-slow);
    border-right: 1px solid rgba(255, 255, 255, 0.06);
}

.sidebar-header {
    padding: 20px 20px 16px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    border-bottom: 1px solid rgba(255, 255, 255, 0.06);
}

.logo {
    display: flex;
    align-items: center;
    gap: 10px;
}

.logo-icon {
    width: 28px;
    height: 28px;
    color: var(--accent);
}

.logo-text {
    font-size: 1.1rem;
    font-weight: 700;
    color: var(--text-inverse);
    letter-spacing: -0.02em;
}

.env-badge {
    font-family: var(--font-mono);
    font-size: 0.65rem;
    font-weight: 600;
    padding: 2px 8px;
    border-radius: 4px;
    background: rgba(5, 150, 105, 0.2);
    color: #34D399;
    letter-spacing: 0.05em;
}

.sidebar-nav {
    flex: 1;
    padding: 16px 0;
    overflow-y: auto;
}

.nav-section-title {
    font-size: 0.7rem;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.08em;
    color: rgba(255, 255, 255, 0.3);
    padding: 0 20px;
    margin-bottom: 8px;
}

.query-list {
    list-style: none;
}

.query-item {
    padding: 10px 20px;
    cursor: pointer;
    font-size: 0.87rem;
    color: var(--text-sidebar);
    transition: all var(--transition);
    display: flex;
    align-items: center;
    gap: 10px;
    border-left: 3px solid transparent;
}

.query-item:hover {
    background: rgba(255, 255, 255, 0.05);
    color: var(--text-sidebar-active);
}

.query-item.active {
    background: rgba(255, 255, 255, 0.08);
    color: var(--text-sidebar-active);
    border-left-color: var(--accent);
}

.query-item .chart-type-badge {
    font-family: var(--font-mono);
    font-size: 0.6rem;
    padding: 1px 5px;
    border-radius: 3px;
    background: rgba(255, 255, 255, 0.08);
    color: rgba(255, 255, 255, 0.4);
    margin-left: auto;
}

.query-item.loading {
    color: var(--text-tertiary);
    font-style: italic;
    cursor: default;
    animation: pulse 1.5s infinite;
}

@keyframes pulse {
    0%, 100% { opacity: 0.5; }
    50% { opacity: 1; }
}

.sidebar-footer {
    padding: 12px 20px;
    border-top: 1px solid rgba(255, 255, 255, 0.06);
    display: flex;
    align-items: center;
    gap: 8px;
}

.connection-status {
    display: flex;
    align-items: center;
    gap: 6px;
    margin-left: auto;
    font-size: 0.75rem;
    color: var(--text-sidebar);
}

.status-dot {
    width: 7px;
    height: 7px;
    border-radius: 50%;
    background: var(--warning);
    transition: background var(--transition);
}

.status-dot.connected { background: var(--success); }
.status-dot.error { background: var(--danger); }

/* ── Main Content ─────────────────────────────────────────── */
.main-content {
    margin-left: var(--sidebar-width);
    flex: 1;
    min-height: 100vh;
    display: flex;
    flex-direction: column;
}

.topbar {
    height: var(--topbar-height);
    padding: 0 28px;
    display: flex;
    align-items: center;
    gap: 16px;
    background: var(--bg-surface);
    border-bottom: 1px solid var(--border);
    position: sticky;
    top: 0;
    z-index: 50;
}

.btn-hamburger {
    display: none;
    background: none;
    border: none;
    color: var(--text-secondary);
    cursor: pointer;
    padding: 4px;
}

.page-title {
    font-size: 1.15rem;
    font-weight: 700;
    letter-spacing: -0.02em;
}

.topbar-actions {
    margin-left: auto;
    display: flex;
    align-items: center;
    gap: 12px;
}

.date-range {
    display: flex;
    align-items: center;
    gap: 8px;
}

.date-input {
    font-family: var(--font-mono);
    font-size: 0.8rem;
    padding: 6px 10px;
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    background: var(--bg-root);
    color: var(--text-primary);
    outline: none;
    transition: border-color var(--transition);
}

.date-input:focus {
    border-color: var(--accent);
    box-shadow: 0 0 0 3px var(--accent-soft);
}

.date-separator {
    color: var(--text-tertiary);
    font-size: 0.85rem;
}

/* ── Buttons ──────────────────────────────────────────────── */
.btn-primary {
    font-family: var(--font-sans);
    font-size: 0.8rem;
    font-weight: 600;
    padding: 7px 16px;
    border: none;
    border-radius: var(--radius-sm);
    background: var(--accent);
    color: white;
    cursor: pointer;
    transition: all var(--transition);
}

.btn-primary:hover {
    background: var(--accent-hover);
    box-shadow: 0 0 0 3px var(--accent-soft);
}

.btn-icon {
    background: none;
    border: none;
    color: var(--text-sidebar);
    cursor: pointer;
    padding: 6px;
    border-radius: var(--radius-sm);
    transition: all var(--transition);
    display: flex;
    align-items: center;
    justify-content: center;
}

.btn-icon:hover {
    background: rgba(255, 255, 255, 0.1);
    color: var(--text-sidebar-active);
}

.chart-actions .btn-icon {
    color: var(--text-tertiary);
}

.chart-actions .btn-icon:hover {
    background: var(--bg-hover);
    color: var(--text-primary);
}

/* ── KPI Cards ────────────────────────────────────────────── */
.kpi-row {
    display: grid;
    grid-template-columns: repeat(4, 1fr);
    gap: 16px;
    padding: 24px 28px 0;
}

.kpi-card {
    background: var(--bg-surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 20px;
    box-shadow: var(--shadow-card);
    transition: all var(--transition);
}

.kpi-card:hover {
    box-shadow: var(--shadow-md);
    border-color: var(--accent-soft);
}

.kpi-label {
    font-size: 0.75rem;
    font-weight: 500;
    color: var(--text-secondary);
    text-transform: uppercase;
    letter-spacing: 0.04em;
    margin-bottom: 8px;
}

.kpi-value {
    font-size: 1.8rem;
    font-weight: 700;
    color: var(--text-primary);
    letter-spacing: -0.03em;
    font-variant-numeric: tabular-nums;
    line-height: 1.1;
}

.kpi-sub {
    font-size: 0.72rem;
    color: var(--text-tertiary);
    margin-top: 6px;
}

/* ── Charts Grid ──────────────────────────────────────────── */
.charts-grid {
    display: grid;
    grid-template-columns: repeat(2, 1fr);
    gap: 16px;
    padding: 24px 28px 28px;
}

.chart-card {
    background: var(--bg-surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    box-shadow: var(--shadow-card);
    overflow: hidden;
    display: flex;
    flex-direction: column;
    transition: box-shadow var(--transition);
}

.chart-card:hover {
    box-shadow: var(--shadow-md);
}

.chart-card--wide {
    grid-column: span 2;
}

.chart-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 16px 20px 0;
}

.chart-title {
    font-size: 0.9rem;
    font-weight: 600;
    color: var(--text-primary);
}

.chart-actions {
    display: flex;
    gap: 4px;
}

.chart-container {
    width: 100%;
    height: 340px;
    padding: 8px 12px;
}

.chart-card--wide .chart-container {
    height: 380px;
}

.chart-footer {
    padding: 4px 20px 10px;
    display: flex;
    justify-content: flex-end;
}

.chart-cached {
    font-family: var(--font-mono);
    font-size: 0.65rem;
    color: var(--text-tertiary);
}

/* ── Loading States ───────────────────────────────────────── */
.chart-loading {
    display: flex;
    align-items: center;
    justify-content: center;
    height: 100%;
    color: var(--text-tertiary);
    font-size: 0.85rem;
}

.chart-loading::after {
    content: '';
    width: 24px;
    height: 24px;
    border: 2px solid var(--border);
    border-top-color: var(--accent);
    border-radius: 50%;
    animation: spin 0.8s linear infinite;
    margin-left: 10px;
}

@keyframes spin {
    to { transform: rotate(360deg); }
}

.chart-error {
    display: flex;
    align-items: center;
    justify-content: center;
    height: 100%;
    color: var(--danger);
    font-size: 0.85rem;
    flex-direction: column;
    gap: 8px;
}

/* ── Modal ────────────────────────────────────────────────── */
.modal-overlay {
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.6);
    backdrop-filter: blur(4px);
    z-index: 200;
    display: none;
    align-items: center;
    justify-content: center;
    padding: 40px;
}

.modal-overlay.active {
    display: flex;
}

.modal-content {
    background: var(--bg-surface);
    border-radius: var(--radius);
    width: 100%;
    max-width: 1200px;
    max-height: 85vh;
    box-shadow: var(--shadow-lg);
    display: flex;
    flex-direction: column;
}

.modal-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 20px 24px;
    border-bottom: 1px solid var(--border);
}

.modal-title {
    font-size: 1.1rem;
    font-weight: 600;
}

.btn-close-modal {
    color: var(--text-secondary);
}

.btn-close-modal:hover {
    color: var(--text-primary);
    background: var(--bg-hover);
}

.modal-chart {
    flex: 1;
    min-height: 500px;
    padding: 16px;
}

/* ── Toast ────────────────────────────────────────────────── */
.toast-container {
    position: fixed;
    bottom: 20px;
    right: 20px;
    z-index: 300;
    display: flex;
    flex-direction: column;
    gap: 8px;
}

.toast {
    padding: 12px 20px;
    border-radius: var(--radius-sm);
    font-size: 0.82rem;
    font-weight: 500;
    box-shadow: var(--shadow-md);
    animation: slideIn 0.3s ease-out;
    max-width: 360px;
}

.toast--success { background: var(--success); color: white; }
.toast--error { background: var(--danger); color: white; }
.toast--info { background: var(--info); color: white; }

@keyframes slideIn {
    from { transform: translateX(100%); opacity: 0; }
    to { transform: translateX(0); opacity: 1; }
}

/* ── Responsive ───────────────────────────────────────────── */
@media (max-width: 1024px) {
    .kpi-row {
        grid-template-columns: repeat(2, 1fr);
    }
    .charts-grid {
        grid-template-columns: 1fr;
    }
    .chart-card--wide {
        grid-column: span 1;
    }
}

@media (max-width: 768px) {
    .sidebar {
        transform: translateX(-100%);
    }
    .sidebar.open {
        transform: translateX(0);
    }
    .main-content {
        margin-left: 0;
    }
    .btn-hamburger {
        display: flex;
    }
    .kpi-row {
        grid-template-columns: 1fr 1fr;
        padding: 16px;
    }
    .charts-grid {
        padding: 16px;
    }
    .date-range {
        flex-wrap: wrap;
    }
}

@media (max-width: 480px) {
    .kpi-row {
        grid-template-columns: 1fr;
    }
}

/* ── Scrollbar ────────────────────────────────────────────── */
::-webkit-scrollbar {
    width: 6px;
}
::-webkit-scrollbar-track {
    background: transparent;
}
::-webkit-scrollbar-thumb {
    background: var(--border-strong);
    border-radius: 3px;
}
::-webkit-scrollbar-thumb:hover {
    background: var(--text-tertiary);
}
