/* =========================================================================
   Measure — pro-tool design system
   Dark-first. Light via [data-theme="light"]. Tokens from Claude Design bundle.
   ========================================================================= */

@font-face {
  font-family: "Inter";
  src: url("/static/fonts/inter.woff2") format("woff2");
  font-weight: 100 900;
  font-display: swap;
  font-style: normal;
}
@font-face {
  font-family: "JetBrains Mono";
  src: url("/static/fonts/jetbrains-mono.woff2") format("woff2");
  font-weight: 100 800;
  font-display: swap;
  font-style: normal;
}

:root {
  --ff-sans: "Inter", system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  --ff-mono: "JetBrains Mono", ui-monospace, "SF Mono", Menlo, monospace;
  --fs-xs: 11px;
  --fs-sm: 12px;
  --fs-base: 13px;
  --fs-md: 14px;
  --fs-lg: 16px;
  --fs-xl: 19px;
  --fs-2xl: 24px;
  --fs-3xl: 32px;

  --r-1: 3px;
  --r-2: 5px;
  --r-3: 8px;
  --r-4: 12px;
  --r-pill: 999px;

  --s-1: 4px;
  --s-2: 8px;
  --s-3: 12px;
  --s-4: 16px;
  --s-5: 20px;
  --s-6: 24px;
  --s-7: 32px;
  --s-8: 48px;

  --ease: cubic-bezier(.2, .7, .2, 1);
  --dur-fast: 100ms;
  --dur: 180ms;

  --density-row: 32px;
}

/* ---- Dark theme (default) ---- */
[data-theme="dark"] {
  --bg: #0a0b0d;
  --canvas-bg: #0e1014;
  --surface-1: #14161a;
  --surface-2: #1a1d22;
  --surface-3: #20242a;
  --hover: #20242a;
  --border: #22262c;
  --border-strong: #2e333a;
  --divider: #1a1d22;

  --ink: #ebecee;
  --ink-2: #b6bac1;
  --ink-3: #888c93;
  --muted: #6a6f77;

  --accent: #f4a72c;
  --accent-soft: #f4a72c22;
  --accent-ink: #fbbf52;
  --accent-press: #d18e1d;
  --accent-on: #1a0e00;

  --danger: #f87171;
  --danger-soft: #f8717122;
  --success: #4ade80;
  --warning: #fbbf24;

  --c-distance: #6ee7b7;
  --c-path: #93c5fd;
  --c-area: #c4b5fd;
  --c-angle: #fcd34d;
  --c-calibration: #fb7185;

  --shadow-1: 0 1px 2px rgba(0,0,0,0.4);
  --shadow-2: 0 8px 24px rgba(0,0,0,0.4), 0 2px 4px rgba(0,0,0,0.3);
  --shadow-3: 0 16px 48px rgba(0,0,0,0.55), 0 4px 12px rgba(0,0,0,0.4);

  --canvas-paper: #f5f3ec;
  --canvas-ink: #1a1d22;
  --label-bg: rgba(20,22,26,0.92);
  --label-ink: #ebecee;
}

/* ---- Light theme ---- */
[data-theme="light"] {
  --bg: #f7f7f4;
  --canvas-bg: #ececea;
  --surface-1: #ffffff;
  --surface-2: #fbfbf9;
  --surface-3: #f1f1ee;
  --hover: #f1f1ee;
  --border: #e1e0d9;
  --border-strong: #cdccc4;
  --divider: #ebeae3;

  --ink: #0e0f11;
  --ink-2: #41454c;
  --ink-3: #6b7079;
  --muted: #8a8e95;

  --accent: #c1750f;
  --accent-soft: #c1750f1a;
  --accent-ink: #a26209;
  --accent-press: #8c5408;
  --accent-on: #ffffff;

  --danger: #c43b3b;
  --danger-soft: #c43b3b14;
  --success: #1f7a3f;
  --warning: #a96800;

  --c-distance: #047857;
  --c-path: #1d4ed8;
  --c-area: #6d28d9;
  --c-angle: #b45309;
  --c-calibration: #be123c;

  --shadow-1: 0 1px 2px rgba(15,17,21,0.06);
  --shadow-2: 0 6px 20px rgba(15,17,21,0.1), 0 2px 4px rgba(15,17,21,0.06);
  --shadow-3: 0 16px 40px rgba(15,17,21,0.18), 0 4px 12px rgba(15,17,21,0.1);

  --canvas-paper: #ffffff;
  --canvas-ink: #21232a;
  --label-bg: rgba(255,255,255,0.95);
  --label-ink: #0e0f11;
}

/* ---- Reset + base ---- */
*, *::before, *::after { box-sizing: border-box; }
html, body { height: 100%; margin: 0; overflow: hidden; }
[hidden] { display: none !important; }

body {
  font-family: var(--ff-sans);
  font-size: var(--fs-base);
  line-height: 1.45;
  color: var(--ink);
  background: var(--bg);
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  font-feature-settings: "ss01", "cv11", "tnum";
}

h1, h2, h3, h4 { margin: 0; line-height: 1.15; font-weight: 600; letter-spacing: -0.012em; }
p { margin: 0; }
button { font: inherit; color: inherit; cursor: pointer; }
input, select, textarea { font: inherit; color: inherit; }
.mono { font-family: var(--ff-mono); font-variant-numeric: tabular-nums; }
.tnum { font-variant-numeric: tabular-nums; }
.muted { color: var(--muted); }

#main { height: 100%; }

::-webkit-scrollbar { width: 10px; height: 10px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: var(--border-strong); border-radius: 4px; border: 2px solid var(--bg); }
::-webkit-scrollbar-thumb:hover { background: var(--ink-3); }

:focus-visible { outline: 2px solid var(--accent); outline-offset: 1px; border-radius: var(--r-2); }

.skip-link {
  position: absolute; left: -9999px; top: 0; z-index: 1000;
  background: var(--surface-1); color: var(--ink);
  padding: 8px 12px; border-radius: var(--r-2); border: 1px solid var(--border);
}
.skip-link:focus { left: 8px; top: 8px; }
.live-region { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); }

/* =========================================================================
   Atoms
   ========================================================================= */

.i { display: block; flex: none; stroke: currentColor; fill: none;
  stroke-width: 1.6; stroke-linecap: round; stroke-linejoin: round; }

.btn {
  display: inline-flex; align-items: center; gap: 6px;
  padding: 0 10px; height: 28px;
  background: var(--surface-2); color: var(--ink);
  border: 1px solid var(--border); border-radius: var(--r-2);
  font-size: var(--fs-sm); font-weight: 500; white-space: nowrap;
  transition: background var(--dur-fast) var(--ease), border-color var(--dur-fast) var(--ease);
}
.btn:hover { background: var(--hover); border-color: var(--border-strong); }
.btn:disabled { opacity: 0.45; cursor: not-allowed; }
a.btn { text-decoration: none; }
.btn .i { width: 16px; height: 16px; }
.btn--primary, .btn-primary {
  background: var(--accent); color: var(--accent-on);
  border-color: var(--accent); font-weight: 600;
}
.btn--primary:hover, .btn-primary:hover { background: var(--accent-press); border-color: var(--accent-press); }
/* Marketing pages only (the app never uses <a class="btn">): light-theme amber
   #c1750f behind white text is 3.6:1 — below AA for these button sizes. Anchor
   primaries get the darker accent-ink amber (#a26209, 4.9:1) instead. */
[data-theme="light"] a.btn-primary, [data-theme="light"] a.btn--primary {
  background: var(--accent-ink); border-color: var(--accent-ink);
}
[data-theme="light"] a.btn-primary:hover, [data-theme="light"] a.btn--primary:hover {
  background: var(--accent-press); border-color: var(--accent-press);
}
.btn--ghost, .btn-ghost { background: transparent; }
.btn--ghost:hover, .btn-ghost:hover { background: var(--hover); }
.btn--danger, .btn-danger { color: var(--danger); }
.btn--danger:hover, .btn-danger:hover { background: var(--danger-soft); }
.btn--lg, .btn-lg { height: 36px; padding: 0 14px; font-size: var(--fs-base); }
.btn-sm { height: 22px; padding: 0 6px; font-size: var(--fs-xs); }
.btn--icon { width: 28px; padding: 0; justify-content: center; }

.icon-btn {
  display: inline-flex; align-items: center; justify-content: center;
  width: 32px; height: 32px; padding: 0;
  background: transparent; border: 1px solid transparent;
  border-radius: var(--r-2); color: var(--ink-2);
  transition: background var(--dur-fast) var(--ease), color var(--dur-fast) var(--ease);
}
.icon-btn:hover { background: var(--hover); color: var(--ink); }
.icon-btn.danger:hover { background: var(--danger-soft); color: var(--danger); }

.kbd, kbd {
  display: inline-flex; align-items: center; justify-content: center;
  min-width: 18px; height: 18px; padding: 0 4px;
  background: var(--surface-3); border: 1px solid var(--border);
  border-bottom-color: var(--border-strong); border-radius: var(--r-1);
  font-family: var(--ff-mono); font-size: 10px; font-weight: 500; color: var(--ink-2);
}

.chip {
  display: inline-flex; align-items: center; gap: 4px;
  padding: 2px 8px; height: 20px; border-radius: var(--r-pill);
  font-size: var(--fs-xs); font-weight: 500;
  background: var(--surface-3); color: var(--ink-2);
  border: 1px solid var(--border); white-space: nowrap;
}
.chip-soft { background: var(--surface-2); }
.chip-dot { width: 6px; height: 6px; border-radius: 50%; }

/* Segmented control */
.seg, .segmented {
  display: inline-flex; background: var(--surface-3);
  padding: 2px; border-radius: var(--r-2); border: 1px solid var(--border);
}
.seg button {
  display: inline-flex; align-items: center; justify-content: center;
  height: 22px; padding: 0 10px; background: transparent; border: none;
  font-size: var(--fs-xs); font-weight: 500; color: var(--ink-3);
  border-radius: var(--r-1); cursor: pointer;
}
.segmented label { cursor: pointer; position: relative; }
.segmented input { position: absolute; opacity: 0; pointer-events: none; }
.seg button[data-active="true"],
.segmented input:checked + span {
  background: var(--surface-1); color: var(--ink); box-shadow: var(--shadow-1);
}
.segmented label span {
  display: inline-flex; align-items: center; justify-content: center;
  height: 22px; padding: 0 10px; border-radius: var(--r-1);
  font-size: var(--fs-xs); font-weight: 500; color: var(--ink-3);
}

/* =========================================================================
   Top bar (desktop editor)
   ========================================================================= */

.topbar {
  display: flex; align-items: center; gap: 4px;
  height: 44px; padding: 0 var(--s-2);
  background: var(--surface-1); border-bottom: 1px solid var(--border);
  flex: none; z-index: 10;
}
.topbar__brand {
  display: inline-flex; align-items: center; gap: 6px;
  padding: 0 6px; height: 28px; text-decoration: none; color: var(--ink);
  border-radius: var(--r-2); font-weight: 600; letter-spacing: -0.01em; font-size: var(--fs-base);
}
.topbar__brand:hover { background: var(--hover); }
.topbar__brand-mark { color: var(--accent); display: inline-flex; }
.topbar__brand-mark .i { width: 20px; height: 20px; }
.topbar__divider { width: 1px; height: 16px; background: var(--border); margin: 0 4px; }
.topbar__crumb {
  display: inline-flex; align-items: center; gap: 6px;
  padding: 0 8px; height: 28px; border-radius: var(--r-2);
  color: var(--ink); font-size: var(--fs-base); font-weight: 500;
  cursor: pointer; background: transparent; border: none; max-width: 320px;
}
.topbar__crumb:hover { background: var(--hover); }
.topbar__crumb-name { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.topbar__pages { display: inline-flex; align-items: center; gap: 2px; padding: 0 4px; }
.topbar__page {
  height: 22px; min-width: 22px; padding: 0 6px; border-radius: var(--r-1);
  background: transparent; border: none; color: var(--ink-3);
  font-family: var(--ff-mono); font-size: var(--fs-xs); font-weight: 500;
  text-decoration: none; display: inline-flex; align-items: center; justify-content: center;
}
.topbar__page:hover { background: var(--hover); color: var(--ink); }
.topbar__page.active {
  background: var(--surface-3); color: var(--ink);
  box-shadow: inset 0 0 0 1px var(--border-strong);
}
.topbar__spacer { flex: 1; }
.topbar__user {
  display: inline-flex; align-items: center; height: 24px; padding: 0 6px;
  font-family: var(--ff-mono); font-size: var(--fs-xs); color: var(--ink-3);
}

/* Scale chip */
.scale-chip {
  display: inline-flex; align-items: center; gap: 6px;
  padding: 0 8px; height: 24px; background: var(--surface-3);
  border: 1px solid var(--border); border-radius: var(--r-2);
  font-family: var(--ff-mono); font-size: var(--fs-xs); color: var(--ink);
}
.scale-chip__dot { width: 6px; height: 6px; border-radius: 50%; background: var(--success); }
.scale-chip.warn { color: var(--warning); }
.scale-chip.warn .scale-chip__dot { background: var(--warning); }

/* =========================================================================
   Editor body
   ========================================================================= */

.editor { position: relative; display: flex; flex-direction: column; height: 100%; width: 100%; background: var(--canvas-bg); }
.editor__body { position: relative; flex: 1; min-height: 0; display: flex; }
.editor__canvas-area {
  position: relative; flex: 1; min-width: 0;
  background:
    radial-gradient(circle at 50% 28%, color-mix(in srgb, var(--accent) 6%, transparent), transparent 60%),
    var(--canvas-bg);
}

/* Tool rail (desktop) */
.toolrail {
  position: absolute; top: 50%; left: var(--s-3); transform: translateY(-50%);
  display: flex; flex-direction: column; gap: 2px; padding: 4px;
  background: var(--surface-1); border: 1px solid var(--border);
  border-radius: var(--r-3); box-shadow: var(--shadow-2); z-index: 20;
}
.toolrail__sep { height: 1px; background: var(--divider); margin: 4px; }
.tool-btn {
  position: relative; width: 34px; height: 34px;
  display: flex; align-items: center; justify-content: center;
  background: transparent; border: none; border-radius: var(--r-2);
  color: var(--ink-2);
  transition: background var(--dur-fast) var(--ease), color var(--dur-fast) var(--ease);
}
.tool-btn .i { width: 22px; height: 22px; }
.tool-btn:hover { background: var(--hover); color: var(--ink); }
.tool-btn[data-tint] { color: var(--tint); }
.tool-btn.active { background: var(--accent); color: var(--accent-on); }
.tool-btn .tool-label { display: none; }
.tool-btn__kbd {
  position: absolute; bottom: 2px; right: 3px;
  font-family: var(--ff-mono); font-size: 8px; color: var(--muted); font-weight: 600; pointer-events: none;
}
.tool-btn.active .tool-btn__kbd { color: color-mix(in srgb, var(--accent-on) 55%, transparent); }
.tool-btn__tip {
  position: absolute; left: calc(100% + 10px); top: 50%; transform: translateY(-50%);
  padding: 4px 8px; background: var(--surface-3); border: 1px solid var(--border-strong);
  border-radius: var(--r-2); font-size: var(--fs-xs); color: var(--ink);
  white-space: nowrap; opacity: 0; pointer-events: none;
  transition: opacity var(--dur-fast) var(--ease); box-shadow: var(--shadow-2);
  display: flex; gap: 6px; align-items: center; z-index: 30;
}
.tool-btn:hover .tool-btn__tip { opacity: 1; }
.tool-btn--cal { color: var(--c-calibration); }
.tool-btn--cal.active { background: var(--c-calibration); color: #fff; }
.tool-btn--snap[aria-pressed="true"] { background: var(--accent); color: var(--accent-on); border-color: var(--accent); }

/* Canvas */
.canvas-wrap {
  position: absolute; inset: 0; overflow: hidden;
  cursor: default; user-select: none; -webkit-user-select: none; touch-action: none;
}
#measure-canvas { display: block; width: 100%; height: 100%; }

.measure-loupe {
  position: absolute; pointer-events: none; border-radius: 50%;
  filter: drop-shadow(0 8px 20px rgba(0,0,0,0.45)) drop-shadow(0 2px 4px rgba(0,0,0,0.35));
  z-index: 50; animation: loupe-in 120ms var(--ease);
}
@keyframes loupe-in { from { transform: scale(0.85); opacity: 0; } to { transform: scale(1); opacity: 1; } }

/* Status bar pill (desktop) */
.statusbar {
  position: absolute; bottom: var(--s-3); left: 50%; transform: translateX(-50%);
  display: flex; align-items: center; gap: 2px; padding: 3px;
  background: color-mix(in srgb, var(--surface-1) 92%, transparent);
  backdrop-filter: blur(12px); -webkit-backdrop-filter: blur(12px);
  border: 1px solid var(--border); border-radius: var(--r-pill);
  box-shadow: var(--shadow-2); z-index: 18; font-size: var(--fs-xs); color: var(--ink-2);
}
.statusbar__item {
  display: inline-flex; align-items: center; gap: 6px; padding: 0 10px; height: 26px;
  border-radius: var(--r-pill); font-family: var(--ff-mono); font-variant-numeric: tabular-nums; white-space: nowrap;
}
.statusbar__btn { background: transparent; border: none; color: var(--ink-2); }
.statusbar__btn:hover { background: var(--hover); color: var(--ink); }
.statusbar__btn .i { width: 16px; height: 16px; }
.statusbar__sep { width: 1px; height: 14px; background: var(--border); margin: 0 2px; }
.statusbar__label { font-family: var(--ff-sans); color: var(--muted); text-transform: uppercase; font-size: 10px; letter-spacing: 0.06em; }
.statusbar.warn .statusbar__scale { color: var(--warning); }

/* Hint pill */
.tool-hint {
  position: absolute; top: var(--s-3); left: 50%; transform: translateX(-50%);
  padding: 6px 14px; background: color-mix(in srgb, var(--surface-1) 90%, transparent);
  backdrop-filter: blur(12px); -webkit-backdrop-filter: blur(12px);
  border: 1px solid var(--border); border-radius: var(--r-pill);
  display: inline-flex; align-items: center; gap: 8px;
  font-size: var(--fs-sm); color: var(--ink); box-shadow: var(--shadow-2);
  z-index: 18; max-width: calc(100% - 40px); white-space: nowrap;
}
.tool-hint.flash { animation: hint-in var(--dur) var(--ease); }
@keyframes hint-in {
  from { opacity: 0; transform: translate(-50%, -8px); }
  to { opacity: 1; transform: translate(-50%, 0); }
}

/* First-run banner */
.first-run {
  position: absolute; top: var(--s-3); left: 50%; transform: translateX(-50%);
  display: flex; align-items: flex-start; gap: 10px; max-width: 460px;
  padding: 10px 12px; background: var(--surface-1);
  border: 1px solid var(--border-strong); border-radius: var(--r-3);
  box-shadow: var(--shadow-2); z-index: 19; font-size: var(--fs-sm);
}
.first-run .i { color: var(--accent); margin-top: 1px; width: 20px; height: 20px; }
.first-run p { color: var(--ink-2); }
.first-run strong { color: var(--ink); }

/* Canvas overlay (loading) + error */
.canvas-overlay {
  position: absolute; inset: 0; display: flex; align-items: center; justify-content: center;
  gap: 10px; color: var(--ink-2); background: var(--canvas-bg); z-index: 8; font-size: var(--fs-sm);
}
.spinner {
  width: 16px; height: 16px; border-radius: 50%;
  border: 2px solid var(--border-strong); border-top-color: var(--accent);
  animation: spin 0.7s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }
.canvas-error {
  position: absolute; inset: 0; display: flex; flex-direction: column; gap: 10px;
  align-items: center; justify-content: center; background: var(--canvas-bg); z-index: 9; color: var(--ink-2);
}

/* Value bubble */
.value-bubble {
  position: absolute; left: 50%; top: 16px; transform: translateX(-50%);
  display: flex; flex-direction: column; align-items: center;
  padding: 6px 12px; background: var(--surface-1); border: 1px solid var(--border-strong);
  border-radius: var(--r-3); box-shadow: var(--shadow-2); z-index: 19;
  opacity: 0; transition: opacity var(--dur) var(--ease); pointer-events: none;
}
.value-bubble.show { opacity: 1; }
.value-bubble strong { font-family: var(--ff-mono); font-size: var(--fs-md); }
.value-bubble small { color: var(--muted); font-size: var(--fs-xs); }

/* Delete FAB */
.delete-fab {
  position: absolute; transform: translate(-50%, -50%);
  width: 34px; height: 34px; border-radius: 50%;
  background: var(--danger); color: #fff; border: none;
  display: inline-flex; align-items: center; justify-content: center;
  box-shadow: var(--shadow-2); z-index: 21;
}
.delete-fab .i { width: 18px; height: 18px; }
.delete-fab:hover { filter: brightness(1.08); }

/* Action bar */
.action-bar {
  position: absolute; bottom: 60px; left: 50%; transform: translateX(-50%);
  display: flex; gap: 4px; padding: 4px;
  background: var(--surface-1); border: 1px solid var(--border-strong);
  border-radius: var(--r-3); box-shadow: var(--shadow-3); z-index: 19;
  animation: hint-in var(--dur) var(--ease);
}
.action-bar .btn { height: 32px; }

/* =========================================================================
   Right panel
   ========================================================================= */

.panel {
  width: 320px; flex: none; display: flex; flex-direction: column;
  background: var(--surface-1); border-left: 1px solid var(--border);
  min-height: 0; transition: width var(--dur) var(--ease);
}
.editor:not(.panel-open) .panel {
  width: 0; border-left: none; overflow: hidden; pointer-events: none;
}
.panel__head {
  display: flex; align-items: center; justify-content: space-between;
  padding: var(--s-3); border-bottom: 1px solid var(--divider); flex: none; gap: 8px;
}
.panel-grab { display: none; }
.panel__tabs { display: inline-flex; background: var(--surface-3); border-radius: var(--r-2); padding: 2px; }
.panel__tab {
  display: inline-flex; align-items: center; gap: 5px;
  height: 24px; padding: 0 10px; background: transparent; border: none;
  border-radius: var(--r-1); font-size: var(--fs-xs); font-weight: 500; color: var(--ink-3);
}
.panel__tab[data-active="true"] { background: var(--surface-1); color: var(--ink); box-shadow: var(--shadow-1); }
.panel__tab-count {
  background: var(--border); color: var(--ink-2); font-family: var(--ff-mono);
  padding: 1px 5px; border-radius: var(--r-1); font-size: 10px; font-weight: 600;
}
.panel__tab[data-active="true"] .panel__tab-count { background: var(--accent-soft); color: var(--accent-ink); }

.panel__filter {
  display: flex; align-items: center; gap: 6px; padding: 8px var(--s-3) 6px;
  border-bottom: 1px solid var(--divider);
}
.panel__filter-box {
  flex: 1; display: flex; align-items: center; gap: 6px; padding: 0 8px; height: 26px;
  background: var(--surface-2); border: 1px solid var(--border); border-radius: var(--r-2); color: var(--muted);
}
.panel__filter-box .i { width: 14px; height: 14px; }
.panel__filter-box input { flex: 1; background: transparent; border: none; outline: none; color: var(--ink); font-size: var(--fs-sm); }

.panel__summary { display: flex; gap: 6px; flex-wrap: wrap; padding: 8px var(--s-3); border-bottom: 1px solid var(--divider); }
.panel__summary:empty { display: none; }

.panel__body { flex: 1; min-height: 0; overflow-y: auto; display: flex; flex-direction: column; }

.panel-section { display: flex; flex-direction: column; }
.section-head {
  display: flex; align-items: center; justify-content: space-between;
  padding: 8px var(--s-3) 4px;
}
.section-title { font-size: 10px; font-weight: 600; text-transform: uppercase; letter-spacing: 0.08em; color: var(--muted); }

.panel-foot { padding: 8px; display: flex; gap: 4px; border-top: 1px solid var(--divider); flex: none; }
.panel-foot .btn { flex: 1; justify-content: center; }

/* Measurement row */
.measurement-list, .calibration-list { list-style: none; margin: 0; padding: 4px 0; }
.measurement-row {
  display: grid; grid-template-columns: 8px 1fr auto auto; align-items: center; gap: 8px;
  padding: 4px 8px; margin: 1px 6px; border-radius: var(--r-2); cursor: pointer;
  border: 1px solid transparent; min-height: var(--density-row);
}
.measurement-row:hover { background: var(--surface-2); }
.measurement-row.selected { background: var(--accent-soft); border-color: color-mix(in srgb, var(--accent) 50%, transparent); }
.kind-dot { width: 8px; height: 8px; border-radius: 50%; }
.kind-dot.distance { background: var(--c-distance); }
.kind-dot.path { background: var(--c-path); }
.kind-dot.area { background: var(--c-area); }
.kind-dot.angle { background: var(--c-angle); }
.row-main { min-width: 0; display: flex; flex-direction: column; }
.label-input {
  background: transparent; border: 1px solid transparent; padding: 0 4px; height: 20px;
  border-radius: var(--r-1); color: var(--ink); font-size: var(--fs-sm); font-weight: 500; width: 100%; min-width: 0;
}
.label-input::placeholder { color: var(--muted); font-style: italic; font-weight: 400; text-transform: capitalize; }
.label-input:focus { background: var(--surface-1); border-color: var(--accent); outline: none; }
.row-value { font-family: var(--ff-mono); font-size: var(--fs-sm); color: var(--ink-2); padding-left: 4px; font-variant-numeric: tabular-nums; }
.row-btn { width: 22px; height: 22px; opacity: 0; }
.measurement-row:hover .row-btn, .measurement-row.selected .row-btn { opacity: 1; }
.row-btn .i { width: 16px; height: 16px; }

/* Calibration row */
.calibration-row {
  display: grid; grid-template-columns: 8px 1fr auto auto; gap: 6px; align-items: center;
  padding: 8px 10px; margin: 4px 6px; border-radius: var(--r-2);
  background: var(--surface-2); border: 1px solid var(--border);
}
.cal-dot { width: 8px; height: 8px; border-radius: 50%; background: var(--c-calibration); }
.cal-row-main { min-width: 0; display: flex; flex-direction: column; }
.cal-row-label { font-size: var(--fs-sm); color: var(--ink); font-weight: 500; }
.cal-row-label.muted { color: var(--muted); font-style: italic; font-weight: 400; }
.cal-row-value { font-family: var(--ff-mono); font-size: var(--fs-xs); color: var(--c-calibration); font-weight: 600; }
.calibration-row .row-btn { opacity: 1; }

.section-empty, .panel-empty { padding: 24px 16px; text-align: center; color: var(--muted); font-size: var(--fs-sm); }
.panel-empty p { margin-bottom: 2px; }
.panel-empty p:first-child { color: var(--ink-2); font-weight: 500; }

/* Calibration consistency badge + effective scale */
.cal-stats {
  margin: 4px 6px; padding: 8px 10px; border-radius: var(--r-2);
  font-size: var(--fs-xs); display: flex; align-items: flex-start; gap: 8px;
  background: color-mix(in srgb, var(--warning) 12%, transparent);
  border: 1px solid color-mix(in srgb, var(--warning) 30%, transparent); color: var(--warning);
}
.cal-stats.ok {
  background: color-mix(in srgb, var(--success) 12%, transparent);
  border-color: color-mix(in srgb, var(--success) 30%, transparent); color: var(--success);
}
.cal-stats strong { font-weight: 600; }
.effective-scale { padding: 6px var(--s-3) 10px; display: flex; flex-direction: column; gap: 4px; }
.effective-scale__row { display: flex; justify-content: space-between; font-size: var(--fs-sm); color: var(--muted); }
.effective-scale__row .mono { color: var(--ink); }

/* =========================================================================
   Mobile editor chrome
   ========================================================================= */

.mob-topbar {
  display: none; flex-direction: column;
  padding: max(10px, env(safe-area-inset-top)) 10px 10px;
  background: color-mix(in srgb, var(--surface-1) 90%, transparent);
  backdrop-filter: saturate(180%) blur(20px); -webkit-backdrop-filter: saturate(180%) blur(20px);
  border-bottom: 1px solid var(--border); flex: none; position: relative; z-index: 30; gap: 8px;
}
.mob-topbar__row { display: flex; align-items: center; gap: 8px; min-height: 36px; }
.mob-topbar__back { width: 36px; height: 36px; margin-left: -6px; }
.mob-topbar__back .i { width: 22px; height: 22px; }
.mob-topbar__title { flex: 1; min-width: 0; }
.mob-topbar__name {
  font-weight: 600; font-size: 15px; letter-spacing: -0.012em; color: var(--ink);
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis; line-height: 1.25;
  background: none; border: none; padding: 0; text-align: left; cursor: pointer; width: 100%;
}
.mob-topbar__chips { display: flex; align-items: center; gap: 6px; min-height: 24px; }
.mob-topbar__pages { display: inline-flex; background: var(--surface-3); border: 1px solid var(--border); border-radius: var(--r-pill); padding: 2px; gap: 1px; }
.mob-topbar__page {
  width: 24px; height: 20px; display: inline-flex; align-items: center; justify-content: center;
  border-radius: var(--r-pill); background: transparent; border: none; color: var(--ink-3);
  font-family: var(--ff-mono); font-size: 11px; font-weight: 500; text-decoration: none;
}
.mob-topbar__page.active { background: var(--accent); color: var(--accent-on); }

.mob-tools {
  position: absolute; left: 50%; transform: translateX(-50%); bottom: 84px;
  display: none; gap: 2px; padding: 4px;
  background: var(--surface-1); border: 1px solid var(--border); border-radius: var(--r-3);
  box-shadow: var(--shadow-3); z-index: 45; animation: hint-in var(--dur) var(--ease);
}
.mob-tools::after {
  content: ""; position: absolute; bottom: -7px; left: 50%; transform: translateX(-50%) rotate(45deg);
  width: 12px; height: 12px; background: var(--surface-1);
  border-right: 1px solid var(--border); border-bottom: 1px solid var(--border);
}
.mob-tools .tool-btn { width: 44px; height: 44px; }
.mob-tools .tool-btn .tool-btn__kbd, .mob-tools .tool-btn__tip { display: none; }

.mob-dock {
  position: absolute; left: 0; right: 0; bottom: max(16px, env(safe-area-inset-bottom));
  padding: 0 12px; display: none; align-items: center; justify-content: center;
  gap: 8px; z-index: 40; pointer-events: none;
}
.mob-dock > * { pointer-events: auto; }
.mob-dock__pill {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  height: 44px; padding: 0 16px;
  background: color-mix(in srgb, var(--surface-1) 92%, transparent);
  backdrop-filter: saturate(180%) blur(20px); -webkit-backdrop-filter: saturate(180%) blur(20px);
  border: 1px solid color-mix(in srgb, var(--border-strong) 50%, transparent);
  border-radius: var(--r-pill); box-shadow: 0 6px 16px rgba(0,0,0,0.25), 0 2px 4px rgba(0,0,0,0.15);
  font-size: var(--fs-sm); font-weight: 500; color: var(--ink);
  flex: 1; min-width: 0; max-width: 160px; white-space: nowrap;
}
.mob-dock__pill .i { width: 18px; height: 18px; flex: none; }
.mob-dock__pill.active { background: var(--accent); color: var(--accent-on); border-color: var(--accent); }
.mob-dock__pill--cal { flex: 0 0 auto; max-width: none; width: 44px; padding: 0; color: var(--c-calibration); }
.mob-dock__pill--cal[aria-pressed="true"] { background: var(--c-calibration); border-color: var(--c-calibration); color: #fff; }
.mob-dock__pill--cal[data-no-scale="true"] { width: auto; padding: 0 14px; background: var(--c-calibration); color: #fff; border-color: var(--c-calibration); }
.mob-dock__pill--snap { flex: 0 0 auto; max-width: none; width: 44px; padding: 0; }
.mob-dock__pill--snap[aria-pressed="true"] { background: var(--accent); border-color: var(--accent); color: var(--accent-on); }
.mob-dock__pill--cal .calibrate-toggle-label { display: none; }
.mob-dock__pill--cal[data-no-scale="true"] .calibrate-toggle-label { display: inline; }
.mob-dock__count {
  background: var(--accent); color: var(--accent-on); font-family: var(--ff-mono);
  font-size: 10px; font-weight: 700; padding: 1px 6px; border-radius: 999px; margin-left: 2px;
}
.mob-dock__pill.active .mob-dock__count { background: rgba(0,0,0,0.18); }
.badge {
  background: var(--c-calibration); color: #fff; font-size: 10px; font-weight: 700;
  min-width: 16px; height: 16px; padding: 0 4px; border-radius: 999px;
  display: inline-flex; align-items: center; justify-content: center;
}
.tools-fab-caret { width: 14px; height: 14px; }

/* =========================================================================
   Modal (dialog-based, from modal.js)
   ========================================================================= */

.modal { padding: 0; border: none; background: transparent; max-width: none; max-height: none; color: var(--ink); }
.modal::backdrop { background: rgba(0,0,0,0.55); backdrop-filter: blur(4px); -webkit-backdrop-filter: blur(4px); }
.modal-form {
  width: min(440px, calc(100vw - 32px));
  background: var(--surface-1); border: 1px solid var(--border);
  border-radius: var(--r-4); box-shadow: var(--shadow-3); overflow: hidden;
  animation: modal-in var(--dur) var(--ease);
}
@keyframes modal-in { from { opacity: 0; transform: translateY(-8px) scale(0.98); } to { opacity: 1; transform: none; } }
.modal-head { display: flex; align-items: center; justify-content: space-between; padding: 14px 16px 6px; }
.modal-title { font-size: var(--fs-lg); font-weight: 600; }
.modal-body { padding: 6px 16px 14px; display: flex; flex-direction: column; gap: 12px; }
.modal-message { color: var(--ink-2); font-size: var(--fs-sm); line-height: 1.5; }
.modal-foot { display: flex; justify-content: flex-end; gap: 6px; padding: 12px 16px; border-top: 1px solid var(--divider); background: var(--surface-2); }

.form-row, .field { display: flex; flex-direction: column; gap: 4px; }
.form-label, .field__label { font-size: var(--fs-xs); color: var(--muted); text-transform: uppercase; letter-spacing: 0.06em; font-weight: 600; }
.form-row input, .form-row select, .input, .select, .modal input, .modal select {
  height: 32px; padding: 0 10px; background: var(--surface-2);
  border: 1px solid var(--border); border-radius: var(--r-2); color: var(--ink); font-size: var(--fs-base); width: 100%;
}
.modal input:focus, .modal select:focus, .form-row input:focus, .form-row select:focus {
  outline: none; border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-soft);
}
.input.invalid, .modal input.invalid { border-color: var(--danger); box-shadow: 0 0 0 3px var(--danger-soft); }
.input-group { display: flex; gap: 6px; }
.input-group input { flex: 1; }
.input-group select { width: auto; min-width: 72px; flex: none; }
.form-hint { font-size: var(--fs-xs); color: var(--muted); }
.form-hint.error { color: var(--danger); }
.form-hint strong { color: var(--ink-2); font-family: var(--ff-mono); }

.shortcuts-grid { display: grid; grid-template-columns: auto 1fr; gap: 8px 14px; align-items: center; }
.shortcuts-grid kbd { justify-self: start; }
.shortcuts-grid span { font-size: var(--fs-sm); color: var(--ink-2); }

/* =========================================================================
   Toast
   ========================================================================= */

.toast {
  position: fixed; left: 50%; bottom: 80px; transform: translateX(-50%) translateY(8px);
  display: inline-flex; align-items: center; gap: 8px;
  padding: 8px 14px; background: var(--ink); color: var(--bg);
  border-radius: var(--r-pill); font-size: var(--fs-sm); box-shadow: var(--shadow-2);
  z-index: 300; opacity: 0; pointer-events: none; transition: opacity var(--dur) var(--ease), transform var(--dur) var(--ease);
}
.toast.show { opacity: 1; transform: translateX(-50%) translateY(0); pointer-events: auto; }
.toast-close { background: none; border: none; color: var(--bg); font-size: 16px; line-height: 1; padding: 0 0 0 4px; }

/* =========================================================================
   App footer (backup.js) — identical markup/behavior on index.html and
   editor.html: Back up / Restore / storage used / About & privacy. Small
   and unobtrusive by design (PLAN.md M6) — a single row of muted text
   links, not a bar of buttons.
   ========================================================================= */

.app-footer {
  flex: none; display: flex; align-items: center; justify-content: center;
  flex-wrap: wrap; gap: 6px; padding: 8px 16px;
  border-top: 1px solid var(--divider); background: var(--surface-1);
  font-size: var(--fs-xs); color: var(--muted);
}
.app-footer__link {
  background: none; border: none; padding: 2px 1px; color: var(--muted);
  font-size: var(--fs-xs); font-family: var(--ff-sans); cursor: pointer;
}
.app-footer__link:hover { color: var(--ink-2); text-decoration: underline; }
.app-footer__dot { opacity: 0.6; }
.app-footer__usage-wrap { display: inline-flex; align-items: center; gap: 6px; }
.app-footer__usage { font-family: var(--ff-mono); }

/* =========================================================================
   Drawings list page
   ========================================================================= */

.list-page { position: absolute; inset: 0; background: var(--bg); overflow-y: auto; display: flex; flex-direction: column; }
.page-head {
  position: sticky; top: 0; z-index: 5;
  background: color-mix(in srgb, var(--bg) 95%, transparent);
  backdrop-filter: blur(12px); -webkit-backdrop-filter: blur(12px);
  display: flex; align-items: center; justify-content: space-between;
  padding: 16px 24px; border-bottom: 1px solid var(--border); gap: 12px;
}
.page-head h1 { font-size: var(--fs-xl); font-weight: 600; }
.page-sub { color: var(--muted); font-size: var(--fs-sm); margin-top: 1px; font-family: var(--ff-mono); }
.page-head__actions { display: flex; gap: 8px; align-items: center; }

.list-filters { display: flex; align-items: center; gap: 8px; padding: 12px 24px; border-bottom: 1px solid var(--divider); }
.list-search {
  flex: 1; max-width: 340px; display: flex; align-items: center; gap: 6px;
  padding: 0 10px; height: 30px; background: var(--surface-2);
  border: 1px solid var(--border); border-radius: var(--r-2); color: var(--muted);
}
.list-search .i { width: 16px; height: 16px; }
.list-search input { flex: 1; background: transparent; border: none; outline: none; font-size: var(--fs-sm); color: var(--ink); }
.list-filters__spacer { flex: 1; }

.list-body { padding: 16px 24px 64px; flex: 1; }

.upload-card {
  border: 1.5px dashed var(--border-strong); border-radius: var(--r-4);
  padding: 24px; margin-bottom: 20px;
  background:
    repeating-linear-gradient(45deg, transparent, transparent 12px, color-mix(in srgb, var(--accent) 4%, transparent) 12px, color-mix(in srgb, var(--accent) 4%, transparent) 13px),
    var(--surface-2);
  transition: border-color var(--dur) var(--ease);
}
.upload-card.is-dragover, .upload-card:hover { border-color: var(--accent); }
.dropzone { display: grid; grid-template-columns: 56px 1fr auto; align-items: center; gap: 16px; cursor: pointer; }
.dz-icon { width: 56px; height: 56px; background: var(--surface-1); border: 1px solid var(--border); border-radius: var(--r-3); padding: 14px; color: var(--accent); }
.dz-title { font-size: var(--fs-md); font-weight: 600; }
.dz-title .link { color: var(--accent-ink); }
.dz-sub { color: var(--muted); font-size: var(--fs-xs); font-family: var(--ff-mono); margin-top: 2px; }
.dz-camera { grid-column: 1 / -1; margin-top: 4px; }

.upload-meta { margin-top: 16px; display: flex; flex-direction: column; gap: 12px; }
.upload-file { display: flex; align-items: center; gap: 10px; }
.upload-file .file-icon { color: var(--accent); width: 24px; height: 24px; }
.upload-filename { font-weight: 600; font-size: var(--fs-sm); }
.upload-filesize { font-size: var(--fs-xs); font-family: var(--ff-mono); }
.upload-file > div { flex: 1; min-width: 0; }
.upload-progress { display: flex; flex-direction: column; gap: 4px; }
.upload-progress-bar { height: 6px; border-radius: var(--r-pill); background: var(--accent); width: 0%; transition: width 120ms linear; }
.upload-progress-label { font-size: var(--fs-xs); }
.form-actions { display: flex; justify-content: flex-end; }

.card-grid {
  list-style: none; margin: 0; padding: 0; display: grid;
  grid-template-columns: repeat(auto-fill, minmax(240px, 1fr)); gap: 16px;
}
.card {
  position: relative; background: var(--surface-1); border: 1px solid var(--border);
  border-radius: var(--r-3); overflow: hidden; display: flex; flex-direction: column;
  transition: transform var(--dur-fast) var(--ease), border-color var(--dur-fast) var(--ease), box-shadow var(--dur-fast) var(--ease);
}
.card:hover { border-color: var(--border-strong); transform: translateY(-1px); box-shadow: var(--shadow-2); }
.card-thumb {
  display: block; aspect-ratio: 4 / 3; position: relative; overflow: hidden;
  background: var(--canvas-paper); border-bottom: 1px solid var(--border);
}
.card-thumb img { width: 100%; height: 100%; object-fit: cover; display: block; }
.card-thumb-fallback { width: 100%; height: 100%; display: grid; place-items: center; color: var(--canvas-ink); }
.chip-floating {
  position: absolute; top: 8px; right: 8px; padding: 2px 6px;
  background: rgba(0,0,0,0.7); color: #fff; font-family: var(--ff-mono); font-size: 10px; border-radius: var(--r-1); border: none;
}
.card-body { padding: 10px 12px 12px; display: flex; flex-direction: column; gap: 6px; }
.card-title { font-size: var(--fs-base); font-weight: 600; color: var(--ink); text-decoration: none; }
.card-title:hover { color: var(--accent-ink); }
.card-meta { display: flex; gap: 6px; align-items: center; flex-wrap: wrap; }
.card-actions { position: absolute; top: 6px; left: 6px; }
.card-actions .icon-btn { background: color-mix(in srgb, var(--surface-1) 80%, transparent); }

.empty-state { padding: 64px 24px; text-align: center; color: var(--muted); }
.empty-state svg { color: var(--border-strong); margin-bottom: 12px; }
.empty-state h2 { color: var(--ink-2); margin-bottom: 6px; }

/* Card popover menu */
.popover-menu {
  position: absolute; min-width: 160px; padding: 4px;
  background: var(--surface-1); border: 1px solid var(--border-strong);
  border-radius: var(--r-3); box-shadow: var(--shadow-3); z-index: 300;
}
.popover-menu button {
  display: flex; align-items: center; gap: 8px; width: 100%;
  padding: 6px 8px; background: transparent; border: none; border-radius: var(--r-2);
  color: var(--ink); font-size: var(--fs-sm); text-align: left;
}
.popover-menu button:hover { background: var(--hover); }
.popover-menu button.danger { color: var(--danger); }
.popover-menu button.danger:hover { background: var(--danger-soft); }
.popover-menu .i { width: 18px; height: 18px; }

/* =========================================================================
   Responsive — mobile (≤768px)
   ========================================================================= */

@media (max-width: 768px) {
  .topbar, .toolrail, .statusbar, .panel__filter { display: none; }

  .mob-topbar { display: flex; }
  .mob-dock { display: flex; }
  .mob-tools:not([hidden]) { display: flex; }

  .editor__canvas-area {
    background:
      radial-gradient(circle at 50% 28%, color-mix(in srgb, var(--accent) 5%, transparent), transparent 55%),
      var(--canvas-bg);
  }

  .tool-hint { top: auto; bottom: 132px; font-size: var(--fs-xs); padding: 5px 12px; }
  .first-run { top: auto; bottom: 132px; max-width: calc(100% - 24px); }
  .action-bar { bottom: 132px; }

  /* Panel becomes a bottom sheet. When closed it sits at translateY(100%),
     top edge exactly on the viewport edge — iOS subpixel compositing leaves
     a sliver of the rounded top visible and the upward box-shadow always
     bleeds in, so flip to visibility:hidden once the slide-out finishes. */
  .panel {
    position: absolute; left: 0; right: 0; bottom: 0; width: auto;
    border-left: none; border-top: 1px solid var(--border);
    border-radius: 22px 22px 0 0; max-height: calc(100% - 80px); z-index: 60;
    box-shadow: 0 -20px 60px rgba(0,0,0,0.45); transform: translateY(100%);
    visibility: hidden;
    transition: transform var(--dur) var(--ease), visibility 0s var(--dur);
  }
  .editor.panel-open .panel {
    transform: translateY(0);
    visibility: visible;
    transition: transform var(--dur) var(--ease), visibility 0s;
  }
  .editor:not(.panel-open) .panel { width: auto; }
  .panel-grab { display: block; width: 44px; height: 5px; background: var(--border-strong); opacity: 0.65; border-radius: 999px; margin: 9px auto 2px; flex: none; }
  .measurement-row { min-height: 40px; padding: 6px 8px; }
  .row-btn { opacity: 1; }
}

/* Desktop: hide mobile-only chrome explicitly */
@media (min-width: 769px) {
  .mob-topbar, .mob-dock, .mob-tools { display: none !important; }
  .panel-grab { display: none; }
}

@media (max-width: 768px) {
  .page-head { flex-direction: column; align-items: stretch; padding: 14px 16px 12px; gap: 12px; }
  .page-head h1 { font-size: 22px; }
  .page-head__actions .btn { flex: 1; justify-content: center; height: 38px; }
  .list-filters { padding: 8px 16px 12px; }
  .list-search { max-width: none; height: 36px; border-radius: var(--r-pill); }
  .list-body { padding: 12px 16px 64px; }
  .dropzone { grid-template-columns: 44px 1fr; grid-template-areas: "icon text" "btn btn"; }
  .dz-icon { grid-area: icon; width: 44px; height: 44px; padding: 10px; border-radius: var(--r-2); }
  .dropzone > p.dz-title, .dropzone > p.dz-sub { grid-area: text; }
  .dz-camera { grid-area: btn; }
  .card-grid { grid-template-columns: 1fr; gap: 10px; }
  .card { display: grid; grid-template-columns: 108px 1fr; }
  .card:hover { transform: none; }
  .card-thumb { aspect-ratio: 1 / 1; border-bottom: none; border-right: 1px solid var(--border); }
  .card-actions { left: auto; right: 6px; }
}
