/* ================================================================
   HAWAIIAN ORGANIC OBSERVATORY - V2 DASHBOARD
   Volcanic Earth Theme with Light/Dark Mode
   ================================================================ */

/* === DARK THEME (Default) === */
:root,
[data-theme="dark"] {
    /* Volcanic Earth Palette - Dark */
    --bg-deep: #0d0d0d;
    --bg-surface: #161616;
    --bg-elevated: #1e1e1e;
    --bg-panel: #242424;
    --bg-hover: #2a2a2a;

    /* Accent Colors - Earth & Ocean */
    --accent-terracotta: #E07A5F;
    --accent-ochre: #F4A259;
    --accent-sage: #81B29A;
    --accent-ocean: #3D85C6;
    --accent-deep-teal: #2A6478;
    --accent-volcanic: #8B4D5C;

    /* Text Colors */
    --text-primary: #FAFAF9;
    --text-secondary: #A8A8A6;
    --text-muted: #6B6B69;
    --text-accent: var(--accent-terracotta);

    /* Borders & Lines */
    --border-subtle: rgba(255, 255, 255, 0.06);
    --border-medium: rgba(255, 255, 255, 0.1);
    --border-glow: rgba(224, 122, 95, 0.3);

    /* Chart Colors - Distinctive Palette */
    --chart-1: #E07A5F;
    --chart-2: #81B29A;
    --chart-3: #F4A259;
    --chart-4: #3D85C6;
    --chart-5: #9B7E6A;
    --chart-6: #D4A574;
    --chart-7: #6BA3BE;
    --chart-8: #C97C6B;

    /* Positive/Negative */
    --positive: #81B29A;
    --negative: #E07A5F;

    /* Map */
    --map-bg: #1a2e35;
    --map-land: #2a3f47;

    /* Shadows & Effects */
    --shadow-sm: 0 2px 8px rgba(0, 0, 0, 0.3);
    --shadow-md: 0 4px 20px rgba(0, 0, 0, 0.4);
    --shadow-lg: 0 8px 40px rgba(0, 0, 0, 0.5);
    --shadow-glow: 0 0 30px rgba(224, 122, 95, 0.15);

    /* Header bg */
    --header-bg: rgba(22, 22, 22, 0.8);

    /* Orb opacity */
    --orb-opacity: 0.4;
}

/* === LIGHT THEME === */
[data-theme="light"] {
    /* Warm, earthy light palette */
    --bg-deep: #F8F6F3;
    --bg-surface: #FFFFFF;
    --bg-elevated: #FAFAF8;
    --bg-panel: #F0EDE8;
    --bg-hover: #E8E4DD;

    /* Accent Colors - richer for light bg */
    --accent-terracotta: #D66853;
    --accent-ochre: #E8934A;
    --accent-sage: #6A9B84;
    --accent-ocean: #3574B0;
    --accent-deep-teal: #1E5266;
    --accent-volcanic: #7A3E4A;

    /* Text Colors */
    --text-primary: #1A1A18;
    --text-secondary: #4A4A48;
    --text-muted: #7A7A78;
    --text-accent: var(--accent-terracotta);

    /* Borders & Lines */
    --border-subtle: rgba(0, 0, 0, 0.06);
    --border-medium: rgba(0, 0, 0, 0.1);
    --border-glow: rgba(214, 104, 83, 0.3);

    /* Chart Colors - richer for light mode */
    --chart-1: #D66853;
    --chart-2: #6A9B84;
    --chart-3: #E8934A;
    --chart-4: #3574B0;
    --chart-5: #8A6D5B;
    --chart-6: #C49462;
    --chart-7: #5A92A8;
    --chart-8: #B86B5A;

    /* Positive/Negative */
    --positive: #4A8B6A;
    --negative: #C45A42;

    /* Map */
    --map-bg: #E8F4F8;
    --map-land: #D4E8D4;

    /* Shadows - softer for light mode */
    --shadow-sm: 0 2px 8px rgba(0, 0, 0, 0.08);
    --shadow-md: 0 4px 20px rgba(0, 0, 0, 0.1);
    --shadow-lg: 0 8px 40px rgba(0, 0, 0, 0.12);
    --shadow-glow: 0 0 30px rgba(214, 104, 83, 0.1);

    /* Header bg */
    --header-bg: rgba(255, 255, 255, 0.9);

    /* Orb opacity - subtler in light mode */
    --orb-opacity: 0.15;
}

/* === SHARED VARIABLES === */
:root {
    /* Typography */
    --font-display: 'Sora', sans-serif;
    --font-body: 'Source Sans 3', sans-serif;

    /* Spacing */
    --space-xs: 0.25rem;
    --space-sm: 0.5rem;
    --space-md: 1rem;
    --space-lg: 1.5rem;
    --space-xl: 2rem;
    --space-2xl: 3rem;

    /* Borders */
    --radius-sm: 6px;
    --radius-md: 10px;
    --radius-lg: 16px;
    --radius-xl: 24px;

    /* Transitions */
    --transition-fast: 150ms ease;
    --transition-base: 250ms ease;
    --transition-slow: 400ms ease;
    --transition-theme: 300ms ease;
}

/* === RESET & BASE === */
*, *::before, *::after {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
}

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

body {
    font-family: var(--font-body);
    background: var(--bg-deep);
    color: var(--text-primary);
    line-height: 1.5;
    min-height: 100vh;
    overflow-x: hidden;
    transition: background var(--transition-theme), color var(--transition-theme);
}

/* === AMBIENT BACKGROUND === */
.ambient-bg {
    position: fixed;
    inset: 0;
    pointer-events: none;
    z-index: 0;
    overflow: hidden;
}

.topo-lines {
    position: absolute;
    inset: 0;
    opacity: 0.03;
    background-image:
        repeating-linear-gradient(
            0deg,
            transparent,
            transparent 60px,
            currentColor 60px,
            currentColor 61px
        ),
        repeating-linear-gradient(
            90deg,
            transparent,
            transparent 60px,
            currentColor 60px,
            currentColor 61px
        );
    color: var(--text-muted);
}

[data-theme="light"] .topo-lines {
    opacity: 0.04;
}

.gradient-orb {
    position: absolute;
    border-radius: 50%;
    filter: blur(100px);
    opacity: var(--orb-opacity);
    transition: opacity var(--transition-theme);
}

.orb-1 {
    width: 600px;
    height: 600px;
    background: radial-gradient(circle, var(--accent-terracotta) 0%, transparent 70%);
    top: -200px;
    right: -100px;
    animation: float-slow 20s ease-in-out infinite;
}

.orb-2 {
    width: 500px;
    height: 500px;
    background: radial-gradient(circle, var(--accent-deep-teal) 0%, transparent 70%);
    bottom: -150px;
    left: -100px;
    animation: float-slow 25s ease-in-out infinite reverse;
}

@keyframes float-slow {
    0%, 100% { transform: translate(0, 0); }
    50% { transform: translate(30px, -20px); }
}

/* === LOADING OVERLAY === */
.loading-overlay {
    position: fixed;
    inset: 0;
    z-index: 1000;
    display: flex;
    align-items: center;
    justify-content: center;
    background: var(--bg-deep);
    transition: opacity 0.5s ease, visibility 0.5s ease;
}

.loading-overlay.opacity-0 {
    opacity: 0;
    visibility: hidden;
    pointer-events: none;
}

.loader-content {
    text-align: center;
}

.loader-ring {
    width: 80px;
    height: 80px;
    margin: 0 auto var(--space-lg);
}

.loader-ring svg {
    width: 100%;
    height: 100%;
    transform: rotate(-90deg);
}

.loader-track {
    fill: none;
    stroke: var(--bg-panel);
    stroke-width: 4;
}

.loader-progress {
    fill: none;
    stroke: var(--accent-terracotta);
    stroke-width: 4;
    stroke-linecap: round;
    stroke-dasharray: 251;
    stroke-dashoffset: 251;
    animation: loader-spin 1.5s ease-in-out infinite;
}

@keyframes loader-spin {
    0% { stroke-dashoffset: 251; }
    50% { stroke-dashoffset: 60; }
    100% { stroke-dashoffset: 251; }
}

.loader-title {
    font-family: var(--font-display);
    font-size: 1.5rem;
    font-weight: 600;
    color: var(--text-primary);
    margin-bottom: var(--space-xs);
}

.loader-subtitle {
    font-size: 0.875rem;
    color: var(--text-muted);
}

/* === DASHBOARD LAYOUT === */
.dashboard-layout {
    position: relative;
    z-index: 1;
    display: grid;
    grid-template-columns: 280px 1fr;
    grid-template-rows: auto 1fr;
    grid-template-areas:
        "header header"
        "sidebar main";
    min-height: 100vh;
}

/* === HEADER === */
.main-header {
    grid-area: header;
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: var(--space-md) var(--space-xl);
    background: var(--header-bg);
    backdrop-filter: blur(20px);
    border-bottom: 1px solid var(--border-subtle);
    position: sticky;
    top: 0;
    z-index: 1001;
    transition: background var(--transition-theme), border-color var(--transition-theme);
}

.header-brand {
    display: flex;
    align-items: center;
    gap: var(--space-md);
}

.brand-icon {
    width: 44px;
    height: 44px;
    display: flex;
    align-items: center;
    justify-content: center;
    background: linear-gradient(135deg, var(--accent-terracotta), var(--accent-ochre));
    border-radius: var(--radius-md);
    color: white;
    box-shadow: var(--shadow-sm);
}

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

.brand-text h1 {
    font-family: var(--font-display);
    font-size: 1.25rem;
    font-weight: 700;
    letter-spacing: -0.02em;
    color: var(--text-primary);
    transition: color var(--transition-theme);
}

.brand-tagline {
    font-size: 0.75rem;
    color: var(--text-muted);
    letter-spacing: 0.05em;
    text-transform: uppercase;
    transition: color var(--transition-theme);
}

.header-nav {
    display: flex;
    align-items: center;
    gap: var(--space-sm);
}

/* === THEME TOGGLE === */
.theme-toggle {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 40px;
    height: 40px;
    background: var(--bg-surface);
    border: 1px solid var(--border-medium);
    border-radius: var(--radius-sm);
    cursor: pointer;
    transition: var(--transition-fast);
    color: var(--text-secondary);
}

.theme-toggle:hover {
    border-color: var(--accent-terracotta);
    color: var(--accent-terracotta);
    background: var(--bg-hover);
}

.theme-toggle svg {
    width: 20px;
    height: 20px;
    transition: transform 0.3s ease;
}

/* Show sun in dark mode, moon in light mode */
[data-theme="dark"] .theme-toggle .icon-sun { display: block; }
[data-theme="dark"] .theme-toggle .icon-moon { display: none; }
[data-theme="light"] .theme-toggle .icon-sun { display: none; }
[data-theme="light"] .theme-toggle .icon-moon { display: block; }

.theme-toggle:hover svg {
    transform: rotate(15deg);
}

.nav-link {
    display: flex;
    align-items: center;
    gap: var(--space-xs);
    padding: var(--space-sm) var(--space-md);
    font-size: 0.875rem;
    font-weight: 500;
    color: var(--text-secondary);
    text-decoration: none;
    background: var(--bg-surface);
    border: 1px solid var(--border-medium);
    border-radius: var(--radius-sm);
    transition: var(--transition-fast);
}

.nav-link:hover {
    color: var(--accent-terracotta);
    border-color: var(--accent-terracotta);
    background: var(--bg-hover);
}

.nav-link svg {
    width: 14px;
    height: 14px;
}

/* === CONTROL PANEL (SIDEBAR) - STICKY === */
.control-panel {
    grid-area: sidebar;
    background: var(--bg-surface);
    border-right: 1px solid var(--border-subtle);
    padding: var(--space-xl) var(--space-lg);
    display: flex;
    flex-direction: column;
    gap: var(--space-xl);
    position: sticky;
    top: 73px; /* Height of header */
    height: calc(100vh - 73px);
    overflow-y: auto;
    transition: background var(--transition-theme), border-color var(--transition-theme);
}

.panel-section {
    display: flex;
    flex-direction: column;
    gap: var(--space-md);
}

.section-label {
    font-family: var(--font-display);
    font-size: 0.6875rem;
    font-weight: 600;
    color: var(--text-muted);
    text-transform: uppercase;
    letter-spacing: 0.1em;
    transition: color var(--transition-theme);
}

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

.year-display {
    font-family: var(--font-display);
    font-size: 2.5rem;
    font-weight: 800;
    color: var(--accent-terracotta);
    line-height: 1;
}

[data-theme="dark"] .year-display {
    text-shadow: 0 0 40px rgba(224, 122, 95, 0.4);
}

.slider-container {
    display: flex;
    flex-direction: column;
    gap: var(--space-xs);
}

.year-slider {
    -webkit-appearance: none;
    appearance: none;
    width: 100%;
    height: 6px;
    background: var(--bg-panel);
    border-radius: 3px;
    outline: none;
    cursor: pointer;
    transition: background var(--transition-theme);
}

.year-slider::-webkit-slider-thumb {
    -webkit-appearance: none;
    appearance: none;
    width: 20px;
    height: 20px;
    background: var(--accent-terracotta);
    border-radius: 50%;
    cursor: pointer;
    box-shadow: 0 0 10px rgba(224, 122, 95, 0.5);
    transition: var(--transition-fast);
}

.year-slider::-webkit-slider-thumb:hover {
    transform: scale(1.1);
    box-shadow: 0 0 20px rgba(224, 122, 95, 0.7);
}

.year-slider::-moz-range-thumb {
    width: 20px;
    height: 20px;
    background: var(--accent-terracotta);
    border: none;
    border-radius: 50%;
    cursor: pointer;
    box-shadow: 0 0 10px rgba(224, 122, 95, 0.5);
}

.slider-labels {
    display: flex;
    justify-content: space-between;
    font-size: 0.6875rem;
    color: var(--text-muted);
    transition: color var(--transition-theme);
}

.playback-controls {
    display: flex;
    gap: var(--space-sm);
}

.playback-btn {
    flex: 1;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: var(--space-xs);
    padding: var(--space-sm) var(--space-md);
    font-family: var(--font-display);
    font-size: 0.75rem;
    font-weight: 600;
    border: none;
    border-radius: var(--radius-sm);
    cursor: pointer;
    transition: var(--transition-fast);
}

.playback-btn svg {
    width: 14px;
    height: 14px;
}

.playback-btn.play {
    background: var(--accent-terracotta);
    color: white;
}

.playback-btn.play:hover {
    background: var(--accent-ochre);
}

.playback-btn.pause {
    background: var(--bg-panel);
    color: var(--text-secondary);
    transition: background var(--transition-theme), color var(--transition-theme);
}

.playback-btn.pause:hover {
    background: var(--bg-hover);
}

.hidden {
    display: none !important;
}

/* Filter Groups */
.filter-group {
    display: flex;
    flex-direction: column;
    gap: var(--space-sm);
}

.filter-group .flex {
    display: flex;
}

.filter-group .items-center {
    align-items: center;
}

.filter-group input[type="checkbox"] {
    -webkit-appearance: none;
    appearance: none;
    width: 18px;
    height: 18px;
    background: var(--bg-panel);
    border: 1px solid var(--border-medium);
    border-radius: 4px;
    cursor: pointer;
    transition: var(--transition-fast), background var(--transition-theme);
    position: relative;
}

.filter-group input[type="checkbox"]:checked {
    background: var(--accent-terracotta);
    border-color: var(--accent-terracotta);
}

.filter-group input[type="checkbox"]:checked::after {
    content: '';
    position: absolute;
    left: 5px;
    top: 2px;
    width: 5px;
    height: 9px;
    border: solid white;
    border-width: 0 2px 2px 0;
    transform: rotate(45deg);
}

.filter-group label {
    margin-left: var(--space-sm);
    font-size: 0.875rem;
    color: var(--text-secondary);
    cursor: pointer;
    transition: color var(--transition-fast);
}

.filter-group label:hover {
    color: var(--text-primary);
}

/* Certifier Select */
.certifier-select {
    width: 100%;
    padding: var(--space-sm) var(--space-md);
    font-family: var(--font-body);
    font-size: 0.875rem;
    color: var(--text-primary);
    background: var(--bg-panel);
    border: 1px solid var(--border-medium);
    border-radius: var(--radius-sm);
    outline: none;
    cursor: pointer;
    transition: var(--transition-fast), background var(--transition-theme);
}

.certifier-select:hover,
.certifier-select:focus {
    border-color: var(--accent-terracotta);
}

.certifier-select option {
    background: var(--bg-elevated);
    color: var(--text-primary);
}

/* === CONTENT AREA === */
.content-area {
    grid-area: main;
    padding: var(--space-xl);
    overflow-y: auto;
    display: flex;
    flex-direction: column;
    gap: var(--space-lg);
}

/* === KPI STRIP === */
.kpi-strip {
    display: grid;
    grid-template-columns: repeat(4, 1fr);
    gap: var(--space-sm);
}

.kpi-card {
    background: var(--bg-surface);
    border: 1px solid var(--border-subtle);
    border-radius: var(--radius-lg);
    padding: var(--space-sm) var(--space-md);
    transition: var(--transition-base), background var(--transition-theme), border-color var(--transition-theme);
    position: relative;
    overflow: hidden;
}

.kpi-card::before {
    content: '';
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    height: 3px;
    background: linear-gradient(90deg, transparent, var(--border-medium), transparent);
}

.kpi-card.primary::before {
    background: linear-gradient(90deg, var(--accent-terracotta), var(--accent-ochre));
}

.kpi-card:hover {
    border-color: var(--border-medium);
    box-shadow: var(--shadow-md);
}

.kpi-value {
    font-family: var(--font-display);
    font-size: 1.75rem;
    font-weight: 700;
    color: var(--text-primary);
    line-height: 1.2;
    transition: color var(--transition-theme);
}

.kpi-value.small {
    font-size: 1.1rem;
    font-weight: 600;
}

.kpi-value-row {
    display: flex;
    align-items: baseline;
    gap: var(--space-sm);
}

.kpi-badge {
    font-family: var(--font-display);
    font-size: 0.6875rem;
    font-weight: 600;
    padding: 2px 8px;
    border-radius: 100px;
    background: var(--bg-panel);
    color: var(--text-muted);
    transition: background var(--transition-theme), color var(--transition-theme);
}

.kpi-badge.positive {
    background: rgba(129, 178, 154, 0.2);
    color: var(--positive);
}

.kpi-badge.negative {
    background: rgba(224, 122, 95, 0.2);
    color: var(--negative);
}

.kpi-label {
    font-family: var(--font-display);
    font-size: 0.7rem;
    font-weight: 600;
    color: var(--text-secondary);
    margin-top: 2px;
    text-transform: uppercase;
    letter-spacing: 0.05em;
    transition: color var(--transition-theme);
}

.kpi-sublabel {
    font-size: 0.6875rem;
    color: var(--text-muted);
    margin-top: 2px;
    transition: color var(--transition-theme);
}

/* Data Notes */
.data-note {
    font-size: 0.75rem;
    line-height: 1.4;
    color: var(--text-muted);
    background: rgba(224, 122, 95, 0.08);
    border-left: 3px solid var(--accent-terracotta);
    padding: var(--space-sm) var(--space-md);
    border-radius: var(--radius-sm);
    margin-top: var(--space-sm);
}

.data-note strong {
    color: var(--text-secondary);
}

/* Dynamic KPI colors */
#kpi-net.text-emerald-600,
#kpi-net.positive {
    color: var(--positive) !important;
}

#kpi-net.text-red-600,
#kpi-net.negative {
    color: var(--negative) !important;
}

#kpi-net-badge.bg-emerald-100 {
    background: rgba(129, 178, 154, 0.2) !important;
    color: var(--positive) !important;
}

#kpi-net-badge.bg-red-100 {
    background: rgba(224, 122, 95, 0.2) !important;
    color: var(--negative) !important;
}

/* === VISUALIZATION ROWS === */
.viz-row {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: var(--space-lg);
}

.viz-row.primary-row {
    grid-template-columns: 2fr 1fr;
}

.viz-row.triple {
    grid-template-columns: repeat(3, 1fr);
}

.side-charts {
    display: flex;
    flex-direction: column;
    gap: var(--space-lg);
}

/* === VISUALIZATION PANELS === */
.viz-panel {
    background: var(--bg-surface);
    border: 1px solid var(--border-subtle);
    border-radius: var(--radius-lg);
    padding: var(--space-lg);
    display: flex;
    flex-direction: column;
    transition: var(--transition-base), background var(--transition-theme), border-color var(--transition-theme);
}

.viz-panel:hover {
    border-color: var(--border-medium);
}

.viz-panel.map-panel {
    position: relative;
    padding: var(--space-md);
}

.viz-panel.compact {
    flex: 1;
}

.viz-panel.narrow {
    min-height: 280px;
}

.viz-panel.wide {
    grid-column: 1 / -1;
}

.panel-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: var(--space-md);
}

.panel-header h3 {
    font-family: var(--font-display);
    font-size: 0.875rem;
    font-weight: 600;
    color: var(--text-primary);
    transition: color var(--transition-theme);
}

.panel-subtitle {
    font-size: 0.6875rem;
    color: var(--text-muted);
    font-weight: 400;
    margin-top: 2px;
}

.panel-badge {
    font-family: var(--font-display);
    font-size: 0.625rem;
    font-weight: 600;
    padding: 3px 8px;
    background: var(--bg-panel);
    color: var(--text-muted);
    border-radius: 100px;
    text-transform: uppercase;
    letter-spacing: 0.05em;
    transition: background var(--transition-theme), color var(--transition-theme);
}

/* === CHART CONTAINERS === */
.chart-container {
    flex: 1;
    min-height: 200px;
    position: relative;
}

.chart-container.donut {
    min-height: 180px;
}

.chart-container.bar {
    min-height: 180px;
}

.chart-container.bar-sm {
    min-height: 160px;
}

.chart-container.line {
    min-height: 220px;
}

.chart-container.line-wide {
    min-height: 180px;
}

.chart-container.cloud {
    min-height: 280px;
}

.chart-container.tree {
    min-height: 220px;
}

/* === MAP CONTAINER === */
.map-container {
    flex: 1;
    min-height: 420px;
    border-radius: var(--radius-md);
    overflow: hidden;
    background: var(--map-bg);
    transition: background var(--transition-theme);
}

/* Leaflet Overrides */
.leaflet-container {
    background: var(--map-bg) !important;
    font-family: var(--font-body) !important;
}

.leaflet-control-zoom {
    border: none !important;
    box-shadow: var(--shadow-md) !important;
}

.leaflet-control-zoom a {
    background: var(--bg-panel) !important;
    color: var(--text-primary) !important;
    border: 1px solid var(--border-subtle) !important;
}

.leaflet-control-zoom a:hover {
    background: var(--bg-elevated) !important;
}

.leaflet-popup-content-wrapper {
    background: var(--bg-panel) !important;
    color: var(--text-primary) !important;
    border-radius: var(--radius-md) !important;
    box-shadow: var(--shadow-lg) !important;
    border: 1px solid var(--border-subtle) !important;
}

.leaflet-popup-tip {
    background: var(--bg-panel) !important;
}

.leaflet-popup-close-button {
    color: var(--text-muted) !important;
}

/* === TOOLTIPS === */
.chart-tooltip {
    position: absolute;
    display: none;
    background: var(--bg-panel);
    border: 1px solid var(--border-medium);
    border-radius: var(--radius-sm);
    padding: var(--space-sm) var(--space-md);
    font-size: 0.75rem;
    color: var(--text-primary);
    box-shadow: var(--shadow-lg);
    pointer-events: none;
    z-index: 1000;
    max-width: 280px;
    backdrop-filter: blur(10px);
}

.chart-tooltip.global {
    position: fixed;
}

.chart-tooltip strong {
    color: var(--accent-terracotta);
}

/* === D3 CHART STYLING === */
/* Axis styling */
.viz-panel text {
    font-family: var(--font-body);
    fill: var(--text-muted);
    font-size: 10px;
}

/* Hide axis lines by default for cleaner look (Data Looks Better Naked) */
.viz-panel .domain {
    stroke: transparent;
}

/* Show bottom x-axis line only if needed, but often not needed with ticks */
/* .viz-panel .x-axis .domain { stroke: var(--border-subtle); } */

.viz-panel .tick line {
    stroke: var(--border-subtle);
    stroke-dasharray: 2,2; /* Dashed grid lines */
    opacity: 0.3; /* Subtle */
}

/* Remove y-axis tick lines if they are just clutter */
/* We can control this per chart or globally */

/* Bar styling */
.viz-panel .bar {
    transition: opacity var(--transition-fast);
}

.viz-panel .bar:hover {
    opacity: 0.8;
}

/* Line chart styling */
.viz-panel path.line {
    fill: none;
    stroke-width: 2;
}

/* === OPERATIONS TABLE === */
.table-container {
    height: 400px;
    overflow-y: auto; /* Scroll ONLY the container body */
    background: var(--bg-surface);
    border-radius: var(--radius-md);
    position: relative;
    transition: background var(--transition-theme);
    border: 1px solid var(--border-subtle);
}

.table-responsive {
    width: 100%;
    /* Remove overflow from here if we want sticky headers to work against table-container scroll */
    /* Or if table-responsive is the scroll parent, we apply height here */
    height: 100%; 
    overflow-y: auto; /* Make this the scroll container */
    overflow-x: auto;
}

.data-table {
    width: 100%;
    border-collapse: separate; /* Required for sticky headers in some browsers */
    border-spacing: 0;
    font-size: 0.875rem;
    color: var(--text-secondary);
}

.data-table th {
    background: var(--bg-panel);
    position: sticky;
    top: 0;
    z-index: 10;
    font-weight: 600;
    font-family: var(--font-display);
    color: var(--text-primary);
    text-transform: uppercase;
    font-size: 0.75rem;
    letter-spacing: 0.05em;
    transition: background var(--transition-theme), color var(--transition-theme);
    border-bottom: 2px solid var(--border-medium);
    padding: var(--space-md);
    text-align: left;
    cursor: pointer; /* Clickable headers */
    user-select: none;
}

.data-table th:hover {
    background: var(--bg-hover);
    color: var(--accent-terracotta);
}

.data-table td {
    padding: var(--space-md);
    text-align: left;
    border-bottom: 1px solid var(--border-subtle);
}

/* Remove side padding for first/last columns */
.data-table th:first-child,
.data-table td:first-child {
    padding-left: var(--space-lg);
}

.data-table th:last-child,
.data-table td:last-child {
    padding-right: var(--space-lg);
}

/* Sort Icons */
.sort-icon::after {
    content: '↕';
    display: inline-block;
    margin-left: 5px;
    opacity: 0.3;
    font-size: 0.8em;
}

th.sorted-asc .sort-icon::after {
    content: '↑';
    opacity: 1;
    color: var(--accent-terracotta);
}

th.sorted-desc .sort-icon::after {
    content: '↓';
    opacity: 1;
    color: var(--accent-terracotta);
}

/* Table Body Rows */
.data-table tbody tr {
    transition: background-color var(--transition-fast);
}

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

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

.data-table td.op-name {
    font-weight: 500;
    color: var(--text-primary);
}

.data-table td.op-certifier {
    font-size: 0.8125rem;
    color: var(--text-muted);
}

/* === SCROLLBAR STYLING === */
::-webkit-scrollbar {
    width: 8px;
    height: 8px;
}

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

::-webkit-scrollbar-thumb {
    background: var(--bg-panel);
    border-radius: 4px;
}

::-webkit-scrollbar-thumb:hover {
    background: var(--text-muted);
}

.control-panel::-webkit-scrollbar {
    width: 4px;
}

/* === ANIMATIONS === */
@keyframes fade-in {
    from { opacity: 0; transform: translateY(10px); }
    to { opacity: 1; transform: translateY(0); }
}

.kpi-card {
    animation: fade-in 0.5s ease backwards;
}

.kpi-card:nth-child(1) { animation-delay: 0.1s; }
.kpi-card:nth-child(2) { animation-delay: 0.15s; }
.kpi-card:nth-child(3) { animation-delay: 0.2s; }
.kpi-card:nth-child(4) { animation-delay: 0.25s; }

.viz-panel {
    animation: fade-in 0.5s ease backwards;
    animation-delay: 0.3s;
}

.viz-row:nth-child(2) .viz-panel { animation-delay: 0.35s; }
.viz-row:nth-child(3) .viz-panel { animation-delay: 0.4s; }
.viz-row:nth-child(4) .viz-panel { animation-delay: 0.45s; }
.viz-row:nth-child(5) .viz-panel { animation-delay: 0.5s; }

/* === RESPONSIVE === */
@media (max-width: 1400px) {
    .kpi-strip {
        grid-template-columns: repeat(2, 1fr);
    }

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

    .viz-row.triple .viz-panel:last-child {
        grid-column: 1 / -1;
    }
}

@media (max-width: 1100px) {
    .dashboard-layout {
        grid-template-columns: 1fr;
        grid-template-areas:
            "header"
            "main";
    }

    .control-panel {
        display: none; /* Hide sidebar on mobile - could make it a drawer */
    }

    .viz-row,
    .viz-row.primary-row {
        grid-template-columns: 1fr;
    }

    .side-charts {
        flex-direction: row;
    }
}

@media (max-width: 768px) {
    .main-header {
        flex-direction: column;
        gap: var(--space-md);
        text-align: center;
    }

    .kpi-strip {
        grid-template-columns: 1fr;
    }

    .side-charts {
        flex-direction: column;
    }

    .kpi-value {
        font-size: 2rem;
    }

    .year-display {
        font-size: 2rem;
    }
}

/* === UTILITY CLASSES (for JS compatibility) === */
.text-emerald-600 { color: var(--positive) !important; }
.text-red-600 { color: var(--negative) !important; }
.bg-emerald-100 { background: rgba(129, 178, 154, 0.2) !important; }
.bg-red-100 { background: rgba(224, 122, 95, 0.2) !important; }
.text-emerald-700 { color: var(--positive) !important; }
.text-red-700 { color: var(--negative) !important; }

/* === MODAL STYLES === */
.modal-overlay {
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.75);
    backdrop-filter: blur(4px);
    z-index: 2000; /* Above everything */
    display: flex;
    align-items: center;
    justify-content: center;
    padding: var(--space-md);
    animation: fadeIn 0.2s ease-out;
}

.modal-container {
    background: var(--bg-surface);
    width: 100%;
    max-width: 800px;
    max-height: 90vh;
    border-radius: var(--radius-lg);
    border: 1px solid var(--border-medium);
    box-shadow: var(--shadow-lg);
    display: flex;
    flex-direction: column;
    overflow: hidden;
    animation: slideUp 0.3s ease-out;
}

.modal-header {
    padding: var(--space-lg);
    border-bottom: 1px solid var(--border-subtle);
    display: flex;
    align-items: center;
    justify-content: space-between;
    background: var(--bg-panel);
}

.modal-title {
    font-family: var(--font-display);
    font-size: 1.25rem;
    font-weight: 600;
    color: var(--text-primary);
}

.modal-close {
    background: transparent;
    border: none;
    color: var(--text-muted);
    cursor: pointer;
    padding: var(--space-xs);
    border-radius: var(--radius-sm);
    transition: var(--transition-fast);
    display: flex;
    align-items: center;
    justify-content: center;
}

.modal-close:hover {
    background: var(--bg-hover);
    color: var(--text-primary);
}

.modal-close svg {
    width: 24px;
    height: 24px;
}

.modal-body {
    padding: var(--space-lg);
    overflow-y: auto;
    display: flex;
    flex-direction: column;
    gap: var(--space-lg);
}

.modal-section {
    display: flex;
    flex-direction: column;
    gap: var(--space-sm);
}

.op-name-large {
    font-family: var(--font-display);
    font-size: 1.75rem;
    font-weight: 700;
    color: var(--text-primary);
    line-height: 1.2;
}

.status-badge {
    display: inline-block;
    padding: 4px 12px;
    border-radius: 100px;
    font-size: 0.875rem;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.05em;
    width: fit-content;
}

.status-badge.certified { background: rgba(16, 185, 129, 0.2); color: #10b981; }
.status-badge.surrendered { background: rgba(239, 68, 68, 0.2); color: #ef4444; }
.status-badge.suspended { background: rgba(245, 158, 11, 0.2); color: #f59e0b; }
.status-badge.revoked { background: rgba(185, 28, 28, 0.2); color: #b91c1c; }

.modal-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
    gap: var(--space-lg);
}

.modal-card {
    background: var(--bg-panel);
    padding: var(--space-md);
    border-radius: var(--radius-md);
    border: 1px solid var(--border-subtle);
}

.modal-card h4 {
    font-family: var(--font-display);
    font-size: 0.875rem;
    color: var(--text-muted);
    text-transform: uppercase;
    letter-spacing: 0.05em;
    margin-bottom: var(--space-md);
    border-bottom: 1px solid var(--border-subtle);
    padding-bottom: var(--space-xs);
}

.modal-card p {
    font-size: 0.875rem;
    margin-bottom: var(--space-xs);
    color: var(--text-secondary);
}

.modal-card strong {
    color: var(--text-primary);
    font-weight: 600;
}

.products-list {
    display: flex;
    flex-wrap: wrap;
    gap: var(--space-xs);
}

.product-tag {
    background: var(--bg-elevated);
    padding: 4px 8px;
    border-radius: 4px;
    font-size: 0.8125rem;
    color: var(--text-secondary);
    border: 1px solid var(--border-subtle);
}

.raw-data-section details {
    cursor: pointer;
    color: var(--text-muted);
    font-size: 0.875rem;
}

.raw-data-section summary:hover {
    color: var(--text-primary);
}

.raw-data-section pre {
    background: #000;
    padding: var(--space-md);
    border-radius: var(--radius-sm);
    overflow-x: auto;
    font-size: 0.75rem;
    color: #0f0;
    margin-top: var(--space-sm);
}

@keyframes fadeIn {
    from { opacity: 0; }
    to { opacity: 1; }
}

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