/* ===== FONTS ===== */
@import url('https://api.fontshare.com/v2/css?f[]=satoshi@400,500,700&f[]=cabinet-grotesk@700,800&display=swap');

:root {
  --font-body: 'Satoshi', 'Helvetica Neue', sans-serif;
  --font-display: 'Cabinet Grotesk', 'Satoshi', sans-serif;

  /* Type Scale */
  --text-xs:   clamp(0.75rem,  0.7rem  + 0.25vw, 0.875rem);
  --text-sm:   clamp(0.875rem, 0.8rem  + 0.35vw, 1rem);
  --text-base: clamp(1rem,     0.95rem + 0.25vw, 1.125rem);
  --text-lg:   clamp(1.125rem, 1rem    + 0.75vw, 1.5rem);
  --text-xl:   clamp(1.5rem,   1.2rem  + 1.25vw, 2.25rem);

  /* Spacing */
  --space-1:  0.25rem;
  --space-2:  0.5rem;
  --space-3:  0.75rem;
  --space-4:  1rem;
  --space-5:  1.25rem;
  --space-6:  1.5rem;
  --space-8:  2rem;
  --space-10: 2.5rem;
  --space-12: 3rem;
  --space-16: 4rem;
  --space-20: 5rem;

  /* Radius */
  --radius-sm: 0.375rem;
  --radius-md: 0.5rem;
  --radius-lg: 0.75rem;
  --radius-xl: 1rem;
  --radius-full: 9999px;

  --transition-interactive: 180ms cubic-bezier(0.16, 1, 0.3, 1);
  --content-wide: 1280px;
}

/* ===== LIGHT MODE (Warm Temple Palette) ===== */
:root, [data-theme="light"] {
  --color-bg:             #faf8f5;
  --color-surface:        #ffffff;
  --color-surface-2:      #f5f2ed;
  --color-surface-offset: #eee9e2;
  --color-divider:        #e0d8ce;
  --color-border:         #d4cbbf;

  --color-text:           #2c1810;
  --color-text-muted:     #7a6b5d;
  --color-text-faint:     #b5a899;
  --color-text-inverse:   #faf8f5;

  --color-primary:        #b8450e;
  --color-primary-hover:  #963a0c;
  --color-primary-active: #752e09;
  --color-primary-light:  #fde8dd;

  --color-accent:         #1a6b52;
  --color-accent-light:   #e0f0ea;

  --color-gold:           #c49000;
  --color-gold-light:     #fef3d4;

  --color-blue:           #1e5f8a;
  --color-purple:         #6b3fa0;
  --color-teal:           #0e7b7b;

  --shadow-sm: 0 1px 3px rgba(44,24,16,0.06);
  --shadow-md: 0 4px 12px rgba(44,24,16,0.08);
  --shadow-lg: 0 12px 32px rgba(44,24,16,0.1);
}

/* ===== DARK MODE ===== */
[data-theme="dark"] {
  --color-bg:             #1a1512;
  --color-surface:        #231d18;
  --color-surface-2:      #2c2520;
  --color-surface-offset: #352d27;
  --color-divider:        #3d342d;
  --color-border:         #4a3f37;

  --color-text:           #e8ddd4;
  --color-text-muted:     #9a8b7d;
  --color-text-faint:     #6b5d52;
  --color-text-inverse:   #1a1512;

  --color-primary:        #e8743e;
  --color-primary-hover:  #f08a58;
  --color-primary-active: #f5a070;
  --color-primary-light:  #3a2518;

  --color-accent:         #3db88e;
  --color-accent-light:   #1e2d27;

  --color-gold:           #e8b840;
  --color-gold-light:     #2d2718;

  --color-blue:           #5a9bc5;
  --color-purple:         #a878d8;
  --color-teal:           #3ababa;

  --shadow-sm: 0 1px 3px rgba(0,0,0,0.2);
  --shadow-md: 0 4px 12px rgba(0,0,0,0.3);
  --shadow-lg: 0 12px 32px rgba(0,0,0,0.35);
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme]) {
    --color-bg: #1a1512; --color-surface: #231d18; --color-surface-2: #2c2520;
    --color-surface-offset: #352d27; --color-divider: #3d342d; --color-border: #4a3f37;
    --color-text: #e8ddd4; --color-text-muted: #9a8b7d; --color-text-faint: #6b5d52;
    --color-text-inverse: #1a1512;
    --color-primary: #e8743e; --color-primary-hover: #f08a58; --color-primary-active: #f5a070;
    --color-primary-light: #3a2518;
    --color-accent: #3db88e; --color-accent-light: #1e2d27;
    --color-gold: #e8b840; --color-gold-light: #2d2718;
    --color-blue: #5a9bc5; --color-purple: #a878d8; --color-teal: #3ababa;
    --shadow-sm: 0 1px 3px rgba(0,0,0,0.2); --shadow-md: 0 4px 12px rgba(0,0,0,0.3);
    --shadow-lg: 0 12px 32px rgba(0,0,0,0.35);
  }
}

/* ===== LAYOUT ===== */
.app-shell {
  display: flex;
  flex-direction: column;
  min-height: 100dvh;
}

.app-header {
  position: sticky;
  top: 0;
  z-index: 100;
  background: var(--color-surface);
  border-bottom: 1px solid var(--color-divider);
  padding: var(--space-3) var(--space-6);
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--space-4);
  backdrop-filter: blur(12px);
  background: color-mix(in srgb, var(--color-surface) 85%, transparent);
}

.logo-area {
  display: flex;
  align-items: center;
  gap: var(--space-3);
}

.logo-area svg { flex-shrink: 0; }

.logo-text {
  font-family: var(--font-display);
  font-size: var(--text-lg);
  font-weight: 700;
  color: var(--color-text);
  line-height: 1.1;
}

.logo-text span {
  display: block;
  font-size: var(--text-xs);
  font-family: var(--font-body);
  font-weight: 400;
  color: var(--color-text-muted);
  letter-spacing: 0.04em;
}

.header-actions {
  display: flex;
  align-items: center;
  gap: var(--space-2);
}

.lang-toggle, .theme-toggle {
  padding: var(--space-1) var(--space-2);
  border-radius: var(--radius-sm);
  font-size: var(--text-xs);
  color: var(--color-text-muted);
  background: var(--color-surface-2);
  border: 1px solid var(--color-border);
  font-weight: 500;
}

.lang-toggle:hover, .theme-toggle:hover {
  color: var(--color-text);
  background: var(--color-surface-offset);
}

.lang-toggle.active {
  color: var(--color-primary);
  background: var(--color-primary-light);
  border-color: var(--color-primary);
}

/* ===== NAV TABS ===== */
.nav-tabs {
  display: flex;
  gap: var(--space-1);
  padding: var(--space-2) var(--space-6);
  background: var(--color-surface);
  border-bottom: 1px solid var(--color-divider);
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
}

.nav-tab {
  padding: var(--space-2) var(--space-4);
  border-radius: var(--radius-md);
  font-size: var(--text-sm);
  font-weight: 500;
  color: var(--color-text-muted);
  white-space: nowrap;
  position: relative;
}

.nav-tab:hover { color: var(--color-text); background: var(--color-surface-2); }

.nav-tab.active {
  color: var(--color-primary);
  background: var(--color-primary-light);
}

/* ===== MAIN CONTENT ===== */
.main-content {
  flex: 1;
  padding: var(--space-6);
  max-width: var(--content-wide);
  margin: 0 auto;
  width: 100%;
}

.section { display: none; }
.section.active { display: block; }

/* ===== KPI CARDS ===== */
.kpi-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
  gap: var(--space-4);
  margin-bottom: var(--space-8);
}

.kpi-card {
  background: var(--color-surface);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-lg);
  padding: var(--space-5);
  display: flex;
  flex-direction: column;
  gap: var(--space-1);
}

.kpi-label {
  font-size: var(--text-xs);
  color: var(--color-text-muted);
  text-transform: uppercase;
  letter-spacing: 0.06em;
  font-weight: 500;
}

.kpi-value {
  font-family: var(--font-display);
  font-size: var(--text-xl);
  font-weight: 800;
  color: var(--color-text);
  font-variant-numeric: tabular-nums lining-nums;
}

.kpi-sub {
  font-size: var(--text-xs);
  color: var(--color-text-faint);
}

/* ===== CHART CONTAINERS ===== */
.chart-grid {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: var(--space-6);
  margin-bottom: var(--space-8);
}

.chart-card {
  background: var(--color-surface);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-lg);
  padding: var(--space-5);
  overflow: hidden;
}

.chart-card.full-width {
  grid-column: 1 / -1;
}

.chart-title {
  font-family: var(--font-display);
  font-size: var(--text-lg);
  font-weight: 700;
  color: var(--color-text);
  margin-bottom: var(--space-1);
}

.chart-subtitle {
  font-size: var(--text-xs);
  color: var(--color-text-muted);
  margin-bottom: var(--space-4);
}

.chart-wrapper {
  position: relative;
  width: 100%;
}

.chart-wrapper canvas {
  width: 100% !important;
  max-height: 340px;
}

/* ===== MAP ===== */
.map-container {
  width: 100%;
  height: 520px;
  border-radius: var(--radius-lg);
  overflow: hidden;
  border: 1px solid var(--color-border);
}

.map-legend {
  display: flex;
  gap: var(--space-4);
  margin-top: var(--space-3);
  font-size: var(--text-xs);
  color: var(--color-text-muted);
}

.map-legend-item {
  display: flex;
  align-items: center;
  gap: var(--space-1);
}

.map-legend-dot {
  width: 10px;
  height: 10px;
  border-radius: var(--radius-full);
}

/* ===== DATA TABLE ===== */
.table-wrapper {
  overflow-x: auto;
  border: 1px solid var(--color-border);
  border-radius: var(--radius-lg);
  background: var(--color-surface);
}

.data-table {
  font-size: var(--text-sm);
  font-variant-numeric: tabular-nums lining-nums;
}

.data-table th {
  background: var(--color-surface-2);
  padding: var(--space-3) var(--space-4);
  text-align: left;
  font-weight: 600;
  color: var(--color-text);
  font-size: var(--text-xs);
  text-transform: uppercase;
  letter-spacing: 0.04em;
  border-bottom: 2px solid var(--color-divider);
  position: sticky;
  top: 0;
  cursor: pointer;
  white-space: nowrap;
  user-select: none;
}

.data-table th:hover { background: var(--color-surface-offset); }

.data-table td {
  padding: var(--space-2) var(--space-4);
  border-bottom: 1px solid var(--color-divider);
  color: var(--color-text);
}

.data-table tr:hover td {
  background: var(--color-surface-2);
}

.heritage-badge {
  display: inline-block;
  padding: 2px 8px;
  border-radius: var(--radius-full);
  font-size: var(--text-xs);
  font-weight: 600;
}

.heritage-badge.yes {
  background: var(--color-accent-light);
  color: var(--color-accent);
}

.heritage-badge.no {
  background: var(--color-surface-2);
  color: var(--color-text-faint);
}

.bar-cell {
  display: flex;
  align-items: center;
  gap: var(--space-2);
}

.bar-cell .bar {
  height: 6px;
  border-radius: var(--radius-full);
  background: var(--color-primary);
  transition: width 0.5s ease;
}

/* ===== INSIGHTS ===== */
.insight-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(280px, 1fr));
  gap: var(--space-4);
  margin-bottom: var(--space-6);
}

.insight-card {
  background: var(--color-surface);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-lg);
  padding: var(--space-5);
}

.insight-card h4 {
  font-size: var(--text-sm);
  font-weight: 700;
  color: var(--color-primary);
  margin-bottom: var(--space-2);
  display: flex;
  align-items: center;
  gap: var(--space-2);
}

.insight-card p {
  font-size: var(--text-sm);
  color: var(--color-text-muted);
  line-height: 1.6;
}

.stat-highlight {
  font-weight: 700;
  color: var(--color-text);
}

/* ===== FOOTER ===== */
.app-footer {
  text-align: center;
  padding: var(--space-6);
  font-size: var(--text-xs);
  color: var(--color-text-faint);
  border-top: 1px solid var(--color-divider);
}

.app-footer a {
  color: var(--color-text-muted);
  text-decoration: none;
}

.app-footer a:hover { color: var(--color-primary); }

/* ===== RESPONSIVE ===== */
@media (max-width: 768px) {
  .app-header { padding: var(--space-2) var(--space-3); }
  .nav-tabs { padding: var(--space-2) var(--space-3); }
  .main-content { padding: var(--space-4) var(--space-3); }
  .chart-grid { grid-template-columns: 1fr; }
  .kpi-grid { grid-template-columns: repeat(2, 1fr); }
  .map-container { height: 360px; }
  .logo-text { font-size: var(--text-base); }
  .logo-text span { display: none; }
}

@media (max-width: 480px) {
  .kpi-grid { grid-template-columns: 1fr; }
}

/* ===== ANIMATIONS ===== */
@keyframes fadeUp {
  from { opacity: 0; transform: translateY(12px); }
  to { opacity: 1; transform: translateY(0); }
}

.fade-up {
  animation: fadeUp 0.5s cubic-bezier(0.16, 1, 0.3, 1) both;
}

.chart-card { animation: fadeUp 0.5s cubic-bezier(0.16, 1, 0.3, 1) both; }
.chart-card:nth-child(1) { animation-delay: 0.05s; }
.chart-card:nth-child(2) { animation-delay: 0.1s; }
.chart-card:nth-child(3) { animation-delay: 0.15s; }
.chart-card:nth-child(4) { animation-delay: 0.2s; }

/* ===== SEARCH ===== */
.search-bar {
  display: flex;
  align-items: center;
  gap: var(--space-2);
  background: var(--color-surface);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-md);
  padding: var(--space-2) var(--space-3);
  margin-bottom: var(--space-4);
  max-width: 400px;
}

.search-bar input {
  border: none;
  outline: none;
  background: none;
  font-size: var(--text-sm);
  width: 100%;
}

.search-bar svg { color: var(--color-text-muted); flex-shrink: 0; }

/* Scrollbar */
::-webkit-scrollbar { width: 6px; height: 6px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: var(--color-border); border-radius: 3px; }
::-webkit-scrollbar-thumb:hover { background: var(--color-text-faint); }
