:root {
  --space-2: 8px;
  --space-3: 12px;
  --space-4: 16px;
  --tap: 48px;
  --tap-lg: 64px;
  --tap-min: 44px;
  --header-h: 52px;
  --dock-h: 64px;
  --z-content: 1;
  --z-header: 20;
  --z-dock: 30;
  --safe-t: env(safe-area-inset-top, 0px);
  --safe-b: env(safe-area-inset-bottom, 0px);
  --safe-top: var(--safe-t);
  --safe-bottom: var(--safe-b);
  --vvh: 100dvh;
  --kb: 0px;
  --bg: #1a1a17;
  --surface: #2a2a24;
  --ink: #f4f1ea;
  --muted: #b7b3a8;
  --talk: #e6c200;
  --miss: #ffb020;
  --line: #3a3a32;
  --radius: 12px;
}
* { box-sizing: border-box; }
html, body {
  margin: 0;
  height: 100%;
  min-height: 100dvh;
  min-height: 100svh;
  background: var(--bg);
  color: var(--ink);
  font: 18px/1.45 system-ui, sans-serif;
  overscroll-behavior-y: contain;
}
.app {
  min-height: 100dvh;
  height: 100dvh;
  display: flex;
  flex-direction: column;
  max-width: 520px;
  margin: 0 auto;
  overflow: hidden;
}
.app-header {
  display: flex;
  align-items: center;
  gap: 8px;
  min-height: var(--tap);
  padding: max(12px, var(--safe-t)) 16px 12px;
  background: #11110e;
  flex-shrink: 0;
  z-index: var(--z-header);
}
.app-header h1 {
  margin: 0;
  font-size: 1.15rem;
  flex: 1;
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.talkbar {
  flex-shrink: 0;
  background: #3a3510;
  color: var(--talk);
  padding: 12px 16px;
  border-bottom: 2px solid var(--talk);
  z-index: 6;
  max-height: 48dvh;
  overflow: auto;
}
.talkbar.listen { background: #4a3008; }
.talkbar.ask { background: #3a2a10; }
.talkbar p { margin: 0 0 6px; }
.talkbar label { color: var(--talk); margin-top: 10px; }
.talkbar textarea {
  background: #11110e;
  color: var(--ink);
  min-height: 88px;
  font-size: 18px;
}
.talkbar .primary { margin-top: 8px; }
.talk-kicker { font-weight: 750; font-size: 1.05rem; }
.talk-heard { color: var(--ink); font-size: 0.95rem; }
.talk-got { color: var(--ink); }
.talk-ask { color: #fff; font-weight: 750; background: #11110e; padding: 8px 10px; border-radius: 8px; }
.app-main {
  flex: 1;
  z-index: var(--z-content);
  overflow: auto;
  -webkit-overflow-scrolling: touch;
  padding: 16px 16px 24px;
  padding-bottom: calc(var(--dock-h) + var(--safe-b) + 24px);
}
.app-main input:focus, .app-main textarea:focus {
  scroll-margin-bottom: calc(var(--dock-h) + var(--safe-b) + 16px);
}
.dock {
  flex-shrink: 0;
  z-index: var(--z-dock);
  min-height: calc(var(--dock-h) + var(--safe-b));
  padding: 10px 16px calc(12px + var(--safe-b));
  background: #11110e;
  border-top: 1px solid var(--line);
}
[data-primary] {
  min-height: var(--tap-min);
  min-width: var(--tap-min);
  position: relative;
  z-index: var(--z-content);
}
.offline {
  font-size: 0.75rem;
  background: var(--miss);
  color: #111;
  padding: 4px 8px;
  border-radius: 999px;
  font-weight: 700;
  white-space: nowrap;
}
button, .chip, .file-btn {
  min-height: var(--tap);
  border: 0;
  border-radius: var(--radius);
  font: 700 16px/1.2 system-ui;
  touch-action: manipulation;
  -webkit-tap-highlight-color: transparent;
  color: var(--ink);
  background: var(--surface);
}
.primary, .talk, .file-btn {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 100%;
  min-height: var(--tap-lg);
  background: var(--talk);
  color: #111;
  margin-top: 8px;
}
.file-btn { margin: 8px 0 0; cursor: pointer; }
.file-btn input { display: none; }
.ghost { background: transparent; color: var(--ink); min-width: var(--tap); }
.ghost.full { width: 100%; margin-top: 8px; border: 1px solid var(--line); }
.back-btn {
  background: var(--surface);
  border: 2px solid var(--line);
  color: var(--ink);
  min-width: var(--tap);
  min-height: var(--tap);
  padding: 0 16px;
  font-weight: 800;
  flex-shrink: 0;
}
.back-btn:active {
  border-color: var(--talk);
  background: #3a3510;
  color: var(--talk);
}
.home-mark {
  background: var(--talk);
  color: #111;
  min-width: var(--tap);
  min-height: var(--tap);
  padding: 0 12px;
  font-weight: 800;
  flex-shrink: 0;
  letter-spacing: 0.02em;
}
.home-mark:active { filter: brightness(1.08); }
.field-cta {
  margin-top: 8px;
  margin-bottom: 12px;
  min-height: var(--tap-lg);
  width: 100%;
}
html.kb-open .dock {
  display: none;
}
html.kb-open .app-main {
  padding-bottom: 24px;
}
html.kb-open .plan-tools {
  padding-bottom: calc(10px + var(--kb));
}
.row { display: flex; gap: 8px; margin-top: 8px; }
.row > * { flex: 1; }
.row .primary { margin-top: 0; }
.chips { display: flex; gap: 8px; }
.chips.tight { margin-bottom: 8px; }
.chip {
  flex: 1;
  background: var(--surface);
  color: var(--ink);
  border: 2px solid var(--line);
}
.chip.on { border-color: var(--talk); background: #3a3510; color: var(--talk); }
.grow { flex: 1; min-width: 0; }
.ghost.sm { min-height: 44px; min-width: 44px; padding: 0 10px; font-size: 0.85rem; }
.file-btn { margin-top: 0; }
.row .file-btn { width: auto; flex: 1; display: flex; }
label.file-btn:not(.primary) {
  background: var(--surface);
  color: var(--ink);
  border: 1px solid var(--line);
}
.card {
  background: var(--surface);
  border-radius: var(--radius);
  padding: 12px;
  margin-bottom: 10px;
}
.card.tap { min-height: 56px; cursor: pointer; }
.card.missing { outline: 2px solid var(--miss); }
.card h2 { margin: 0 0 6px; font-size: 1rem; }
label { display: block; margin: 12px 0 4px; color: var(--muted); font-size: 0.9rem; }
label.check {
  display: flex;
  align-items: center;
  gap: 10px;
  min-height: var(--tap);
  color: var(--ink);
  margin: 4px 0 8px;
}
label.check input { width: auto; min-height: 24px; }
input, select, textarea {
  width: 100%;
  min-height: var(--tap);
  font-size: 18px;
  background: #11110e;
  color: var(--ink);
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 8px 10px;
  scroll-margin-bottom: 88px;
}
input.need { outline: 2px solid var(--miss); }
.pair { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }
.fine { color: var(--muted); font-size: 0.9rem; }
.lede { color: var(--muted); margin-top: 0; }
.thumbs { display: flex; gap: 10px; overflow-x: auto; margin: 8px 0; align-items: flex-start; }
.thumbs img { width: 96px; height: 96px; object-fit: cover; border-radius: 8px; flex-shrink: 0; }
.thumb-card {
  flex: 0 0 120px;
  display: flex;
  flex-direction: column;
  gap: 6px;
}
.thumb-card input { font-size: 0.85rem; min-height: 44px; }
.thumb-card button { min-height: 44px; font-size: 0.9rem; }
.banner {
  background: #3a3510;
  color: var(--talk);
  padding: 10px 12px;
  border-radius: 8px;
  font-weight: 650;
}
.range { font-size: 1.35rem; font-weight: 750; margin: 8px 0 16px; }
.range span { display: block; font-size: 0.85rem; font-weight: 500; color: var(--muted); }
.empty { color: var(--muted); padding: 24px 0; }
@media (prefers-reduced-motion: reduce) {
  * { animation: none !important; transition: none !important; }
}
.chips.modes {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 6px;
}
.chips.modes .chip { font-size: 14px; padding: 0 2px; }
.app.plan-on .app-main {
  padding: 0;
  overflow: hidden;
  display: flex;
  flex-direction: column;
  min-height: 0;
}
.plan-shell {
  flex: 1;
  min-height: 0;
  display: flex;
  flex-direction: column;
}
.plan-hud {
  display: grid;
  grid-template-columns: 0.9fr 1.5fr 0.9fr;
  gap: 8px;
  padding: 8px 12px;
  background: #11110e;
  border-bottom: 1px solid var(--line);
  flex-shrink: 0;
}
.plan-hud label { margin: 0 0 4px; }
.plan-hud input { min-height: 48px; }
.plan-ceil-row {
  display: flex;
  gap: 6px;
  align-items: stretch;
}
.plan-ceil-row .chips { flex: 1; min-width: 0; }
.plan-bar {
  display: flex;
  gap: 8px;
  padding: 8px 12px;
  flex-shrink: 0;
  background: #11110e;
  border-bottom: 1px solid var(--line);
}
.plan-bar button {
  min-height: 48px;
  min-width: 44px;
  padding: 0 12px;
  flex: 1;
}
.plan-bar #plan-add-rect.on {
  background: var(--talk);
  color: #111;
}
.plan-bar [hidden] { display: none !important; }
.plan-tools .primary[data-primary] {
  margin-top: 8px;
}
.plan-tools .primary:disabled {
  opacity: 0.45;
}
.plan-stats {
  display: flex;
  flex-direction: column;
  justify-content: flex-end;
  color: var(--talk);
  font-weight: 750;
  font-size: 0.95rem;
  padding-bottom: 6px;
}
.plan-stats span { color: var(--muted); font-weight: 500; font-size: 0.8rem; }
.plan-stage {
  flex: 1;
  min-height: 0;
  position: relative;
  background: #12140f;
  touch-action: none;
  overflow: hidden;
  display: flex;
  flex-direction: column;
  -webkit-user-select: none;
  user-select: none;
  -webkit-touch-callout: none;
}
.plan-stage.move-on {
  outline: 3px solid var(--talk);
  outline-offset: -3px;
}
.plan-move {
  position: absolute;
  left: 10px;
  right: 68px;
  top: 10px;
  display: flex;
  align-items: center;
  gap: 8px;
  min-height: 48px;
  padding: 6px 8px 6px 12px;
  background: var(--talk);
  color: #111;
  font-weight: 800;
  border-radius: 10px;
  z-index: 4;
}
.plan-move[hidden] { display: none; }
.plan-move button {
  margin-left: auto;
  background: #11110e;
  color: var(--talk);
  min-height: 44px;
  min-width: 72px;
  padding: 0 14px;
}
.plan-stage svg {
  flex: 1;
  min-height: 0;
  width: 100%;
  height: auto;
  display: block;
}
.plan-hint {
  position: static;
  flex-shrink: 0;
  margin: 8px 12px 10px;
  padding: 8px 10px;
  background: #11110ecc;
  color: var(--talk);
  font-weight: 650;
  border-radius: 8px;
  pointer-events: none;
}
.plan-zoom {
  position: absolute;
  right: 10px;
  top: 10px;
  display: flex;
  flex-direction: column;
  gap: 6px;
}
.plan-zoom button {
  width: 48px;
  min-height: 48px;
  background: #11110ecc;
  border: 1px solid var(--line);
  color: var(--ink);
  font-size: 1.25rem;
}
.plan-tools {
  flex-shrink: 0;
  padding: 8px 12px 10px;
  background: #11110e;
  border-top: 1px solid var(--line);
}
.plan-tools .row { margin-top: 0; }
.plan-tools .chip { min-height: 48px; }
.plan-wall {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
  align-items: end;
  margin-bottom: 8px;
}
.plan-wall input { min-height: 48px; font-size: 18px; }
.home-banner {
  background: linear-gradient(#3a3510, #2a2610);
  border: 2px solid var(--talk);
  border-radius: var(--radius);
  padding: 28px 16px 24px;
  margin: 8px 0 20px;
  text-align: center;
}
.home-banner .brand {
  margin: 0;
  font-size: 2rem;
  font-weight: 800;
  color: var(--talk);
  letter-spacing: 0.04em;
}
.home-banner .tag {
  margin: 8px 0 0;
  color: var(--ink);
  font-size: 1.05rem;
}
.home-btn {
  width: 100%;
  min-height: var(--tap-lg);
  margin-top: 10px;
  background: var(--surface);
  border: 1px solid var(--line);
}
.ghost-home { background: transparent; }
.settings-h { font-size: 1.05rem; margin: 24px 0 8px; }
.chips.wrap { flex-wrap: wrap; }
.line-card input { margin-bottom: 8px; }
.quote-doc .brand-sm { color: var(--talk); font-weight: 800; margin: 0; }
.quote-head {
  display: flex;
  align-items: center;
  gap: 12px;
  margin-bottom: 8px;
}
.quote-logo-slot, .logo-preview {
  flex-shrink: 0;
}
.quote-logo {
  display: block;
  width: 64px;
  height: 64px;
  object-fit: contain;
  background: #fff;
  border-radius: 8px;
}
.logo-preview { margin: 8px 0; }
.quote-terms {
  margin-top: 18px;
  padding-top: 12px;
  border-top: 1px solid var(--line);
}
.quote-terms p {
  white-space: pre-wrap;
  font-size: 0.9rem;
  margin: 6px 0 0;
}
.quote-doc h3 { font-size: 1rem; margin: 0 0 6px; }
.quote-room {
  display: grid;
  grid-template-columns: 1fr minmax(108px, 38%);
  gap: 10px 12px;
  align-items: start;
  margin: 14px 0;
  padding-bottom: 12px;
  border-bottom: 1px solid var(--line);
  break-inside: avoid;
}
.quote-room-copy p { margin: 4px 0; font-size: 0.92rem; }
.quote-room-plan .diagram-wrap {
  margin: 0;
  min-height: 0;
  padding: 4px;
}
.quote-room-plan .room-diagram {
  min-height: 108px;
  aspect-ratio: 4 / 3;
}
.diagram-wrap {
  background: #12140f;
  border-radius: 10px;
  padding: 8px;
  margin: 8px 0;
  min-height: 220px;
}
.room-diagram {
  display: block;
  width: 100%;
  height: auto;
  min-height: 220px;
  aspect-ratio: 4 / 3;
  touch-action: none;
}
.nook-hit { cursor: grab; }
.nook-hit.on { cursor: grab; }
#nook-rotate {
  width: 100%;
  min-height: var(--tap-lg);
  margin-top: 8px;
}
.calc-list {
  list-style: none;
  margin: 0;
  padding: 0;
}
.calc-list li {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  padding: 8px 0;
  border-bottom: 1px solid var(--line);
  font-size: 0.95rem;
}
.calc-list li span {
  color: var(--muted);
  flex-shrink: 0;
}
.est-h {
  font-size: 0.9rem;
  color: var(--muted);
  margin: 14px 0 4px;
}
.est-room .line-card { margin-top: 10px; }
.est-room .line-card input { margin-bottom: 6px; }
@media print {
  body * { visibility: hidden; }
  #quote-doc, #quote-doc * { visibility: visible; }
  #quote-doc {
    position: absolute;
    left: 0;
    top: 0;
    width: 100%;
    background: #fff;
    color: #111;
  }
  #quote-doc .diagram-wrap { background: #eee; }
  #quote-doc .room-diagram text { fill: #111 !important; }
  #quote-doc .quote-logo { background: #fff; }
  .app-header, .dock, .talkbar { display: none !important; }
}
@media (min-width: 720px) {
  .app { max-width: 720px; }
  .app.plan-on { max-width: 900px; }
}
details.ornate { margin: 12px 0; border: 2px solid var(--line); border-radius: var(--radius); padding: 0 12px 8px; }
details.ornate > summary {
  min-height: var(--tap);
  display: flex;
  align-items: center;
  font-weight: 700;
  cursor: pointer;
  list-style: none;
}
details.ornate > summary::before { content: "+"; margin-right: 10px; color: var(--talk); font-size: 1.3rem; }
details.ornate[open] > summary::before { content: "−"; }
details.ornate > summary::-webkit-details-marker { display: none; }
