:root {
  --bg: #f4f2ec;
  --panel: #ffffff;
  --ink: #26241f;
  --muted: #7a766c;
  --accent: #b4552d;
  --accent-soft: #f3e3da;
  --wall: #33302a;
  --line: #e2ded4;
  --ok: #3c7a4e;
  --warn: #b3372c;
  font-size: 15px;
}
* { box-sizing: border-box; margin: 0; padding: 0; }
[hidden] { display: none !important; }
html, body { height: 100%; }
body {
  font-family: "Avenir Next", "Segoe UI", system-ui, sans-serif;
  background: var(--bg);
  color: var(--ink);
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

/* ---------- top bar ---------- */
#topbar {
  display: flex; align-items: center; gap: 16px;
  padding: 8px 14px;
  background: var(--panel);
  border-bottom: 1px solid var(--line);
  flex-wrap: wrap;
}
#btn-sidebar { display: none; }
@media (max-width: 900px) { #btn-sidebar { display: block; } }
.brand { display: flex; align-items: center; gap: 10px; }
.brand .logo { font-size: 26px; }
.brand h1 { font-size: 16px; font-weight: 700; letter-spacing: .2px; }
.brand .sub { font-size: 11.5px; color: var(--muted); }
.topbar-controls { display: flex; align-items: center; gap: 10px; }
#apt-select {
  padding: 6px 8px; border: 1px solid var(--line); border-radius: 8px;
  background: #fbfaf7; font-size: 13px; max-width: 260px;
}
.area-badge {
  font-size: 12px; padding: 5px 10px; border-radius: 999px;
  background: var(--accent-soft); color: var(--accent); font-weight: 600;
  white-space: nowrap;
}
.topbar-actions { display: flex; align-items: center; gap: 6px; margin-left: auto; flex-wrap: wrap; }
.topbar-actions .sep { width: 1px; height: 22px; background: var(--line); margin: 0 4px; }
button {
  font: inherit; font-size: 13px;
  padding: 6px 10px; border-radius: 8px; border: 1px solid var(--line);
  background: #fbfaf7; color: var(--ink); cursor: pointer;
  transition: background .12s, border-color .12s;
}
button:hover { background: #f1eee6; }
button.active { background: var(--accent-soft); border-color: var(--accent); color: var(--accent); }
button.primary { background: var(--accent); border-color: var(--accent); color: #fff; font-weight: 600; }
button.primary:hover { background: #9c4826; }
button.danger { color: var(--warn); border-color: #e8c8c4; }
button.danger:hover { background: #f9ecea; }

/* ---------- estimate banner ---------- */
#estimate-banner {
  background: #fdf6df; border-bottom: 1px solid #eadfb2;
  color: #6b5b13; font-size: 12.5px;
  padding: 6px 40px 6px 14px; position: relative;
}
#estimate-banner button {
  position: absolute; right: 8px; top: 3px;
  border: none; background: none; font-size: 16px; color: #6b5b13; padding: 2px 6px;
}
#estimate-banner.hidden { display: none; }

/* ---------- layout ---------- */
main { flex: 1; display: flex; min-height: 0; }
#sidebar {
  width: 250px; min-width: 250px;
  background: var(--panel); border-right: 1px solid var(--line);
  display: flex; flex-direction: column; overflow: hidden;
}
.sidebar-head { padding: 10px; border-bottom: 1px solid var(--line); }
#cat-search {
  width: 100%; padding: 7px 10px; border: 1px solid var(--line);
  border-radius: 8px; font: inherit; font-size: 13px; background: #fbfaf7;
}
#catalog { flex: 1; overflow-y: auto; padding: 6px 10px 10px; }
.cat-group h3 {
  font-size: 11px; text-transform: uppercase; letter-spacing: .8px;
  color: var(--muted); margin: 12px 0 6px; cursor: pointer; user-select: none;
}
.cat-group h3::before { content: "▾ "; }
.cat-group.closed h3::before { content: "▸ "; }
.cat-group.closed .cat-items { display: none; }
.cat-items { display: flex; flex-direction: column; gap: 4px; }
.cat-item {
  display: flex; justify-content: space-between; align-items: center;
  padding: 6px 9px; border: 1px solid var(--line); border-radius: 8px;
  background: #fbfaf7; cursor: pointer; font-size: 13px;
}
.cat-item:hover { border-color: var(--accent); background: var(--accent-soft); }
.cat-item .dims { font-size: 11px; color: var(--muted); }
.sidebar-tip {
  padding: 10px; border-top: 1px solid var(--line);
  font-size: 11px; color: var(--muted); line-height: 1.7;
}
kbd {
  background: #eeebe2; border: 1px solid #d8d4c8; border-bottom-width: 2px;
  border-radius: 4px; padding: 0 4px; font-size: 10px; font-family: inherit;
}

/* ---------- canvas ---------- */
#canvas-wrap { flex: 1; position: relative; min-width: 0; background:
  radial-gradient(circle at 30% 20%, #faf8f2 0%, var(--bg) 70%); }
#plan { width: 100%; height: 100%; display: block; touch-action: none; }
#plan .room-fill { stroke: none; }
#plan .room-name { font-weight: 700; fill: #4a463d; pointer-events: none; }
#plan .room-area { fill: #8a8578; pointer-events: none; }
#plan .dim-label { fill: #9b6a4f; pointer-events: none; font-weight: 600; }
#plan .fixture { fill: #d9d4c7; stroke: #b0aa9a; stroke-width: 14; }
#plan .fixture-label { fill: #8a8578; pointer-events: none; }
#plan .furn { cursor: grab; }
#plan .furn.dragging { cursor: grabbing; }
#plan .furn-shape { stroke: #00000033; stroke-width: 16; }
#plan .furn.selected .furn-shape { stroke: var(--accent); stroke-width: 34; }
#plan .furn.colliding .furn-shape { stroke: var(--warn); stroke-width: 34; stroke-dasharray: 60 40; }
#plan .furn-label { pointer-events: none; fill: #33302a; font-weight: 600; }
#plan .furn-dims { pointer-events: none; fill: #00000066; }
#plan .void-hatch { fill: url(#hatch); stroke: #b0aa9a; stroke-width: 10; }
#plan .void-label { fill: #a09a8c; pointer-events: none; }
#plan .street-label { fill: #b0a894; font-style: italic; pointer-events: none; }
#plan .measure-line { stroke: var(--accent); stroke-width: 20; stroke-dasharray: 50 30; }
#plan .measure-dot { fill: var(--accent); }
#plan .measure-text { fill: var(--accent); font-weight: 700; paint-order: stroke; stroke: #ffffffcc; stroke-width: 40; }

#zoom-controls {
  position: absolute; right: 14px; bottom: 40px;
  display: flex; flex-direction: column; gap: 5px;
}
#zoom-controls button { width: 36px; height: 36px; font-size: 16px; }
#measure-readout {
  position: absolute; left: 14px; bottom: 40px;
  background: var(--panel); border: 1px solid var(--accent);
  color: var(--accent); border-radius: 8px; padding: 6px 12px; font-size: 13px; font-weight: 600;
}

/* ---------- inspector ---------- */
#inspector {
  width: 230px; min-width: 230px;
  background: var(--panel); border-left: 1px solid var(--line);
  padding: 14px; overflow-y: auto;
}
#inspector h2 { font-size: 14px; margin-bottom: 10px; }
.insp-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }
.insp-grid label { font-size: 11px; color: var(--muted); display: flex; flex-direction: column; gap: 3px; }
.insp-grid label:first-child { grid-column: 1 / -1; }
.insp-grid input {
  width: 100%; padding: 5px 7px; border: 1px solid var(--line);
  border-radius: 6px; font: inherit; font-size: 13px; background: #fbfaf7;
}
.insp-grid input[type=color] { padding: 2px; height: 30px; }
.insp-actions { display: flex; gap: 6px; margin-top: 12px; flex-wrap: wrap; }
.insp-room { margin-top: 12px; font-size: 12px; color: var(--muted); }

/* ---------- modal ---------- */
#modal {
  position: fixed; inset: 0; background: #00000055; z-index: 50;
  display: flex; align-items: center; justify-content: center; padding: 20px;
}
.modal-card {
  background: var(--panel); border-radius: 14px; max-width: 760px; width: 100%;
  max-height: 86vh; display: flex; flex-direction: column; box-shadow: 0 18px 60px #00000033;
}
.modal-head {
  display: flex; justify-content: space-between; align-items: center;
  padding: 14px 18px; border-bottom: 1px solid var(--line);
}
.modal-head h2 { font-size: 15px; }
.modal-head button { border: none; background: none; font-size: 20px; }
.modal-body { padding: 16px 18px; overflow-y: auto; font-size: 13px; line-height: 1.6; }
.modal-body textarea {
  width: 100%; min-height: 320px; font-family: ui-monospace, "SF Mono", Menlo, monospace;
  font-size: 12px; border: 1px solid var(--line); border-radius: 8px; padding: 10px;
  background: #fbfaf7; resize: vertical;
}
.modal-body pre {
  background: #f6f4ee; border: 1px solid var(--line); border-radius: 8px;
  padding: 12px; font-size: 11.5px; white-space: pre-wrap; word-break: break-word;
  max-height: 300px; overflow-y: auto;
}
.modal-body .row { display: flex; gap: 8px; margin-top: 12px; flex-wrap: wrap; }

/* ---------- toast & status ---------- */
#toast {
  position: fixed; bottom: 46px; left: 50%; transform: translateX(-50%);
  background: var(--ink); color: #fff; font-size: 13px;
  padding: 9px 18px; border-radius: 999px; z-index: 60;
  box-shadow: 0 6px 24px #00000040;
}
#statusbar {
  display: flex; justify-content: space-between;
  background: var(--panel); border-top: 1px solid var(--line);
  font-size: 11px; color: var(--muted); padding: 4px 14px;
}

/* ---------- responsive ---------- */
@media (max-width: 900px) {
  #sidebar { position: absolute; z-index: 20; height: calc(100% - 96px); box-shadow: 4px 0 18px #00000022; transform: translateX(-100%); transition: transform .2s; }
  #sidebar.open { transform: none; }
  #inspector { position: absolute; right: 0; z-index: 20; height: calc(100% - 96px); box-shadow: -4px 0 18px #00000022; }
  .brand h1 { font-size: 13px; }
}
