:root {
  --bg: #f4f5f6;
  --panel-bg: #ffffff;
  --panel-bg-soft: #eef1f4;
  --border: #d7dde3;
  --text: #1a1d21;
  --muted: #5b6572;
  --accent: #154273;
  --accent-strong: #01689b;
  --accent-fill: #154273;
  --accent-soft: #e6edf4;
  --green: #007a3d;
  --orange: #e17000;
  --red: #d52b1e;
  --unknown: #6b7280;
  --focus: #fdc700;
  --header-bg: #154273;
  --header-text: #ffffff;
  --shadow: 0 1px 2px rgba(15, 23, 42, 0.06);
  --shadow-sm: 0 1px 2px rgba(15, 23, 42, 0.05);
  --radius: 6px;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #14171a;
    --panel-bg: #1c2024;
    --panel-bg-soft: #21262c;
    --border: #333a41;
    --text: #eceef0;
    --muted: #9aa3ad;
    --accent: #7aa8d1;
    --accent-strong: #8fc1e8;
    --accent-fill: #2f6690;
    --accent-soft: #1e2c3a;
    --green: #2fa966;
    --orange: #f0923a;
    --red: #f0776c;
    --unknown: #838d99;
    --focus: #fdc700;
    --header-bg: #0d2440;
    --header-text: #f2f5f8;
    --shadow: 0 1px 2px rgba(0, 0, 0, 0.35);
    --shadow-sm: 0 1px 2px rgba(0, 0, 0, 0.3);
  }
}

* { box-sizing: border-box; }

:focus-visible {
  outline: 3px solid var(--focus);
  outline-offset: 2px;
}

body {
  margin: 0;
  font-family: "Inter", "Segoe UI", system-ui, -apple-system, Roboto, sans-serif;
  background: var(--bg);
  color: var(--text);
  padding: 0 16px 40px;
  -webkit-font-smoothing: antialiased;
}

a { color: var(--accent-strong); text-decoration: underline; text-underline-offset: 2px; }
a:hover { color: var(--accent); }

.auth-screen {
  min-height: 100vh;
  margin: 0 -16px;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px;
  background: var(--header-bg);
}

/* A class-based `display` always beats the browser's built-in
   `[hidden] { display: none }` (author origin beats user-agent origin,
   regardless of specificity) -- without this, toggling .hidden in JS on
   an .auth-screen element has no visual effect at all. */
.auth-screen[hidden] {
  display: none;
}

.auth-card {
  width: 100%;
  max-width: 380px;
  background: var(--panel-bg);
  border-radius: var(--radius);
  border-top: 4px solid var(--accent);
  box-shadow: var(--shadow);
  padding: 32px 28px;
  text-align: center;
}

.brand-mark {
  flex-shrink: 0;
  display: inline-block;
  border-radius: 2px;
}

.brand-kicker {
  margin: 0 0 4px;
  font-size: 0.7rem;
  font-weight: 700;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--accent);
}

.brand-kicker--on-dark { color: rgba(255, 255, 255, 0.75); }

.auth-card h1 {
  font-size: 1.32rem;
  font-weight: 700;
  margin: 4px 0 6px;
  color: var(--text);
}

.auth-subtitle {
  margin: 0 0 22px;
  font-size: 0.86rem;
  color: var(--muted);
}

#login-form {
  display: flex;
  flex-direction: column;
  gap: 6px;
  text-align: left;
}

#login-form label {
  font-size: 0.78rem;
  font-weight: 600;
  color: var(--text);
  margin-top: 10px;
}

#login-form input {
  padding: 10px 11px;
  border: 1px solid var(--border);
  border-radius: 4px;
  background: var(--panel-bg);
  color: var(--text);
  font-size: 0.92rem;
}

#login-form input:focus-visible { outline: 3px solid var(--focus); outline-offset: 1px; border-color: var(--accent); }

#login-submit {
  margin-top: 18px;
  padding: 11px;
  border: none;
  border-radius: 4px;
  background: var(--accent-fill);
  color: #fff;
  font-weight: 700;
  font-size: 0.92rem;
  cursor: pointer;
}

#login-submit:disabled { opacity: 0.6; cursor: default; }
#login-submit:not(:disabled):hover { background: var(--accent-strong); }

.auth-message {
  font-size: 0.84rem;
  margin: 16px 0 0;
}

.auth-error {
  color: var(--red);
  font-weight: 600;
}

#access-denied .auth-card button {
  margin-top: 14px;
  padding: 9px 16px;
  border: 1px solid var(--border);
  border-radius: 4px;
  background: var(--panel-bg-soft);
  color: var(--text);
  font-weight: 600;
  cursor: pointer;
}

#access-denied .auth-card button:hover { background: var(--accent-soft); border-color: var(--accent); }

.header-band {
  background: var(--header-bg);
  margin: 0 -16px 20px;
  padding: 0 16px;
}

/* A flat multi-tone strip under the header, echoing the banded "ribbon"
   used in Dutch central-government branding -- built entirely from this
   app's own blue tones, not a reproduction of any ministry's official
   identity. */
.header-band::after {
  content: "";
  display: block;
  height: 5px;
  background: linear-gradient(
    90deg,
    var(--accent) 0%, var(--accent) 20%,
    var(--accent-strong) 20%, var(--accent-strong) 40%,
    #6d99b8 40%, #6d99b8 60%,
    var(--accent) 60%, var(--accent) 80%,
    var(--accent-strong) 80%, var(--accent-strong) 100%
  );
}

.app-header {
  max-width: 1140px;
  margin: 0 auto;
  padding: 24px 0 20px;
  color: var(--header-text);
}

.app-header h1 {
  margin: 0 0 6px;
  font-size: 1.6rem;
  font-weight: 700;
  letter-spacing: -0.005em;
  color: #fff;
}

.subtitle {
  margin: 0;
  color: rgba(255, 255, 255, 0.82);
  font-size: 0.9rem;
  max-width: 760px;
  line-height: 1.5;
}

.subtitle a { color: #cfe0ef; font-weight: 600; }

.header-top {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 16px;
  flex-wrap: wrap;
}

.brand-row {
  display: flex;
  align-items: flex-start;
  gap: 14px;
}

.brand-row .brand-mark { margin-top: 3px; }

.account-bar {
  display: flex;
  align-items: center;
  gap: 10px;
  font-size: 0.82rem;
  color: rgba(255, 255, 255, 0.82);
  white-space: nowrap;
}

.account-bar button {
  background: transparent;
  color: #fff;
  border: 1px solid rgba(255, 255, 255, 0.55);
  border-radius: 4px;
  padding: 6px 12px;
  font-size: 0.82rem;
  font-weight: 600;
  cursor: pointer;
}

.account-bar button:hover { background: rgba(255, 255, 255, 0.12); }

.snapshot-note {
  margin: 16px 0 10px;
  font-size: 0.78rem;
  color: rgba(255, 255, 255, 0.68);
}

.stat-strip {
  display: flex;
  gap: 10px;
  flex-wrap: wrap;
}

.stat-chip {
  display: inline-flex;
  align-items: center;
  gap: 7px;
  font-size: 0.8rem;
  font-weight: 600;
  padding: 6px 12px;
  border-radius: 4px;
  background: rgba(255, 255, 255, 0.1);
  border: 1px solid rgba(255, 255, 255, 0.18);
  color: #fff;
}

main {
  max-width: 1140px;
  margin: 0 auto;
  display: grid;
  grid-template-columns: 1.3fr 1fr;
  grid-template-rows: auto auto;
  gap: 16px;
}

#map {
  height: 400px;
  border-radius: var(--radius);
  border: 1px solid var(--border);
  grid-column: 1;
  grid-row: 1;
  box-shadow: var(--shadow-sm);
  overflow: hidden;
}

@media (prefers-color-scheme: dark) {
  #map .leaflet-tile-pane {
    filter: invert(1) hue-rotate(180deg) brightness(0.92) contrast(0.9) saturate(0.8);
  }
}

.country-list {
  grid-column: 2;
  grid-row: 1;
  background: var(--panel-bg);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 14px 14px;
  max-height: 400px;
  overflow-y: auto;
  box-shadow: var(--shadow-sm);
}

.country-list h2 {
  margin: 2px 6px 10px;
  font-size: 0.78rem;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--muted);
  font-weight: 700;
}

#country-list-items {
  list-style: none;
  margin: 0;
  padding: 0;
  display: flex;
  flex-direction: column;
  gap: 3px;
}

.country-item {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 10px;
  border-radius: 4px;
  border-left: 3px solid transparent;
  cursor: pointer;
  background: none;
  border-top: none;
  border-right: none;
  border-bottom: none;
  width: 100%;
  text-align: left;
  font-size: 0.94rem;
  font-weight: 600;
  color: var(--text);
  transition: background 0.12s ease, border-color 0.12s ease;
}

.country-item:hover { background: var(--panel-bg-soft); }

.country-item.active {
  background: var(--accent-soft);
  border-left-color: var(--accent);
}

.country-item-name { flex-shrink: 0; }

.risk-num {
  margin-left: auto;
  font-family: "JetBrains Mono", monospace;
  font-size: 0.78rem;
  font-weight: 600;
  color: var(--muted);
  min-width: 28px;
  text-align: right;
}

.mini-bars {
  display: flex;
  flex-direction: column;
  gap: 3px;
  width: 64px;
  flex-shrink: 0;
}

.mini-bar-track {
  height: 5px;
  border-radius: 2px;
  background: var(--border);
  overflow: hidden;
}

.mini-bar-fill {
  display: block;
  height: 100%;
  border-radius: 2px;
}

.mini-bar-fill.conflict { background: var(--red); }
.mini-bar-fill.disaster { background: var(--orange); }

.dot {
  width: 10px;
  height: 10px;
  border-radius: 50%;
  flex-shrink: 0;
  box-shadow: 0 0 0 3px transparent;
}

.dot.Green { background: var(--green); }
.dot.Orange { background: var(--orange); }
.dot.Red { background: var(--red); box-shadow: 0 0 0 3px rgba(213, 43, 30, 0.18); }
.dot.unknown { background: var(--unknown); }

.detail-panel {
  grid-column: 1 / span 2;
  grid-row: 2;
  background: var(--panel-bg);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 22px 26px;
  box-shadow: var(--shadow-sm);
}

.detail-placeholder { color: var(--muted); }

.detail-header {
  display: flex;
  align-items: center;
  gap: 12px;
  flex-wrap: wrap;
  margin-bottom: 2px;
}

.detail-header h3 {
  margin: 0;
  font-size: 1.4rem;
  font-weight: 700;
  letter-spacing: -0.005em;
}

.badge {
  display: inline-block;
  padding: 3px 10px;
  border-radius: 4px;
  font-size: 0.72rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.03em;
  color: #fff;
}

.badge.Green { background: var(--green); }
.badge.Orange { background: var(--orange); }
.badge.Red { background: var(--red); }
.badge.unknown { background: var(--unknown); }

.driver-tag {
  margin-left: auto;
  font-size: 0.76rem;
  color: var(--muted);
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.03em;
  background: var(--panel-bg-soft);
  border: 1px solid var(--border);
  padding: 3px 10px;
  border-radius: 4px;
}

.gauges {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 20px;
  margin-top: 18px;
}

.gauge-card {
  display: flex;
  align-items: center;
  gap: 16px;
  background: var(--panel-bg-soft);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 14px 16px;
}

.radial-gauge {
  --value: 0;
  --gauge-color: var(--green);
  width: 72px;
  height: 72px;
  border-radius: 50%;
  flex-shrink: 0;
  background: conic-gradient(var(--gauge-color) calc(var(--value) * 1%), var(--border) 0);
  display: flex;
  align-items: center;
  justify-content: center;
  position: relative;
}

.radial-gauge::before {
  content: "";
  position: absolute;
  inset: 7px;
  border-radius: 50%;
  background: var(--panel-bg);
}

.radial-value {
  position: relative;
  z-index: 1;
  font-family: "JetBrains Mono", monospace;
  font-weight: 700;
  font-size: 1.05rem;
  color: var(--gauge-color);
}

.synth-asterisk {
  font-size: 0.55em;
  color: var(--orange);
  cursor: help;
  margin-left: 1px;
}

.gauge-info { flex: 1; min-width: 0; }

.gauge-title {
  font-weight: 700;
  font-size: 0.9rem;
  margin-bottom: 6px;
  display: flex;
  align-items: center;
  gap: 6px;
}

.gauge-icon { width: 16px; height: 16px; flex-shrink: 0; color: var(--muted); }

.day-strip {
  display: flex;
  gap: 3px;
}

.day-chip {
  flex: 1;
  height: 16px;
  border-radius: 3px;
  position: relative;
  cursor: default;
}

.day-chip.Green { background: var(--green); opacity: 0.85; }
.day-chip.Orange { background: var(--orange); opacity: 0.9; }
.day-chip.Red { background: var(--red); }
.day-chip.unknown { background: var(--border); }

.gauge-disclaimer {
  font-size: 0.78rem;
  color: var(--muted);
  margin: 12px 0 0;
  line-height: 1.5;
}

.explain-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 16px;
  margin-bottom: 8px;
}

.explain-box {
  background: var(--panel-bg-soft);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 12px 16px;
}

.explain-box > strong {
  display: block;
  font-size: 0.8rem;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  margin-bottom: 8px;
}

.explain-box ul {
  list-style: none;
  margin: 0;
  padding: 0;
  font-size: 0.85rem;
}

.explain-box li {
  padding: 4px 0;
  border-bottom: 1px solid var(--border);
}

.explain-box li:last-child { border-bottom: none; }

.theme-count {
  display: block;
  color: var(--muted);
  font-size: 0.76rem;
}

.synthetic-note {
  font-size: 0.78rem;
  color: var(--muted);
  margin: 4px 0 10px;
}

.synthetic-tag {
  display: inline-block;
  font-size: 0.63rem;
  font-weight: 800;
  letter-spacing: 0.05em;
  text-transform: uppercase;
  color: #fff;
  background: #6b7280;
  padding: 2px 7px;
  border-radius: 4px;
  vertical-align: middle;
}

.acled-box {
  border: 1px solid var(--accent);
}

.presence-box {
  border: 1px solid var(--green);
}

.acled-tag {
  display: inline-block;
  font-size: 0.63rem;
  font-weight: 800;
  letter-spacing: 0.05em;
  text-transform: uppercase;
  color: #fff;
  background: var(--accent-fill);
  padding: 2px 7px;
  border-radius: 4px;
  vertical-align: middle;
}

.acled-summary {
  font-size: 0.88rem;
  margin: 0 0 6px;
}

.attribution {
  font-size: 0.74rem;
  color: var(--muted);
  margin: 8px 0 0;
}

details summary {
  cursor: pointer;
  font-size: 0.82rem;
  color: var(--muted);
  font-weight: 600;
  margin-top: 8px;
}

details[open] summary { margin-bottom: 8px; }

.history-toggle ul { margin-top: 8px; }

.detail-grid {
  display: grid;
  grid-template-columns: 1.3fr 1fr;
  gap: 24px;
  margin-top: 18px;
}

.detail-grid h4 {
  margin: 4px 0 8px;
  font-size: 0.8rem;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--muted);
  font-weight: 700;
}

.chart-box { position: relative; height: 210px; margin-bottom: 18px; }
.chart-box-small { height: 120px; margin-bottom: 0; }

.side-section {
  background: var(--panel-bg-soft);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 14px 16px;
  margin-bottom: 16px;
}

.side-section > strong {
  display: block;
  font-size: 0.8rem;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--muted);
  margin-bottom: 8px;
}

.events-list ul { padding-left: 0; margin: 0; list-style: none; }
.events-list li {
  margin-bottom: 10px;
  padding-bottom: 10px;
  border-bottom: 1px solid var(--border);
  font-size: 0.88rem;
}
.events-list li:last-child { border-bottom: none; margin-bottom: 0; padding-bottom: 0; }
.events-list li.historical { opacity: 0.6; }

.event-tag {
  font-size: 0.68rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.03em;
  color: var(--muted);
  margin-left: 6px;
}

.no-events {
  color: var(--muted);
  font-style: italic;
  font-size: 0.88rem;
  margin: 0;
}

.about-panel {
  max-width: 660px;
  margin: 20px auto;
  background: var(--panel-bg);
  border: 1px solid var(--border);
  border-top: 4px solid var(--accent);
  border-radius: var(--radius);
  padding: 24px 28px;
  box-shadow: var(--shadow);
  line-height: 1.55;
}

.about-panel[hidden] { display: none; }

.about-panel code {
  background: var(--panel-bg-soft);
  padding: 1px 6px;
  border-radius: 4px;
  font-size: 0.85em;
}

.about-panel button {
  margin-top: 8px;
  padding: 9px 18px;
  border-radius: 4px;
  border: none;
  background: var(--accent-fill);
  color: #fff;
  font-weight: 600;
  cursor: pointer;
  font-size: 0.9rem;
}

.about-panel button:hover { background: var(--accent-strong); }

.app-footer {
  max-width: 1140px;
  margin: 32px auto 0;
  padding: 14px 4px;
  display: flex;
  align-items: center;
  gap: 10px;
  font-size: 0.78rem;
  color: var(--muted);
  border-top: 1px solid var(--border);
}

@media (max-width: 820px) {
  main { grid-template-columns: 1fr; }
  #map, .country-list, .detail-panel { grid-column: 1; }
  .country-list { grid-row: 2; }
  .detail-panel { grid-row: 3; }
  .detail-grid { grid-template-columns: 1fr; }
  .gauges { grid-template-columns: 1fr; }
  .explain-grid { grid-template-columns: 1fr; }
  .mini-bars { width: 46px; }
}
