/* ─────────────────────────────────────────
   IQ WORLD MAP · Usability-first redesign
   Prinzipien: System-Font, hoher Kontrast,
   klare Hierarchie, kein visuelles Rauschen
───────────────────────────────────────── */

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

:root {
  /* Farben */
  --text:         #111111;
  --text-mid:     #444444;
  --text-dim:     #767676;   /* WCAG AA konform auf weiß */
  --bg:           #ffffff;
  --bg-stripe:    #f6f7f8;
  --bg-hover:     #eef2fc;
  --bg-selected:  #dde8ff;
  --border:       #d0d5dd;
  --border-light: #e8eaed;
  --accent:       #1a4fa0;   /* Kontrast 7:1 auf weiß */
  --accent-light: #e8eef8;
  --red:          #b91c1c;

  /* Schrift */
  --font: system-ui, -apple-system, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  --font-mono: ui-monospace, "SF Mono", "Cascadia Mono", "Roboto Mono", monospace;

  /* Layout */
  --radius: 5px;
  --header-h: 52px;
}

html { scroll-behavior: smooth; }

body {
  font-family: var(--font);
  font-size: 16px;
  line-height: 1.5;
  color: var(--text);
  background: var(--bg);
  -webkit-font-smoothing: antialiased;
}

a { color: var(--accent); }
a:hover { text-decoration: underline; }

/* ══════ LOADING ══════ */

.loading-screen {
  position: fixed; inset: 0; z-index: 9999;
  background: #fff;
  display: flex; flex-direction: column;
  align-items: center; justify-content: center; gap: 12px;
  transition: opacity 0.3s;
}
.loading-screen.done { opacity: 0; pointer-events: none; }
.loading-title { font-size: 18px; font-weight: 600; color: var(--text); }
.loading-bar-wrap {
  width: 160px; height: 3px;
  background: var(--border-light); border-radius: 2px; overflow: hidden;
}
.loading-bar {
  height: 100%; background: var(--accent); border-radius: 2px;
  animation: loading-sweep 1s ease-in-out infinite;
}
@keyframes loading-sweep {
  0%   { width: 0;   margin-left: 0; }
  50%  { width: 50%; margin-left: 25%; }
  100% { width: 0;   margin-left: 100%; }
}
.loading-sub { font-size: 13px; color: var(--text-dim); }

/* ══════ HEADER ══════ */

.site-header {
  position: sticky; top: 0; z-index: 200;
  height: var(--header-h);
  background: #fff;
  border-bottom: 2px solid var(--text);
  display: flex; align-items: center;
  padding: 0 24px; gap: 16px;
}

.header-title {
  font-size: 17px;
  font-weight: 700;
  color: var(--text);
  letter-spacing: -0.01em;
  flex-shrink: 0;
}

.header-subtitle {
  font-size: 13px;
  color: var(--text-dim);
  flex: 1;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

/* Sprachumschalter */
.lang-switcher {
  display: flex; gap: 2px; flex-shrink: 0;
}

.lang-btn {
  font-family: var(--font);
  font-size: 13px;
  font-weight: 500;
  padding: 5px 11px;
  border: 1px solid var(--border);
  border-radius: 4px;
  background: transparent;
  color: var(--text-mid);
  cursor: pointer;
  transition: background 0.1s, color 0.1s, border-color 0.1s;
}
.lang-btn:hover {
  background: var(--bg-stripe);
  border-color: var(--text-mid);
  color: var(--text);
}
.lang-btn.active {
  background: var(--text);
  border-color: var(--text);
  color: #fff;
}

/* ══════ MAP-SEKTION ══════ */

.map-section {
  border-bottom: 1px solid var(--border);
  padding: 20px 24px 16px;
}

.map-section-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 10px;
  gap: 12px;
  flex-wrap: wrap;
}

.map-section-title {
  font-size: 13px;
  font-weight: 600;
  color: var(--text-mid);
  text-transform: uppercase;
  letter-spacing: 0.06em;
}

.map-hint {
  font-size: 13px;
  color: var(--text-dim);
}

.map-wrap {
  position: relative;
  background: #deeaf5;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  overflow: hidden;
  height: 460px;
}

#world-map { width: 100%; height: 100%; display: block; }

/* Länderkonturen */
.sphere-fill  { fill: #deeaf5; }
.sphere-stroke{ fill: none; stroke: #b0c8de; stroke-width: 0.7px; }
.graticule    { fill: none; stroke: rgba(80,130,180,0.12); stroke-width: 0.4px; }

.country {
  stroke: rgba(255,255,255,0.75);
  stroke-width: 0.4px;
  cursor: pointer;
  transition: stroke 0.1s, stroke-width 0.1s;
}
.country:hover       { stroke: #222; stroke-width: 1.2px; }
.country.no-data     { fill: #c8d0da; }
.country.selected    { stroke: #1a4fa0; stroke-width: 2px; }

/* Zoom-Buttons */
.zoom-controls {
  position: absolute; bottom: 12px; right: 12px;
  display: flex; flex-direction: column; gap: 3px;
}
.zoom-btn {
  width: 32px; height: 32px;
  background: rgba(255,255,255,0.95);
  border: 1px solid var(--border);
  border-radius: 4px;
  font-size: 16px; font-weight: 600;
  color: var(--text); cursor: pointer;
  display: flex; align-items: center; justify-content: center;
  box-shadow: 0 1px 3px rgba(0,0,0,0.12);
  transition: background 0.1s;
}
.zoom-btn:hover { background: var(--bg-stripe); }

/* Legende */
.legend-row {
  display: flex; align-items: center; gap: 8px;
  margin-top: 10px;
}
.legend-label { font-size: 12px; color: var(--text-dim); white-space: nowrap; }
.legend-bar {
  flex: 1; max-width: 240px; height: 8px; border-radius: 4px;
  background: linear-gradient(to right,
    #8b1a1a 0%, #c0392b 12%, #d35400 26%,
    #e67e22 38%, #f0b429 50%, #c8d800 56%,
    #52b788 68%, #27ae60 80%, #0d7a42 100%);
  border: 1px solid rgba(0,0,0,0.1);
}
.legend-ticks {
  display: flex; justify-content: space-between;
  font-size: 11px; color: var(--text-dim);
  max-width: 240px; /* match legend-bar max-width */
}

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

#tooltip {
  position: fixed; pointer-events: none; z-index: 500;
  opacity: 0; transition: opacity 0.1s;
}
#tooltip.visible { opacity: 1; }

.tooltip-inner {
  background: #fff;
  border: 1px solid var(--text);
  border-radius: var(--radius);
  box-shadow: 0 4px 16px rgba(0,0,0,0.18);
  padding: 12px 16px;
  min-width: 200px;
}

.tt-header {
  display: flex; align-items: center; gap: 8px;
  margin-bottom: 10px; padding-bottom: 10px;
  border-bottom: 1px solid var(--border-light);
}
.tt-flag { font-size: 22px; line-height: 1; }
.tt-name { font-size: 16px; font-weight: 700; color: var(--text); }

.tt-grid {
  display: grid; grid-template-columns: repeat(3, 1fr); gap: 12px;
}
.tt-cell-label {
  font-size: 11px; font-weight: 600;
  text-transform: uppercase; letter-spacing: 0.06em;
  color: var(--text-dim); margin-bottom: 2px;
}
.tt-cell-value {
  font-family: var(--font-mono);
  font-size: 20px; font-weight: 700;
  color: var(--text); line-height: 1;
}
.tt-cell-value.dimmed {
  font-size: 14px; font-weight: 400; color: var(--text-dim);
}

.tt-bar-wrap {
  margin-top: 10px; height: 4px;
  background: var(--border-light); border-radius: 2px; overflow: hidden;
}
.tt-bar { height: 100%; border-radius: 2px; }

.tt-rank-row {
  margin-top: 5px; font-size: 11px; color: var(--text-dim);
}

/* ══════ TABELLEN-SEKTION ══════ */

.table-section {
  padding: 28px 24px 40px;
}

.section-head {
  display: flex; align-items: center;
  justify-content: space-between;
  margin-bottom: 16px; gap: 16px; flex-wrap: wrap;
}

.section-title {
  font-size: 20px; font-weight: 700;
  color: var(--text); letter-spacing: -0.01em;
}

/* Suche */
.search-wrap { position: relative; }
.search-icon {
  position: absolute; left: 10px; top: 50%;
  transform: translateY(-50%);
  font-size: 15px; color: var(--text-dim); pointer-events: none;
}
.table-search {
  font-family: var(--font); font-size: 14px;
  padding: 8px 12px 8px 32px;
  border: 1px solid var(--border); border-radius: var(--radius);
  color: var(--text); background: var(--bg);
  width: 240px; outline: none;
  transition: border-color 0.15s, box-shadow 0.15s;
}
.table-search:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px rgba(26,79,160,0.1);
}
.table-search::placeholder { color: var(--text-dim); }

/* Tabelle */
.table-wrap {
  border: 1px solid var(--border);
  border-radius: var(--radius);
  overflow: hidden;
  /* Scroll auf kleinen Bildschirmen */
  overflow-x: auto;
}

table {
  width: 100%;
  border-collapse: collapse;
  font-size: 15px;
}

/* Sticky Header */
thead {
  position: sticky;
  top: var(--header-h);
  z-index: 10;
  background: var(--bg-stripe);
}

thead tr {
  border-bottom: 2px solid var(--border);
}

th {
  padding: 10px 14px;
  text-align: left;
  font-size: 12px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.07em;
  color: var(--text-mid);
  white-space: nowrap;
  cursor: pointer;
  user-select: none;
  vertical-align: bottom;
}
th:hover { color: var(--accent); }
th.sorted { color: var(--text); }

.th-main { display: block; }
.th-sub {
  display: block;
  font-size: 10px; font-weight: 400;
  text-transform: none; letter-spacing: 0.02em;
  color: var(--text-dim); margin-top: 1px;
}

.sort-icon { margin-left: 3px; font-style: normal; opacity: 0.4; }
th.sorted .sort-icon { opacity: 1; }

th.col-right, td.col-right { text-align: right; }

/* Tabellenzeilen */
tbody tr {
  border-bottom: 1px solid var(--border-light);
  cursor: pointer;
  transition: background 0.08s;
}
tbody tr:nth-child(even) { background: var(--bg-stripe); }
tbody tr:hover            { background: var(--bg-hover); }
tbody tr.row-selected     { background: var(--bg-selected) !important; }
tbody tr:last-child       { border-bottom: none; }

td { padding: 9px 14px; vertical-align: middle; }

/* Zellen */
.td-rank {
  text-align: right; width: 40px;
  font-family: var(--font-mono);
  font-size: 12px; color: var(--text-dim);
}

.td-country { display: flex; align-items: center; gap: 9px; }
.td-flag    { font-size: 18px; line-height: 1; flex-shrink: 0; }
.td-name    { font-weight: 500; color: var(--text); }

/* Zahlenzellen: immer Monospace, rechtsbündig, hoher Kontrast */
.td-num {
  text-align: right;
  font-family: var(--font-mono);
  font-size: 15px; font-weight: 600;
  color: var(--text);
  /* tabular-nums: alle Ziffern gleich breit → Spalten fluchten */
  font-variant-numeric: tabular-nums;
  white-space: nowrap;
}

/* IQ: farbiger Punkt als Indikator, Zahl selbst immer schwarz */
.td-iq {
  text-align: right;
  white-space: nowrap;
  font-family: var(--font-mono);
  font-size: 15px; font-weight: 600;
  color: var(--text);
  font-variant-numeric: tabular-nums;
}
.iq-dot {
  display: inline-block;
  width: 9px; height: 9px; border-radius: 50%;
  margin-right: 6px;
  vertical-align: middle;
  flex-shrink: 0;
}

/* Fehlende Daten: klar unterscheidbar */
.td-na {
  text-align: right;
  color: var(--text-dim);
  font-size: 14px;
}

/* ══════ QUELLEN ══════ */

.sources-section {
  background: var(--bg-stripe);
  border-top: 1px solid var(--border);
  padding: 40px 24px 48px;
}

.sources-inner { max-width: 800px; }

.sources-section .section-title { margin-bottom: 24px; }

.source-list {
  list-style: none;
  display: flex; flex-direction: column; gap: 1px;
  border: 1px solid var(--border); border-radius: var(--radius);
  overflow: hidden; margin-bottom: 24px;
}

.source-item {
  background: var(--bg);
  padding: 16px 20px;
  border-bottom: 1px solid var(--border-light);
  display: grid;
  grid-template-columns: 32px 1fr;
  gap: 14px;
  align-items: start;
}
.source-item:last-child { border-bottom: none; }

.source-num {
  font-family: var(--font-mono);
  font-size: 12px; font-weight: 700;
  color: var(--accent);
  padding-top: 2px;
}

.source-cite {
  font-size: 14px; font-weight: 600;
  color: var(--text); margin-bottom: 4px; line-height: 1.4;
}
.source-cite a {
  color: var(--accent); text-decoration: none;
  border-bottom: 1px solid rgba(26,79,160,0.3);
}
.source-cite a:hover { border-bottom-color: var(--accent); }

.source-desc {
  font-size: 13px; color: var(--text-mid); line-height: 1.6;
}

/* Hinweis-Boxen */
.info-box {
  border: 1px solid var(--border);
  border-left: 4px solid var(--accent);
  border-radius: var(--radius);
  padding: 16px 20px;
  background: var(--bg);
  margin-bottom: 12px;
}
.info-box h3 {
  font-size: 14px; font-weight: 700;
  color: var(--text); margin-bottom: 6px;
}
.info-box p {
  font-size: 13px; color: var(--text-mid); line-height: 1.7;
}

.warning-box {
  border: 1px solid #fca5a5;
  border-left: 4px solid var(--red);
  border-radius: var(--radius);
  padding: 16px 20px;
  background: #fef2f2;
}
.warning-box h3 {
  font-size: 14px; font-weight: 700;
  color: var(--red); margin-bottom: 6px;
}
.warning-box p {
  font-size: 13px; color: #7f1d1d; line-height: 1.7;
}

/* ══════ FOOTER ══════ */

.site-footer {
  border-top: 1px solid var(--border);
  padding: 14px 24px;
  font-size: 12px;
  color: var(--text-dim);
  display: flex; justify-content: space-between;
  align-items: center; gap: 12px; flex-wrap: wrap;
}

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

@media (max-width: 800px) {
  .site-header { padding: 0 16px; }
  .header-subtitle { display: none; }
  .map-section { padding: 14px 16px 12px; }
  .map-wrap { height: 280px; }
  .table-section { padding: 20px 16px 32px; }
  .sources-section { padding: 28px 16px 36px; }
  .table-search { width: 180px; }
  .site-footer { padding: 12px 16px; }
}

@media (max-width: 540px) {
  .map-wrap { height: 220px; }
  .lang-btn { padding: 4px 8px; }
  .section-head { flex-direction: column; align-items: flex-start; }
}
