/* Lotron Inventory — mobile-first, light surface, Lotron-orange accents.
   Button rule (non-negotiable): a label is always high-contrast against its fill.
   On the orange fill the label is near-black (#1a0a04); secondary buttons use dark
   text on light with an orange border. Anchors styled as buttons set their colour with
   winning specificity so a global link colour can never make them orange-on-orange. */

:root {
  --accent: #C15F3C;        /* Lotron orange */
  --accent-ink: #1a0a04;    /* near-black label on orange fill */
  --accent-tint: #f6e3d9;   /* soft orange wash for selections */
  --ink: #241c17;           /* primary text */
  --muted: #6f655d;         /* secondary text */
  --surface: #ffffff;
  --bg: #f6f3ef;
  --line: #e3ddd6;
  --danger: #b3261e;
  --radius: 14px;
  --tap: 44px;              /* minimum tap target */
}

* { box-sizing: border-box; }

html, body { margin: 0; }

body {
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  color: var(--ink);
  background: var(--bg);
  -webkit-text-size-adjust: 100%;
  line-height: 1.4;
  /* keep content clear of notches/home indicators */
  padding-bottom: env(safe-area-inset-bottom);
}

/* Global link colour. The a.btn rules below have higher specificity (and load after),
   so a link styled as a button never inherits this orange. */
a:link, a:visited { color: var(--accent); }

.muted { color: var(--muted); }
.pad { padding: 16px; }

/* ── buttons ──────────────────────────────────────────────────────────────── */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 0.4em;
  min-height: var(--tap);
  padding: 0 16px;
  border: 1.5px solid transparent;
  border-radius: 12px;
  font: inherit;
  font-weight: 600;
  line-height: 1;
  text-decoration: none;
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
  transition: filter 0.12s ease, background 0.12s ease;
}
.btn:disabled { opacity: 0.5; cursor: not-allowed; }
.btn:active:not(:disabled) { filter: brightness(0.96); }

.btn-primary { background: var(--accent); color: var(--accent-ink); border-color: var(--accent); }
.btn-secondary { background: var(--surface); color: var(--ink); border-color: var(--accent); }
.btn-danger { background: var(--surface); color: var(--danger); border-color: var(--danger); }

.btn-block { width: 100%; }
.btn-sm { min-height: var(--tap); padding: 0 12px; font-size: 0.9rem; }

/* Anchor-as-button: beat the global a:link colour with winning specificity. */
a.btn:link, a.btn:visited { color: var(--accent-ink); text-decoration: none; }
a.btn.btn-secondary:link, a.btn.btn-secondary:visited { color: var(--ink); }
a.btn.btn-danger:link, a.btn.btn-danger:visited { color: var(--danger); }

/* template / filter chips */
.chip {
  min-height: var(--tap);
  padding: 0 14px;
  border: 1.5px solid var(--line);
  border-radius: 999px;
  background: var(--surface);
  color: var(--ink);
  font: inherit;
  font-weight: 600;
  font-size: 0.9rem;
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
}
.chip:active { background: var(--accent-tint); border-color: var(--accent); }

/* ── header ───────────────────────────────────────────────────────────────── */
.app-header {
  position: sticky;
  top: 0;
  z-index: 10;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  background: var(--surface);
  border-bottom: 1px solid var(--line);
  padding: calc(env(safe-area-inset-top) + 10px) max(14px, env(safe-area-inset-right)) 10px max(14px, env(safe-area-inset-left));
}
.hdr-left { display: flex; align-items: center; gap: 8px; min-width: 0; }
.hdr-title { font-weight: 700; font-size: 1.1rem; }
.crumb { font-weight: 600; font-size: 1.05rem; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.btn-back {
  display: inline-flex; align-items: center; justify-content: center;
  width: var(--tap); height: var(--tap);
  margin-left: -6px;
  border: none; background: transparent; border-radius: 12px;
  font-size: 1.9rem; line-height: 1; color: var(--ink); cursor: pointer;
}
.btn-back:active { background: var(--bg); }

/* ── login ────────────────────────────────────────────────────────────────── */
.login-wrap { min-height: 100vh; min-height: 100dvh; display: flex; align-items: center; justify-content: center; padding: 24px max(16px, env(safe-area-inset-right)) 24px max(16px, env(safe-area-inset-left)); }
.login { width: 100%; max-width: 380px; background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 24px; box-shadow: 0 8px 30px rgba(60, 40, 25, 0.08); }
.login-title { margin: 0 0 4px; font-size: 1.4rem; }
.login-sub { margin: 0 0 18px; color: var(--muted); }
.field {
  width: 100%; min-height: var(--tap);
  padding: 0 14px; margin-bottom: 12px;
  border: 1.5px solid var(--line); border-radius: 12px;
  font: inherit; background: var(--surface); color: var(--ink);
}
.field:focus { outline: none; border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-tint); }
.login-err { color: var(--danger); min-height: 1.2em; margin-bottom: 10px; font-size: 0.9rem; }

/* ── home ─────────────────────────────────────────────────────────────────── */
.home { padding: 16px max(16px, env(safe-area-inset-right)) 24px max(16px, env(safe-area-inset-left)); }
.empty { padding: 32px 16px; text-align: center; color: var(--muted); }
.card-grid { display: grid; grid-template-columns: 1fr; gap: 12px; }
@media (min-width: 560px) { .card-grid { grid-template-columns: 1fr 1fr; } }

.loc-card {
  display: flex; flex-direction: column; align-items: flex-start; gap: 4px;
  width: 100%; min-height: 96px; padding: 16px;
  text-align: left; cursor: pointer;
  background: var(--surface); border: 1px solid var(--line);
  border-left: 5px solid var(--accent); border-radius: var(--radius);
  font: inherit; color: var(--ink);
  box-shadow: 0 2px 8px rgba(60, 40, 25, 0.05);
}
.loc-card:active { background: #fffaf7; }
.loc-name { font-size: 1.15rem; font-weight: 700; }
/* Darker than --accent so small uppercase text clears WCAG AA (~5:1 on white). */
.loc-meta { color: #9C4626; font-weight: 600; font-size: 0.85rem; text-transform: uppercase; letter-spacing: 0.03em; }
.loc-dim { color: var(--muted); font-size: 0.95rem; }

/* ── location screen ──────────────────────────────────────────────────────── */
.loc-screen { display: flex; flex-direction: column; gap: 14px; padding: 14px max(14px, env(safe-area-inset-right)) 24px max(14px, env(safe-area-inset-left)); }
@media (min-width: 880px) {
  .loc-screen { flex-direction: row; align-items: flex-start; }
  .editor-pane { flex: 1 1 auto; min-width: 0; }
  .side-pane { flex: 0 0 360px; position: sticky; top: 78px; }
}

.editor-pane, .side-pane { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 12px; }

.side-empty { padding: 20px 8px; }
.side-head { display: flex; align-items: baseline; gap: 8px; margin-bottom: 10px; }
.side-title { font-size: 1.1rem; font-weight: 700; }
.side-kind { color: #9C4626; font-weight: 600; font-size: 0.8rem; text-transform: uppercase; letter-spacing: 0.03em; }
.elev-host { margin-bottom: 6px; }
.elev-selcap { min-height: 1.1em; font-size: 0.85rem; margin-bottom: 8px; }

.tree-list { margin: 4px 0 12px; }
.tree-level { font-weight: 600; padding: 6px 0 2px; border-top: 1px solid var(--line); }
.tree-level:first-child { border-top: none; }
.tree-conts { display: flex; flex-wrap: wrap; gap: 6px; padding: 2px 0 6px 10px; }
.tree-cont { display: inline-flex; align-items: center; min-height: 26px; padding: 2px 9px; border-radius: 8px; background: var(--accent-tint); color: var(--accent-ink); font-size: 0.82rem; font-weight: 600; }

/* ── 2D editor ────────────────────────────────────────────────────────────── */
.ed2d-toolbar { display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between; gap: 10px; margin-bottom: 8px; }
.ed2d-palette { display: flex; flex-wrap: wrap; gap: 8px; }
.ed2d-actions { display: flex; gap: 8px; }
.ed2d-hint { color: var(--muted); font-size: 0.9rem; padding: 4px 2px 8px; }
.ed2d-stage { overflow: auto; -webkit-overflow-scrolling: touch; }
.ed2d-svg { display: block; }

.unit-rect { fill: #fbeee6; stroke: #c9a18a; stroke-width: 1.5; }
.unit.selected .unit-rect { fill: var(--accent-tint); stroke: var(--accent); stroke-width: 2.5; }
.unit-label { fill: var(--ink); font-size: 13px; font-weight: 700; pointer-events: none; }
.unit-dim { fill: var(--muted); font-size: 10px; pointer-events: none; }

.handle { fill: #ffffff; stroke: var(--accent); stroke-width: 2.5; }
.handle-stem { stroke: var(--accent); stroke-width: 2; }
/* Visible handle art is non-interactive so taps fall through to the larger hit rings. */
.handle, .handle-stem { pointer-events: none; }
.grabbable { cursor: pointer; }
.resize-hit { cursor: nwse-resize; }
.rotate-hit { cursor: grab; }

/* ── elevation ────────────────────────────────────────────────────────────── */
.elev-toolbar { display: flex; flex-wrap: wrap; gap: 8px; margin-bottom: 8px; }
.elev-hint { color: var(--muted); font-size: 0.85rem; padding: 2px 2px 8px; }
.elev-stage { overflow: auto; -webkit-overflow-scrolling: touch; }
.elev-svg { display: block; }

.elev-outer { fill: #fbf7f3; stroke: #b9b2aa; stroke-width: 2; }
.elev-band { fill: #f1ece6; stroke: #cdc5bc; stroke-width: 1; }
.elev-band.selected { fill: var(--accent-tint); stroke: var(--accent); stroke-width: 2; }
.elev-band-label { fill: var(--muted); font-size: 11px; font-weight: 600; pointer-events: none; }
.elev-cont { fill: #e9eef0; stroke: #9bb0b8; stroke-width: 1; }
.elev-cont.selected { fill: #ffffff; stroke: var(--accent); stroke-width: 2.5; }
.elev-cont-label { fill: var(--ink); font-size: 11px; font-weight: 700; pointer-events: none; }
.elev-boundary { fill: transparent; cursor: ns-resize; }

/* ── misc ─────────────────────────────────────────────────────────────────── */
.errbox { margin: 16px; padding: 14px 16px; border: 1px solid #e7bdb9; background: #fbeceb; color: #7a1c16; border-radius: 12px; }

/* ── 3D viewer (M2) ───────────────────────────────────────────────────────────
   Full-screen overlay. The toolbar sits over the canvas; its buttons obey the
   non-negotiable contrast rule (near-black label on orange fill for primary /
   active; dark text on light with an orange border for secondary). */
body.viewer3d-open { overflow: hidden; }

.viewer3d {
  position: fixed;
  inset: 0;
  z-index: 50;
  background: var(--bg);
  overflow: hidden;
  touch-action: none;            /* the canvas drives its own gestures */
}
.viewer3d-stage { position: absolute; inset: 0; }
.viewer3d-stage canvas.v3d-canvas { display: block; width: 100% !important; height: 100% !important; }
.viewer3d-stage .v3d-labels { pointer-events: none; }

/* Top toolbar: a translucent strip, safe-area aware, wraps on narrow phones. */
.viewer3d-bar {
  position: absolute;
  top: 0; left: 0; right: 0;
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 8px;
  padding: calc(env(safe-area-inset-top) + 10px) max(12px, env(safe-area-inset-right)) 10px max(12px, env(safe-area-inset-left));
  background: rgba(255, 255, 255, 0.92);
  border-bottom: 1px solid var(--line);
  box-shadow: 0 2px 10px rgba(60, 40, 25, 0.08);
}
.viewer3d-bar .v3d-x { min-width: var(--tap); padding: 0 12px; font-size: 1.05rem; }

.v3d-chips { display: flex; flex-wrap: wrap; gap: 6px; }
.v3d-chip { min-height: 38px; padding: 0 12px; font-size: 0.85rem; }
/* Active tier chip: orange fill, near-black label (contrast rule). */
.v3d-chip.chip-on { background: var(--accent); color: var(--accent-ink); border-color: var(--accent); }

.v3d-explode { display: inline-flex; align-items: center; gap: 8px; margin-left: auto; }
.v3d-explode-label { color: var(--muted); font-size: 0.8rem; font-weight: 600; text-transform: uppercase; letter-spacing: 0.03em; }
.v3d-slider { width: clamp(96px, 28vw, 180px); accent-color: var(--accent); height: var(--tap); cursor: pointer; }

/* CSS2D labels — readable pill, never intercept taps. */
.css2d-label {
  pointer-events: none;
  padding: 3px 9px;
  border-radius: 999px;
  background: rgba(36, 28, 23, 0.9);
  color: #fff;
  font: 600 12px/1.1 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  white-space: nowrap;
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.25);
  border: 1px solid rgba(255, 255, 255, 0.18);
  transform: translateY(-2px);
}

.viewer3d-empty {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px;
  pointer-events: none;
}
.viewer3d-empty-card {
  pointer-events: none;
  max-width: 320px;
  padding: 16px 18px;
  text-align: center;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: 0 6px 24px rgba(60, 40, 25, 0.10);
}
.viewer3d-loading { position: absolute; inset: 0; display: flex; align-items: center; justify-content: center; }

/* ── "Map a space" capture (M3, Pass A) ─────────────────────────────────────
   The location-screen CTA bar, plus a dismissible photo-capture / analysis modal.
   Buttons reuse .btn-primary (near-black label on orange fill) and .btn-secondary
   (dark label on light with an orange border), so the non-negotiable contrast rule
   holds in every state. */

/* CTA bar above the floor plan. Full-width on phones for prominence, natural on tablet+. */
.loc-toolbar { display: flex; flex-wrap: wrap; gap: 10px; margin-bottom: 12px; }
.loc-toolbar .btn { flex: 1 1 auto; }
@media (min-width: 560px) { .loc-toolbar .btn { flex: 0 0 auto; } }

.cap-overlay {
  position: fixed;
  inset: 0;
  z-index: 60;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: max(16px, env(safe-area-inset-top)) max(16px, env(safe-area-inset-right)) max(16px, env(safe-area-inset-bottom)) max(16px, env(safe-area-inset-left));
  background: rgba(36, 28, 23, 0.55);
}
body.cap-open { overflow: hidden; }

.cap-card {
  position: relative;
  width: 100%;
  max-width: 420px;
  max-height: 92dvh;
  overflow: auto;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 20px;
  box-shadow: 0 16px 50px rgba(36, 28, 23, 0.30);
}
.cap-x {
  position: absolute;
  top: 8px; right: 8px;
  display: inline-flex; align-items: center; justify-content: center;
  width: var(--tap); height: var(--tap);
  border: none; background: transparent; border-radius: 12px;
  font-size: 1.2rem; line-height: 1; color: var(--muted); cursor: pointer;
  -webkit-tap-highlight-color: transparent;
}
.cap-x:active { background: var(--bg); }

.cap-body { min-width: 0; }
.cap-title { margin: 0 0 12px; font-size: 1.2rem; padding-right: 36px; }
.cap-title-center { padding-right: 0; text-align: center; }

.cap-preview {
  display: block;
  width: 100%;
  max-height: 46dvh;
  object-fit: contain;
  background: #000;
  border: 1px solid var(--line);
  border-radius: 12px;
}

.cap-status { margin: 12px 0 0; }
.cap-title-center + .cap-status { text-align: center; }

/* "PC isn't responding" reassurance — a soft warm callout. Hidden until it has text. */
.cap-asleep {
  margin: 12px 0 0;
  padding: 10px 12px;
  background: var(--accent-tint);
  color: #7a2e12;            /* dark warm text on the light tint — AA contrast */
  border-radius: 10px;
  font-size: 0.9rem;
  font-weight: 600;
  text-align: center;
}
.cap-asleep:empty { display: none; }

.cap-error { margin: 0 0 4px; color: var(--danger); font-weight: 600; }

.cap-actions { display: flex; gap: 10px; margin-top: 16px; }
.cap-actions .btn { flex: 1 1 0; }

.cap-spinner {
  width: 42px; height: 42px;
  margin: 6px auto 14px;
  border: 4px solid var(--line);
  border-top-color: var(--accent);
  border-radius: 50%;
  animation: cap-spin 0.8s linear infinite;
}
@keyframes cap-spin { to { transform: rotate(360deg); } }
@media (prefers-reduced-motion: reduce) { .cap-spinner { animation-duration: 2.4s; } }
