/* Political Atlas uses the JDP-I design system (H&P suite, cyan accent).
   Tokens come from https://jdpi.pages.dev/design/jdpi.css; the fallbacks keep
   the page styled if that stylesheet can't load. */
:root {
  --bg: var(--jdpi-bg, #101820);
  --surface: var(--jdpi-panel, #17242e);
  --surface-2: var(--jdpi-panel-2, #1c2b36);
  --text: var(--jdpi-text, #edf3f1);
  --muted: var(--jdpi-muted, #91a0aa);
  --border: var(--jdpi-line, #293a46);
  --accent: var(--jdpi-cyan, #6ddac8);
  --ocean: var(--jdpi-inset, #0d1721);
  --land-inactive: #22323d;
  --land-stroke: #0d1721;
  --hover-stroke: #edf3f1;
  --warn-bg: rgba(240, 185, 90, .12);
  --warn-text: var(--jdpi-amber, #f0b95a);
  --ok-bg: rgba(127, 214, 164, .12);
  --ok-text: var(--jdpi-ok, #7fd6a4);
  --shadow: var(--jdpi-shadow, 0 10px 28px rgba(0, 0, 0, .45));
  --font-display: var(--jdpi-font-display, "Manrope", "DM Sans", system-ui, sans-serif);
  --font-ui: var(--jdpi-font-ui, "DM Sans", system-ui, sans-serif);
  --font-mono: var(--jdpi-font-mono, "DM Mono", ui-monospace, monospace);

  /* categorical palette for system types (tuned for the dark workspace) */
  --c-presidential: #f08a5d;
  --c-semi: #f0b95a;
  --c-parl-rep: #5b9cf0;
  --c-parl-mon: #a78bfa;
  --c-abs-mon: #e05a7a;
  --c-one-party: #e5534b;
  --c-directorial: #6ddac8;
  --c-theocratic: #c9a227;
  --c-transitional: #7d8b96;
  --c-territory: #4d6170;

  /* sequential for elections */
  --e-1: #e5534b;
  --e-2: #f08a5d;
  --e-3: #f0d25a;
  --e-4: #5b9cf0;
  --e-5: #3d5263;

  color-scheme: dark;
}

* { box-sizing: border-box; }
html, body { height: 100%; margin: 0; }
body {
  background: var(--bg);
  color: var(--text);
  font: 14px/1.5 var(--font-ui);
  display: flex;
  flex-direction: column;
}

.topbar {
  display: flex; align-items: center; justify-content: space-between; gap: 16px;
  padding: 12px 20px; background: var(--surface); border-bottom: 1px solid var(--border);
  flex-wrap: wrap;
}
.brand { display: flex; align-items: center; gap: 10px; }
.logo { width: 28px; height: 28px; color: var(--accent); }
h1 { font: 700 18px var(--font-display); margin: 0; letter-spacing: -.02em; }
.subtitle { margin: 0; font: 10px var(--font-mono); letter-spacing: .04em; color: var(--muted); }
.eyebrow { margin: 0 0 2px; color: var(--accent); font: 500 9px var(--font-mono); letter-spacing: .15em; text-transform: uppercase; }
.controls { display: flex; gap: 12px; align-items: center; flex-wrap: wrap; }

.search-wrap { position: relative; }
#search {
  width: 240px; padding: 8px 12px; border-radius: 8px; border: 1px solid var(--border);
  background: var(--surface-2); color: var(--text); font: inherit;
}
#search:focus { outline: 2px solid var(--accent); outline-offset: -1px; }
.search-results {
  position: absolute; top: calc(100% + 4px); left: 0; right: 0; z-index: 20;
  list-style: none; margin: 0; padding: 4px; background: var(--surface);
  border: 1px solid var(--border); border-radius: 8px; box-shadow: var(--shadow);
  max-height: 300px; overflow: auto;
}
.search-results li { padding: 6px 8px; border-radius: 6px; cursor: pointer; display: flex; gap: 8px; align-items: center; }
.search-results li:hover, .search-results li[aria-selected="true"] { background: var(--surface-2); }

.segmented { display: inline-flex; background: var(--surface-2); border: 1px solid var(--border); border-radius: 8px; padding: 2px; }
.segmented button {
  border: 0; background: transparent; color: var(--muted); font: inherit; font-weight: 500;
  padding: 6px 10px; border-radius: 6px; cursor: pointer;
}
.segmented button.active { background: rgba(109, 218, 200, .1); color: var(--accent); box-shadow: inset 0 0 0 1px #3f7a70; }

.layout { flex: 1; display: grid; grid-template-columns: 1fr 440px; min-height: 0; }
.map-wrap { position: relative; background: var(--ocean); overflow: hidden; min-height: 360px; }
#map { width: 100%; height: 100%; display: block; cursor: grab; }
#map:active { cursor: grabbing; }
.country { stroke: var(--land-stroke); stroke-width: .5; vector-effect: non-scaling-stroke; transition: fill .2s; }
.country.inactive { fill: var(--land-inactive); }
.country.active { cursor: pointer; }
.country.active:hover { stroke: var(--hover-stroke); stroke-width: 1.5; }
.country.selected { stroke: var(--hover-stroke); stroke-width: 2.2; }
.microstate { stroke: var(--land-stroke); stroke-width: 1; vector-effect: non-scaling-stroke; cursor: pointer; }

.map-tools { position: absolute; top: 12px; left: 12px; display: flex; flex-direction: column; gap: 4px; }
.map-tools button {
  width: 32px; height: 32px; border-radius: 8px; border: 1px solid var(--border);
  background: var(--surface); color: var(--text); font-size: 16px; cursor: pointer; box-shadow: var(--shadow);
}
.legend {
  position: absolute; left: 12px; bottom: 12px; background: var(--surface); border: 1px solid var(--border);
  border-radius: 10px; padding: 10px 12px; box-shadow: var(--shadow); font-size: 12px; max-width: calc(100% - 24px);
}
.legend h4 { margin: 0 0 6px; font: 10px var(--font-mono); text-transform: uppercase; letter-spacing: .12em; color: var(--accent); }
.legend ul { list-style: none; margin: 0; padding: 0; display: grid; grid-template-columns: repeat(2, auto); gap: 3px 14px; }
.legend li { display: flex; align-items: center; gap: 6px; }
.swatch { width: 12px; height: 12px; border-radius: 3px; flex: none; }
.tooltip {
  position: absolute; pointer-events: none; background: var(--surface); color: var(--text);
  border: 1px solid var(--border); border-radius: 8px; padding: 6px 10px; box-shadow: var(--shadow); font-size: 12px;
  white-space: nowrap; z-index: 10;
}
.tooltip strong { display: block; font-size: 13px; }

.panel { background: var(--surface); border-left: 1px solid var(--border); overflow-y: auto; padding: 20px; }
.panel-empty h2 { margin-top: 0; font: 600 18px var(--font-display); letter-spacing: -.02em; }
.panel-empty p { color: var(--muted); }
.panel h3 { font: 10px var(--font-mono); text-transform: uppercase; letter-spacing: .14em; color: var(--accent); margin: 24px 0 8px; }
.upcoming { list-style: none; padding: 0; margin: 0; }
.upcoming li {
  display: grid; grid-template-columns: 78px 1fr; gap: 8px; padding: 8px 0; border-bottom: 1px solid var(--border); cursor: pointer;
}
.upcoming li:hover .u-name { color: var(--accent); }
.u-date { color: var(--muted); font: 11px var(--font-mono); }
.u-name { font-weight: 600; }
.u-kind { display: block; color: var(--muted); font-size: 12px; }

.c-head { display: flex; gap: 12px; align-items: flex-start; }
.c-head img { width: 44px; height: 30px; object-fit: cover; border-radius: 4px; border: 1px solid var(--border); margin-top: 4px; }
.c-head h2 { margin: 0; font: 600 24px var(--font-display); letter-spacing: -.03em; }
.c-system { color: var(--muted); margin: 2px 0 0; }
.close { margin-left: auto; border: 0; background: var(--surface-2); color: var(--text); width: 28px; height: 28px; border-radius: 6px; cursor: pointer; flex: none; }
.badge { display: inline-block; font: 500 9px var(--font-mono); text-transform: uppercase; letter-spacing: .08em; padding: 3px 8px; border-radius: 3px; margin-top: 8px; }
.badge.stable { background: var(--ok-bg); color: var(--ok-text); }
.badge.in-flux { background: var(--warn-bg); color: var(--warn-text); }

.power-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }
.card { background: var(--surface-2); border: 1px solid var(--border); border-radius: 10px; padding: 10px 12px; }
.card .role { font: 9px var(--font-mono); text-transform: uppercase; letter-spacing: .1em; color: var(--muted); }
.card .who { font-weight: 600; margin-top: 2px; }
.card .party { font-size: 12px; color: var(--muted); }
.card.full { grid-column: 1 / -1; }
.chips { display: flex; flex-wrap: wrap; gap: 4px; margin-top: 4px; }
.chip { background: var(--surface); border: 1px solid var(--border); border-radius: 99px; padding: 1px 8px; font-size: 12px; }
.leg-item + .leg-item { margin-top: 8px; }
.leg-item .control { font-weight: 600; }
.leg-item .detail { font-size: 12px; color: var(--muted); }

.timeline { list-style: none; margin: 0; padding: 0 0 0 14px; border-left: 2px solid var(--border); }
.timeline li { position: relative; padding: 0 0 12px 10px; }
.timeline li::before {
  content: ""; position: absolute; left: -21px; top: 5px; width: 10px; height: 10px; border-radius: 50%;
  background: var(--surface); border: 2px solid var(--muted);
}
.timeline li.upcoming-e::before { border-color: var(--accent); background: var(--accent); }
.timeline .t-date { font: 11px var(--font-mono); color: var(--muted); }
.timeline .t-count { font-size: 11px; font-weight: 600; color: var(--accent); margin-left: 6px; }
.timeline .t-name { font-weight: 600; }
.timeline .t-note { font-size: 12px; color: var(--muted); }

.synopsis { font-size: 15px; line-height: 1.6; }
.bullets { margin: 0; padding-left: 18px; }
.bullets li { margin-bottom: 4px; }
.review {
  margin-top: 20px; padding: 10px 12px; border-radius: 8px; background: var(--warn-bg); color: var(--warn-text); font-size: 12px;
}
.meta { margin-top: 16px; font-size: 12px; color: var(--muted); }

@media (max-width: 900px) {
  .topbar { padding: 10px 16px; }
  #search { width: 100%; }
  .search-wrap, .controls { width: 100%; }
  .segmented { width: 100%; }
  .segmented button { flex: 1; }
  .layout { grid-template-columns: 1fr; grid-template-rows: 55vh auto; }
  .panel { border-left: 0; border-top: 1px solid var(--border); padding: 16px; }
  .legend ul { grid-template-columns: 1fr 1fr; }
  .legend { font-size: 11px; }
}
