:root {
  --ink: #26342e;
  --muted: #6f7b73;
  --line: #e1e7e2;
  --bg: #f3f5f1;
  --green: #3f6b55;
  --green-soft: #e8f1eb;
  --warn: #b86f1f;
  --danger: #b4473b;
}

* { box-sizing: border-box; }
html, body { margin: 0; }
body {
  min-width: 320px;
  color: var(--ink);
  background: var(--bg);
  font: 13px/1.4 Inter, ui-sans-serif, system-ui, -apple-system, "Segoe UI", sans-serif;
}
button, input, select { font: inherit; color: inherit; }

.topbar {
  display: flex;
  height: 60px;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  padding: 0 18px;
  border-bottom: 1px solid var(--line);
  background: #fff;
}
.brand { display: flex; min-width: 0; align-items: center; gap: 10px; }
.brand-mark {
  display: grid;
  width: 36px;
  height: 36px;
  flex: none;
  place-items: center;
  border-radius: 10px;
  background: var(--green-soft);
  color: var(--green);
}
.brand-mark svg { width: 21px; height: 21px; }
.brand strong { display: block; font-size: 14px; }
.brand span { display: block; color: var(--muted); font-size: 11px; }
.top-actions { display: flex; align-items: center; gap: 6px; }
.save-status { margin-right: 6px; color: var(--muted); font-size: 11px; white-space: nowrap; }
.save-status.error { color: var(--danger); }

.btn {
  display: inline-flex;
  min-height: 32px;
  align-items: center;
  justify-content: center;
  gap: 6px;
  padding: 0 11px;
  border: 1px solid #d9e2db;
  border-radius: 8px;
  background: #fff;
  cursor: pointer;
  font-size: 12px;
  white-space: nowrap;
}
.btn:hover { border-color: #b9cbbe; background: #f6faf7; }
.btn:disabled { cursor: default; opacity: 0.45; background: #fff; }
.btn.primary { border-color: var(--green); background: var(--green); color: #fff; }
.btn.primary:hover { background: #355c48; }
.btn.danger { color: var(--danger); }
.btn.danger:hover { border-color: #e6c3bd; background: #fff5f3; }
.btn.active { border-color: #8fb39b; background: var(--green-soft); color: #2c5340; font-weight: 600; }
.btn.icon { width: 32px; padding: 0; font-size: 16px; }
.btn svg { width: 15px; height: 15px; flex: none; }
.btn.wide { width: 100%; }

.layout {
  display: grid;
  height: calc(100vh - 60px);
  min-height: 560px;
  grid-template-columns: 310px minmax(0, 1fr) 290px;
}
.sidebar, .inspector {
  min-height: 0;
  overflow-y: auto;
  background: #f8faf7;
  scrollbar-width: thin;
}
.sidebar { border-right: 1px solid var(--line); }
.inspector { padding: 12px; border-left: 1px solid var(--line); }

.tabs {
  position: sticky;
  top: 0;
  z-index: 1;
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 4px;
  padding: 10px 12px;
  border-bottom: 1px solid var(--line);
  background: #f8faf7;
}
.tab {
  padding: 7px 0;
  border: 1px solid transparent;
  border-radius: 8px;
  background: none;
  color: var(--muted);
  cursor: pointer;
  font-size: 12px;
  font-weight: 600;
}
.tab[aria-selected="true"] { border-color: var(--line); background: #fff; color: var(--ink); }
.tab-panel { display: grid; gap: 12px; padding: 12px; }
.tab-panel[hidden] { display: none; }

.panel {
  display: grid;
  gap: 9px;
  padding: 13px;
  border: 1px solid #e6ebe6;
  border-radius: 12px;
  background: #fff;
}
.panel h2 {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin: 0;
  font-size: 13px;
}
.hint { margin: 0; color: var(--muted); font-size: 11px; line-height: 1.5; }
.hint.warn, .warn { color: var(--warn); }
.mt { margin-top: 4px; }
.stack { display: grid; gap: 7px; }
.grid2 { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }
.grid3 { display: grid; grid-template-columns: repeat(3, 1fr); gap: 6px; }
.span2 { grid-column: span 2; }

.field { display: grid; min-width: 0; gap: 4px; color: #5f6b63; font-size: 11px; font-weight: 600; }
.field input, .field select {
  width: 100%;
  height: 32px;
  min-width: 0;
  padding: 0 8px;
  border: 1px solid #dbe3dd;
  border-radius: 7px;
  outline: 0;
  background: #fff;
  font-size: 12px;
  font-weight: 400;
  font-variant-numeric: tabular-nums;
}
.field input[type="color"] { padding: 2px; cursor: pointer; }
.field input:focus, .field select:focus { border-color: #85a891; box-shadow: 0 0 0 3px rgba(63, 107, 85, 0.13); }
.check { display: flex; align-items: center; gap: 7px; cursor: pointer; font-size: 12px; user-select: none; }
.check input { width: 15px; height: 15px; margin: 0; accent-color: var(--green); }
.check.inline { padding: 0 6px; font-size: 11px; }

.catalog { display: grid; grid-template-columns: 1fr 1fr; gap: 6px; }
.cat-btn {
  display: grid;
  gap: 1px;
  min-height: 46px;
  padding: 6px 8px 6px 30px;
  position: relative;
  border: 1px solid #e8ece8;
  border-radius: 8px;
  background: #fff;
  cursor: pointer;
  text-align: left;
}
.cat-btn:hover { border-color: #b9cbbe; background: #fafcfa; }
.cat-btn i {
  position: absolute;
  top: 50%;
  left: 8px;
  width: 15px;
  height: 15px;
  border: 1px solid rgba(0, 0, 0, 0.12);
  border-radius: 4px;
  transform: translateY(-50%);
}
.cat-btn strong { overflow: hidden; font-size: 11px; text-overflow: ellipsis; white-space: nowrap; }
.cat-btn small { color: var(--muted); font-size: 10px; }

.count {
  min-width: 22px;
  padding: 1px 6px;
  border-radius: 6px;
  background: #eff3ef;
  color: var(--muted);
  font-size: 10px;
  text-align: center;
}
.item-list { display: grid; gap: 3px; margin: 0; padding: 0; list-style: none; }
.item-list button {
  display: flex;
  width: 100%;
  align-items: center;
  gap: 8px;
  padding: 6px;
  border: 1px solid transparent;
  border-radius: 7px;
  background: none;
  cursor: pointer;
  text-align: left;
}
.item-list button:hover, .item-list button[aria-current="true"] { border-color: #e1e8e2; background: #f5f9f6; }
.item-list i { width: 14px; height: 14px; flex: none; border: 1px solid rgba(0, 0, 0, 0.12); border-radius: 4px; }
.item-list span { display: grid; min-width: 0; flex: 1; }
.item-list strong { overflow: hidden; font-size: 11px; font-weight: 600; text-overflow: ellipsis; white-space: nowrap; }
.item-list small { color: var(--muted); font-size: 10px; }
.item-list b { color: var(--warn); font-size: 12px; }
.item-list .err { color: var(--danger); }

.wall-list, .opening-list { display: grid; gap: 6px; }
.wall-row {
  display: grid;
  grid-template-columns: 24px minmax(0, 1fr) 92px;
  align-items: center;
  gap: 6px;
}
.wall-row .num {
  display: grid;
  width: 22px;
  height: 22px;
  place-items: center;
  border-radius: 6px;
  background: #eef3ef;
  color: var(--green);
  font-size: 11px;
  font-weight: 700;
}
.wall-row input {
  width: 100%;
  height: 30px;
  min-width: 0;
  padding: 0 7px;
  border: 1px solid #dbe3dd;
  border-radius: 7px;
  font-size: 12px;
}
.opening-row {
  display: flex;
  width: 100%;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  padding: 7px 9px;
  border: 1px solid #e6ece7;
  border-radius: 8px;
  background: #fff;
  cursor: pointer;
  font-size: 12px;
  text-align: left;
}
.opening-row:hover, .opening-row[aria-current="true"] { border-color: #b9cbbe; background: #f5f9f6; }
.opening-row small { color: var(--muted); }

.inspector h2 { margin: 2px 0 10px; font-size: 13px; }
.inspector .panel + .panel { margin-top: 10px; }
.empty-tips { display: grid; gap: 8px; margin: 0; padding-left: 18px; color: var(--muted); font-size: 12px; }

.stage {
  display: grid;
  min-width: 0;
  min-height: 0;
  grid-template-rows: auto minmax(0, 1fr) auto;
  gap: 10px;
  padding: 12px 14px;
}
.toolbar { display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between; gap: 8px; }
.toolbar-group { display: flex; align-items: center; gap: 6px; }
.zoom-label { min-width: 46px; color: var(--muted); font-size: 11px; font-variant-numeric: tabular-nums; text-align: center; }
.canvas-wrap {
  position: relative;
  min-height: 0;
  overflow: hidden;
  border: 1px solid #dde4de;
  border-radius: 14px;
  background: radial-gradient(circle at 1px 1px, rgba(100, 120, 106, 0.1) 1px, transparent 1.3px) 0 0 / 18px 18px, #eef2ef;
}
.plan { display: block; width: 100%; height: 100%; touch-action: none; user-select: none; cursor: grab; }
.plan.panning { cursor: grabbing; }
.plan [data-kind="item"] { cursor: move; }
.plan [data-kind="item"].locked { cursor: not-allowed; }
.plan [data-kind="rotate"] { cursor: crosshair; }
.plan [data-kind="opening"] { cursor: ew-resize; }
.plan [data-kind="vertex"] { cursor: move; }
.plan [data-kind="wall-add"] { cursor: copy; }
.statusbar {
  display: flex;
  min-height: 20px;
  flex-wrap: wrap;
  justify-content: space-between;
  gap: 4px 14px;
  color: var(--muted);
  font-size: 11px;
}
.statusbar .warn { font-weight: 600; }

@media (max-width: 1180px) {
  .layout {
    height: auto;
    grid-template-columns: 300px minmax(0, 1fr);
    grid-template-areas: "side stage" "side insp";
  }
  .sidebar { grid-area: side; max-height: none; }
  .stage { grid-area: stage; height: calc(100vh - 60px); min-height: 520px; }
  .inspector { grid-area: insp; border-top: 1px solid var(--line); border-left: 0; }
}

@media (max-width: 760px) {
  .topbar { padding: 0 12px; }
  .brand span, .save-status { display: none; }
  .layout { display: flex; flex-direction: column; }
  .stage { order: -2; height: 72vh; min-height: 440px; padding: 10px; }
  .inspector { order: -1; border-bottom: 1px solid var(--line); }
  .sidebar { border-right: 0; }
  .check.inline { display: none; }
}
