/* ==========================================================================
   臺南市人口推估儀表板 (2026-2075) - DayNight Design System
   Snow Edition (Light) & Carbon Edition (Dark)
   ========================================================================== */

@import url('https://fonts.googleapis.com/css2?family=DM+Sans:ital,opsz,wght@0,9..40,100..1000;1,9..40,100..1000&family=Noto+Sans+TC:wght@300;400;500;600;700;900&family=JetBrains+Mono:wght@400;500;600&display=swap');

/* --- Root Design Tokens (Snow Light Theme Default) --- */
:root {
    --bg-base: #F8FAFC;
    --bg-surface: #FFFFFF;
    --bg-surface-elevated: #FFFFFF;
    --bg-muted: #F1F5F9;
    --border-subtle: #E2E8F0;
    --border-strong: #CBD5E1;
    
    --text-main: #0F172A;
    --text-muted: #475569;
    --text-subtle: #64748B;
    
    --primary: #0284C7;
    --primary-hover: #0369A1;
    --primary-subtle: #E0F2FE;
    
    --male: #2563EB;
    --male-subtle: #DBEAFE;
    --female: #EC4899;
    --female-subtle: #FCE7F3;
    
    --young: #10B981;
    --young-subtle: #D1FAE5;
    --working: #0284C7;
    --working-subtle: #E0F2FE;
    --elderly: #F59E0B;
    --elderly-subtle: #FEF3C7;
    --super-elderly: #DC2626;
    --super-elderly-subtle: #FEE2E2;

    --success: #10B981;
    --warning: #F59E0B;
    --danger: #EF4444;
    
    --radius-sm: 6px;
    --radius-md: 10px;
    --radius-lg: 16px;
    
    --shadow-sm: 0 1px 2px 0 rgba(0, 0, 0, 0.05);
    --shadow-md: 0 4px 6px -1px rgba(0, 0, 0, 0.07), 0 2px 4px -2px rgba(0, 0, 0, 0.05);
    --shadow-lg: 0 10px 15px -3px rgba(0, 0, 0, 0.08), 0 4px 6px -4px rgba(0, 0, 0, 0.04);
    
    --transition: all 0.25s cubic-bezier(0.16, 1, 0.3, 1);
    --header-height: 72px;
}

/* --- Carbon Dark Mode --- */
html.carbon {
    --bg-base: #090D16;
    --bg-surface: #111827;
    --bg-surface-elevated: #1F2937;
    --bg-muted: #1E293B;
    --border-subtle: #273549;
    --border-strong: #374151;
    
    --text-main: #F8FAFC;
    --text-muted: #94A3B8;
    --text-subtle: #64748B;
    
    --primary: #38BDF8;
    --primary-hover: #7DD3FC;
    --primary-subtle: rgba(56, 189, 248, 0.15);
    
    --male: #60A5FA;
    --male-subtle: rgba(96, 165, 250, 0.15);
    --female: #F472B6;
    --female-subtle: rgba(244, 114, 182, 0.15);
    
    --young: #34D399;
    --young-subtle: rgba(52, 211, 153, 0.15);
    --working: #38BDF8;
    --working-subtle: rgba(56, 189, 248, 0.15);
    --elderly: #FBBF24;
    --elderly-subtle: rgba(251, 191, 36, 0.15);
    --super-elderly: #F87171;
    --super-elderly-subtle: rgba(248, 113, 113, 0.15);

    --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 12px 24px rgba(0, 0, 0, 0.5);
}

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

[v-cloak], .anti-fouc {
    display: none !important;
}

body {
    font-family: 'DM Sans', 'Noto Sans TC', -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
    background-color: var(--bg-base);
    color: var(--text-main);
    line-height: 1.5;
    -webkit-font-smoothing: antialiased;
    transition: background-color 0.25s ease, color 0.25s ease;
    overflow-x: hidden;
}

/* Sticky Header Scroll Margin Offset (Constitutional Clause 1.2) */
section, article, [id] {
    scroll-margin-top: calc(var(--header-height) + 20px);
}

/* --- Header & Top Navigation --- */
.header-nav {
    position: sticky;
    top: 0;
    z-index: 1000;
    height: var(--header-height);
    background-color: var(--bg-surface);
    border-bottom: 1px solid var(--border-subtle);
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0 2rem;
    box-shadow: var(--shadow-sm);
    backdrop-filter: blur(12px);
}

.brand-wrapper {
    display: flex;
    align-items: center;
    gap: 0.85rem;
}

.brand-badge {
    background-color: var(--primary-subtle);
    color: var(--primary);
    font-size: 0.75rem;
    font-weight: 700;
    padding: 0.25rem 0.6rem;
    border-radius: var(--radius-sm);
    letter-spacing: 0.05em;
}

.brand-title {
    font-size: 1.15rem;
    font-weight: 700;
    color: var(--text-main);
    display: flex;
    align-items: center;
    gap: 0.5rem;
}

.brand-subtitle {
    font-size: 0.8rem;
    color: var(--text-muted);
    font-weight: 500;
}

.nav-actions {
    display: flex;
    align-items: center;
    gap: 1rem;
}

.theme-toggle-btn, .btn-secondary, .btn-primary {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 0.5rem;
    padding: 0.5rem 1rem;
    border-radius: var(--radius-sm);
    font-size: 0.875rem;
    font-weight: 600;
    cursor: pointer;
    transition: var(--transition);
    border: 1px solid var(--border-subtle);
    background-color: var(--bg-surface-elevated);
    color: var(--text-main);
}

.btn-primary {
    background-color: var(--primary);
    color: #FFFFFF;
    border-color: var(--primary);
}

.btn-primary:hover {
    background-color: var(--primary-hover);
}

.btn-secondary:hover {
    background-color: var(--bg-muted);
    border-color: var(--border-strong);
}

.export-dropdown-menu {
    position: absolute;
    top: calc(100% + 8px);
    right: 0;
    width: 320px;
    background-color: var(--bg-surface);
    border: 1px solid var(--border-subtle);
    border-radius: var(--radius-md);
    box-shadow: var(--shadow-lg);
    z-index: 1100;
    padding: 0.5rem;
    display: flex;
    flex-direction: column;
    gap: 0.35rem;
}

.export-item {
    display: flex;
    flex-direction: column;
    padding: 0.6rem 0.75rem;
    border-radius: var(--radius-sm);
    text-decoration: none;
    color: var(--text-main);
    transition: var(--transition);
}

.export-item:hover {
    background-color: var(--primary-subtle);
}

.export-item strong {
    font-size: 0.825rem;
    color: var(--primary);
}

.export-item span {
    font-size: 0.725rem;
    color: var(--text-muted);
    margin-top: 0.15rem;
}

/* --- Main Layout --- */
.container {
    max-width: 1560px;
    margin: 0 auto;
    padding: 1.5rem 2rem 4rem 2rem;
}

/* --- Control Bar (Sticky Scenario & Time Travel Controller) --- */
.controller-card {
    background-color: var(--bg-surface);
    border: 1px solid var(--border-subtle);
    border-radius: var(--radius-md);
    padding: 1.25rem 1.5rem;
    margin-bottom: 1.5rem;
    box-shadow: var(--shadow-sm);
    display: flex;
    flex-direction: column;
    gap: 1.25rem;
}

.controller-row {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    justify-content: space-between;
    gap: 1rem;
}

.scenario-group {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    background-color: var(--bg-muted);
    padding: 0.25rem;
    border-radius: var(--radius-sm);
    border: 1px solid var(--border-subtle);
}

.scenario-btn {
    padding: 0.4rem 1rem;
    border-radius: var(--radius-sm);
    font-size: 0.85rem;
    font-weight: 600;
    border: none;
    background: transparent;
    color: var(--text-muted);
    cursor: pointer;
    transition: var(--transition);
}

.scenario-btn.active {
    background-color: var(--bg-surface);
    color: var(--primary);
    box-shadow: var(--shadow-sm);
}

.district-select-wrapper {
    display: flex;
    align-items: center;
    gap: 0.6rem;
}

.custom-select {
    padding: 0.45rem 1.75rem 0.45rem 0.85rem;
    border-radius: var(--radius-sm);
    border: 1px solid var(--border-strong);
    background-color: var(--bg-surface);
    color: var(--text-main);
    font-size: 0.875rem;
    font-weight: 600;
    cursor: pointer;
    outline: none;
}

/* --- Timeline Slider Bar --- */
.timeline-box {
    display: flex;
    align-items: center;
    gap: 1.25rem;
    width: 100%;
    background-color: var(--bg-muted);
    padding: 0.75rem 1.25rem;
    border-radius: var(--radius-sm);
}

.timeline-play-btn {
    width: 36px;
    height: 36px;
    border-radius: 50%;
    border: none;
    background-color: var(--primary);
    color: white;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    transition: var(--transition);
    flex-shrink: 0;
}

.timeline-play-btn:hover {
    transform: scale(1.05);
}

.timeline-slider-wrap {
    flex: 1;
    display: flex;
    flex-direction: column;
    gap: 0.35rem;
}

.slider-label-row {
    display: flex;
    justify-content: space-between;
    font-size: 0.75rem;
    font-weight: 600;
    color: var(--text-subtle);
}

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

.year-slider::-webkit-slider-thumb {
    -webkit-appearance: none;
    appearance: none;
    width: 18px;
    height: 18px;
    border-radius: 50%;
    background: var(--primary);
    cursor: pointer;
    box-shadow: 0 0 0 3px var(--primary-subtle);
    transition: transform 0.15s ease;
}

.year-slider::-webkit-slider-thumb:hover {
    transform: scale(1.2);
}

.current-year-badge {
    font-family: 'JetBrains Mono', monospace;
    font-size: 1.25rem;
    font-weight: 800;
    color: var(--primary);
    min-width: 90px;
    text-align: right;
}

/* --- KPI Summary Metric Cards Grid --- */
.kpi-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
    gap: 1rem;
    margin-bottom: 1.5rem;
}

.kpi-card {
    background-color: var(--bg-surface);
    border: 1px solid var(--border-subtle);
    border-radius: var(--radius-md);
    padding: 1.25rem;
    box-shadow: var(--shadow-sm);
    display: flex;
    flex-direction: column;
    gap: 0.4rem;
    position: relative;
    overflow: hidden;
}

.kpi-card::before {
    content: '';
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    height: 3px;
    background-color: var(--primary);
}

.kpi-card.kpi-young::before { background-color: var(--young); }
.kpi-card.kpi-working::before { background-color: var(--working); }
.kpi-card.kpi-elderly::before { background-color: var(--elderly); }
.kpi-card.kpi-super-elderly::before { background-color: var(--super-elderly); }

.kpi-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
}

.kpi-title {
    font-size: 0.825rem;
    font-weight: 600;
    color: var(--text-muted);
}

.kpi-tag {
    font-size: 0.7rem;
    font-weight: 700;
    padding: 0.15rem 0.45rem;
    border-radius: 4px;
    background-color: var(--bg-muted);
    color: var(--text-subtle);
}

.kpi-value {
    font-family: 'JetBrains Mono', monospace;
    font-size: 1.75rem;
    font-weight: 800;
    color: var(--text-main);
}

.kpi-footer {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    font-size: 0.775rem;
    color: var(--text-subtle);
}

/* --- Dashboard Grid Sections --- */
.dashboard-grid {
    display: grid;
    grid-template-columns: repeat(12, 1fr);
    gap: 1.5rem;
    margin-bottom: 1.5rem;
}

.col-12 { grid-column: span 12; }
.col-8 { grid-column: span 8; }
.col-6 { grid-column: span 6; }
.col-4 { grid-column: span 4; }

.card {
    background-color: var(--bg-surface);
    border: 1px solid var(--border-subtle);
    border-radius: var(--radius-md);
    box-shadow: var(--shadow-sm);
    display: flex;
    flex-direction: column;
    overflow: hidden;
}

.card-header {
    padding: 1rem 1.25rem;
    border-bottom: 1px solid var(--border-subtle);
    display: flex;
    align-items: center;
    justify-content: space-between;
}

.card-title-group {
    display: flex;
    align-items: center;
    gap: 0.6rem;
}

.card-icon {
    width: 28px;
    height: 28px;
    border-radius: var(--radius-sm);
    background-color: var(--primary-subtle);
    color: var(--primary);
    display: flex;
    align-items: center;
    justify-content: center;
}

.card-title {
    font-size: 1rem;
    font-weight: 700;
    color: var(--text-main);
}

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

.card-body {
    padding: 1.25rem;
    flex: 1;
    position: relative;
}

/* --- Chart Containers --- */
.chart-container {
    position: relative;
    width: 100%;
    height: 380px;
}

.chart-container-sm {
    position: relative;
    width: 100%;
    height: 280px;
}

/* --- Map Container --- */
#district-map {
    width: 100%;
    height: 480px;
    min-height: 480px;
    border-radius: var(--radius-sm);
    z-index: 10;
    background-color: var(--bg-muted);
}

.custom-map-tooltip {
    background-color: var(--bg-surface) !important;
    border: 1px solid var(--border-subtle) !important;
    border-radius: var(--radius-sm) !important;
    box-shadow: var(--shadow-md) !important;
    color: var(--text-main) !important;
}

.map-legend {
    background-color: var(--bg-surface);
    padding: 0.75rem 1rem;
    border-radius: var(--radius-sm);
    border: 1px solid var(--border-subtle);
    font-size: 0.75rem;
    line-height: 1.4;
    box-shadow: var(--shadow-md);
    color: var(--text-main);
    backdrop-filter: blur(8px);
}

.legend-item {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    margin-top: 0.25rem;
}

.legend-color {
    width: 14px;
    height: 14px;
    border-radius: 2px;
}

/* --- Simulation Sandbox Card --- */
.sandbox-card {
    background: linear-gradient(135deg, var(--bg-surface) 0%, var(--bg-muted) 100%);
    border: 1px solid var(--primary);
}

.sandbox-controls {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(240px, 1fr));
    gap: 1.25rem;
    margin-bottom: 1rem;
}

.control-item {
    display: flex;
    flex-direction: column;
    gap: 0.35rem;
}

.control-label {
    display: flex;
    justify-content: space-between;
    font-size: 0.8rem;
    font-weight: 600;
    color: var(--text-main);
}

/* --- Data Table --- */
.table-responsive {
    width: 100%;
    overflow-x: auto;
}

.data-table {
    width: 100%;
    border-collapse: collapse;
    font-size: 0.85rem;
    text-align: right;
}

.data-table th, .data-table td {
    padding: 0.6rem 0.85rem;
    border-bottom: 1px solid var(--border-subtle);
}

.data-table th {
    background-color: var(--bg-muted);
    color: var(--text-muted);
    font-weight: 700;
    text-align: right;
    position: sticky;
    top: 0;
}

.data-table th:first-child, .data-table td:first-child {
    text-align: left;
    font-weight: 600;
}

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

/* --- Footer --- */
.footer-bar {
    margin-top: 3rem;
    padding: 2rem;
    border-top: 1px solid var(--border-subtle);
    background-color: var(--bg-surface);
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    justify-content: space-between;
    gap: 1rem;
    font-size: 0.8rem;
    color: var(--text-muted);
}

/* --- Responsive Adjustments --- */
@media (max-width: 1024px) {
    .col-8, .col-6, .col-4 { grid-column: span 12; }
    .container { padding: 1rem; }
    .header-nav { padding: 0 1rem; }
}

@media print {
    .header-nav, .controller-card, .timeline-box, .nav-actions { display: none !important; }
    body { background: white; color: black; }
    .card { border: 1px solid #ccc; box-shadow: none; page-break-inside: avoid; }
}
