/* ═══════════════════════════════════════════════
   Health Survey — Design System
   ═══════════════════════════════════════════════ */

/* ── Color Tokens (Light) ── */
:root {
    --color-primary: #0d9488;
    --color-primary-hover: #0f766e;
    --color-primary-light: #ccfbf1;
    --color-primary-subtle: #f0fdfa;
    --color-primary-rgb: 13, 148, 136;

    --color-accent: #f59e0b;
    --color-accent-hover: #d97706;

    --color-bg: #f8fafb;
    --color-surface: #ffffff;
    --color-surface-raised: #ffffff;
    --color-surface-hover: #f1f5f9;
    --color-surface-inset: #f1f5f9;

    --color-text: #1e293b;
    --color-text-secondary: #64748b;
    --color-text-tertiary: #94a3b8;

    --color-border: #e2e8f0;
    --color-border-light: #f1f5f9;

    --color-nav-bg: #0d9488;
    --color-nav-text: rgba(255, 255, 255, 0.85);
    --color-nav-text-active: #ffffff;

    --color-option-hover: #f0fdfa;
    --color-option-active: #ccfbf1;
    --color-option-selected-border: #0d9488;
    --color-option-selected-bg: #f0fdfa;

    --color-score-high: #ef4444;
    --color-score-med: #f59e0b;
    --color-score-low: #06b6d4;
    --color-score-min: #10b981;

    --enn-type1: #0d9488;
    --enn-type2: #10b981;
    --enn-type3: #f59e0b;
    --enn-type4: #8b5cf6;
    --enn-type5: #3b82f6;
    --enn-type6: #6366f1;
    --enn-type7: #f97316;
    --enn-type8: #ef4444;
    --enn-type9: #06b6d4;
    --enn-triad-body: #ef4444;
    --enn-triad-heart: #f59e0b;
    --enn-triad-head: #06b6d4;

    --shadow-sm: 0 1px 3px rgba(0,0,0,0.06), 0 1px 2px rgba(0,0,0,0.04);
    --shadow-md: 0 4px 12px rgba(0,0,0,0.07), 0 2px 4px rgba(0,0,0,0.04);
    --shadow-lg: 0 10px 30px rgba(0,0,0,0.08), 0 4px 8px rgba(0,0,0,0.04);

    --radius-sm: 0.5rem;
    --radius-md: 0.75rem;
    --radius-lg: 1rem;
    --radius-xl: 1.25rem;

    --font-body: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;

    --transition-fast: 0.15s ease;
    --transition-base: 0.25s ease;
}

/* ── Color Tokens (Dark) ── */
[data-theme="dark"] {
    --color-primary: #2dd4bf;
    --color-primary-hover: #5eead4;
    --color-primary-light: #1a3a38;
    --color-primary-subtle: #0f2928;
    --color-primary-rgb: 45, 212, 191;

    --color-accent: #fbbf24;
    --color-accent-hover: #fcd34d;

    --color-bg: #0c1222;
    --color-surface: #1a2332;
    --color-surface-raised: #1e293b;
    --color-surface-hover: #253345;
    --color-surface-inset: #0f172a;

    --color-text: #e2e8f0;
    --color-text-secondary: #94a3b8;
    --color-text-tertiary: #64748b;

    --color-border: #334155;
    --color-border-light: #1e293b;

    --color-nav-bg: #1a2332;
    --color-nav-text: rgba(255, 255, 255, 0.65);
    --color-nav-text-active: #2dd4bf;

    --color-option-hover: #253345;
    --color-option-active: #1a3a38;
    --color-option-selected-border: #2dd4bf;
    --color-option-selected-bg: #0f2928;

    --color-score-high: #f87171;
    --color-score-med: #fbbf24;
    --color-score-low: #22d3ee;
    --color-score-min: #34d399;

    --enn-type1: #2dd4bf;
    --enn-type2: #34d399;
    --enn-type3: #fbbf24;
    --enn-type4: #a78bfa;
    --enn-type5: #60a5fa;
    --enn-type6: #818cf8;
    --enn-type7: #fb923c;
    --enn-type8: #f87171;
    --enn-type9: #22d3ee;
    --enn-triad-body: #f87171;
    --enn-triad-heart: #fbbf24;
    --enn-triad-head: #22d3ee;

    --shadow-sm: 0 1px 3px rgba(0,0,0,0.3);
    --shadow-md: 0 4px 12px rgba(0,0,0,0.4);
    --shadow-lg: 0 10px 30px rgba(0,0,0,0.5);
}

/* ── Base ── */
html {
    font-size: 14px;
    position: relative;
    min-height: 100%;
}

@media (min-width: 768px) {
    html { font-size: 16px; }
}

body {
    font-family: var(--font-body);
    background-color: var(--color-bg);
    color: var(--color-text);
    margin-bottom: 60px;
    -webkit-text-size-adjust: 100%;
    line-height: 1.65;
    transition: background-color var(--transition-base), color var(--transition-base);
}

/* ── Typography ── */
h1, h2, h3, h4, h5, h6 {
    font-weight: 700;
    letter-spacing: -0.01em;
    line-height: 1.3;
    color: var(--color-text);
}

.text-muted { color: var(--color-text-secondary) !important; }
.text-tertiary { color: var(--color-text-tertiary); }

.section-subtitle {
    color: var(--color-text-secondary);
    font-size: 0.95rem;
    line-height: 1.6;
}

a { color: var(--color-primary); }
a:hover { color: var(--color-primary-hover); }

/* ── Focus ── */
.btn:focus, .btn:active:focus, .btn-link.nav-link:focus, .form-control:focus, .form-check-input:focus {
    box-shadow: 0 0 0 0.2rem rgba(var(--color-primary-rgb), 0.3);
}

/* ── Sidebar ── */
.sidebar {
    position: fixed;
    top: 0;
    left: 0;
    bottom: 0;
    width: 260px;
    background: var(--color-nav-bg);
    z-index: 1050;
    display: flex;
    flex-direction: column;
    transform: translateX(-100%);
    transition: transform var(--transition-base);
    border-right: 1px solid rgba(255,255,255,0.08);
}

.sidebar.open {
    transform: translateX(0);
}

.sidebar-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0.85rem 1rem;
    border-bottom: 1px solid rgba(255,255,255,0.08);
    flex-shrink: 0;
}

.sidebar-brand {
    color: var(--color-nav-text-active) !important;
    font-weight: 700;
    font-size: 1.1rem;
    letter-spacing: -0.02em;
    text-decoration: none;
}

.sidebar-brand:hover {
    color: var(--color-nav-text-active) !important;
    text-decoration: none;
}

.sidebar-pin {
    background: none;
    border: 1px solid rgba(255,255,255,0.15);
    color: var(--color-nav-text);
    border-radius: var(--radius-sm);
    padding: 0.3rem;
    cursor: pointer;
    transition: all var(--transition-fast);
    display: flex;
    align-items: center;
    justify-content: center;
    width: 30px;
    height: 30px;
}

.sidebar-pin:hover {
    background: rgba(255,255,255,0.12);
    color: var(--color-nav-text-active);
    border-color: rgba(255,255,255,0.3);
}

.sidebar-pin .pin-icon {
    transition: transform var(--transition-fast);
}

.sidebar-pin.pinned {
    background: rgba(255,255,255,0.15);
    color: var(--color-nav-text-active);
    border-color: rgba(255,255,255,0.3);
}

.sidebar-pin.pinned .pin-icon {
    transform: rotate(45deg);
}

.sidebar-nav {
    flex: 1;
    padding: 0.75rem 0.65rem;
    overflow-y: auto;
}

.sidebar-link {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    padding: 0.6rem 0.75rem;
    color: var(--color-nav-text) !important;
    font-weight: 500;
    font-size: 0.9rem;
    border-radius: var(--radius-sm);
    text-decoration: none;
    transition: color var(--transition-fast), background var(--transition-fast);
    margin-bottom: 2px;
}

.sidebar-link:hover,
.sidebar-link:focus {
    color: var(--color-nav-text-active) !important;
    background: rgba(255,255,255,0.1);
    text-decoration: none;
}

.sidebar-link.active {
    color: var(--color-nav-text-active) !important;
    background: rgba(255,255,255,0.12);
}

.sidebar-link svg {
    flex-shrink: 0;
    opacity: 0.7;
}

.sidebar-link:hover svg,
.sidebar-link.active svg {
    opacity: 1;
}

.sidebar-section {
    padding: 0.85rem 0.75rem 0.35rem;
    font-size: 0.7rem;
    font-weight: 700;
    letter-spacing: 0.06em;
    text-transform: uppercase;
    color: var(--color-nav-text);
    opacity: 0.55;
}

.sidebar-footer {
    padding: 0.75rem 0.65rem;
    border-top: 1px solid rgba(255,255,255,0.08);
    flex-shrink: 0;
}

.sidebar-user {
    display: flex;
    align-items: center;
    gap: 0.6rem;
    padding: 0.4rem 0.6rem 0.7rem;
    margin-bottom: 0.4rem;
    border-bottom: 1px solid rgba(255,255,255,0.08);
    min-width: 0;
}

.sidebar-user-avatar {
    flex-shrink: 0;
    width: 32px;
    height: 32px;
    border-radius: 50%;
    background: rgba(255,255,255,0.15);
    color: var(--color-nav-text-active);
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 0.75rem;
    font-weight: 700;
}

.sidebar-user-meta {
    display: flex;
    flex-direction: column;
    min-width: 0;
    line-height: 1.25;
}

.sidebar-user-name {
    color: var(--color-nav-text-active);
    font-size: 0.85rem;
    font-weight: 600;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.sidebar-user-email {
    color: var(--color-nav-text);
    font-size: 0.72rem;
    opacity: 0.7;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

/* Sidebar overlay (mobile) */
.sidebar-overlay {
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.5);
    z-index: 1040;
    opacity: 0;
    visibility: hidden;
    transition: opacity var(--transition-base), visibility var(--transition-base);
}

.sidebar-overlay.visible {
    opacity: 1;
    visibility: visible;
}

/* ── Top Bar ── */
.topbar {
    position: sticky;
    top: 0;
    z-index: 1030;
    display: flex;
    align-items: center;
    gap: 0.75rem;
    background: var(--color-nav-bg);
    padding: 0.55rem 1rem;
    border-bottom: 1px solid rgba(255,255,255,0.08);
    min-height: 50px;
}

.topbar-title {
    color: var(--color-nav-text-active);
    font-weight: 600;
    font-size: 0.95rem;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

/* Hamburger button */
.hamburger {
    background: none;
    border: none;
    cursor: pointer;
    padding: 6px;
    display: flex;
    flex-direction: column;
    gap: 4px;
    border-radius: var(--radius-sm);
    transition: background var(--transition-fast);
}

.hamburger:hover {
    background: rgba(255,255,255,0.1);
}

.hamburger-line {
    display: block;
    width: 20px;
    height: 2px;
    background: var(--color-nav-text-active);
    border-radius: 1px;
    transition: transform var(--transition-fast), opacity var(--transition-fast);
}

.hamburger.active .hamburger-line:nth-child(1) {
    transform: translateY(6px) rotate(45deg);
}

.hamburger.active .hamburger-line:nth-child(2) {
    opacity: 0;
}

.hamburger.active .hamburger-line:nth-child(3) {
    transform: translateY(-6px) rotate(-45deg);
}

/* ── Theme Toggle (in sidebar) ── */
.theme-toggle {
    background: none;
    border: 1px solid rgba(255,255,255,0.15);
    color: var(--color-nav-text);
    border-radius: var(--radius-sm);
    padding: 0.5rem 0.75rem;
    font-size: 0.85rem;
    cursor: pointer;
    transition: all var(--transition-fast);
    display: flex;
    align-items: center;
    gap: 0.5rem;
    width: 100%;
}

.theme-toggle:hover {
    background: rgba(255,255,255,0.12);
    color: var(--color-nav-text-active);
    border-color: rgba(255,255,255,0.3);
}

.theme-toggle .icon-sun,
.theme-toggle .icon-moon { display: none; }

.theme-toggle .theme-label-light,
.theme-toggle .theme-label-dark { display: none; font-weight: 500; }

:root .theme-toggle .icon-moon { display: inline; }
:root .theme-toggle .theme-label-light { display: inline; }
[data-theme="dark"] .theme-toggle .icon-sun { display: inline; }
[data-theme="dark"] .theme-toggle .icon-moon { display: none; }
[data-theme="dark"] .theme-toggle .theme-label-dark { display: inline; }
[data-theme="dark"] .theme-toggle .theme-label-light { display: none; }

/* ── Pinned sidebar on desktop ── */
@media (min-width: 768px) {
    .sidebar-pinned .sidebar {
        transform: translateX(0);
    }

    .sidebar-pinned .topbar {
        margin-left: 260px;
    }

    .sidebar-pinned .page-wrapper {
        margin-left: 260px;
    }

    .sidebar-pinned .sidebar-overlay {
        display: none;
    }
}

/* ── Cards ── */
.card {
    background: var(--color-surface);
    border: 1px solid var(--color-border);
    border-radius: var(--radius-lg);
    box-shadow: var(--shadow-sm);
    transition: background var(--transition-base), border-color var(--transition-base), box-shadow var(--transition-base);
}

.card-header {
    background: var(--color-surface) !important;
    border-bottom: 1px solid var(--color-border);
}

.card-elevated {
    box-shadow: var(--shadow-md);
}

/* ── Buttons ── */
.btn {
    border-radius: var(--radius-sm);
    font-weight: 600;
    letter-spacing: 0.01em;
    transition: all var(--transition-fast);
}

.btn-primary {
    background: var(--color-primary);
    border-color: var(--color-primary);
    color: #fff;
}

.btn-primary:hover, .btn-primary:focus {
    background: var(--color-primary-hover);
    border-color: var(--color-primary-hover);
    color: #fff;
    box-shadow: 0 4px 12px rgba(var(--color-primary-rgb), 0.35);
}

.btn-outline-primary {
    color: var(--color-primary);
    border-color: var(--color-primary);
}

.btn-outline-primary:hover {
    background: var(--color-primary);
    border-color: var(--color-primary);
    color: #fff;
}

.btn-outline-secondary {
    color: var(--color-text-secondary);
    border-color: var(--color-border);
}

.btn-outline-secondary:hover {
    background: var(--color-surface-hover);
    border-color: var(--color-border);
    color: var(--color-text);
}

[data-theme="dark"] .btn-outline-secondary:hover {
    background: var(--color-surface-hover);
    color: var(--color-text);
}

.btn-outline-dark {
    color: var(--color-text);
    border-color: var(--color-border);
}

.btn-outline-dark:hover {
    background: var(--color-text);
    border-color: var(--color-text);
    color: var(--color-surface);
}

.btn-success {
    background: #10b981;
    border-color: #10b981;
}

.btn-success:hover {
    background: #059669;
    border-color: #059669;
    box-shadow: 0 4px 12px rgba(16, 185, 129, 0.35);
}

/* ── Survey Options (touch-friendly) ── */
.survey-option {
    position: relative;
    padding: 0.8rem 1rem;
    padding-left: 1rem;
    margin-bottom: 0.5rem;
    border: 2px solid var(--color-border);
    border-radius: var(--radius-md);
    transition: all var(--transition-fast);
    min-height: 48px;
    display: flex;
    align-items: center;
    cursor: pointer;
    background: var(--color-surface);
}

/* Override Bootstrap .form-check positioning — we use flex instead */
.survey-option.form-check {
    padding-left: 1rem;
}

.survey-option .form-check-input {
    position: relative;
    z-index: 2;
    float: none;
    margin-left: 0;
    width: 1.25em;
    height: 1.25em;
    margin-top: 0;
    flex-shrink: 0;
    border-color: var(--color-border);
}

.survey-option:hover {
    background: var(--color-option-hover);
    border-color: rgba(var(--color-primary-rgb), 0.3);
    box-shadow: var(--shadow-sm);
}

.survey-option:active {
    background: var(--color-option-active);
    transform: scale(0.99);
}

.survey-option.selected,
.survey-option:has(.form-check-input:checked) {
    border-color: var(--color-option-selected-border);
    background: var(--color-option-selected-bg);
    box-shadow: 0 0 0 1px var(--color-option-selected-border);
}

.survey-option .form-check-input:checked {
    background-color: var(--color-primary);
    border-color: var(--color-primary);
}

.survey-option .form-check-label {
    position: static;
    padding-left: 0.35rem;
    flex: 1;
    cursor: pointer;
    font-weight: 450;
    color: var(--color-text);
}

.survey-option .form-check-input:checked ~ .form-check-label {
    font-weight: 600;
    color: var(--color-text);
}

/* Stretch label click area to fill the entire survey-option */
.survey-option .form-check-label::after {
    content: '';
    position: absolute;
    inset: 0;
    z-index: 1;
}

/* ── Form Controls ── */
.form-control, .form-select {
    background: var(--color-surface);
    border-color: var(--color-border);
    color: var(--color-text);
    border-radius: var(--radius-sm);
}

.form-control[readonly] {
    background: var(--color-surface-inset);
    color: var(--color-text);
    opacity: 1;
}

.form-control:focus, .form-select:focus {
    border-color: var(--color-primary);
    background: var(--color-surface);
    color: var(--color-text);
}

.form-label {
    font-weight: 600;
    color: var(--color-text);
    margin-bottom: 0.6rem;
    line-height: 1.5;
}

.form-text { color: var(--color-text-tertiary); }

/* ── Progress Bar ── */
.progress {
    background: var(--color-surface-inset);
    border-radius: 99px;
    overflow: hidden;
}

.progress-bar {
    transition: width 0.4s ease;
}

.progress-bar-primary {
    background: linear-gradient(90deg, var(--color-primary), #14b8a6);
}

/* ── Progress Dots ── */
.section-dots {
    gap: 2px;
}

.section-dot {
    width: 10px;
    height: 10px;
    border-radius: 50%;
    display: inline-block;
    flex-shrink: 0;
    transition: all var(--transition-fast);
}

@media (max-width: 575.98px) {
    .section-dot { width: 7px; height: 7px; }
}

.dot-complete {
    background-color: var(--color-primary);
}

.dot-current {
    background-color: var(--color-primary);
    box-shadow: 0 0 0 3px rgba(var(--color-primary-rgb), 0.25);
}

.dot-pending {
    background-color: var(--color-border);
}

/* ── Survey Navigation (sticky on mobile) ── */
.survey-nav {
    position: sticky;
    bottom: 0;
    background: var(--color-surface);
    margin-left: -1rem;
    margin-right: -1rem;
    margin-bottom: -1rem;
    padding: 0.75rem 1rem;
    border-top: 1px solid var(--color-border);
    z-index: 10;
}

@media (min-width: 768px) {
    .survey-nav {
        position: static;
        margin: 0;
        padding: 0;
        padding-top: 1rem;
        margin-top: 0.5rem;
        background: transparent;
        border-top: 1px solid var(--color-border);
    }
}

/* ── Driver Breakdown ── */
.driver-row {
    padding: 0.85rem 1rem;
    transition: background var(--transition-fast);
    border-bottom: 1px solid var(--color-border-light);
}

.driver-row:last-child { border-bottom: none; }

.driver-row:hover {
    background: var(--color-surface-hover);
}

.driver-name {
    font-weight: 600;
    color: var(--color-text);
}

.driver-desc {
    color: var(--color-text-secondary);
    font-size: 0.85rem;
}

@media (max-width: 575.98px) {
    .driver-desc {
        display: block;
        margin-top: 0.15rem;
        margin-left: 0;
    }
}

/* ── Primary Driver Card (gradient accent) ── */
.primary-driver-card {
    background: linear-gradient(135deg, var(--color-primary-subtle), var(--color-primary-light));
    border: 2px solid rgba(var(--color-primary-rgb), 0.2);
}

.primary-driver-card .driver-label {
    font-size: 0.8rem;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.08em;
    color: var(--color-primary);
}

.primary-driver-card .driver-value {
    font-size: 1.5rem;
    font-weight: 800;
    color: var(--color-text);
}

/* ── Score Badges ── */
.badge-score-high { background: var(--color-score-high); color: #fff; }
.badge-score-med  { background: var(--color-score-med);  color: #fff; }
.badge-score-low  { background: var(--color-score-low);  color: #fff; }
.badge-score-min  { background: var(--color-score-min);  color: #fff; }

.progress-score-high { background: var(--color-score-high); }
.progress-score-med  { background: var(--color-score-med); }
.progress-score-low  { background: var(--color-score-low); }
.progress-score-min  { background: var(--color-score-min); }

/* ── Stat Cards ── */
.stat-card {
    text-align: center;
    padding: 1rem;
}

.stat-value {
    font-size: 2rem;
    font-weight: 800;
    line-height: 1.1;
    color: var(--color-primary);
}

.stat-label {
    font-size: 0.8rem;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.06em;
    color: var(--color-text-secondary);
    margin-top: 0.25rem;
}

/* ── Info box ── */
.info-box {
    background: var(--color-surface-inset);
    border-radius: var(--radius-md);
    border: 1px solid var(--color-border);
}

/* ── Consent box ── */
.consent-box {
    background: var(--color-surface);
    border: 2px solid var(--color-border);
    border-radius: var(--radius-md);
}

/* ── Chart Containers ── */
.chart-container {
    position: relative;
    width: 100%;
}

/* ── Table ── */
.table { color: var(--color-text); }
.table th { color: var(--color-text-secondary); font-weight: 600; font-size: 0.8rem; text-transform: uppercase; letter-spacing: 0.04em; }
.table td { vertical-align: middle; }
.table-hover tbody tr:hover { background: var(--color-surface-hover); }
.table-light, .table-light th { background: var(--color-surface-inset) !important; color: var(--color-text-secondary) !important; }

/* ── Footer ── */
.footer {
    background: var(--color-surface);
    border-top: 1px solid var(--color-border);
    color: var(--color-text-secondary);
}

.footer a { color: var(--color-text-tertiary); }
.footer a:hover { color: var(--color-primary); }

/* ── Alert ── */
.alert-themed {
    background: var(--color-surface-inset);
    border: 1px solid var(--color-border);
    color: var(--color-text-secondary);
    border-radius: var(--radius-md);
}

/* ── Hero Section ── */
.hero-title {
    font-weight: 800;
    letter-spacing: -0.03em;
    background: linear-gradient(135deg, var(--color-primary), #14b8a6);
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    background-clip: text;
}

.feature-card {
    border: 1px solid var(--color-border);
    transition: all var(--transition-base);
}

.feature-card:hover {
    box-shadow: var(--shadow-md);
    border-color: rgba(var(--color-primary-rgb), 0.2);
    transform: translateY(-2px);
}

.feature-card .feature-title {
    color: var(--color-primary);
    font-weight: 700;
}

/* ── Responsive ── */
@media (max-width: 575.98px) {
    .container {
        padding-left: 1rem;
        padding-right: 1rem;
    }

    .display-5 { font-size: 1.75rem; }
    .display-6 { font-size: 1.5rem; }
    .lead { font-size: 1rem; }

    .action-buttons { flex-direction: column; }
    .action-buttons .btn { width: 100%; }

    .btn-mobile-full { display: block; width: 100%; }
}

/* ── Smooth transitions for theme switch ── */
body, .card, .card-header, .survey-option, .survey-nav,
.form-control, .form-select, .btn, .sidebar, .topbar, .footer,
.driver-row, .progress, .table, .alert-themed, .info-box {
    transition: background-color var(--transition-base),
                color var(--transition-base),
                border-color var(--transition-base),
                box-shadow var(--transition-base);
}

/* ── AI Insight Card ── */
.ai-insight-card {
    border-left: 3px solid var(--color-primary);
}

.ai-insight-text {
    color: var(--color-text);
    line-height: 1.75;
    font-size: 0.95rem;
}

.ai-insight-text p:last-child {
    margin-bottom: 0;
}

/* ── Selection highlight ── */
::selection {
    background: rgba(var(--color-primary-rgb), 0.2);
}
