:root {
  color-scheme: dark;
  --bg: #0b1019;
  --bg-2: #111927;
  --panel: #151e2b;
  --panel-2: #1b2534;
  --line: #2b3a4f;
  --line-2: #3a4b63;
  --text: #e9eff9;
  --text-2: #a8bad0;
  --muted: #8296ae;
  --accent: #2b7be4;
  --accent-2: #4e9cff;
  --good: #3fd08b;
  --warn: #ffc065;
  --bad: #e8657f;
  --r: 10px;
  font-family: Inter, ui-sans-serif, system-ui, "Segoe UI", Roboto, Arial, sans-serif;
}
* { box-sizing: border-box; }
[hidden] { display: none !important; }
html, body { margin: 0; background: var(--bg); color: var(--text); }
body { min-height: 100vh; }
button, input, select, textarea { font: inherit; color: inherit; }
button {
  cursor: pointer; background: var(--panel-2); border: 1px solid var(--line-2);
  border-radius: 8px; padding: 8px 13px; transition: background .15s, border-color .15s, opacity .15s;
}
button:hover:not(:disabled) { background: #26364b; }
button:disabled { opacity: .5; cursor: not-allowed; }
button.primary { background: var(--accent); border-color: #3d8bf0; color: #fff; }
button.primary:hover:not(:disabled) { background: #3387f2; }
button.ghost { background: transparent; }
button.danger { background: #3a1e28; border-color: #8d3448; color: #ffb3c0; }
button.danger:hover:not(:disabled) { background: #4a2532; }
input, select, textarea {
  width: 100%; background: #0e1725; border: 1px solid var(--line-2); border-radius: 8px;
  padding: 9px 11px; outline: none;
}
input:focus, select:focus, textarea:focus { border-color: var(--accent-2); }
label { display: block; font-size: 12px; color: var(--muted); margin: 12px 0 5px; }
hr { border: 0; border-top: 1px solid var(--line); margin: 16px 0; }
h1 { font-size: 20px; margin: 0 0 6px; }
b { font-weight: 600; }

/* --- shell ------------------------------------------------------------------------------------------------------ */
.app { display: flex; flex-direction: column; min-height: 100vh; }
.top {
  display: flex; align-items: center; gap: 14px; flex-wrap: wrap;
  padding: 14px 20px; border-bottom: 1px solid var(--line); background: var(--bg-2);
  position: sticky; top: 0; z-index: 10;
}
.brand { display: flex; align-items: center; gap: 9px; font-size: 17px; letter-spacing: -.01em; }
.brand .logo, .gate-brand .logo {
  display: inline-grid; place-items: center; width: 30px; height: 30px; border-radius: 9px;
  background: linear-gradient(150deg, #2b7be4, #1b4f96); color: #fff; font-size: 16px;
}
.tabs { display: flex; gap: 4px; background: #0e1622; border: 1px solid var(--line); border-radius: 999px; padding: 4px; }
.tabs button { border: 0; background: transparent; border-radius: 999px; padding: 8px 16px; color: var(--text-2); }
.tabs button.on { background: var(--accent); color: #fff; }
.who { display: flex; align-items: center; gap: 8px; margin-left: auto; flex-wrap: wrap; }
.chip { padding: 6px 12px; border-radius: 999px; background: #16283f; border: 1px solid #2d4a6e; font-size: 13px; }
.chip::before { content: "●"; color: var(--good); margin-right: 6px; font-size: 10px; vertical-align: 1px; }
.status { font-size: 12px; color: var(--muted); min-width: 70px; }
main { padding: 18px 20px 40px; }

/* --- layout ----------------------------------------------------------------------------------------------------- */
.stats { display: grid; grid-template-columns: repeat(5, minmax(0, 1fr)); gap: 10px; margin-bottom: 14px; }
.stat { background: var(--panel); border: 1px solid var(--line); border-radius: var(--r); padding: 12px 14px; }
.stat b { display: block; font-size: 22px; letter-spacing: -.02em; }
.stat small { color: var(--muted); font-size: 12px; }
.layout { display: grid; grid-template-columns: minmax(0, 1fr) 300px; gap: 14px; align-items: start; }
.left { min-width: 0; }
.panel { background: var(--panel); border: 1px solid var(--line); border-radius: var(--r); padding: 14px; margin-bottom: 14px; }
.panel.inset { background: var(--panel-2); margin: 0; }
.layout > aside { position: sticky; top: 76px; margin-bottom: 0; }
.toolbar { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; margin-bottom: 12px; }
.toolbar strong { margin-right: auto; }
.toolbar input, .toolbar select { width: auto; min-width: 150px; flex: 0 1 260px; }
.toolbar input[type=search] { flex: 1 1 220px; }
.hint { color: var(--muted); font-size: 12px; line-height: 1.55; margin: 10px 0 0; }
.muted { color: var(--muted); font-weight: 400; font-size: 12px; }
.err { color: var(--bad); font-size: 13px; min-height: 18px; margin-top: 8px; }

/* --- plan ------------------------------------------------------------------------------------------------------- */
.board { background: #0d1624; border: 1px solid var(--line); border-radius: 8px; padding: 12px; overflow: auto; }
svg#map { width: 100%; min-width: 420px; max-height: 52vh; display: block; touch-action: none; }
.room { fill: #101d30; stroke: #a6b7ca; stroke-width: .05; }
.rack { cursor: grab; }
.rack rect { fill: #1d4d83; stroke: #68b8ff; stroke-width: .045; rx: .06; }
.rack.active rect { fill: #8c5920; stroke: var(--warn); stroke-width: .09; }
.rack text { fill: #f6f9ff; font-size: .17px; pointer-events: none; }
.rack text.small { font-size: .13px; fill: #cfe0f5; }
.grid { display: grid; grid-template-columns: 58px repeat(3, minmax(0, 1fr)); gap: 5px; }
.cell, .rowlabel {
  min-height: 62px; padding: 7px; border: 1px solid var(--line-2); border-radius: 6px;
  background: #1b2738; text-align: center;
}
.cell { cursor: pointer; }
.cell:hover { border-color: var(--accent-2); }
.cell.selected { background: #17395f; border-color: var(--accent-2); }
.cell b { display: block; font-size: 12px; }
.cell small { display: block; color: var(--muted); font-size: 11px; margin-top: 3px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.rowlabel { display: flex; align-items: center; justify-content: center; color: var(--muted); font-size: 12px; }
.lower { display: grid; grid-template-columns: minmax(0, 1fr) minmax(0, 1fr); gap: 12px; }
.item { display: flex; align-items: center; gap: 8px; padding: 8px 2px; border-bottom: 1px solid var(--line); }
.item:last-child { border-bottom: 0; }
.item .grow { flex: 1; min-width: 0; }
.item b { display: block; overflow-wrap: anywhere; }
.item small { color: var(--muted); font-size: 11px; }
.item .qty { font-variant-numeric: tabular-nums; font-size: 13px; color: var(--text-2); }
.item button { padding: 4px 8px; font-size: 12px; }
.pair { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }
.full { width: 100%; margin-top: 12px; }
.editor-empty { color: var(--muted); font-size: 12px; }

/* --- tables ----------------------------------------------------------------------------------------------------- */
.tablewrap { overflow-x: auto; }
.tbl { width: 100%; border-collapse: collapse; font-size: 14px; }
.tbl th, .tbl td { text-align: left; padding: 10px 8px; border-bottom: 1px solid var(--line); }
.tbl th { color: var(--muted); font-weight: 500; font-size: 12px; text-transform: uppercase; letter-spacing: .04em; }
.tbl td.num, .tbl th.num { text-align: right; font-variant-numeric: tabular-nums; }
.tbl tr:hover td { background: #18222f; }
.tbl .actions { display: flex; gap: 6px; justify-content: flex-end; }
.tbl .actions button { padding: 4px 9px; font-size: 12px; }
.empty { color: var(--muted); padding: 22px 4px; text-align: center; font-size: 13px; }

/* --- movements -------------------------------------------------------------------------------------------------- */
.moves { display: flex; flex-direction: column; }
.move { display: grid; grid-template-columns: 118px 132px minmax(0, 1fr); gap: 12px; padding: 10px 4px; border-bottom: 1px solid var(--line); align-items: baseline; }
.move:last-child { border-bottom: 0; }
.move time { color: var(--muted); font-size: 12px; font-variant-numeric: tabular-nums; }
.move .by { font-size: 13px; color: var(--text-2); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.move .what { font-size: 14px; overflow-wrap: anywhere; }
.move .tag { display: inline-block; font-size: 10px; text-transform: uppercase; letter-spacing: .05em; color: var(--muted); border: 1px solid var(--line); border-radius: 4px; padding: 1px 4px; margin-right: 6px; vertical-align: 1px; }

/* --- gate ------------------------------------------------------------------------------------------------------- */
.gate {
  position: fixed; inset: 0; z-index: 100; display: grid; place-items: center; padding: 20px;
  background: rgba(6, 10, 17, .72); backdrop-filter: blur(3px);
}
.gate[hidden] { display: none; }
body.locked .app { filter: blur(9px); pointer-events: none; user-select: none; }
.gate-card {
  width: 100%; max-width: 420px; background: var(--panel); border: 1px solid var(--line);
  border-radius: 16px; padding: 24px; box-shadow: 0 30px 80px rgba(0, 0, 0, .5);
}
.gate-brand { display: flex; align-items: center; gap: 9px; font-size: 15px; color: var(--text-2); margin-bottom: 14px; }
.user-list { display: flex; flex-direction: column; gap: 8px; margin: 16px 0; max-height: 44vh; overflow-y: auto; }
.user-list button { text-align: left; padding: 12px 14px; font-size: 15px; }
.user-list button:hover { border-color: var(--accent-2); }
.inline { display: flex; gap: 8px; margin-top: 10px; }
.inline input { flex: 1; }

/* --- dialogs ---------------------------------------------------------------------------------------------------- */
dialog {
  border: 1px solid var(--line); border-radius: 14px; background: var(--panel);
  color: var(--text); padding: 0; width: min(460px, calc(100vw - 32px));
  box-shadow: 0 30px 80px rgba(0, 0, 0, .55);
}
dialog::backdrop { background: rgba(5, 9, 15, .65); }
dialog form { padding: 20px; margin: 0; }
.dlg-head { display: flex; align-items: center; gap: 8px; margin-bottom: 6px; }
.dlg-head h2 { font-size: 17px; margin: 0; }
.dlg-actions { display: flex; justify-content: flex-end; gap: 8px; margin-top: 16px; }
.dlg-actions button, .dialog-wide { min-width: 110px; }
dialog textarea { resize: vertical; }
#userRows .item { padding: 8px 0; }

@media (max-width: 1100px) {
  .stats { grid-template-columns: repeat(3, minmax(0, 1fr)); }
  .layout { grid-template-columns: minmax(0, 1fr); }
  .layout > aside { position: static; }
}
@media (max-width: 760px) {
  .stats { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .lower { grid-template-columns: minmax(0, 1fr); }
  .top { padding: 12px; gap: 10px; }
  .tabs { order: 3; width: 100%; overflow-x: auto; }
  .tabs button { flex: 1; padding: 8px 10px; font-size: 13px; white-space: nowrap; }
  .who { margin-left: 0; }
  main { padding: 12px; }
  .move { grid-template-columns: 92px minmax(0, 1fr); }
  .move .by { grid-column: 2; }
  .move .what { grid-column: 2; }
  .grid { grid-template-columns: 46px repeat(3, minmax(0, 1fr)); }
}

/* --- products: the name is the group, the SKUs are its children --- */
.tbl tr.group { cursor: pointer; }
.tbl tr.group:hover td { background: #1b2836; }
.tbl tr.group td { border-bottom: 1px solid var(--line); padding-top: 12px; padding-bottom: 12px; }
.tbl tr.child td { background: #121a26; font-size: 13px; }
.tbl tr.child td.sku { padding-left: 30px; font-variant-numeric: tabular-nums; color: var(--text); }
.tbl tr.child td.dim { border-left: 2px solid var(--line-2); }
.tbl .caret { display: inline-block; width: 14px; color: var(--muted); transition: transform .15s; }
.tbl .caret.open { transform: rotate(90deg); color: var(--accent-2); }

/* --- movements: the ticket number of a written-off position --- */
.move .note { display: block; margin-top: 3px; font-size: 12px; color: var(--warn); }
.move .note::before { content: "комментарий: "; color: var(--muted); }
