/* ========================================================
   COVID-19 Tracker - Modernized CSS with Theme Switching
   Default: Bright / Light Mode
   ======================================================== */

:root {
    --font-sans: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
    
    /* Default: Bright / Light Theme */
    color-scheme: light;
    --bg-page: #f8fafc;
    --bg-surface: #ffffff;
    --bg-surface-secondary: #f1f5f9;
    --text-primary: #0f172a;
    --text-secondary: #475569;
    --text-muted: #64748b;
    --border-color: #e2e8f0;
    --border-subtle: #cbd5e1;
    --table-stripe: rgba(0, 0, 0, 0.02);
    --table-hover: rgba(2, 132, 199, 0.05);
    --chart-grid: rgba(0, 0, 0, 0.06);

    /* Semantic Status Colors */
    --color-confirmed: #0284c7;
    --color-confirmed-bg: #e0f2fe;
    --color-death: #ef4444;
    --color-death-bg: #fee2e2;
    --color-recovered: #10b981;
    --color-recovered-bg: #d1fae5;
    --color-warning: #f59e0b;
    --color-warning-bg: #fef3c7;
    --color-indigo: #6366f1;
    --color-indigo-bg: #e0e7ff;

    --radius-sm: 6px;
    --radius-md: 10px;
    --radius-lg: 16px;
    --radius-full: 9999px;

    --shadow-sm: 0 1px 2px 0 rgba(0, 0, 0, 0.05);
    --shadow-md: 0 4px 6px -1px rgba(0, 0, 0, 0.08), 0 2px 4px -2px rgba(0, 0, 0, 0.04);
    --shadow-lg: 0 10px 15px -3px rgba(0, 0, 0, 0.08), 0 4px 6px -4px rgba(0, 0, 0, 0.04);
}

/* Explicit Dark Mode (applied via data-theme or meta) */
:root[data-theme="dark"],
:root:has(> head > meta[name="color-scheme"][content="dark"]) {
    color-scheme: dark;
    --bg-page: #0b0f19;
    --bg-surface: #131b2e;
    --bg-surface-secondary: #1e293b;
    --text-primary: #f8fafc;
    --text-secondary: #cbd5e1;
    --text-muted: #94a3b8;
    --border-color: #27354f;
    --border-subtle: #334155;
    --table-stripe: rgba(255, 255, 255, 0.02);
    --table-hover: rgba(2, 132, 199, 0.12);
    --chart-grid: rgba(255, 255, 255, 0.07);

    --color-confirmed-bg: rgba(2, 132, 199, 0.18);
    --color-death-bg: rgba(239, 68, 68, 0.18);
    --color-recovered-bg: rgba(16, 185, 129, 0.18);
    --color-warning-bg: rgba(245, 158, 11, 0.18);
    --color-indigo-bg: rgba(99, 102, 241, 0.18);
}

*, *::before, *::after {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
}

body {
    font-family: var(--font-sans);
    background-color: var(--bg-page);
    color: var(--text-primary);
    line-height: 1.6;
    transition: background-color 0.25s ease, color 0.25s ease;
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
}

/* ========================================================
   HERO HEADER
   ======================================================== */
.hero-header {
    background: linear-gradient(135deg, #090d16 0%, #111827 50%, #0f172a 100%);
    color: #ffffff;
    padding: 48px 20px 42px;
    border-bottom: 1px solid rgba(255, 255, 255, 0.08);
    position: relative;
    overflow: hidden;
}

.hero-header::before {
    content: "";
    position: absolute;
    top: -50%;
    left: 50%;
    width: 600px;
    height: 400px;
    background: radial-gradient(circle, rgba(2, 132, 199, 0.18) 0%, transparent 70%);
    transform: translateX(-50%);
    pointer-events: none;
}

.hero-top-bar {
    display: flex;
    justify-content: space-between;
    align-items: center;
    max-width: 960px;
    margin: 0 auto 16px;
    flex-wrap: wrap;
    gap: 12px;
}

.badge-live {
    display: inline-flex;
    align-items: center;
    gap: 8px;
    background: rgba(16, 185, 129, 0.15);
    border: 1px solid rgba(16, 185, 129, 0.3);
    color: #34d399;
    padding: 5px 14px;
    border-radius: var(--radius-full);
    font-size: 0.75rem;
    font-weight: 600;
    letter-spacing: 0.05em;
    text-transform: uppercase;
}

.pulse-dot {
    width: 8px;
    height: 8px;
    background-color: #10b981;
    border-radius: 50%;
    box-shadow: 0 0 0 0 rgba(16, 185, 129, 0.7);
    animation: pulse 1.8s infinite;
}

@keyframes pulse {
    0% { transform: scale(0.95); box-shadow: 0 0 0 0 rgba(16, 185, 129, 0.7); }
    70% { transform: scale(1); box-shadow: 0 0 0 6px rgba(16, 185, 129, 0); }
    100% { transform: scale(0.95); box-shadow: 0 0 0 0 rgba(16, 185, 129, 0); }
}

/* Theme Switcher Button */
.btn-theme-toggle {
    display: inline-flex;
    align-items: center;
    gap: 8px;
    background: rgba(255, 255, 255, 0.1);
    backdrop-filter: blur(8px);
    border: 1px solid rgba(255, 255, 255, 0.18);
    color: #f1f5f9;
    padding: 6px 14px;
    border-radius: var(--radius-full);
    font-size: 0.85rem;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.2s ease;
}

.btn-theme-toggle:hover {
    background: rgba(255, 255, 255, 0.2);
    color: #ffffff;
    border-color: rgba(255, 255, 255, 0.35);
}

.btn-theme-toggle:focus-visible {
    outline: 2px solid #38bdf8;
    outline-offset: 2px;
}

.theme-icon-sun {
    display: none;
    color: #fbbf24;
}

.theme-icon-moon {
    display: inline-flex;
    color: #38bdf8;
}

:root[data-theme="dark"] .theme-icon-sun {
    display: inline-flex;
}

:root[data-theme="dark"] .theme-icon-moon {
    display: none;
}

.hero-title {
    font-size: 2.25rem;
    font-weight: 800;
    letter-spacing: -0.02em;
    margin-bottom: 12px;
    background: linear-gradient(180deg, #ffffff 0%, #cbd5e1 100%);
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
}

@media (max-width: 576px) {
    .hero-title {
        font-size: 1.75rem;
    }
}

.hero-subtitle {
    color: #94a3b8;
    font-size: 0.95rem;
    margin-bottom: 20px;
}

.last-updated-bar {
    display: inline-flex;
    align-items: center;
    gap: 10px;
    background: rgba(255, 255, 255, 0.07);
    backdrop-filter: blur(8px);
    border: 1px solid rgba(255, 255, 255, 0.12);
    padding: 6px 16px;
    border-radius: var(--radius-full);
    font-size: 0.85rem;
    color: #e2e8f0;
}

.btn-refresh {
    background: transparent;
    border: none;
    color: #38bdf8;
    cursor: pointer;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    padding: 4px;
    border-radius: 50%;
    transition: all 0.2s ease;
}

.btn-refresh:hover {
    color: #ffffff;
    background: rgba(255, 255, 255, 0.15);
    transform: rotate(45deg);
}

.refresh-icon-svg.spinning {
    animation: spin 0.8s linear infinite;
}

@keyframes spin {
    from { transform: rotate(0deg); }
    to { transform: rotate(360deg); }
}

/* ========================================================
   DASHBOARD SECTION & CARDS
   ======================================================== */
.dashboard-wrapper {
    margin-top: -24px;
    position: relative;
    z-index: 5;
    margin-bottom: 40px;
}

.dashboard-card-section {
    background-color: var(--bg-surface);
    border-radius: var(--radius-lg);
    border: 1px solid var(--border-color);
    box-shadow: var(--shadow-md);
    padding: 24px 20px;
    margin-bottom: 24px;
    transition: background-color 0.25s ease, border-color 0.25s ease;
}

.section-header-title {
    font-size: 1.25rem;
    font-weight: 700;
    color: var(--text-primary);
    margin-bottom: 20px;
    display: flex;
    align-items: center;
    gap: 10px;
}

.stats-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
    gap: 16px;
}

.stat-item {
    background-color: var(--bg-surface-secondary);
    border: 1px solid var(--border-color);
    border-radius: var(--radius-md);
    padding: 16px 12px;
    text-align: center;
    position: relative;
    transition: transform 0.2s ease, box-shadow 0.2s ease, background-color 0.25s ease;
}

.stat-item:hover {
    transform: translateY(-2px);
    box-shadow: var(--shadow-sm);
}

.stat-item.confirmed { border-top: 4px solid var(--color-confirmed); }
.stat-item.death { border-top: 4px solid var(--color-death); }
.stat-item.recovered { border-top: 4px solid var(--color-recovered); }
.stat-item.warning { border-top: 4px solid var(--color-warning); }
.stat-item.indigo { border-top: 4px solid var(--color-indigo); }

.stat-number {
    font-size: 1.75rem;
    font-weight: 800;
    line-height: 1.2;
    margin-bottom: 4px;
    font-variant-numeric: tabular-nums;
}

.stat-item.confirmed .stat-number { color: var(--color-confirmed); }
.stat-item.death .stat-number { color: var(--color-death); }
.stat-item.recovered .stat-number { color: var(--color-recovered); }
.stat-item.warning .stat-number { color: var(--color-warning); }
.stat-item.indigo .stat-number { color: var(--color-indigo); }

.diff-badge {
    display: inline-block;
    padding: 2px 8px;
    border-radius: var(--radius-full);
    font-size: 0.75rem;
    font-weight: 700;
    margin-bottom: 6px;
}

.badge-danger-soft {
    background-color: var(--color-death-bg);
    color: var(--color-death);
}

.badge-success-soft {
    background-color: var(--color-recovered-bg);
    color: var(--color-recovered);
}

.stat-label {
    font-size: 0.825rem;
    font-weight: 600;
    color: var(--text-secondary);
    text-transform: uppercase;
    letter-spacing: 0.04em;
    margin: 0;
}

.btn-terms-container {
    text-align: center;
    margin-top: 18px;
}

.btn-terms {
    background: none;
    border: none;
    color: var(--text-muted);
    font-size: 0.875rem;
    font-weight: 500;
    cursor: pointer;
    display: inline-flex;
    align-items: center;
    gap: 6px;
    transition: color 0.2s ease;
}

.btn-terms:hover {
    color: var(--color-confirmed);
    text-decoration: underline;
}

.dashboard-footer-info {
    text-align: center;
    font-size: 0.775rem;
    color: var(--text-muted);
    margin-top: 8px;
}

/* ========================================================
   TABS SECTION
   ======================================================== */
.nav-tabs-wrapper {
    display: flex;
    justify-content: center;
    margin-bottom: 24px;
}

.nav-tabs-pill.nav {
    display: inline-flex;
    flex-wrap: nowrap;
    background-color: var(--bg-surface-secondary);
    padding: 4px;
    border-radius: var(--radius-full);
    border: 1px solid var(--border-color);
    border-bottom: 1px solid var(--border-color) !important;
}

.nav-tabs-pill .tab-btn.nav-link {
    border: none !important;
    background: transparent;
    padding: 10px 24px;
    font-size: 0.95rem;
    font-weight: 600;
    color: var(--text-secondary);
    border-radius: var(--radius-full);
    cursor: pointer;
    display: inline-flex;
    align-items: center;
    gap: 8px;
    transition: all 0.25s ease;
    text-decoration: none !important;
}

.nav-tabs-pill .tab-btn.nav-link:hover {
    color: var(--text-primary);
    border: none !important;
    background: transparent;
}

.nav-tabs-pill .tab-btn.nav-link.active {
    background-color: var(--bg-surface) !important;
    color: var(--color-confirmed) !important;
    box-shadow: var(--shadow-sm);
    border: none !important;
}

/* ========================================================
   MAPS & TABLES
   ======================================================== */
.map-card {
    background-color: var(--bg-surface);
    border-radius: var(--radius-lg);
    border: 1px solid var(--border-color);
    box-shadow: var(--shadow-md);
    padding: 20px;
    margin-bottom: 30px;
    transition: background-color 0.25s ease, border-color 0.25s ease;
}

#map-world, #map-vn {
    max-width: 100%;
    margin: 0 auto;
    display: flex;
    justify-content: center;
}

.map-tooltip-content {
    padding: 4px 6px;
    font-size: 13px;
    line-height: 1.5;
}

.map-tooltip-title {
    font-size: 14px;
    font-weight: 700;
    color: #1e293b;
    display: block;
    border-bottom: 1px solid #e2e8f0;
    padding-bottom: 3px;
    margin-bottom: 4px;
}

:root[data-theme="dark"] .map-tooltip-title {
    color: #f8fafc;
    border-color: #334155;
}

/* Table Card & Responsive Wrapper */
.table-card {
    background-color: var(--bg-surface);
    border-radius: var(--radius-lg);
    border: 1px solid var(--border-color);
    box-shadow: var(--shadow-md);
    padding: 20px;
    margin-bottom: 40px;
    transition: background-color 0.25s ease, border-color 0.25s ease;
}

.table-filter-bar {
    margin-bottom: 16px;
}

.search-input-group {
    position: relative;
    max-width: 400px;
}

.search-input-group input {
    width: 100%;
    padding: 10px 16px 10px 38px;
    border-radius: var(--radius-full);
    border: 1px solid var(--border-color);
    background-color: var(--bg-surface-secondary);
    color: var(--text-primary);
    font-size: 0.9rem;
    transition: border-color 0.2s, box-shadow 0.2s, background-color 0.25s;
}

.search-input-group input::placeholder {
    color: var(--text-muted);
}

.search-input-group input:focus {
    outline: none;
    border-color: var(--color-confirmed);
    box-shadow: 0 0 0 3px rgba(2, 132, 199, 0.15);
}

.search-icon {
    position: absolute;
    left: 14px;
    top: 50%;
    transform: translateY(-50%);
    color: var(--text-muted);
    font-size: 0.9rem;
    pointer-events: none;
}

.table-wrapper {
    overflow-x: auto;
    max-height: 520px;
    border-radius: var(--radius-md);
    border: 1px solid var(--border-color);
}

.modern-table {
    width: 100%;
    margin-bottom: 0;
    border-collapse: separate;
    border-spacing: 0;
    font-size: 0.925rem;
}

.modern-table thead th {
    position: sticky;
    top: 0;
    z-index: 2;
    background-color: var(--bg-surface-secondary);
    color: var(--text-secondary);
    font-weight: 700;
    text-transform: uppercase;
    font-size: 0.75rem;
    letter-spacing: 0.05em;
    padding: 14px 16px;
    border-bottom: 2px solid var(--border-color);
    white-space: nowrap;
}

.modern-table tbody td, .modern-table tbody th {
    padding: 12px 16px;
    vertical-align: middle;
    border-bottom: 1px solid var(--border-color);
    color: var(--text-primary);
}

.modern-table tbody tr:nth-of-type(even) {
    background-color: var(--table-stripe);
}

.modern-table tbody tr:hover {
    background-color: var(--table-hover);
}

.country-flag {
    border-radius: 2px;
    box-shadow: 0 1px 2px rgba(0,0,0,0.15);
    object-fit: cover;
}

.btn-more-container {
    text-align: center;
    padding: 16px 0 4px;
}

.btn-more {
    padding: 10px 28px;
    border-radius: var(--radius-full);
    font-weight: 600;
    font-size: 0.875rem;
    border: 1px solid var(--color-confirmed);
    color: var(--color-confirmed);
    background: transparent;
    transition: all 0.2s ease;
    cursor: pointer;
}

.btn-more:hover {
    background-color: var(--color-confirmed);
    color: #ffffff;
}

/* ========================================================
   CHARTS SECTION
   ======================================================== */
.chart-section {
    margin-bottom: 50px;
}

.chart-card {
    background-color: var(--bg-surface);
    border-radius: var(--radius-lg);
    border: 1px solid var(--border-color);
    box-shadow: var(--shadow-md);
    padding: 24px;
    margin-bottom: 30px;
    height: 400px;
    position: relative;
    transition: background-color 0.25s ease, border-color 0.25s ease;
}

/* ========================================================
   MODAL DIALOG
   ======================================================== */
.modal-content {
    background-color: var(--bg-surface);
    border-radius: var(--radius-lg);
    border: 1px solid var(--border-color);
    box-shadow: var(--shadow-lg);
    color: var(--text-primary);
}

.modal-header {
    border-bottom: 1px solid var(--border-color);
    padding: 18px 24px;
}

.modal-title {
    font-weight: 700;
    font-size: 1.15rem;
}

.modal-body {
    padding: 24px;
    font-size: 0.925rem;
    line-height: 1.7;
    color: var(--text-secondary);
}

.modal-body h6 {
    color: var(--text-primary);
    font-weight: 700;
    margin-top: 14px;
    margin-bottom: 8px;
}

.modal-footer {
    border-top: 1px solid var(--border-color);
    padding: 14px 24px;
}

/* ========================================================
   FOOTER
   ======================================================== */
.site-footer {
    background-color: #0b0f19;
    color: #64748b;
    padding: 40px 20px 24px;
    font-size: 0.875rem;
    border-top: 1px solid rgba(255, 255, 255, 0.05);
}

.site-footer a {
    color: #94a3b8;
    text-decoration: none;
    transition: color 0.2s ease;
}

.site-footer a:hover {
    color: #38bdf8;
}

.social-circle {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 36px;
    height: 36px;
    border-radius: 50%;
    background-color: rgba(255, 255, 255, 0.05);
    color: #94a3b8;
    margin: 0 4px;
    transition: all 0.2s ease;
}

.social-circle:hover {
    background-color: #38bdf8;
    color: #ffffff;
    transform: translateY(-2px);
}
