/* KOG Estimator
   Palette taken from drafting film and cost-plan stationery rather than
   generic dashboard chrome. Boldness is spent entirely on the rate gauge. */

:root {
  --paper:      #EEF0EB;
  --panel:      #FCFCFA;
  --ink:        #16211C;
  --ink-2:      #5A655E;
  --ink-3:      #8B948C;
  --rule:       #C7CDC4;
  --rule-soft:  #DFE3DC;
  --accent:     #17554A;
  --accent-lo:  #DCE7E1;
  --flag:       #9A4A22;
  --field:      #FFFFFF;
  --field-edge: #B9C1B7;

  --sans: system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  --mono: ui-monospace, "Cascadia Mono", "SF Mono", "DejaVu Sans Mono", Menlo, Consolas, monospace;

  --gap: 1.5rem;
  --radius: 2px;
}

* { box-sizing: border-box; }

html { -webkit-text-size-adjust: 100%; }

body {
  margin: 0;
  background: var(--paper);
  color: var(--ink);
  font-family: var(--sans);
  font-size: 15px;
  line-height: 1.5;
}

.vh {
  position: absolute; width: 1px; height: 1px;
  overflow: hidden; clip-path: inset(50%); white-space: nowrap;
}

/* ---------------------------------------------------------------- topbar */
.topbar {
  position: sticky; top: 0; z-index: 40;
  display: flex; align-items: center; justify-content: space-between;
  gap: var(--gap);
  padding: 0.65rem 1.5rem;
  background: var(--ink);
  color: var(--panel);
  border-bottom: 3px solid var(--accent);
}

.brand { display: flex; align-items: baseline; gap: 0.6rem; }

.brand-mark {
  font-weight: 700; letter-spacing: 0.08em; font-size: 0.95rem;
  padding: 0.15rem 0.4rem;
  border: 1px solid rgba(252,252,250,0.45);
  border-radius: var(--radius);
}

.brand-name { font-size: 1.05rem; font-weight: 500; letter-spacing: 0.01em; }

.topbar-actions { display: flex; align-items: center; gap: 0.5rem; flex-wrap: wrap; }

.savestate {
  font-size: 0.8rem; color: rgba(252,252,250,0.7);
  min-width: 5.5rem; text-align: right;
  font-variant-numeric: tabular-nums;
}
.savestate[data-dirty="1"] { color: #E8C489; }

/* ---------------------------------------------------------------- buttons */
.btn {
  font: inherit; font-size: 0.85rem;
  padding: 0.4rem 0.8rem;
  background: transparent;
  color: var(--panel);
  border: 1px solid rgba(252,252,250,0.4);
  border-radius: var(--radius);
  cursor: pointer;
}
.btn:hover { background: rgba(252,252,250,0.1); }
.btn:focus-visible { outline: 2px solid #E8C489; outline-offset: 2px; }

.btn-primary { background: var(--accent); border-color: var(--accent); }
.btn-primary:hover { background: #1D6B5C; }

.btn-add {
  margin-top: 0.6rem;
  color: var(--accent);
  border: 1px dashed var(--field-edge);
  background: transparent;
}
.btn-add:hover { background: var(--accent-lo); border-color: var(--accent); }
.btn-add:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }

.btn-row {
  font: inherit; font-size: 1rem; line-height: 1;
  width: 1.6rem; height: 1.6rem;
  padding: 0; cursor: pointer;
  color: var(--ink-3);
  background: transparent;
  border: 1px solid transparent;
  border-radius: var(--radius);
}
.btn-row:hover { color: var(--flag); border-color: var(--rule); background: var(--panel); }
.btn-row:focus-visible { outline: 2px solid var(--accent); outline-offset: 1px; }

/* ---------------------------------------------------------------- shell */
.sheet {
  max-width: 78rem;
  margin: 0 auto;
  padding: var(--gap) 1.5rem 4rem;
}

/* ------------------------------------------------------------ titleblock */
/* Modelled on the fielded title block at the foot of a construction drawing */
.titleblock {
  display: grid;
  grid-template-columns: repeat(12, 1fr);
  background: var(--panel);
  border: 1px solid var(--rule);
  border-radius: var(--radius);
  overflow: hidden;
}

.tb-field {
  grid-column: span 3;
  border-right: 1px solid var(--rule-soft);
  border-bottom: 1px solid var(--rule-soft);
  padding: 0.45rem 0.7rem 0.5rem;
  min-width: 0;
}
.tb-wide { grid-column: span 6; }
.tb-narrow { grid-column: span 2; }

.tb-field label {
  display: block;
  font-size: 0.68rem;
  letter-spacing: 0.03em;
  color: var(--ink-3);
  margin-bottom: 0.1rem;
}

.tb-field input {
  font: inherit;
  font-size: 0.95rem;
  width: 100%;
  border: 0;
  background: transparent;
  color: var(--ink);
  padding: 0;
}
.tb-field input::placeholder { color: #B6BEB6; }
.tb-field input:focus { outline: none; }
.tb-field:focus-within { background: var(--accent-lo); }

/* ---------------------------------------------------------------- gauge */
.gauge {
  display: grid;
  grid-template-columns: minmax(11rem, auto) 1fr;
  gap: 1.25rem 2rem;
  align-items: center;
  margin-top: var(--gap);
  padding: 1.5rem 1.75rem;
  background: var(--panel);
  border: 1px solid var(--rule);
  border-left: 4px solid var(--accent);
  border-radius: var(--radius);
}

.gauge-figure { display: flex; flex-direction: column; }

.rate-big {
  font-family: var(--mono);
  font-size: clamp(2.4rem, 6vw, 3.6rem);
  font-weight: 600;
  line-height: 0.95;
  letter-spacing: -0.02em;
  font-variant-numeric: tabular-nums;
  color: var(--ink);
}
.rate-big[data-over="1"] { color: var(--flag); }

.rate-unit { font-size: 0.85rem; color: var(--ink-2); margin-top: 0.4rem; }

.gauge-scale { min-width: 0; }

.scale-track {
  position: relative;
  height: 2.4rem;
  background: linear-gradient(var(--rule-soft), var(--rule-soft)) no-repeat center/100% 1px;
  border-left: 1px solid var(--rule);
  border-right: 1px solid var(--rule);
}

.scale-zone {
  position: absolute; top: 0; bottom: 0;
  background: var(--accent-lo);
  transition: left 140ms ease, width 140ms ease;
}

.scale-marker {
  position: absolute; top: 0; bottom: 0;
  width: 0;
  transition: left 140ms ease;
}
.marker-stem {
  position: absolute; top: 0; bottom: 0; left: -1px;
  width: 2px;
  background: var(--accent);
}
.marker-stem::before {
  content: "";
  position: absolute; top: -1px; left: -4px;
  border-left: 5px solid transparent;
  border-right: 5px solid transparent;
  border-top: 7px solid var(--accent);
}
.scale-marker[data-over="1"] .marker-stem { background: var(--flag); }
.scale-marker[data-over="1"] .marker-stem::before { border-top-color: var(--flag); }

.scale-ticks {
  position: relative;
  height: 1.4rem;
  font-family: var(--mono);
  font-size: 0.72rem;
  color: var(--ink-3);
}
.scale-ticks span {
  position: absolute; top: 0.25rem;
  transform: translateX(-50%);
  font-variant-numeric: tabular-nums;
}

.scale-verdict {
  margin: 0.35rem 0 0;
  font-size: 0.86rem;
  color: var(--ink-2);
  max-width: 62ch;
}

.gauge-totals {
  grid-column: 1 / -1;
  display: flex; flex-wrap: wrap; gap: 0 2.5rem;
  margin: 0;
  padding-top: 1rem;
  border-top: 1px solid var(--rule-soft);
}
.gauge-totals > div { display: flex; flex-direction: column; }
.gauge-totals dt { font-size: 0.72rem; color: var(--ink-3); }
.gauge-totals dd {
  margin: 0.1rem 0 0;
  font-family: var(--mono);
  font-variant-numeric: tabular-nums;
  font-size: 1.02rem;
}
.gauge-totals .total dd { font-weight: 700; color: var(--accent); }

/* ---------------------------------------------------------------- blocks */
.block {
  margin-top: 2.25rem;
  padding: 1.35rem 1.5rem 1.5rem;
  background: var(--panel);
  border: 1px solid var(--rule);
  border-radius: var(--radius);
}

.block-head { margin-bottom: 1rem; }
.block-head h2 {
  margin: 0;
  font-size: 1.12rem;
  font-weight: 600;
  letter-spacing: -0.01em;
}
.block-head p {
  margin: 0.25rem 0 0;
  font-size: 0.87rem;
  color: var(--ink-2);
  max-width: 68ch;
}

.toggle {
  display: inline-flex; align-items: center; gap: 0.45rem;
  margin-top: 0.7rem;
  font-size: 0.87rem;
  color: var(--ink-2);
  cursor: pointer;
}
.toggle input { accent-color: var(--accent); width: 1rem; height: 1rem; }

/* ---------------------------------------------------------------- tables */
.scroll-x { overflow-x: auto; }

.grid {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.9rem;
}

.grid th,
.grid td {
  padding: 0.28rem 0.5rem;
  text-align: left;
  border-bottom: 1px solid var(--rule-soft);
  vertical-align: middle;
}

.grid thead th {
  font-size: 0.72rem;
  font-weight: 600;
  color: var(--ink-3);
  border-bottom: 1px solid var(--rule);
  padding-bottom: 0.4rem;
}

.grid tfoot th,
.grid tfoot td {
  border-top: 2px solid var(--ink);
  border-bottom: 0;
  padding-top: 0.5rem;
  font-weight: 600;
}

.grid .c-num,
.grid .c-pct {
  text-align: right;
  font-family: var(--mono);
  font-variant-numeric: tabular-nums;
  white-space: nowrap;
}
.grid thead .c-num,
.grid thead .c-pct { font-family: var(--sans); }

.c-num { width: 7.5rem; }
.c-pct { width: 4.5rem; color: var(--ink-2); }
.c-act { width: 2.2rem; }
.c-note { width: 32%; }

.grid tbody tr:hover { background: #F6F8F4; }

/* inputs inside tables */
.grid input {
  font: inherit;
  font-size: 0.9rem;
  width: 100%;
  padding: 0.2rem 0.35rem;
  color: var(--ink);
  background: var(--field);
  border: 1px solid transparent;
  border-radius: var(--radius);
}
.grid input:hover { border-color: var(--rule-soft); }
.grid input:focus {
  outline: none;
  border-color: var(--accent);
  background: #fff;
  box-shadow: 0 0 0 2px var(--accent-lo);
}
.grid input.num {
  text-align: right;
  font-family: var(--mono);
  font-variant-numeric: tabular-nums;
}
.grid input.note { font-size: 0.82rem; color: var(--ink-2); }

/* group header rows in the FF&E table */
.grp-head td {
  background: var(--accent-lo);
  border-bottom: 1px solid var(--rule);
  padding: 0.35rem 0.5rem;
}
.grp-head input {
  background: transparent;
  font-weight: 600;
  font-size: 0.9rem;
}
.grp-sub td, .grp-sub th {
  border-top: 1px solid var(--rule);
  font-weight: 600;
}

.ffe-group { margin-bottom: 1.25rem; }

/* ---------------------------------------------------------------- derive */
.derive {
  margin-top: 1.1rem;
  border-top: 2px solid var(--ink);
  padding-top: 0.6rem;
}

.derive-row {
  display: flex; align-items: center; gap: 0.75rem;
  padding: 0.32rem 0;
  border-bottom: 1px solid var(--rule-soft);
  font-size: 0.9rem;
}
.derive-row:last-child { border-bottom: 0; }
.derive-row label,
.derive-label { flex: 1 1 auto; color: var(--ink-2); }
.derive-row label em { font-style: normal; color: var(--ink-3); font-size: 0.82rem; }

.field-num { display: inline-flex; align-items: center; gap: 0.3rem; }
.field-num input {
  font: inherit;
  font-family: var(--mono);
  font-variant-numeric: tabular-nums;
  text-align: right;
  width: 6rem;
  padding: 0.2rem 0.4rem;
  background: var(--field);
  border: 1px solid var(--field-edge);
  border-radius: var(--radius);
  color: var(--ink);
}
.field-num input:focus {
  outline: none;
  border-color: var(--accent);
  box-shadow: 0 0 0 2px var(--accent-lo);
}
.field-num .suffix { font-size: 0.8rem; color: var(--ink-3); width: 2.6rem; }

.derive-out {
  font-family: var(--mono);
  font-variant-numeric: tabular-nums;
  text-align: right;
  min-width: 8rem;
}
.derive-final { border-top: 1px solid var(--rule); padding-top: 0.5rem; }
.derive-final .derive-label { color: var(--ink); font-weight: 600; }
.derive-final .derive-out { font-weight: 700; color: var(--accent); }
.derive-override { background: #FBF7EC; }

/* ---------------------------------------------------------------- matrix */
.matrix { min-width: 34rem; }
.matrix th { font-family: var(--mono); font-variant-numeric: tabular-nums; }
.matrix thead th { text-align: right; color: var(--ink-2); }
.matrix thead th:first-child {
  text-align: left; font-family: var(--sans); color: var(--ink-3);
}
.matrix tbody th { text-align: left; font-weight: 600; }
.matrix td {
  text-align: right;
  font-family: var(--mono);
  font-variant-numeric: tabular-nums;
  color: var(--ink-2);
}
.matrix td.here {
  background: var(--accent);
  color: #fff;
  font-weight: 700;
}

/* ---------------------------------------------------------------- notes */
.notes { display: grid; grid-template-columns: repeat(3, 1fr); gap: 1.1rem; }
.note-field { display: flex; flex-direction: column; }
.note-field label {
  font-size: 0.78rem;
  color: var(--ink-3);
  margin-bottom: 0.3rem;
}
.note-field textarea {
  font: inherit;
  font-size: 0.85rem;
  line-height: 1.55;
  resize: vertical;
  padding: 0.55rem 0.65rem;
  color: var(--ink);
  background: var(--field);
  border: 1px solid var(--field-edge);
  border-radius: var(--radius);
}
.note-field textarea:focus {
  outline: none;
  border-color: var(--accent);
  box-shadow: 0 0 0 2px var(--accent-lo);
}

.footnote {
  margin: 2rem 0 0;
  font-size: 0.8rem;
  color: var(--ink-3);
  max-width: 70ch;
}

/* ---------------------------------------------------------------- dialog */
.dlg {
  border: 1px solid var(--rule);
  border-radius: var(--radius);
  padding: 0;
  background: var(--panel);
  color: var(--ink);
  max-width: 46rem;
  width: calc(100% - 3rem);
}
.dlg::backdrop { background: rgba(22,33,28,0.45); }

.dlg-inner { padding: 1.4rem 1.5rem; }
.dlg-inner h2 { margin: 0 0 0.9rem; font-size: 1.1rem; }

.est-list { max-height: 26rem; overflow-y: auto; }

.est-row {
  display: grid;
  grid-template-columns: 1fr auto auto;
  gap: 0.4rem 1rem;
  align-items: center;
  padding: 0.65rem 0.2rem;
  border-bottom: 1px solid var(--rule-soft);
}
.est-main { min-width: 0; }
.est-name { font-weight: 600; }
.est-meta { font-size: 0.8rem; color: var(--ink-3); }
.est-figure {
  font-family: var(--mono);
  font-variant-numeric: tabular-nums;
  text-align: right;
  font-size: 0.88rem;
}
.est-figure small { display: block; color: var(--ink-3); font-size: 0.75rem; }
.est-actions { display: flex; gap: 0.35rem; }

.est-actions .btn,
.dlg-actions .btn { color: var(--ink); border-color: var(--field-edge); }
.est-actions .btn:hover,
.dlg-actions .btn:hover { background: var(--accent-lo); }
.est-actions .btn-danger { color: var(--flag); }
.est-actions .btn-danger:hover { background: #F6E7DF; }

.dlg-actions { display: flex; justify-content: flex-end; margin-top: 1rem; }

.empty { padding: 1.5rem 0.2rem; color: var(--ink-2); font-size: 0.9rem; }

/* ---------------------------------------------------------------- toast */
.toast {
  position: fixed; left: 50%; bottom: 1.5rem;
  transform: translate(-50%, 1rem);
  padding: 0.55rem 1rem;
  background: var(--ink);
  color: var(--panel);
  border-radius: var(--radius);
  font-size: 0.86rem;
  opacity: 0;
  pointer-events: none;
  transition: opacity 160ms ease, transform 160ms ease;
  z-index: 60;
}
.toast[data-show="1"] { opacity: 1; transform: translate(-50%, 0); }
.toast[data-tone="bad"] { background: var(--flag); }

/* ---------------------------------------------------------------- responsive */
@media (max-width: 900px) {
  .gauge { grid-template-columns: 1fr; }
  .notes { grid-template-columns: 1fr; }
  .tb-field, .tb-wide, .tb-narrow { grid-column: span 6; }
  .c-note { display: none; }
  .grid thead .c-note { display: none; }
}

@media (max-width: 600px) {
  .sheet { padding: 1rem 0.75rem 3rem; }
  .topbar { padding: 0.55rem 0.9rem; }
  .brand-name { display: none; }
  .tb-field, .tb-wide, .tb-narrow { grid-column: span 12; }
  .gauge { padding: 1.1rem; }
}

@media (prefers-reduced-motion: reduce) {
  * { transition: none !important; }
}

@media print {
  .topbar, .btn, .c-act, .toast { display: none !important; }
  body { background: #fff; }
  .block, .gauge, .titleblock { border-color: #999; break-inside: avoid; }
}

/* ================================================================ v2 UI */
.model-badge {
  display: inline-flex;
  align-items: center;
  padding: 0.1rem 0.45rem;
  border: 1px solid rgba(252,252,250,0.35);
  border-radius: 999px;
  font-size: 0.68rem;
  letter-spacing: 0.04em;
  color: rgba(252,252,250,0.8);
}
.model-badge[data-model="v2"] {
  background: rgba(46, 125, 106, 0.35);
  border-color: rgba(139, 211, 190, 0.55);
  color: #F5FFFB;
}
.model-badge[data-model="v1"] {
  background: rgba(255,255,255,0.06);
}

.warning-panel {
  margin-top: var(--gap);
  padding: 1rem 1.25rem;
  border: 1px solid #D7B08C;
  border-left: 4px solid #B56A32;
  background: #FFF8F1;
}
.warning-panel[hidden] { display: none !important; }
.warning-panel h2 { margin: 0 0 0.45rem; font-size: 0.95rem; }
.warning-panel ul { margin: 0; padding-left: 1.15rem; color: var(--ink-2); }
.warning-panel li + li { margin-top: 0.35rem; }
.warning-error { color: var(--flag); }

.input-grid {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 0.8rem;
}
.input-card {
  display: flex;
  flex-direction: column;
  gap: 0.35rem;
  min-width: 0;
  padding: 0.75rem;
  background: #F8FAF7;
  border: 1px solid var(--rule-soft);
}
.input-card > span:first-child { font-weight: 600; font-size: 0.82rem; }
.input-card small { color: var(--ink-3); font-size: 0.74rem; line-height: 1.35; }
.input-card select {
  width: 100%;
  min-height: 2rem;
  font: inherit;
  font-size: 0.85rem;
  color: var(--ink);
  background: var(--field);
  border: 1px solid var(--field-edge);
  border-radius: var(--radius);
  padding: 0.25rem 0.4rem;
}
.field-num.wide { width: 100%; }
.field-num.wide input { width: 100%; min-width: 0; }
.check-card .check-line { display: flex; align-items: center; gap: 0.45rem; font-weight: 400; }
.check-card input[type="checkbox"], .scope-check input { accent-color: var(--accent); width: 1rem; height: 1rem; }

.subhead {
  margin: 1.25rem 0 0.45rem;
  font-size: 0.88rem;
  font-weight: 600;
  color: var(--ink-2);
}
.scope-grid .scope-check { width: 4rem; text-align: center; }
.scope-grid .model-rate { color: var(--ink-2); }
.scope-grid input.override-rate { min-width: 7rem; }

.tier-grid {
  display: grid;
  grid-template-columns: repeat(5, minmax(0, 1fr));
  gap: 0.6rem;
  margin-bottom: 1rem;
}
.tier-card {
  display: flex;
  flex-direction: column;
  min-width: 0;
  padding: 0.7rem 0.75rem;
  border: 1px solid var(--rule-soft);
  background: #F8FAF7;
}
.tier-card .tier-label { font-size: 0.72rem; color: var(--ink-3); }
.tier-card strong { margin-top: 0.15rem; font-family: var(--mono); font-size: 1rem; }
.tier-card small { margin-top: 0.1rem; color: var(--ink-3); font-size: 0.68rem; }

code { font-family: var(--mono); font-size: 0.9em; }

@media (max-width: 1000px) {
  .input-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .tier-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
}

@media (max-width: 600px) {
  .input-grid, .tier-grid { grid-template-columns: 1fr; }
  .model-badge { display: none; }
}
