:root {
  --paper: oklch(0.965 0.012 85);
  --panel: oklch(0.98 0.008 85);
  --ink: oklch(0.3 0.018 55);
  --muted: oklch(0.48 0.02 60);
  --line: oklch(0.86 0.012 80);
  --accent: oklch(0.38 0.055 160);
  --accent-ink: oklch(0.97 0.01 85);
  --warn: oklch(0.45 0.08 35);
  --locked: oklch(0.55 0.015 70);
  --focus: oklch(0.38 0.055 160);
  --selected: oklch(0.92 0.03 150);
  --header-h: 3.1rem;
  --inspector-w: 280px;
  --sidebar-w: 200px;
  --touch: 44px;
  --status-h: 1.85rem;
}

*,
*::before,
*::after {
  box-sizing: border-box;
}

[hidden] {
  display: none !important;
}

html,
body {
  margin: 0;
  min-height: 100%;
  height: 100%;
  overflow: hidden;
  overflow-x: hidden;
  background: var(--paper);
  color: var(--ink);
  font-family: "SF Pro Text", "Segoe UI", system-ui, sans-serif;
  font-size: 15px;
  line-height: 1.4;
  max-width: 100%;
}

body {
  display: grid;
  grid-template-rows: auto minmax(0, 1fr) auto;
  min-height: 100dvh;
  height: 100dvh;
}

h1,
h2,
h3 {
  font-weight: 600;
  letter-spacing: 0;
  margin: 0;
}

h1 {
  font-size: 0.98rem;
  font-weight: 650;
}

h2 {
  font-size: 0.78rem;
  color: var(--muted);
}

h3 {
  font-size: 0.88rem;
  margin-bottom: 0.35rem;
  color: var(--ink);
}

button,
input,
select,
summary {
  font: inherit;
  color: inherit;
}

button {
  min-height: var(--touch);
  padding: 0 0.7rem;
  border: 0;
  background: transparent;
  border-radius: 2px;
  cursor: pointer;
  border-bottom: 1px solid transparent;
}

button:hover {
  color: var(--accent);
}

button:active {
  transform: translateY(1px);
}

button[aria-pressed="true"],
.floor-tab.is-active {
  color: var(--accent);
  border-bottom-color: var(--accent);
  font-weight: 600;
}

button:disabled {
  opacity: 0.45;
  cursor: not-allowed;
  transform: none;
}

.button-primary {
  background: var(--accent);
  color: var(--accent-ink);
  min-height: var(--touch);
  padding: 0 1rem;
}

.button-primary:hover {
  color: var(--accent-ink);
  filter: brightness(1.05);
}

button:focus-visible,
input:focus-visible,
a:focus-visible,
svg:focus-visible,
summary:focus-visible {
  outline: 2px solid var(--focus);
  outline-offset: 2px;
}

input {
  min-height: var(--touch);
  width: 100%;
  max-width: 100%;
  border: 0;
  border-bottom: 1px solid var(--line);
  background: transparent;
  padding: 0 0.15rem;
  font-variant-numeric: tabular-nums;
}

input:disabled {
  color: var(--locked);
}

.skip-link {
  position: absolute;
  left: 0.5rem;
  top: -3rem;
  background: var(--accent);
  color: var(--accent-ink);
  padding: 0.5rem 0.8rem;
  z-index: 20;
}

.skip-link:focus {
  top: 0.5rem;
}

.app-header {
  display: grid;
  grid-template-columns: auto auto auto minmax(0, 1fr) auto;
  gap: 0.35rem 0.85rem;
  align-items: center;
  padding: 0.2rem 0.75rem;
  border-bottom: 1px solid var(--line);
  background: var(--panel);
  min-height: var(--header-h);
  min-width: 0;
  max-width: 100%;
  position: relative;
  z-index: 20;
}

.brand {
  display: flex;
  flex-direction: column;
  gap: 0;
  min-width: 0;
}

.brand-kicker {
  margin: 0;
  font-size: 0.68rem;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--muted);
}

.scale-banner {
  margin: 0;
  font-size: 0.76rem;
  color: var(--muted);
}

.floor-nav,
.header-tools,
.view-switcher {
  display: flex;
  gap: 0.1rem;
  align-items: center;
  flex-wrap: nowrap;
  min-width: 0;
}

.view-switcher {
  justify-content: flex-start;
  max-width: 100%;
}

.save-state {
  margin: 0;
  font-size: 0.7rem;
  color: var(--muted);
}

.save-state.is-error {
  color: var(--warn);
}

.workspace {
  display: grid;
  grid-template-columns: minmax(0, 1fr);
  min-height: 0;
  min-width: 0;
}

.workspace.has-sidebar.has-inspector {
  grid-template-columns: var(--sidebar-w) minmax(0, 1fr) var(--inspector-w);
}

.workspace.has-sidebar:not(.has-inspector) {
  grid-template-columns: var(--sidebar-w) minmax(0, 1fr);
}

.workspace.has-inspector:not(.has-sidebar) {
  grid-template-columns: minmax(0, 1fr) var(--inspector-w);
}

.sidebar,
.inspector {
  background: var(--panel);
  padding: 0.55rem 0.75rem 0.85rem;
  overflow: auto;
  min-height: 0;
}

.sidebar {
  border-right: 1px solid var(--line);
  width: var(--sidebar-w);
}

.inspector {
  border-left: 1px solid var(--line);
  width: var(--inspector-w);
  max-width: 320px;
}

.inspector-peek {
  display: flex;
  flex-direction: column;
  gap: 0.1rem;
}

.selection-summary {
  min-width: 0;
}

.sheet-toolbar,
#edit-measures,
#close-inspector,
#close-inventory {
  display: none;
}

.sheet-heading {
  margin: 0;
  font-size: 0.78rem;
  color: var(--muted);
}

.sheet-close {
  min-height: var(--touch);
  min-width: var(--touch);
  padding: 0 0.75rem;
  border: 1px solid var(--line);
  font-weight: 600;
}

.drawer {
  border-bottom: 1px solid var(--line);
  padding: 0.35rem 0 0.55rem;
}

.drawer:last-child {
  border-bottom: 0;
}

.drawer summary {
  min-height: var(--touch);
  display: flex;
  align-items: center;
  cursor: pointer;
  font-size: 0.78rem;
  color: var(--muted);
  list-style: none;
}

.drawer summary::-webkit-details-marker {
  display: none;
}

.hint,
.meta,
.notes,
.source,
.legend,
.parking,
.status-bar {
  color: var(--muted);
  font-size: 0.8rem;
}

.item-list {
  list-style: none;
  margin: 0.15rem 0 0;
  padding: 0;
}

.item-list button {
  width: 100%;
  text-align: left;
  margin: 0;
  padding: 0.2rem 0.12rem;
  display: grid;
  grid-template-columns: 1rem minmax(0, 1fr) auto;
  gap: 0.35rem;
  align-items: center;
  font-variant-numeric: tabular-nums;
  min-height: 2.15rem;
}

.item-name {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.item-list button[aria-current="true"] {
  background: var(--selected);
  color: var(--ink);
  border-bottom-color: transparent;
}

.item-icon {
  width: 1rem;
  height: 1rem;
  stroke: currentColor;
  fill: none;
  stroke-width: 1.6;
}

.item-list .dim {
  color: var(--muted);
  font-size: 0.72rem;
  font-variant-numeric: tabular-nums;
  white-space: nowrap;
}

.item-list .fixed-mark {
  font-size: 0.65rem;
  color: var(--warn);
}

.viewport {
  display: grid;
  grid-template-columns: minmax(0, 1fr);
  grid-template-rows: minmax(0, 1fr);
  min-width: 0;
  min-height: 0;
}

.viewport.is-split {
  grid-template-columns: minmax(0, 1fr) minmax(0, 1fr);
}

.panel {
  display: flex;
  flex-direction: column;
  min-height: 0;
  min-width: 0;
}

.viewport.is-split .plan-panel {
  border-right: 1px solid var(--line);
}

.panel-toolbar {
  display: flex;
  flex-wrap: wrap;
  gap: 0.2rem 0.5rem;
  align-items: center;
  padding: 0.1rem 0.45rem;
  border-bottom: 1px solid var(--line);
  min-height: var(--touch);
  max-width: 100%;
  /* Menus must extend over the canvas, not be clipped by a scroll container. */
  overflow: visible;
  flex-shrink: 0;
}

.toolbar-group {
  display: flex;
  flex-wrap: nowrap;
  gap: 0.08rem;
}

.toolbar-more,
.more-menu {
  position: relative;
}

.toolbar-more summary,
.more-menu summary {
  min-height: var(--touch);
  display: flex;
  align-items: center;
  padding: 0 0.65rem;
  cursor: pointer;
  list-style: none;
}

.toolbar-more summary::-webkit-details-marker,
.more-menu summary::-webkit-details-marker {
  display: none;
}

.toolbar-more-panel,
.more-menu-panel {
  position: absolute;
  right: 0;
  top: calc(100% - 2px);
  z-index: 30;
  background: var(--panel);
  border: 1px solid var(--line);
  min-width: 12rem;
  padding: 0.25rem;
  display: flex;
  flex-direction: column;
  box-shadow: 0 8px 24px oklch(0.4 0.02 55 / 0.12);
}

.plan-wrap,
.scene-wrap {
  position: relative;
  flex: 1;
  min-height: 300px;
  background: oklch(0.94 0.014 82);
}

#plan-svg,
#scene-canvas {
  width: 100%;
  height: 100%;
  display: block;
}

#plan-svg {
  touch-action: pan-y;
}

.legend {
  position: absolute;
  left: 0.55rem;
  bottom: 0.35rem;
  margin: 0;
  padding: 0;
  background: transparent;
}

.atmosphere-panel {
  min-height: 0;
  padding: 0.5rem 0.9rem 0.55rem;
  overflow: hidden;
  display: flex;
  flex-direction: column;
}

.atmosphere-figure {
  margin: 0;
  flex: 1;
  min-height: 0;
  display: flex;
  flex-direction: column;
  max-width: none;
  height: 100%;
}

.atmosphere-figure img {
  display: block;
  width: 100%;
  flex: 1;
  min-height: 0;
  height: 100%;
  object-fit: contain;
  object-position: center;
}

.atmosphere-figure figcaption {
  margin-top: 0.45rem;
  color: var(--muted);
  max-width: 72ch;
  flex: 0 0 auto;
}

.measure-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 0.4rem 0.55rem;
}

.field span,
.check {
  display: block;
  font-size: 0.74rem;
  color: var(--muted);
  margin-bottom: 0.1rem;
}

.check {
  display: flex;
  align-items: center;
  gap: 0.45rem;
  min-height: var(--touch);
}

.check input {
  width: 1.1rem;
  min-height: 1.1rem;
}

.inspector-actions,
.stack-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 0.3rem;
  margin-top: 0.55rem;
  align-items: center;
}

.nudge-group {
  display: flex;
  gap: 0.1rem;
}

.file-button {
  position: relative;
  overflow: hidden;
  display: inline-flex;
  align-items: center;
  min-height: var(--touch);
  padding: 0 0.7rem;
  cursor: pointer;
}

.file-button input {
  position: absolute;
  inset: 0;
  opacity: 0;
  cursor: pointer;
}

.certainty {
  font-size: 0.75rem;
  margin: 0.1rem 0 0.4rem;
  color: var(--muted);
}

.certainty.is-locked {
  color: var(--warn);
}

.form-error {
  min-height: 1.1rem;
  color: var(--warn);
  margin: 0.2rem 0 0;
}

.conflict-list {
  margin: 0;
  padding-left: 1.05rem;
}

.conflict-list li {
  margin: 0.25rem 0;
}

.empty-state {
  color: var(--muted);
  margin-top: 0.5rem;
}

.variant-panel {
  margin: 0.6rem 0;
  padding-top: 0.5rem;
  border-top: 1px solid var(--line);
}

.status-bar {
  margin: 0;
  padding: 0.2rem 0.85rem;
  border-top: 1px solid var(--line);
  background: var(--panel);
  font-variant-numeric: tabular-nums;
  min-height: var(--status-h);
}

.webgl-banner {
  margin: 0 0 0 0.4rem;
  padding: 0;
  color: var(--warn);
  flex: 1 1 8rem;
}

.app-dialog {
  border: 1px solid var(--line);
  background: var(--panel);
  color: var(--ink);
  max-width: 32rem;
  padding: 1.1rem 1.15rem;
}

.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  overflow: hidden;
  clip: rect(0 0 0 0);
}

.sheet-backdrop {
  position: fixed;
  inset: 0;
  background: oklch(0.25 0.02 55 / 0.28);
  z-index: 16;
}

.plan-room {
  fill: oklch(0.97 0.012 85);
  stroke: none;
}

.is-overlay .plan-room {
  fill-opacity: 0.18;
}

.plan-room-label,
.plan-room-area,
.plan-item-label,
.plan-fixed-label {
  font-size: 10px;
  fill: oklch(0.38 0.02 55);
  text-anchor: middle;
  pointer-events: none;
  font-variant-numeric: tabular-nums;
}

.plan-dim-label,
.plan-cota,
.plan-ruler-label {
  font-size: 10px;
  fill: #2b2824;
  stroke: #fbf8f2;
  stroke-width: 2px;
  paint-order: stroke fill;
  text-anchor: middle;
  pointer-events: none;
  font-variant-numeric: tabular-nums;
}

.plan-wall {
  fill: oklch(0.32 0.015 55);
}

.plan-window {
  stroke: oklch(0.62 0.04 230);
  stroke-width: 1.6;
}

.plan-door {
  stroke: oklch(0.32 0.015 55);
  stroke-width: 1.3;
}

.plan-door-arc {
  stroke: oklch(0.55 0.02 60);
  stroke-dasharray: 3 3;
}

.plan-fixed {
  fill: oklch(0.88 0.012 80);
  stroke: oklch(0.58 0.015 60);
}

.plan-path,
.plan-path-dash {
  stroke: oklch(0.5 0.015 60);
  fill: none;
}

.plan-path-dash {
  stroke-dasharray: 4 3;
}

.plan-grid-line {
  stroke: oklch(0.9 0.014 80);
  stroke-width: 0.35;
}

.plan-item-shape {
  fill: oklch(0.82 0.018 80);
  stroke: oklch(0.35 0.018 55);
  stroke-width: 0.85;
  cursor: pointer;
  touch-action: none;
}

.plan-item.is-selected .plan-item-shape {
  fill: var(--selected);
  stroke: var(--accent);
  stroke-width: 1.7;
}

.plan-item.is-conflict .plan-item-shape {
  fill: oklch(0.9 0.03 40);
}

.plan-item.is-fixed .plan-item-shape {
  fill: oklch(0.86 0.012 80);
  stroke-dasharray: 3 2;
}

.plan-mattress {
  fill: oklch(0.95 0.012 85);
  stroke: oklch(0.58 0.02 60);
}

.plan-vehicle-body {
  fill: none;
  stroke: oklch(0.32 0.015 55);
}

.plan-glyph {
  fill: none;
  stroke: oklch(0.38 0.02 55);
  stroke-width: 1.1;
}

.plan-glyph-front {
  fill: oklch(0.55 0.04 160);
  stroke: none;
}

.plan-cooktop,
.plan-sink {
  fill: none;
  stroke: oklch(0.45 0.015 55);
}

.plan-dim,
.plan-ruler {
  stroke: oklch(0.92 0.01 80);
  fill: none;
}

.plan-endpoint {
  fill: var(--accent);
}

.plan-hit {
  fill: transparent;
}

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

@media (min-width: 981px) {
  #toggle-inventory,
  #toggle-inspector,
  #edit-measures,
  #close-inspector,
  #close-inventory,
  .sheet-toolbar {
    display: none;
  }
}

@media (max-width: 980px) {
  html,
  body {
    height: 100%;
    overflow: hidden;
  }

  .app-header {
    grid-template-columns: auto minmax(0, 1fr) auto;
    grid-template-areas:
      "brand floors tools"
      "views views views";
    gap: 0.05rem 0.35rem;
    padding: 0.1rem 0.4rem;
    z-index: 22;
  }

  .brand {
    grid-area: brand;
  }

  .brand h1,
  .scale-banner {
    display: none;
  }

  .save-state {
    display: none;
  }

  .floor-nav {
    grid-area: floors;
    min-width: 0;
    overflow-x: auto;
  }

  .view-switcher {
    grid-area: views;
    width: 100%;
    overflow-x: auto;
  }

  .header-tools {
    grid-area: tools;
  }

  .header-tools > #undo,
  .header-tools > #redo {
    display: none;
  }

  .workspace,
  .workspace.has-inspector,
  .workspace.has-sidebar,
  .workspace.has-sidebar.has-inspector,
  .workspace.has-inspector:not(.has-sidebar),
  .workspace.has-sidebar:not(.has-inspector) {
    display: grid;
    grid-template-columns: minmax(0, 1fr);
    grid-template-rows: minmax(300px, 1fr) auto;
    grid-template-areas:
      "stage"
      "inspect";
    min-height: 0;
    height: 100%;
  }

  .viewport {
    grid-area: stage;
    min-height: 300px;
    min-width: 0;
    height: auto;
    overflow: hidden;
  }

  .sidebar {
    position: fixed;
    z-index: 18;
    top: auto;
    left: 0;
    bottom: 0;
    width: min(22rem, 100%);
    max-width: 100%;
    height: auto;
    max-height: 78dvh;
    overflow: auto;
    border-right: 1px solid var(--line);
    border-top: 1px solid var(--line);
    transform: translateX(-105%);
  }

  .sidebar.is-open {
    transform: none;
    pointer-events: auto;
  }

  .sidebar:not(.is-open) {
    pointer-events: none;
  }

  .inspector {
    grid-area: inspect;
    position: relative;
    left: auto;
    right: auto;
    bottom: auto;
    top: auto;
    z-index: 1;
    width: 100%;
    max-width: none;
    height: auto;
    max-height: none;
    overflow: hidden;
    border-left: 0;
    border-top: 1px solid var(--line);
    padding: 0.28rem 0.7rem;
    transform: none;
  }

  .inspector.is-open {
    position: fixed;
    left: 0;
    right: 0;
    bottom: 0;
    z-index: 18;
    max-height: 78dvh;
    overflow: auto;
    padding: 0.55rem 0.75rem 0.85rem;
  }

  .inspector-peek {
    flex-direction: row;
    align-items: center;
    gap: 0.5rem;
  }

  .inspector-peek .selection-summary {
    flex: 1;
    min-width: 0;
  }

  .inspector.is-open .inspector-peek {
    position: sticky;
    top: 0;
    z-index: 1;
    background: var(--panel);
    align-items: flex-start;
    padding-bottom: 0.35rem;
    border-bottom: 1px solid var(--line);
    margin-bottom: 0.35rem;
  }

  #insp-title {
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
  }

  .inspector:not(.is-open) #insp-certainty,
  .inspector:not(.is-open) #measure-form,
  .inspector:not(.is-open) #insp-body,
  .inspector:not(.is-open) .empty-state,
  .inspector:not(.is-open) #close-inspector {
    display: none;
  }

  .inspector.is-open #edit-measures {
    display: none;
  }

  #edit-measures {
    display: inline-flex;
    align-items: center;
    flex: 0 0 auto;
    white-space: nowrap;
    color: var(--accent);
    border-bottom-color: var(--accent);
    font-weight: 600;
  }

  .sheet-toolbar {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 0.5rem;
    position: sticky;
    top: 0;
    z-index: 1;
    background: var(--panel);
    padding-bottom: 0.35rem;
    margin-bottom: 0.35rem;
    border-bottom: 1px solid var(--line);
  }

  #close-inventory,
  .inspector.is-open #close-inspector {
    display: inline-flex;
    align-items: center;
    justify-content: center;
  }

  body.is-atmosphere #toggle-inventory,
  body.is-atmosphere #toggle-inspector,
  body.is-atmosphere #edit-measures {
    display: none;
  }

  .item-list button {
    min-height: var(--touch);
  }

  .legend {
    position: absolute;
    font-size: 0.72rem;
  }
}

@media (max-width: 736px) {
  body {
    font-size: 16px;
  }

  .app-header {
    grid-template-columns: auto minmax(0, 1fr) auto;
    grid-template-areas:
      "brand floors tools"
      "views views views";
    padding: 0.08rem 0.35rem 0.12rem;
  }

  .brand-kicker {
    font-size: 0.62rem;
    letter-spacing: 0.05em;
  }

  .floor-nav button,
  .view-switcher button,
  .header-tools button,
  .header-tools summary,
  .toolbar-group button,
  .toolbar-more summary {
    min-height: var(--touch);
    padding: 0 0.45rem;
    font-size: 0.9rem;
  }

  .plan-panel .panel-toolbar h2,
  .scene-panel .panel-toolbar h2 {
    display: none;
  }

  .nudge-group {
    display: none;
  }

  .inspector.is-open .nudge-group {
    display: flex;
  }
}
