/* Scan to Sketch — main styles
   Colors are inspired by marker renderings: warm paper, dark ink, orange and blue accents. */

:root {
  --paper: #f6f3ec;
  --paper-2: #ece6d9;
  --card: #ffffff;
  --ink: #26231f;
  --ink-2: #5b554c;
  --line: #d9d1c2;
  --accent: #e8743b;      /* marker orange */
  --accent-ink: #b9521f;
  --blue: #2f6db3;        /* marker blue */
  --blue-ink: #1f4f86;
  --good: #2e7d4f;
  --warn: #a8640b;
  --danger: #b3261e;
  --radius: 14px;
  --tap: 48px;            /* minimum touch target */
  --topbar-h: 60px;
  --shadow: 0 2px 10px rgba(38, 35, 31, .08);
  color-scheme: light;
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }   /* make sure hidden things stay hidden */
html, body { margin: 0; height: 100%; }
body {
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, Arial, sans-serif;
  font-size: 16px;
  line-height: 1.45;
  color: var(--ink);
  background: var(--paper);
  -webkit-text-size-adjust: 100%;
}
h1, h2, h3 { line-height: 1.2; margin: 0 0 .5rem; }
h2 { font-size: 1.05rem; }
p { margin: 0 0 .75rem; }
.muted { color: var(--ink-2); }
.small { font-size: .875rem; }
.sr-only { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }

/* ---------- Top bar ---------- */
.topbar {
  height: var(--topbar-h);
  display: flex; align-items: center; justify-content: space-between; gap: 12px;
  padding: 0 16px;
  background: var(--card);
  border-bottom: 1px solid var(--line);
}
.brand { display: flex; align-items: center; gap: 10px; font-weight: 700; font-size: 1.15rem; }
.brand-icon { width: 30px; height: 30px; }

/* ---------- Buttons ---------- */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  min-height: var(--tap);
  padding: 10px 16px;
  border: 2px solid var(--ink);
  border-radius: 12px;
  background: var(--card);
  color: var(--ink);
  font: inherit; font-weight: 600;
  cursor: pointer;
  text-align: center;
  user-select: none; -webkit-user-select: none;
  touch-action: manipulation;
}
.btn:hover { background: var(--paper-2); }
.btn:active { transform: translateY(1px); }
.btn:focus-visible, .segmented button:focus-visible, .link-btn:focus-visible { outline: 3px solid var(--blue); outline-offset: 2px; }
.btn-primary { background: var(--ink); color: #fff; }
.btn-primary:hover { background: #3d3832; }
.btn-accent { background: var(--accent); border-color: var(--accent-ink); color: #fff; }
.btn-accent:hover { background: #d9652c; }
.btn-ghost { border-color: transparent; background: transparent; }
.btn-small { min-height: 40px; padding: 6px 12px; font-size: .9rem; border-width: 1.5px; }
.btn-big { min-height: 56px; padding: 12px 22px; font-size: 1.1rem; }
.btn .ico { font-size: 1.3rem; line-height: 1; }
.btn.grow { flex: 1; }
.btn.wide, .segmented.wide { width: 100%; }
.link-btn { background: none; border: 0; color: var(--blue-ink); text-decoration: underline; font: inherit; cursor: pointer; padding: 8px; min-height: var(--tap); }

/* Two-or-more choice switch */
.segmented { display: inline-flex; border: 2px solid var(--ink); border-radius: 12px; overflow: hidden; }
.segmented button {
  flex: 1; min-height: 44px; padding: 6px 14px;
  border: 0; background: var(--card); color: var(--ink);
  font: inherit; font-weight: 600; cursor: pointer; touch-action: manipulation;
}
.segmented button + button { border-left: 2px solid var(--ink); }
.segmented button[aria-pressed="true"] { background: var(--ink); color: #fff; }

/* ---------- Layout ---------- */
.workspace {
  display: grid;
  grid-template-columns: 1fr 340px;
  height: calc(100dvh - var(--topbar-h));
}
.stage { position: relative; overflow: hidden; background: var(--paper); }
.viewer { position: absolute; inset: 0; touch-action: none; }
.viewer canvas { display: block; width: 100%; height: 100%; outline: none; }
.panel {
  overflow-y: auto;
  padding: 14px;
  background: var(--paper-2);
  border-left: 1px solid var(--line);
  display: flex; flex-direction: column; gap: 12px;
}
@media (max-width: 860px) {
  .workspace { display: block; height: auto; }
  .stage { height: 62dvh; min-height: 320px; }
  .panel { border-left: 0; border-top: 1px solid var(--line); }
  .viewbar-label { display: none; }
  .viewbar { flex-wrap: nowrap; }
  .toast { bottom: 20px; }
}

/* ---------- Cards in the panel ---------- */
.card {
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 14px;
  box-shadow: var(--shadow);
  display: flex; flex-direction: column; gap: 10px;
}
.card h2 { margin: 0; }
.card-head { display: flex; align-items: center; justify-content: space-between; gap: 8px; }
.row { display: flex; gap: 8px; }
.grid-3 { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; }
.grid-3 .btn { flex-direction: column; gap: 2px; padding: 8px 4px; font-size: .85rem; min-height: 64px; }

.facts { display: grid; grid-template-columns: auto 1fr; gap: 4px 12px; margin: 0; }
.facts dt { color: var(--ink-2); }
.facts dd { margin: 0; text-align: right; font-weight: 600; overflow-wrap: anywhere; }
.facts.big dd { font-size: 1.15rem; font-variant-numeric: tabular-nums; }
.facts small { font-weight: 400; color: var(--ink-2); }

.badge { margin: 0; padding: 8px 10px; border-radius: 10px; font-size: .9rem; font-weight: 600; }
.badge.estimated { background: #fff3dc; color: var(--warn); border: 1px solid #f0d49c; }
.badge.set { background: #e3f3e8; color: var(--good); border: 1px solid #b6dcc3; }

.measure-list { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 6px; }
.measure-list li {
  display: flex; align-items: center; gap: 8px;
  padding: 6px 6px 6px 10px; border: 1px solid var(--line); border-radius: 10px;
}
.measure-list .m-name { font-weight: 700; color: var(--accent-ink); }
.measure-list .m-val { flex: 1; font-variant-numeric: tabular-nums; font-weight: 600; }
.measure-list .btn { min-height: 40px; padding: 4px 10px; }
.measure-list .empty-note { border: 1px dashed var(--line); color: var(--ink-2); font-size: .9rem; }

.privacy { font-size: .85rem; color: var(--ink-2); margin: 4px 2px; }

/* ---------- Stage overlays ---------- */
.empty { position: absolute; inset: 0; display: grid; place-items: center; padding: 16px; }
.empty-card {
  max-width: 460px; text-align: center;
  background: var(--card); border: 2px dashed var(--line); border-radius: 20px;
  padding: 28px 22px;
}
.empty-card h1 { font-size: 1.6rem; }
.empty-actions { display: flex; flex-wrap: wrap; gap: 10px; justify-content: center; margin: 16px 0 8px; }

.viewbar {
  position: absolute; left: 50%; bottom: 12px; transform: translateX(-50%);
  display: flex; align-items: center; gap: 6px; flex-wrap: wrap; justify-content: center;
  background: rgba(255,255,255,.92); border: 1px solid var(--line); border-radius: 14px;
  padding: 6px; box-shadow: var(--shadow);
  max-width: calc(100% - 24px);
}
.viewbar-label { font-size: .85rem; color: var(--ink-2); padding: 0 4px; }
.viewbar .btn.active { background: var(--ink); color: #fff; }

.hint {
  position: absolute; top: 12px; left: 50%; transform: translateX(-50%);
  background: var(--blue); color: #fff; font-weight: 600;
  padding: 10px 16px; border-radius: 12px; box-shadow: var(--shadow);
  max-width: calc(100% - 24px); text-align: center;
}

.labels { position: absolute; inset: 0; pointer-events: none; }
.m-label {
  position: absolute; transform: translate(-50%, -50%);
  background: #fff; color: var(--accent-ink);
  border: 2px solid var(--accent); border-radius: 10px;
  padding: 2px 8px; font-weight: 700; font-size: .95rem; white-space: nowrap;
  font-variant-numeric: tabular-nums;
}

.drop-overlay {
  position: absolute; inset: 10px; display: grid; place-items: center;
  border: 4px dashed var(--blue); border-radius: 20px; background: rgba(47,109,179,.1);
  font-size: 1.4rem; font-weight: 700; color: var(--blue-ink); pointer-events: none;
}

/* ---------- Busy + toast ---------- */
.busy { position: fixed; inset: 0; display: grid; place-items: center; background: rgba(38,35,31,.35); z-index: 50; }
.busy-card { background: var(--card); border-radius: 16px; padding: 24px 28px; text-align: center; max-width: 320px; box-shadow: var(--shadow); }
.busy-card p { margin: 12px 0 0; font-weight: 600; }
.spinner {
  width: 42px; height: 42px; margin: 0 auto;
  border: 5px solid var(--paper-2); border-top-color: var(--accent); border-radius: 50%;
  animation: spin 0.9s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }
@media (prefers-reduced-motion: reduce) { .spinner { animation-duration: 3s; } }

.toast {
  position: fixed; left: 50%; bottom: 84px; transform: translateX(-50%);
  background: var(--ink); color: #fff; padding: 12px 18px; border-radius: 12px;
  font-weight: 600; z-index: 60; max-width: calc(100% - 32px); box-shadow: var(--shadow);
}

/* ---------- Dialogs ---------- */
.dialog {
  border: 0; border-radius: 18px; padding: 0;
  width: min(480px, calc(100% - 24px));
  max-height: calc(100dvh - 24px);
  color: var(--ink); background: var(--card);
  box-shadow: 0 10px 40px rgba(0,0,0,.25);
}
.dialog-wide { width: min(720px, calc(100% - 24px)); }
.dialog::backdrop { background: rgba(38,35,31,.45); }
.dialog form { padding: 20px; }
.dialog-actions { display: flex; justify-content: flex-end; gap: 10px; margin-top: 16px; }
.choices { border: 0; padding: 0; margin: 0 0 12px; display: flex; flex-direction: column; gap: 6px; }
.choices legend { font-weight: 700; margin-bottom: 6px; }
.choice {
  display: flex; align-items: center; gap: 10px;
  min-height: var(--tap); padding: 6px 12px;
  border: 2px solid var(--line); border-radius: 12px; cursor: pointer;
}
.choice:has(input:checked) { border-color: var(--ink); background: var(--paper); }
.choice input { width: 22px; height: 22px; accent-color: var(--ink); }
.choice .c-now { margin-left: auto; color: var(--ink-2); font-size: .9rem; }
.field { display: flex; flex-direction: column; gap: 6px; font-weight: 700; }
.input-unit { display: flex; align-items: center; gap: 8px; }
.input-unit input {
  flex: 1; min-height: 52px; font-size: 1.3rem; padding: 8px 12px;
  border: 2px solid var(--ink); border-radius: 12px; font-family: inherit;
}
.input-unit span { font-size: 1.1rem; font-weight: 700; min-width: 2.5em; }
.error { color: var(--danger); font-weight: 600; }

.guide-head { display: flex; justify-content: space-between; align-items: center; gap: 12px; margin-bottom: 8px; }
.guide { padding-left: 1.4rem; margin: 0 0 12px; }
.guide li { margin-bottom: 14px; }
.guide li::marker { font-weight: 700; color: var(--accent-ink); }
.guide h3 { font-size: 1rem; margin-bottom: 4px; }
.guide p { margin: 0; }

.noscript { padding: 20px; font-weight: 700; }

/* ---------- Tabs ---------- */
.tabs { display: flex; gap: 6px; }
.tab {
  display: inline-flex; align-items: center; gap: 8px;
  min-height: 44px; padding: 6px 14px;
  border: 2px solid transparent; border-radius: 12px;
  background: transparent; color: var(--ink);
  font: inherit; font-weight: 700; cursor: pointer; touch-action: manipulation;
}
.tab:hover:not(:disabled) { background: var(--paper-2); }
.tab[aria-selected="true"] { border-color: var(--ink); background: var(--paper); }
.tab:disabled { color: #aaa29a; cursor: not-allowed; }
.tab-num {
  display: inline-grid; place-items: center; width: 24px; height: 24px; border-radius: 50%;
  background: var(--ink); color: #fff; font-size: .8rem;
}
.tab:disabled .tab-num { background: #cfc8bd; }
.tab[aria-selected="true"] .tab-num { background: var(--accent); }
.tab:focus-visible { outline: 3px solid var(--blue); outline-offset: 2px; }
@media (max-width: 640px) {
  .brand-name, .guide-text { display: none; }
  .topbar { padding: 0 8px; gap: 6px; }
  .tab { padding: 6px 10px; }
}

/* ---------- Drawing sheet ---------- */
.sheet-stage { background: #d9d4ca; }
.sheet { position: absolute; inset: 0; touch-action: none; cursor: grab; }
.sheet:active { cursor: grabbing; }
.sheet svg { width: 100%; height: 100%; display: block; }
.sheet svg > rect:first-of-type { filter: drop-shadow(0 2px 6px rgba(0,0,0,.25)); }
.zoombar {
  position: absolute; right: 12px; bottom: 12px; display: flex; gap: 6px;
  background: rgba(255,255,255,.92); border: 1px solid var(--line); border-radius: 14px; padding: 6px;
  box-shadow: var(--shadow);
}
.zoombar .btn { min-width: 44px; font-size: 1.1rem; }
.segmented small { font-weight: 400; font-size: .8rem; }
.select {
  width: 100%; min-height: var(--tap); padding: 8px 12px;
  border: 2px solid var(--ink); border-radius: 12px; background: var(--card);
  font: inherit; font-weight: 600; color: var(--ink);
}
.check { display: flex; align-items: center; gap: 10px; min-height: var(--tap); cursor: pointer; font-weight: 600; }
.check input { width: 24px; height: 24px; accent-color: var(--ink); }
.check small { font-weight: 400; color: var(--ink-2); }
.overflow-warn { color: var(--warn); font-weight: 600; }

/* ---------- Drawing tools ---------- */
.tool-grid { display: grid; grid-template-columns: repeat(5, 1fr); gap: 6px; }
.tool { flex-direction: column; gap: 2px; padding: 6px 2px; font-size: .78rem; min-height: 62px; border-width: 1.5px; }
.tool .ico { font-size: 1.35rem; }
.tool[aria-pressed="true"] { background: var(--ink); color: #fff; }
@media (max-width: 380px) { .tool-grid { grid-template-columns: repeat(3, 1fr); } }
.btn-danger { border-color: var(--danger); color: var(--danger); }
.btn-danger:hover { background: #fbeceb; }
.btn[aria-pressed="true"]:not(.tool) { background: var(--ink); color: #fff; }
.btn:disabled { opacity: .45; cursor: not-allowed; }
.selection { border: 2px solid var(--blue); }
.stack { display: flex; flex-direction: column; gap: 8px; }
.small-field { font-size: .9rem; }
.small-field input, #textInput {
  min-height: var(--tap); padding: 8px 12px; font: inherit; font-weight: 400; font-size: 1rem;
  border: 2px solid var(--ink); border-radius: 12px; background: #fff; color: var(--ink);
}
#textInput { font-size: 1.15rem; resize: vertical; }
.sheet-stage .hint { z-index: 2; }

/* ---------- Rendering ---------- */
.render-stage { background: #d9d4ca; display: grid; place-items: center; }
.render-frame { position: relative; box-shadow: 0 3px 14px rgba(0,0,0,.22); background: #fdfcf7; }
.render-canvas { display: block; }
.render-overlay { position: absolute; inset: 0; touch-action: none; cursor: crosshair; }
.pill {
  position: absolute; top: 12px; right: 12px; background: var(--ink); color: #fff;
  padding: 6px 14px; border-radius: 999px; font-weight: 700; font-size: .9rem;
}
.grid-2 { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }
.range { display: grid; grid-template-columns: 4.6em 1fr; align-items: center; gap: 8px; font-weight: 600; min-height: var(--tap); }
.range input { width: 100%; height: 32px; accent-color: var(--accent); }
.swatches { display: flex; flex-wrap: wrap; gap: 8px; }
.swatch {
  width: 44px; height: 44px; border-radius: 50%; border: 3px solid #fff; background: var(--c);
  box-shadow: 0 0 0 1.5px var(--line); cursor: pointer; padding: 0; touch-action: manipulation;
  display: grid; place-items: center; position: relative;
}
.swatch[aria-pressed="true"] { box-shadow: 0 0 0 3px var(--ink); }
.swatch-custom { background: conic-gradient(#e8743b, #f2c14e, #7cb55a, #4a90c8, #8a6cc2, #d9483b, #e8743b); }
.swatch-custom input { position: absolute; inset: 0; opacity: 0; cursor: pointer; }
.swatch-custom span { color: #fff; font-weight: 800; font-size: 1.3rem; text-shadow: 0 1px 2px rgba(0,0,0,.5); pointer-events: none; }
.selection-inline { border-top: 2px solid var(--blue); padding-top: 10px; }
.render-stage .hint { z-index: 2; }
@media (max-width: 640px) { .tab { padding: 6px 8px; font-size: .9rem; gap: 5px; } .tab-long { display: none; } }
