/**
 * carte-engine.css — Theme system + layout components for interactive maps
 * Default: Light theme | Themes: light, dark, ocean, satellite, print
 */

/* ══════════════════════════════════════════
   THEMES — CSS Variables
   ══════════════════════════════════════════ */

/* Light (default) */
:root,
[data-theme="light"] {
    --bg-deep: #f8fafc;
    --bg-card: #ffffff;
    --bg-surface: #f1f5f9;
    --border: #e2e8f0;
    --text: #1e293b;
    --text-dim: #64748b;
    --accent: #f97316;
    --accent-glow: #ea580c;
    --lava: #dc2626;
    --lava-glow: #b91c1c;
    --tectonic: #0891b2;
    --ocean: #e0f2fe;
    --land: #cbd5e1;
    --land-stroke: #94a3b8;
    --dormant: #d97706;
    --extinct: #6b7280;
    --active: #dc2626;
    --tooltip-shadow: rgba(0,0,0,0.12);
    --map-hover: #a8b8cc;
}

/* Dark */
[data-theme="dark"] {
    --bg-deep: #0a0e1a;
    --bg-card: #111827;
    --bg-surface: #1a2234;
    --border: #1e3a5f;
    --text: #e2e8f0;
    --text-dim: #64748b;
    --accent: #f97316;
    --accent-glow: #ff6b00;
    --lava: #ef4444;
    --lava-glow: #dc2626;
    --tectonic: #06b6d4;
    --ocean: #0c1929;
    --land: #1a2e44;
    --land-stroke: #2a4060;
    --dormant: #fbbf24;
    --extinct: #6b7280;
    --active: #ef4444;
    --tooltip-shadow: rgba(0,0,0,0.5);
    --map-hover: #243b56;
}

/* Ocean */
[data-theme="ocean"] {
    --bg-deep: #0c1929;
    --bg-card: #0f2942;
    --bg-surface: #133557;
    --border: #1e4976;
    --text: #e0f2fe;
    --text-dim: #7dd3fc;
    --accent: #38bdf8;
    --accent-glow: #0ea5e9;
    --lava: #f87171;
    --lava-glow: #ef4444;
    --tectonic: #22d3ee;
    --ocean: #082035;
    --land: #164e63;
    --land-stroke: #1e6b85;
    --dormant: #fbbf24;
    --extinct: #6b7280;
    --active: #f87171;
    --tooltip-shadow: rgba(0,0,0,0.5);
    --map-hover: #1c6b8a;
}

/* Satellite */
[data-theme="satellite"] {
    --bg-deep: #1a1a0e;
    --bg-card: #2a2a1c;
    --bg-surface: #33331f;
    --border: #4a4a30;
    --text: #e8e8d0;
    --text-dim: #a0a080;
    --accent: #84cc16;
    --accent-glow: #65a30d;
    --lava: #ef4444;
    --lava-glow: #dc2626;
    --tectonic: #06b6d4;
    --ocean: #0a1a0a;
    --land: #2d4a2d;
    --land-stroke: #3d5a3d;
    --dormant: #fbbf24;
    --extinct: #6b7280;
    --active: #ef4444;
    --tooltip-shadow: rgba(0,0,0,0.5);
    --map-hover: #3a6a3a;
}

/* Print */
[data-theme="print"] {
    --bg-deep: #ffffff;
    --bg-card: #ffffff;
    --bg-surface: #f9fafb;
    --border: #d1d5db;
    --text: #111827;
    --text-dim: #6b7280;
    --accent: #ea580c;
    --accent-glow: #c2410c;
    --lava: #dc2626;
    --lava-glow: #b91c1c;
    --tectonic: #0891b2;
    --ocean: #f0f9ff;
    --land: #e5e7eb;
    --land-stroke: #9ca3af;
    --dormant: #d97706;
    --extinct: #6b7280;
    --active: #dc2626;
    --tooltip-shadow: rgba(0,0,0,0.1);
    --map-hover: #d1d5db;
}

/* ══════════════════════════════════════════
   RESET & BASE
   ══════════════════════════════════════════ */

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

body {
    font-family: 'Outfit', sans-serif;
    background: var(--bg-deep);
    color: var(--text);
    overflow-x: hidden;
    transition: background 0.3s, color 0.3s;
}

/* ══════════════════════════════════════════
   HEADER (stripped by wrapper, kept for standalone)
   ══════════════════════════════════════════ */

.site-header {
    background: var(--bg-card);
    border-bottom: 1px solid var(--border);
    padding: 0 24px;
    height: 56px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    position: sticky;
    top: 0;
    z-index: 100;
}
.site-header .logo {
    display: flex;
    align-items: center;
    gap: 10px;
    font-weight: 700;
    font-size: 16px;
    color: var(--text);
    text-decoration: none;
}
.site-header .logo span { font-size: 24px; }
.site-header nav { display: flex; gap: 4px; align-items: center; }
.site-header nav a {
    color: var(--text-dim);
    text-decoration: none;
    font-size: 13px;
    font-weight: 500;
    padding: 6px 12px;
    border-radius: 6px;
    transition: all 0.2s;
}
.site-header nav a:hover { color: var(--text); background: var(--bg-surface); }
.site-header nav a.active { color: var(--accent); background: rgba(249,115,22,0.1); }

/* Theme Picker (in standalone header) */
.theme-picker {
    display: flex;
    gap: 5px;
    margin-left: 12px;
    padding: 4px 8px;
    background: var(--bg-surface);
    border-radius: 20px;
    border: 1px solid var(--border);
}
.theme-dot {
    width: 16px;
    height: 16px;
    border-radius: 50%;
    cursor: pointer;
    transition: all 0.2s;
    border: 2px solid transparent;
}
.theme-dot[data-theme="dark"] { background: #1e293b; }
.theme-dot[data-theme="light"] { background: #f8fafc; border-color: #e2e8f0; }
.theme-dot[data-theme="ocean"] { background: #0c4a6e; }
.theme-dot[data-theme="satellite"] { background: #365314; }
.theme-dot[data-theme="print"] { background: #fff; border-color: #d1d5db; }
.theme-dot:hover { transform: scale(1.2); }
.theme-dot.active { border-color: var(--accent); box-shadow: 0 0 8px rgba(249,115,22,0.4); }

/* ══════════════════════════════════════════
   BREADCRUMB (stripped by wrapper)
   ══════════════════════════════════════════ */

.breadcrumb {
    padding: 12px 24px;
    font-size: 12px;
    color: var(--text-dim);
    max-width: 1400px;
    margin: 0 auto;
}
.breadcrumb a { color: var(--text-dim); text-decoration: none; }
.breadcrumb a:hover { color: var(--accent); }

/* ══════════════════════════════════════════
   HERO TITLE
   ══════════════════════════════════════════ */

.hero-title {
    max-width: 1400px;
    margin: 0 auto;
    padding: 0 24px 20px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    flex-wrap: wrap;
    gap: 16px;
}
.hero-title h1 {
    font-size: 28px;
    font-weight: 800;
    letter-spacing: -0.5px;
    display: flex;
    align-items: center;
    gap: 12px;
    flex-wrap: wrap;
}
.hero-title h1 .emoji { font-size: 32px; }
.hero-title h1 .highlight { color: var(--accent); }
.badge-count {
    font-family: 'JetBrains Mono', monospace;
    font-size: 14px;
    font-weight: 600;
}
.badge-live {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    background: rgba(239,68,68,0.12);
    color: var(--lava);
    font-size: 11px;
    font-weight: 600;
    padding: 4px 10px;
    border-radius: 20px;
    font-family: 'JetBrains Mono', monospace;
}
.badge-live::before {
    content: '';
    width: 6px;
    height: 6px;
    border-radius: 50%;
    background: var(--lava);
    animation: pulse 1.5s ease infinite;
}
@keyframes pulse {
    0%, 100% { opacity: 1; box-shadow: 0 0 0 0 rgba(239,68,68,0.4); }
    50% { opacity: 0.6; box-shadow: 0 0 0 6px rgba(239,68,68,0); }
}

/* ══════════════════════════════════════════
   STATS BAR
   ══════════════════════════════════════════ */

.stats-bar {
    max-width: 1400px;
    margin: 0 auto 16px;
    padding: 0 24px;
    display: flex;
    gap: 24px;
    flex-wrap: wrap;
}
.stat-item {
    display: flex;
    align-items: center;
    gap: 8px;
    font-size: 13px;
    color: var(--text-dim);
}
.stat-item .num {
    font-family: 'JetBrains Mono', monospace;
    font-weight: 600;
    font-size: 15px;
    color: var(--text);
}
.stat-item.active .num { color: var(--lava); }
.stat-item.dormant .num { color: var(--dormant); }
.stat-item.extinct .num { color: var(--extinct); }

/* ══════════════════════════════════════════
   CONTROLS / FILTERS
   ══════════════════════════════════════════ */

.controls {
    max-width: 1400px;
    margin: 0 auto 12px;
    padding: 0 24px;
    display: flex;
    align-items: center;
    gap: 8px;
    flex-wrap: wrap;
}
.filter-btn {
    background: var(--bg-surface);
    border: 1px solid var(--border);
    color: var(--text-dim);
    font-family: 'Outfit', sans-serif;
    font-size: 12px;
    font-weight: 500;
    padding: 6px 14px;
    border-radius: 20px;
    cursor: pointer;
    transition: all 0.2s;
    display: flex;
    align-items: center;
    gap: 5px;
}
.filter-btn:hover { border-color: var(--accent); color: var(--text); }
.filter-btn.active { background: rgba(249,115,22,0.12); border-color: var(--accent); color: var(--accent); }
.filter-btn .dot {
    width: 8px;
    height: 8px;
    border-radius: 50%;
}

.separator { width: 1px; height: 20px; background: var(--border); margin: 0 4px; }

.toggle-check {
    display: flex;
    align-items: center;
    gap: 6px;
    font-size: 12px;
    color: var(--text-dim);
    cursor: pointer;
    padding: 5px 10px;
    border-radius: 6px;
    transition: all 0.2s;
}
.toggle-check:hover { color: var(--text); background: var(--bg-surface); }
.toggle-check .cbox {
    width: 16px;
    height: 16px;
    border: 1px solid var(--border);
    border-radius: 3px;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 10px;
    color: var(--accent);
    background: var(--bg-card);
}

/* ══════════════════════════════════════════
   MAP CONTAINER
   ══════════════════════════════════════════ */

.map-wrapper {
    max-width: 1400px;
    margin: 0 auto;
    padding: 0 24px;
}
.map-container {
    background: var(--ocean);
    border-radius: 16px;
    border: 1px solid var(--border);
    overflow: hidden;
    position: relative;
    cursor: grab;
    min-height: 500px;
    aspect-ratio: 2 / 1;
}
.map-container:active { cursor: grabbing; }
.map-container svg {
    display: block;
    width: 100%;
    height: 100%;
    min-height: inherit;
}

/* D3 Map styles */
.country,
.country-data {
    fill: var(--land);
    stroke: var(--land-stroke);
    stroke-width: 0.4;
    transition: fill 0.2s, stroke 0.2s;
    cursor: pointer;
}
.country:hover,
.country-data:hover { fill: var(--map-hover); stroke: var(--accent); stroke-width: 0.8; }
.country-data.dimmed { opacity: 0.2; }

.graticule {
    fill: none;
    stroke: var(--border);
    stroke-width: 0.3;
    opacity: 0.3;
}

.tectonic-line {
    fill: none;
    stroke: var(--tectonic);
    stroke-width: 1.2;
    stroke-dasharray: 6 3;
    opacity: 0.5;
}
.tectonic-line.hidden { display: none; }

/* ══════════════════════════════════════════
   TOOLTIP
   ══════════════════════════════════════════ */

.tooltip {
    position: fixed;
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: 10px;
    padding: 14px 16px;
    font-size: 13px;
    pointer-events: none;
    opacity: 0;
    transition: opacity 0.15s;
    z-index: 200;
    min-width: 220px;
    box-shadow: 0 10px 30px var(--tooltip-shadow);
}
.tooltip.visible, .tooltip.show { opacity: 1; }
.tooltip .t-name, .tip-name {
    font-weight: 700;
    font-size: 15px;
    margin-bottom: 2px;
    display: flex;
    align-items: center;
    gap: 6px;
}
.tooltip .t-sub, .tip-sub { color: var(--text-dim); font-size: 12px; margin-bottom: 8px; }
.tooltip .t-row, .t-row, .tip-row {
    display: flex;
    justify-content: space-between;
    padding: 3px 0;
    border-top: 1px solid var(--border);
}
.tooltip .t-label, .t-label, .tip-row .tl { color: var(--text-dim); }
.tooltip .t-value, .t-value, .tip-row .tv {
    font-family: 'JetBrains Mono', monospace;
    font-weight: 600;
    font-size: 12px;
}
.tooltip .t-badge, .t-badge, .tip-status {
    display: inline-flex;
    align-items: center;
    gap: 5px;
    font-size: 11px;
    font-weight: 600;
    padding: 2px 8px;
    border-radius: 10px;
    margin-top: 4px;
}

/* Sidebar (country detail panel) */
.sidebar {
    position: fixed;
    top: 0;
    right: 0;
    width: 380px;
    max-width: 90vw;
    height: 100vh;
    background: var(--bg-card);
    border-left: 1px solid var(--border);
    transform: translateX(100%);
    transition: transform 0.3s ease;
    z-index: 300;
    overflow-y: auto;
    box-shadow: -5px 0 30px var(--tooltip-shadow);
}
.sidebar.open { transform: translateX(0); }
.sidebar-overlay {
    position: fixed;
    inset: 0;
    background: rgba(0,0,0,0.3);
    z-index: 299;
    display: none;
}
.sidebar-overlay.visible { display: block; }
.sidebar-header {
    padding: 20px;
    border-bottom: 1px solid var(--border);
    display: flex;
    align-items: flex-start;
    justify-content: space-between;
}
.sidebar-emoji { font-size: 40px; }
.sidebar-title { font-size: 18px; font-weight: 700; }
.sidebar-subtitle { font-size: 13px; color: var(--text-dim); margin-top: 2px; }
.sidebar-badge {
    display: inline-block;
    padding: 2px 10px;
    border-radius: 20px;
    font-size: 11px;
    font-weight: 600;
    margin-top: 4px;
}
.sidebar-close {
    background: var(--bg-surface);
    border: 1px solid var(--border);
    color: var(--text);
    width: 32px;
    height: 32px;
    border-radius: 8px;
    cursor: pointer;
    font-size: 16px;
    display: flex;
    align-items: center;
    justify-content: center;
}
.sidebar-close:hover { border-color: var(--accent); color: var(--accent); }
.sidebar-section { padding: 16px 20px; }
.sidebar-section-title {
    font-size: 10px;
    font-weight: 700;
    color: var(--text-dim);
    text-transform: uppercase;
    letter-spacing: 1px;
    margin-bottom: 10px;
}
.sidebar-row {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 6px 0;
    font-size: 13px;
    border-bottom: 1px solid var(--border);
}
.sidebar-row:last-child { border-bottom: none; }
.sidebar-divider { height: 1px; background: var(--border); }
.sidebar-links { padding: 16px 20px; }
.sidebar-link {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 8px 12px;
    border-radius: 8px;
    color: var(--text);
    text-decoration: none;
    font-size: 13px;
    transition: all 0.2s;
}
.sidebar-link:hover { background: var(--bg-surface); }
.sidebar-link .link-icon { font-size: 16px; }
.sidebar-link .link-arrow { margin-left: auto; color: var(--text-dim); }

/* ══════════════════════════════════════════
   DOWNLOAD BAR
   ══════════════════════════════════════════ */

.download-bar {
    max-width: 1400px;
    margin: 16px auto 0;
    padding: 0 24px;
}
.download-inner {
    background: var(--bg-surface);
    border: 1px solid var(--border);
    border-radius: 12px;
    padding: 16px 20px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    flex-wrap: wrap;
    gap: 12px;
}
.download-label {
    font-size: 14px;
    font-weight: 600;
    display: flex;
    align-items: center;
    gap: 8px;
}
.download-buttons { display: flex; gap: 8px; flex-wrap: wrap; }
.dl-btn {
    background: var(--bg-card);
    border: 1px solid var(--border);
    color: var(--text);
    font-family: 'Outfit', sans-serif;
    font-size: 12px;
    font-weight: 600;
    padding: 8px 16px;
    border-radius: 8px;
    cursor: pointer;
    transition: all 0.2s;
    display: flex;
    align-items: center;
    gap: 6px;
}
.dl-btn:hover { border-color: var(--accent); color: var(--accent); background: rgba(249,115,22,0.06); }
.dl-btn .icon { font-size: 14px; }
.dl-btn.primary {
    background: var(--accent);
    border-color: var(--accent);
    color: white;
}
.dl-btn.primary:hover { background: var(--accent-glow); }
.dl-btn.ultra {
    background: linear-gradient(135deg, var(--accent), var(--accent-glow));
    border-color: var(--accent);
    color: white;
}
.dl-btn.ultra:hover { filter: brightness(1.1); }

.dl-options {
    display: flex;
    gap: 16px;
    font-size: 12px;
    color: var(--text-dim);
}
.dl-options label { display: flex; align-items: center; gap: 5px; cursor: pointer; }
.dl-options input[type="checkbox"] {
    accent-color: var(--accent);
    width: 14px;
    height: 14px;
}

/* ══════════════════════════════════════════
   LEGEND
   ══════════════════════════════════════════ */

.legend-section {
    max-width: 1400px;
    margin: 20px auto;
    padding: 0 24px;
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(300px, 1fr));
    gap: 12px;
}
.legend-card {
    background: var(--bg-surface);
    border: 1px solid var(--border);
    border-radius: 12px;
    padding: 16px;
}
.legend-card h3 {
    font-size: 13px;
    font-weight: 600;
    margin-bottom: 10px;
    color: var(--text-dim);
    text-transform: uppercase;
    letter-spacing: 1px;
}
.legend-items { display: flex; flex-wrap: wrap; gap: 12px; }
.legend-item {
    display: flex;
    align-items: center;
    gap: 8px;
    font-size: 13px;
}
.legend-dot {
    width: 10px;
    height: 10px;
    border-radius: 50%;
    flex-shrink: 0;
}
.legend-line {
    width: 24px;
    height: 2px;
    flex-shrink: 0;
    border-top: 2px dashed;
}

/* ══════════════════════════════════════════
   SEO CONTENT
   ══════════════════════════════════════════ */

.seo-content {
    max-width: 1400px;
    margin: 40px auto;
    padding: 0 24px;
}
.seo-inner {
    background: var(--bg-surface);
    border: 1px solid var(--border);
    border-radius: 16px;
    padding: 32px;
}
.seo-inner h2 {
    font-size: 22px;
    font-weight: 700;
    margin-bottom: 16px;
}
.seo-inner h3 {
    font-size: 16px;
    font-weight: 600;
    margin: 20px 0 8px;
    color: var(--accent);
}
.seo-inner p {
    font-size: 14px;
    line-height: 1.7;
    color: var(--text-dim);
    margin-bottom: 12px;
}
.seo-inner a { color: var(--tectonic); text-decoration: none; }
.seo-inner a:hover { text-decoration: underline; }

/* ══════════════════════════════════════════
   FOOTER (stripped by wrapper)
   ══════════════════════════════════════════ */

.site-footer {
    border-top: 1px solid var(--border);
    padding: 24px;
    text-align: center;
    font-size: 12px;
    color: var(--text-dim);
    margin-top: 40px;
}

/* ══════════════════════════════════════════
   ZOOM CONTROLS
   ══════════════════════════════════════════ */

.zoom-controls, .zoom-info {
    position: absolute;
    bottom: 12px;
    right: 12px;
    display: flex;
    gap: 4px;
    z-index: 10;
}
.zoom-btn {
    width: 32px;
    height: 32px;
    border-radius: 8px;
    background: var(--bg-card);
    border: 1px solid var(--border);
    color: var(--text);
    font-size: 16px;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all 0.2s;
}
.zoom-btn:hover { border-color: var(--accent); color: var(--accent); }

/* ══════════════════════════════════════════
   PRINT
   ══════════════════════════════════════════ */

@media print {
    body { background: white !important; color: black !important; }
    .site-header, .controls, .download-bar, .site-footer, .breadcrumb,
    .legend-section, .seo-content, .stats-bar, .zoom-controls, .zoom-info,
    .theme-picker { display: none !important; }
    .map-container { border: 1px solid #ccc !important; border-radius: 0 !important; }
    .country, .country-data { fill: #e5e7eb !important; stroke: #9ca3af !important; }
    .hero-title { padding: 12px 0 !important; }
    .hero-title h1 { color: black !important; font-size: 20px !important; }
    .print-header { display: block !important; text-align: center; margin-bottom: 8px; }
    @page { size: A4 landscape; margin: 1cm; }
}
.print-header { display: none; }

/* ══════════════════════════════════════════
   RESPONSIVE
   ══════════════════════════════════════════ */

@media (max-width: 768px) {
    .hero-title h1 { font-size: 20px; }
    .hero-title { padding: 0 16px 12px; }
    .site-header nav { display: none; }
    .download-inner { flex-direction: column; align-items: flex-start; }
    .stats-bar { gap: 12px; padding: 0 16px; }
    .legend-section { grid-template-columns: 1fr; padding: 0 16px; }
    .controls { padding: 0 16px; }
    .map-wrapper { padding: 0 12px; }
    .seo-inner { padding: 20px; }
    .sidebar { width: 100vw; }
}
