:root {
  --ink: #1F2A33;
  --muted: #67737E;
  --line: #E0E4E8;
  --panel: #FFFFFF;
  --paper: #EEF1F3;
  --accent: #2952E3;
  --accent-soft: #EAEFFD;
  --font: 'Avenir Next', Avenir, 'Segoe UI', system-ui, sans-serif;
}

* { box-sizing: border-box; }
html, body { height: 100%; margin: 0; }

body {
  font: 13px/1.4 var(--font);
  color: var(--ink);
  background: var(--panel);
  display: grid;
  grid-template-columns: 212px 1fr 296px;
  grid-template-rows: 48px 1fr 28px;
  grid-template-areas:
    "top top top"
    "rail stage insp"
    "status status status";
  overflow: hidden;
}

/* ---------- top bar ---------- */
.top {
  grid-area: top;
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 0 12px;
  border-bottom: 1px solid var(--line);
  min-width: 0;
}
.brand { display: flex; align-items: center; gap: 8px; font-weight: 700; font-size: 15px; white-space: nowrap; }
.plans { display: flex; gap: 6px; align-items: center; }
.plans select { max-width: 200px; }
.spacer { flex: 1; }
.grp { display: flex; align-items: center; }
.grp > * { border-radius: 0; margin-left: -1px; }
.grp > :first-child { border-radius: 6px 0 0 6px; margin-left: 0; }
.grp > :last-child { border-radius: 0 6px 6px 0; }
.zoom-label {
  min-width: 52px; text-align: center; padding: 5px 6px;
  border: 1px solid var(--line); background: #fff; font-variant-numeric: tabular-nums;
}

button {
  font: inherit; color: inherit; background: #fff;
  border: 1px solid var(--line); border-radius: 6px;
  padding: 5px 10px; cursor: pointer; white-space: nowrap;
}
button:hover { background: #F3F5F7; }
button:disabled { opacity: .45; cursor: default; }
button:focus-visible, input:focus-visible, select:focus-visible {
  outline: 2px solid var(--accent); outline-offset: 1px;
}
select, input[type=text], input[type=number] {
  font: inherit; color: inherit; background: #fff;
  border: 1px solid var(--line); border-radius: 6px; padding: 4px 7px;
  min-width: 0;
}
input[type=number] { font-variant-numeric: tabular-nums; }
input:disabled, select:disabled { background: #F5F6F7; color: #A5ADB4; }

/* ---------- tool rail ---------- */
.rail { grid-area: rail; border-right: 1px solid var(--line); overflow-y: auto; overflow-x: hidden; padding: 8px 10px 16px; }
.rail h4 { font-size: 12px; font-weight: 600; color: var(--muted); margin: 14px 2px 6px; }
.rail h4:first-child { margin-top: 4px; }
.tiles { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 6px; }
.tile {
  display: flex; flex-direction: column; align-items: stretch; gap: 4px;
  padding: 5px; border-radius: 8px; border: 1px solid transparent;
  background: none; font-size: 11.5px; text-align: center; line-height: 1.2; min-width: 0;
}
.tile:hover { background: #F3F5F7; }
.tile .ic { height: 46px; background: var(--paper); border-radius: 5px; display: grid; place-items: center; overflow: hidden; }
.tile .ic svg { max-width: 86%; max-height: 38px; overflow: visible; }
.tile.on { border-color: var(--accent); background: var(--accent-soft); }
.tile.on .ic { background: #DFE6FB; }

/* ---------- canvas ---------- */
.stage { grid-area: stage; position: relative; background: var(--paper); overflow: hidden; }
#canvas { width: 100%; height: 100%; display: block; touch-action: none; user-select: none; -webkit-user-select: none; }
#canvas.t-place { cursor: crosshair; }
#canvas.t-select .item { cursor: move; }
#canvas.t-pan, #canvas.space, #canvas.space .item { cursor: grab; }
#canvas.panning, #canvas.panning .item { cursor: grabbing; }
#canvas text { user-select: none; -webkit-user-select: none; }

.inline-pop {
  position: absolute; z-index: 5; transform: translate(-50%, -17px);
  display: flex; flex-direction: column; align-items: center; gap: 5px;
}
.inline-edit {
  width: 72px; padding: 4px 6px; text-align: center;
  font: 600 14px var(--font); color: var(--ink); background: #fff;
  border: 2px solid var(--accent); border-radius: 6px;
  box-shadow: 0 2px 8px rgba(31, 42, 51, .18); outline: none;
}
.pop-types {
  display: flex; background: #fff; border-radius: 7px; padding: 3px; gap: 2px;
  box-shadow: 0 2px 8px rgba(31, 42, 51, .18), 0 0 0 1px var(--line);
}
.pop-types button { border: 0; padding: 3px 8px; font-size: 12px; border-radius: 5px; }
.pop-types button.on { background: var(--ink); color: #fff; }

/* ---------- inspector ---------- */
.insp { grid-area: insp; border-left: 1px solid var(--line); overflow-y: auto; }
.insp section { padding: 14px 16px; border-bottom: 1px solid var(--line); }
.insp h2 { font-size: 16px; margin: 0 0 10px; font-weight: 700; }
.insp h3 { font-size: 13px; margin: 0 0 8px; font-weight: 600; }
.insp p { margin: 6px 0; }
.muted { color: var(--muted); }
.small { font-size: 12px; }

.f { display: grid; grid-template-columns: 92px 1fr auto; align-items: center; gap: 8px; margin: 7px 0; }
.f > span { color: var(--muted); }
.f input, .f select { width: 100%; }
.f em { font-style: normal; color: var(--muted); }
.two { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.two .f { grid-template-columns: auto 1fr; }

.seg { display: flex; }
.seg button { flex: 1; border-radius: 0; margin-left: -1px; padding: 4px 6px; }
.seg button:first-child { border-radius: 6px 0 0 6px; margin-left: 0; }
.seg button:last-child { border-radius: 0 6px 6px 0; }
.seg button.on { background: var(--ink); color: #fff; border-color: var(--ink); position: relative; }

.rot { display: flex; gap: 6px; align-items: center; }
.rot input { width: 64px; flex: none; }
.rot button { padding: 4px 8px; }

.sides { display: grid; grid-template-columns: 52px 1fr 58px; gap: 6px 8px; align-items: center; }
.sides > span { color: var(--muted); }
.sides-actions { display: flex; gap: 6px; margin-top: 10px; flex-wrap: wrap; }
.sides-actions button { padding: 4px 8px; font-size: 12px; }

.chk { display: flex; gap: 8px; align-items: center; margin: 7px 0; cursor: pointer; }
.chk input { margin: 0; }

.swatches { display: flex; gap: 8px; flex-wrap: wrap; }
.sw { width: 24px; height: 24px; border-radius: 50%; padding: 0; border: 2px solid #fff; box-shadow: 0 0 0 1px var(--line); }
.sw:hover { box-shadow: 0 0 0 1px var(--muted); }
.sw.on { box-shadow: 0 0 0 2px var(--ink); }

.btns { display: flex; gap: 8px; margin-top: 10px; flex-wrap: wrap; }
.btn-primary { background: var(--ink); color: #fff; border-color: var(--ink); }
.btn-primary:hover { background: #33414D; }
.danger { color: #B3261E; }
.align { display: grid; grid-template-columns: repeat(3, 1fr); gap: 6px; }
.align button { padding: 4px 6px; font-size: 12px; }

.totals { display: flex; gap: 18px; margin-bottom: 10px; }
.totals div { display: flex; flex-direction: column; }
.totals b { font-size: 22px; line-height: 1.1; font-variant-numeric: tabular-nums; }
.totals span { color: var(--muted); font-size: 12px; }
.zone-list { width: 100%; border-collapse: collapse; font-size: 12.5px; }
.zone-list td { padding: 4px 0; border-top: 1px solid var(--line); font-variant-numeric: tabular-nums; }
.zone-list td.n { text-align: right; padding-left: 10px; color: var(--muted); }
.zone-vis { display: inline-flex; align-items: center; gap: 6px; margin-right: 6px; cursor: pointer; vertical-align: -2px; }
.zone-vis input { margin: 0; }
.zone-vis .dot { margin-right: 0; }
.linkish { border: 0; background: none; padding: 0; font: inherit; color: inherit; text-align: left; white-space: normal; }
.linkish:hover { background: none; text-decoration: underline; }
.zone-list tr.off .linkish, .zone-list tr.off td.n { color: #A5ADB4; }
.zone-list tr.off .dot { opacity: .35; }
.dot { display: inline-block; width: 10px; height: 10px; border-radius: 50%; margin-right: 7px; vertical-align: -1px; }
.sub { font-weight: 600; margin: 14px 0 4px; }

dl.keys { display: grid; grid-template-columns: auto 1fr; gap: 5px 12px; margin: 0; font-size: 12px; }
dl.keys dt { white-space: nowrap; }
dl.keys dd { margin: 0; color: var(--muted); }
kbd {
  font: inherit; font-size: 11px; padding: 1px 5px; border-radius: 4px;
  border: 1px solid var(--line); border-bottom-width: 2px; background: #FAFBFB;
}

/* ---------- status + toast ---------- */
.status {
  grid-area: status; display: flex; justify-content: space-between; align-items: center;
  padding: 0 12px; border-top: 1px solid var(--line); color: var(--muted); font-size: 12px;
  white-space: nowrap; overflow: hidden;
}
.status-right { display: flex; gap: 18px; }
#saveStatus.bad { color: #B3261E; font-weight: 600; }
.toast {
  position: fixed; bottom: 42px; left: 50%; transform: translateX(-50%);
  background: var(--ink); color: #fff; padding: 8px 14px; border-radius: 8px;
  opacity: 0; transition: opacity .18s; pointer-events: none;
}
.toast.show { opacity: 1; }

@media (prefers-reduced-motion: reduce) { .toast { transition: none; } }
@media (max-width: 1100px) {
  body { grid-template-columns: 176px 1fr 260px; }
  .brand { display: none; }
}

/* ---------- locked (online, opened without the private link) ---------- */
.locked { position: fixed; inset: 0; z-index: 50; display: grid; place-items: center; background: rgba(238, 241, 243, .92); }
.locked-card { max-width: 380px; padding: 24px 26px; background: #fff; border: 1px solid var(--line); border-radius: 12px; box-shadow: 0 8px 30px rgba(31, 42, 51, .12); }
.locked-card h2 { margin: 0 0 8px; font-size: 18px; }
.locked-card p { margin: 0; color: var(--muted); }

/* ---------- back to tools (website only) ---------- */
.crumb { color: var(--muted); text-decoration: none; white-space: nowrap; padding: 5px 8px; margin-right: -4px; border-radius: 6px; }
.crumb:hover { background: #F3F5F7; color: var(--ink); }
.crumb:focus-visible { outline: 2px solid var(--accent); outline-offset: 1px; }

/* ---------- save button ---------- */
.save-btn { background: var(--ink); border-color: var(--ink); color: #fff; min-width: 74px; position: relative; z-index: 1; }
.save-btn:hover { background: #33414D; }
.save-btn.failed { background: #B3261E; border-color: #B3261E; }

.unlock { display: flex; gap: 8px; margin-top: 14px; }
.unlock input { flex: 1; min-width: 0; }
.unlock button { background: var(--ink); border-color: var(--ink); color: #fff; }
.unlock-msg:not(:empty) { margin-top: 8px !important; color: #B3261E !important; font-weight: 600; }
