:root {
  --bg: #f4f6f5;
  --card: #ffffff;
  --text: #17201b;
  --muted: #66736b;
  --line: #e2e7e4;
  --brand: #166534;
  --brand-2: #15803d;
  --brand-soft: #e8f5ec;
  --empty: #16a34a;
  --empty-bg: #dcfce7;
  --pre: #dc2626;
  --pre-bg: #fee2e2;
  --freeze: #3c3c8c;
  --freeze-bg: #e0e0f5;
  --picked: #b8860b;
  --picked-bg: #fbf1d0;
  --mat: #7c3aed;
  --mat-bg: #ede9fe;
  --exp: #0e7490;
  --exp-bg: #cffafe;
  --sel: #f59e0b;
  --radius: 12px;
  --shadow: 0 1px 2px rgba(16, 24, 20, .06), 0 4px 16px rgba(16, 24, 20, .06);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  font-size: 15px;
  color: var(--text);
  background: var(--bg);
}
* { box-sizing: border-box; }
body { margin: 0; min-height: 100vh; -webkit-tap-highlight-color: transparent; }
button, input, select { font: inherit; color: inherit; }
h1, h2, h3 { margin: 0; font-weight: 650; letter-spacing: -.01em; }
h2 { font-size: 16px; }
h3 { font-size: 14px; color: var(--muted); text-transform: uppercase; letter-spacing: .04em; }

/* ---------- buttons / inputs ---------- */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  min-height: 38px; padding: 0 14px; border-radius: 10px; border: 1px solid var(--line);
  background: var(--card); cursor: pointer; white-space: nowrap; transition: background .15s, border-color .15s;
}
.btn:hover { background: #f1f4f2; }
.btn:disabled { opacity: .45; cursor: default; }
.btn.primary { background: var(--brand); border-color: var(--brand); color: #fff; }
.btn.primary:hover { background: var(--brand-2); }
.btn.danger { color: var(--pre); border-color: #f5c2c2; }
.btn.freeze { color: #fff; background: var(--freeze); border-color: var(--freeze); }
.btn.picked { color: #3d2c00; background: #f4d77a; border-color: #e9c45a; }
.btn.small { min-height: 30px; padding: 0 10px; font-size: 13px; border-radius: 8px; }
.btn.icon { padding: 0; width: 34px; min-height: 34px; }
.btn.active { outline: 2px solid var(--sel); outline-offset: 1px; background: #fff7e6; }
.btn.ghost { border-color: transparent; background: transparent; }
input[type=text], input[type=password], input[type=number], input:not([type]) {
  width: 100%; min-height: 40px; padding: 8px 12px; border-radius: 10px; border: 1px solid #d3dad6; background: #fff;
}
input:focus { outline: 2px solid #86efac; border-color: var(--brand-2); }
label.check { display: inline-flex; align-items: center; gap: 8px; cursor: pointer; user-select: none; }
label.check input { width: 20px; height: 20px; accent-color: var(--brand); }

/* ---------- layout ---------- */
.topbar {
  position: sticky; top: 0; z-index: 30; display: flex; align-items: center; gap: 10px; flex-wrap: wrap;
  padding: 10px 16px; background: #fff; border-bottom: 1px solid var(--line);
}
.brand { display: flex; align-items: center; gap: 10px; font-weight: 700; color: var(--brand); }
.brand .logo { width: 30px; height: 30px; border-radius: 9px; background: var(--brand); color: #fff; display: grid; place-items: center; font-size: 16px; }
.brand small { display: block; font-weight: 500; color: var(--muted); font-size: 12px; }
.topbar .spacer { flex: 1; }
.user-chip { padding: 5px 10px; border-radius: 99px; background: var(--brand-soft); color: var(--brand); font-weight: 600; font-size: 13px; }
.layout { display: grid; grid-template-columns: minmax(300px, 380px) 1fr; gap: 16px; padding: 16px; max-width: 1500px; margin: 0 auto; }
.col { display: flex; flex-direction: column; gap: 16px; min-width: 0; }
.card { background: var(--card); border-radius: var(--radius); box-shadow: var(--shadow); padding: 16px; min-width: 0; }
.card-head { display: flex; align-items: center; justify-content: space-between; gap: 10px; margin-bottom: 12px; flex-wrap: wrap; }
.muted { color: var(--muted); }
.row { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; }
.grow { flex: 1; }

/* ---------- tree ---------- */
.tree { max-height: calc(100vh - 150px); overflow: auto; margin: 0 -8px; padding: 0 8px; }
.t-room, .t-stand { margin: 2px 0; }
.t-head {
  display: flex; align-items: center; gap: 8px; width: 100%; padding: 8px 10px; border-radius: 9px;
  border: 0; background: transparent; cursor: pointer; text-align: left;
}
.t-head:hover { background: #f1f4f2; }
.t-room > .t-head { font-weight: 650; }
.t-stand > .t-head { font-size: 14px; }
.t-caret { width: 14px; color: var(--muted); transition: transform .15s; flex: none; }
.open > .t-head .t-caret { transform: rotate(90deg); }
.t-kids { margin-left: 14px; border-left: 1px dashed var(--line); padding-left: 6px; }
.t-free { margin-left: auto; font-size: 11px; font-weight: 600; color: var(--empty); background: var(--empty-bg); border-radius: 99px; padding: 2px 8px; white-space: nowrap; }
.t-cont {
  display: flex; align-items: center; gap: 8px; width: 100%; padding: 7px 10px; margin: 2px 0; border-radius: 9px;
  border: 1px solid transparent; background: transparent; cursor: pointer; text-align: left; font-size: 14px;
}
.t-cont:hover { background: #f6f8f7; }
.t-cont.sel { border-color: var(--sel); background: #fff7e6; }
.t-cont.empty { background: var(--empty-bg); }
.t-cont.freeze { background: var(--freeze); color: #fff; }
.t-cont.freeze .badge { background: rgba(255,255,255,.2); color: #fff; }
.t-cont.sel.freeze { outline: 2px solid var(--sel); }
.t-cont .meta { margin-left: auto; color: var(--muted); font-size: 12px; white-space: nowrap; }
.t-cont.freeze .meta { color: #dfe0ff; }
.dot { width: 10px; height: 10px; border-radius: 3px; flex: none; background: #cbd5d0; }
.dot.empty { background: var(--empty); } .dot.pre { background: var(--pre); } .dot.freeze { background: var(--freeze); }
.dot.mat { background: var(--mat); } .dot.exp { background: var(--exp); } .dot.lg { background: var(--picked); }
.badge { font-size: 11px; font-weight: 600; border-radius: 99px; padding: 2px 7px; white-space: nowrap; }
.badge.pre { background: var(--pre-bg); color: var(--pre); }
.badge.freeze { background: var(--freeze-bg); color: var(--freeze); }
.badge.mat { background: var(--mat-bg); color: var(--mat); }
.badge.exp { background: var(--exp-bg); color: var(--exp); }
.badge.frozen { background: var(--freeze-bg); color: var(--freeze); }
.badge.picked { background: var(--picked-bg); color: var(--picked); }
.badge.empty { background: var(--empty-bg); color: var(--empty); }

/* ---------- notifications ---------- */
.notes { display: grid; gap: 8px; }
.note { border-radius: 10px; padding: 10px 12px; font-size: 14px; line-height: 1.6; }
.note b { margin-right: 6px; }
.note.pre { background: var(--pre-bg); color: #8f1d1d; }
.note.freeze { background: var(--freeze-bg); color: var(--freeze); }
.note.ok { background: var(--brand-soft); color: var(--brand); }
.link { border: 0; background: none; padding: 0; color: inherit; text-decoration: underline; cursor: pointer; font: inherit; }
.note .link { margin-right: 4px; }
.note-list { max-height: 7.5em; overflow: auto; }

/* ---------- container form ---------- */
.form-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(170px, 1fr)); gap: 10px 12px; }
.field label { display: block; font-size: 12px; color: var(--muted); margin-bottom: 4px; font-weight: 600; }
.sel-title { font-size: 18px; font-weight: 700; }
.lock { margin-top: 10px; padding: 10px 12px; border-radius: 10px; background: var(--picked-bg); color: #6b4e00; font-size: 14px; }
.transfer-hint { margin-top: 10px; padding: 10px 12px; border-radius: 10px; background: #fff7e6; color: #8a5300; font-size: 14px; }
.actions { display: flex; gap: 8px; flex-wrap: wrap; margin-top: 14px; }
.actions .sep { flex: 1; }

/* ---------- logistics ---------- */
.lg-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 14px; }
.lg-box h3 { margin-bottom: 8px; }
.lg-box.frozen h3 { color: var(--freeze); } .lg-box.picked h3 { color: var(--picked); }
.lg-list { border: 1px solid var(--line); border-radius: 10px; max-height: 220px; overflow: auto; min-height: 60px; }
.lg-item { display: flex; gap: 8px; align-items: flex-start; padding: 8px 10px; border-bottom: 1px solid var(--line); font-size: 13px; cursor: pointer; }
.lg-item:last-child { border-bottom: 0; }
.lg-item.on { background: #fff7e6; }
.lg-item input { margin-top: 2px; width: 18px; height: 18px; accent-color: var(--brand); flex: none; }
.lg-empty { padding: 14px; color: var(--muted); font-size: 13px; text-align: center; }

/* ---------- search ---------- */
.results { margin-top: 12px; max-height: 360px; overflow: auto; border-radius: 10px; border: 1px solid var(--line); }
.res { display: block; width: 100%; text-align: left; border: 0; border-bottom: 1px solid var(--line); background: #fff; padding: 9px 12px; cursor: pointer; font-size: 13px; }
.res:hover { background: #f6f8f7; }
.res b { font-size: 14px; }
.res-sum { padding: 10px 12px; font-weight: 600; background: #f8faf9; font-size: 14px; }

/* ---------- temps ---------- */
.temps { display: grid; grid-template-columns: repeat(auto-fill, minmax(110px, 1fr)); gap: 8px; }
.temps .field input { text-align: center; }

/* ---------- tables (logs) ---------- */
.table-wrap { overflow: auto; max-height: calc(100vh - 220px); border: 1px solid var(--line); border-radius: 10px; }
table { border-collapse: collapse; width: 100%; font-size: 13px; }
th, td { padding: 8px 10px; border-bottom: 1px solid var(--line); text-align: left; vertical-align: top; }
th { position: sticky; top: 0; background: #f8faf9; font-weight: 650; z-index: 1; }
.tabs { display: flex; gap: 6px; margin-bottom: 12px; flex-wrap: wrap; }
.tab { border: 1px solid var(--line); background: #fff; border-radius: 99px; padding: 6px 14px; cursor: pointer; }
.tab.on { background: var(--brand); color: #fff; border-color: var(--brand); }

/* ---------- editor ---------- */
.ed-layout { display: grid; grid-template-columns: minmax(320px, 460px) 1fr; gap: 16px; padding: 16px; max-width: 1600px; margin: 0 auto; }
.ed-list { display: flex; flex-direction: column; gap: 8px; }
.ed-room { border: 1px solid var(--line); border-radius: 12px; background: #fff; }
.ed-room.dragging, .ed-stand.dragging, .chip.dragging { opacity: .6; box-shadow: 0 6px 20px rgba(0,0,0,.15); }
.ed-room-head { display: flex; align-items: center; gap: 6px; padding: 8px; flex-wrap: wrap; }
.ed-room-head .name { font-weight: 650; flex: 1; min-width: 100px; }
.handle { cursor: grab; touch-action: none; user-select: none; padding: 6px 8px; color: var(--muted); border-radius: 8px; font-size: 16px; line-height: 1; }
.handle:active { cursor: grabbing; background: #eef2ef; }
.ed-stands { padding: 0 8px 8px 8px; display: flex; flex-direction: column; gap: 6px; }
.ed-stand { display: flex; align-items: center; gap: 6px; padding: 6px; border-radius: 10px; background: #f7f9f8; flex-wrap: wrap; }
.ed-stand .sname { font-weight: 600; font-size: 14px; min-width: 70px; }
.ed-stand input[type=number] { width: 70px; min-height: 32px; padding: 4px 8px; }
.chips { display: flex; gap: 4px; flex-wrap: wrap; width: 100%; padding-left: 34px; }
.chip { display: inline-flex; align-items: center; gap: 2px; border-radius: 8px; border: 1px solid var(--line); background: #fff; font-size: 12px; padding: 2px 2px 2px 0; }
.chip.full { border-color: #b7d8c2; background: #f0faf3; }
.chip .handle { padding: 4px 6px; font-size: 12px; }
.chip .x { border: 0; background: none; color: var(--muted); cursor: pointer; padding: 2px 5px; font-size: 13px; }
.chip .x:hover { color: var(--pre); }
.map-card { position: sticky; top: 72px; }
.map-editor { width: 100%; height: calc(100vh - 200px); min-height: 420px; border: 1px solid var(--line); border-radius: 12px; background: #fbfcfb; touch-action: none; }

/* ---------- map ---------- */
svg.map { display: block; user-select: none; }
.m-room { fill: #f3f7f4; stroke: #b9c8be; stroke-width: 1.5; }
.m-room.corr { fill: #f7f4ec; stroke: #d6c9a4; }
.m-room-title { font-size: 13px; font-weight: 650; fill: #3e4d44; pointer-events: none; }
.m-stand { fill: #fff; stroke: #9aaaa0; stroke-width: 1; }
.m-cell { fill: #cbd5d0; cursor: pointer; }
.m-cell.empty { fill: #86efac; }
.m-cell.filled { fill: #a8b5ad; }
.m-cell.mat { fill: #a78bfa; }
.m-cell.exp { fill: #67e8f9; }
.m-cell.pre { fill: var(--pre); }
.m-cell.freeze { fill: var(--freeze); }
.m-cell.lg-frozen { fill: #9a9ad6; }
.m-cell.lg-picked { fill: #e9c45a; }
.m-cell.sel { stroke: var(--sel); stroke-width: 3; }
.m-marker { fill: none; stroke: var(--sel); stroke-width: 3; pointer-events: none; animation: pulse 1.4s ease-in-out infinite; }
@keyframes pulse { 0%, 100% { stroke-opacity: 1; } 50% { stroke-opacity: .3; } }
.ed .m-room { cursor: move; }
.ed .m-stand-g { cursor: move; }
.ed .m-stand-g.on .m-stand { stroke: var(--sel); stroke-width: 2.5; }
.m-resize { fill: var(--brand); cursor: nwse-resize; }

.minimap {
  position: fixed; right: 16px; bottom: 16px; z-index: 40; width: 320px; background: #fff; border-radius: 14px;
  box-shadow: 0 8px 30px rgba(16, 24, 20, .18); overflow: hidden; border: 1px solid var(--line);
}
.minimap-head { display: flex; align-items: center; gap: 6px; padding: 6px 8px 6px 12px; font-size: 13px; font-weight: 650; border-bottom: 1px solid var(--line); }
.minimap-head .grow { color: var(--muted); font-weight: 500; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.minimap svg { width: 100%; height: 200px; background: #fbfcfb; }
.minimap.collapsed svg, .minimap.collapsed .legend { display: none; }
.minimap.collapsed { width: auto; }
.legend { display: flex; gap: 8px; flex-wrap: wrap; padding: 6px 10px 8px; font-size: 11px; color: var(--muted); }
.legend span { display: inline-flex; align-items: center; gap: 4px; }
.map-full { position: fixed; inset: 0; z-index: 60; background: rgba(15, 23, 19, .55); display: flex; padding: 16px; }
.map-full .card { flex: 1; display: flex; flex-direction: column; }
.map-full svg { flex: 1; width: 100%; min-height: 0; }

/* ---------- login ---------- */
.login-wrap { min-height: 100vh; display: grid; place-items: center; padding: 20px; background: linear-gradient(160deg, #e9f6ee, #f4f6f5 55%); }
.login { width: 100%; max-width: 380px; }
.login .brand { margin-bottom: 18px; font-size: 18px; }
.login .err { color: var(--pre); min-height: 22px; font-size: 14px; margin-top: 8px; }

/* ---------- toast / modal ---------- */
.toast {
  position: fixed; left: 50%; bottom: 24px; transform: translateX(-50%); z-index: 100; max-width: min(92vw, 520px);
  background: #17201b; color: #fff; padding: 12px 16px; border-radius: 12px; box-shadow: var(--shadow); font-size: 14px;
}
.toast.err { background: #991b1b; }
.modal-back { position: fixed; inset: 0; z-index: 90; background: rgba(15, 23, 19, .45); display: grid; place-items: center; padding: 16px; }
.modal { width: 100%; max-width: 420px; background: #fff; border-radius: 14px; padding: 18px; box-shadow: var(--shadow); }
.modal p { margin: 0 0 14px; line-height: 1.45; }
.modal .row { justify-content: flex-end; margin-top: 14px; }

/* ---------- mobile ---------- */
.mtabs { display: none; }
@media (max-width: 900px) {
  :root { font-size: 15px; }
  .layout, .ed-layout { grid-template-columns: 1fr; padding: 10px; gap: 10px; padding-bottom: 140px; }
  .topbar { padding: 8px 10px; }
  .topbar .btn .lbl { display: none; }
  .tree { max-height: none; }
  .lg-grid { grid-template-columns: 1fr; }
  .mtabs {
    display: flex; position: fixed; left: 0; right: 0; bottom: 0; z-index: 45; background: #fff; border-top: 1px solid var(--line);
    padding-bottom: env(safe-area-inset-bottom);
  }
  .mtabs button { flex: 1; border: 0; background: none; padding: 10px 4px; font-size: 12px; color: var(--muted); display: flex; flex-direction: column; align-items: center; gap: 2px; }
  .mtabs button.on { color: var(--brand); font-weight: 700; }
  .mtabs .ic { font-size: 18px; }
  body[data-mtab="tree"] .p-card, body[data-mtab="tree"] .p-more { display: none; }
  body[data-mtab="card"] .p-tree, body[data-mtab="card"] .p-more { display: none; }
  body[data-mtab="more"] .p-tree, body[data-mtab="more"] .p-card { display: none; }
  .minimap { right: 8px; bottom: 64px; width: 210px; }
  .minimap svg { height: 130px; }
  .legend { display: none; }
  .map-card { position: static; }
  .map-editor { height: 60vh; }
  .toast { bottom: 80px; }
}

[hidden] { display: none !important; }
