/* ============================================================
   Plano – Theme (Journaling-Stil)
   Cloud Dancer + Terrakotta + Salbei
   ============================================================ */

:root {
  /* Farbpalette */
  --bg: #F2F0E9;            /* Cloud Dancer Hintergrund */
  --paper: #F6F4ED;         /* Canvas / Papier */
  --card: #FBFAF6;          /* Karten / Panels */
  --card-2: #FFFFFF;

  --terracotta: #C2674E;    /* Hauptakzent */
  --terracotta-dark: #AC583F;
  --terracotta-soft: #Eadfd9;

  --sage: #8FA178;          /* zweiter Akzent / Hilfslinien */
  --sage-soft: #DDE3D2;

  --ink: #3D3833;           /* Text */
  --ink-soft: #6B6457;      /* Möbel-Umrisse, sekundärer Text */
  --ink-faint: #9c9488;
  --dot: #C9C3B6;           /* Rasterpunkte */
  --line: #E3DFD4;          /* Trennlinien */
  --wall: #4A443D;          /* Wandfarbe */

  --shadow-soft: 0 8px 24px rgba(61, 56, 51, 0.10);
  --shadow-card: 0 2px 10px rgba(61, 56, 51, 0.07);
  --radius: 16px;
  --radius-sm: 10px;

  --font-hand: 'Caveat', 'Segoe Script', cursive;
  --font-body: 'Nunito', system-ui, -apple-system, sans-serif;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  height: 100%;
  background: var(--bg);
  color: var(--ink);
  font-family: var(--font-body);
  -webkit-font-smoothing: antialiased;
  overflow: hidden;
  overscroll-behavior: none;
  position: relative;
}

#app { height: 100vh; height: 100dvh; width: 100vw; }

button { font-family: var(--font-body); cursor: pointer; }

/* ============================================================
   App-Layout: Topbar + (Sidebar | Canvas | Detail) + Bottombar
   ============================================================ */
.app-shell {
  display: grid;
  grid-template-rows: auto 1fr;
  height: 100%;
}

.app-main {
  display: grid;
  grid-template-columns: 264px 1fr 280px;
  min-height: 0;
  position: relative;
}

/* ---------- Topbar ---------- */
.topbar {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 10px 16px;
  padding-top: calc(10px + env(safe-area-inset-top));
  background: var(--card);
  border-bottom: 1px solid var(--line);
}
.brand {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-right: 10px;
}
.brand .logo {
  width: 30px; height: 30px;
  border-radius: 50%;
  background: var(--terracotta);
  display: grid; place-items: center;
  color: #fff;
  font-family: var(--font-hand);
  font-size: 22px; font-weight: 700;
  box-shadow: var(--shadow-card);
}
.brand .name {
  font-family: var(--font-hand);
  font-size: 30px;
  font-weight: 700;
  line-height: 1;
  color: var(--ink);
}
.topbar-spacer { flex: 1; }
.room-dims {
  font-family: var(--font-hand);
  font-size: 22px;
  color: var(--ink-soft);
}

/* Buttons */
.btn {
  border: 1px solid var(--line);
  background: var(--card-2);
  color: var(--ink);
  padding: 8px 14px;
  border-radius: 999px;
  font-size: 14px;
  font-weight: 700;
  display: inline-flex;
  align-items: center;
  gap: 7px;
  transition: transform .06s ease, background .15s ease, border-color .15s ease;
}
.btn:hover { background: var(--bg); }
.btn:active { transform: translateY(1px); }
.btn.primary {
  background: var(--terracotta);
  border-color: var(--terracotta);
  color: #fff;
}
.btn.primary:hover { background: var(--terracotta-dark); border-color: var(--terracotta-dark); }
.btn.ghost { background: transparent; border-color: transparent; }
.btn.ghost:hover { background: var(--bg); }
.btn.danger { color: var(--terracotta-dark); border-color: var(--terracotta-soft); background: #fff; }
.btn.danger:hover { background: var(--terracotta-soft); }
.btn:disabled { opacity: .4; cursor: not-allowed; }
.btn .ico { font-size: 16px; line-height: 1; }
.icon-btn {
  width: 38px; height: 38px;
  border-radius: 50%;
  border: 1px solid var(--line);
  background: var(--card-2);
  display: grid; place-items: center;
  font-size: 18px;
  color: var(--ink);
}
.icon-btn:hover { background: var(--bg); }
.icon-btn:disabled { opacity: .35; cursor: not-allowed; }

/* ---------- Sidebar (Möbelbibliothek) ---------- */
.sidebar {
  background: var(--card);
  border-right: 1px solid var(--line);
  display: flex;
  flex-direction: column;
  min-height: 0;
}
.search {
  margin: 12px;
  position: relative;
}
.search input {
  width: 100%;
  padding: 10px 12px 10px 34px;
  border: 1px solid var(--line);
  border-radius: 999px;
  background: var(--card-2);
  font-family: var(--font-body);
  font-size: 14px;
  color: var(--ink);
}
.search input:focus { outline: 2px solid var(--sage-soft); border-color: var(--sage); }
.search .search-ico {
  position: absolute; left: 12px; top: 50%; transform: translateY(-50%);
  color: var(--ink-faint); font-size: 15px;
}

.categories {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 6px;
  padding: 0 12px 10px;
}
.cat {
  border: 1px solid var(--line);
  background: var(--card-2);
  border-radius: var(--radius-sm);
  padding: 8px 4px;
  text-align: center;
  font-size: 10.5px;
  font-weight: 700;
  color: var(--ink-soft);
  line-height: 1.15;
  display: flex; flex-direction: column; align-items: center; gap: 4px;
}
.cat .cat-ico { font-size: 18px; }
.cat.active { background: var(--sage-soft); border-color: var(--sage); color: var(--ink); }
.cat:hover { background: var(--bg); }

.lib-list {
  flex: 1;
  overflow-y: auto;
  padding: 6px 12px 16px;
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
  align-content: start;
}
.lib-item {
  background: var(--card-2);
  border: 1px solid var(--line);
  border-radius: var(--radius-sm);
  padding: 8px;
  cursor: grab;
  text-align: center;
  transition: border-color .15s ease, transform .06s ease, box-shadow .15s ease;
}
.lib-item:hover { border-color: var(--sage); box-shadow: var(--shadow-card); }
.lib-item:active { cursor: grabbing; transform: scale(.98); }
.lib-item .thumb {
  height: 64px;
  display: grid; place-items: center;
  margin-bottom: 6px;
}
.lib-item .thumb svg { width: 100%; height: 100%; }
.lib-item .label {
  font-size: 11.5px;
  font-weight: 700;
  color: var(--ink-soft);
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.lib-item .mini-size { font-size: 10.5px; color: var(--ink-faint); margin-top: 2px; }
.lib-empty { grid-column: 1/-1; color: var(--ink-faint); font-size: 13px; text-align: center; padding: 20px 0; line-height: 1.45; }

/* Meine Möbel */
.myfurniture-btn {
  display: flex; align-items: center; justify-content: center; gap: 7px;
  margin: 0 12px 8px; padding: 9px;
  border: 1px dashed var(--terracotta); background: var(--terracotta-soft);
  color: var(--terracotta-dark); border-radius: 999px; font-weight: 800; font-size: 13px;
}
.myfurniture-btn.active { background: var(--terracotta); color: #fff; border-style: solid; border-color: var(--terracotta); }
.myfurniture-btn .cat-ico { font-size: 15px; }
.lib-item.mine { position: relative; padding: 7px; }
.lib-item.mine .thumb { height: 44px; margin-bottom: 4px; }
.lib-item.mine .label {
  white-space: normal; font-size: 11px; line-height: 1.2;
  display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden;
}
.lib-item.mine .mini-size { font-size: 10px; margin-top: 1px; }
.lib-del {
  position: absolute; top: 5px; right: 5px; width: 20px; height: 20px;
  border-radius: 50%; border: none; background: rgba(61, 56, 51, .08);
  color: var(--ink-soft); font-size: 11px; line-height: 1; display: none;
}
.lib-item.mine:hover .lib-del { display: block; }
.lib-del:hover { background: var(--terracotta-soft); color: var(--terracotta-dark); }
.detail .btn.block { width: 100%; justify-content: center; margin-top: 14px; }

/* ---------- Canvas ---------- */
.canvas-wrap {
  position: relative;
  background: var(--bg);
  min-height: 0;
  overflow: hidden;
}
#stage-container { width: 100%; height: 100%; touch-action: none; }
#stage-container canvas { touch-action: none; }
.canvas-wrap.drop-hover::after {
  content: '';
  position: absolute; inset: 10px;
  border: 2px dashed var(--sage);
  border-radius: var(--radius);
  pointer-events: none;
}

/* ---------- Bottombar (über Canvas schwebend) ---------- */
.bottombar {
  position: absolute;
  bottom: calc(14px + env(safe-area-inset-bottom)); left: 50%; transform: translateX(-50%);
  display: flex; align-items: center; gap: 6px;
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: 999px;
  padding: 6px 10px;
  box-shadow: var(--shadow-soft);
}
.bottombar .zoom-val { font-weight: 700; font-size: 13px; width: 46px; text-align: center; color: var(--ink-soft); }
.bottombar .sep { width: 1px; height: 22px; background: var(--line); margin: 0 4px; }
.unit-toggle {
  display: inline-flex; border: 1px solid var(--line); border-radius: 999px; overflow: hidden; background: var(--card-2);
}
.unit-toggle button {
  border: none; background: transparent; padding: 7px 12px; font-weight: 700; font-size: 13px; color: var(--ink-soft);
}
.unit-toggle button.active { background: var(--sage); color: #fff; }
.scale-note { font-size: 11px; color: var(--ink-faint); margin-left: 4px; }

/* ---------- Detail-Panel ---------- */
.detail {
  background: var(--card);
  border-left: 1px solid var(--line);
  padding: 18px 16px;
  overflow-y: auto;
}
.detail h2 {
  font-family: var(--font-hand);
  font-size: 28px;
  margin: 0 0 2px;
  font-weight: 700;
}
.detail .sub { color: var(--ink-faint); font-size: 12.5px; margin-bottom: 16px; }
.detail .empty-hint { color: var(--ink-faint); font-size: 13.5px; line-height: 1.5; }
.field-label {
  font-size: 11px; font-weight: 800; letter-spacing: .06em; text-transform: uppercase;
  color: var(--ink-faint); margin: 16px 0 7px;
}
.size-row { display: flex; gap: 10px; }
.size-row .field { flex: 1; }
.field input, .field select {
  width: 100%; padding: 9px 10px; border: 1px solid var(--line); border-radius: var(--radius-sm);
  background: var(--card-2); font-family: var(--font-body); font-size: 14px; color: var(--ink);
}
.field input:focus { outline: 2px solid var(--sage-soft); border-color: var(--sage); }
.field .mini { font-size: 11px; color: var(--ink-faint); margin-bottom: 4px; display: block; }
.detail .row-btns { display: flex; gap: 8px; margin-top: 14px; }
.detail .row-btns .btn { flex: 1; justify-content: center; }
.tip {
  margin-top: 18px; background: var(--sage-soft); border-radius: var(--radius-sm);
  padding: 11px 12px; font-size: 12.5px; color: var(--ink); line-height: 1.45;
}
.tip b { color: var(--terracotta-dark); }

/* ---------- Dialoge ---------- */
.overlay {
  position: fixed; inset: 0; background: rgba(61,56,51,.34);
  display: grid; place-items: center; z-index: 50; padding: 20px;
  overflow-y: auto;
}
.dialog {
  background: var(--card);
  border-radius: var(--radius);
  box-shadow: var(--shadow-soft);
  width: 100%; max-width: 460px;
  padding: 22px;
  animation: pop .16s ease;
  max-height: calc(100vh - 40px);
  max-height: calc(100dvh - 40px);
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
}
@keyframes pop { from { transform: scale(.96); opacity: 0; } to { transform: scale(1); opacity: 1; } }
.dialog.wide { max-width: 560px; }
.dialog-head { display: flex; align-items: center; justify-content: space-between; margin-bottom: 14px; }
.dialog-head h3 { font-family: var(--font-hand); font-size: 30px; margin: 0; font-weight: 700; }
.dialog-close { border: none; background: transparent; font-size: 22px; color: var(--ink-faint); line-height: 1; }
.dialog-close:hover { color: var(--ink); }

.tabs { display: flex; background: var(--bg); border-radius: 999px; padding: 4px; margin-bottom: 16px; }
.tabs button { flex: 1; border: none; background: transparent; padding: 9px; border-radius: 999px; font-weight: 700; color: var(--ink-soft); }
.tabs button.active { background: var(--card-2); color: var(--ink); box-shadow: var(--shadow-card); }

.shape-option {
  display: flex; align-items: center; gap: 12px;
  border: 1px solid var(--line); border-radius: var(--radius-sm);
  padding: 12px 14px; margin-bottom: 8px; background: var(--card-2);
  cursor: pointer;
}
.shape-option.active { border-color: var(--sage); background: var(--sage-soft); }
.shape-option.disabled { opacity: .5; cursor: default; }

.l-params { margin-bottom: 4px; }
.corner-row { display: flex; gap: 6px; margin-bottom: 4px; }
.corner-btn {
  flex: 1; border: 1px solid var(--line); background: var(--card-2);
  border-radius: var(--radius-sm); padding: 9px; font-size: 17px; color: var(--ink-soft);
}
.corner-btn.active { border-color: var(--sage); background: var(--sage-soft); color: var(--ink); }
.preview-box svg { border-radius: 8px; }
.shape-option .glyph { width: 26px; height: 26px; border: 2px solid var(--ink-soft); border-radius: 4px; }
.shape-option .glyph.l { border-radius: 4px; clip-path: polygon(0 0, 60% 0, 60% 55%, 100% 55%, 100% 100%, 0 100%); }
.shape-option .txt b { font-size: 15px; }
.shape-option .txt span { font-size: 12px; color: var(--ink-faint); margin-left: 6px; }
.shape-option .badge-soon { margin-left: auto; font-size: 10px; font-weight: 800; color: var(--sage); border: 1px solid var(--sage); border-radius: 999px; padding: 2px 8px; }

.dim-row { display: flex; gap: 12px; margin: 14px 0 4px; }
.dim-row .field { flex: 1; }
.preview-box { display: grid; place-items: center; margin: 14px 0; }
.dialog .btn.block { width: 100%; justify-content: center; padding: 12px; font-size: 15px; margin-top: 12px; }

.format-row { display: flex; gap: 10px; margin-bottom: 14px; }
.format-row button {
  flex: 1; border: 1px solid var(--line); background: var(--card-2); padding: 12px; border-radius: var(--radius-sm); font-weight: 700; color: var(--ink-soft);
}
.format-row button.active { border-color: var(--terracotta); background: var(--terracotta-soft); color: var(--terracotta-dark); }
.checkbox-row { display: flex; align-items: center; gap: 9px; font-size: 14px; margin-bottom: 6px; }
.checkbox-row input { width: 17px; height: 17px; accent-color: var(--sage); }
.dialog .note { font-size: 12px; color: var(--ink-faint); text-align: center; margin-top: 12px; }

/* Meine Räume */
.rooms-list { display: flex; flex-direction: column; gap: 8px; max-height: 340px; overflow-y: auto; }
.room-row { display: flex; align-items: center; gap: 10px; border: 1px solid var(--line); border-radius: var(--radius-sm); padding: 10px 12px; background: var(--card-2); }
.room-row .r-name { flex: 1; font-weight: 700; }
.room-row .r-meta { font-size: 12px; color: var(--ink-faint); }
.rooms-empty { color: var(--ink-faint); text-align: center; padding: 20px; }

/* Toast */
.toast {
  position: fixed; bottom: 78px; left: 50%; transform: translateX(-50%);
  background: var(--ink); color: #fff; padding: 10px 18px; border-radius: 999px;
  font-size: 14px; font-weight: 700; box-shadow: var(--shadow-soft); z-index: 60;
  opacity: 0; transition: opacity .2s ease, transform .2s ease; pointer-events: none;
}
.toast.show { opacity: 1; transform: translateX(-50%) translateY(0); }

/* Mobile-Umschalter (nur auf schmalen Geräten sichtbar) */
.mobile-toggle { display: none; }

/* Responsive: schmale Geräte */
@media (max-width: 920px) {
  .mobile-toggle { display: grid; }
  .app-main { grid-template-columns: 1fr; }
  .sidebar { position: absolute; z-index: 20; width: 264px; height: 100%; transform: translateX(-100%); transition: transform .2s ease; box-shadow: var(--shadow-soft); }
  .sidebar.open { transform: translateX(0); }
  /* Detail-Panel als Bottom-Sheet (Grundriss bleibt oben sichtbar) */
  .detail {
    position: absolute; left: 0; right: 0; bottom: 0; width: auto;
    height: auto; max-height: 48vh; overflow-y: auto; z-index: 25;
    border-left: none; border-top: 1px solid var(--line);
    border-radius: 20px 20px 0 0;
    box-shadow: 0 -10px 28px rgba(61, 56, 51, .16);
    padding: 8px 16px calc(18px + env(safe-area-inset-bottom));
    transform: translateY(110%);
    transition: transform .22s ease;
  }
  .detail.open { transform: translateY(0); }
  .detail::before {
    content: ''; display: block; width: 42px; height: 4px; border-radius: 2px;
    background: var(--line); margin: 4px auto 10px;
  }
  body.detail-open .bottombar { display: none; }
  .room-dims { display: none; }
}
@media (max-width: 560px) {
  .topbar { gap: 4px; padding: 8px 10px; overflow-x: auto; }
  .brand .name { font-size: 24px; }
}
