/* College Cost Planner PWA — hand-rolled, mobile-first (375px), no framework.
   Light/dark via prefers-color-scheme. */

:root {
  --bg: #f4f6fa;
  --surface: #ffffff;
  --text: #1c2431;
  --muted: #5c6b80;
  --border: #d7dee8;
  --accent: #1e3a5f;
  --accent-contrast: #ffffff;
  --link: #24558c;
  --danger: #b3261e;
  --warn-bg: #fdf3d7;
  --warn-border: #e2c464;
  --warn-text: #6a5310;
  --info-bg: #e3edf9;
  --info-border: #9dbde4;
  --demo-bg: #efe3f9;
  --demo-border: #bb93e0;
  /* semantic verdict palette (keys come from the engine's verdict.color) */
  --verdict-red: #b3261e;
  --verdict-orange: #c05e12;
  --verdict-yellow: #8f7a0a;
  --verdict-green: #2e7d43;
  --chart-cost: #b3745e;
  --chart-funded: #4d789c;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #12161d;
    --surface: #1b2230;
    --text: #e6ebf2;
    --muted: #9aa7b8;
    --border: #333e50;
    --accent: #7ba3d0;
    --accent-contrast: #10151d;
    --link: #8fb6e2;
    --danger: #ff8a80;
    --warn-bg: #3a3113;
    --warn-border: #806a1f;
    --warn-text: #ecd888;
    --info-bg: #1c2c40;
    --info-border: #3c5a80;
    --demo-bg: #2d2140;
    --demo-border: #6f4e96;
    --verdict-red: #ff8a80;
    --verdict-orange: #ffb26b;
    --verdict-yellow: #e3cf5c;
    --verdict-green: #7ed09a;
    --chart-cost: #cf8a70;
    --chart-funded: #6f9dc4;
  }
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  font: 16px/1.5 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  background: var(--bg);
  color: var(--text);
  padding-bottom: calc(64px + env(safe-area-inset-bottom));
}

a { color: var(--link); }
h1 { font-size: 1.35rem; margin: 0.2rem 0 0.6rem; }
h2 { font-size: 1.1rem; margin: 1rem 0 0.4rem; }
h3 { font-size: 1rem; margin: 0.8rem 0 0.3rem; }
p { margin: 0.4rem 0; }
.muted { color: var(--muted); font-size: 0.9rem; }
.small { font-size: 0.85rem; }
.hidden { display: none !important; }

/* ---------- header / footer / nav ---------- */
.app-header {
  display: flex; align-items: center; gap: 0.5rem;
  padding: 0.6rem 0.9rem;
  background: var(--accent); color: var(--accent-contrast);
}
.app-title { font-weight: 600; flex: 1; }
.engine-badge {
  font-size: 0.72rem; padding: 0.15rem 0.5rem; border-radius: 999px;
  background: rgba(255, 255, 255, 0.18); color: inherit;
  letter-spacing: 0.02em;
}
@media (prefers-color-scheme: dark) {
  .app-header { color: var(--text); }
}

.app-footer {
  margin: 1.4rem 0.9rem 0.8rem; padding-top: 0.7rem;
  border-top: 1px solid var(--border);
  color: var(--muted); font-size: 0.8rem; text-align: center;
}

.bottom-nav {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 20;
  display: flex;
  background: var(--surface);
  border-top: 1px solid var(--border);
  padding-bottom: env(safe-area-inset-bottom);
}
.bottom-nav a {
  flex: 1; text-align: center; padding: 0.8rem 0.1rem;
  font-size: 0.78rem; text-decoration: none; color: var(--muted);
  min-height: 44px;
}
.bottom-nav a.active {
  color: var(--accent); font-weight: 700;
  border-top: 2px solid var(--accent); margin-top: -1px;
}
@media (prefers-color-scheme: dark) {
  .bottom-nav a.active { color: var(--link); border-top-color: var(--link); }
}

/* ---------- layout ---------- */
.view { padding: 0.9rem; max-width: 720px; margin: 0 auto; outline: none; }
@media (min-width: 900px) { .view { max-width: 860px; } }

.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 0.9rem;
  margin: 0.7rem 0;
}

/* ---------- banners ---------- */
#banners { max-width: 720px; margin: 0 auto; padding: 0 0.9rem; }
@media (min-width: 900px) { #banners { max-width: 860px; } }
.banner {
  border-radius: 8px; border: 1px solid var(--info-border);
  background: var(--info-bg); padding: 0.6rem 0.8rem;
  margin: 0.6rem 0; font-size: 0.9rem;
}
.banner-warn { background: var(--warn-bg); border-color: var(--warn-border); color: var(--warn-text); }
.banner-demo { background: var(--demo-bg); border-color: var(--demo-border); }
.banner-danger { border-color: var(--danger); color: var(--danger); background: var(--surface); }

/* ---------- forms ---------- */
label.field { display: block; margin: 0.55rem 0; }
label.field > span {
  display: block; font-size: 0.84rem; color: var(--muted); margin-bottom: 0.15rem;
}
input[type="text"], input[type="number"], input[type="date"], input[type="url"],
select, textarea {
  width: 100%; padding: 0.55rem 0.6rem; font: inherit;
  border: 1px solid var(--border); border-radius: 8px;
  background: var(--bg); color: var(--text);
  min-height: 44px;
}
textarea { min-height: 90px; font-family: ui-monospace, monospace; font-size: 0.82rem; }
input:focus, select:focus, textarea:focus, button:focus-visible, a:focus-visible {
  outline: 2px solid var(--accent); outline-offset: 1px;
}
@media (prefers-color-scheme: dark) {
  input:focus, select:focus, textarea:focus, button:focus-visible, a:focus-visible {
    outline-color: var(--link);
  }
}
.check { display: flex; gap: 0.5rem; align-items: flex-start; margin: 0.55rem 0; }
.check input { width: 1.15rem; height: 1.15rem; margin-top: 0.2rem; }
.grid2 { display: grid; grid-template-columns: 1fr; gap: 0 0.8rem; }
@media (min-width: 560px) { .grid2 { grid-template-columns: 1fr 1fr; } }

fieldset.section {
  border: 1px solid var(--border); border-radius: 10px;
  margin: 0.8rem 0; padding: 0.2rem 0.9rem 0.8rem;
  background: var(--surface);
}
fieldset.section > legend {
  font-weight: 700; padding: 0 0.4rem; font-size: 0.95rem;
}
details.section { border: 1px solid var(--border); border-radius: 10px; margin: 0.8rem 0; background: var(--surface); }
details.section > summary { font-weight: 700; padding: 0.75rem 0.9rem; cursor: pointer; min-height: 44px; }
details.section > .section-body { padding: 0 0.9rem 0.9rem; }

/* ---------- buttons ---------- */
button, .btn {
  font: inherit; border-radius: 8px; border: 1px solid var(--border);
  background: var(--surface); color: var(--text);
  padding: 0.6rem 1rem; cursor: pointer; min-height: 44px;
}
.btn-primary { background: var(--accent); color: var(--accent-contrast); border-color: var(--accent); font-weight: 600; }
.btn-danger { background: transparent; color: var(--danger); border-color: var(--danger); }
.btn-small { padding: 0.35rem 0.7rem; min-height: 36px; font-size: 0.85rem; }
button[disabled] { opacity: 0.5; cursor: not-allowed; }
.btn-row { display: flex; flex-wrap: wrap; gap: 0.5rem; margin: 0.7rem 0; }

/* ---------- verdict card ---------- */
.verdict-card { border-left: 6px solid var(--muted); }
.verdict-label { font-size: 1.15rem; font-weight: 800; letter-spacing: 0.01em; }
.verdict-red    { border-left-color: var(--verdict-red); }    .verdict-red    .verdict-label { color: var(--verdict-red); }
.verdict-orange { border-left-color: var(--verdict-orange); } .verdict-orange .verdict-label { color: var(--verdict-orange); }
.verdict-yellow { border-left-color: var(--verdict-yellow); } .verdict-yellow .verdict-label { color: var(--verdict-yellow); }
.verdict-green  { border-left-color: var(--verdict-green); }  .verdict-green  .verdict-label { color: var(--verdict-green); }

/* ---------- tables ---------- */
.table-scroll { overflow-x: auto; -webkit-overflow-scrolling: touch; }
table.data {
  border-collapse: collapse; width: 100%; font-size: 0.84rem;
  min-width: 560px;
}
table.data th, table.data td {
  border-bottom: 1px solid var(--border);
  padding: 0.4rem 0.5rem; text-align: right; white-space: nowrap;
}
table.data th:first-child, table.data td:first-child { text-align: left; }
table.data thead th { position: sticky; top: 0; background: var(--surface); }
table.kv { width: 100%; border-collapse: collapse; }
table.kv td { padding: 0.3rem 0.2rem; border-bottom: 1px solid var(--border); }
table.kv td:last-child { text-align: right; font-variant-numeric: tabular-nums; }
tr.row-alert td { color: var(--danger); font-weight: 700; }

/* ---------- chart ---------- */
.chart-wrap { overflow-x: auto; }
.chart-legend { display: flex; gap: 1rem; font-size: 0.8rem; margin: 0.3rem 0; }
.chart-legend .swatch { display: inline-block; width: 12px; height: 12px; border-radius: 3px; margin-right: 4px; vertical-align: -1px; }

/* ---------- disclaimer gate ---------- */
.gate {
  position: fixed; inset: 0; z-index: 100;
  background: color-mix(in srgb, var(--bg) 75%, black 25%);
  display: flex; align-items: center; justify-content: center;
  padding: 1rem;
}
.gate-card {
  background: var(--surface); border: 1px solid var(--border);
  border-radius: 12px; padding: 1.2rem; max-width: 480px;
  box-shadow: 0 10px 40px rgba(0, 0, 0, 0.35);
}
.gate-card h1 { margin-top: 0; }
.gate-card button { width: 100%; margin-top: 0.8rem; }

/* ---------- progress / status ---------- */
.engine-progress { font-size: 0.85rem; color: var(--muted); }
.issues li.error { color: var(--danger); }
.issues li.warning { color: var(--warn-text); }
@media (prefers-color-scheme: dark) { .issues li.warning { color: var(--warn-text); } }

.scenario-item { display: flex; flex-wrap: wrap; align-items: center; gap: 0.5rem; padding: 0.55rem 0; border-bottom: 1px solid var(--border); }
.scenario-item .name { flex: 1 1 100%; font-weight: 600; }
@media (min-width: 560px) { .scenario-item .name { flex: 1; } }

.radio-row { display: flex; flex-direction: column; gap: 0.4rem; margin: 0.5rem 0; }
.radio-row label { display: flex; gap: 0.5rem; align-items: flex-start; }
.radio-row input { width: 1.1rem; height: 1.1rem; margin-top: 0.2rem; }

/* ---------- Cash Flow / Spending (bank imports, S12) ---------- */
.privacy-note { font-weight: 600; font-size: 0.88rem; }
.queue-item { border-top: 1px solid var(--border); padding: 0.55rem 0; }
.tag {
  display: inline-block; font-size: 0.7rem; font-weight: 700;
  padding: 0.05rem 0.4rem; border-radius: 999px; letter-spacing: 0.03em;
  vertical-align: 1px;
}
.tag-warn { background: var(--warn-bg); border: 1px solid var(--warn-border); color: var(--warn-text); }

/* dependency-free SVG pie + legend */
.pie-wrap { display: flex; flex-wrap: wrap; gap: 1rem; align-items: flex-start; margin: 0.6rem 0; }
.pie-wrap svg { flex: 0 0 auto; }
.pie-legend { flex: 1 1 220px; display: flex; flex-direction: column; gap: 0.25rem; font-size: 0.84rem; min-width: 200px; }
.pie-legend-item { display: flex; align-items: baseline; gap: 0.45rem; }
.pie-legend-item .swatch { display: inline-block; width: 12px; height: 12px; border-radius: 3px; flex: 0 0 auto; align-self: center; }
.pie-legend-label { flex: 1; overflow-wrap: anywhere; }
.pie-legend-value { font-variant-numeric: tabular-nums; white-space: nowrap; }

/* derivation-schedule modal */
.modal-card { max-width: 640px; width: 100%; max-height: 85vh; display: flex; flex-direction: column; }
.schedule-pre {
  overflow: auto; flex: 1; background: var(--bg); border: 1px solid var(--border);
  border-radius: 8px; padding: 0.7rem; font-size: 0.72rem; line-height: 1.45;
  white-space: pre; margin: 0.4rem 0;
}

/* transparency page ("What we can see", story A3) */
.privacy-sig-head {
  display: flex; align-items: baseline; justify-content: space-between;
  gap: 0.5rem; flex-wrap: wrap;
}
.privacy-sig-head h3 { margin: 0; }
.pill {
  display: inline-block; font-size: 0.72rem; font-weight: 600;
  padding: 0.1rem 0.5rem; border-radius: 999px; white-space: nowrap;
  background: var(--info-bg); border: 1px solid var(--info-border);
  color: var(--text);
}
.pill-warn {
  background: var(--warn-bg); border-color: var(--warn-border);
  color: var(--warn-text);
}
