:root {
  color-scheme: light;
  --bg: #eef2f6;
  --panel: #ffffff;
  --text: #172033;
  --muted: #687386;
  --line: #cbd5e1;
  --accent: #2563eb;
  --accent-dark: #1d4ed8;
  --danger: #dc2626;
  --furniture: #60a5fa;
  --reference: #94a3b8;
  --zone: #f59e0b;
  --door: #ef4444;
}

* { box-sizing: border-box; }
body {
  margin: 0;
  min-width: 320px;
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  background: var(--bg);
  color: var(--text);
}
button, input, select { font: inherit; }
button {
  min-height: 42px;
  border: 0;
  border-radius: 9px;
  background: var(--accent);
  color: white;
  padding: .65rem .9rem;
  cursor: pointer;
  font-weight: 650;
}
button:hover { background: var(--accent-dark); }
button.secondary { background: #475569; }
button.danger { background: var(--danger); width: 100%; }
button:disabled { opacity: .45; cursor: not-allowed; }
button:focus-visible, input:focus-visible, select:focus-visible {
  outline: 3px solid rgba(37, 99, 235, .25);
  outline-offset: 2px;
}
input, select {
  width: 100%;
  min-height: 40px;
  margin-top: .3rem;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: .5rem .6rem;
  background: white;
  color: var(--text);
}
label {
  display: block;
  margin: .55rem 0;
  color: #334155;
  font-size: .88rem;
  font-weight: 600;
}
.topbar {
  display: flex;
  gap: 1rem;
  align-items: center;
  justify-content: space-between;
  padding: 1rem 1.25rem;
  background: #111827;
  color: white;
}
.topbar h1 { margin: 0; font-size: 1.4rem; }
.topbar p { margin: .25rem 0 0; color: #cbd5e1; font-size: .9rem; }
.save-row {
  display: grid;
  grid-template-columns: minmax(130px, 1fr) auto minmax(160px, 1fr) auto;
  gap: .5rem;
  align-items: center;
}
.save-row input, .save-row select { margin: 0; }
.layout {
  display: grid;
  grid-template-columns: minmax(250px, 310px) minmax(360px, 1fr) minmax(220px, 280px);
  gap: 1rem;
  padding: 1rem;
  align-items: start;
}
.panel {
  background: var(--panel);
  border: 1px solid #dbe2ea;
  border-radius: 12px;
  overflow: hidden;
}
.panel section { padding: 1rem; border-bottom: 1px solid #e5e7eb; }
.panel section:last-child { border-bottom: 0; }
.panel h2 { font-size: 1rem; margin: 0 0 .75rem; }
.panel h3 { font-size: .9rem; margin: 1rem 0 .5rem; }
.grid2 {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: .5rem;
}
.workspace { min-width: 0; }
.status {
  background: white;
  border: 1px solid #dbe2ea;
  border-radius: 10px;
  padding: .65rem .8rem;
  margin-bottom: .75rem;
  color: #334155;
}
.status.error { border-color: #fecaca; color: #991b1b; background: #fff7f7; }
.status.ok { border-color: #bbf7d0; color: #166534; background: #f7fff9; }
.canvas-wrap {
  background:
    linear-gradient(#e5e7eb 1px, transparent 1px),
    linear-gradient(90deg, #e5e7eb 1px, transparent 1px),
    white;
  background-size: 25px 25px;
  border: 1px solid #dbe2ea;
  border-radius: 12px;
  min-height: 540px;
  overflow: hidden;
}
#plan {
  display: block;
  width: 100%;
  min-height: 540px;
  touch-action: none;
  user-select: none;
}
.room-fill { fill: rgba(148, 163, 184, .07); }
.wall { stroke: #111827; stroke-width: 5; stroke-linecap: round; }
.wall-label { fill: #475569; font-size: 13px; font-weight: 700; text-anchor: middle; }
.object { cursor: grab; }
.object:active { cursor: grabbing; }
.object-shape { stroke: #334155; stroke-width: 2; vector-effect: non-scaling-stroke; }
.object.furniture .object-shape { fill: var(--furniture); }
.object.reference .object-shape { fill: var(--reference); fill-opacity: .65; stroke-dasharray: 6 4; }
.object.invalid .object-shape { fill: #fca5a5; stroke: #b91c1c; }
.object.selected .object-shape { stroke: var(--accent-dark); stroke-width: 4; }
.object-label {
  pointer-events: none;
  fill: #0f172a;
  font-size: 12px;
  font-weight: 700;
  text-anchor: middle;
  dominant-baseline: middle;
}
.deadzone { fill: rgba(245, 158, 11, .26); stroke: #d97706; stroke-width: 1.5; }
.deadzone-label { fill: #92400e; font-size: 10px; text-anchor: middle; }
.door-sector { fill: rgba(239, 68, 68, .13); stroke: rgba(185, 28, 28, .7); stroke-width: 1.5; }
.door-leaf { stroke: #b91c1c; stroke-width: 4; }
.door-gap { stroke: white; stroke-width: 8; }
.hinge { fill: #b91c1c; }
.legend {
  display: flex;
  flex-wrap: wrap;
  gap: .85rem;
  margin-top: .65rem;
  color: var(--muted);
  font-size: .82rem;
}
.legend span { display: inline-flex; gap: .35rem; align-items: center; }
.dot { width: 11px; height: 11px; border-radius: 50%; display: inline-block; }
.dot.furniture { background: var(--furniture); }
.dot.reference { background: var(--reference); }
.dot.zone { background: var(--zone); }
.dot.door, .dot.invalid { background: var(--door); }
.button-row {
  display: grid;
  grid-template-columns: 1fr 1fr 1fr;
  gap: .4rem;
  margin: .75rem 0;
}
.button-row button { padding-inline: .45rem; }
.checkline {
  display: flex;
  gap: .5rem;
  align-items: center;
}
.checkline input { width: 18px; min-height: 18px; margin: 0; }
.hint { color: var(--muted); font-size: .82rem; line-height: 1.4; }
.hidden { display: none !important; }
.distance-list {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: .4rem;
}
.distance-list div, .metric {
  background: #f8fafc;
  border: 1px solid #e2e8f0;
  border-radius: 7px;
  padding: .45rem .55rem;
  font-size: .84rem;
}
.element-list { display: grid; gap: .4rem; }
.element-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: .5rem;
  border: 1px solid #e2e8f0;
  border-radius: 8px;
  padding: .5rem .6rem;
  font-size: .83rem;
}
.element-row button {
  min-height: 30px;
  padding: .25rem .5rem;
  font-size: .78rem;
}
@media (max-width: 1050px) {
  .layout { grid-template-columns: 280px minmax(360px, 1fr); }
  .inspector { grid-column: 1 / -1; display: grid; grid-template-columns: 1fr 1fr; }
  .inspector section { border-bottom: 0; border-right: 1px solid #e5e7eb; }
}
@media (max-width: 760px) {
  .topbar { align-items: stretch; flex-direction: column; }
  .save-row { grid-template-columns: 1fr 1fr; }
  .layout { grid-template-columns: 1fr; }
  .workspace { grid-row: 1; }
  .controls { grid-row: 2; }
  .inspector { grid-column: auto; grid-row: 3; display: block; }
  .canvas-wrap, #plan { min-height: 420px; }
}
@media (max-width: 430px) {
  .grid2 { grid-template-columns: 1fr; }
  .save-row { grid-template-columns: 1fr; }
  .button-row { grid-template-columns: 1fr; }
}


/* Compact editor controls */
.wide-action { grid-column: 1 / -1; }

.copy-panel {
  margin: .75rem 1rem 0;
  padding: .85rem 1rem;
  display: grid;
  grid-template-columns: minmax(180px, 1.2fr) minmax(190px, 1fr) minmax(220px, auto) auto;
  gap: .75rem;
  align-items: center;
  background: #fff;
  border: 1px solid #dbe2ea;
  border-radius: 12px;
}
.copy-panel p { margin: .2rem 0 0; color: var(--muted); font-size: .82rem; }
.copy-panel label { margin: 0; }
.copy-actions { display: flex; gap: .45rem; flex-wrap: wrap; }

.controls .accordion {
  border-bottom: 1px solid #e5e7eb;
}
.controls .accordion:last-child { border-bottom: 0; }
.controls .accordion > summary {
  list-style: none;
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: .75rem;
  padding: .9rem 1rem;
  cursor: pointer;
  font-size: 1rem;
  font-weight: 750;
  color: #1e293b;
  background: #fff;
  user-select: none;
}
.controls .accordion > summary::-webkit-details-marker { display: none; }
.controls .accordion > summary:hover { background: #f8fafc; }
.controls .accordion[open] > summary { background: #f8fafc; }
.accordion-chevron {
  transition: transform .16s ease;
  color: var(--muted);
  font-size: 1.1rem;
}
.controls .accordion[open] .accordion-chevron { transform: rotate(180deg); }
.accordion-body { padding: .15rem 1rem 1rem; }

.selected-editor {
  margin-top: .75rem;
  padding: .75rem;
  background: #f8fafc;
  border: 1px solid #e2e8f0;
  border-radius: 9px;
}
.readonly-row {
  margin: .55rem 0;
  color: #475569;
  font-size: .85rem;
}
.full-action {
  width: 100%;
  margin-bottom: .45rem;
}

@media (max-width: 1050px) {
  .copy-panel {
    grid-template-columns: 1fr 1fr;
  }
}

@media (max-width: 760px) {
  .copy-panel {
    grid-template-columns: 1fr;
  }
}
