:root {
  --ink: #1c1915;
  --muted: #4f4a42;
  --line: #e0d9cc;
  --paper: #fbfaf7;
  --page: #efece4;
  --teal: #1f6f78;
  --teal-dark: #164e55;
  --brass: #f0c36a;
  --rust: #c4552a;
  --danger: #8f2d2d;
  --quote: #1c2422;
  --quote-text: #f4f1ea;
  --warn: #8a5a12;
  --sans: ui-sans-serif, system-ui, -apple-system, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  --mono: ui-monospace, "SFMono-Regular", Menlo, Consolas, "Liberation Mono", monospace;
  color-scheme: light;
}

* { box-sizing: border-box; }

[hidden] { display: none !important; }

body {
  margin: 0;
  background:
    radial-gradient(900px 420px at 0% -10%, #e4eee8 0%, transparent 70%),
    radial-gradient(700px 360px at 100% 0%, #f6e7d4 0%, transparent 62%),
    var(--page);
  color: var(--ink);
  font-family: var(--sans);
  font-size: 16px;
  line-height: 1.45;
}

.screen {
  max-width: 1180px;
  margin: 0 auto;
  padding: 1.25rem 1.25rem 3rem;
}

h1, h2, h3 { line-height: 1.2; }

h1 {
  margin: 0;
  font-size: 2.1rem;
  letter-spacing: -0.03em;
}

h2 { margin: 0 0 0.35rem; font-size: 1.2rem; }

h3 { margin: 1.1rem 0 0.4rem; font-size: 0.98rem; }

p { margin: 0.35rem 0; }

.eyebrow {
  margin: 0 0 0.2rem;
  font-size: 0.75rem;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--teal-dark);
  font-weight: 700;
}

.lede { color: var(--muted); margin-top: 0.35rem; }

.top {
  display: flex;
  justify-content: space-between;
  gap: 1.5rem;
  align-items: end;
  margin-bottom: 1rem;
}

.top-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 0.45rem;
  align-items: end;
  justify-content: flex-end;
}

.disclaimer {
  margin: 0 0 0.8rem;
  padding: 0.75rem 0.9rem;
  border-left: 4px solid #a6843d;
  background: #f8f1e3;
  color: #3a3226;
}

.status:empty { display: none; }

.status {
  margin: 0 0 0.8rem;
  color: var(--teal-dark);
  font-weight: 600;
}

.layout {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 360px;
  gap: 1rem;
  align-items: start;
}

section, .part {
  background: var(--paper);
  border: 1px solid var(--line);
  border-radius: 14px;
}

section { padding: 1rem 1.05rem 1.15rem; margin-bottom: 0.9rem; }

.part { padding: 0.85rem; margin-top: 0.75rem; background: #fff; }

label, legend { font-size: 0.82rem; color: #3a342c; }

.field {
  display: flex;
  flex-direction: column;
  gap: 0.25rem;
  min-width: 0;
}

.fields {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(148px, 1fr));
  gap: 0.65rem;
  margin: 0.7rem 0;
}

.field.wide { grid-column: span 2; }

input, select, button, .btn {
  font: inherit;
  color: var(--ink);
}

input, select {
  width: 100%;
  background: #fff;
  border: 1px solid #d4cdc0;
  border-radius: 8px;
  padding: 0.45rem 0.55rem;
}

input:focus, select:focus, button:focus-visible, .btn:focus-visible {
  outline: 2px solid var(--teal);
  outline-offset: 1px;
  border-color: var(--teal);
}

.inline {
  display: flex;
  align-items: center;
  gap: 0.25rem;
}

.inline input { flex: 1; }

button, .btn {
  border: 1px solid #cfc6b6;
  background: #fff;
  border-radius: 8px;
  padding: 0.45rem 0.7rem;
  cursor: pointer;
}

button:hover, .btn:hover { border-color: #9d9486; }

button.primary, .btn.primary {
  background: var(--teal);
  border-color: var(--teal-dark);
  color: white;
}

button.ghost { background: transparent; }

button.danger, .danger { color: var(--danger); }

.btn { display: inline-flex; align-items: center; }

.unit-switch, .choices {
  border: 1px solid var(--line);
  border-radius: 10px;
  margin: 0.7rem 0 0;
  padding: 0.45rem 0.7rem 0.6rem;
}

.unit-switch { margin: 0; }

.choices.tight { margin-top: 0.4rem; }

.choices label, .unit-switch label { margin-right: 0.8rem; }

.check {
  display: flex;
  align-items: center;
  gap: 0.4rem;
  margin: 0.25rem 0;
}

.check input { width: auto; }

.currency-field { width: 4.5rem; }

.row-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 0.45rem;
  margin-top: 0.6rem;
}

.table-wrap { overflow-x: auto; }

table { width: 100%; border-collapse: collapse; }

th, td {
  text-align: left;
  padding: 0.3rem;
  vertical-align: middle;
  font-weight: 500;
}

caption {
  text-align: left;
  font-weight: 650;
  margin-bottom: 0.35rem;
}

.part-top {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 7.5rem auto;
  gap: 0.6rem;
  align-items: end;
}

.bend-row {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 0.6rem;
  margin: 0.35rem 0 0.7rem;
  padding: 0.55rem;
  background: #f6f3ec;
  border-radius: 10px;
}

.fee-row, .preset-row, .k-row {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 8rem auto;
  gap: 0.45rem;
  margin-bottom: 0.4rem;
  align-items: center;
}

.k-row {
  grid-template-columns: minmax(0, 0.9fr) minmax(0, 1.4fr) 5.5rem auto;
  align-items: center;
}

.k-head {
  margin-bottom: 0.15rem;
  color: var(--muted);
  font-size: 0.78rem;
}

.formula-block {
  display: grid;
  grid-template-columns: 220px minmax(0, 1fr);
  gap: 0.8rem;
  align-items: center;
}

.bend-figure { margin: 0; }

.bend-figure svg {
  width: 100%;
  height: auto;
  border-radius: 10px;
  border: 1px solid var(--line);
}

.bend-figure figcaption { color: var(--muted); font-size: 0.82rem; margin-top: 0.35rem; }

.formula, .math {
  font-family: var(--mono);
  font-size: 0.82rem;
  background: #f3f0e8;
  border-radius: 10px;
  padding: 0.7rem 0.8rem;
}

.formula p, .math p { margin: 0.15rem 0; }

.math { margin-top: 0.45rem; }

.derived .flat-used { font-weight: 700; }

.hint, small { color: var(--muted); font-size: 0.78rem; }

.error { color: var(--danger); font-weight: 650; }

.warn { color: var(--warn); }

.solver-result { min-height: 1.2rem; }

.solver-k {
  font-family: var(--mono);
  font-size: 1.35rem;
  margin: 0.4rem 0;
}

.nest-headline { font-size: 1.15rem; }

.nest-parts { margin: 0.4rem 0 0.2rem; padding-left: 1.1rem; }

.nest-visual {
  display: flex;
  flex-wrap: wrap;
  gap: 0.8rem;
  margin-top: 0.6rem;
}

.nest-visual figure {
  margin: 0;
  width: min(100%, 640px);
}

.nest-visual figcaption { font-size: 0.82rem; color: var(--muted); margin-top: 0.3rem; }

canvas {
  display: block;
  border-radius: 8px;
  background: #f6f1e6;
}

.legend {
  list-style: none;
  display: flex;
  flex-wrap: wrap;
  gap: 0.7rem;
  padding: 0;
  margin: 0.5rem 0 0;
}

.legend li { display: flex; align-items: center; gap: 0.35rem; font-size: 0.85rem; }

.legend i {
  width: 0.8rem;
  height: 0.8rem;
  border-radius: 2px;
  display: inline-block;
}

.quote-wrap {
  position: sticky;
  top: 0.75rem;
  max-height: calc(100vh - 1.5rem);
  overflow: auto;
}

.quote {
  background: var(--quote);
  color: var(--quote-text);
  border-radius: 16px;
  padding: 0.9rem 1rem 1.1rem;
}

.quote .eyebrow { color: var(--brass); }

.quote-total {
  position: sticky;
  top: 0;
  background: var(--quote);
  padding-bottom: 0.6rem;
  z-index: 1;
}

.quote-job { color: #d9d3c6; margin: 0; }

.sell {
  margin: 0.15rem 0;
  font-size: 2.4rem;
  letter-spacing: -0.03em;
  font-variant-numeric: tabular-nums;
  color: var(--brass);
  font-weight: 720;
}

.per-part, .quote-foot, .quote .hint { color: #d4cdc0; }

.quote h3 { color: #fff; }

.quote .field, .quote legend, .quote label { color: #efeae1; }

.quote input, .quote select {
  background: #101614;
  color: var(--quote-text);
  border-color: #3a4642;
}

.notices { margin: 0.4rem 0 0; padding-left: 1.1rem; }

.notices .error { color: #ffb4a8; }

.notices .warn { color: var(--brass); }

.quote-body p { font-variant-numeric: tabular-nums; }

footer {
  margin-top: 0.4rem;
  color: var(--muted);
  font-size: 0.88rem;
}

.sr {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  border: 0;
}

.print-only { display: none; }

.print-sheet { max-width: 760px; color: #111; }

.print-kicker {
  letter-spacing: 0.08em;
  text-transform: uppercase;
  font-size: 0.75rem;
  margin: 0;
}

.print-title { font-size: 1.8rem; margin: 0.2rem 0 0.4rem; font-weight: 720; }

.print-disclaimer {
  border-left: 3px solid #111;
  padding-left: 0.6rem;
  font-size: 0.9rem;
}

.print-sheet table { margin: 0.6rem 0 1rem; }

.print-sheet th, .print-sheet td {
  border-bottom: 1px solid #ccc;
  padding: 0.3rem 0.4rem 0.3rem 0;
}

.print-total { font-size: 1.4rem; font-weight: 720; }

@media (max-width: 980px) {
  .layout { grid-template-columns: 1fr; }
  .quote-wrap { position: static; max-height: none; }
  .top { flex-direction: column; align-items: stretch; }
  .top-actions { justify-content: flex-start; }
  .formula-block, .part-top, .bend-row { grid-template-columns: 1fr; }
  .field.wide { grid-column: auto; }
}

@media print {
  body { background: white; }
  .screen { display: none !important; }
  .print-only { display: block !important; }
  @page { margin: 14mm; }
}
