/* Blueprint Reader — mobile-first, glove-friendly, sunlight-readable */
:root {
  --bg: #f4f6f8;
  --card: #ffffff;
  --text: #111827;
  --muted: #4b5563;
  --primary: #1a56db;
  --primary-dark: #1443ac;
  --danger: #b91c1c;
  --border: #d1d5db;
  --radius: 14px;
  --tap: 56px; /* minimum touch target */
  --wall: #2563eb;
  --window: #16a34a;
  --door: #ea580c;
  --opening: #9333ea;
  --dim: #0d9488;
}
* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { margin: 0; padding: 0; }
body {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  background: var(--bg);
  color: var(--text);
  font-size: 17px;
  line-height: 1.45;
  overscroll-behavior-y: none;
}
#appHeader {
  position: sticky; top: 0; z-index: 50;
  background: var(--primary); color: #fff;
  padding: 12px 16px;
  display: flex; align-items: center; justify-content: space-between;
  box-shadow: 0 2px 6px rgba(0,0,0,.25);
}
.brand { display: flex; align-items: center; gap: 10px; font-weight: 800; font-size: 19px; }
.brand-icon { font-size: 24px; }
.pips { display: flex; gap: 6px; }
.pips span { width: 10px; height: 10px; border-radius: 50%; background: rgba(255,255,255,.35); }
.pips span.on { background: #fff; }

main { padding: 16px 14px 40px; max-width: 760px; margin: 0 auto; }
.view { display: none; }
.view.active { display: block; animation: fadein .18s ease; }
@keyframes fadein { from { opacity: 0; } to { opacity: 1; } }

h1 { font-size: 27px; margin: 6px 0 8px; }
h2.view-title { font-size: 22px; margin: 4px 0 10px; }
.lede { color: var(--muted); font-size: 18px; margin: 0 0 18px; }
.hint { color: var(--muted); font-size: 15.5px; }
.hint.small { font-size: 13.5px; }
.hint.center, .center { text-align: center; }

.card {
  background: var(--card); border: 1px solid var(--border);
  border-radius: var(--radius); padding: 14px 16px; margin-top: 16px;
  box-shadow: 0 1px 3px rgba(0,0,0,.08);
}
.card h2 { font-size: 18px; margin: 0 0 8px; }
.card ul { margin: 0; padding-left: 20px; }
.card li { margin: 6px 0; }
.v2note { font-size: 14.5px; color: var(--muted); border-left: 5px solid var(--primary); }

.btn-col { display: flex; flex-direction: column; gap: 14px; margin-top: 8px; }
.btn-row { display: flex; gap: 10px; margin-top: 14px; }
.btn-row.wrap { flex-wrap: wrap; }
.btn {
  min-height: var(--tap);
  border: none; border-radius: var(--radius);
  font-size: 18px; font-weight: 700;
  padding: 14px 20px; cursor: pointer;
  display: inline-flex; align-items: center; justify-content: center; gap: 10px;
  flex: 1;
}
.btn:active { transform: scale(.98); }
.btn-xl { font-size: 21px; padding: 18px 20px; }
.btn-primary { background: var(--primary); color: #fff; }
.btn-primary:active { background: var(--primary-dark); }
.btn-secondary { background: #e5e7eb; color: var(--text); }
.btn-danger { background: var(--danger); color: #fff; }
.btn-ico { font-size: 24px; }
.btn-step { flex: 0 0 72px; font-size: 26px; }
.btn:disabled { opacity: .45; }

.canvas-wrap {
  position: relative; width: 100%;
  background: #0f172a; border-radius: var(--radius);
  overflow: hidden; margin-top: 10px;
  touch-action: none;
  border: 2px solid var(--border);
}
.canvas-wrap canvas { display: block; width: 100%; height: auto; }

.legend { display: flex; flex-wrap: wrap; gap: 8px; margin: 10px 0 4px; }
.chip {
  font-size: 14px; font-weight: 700; padding: 8px 12px;
  border-radius: 999px; background: #e5e7eb; border: 2px solid transparent;
}
.chip-wall { color: var(--wall); border-color: var(--wall); }
.chip-window { color: var(--window); border-color: var(--window); }
.chip-door { color: var(--door); border-color: var(--door); }
.chip-opening { color: var(--opening); border-color: var(--opening); }
.chip-dim { color: var(--dim); border-color: var(--dim); }

.counts { display: flex; gap: 10px; flex-wrap: wrap; margin: 12px 0 4px; font-size: 15px; font-weight: 700; }
.counts span { background: var(--card); border: 1px solid var(--border); border-radius: 10px; padding: 8px 12px; }

.calib-bar {
  margin-top: 12px; padding: 12px 14px; border-radius: var(--radius);
  background: #fef3c7; border: 2px solid #f59e0b; font-weight: 700; font-size: 16px;
}
.calib-bar.ok { background: #dcfce7; border-color: #16a34a; }
.hidden { display: none !important; }

/* progress */
.progress-list { display: flex; flex-direction: column; gap: 12px; margin: 18px 0; }
.pstep {
  display: flex; align-items: center; gap: 12px;
  background: var(--card); border: 1px solid var(--border);
  border-radius: var(--radius); padding: 16px; font-size: 18px; font-weight: 600;
  color: var(--muted);
}
.pstep .dot { width: 22px; height: 22px; border-radius: 50%; border: 3px solid var(--border); flex: 0 0 auto; }
.pstep .sub { font-weight: 400; font-size: 14px; }
.pstep.run { color: var(--text); border-color: var(--primary); }
.pstep.run .dot { border-color: var(--primary); border-top-color: transparent; animation: spin 0.9s linear infinite; }
.pstep.done { color: var(--text); }
.pstep.done .dot { background: var(--window); border-color: var(--window); }
.pstep.skip { text-decoration: line-through; opacity: .6; }
@keyframes spin { to { transform: rotate(360deg); } }

/* takeoff tables */
.to-table { width: 100%; border-collapse: collapse; font-size: 15.5px; margin: 10px 0 18px; background: var(--card); border-radius: var(--radius); overflow: hidden; }
.to-table th, .to-table td { padding: 12px 10px; border-bottom: 1px solid var(--border); text-align: left; }
.to-table th { background: #e5e7eb; font-size: 14px; text-transform: uppercase; letter-spacing: .04em; }
.to-table tr:last-child td { border-bottom: none; }
.mono { font-family: ui-monospace, SFMono-Regular, Menlo, monospace; }
.to-total { font-size: 19px; font-weight: 800; }
.warn { background: #fef3c7; border: 2px solid #f59e0b; border-radius: var(--radius); padding: 12px 14px; font-size: 15.5px; margin: 12px 0; }

/* bottom sheets */
.scrim { position: fixed; inset: 0; background: rgba(0,0,0,.5); z-index: 90; }
.sheet {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 100;
  background: var(--card); border-radius: 20px 20px 0 0;
  padding: 8px 18px 26px; max-height: 82vh; overflow-y: auto;
  box-shadow: 0 -4px 24px rgba(0,0,0,.3);
  animation: slideup .2s ease;
}
@keyframes slideup { from { transform: translateY(40px); opacity: 0; } to { transform: none; opacity: 1; } }
.sheet-head { display: flex; align-items: center; justify-content: space-between; position: sticky; top: 0; background: var(--card); padding: 10px 0; }
.sheet-head h3 { margin: 0; font-size: 20px; }
.icon-btn {
  width: 48px; height: 48px; border-radius: 50%; border: none;
  background: #e5e7eb; font-size: 20px; font-weight: 700; cursor: pointer;
}
.field { margin: 14px 0; }
.field > label { display: block; font-weight: 700; font-size: 16px; margin-bottom: 8px; }
.seg { display: flex; gap: 8px; }
.seg button {
  flex: 1; min-height: 52px; border-radius: 12px; border: 2px solid var(--border);
  background: #fff; font-size: 16px; font-weight: 700; cursor: pointer;
}
.seg button.sel { border-color: var(--primary); background: #dbeafe; color: var(--primary-dark); }
.dim-chips { display: flex; flex-wrap: wrap; gap: 8px; margin-bottom: 10px; }
.dim-chips button {
  min-height: 48px; padding: 8px 14px; border-radius: 10px;
  border: 2px solid var(--dim); background: #f0fdfa; color: #0f766e;
  font-weight: 700; font-size: 16px; cursor: pointer;
}
.input-row { display: flex; gap: 10px; }
.input-row input {
  flex: 1; min-height: var(--tap); font-size: 19px; padding: 10px 14px;
  border: 2px solid var(--border); border-radius: var(--radius);
}
.input-row .btn { flex: 0 0 auto; }

/* toast + loading */
.toast {
  position: fixed; left: 16px; right: 16px; bottom: 24px; z-index: 200;
  background: #111827; color: #fff; padding: 16px; border-radius: var(--radius);
  font-size: 16px; font-weight: 600; text-align: center;
  box-shadow: 0 4px 16px rgba(0,0,0,.4);
}
.loading-overlay {
  position: fixed; inset: 0; z-index: 300; background: rgba(15,23,42,.78);
  display: flex; flex-direction: column; gap: 18px; align-items: center; justify-content: center;
  color: #fff; font-size: 18px; font-weight: 700;
}
.spinner {
  width: 54px; height: 54px; border-radius: 50%;
  border: 6px solid rgba(255,255,255,.3); border-top-color: #fff;
  animation: spin 0.9s linear infinite;
}
@media (min-width: 700px) {
  .btn-row .btn { flex: 1; }
}
