:root {
  --bg: #f4f2ee; --panel: #fff; --ink: #1f2326; --muted: #5f676d; --line: #d9d6cf;
  --accent: #e88a1a; --accent-ink: #fff; --steel: #5a6b78; --ok: #2a7a4a; --bad: #b3261e; --warn: #fff4d6;
  --field: #fbfaf8;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #16191b; --panel: #1f2326; --ink: #e8e6e1; --muted: #9aa3a8; --line: #343a3e;
    --accent: #f09a33; --accent-ink: #1a1a1a; --steel: #8fa3b2; --ok: #5cc28a; --bad: #ff8a80; --warn: #3a3220;
    --field: #191c1e; color-scheme: dark;
  }
}
:root[data-theme="dark"] {
  --bg: #16191b; --panel: #1f2326; --ink: #e8e6e1; --muted: #9aa3a8; --line: #343a3e;
  --accent: #f09a33; --accent-ink: #1a1a1a; --steel: #8fa3b2; --ok: #5cc28a; --bad: #ff8a80; --warn: #3a3220;
  --field: #191c1e; color-scheme: dark;
}

* { box-sizing: border-box; }
body { margin: 0; background: var(--bg); color: var(--ink); font: 15px/1.45 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif; }
header, main, footer { max-width: 1320px; margin: 0 auto; padding: 0 16px; }
header { padding-top: 24px; }
h1 { margin: 0 0 6px; font-size: 26px; letter-spacing: -.01em; }
header p { margin: 0 0 18px; color: var(--muted); max-width: 75ch; }
footer { color: var(--muted); font-size: 13px; padding-bottom: 32px; }
a { color: var(--steel); }
small, .small { color: var(--muted); font-size: 12.5px; }

main { display: grid; grid-template-columns: minmax(300px, 400px) minmax(0, 1fr); gap: 20px; align-items: start; }
@media (max-width: 900px) { main { grid-template-columns: minmax(0, 1fr); } }

form, #out { background: var(--panel); border: 1px solid var(--line); border-radius: 10px; padding: 14px 16px; }
#out { position: sticky; top: 12px; }
@media (max-width: 900px) { #out { position: static; } }

fieldset { border: 0; border-top: 1px solid var(--line); margin: 0; padding: 12px 0 14px; min-width: 0; }
fieldset:first-of-type { border-top: 0; }
fieldset.inner { border: 0; padding: 6px 0 0; }
fieldset.inner:disabled { opacity: .45; }
legend { font-weight: 650; padding: 0; margin-bottom: 8px; }
legend small { font-weight: 400; margin-left: 6px; }
.grid2 { display: grid; grid-template-columns: 1fr 1fr; gap: 8px 12px; }
label { display: flex; flex-direction: column; gap: 3px; font-size: 13px; color: var(--muted); justify-content: flex-end; }
label.wide { margin-top: 10px; }
label.check { flex-direction: row; align-items: center; gap: 8px; margin-top: 12px; color: var(--ink); font-size: 14px; }
input, select { font: inherit; color: var(--ink); background: var(--field); border: 1px solid var(--line); border-radius: 6px; padding: 6px 8px; width: 100%; min-width: 0; }
input:focus, select:focus { outline: 2px solid var(--accent); outline-offset: -1px; }
input[type=radio], input[type=checkbox] { width: auto; accent-color: var(--accent); }
.radio { display: flex; gap: 14px; align-items: center; margin-top: 10px; font-size: 14px; }
.radio span { color: var(--muted); font-size: 13px; }
.radio label { flex-direction: row; align-items: center; gap: 5px; color: var(--ink); font-size: 14px; }

table.rows { width: 100%; border-collapse: collapse; }
table.rows th { font-size: 12px; font-weight: 500; color: var(--muted); text-align: left; padding: 0 4px 3px; }
table.rows td { padding: 2px 3px; }
table.rows td:last-child { width: 30px; }
button { font: inherit; cursor: pointer; border-radius: 7px; border: 1px solid transparent; padding: 8px 14px; background: var(--accent); color: var(--accent-ink); font-weight: 600; }
button:disabled { opacity: .45; cursor: default; }
button.ghost { background: transparent; color: var(--ink); border-color: var(--line); font-weight: 500; }
button.ghost:hover { border-color: var(--muted); }
button.add { margin-top: 6px; padding: 5px 10px; font-size: 13px; }
button.x { background: transparent; color: var(--muted); padding: 2px 8px; font-size: 18px; line-height: 1; }
button.x:hover { color: var(--bad); }
button.link { background: none; border: 0; padding: 0; color: var(--steel); text-decoration: underline; font-weight: 500; }
.actions { display: flex; gap: 10px; flex-wrap: wrap; margin-top: 14px; }
.actions.bar { margin: 4px 0 10px; }
.actions.top { margin: 0 0 4px; justify-content: flex-end; }

#status { margin: 0 0 6px; font-weight: 600; }
#status[data-kind=busy] { color: var(--muted); }
#status[data-kind=bad] { color: var(--bad); }
#status[data-kind=ok] { color: var(--ok); }
#notes { margin: 0 0 8px; padding: 0; list-style: none; }
#notes li { background: var(--warn); border-radius: 6px; padding: 5px 10px; margin-bottom: 4px; font-size: 14px; }

[role=tablist] { display: flex; gap: 2px; border-bottom: 1px solid var(--line); margin-bottom: 12px; overflow-x: auto; }
[role=tab] { background: none; color: var(--muted); border-radius: 0; border: 0; border-bottom: 2px solid transparent; padding: 8px 12px; font-weight: 550; }
[role=tab][aria-selected=true] { color: var(--ink); border-bottom-color: var(--accent); }

#plan { background: #fafaf7; border-radius: 8px; padding: 8px; }
#plan svg { width: 100%; height: auto; max-height: 72vh; display: block; margin: 0 auto; }
#summary { display: grid; grid-template-columns: max-content 1fr; gap: 3px 14px; margin: 12px 0 6px; font-size: 14px; }
#summary dt { color: var(--muted); }
#summary dd { margin: 0; font-variant-numeric: tabular-nums; }
.key { font-size: 12.5px; color: var(--muted); display: flex; flex-wrap: wrap; gap: 4px 12px; align-items: center; }
.sw { display: inline-block; width: 18px; height: 10px; border-radius: 2px; margin-right: -6px; vertical-align: -1px; }
.sw.bar { background: #5a6b78; } .sw.clip { background: #e88a1a; } .sw.hinge { background: #e06; opacity: .5; }
.sw.shelf { background: #888; opacity: .45; } .sw.open { border: 1px dashed #888; }

#viewer { height: min(68vh, 640px); border-radius: 8px; background: linear-gradient(#eef0f1, #d9dde0); overflow: hidden; touch-action: none; }
@media (prefers-color-scheme: dark) { :root:not([data-theme="light"]) #viewer { background: linear-gradient(#2a3034, #1a1e21); } }
:root[data-theme="dark"] #viewer { background: linear-gradient(#2a3034, #1a1e21); }
#viewer canvas { width: 100% !important; height: 100% !important; display: block; }

#parts { width: 100%; border-collapse: collapse; font-size: 14px; }
#parts th { text-align: left; font-weight: 500; color: var(--muted); font-size: 12.5px; border-bottom: 1px solid var(--line); padding: 4px 6px; }
#parts td { border-bottom: 1px solid var(--line); padding: 5px 6px; vertical-align: top; }
#parts td.st { color: var(--muted); white-space: nowrap; font-variant-numeric: tabular-nums; }
#sheet-frame { width: 100%; height: 70vh; border: 1px solid var(--line); border-radius: 8px; background: #fff; }
