:root {
    /* Brand colors (same in both themes) */
    --primary-color: #1976d2;
    --secondary-color: #2196f3;
    --success-color: #2e7d32;
    --warning-color: #f57f17;
    --danger-color: #c62828;

    /* Light theme (default) — semantic tokens */
    --bg-page: #f5f5f5;
    --bg-card: #ffffff;
    --bg-card-elevated: #fafafa;
    --bg-input: #ffffff;
    --bg-ideal-hours: #e8f5e9;
    --text-primary: #212121;
    --text-secondary: #757575;
    --text-muted: #999999;
    --border-color: #e0e0e0;
    --card-shadow: 0 4px 6px rgba(0, 0, 0, 0.1);
    --row-hover: rgba(0, 0, 0, 0.02);
    --chart-grid: rgba(0, 0, 0, 0.05);

    --transition-speed: 0.3s;
}

/* Dark theme: applied when <html data-theme="dark"> or user system preference */
html[data-theme="dark"] {
    --bg-page: #121212;
    --bg-card: #1e1e1e;
    --bg-card-elevated: #2a2a2a;
    --bg-input: #2a2a2a;
    --bg-ideal-hours: #1b3a1f;
    --text-primary: #e8e8e8;
    --text-secondary: #a8a8a8;
    --text-muted: #707070;
    --border-color: #3a3a3a;
    --card-shadow: 0 4px 12px rgba(0, 0, 0, 0.5);
    --row-hover: rgba(255, 255, 255, 0.04);
    --chart-grid: rgba(255, 255, 255, 0.08);
}

/* Auto dark mode for users who haven't made an explicit choice */
@media (prefers-color-scheme: dark) {
    html:not([data-theme]) {
        --bg-page: #121212;
        --bg-card: #1e1e1e;
        --bg-card-elevated: #2a2a2a;
        --bg-input: #2a2a2a;
        --bg-ideal-hours: #1b3a1f;
        --text-primary: #e8e8e8;
        --text-secondary: #a8a8a8;
        --text-muted: #707070;
        --border-color: #3a3a3a;
        --card-shadow: 0 4px 12px rgba(0, 0, 0, 0.5);
        --row-hover: rgba(255, 255, 255, 0.04);
        --chart-grid: rgba(255, 255, 255, 0.08);
    }
}

body {
    background-color: var(--bg-page);
    color: var(--text-primary);
    display: flex;
    flex-direction: column;
    min-height: 100vh;
    font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
    line-height: 1.6;
    transition: background-color var(--transition-speed) ease, color var(--transition-speed) ease;
}

.container { margin-top: 20px; flex: 1; max-width: 1200px; }

.card {
    border: 1px solid var(--border-color);
    border-radius: 10px;
    box-shadow: var(--card-shadow);
    transition: transform var(--transition-speed) ease,
                background-color var(--transition-speed) ease;
    margin-bottom: 1.5rem;
    overflow: hidden;
    background-color: var(--bg-card);
}
.card:hover { transform: translateY(-5px); }
/* Respect users who prefer reduced motion */
@media (prefers-reduced-motion: reduce) {
    .card, .card:hover, .icon, .icon:hover, .footer a { transition: none; transform: none; }
    .loading-spinner { animation: none; }
}

.card-header {
    background: var(--bg-card-elevated);
    color: var(--text-primary);
    border-bottom: 2px solid var(--primary-color);
    border-radius: 10px 10px 0 0 !important;
    padding: 1.25rem;
}
.card-header h2 { margin: 0; font-size: 1.25rem; font-weight: 600; color: var(--primary-color); }
.card-body { background-color: var(--bg-card); color: var(--text-primary); }

.table { margin-bottom: 0; color: var(--text-primary); }

/* Column headers (thead > th) keep the blue */
.table thead th {
    background-color: var(--primary-color);
    color: white;
    font-weight: 600;
    padding: 1rem;
}

.table td {
    vertical-align: middle;
    border-color: var(--border-color);
    padding: 0.75rem;
    background-color: var(--bg-card);
    color: var(--text-primary);
}
.table-hover tbody tr:hover td { background-color: var(--row-hover); }
.thead-light th {
    background-color: var(--primary-color); color: white;
    border-bottom: 2px solid var(--secondary-color);
}

/* Severity indicators: background color + text */
.good, .fair, .poor {
    text-align: center; font-weight: 600;
    padding: 0.5rem; border-radius: 4px;
    color: white;
}
.good { background-color: var(--success-color) !important; color: white !important; }
.fair { background-color: var(--warning-color) !important; color: white !important; }
.poor { background-color: var(--danger-color)  !important; color: white !important; }

/* General Information: plain value cells (no severity color) */
.metrics-row .metric-value:not(.good):not(.fair):not(.poor) {
    color: var(--text-primary);
    background-color: var(--bg-card);
    font-size: 1rem;
    font-weight: 500;
}

.header {
    background: var(--bg-card);
    color: var(--text-primary);
    border-bottom: 3px solid var(--primary-color);
    padding: 1.5rem 2rem;
    text-align: center;
    box-shadow: var(--card-shadow);
}
.header h1 { margin: 0 0 0.25rem 0; font-size: 2.5rem; font-weight: 700; color: var(--primary-color); }
.header p  { margin: 0; font-size: 1.1rem; color: var(--text-secondary); }

/* Theme toggle button */
.theme-toggle {
    position: absolute;
    top: 1rem;
    right: 1rem;
    background: var(--bg-card-elevated);
    color: var(--text-primary);
    border: 1px solid var(--border-color);
    border-radius: 50%;
    width: 44px;
    height: 44px;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 1.1rem;
    transition: background var(--transition-speed) ease;
}
.theme-toggle:hover { background: var(--border-color); }
.theme-toggle:focus { outline: 2px solid var(--primary-color); outline-offset: 2px; }
.header { position: relative; }

.footer {
    background: var(--bg-card);
    color: var(--text-secondary);
    border-top: 2px solid var(--border-color);
    text-align: center;
    padding: 1rem 0;
    width: 100%;
    font-size: 0.9rem;
}
.footer a { color: var(--primary-color); text-decoration: underline; transition: opacity var(--transition-speed) ease; }
.footer a:hover { opacity: 0.7; }

.icon {
    margin-right: 8px;
    transition: transform var(--transition-speed) ease;
    width: 20px; text-align: center; color: var(--secondary-color);
}
.icon:hover { transform: scale(1.2); }

.description { color: var(--text-secondary); font-size: 0.9rem; margin-top: 0.25rem; }
.band-description { color: var(--text-secondary); font-size: 0.85rem; max-width: 300px; }

/* Form controls must follow theme */
.form-control, select.form-control, input.form-control {
    background-color: var(--bg-input);
    color: var(--text-primary);
    border-color: var(--border-color);
}
.form-control:focus {
    background-color: var(--bg-input);
    color: var(--text-primary);
}
html[data-theme="dark"] .form-control::placeholder { color: var(--text-muted); }
html[data-theme="dark"] .alert-info {
    background-color: #1a3a4a;
    color: #a8d8e8;
    border-color: #2a5a6a;
}
html[data-theme="dark"] .btn-outline-secondary { color: var(--text-secondary); border-color: var(--border-color); }
html[data-theme="dark"] .btn-outline-secondary:hover { background-color: var(--bg-card-elevated); color: var(--text-primary); }
html[data-theme="dark"] hr { border-color: var(--border-color); }
html[data-theme="dark"] .text-muted { color: var(--text-muted) !important; }

.loading {
    position: fixed; top: 0; left: 0; width: 100%; height: 100%;
    background: rgba(0, 0, 0, 0.6);
    display: flex; justify-content: center; align-items: center;
    z-index: 1000;
}
.loading-spinner {
    width: 50px; height: 50px;
    border: 5px solid var(--border-color);
    border-top: 5px solid var(--secondary-color);
    border-radius: 50%;
    animation: spin 1s linear infinite;
}
@keyframes spin {
    0% { transform: rotate(0deg); }
    100% { transform: rotate(360deg); }
}

#countdown { color: var(--secondary-color); font-weight: bold; }

.chart-container { position: relative; height: 400px; margin: 20px 0; }

/* Stale-data banner */
.stale-banner {
    background: #fff3cd;
    color: #856404;
    padding: 0.75rem 1rem;
    border: 1px solid #ffeeba;
    border-radius: 4px;
    margin-bottom: 1rem;
}
html[data-theme="dark"] .stale-banner {
    background: #3a2f0a;
    color: #ffd966;
    border-color: #5a4a1f;
}
.stale-banner i { margin-right: 0.5rem; }

/* Ideal-hours cell background (keeps green tint but theme-aware) */
.ideal-hours-cell {
    background-color: var(--bg-ideal-hours) !important;
    font-weight: 600;
}

/* Modal styles (self-managed, no bootstrap.js dep) */
.modal { display: none; position: fixed; z-index: 1050; inset: 0; overflow: auto; }
.modal.show { display: block; }
.modal-backdrop {
    position: fixed; inset: 0; z-index: 1040;
    width: 100vw; height: 100vh;
    background-color: #000; opacity: 0.5;
}
.modal-dialog { position: relative; width: auto; margin: 1.75rem auto; max-width: 500px; }
.modal-dialog-centered { display: flex; align-items: center; min-height: calc(100% - 3.5rem); }
.modal-content {
    position: relative; display: flex; flex-direction: column; width: 100%;
    background-color: var(--bg-card); color: var(--text-primary);
    border: 1px solid var(--border-color);
    border-radius: 0.3rem; box-shadow: 0 0.25rem 0.5rem rgba(0, 0, 0, 0.5);
    outline: 0;
}
.modal-header {
    display: flex; align-items: flex-start; justify-content: space-between;
    padding: 1rem; border-bottom: 2px solid var(--primary-color);
    background: var(--bg-card-elevated);
    color: var(--text-primary);
    border-top-left-radius: 0.3rem; border-top-right-radius: 0.3rem;
}
.modal-header h5 { color: var(--primary-color); font-weight: 600; }
.modal-body { position: relative; flex: 1 1 auto; padding: 1rem; }
.modal-footer {
    display: flex; align-items: center; justify-content: flex-end;
    padding: 1rem; border-top: 1px solid var(--border-color);
    border-bottom-right-radius: 0.3rem; border-bottom-left-radius: 0.3rem;
}
.modal-footer > * { margin-left: 0.5rem; }

@media (max-width: 768px) {
    .container { padding: 10px; }
    .card { margin-bottom: 1rem; }
    .header h1 { font-size: 2rem; }
    .table th { width: 50%; }
    .table-responsive {
        display: block; width: 100%;
        overflow-x: auto; -webkit-overflow-scrolling: touch;
    }
    .band-description { max-width: 200px; }
    .chart-container { height: 300px; }
    .theme-toggle { top: 0.5rem; right: 0.5rem; width: 36px; height: 36px; font-size: 0.9rem; }
}

/* ============================================================
   Metric trends removed per user request
   ============================================================ */