/* World Vision brand palette (World Vision RGB Palette.ase, Accessible Colour Guide).
   Orange #ff5515 is the primary accent; Midnight #111222 and the Field greys carry the UI. */
:root {
  color-scheme: light;
  --wv-orange: #ff5515; --wv-orange-100: #ffebe1; --wv-orange-200: #ffd5bf; --wv-orange-500: #ff7a38; --wv-orange-800: #f14014; --wv-orange-900: #e32c13;
  --wv-midnight: #111222; --wv-grey-800: #282737; --wv-grey-700: #3f3d4c; --wv-grey-600: #565461; --wv-grey-500: #6d6a76;
  --wv-field-50: #f3f2f0; --wv-field-100: #e9e7e3; --wv-field-200: #dedbd7; --wv-field-300: #d3d0c9; --wv-field-400: #c9c4bc;
  --wv-blue-100: #e0f7fa; --wv-blue-200: #beecf4; --wv-blue-800: #0c7993; --wv-blue-900: #03586e;
  --wv-green-100: #d1efdd; --wv-green-200: #b6e4c8; --wv-green-800: #155930; --wv-green-900: #073a1b;
  --wv-red-100: #f1d0d8; --wv-red-200: #e4b2be; --wv-red-800: #b10831; --wv-red-900: #830221;

  --brand: var(--wv-orange);
  --brand-ink: var(--wv-midnight);        /* text on orange (accessible at all sizes) */
  --brand-2: var(--wv-blue-800);
  --nav-bg: var(--wv-midnight);
  --nav-ink: #ffffff;
  --page: var(--wv-field-50);
  --surface: #ffffff;
  --surface-2: var(--wv-field-50);
  --ink: var(--wv-midnight);
  --ink-2: var(--wv-grey-700);
  --muted: var(--wv-grey-500);
  --line: var(--wv-field-200);
  --axis: var(--wv-field-400);
  --ring: rgba(17, 18, 34, 0.10);
  --focus: var(--wv-blue-800);
  --link: var(--wv-blue-800);
  --series-1: var(--wv-blue-800);
  --ord-1: #5fbdd2; --ord-2: #2c9ab5; --ord-3: #0c7993; --ord-4: #03586e;
  --st-good: #0ca30c; --st-warn: #fab219; --st-crit: #d03b3b; --st-done: var(--wv-blue-800);
  --rag-green-bg: var(--wv-green-100); --rag-green-fg: var(--wv-green-900);
  --rag-amber-bg: var(--wv-orange-100); --rag-amber-fg: var(--wv-orange-900);
  --rag-red-bg: var(--wv-red-100);     --rag-red-fg: var(--wv-red-900);
  --rag-done-bg: var(--wv-blue-100);   --rag-done-fg: var(--wv-blue-900);
  --input-ink: var(--wv-blue-900);
  --shadow: 0 1px 2px rgba(17,18,34,.04), 0 4px 16px rgba(17,18,34,.06);
  --radius: 12px;
  --nav-w: 236px;
  --font: "Inter", system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    color-scheme: dark;
    --brand-2: #5fbdd2; --nav-bg: #0b0c18; --page: var(--wv-midnight); --surface: var(--wv-grey-800); --surface-2: #2f2e3f;
    --ink: #ffffff; --ink-2: var(--wv-field-200); --muted: var(--wv-field-400); --line: var(--wv-grey-700); --axis: var(--wv-grey-600);
    --ring: rgba(255,255,255,.10); --focus: #7fcbdc; --link: var(--wv-blue-200);
    --series-1: #5fbdd2; --ord-1: #beecf4; --ord-2: #7fd0e0; --ord-3: #3fa7c2; --ord-4: #0c7993; --st-done: #7fcbdc;
    --rag-green-bg: var(--wv-green-900); --rag-green-fg: var(--wv-green-200);
    --rag-amber-bg: #5a2a0e; --rag-amber-fg: #ffbd9d;
    --rag-red-bg: var(--wv-red-900); --rag-red-fg: var(--wv-red-200);
    --rag-done-bg: var(--wv-blue-900); --rag-done-fg: var(--wv-blue-200);
    --input-ink: var(--wv-blue-200); --shadow: 0 1px 2px rgba(0,0,0,.5);
  }
}
:root[data-theme="dark"] {
  color-scheme: dark;
  --brand-2: #5fbdd2; --nav-bg: #0b0c18; --page: var(--wv-midnight); --surface: var(--wv-grey-800); --surface-2: #2f2e3f;
  --ink: #ffffff; --ink-2: var(--wv-field-200); --muted: var(--wv-field-400); --line: var(--wv-grey-700); --axis: var(--wv-grey-600);
  --ring: rgba(255,255,255,.10); --focus: #7fcbdc; --link: var(--wv-blue-200);
  --series-1: #5fbdd2; --ord-1: #beecf4; --ord-2: #7fd0e0; --ord-3: #3fa7c2; --ord-4: #0c7993; --st-done: #7fcbdc;
  --rag-green-bg: var(--wv-green-900); --rag-green-fg: var(--wv-green-200);
  --rag-amber-bg: #5a2a0e; --rag-amber-fg: #ffbd9d;
  --rag-red-bg: var(--wv-red-900); --rag-red-fg: var(--wv-red-200);
  --rag-done-bg: var(--wv-blue-900); --rag-done-fg: var(--wv-blue-200);
  --input-ink: var(--wv-blue-200); --shadow: 0 1px 2px rgba(0,0,0,.5);
}

* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; }
body {
  font-family: var(--font);
  font-size: 14px; line-height: 1.45;
  color: var(--ink); background: var(--page);
}
a { color: var(--link); }
a.btn { color: var(--ink); text-decoration: none; }
button, input, select, textarea { font: inherit; color: inherit; }
h1, h2, h3 { margin: 0; font-weight: 600; letter-spacing: -0.01em; }
h1 { font-size: 20px; }
h2 { font-size: 16px; }
h3 { font-size: 14px; color: var(--ink-2); font-weight: 600; }
.muted { color: var(--muted); }
.small { font-size: 12px; }
.num { font-variant-numeric: tabular-nums; }
.hidden { display: none !important; }

/* ---------- layout */
.app { display: grid; grid-template-columns: var(--nav-w) 1fr; min-height: 100vh; }
.nav {
  background: var(--nav-bg); color: var(--nav-ink); padding: 20px 16px; display: flex; flex-direction: column; gap: 4px;
  position: sticky; top: 0; height: 100vh;
}
.nav .logo { margin: 4px 4px 18px; }
.nav .logo img { width: 150px; height: auto; display: block; }
.nav .logo span { display: block; font-weight: 500; font-size: 12.5px; line-height: 1.35; opacity: .8; margin-top: 12px; }
.nav .logo b { display: block; font-weight: 700; font-size: 14px; margin-top: 6px; letter-spacing: -0.01em; }
.nav button {
  background: transparent; border: 0; color: var(--nav-ink); text-align: left; padding: 10px 12px 10px 14px; border-radius: 8px;
  cursor: pointer; display: flex; align-items: center; gap: 10px; opacity: .8; position: relative; font-weight: 500;
}
.nav button:hover { background: rgba(255,255,255,.08); opacity: 1; }
.nav button.active { background: rgba(255,255,255,.10); opacity: 1; font-weight: 600; }
.nav button.active::before { content: ""; position: absolute; left: 0; top: 9px; bottom: 9px; width: 3px; border-radius: 3px; background: var(--brand); }
.nav .spacer { flex: 1; }
.nav .foot { font-size: 12px; opacity: .8; line-height: 1.5; }
.nav .foot b { display: inline-block; padding: 1px 6px; border-radius: 4px; background: rgba(255,255,255,.14); font-weight: 600; }
.main { padding: 20px 24px 40px; min-width: 0; }
.topbar { display: flex; align-items: center; justify-content: space-between; gap: 12px; margin-bottom: 16px; flex-wrap: wrap; }
.topbar .actions { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }

/* ---------- controls */
.btn {
  border: 1px solid var(--line); background: var(--surface); border-radius: 8px; padding: 8px 12px; cursor: pointer;
  display: inline-flex; align-items: center; gap: 6px; box-shadow: none; white-space: nowrap;
}
.btn:hover { border-color: var(--axis); }
.btn.primary { background: var(--brand); border-color: var(--brand); color: var(--brand-ink); font-weight: 600; }
.btn.primary:hover { background: var(--wv-orange-800); border-color: var(--wv-orange-800); }
.btn.ghost { background: transparent; }
.btn.sm { padding: 5px 9px; font-size: 12px; border-radius: 6px; }
.btn:disabled { opacity: .5; cursor: not-allowed; }
.btn:focus-visible, input:focus-visible, select:focus-visible, textarea:focus-visible { outline: 2px solid var(--focus); outline-offset: 1px; }
input, select, textarea {
  border: 1px solid var(--line); background: var(--surface); border-radius: 8px; padding: 8px 10px; width: 100%;
}
textarea { min-height: 70px; resize: vertical; }
label.field { display: flex; flex-direction: column; gap: 4px; font-size: 12px; color: var(--ink-2); }
label.field > span { font-weight: 600; }
label.field .hint { font-weight: 400; color: var(--muted); }
.field input.entry, .field textarea.entry, .field select.entry { color: var(--input-ink); }
.check { display: flex; align-items: center; gap: 8px; font-size: 13px; }
.check input { width: auto; }

.filters {
  display: flex; gap: 8px; flex-wrap: wrap; align-items: end; background: var(--surface); padding: 12px;
  border-radius: var(--radius); box-shadow: var(--shadow); margin-bottom: 16px;
}
.filters label.field { min-width: 120px; flex: 1 1 120px; }
.filters .btn { align-self: end; }

/* ---------- cards */
.card { background: var(--surface); border-radius: var(--radius); box-shadow: var(--shadow); padding: 16px; min-width: 0; }
.card-head { display: flex; align-items: baseline; justify-content: space-between; gap: 8px; margin-bottom: 10px; flex-wrap: wrap; }
.card-head .sub { color: var(--muted); font-size: 12px; }
.grid { display: grid; gap: 16px; }
.grid.kpis { grid-template-columns: repeat(auto-fit, minmax(160px, 1fr)); margin-bottom: 16px; }
.grid.two { grid-template-columns: repeat(auto-fit, minmax(340px, 1fr)); margin-bottom: 16px; }
.kpi { padding: 14px 16px; }
.kpi .label { font-size: 11.5px; color: var(--ink-2); font-weight: 600; text-transform: uppercase; letter-spacing: .06em; }
.kpi .value { font-size: 30px; font-weight: 600; line-height: 1.15; margin: 6px 0 2px; }
.kpi .value small { font-size: 14px; color: var(--muted); font-weight: 400; margin-left: 4px; }
.kpi .foot { font-size: 12px; color: var(--muted); }
.kpi .bar { height: 4px; background: var(--line); border-radius: 2px; margin-top: 10px; overflow: hidden; }
.kpi .bar i { display: block; height: 100%; background: var(--brand); border-radius: 2px; }

.chart-wrap { position: relative; height: 260px; }
.chart-wrap.tall { height: 320px; }
.empty { color: var(--muted); font-size: 13px; padding: 24px; text-align: center; border: 1px dashed var(--line); border-radius: 8px; }
.legend { display: flex; gap: 14px; flex-wrap: wrap; font-size: 12px; color: var(--ink-2); margin-top: 8px; }
.legend i { display: inline-block; width: 10px; height: 10px; border-radius: 3px; margin-right: 6px; vertical-align: -1px; }
details.tbl summary { cursor: pointer; color: var(--muted); font-size: 12px; margin-top: 8px; }

/* ---------- tables */
.table-wrap { overflow: auto; max-width: 100%; }
table { border-collapse: collapse; width: 100%; font-size: 13px; }
th, td { text-align: left; padding: 8px 10px; border-bottom: 1px solid var(--line); vertical-align: top; }
th { color: var(--ink-2); font-weight: 600; font-size: 12px; background: var(--surface-2); position: sticky; top: 0; white-space: nowrap; }
td.num, th.num { text-align: right; font-variant-numeric: tabular-nums; }
tr.clickable { cursor: pointer; }
tr.clickable:hover td { background: var(--surface-2); }
tfoot td { font-weight: 600; background: var(--surface-2); }
.chip { display: inline-flex; align-items: center; gap: 5px; padding: 2px 8px; border-radius: 999px; font-size: 12px; font-weight: 600; white-space: nowrap; }
.chip::before { content: ""; width: 7px; height: 7px; border-radius: 50%; background: currentColor; }
.chip.Green { background: var(--rag-green-bg); color: var(--rag-green-fg); }
.chip.Amber { background: var(--rag-amber-bg); color: var(--rag-amber-fg); }
.chip.Red { background: var(--rag-red-bg); color: var(--rag-red-fg); }
.chip.Complete { background: var(--rag-done-bg); color: var(--rag-done-fg); }
.chip.none { background: var(--surface-2); color: var(--muted); }
.chip.none::before { display: none; }
.status { font-size: 12px; color: var(--ink-2); }
.ach { display: inline-block; min-width: 56px; padding: 2px 6px; border-radius: 6px; text-align: right; font-variant-numeric: tabular-nums; }
.ach.blank { color: var(--muted); }

/* ---------- goals view */
.goal-block { margin-bottom: 16px; }
.goal-block .goal-head { display: grid; grid-template-columns: 1fr auto; gap: 12px; align-items: start; margin-bottom: 8px; }
.goal-block .goal-title { font-weight: 600; font-size: 15px; }
.goal-block .goal-meta { color: var(--muted); font-size: 12px; margin-top: 2px; }
.goal-block .goal-outcome { color: var(--ink-2); font-size: 13px; margin-top: 4px; }
.progress { height: 6px; background: var(--line); border-radius: 3px; overflow: hidden; }
.progress i { display: block; height: 100%; background: var(--brand); border-radius: 3px; }
.tag { display: inline-block; background: var(--surface-2); border: 1px solid var(--line); border-radius: 6px; padding: 1px 6px; font-size: 11px; color: var(--ink-2); }

/* ---------- updates view */
.capture { display: grid; grid-template-columns: repeat(auto-fit, minmax(340px, 1fr)); gap: 16px; }
.capture .card h3 { margin-bottom: 8px; }
.capture .target { font-size: 12px; color: var(--muted); margin-bottom: 8px; }
.form-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(220px, 1fr)); gap: 10px; }
.form-grid .wide { grid-column: 1 / -1; }
.form-actions { display: flex; gap: 8px; justify-content: flex-end; margin-top: 12px; align-items: center; flex-wrap: wrap; }
.form-actions .status-msg { margin-right: auto; font-size: 12px; color: var(--muted); }

/* ---------- modal */
.modal-back { position: fixed; inset: 0; background: rgba(10, 20, 40, .45); display: flex; align-items: flex-start; justify-content: center; padding: 24px 16px; overflow: auto; z-index: 40; }
.modal { background: var(--surface); border-radius: var(--radius); box-shadow: 0 20px 60px rgba(0,0,0,.3); width: min(920px, 100%); padding: 20px; }
.modal h2 { margin-bottom: 12px; }
.modal .close { float: right; }

/* ---------- login */
.login { position: fixed; inset: 0; background: var(--wv-midnight); display: flex; align-items: center; justify-content: center; z-index: 50; padding: 16px; overflow: hidden; }
.login .brand { position: absolute; top: 28px; left: 32px; width: 170px; }
.login .box { background: var(--surface); color: var(--ink); border-radius: var(--radius); padding: 28px; width: min(380px, 100%); box-shadow: 0 20px 60px rgba(0,0,0,.3); }
.login .box h1 { font-size: 18px; margin-bottom: 4px; }
.login .box .eyebrow { color: var(--brand); font-weight: 600; font-size: 12px; letter-spacing: .06em; text-transform: uppercase; margin-bottom: 8px; }
.login .box p { margin: 0 0 16px; color: var(--muted); font-size: 13px; }
.login .err { color: var(--st-crit); font-size: 13px; margin-top: 8px; min-height: 18px; }

/* ---------- toast */
.toast { position: fixed; bottom: 20px; left: 50%; transform: translateX(-50%); background: var(--ink); color: var(--surface); padding: 10px 16px; border-radius: 8px; font-size: 13px; box-shadow: var(--shadow); z-index: 60; max-width: min(90vw, 560px); }
.toast.error { background: var(--wv-red-800); color: #fff; }
.banner { background: var(--rag-amber-bg); color: var(--rag-amber-fg); border-left: 3px solid var(--brand); border-radius: 8px; padding: 8px 12px; font-size: 13px; margin-bottom: 12px; }

/* ---------- help */
.help dl { display: grid; grid-template-columns: 220px 1fr; gap: 8px 16px; }
.help dt { font-weight: 600; color: var(--ink-2); }
.help dd { margin: 0; }
.help ol, .help ul { padding-left: 20px; }

/* ---------- responsive */
@media (max-width: 860px) {
  .app { grid-template-columns: 1fr; }
  .nav { position: static; height: auto; flex-direction: row; flex-wrap: wrap; align-items: center; padding: 12px 16px; }
  .nav .logo { width: 100%; margin-bottom: 6px; }
  .nav .logo img { width: 120px; }
  .nav .logo span, .nav .logo b { display: none; }
  .nav .spacer, .nav .foot { display: none; }
  .main { padding: 16px; }
  .help dl { grid-template-columns: 1fr; }
  .goal-block .goal-head { grid-template-columns: 1fr; }
}
