/* Award Letter Compare - styles
   Themes: follows the device by default; the Theme menu can force light/dark.
   The letter ("paper") ignores the theme on purpose and is always light. */

:root {
  --bg: #f4f6fa;
  --surface: #ffffff;
  --surface-2: #eef1f7;
  --text: #17202e;
  --muted: #4d5a6e;
  --border: #c5cddb;
  --accent: #2c4a7c;
  --accent-text: #ffffff;
  --accent-soft: #dfe7f5;
  --danger: #a3262a;
  --danger-soft: #fbe4e4;
  --ok: #1d6b45;
  --focus: #0b5fff;
  --best-bg: #e0f3e8;
  --best-text: #0f4d2e;
  --c-gift: #1f7a5a;
  --c-loan: #3a5fa8;
  --c-loan-2: #8fa7d6;
  --c-work: #a8680a;
  --c-still: #8a2f3c;
  --shadow: 0 1px 2px rgba(20, 30, 50, .08), 0 4px 14px rgba(20, 30, 50, .06);
  color-scheme: light;
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #0f141d;
    --surface: #182030;
    --surface-2: #1f2940;
    --text: #e8edf6;
    --muted: #a9b5c9;
    --border: #36435c;
    --accent: #8fb0ee;
    --accent-text: #0c1424;
    --accent-soft: #24365a;
    --danger: #ff8d90;
    --danger-soft: #3b1f23;
    --ok: #6fd3a2;
    --focus: #7db0ff;
    --best-bg: #17382a;
    --best-text: #9be7be;
    --c-gift: #4cc39a;
    --c-loan: #7fa3ee;
    --c-loan-2: #3a5694;
    --c-work: #e0a54a;
    --c-still: #ee8a99;
    --shadow: 0 1px 2px rgba(0, 0, 0, .4), 0 4px 14px rgba(0, 0, 0, .3);
    color-scheme: dark;
  }
}

:root[data-theme="dark"] {
  --bg: #0f141d;
  --surface: #182030;
  --surface-2: #1f2940;
  --text: #e8edf6;
  --muted: #a9b5c9;
  --border: #36435c;
  --accent: #8fb0ee;
  --accent-text: #0c1424;
  --accent-soft: #24365a;
  --danger: #ff8d90;
  --danger-soft: #3b1f23;
  --ok: #6fd3a2;
  --focus: #7db0ff;
  --best-bg: #17382a;
  --best-text: #9be7be;
  --c-gift: #4cc39a;
  --c-loan: #7fa3ee;
  --c-loan-2: #3a5694;
  --c-work: #e0a54a;
  --c-still: #ee8a99;
  --shadow: 0 1px 2px rgba(0, 0, 0, .4), 0 4px 14px rgba(0, 0, 0, .3);
  color-scheme: dark;
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 16px/1.5 system-ui, -apple-system, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
}
h1, h2, h3, h4 { line-height: 1.25; margin: 0 0 .5rem; }
h2 { font-size: 1.4rem; }
h3 { font-size: 1.1rem; }
p { margin: 0 0 .75rem; }
code { background: var(--surface-2); padding: 0 .3em; border-radius: 4px; }
[hidden] { display: none !important; }

.sr-only {
  position: absolute !important; width: 1px; height: 1px; padding: 0; margin: -1px;
  overflow: hidden; clip: rect(0, 0, 0, 0); white-space: nowrap; border: 0;
}

/* Focus: always visible, never colour-only (thick outline + offset). */
:focus-visible {
  outline: 3px solid var(--focus);
  outline-offset: 2px;
  border-radius: 4px;
}
.skip {
  position: absolute; left: 8px; top: -60px; background: var(--surface); color: var(--text);
  padding: .5rem .75rem; border: 2px solid var(--focus); border-radius: 6px; z-index: 50;
}
.skip:focus { top: 8px; }
main:focus { outline: none; }

/* ---------- header / tabs ---------- */
.top { background: var(--surface); border-bottom: 1px solid var(--border); position: sticky; top: 0; z-index: 20; }
.top-inner { max-width: 1180px; margin: 0 auto; padding: .6rem 16px .2rem; display: flex; flex-wrap: wrap; gap: .5rem 1.5rem; align-items: center; justify-content: space-between; }
.brand h1 { font-size: 1.25rem; margin: 0; }
.tag { margin: 0; color: var(--muted); font-size: .85rem; }
.top-tools { display: flex; align-items: center; gap: .75rem; flex-wrap: wrap; font-size: .85rem; }
.theme-pick { display: flex; align-items: center; gap: .4rem; color: var(--muted); }
.theme-pick select { font: inherit; }
.save-state { color: var(--muted); min-width: 8ch; }
.save-state.err { color: var(--danger); font-weight: 600; }
.tabs { max-width: 1180px; margin: 0 auto; padding: 0 16px; display: flex; gap: .25rem; overflow-x: auto; }
.tab {
  font: inherit; font-weight: 600; background: none; color: var(--muted); border: 0;
  border-bottom: 4px solid transparent; padding: .6rem .9rem; cursor: pointer; white-space: nowrap;
}
.tab:hover { color: var(--text); }
.tab[aria-current="page"] { color: var(--text); border-bottom-color: var(--accent); }

main { max-width: 1180px; margin: 0 auto; padding: 16px; }
.foot { max-width: 1180px; margin: 0 auto; padding: 8px 16px 32px; color: var(--muted); font-size: .85rem; }
.notice {
  position: fixed; left: 16px; bottom: 16px; right: 16px; max-width: 640px; z-index: 40;
  background: var(--surface); color: var(--text); border: 2px solid var(--accent); border-left-width: 8px;
  padding: .6rem .8rem; border-radius: 10px; box-shadow: var(--shadow), 0 8px 28px rgba(0, 0, 0, .25);
  display: flex; flex-wrap: wrap; gap: .5rem .9rem; align-items: center; justify-content: space-between;
}
.notice.err { background: var(--danger-soft); border-color: var(--danger); }

/* ---------- controls ---------- */
.btn {
  font: inherit; font-weight: 600; cursor: pointer; border-radius: 8px; padding: .5rem .9rem; min-height: 44px;
  background: var(--surface); color: var(--text); border: 2px solid var(--border);
}
.btn:hover { border-color: var(--accent); }
.btn.primary { background: var(--accent); color: var(--accent-text); border-color: var(--accent); }
.btn.danger { color: var(--danger); border-color: var(--danger); }
.btn.small { min-height: 36px; padding: .25rem .6rem; font-size: .85rem; }
.btn[disabled] { opacity: .55; cursor: not-allowed; }
.toolbar { display: flex; flex-wrap: wrap; gap: .6rem 1rem; align-items: end; margin: .5rem 0 1rem; }
.field { display: flex; flex-direction: column; gap: .25rem; min-width: 0; }
.field.inline { flex-direction: row; align-items: center; gap: .5rem; }
label, legend { font-weight: 600; font-size: .92rem; }
input[type="text"], input[type="number"], input[type="date"], input[type="email"], select, textarea {
  font: inherit; color: var(--text); background: var(--surface); border: 2px solid var(--border);
  border-radius: 8px; padding: .45rem .6rem; min-height: 44px; width: 100%; max-width: 100%;
}
textarea { resize: vertical; }
input[type="file"] { font: inherit; max-width: 100%; }
.field.inline input { width: 7rem; }
.hint { color: var(--muted); font-size: .88rem; }
.card { background: var(--surface); border: 1px solid var(--border); border-radius: 12px; padding: 1rem; margin-bottom: 1rem; box-shadow: var(--shadow); }

/* ---------- compare ---------- */
.cards { display: grid; grid-template-columns: repeat(auto-fit, minmax(210px, 1fr)); gap: .8rem; margin-bottom: 1.25rem; }
.stat { background: var(--surface); border: 1px solid var(--border); border-radius: 12px; padding: .9rem 1rem; box-shadow: var(--shadow); }
.stat .k { display: block; color: var(--muted); font-size: .85rem; font-weight: 600; }
.stat .v { display: block; font-size: 1.6rem; font-weight: 700; margin: .1rem 0; }
.stat .who { display: block; font-size: .95rem; overflow-wrap: anywhere; }

.bars { margin-bottom: 1.5rem; }
.bar-row { background: var(--surface); border: 1px solid var(--border); border-radius: 12px; padding: .8rem 1rem; margin-bottom: .7rem; }
.bar-name { font-weight: 700; overflow-wrap: anywhere; }
.bar-name .muted { font-weight: 400; }
.muted { color: var(--muted); }
.bar { display: flex; height: 30px; border: 2px solid var(--text); border-radius: 6px; overflow: hidden; margin: .5rem 0; background: var(--surface); }
.bar .seg { height: 100%; min-width: 0; }
.seg-gift, .sw-gift { background: var(--c-gift); }
.seg-loan, .sw-loan { background: repeating-linear-gradient(45deg, var(--c-loan) 0 6px, var(--c-loan-2) 6px 12px); }
.seg-work, .sw-work { background: radial-gradient(circle at 3px 3px, var(--surface) 1.2px, transparent 1.6px) 0 0 / 7px 7px, var(--c-work); }
.seg-still, .sw-still { background: repeating-linear-gradient(-45deg, transparent 0 4px, var(--c-still) 4px 6px); }
.legend { list-style: none; display: flex; flex-wrap: wrap; gap: .25rem 1.25rem; padding: 0; margin: 0; font-size: .9rem; }
.legend li { display: flex; align-items: center; gap: .4rem; }
.sw { width: 18px; height: 18px; border: 2px solid var(--text); border-radius: 3px; flex: none; }
.over-note { font-size: .88rem; color: var(--muted); margin: .4rem 0 0; }

.table-scroll { overflow-x: auto; border: 1px solid var(--border); border-radius: 12px; background: var(--surface); box-shadow: var(--shadow); }
.cmp { border-collapse: separate; border-spacing: 0; width: 100%; min-width: 520px; }
.cmp caption { text-align: left; padding: .7rem 1rem; font-weight: 700; }
.cmp th, .cmp td { padding: .55rem .8rem; text-align: right; border-top: 1px solid var(--border); vertical-align: top; }
.cmp thead th { background: var(--surface-2); text-align: right; position: sticky; top: 0; vertical-align: bottom; overflow-wrap: anywhere; min-width: 130px; }
.cmp thead th:first-child, .cmp tbody th[scope="row"] { text-align: left; position: sticky; left: 0; background: var(--surface); min-width: 150px; z-index: 1; }
.cmp thead th:first-child { background: var(--surface-2); z-index: 2; }
.cmp tbody th[scope="row"] { font-weight: 500; }
.cmp tr.strong th[scope="row"], .cmp tr.strong td { font-weight: 700; }
.cmp th[scope="rowgroup"] { background: var(--accent-soft); text-align: left; font-size: .85rem; text-transform: uppercase; letter-spacing: .04em; color: var(--text); }
.cmp td.best { background: var(--best-bg); color: var(--best-text); font-weight: 700; box-shadow: inset 0 0 0 2px var(--c-gift); }
.badge-best {
  display: inline-block; margin-right: .4rem; padding: 0 .4rem; font-size: .7rem; font-weight: 800; letter-spacing: .06em;
  border: 2px solid currentColor; border-radius: 4px; vertical-align: middle;
}
.row-note { display: block; font-weight: 400; color: var(--muted); font-size: .78rem; margin-top: .1rem; }
.empty { background: var(--surface); border: 2px dashed var(--border); border-radius: 12px; padding: 1.5rem; text-align: center; }

/* ---------- enter ---------- */
.enter-grid { display: grid; grid-template-columns: 300px minmax(0, 1fr); gap: 1.25rem; align-items: start; }
.pane-actions { display: flex; flex-wrap: wrap; gap: .5rem; margin-bottom: .75rem; }
.school-list { list-style: none; margin: 0; padding: 0; display: grid; gap: .5rem; }
.school-item { background: var(--surface); border: 2px solid var(--border); border-radius: 10px; padding: .5rem; }
.school-item.current { border-color: var(--accent); box-shadow: inset 6px 0 0 var(--accent); }
.school-pick { font: inherit; font-weight: 700; text-align: left; width: 100%; background: none; border: 0; color: var(--text); cursor: pointer; padding: .25rem .25rem .25rem .5rem; overflow-wrap: anywhere; min-height: 36px; }
.school-item .row-actions { display: flex; gap: .4rem; padding-left: .5rem; margin-top: .25rem; }
.tagpill { display: inline-block; font-size: .7rem; font-weight: 800; border: 2px solid var(--muted); color: var(--muted); border-radius: 999px; padding: 0 .45rem; margin-left: .4rem; vertical-align: middle; }
.cur-mark { font-size: .75rem; color: var(--accent); font-weight: 700; margin-left: .4rem; }

.summary {
  position: sticky; top: 108px; z-index: 5; display: grid; grid-template-columns: repeat(auto-fit, minmax(130px, 1fr));
  gap: .5rem; background: var(--surface); border: 2px solid var(--accent); border-radius: 12px; padding: .6rem .8rem; margin: 0 0 1rem; box-shadow: var(--shadow);
}
.summary div { min-width: 0; }
.summary dt { color: var(--muted); font-size: .78rem; font-weight: 600; }
.summary dd { margin: 0; font-weight: 700; font-size: 1.05rem; overflow-wrap: anywhere; }
fieldset { border: 1px solid var(--border); border-radius: 12px; background: var(--surface); padding: .8rem 1rem 1rem; margin: 0 0 1rem; min-width: 0; }
legend { padding: 0 .4rem; font-size: 1rem; }
.fgrid { display: grid; grid-template-columns: repeat(auto-fit, minmax(230px, 1fr)); gap: .8rem 1rem; }
.fgrid .wide { grid-column: 1 / -1; }
.money, .suffixed { position: relative; display: flex; align-items: center; }
.money .pre, .suffixed .suf-txt { position: absolute; color: var(--muted); font-weight: 700; pointer-events: none; }
.money .pre { left: .75rem; }
.money input { padding-left: 1.6rem; }
.suffixed .suf-txt { right: .75rem; }
.suffixed input { padding-right: 1.8rem; }
.radios { display: flex; flex-wrap: wrap; gap: .5rem 1.25rem; }
.radios label { font-weight: 500; display: flex; align-items: center; gap: .4rem; min-height: 44px; }
.radios input { width: 20px; height: 20px; }

/* ---------- percent of need met: coloured text (a word is always available to screen readers) ---------- */
:root { --n-great: #0b6b35; --n-solid: #1a5aa6; --n-fair: #8a5300; --n-bad: #b3202a; }
@media (prefers-color-scheme: dark) { :root:not([data-theme="light"]) { --n-great: #6fe0a0; --n-solid: #8fb8ff; --n-fair: #f0b24a; --n-bad: #ff8d90; } }
:root[data-theme="dark"] { --n-great: #6fe0a0; --n-solid: #8fb8ff; --n-fair: #f0b24a; --n-bad: #ff8d90; }
.need { font-weight: 700; }
.need-great { color: var(--n-great); } .need-solid { color: var(--n-solid); } .need-fair { color: var(--n-fair); } .need-bad { color: var(--n-bad); }
.paper .lt-n { font-weight: 700; }
.paper .lt-n-great { color: #0b6b35; } .paper .lt-n-solid { color: #1a5aa6; } .paper .lt-n-fair { color: #8a5300; } .paper .lt-n-bad { color: #b3202a; }
@media print { #printArea .lt-n { -webkit-print-color-adjust: exact; print-color-adjust: exact; } }
.paper .lt-inner { gap: 8px; margin: 0; }
.paper .lt-inner-foot { padding: 2px 7px 4px; }
.paper .lt-inner .lt-tbl { font-size: .9em; }

/* ---------- earnings combobox ---------- */
.combo { position: relative; }
.combo-list { position: absolute; z-index: 15; left: 0; right: 0; top: 100%; margin: 2px 0 0; padding: .25rem; list-style: none; max-height: 18rem; overflow: auto; background: var(--surface); border: 2px solid var(--accent); border-radius: 8px; box-shadow: var(--shadow), 0 8px 24px rgba(0, 0, 0, .25); }
.combo-list li { padding: .45rem .6rem; border-radius: 6px; cursor: pointer; display: flex; flex-wrap: wrap; gap: .1rem .6rem; align-items: baseline; }
.combo-list li[aria-selected="true"], .combo-list li:hover { background: var(--accent-soft); outline: 2px solid var(--accent); outline-offset: -2px; }
.opt-name { font-weight: 700; overflow-wrap: anywhere; }

/* ---------- return on investment ---------- */
.roi-card h4 { margin: 0 0 .5rem; font-size: 1rem; overflow-wrap: anywhere; }
.hits { list-style: none; margin: .25rem 0 .5rem; padding: 0; display: grid; gap: .35rem; }
.hit { font: inherit; text-align: left; width: 100%; min-height: 44px; cursor: pointer; color: var(--text); background: var(--surface-2); border: 2px solid var(--border); border-radius: 8px; padding: .4rem .6rem; display: flex; flex-wrap: wrap; gap: .1rem .6rem; align-items: baseline; }
.hit:hover { border-color: var(--accent); }
.hit-name { font-weight: 700; overflow-wrap: anywhere; }
.how summary { cursor: pointer; font-weight: 700; }
.how ul { margin: .6rem 0 0; padding-left: 1.2rem; }
.how li { margin-bottom: .4rem; }

/* ---------- letter view ---------- */
.letter-controls { display: grid; grid-template-columns: repeat(auto-fit, minmax(200px, 1fr)); gap: .8rem 1rem; margin-bottom: .5rem; }
.paper-wrap { padding: 0; }

/* The letter is ALWAYS a light paper document, whatever the app theme. */
.paper {
  --lt-slate: #4f6485;
  --lt-olive: #7b7842; /* template olive, darkened ~9% so white text reaches 4.5:1 */
  --lt-band: #d9d9d9;
  --lt-ink: #111111;
  background: #ffffff;
  color: var(--lt-ink);
  color-scheme: light;
  font: 13px/1.3 Arial, Helvetica, sans-serif;
  max-width: 820px;
  margin: 0 auto;
  padding: 14px;
  border: 1px solid #b9c0cc;
  box-shadow: var(--shadow);
}
.paper * { box-sizing: border-box; }
.paper p, .paper h3, .paper h4 { margin: 0; color: var(--lt-ink); }
.lt-head { background: var(--lt-slate); color: #fff; border-radius: 6px; padding: 10px 12px 9px; margin-bottom: 8px; }
.lt-head * { color: #fff !important; }
.lt-head-top { display: flex; justify-content: space-between; gap: 12px; align-items: flex-start; }
.lt-school { font-size: 1.45em; font-weight: 700; overflow-wrap: anywhere; }
.lt-date { font-weight: 700; font-size: .9em; white-space: nowrap; }
.lt-sub { font-weight: 700; font-size: 1.1em; margin-top: 4px !important; }
.lt-stu { font-weight: 700; font-size: .9em; margin-top: 6px !important; }
.lt-box { border: 2px solid var(--lt-slate); border-radius: 6px; overflow: hidden; background: #fff; margin: 0 0 8px; break-inside: avoid; }
.lt-box.olive { border-color: var(--lt-olive); }
.lt-bar { background: var(--lt-slate); color: #fff !important; font-size: 1.2em; font-weight: 700; padding: 3px 8px; }
.lt-box.olive .lt-bar { background: var(--lt-olive); }
.paper .lt-bar { color: #fff; }
.lt-h { font-size: 1.15em; font-weight: 700; margin: 4px 0 1px !important; }
.lt-p { font-size: .95em; margin: 0 0 6px !important; }
.lt-tbl { width: 100%; border-collapse: collapse; table-layout: fixed; font-size: .93em; }
.lt-tbl th, .lt-tbl td { padding: 1px 5px; text-align: left; font-weight: 400; vertical-align: top; color: var(--lt-ink); }
.lt-tbl tr.band th, .lt-tbl tr.band td { background: var(--lt-band); }
.lt-tbl tr.strong th, .lt-tbl tr.strong td { font-weight: 700; }
.lt-tbl .sub { display: block; font-size: .82em; font-weight: 400; }
.lt-tbl th.indent { padding-left: 1.8em; }
.lt-tbl .c { text-align: center; }
.lt-cost thead th { font-weight: 700; text-align: center; }
.lt-cost col { width: auto; }
.lt-tbl .c-label { width: 62%; }
.lt-tbl .c-val { width: 38%; }
.lt-cost tbody th { width: 33.3%; }
.lt-tbl td.v { text-align: right; white-space: nowrap; }
.lt-tbl .num { display: inline-block; text-align: right; }
.lt-tbl .suf { display: inline-block; width: 3.4em; text-align: left; padding-left: .15em; }
.lt-tbl .line { display: block; }
.lt-two { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; align-items: start; }
.lt-col { min-width: 0; }
.lt-foot { font-size: .85em; margin: 0 0 8px !important; }
.lt-body { padding: 3px 7px 4px; font-size: .88em; }
.lt-body ul { margin: 3px 0 0; padding-left: 1.4em; }
.lt-note { border: 2px solid var(--lt-slate); border-radius: 6px; padding: 4px 7px 6px; margin: 0 0 8px; background: #fff; break-inside: avoid; }
.lt-note.tall { min-height: 3.6em; }
.lt-ul { font-size: .92em; font-weight: 700; text-decoration: underline; overflow-wrap: anywhere; }
.lt-text { font-size: .9em; margin-top: 4px !important; overflow-wrap: anywhere; white-space: normal; }
.lt-info { line-height: 1.55; }
.paper a { color: #143c8c; text-decoration: underline; overflow-wrap: anywhere; }

@media (max-width: 640px) {
  .lt-two { grid-template-columns: 1fr; gap: 0; }
  .paper { padding: 8px; font-size: 12.5px; }
}

/* ---------- dialogs / drop zone ---------- */
dialog { border: 2px solid var(--border); border-radius: 14px; background: var(--surface); color: var(--text); padding: 1.2rem; max-width: min(480px, calc(100vw - 32px)); }
dialog::backdrop { background: rgba(10, 14, 24, .6); }
dialog:not([open]) { display: none; }
.dlg-actions { display: flex; justify-content: flex-end; gap: .6rem; flex-wrap: wrap; }
.drop { border: 3px dashed var(--border); border-radius: 12px; padding: 1rem; text-align: center; background: var(--surface-2); }
.drop.over { border-color: var(--accent); background: var(--accent-soft); }
.drop .field { max-width: 420px; margin: 0 auto; text-align: left; }
.drop-text { font-weight: 600; }
.msg { border-radius: 8px; padding: .7rem .9rem; margin-top: .8rem; border: 2px solid var(--border); background: var(--surface-2); }
.msg.err { border-color: var(--danger); background: var(--danger-soft); }
.msg.ok { border-color: var(--ok); }
.msg ul { margin: .3rem 0; padding-left: 1.2rem; max-height: 9rem; overflow: auto; }

/* ---------- small screens ---------- */
@media (max-width: 860px) {
  .enter-grid { grid-template-columns: 1fr; }
  .summary { top: 118px; }
}
@media (max-width: 520px) {
  body { font-size: 15.5px; }
  .top { position: static; }
  .summary { grid-template-columns: repeat(2, minmax(0, 1fr)); position: static; }
  .stat .v { font-size: 1.4rem; }
}
@media (prefers-reduced-motion: no-preference) {
  .btn, .tab { transition: border-color .12s, color .12s; }
}

/* ---------- printing: only the letter(s) ---------- */
#printArea { display: none; }

@media print {
  @page { size: letter portrait; margin: 0.35in; }
  html, body { background: #fff !important; color: #000; }
  body > *:not(#printArea) { display: none !important; }
  #printArea { display: block !important; }
  #printArea .paper {
    -webkit-print-color-adjust: exact; print-color-adjust: exact;
    max-width: none; width: 100%; margin: 0; padding: 0; border: 0; box-shadow: none;
    font-size: 8pt; line-height: 1.2;
    break-after: page; page-break-after: always; break-inside: avoid;
  }
  #printArea .paper:last-child { break-after: auto; page-break-after: auto; }
  #printArea .paper *, #printArea .paper *::before { -webkit-print-color-adjust: exact; print-color-adjust: exact; }
  #printArea .lt-two { display: grid !important; grid-template-columns: 1fr 1fr !important; gap: 11pt !important; }
  #printArea .lt-box, #printArea .lt-note, #printArea .lt-head { break-inside: avoid; page-break-inside: avoid; }
  #printArea .paper a { color: #143c8c; }
}
