/* Layout: Arbeitsfläche mit Werkzeugleiste oben, Katalog links, Eigenschaften rechts.
   Anmutung: Architekten-Transparentpapier, Salbeigrün als Tinte, Kupfer für Auswahl. */
:root {
  --bg: #eef0ec;
  --paper: #fbfbf8;
  --panel: #ffffff;
  --ink: #1e2724;
  --muted: #5d6a65;
  --line: #d6dcd7;
  --accent: #2d5e55;
  --accent-ink: #ffffff;
  --accent-soft: #dfe9e5;
  --select: #c9773f;
  --danger: #b8382c;
  --danger-soft: #f6dedb;
  --grid: #e3e7e2;
  --grid-major: #cfd6d0;
  --room-fill: rgba(45, 94, 85, 0.07);
  --room-stroke: #2d5e55;
  --shadow: 0 1px 2px rgba(20, 30, 28, .06), 0 6px 20px rgba(20, 30, 28, .07);
  --f-display: "Bricolage Grotesque", "Avenir Next", system-ui, sans-serif;
  --f-body: "Figtree", system-ui, -apple-system, "Segoe UI", sans-serif;
  --f-mono: "JetBrains Mono", ui-monospace, "SF Mono", Menlo, monospace;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #151a19; --paper: #1b2120; --panel: #202726; --ink: #e6ece9; --muted: #9aa8a3; --line: #33403d;
    --accent: #7fc2b2; --accent-ink: #0f1716; --accent-soft: #24403a; --select: #e39a62; --danger: #ef7b6e; --danger-soft: #4a2622;
    --grid: #232b29; --grid-major: #2e3836; --room-fill: rgba(127, 194, 178, 0.08); --room-stroke: #7fc2b2;
    --shadow: 0 1px 2px rgba(0,0,0,.3), 0 6px 20px rgba(0,0,0,.35); color-scheme: dark;
  }
}
:root[data-theme="dark"] {
  --bg: #151a19; --paper: #1b2120; --panel: #202726; --ink: #e6ece9; --muted: #9aa8a3; --line: #33403d;
  --accent: #7fc2b2; --accent-ink: #0f1716; --accent-soft: #24403a; --select: #e39a62; --danger: #ef7b6e; --danger-soft: #4a2622;
  --grid: #232b29; --grid-major: #2e3836; --room-fill: rgba(127, 194, 178, 0.08); --room-stroke: #7fc2b2;
  --shadow: 0 1px 2px rgba(0,0,0,.3), 0 6px 20px rgba(0,0,0,.35); color-scheme: dark;
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }
html, body { height: 100%; }
body { margin: 0; background: var(--bg); color: var(--ink); font: 14px/1.45 var(--f-body); }
button, input, select, textarea { font: inherit; color: inherit; }
:focus-visible { outline: 2px solid var(--select); outline-offset: 2px; }
.sr { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); }
h1, h2, h3 { font-family: var(--f-display); font-weight: 700; letter-spacing: -0.01em; text-wrap: balance; margin: 0; }

/* ---------- Buttons & Inputs ---------- */
.btn { display: inline-flex; align-items: center; justify-content: center; gap: 6px; height: 32px; padding: 0 12px; border: 1px solid var(--line); background: var(--panel); border-radius: 6px; cursor: pointer; white-space: nowrap; text-decoration: none; color: var(--ink); font-weight: 500; }
.btn:hover { border-color: var(--accent); }
.btn:disabled { opacity: .45; cursor: not-allowed; }
.btn.primary { background: var(--accent); color: var(--accent-ink); border-color: var(--accent); }
.btn.danger { color: var(--danger); }
.btn.danger:hover { border-color: var(--danger); }
.btn.ghost { border-color: transparent; background: transparent; }
.btn.icon { width: 32px; padding: 0; font-size: 16px; }
.btn.wide { width: 100%; }
.btn.tool[aria-pressed="true"] { background: var(--accent); color: var(--accent-ink); border-color: var(--accent); }
input:not([type=color]):not([type=range]):not([type=file]), select, textarea { height: 32px; padding: 0 9px; border: 1px solid var(--line); border-radius: 6px; background: var(--paper); min-width: 0; }
textarea { height: auto; padding: 8px 9px; resize: vertical; }
input[type=color] { width: 44px; height: 32px; padding: 2px; border: 1px solid var(--line); border-radius: 6px; background: var(--paper); }

/* ---------- Startseite ---------- */
.home { max-width: 980px; margin: 0 auto; padding-block: 48px 64px; padding-left: max(16px, env(safe-area-inset-left, 0px)); padding-right: max(16px, env(safe-area-inset-right, 0px)); display: grid; gap: 28px; }
.brand { display: flex; align-items: center; gap: 12px; }
.brand svg { width: 40px; height: 40px; }
.b-wall { fill: var(--paper); stroke: var(--accent); stroke-width: 3; }
.b-line { fill: none; stroke: var(--accent); stroke-width: 3; }
.b-sofa { fill: var(--select); }
.brand h1 { font-size: clamp(28px, 5vw, 40px); }
.lede { color: var(--muted); max-width: 60ch; margin: 10px 0 0; font-size: 16px; }
.new-project { display: grid; gap: 6px; max-width: 560px; }
.new-project label { font-weight: 600; }
.new-project .row { display: flex; gap: 8px; }
.new-project input { flex: 1; height: 40px; font-size: 15px; }
.new-project .btn { height: 40px; }
.project-list { display: grid; grid-template-columns: repeat(auto-fill, minmax(260px, 1fr)); gap: 16px; }
.pcard { background: var(--panel); border: 1px solid var(--line); border-radius: 10px; overflow: hidden; display: grid; grid-template-rows: 150px auto; text-decoration: none; color: inherit; transition: border-color .15s, transform .15s; }
.pcard:hover { border-color: var(--accent); transform: translateY(-1px); }
.pcard .thumb { background: var(--paper) center / contain no-repeat; border-bottom: 1px solid var(--line); display: grid; place-items: center; color: var(--muted); font-size: 13px;
  background-image: linear-gradient(var(--grid) 1px, transparent 1px), linear-gradient(90deg, var(--grid) 1px, transparent 1px); background-size: 20px 20px; }
.pcard .meta { padding: 12px 14px; display: grid; gap: 4px; }
.pcard h3 { font-size: 17px; }
.pcard .facts { color: var(--muted); font-size: 13px; display: flex; justify-content: space-between; gap: 8px; align-items: center; }
.empty { color: var(--muted); border: 1px dashed var(--line); border-radius: 10px; padding: 28px; text-align: center; }

/* ---------- Editor ---------- */
.editor { display: grid; height: 100%; grid-template-columns: 260px minmax(0, 1fr) 280px; grid-template-rows: auto minmax(0, 1fr); grid-template-areas: "top top top" "left stage right"; }
.topbar { grid-area: top; display: flex; flex-wrap: wrap; align-items: center; gap: 8px 14px; padding: 8px max(12px, env(safe-area-inset-right, 0px)) 8px max(12px, env(safe-area-inset-left, 0px)); background: var(--panel); border-bottom: 1px solid var(--line); }
.topbar .group { display: flex; gap: 4px; align-items: center; }
.project-name { font-family: var(--f-display); font-weight: 700; font-size: 17px; border-color: transparent !important; background: transparent !important; width: 240px; }
.project-name:hover, .project-name:focus { border-color: var(--line) !important; }
.variants select { max-width: 170px; }
.save-state { margin-left: auto; color: var(--muted); font-size: 12px; font-family: var(--f-mono); }
.save-state.err { color: var(--danger); }

.side { background: var(--panel); overflow: auto; padding: 12px; display: flex; flex-direction: column; gap: 12px; min-height: 0; }
.side.left { grid-area: left; border-right: 1px solid var(--line); }
.side.right { grid-area: right; border-left: 1px solid var(--line); }
.tabs { display: flex; gap: 4px; background: var(--bg); padding: 3px; border-radius: 8px; }
.tab { flex: 1; height: 30px; border: 0; background: transparent; border-radius: 6px; cursor: pointer; font-weight: 600; color: var(--muted); }
.tab[aria-selected="true"] { background: var(--panel); color: var(--ink); box-shadow: var(--shadow); }
.tabpanel { display: flex; flex-direction: column; gap: 10px; }
.search { width: 100%; }
.stack { display: grid; gap: 6px; }

.catalog { display: grid; gap: 14px; }
.cat-title { font-size: 11px; font-weight: 600; letter-spacing: .06em; text-transform: uppercase; color: var(--muted); margin-bottom: 6px; }
.cat-items { display: grid; grid-template-columns: 1fr 1fr; gap: 6px; }
.citem { position: relative; display: grid; gap: 2px; justify-items: center; padding: 8px 4px 6px; border: 1px solid var(--line); border-radius: 8px; background: var(--paper); cursor: grab; text-align: center; user-select: none; }
.citem:hover { border-color: var(--accent); }
.citem svg, .citem img { width: 100%; height: 52px; }
.citem img { object-fit: contain; }
.citem .n { font-size: 12px; font-weight: 500; line-height: 1.2; }
.citem .s { font-size: 10.5px; color: var(--muted); font-family: var(--f-mono); }
.citem .edit { position: absolute; top: 3px; right: 3px; width: 22px; height: 22px; border: 0; border-radius: 5px; background: var(--panel); cursor: pointer; font-size: 12px; opacity: 0; }
.citem:hover .edit, .citem .edit:focus { opacity: 1; }
.citem.custom { border-style: dashed; }

.room-list { display: grid; gap: 4px; }
.room-row { display: flex; justify-content: space-between; gap: 8px; padding: 8px 10px; border: 1px solid var(--line); border-radius: 6px; cursor: pointer; background: var(--paper); text-align: left; }
.room-row:hover, .room-row.sel { border-color: var(--accent); }
.room-row span:last-child { font-family: var(--f-mono); color: var(--muted); font-variant-numeric: tabular-nums; }

/* ---------- Arbeitsfläche ---------- */
.stage { grid-area: stage; position: relative; overflow: hidden; background: var(--paper); touch-action: none; }
#canvas { width: 100%; height: 100%; display: block; user-select: none; -webkit-user-select: none; }
#canvas.pan { cursor: grabbing; }
#canvas.m-room, #canvas.m-measure, #canvas.m-calibrate { cursor: crosshair; }
#canvas .item { cursor: move; }
#canvas .room { cursor: pointer; }
#canvas .handle { cursor: grab; }
#canvas text { font-family: var(--f-body); pointer-events: none; }
#canvas .dim { font-family: var(--f-mono); }
.hint { position: absolute; left: 50%; bottom: 16px; transform: translateX(-50%); background: var(--ink); color: var(--paper); padding: 8px 14px; border-radius: 8px; font-size: 13px; box-shadow: var(--shadow); max-width: calc(100% - 32px); text-align: center; }
.banner { position: absolute; left: 16px; right: 16px; top: 12px; background: var(--danger-soft); color: var(--ink); border: 1px solid var(--danger); padding: 10px 14px; border-radius: 8px; display: flex; gap: 12px; align-items: center; justify-content: space-between; flex-wrap: wrap; }
.scalebar { position: absolute; left: 14px; bottom: 14px; display: grid; gap: 2px; font: 11px var(--f-mono); color: var(--muted); pointer-events: none; }
.scalebar span { display: block; height: 6px; border: 1.5px solid var(--muted); border-top: 0; }

/* ---------- Eigenschaften ---------- */
.props h2 { font-size: 18px; }
.psec { display: grid; gap: 8px; padding-bottom: 12px; border-bottom: 1px solid var(--line); }
.psec:last-child { border-bottom: 0; }
.psec h3 { font-size: 12px; font-family: var(--f-body); font-weight: 600; letter-spacing: .06em; text-transform: uppercase; color: var(--muted); }
.field { display: grid; gap: 3px; }
.field > span { font-size: 12px; color: var(--muted); }
.grid2 { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }
.grid3 { display: grid; grid-template-columns: 1fr 1fr 1fr; gap: 6px; }
.unit { position: relative; }
.unit input { width: 100%; padding-right: 30px; font-family: var(--f-mono); font-variant-numeric: tabular-nums; }
.unit::after { content: attr(data-unit); position: absolute; right: 8px; top: 50%; transform: translateY(-50%); font-size: 11px; color: var(--muted); pointer-events: none; }
.btnrow { display: flex; flex-wrap: wrap; gap: 6px; }
.note { color: var(--muted); font-size: 13px; margin: 0; }
.warn { background: var(--danger-soft); color: var(--ink); border-left: 3px solid var(--danger); padding: 8px 10px; border-radius: 4px; font-size: 13px; }
.photo { width: 100%; border-radius: 8px; border: 1px solid var(--line); }
.kbd { font-family: var(--f-mono); font-size: 11px; border: 1px solid var(--line); border-bottom-width: 2px; border-radius: 4px; padding: 0 4px; background: var(--paper); }
.shortcuts { display: grid; grid-template-columns: auto 1fr; gap: 4px 10px; font-size: 12.5px; color: var(--muted); }
.stat { display: flex; justify-content: space-between; font-size: 13px; }
.stat b { font-family: var(--f-mono); font-weight: 500; font-variant-numeric: tabular-nums; }
input[type=range] { width: 100%; accent-color: var(--accent); }

/* ---------- Dialog ---------- */
dialog { border: 1px solid var(--line); border-radius: 12px; padding: 0; background: var(--panel); color: var(--ink); box-shadow: var(--shadow); width: min(560px, calc(100vw - 32px)); max-height: calc(100vh - 32px); }
dialog::backdrop { background: rgba(15, 22, 20, .45); }
.dlg { display: grid; gap: 14px; padding: 20px; }
.dlg h2 { font-size: 20px; }
.dlg .actions { display: flex; flex-direction: row-reverse; justify-content: flex-start; gap: 8px; flex-wrap: wrap; }
.dlg .preview { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.dlg .pv { border: 1px solid var(--line); border-radius: 8px; background: var(--paper); min-height: 140px; display: grid; place-items: center; padding: 8px; position: relative; }
.dlg .pv svg, .dlg .pv img { max-width: 100%; max-height: 180px; }
.dlg .pv small { position: absolute; top: 6px; left: 8px; font-size: 11px; color: var(--muted); }
.ai-box { border: 1px solid var(--line); border-radius: 8px; padding: 12px; display: grid; gap: 8px; background: var(--paper); }
.ai-box .status { font-size: 12.5px; color: var(--muted); }
.spinner { width: 14px; height: 14px; border: 2px solid currentColor; border-right-color: transparent; border-radius: 50%; animation: spin .8s linear infinite; display: inline-block; }
@keyframes spin { to { transform: rotate(360deg); } }
@media (prefers-reduced-motion: reduce) { .spinner { animation-duration: 3s; } .pcard { transition: none; } }

/* ---------- Schmal (Tablet / Handy) ---------- */
@media (max-width: 1000px) {
  .editor { grid-template-columns: 220px minmax(0, 1fr); grid-template-rows: auto minmax(0, 1fr) auto; grid-template-areas: "top top" "left stage" "right right"; }
  .side.right { max-height: 34vh; border-left: 0; border-top: 1px solid var(--line); }
}
@media (max-width: 640px) {
  .editor { height: auto; grid-template-columns: minmax(0, 1fr); grid-template-rows: auto 60vh auto auto; grid-template-areas: "top" "stage" "right" "left"; }
  .side.right, .side.left { max-height: none; overflow: visible; border-right: 0; border-left: 0; border-top: 1px solid var(--line); }
  .project-name { width: 100%; }
  .new-project .row { flex-direction: column; }
}
@media print {
  .topbar, .side, .hint, .banner { display: none !important; }
  .editor { display: block; }
  .stage { height: 100vh; }
}
.unit input::-webkit-outer-spin-button, .unit input::-webkit-inner-spin-button { -webkit-appearance: none; margin: 0; }
.unit input[type=number] { -moz-appearance: textfield; appearance: textfield; }
