:root {
  --bg: #f4f6f9; --panel: #ffffff; --ink: #121826; --muted: #5b6475; --line: #e3e7ee;
  --accent: #2563eb; --accent-soft: #e8efff; --bar: #0f172a; --bar-ink: #e6ebf5; --stage: #dde2ea;
  --danger: #dc2626;
}
@media (prefers-color-scheme: dark) {
  :root { --bg: #0b1020; --panel: #121a2e; --ink: #e6ebf5; --muted: #95a0b8; --line: #23304d;
          --accent: #4f8bff; --accent-soft: #1a2747; --stage: #070b16; }
}
* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; background: var(--bg); color: var(--ink);
  font: 14px/1.4 Inter, system-ui, -apple-system, "Segoe UI", Roboto, sans-serif; }
body { display: grid; grid-template-rows: auto 1fr auto; }
button, select, input { font: inherit; }

.bar { display: flex; align-items: center; gap: 14px; padding: 8px 14px; background: var(--bar); color: var(--bar-ink); flex-wrap: wrap; }
.brand { display: flex; align-items: center; gap: 8px; font-weight: 700; letter-spacing: .02em; margin-right: 6px; }
.mark { display: inline-grid; place-items: center; width: 26px; height: 26px; border-radius: 7px; background: linear-gradient(135deg, #3b82f6, #06b6d4); color: #fff; font-size: 14px; }
.field { display: flex; align-items: center; gap: 6px; font-size: 12px; color: #9fb0cf; }
.field select { background: #1b2540; color: var(--bar-ink); border: 1px solid #2c3a5e; border-radius: 6px; padding: 5px 8px; max-width: 240px; }
.tools { display: flex; gap: 2px; background: #1b2540; border-radius: 8px; padding: 3px; }
.tools button { background: transparent; color: #c8d3ea; border: 0; padding: 6px 12px; border-radius: 6px; cursor: pointer; }
.tools button:hover { background: #26335a; }
.tools button[aria-pressed="true"] { background: var(--accent); color: #fff; }
.btn { background: var(--accent); color: #fff; border: 0; border-radius: 6px; padding: 6px 12px; cursor: pointer; }
.btn.ghost { background: transparent; border: 1px solid #2c3a5e; color: var(--bar-ink); }
.btn.small { padding: 4px 10px; font-size: 12px; }

main { display: grid; grid-template-columns: 230px 1fr 300px; min-height: 0; }
aside { background: var(--panel); border-right: 1px solid var(--line); overflow: auto; min-height: 0; }
aside.takeoff { border-right: 0; border-left: 1px solid var(--line); display: flex; flex-direction: column; }
aside h2 { font-size: 12px; text-transform: uppercase; letter-spacing: .08em; color: var(--muted); margin: 14px 14px 8px; }
#sheetlist { list-style: none; margin: 0; padding: 0 6px 12px; }
#sheetlist li { padding: 7px 8px; border-radius: 6px; cursor: pointer; display: grid; grid-template-columns: 64px 1fr; gap: 6px; }
#sheetlist li:hover { background: var(--accent-soft); }
#sheetlist li.on { background: var(--accent); color: #fff; }
#sheetlist .num { font-weight: 600; font-variant-numeric: tabular-nums; }
#sheetlist .ttl { font-size: 12px; color: var(--muted); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
#sheetlist li.on .ttl { color: #dbe6ff; }

.stage { position: relative; overflow: hidden; background: var(--stage); cursor: crosshair; outline: none; }
.stage.pan { cursor: grab; } .stage.panning { cursor: grabbing; }
#world { position: absolute; left: 0; top: 0; transform-origin: 0 0; box-shadow: 0 6px 30px rgba(0,0,0,.25); background: #fff; }
#sheet { display: block; user-select: none; }
#overlay { position: absolute; left: 0; top: 0; overflow: visible; }
.busy { position: absolute; right: 14px; top: 14px; background: var(--bar); color: #fff; padding: 6px 12px; border-radius: 6px; font-size: 12px; }

.takeoff-head { display: flex; align-items: center; justify-content: space-between; padding-right: 12px; }
#items { list-style: none; margin: 0; padding: 0 8px; }
#items li { border: 1px solid var(--line); border-radius: 8px; padding: 8px 10px; margin-bottom: 8px; display: grid; grid-template-columns: 10px 1fr auto; gap: 4px 8px; align-items: center; }
#items li.sel { border-color: var(--accent); box-shadow: 0 0 0 2px var(--accent-soft); }
#items .sw { width: 10px; height: 10px; border-radius: 3px; }
#items .name { border: 0; background: transparent; color: var(--ink); font-weight: 600; width: 100%; padding: 0; }
#items .qty { font-variant-numeric: tabular-nums; font-weight: 700; text-align: right; }
#items .meta { grid-column: 2 / 4; font-size: 12px; color: var(--muted); display: flex; justify-content: space-between; }
#items .del { border: 0; background: none; color: var(--muted); cursor: pointer; padding: 0 2px; }
#items .del:hover { color: var(--danger); }
.empty { color: var(--muted); font-size: 13px; padding: 0 14px; }
.status { display: flex; justify-content: space-between; padding: 5px 14px; font-size: 12px; color: var(--muted); background: var(--panel); border-top: 1px solid var(--line); }

@media (max-width: 900px) { main { grid-template-columns: 1fr; grid-template-rows: auto 1fr auto; }
  aside.sheets, aside.takeoff { max-height: 160px; } }
.calib { position: absolute; left: 50%; top: 14px; transform: translateX(-50%); background: var(--panel); color: var(--ink);
  border: 1px solid var(--line); border-radius: 10px; padding: 10px 12px; display: flex; gap: 8px; align-items: end; box-shadow: 0 8px 30px rgba(0,0,0,.2); }
.calib[hidden] { display: none; }
.calib label { display: grid; gap: 4px; font-size: 12px; color: var(--muted); }
.calib input { border: 1px solid var(--line); border-radius: 6px; padding: 6px 8px; width: 170px; background: var(--bg); color: var(--ink); }
.btn.ghostdark { background: transparent; color: var(--muted); border: 1px solid var(--line); }
#suggest { list-style: none; margin: 0; padding: 0 8px 4px; }
#suggest li { display: grid; grid-template-columns: 44px 1fr auto; gap: 8px; align-items: center; padding: 6px; border-radius: 8px; border: 1px solid transparent; }
#suggest li:hover { border-color: var(--line); background: var(--accent-soft); }
#suggest img { width: 44px; height: 44px; object-fit: contain; background: #fff; border: 1px solid var(--line); border-radius: 6px; image-rendering: auto; }
#suggest .txtmark { width: 44px; height: 44px; display: grid; place-items: center; font-weight: 700; font-size: 18px; border: 1px solid var(--line); border-radius: 6px; background: #fff; color: #111; }
#suggest .sname { font-weight: 600; }
#suggest .sinfo { font-size: 12px; color: var(--muted); }
#suggest .add[disabled] { background: var(--line); color: var(--muted); cursor: default; }
.savestate { margin-left: auto; margin-right: 8px; font-size: 11px; color: var(--muted); }
.savestate.warn { color: var(--danger); }
#items .price { grid-column: 2 / 4; display: flex; gap: 8px; align-items: center; font-size: 12px; }
#items .psel { flex: 1; min-width: 0; font-size: 12px; padding: 3px 4px; border: 1px solid var(--line); border-radius: 5px; background: var(--bg); color: var(--ink); }
#items .ptotal { font-variant-numeric: tabular-nums; font-weight: 600; white-space: nowrap; }
#items .ptotal.none { color: var(--muted); font-weight: 400; }
.estimate { margin: 4px 8px 16px; padding: 10px 12px; border: 1px solid var(--line); border-radius: 8px; background: var(--bg); font-size: 13px; display: grid; grid-template-columns: 1fr auto; gap: 3px 12px; }
.estimate .t { font-weight: 700; font-size: 15px; border-top: 1px solid var(--line); padding-top: 4px; }
.estimate .warn { grid-column: 1 / 3; color: #b45309; font-size: 12px; }
.estimate span:nth-child(even) { text-align: right; font-variant-numeric: tabular-nums; }
.pb { border: 0; border-radius: 12px; padding: 0; width: min(1000px, 94vw); max-height: 88vh; background: var(--panel); color: var(--ink); box-shadow: 0 20px 60px rgba(0,0,0,.35); }
.pb::backdrop { background: rgba(8,12,24,.55); }
.pb-inner { display: flex; flex-direction: column; max-height: 88vh; }
.pb-head { display: flex; align-items: center; gap: 10px; padding: 12px 16px; border-bottom: 1px solid var(--line); }
.pb-head h2 { margin: 0; font-size: 16px; }
.pb-help { margin: 10px 16px 0; color: var(--muted); font-size: 12px; }
.pb-settings { display: flex; gap: 16px; padding: 10px 16px; flex-wrap: wrap; }
.pb-settings label { display: grid; gap: 4px; font-size: 12px; color: var(--muted); }
.pb input, .pb select { border: 1px solid var(--line); border-radius: 5px; padding: 5px 6px; background: var(--bg); color: var(--ink); font-size: 13px; width: 100%; }
.pb-settings input, .pb-table input.y { background: #fef9c3; color: #111; }
.pb-tablewrap { overflow: auto; padding: 0 16px; }
.pb-table { width: 100%; border-collapse: collapse; font-size: 13px; }
.pb-table th { text-align: left; font-size: 11px; text-transform: uppercase; letter-spacing: .05em; color: var(--muted); padding: 6px 4px; position: sticky; top: 0; background: var(--panel); }
.pb-table td { padding: 3px 4px; }
.pb-table td:nth-child(1) { width: 32%; } .pb-table td:nth-child(2) { width: 70px; } .pb-table td:nth-child(3), .pb-table td:nth-child(4), .pb-table td:nth-child(5) { width: 100px; }
.pb-foot { display: flex; gap: 8px; justify-content: flex-end; padding: 12px 16px; border-top: 1px solid var(--line); }
.pb-del { border: 0; background: none; color: var(--muted); cursor: pointer; }
.pb-del:hover { color: var(--danger); }
.pb-table { min-width: 820px; }
.pb-table td:nth-child(1) input { min-width: 240px; }
#items .chk { grid-column: 2 / 4; font-size: 12px; display: flex; align-items: center; gap: 6px; color: var(--muted); cursor: pointer; }
#items li.ok { border-color: #16a34a; }
#items li.ok .chk { color: #16a34a; font-weight: 600; }
.userbox { margin-left: auto; display: flex; gap: 6px; }
.userbox a { text-decoration: none; }
/* plan state in the viewer */
.plantag { font-size: 12px; font-weight: 600; padding: 4px 10px; border-radius: 999px; background: rgba(219,234,254,.95); color: #1e40af; text-decoration: none; white-space: nowrap; align-self: center; }
.plantag.locked { background: #fee2e2; color: #991b1b; }
.tools button.locked, button.locked { opacity: .45; }

/* Do It Yourself plan picker (plan.js), on the Projects page and in the viewer dialog */
.vqplan { display: grid; gap: 10px; color: var(--ink); }
.vqplan-head { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; }
.vqplan .pill { display: inline-block; padding: 2px 8px; border-radius: 999px; font-size: 12px; font-weight: 600; white-space: nowrap; }
.vqplan .pill.trial { background: #dbeafe; color: #1e40af; }
.vqplan .pill.active, .vqplan .pill.staff { background: #dcfce7; color: #166534; }
.vqplan .pill.ending, .vqplan .pill.past_due { background: #fef3c7; color: #92400e; }
.vqplan .pill.expired, .vqplan .pill.none { background: #fee2e2; color: #991b1b; }
.vqplan .msg { font-size: 13px; color: var(--muted); margin: 0; }
.vqplan-msg:empty { display: none; }
.vqplan-help { margin: 0; color: var(--muted); font-size: 13px; }
.vqplan-now { margin: 0; font-weight: 600; }
.vqplan fieldset { border: 1px solid var(--line); border-radius: 10px; padding: 8px 12px; margin: 0; }
.vqplan legend { font-size: 12px; color: var(--muted); padding: 0 4px; }
.tradepick { display: flex; flex-wrap: wrap; gap: 6px 14px; }
.tradepick label { display: flex; align-items: center; gap: 6px; font-size: 13px; }
.vqplan-row { display: flex; align-items: center; gap: 12px; flex-wrap: wrap; }
.vqplan-row .spacer { flex: 1; }
.vqplan .seg { display: flex; align-items: center; gap: 6px; font-size: 13px; }
.vqplan .quote { margin: 0; font-size: 15px; font-weight: 700; }
.vqplan .quote small { font-weight: 400; color: var(--muted); }
.vqplan input[type=checkbox], .vqplan input[type=radio] { width: auto; }
.plandlg { width: min(640px, 94vw); }
.plandlg .vqplan { padding: 14px 16px 16px; }
.plandlg .why { margin: 12px 16px 0; padding: 8px 12px; border-radius: 8px; background: #fee2e2; color: #991b1b; font-size: 13px; }
.plandlg .why:empty { display: none; }
button.plantag { border: 0; cursor: pointer; font-family: inherit; }
.pb-head .spacer { flex: 1; }
.vqplan .btn:disabled { opacity: .45; cursor: default; }
