:root {
  color-scheme: light;
  --bg: #edf1f0;
  --panel: #ffffff;
  --surface: #f6f8f7;
  --surface-strong: #eef3f1;
  --ink: #18211f;
  --muted: #5b6764;
  --line: #d5ddda;
  --line-strong: #aebbb7;
  --accent: #0b6b5f;
  --accent-strong: #075349;
  --accent-soft: #e1f1ed;
  --wood: #b7773a;
  --wood-alt: #d19a59;
  --gap: #020202;
  --edge: #dfe5e2;
  --uk: #22677b;
  --danger: #a23b2f;
  --warning: #96631c;
  --shadow: 0 8px 28px rgba(24, 41, 37, 0.09);
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

* {
  box-sizing: border-box;
}

html {
  background: var(--bg);
}

body {
  margin: 0;
  min-height: 100vh;
  color: var(--ink);
  background: var(--bg);
}

button,
input,
select {
  font: inherit;
}

button:disabled {
  cursor: not-allowed;
  opacity: 0.45;
}

.app-shell {
  width: min(1880px, calc(100vw - 28px));
  margin: 0 auto;
  padding: 14px 0 28px;
}

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 24px;
  min-height: 66px;
  padding: 8px 2px 14px;
}

.eyebrow,
.panel-kicker {
  margin: 0 0 3px;
  color: var(--accent);
  font-size: 0.72rem;
  font-weight: 800;
  letter-spacing: 0;
  text-transform: uppercase;
}

h1,
h2,
h3,
h4,
p {
  margin-top: 0;
}

h1 {
  margin-bottom: 0;
  font-size: 1.72rem;
  line-height: 1.1;
  letter-spacing: 0;
}

h2 {
  margin-bottom: 10px;
  font-size: 1rem;
  line-height: 1.25;
  letter-spacing: 0;
}

.status-strip {
  display: flex;
  flex-wrap: wrap;
  justify-content: flex-end;
  gap: 6px;
}

.status-strip span {
  display: grid;
  gap: 1px;
  min-width: 104px;
  min-height: 48px;
  padding: 7px 10px;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: rgba(255, 255, 255, 0.9);
  color: var(--muted);
  font-size: 0.75rem;
}

.status-strip strong {
  color: var(--ink);
  font-size: 0.94rem;
}

.workspace {
  display: grid;
  grid-template-columns: minmax(330px, 390px) minmax(0, 1fr);
  gap: 16px;
  align-items: start;
}

.input-panel,
.result-panel {
  min-width: 0;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel);
  box-shadow: var(--shadow);
}

.input-panel {
  position: sticky;
  top: 12px;
  max-height: calc(100vh - 24px);
  overflow: auto;
  -webkit-overflow-scrolling: touch;
  padding: 16px;
}

.input-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin: -16px -16px 0;
  padding: 15px 16px 13px;
  border-bottom: 1px solid var(--line);
  background: var(--panel);
}

.input-head h2 {
  margin: 0;
  font-size: 1.08rem;
}

.live-status {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 5px 8px;
  border: 1px solid #acd2c9;
  border-radius: 6px;
  background: #eaf6f3;
  color: var(--accent-strong);
  font-size: 0.72rem;
  font-weight: 800;
  text-transform: uppercase;
}

.live-status i {
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: #168575;
}

.field-block {
  padding-top: 18px;
}

.field-block + .field-block {
  margin-top: 17px;
  border-top: 1px solid var(--line);
}

.field-block h2 {
  margin-bottom: 12px;
  color: var(--ink);
  font-size: 0.88rem;
  text-transform: uppercase;
}

label {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 94px 34px;
  gap: 8px;
  align-items: center;
  min-height: 38px;
  margin-bottom: 8px;
  color: var(--muted);
  font-size: 0.84rem;
}

.range-row {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
}

.range-row label {
  grid-template-columns: minmax(32px, 1fr) 70px 27px;
}

input,
select {
  width: 100%;
  min-width: 0;
  height: 34px;
  border: 1px solid var(--line-strong);
  border-radius: 5px;
  padding: 6px 8px;
  background: #fff;
  color: var(--ink);
}

input {
  text-align: right;
}

select {
  appearance: auto;
  padding-right: 4px;
}

input:focus,
select:focus {
  outline: 3px solid rgba(11, 107, 95, 0.16);
  border-color: var(--accent);
}

small {
  color: var(--muted);
}

.edge-title {
  margin: 10px 0 5px;
  color: var(--ink);
  font-size: 0.76rem;
  font-weight: 800;
}

.actions,
.export-actions {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: flex-end;
  gap: 7px;
}

.actions {
  position: sticky;
  bottom: -16px;
  z-index: 3;
  margin: 18px -16px -16px;
  padding: 12px 16px;
  border-top: 1px solid var(--line);
  background: rgba(255, 255, 255, 0.96);
}

button {
  min-height: 36px;
  border: 1px solid transparent;
  border-radius: 5px;
  padding: 7px 11px;
  cursor: pointer;
  font-weight: 750;
}

button:focus-visible {
  outline: 3px solid rgba(11, 107, 95, 0.22);
  outline-offset: 2px;
}

.primary-button {
  background: var(--accent);
  color: #fff;
}

.primary-button:hover {
  background: var(--accent-strong);
}

.secondary-button,
.icon-button {
  border-color: var(--line-strong);
  background: var(--panel);
  color: var(--ink);
}

.secondary-button:hover,
.icon-button:hover {
  border-color: var(--accent);
  color: var(--accent-strong);
}

.secondary-button.is-active {
  border-color: var(--accent);
  background: var(--accent-soft);
  color: var(--accent-strong);
}

.icon-button,
#reset-button {
  display: inline-grid;
  width: 36px;
  min-width: 36px;
  height: 36px;
  min-height: 36px;
  place-items: center;
  padding: 0;
  font-size: 1.15rem;
  line-height: 1;
}

.result-panel {
  overflow: clip;
}

.result-head,
.section-head {
  display: flex;
  justify-content: space-between;
  gap: 18px;
  align-items: center;
  padding: 15px 18px;
  border-bottom: 1px solid var(--line);
}

.result-head h2 {
  margin-bottom: 4px;
  font-size: 1.15rem;
}

.result-head p,
.section-head p {
  margin-bottom: 0;
  color: var(--muted);
  font-size: 0.84rem;
}

.selection-summary {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  border-bottom: 1px solid var(--line);
  background: var(--surface);
}

.selection-summary > div {
  display: grid;
  min-width: 0;
  min-height: 76px;
  align-content: center;
  gap: 2px;
  padding: 11px 15px;
  border-right: 1px solid var(--line);
}

.selection-summary > div:last-child {
  border-right: 0;
}

.selection-summary span,
.selection-summary small {
  overflow: hidden;
  color: var(--muted);
  font-size: 0.72rem;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.selection-summary strong {
  overflow: hidden;
  font-size: 1rem;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.plan-insights {
  display: flex;
  flex-wrap: wrap;
  gap: 8px 18px;
  min-height: 42px;
  align-items: center;
  padding: 9px 18px;
  border-bottom: 1px solid var(--line);
  background: #fff;
}

.plan-insight {
  display: inline-flex;
  align-items: center;
  gap: 7px;
  color: var(--muted);
  font-size: 0.78rem;
}

.plan-insight::before {
  width: 7px;
  height: 7px;
  flex: 0 0 auto;
  border-radius: 50%;
  background: var(--accent);
  content: "";
}

.plan-insight--warn::before {
  background: var(--warning);
}

.preview-area {
  background: #f2f5f4;
}

.preview-toolbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 14px;
  padding: 9px 14px;
  border-bottom: 1px solid var(--line);
  background: var(--panel);
}

.legend {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  color: var(--muted);
  font-size: 0.76rem;
}

.legend span {
  display: inline-flex;
  align-items: center;
  gap: 5px;
}

.legend i {
  display: inline-block;
  width: 14px;
  height: 8px;
  border: 1px solid rgba(0, 0, 0, 0.18);
}

.legend-board {
  background: var(--wood);
}

.legend-gap,
.legend-joint {
  background: var(--gap);
}

.legend-edge {
  background: var(--edge);
}

.legend-uk {
  background: var(--uk);
}

.zoom-controls {
  display: flex;
  align-items: center;
  gap: 7px;
  flex: 0 0 auto;
}

#preview-zoom {
  width: 116px;
  height: auto;
  border: 0;
  padding: 0;
  accent-color: var(--accent);
}

#zoom-value {
  min-width: 42px;
  color: var(--muted);
  font-size: 0.76rem;
  font-variant-numeric: tabular-nums;
  text-align: center;
}

.svg-preview {
  min-height: 620px;
  overflow: auto;
  padding: 14px;
  -webkit-overflow-scrolling: touch;
  background: #e9eeec;
}

.svg-preview svg {
  display: block;
  width: 100%;
  min-width: 0;
  max-width: none;
  height: auto;
  border: 1px solid #c7d0cd;
  border-radius: 6px;
  background: #fff;
  box-shadow: 0 3px 12px rgba(24, 41, 37, 0.08);
}

.svg-preview .placeholder {
  min-height: 420px;
  display: grid;
  place-items: center;
  border: 1px dashed var(--line-strong);
  border-radius: 6px;
  color: var(--muted);
  background: #fff;
}

.result-tabs {
  position: sticky;
  top: 0;
  z-index: 5;
  display: flex;
  overflow-x: auto;
  border-top: 1px solid var(--line);
  border-bottom: 1px solid var(--line);
  background: rgba(255, 255, 255, 0.97);
}

.result-tab {
  min-height: 45px;
  flex: 0 0 auto;
  border: 0;
  border-bottom: 3px solid transparent;
  border-radius: 0;
  padding: 10px 18px 8px;
  background: transparent;
  color: var(--muted);
}

.result-tab:hover {
  color: var(--ink);
  background: var(--surface);
}

.result-tab.is-active {
  border-bottom-color: var(--accent);
  color: var(--accent-strong);
  background: var(--accent-soft);
}

.tab-panel[hidden] {
  display: none !important;
}

.tab-panel {
  background: var(--panel);
}

.table-wrap {
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
  background: var(--panel);
}

table {
  width: 100%;
  min-width: 940px;
  border-collapse: collapse;
}

.joint-table {
  min-width: 1080px;
}

th,
td {
  padding: 10px 12px;
  border-bottom: 1px solid var(--line);
  text-align: right;
  white-space: nowrap;
}

th {
  position: sticky;
  top: 0;
  z-index: 1;
  background: #f0f4f2;
  color: var(--muted);
  font-size: 0.72rem;
  text-transform: uppercase;
}

td {
  font-size: 0.86rem;
}

th:first-child,
td:first-child {
  text-align: left;
}

tbody tr {
  cursor: pointer;
}

tbody tr:hover {
  background: #f1f8f6;
}

tbody tr.is-selected {
  background: var(--accent-soft);
  box-shadow: inset 4px 0 0 var(--accent);
}

.rating {
  display: inline-flex;
  min-width: 86px;
  align-items: center;
  justify-content: center;
  border-radius: 5px;
  padding: 4px 8px;
  color: #15423f;
  background: #dcefeb;
  font-weight: 800;
}

.rating.ok {
  color: #674615;
  background: #f5e1c2;
}

.rating.tight {
  color: #7b251b;
  background: #f3d7d2;
}

.empty-state {
  padding: 20px 18px;
  color: var(--danger);
  background: #fff6f3;
  border-bottom: 1px solid #e9bdb5;
}

.cutlist-area {
  background: var(--panel);
}

.cutlist-output {
  padding: 0 18px 20px;
}

.cutlist-summary {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 1px;
  margin: 16px 0;
  border: 1px solid var(--line);
  border-radius: 6px;
  overflow: hidden;
  background: var(--line);
}

.cutlist-summary span {
  display: grid;
  min-height: 58px;
  align-content: center;
  gap: 2px;
  padding: 9px 12px;
  background: var(--surface);
  color: var(--muted);
  font-size: 0.74rem;
}

.cutlist-summary strong {
  color: var(--ink);
  font-size: 0.96rem;
}

.cutlist-shim {
  margin-bottom: 16px;
  padding: 12px;
  border-left: 3px solid var(--accent);
  background: var(--surface);
}

.cutlist-shim h3,
.cutlist-block h3,
.cutlist-plain h3,
.cutlist-patterns h3 {
  margin: 0 0 7px;
  font-size: 0.9rem;
}

.cutlist-shim p,
.cutlist-block p {
  margin: 0 0 8px;
  color: var(--muted);
  font-size: 0.82rem;
}

.shim-sequence {
  overflow-x: auto;
  color: var(--ink);
  font: 0.84rem/1.5 ui-monospace, SFMono-Regular, Consolas, "Liberation Mono", monospace;
  white-space: nowrap;
}

.cutlist-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 16px;
  align-items: start;
}

.cutlist-block {
  min-width: 0;
}

.cutlist-block h4 {
  margin: 13px 0 7px;
  color: var(--muted);
  font-size: 0.72rem;
  text-transform: uppercase;
}

.cutlist-table-wrap {
  overflow-x: auto;
  border: 1px solid var(--line);
  border-radius: 6px;
}

.cutlist-table {
  min-width: 420px;
}

.cutlist-table th,
.cutlist-table td {
  padding: 8px 10px;
}

.cutlist-patterns {
  margin-top: 16px;
  padding-top: 14px;
  border-top: 1px solid var(--line);
}

.cutlist-pattern-list {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
  gap: 8px;
}

.cutlist-pattern {
  min-width: 0;
  padding: 10px 11px;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: var(--surface);
}

.cutlist-pattern strong {
  display: block;
  margin-bottom: 4px;
  font-size: 0.86rem;
}

.cutlist-pattern span {
  display: block;
  color: var(--muted);
  font-size: 0.8rem;
  line-height: 1.45;
}

.cutlist-plain {
  margin-top: 16px;
}

.cutlist-plain pre {
  max-height: 280px;
  margin: 0;
  overflow: auto;
  border: 1px solid var(--line);
  border-radius: 6px;
  padding: 12px;
  background: #f2f5f4;
  color: var(--ink);
  font: 0.8rem/1.45 ui-monospace, SFMono-Regular, Consolas, "Liberation Mono", monospace;
  white-space: pre-wrap;
}

.cutlist-output .placeholder {
  min-height: 160px;
  display: grid;
  place-items: center;
  border: 1px dashed var(--line-strong);
  border-radius: 6px;
  color: var(--muted);
  background: #fff;
}

.planner-note {
  margin: 0;
  padding: 11px 18px;
  border-top: 1px solid var(--line);
  color: var(--muted);
  background: var(--surface);
  font-size: 0.72rem;
}

.error input,
input.error {
  border-color: var(--danger);
  background: #fff8f6;
}

@media (max-width: 1180px) {
  .workspace {
    grid-template-columns: minmax(310px, 350px) minmax(0, 1fr);
  }

  .selection-summary {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  .selection-summary > div:nth-child(2) {
    border-right: 0;
  }

  .selection-summary > div:nth-child(-n + 2) {
    border-bottom: 1px solid var(--line);
  }
}

@media (max-width: 900px) {
  .app-shell {
    width: min(100vw - 18px, 780px);
    padding-top: 8px;
  }

  .topbar,
  .result-head,
  .section-head,
  .preview-toolbar {
    align-items: flex-start;
    flex-direction: column;
  }

  .status-strip,
  .export-actions,
  .legend {
    justify-content: flex-start;
  }

  .workspace {
    grid-template-columns: minmax(0, 1fr);
  }

  .input-panel {
    position: static;
    max-height: none;
    overflow: visible;
  }

  .actions {
    bottom: 0;
  }

  .zoom-controls {
    width: 100%;
  }

  #preview-zoom {
    flex: 1;
  }

  .svg-preview {
    min-height: 520px;
  }

  .cutlist-summary {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  .cutlist-grid {
    grid-template-columns: 1fr;
  }
}

@media (max-width: 560px) {
  .topbar {
    gap: 12px;
  }

  .status-strip {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    width: 100%;
  }

  .status-strip span {
    min-width: 0;
  }

  .range-row {
    grid-template-columns: 1fr;
    gap: 0;
  }

  label,
  .range-row label {
    grid-template-columns: minmax(0, 1fr) 102px 32px;
  }

  input,
  select {
    min-height: 42px;
    font-size: 16px;
  }

  button {
    min-height: 42px;
  }

  .icon-button,
  #reset-button {
    width: 42px;
    height: 42px;
  }

  .selection-summary {
    grid-template-columns: 1fr;
  }

  .selection-summary > div {
    min-height: 64px;
    border-right: 0;
    border-bottom: 1px solid var(--line);
  }

  .selection-summary > div:last-child {
    border-bottom: 0;
  }

  .plan-insights {
    display: grid;
  }

  .svg-preview {
    min-height: 430px;
    padding: 8px;
  }

  .result-tab {
    padding-inline: 14px;
  }

  th,
  td {
    padding: 10px;
  }

  table {
    min-width: 800px;
  }

  .cutlist-summary {
    grid-template-columns: 1fr;
  }

  .cutlist-output {
    padding: 0 10px 16px;
  }
}

@media print {
  @page {
    margin: 12mm;
  }

  body,
  html {
    background: #fff;
  }

  .app-shell {
    width: 100%;
    padding: 0;
  }

  .topbar {
    padding-bottom: 10px;
  }

  .status-strip,
  .input-panel,
  .export-actions,
  .zoom-controls,
  .result-tabs,
  #tab-layout,
  #tab-uk,
  #tab-joints {
    display: none !important;
  }

  .workspace {
    display: block;
  }

  .result-panel {
    border: 0;
    box-shadow: none;
  }

  .result-head,
  .selection-summary,
  .plan-insights,
  .preview-area,
  #tab-cutlist {
    break-inside: avoid;
  }

  .preview-toolbar {
    padding-inline: 0;
  }

  .svg-preview {
    min-height: 0;
    overflow: visible;
    padding: 0;
    background: #fff;
  }

  .svg-preview svg {
    width: 100% !important;
    box-shadow: none;
  }

  #tab-cutlist {
    display: block !important;
  }

  .cutlist-plain {
    display: none;
  }
}
