/*
 * observatory.css
 * Crown Dependencies Re-Identification Observatory
 * Shared design tokens and component styles — link from every iframe page.
 * https://observatory.coalfinch.com · Coalfinch
 *
 * EDITING THIS FILE affects all pages. Do not introduce new hex values —
 * add an alias in :root pointing at an existing token instead.
 */

/* ─────────────────────────────────────────────
   RESET
───────────────────────────────────────────── */

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


/* ─────────────────────────────────────────────
   DESIGN TOKENS
───────────────────────────────────────────── */

:root {

  /* Backgrounds */
  --bg:       #0f172a;   /* page background */
  --surface:  #1e293b;   /* card / panel surface */
  --surface2: #162032;   /* recessed surface (inside a card, code blocks) */

  /* Borders */
  --border:   #1e293b;   /* subtle — same as surface, nearly invisible */
  --border2:  #334155;   /* visible divider */

  /* Text */
  --text:     #e2e8f0;   /* primary — headings, values */
  --muted:    #64748b;   /* de-emphasised labels, decorative eyebrows */
  --muted2:   #94a3b8;   /* body copy, descriptions, secondary UI chrome.
                            NOTE: muted2 is LIGHTER than muted. Do not swap. */

  /* Accents */
  --blue:     #60a5fa;
  --blue-dim: #1d4ed8;   /* active button fill */
  --green:    #34d399;
  --amber:    #fbbf24;
  --red:      #f87171;   /* risk / error states only — never use for islands */
  --purple:   #a78bfa;   /* restricted / auth-gated areas */
  --orange:   #fb923c;

  /* ── Island colours ──────────────────────────
     These are canonical. Never substitute.
     IoM  = blue   (the sea)
     GSY  = green  (the fields)
     JSY  = amber  (Jersey Royal — orange jelly)
     UK   = #94a3b8 (John Major grey)
  ────────────────────────────────────────────── */
  --iom: #3b82f6;   /* Isle of Man   */
  --gsy: #10b981;   /* Guernsey      */
  --jsy: #f59e0b;   /* Jersey        */
  --uk:  #94a3b8;   /* United Kingdom */

}


/* ─────────────────────────────────────────────
   BASE
───────────────────────────────────────────── */

html {
  scroll-behavior: smooth;
}

body {
  font-family: 'Inter', system-ui, sans-serif;
  background: var(--bg);
  color: var(--text);
  font-size: 14px;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
}

/* Suppress scrollbars — height is managed by parent iframe via postMessage.
   Only apply on pages that are truly single-view with no internal tabs.
   Pages with internal tabs must NOT set overflow:hidden — tab switching
   changes content height and notifyHeight() needs a real scrollHeight. */
body.single-view {
  overflow: hidden;
}

/* Scrollbar hiding for inner scrollable elements (e.g. tab rows) */
.no-scrollbar { scrollbar-width: none; }
.no-scrollbar::-webkit-scrollbar { display: none; }


/* ─────────────────────────────────────────────
   SHELL
───────────────────────────────────────────── */

.shell {
  max-width: 960px;
  margin: 0 auto;
  padding: 20px 20px 40px;
}

@media (max-width: 600px) {
  .shell { padding: 16px 14px 32px; }
}


/* ─────────────────────────────────────────────
   TYPOGRAPHY HELPERS
───────────────────────────────────────────── */

h1 {
  font-size: 20px;
  font-weight: 800;
  color: var(--text);
  letter-spacing: -0.01em;
  line-height: 1.2;
  margin-bottom: 8px;
}

.eyebrow {
  font-size: 11px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--muted);
  margin-bottom: 10px;
}

p {
  font-size: 13px;
  color: var(--muted2);
  line-height: 1.7;
  max-width: 640px;
}


/* ─────────────────────────────────────────────
   INTRO STRIP
   Accent colour via border-left — override per page:
   .intro { border-left-color: var(--iom); }
───────────────────────────────────────────── */

.intro {
  background: var(--surface2);
  border: 1px solid var(--border2);
  border-left: 3px solid var(--blue);
  border-radius: 8px;
  padding: 14px 16px;
  margin-bottom: 22px;
  font-size: 12px;
  color: var(--muted2);
  line-height: 1.7;
}
.intro strong { color: var(--text); }
.intro em     { color: var(--muted2); font-style: normal; }
.intro .caveat {
  margin-top: 8px;
  font-size: 11px;
  color: var(--muted);
  font-style: italic;
}


/* ─────────────────────────────────────────────
   PLAIN / METHOD BOXES
───────────────────────────────────────────── */

.plain-box {
  background: var(--surface2);
  border: 1px solid var(--border2);
  border-radius: 8px;
  padding: 13px 15px;
  margin-bottom: 18px;
  font-size: 12px;
  color: var(--muted2);
  line-height: 1.7;
}
.plain-box strong { color: var(--text); }
.plain-box.hidden { display: none; }

.method-note {
  background: var(--surface2);
  border: 1px solid var(--border2);
  border-radius: 8px;
  padding: 14px 16px;
  font-size: 11px;
  color: var(--muted2);
  line-height: 1.7;
}
.method-note strong { color: var(--muted); }


/* ─────────────────────────────────────────────
   CONTROLS BAR
───────────────────────────────────────────── */

.controls {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  margin-bottom: 14px;
  align-items: center;
}

.ctrl-label {
  font-size: 10px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--muted);
  margin-right: 2px;
}


/* ─────────────────────────────────────────────
   PILL BUTTONS  (mutually-exclusive toggle groups)
───────────────────────────────────────────── */

.pill {
  background: none;
  border: 1px solid var(--border2);
  border-radius: 20px;
  color: var(--muted2);
  cursor: pointer;
  font-family: inherit;
  font-size: 11px;
  font-weight: 500;
  letter-spacing: 0.03em;
  padding: 4px 12px;
  transition: color 0.15s, border-color 0.15s, background 0.15s;
  white-space: nowrap;
}
.pill.active {
  background: var(--blue-dim);
  border-color: var(--blue);
  color: var(--blue);
}
.pill:hover:not(.active) {
  border-color: var(--muted);
  color: var(--text);
}


/* ─────────────────────────────────────────────
   TOGGLE BUTTONS  (binary on/off, e.g. Plain / Technical)
───────────────────────────────────────────── */

.toggle {
  display: flex;
  background: var(--surface);
  border: 1px solid var(--border2);
  border-radius: 20px;
  overflow: hidden;
}

.toggle-btn {
  background: none;
  border: none;
  color: var(--muted2);
  cursor: pointer;
  font-family: inherit;
  font-size: 11px;
  font-weight: 500;
  padding: 5px 14px;
  transition: background 0.15s, color 0.15s;
  white-space: nowrap;
}
.toggle-btn.active {
  background: var(--blue-dim);
  color: var(--blue);
}
.toggle-btn:hover:not(.active) {
  color: var(--text);
}


/* ─────────────────────────────────────────────
   SELECT DROPDOWNS
───────────────────────────────────────────── */

select {
  appearance: none;
  -webkit-appearance: none;
  background: var(--bg);
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='10' height='6'%3E%3Cpath d='M0 0l5 6 5-6z' fill='%2394a3b8'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 10px center;
  border: 1px solid var(--border2);
  border-radius: 6px;
  color: var(--text);
  cursor: pointer;
  font-family: inherit;
  font-size: 12px;
  padding: 7px 28px 7px 10px;
  transition: border-color 0.15s;
}
select:focus {
  outline: none;
  border-color: var(--blue);
}
/* Selected / has-value state */
select.has-value {
  border-color: #1e40af;
  background-color: #0f1f3d;
}


/* ─────────────────────────────────────────────
   INTERNAL TAB NAVIGATION
   (within an iframe page, not the app shell tabs)
───────────────────────────────────────────── */

.tabs {
  display: flex;
  gap: 0;
  border-bottom: 1px solid var(--border2);
  overflow-x: auto;
  scrollbar-width: none;
  margin-bottom: 24px;
}
.tabs::-webkit-scrollbar { display: none; }

.tab {
  background: none;
  border: none;
  border-bottom: 2px solid transparent;
  color: var(--muted2);        /* #94a3b8 — minimum for legibility on --bg */
  cursor: pointer;
  font-family: inherit;
  font-size: 12px;
  font-weight: 500;
  letter-spacing: 0.03em;
  margin-bottom: -1px;
  padding: 8px 16px;
  transition: color 0.15s, border-color 0.15s;
  white-space: nowrap;
}
.tab.active {
  color: var(--blue);
  border-bottom-color: var(--blue);
  font-weight: 600;
}
.tab:hover:not(.active) {
  color: var(--text);
}


/* ─────────────────────────────────────────────
   STAT CARDS
───────────────────────────────────────────── */

.cards {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(155px, 1fr));
  gap: 9px;
  margin-bottom: 20px;
}

.card {
  background: var(--surface);
  border: 1px solid var(--border2);
  border-top: 3px solid var(--border2); /* override per island: border-top-color: var(--iom) */
  border-radius: 8px;
  padding: 13px 15px;
}
.card-label {
  font-size: 10px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--muted2);
  margin-bottom: 5px;
}
.card-value {
  font-size: 21px;
  font-variant-numeric: tabular-nums;
  font-weight: 500;
  line-height: 1;
}
.card-sub {
  font-size: 11px;
  color: var(--muted2);
  margin-top: 3px;
}
.card-up   { color: var(--amber); font-size: 10px; margin-top: 3px; }
.card-dn   { color: var(--iom);   font-size: 10px; margin-top: 3px; }


/* ─────────────────────────────────────────────
   CHART WRAPPER
───────────────────────────────────────────── */

.chart-wrap {
  background: var(--surface);
  border: 1px solid var(--border2);
  border-radius: 10px;
  padding: 18px 14px 12px;
  margin-bottom: 10px;
}

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

.legend {
  display: flex;
  flex-wrap: wrap;
  gap: 14px;
  margin-bottom: 10px;
  font-size: 11px;
  color: var(--muted2);
}
.leg-item {
  display: flex;
  align-items: center;
  gap: 5px;
}
.leg-sw {
  width: 12px;
  height: 3px;
  border-radius: 1px;
  display: inline-block;
  flex-shrink: 0;
}


/* ─────────────────────────────────────────────
   AUDIENCE TOGGLE  (Plain language / Technical)
───────────────────────────────────────────── */

.audience-bar {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-bottom: 24px;
  flex-wrap: wrap;
}
.aud-label {
  font-size: 11px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--muted);
}


/* ─────────────────────────────────────────────
   SOURCE / STATUS TAGS
───────────────────────────────────────────── */

.source-tag {
  display: inline-block;
  font-size: 9px;
  padding: 2px 7px;
  border-radius: 3px;
  margin-left: 6px;
  vertical-align: middle;
}
.source-tag.official {
  background: rgba(16, 185, 129, 0.12);
  color: var(--gsy);
  border: 1px solid rgba(16, 185, 129, 0.25);
}
.source-tag.estimated {
  background: rgba(251, 191, 36, 0.10);
  color: var(--amber);
  border: 1px solid rgba(251, 191, 36, 0.25);
}


/* ─────────────────────────────────────────────
   PANEL  (bordered content block with header)
───────────────────────────────────────────── */

.panel {
  background: var(--surface);
  border: 1px solid var(--border2);
  border-radius: 10px;
  overflow: hidden;
}
.panel-head {
  padding: 12px 16px;
  border-bottom: 1px solid var(--border2);
  font-size: 11px;
  font-weight: 600;
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: 0.06em;
  display: flex;
  align-items: center;
  justify-content: space-between;
}
.panel-body {
  padding: 14px 16px;
}


/* ─────────────────────────────────────────────
   PAGE FOOTER
───────────────────────────────────────────── */

.page-footer {
  margin-top: 32px;
  padding-top: 16px;
  border-top: 1px solid var(--border2);
  font-size: 10px;
  color: var(--muted);
  display: flex;
  justify-content: space-between;
  flex-wrap: wrap;
  gap: 8px;
}
.page-footer a {
  color: var(--muted2);
  text-decoration: none;
}
.page-footer a:hover {
  color: var(--text);
}


/* ─────────────────────────────────────────────
   RANGE SLIDERS
───────────────────────────────────────────── */

input[type="range"] {
  -webkit-appearance: none;
  appearance: none;
  width: 100%;
  height: 3px;
  background: var(--border2);
  border-radius: 2px;
  outline: none;
  cursor: pointer;
}
input[type="range"]::-webkit-slider-thumb {
  -webkit-appearance: none;
  width: 14px;
  height: 14px;
  border-radius: 50%;
  background: var(--blue);
  cursor: pointer;
}
input[type="range"]::-moz-range-thumb {
  width: 14px;
  height: 14px;
  border-radius: 50%;
  background: var(--blue);
  cursor: pointer;
  border: none;
}


/* ─────────────────────────────────────────────
   UTILITY
───────────────────────────────────────────── */

.monospace {
  font-family: 'JetBrains Mono', monospace;
}

.text-iom    { color: var(--iom); }
.text-gsy    { color: var(--gsy); }
.text-jsy    { color: var(--jsy); }
.text-uk     { color: var(--uk);  }
.text-muted  { color: var(--muted);  }
.text-muted2 { color: var(--muted2); }
.text-amber  { color: var(--amber); }
.text-red    { color: var(--red);   }
.text-green  { color: var(--green); }
.text-blue   { color: var(--blue);  }

.border-iom { border-color: var(--iom); }
.border-gsy { border-color: var(--gsy); }
.border-jsy { border-color: var(--jsy); }


/* ─────────────────────────────────────────────
   REDUCED MOTION
───────────────────────────────────────────── */

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    transition: none !important;
    animation: none !important;
  }
}

/* ── LIGHT MODE ──────────────────────────────────────────────────────────────
   Applied when App.jsx sends { type:'observatory-theme', light:true }
   or when the body carries class="light" for any reason.
   All values shadow the :root dark defaults above.
────────────────────────────────────────────────────────────────────────────── */
body.light {
  --bg:       #f8fafc;
  --surface:  #ffffff;
  --surface2: #f1f5f9;
  --border:   #e2e8f0;
  --border2:  #cbd5e1;
  --text:     #0f172a;
  --muted:    #64748b;
  --muted2:   #475569;
  --blue:     #2563eb;
  --blue-dim: rgba(37,99,235,0.08);
  --iom:      #2563eb;
  --gsy:      #059669;
  --jsy:      #d97706;
  --uk:       #64748b;
  --green:    #059669;
  --amber:    #d97706;
  --red:      #dc2626;
  --purple:   #7c3aed;
  --orange:   #ea580c;
}
/* Fix hard-coded dark colours on select */
body.light select {
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='10' height='6'%3E%3Cpath d='M0 0l5 6 5-6z' fill='%2364748b'/%3E%3C/svg%3E");
}
body.light select.has-value {
  border-color: #2563eb;
  background-color: #eff6ff;
}

/* ── RESPONSIVE / MOBILE ─────────────────────────────────────────────────────
   Compact layout for screens narrower than 640 px.
────────────────────────────────────────────────────────────────────────────── */
@media (max-width: 640px) {
  .shell { padding: 12px 14px 28px; }
  .cards { grid-template-columns: repeat(2, 1fr); gap: 7px; }
  h1 { font-size: 17px; }
  .controls { gap: 4px; }
  .tabs { overflow-x: auto; }
  p { max-width: 100%; }
}

