:root {
  --bg: #eef0f3;
  --panel: #ffffff;
  --line: #dde1e6;
  --text: #1f2328;
  --muted: #6a737d;
  --accent: #2563eb;
  --accent-soft: #e8efff;
  --danger: #c62828;
  --canvas: #fafbfc;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  font-size: 13px;
  color: var(--text);
}
* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; background: var(--bg); overflow: hidden; }
button, input, select, textarea { font: inherit; color: inherit; }
button {
  background: #fff; border: 1px solid var(--line); border-radius: 6px; padding: 5px 10px; cursor: pointer;
  white-space: nowrap; transition: background .12s, border-color .12s;
}
button:hover { background: #f4f6f8; border-color: #c8ced6; }
button:active { background: #eceff3; }
button:disabled { opacity: .45; cursor: default; }
button.primary { background: var(--accent); border-color: var(--accent); color: #fff; font-weight: 600; }
button.primary:hover { background: #1d4fd8; }
button.danger { color: var(--danger); }
button.small { padding: 3px 8px; font-size: 12px; }
button.wide { width: 100%; }
button.active, .tools button.active { background: var(--accent-soft); border-color: var(--accent); color: var(--accent); }
input[type=text], input[type=number], input:not([type]), input[type=search], select, textarea {
  border: 1px solid var(--line); border-radius: 6px; padding: 5px 7px; background: #fff; min-width: 0;
}
input:focus, select:focus, textarea:focus, button:focus-visible { outline: 2px solid var(--accent); outline-offset: 0; border-color: var(--accent); }

/* ---------- Kopfzeile ---------- */
.topbar {
  height: 52px; display: flex; align-items: center; gap: 10px; padding: 0 12px;
  background: var(--panel); border-bottom: 1px solid var(--line); overflow-x: auto; overflow-y: hidden;
}
.brand { display: flex; align-items: center; gap: 6px; }
.logo { width: 22px; height: 22px; color: var(--accent); flex: none; }
.proj-name { border: 1px solid transparent !important; font-weight: 600; font-size: 15px; width: 170px; }
.proj-name:hover { border-color: var(--line) !important; }
.tb-group { display: flex; gap: 4px; align-items: center; padding-left: 10px; border-left: 1px solid var(--line); }
.file-name { color: var(--muted); font-size: 12px; max-width: 140px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.tb-group.mode span { color: var(--muted); white-space: nowrap; }
.tb-group.mode select { max-width: 210px; }
.toggles label { display: flex; gap: 3px; align-items: center; white-space: nowrap; color: #3a4148; cursor: pointer; }
.toggles { gap: 10px; }
.topbar > .primary { margin-left: auto; }

/* ---------- Layout ---------- */
.main { display: grid; grid-template-columns: 250px 1fr 290px; height: calc(100% - 52px); }
aside { background: var(--panel); overflow-y: auto; }
aside.left { border-right: 1px solid var(--line); display: flex; flex-direction: column; }
aside.right { border-left: 1px solid var(--line); }
.panel { padding: 12px; border-bottom: 1px solid var(--line); }
.panel h2 { font-size: 11px; text-transform: uppercase; letter-spacing: .06em; color: var(--muted); margin: 0 0 8px; font-weight: 600; }
.panel h3 { font-size: 14px; margin: 0 0 10px; }
.lib { flex: 1; display: flex; flex-direction: column; min-height: 0; }
.lib input[type=search] { width: 100%; margin-bottom: 8px; }
#library { overflow-y: auto; flex: 1; margin: 0 -4px; padding: 0 4px; }

/* Geschosse */
.floor-list { list-style: none; margin: 0 0 8px; padding: 0; display: flex; flex-direction: column; gap: 4px; }
.floor-list li {
  display: flex; align-items: center; gap: 6px; padding: 6px 8px; border: 1px solid var(--line); border-radius: 6px; cursor: pointer;
}
.floor-list li:hover { background: #f6f8fa; }
.floor-list li.active { border-color: var(--accent); background: var(--accent-soft); }
.floor-list .short { font-weight: 700; min-width: 26px; color: var(--accent); }
.floor-list .fname { flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.floor-list .farea { color: var(--muted); font-size: 11px; }
.floor-list .fbtn { border: none; background: none; padding: 0 3px; color: var(--muted); visibility: hidden; }
.floor-list li:hover .fbtn, .floor-list li.active .fbtn { visibility: visible; }
.floor-list .fbtn:hover { color: var(--text); }

.tools { display: grid; grid-template-columns: 1fr 1fr; gap: 4px; }
.tools button { text-align: left; }

/* Bibliothek */
.lib-cat { margin-bottom: 6px; }
.lib-cat > summary { cursor: pointer; font-weight: 600; padding: 4px 2px; list-style: none; display: flex; align-items: center; gap: 4px; }
.lib-cat > summary::before { content: "▸"; color: var(--muted); font-size: 10px; width: 10px; transition: transform .12s; }
.lib-cat[open] > summary::before { transform: rotate(90deg); }
.lib-cat > summary::-webkit-details-marker { display: none; }
.lib-grid { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 4px; padding: 4px 0 6px; }
.tile { min-width: 0; overflow: hidden; overflow-wrap: anywhere; hyphens: auto; }
.tile {
  display: flex; flex-direction: column; align-items: center; gap: 2px; padding: 5px 2px 4px; border: 1px solid var(--line);
  border-radius: 6px; cursor: grab; background: #fff; font-size: 10.5px; text-align: center; line-height: 1.15; user-select: none;
}
.tile:hover { border-color: var(--accent); background: #f8faff; }
.tile svg { width: 52px; height: 40px; }
.tile .room-thumb { width: 52px; height: 40px; display: grid; place-items: center; }
.tile .room-thumb span { display: block; border: 2px solid #444; background: #fff; }
.tile .room-thumb span.outdoor { border-style: dashed; border-width: 1.5px; background: #f1f1ee; }
.tile .room-thumb span.void { background: linear-gradient(to top right, transparent 48%, #999 49%, #999 51%, transparent 52%), linear-gradient(to bottom right, transparent 48%, #999 49%, #999 51%, transparent 52%), #fff; }

/* ---------- Zeichenfläche ---------- */
.canvas-wrap { position: relative; overflow: hidden; background: var(--canvas); }
#canvas { width: 100%; height: 100%; display: block; touch-action: none; cursor: default; user-select: none; -webkit-user-select: none; }
#canvas.panning, #canvas.panning * { cursor: grabbing !important; }
#canvas[data-tool=room], #canvas[data-tool=wall], #canvas[data-tool=dimension], #canvas[data-tool=line] { cursor: crosshair; }
#canvas[data-tool=text] { cursor: text; }
.grid-major { stroke: #e2e5ea; stroke-width: 1; fill: none; }
.grid-minor { stroke: #f0f2f4; stroke-width: 1; fill: none; }
#world .room, #world .room-outdoor, #world .item, #world .room-label { cursor: move; }
#world .item.selected .sym-line, #world .item.selected .sym-fill { stroke: var(--accent); }
.sel-outline { fill: rgba(37, 99, 235, .06); stroke: var(--accent); stroke-width: 2; vector-effect: non-scaling-stroke; pointer-events: none; }
.edge-handle { stroke: transparent; cursor: ew-resize; }
.edge-handle.ns { cursor: ns-resize; }
.edge-handle:hover { stroke: rgba(37, 99, 235, .35); }
.vertex-hit { fill: transparent; cursor: pointer; }
.vertex-hit:hover + .vertex { fill: var(--accent); }
.vertex { fill: #fff; stroke: var(--accent); stroke-width: 1.5; vector-effect: non-scaling-stroke; pointer-events: none; }
.edge-len { font-size: 12px; fill: var(--accent); text-anchor: middle; dominant-baseline: central; font-weight: 600; pointer-events: none; paint-order: stroke; stroke: #fff; stroke-width: 3px; }
.sel-box { fill: none; stroke: var(--accent); stroke-width: 1.2; stroke-dasharray: 4 3; vector-effect: non-scaling-stroke; pointer-events: none; }
.handle { fill: #fff; stroke: var(--accent); stroke-width: 1.5; vector-effect: non-scaling-stroke; cursor: nwse-resize; }
.handle.rot { cursor: grab; fill: var(--accent); }
.rot-line { stroke: var(--accent); stroke-width: 1; vector-effect: non-scaling-stroke; pointer-events: none; }
.guide { stroke: #e0368a; stroke-width: 1; stroke-dasharray: 5 4; vector-effect: non-scaling-stroke; pointer-events: none; }
.draw-rect { fill: rgba(37, 99, 235, .08); stroke: var(--accent); stroke-width: 1.5; vector-effect: non-scaling-stroke; }
.draw-line { stroke: var(--accent); stroke-width: 2; vector-effect: non-scaling-stroke; }
.live-info { font-size: 13px; font-weight: 700; fill: #111; text-anchor: middle; dominant-baseline: central; pointer-events: none; paint-order: stroke; stroke: #fff; stroke-width: 4px; stroke-linejoin: round; }

.zoom-ctrl { position: absolute; right: 12px; bottom: 36px; display: flex; flex-direction: column; gap: 4px; }
.zoom-ctrl button { width: 32px; height: 32px; padding: 0; font-size: 16px; box-shadow: 0 1px 3px rgba(0,0,0,.08); }
.status {
  position: absolute; left: 0; right: 0; bottom: 0; height: 24px; padding: 0 12px; display: flex; gap: 18px; align-items: center;
  background: rgba(255,255,255,.92); border-top: 1px solid var(--line); color: var(--muted); font-size: 11.5px; white-space: nowrap; overflow: hidden;
}
.status b { color: var(--text); font-weight: 600; }
.floor-badge {
  position: absolute; left: 12px; top: 12px; background: rgba(255,255,255,.95); border: 1px solid var(--line); border-radius: 6px;
  padding: 5px 10px; font-weight: 600; box-shadow: 0 1px 3px rgba(0,0,0,.06); pointer-events: none;
}

/* ---------- Eigenschaften ---------- */
.props .row { display: grid; grid-template-columns: 88px 1fr; align-items: center; gap: 6px; margin-bottom: 6px; }
.props .row > span { color: var(--muted); }
.props .row input, .props .row select, .props .row textarea { width: 100%; }
.props .row label { display: flex; align-items: center; gap: 6px; }
.props .row input[type=checkbox] { width: auto; margin: 0; }
.props .dims3 { display: grid; grid-template-columns: 1fr 1fr 1fr; gap: 6px; margin-bottom: 8px; }
.props .dims3 label { display: flex; flex-direction: column; gap: 2px; color: var(--muted); font-size: 11px; }
.props .dims3 input { width: 100%; font-weight: 600; font-size: 13px; color: var(--text); }
.props .btns { display: flex; flex-wrap: wrap; gap: 4px; margin: 8px 0; }
.props .hint { color: var(--muted); font-size: 11.5px; line-height: 1.45; margin: 6px 0; }
.props .sub { font-size: 11px; color: var(--muted); text-transform: uppercase; letter-spacing: .05em; margin: 12px 0 6px; }
.props .big-area { font-size: 22px; font-weight: 700; margin: 2px 0 10px; }
.props .big-area small { font-size: 12px; color: var(--muted); font-weight: 400; }
.anchor { display: grid; grid-template-columns: repeat(3, 16px); gap: 2px; flex: none; }
.anchor button { width: 16px; height: 16px; padding: 0; border-radius: 3px; }
.anchor button.on { background: var(--accent); border-color: var(--accent); }
.anchor-row { display: flex; gap: 10px; align-items: center; margin-bottom: 8px; }
.anchor-row .hint { margin: 0; }
.seg { display: inline-flex; border: 1px solid var(--line); border-radius: 6px; overflow: hidden; }
.seg button { border: none; border-radius: 0; padding: 3px 8px; }
.seg button + button { border-left: 1px solid var(--line); }
.seg button.on { background: var(--accent-soft); color: var(--accent); font-weight: 600; }
.warn { background: #fff4e5; border: 1px solid #f5c983; color: #7a4b00; padding: 6px 8px; border-radius: 6px; font-size: 12px; margin-bottom: 8px; }
kbd { background: #f1f3f5; border: 1px solid #d0d7de; border-bottom-width: 2px; border-radius: 4px; padding: 0 4px; font-size: 11px; font-family: inherit; }
.keys { display: grid; grid-template-columns: auto 1fr; gap: 3px 8px; font-size: 11.5px; color: var(--muted); align-items: center; }

/* Flächentabelle */
.area-table { width: 100%; border-collapse: collapse; font-size: 12px; }
.area-table td { padding: 3px 2px; border-bottom: 1px solid #f0f2f4; }
.area-table td.num { text-align: right; white-space: nowrap; font-variant-numeric: tabular-nums; }
.area-table tr.room-row { cursor: pointer; }
.area-table tr.room-row:hover td { background: #f6f8fa; }
.area-table tr.room-row.sel td { background: var(--accent-soft); }
.area-table tr.fl td { font-weight: 700; padding-top: 10px; border-bottom: 1px solid var(--line); }
.area-table tr.sum td { font-weight: 600; border-bottom: none; }
.area-table tr.total td { font-weight: 700; border-top: 2px solid var(--text); border-bottom: none; padding-top: 6px; }
.area-table .fac { color: var(--muted); }

/* ---------- Dialoge ---------- */
.plans-list { display: flex; flex-direction: column; gap: 6px; max-height: 50vh; overflow-y: auto; }
.plan-row { display: flex; align-items: center; gap: 8px; padding: 8px 10px; border: 1px solid var(--line); border-radius: 8px; }
.plan-row:hover { border-color: var(--accent); background: #f8faff; }
.plan-info { flex: 1; display: flex; flex-direction: column; gap: 2px; min-width: 0; }
.plan-info b { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.save-online { display: flex; gap: 6px; align-items: center; margin-bottom: 4px; }
.save-online input { flex: 1; }
.plans-list .sub { font-size: 11px; color: var(--muted); text-transform: uppercase; letter-spacing: .05em; margin: 10px 0 2px; }
.dlg label.inline { flex-direction: row; align-items: center; gap: 6px; color: var(--text); }
.warn-text { color: var(--danger); margin: 0; min-height: 1.2em; font-size: 12px; }
code { background: #f1f3f5; border-radius: 4px; padding: 0 4px; font-size: 12px; }
dialog { border: none; border-radius: 12px; padding: 0; box-shadow: 0 20px 60px rgba(0,0,0,.25); max-width: 560px; width: calc(100% - 32px); }
dialog::backdrop { background: rgba(20, 24, 30, .35); }
.dlg { padding: 20px; display: flex; flex-direction: column; gap: 12px; }
.dlg h2 { margin: 0; font-size: 18px; }
.dlg label { display: flex; flex-direction: column; gap: 4px; color: var(--muted); }
.dlg label select, .dlg label input { color: var(--text); }
.grid2 { display: grid; grid-template-columns: 1fr 1fr; gap: 10px 14px; }
.checks { display: grid; grid-template-columns: 1fr 1fr; gap: 6px 14px; }
.checks label { flex-direction: row; align-items: center; gap: 6px; color: var(--text); }
.dlg-actions { display: flex; justify-content: flex-end; gap: 8px; margin-top: 4px; }
#btnOpenLocal { margin-right: auto; }
.muted { color: var(--muted); margin: 0; line-height: 1.45; }
.small { font-size: 12px; }

#toast {
  position: fixed; left: 50%; bottom: 40px; transform: translateX(-50%) translateY(20px); background: #1f2328; color: #fff; padding: 9px 16px;
  border-radius: 8px; font-size: 13px; opacity: 0; pointer-events: none; transition: opacity .2s, transform .2s; max-width: 80vw; z-index: 50;
}
#toast.show { opacity: 1; transform: translateX(-50%) translateY(0); }

/* ---------- Schmale Bildschirme ---------- */
@media (max-width: 1200px) {
  .main { grid-template-columns: 220px 1fr 260px; }
  .toggles label:nth-child(n+4) { display: none; }
}
@media (max-width: 800px) {
  html, body { overflow: auto; }
  .main { grid-template-columns: 1fr; height: auto; }
  .canvas-wrap { order: -1; height: 62vh; }
  aside.left, aside.right { border: none; border-top: 1px solid var(--line); }
  .lib { max-height: 50vh; }
}
