:root {
  color-scheme: light;
  --background: #fafafa;
  --foreground: #18181b;
  --card: #fff;
  --muted: #f4f4f5;
  --muted-foreground: #52525b;
  --border: #e4e4e7;
  --input: #d4d4d8;
  --primary: #18181b;
  --primary-foreground: #fafafa;
  --accent: #f4f4f5;
  --ring: #71717a;
  --warning: #fffbeb;
  --warning-foreground: #854d0e;
  --radius: .625rem;
  --line: var(--border);
  --surface: var(--card);
  --roof: #066c98;
  --walk: #136f49;
  --canopy: #996119;
  font-family: Inter, "Segoe UI", system-ui, sans-serif;
  font-size: 100%;
  line-height: 1.5;
  color: var(--foreground);
  background: var(--background);
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }
body { margin: 0; }
h1, h2, h3, p, figure { margin: 0; }
button, input { font: inherit; }
button, a { -webkit-tap-highlight-color: transparent; }
a { color: var(--primary); text-underline-offset: .2em; }
button:not(:disabled) { cursor: pointer; }
:focus-visible { outline: 2px solid var(--ring); outline-offset: 3px; }
.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip-path: inset(50%);
  white-space: nowrap;
  border: 0;
}

.topbar { background: var(--surface); border-bottom: 1px solid var(--line); }
.topbar-inner {
  display: flex;
  align-items: center;
  gap: 3rem;
  min-height: 74px;
  max-width: 1370px;
  margin: 0 auto;
  padding-inline: clamp(1rem, 4vw, 3.25rem);
}
.identity { display: flex; align-items: center; gap: .75rem; }
.identity-title, .identity-subtitle { display: block; white-space: nowrap; }
.identity-title { font-weight: 700; line-height: 1.25; }
.identity-subtitle { color: var(--muted-foreground); font-size: .82rem; margin-top: .12rem; }
.brand-mark {
  width: 38px;
  height: 38px;
  border-radius: 9px;
  display: grid;
  place-items: center;
  background: var(--primary);
}
.brand-mark span {
  width: 19px;
  height: 20px;
  border: 1.5px solid var(--primary-foreground);
  border-radius: 2px;
  position: relative;
}
.brand-mark span::before {
  content: "";
  position: absolute;
  inset: 4px 6px 0 0;
  border-top: 1px solid var(--primary-foreground);
  border-right: 1px solid var(--primary-foreground);
}
.tabs, .language-switch {
  display: flex;
  align-self: center;
  gap: .15rem;
  min-height: 38px;
  padding: .2rem;
  border-radius: var(--radius);
  background: var(--muted);
}
.tabs button, .language-switch button {
  padding: .34rem .74rem;
  border: 1px solid transparent;
  border-radius: calc(var(--radius) - .17rem);
  background: transparent;
  color: var(--muted-foreground);
  font-size: .9rem;
  font-weight: 550;
  white-space: nowrap;
}
.tabs button:hover, .language-switch button:hover { color: var(--primary); }
.tabs button[aria-selected="true"], .language-switch button[aria-pressed="true"] {
  border-color: var(--border);
  color: var(--foreground);
  background: var(--card);
  box-shadow: 0 1px 2px #18181b13;
}
.language-switch { margin-left: auto; min-height: 34px; }
.language-switch button { padding: .2rem .48rem; font-size: .81rem; font-weight: 650; }

main { max-width: 1370px; margin: auto; padding: 2.1rem clamp(1rem, 4vw, 3.25rem) 1.75rem; }
.page-header { display: flex; justify-content: space-between; align-items: end; gap: 1rem; margin-bottom: 1.5rem; }
.kicker { color: var(--muted-foreground); font-size: .82rem; font-weight: 650; margin-bottom: .3rem; }
h1 { font-size: clamp(2rem, 5.2vw, 2.9rem); font-weight: 680; letter-spacing: -.042em; line-height: 1.1; }
.page-intro { margin-top: .55rem; color: var(--muted-foreground); }
h2 { font-size: 1.15rem; line-height: 1.25; letter-spacing: -.018em; }
h3 { font-size: .98rem; }
.export-actions { display: flex; }
.export-actions .button:first-child { border-radius: calc(var(--radius) - .12rem) 0 0 calc(var(--radius) - .12rem); }
.export-actions .button:last-child { border-radius: 0 calc(var(--radius) - .12rem) calc(var(--radius) - .12rem) 0; }
.button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: 41px;
  padding: .48rem .85rem;
  border: 1px solid var(--line);
  border-radius: calc(var(--radius) - .12rem);
  background: var(--surface);
  color: var(--foreground);
  font-size: .9rem;
  line-height: 1.25;
  font-weight: 650;
  text-decoration: none;
  white-space: nowrap;
}
.button:hover:not(:disabled) { background: var(--accent); }
.button.primary { border-color: var(--primary); background: var(--primary); color: var(--primary-foreground); }
.button.primary:hover:not(:disabled) { background: #3f3f46; }
.button:disabled { opacity: .48; }
.export-error { color: #9e392e; margin-bottom: .8rem; }

.planner-layout, .reference-layout { display: grid; align-items: start; gap: 1rem; }
.planner-layout { grid-template-columns: minmax(0, 1fr) minmax(20.5rem, 23rem); }
.reference-layout { grid-template-columns: minmax(14rem, 17rem) minmax(0, 1fr); }
.sidebar { min-width: 0; display: grid; gap: 1rem; }
.panel {
  min-width: 0;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: calc(var(--radius) + .16rem);
  box-shadow: 0 1px 2px #18181b0b;
}
.panel-heading { padding: 1rem 1.12rem; border-bottom: 1px solid var(--line); }
.panel-heading p { color: var(--muted-foreground); font-size: .9rem; margin-top: .3rem; }
.drawing-heading { display: flex; flex-wrap: wrap; justify-content: space-between; align-items: center; gap: .65rem .85rem; }
.drawing-heading > div { flex: 1 1 11rem; min-width: 0; }
.switch { display: inline-flex; flex: none; align-items: center; gap: .5rem; color: var(--foreground); cursor: pointer; font-size: .9rem; font-weight: 650; }
.switch input { position: absolute; opacity: 0; width: 1px; height: 1px; }
.switch-track {
  position: relative;
  flex: none;
  width: 34px;
  height: 19px;
  border: 1px solid var(--input);
  border-radius: 12px;
  background: var(--input);
}
.switch-track::after {
  content: "";
  position: absolute;
  top: 2px;
  left: 2px;
  width: 13px;
  height: 13px;
  border-radius: 50%;
  background: #fff;
  box-shadow: 0 1px 2px #18181b30;
  transition: transform .15s ease;
}
.switch input:checked + .switch-track { border-color: var(--primary); background: var(--primary); }
.switch input:checked + .switch-track::after { transform: translateX(15px); }
.switch input:focus-visible + .switch-track { outline: 2px solid var(--ring); outline-offset: 3px; }
.switch span:last-child { white-space: nowrap; }
.map-stage {
  display: grid;
  place-items: center;
  padding: .5rem .6rem .1rem;
  background: #fafafa;
}
.map-stage, .pdf-paper { user-select: none; -webkit-user-select: none; }
.map, .pdf-paper img { -webkit-user-drag: none; }
.map {
  --background: #fafafa;
  --edge: #60776b;
  --light: #e8eee9;
  display: block;
  width: 100%;
  max-width: 660px;
  min-width: 0;
}
.map text { fill: var(--foreground); font: 500 .93rem system-ui, sans-serif; }
.map .text-small { font-size: .79rem; }
.map .muted { fill: var(--muted-foreground); }
.map .ground { fill: var(--light); }
.map .house { fill: var(--muted); stroke: var(--edge); }
.map .zone { fill: var(--light); stroke: var(--edge); stroke-dasharray: 5 4; }
.map .roof { fill: #d6eaf3; stroke: var(--roof); stroke-width: 2; }
.map .shed { fill: #e3ece7; stroke: var(--foreground); stroke-width: 1.6; }
.map .car { fill: #f3f6f4; stroke: var(--edge); }
.map .walk { fill: none; stroke: var(--walk); stroke-width: 1.8; }
.map .walk-halo { fill: none; stroke: var(--background); stroke-width: 4; stroke-linejoin: round; }
.map .door-cover { fill: #f6eddb; stroke: var(--canopy); stroke-width: 1.25; stroke-dasharray: 4 3; }
.map .guide { fill: none; stroke: var(--edge); stroke-width: 1; }
.map .halo, .map.aerial-on text {
  paint-order: stroke;
  stroke: var(--background);
  stroke-width: 3;
  stroke-linejoin: round;
}
.map.aerial-on .ground { fill: transparent; }
.map.aerial-on .zone, .map.aerial-on .house { fill: rgb(249 251 249 / .22); }
.map.aerial-on .roof { fill: rgb(45 143 183 / .26); }
.map.aerial-on .car { fill: rgb(232 242 236 / .78); }
.map .drag-target { touch-action: none; cursor: grab; }
.map .drag-target:active { cursor: grabbing; }
.map .no-hit { pointer-events: none; }
.drawing figcaption { border-top: 1px solid var(--line); padding: .82rem 1.12rem; }
.legend { display: flex; flex-wrap: wrap; gap: .42rem 1rem; font-size: .86rem; }
.legend span { display: inline-flex; align-items: center; gap: .45rem; }
.legend i { height: .75rem; width: .9rem; border-radius: 2px; }
.legend-zone { border: 1px dashed var(--muted-foreground); background: var(--muted); }
.legend-roof { border: 1px solid var(--roof); background: #d6eaf3; }
.legend-route { border-top: 2px dashed var(--walk); margin-top: .56rem; }
.legend-canopy { border: 1px dashed var(--canopy); background: #f6eddb; }
.metadata { color: var(--muted-foreground); font-size: .81rem; }
.drawing figcaption .metadata { margin-top: .35rem; }

.budget { padding: 1rem 1.12rem; }
.budget h2 { font-size: .98rem; font-weight: 600; color: var(--muted-foreground); }
.covered-area { font-weight: 700; font-size: clamp(2.1rem, 3.5vw, 2.7rem); letter-spacing: -.045em; line-height: 1.15; margin-top: .25rem; }
.budget progress { display: block; width: 100%; height: .38rem; border: 0; accent-color: var(--primary); margin: .52rem 0 .55rem; }
.budget progress::-webkit-progress-bar { background: var(--muted); border-radius: 8px; }
.budget progress::-webkit-progress-value { background: var(--primary); border-radius: 8px; }
.budget progress::-moz-progress-bar { background: var(--primary); border-radius: 8px; }
.budget-meta { display: flex; flex-wrap: wrap; justify-content: space-between; gap: .15rem .75rem; font-size: .9rem; font-weight: 600; }
.budget-meta p + p { color: var(--muted-foreground); font-weight: 500; }
.budget-detail { color: var(--muted-foreground); font-size: .85rem; margin-top: .2rem; }
.panel-heading .warning {
  color: var(--warning-foreground);
  background: var(--warning);
  border: 1px solid #fde68a;
  padding: .48rem .64rem;
  border-radius: calc(var(--radius) - .1rem);
  margin-top: .6rem;
  font-weight: 550;
}
.editor-controls { padding: 0 1.12rem .85rem; }
.control-group { padding-top: .85rem; }
.control-group + .control-group { border-top: 1px solid var(--line); margin-top: .85rem; }
.control-group h3 { margin-bottom: .5rem; }
.object-buttons, .movement { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: .3rem; }
.object-buttons { grid-template-columns: repeat(2, minmax(0, 1fr)); background: var(--muted); border-radius: var(--radius); padding: .2rem; gap: .2rem; }
.object-buttons .button, .movement .button { min-height: 34px; padding: .36rem .25rem; }
.object-buttons .button { border-color: transparent; background: transparent; font-weight: 550; }
.movement { margin-top: .35rem; }
.object-buttons [aria-pressed="true"], .object-buttons [aria-pressed="true"]:hover:not(:disabled) {
  border-color: var(--border);
  background: var(--card);
  color: var(--primary);
  box-shadow: 0 1px 2px #18181b10;
}
.dimensions-grid { display: grid; grid-template-columns: 1fr 1fr; gap: .38rem .75rem; margin-top: .6rem; }
.size-row { display: grid; grid-template-columns: minmax(0, 1fr) auto; gap: 0 .3rem; align-items: center; }
.size-row label, .size-row output { font-size: .88rem; }
.size-row output, .covered-area, .budget-meta, .budget-detail { font-variant-numeric: tabular-nums; }
.size-row output { white-space: nowrap; color: var(--muted-foreground); }
.size-row input { grid-column: 1/-1; width: 100%; min-width: 0; height: 23px; margin: 0; appearance: none; background: transparent; cursor: pointer; }
.size-row input::-webkit-slider-runnable-track {
  height: .28rem;
  border-radius: 1rem;
  background: linear-gradient(to right, var(--primary) 0 var(--range-fill, 0%), var(--border) var(--range-fill, 0%) 100%);
}
.size-row input::-webkit-slider-thumb {
  appearance: none; width: 15px; height: 15px; margin-top: -5px;
  border: 1.5px solid var(--primary); border-radius: 50%; background: var(--surface);
  box-shadow: 0 1px 2px #18181b1a;
}
.size-row input::-moz-range-track { height: .28rem; border-radius: 1rem; background: var(--border); }
.size-row input::-moz-range-progress { height: .28rem; border-radius: 1rem; background: var(--primary); }
.size-row input::-moz-range-thumb { width: 13px; height: 13px; border: 1.5px solid var(--primary); border-radius: 50%; background: var(--surface); }
.workspace-footer { display: flex; justify-content: space-between; align-items: start; gap: .6rem 1rem; margin-top: .9rem; color: var(--muted-foreground); font-size: .87rem; }
.workspace-footer a { white-space: nowrap; }

.references { padding: 1rem; }
.references h2 { margin: .1rem .25rem .75rem; }
.reference {
  display: block;
  width: 100%;
  padding: .66rem .6rem;
  margin-bottom: .16rem;
  border: 1px solid transparent;
  border-radius: 8px;
  background: transparent;
  color: var(--foreground);
  text-align: left;
}
.reference:hover { background: var(--muted); }
.reference[aria-current="page"] { border-color: var(--border); background: var(--accent); }
.reference span, .reference small { display: block; }
.reference span { font-size: .93rem; font-weight: 650; }
.reference small { margin-top: .14rem; color: var(--muted-foreground); font-size: .82rem; }
.pdf-toolbar { display: flex; gap: .55rem .7rem; flex-wrap: wrap; align-items: center; padding: .8rem .92rem; border-bottom: 1px solid var(--line); }
.pdf-toolbar label { white-space: nowrap; font-size: .9rem; }
.pdf-toolbar input { width: 3.45rem; padding: .28rem; border: 1px solid var(--line); border-radius: 6px; text-align: center; }
.pdf-page-link { margin-left: auto; font-size: .9rem; }
.pdf-paper { padding: clamp(.6rem, 2.2vw, 1.4rem); background: var(--muted); border-radius: 0 0 calc(var(--radius) + .16rem) calc(var(--radius) + .16rem); }
.pdf-paper img { display: block; margin: 0 auto; max-width: 100%; max-height: 80vh; object-fit: contain; background: #fff; box-shadow: 0 2px 9px #2b392521; }

@media (max-width: 840px) {
  .planner-layout { grid-template-columns: minmax(0, 1fr) minmax(18rem, 20rem); }
  .dimensions-grid { grid-template-columns: 1fr; }
}
@media (max-width: 690px) {
  main { padding-top: 1.25rem; }
  .topbar-inner { display: grid; grid-template-columns: 1fr auto; min-height: 0; gap: .65rem 1rem; padding-block: .8rem; }
  .language-switch { grid-column: 2; grid-row: 1; }
  .tabs { grid-column: 1 / -1; justify-self: start; }
  .page-header { align-items: start; flex-direction: column; margin-bottom: 1rem; }
  .planner-layout, .reference-layout { grid-template-columns: minmax(0, 1fr); }
  .sidebar { display: contents; }
  .budget { order: -1; }
  .dimensions-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .workspace-footer { flex-wrap: wrap; }
  .pdf-page-link { margin-left: 0; }
  .pdf-paper img { max-height: none; }
}

@media (prefers-reduced-motion: reduce) {
  .switch-track::after { transition: none; }
}
@media (max-width: 365px) {
  .dimensions-grid { grid-template-columns: 1fr; }
  .switch { white-space: nowrap; }
}
