/* Plan Designer layout and components. Colors come only from theme tokens. */

:root { --row-alt: rgba(13, 107, 128, .06); --danger: #b42318; --danger-bg: #fdecea; --indent: 18px; }
[data-theme="zen-cosmic"] { --row-alt: rgba(125, 211, 252, .05); --danger: #f87171; --danger-bg: rgba(248, 113, 113, .12); }
html { color-scheme: light; }
[data-theme="zen-cosmic"] { color-scheme: dark; }
body { font-size: 14px; line-height: 1.45; }

.skip { position: absolute; left: -999px; top: 8px; background: var(--surface); color: var(--fg); padding: 8px 12px; border-radius: 8px; z-index: 10; }
.skip:focus { left: 16px; }
:focus-visible { outline: 3px solid var(--cyan); outline-offset: 2px; }

/* ---------- top bar ---------- */
.page-head { display: flex; flex-wrap: wrap; gap: 12px 24px; align-items: center; justify-content: space-between;
  padding: 16px 20px; margin-bottom: 16px; }
.brand { display: flex; gap: 12px; align-items: center; }
.logo { font-size: 26px; color: var(--teal); }
h1 { margin: 0; font-size: 18px; letter-spacing: .01em; }
.brand .sub { margin: 2px 0 0; color: var(--muted); font-size: 12px; }
.context { display: flex; flex-wrap: wrap; gap: 8px 10px; align-items: center; }
.context label { font-size: 12px; color: var(--muted); font-weight: 600; }

select, input { font: inherit; color: var(--fg); background: var(--surface); border: 1px solid var(--line-strong);
  border-radius: 8px; padding: 6px 9px; min-height: 34px; max-width: 100%; }
input[readonly] { background: var(--elevated); color: var(--muted); border-style: dashed; }
input[aria-invalid] { border-color: var(--danger); box-shadow: 0 0 0 2px var(--danger-bg); }

.btn { font: inherit; font-size: 13px; }
.btn.primary { background: var(--teal); color: #fff; border-color: var(--teal); font-weight: 600; padding: 8px 18px; }
[data-theme="zen-cosmic"] .btn.primary { color: #0a0a14; }
.btn.primary:hover { filter: brightness(1.08); color: #fff; }

/* ---------- page ---------- */
.pd-main { padding-top: 0; padding-bottom: 48px; }
.about { margin-bottom: 16px; }
.about summary, .payload summary { cursor: pointer; font-weight: 700; color: var(--teal); }
.about p { margin: 10px 0; max-width: 72ch; }
.hint { color: var(--muted); font-size: 12.5px; }
.product-summary { margin: 0 0 16px; color: var(--muted); }

.layout { display: grid; grid-template-columns: minmax(0, 1fr) 340px; gap: 24px; align-items: start; }
.toolbar { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; justify-content: space-between; margin-bottom: 12px; min-height: 36px; }
.toolbar h2 { margin: 0; font-size: 15px; }
.tools { display: flex; flex-wrap: wrap; gap: 6px; }

/* ---------- groups and provision rows ---------- */
.group { margin: 0 0 16px; padding: 6px 0 8px; overflow: hidden; }
.group legend { float: left; width: 100%; padding: 10px 16px 8px; font-size: 11px; font-weight: 800; letter-spacing: .08em;
  text-transform: uppercase; color: var(--teal); border-bottom: 1px solid var(--line); }
.group legend + * { clear: both; }
.group-notes { padding: 0 16px; }
.notes { margin: 8px 0 4px; font-size: 12.5px; color: var(--muted); }
.notes summary { cursor: pointer; color: var(--amber); font-weight: 600; }
.notes ul { margin: 6px 0; padding-left: 18px; }

.prov { --pad: calc(16px + var(--depth) * var(--indent)); }
.line { display: grid; grid-template-columns: 26px minmax(0, 1fr) auto minmax(180px, 260px); gap: 8px; align-items: center;
  padding: 6px 16px 6px var(--pad); }
.prov.alt > .line { background: var(--row-alt); }
.prov[data-id] .line label { font-size: 12.5px; font-weight: 600; letter-spacing: .01em; }
.sub { position: relative; }
.sub::before { content: ""; position: absolute; top: 0; bottom: 6px; left: calc(28px + var(--depth, 0) * var(--indent)); border-left: 1px dashed var(--line-strong); }
.ctl select, .ctl input { width: 100%; }

.tog { width: 24px; height: 24px; border-radius: 6px; border: 1px solid var(--line-strong); background: var(--elevated); color: var(--teal);
  cursor: pointer; display: grid; place-items: center; padding: 0; }
.tog::before { content: "▸"; font-size: 13px; transition: transform .15s; }
.tog[aria-expanded="true"]::before { transform: rotate(90deg); }
.tog:disabled { opacity: .3; cursor: default; }
.tog-spacer { width: 24px; }

.meta { display: flex; gap: 6px; align-items: center; justify-content: flex-end; }
.badge { font-size: 10.5px; font-weight: 700; border-radius: 999px; padding: 2px 8px; white-space: nowrap; border: 1px solid; }
.badge[data-kind="prefill"] { color: var(--sky); border-color: var(--sky); }
.badge[data-kind="record"] { color: var(--muted); border-color: var(--line-strong); }
.badge[data-kind="edited"] { color: var(--amber); border-color: var(--amber); }
.info { width: 22px; height: 22px; border-radius: 50%; border: 1px solid var(--cyan); background: transparent; color: var(--cyan);
  font: italic 700 12px Georgia, serif; cursor: pointer; padding: 0; }
.info:hover { background: var(--cyan); color: var(--surface); }
.err { margin: 0; padding: 2px 16px 6px calc(var(--pad) + 34px); color: var(--danger); font-size: 12px; font-weight: 600; }

/* ---------- side panel ---------- */
.side { position: sticky; top: 16px; display: grid; gap: 16px; }
.premium-k { font-size: 10.5px; letter-spacing: .08em; text-transform: uppercase; color: var(--teal); font-weight: 800; }
.premium-v { display: flex; align-items: baseline; gap: 10px; }
#total { font-size: 34px; font-weight: 800; color: var(--fg); font-variant-numeric: tabular-nums; }
.delta { font-weight: 700; font-size: 13px; opacity: 0; }
.delta[data-dir="up"] { color: var(--danger); }
.delta[data-dir="down"] { color: var(--green); }
.delta.flash { animation: flash 2.4s ease-out; }
@keyframes flash { 0%, 60% { opacity: 1; } 100% { opacity: 0; } }
.scores { margin: 4px 0 8px; font-size: 12px; color: var(--muted); }
.breakdown summary { cursor: pointer; font-size: 12.5px; color: var(--teal); font-weight: 600; }
.breakdown table { width: 100%; border-collapse: collapse; margin-top: 8px; font-size: 12px; }
.breakdown th { text-align: left; font-weight: 500; color: var(--muted); padding: 4px 6px 4px 0; border-top: 1px solid var(--line); text-transform: none; }
.breakdown td { text-align: right; white-space: nowrap; padding: 4px 0; border-top: 1px solid var(--line); font-variant-numeric: tabular-nums; }
.breakdown td.credit { color: var(--green); }
.uw h2 { margin: 0 0 4px; font-size: 15px; }
.count { margin: 0 0 8px; color: var(--muted); font-size: 12.5px; }
.referrals { margin: 0 0 12px; padding: 0; list-style: none; display: grid; gap: 6px; max-height: 40vh; overflow: auto; }
.referrals li { font-size: 12.5px; padding: 7px 10px; border-radius: 8px; border-left: 3px solid var(--amber); background: var(--elevated); }
.referrals li.block { border-left-color: var(--danger); background: var(--danger-bg); }
.status { margin: 8px 0 0; font-size: 12.5px; font-weight: 600; }
.status[data-kind="error"] { color: var(--danger); }
.status[data-kind="ok"] { color: var(--green); }

.payload { margin-top: 24px; }
.payload pre { max-height: 420px; overflow: auto; background: var(--elevated); border: 1px solid var(--line); border-radius: 10px;
  padding: 12px; font-size: 12px; line-height: 1.4; white-space: pre; }

/* ---------- knowledge-base dialog ---------- */
dialog#kb { border: 1px solid var(--line); border-radius: 14px; padding: 0; width: min(560px, calc(100vw - 32px)); max-height: 85vh;
  background: var(--surface); color: var(--fg); box-shadow: 0 24px 70px rgba(0, 0, 0, .35); }
dialog#kb::backdrop { background: rgba(6, 12, 24, .55); }
.kb-box { padding: 0 0 14px; }
.kb-hdr { display: flex; justify-content: space-between; align-items: center; gap: 10px; background: var(--teal); color: #fff; padding: 12px 16px; }
[data-theme="zen-cosmic"] .kb-hdr { color: #0a0a14; }
.kb-hdr h2 { margin: 0; font-size: 15px; }
.kb-close { background: transparent; border: 0; color: inherit; font-size: 22px; cursor: pointer; line-height: 1; }
.kb-crumb { margin: 10px 16px 0; font-size: 11.5px; color: var(--muted); }
#kb-body { padding: 4px 16px; line-height: 1.55; }
.kb-selected { padding: 8px 10px; border-radius: 8px; background: var(--elevated); border-left: 3px solid var(--cyan); }
.kb-source { border: 1px solid var(--line); border-radius: 10px; padding: 8px 12px; }
.kb-source h3 { margin: 0 0 4px; font-size: 12.5px; color: var(--sky); }
.kb-source p { margin: 0; font-size: 13px; }
.kb-ftr { text-align: right; padding: 4px 16px 0; }

/* ---------- responsive ---------- */
@media (max-width: 960px) {
  .layout { grid-template-columns: minmax(0, 1fr); }
  /* premium + underwriting sit side by side above the tree on tablets, stacked on phones */
  .side { position: static; order: -1; grid-template-columns: repeat(2, minmax(0, 1fr)); align-items: stretch; }
  .referrals { max-height: none; }
}
@media (max-width: 640px) {
  :root { --indent: 10px; }
  .page-head { padding: 12px 14px; }
  .context { width: 100%; display: grid; grid-template-columns: 1fr; }
  .context select, .context .btn { width: 100%; }
  .side { grid-template-columns: minmax(0, 1fr); }
  .page-head .brand { width: 100%; }
  .toolbar { align-items: stretch; }
  .toolbar h2 { width: 100%; }
  .tools { width: 100%; display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); }
  .tools .btn { padding: 8px 6px; min-height: 36px; white-space: nowrap; font-size: 12.5px; }
  .uw .btn.primary { width: 100%; min-height: 40px; }
  /* touch targets: toggles and info buttons grow to 32px on phones */
  .line { grid-template-columns: 32px minmax(0, 1fr) auto; padding-right: 12px; gap: 6px 8px; }
  .line .ctl { grid-column: 2 / -1; }
  .tog, .tog-spacer, .info { width: 32px; height: 32px; }
  .err { padding-left: calc(var(--pad) + 40px); }
  .ctl select, .ctl input { min-height: 40px; }
  .sub::before { display: none; }
  #total { font-size: 28px; }
}

/* ---------- platform chrome on this page ---------- */
.continue-flow { display: inline-flex; margin-top: 10px; text-decoration: none; }
