:root {
  --bg: #f3f5f8; --card: #ffffff; --ink: #18202a; --muted: #5b6673; --line: #dde3ea; --accent: #1f6feb; --accent-ink: #ffffff;
  --listing: #0f7b4f; --allowance: #9a6200; --labor: #5b4bc4; --warn: #8a5300; --error: #b42318; --radius: 12px;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  color: var(--ink); background: var(--bg);
}
* { box-sizing: border-box; }
[hidden] { display: none !important; }
body { margin: 0; background: var(--bg); line-height: 1.45; }
h1 { font-size: 1.35rem; margin: 0; }
h2 { font-size: 1.05rem; margin: 0 0 .6rem; }
h3 { font-size: .98rem; margin: 1rem 0 .4rem; }
h4 { font-size: .85rem; margin: .8rem 0 .25rem; text-transform: uppercase; letter-spacing: .03em; color: var(--muted); }
.small { font-size: .85rem; }
.muted { color: var(--muted); }
.top { display: flex; flex-wrap: wrap; gap: .75rem 1.5rem; align-items: center; justify-content: space-between; padding: 1rem clamp(16px, 3vw, 32px); background: #0f2338; color: #fff; }
.top .sub { margin: .2rem 0 0; color: #b9c7d6; font-size: .9rem; }
.privacy { margin: 0; padding: .55rem clamp(16px, 3vw, 32px); background: #f0f2f4; border-bottom: 1px solid var(--line); font-size: .84rem; color: #2c333b; }
.privacy button.link { font-size: inherit; padding: 0; text-decoration: underline; }
.badge { margin: 0; padding: .35rem .7rem; border-radius: 999px; background: #ffe6b3; color: #4a3200; font-size: .8rem; font-weight: 600; }
.layout { display: grid; gap: 16px; padding: 16px clamp(16px, 3vw, 32px); grid-template-columns: minmax(0, 2fr) minmax(280px, 1fr);
  grid-template-areas: "viewer details" "summary summary" "proposal proposal" "inputs estimate" "method method"; }
.proposal-card { grid-area: proposal; }
.viewer-card { grid-area: viewer; } .details-card { grid-area: details; } .summary-card { grid-area: summary; }
.inputs-card { grid-area: inputs; } .estimate-card { grid-area: estimate; min-width: 0; } .method-card { grid-area: method; }
@media (min-width: 1100px) { .layout { grid-template-columns: minmax(0, 2fr) minmax(320px, 1fr); grid-template-areas: "viewer details" "summary summary" "proposal proposal" "estimate inputs" "method method"; } }
.card { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); padding: 16px; box-shadow: 0 1px 2px rgba(16, 24, 40, .04); min-width: 0; }
.card-head { display: flex; flex-wrap: wrap; gap: .5rem; align-items: center; justify-content: space-between; margin-bottom: .6rem; }
.card-head h2 { margin: 0; }
.toolbar { display: flex; flex-wrap: wrap; gap: .4rem; }
button { font: inherit; font-size: .88rem; border: 1px solid var(--line); background: #fff; color: var(--ink); border-radius: 8px; padding: .45rem .75rem; cursor: pointer; min-height: 36px; }
button:hover { border-color: #b8c3cf; } button:focus-visible, input:focus-visible, [tabindex]:focus-visible { outline: 3px solid #9cc2ff; outline-offset: 2px; }
button:disabled { opacity: .5; cursor: not-allowed; }
#btn-csv, #btn-print { background: var(--accent); color: var(--accent-ink); border-color: var(--accent); }
button.primary { background: #161616; color: #fff; border-color: #161616; }
#proposal-form textarea { font: inherit; font-size: .9rem; border: 1px solid var(--line); border-radius: 8px; padding: .4rem .5rem; width: 100%; resize: vertical; }
#proposal-form input[type=text], #proposal-form input[type=date], #proposal-form input[type=number] { font: inherit; font-size: .9rem; border: 1px solid var(--line); border-radius: 8px; padding: .4rem .5rem; width: 100%; min-height: 34px; }
.optional-list { display: grid; gap: .5rem; padding: .4rem 0; } .optional-row { display: grid; grid-template-columns: 1fr 180px auto; gap: .5rem; align-items: start; }
@media (max-width: 600px) { .optional-row { grid-template-columns: 1fr; } }
#proposal-message:empty { display: none; }
body.previewing { overflow: hidden; }
.preview { position: fixed; inset: 0; z-index: 50; background: #2a2a2a; display: flex; flex-direction: column; }
.preview-bar { display: flex; flex-wrap: wrap; align-items: center; gap: .5rem; padding: .6rem 1rem; background: #111; color: #fff; }
.preview-bar button { min-height: 32px; } .preview-bar .spacer { flex: 1; }
.preview-info { font-size: .78rem; color: #c8c8c8; }
.seg { display: inline-flex; border: 1px solid #555; border-radius: 8px; overflow: hidden; } .seg button { border: 0; border-radius: 0; background: #222; color: #ddd; }
.seg button[aria-pressed=true] { background: #fff; color: #111; font-weight: 600; }
.preview-stale { margin: 0; padding: .45rem 1rem; background: #fff3cd; color: #5c4300; font-size: .85rem; }
#preview-frame { flex: 1; width: 100%; border: 0; background: #d9d9d9; }
button.link { border: 0; background: none; color: var(--accent); padding: .2rem; min-height: 0; }
.viewer { position: relative; height: clamp(320px, 52vh, 560px); border-radius: 10px; overflow: hidden; background: #eef2f6; touch-action: none; }
.viewer canvas { display: block; cursor: grab; } .viewer canvas:active { cursor: grabbing; }
.layers { display: flex; flex-wrap: wrap; gap: .35rem .9rem; border: 0; padding: .6rem 0 0; margin: 0; }
.layers legend { font-weight: 600; font-size: .85rem; padding: 0; margin-bottom: .2rem; }
.layer { font-size: .85rem; display: inline-flex; gap: .35rem; align-items: center; }
.fallback { border: 1px dashed #c3ccd6; border-radius: 10px; padding: 12px; background: #fafbfc; }
.fallback-note { margin: 0 0 .6rem; font-size: .9rem; }
.plan svg { width: 100%; height: auto; display: block; }
.p-perimeter { fill: #2a9d8f; } .p-field { fill: #f4f6f8; stroke: #8fb3cf; } .p-coping { fill: #8a3b2f; } .p-gutter { fill: #2f5d8a; } .p-downspout { fill: #163a5c; }
.plan [data-component] { cursor: pointer; } .plan .selected { stroke: #ff7a00; stroke-width: 3; } .p-label { font-size: 11px; fill: #5b6673; }
.summary { display: grid; gap: 12px; grid-template-columns: repeat(auto-fit, minmax(170px, 1fr)); }
.stat { border: 1px solid var(--line); border-radius: 10px; padding: .7rem .8rem; display: flex; flex-direction: column; gap: .15rem; }
.stat-label { font-size: .78rem; color: var(--muted); text-transform: uppercase; letter-spacing: .03em; }
.stat strong { font-size: 1.3rem; } .stat-sub { font-size: .78rem; color: var(--muted); }
.warn { color: var(--warn); font-size: .88rem; margin: .5rem 0 0; } .error { color: var(--error); font-size: .88rem; margin: .5rem 0 0; font-weight: 600; }
.group { border-top: 1px solid var(--line); padding: .45rem 0; }
.group summary { cursor: pointer; font-weight: 600; font-size: .92rem; padding: .25rem 0; }
.fields { display: grid; grid-template-columns: repeat(auto-fill, minmax(210px, 1fr)); gap: .45rem .9rem; padding: .4rem 0 .2rem; }
.field { display: flex; flex-direction: column; gap: .2rem; font-size: .82rem; }
.field.check { flex-direction: row-reverse; justify-content: flex-end; align-items: center; gap: .45rem; }
.field-label { color: var(--muted); display: flex; gap: .35rem; align-items: center; flex-wrap: wrap; }
.field-input { display: flex; align-items: center; border: 1px solid var(--line); border-radius: 8px; overflow: hidden; background: #fff; }
.field-input input { border: 0; padding: .4rem .5rem; font: inherit; font-size: .9rem; width: 100%; min-width: 0; min-height: 34px; background: transparent; }
.unit { padding: 0 .55rem; color: var(--muted); font-size: .78rem; background: #f6f8fa; align-self: stretch; display: flex; align-items: center; border-left: 1px solid var(--line); white-space: nowrap; }
.tag { display: inline-block; font-size: .7rem; font-weight: 600; border-radius: 999px; padding: .05rem .45rem; border: 1px solid currentColor; }
.tag.listing { color: var(--listing); } .tag.allowance { color: var(--allowance); } .tag.labor { color: var(--labor); }
.table-wrap { overflow-x: auto; -webkit-overflow-scrolling: touch; }
table.estimate { border-collapse: collapse; width: 100%; font-size: .84rem; }
.estimate th, .estimate td { border-bottom: 1px solid var(--line); padding: .38rem .45rem; text-align: left; vertical-align: top; }
.estimate thead th { position: sticky; top: 0; background: #f6f8fa; font-size: .76rem; text-transform: uppercase; letter-spacing: .03em; color: var(--muted); white-space: nowrap; }
.estimate .num { text-align: right; white-space: nowrap; font-variant-numeric: tabular-nums; }
.estimate tbody tr[data-line] { cursor: pointer; } .estimate tbody tr[data-line]:hover { background: #f5f9ff; }
.estimate tr.active { background: #fff3e6; } .estimate tr.group-row th { background: #f0f3f7; font-size: .82rem; }
.estimate tfoot th { text-align: right; font-weight: 500; } .estimate tfoot tr.total th, .estimate tfoot tr.total td { font-weight: 700; border-top: 2px solid #c8d0d9; }
#details ul, .method-card ul, .method-card ol { padding-left: 1.2rem; margin: .2rem 0; } #details li, .method-card li { margin: .15rem 0; }
.foot { padding: 0 clamp(16px, 3vw, 32px) 24px; }
@media (max-width: 860px) {
  .layout { grid-template-columns: minmax(0, 1fr); grid-template-areas: "viewer" "details" "summary" "proposal" "estimate" "inputs" "method"; }
  .preview-bar { gap: .35rem; } .preview-info { order: 9; flex-basis: 100%; }
  .viewer { height: 56vh; min-height: 300px; }
  .stat strong { font-size: 1.15rem; }
  .top h1 { font-size: 1.15rem; }
  #estimate { min-width: 780px; }
  #estimate td:nth-child(2) { min-width: 230px; }
  #estimate tfoot th { text-align: left; }
}
@media print {
  body { background: #fff; }
  .top { background: #fff; color: #000; border-bottom: 2px solid #000; } .top .sub { color: #333; }
  .viewer-card, .inputs-card, .details-card, .proposal-card, .preview, .privacy, .toolbar, button, .foot { display: none !important; }
  .layout { display: block; padding: 0; }
  .card { border: 0; box-shadow: none; padding: 8px 0; break-inside: avoid-page; }
  .estimate-card, .method-card { break-inside: auto; }
  .table-wrap { overflow: visible; } .estimate thead th { position: static; }
  a { color: #000; text-decoration: none; }
  .estimate tr.active { background: none; }
}
