/* Payung tariff desk: layout and the desk's own parts. Shared parts come from /ui.css and every
   colour from the tokens in /theme.css. */

:root {
  --desk-head-h: 114px;
  --desk-nav-w: 208px;
  --desk-preview-w: 360px;
}

/* ---------- loading and sign in ---------- */
.desk-loading { justify-content: center; min-height: 100dvh; padding: var(--s-4); }

.login { min-height: 100dvh; display: grid; place-items: center; padding: var(--s-4); }
.login-card { width: min(420px, 100%); }
.login-card .brand {
  display: flex; align-items: center; gap: var(--s-2);
  font: var(--w-bold) var(--t-lg)/1 var(--sans); letter-spacing: -0.02em;
}
.login-card h1 { font: var(--w-bold) var(--t-xl)/1.2 var(--sans); margin: var(--s-5) 0 var(--s-4); }
.login-card .notice a { color: var(--ink); font-weight: var(--w-medium); }
.login-card .btn { margin-top: var(--s-2); }

/* ---------- desk layout ---------- */
.desk {
  display: grid;
  grid-template-columns: var(--desk-nav-w) minmax(0, 1fr) var(--desk-preview-w);
  grid-template-areas: "head head head" "nav editor preview";
  grid-template-rows: auto 1fr;
  min-height: 100dvh;
}

.desk-head { grid-area: head; position: sticky; top: 0; z-index: 20; }
.desk-head .topnav { position: static; }
.desk-head .who { max-width: 340px; }
.desk-title {
  margin: 0; padding-left: var(--s-4); border-left: 1px solid var(--line);
  font: var(--w-medium) var(--t-md)/1.2 var(--sans); color: var(--ink-2); white-space: nowrap;
}

.desk-bar {
  display: flex; align-items: center; gap: var(--s-4);
  min-height: 52px; padding: var(--s-2) var(--s-5);
  background: var(--surface-2); border-bottom: 1px solid var(--line);
}
.version {
  min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
  font-size: var(--t-sm); color: var(--muted);
}
.version b { color: var(--ink); font-weight: var(--w-medium); margin-right: var(--s-1); }
.draft-status {
  display: inline-flex; align-items: center; gap: var(--s-2); margin-left: auto; min-width: 0;
  flex: none; font-size: var(--t-sm); color: var(--muted); white-space: nowrap;
}
.draft-status.accent { color: var(--ink); font-weight: var(--w-medium); }
.draft-status.critical { color: var(--critical); }
.draft-status.critical .linklike { color: inherit; text-align: left; white-space: normal; }
.dot { width: 8px; height: 8px; flex: none; border-radius: 50%; background: var(--accent-fill); }
.desk-actions { display: flex; gap: var(--s-2); flex: none; }

/* Review stays grey until there is something to review, then turns orange with a count. */
.desk-actions .btn.primary:disabled {
  opacity: 1; background: var(--sunken); border-color: var(--line); color: var(--muted); font-weight: var(--w-medium);
}
.count-badge {
  display: inline-grid; place-items: center; min-width: 22px; height: 22px; padding: 0 6px;
  border-radius: var(--r-pill); font-size: var(--t-xs);
  background: color-mix(in srgb, var(--accent-ink) 24%, transparent);
}

/* ---------- section navigation ---------- */
.sections {
  grid-area: nav; align-self: start; position: sticky; top: var(--desk-head-h);
  display: grid; gap: 2px; padding: var(--s-5) var(--s-3);
}
.sections button {
  appearance: none; display: flex; align-items: center; gap: var(--s-3); width: 100%;
  padding: 10px var(--s-3); border: 0; border-radius: var(--r-sm); background: none; cursor: pointer;
  color: var(--ink-2); font: var(--w-medium) var(--t-base)/1.2 var(--sans); text-align: left; white-space: nowrap;
  transition: background-color var(--dur-fast) ease, color var(--dur-fast) ease;
}
.sections button .i { color: var(--faint); }
.sections button[aria-current="true"] { background: var(--accent-soft); color: var(--accent); }
.sections button[aria-current="true"] .i { color: currentColor; }
.nav-mark { display: inline-flex; margin-left: auto; }
.nav-mark.critical { color: var(--critical); }
.sections .nav-mark.critical .i { color: var(--critical); }

/* ---------- editor ---------- */
.editor {
  grid-area: editor; max-width: none; margin: 0; min-width: 0;
  display: grid; align-content: start; gap: var(--s-4);
  padding: var(--s-6) var(--s-6) var(--s-8);
}
.editor-head { margin-bottom: var(--s-2); }
.card-title { font: var(--w-bold) var(--t-lg)/1.25 var(--sans); overflow-wrap: anywhere; }
.editor .card { display: grid; gap: var(--s-4); }
.editor .card > * { margin: 0; }
.editor .card-head { margin-bottom: 0; flex-wrap: nowrap; }
.editor h4 { font: var(--w-medium) var(--t-sm)/1.3 var(--sans); color: var(--ink-2); margin-bottom: var(--s-2); }

.field-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(180px, 1fr)); gap: var(--s-4); }
.editor .field, .preview .field { margin: 0; }
.field-label { display: flex; align-items: center; gap: var(--s-1); min-height: 20px; }
.check { display: flex; align-items: center; gap: var(--s-2); color: var(--ink); font-size: var(--t-base); cursor: pointer; }

.unit-input { position: relative; display: block; }
.unit-input .unit {
  position: absolute; top: 50%; translate: 0 -50%; pointer-events: none;
  color: var(--muted); font-size: var(--t-sm);
}
.unit-input.after .unit { right: 12px; }
.unit-input.after input { padding-right: 34px; }
.unit-input.before .unit { left: 12px; }
.unit-input.before input { padding-left: 38px; }
.field > .unit-input { margin-top: var(--s-2); }
input[type="number"] { text-align: right; appearance: textfield; }
input[type="number"]::-webkit-inner-spin-button, input[type="number"]::-webkit-outer-spin-button { appearance: none; margin: 0; }
.editor :is(input, textarea).changed { background: var(--accent-soft); border-color: var(--accent-line); }
.editor textarea { min-height: 72px; font-size: var(--t-sm); }

table.data.edit td { padding: 6px var(--s-2); }
table.data.edit td:first-child { padding-left: var(--s-3); }
table.data.edit :is(input, select) { min-height: 40px; padding-top: 8px; padding-bottom: 8px; }
table.data.edit th .help { margin-left: 2px; }
.card > .table-wrap table.data.edit { min-width: 520px; }
.hazard table.data.edit { min-width: 0; }
.row-action { width: 1%; }
.remove { width: 36px; height: 36px; color: var(--muted); }
.add { justify-self: start; }
.bands-table .add { margin-top: var(--s-3); }
.fixed { display: block; padding: 0 var(--s-3); color: var(--muted); text-align: right; white-space: nowrap; }

/* ---------- hazard cards ---------- */
.hazard { container-type: inline-size; }
.hazard-head { display: flex; align-items: flex-start; gap: var(--s-3); }
.hazard-mark {
  display: inline-grid; place-items: center; flex: none; width: 36px; height: 36px; border-radius: var(--r-sm);
  background: color-mix(in srgb, var(--mark) 14%, transparent); color: var(--mark);
}
.hazard-head .fine { margin-top: 2px; }
.bands { display: grid; grid-template-columns: minmax(0, 1fr) minmax(220px, 300px); gap: var(--s-5); align-items: start; }
@container (max-width: 560px) {
  .bands { grid-template-columns: minmax(0, 1fr); }
}

.chart { margin: 0; color: var(--mark); }
.chart svg { display: block; width: 100%; max-width: 360px; height: auto; overflow: visible; }
.chart .area { fill: currentColor; opacity: 0.14; }
.chart .line { fill: none; stroke: currentColor; stroke-width: 2; stroke-linejoin: round; }
.chart .grid { stroke: var(--line); }
.chart text { fill: var(--muted); font: var(--w-regular) 11px var(--sans); }
.chart figcaption { margin-top: var(--s-2); font-size: var(--t-xs); color: var(--muted); }
.chart-note {
  padding: var(--s-4); border-radius: var(--r-md); background: var(--surface-2);
  font-size: var(--t-sm); color: var(--muted);
}

/* ---------- settings rows (pricing, rent) ---------- */
.settings > * + * { border-top: 1px solid var(--line); padding-top: var(--s-4); }
.setting {
  display: grid; grid-template-columns: minmax(0, 1fr) 140px; align-items: center; gap: var(--s-4);
  margin: 0; font-size: var(--t-sm); color: var(--ink-2);
}
.setting b { display: block; color: var(--ink); font-size: var(--t-base); font-weight: var(--w-medium); }
.spread-note { margin-top: var(--s-3); }

/* ---------- preview ---------- */
.preview {
  grid-area: preview; align-self: start; position: sticky; top: var(--desk-head-h);
  max-height: calc(100dvh - var(--desk-head-h)); overflow: auto; overscroll-behavior: contain;
  padding: var(--s-5); background: var(--surface); border-left: 1px solid var(--line);
  min-height: calc(100dvh - var(--desk-head-h));
}
.preview-head { display: flex; align-items: center; justify-content: space-between; gap: var(--s-3); }
.preview-head h2 { font: var(--w-bold) var(--t-lg)/1.25 var(--sans); }
.preview > .fine { margin-top: var(--s-1); }
.pickers { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: var(--s-3); margin-top: var(--s-4); }
.preview .notice { margin-top: var(--s-4); white-space: pre-line; overflow-wrap: anywhere; }
.quote { margin-top: var(--s-5); }
.stale { opacity: 0.45; }

.loss-days { font-size: var(--t-sm); color: var(--ink-2); margin-bottom: var(--s-3); }
.loss-days b { color: var(--ink); font-weight: var(--w-bold); font-size: var(--t-base); }
.ladder { display: grid; gap: var(--s-3); margin: 0; padding: 0; list-style: none; }
.rung { display: grid; grid-template-columns: 56px minmax(0, 1fr) auto; gap: 2px var(--s-3); align-items: center; }
.rung-name { font-weight: var(--w-medium); font-size: var(--t-sm); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.rung-bar { height: 8px; background: var(--sunken); border-radius: var(--r-pill); overflow: hidden; }
.rung-bar i { display: block; height: 100%; background: var(--accent-fill); border-radius: var(--r-pill); }
.rung-price { font-weight: var(--w-bold); white-space: nowrap; }
.rung-price small { font-weight: var(--w-regular); font-size: var(--t-xs); color: var(--muted); }
.rung-price .was { margin-right: var(--s-2); font-weight: var(--w-regular); font-size: var(--t-sm); color: var(--muted); }
.rung-detail { grid-column: 2 / -1; font-size: var(--t-xs); color: var(--muted); }

.try-day { margin-top: var(--s-6); padding-top: var(--s-5); border-top: 1px solid var(--line); }
.try-day h3 { font: var(--w-bold) var(--t-md)/1.3 var(--sans); }
.try-day > .fine { margin-top: var(--s-1); }
.readings { display: grid; gap: var(--s-2); margin-top: var(--s-4); }
.reading { display: grid; grid-template-columns: minmax(0, 1fr) 112px; align-items: center; gap: var(--s-3); margin: 0; }
.reading-name { display: flex; align-items: center; gap: var(--s-2); min-width: 0; color: var(--ink); font-weight: var(--w-medium); }
.reading-name > span:not(.hazard-mark) { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.reading .hazard-mark { width: 28px; height: 28px; }
.reading input { min-height: 40px; padding-top: 8px; padding-bottom: 8px; }
.try-empty { margin-top: var(--s-4); }

#assessment { margin-top: var(--s-4); }
.day-loss { display: flex; flex-wrap: wrap; align-items: baseline; gap: var(--s-2) var(--s-3); }
.day-loss strong { font: var(--w-bold) var(--t-3xl)/1 var(--mono); letter-spacing: -0.02em; }
.day-loss > span:not(.day-chip) { color: var(--ink-2); font-size: var(--t-sm); }
.breakdown { margin-top: var(--s-3); }
#assessment h4 { margin: var(--s-4) 0 0; font: var(--w-medium) var(--t-sm)/1.3 var(--sans); color: var(--ink-2); }
.breakdown .kv, .payouts .kv { font-size: var(--t-sm); }

/* ---------- review drawer ---------- */
table.changes { table-layout: fixed; }
table.changes td { white-space: normal; overflow-wrap: anywhere; vertical-align: top; }
table.changes td.before { color: var(--muted); text-decoration: line-through; text-decoration-color: var(--line-strong); }
table.changes td.after { color: var(--ink); font-weight: var(--w-medium); }
.cell-text { max-height: 12em; overflow: auto; }
#rent-spread td.num { white-space: nowrap; }
.review-actions {
  position: sticky; bottom: 0; display: flex; justify-content: flex-end; flex-wrap: wrap; gap: var(--s-2);
  margin: 0 calc(-1 * var(--s-5)); padding: var(--s-4) var(--s-5);
  background: var(--surface); border-top: 1px solid var(--line);
}
.review-actions .notice { flex: 1 1 100%; white-space: pre-line; overflow-wrap: anywhere; }

/* ---------- toast ---------- */
.toast {
  position: fixed; left: 50%; bottom: var(--s-5); z-index: 60; translate: -50% 0;
  display: flex; align-items: center; gap: var(--s-2); max-width: calc(100vw - 32px); margin: 0;
  padding: var(--s-3) var(--s-4); border-radius: var(--r-pill);
  background: var(--ink); color: var(--bg); box-shadow: var(--shadow-2); font-size: var(--t-sm);
  transition: opacity var(--dur-base) var(--ease-out), transform var(--dur-base) var(--ease-out);
}
@starting-style { .toast { opacity: 0; transform: translateY(8px); } }

/* ---------- hover ---------- */
@media (hover: hover) and (pointer: fine) {
  .sections button:hover:not([aria-current="true"]) { background: var(--sunken); color: var(--ink); }
  .remove:hover { color: var(--critical); background: var(--critical-soft); }
}

/* ---------- narrower screens ---------- */
@media (max-width: 1180px) {
  :root { --desk-nav-w: 184px; --desk-preview-w: 320px; }
  .editor { padding: var(--s-5) var(--s-5) var(--s-8); }
  .who .who-text { display: none; }
}

@media (max-width: 899px) {
  .desk { grid-template-columns: minmax(0, 1fr); grid-template-areas: "head" "nav" "editor" "preview"; grid-template-rows: auto; }
  .sections {
    z-index: 10; display: flex; gap: var(--s-1); overflow-x: auto; padding: var(--s-2) var(--s-4);
    background: var(--bg); border-bottom: 1px solid var(--line); scrollbar-width: none;
  }
  .sections button { width: auto; flex: none; padding: 8px 12px; font-size: var(--t-sm); }
  .preview { position: static; max-height: none; min-height: 0; border-left: 0; border-top: 1px solid var(--line); }
}

@media (max-width: 720px) {
  .desk { padding-bottom: 72px; }
  .desk-head { position: static; }
  .sections { top: 0; }
  .desk-title { padding-left: var(--s-3); font-size: var(--t-base); }
  .desk-bar { flex-wrap: wrap; gap: var(--s-1) var(--s-3); padding: var(--s-2) var(--s-4); }
  .version { flex: 1 1 100%; }
  .draft-status { flex: 0 1 auto; margin-left: 0; white-space: normal; }
  .desk-actions {
    position: fixed; left: 0; right: 0; bottom: 0; z-index: 30;
    padding: var(--s-3) var(--s-4) calc(var(--s-3) + env(safe-area-inset-bottom));
    background: var(--surface); border-top: 1px solid var(--line);
  }
  .desk-actions .btn { flex: 1; min-height: 44px; }
  .editor { padding: var(--s-5) var(--s-4) var(--s-7); }
  .preview { padding: var(--s-5) var(--s-4); }
  .setting { grid-template-columns: minmax(0, 1fr); gap: var(--s-2); }
  .toast { bottom: 88px; }
}

@media (max-width: 1024px) {
  .sections button { min-height: 40px; }
  .chart text { font-size: 14px; }
}
