/* Pledgeline design tokens + components.
   RULE: templates never use literal colours or Tailwind colour utilities
   (bg-white, text-gray-500, ...). Use these classes or var(--token) so light
   and dark resolve from one place. Tailwind is for layout/spacing only. */

:root, [data-theme="light"] {
  color-scheme: light;
  --font: "Noto Sans", system-ui, -apple-system, "Segoe UI", Arial, sans-serif;
  --mono: "Noto Sans Mono", ui-monospace, Consolas, monospace;
  --brand: #1CABE2;            /* UNICEF cyan - fills, bars, focus */
  --brand-strong: #0E7FB2;     /* buttons (white text passes AA) */
  --brand-ink: #ffffff;        /* text on --brand-strong */
  --brand-soft: rgba(28, 171, 226, .13);
  --accent-text: #0B6E9C;      /* cyan for text on light surfaces (AA) */
  --navy: #1E3A5F;             /* Data Druid navy */
  --bg: #edf4f8;
  --blob-1: rgba(28, 171, 226, .30);
  --blob-2: rgba(30, 58, 95, .14);
  --blob-3: rgba(28, 171, 226, .16);
  --surface: rgba(255, 255, 255, .66);
  --surface-strong: rgba(255, 255, 255, .9);
  --surface-solid: #ffffff;
  --surface-2: rgba(226, 238, 245, .55);
  --glass-border: rgba(255, 255, 255, .75);
  --border: #d5e0e7;
  --border-strong: #b7c7d1;
  --text: #13202a;
  --muted: #475763;
  --faint: #64737f;
  --shadow: 0 12px 32px rgba(15, 45, 70, .09), 0 1px 2px rgba(15, 45, 70, .06);
  --ok: #17703f;  --ok-bg: rgba(30, 126, 70, .13);
  --watch: #7d5a04; --watch-bg: rgba(210, 160, 20, .18);
  --flag: #b21f1f; --flag-bg: rgba(178, 31, 31, .10);
  --grey-bg: rgba(90, 110, 125, .12);
  --input-bg: rgba(255, 255, 255, .92);
  --placeholder: #7a8994;
  --focus: 0 0 0 3px rgba(28, 171, 226, .45);
  --heat-ok: #2e8b57; --heat-watch: #e0b43a; --heat-flag: #c0392b; --heat-none: #d9e1e7;
  --radius: 20px; --radius-sm: 14px; --radius-xs: 10px;
}

[data-theme="dark"] {
  color-scheme: dark;
  --brand: #1CABE2;
  --brand-strong: #1CABE2;
  --brand-ink: #03202d;
  --brand-soft: rgba(28, 171, 226, .16);
  --accent-text: #62cbf2;
  --navy: #8fb0dd;
  --bg: #07121a;
  --blob-1: rgba(28, 171, 226, .20);
  --blob-2: rgba(30, 58, 95, .55);
  --blob-3: rgba(14, 127, 178, .18);
  --surface: rgba(17, 32, 43, .62);
  --surface-strong: rgba(20, 37, 49, .92);
  --surface-solid: #101d26;
  --surface-2: rgba(255, 255, 255, .045);
  --glass-border: rgba(255, 255, 255, .09);
  --border: rgba(255, 255, 255, .10);
  --border-strong: rgba(255, 255, 255, .20);
  --text: #e8f0f5;
  --muted: #a8b8c3;
  --faint: #8898a4;
  --shadow: 0 12px 32px rgba(0, 0, 0, .38), 0 1px 2px rgba(0, 0, 0, .3);
  --ok: #72d59c;  --ok-bg: rgba(114, 213, 156, .14);
  --watch: #f1c65e; --watch-bg: rgba(241, 198, 94, .15);
  --flag: #f39191; --flag-bg: rgba(243, 145, 145, .14);
  --grey-bg: rgba(255, 255, 255, .08);
  --input-bg: rgba(6, 16, 23, .55);
  --placeholder: #7e8f9b;
  --focus: 0 0 0 3px rgba(98, 203, 242, .45);
  --heat-none: #24333d;
}

html, body { background: var(--bg); color: var(--text); font-family: var(--font); }
body { -webkit-tap-highlight-color: transparent; }
a { color: inherit; }
.pl-bg {
  position: fixed; inset: 0; z-index: -1; pointer-events: none;
  background:
    radial-gradient(42rem 32rem at 8% -8%, var(--blob-1), transparent 62%),
    radial-gradient(36rem 30rem at 108% 6%, var(--blob-2), transparent 62%),
    radial-gradient(44rem 36rem at 50% 118%, var(--blob-3), transparent 62%),
    var(--bg);
}

/* ---------- glass surfaces ---------- */
.glass {
  background: var(--surface);
  -webkit-backdrop-filter: blur(18px) saturate(150%);
  backdrop-filter: blur(18px) saturate(150%);
  border: 1px solid var(--glass-border);
  box-shadow: var(--shadow);
  border-radius: var(--radius);
}
.card { background: var(--surface); -webkit-backdrop-filter: blur(18px) saturate(150%); backdrop-filter: blur(18px) saturate(150%);
  border: 1px solid var(--glass-border); box-shadow: var(--shadow); border-radius: var(--radius); padding: 1.25rem; }
@media (min-width: 768px) { .card { padding: 1.5rem; } }
.card-title { font-weight: 700; font-size: 1rem; color: var(--text); }
.surface-2 { background: var(--surface-2); border-radius: var(--radius-sm); }
@media (prefers-reduced-transparency: reduce) {
  .glass, .card { -webkit-backdrop-filter: none; backdrop-filter: none; background: var(--surface-solid); }
}

/* ---------- type ---------- */
.page-title { font-size: 1.5rem; font-weight: 800; letter-spacing: -.015em; line-height: 1.2; color: var(--text); }
@media (min-width: 768px) { .page-title { font-size: 1.875rem; } }
.page-sub { color: var(--muted); font-size: .95rem; margin-top: .25rem; }
.eyebrow { font-size: .72rem; font-weight: 700; letter-spacing: .14em; text-transform: uppercase; color: var(--accent-text); }
.text-muted { color: var(--muted); } .text-faint { color: var(--faint); } .text-accent { color: var(--accent-text); }
.text-ok { color: var(--ok); } .text-watch { color: var(--watch); } .text-flag { color: var(--flag); }
.mono { font-family: var(--mono); font-variant-numeric: tabular-nums; }
.verbatim { white-space: pre-line; }
.border-token { border-color: var(--border); }
.divider { border-top: 1px solid var(--border); }

/* ---------- buttons ---------- */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: .5rem;
  min-height: 44px; padding: .6rem 1.15rem; border-radius: 999px;
  font-weight: 600; font-size: .9rem; line-height: 1.1; text-decoration: none; cursor: pointer;
  border: 1px solid var(--border-strong); background: var(--surface-strong); color: var(--text);
  transition: border-color .15s, background .15s, filter .15s, transform .05s;
}
.btn:hover { border-color: var(--brand); }
.btn:active { transform: translateY(1px); }
.btn:focus-visible, .input:focus-visible, .select:focus-visible, .textarea:focus-visible, a:focus-visible, summary:focus-visible { outline: none; box-shadow: var(--focus); }
.btn-primary { background: var(--brand-strong); border-color: var(--brand-strong); color: var(--brand-ink); }
.btn-primary:hover { filter: brightness(1.08); border-color: var(--brand-strong); }
.btn-ghost { background: transparent; border-color: transparent; }
.btn-ghost:hover { background: var(--surface-2); border-color: transparent; }
.btn-danger { color: var(--flag); background: var(--flag-bg); border-color: transparent; }
.btn-danger:hover { border-color: var(--flag); }
.btn-ok { color: var(--ok); background: var(--ok-bg); border-color: transparent; }
.btn-ok:hover { border-color: var(--ok); }
.btn-sm { min-height: 36px; padding: .38rem .85rem; font-size: .8rem; }
.btn-icon { min-height: 40px; width: 40px; padding: 0; }
.btn[disabled], .btn.disabled { opacity: .5; cursor: not-allowed; pointer-events: none; }

/* ---------- forms ---------- */
.field { display: flex; flex-direction: column; gap: .35rem; }
.label { font-size: .78rem; font-weight: 700; color: var(--muted); letter-spacing: .02em; }
.input, .select, .textarea {
  width: 100%; min-height: 44px; border-radius: var(--radius-sm);
  border: 1px solid var(--border-strong); background: var(--input-bg); color: var(--text);
  padding: .6rem .85rem; font: inherit; font-size: .95rem;
}
.textarea { min-height: 96px; resize: vertical; }
.input::placeholder, .textarea::placeholder { color: var(--placeholder); }
.input:focus, .select:focus, .textarea:focus { outline: none; border-color: var(--brand); box-shadow: var(--focus); }
.input:disabled, .select:disabled, .textarea:disabled, .input[readonly] { background: var(--surface-2); color: var(--muted); cursor: not-allowed; }
.select option { background: var(--surface-solid); color: var(--text); }
.help { font-size: .75rem; color: var(--faint); }
.error-text, .errorlist { color: var(--flag); font-size: .8rem; list-style: none; padding: 0; margin: .15rem 0 0; }
.input.is-invalid, .select.is-invalid, .textarea.is-invalid { border-color: var(--flag); }
.check { display: inline-flex; align-items: center; gap: .55rem; cursor: pointer; font-size: .9rem; }
.check input { width: 1.15rem; height: 1.15rem; accent-color: var(--brand-strong); }
.seg { display: flex; flex-wrap: wrap; gap: .4rem; }
.seg label { cursor: pointer; }
.seg input { position: absolute; opacity: 0; pointer-events: none; }
.seg span { display: inline-flex; align-items: center; min-height: 40px; padding: .4rem .9rem; border-radius: 999px;
  border: 1px solid var(--border-strong); background: var(--input-bg); font-size: .82rem; font-weight: 600; color: var(--muted); }
.seg input:checked + span { background: var(--brand-strong); border-color: var(--brand-strong); color: var(--brand-ink); }
.seg input:focus-visible + span { box-shadow: var(--focus); }

/* ---------- chips ---------- */
.chip { display: inline-flex; align-items: center; gap: .3rem; font-size: .72rem; font-weight: 700; letter-spacing: .02em;
  padding: .22rem .62rem; border-radius: 999px; white-space: nowrap; line-height: 1.3; }
.chip-ok { color: var(--ok); background: var(--ok-bg); }
.chip-watch { color: var(--watch); background: var(--watch-bg); }
.chip-flag { color: var(--flag); background: var(--flag-bg); }
.chip-info { color: var(--accent-text); background: var(--brand-soft); }
.chip-grey { color: var(--muted); background: var(--grey-bg); }

/* ---------- tables ---------- */
.tbl-wrap { overflow-x: auto; border-radius: var(--radius-sm); border: 1px solid var(--border); }
.tbl { width: 100%; border-collapse: separate; border-spacing: 0; font-size: .875rem; }
.tbl th { position: sticky; top: 0; z-index: 1; background: var(--surface-strong); text-align: left; font-size: .7rem; font-weight: 700;
  letter-spacing: .08em; text-transform: uppercase; color: var(--accent-text); padding: .7rem .85rem; border-bottom: 1px solid var(--border); white-space: nowrap; }
.tbl td { padding: .7rem .85rem; border-bottom: 1px solid var(--border); vertical-align: top; color: var(--text); }
.tbl tbody tr:last-child td { border-bottom: none; }
.tbl tbody tr:nth-child(even) td { background: var(--surface-2); }
.tbl tbody tr:hover td { background: var(--brand-soft); }
.tbl .num { text-align: right; font-family: var(--mono); font-variant-numeric: tabular-nums; }

/* ---------- data bits ---------- */
.kpi-value { font-family: var(--mono); font-size: 1.75rem; font-weight: 700; color: var(--accent-text); letter-spacing: -.02em; font-variant-numeric: tabular-nums; }
.kpi-label { font-size: .7rem; font-weight: 700; letter-spacing: .1em; text-transform: uppercase; color: var(--faint); margin-top: .2rem; }
.progress { height: 8px; border-radius: 999px; background: var(--grey-bg); overflow: hidden; }
.progress > span { display: block; height: 100%; background: var(--brand); border-radius: 999px; }
.heat { border-radius: 8px; min-height: 26px; }
.heat-ok { background: var(--heat-ok); } .heat-watch { background: var(--heat-watch); }
.heat-flag { background: var(--heat-flag); } .heat-none { background: var(--heat-none); }
.empty { text-align: center; padding: 2.5rem 1rem; color: var(--muted); }
.skeleton { border-radius: var(--radius-xs); background: linear-gradient(90deg, var(--surface-2), var(--border), var(--surface-2));
  background-size: 200% 100%; animation: pl-shimmer 1.2s infinite; }
@keyframes pl-shimmer { to { background-position: -200% 0; } }

/* ---------- alerts / messages ---------- */
.alert { border-radius: var(--radius-sm); padding: .8rem 1rem; font-size: .9rem; border: 1px solid transparent; display: flex; gap: .6rem; align-items: flex-start; }
.alert-success { color: var(--ok); background: var(--ok-bg); }
.alert-error { color: var(--flag); background: var(--flag-bg); }
.alert-warning { color: var(--watch); background: var(--watch-bg); }
.alert-info { color: var(--accent-text); background: var(--brand-soft); }

/* ---------- tabs ---------- */
.tabs { display: flex; gap: .25rem; padding: .25rem; border-radius: 999px; background: var(--surface-2); overflow-x: auto; }
.tab { padding: .5rem 1rem; border-radius: 999px; font-weight: 600; font-size: .85rem; color: var(--muted); white-space: nowrap; text-decoration: none; }
.tab:hover { color: var(--text); }
.tab.active { background: var(--surface-strong); color: var(--text); box-shadow: var(--shadow); }

/* ---------- layout chrome ---------- */
.pl-topbar { position: sticky; top: 0; z-index: 40; background: var(--surface-strong);
  -webkit-backdrop-filter: blur(18px) saturate(150%); backdrop-filter: blur(18px) saturate(150%); border-bottom: 1px solid var(--border); }
.nav-link { display: flex; align-items: center; gap: .75rem; padding: .65rem .9rem; border-radius: 14px; color: var(--muted);
  font-weight: 600; font-size: .9rem; text-decoration: none; }
.nav-link:hover { background: var(--surface-2); color: var(--text); }
.nav-link.active { background: var(--brand-soft); color: var(--accent-text); }
.pl-bottomnav { position: fixed; left: .6rem; right: .6rem; bottom: calc(.6rem + env(safe-area-inset-bottom)); z-index: 40;
  display: grid; grid-template-columns: repeat(5, 1fr); padding: .35rem; border-radius: 22px; background: var(--surface-strong);
  -webkit-backdrop-filter: blur(18px) saturate(150%); backdrop-filter: blur(18px) saturate(150%); border: 1px solid var(--glass-border); box-shadow: var(--shadow); }
.bnav-item { display: flex; flex-direction: column; align-items: center; gap: .15rem; padding: .45rem .2rem; border-radius: 16px;
  font-size: .68rem; font-weight: 600; color: var(--muted); text-decoration: none; background: none; border: 0; cursor: pointer; }
.bnav-item.active { color: var(--accent-text); background: var(--brand-soft); }
.menu-pop { position: absolute; right: 0; margin-top: .5rem; width: 16rem; z-index: 50; padding: .9rem; }
details > summary { list-style: none; } details > summary::-webkit-details-marker { display: none; }
.avatar { width: 36px; height: 36px; border-radius: 999px; display: inline-flex; align-items: center; justify-content: center;
  font-size: .8rem; font-weight: 700; background: var(--brand-soft); color: var(--accent-text); }
.brand-sep { width: 1px; height: 32px; background: var(--border-strong); }
.logo-disc { border-radius: 999px; }

/* theme toggle: show the icon for the theme you would switch TO */
[data-theme="dark"] .icon-when-light { display: none; }
[data-theme="light"] .icon-when-dark, :root:not([data-theme]) .icon-when-dark { display: none; }

/* dialogs */
dialog.pl-dialog { border: none; padding: 0; background: transparent; color: var(--text); max-width: min(92vw, 34rem); width: 100%; }
dialog.pl-dialog::backdrop { background: rgba(4, 14, 22, .5); -webkit-backdrop-filter: blur(4px); backdrop-filter: blur(4px); }

/* scrollbars */
* { scrollbar-color: var(--border-strong) transparent; scrollbar-width: thin; }
::-webkit-scrollbar { width: 10px; height: 10px; }
::-webkit-scrollbar-thumb { background: var(--border-strong); border-radius: 999px; border: 2px solid transparent; background-clip: padding-box; }
::-webkit-scrollbar-track { background: transparent; }

/* htmx */
.htmx-indicator { opacity: 0; transition: opacity .2s; }
.htmx-request .htmx-indicator, .htmx-request.htmx-indicator { opacity: 1; }

/* print: always light, no chrome */
@media print {
  :root, [data-theme="dark"] { --bg: #fff; --surface: #fff; --surface-strong: #fff; --surface-2: #f5f7f8; --text: #000; --muted: #333;
    --faint: #555; --border: #ccc; --accent-text: #0B6E9C; --glass-border: #ccc; --shadow: none; color-scheme: light; }
  .pl-topbar, .pl-bottomnav, .pl-sidebar, .no-print, .pl-bg { display: none !important; }
  .glass, .card { -webkit-backdrop-filter: none; backdrop-filter: none; box-shadow: none; }
}

/* ---------- room to breathe on larger screens ----------
   Phones stay compact; from tablet up the page widens, padding and gaps grow,
   and the base size steps up so everything (rem-based) scales together. */
.pl-wrap { width: 100%; max-width: 1640px; margin-inline: auto; padding-inline: 1rem; }
@media (min-width: 640px)  { .pl-wrap { padding-inline: 1.5rem; } }
@media (min-width: 1024px) {
  .pl-wrap { padding-inline: 2.5rem; }
  .pl-shell { grid-template-columns: 264px minmax(0, 1fr); column-gap: 2.5rem; padding-top: 2.25rem; padding-bottom: 1.5rem; }
  .pl-sidebar nav { padding: 1rem; }
  .nav-link { padding: .8rem 1rem; font-size: .95rem; }
  .card { padding: 2rem; border-radius: 24px; }
  .glass { border-radius: 24px; }
  .page-title { font-size: 2.25rem; }
  .page-sub { font-size: 1.05rem; margin-top: .4rem; }
  .card-title { font-size: 1.1rem; }
  .kpi-value { font-size: 2.1rem; }
  .tbl { font-size: .92rem; }
  .tbl th { padding: .9rem 1.1rem; }
  .tbl td { padding: .95rem 1.1rem; }
  /* stacked sections and grids inside the page get more air */
  #main .space-y-2 > :not([hidden]) ~ :not([hidden]) { margin-top: .75rem; }
  #main .space-y-3 > :not([hidden]) ~ :not([hidden]) { margin-top: 1.1rem; }
  #main .space-y-4 > :not([hidden]) ~ :not([hidden]) { margin-top: 1.6rem; }
  #main .space-y-5 > :not([hidden]) ~ :not([hidden]) { margin-top: 1.9rem; }
  #main .space-y-6 > :not([hidden]) ~ :not([hidden]) { margin-top: 2.25rem; }
  #main .gap-3 { gap: 1.1rem; }
  #main .gap-4 { gap: 1.5rem; }
  #main .gap-5 { gap: 1.75rem; }
  #main .gap-6 { gap: 2rem; }
  #main .mb-4 { margin-bottom: 1.5rem; }
  #main .mb-6 { margin-bottom: 2.25rem; }
  #main .mt-4 { margin-top: 1.5rem; }
  #main .mt-6 { margin-top: 2.25rem; }
}
@media (min-width: 1440px) {
  html { font-size: 17px; }
  .pl-wrap { padding-inline: 3.5rem; }
  .pl-shell { grid-template-columns: 280px minmax(0, 1fr); column-gap: 3rem; }
  .card { padding: 2.25rem; }
}
@media (min-width: 1800px) { html { font-size: 18px; } }
