/* ===== GrundrissStudio ===== */
:root {
  --bg: #0f172a;
  --panel: #1e293b;
  --panel-2: #131c2e;
  --border: #334155;
  --text: #f8fafc;
  --muted: #94a3b8;
  --faint: #64748b;
  --primary: #38bdf8;
  --primary-strong: #0284c7;
  --accent: #f59e0b;
  --danger: #ef4444;
  --canvas: #0b0f19;
  --radius: 8px;
}

* { box-sizing: border-box; margin: 0; padding: 0; }
[hidden] { display: none !important; }

html, body { height: 100%; }

body {
  background: var(--bg);
  color: var(--text);
  font: 14px/1.4 -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Helvetica, Arial, sans-serif;
  overflow: hidden;
}

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

.editor {
  display: grid;
  grid-template-columns: 400px minmax(0, 1fr);
  height: 100vh;
  height: 100dvh;
}

/* ===== Seitenleiste ===== */
#sidebar {
  background: var(--panel);
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  min-height: 0;
  z-index: 2;
}

/* Kopfzeile im Editor */
.ed-header {
  display: flex; align-items: center; gap: 10px;
  padding: 10px 14px; border-bottom: 1px solid var(--border);
}
.ed-title { flex: 1; min-width: 0; display: flex; flex-direction: column; gap: 1px; }
#ed-name {
  width: 100%; background: transparent; border: 1px solid transparent; border-radius: 5px;
  padding: 3px 6px; margin-left: -6px; font-size: 1.02rem; font-weight: 700; color: #fff;
}
#ed-name:hover { border-color: var(--border); }
#ed-name:focus { outline: none; border-color: var(--primary); background: var(--bg); }
.save-status { font-size: 0.7rem; color: var(--faint); }
.save-status.saved::before { content: '✓ '; color: #34d399; }
.save-status.saved.cloud::before { content: '☁ '; color: #38bdf8; }
.save-status.dirty { color: var(--muted); }
.save-status.warn { color: #fbbf24; }

/* Etagen */
.floor-bar {
  display: flex; align-items: stretch; gap: 6px;
  padding: 6px; background: var(--bg); border-bottom: 1px solid var(--border);
}
.floor-actions { display: flex; align-items: center; gap: 2px; flex-shrink: 0; }

.floor-tabs {
  display: flex;
  gap: 4px;
  flex: 1;
  min-width: 0;
  overflow-x: auto;
  scrollbar-width: thin;
}
.floor-tab {
  flex: 0 0 auto;
  min-width: 52px;
  padding: 6px 9px;
  background: transparent;
  border: 1px solid transparent;
  border-radius: 6px;
  color: var(--muted);
  cursor: pointer;
  text-align: center;
  line-height: 1.15;
}
.floor-tab b { font-size: 0.8rem; white-space: nowrap; }
.floor-tab:hover { color: var(--text); }
.floor-tab.active { background: var(--panel); border-color: var(--border); color: var(--primary); }
.floor-tab .count {
  display: inline-block; min-width: 16px; margin-left: 3px; padding: 0 4px;
  border-radius: 8px; background: #334155; color: var(--muted); font-size: 0.62rem; font-weight: 600;
}

.toolbar {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 6px;
  padding: 10px 14px;
  background: #182234;
  border-bottom: 1px solid var(--border);
}
.toolbar-secondary { padding-top: 0; flex-wrap: nowrap; }
.toolbar-secondary .btn { flex: 1 1 0; padding: 7px 6px; white-space: nowrap; }
#btn-orient { min-width: 44px; }

.btn, .icon-btn, .seg-btn {
  border: none;
  border-radius: 6px;
  background: #334155;
  color: #fff;
  font-size: 0.78rem;
  font-weight: 600;
  cursor: pointer;
  transition: background 0.15s;
}
.btn { padding: 7px 11px; }
.btn:hover, .icon-btn:hover { background: #475569; }
.btn:disabled, .icon-btn:disabled { opacity: 0.4; cursor: default; }
.btn[aria-pressed="true"] { background: #0c4a6e; color: var(--primary); }
.btn-sm { padding: 5px 8px; font-size: 0.72rem; }
.btn-primary { background: var(--primary-strong); }
.btn-accent { background: #b45309; }
.btn-accent:hover { background: #92400e; }
.btn-primary:hover { background: #0369a1; }
.btn-danger { background: #991b1b; }
.btn-danger:hover { background: #b91c1c; }
.btn-danger-ghost { background: transparent; color: #fca5a5; border: 1px solid #7f1d1d; }
.btn-danger-ghost:hover { background: #450a0a; }
.btn-wide { width: 100%; }
.icon-btn { width: 32px; height: 31px; font-size: 1rem; line-height: 1; flex-shrink: 0; }
.icon-btn.sm { width: 26px; height: 28px; font-size: 0.9rem; background: transparent; color: var(--muted); }
.icon-btn.sm:hover:not(:disabled) { background: #334155; color: #fff; }
.icon-btn.sm.danger:hover:not(:disabled) { background: #7f1d1d; color: #fff; }

.seg { display: inline-flex; background: var(--bg); border-radius: 7px; padding: 2px; }
.seg-btn { background: transparent; color: var(--muted); padding: 6px 10px; }
.seg-btn.active { background: var(--primary-strong); color: #fff; }

.scroll {
  flex: 1;
  min-height: 0;
  overflow-y: auto;
  padding: 14px;
  display: flex;
  flex-direction: column;
  gap: 14px;
}

.card { background: var(--panel-2); border: 1px solid var(--border); border-radius: var(--radius); padding: 12px 14px; }
.card[hidden] { display: none; }
.card-head { display: flex; align-items: center; justify-content: space-between; gap: 8px; margin-bottom: 10px; }
.card-head h2 {
  font-size: 0.76rem; font-weight: 700; text-transform: uppercase; letter-spacing: 0.06em; color: var(--muted);
  white-space: nowrap;
}
.muted { color: var(--faint); font-weight: 600; }
.measure { font: 600 0.72rem ui-monospace, SFMono-Regular, Menlo, monospace; color: var(--accent); text-align: right; }
.hint { margin-top: 8px; font-size: 0.72rem; color: var(--faint); }
.hint:empty { display: none; }

.form-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }
.field { display: flex; flex-direction: column; gap: 4px; font-size: 0.72rem; color: var(--muted); }
.full { grid-column: 1 / -1; }
.field input, .field select, #list-filter, #lib-search, .ta {
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 5px;
  padding: 7px 8px;
  color: #fff;
  font-size: 0.82rem;
  width: 100%;
}
.field input:focus, .field select:focus, #list-filter:focus, #lib-search:focus, .ta:focus { outline: none; border-color: var(--primary); }
#editor-card.editing { border-color: #0369a1; box-shadow: 0 0 0 1px #0369a1 inset; }

.actions { display: flex; gap: 6px; margin-top: 4px; }
.actions .btn { flex: 1; }
.actions[hidden] { display: none; }

#list-filter { width: 150px; padding: 5px 8px; font-size: 0.75rem; }


/* Elementliste */
.element-list { list-style: none; display: flex; flex-direction: column; }
.element-list li {
  display: grid;
  grid-template-columns: auto minmax(0, 1fr) auto;
  align-items: center;
  gap: 8px;
  padding: 6px 4px;
  border-bottom: 1px solid #1e293b;
  border-radius: 5px;
  cursor: pointer;
  font-size: 0.76rem;
}
.element-list li:hover { background: #1e293b; }
.element-list li.selected { background: #0c4a6e; }
.element-list .name { font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.element-list .coords { font: 0.68rem ui-monospace, SFMono-Regular, Menlo, monospace; color: var(--faint); white-space: nowrap; }
.element-list .empty { cursor: default; color: var(--faint); display: block; padding: 10px 4px; }
.element-list .empty:hover { background: none; }

.tag { display: inline-block; padding: 2px 6px; border-radius: 4px; font-size: 0.64rem; font-weight: 700; white-space: nowrap; }
.tag-wand_aussen { background: #334155; color: #f8fafc; }
.tag-wand_innen  { background: #475569; color: #e2e8f0; }
.tag-fenster     { background: #075985; color: #e0f2fe; }
.tag-tuer        { background: #854d0e; color: #fef08a; }
.tag-gelaender   { background: #7c2d12; color: #ffedd5; }
.tag-zone        { background: #065f46; color: #a7f3d0; }
.tag-masslinie   { background: #831843; color: #fbcfe8; }
.tag-moebel      { background: #581c87; color: #e9d5ff; }

.help summary { cursor: pointer; font-size: 0.76rem; font-weight: 700; text-transform: uppercase; letter-spacing: 0.06em; color: var(--muted); }
.help ul { margin: 10px 0 0 16px; display: flex; flex-direction: column; gap: 5px; font-size: 0.75rem; color: #cbd5e1; }
kbd {
  font: 0.68rem ui-monospace, SFMono-Regular, Menlo, monospace;
  background: #1e293b; border: 1px solid var(--border); border-radius: 3px; padding: 0 4px;
}

/* ===== Zeichenfläche ===== */
#stage { position: relative; background: var(--canvas); overflow: hidden; min-height: 0; }
#cad { position: absolute; inset: 0; display: block; touch-action: none; cursor: default; }
#cad.tool-draw { cursor: crosshair; }
#cad.hovering { cursor: pointer; }
#cad.panning { cursor: grabbing; }

.compass {
  position: absolute; top: 14px; left: 14px;
  display: grid;
  grid-template-columns: auto auto auto;
  grid-template-areas: ". t ." "l c r" ". b .";
  align-items: center; justify-items: center;
  gap: 2px 8px;
  padding: 8px 12px;
  background: rgba(15, 23, 42, 0.85);
  backdrop-filter: blur(4px);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  font-size: 0.7rem;
  color: var(--muted);
  pointer-events: none;
  user-select: none;
}
.c-top { grid-area: t; font-weight: 700; }
.c-bottom { grid-area: b; }
.c-left { grid-area: l; }
.c-right { grid-area: r; }
.c-center { grid-area: c; color: var(--faint); }
.compass .south { color: var(--accent); font-weight: 700; }

.hud {
  position: absolute; right: 14px; bottom: 14px;
  padding: 7px 12px;
  background: rgba(15, 23, 42, 0.85);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  font: 0.72rem ui-monospace, SFMono-Regular, Menlo, monospace;
  color: var(--muted);
  pointer-events: none;
  white-space: nowrap;
}
.hud b { color: #fff; font-weight: 600; }

.toast {
  position: fixed; z-index: 50; left: 50%; bottom: 18px;
  transform: translate(-50%, 20px);
  max-width: min(90%, 480px);
  padding: 9px 14px;
  background: #0c4a6e;
  border: 1px solid #0369a1;
  border-radius: var(--radius);
  font-size: 0.8rem;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.2s, transform 0.2s;
}
.toast.show { opacity: 1; transform: translate(-50%, 0); }
.toast.warn { background: #78350f; border-color: #b45309; }

/* ===== Mobil: Plan oben, Bedienung unten ===== */
@media (max-width: 860px) {
  .editor {
    grid-template-columns: minmax(0, 1fr);
    grid-template-rows: minmax(0, 55fr) minmax(0, 45fr);
  }
  #stage { order: 1; }
  #sidebar { order: 2; border-right: none; border-top: 1px solid var(--border); }
  .compass { top: 8px; left: 8px; padding: 5px 8px; font-size: 0.62rem; }
  .hud { right: 8px; bottom: 8px; font-size: 0.64rem; }
  .field input, .field select { font-size: 16px; } /* verhindert iOS-Zoom */
}

/* ===== Bibliothek ===== */
.library {
  height: 100vh;
  height: 100dvh;
  overflow-y: auto;
  padding: 28px clamp(16px, 4vw, 48px) 48px;
}
.lib-topbar {
  display: flex; flex-wrap: wrap; justify-content: flex-end; align-items: center; gap: 10px;
  max-width: 1280px; margin: 0 auto 14px; min-height: 28px;
}
.acc-badge {
  display: inline-flex; align-items: center; gap: 6px;
  font-size: 0.76rem; color: var(--muted);
  max-width: 60vw; overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}
.acc-badge.cloud { color: #e2e8f0; }
.acc-dot { width: 8px; height: 8px; border-radius: 50%; background: #34d399; flex-shrink: 0; }
.lib-migrate {
  display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between; gap: 10px;
  max-width: 1280px; margin: 0 auto 16px; padding: 10px 14px;
  background: #0c4a6e; border: 1px solid #0369a1; border-radius: var(--radius); font-size: 0.84rem;
}
.lib-header {
  display: flex; flex-wrap: wrap; align-items: flex-end; justify-content: space-between; gap: 16px;
  max-width: 1280px; margin: 0 auto 20px;
}
.lib-title h1 { font-size: 1.6rem; font-weight: 750; letter-spacing: -0.02em; }
.lib-title p { color: var(--muted); font-size: 0.9rem; margin-top: 2px; }
.lib-actions { display: flex; flex-wrap: wrap; gap: 8px; }
.lib-actions .btn { padding: 9px 14px; font-size: 0.85rem; }

.lib-toolbar {
  display: flex; align-items: center; gap: 12px;
  max-width: 1280px; margin: 0 auto 16px;
}
#lib-count { white-space: nowrap; }
#lib-search { max-width: 360px; padding: 8px 10px; font-size: 0.85rem; }
.lib-warn {
  max-width: 1280px; margin: 0 auto 16px; padding: 10px 14px;
  background: #451a03; border: 1px solid #b45309; border-radius: var(--radius); color: #fde68a; font-size: 0.82rem;
}

.lib-grid {
  max-width: 1280px; margin: 0 auto;
  display: grid; gap: 16px;
  grid-template-columns: repeat(auto-fill, minmax(260px, 1fr));
}
.plan-card {
  display: flex; flex-direction: column;
  background: var(--panel-2); border: 1px solid var(--border); border-radius: 10px;
  overflow: hidden; cursor: pointer;
  transition: border-color 0.15s, transform 0.15s;
}
.plan-card:hover, .plan-card:focus-visible { border-color: #0369a1; outline: none; transform: translateY(-1px); }
.thumb-wrap { aspect-ratio: 16 / 10; background: var(--canvas); border-bottom: 1px solid var(--border); }
.thumb { display: block; width: 100%; height: 100%; }
.plan-info { padding: 12px 14px 6px; }
.plan-info h3 { font-size: 0.98rem; font-weight: 700; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.plan-info .meta { font-size: 0.74rem; color: var(--faint); margin-top: 3px; }
.plan-actions { display: flex; flex-wrap: wrap; gap: 6px; padding: 8px 14px 14px; }

.lib-empty {
  grid-column: 1 / -1; text-align: center; padding: 64px 16px;
  border: 1px dashed var(--border); border-radius: 12px;
}
.lib-empty h2 { font-size: 1.15rem; margin-bottom: 6px; }
.lib-empty p { color: var(--muted); margin-bottom: 18px; }
.lib-empty .row { justify-content: center; }
.lib-none { grid-column: 1 / -1; color: var(--muted); padding: 24px 0; }

.row { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 8px; }

/* ===== Dialoge ===== */
.dlg {
  margin: auto;
  width: min(440px, calc(100vw - 24px));
  max-height: calc(100dvh - 24px);
  background: var(--panel); color: var(--text);
  border: 1px solid var(--border); border-radius: 12px;
  padding: 0;
  box-shadow: 0 24px 64px rgba(0, 0, 0, 0.5);
}
.dlg.wide { width: min(760px, calc(100vw - 24px)); }
.dlg::backdrop { background: rgba(2, 6, 23, 0.7); backdrop-filter: blur(2px); }
.dlg form { display: flex; flex-direction: column; max-height: calc(100dvh - 26px); }
.dlg h2 { font-size: 1.05rem; padding: 16px 20px 0; }
.dlg-body { padding: 14px 20px 4px; overflow-y: auto; }
.dlg-text { color: #cbd5e1; font-size: 0.86rem; margin-bottom: 10px; }
.dlg-msg { padding: 0 20px; font-size: 0.8rem; color: #fca5a5; min-height: 0; }
.dlg-msg:empty { display: none; }
.dlg-msg.ok { color: #6ee7b7; }
.dlg-actions {
  display: flex; flex-wrap: wrap; justify-content: flex-end; gap: 8px;
  padding: 14px 20px 18px;
}
.dlg-actions .left { margin-right: auto; }
.dlg-actions .left + .left { margin-right: 0; }
.dlg-actions .left:has(+ .left) { margin-right: 0; }
.dlg-actions .left + :not(.left) { margin-left: auto; }

.ta { display: block; resize: vertical; line-height: 1.45; }
.ta-code { font: 0.72rem/1.45 ui-monospace, SFMono-Regular, Menlo, monospace; color: #7dd3fc; background: #090d16; white-space: pre; }
.ta-tall { min-height: 300px; height: 46dvh; }
.ta-wish { font-size: 0.85rem; }

.ai-steps { display: flex; flex-direction: column; gap: 16px; }
.step { display: grid; grid-template-columns: 28px minmax(0, 1fr); gap: 10px; }
.step > div { display: flex; flex-direction: column; gap: 6px; min-width: 0; }
.step b { font-size: 0.86rem; }
.step .hint { margin: 0; }
.step-no {
  width: 26px; height: 26px; border-radius: 50%;
  display: grid; place-items: center;
  background: #0c4a6e; color: var(--primary); font-weight: 700; font-size: 0.8rem;
}
.step .row { margin-top: 0; }

@media (max-width: 860px) {
  .library { padding-top: 18px; }
  .lib-title h1 { font-size: 1.3rem; }
  .lib-actions { width: 100%; }
  .lib-actions .btn { flex: 1; }
  .ta, .dlg input, .dlg select { font-size: 16px; }
  .ta-code { font-size: 12px; }
}
