/* Layout: desktop planning app. Ribbon of grouped tools on top, 2D plan and 3D view side by side with a draggable divider, status bar at the bottom. Stacks plan over 3D on phones. */
:root {
  --ground: #e7ebe8;
  --chrome: #f7f8f6;
  --chrome-2: #eef1ee;
  --text: #18232b;
  --muted: #5d6a72;
  --line: rgba(24, 35, 43, 0.13);
  --accent: #1d6a61;
  --accent-ink: #ffffff;
  --hi: #1d9e8f;
  --hover: rgba(29, 106, 97, 0.1);
  --roof-teal: #1d6a61;
  --roof-terra: #c5573c;
  --shadow: 0 1px 2px rgba(20, 30, 40, 0.07), 0 6px 18px rgba(20, 30, 40, 0.07);

  --font-display: "Bricolage Grotesque", "Avenir Next", "Segoe UI", system-ui, sans-serif;
  --font-body: "IBM Plex Sans", "Segoe UI", system-ui, -apple-system, sans-serif;
  --font-mono: "IBM Plex Mono", ui-monospace, "SFMono-Regular", Menlo, Consolas, monospace;
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --ground: #10171a;
    --chrome: #172024;
    --chrome-2: #1c272c;
    --text: #e3ece9;
    --muted: #9aaeab;
    --line: rgba(227, 236, 233, 0.12);
    --accent: #63b8ab;
    --accent-ink: #08201c;
    --hi: #4fc3b3;
    --hover: rgba(99, 184, 171, 0.13);
    --roof-teal: #63b8ab;
    --roof-terra: #e07a5f;
    --shadow: 0 1px 2px rgba(0, 0, 0, 0.3), 0 6px 18px rgba(0, 0, 0, 0.3);
    color-scheme: dark;
  }
}
:root[data-theme="dark"] {
  --ground: #10171a;
  --chrome: #172024;
  --chrome-2: #1c272c;
  --text: #e3ece9;
  --muted: #9aaeab;
  --line: rgba(227, 236, 233, 0.12);
  --accent: #63b8ab;
  --accent-ink: #08201c;
  --hi: #4fc3b3;
  --hover: rgba(99, 184, 171, 0.13);
  --roof-teal: #63b8ab;
  --roof-terra: #e07a5f;
  --shadow: 0 1px 2px rgba(0, 0, 0, 0.3), 0 6px 18px rgba(0, 0, 0, 0.3);
  color-scheme: dark;
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }
html, body { height: 100%; }
body {
  margin: 0;
  overflow: hidden;
  background: var(--ground);
  color: var(--text);
  font: 14px/1.4 var(--font-body);
  padding-left: max(16px, env(safe-area-inset-left, 0px));
  padding-right: max(16px, env(safe-area-inset-right, 0px));
  -webkit-font-smoothing: antialiased;
}

.app {
  height: 100%;
  display: grid;
  grid-template-rows: auto minmax(0, 1fr) auto;
  gap: 10px;
  padding-block: 10px;
}

/* ---------- ribbon ---------- */

.ribbon {
  display: flex;
  align-items: stretch;
  gap: 16px;
  padding: 8px 10px 4px 16px;
  background: var(--chrome);
  border: 1px solid var(--line);
  border-radius: 12px;
  box-shadow: var(--shadow);
  min-width: 0;
}
.brand {
  flex: none;
  display: grid;
  align-content: center;
  gap: 2px;
  padding-right: 16px;
  margin-bottom: 4px;
  border-right: 1px solid var(--line);
}
.eyebrow {
  margin: 0;
  font: 500 10.5px/1 var(--font-mono);
  letter-spacing: 0.12em;
  text-transform: uppercase;
  color: var(--accent);
}
h1 { margin: 0; font: 700 22px/1.1 var(--font-display); letter-spacing: -0.01em; }

.groups {
  display: flex;
  gap: 0;
  min-width: 0;
  overflow-x: auto;
  scrollbar-width: thin;
}
.group {
  flex: none;
  display: flex;
  flex-direction: column;
  padding: 0 10px;
  border-right: 1px solid var(--line);
}
.group:last-child { border-right: 0; }
.group .tools { display: flex; gap: 2px; flex: 1; }
.caption {
  margin: 2px 0 0;
  text-align: center;
  font: 500 10.5px/1.4 var(--font-body);
  color: var(--muted);
}

.tool {
  min-width: 52px;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 3px;
  padding: 6px 6px 5px;
  border: 1px solid transparent;
  border-radius: 8px;
  background: transparent;
  color: var(--text);
  font: 500 11.5px/1.15 var(--font-body);
  text-decoration: none;
  cursor: pointer;
  white-space: nowrap;
}
.tool svg {
  width: 22px;
  height: 22px;
  fill: none;
  stroke: currentColor;
  stroke-width: 1.6;
  stroke-linecap: round;
  stroke-linejoin: round;
}
.tool:hover { background: var(--hover); }
.tool[aria-pressed="true"] {
  background: var(--hover);
  border-color: var(--accent);
  color: var(--accent);
}
.tool .sw-teal { stroke: var(--roof-teal); stroke-width: 3; }
.tool .sw-terra { stroke: var(--roof-terra); stroke-width: 3; }

/* ---------- work area ---------- */

.work {
  --split: 50%;
  min-height: 0;
  display: grid;
  grid-template-columns: minmax(0, var(--split)) 10px minmax(0, 1fr);
}
.work[data-layout="plan"] { grid-template-columns: minmax(0, 1fr) 0 0; }
.work[data-layout="3d"] { grid-template-columns: 0 0 minmax(0, 1fr); }
.work[data-layout="plan"] .pane-3d,
.work[data-layout="plan"] .divider,
.work[data-layout="3d"] .pane-plan,
.work[data-layout="3d"] .divider { visibility: hidden; }

.pane {
  min-width: 0;
  min-height: 0;
  display: flex;
  flex-direction: column;
  background: var(--chrome);
  border: 1px solid var(--line);
  border-radius: 12px;
  overflow: hidden;
  box-shadow: var(--shadow);
}
.pane-head {
  flex: none;
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 8px 10px 8px 14px;
  border-bottom: 1px solid var(--line);
  background: var(--chrome-2);
  min-width: 0;
}
.pane-title { font: 600 13px/1.2 var(--font-body); white-space: nowrap; }
.pane-sub { font: 400 12px/1.2 var(--font-mono); color: var(--muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.spacer { flex: 1; }
.hint { font: 400 11.5px/1.2 var(--font-mono); color: var(--muted); white-space: nowrap; }
.mini {
  min-width: 30px;
  padding: 4px 8px;
  border: 1px solid var(--line);
  border-radius: 7px;
  background: var(--chrome);
  color: var(--text);
  font: 500 12.5px/1 var(--font-body);
  cursor: pointer;
}
.mini:hover { background: var(--hover); }

.plan-host, .view-host { position: relative; flex: 1; min-height: 0; }
.plan-host { background: #f4f6f5; }
.plan { display: block; width: 100%; height: 100%; touch-action: none; cursor: grab; user-select: none; }
.plan.is-panning { cursor: grabbing; }
.plan .room { cursor: pointer; }
.plan .room-hit { transition: fill 0.12s; }
.plan .room.is-hover .room-hit { fill: rgba(29, 158, 143, 0.16); stroke: #1d9e8f; stroke-width: 0.04; }
.plan .room.is-selected .room-hit { fill: rgba(29, 158, 143, 0.28); stroke: #1d6a61; stroke-width: 0.07; }
.plan .handle { cursor: move; }
.plan .handle:focus-visible circle:first-child { stroke: #f2b134; }

.north {
  position: absolute;
  top: 10px;
  right: 10px;
  width: 38px;
  display: grid;
  justify-items: center;
  pointer-events: none;
  color: #2a2f38;
  font: 600 11px/1 var(--font-mono);
}
.north svg { width: 34px; height: 34px; }
.north circle { fill: rgba(255, 255, 255, 0.85); stroke: #2a2f38; stroke-width: 1.4; }
.north path { fill: #2a2f38; }

.view-host canvas { display: block; touch-action: none; }
.label-layer { position: absolute; inset: 0; pointer-events: none; }
.room-label {
  display: grid;
  justify-items: center;
  padding: 4px 8px;
  border-radius: 7px;
  background: rgba(247, 248, 246, 0.9);
  border: 1px solid rgba(24, 35, 43, 0.15);
  color: #18232b;
  white-space: nowrap;
  box-shadow: 0 2px 6px rgba(0, 0, 0, 0.12);
}
.room-label b { font: 600 10.5px/1.2 var(--font-mono); letter-spacing: 0.06em; text-transform: uppercase; }
.room-label span { font: 400 10.5px/1.2 var(--font-mono); color: #5d6a72; }
.room-label.is-active { border-color: #1d6a61; box-shadow: 0 0 0 2px #1d9e8f; }

.divider {
  cursor: col-resize;
  position: relative;
  touch-action: none;
}
.divider::after {
  content: "";
  position: absolute;
  inset: 30% 3px;
  border-radius: 4px;
  background: var(--line);
  transition: background 0.15s;
}
.divider:hover::after, .divider.is-dragging::after, .divider:focus-visible::after { background: var(--accent); }

/* ---------- status bar ---------- */

.status {
  display: flex;
  gap: 0;
  align-items: center;
  min-width: 0;
  padding: 6px 4px;
  background: var(--chrome);
  border: 1px solid var(--line);
  border-radius: 10px;
  font: 400 12px/1.3 var(--font-mono);
  color: var(--muted);
  font-variant-numeric: tabular-nums;
}
.status .cell { padding: 0 12px; border-right: 1px solid var(--line); white-space: nowrap; }
.status .cell:last-child { border-right: 0; }
.status .grow { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; color: var(--text); }

button:focus-visible, a:focus-visible, .divider:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
.noscript { position: fixed; inset: 40% 16px auto; text-align: center; }

/* ---------- narrow screens: plan above 3D ---------- */

@media (max-width: 860px) {
  .app { gap: 8px; padding-block: 8px; }
  .ribbon { flex-direction: column; gap: 6px; padding: 8px 8px 4px; }
  .brand { flex-direction: row; border-right: 0; padding-right: 0; margin-bottom: 0; }
  h1 { font-size: 18px; }
  .caption { display: none; }
  .tool { min-width: 46px; padding: 5px 4px; font-size: 10.5px; }
  .tool svg { width: 20px; height: 20px; }
  .group { padding: 0 6px; }
  .work {
    grid-template-columns: minmax(0, 1fr);
    grid-template-rows: minmax(0, var(--split)) 12px minmax(0, 1fr);
  }
  .work[data-layout="plan"] { grid-template-columns: minmax(0, 1fr); grid-template-rows: minmax(0, 1fr) 0 0; }
  .work[data-layout="3d"] { grid-template-columns: minmax(0, 1fr); grid-template-rows: 0 0 minmax(0, 1fr); }
  .divider { cursor: row-resize; }
  .divider::after { inset: 4px 35%; }
  .hint, .pane-sub { display: none; }
  #stCursor, #stZoom { display: none; }
}

@media (prefers-reduced-motion: reduce) {
  * { transition: none !important; }
}
