/* FabCalc — workshop drafting theme. Fonts: system DIN-style (Bahnschrift on Windows, DIN Alternate on Apple). */
:root {
  --font: "Bahnschrift", "DIN Alternate", "DIN 2014", "Barlow", "Franklin Gothic Medium", "Arial Narrow", sans-serif;
  --font-num: "Cascadia Mono", "SF Mono", "JetBrains Mono", Consolas, "Liberation Mono", monospace;
  --bg: #e9e5dc; --surface: #fbfaf6; --surface-2: #f2efe7; --line: #d6d0c3; --line-2: #c4bdae;
  --ink: #1f2421; --ink-2: #4f5650; --ink-3: #7c837d;
  --chrome: #1f2421; --chrome-ink: #f1ede4; --chrome-2: #2c332f;
  --accent: #e0592a; --accent-ink: #fff; --accent-soft: #fbe3d7;
  --good: #2f7d4f; --good-soft: #dcefe2; --warn: #b7791f; --warn-soft: #fbefd6; --bad: #b8362b; --bad-soft: #f8dcd8;
  --canvas: #f6f3ec; --canvas-2: #e8e3d8; --grid: rgba(31,36,33,.055); --grid-major: rgba(31,36,33,.13);
  --wall: rgba(140,128,108,.10); --wall-solid: rgba(120,110,95,.4); --wall3d: #ebe5d8; --floor: rgba(90,80,70,.08);
  --radius: 10px; --shadow: 0 1px 2px rgba(0,0,0,.06), 0 6px 20px rgba(0,0,0,.07);
  --panel-w: 340px; --tap: 40px;
  --safe-b: env(safe-area-inset-bottom, 0px);
}
:root[data-theme="dark"] {
  --bg: #151816; --surface: #1d211f; --surface-2: #242926; --line: #333a36; --line-2: #414943;
  --ink: #ece8df; --ink-2: #b9bcb5; --ink-3: #8a908a; --chrome: #0f1210; --chrome-2: #1b201d;
  --accent: #f0703f; --accent-soft: #3a2419; --good-soft: #17301f; --warn-soft: #3a2e14; --bad-soft: #3b1a17;
  --canvas: #1b1f1d; --canvas-2: #131614; --grid: rgba(236,232,223,.05); --grid-major: rgba(236,232,223,.11);
  --wall: rgba(200,190,170,.06); --wall-solid: rgba(200,190,170,.3); --wall3d: #2a2e2b; --floor: rgba(255,255,255,.04);
}
* { box-sizing: border-box; }
[hidden] { display: none !important; }
html, body { margin: 0; height: 100%; background: var(--bg); color: var(--ink); font-family: var(--font); font-size: 15px; -webkit-text-size-adjust: 100%; }
body { overscroll-behavior: none; }
button, input, select, textarea { font: inherit; color: inherit; }
.num, td.n, .mono { font-family: var(--font-num); font-variant-numeric: tabular-nums; }

#app { display: grid; grid-template-rows: auto auto 1fr auto; height: 100dvh; height: 100vh; }
@supports (height: 100dvh) { #app { height: 100dvh; } }

/* ---------- top bar ---------- */
.topbar { display: flex; align-items: center; gap: 10px; padding: 8px 12px; background: var(--chrome); color: var(--chrome-ink); min-height: 52px; }
.brand { display: flex; align-items: center; gap: 8px; background: none; border: 0; color: inherit; cursor: pointer; padding: 4px 6px; border-radius: 8px; font-weight: 700; letter-spacing: .06em; text-transform: uppercase; font-size: 14px; }
.brand svg { width: 26px; height: 26px; color: var(--accent); }
.brand:hover { background: var(--chrome-2); }
input.proj-name, .topbar input.proj-name { flex: 1; color: var(--chrome-ink); background: transparent; border-color: transparent; min-width: 60px; background: transparent; border: 1px solid transparent; color: inherit; padding: 6px 8px; border-radius: 8px; font-size: 16px; font-weight: 600; }
input.proj-name:hover, input.proj-name:focus { border-color: #4a524d; outline: none; background: var(--chrome-2); }
.save-state { color: #7fbf8f; font-size: 10px; } .save-state.dirty { color: var(--warn); } .save-state.err { color: var(--bad); }
.top-actions { display: flex; align-items: center; gap: 8px; }
.cost-pill { font-family: var(--font-num); background: var(--chrome-2); border: 1px solid #3b433e; padding: 6px 10px; border-radius: 999px; cursor: pointer; white-space: nowrap; font-size: 14px; }
.cost-pill:hover { border-color: var(--accent); }

/* ---------- tabs ---------- */
.tabs { display: flex; gap: 2px; background: var(--chrome); padding: 0 8px; overflow-x: auto; scrollbar-width: none; }
.tabs::-webkit-scrollbar { display: none; }
.tab { background: none; border: 0; color: #b8bbb3; padding: 10px 14px 11px; cursor: pointer; font-weight: 600; letter-spacing: .03em; border-bottom: 3px solid transparent; white-space: nowrap; }
.tab:hover { color: #fff; }
.tab.on { color: #fff; border-bottom-color: var(--accent); }
.tab .badge { display: inline-block; min-width: 18px; padding: 0 5px; margin-left: 6px; border-radius: 9px; background: var(--bad); color: #fff; font-size: 11px; line-height: 18px; text-align: center; }
.bottomnav { display: none; }

/* ---------- views ---------- */
main#views { position: relative; overflow: hidden; min-height: 0; }
.view { position: absolute; inset: 0; display: none; }
.view.on { display: grid; }
.view.page { overflow-y: auto; padding: 18px clamp(12px, 3vw, 32px) 80px; display: none; align-content: start; }
.view.page.on { display: block; }
.page-inner { max-width: 1100px; margin: 0 auto; }

/* design view */
#view-design.on { grid-template-columns: 1fr var(--panel-w); grid-template-rows: auto 1fr; }
.toolbar { grid-column: 1 / -1; display: flex; align-items: center; gap: 6px; padding: 8px 10px; background: var(--surface); border-bottom: 1px solid var(--line); overflow-x: auto; scrollbar-width: thin; }
.toolbar .sep { width: 1px; align-self: stretch; background: var(--line); margin: 0 4px; }
.stage { position: relative; min-width: 0; min-height: 0; background: var(--canvas); touch-action: none; }
#cv { position: absolute; inset: 0; width: 100%; height: 100%; display: block; cursor: crosshair; }
.view-switch { position: absolute; top: 10px; left: 10px; display: flex; background: var(--surface); border: 1px solid var(--line); border-radius: 10px; box-shadow: var(--shadow); overflow: hidden; }
.view-switch button { border: 0; background: none; padding: 8px 12px; cursor: pointer; font-weight: 600; min-width: 48px; }
.view-switch button.on { background: var(--ink); color: var(--surface); }
.hint { position: absolute; left: 50%; top: 12px; transform: translateX(-50%); background: var(--ink); color: var(--surface); padding: 6px 12px; border-radius: 8px; font-size: 13px; pointer-events: none; opacity: 0; transition: opacity .2s; white-space: nowrap; max-width: 90%; overflow: hidden; text-overflow: ellipsis; }
.hint.show { opacity: .92; }
.panel { background: var(--surface); border-left: 1px solid var(--line); min-height: 0; display: flex; flex-direction: column; }
.panel-handle { display: none; }
.panel-body { overflow-y: auto; padding: 14px; flex: 1; }

/* ---------- controls ---------- */
.btn { display: inline-flex; align-items: center; justify-content: center; gap: 6px; min-height: var(--tap); padding: 0 12px; border-radius: 9px; border: 1px solid var(--line-2); background: var(--surface); cursor: pointer; font-weight: 600; white-space: nowrap; }
.btn:hover { border-color: var(--ink-3); }
.btn:active { transform: translateY(1px); }
.btn svg { width: 18px; height: 18px; flex: none; }
.btn.primary { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); }
.btn.primary:hover { filter: brightness(1.05); }
.btn.dark { background: var(--ink); color: var(--surface); border-color: var(--ink); }
.btn.ghost { background: transparent; border-color: transparent; color: inherit; }
.topbar .btn.ghost:hover { background: var(--chrome-2); }
.btn.danger { color: var(--bad); }
.btn.icon { padding: 0; width: var(--tap); }
.btn.sm { min-height: 32px; padding: 0 9px; font-size: 13px; }
.btn[disabled] { opacity: .45; pointer-events: none; }
.btn.on { background: var(--ink); color: var(--surface); border-color: var(--ink); }
.btn-row { display: flex; flex-wrap: wrap; gap: 6px; }
.seg { display: inline-flex; border: 1px solid var(--line-2); border-radius: 9px; overflow: hidden; }
.seg button { border: 0; background: var(--surface); padding: 0 10px; min-height: 34px; cursor: pointer; font-weight: 600; font-size: 13px; }
.seg button + button { border-left: 1px solid var(--line-2); }
.seg button.on { background: var(--ink); color: var(--surface); }

label.f { display: block; margin: 0 0 10px; }
label.f > span { display: block; font-size: 12px; font-weight: 600; color: var(--ink-2); margin-bottom: 4px; letter-spacing: .02em; text-transform: uppercase; }
input[type=text], input[type=number], input:not([type]), select, textarea { width: 100%; min-height: var(--tap); padding: 6px 10px; border-radius: 8px; border: 1px solid var(--line-2); background: var(--surface); }
input:focus, select:focus, textarea:focus { outline: 2px solid var(--accent); outline-offset: -1px; border-color: var(--accent); }
input.len { font-family: var(--font-num); }
input.bad { border-color: var(--bad); background: var(--bad-soft); }
.grid2 { display: grid; grid-template-columns: 1fr 1fr; gap: 0 10px; }
.grid3 { display: grid; grid-template-columns: 1fr 1fr 1fr; gap: 0 8px; }
.check { display: flex; align-items: center; gap: 8px; min-height: 36px; cursor: pointer; }
.check input { width: 20px; height: 20px; accent-color: var(--accent); }
.muted { color: var(--ink-3); }
.small { font-size: 13px; }
h2 { font-size: 20px; margin: 4px 0 12px; letter-spacing: .01em; }
h3 { font-size: 13px; text-transform: uppercase; letter-spacing: .08em; color: var(--ink-2); margin: 18px 0 8px; }
.panel h3:first-child { margin-top: 0; }

.card { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 14px; margin-bottom: 14px; box-shadow: var(--shadow); }
.card-head { display: flex; align-items: baseline; justify-content: space-between; gap: 10px; flex-wrap: wrap; margin-bottom: 8px; }
.card-head h2, .card-head h3 { margin: 0; }
.pagehead { display: flex; align-items: center; justify-content: space-between; gap: 10px; flex-wrap: wrap; margin-bottom: 14px; }
.pagehead h2 { margin: 0; }

table.t { width: 100%; border-collapse: collapse; font-size: 14px; }
table.t th { text-align: left; font-size: 11px; text-transform: uppercase; letter-spacing: .06em; color: var(--ink-3); font-weight: 700; padding: 6px 8px; border-bottom: 1px solid var(--line); }
table.t td { padding: 7px 8px; border-bottom: 1px solid var(--line); vertical-align: top; }
table.t td.n, table.t th.n { text-align: right; white-space: nowrap; }
table.t tr.total td { font-weight: 700; border-top: 2px solid var(--ink); border-bottom: 0; }
table.t input, table.t select { min-height: 34px; padding: 4px 8px; }
.tablewrap { overflow-x: auto; -webkit-overflow-scrolling: touch; }

.tag { display: inline-block; font-size: 11px; font-weight: 700; padding: 2px 7px; border-radius: 999px; background: var(--surface-2); color: var(--ink-2); letter-spacing: .03em; white-space: nowrap; }
.tag.good { background: var(--good-soft); color: var(--good); } .tag.fair { background: var(--surface-2); } .tag.high { background: var(--bad-soft); color: var(--bad); }
.tag.sup { background: var(--accent-soft); color: var(--accent); }
.m-only { display: none; }
.alert { padding: 10px 12px; border-radius: 9px; margin-bottom: 10px; font-size: 14px; border: 1px solid; }
.alert.bad { background: var(--bad-soft); border-color: var(--bad); color: var(--bad); }
.alert.warn { background: var(--warn-soft); border-color: var(--warn); color: var(--ink); }
.alert ul { margin: 4px 0 0 18px; padding: 0; }

/* panel specifics */
.sel-title { display: flex; align-items: center; gap: 8px; margin-bottom: 10px; }
.swatch { width: 18px; height: 18px; border-radius: 4px; border: 1px solid rgba(0,0,0,.25); flex: none; }
.partlist { list-style: none; margin: 0; padding: 0; }
.partlist li { display: flex; align-items: center; gap: 8px; padding: 7px 8px; border-radius: 8px; cursor: pointer; font-size: 14px; }
.partlist li:hover { background: var(--surface-2); }
.partlist li.on { background: var(--accent-soft); }
.partlist li .dim { margin-left: auto; color: var(--ink-3); font-family: var(--font-num); font-size: 12px; white-space: nowrap; }
.partlist .grp { font-weight: 700; font-size: 12px; text-transform: uppercase; letter-spacing: .06em; color: var(--ink-2); cursor: pointer; }
.stat { display: grid; grid-template-columns: 1fr auto; gap: 4px 12px; font-size: 14px; }
.stat b { font-family: var(--font-num); font-weight: 600; text-align: right; }

/* cut diagrams */
.bar-row { margin: 10px 0 14px; }
.bar-row .meta { display: flex; justify-content: space-between; font-size: 12px; color: var(--ink-2); margin-bottom: 4px; font-family: var(--font-num); }
svg.diagram { width: 100%; height: auto; display: block; }
svg.diagram text { font-family: var(--font-num); }
.sheets { display: grid; grid-template-columns: repeat(auto-fill, minmax(min(100%, 420px), 1fr)); gap: 14px; }
.mark { display: inline-grid; place-items: center; width: 24px; height: 24px; border-radius: 6px; background: var(--ink); color: var(--surface); font-weight: 700; font-size: 12px; font-family: var(--font-num); }

/* totals */
.totals { max-width: 420px; margin-left: auto; }
.totals .row { display: flex; justify-content: space-between; padding: 6px 0; border-bottom: 1px dashed var(--line); font-size: 15px; }
.totals .row b { font-family: var(--font-num); }
.totals .row.grand { border-bottom: 0; border-top: 2px solid var(--ink); font-size: 20px; font-weight: 700; padding-top: 10px; }
.bigprice { font-family: var(--font-num); font-size: 28px; font-weight: 700; }

/* compare bars */
.cmp-row { display: grid; grid-template-columns: minmax(140px, 1.2fr) 2fr 190px 70px; gap: 10px; align-items: center; padding: 6px 0; border-bottom: 1px solid var(--line); font-size: 14px; }
.cmp-bar { height: 12px; background: var(--surface-2); border-radius: 6px; overflow: hidden; }
.cmp-bar i { display: block; height: 100%; background: var(--ink-3); border-radius: 6px; }
.cmp-row.cur .cmp-bar i { background: var(--accent); }
.cmp-row.cur { font-weight: 700; }

/* templates */
.tpl-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(160px, 1fr)); gap: 10px; }
.tpl { border: 1px solid var(--line-2); background: var(--surface); border-radius: 10px; padding: 10px; cursor: pointer; text-align: left; display: flex; flex-direction: column; gap: 8px; }
.tpl:hover { border-color: var(--accent); }
.tpl svg { width: 100%; height: 84px; background: var(--canvas); border-radius: 6px; }
.tpl b { font-size: 14px; }

/* modal & toast */
.modal-wrap { position: fixed; inset: 0; background: rgba(15,18,16,.5); display: grid; place-items: center; z-index: 50; padding: 12px; }
.modal-wrap[hidden] { display: none; }
.modal { background: var(--surface); border-radius: 14px; width: min(720px, 100%); max-height: min(88vh, 900px); display: flex; flex-direction: column; box-shadow: 0 20px 60px rgba(0,0,0,.35); }
.modal-head { display: flex; align-items: center; justify-content: space-between; padding: 12px 14px 8px 18px; border-bottom: 1px solid var(--line); }
.modal-head h2 { margin: 0; font-size: 18px; }
.modal-body { padding: 16px 18px 18px; overflow-y: auto; }
.modal-foot { display: flex; gap: 8px; justify-content: flex-end; flex-wrap: wrap; margin-top: 14px; position: sticky; bottom: -18px; background: var(--surface); padding: 10px 0 4px; }
.toast { position: fixed; left: 50%; bottom: calc(24px + var(--safe-b)); transform: translateX(-50%); background: var(--ink); color: var(--surface); padding: 10px 16px; border-radius: 10px; z-index: 60; box-shadow: var(--shadow); max-width: 92vw; }
.menu { display: grid; gap: 6px; }
.menu .btn { justify-content: flex-start; min-height: 48px; }
.menu .btn small { color: var(--ink-3); font-weight: 400; margin-left: auto; }

/* ---------- phones & small tablets ---------- */
@media (max-width: 860px) {
  :root { --tap: 44px; }
  .tabs { display: none; }
  #app { grid-template-rows: auto 1fr auto; }
  .bottomnav { display: grid; grid-template-columns: repeat(5, 1fr); background: var(--chrome); padding-bottom: var(--safe-b); }
  .bottomnav button { background: none; border: 0; color: #aeb2aa; display: flex; flex-direction: column; align-items: center; gap: 2px; padding: 8px 0 7px; font-size: 11px; font-weight: 600; cursor: pointer; position: relative; }
  .bottomnav button svg { width: 22px; height: 22px; }
  .bottomnav button.on { color: #fff; }
  .bottomnav button.on::before { content: ""; position: absolute; top: 0; left: 25%; right: 25%; height: 3px; background: var(--accent); border-radius: 0 0 3px 3px; }
  .bottomnav .badge { position: absolute; top: 4px; right: 22%; background: var(--bad); color: #fff; border-radius: 8px; font-size: 10px; min-width: 16px; line-height: 16px; }
  .topbar { padding: 6px 8px; gap: 6px; padding-top: max(6px, env(safe-area-inset-top)); }
  .brand span, .btn .lbl { display: none; }
  .proj-name { font-size: 15px; }
  #view-design.on { grid-template-columns: 1fr; grid-template-rows: auto 1fr; }
  .panel { position: absolute; left: 0; right: 0; bottom: 0; border-left: 0; border-top: 1px solid var(--line); border-radius: 16px 16px 0 0; box-shadow: 0 -8px 30px rgba(0,0,0,.18); max-height: 62%; height: 62%; transform: translateY(calc(100% - 64px)); transition: transform .22s ease; z-index: 5; }
  .panel.open { transform: none; }
  .panel-handle { display: block; border: 0; background: none; width: 100%; height: 22px; cursor: pointer; flex: none; }
  .panel-handle span { display: block; width: 44px; height: 5px; border-radius: 3px; background: var(--line-2); margin: 8px auto 0; }
  .panel-body { padding: 4px 14px 24px; }
  .view-switch button { padding: 8px 10px; min-width: 42px; }
  .grid3 { grid-template-columns: 1fr 1fr 1fr; }
  .cmp-row { grid-template-columns: 1fr auto auto; }
  .cmp-row .cmp-bar { grid-column: 1 / -1; grid-row: 2; }
  table.buy th.hide-m, table.buy td.hide-m { display: none; }
  table.buy .m-only { display: block; margin-top: 3px; }
  table.t { font-size: 13.5px; }
  .cmp-row .cmp-bar { grid-column: 1 / -1; grid-row: 2; }
  .modal-wrap { place-items: end stretch; padding: 0; }
  .toast { bottom: calc(76px + var(--safe-b)); }
  .modal { width: 100%; max-height: 92vh; border-radius: 16px 16px 0 0; }
  .view.page { padding-bottom: 40px; }
}
@media (max-width: 420px) { .cost-pill { font-size: 13px; padding: 5px 8px; } h2 { font-size: 18px; } }

/* ---------- print (shop packet) ---------- */
@media print {
  .topbar, .tabs, .bottomnav, .toolbar, .noprint { display: none !important; }
  .view.page { position: static; overflow: visible; padding: 0; }
  .card { box-shadow: none; break-inside: avoid; }
}
