/* ============================================================
   lifeproj — thin reskin layer over the Agate / IL Research Labs
   house system (agate-ui.css + ilr_labs.css load first).

   This file does NOT redefine tokens. It maps the app's own
   classes onto the house look, reading house variables so every
   surface flips automatically under data-theme="dark". The nav,
   provisional signal, agate line, and theme toggle come straight
   from the house CSS; everything below is the app's own furniture
   restyled to match.
   ============================================================ */

/* ---- layout ------------------------------------------------ */
main {
  max-width: 1320px;
  margin: 0 auto;
  padding: var(--sp-6) var(--gutter) 110px;
}
/* side menu + content */
.layout {
  display: grid;
  grid-template-columns: 248px minmax(0, 1fr);
  gap: var(--sp-6);
  align-items: start;
}
.content { display: flex; flex-direction: column; gap: var(--sp-5); min-width: 0; }
.step { display: flex; flex-direction: column; gap: var(--sp-5); }
section.panel.step { display: block; }
.step[hidden] { display: none !important; }   /* hidden always wins */
p.sub.step-lede { margin: calc(-1 * var(--sp-3)) 0 var(--sp-6); font-size: var(--fs-ui); }
.labs-provisional { margin-bottom: var(--sp-2); }

/* Theme-flip guard. The house transitions background-color / border-color on the
   theme change, but those properties read var() tokens; some engines don't
   re-resolve a *transitioned* property when its custom property changes, leaving
   the element stuck on the old color. app.js adds .theme-switching for the flip so
   every token change applies instantly; hovers still animate afterward. */
html.theme-switching *,
html.theme-switching *::before,
html.theme-switching *::after { transition: none !important; }

/* ---- panels (the app's sections) --------------------------- */
.panel {
  background: var(--card);
  border: 1px solid var(--line);
  padding: var(--sp-6);
}
.panel > h2 { font-size: var(--fs-h2); margin: 0 0 var(--sp-5); }

/* section labels become house eyebrows */
.section-head {
  font-family: var(--font-ui);
  font-size: var(--fs-label);
  font-weight: 400;
  letter-spacing: var(--track-label);
  text-transform: uppercase;
  color: var(--ink-40);
  margin: var(--sp-6) 0 var(--sp-4);
  padding-top: var(--sp-4);
  border-top: 1px solid var(--line);
}
.section-head:first-of-type { margin-top: 0; padding-top: 0; border-top: 0; }

/* helper prose */
.sub {
  font-family: var(--font-ui);
  font-size: var(--fs-caption);
  color: var(--ink-60);
  line-height: 1.6;
  margin: var(--sp-2) 0 0;
  max-width: 74ch;
}

/* ---- form grid + fields ------------------------------------ */
.grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(190px, 1fr));
  gap: var(--sp-4);
}

label {
  display: flex;
  flex-direction: column;
  gap: 6px;
  font-family: var(--font-ui);
  font-size: var(--fs-caption);
  font-weight: 700;
  color: var(--ink);
}

input, select, textarea {
  font-family: var(--font-ui);
  font-size: var(--fs-ui);
  color: var(--ink);
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: 0;
  padding: 10px 12px;
  transition: border-color var(--t-fast) var(--ease);
}
input:hover, select:hover, textarea:hover { border-color: var(--ink-40); }
input:focus, select:focus, textarea:focus { border-color: var(--ink); outline: none; }
input::placeholder { color: var(--ink-40); }
input[type=number] { font-variant-numeric: tabular-nums; }

.check {
  flex-direction: row;
  align-items: center;
  gap: var(--sp-2);
  font-weight: 400;
  color: var(--ink-80);
}
.check input { width: auto; }

/* ---- buttons ----------------------------------------------- */
/* The accent is spent, not sprayed: Run is the one primary action; everything
   else is quiet. Modal commit buttons (bare, non-secondary) read primary too. */
.actions { display: flex; gap: var(--sp-2); align-items: center; flex-wrap: wrap; margin-top: var(--sp-5); }

button {
  font-family: var(--font-ui);
  font-size: var(--fs-ui);
  font-weight: 700;
  letter-spacing: 0.2px;
  border-radius: 0;
  cursor: pointer;
  transition: background var(--t-fast) var(--ease), color var(--t-fast) var(--ease),
              border-color var(--t-fast) var(--ease);
}

/* filled primary — Run + modal commit (Done / Load / Close) */
#run, #pctl_run,
.modal-card button:not(.secondary):not(.rowdel):not(.linkbtn) {
  padding: 12px 20px;
  border: 1px solid var(--ink);
  background: var(--ink);
  color: var(--paper);
}
#run:hover, #pctl_run:hover,
.modal-card button:not(.secondary):not(.rowdel):not(.linkbtn):hover {
  background: var(--accent); border-color: var(--accent); color: var(--on-accent);
}
#run:disabled, #pctl_run:disabled {
  border-color: var(--line); background: transparent; color: var(--ink-40); cursor: not-allowed;
}

/* outline quiet — .secondary anywhere */
button.secondary {
  padding: 12px 20px;
  border: 1px solid var(--ink);
  background: transparent;
  color: var(--ink);
}
button.secondary:hover { background: var(--ink); color: var(--paper); }
button.secondary:disabled { border-color: var(--line); color: var(--ink-40); cursor: not-allowed; }

/* schedule / editor triggers — look like a field, act like a link */
.linkbtn {
  text-align: left;
  background: var(--card);
  color: var(--ink);
  border: 1px solid var(--line);
  padding: 10px 12px;
  font-family: var(--font-ui);
  font-size: var(--fs-ui);
  font-weight: 400;
}
.linkbtn:hover { border-color: var(--ink-40); }
.linkbtn span { font-weight: 700; }

/* rate-overrides trigger in the actions row */
.ratesbtn { padding: 12px 16px; }
.ratesbtn.active { border-color: var(--accent); color: var(--accent-text); font-weight: 700; }

/* row delete (period editors) */
.rowdel {
  padding: 4px 10px;
  border: 1px solid var(--line);
  background: transparent;
  color: var(--ink-60);
}
.rowdel:hover { border-color: var(--accent); color: var(--accent-text); }

/* ---- illustration summary → house stat cards --------------- */
.summary-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(190px, 1fr));
  gap: var(--sp-4);
}
.summary-item {
  background: var(--card);
  border: 1px solid var(--line);
  padding: var(--sp-4) var(--sp-5);
  display: flex;
  flex-direction: column;
  gap: 6px;
}
/* restore hiding for the conditionally-shown items (CVAT / GLP / lapse / MEC) */
.summary-item[hidden] { display: none; }
.summary-label {
  font-family: var(--font-ui);
  font-size: var(--fs-label);
  font-weight: 400;
  letter-spacing: var(--track-label);
  text-transform: uppercase;
  color: var(--ink-40);
}
.summary-value {
  font-family: var(--font-ui);
  font-variant-numeric: tabular-nums;
  font-weight: 700;
  font-size: 26px;
  line-height: 1.05;
  color: var(--ink);
}

/* ---- notes: warnings + the solve/ratesolve "finding" ------- */
.warning {
  font-family: var(--font-ui);
  font-size: var(--fs-caption);
  color: var(--ink-80);
  background: var(--card);
  border: 1px solid var(--line);
  border-left: 4px solid var(--accent);
  padding: var(--sp-3) var(--sp-4);
  margin: var(--sp-4) 0 0;
  line-height: 1.55;
}
/* the solve result / rate-solve result are the one spent finding per view */
.notice {
  font-family: var(--font-ui);
  font-size: var(--fs-caption);
  color: var(--ink-80);
  background: var(--card);
  border: 1px solid var(--line);
  border-left: 4px solid var(--accent);
  padding: var(--sp-4) var(--sp-5);
  margin: var(--sp-4) 0 0;
  line-height: 1.55;
}
/* infeasible / cautionary: drop the accent, wear the house "penciled-in" hatch */
.notice.infeasible {
  border-left-color: var(--ink-40);
  background: repeating-linear-gradient(-45deg,
    transparent 0 6px, color-mix(in srgb, var(--ink) 5%, transparent) 6px 7px);
}

/* ---- report tables: house hairline discipline -------------- */
.tablewrap { overflow-x: auto; margin-top: var(--sp-4); }

#step_results table {
  width: 100%;
  border-collapse: collapse;
  font-family: var(--font-ui);
  font-size: var(--fs-ui);
  background: var(--card);
  border: 1px solid var(--line);
  font-variant-numeric: tabular-nums;
}
#step_results table th {
  font-size: var(--fs-label);
  letter-spacing: 1.5px;
  text-transform: uppercase;
  font-weight: 400;
  color: var(--ink-40);
  text-align: right;
  padding: 10px 14px;
  border-bottom: 1px solid var(--ink);
  white-space: nowrap;
}
#step_results table th:first-child { text-align: left; }
#step_results table td {
  padding: 9px 14px;
  border-bottom: 1px solid var(--line);
  color: var(--ink-80);
  text-align: right;
  white-space: nowrap;
}
#step_results table td:first-child { text-align: left; color: var(--ink); }
#step_results table tbody tr:last-child td { border-bottom: 0; }
#step_results table tfoot td {
  border-top: 3px double var(--ink);   /* the double rule: a figure is final */
  font-weight: 700;
  color: var(--ink);
}

/* collapsible result sections */
.report-section { border-top: 1px solid var(--line); }
.report-section:first-of-type { margin-top: var(--sp-4); }
.report-section > summary {
  cursor: pointer; padding: 14px 2px;
  font-family: var(--font-ui); font-size: var(--fs-ui); font-weight: 700; color: var(--ink);
  list-style: none; display: flex; align-items: center; gap: var(--sp-2);
}
.report-section > summary::-webkit-details-marker { display: none; }
.report-section > summary::before { content: "▸"; color: var(--accent); font-size: 10px; }
.report-section[open] > summary::before { content: "▾"; }
.report-section .tablewrap { margin-top: 0; padding-bottom: var(--sp-4); }

/* inforce: the optional carrier values, collapsed by default */
.inforce-optional { margin-top: var(--sp-3); }
.inforce-optional > summary {
  cursor: pointer; font-family: var(--font-ui); font-size: var(--fs-caption);
  font-weight: 700; color: var(--accent);
}

/* the chart host (lw-charts draws its own bordered card inside) */
#chart { margin-bottom: var(--sp-4); }

/* ---- dialogs / modals -------------------------------------- */
dialog {
  border: 1px solid var(--ink);
  border-radius: 0;
  padding: 0;
  max-width: 420px;
  width: 90%;
  color: var(--ink-80);
  background: var(--card);
}
dialog::backdrop { background: color-mix(in srgb, var(--ink) 45%, transparent); }
.modal-card { padding: var(--sp-6); }
.modal-card > h2 { font-size: var(--fs-h3); margin: 0 0 var(--sp-4); }

/* period / schedule editor tables (everything except the dense rate grids) */
.modal-card table:not(.rates-table) {
  margin-top: var(--sp-3); width: 100%; border-collapse: collapse;
  font-family: var(--font-ui); font-size: var(--fs-caption);
}
.modal-card table:not(.rates-table) th {
  text-align: left; font-size: var(--fs-label); letter-spacing: 1px;
  text-transform: uppercase; color: var(--ink-40); font-weight: 400;
  padding: 6px 8px 6px 0; border-bottom: 1px solid var(--line);
}
.modal-card table:not(.rates-table) td {
  text-align: left; padding: 6px 8px 6px 0; border-bottom: 1px solid var(--line); color: var(--ink-80);
}
.modal-card td input, .modal-card td select { width: 100%; }
.modal-actions { display: flex; justify-content: flex-end; gap: var(--sp-2); margin-top: var(--sp-4); }

/* period modals (premium / distribution / dbo / face): four data columns + delete */
#premium_modal, #distribution_modal, #dbo_modal, #face_modal {
  max-width: none; width: min(96vw, 760px); }
#premium_table, #distribution_table, #dbo_table, #face_table {
  width: 100%; table-layout: fixed; }
#premium_table th, #premium_table td,
#distribution_table th, #distribution_table td,
#dbo_table th, #dbo_table td,
#face_table th, #face_table td { padding: 4px 8px 4px 0; }
#premium_table th:nth-child(1), #premium_table td:nth-child(1),
#premium_table th:nth-child(2), #premium_table td:nth-child(2),
#distribution_table th:nth-child(1), #distribution_table td:nth-child(1),
#distribution_table th:nth-child(2), #distribution_table td:nth-child(2),
#face_table th:nth-child(1), #face_table td:nth-child(1),
#face_table th:nth-child(2), #face_table td:nth-child(2) { width: 16%; }
#premium_table th:nth-child(3), #premium_table td:nth-child(3),
#distribution_table th:nth-child(3), #distribution_table td:nth-child(3),
#face_table th:nth-child(3), #face_table td:nth-child(3) { width: 27%; }
#premium_table th:nth-child(4), #premium_table td:nth-child(4),
#distribution_table th:nth-child(4), #distribution_table td:nth-child(4),
#face_table th:nth-child(4), #face_table td:nth-child(4) { width: 24%; }
#premium_table th:last-child, #premium_table td:last-child,
#distribution_table th:last-child, #distribution_table td:last-child,
#dbo_table th:last-child, #dbo_table td:last-child,
#face_table th:last-child, #face_table td:last-child { width: 44px; padding-right: 0; }
#dbo_table th:nth-child(1), #dbo_table td:nth-child(1),
#dbo_table th:nth-child(2), #dbo_table td:nth-child(2) { width: 22%; }
#dbo_table th:nth-child(3), #dbo_table td:nth-child(3) { width: 44%; }
#premium_table td input, #premium_table td select,
#distribution_table td input, #distribution_table td select,
#dbo_table td input, #dbo_table td select,
#face_table td input, #face_table td select { width: 100%; box-sizing: border-box; padding: 6px 8px; }
#premium_table .rowdel, #distribution_table .rowdel,
#dbo_table .rowdel, #face_table .rowdel { padding: 4px 8px; }

/* JSON boxes */
.json-box {
  width: 100%; margin-top: var(--sp-3); padding: var(--sp-3);
  border: 1px solid var(--line); border-radius: 0;
  font-family: ui-monospace, "SFMono-Regular", Menlo, Consolas, monospace;
  font-size: var(--fs-caption); color: var(--ink); background: var(--shelf); resize: vertical;
}
code {
  font-family: ui-monospace, "SFMono-Regular", Menlo, Consolas, monospace;
  font-size: var(--fs-caption); background: var(--shelf); padding: 1px 4px; border: 1px solid var(--line);
}

/* ---- dense grids: rate overrides + benchmark --------------- */
#rates_modal { max-width: none; width: 96vw; }
#benchmark_modal, #benchdetail_modal { max-width: none; width: min(96vw, 760px); }
#benchjson_modal, #json_modal { max-width: 560px; }

.modal-wide { padding: var(--sp-6); }
.rates-toolbar { justify-content: flex-start; margin-top: var(--sp-3); }
.rates-wrap { max-height: 70vh; overflow: auto; border: 1px solid var(--line); }
.rates-table { font-size: var(--fs-caption); border-collapse: collapse; width: 100%; font-variant-numeric: tabular-nums; }
.rates-table th, .rates-table td {
  padding: 3px 5px; text-align: right; border-bottom: 1px solid var(--line); white-space: nowrap;
}
.rates-table thead th {
  position: sticky; top: 0; z-index: 2; background: var(--shelf);
  font-family: var(--font-ui); font-size: var(--fs-label); letter-spacing: 0.5px;
  text-transform: uppercase; font-weight: 700; color: var(--ink); text-align: right;
}
.rates-table thead th:first-child { left: 0; z-index: 3; }
.rates-table th.yr {
  position: sticky; left: 0; z-index: 1; background: var(--card);
  text-align: right; color: var(--ink-40); font-weight: 400; text-transform: none; letter-spacing: 0;
}
.rates-table td input {
  width: 88px; padding: 3px 5px; font-size: var(--fs-caption);
  border: 1px solid transparent; border-radius: 0; background: transparent; text-align: right;
}
.rates-table td input:hover { border-color: var(--line); }
.rates-table td input:focus { border-color: var(--accent); background: var(--card); outline: none; }
/* ghost = today's system rate (a placeholder, never submitted) */
.rates-table td input::placeholder { color: var(--ink-40); }
/* a cell the user has actually overridden reads solid + accented */
.rates-table td.ov input {
  color: var(--accent-text); font-weight: 700;
  background: color-mix(in srgb, var(--accent) 8%, var(--card));
}
.rates-table td input::-webkit-outer-spin-button,
.rates-table td input::-webkit-inner-spin-button { -webkit-appearance: none; margin: 0; }
.rates-table td input[type=number] { -moz-appearance: textfield; }

/* detailed benchmark: light separators between the per-metric column groups */
#benchmark_detail td:nth-child(3n),
#benchmark_detail thead tr:first-child th:nth-child(n+3),
#benchmark_detail thead tr:last-child th:nth-child(3n+1) { border-left: 1px solid var(--line); }

/* ---- benchmark diff severity — house-pure (no borrowed color) ----
   The system is one ink + one accent. So drift reads by emphasis, not by a
   traffic-light palette: within tolerance is quiet, larger drift is bold ink,
   the worst tier is the accent. */
td.diff-ok   { color: var(--ink-60); }
td.diff-warn { color: var(--ink); font-weight: 700; }
td.diff-bad  { color: var(--accent-text); font-weight: 700; }

/* ---- COI stress test — same house palette (ink + accent) ----
   A lapsed cell is the worst outcome, so it takes the accent; the maturity row
   is the terminal milestone, set off with a top hairline and bold ink. */
.stress-lapsed { color: var(--accent-text); font-weight: 700; }
#stress_table tr.stress-maturity td { border-top: 1px solid var(--ink); font-weight: 700; }

/* ---- side menu ----------------------------------------------
   A numbered list of steps (each with a one-line status), Run, then Results.
   Sticky, so Run and every step stay one click away. */
.sidenav {
  position: sticky;
  top: var(--sp-5);
  display: flex;
  flex-direction: column;
  gap: var(--sp-4);
  font-family: var(--font-ui);
}
.steps { list-style: none; margin: 0; padding: 0; border: 1px solid var(--line); background: var(--card); }
.steps li + li { border-top: 1px solid var(--line); }
.steps a {
  display: flex;
  gap: var(--sp-3);
  align-items: flex-start;
  padding: 10px 12px;
  color: var(--ink-80);
  text-decoration: none;
  border-left: 3px solid transparent;
}
.steps a:hover { background: color-mix(in srgb, var(--ink) 4%, var(--card)); color: var(--ink); }
.steps a.active {
  border-left-color: var(--accent);
  background: color-mix(in srgb, var(--accent) 7%, var(--card));
  color: var(--ink);
}
.step-num {
  flex: 0 0 22px;
  height: 22px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  border: 1px solid var(--ink-40);
  font-size: var(--fs-label);
  font-weight: 700;
  font-variant-numeric: tabular-nums;
}
.steps a.active .step-num { background: var(--ink); color: var(--paper); border-color: var(--ink); }
.step-text { display: flex; flex-direction: column; gap: 2px; min-width: 0; }
.step-name { font-size: var(--fs-ui); font-weight: 700; }
.step-badge {
  font-size: var(--fs-caption);
  color: var(--ink-60);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.step-badge[data-state="off"] { color: var(--ink-40); }
.step-badge[data-state="bad"] { color: var(--accent-text); font-weight: 700; }
.sidenav-run { display: flex; flex-direction: column; gap: var(--sp-2); }
.sidenav-run #run { width: 100%; }
.sidenav-tools { display: flex; flex-direction: column; gap: var(--sp-2); }
.tools-head {
  font-size: var(--fs-label);
  letter-spacing: var(--track-label);
  text-transform: uppercase;
  color: var(--ink-40);
}
.tools-row { display: flex; gap: var(--sp-2); }
.tools-row button { flex: 1 1 0; padding: 9px 8px; font-size: var(--fs-caption); }
.sidenav-tools .linkbtn { width: 100%; text-align: center; font-size: var(--fs-caption); }
.case-name-row { margin-bottom: var(--sp-5); }
label .opt { font-weight: 400; color: var(--ink-40); }

/* Back / Next at the foot of each step */
.step-nav {
  display: flex;
  justify-content: space-between;
  gap: var(--sp-3);
  flex-wrap: wrap;
  margin-top: var(--sp-6);
  padding-top: var(--sp-5);
  border-top: 1px solid var(--line);
}
.step-nav .step-next { margin-left: auto; }
.step-nav .step-run {
  padding: 12px 20px;
  border: 1px solid var(--ink);
  background: var(--ink);
  color: var(--paper);
}
.step-nav .step-run:hover { background: var(--accent); border-color: var(--accent); color: var(--on-accent); }

/* phones / narrow windows: the menu becomes a scrolling strip above the step */
@media (max-width: 860px) {
  .layout { grid-template-columns: minmax(0, 1fr); gap: var(--sp-4); }
  /* one scrolling strip of steps, then Run + Results side by side; not sticky
     (the Back / Next buttons carry the flow on a small screen) */
  .sidenav { position: static; flex-direction: row; flex-wrap: wrap; gap: var(--sp-2); }
  .sidenav > .steps { display: flex; }
  .sidenav > .steps:first-child { flex: 1 1 100%; overflow-x: auto; }
  .sidenav > .steps li + li { border-top: 0; border-left: 1px solid var(--line); }
  .sidenav > .steps a { white-space: nowrap; border-left: 0; border-bottom: 3px solid transparent;
    padding: 8px 10px; align-items: center; }
  .sidenav > .steps a.active { border-bottom-color: var(--accent); }
  .sidenav .step-badge { display: none; }
  .sidenav-run { flex: 1 1 auto; flex-direction: row; align-items: center; gap: var(--sp-3); }
  .sidenav-run #run { width: auto; padding: 10px 16px; }
  .sidenav-tools { flex: 1 1 100%; flex-direction: row; flex-wrap: wrap; align-items: center; }
  .tools-head { display: none; }
  .panel { padding: var(--sp-5) var(--sp-4); }
}
.run-status {
  font-family: var(--font-ui);
  font-size: var(--fs-caption);
  color: var(--ink-60);
  line-height: 1.45;
}
.run-status.ok::before { content: "✓ "; }
.run-status.stale { color: var(--accent-text); font-weight: 700; }
.run-error { white-space: pre-line; }
body.is-busy, body.is-busy button { cursor: progress; }
button:disabled { opacity: 0.55; cursor: not-allowed; }

/* a decimal rate's percent, under its field */
.pct-hint {
  font-weight: 400;
  font-size: var(--fs-label);
  color: var(--ink-40);
  min-height: 1em;
  font-variant-numeric: tabular-nums;
}
label[hidden] { display: none; }

/* ---- Monte Carlo panel -------------------------------------- */
.pctl-picker .section-head { border-top: 0; padding-top: 0; margin-top: var(--sp-5); }
.pctl-grid { align-items: end; }
.pctl-go { display: flex; align-items: flex-end; }
.pctl-go button { width: 100%; }
#pctl_hint { margin-bottom: var(--sp-5); }
#pctl_hint.warning { margin-top: var(--sp-3); }
.inline-select { flex-direction: row; align-items: center; gap: var(--sp-3);
  font-weight: 400; color: var(--ink-60); margin-bottom: var(--sp-3); }
.inline-select select { min-width: 220px; }

/* what the annual report is illustrating */
.scenario-banner {
  display: flex;
  align-items: center;
  gap: var(--sp-4);
  flex-wrap: wrap;
  font-family: var(--font-ui);
  font-size: var(--fs-caption);
  color: var(--ink-60);
  border: 1px solid var(--line);
  padding: var(--sp-3) var(--sp-4);
  margin-bottom: var(--sp-4);
  line-height: 1.55;
}
.scenario-banner span { flex: 1 1 320px; }
.scenario-banner.is-trial {
  color: var(--ink);
  border-left: 4px solid var(--accent);
  background: color-mix(in srgb, var(--accent) 6%, var(--card));
}
