:root {
  --bg: #EFF0EC;
  --surface: #FBFCFA;
  --ink: #1D2321;
  --muted: #5C6762;
  --line: #CBD2CA;
  --accent: #1F5E8C;
  --accent-ink: #FFFFFF;
  --zero: #B23A2E;
  --ok: #2E7D4F;
  --radius: 10px;
  --veil: rgb(239 240 236 / .30);
  --plate: rgb(251 252 250 / .94);
  --shadow: 0 1px 2px rgb(40 38 30 / .10), 0 4px 14px rgb(40 38 30 / .10);
  --font: "IBM Plex Sans", system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  --font-head: "IBM Plex Sans Condensed", "Arial Narrow", "Roboto Condensed", var(--font);
  color-scheme: light dark;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #151917;
    --surface: #1E2321;
    --ink: #E3E8E4;
    --muted: #98A39E;
    --line: #333C38;
    --accent: #6FA8D6;
    --accent-ink: #0E1A24;
    --zero: #F07B6E;
    --ok: #7BC79A;
    --veil: rgb(21 25 23 / .84);
    --plate: rgb(30 35 33 / .95);
    --shadow: 0 1px 2px rgb(0 0 0 / .3), 0 4px 14px rgb(0 0 0 / .3);
  }
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0; color: var(--ink);
  background: linear-gradient(var(--veil), var(--veil)), url("parts-bg.svg") 0 0 / 760px 760px, var(--bg);
  min-height: 100vh;
  font: 16px/1.45 var(--font);
  padding-bottom: env(safe-area-inset-bottom, 0px);
}
a { color: var(--accent); }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
code { font-size: .92em; background: var(--surface); padding: 1px 4px; border-radius: 4px; }

/* ---------- шапка */
.top {
  position: sticky; top: 0; z-index: 10;
  display: flex; align-items: center; gap: 10px;
  padding: calc(8px + env(safe-area-inset-top, 0px)) 12px 8px;
  background: color-mix(in srgb, var(--bg) 88%, transparent); border-bottom: 1px solid var(--line);
  -webkit-backdrop-filter: blur(10px); backdrop-filter: blur(10px);
}
.brand {
  font: 600 22px/1 var(--font-head); color: var(--ink); text-decoration: none;
  letter-spacing: -.01em;
}
.search { flex: 1; min-width: 0; }
.search input {
  width: 100%; height: 42px; padding: 0 14px;
  border: 1.5px solid var(--line); border-radius: 999px;
  background: var(--surface); color: var(--ink); font: inherit; font-size: 16px;
}
.search input:focus { border-color: var(--accent); outline: none; }
.menu { position: relative; }
.menu summary {
  list-style: none; cursor: pointer; width: 42px; height: 42px; border-radius: 50%;
  display: flex; flex-direction: column; justify-content: center; align-items: center; gap: 4px;
}
.menu summary::-webkit-details-marker { display: none; }
.menu summary span { display: block; width: 18px; height: 2px; background: var(--ink); border-radius: 1px; }
.menu nav {
  position: absolute; right: 0; top: 48px; min-width: 240px;
  background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius);
  box-shadow: 0 10px 30px rgb(0 0 0 / .18); padding: 6px; display: flex; flex-direction: column;
}
.menu nav a, .menu nav .linklike {
  display: block; padding: 11px 12px; color: var(--ink); text-decoration: none; border-radius: 6px;
  font: inherit; text-align: left; width: 100%; background: none; border: 0; cursor: pointer;
}
.menu nav a:hover, .menu nav .linklike:hover { background: var(--bg); }
.menu nav form { margin: 0; border-top: 1px solid var(--line); margin-top: 4px; padding-top: 4px; }

main { max-width: 760px; margin: 0 auto; padding: 16px 14px 48px; }

/* ---------- заголовки: трафаретная надпись на ящике */
.display {
  font: 600 clamp(28px, 7vw, 40px)/1.05 var(--font-head);
  letter-spacing: -.015em; margin: 6px 0 12px; overflow-wrap: anywhere;
}
.sub { font: 600 15px/1.3 var(--font); color: var(--muted); margin: 22px 0 8px; }
.pagehead { display: flex; align-items: baseline; justify-content: space-between; gap: 12px; flex-wrap: wrap; }
.pagehead .display { margin-bottom: 8px; }
.crumbs { font-size: 14px; color: var(--muted); }
.crumbs a { color: var(--muted); }
.muted { color: var(--muted); }
.hint { color: var(--muted); font-size: 14px; margin: -4px 0 4px; }

.flash { padding: 10px 14px; border-radius: var(--radius); background: var(--surface); border-left: 4px solid var(--ok); }
.flash.error { border-left-color: var(--zero); }

/* ---------- места и коробки */
.place { margin: 22px 0 6px; }
.place-name { font: 600 21px/1.15 var(--font-head); margin: 0 0 8px; }
.place-name a { color: var(--ink); text-decoration: none; }
.boxes { list-style: none; padding: 0; margin: 0; display: grid; gap: 6px; grid-template-columns: repeat(auto-fill, minmax(210px, 1fr)); }
.boxes a {
  display: flex; flex-direction: column; gap: 2px; padding: 12px 14px; min-height: 56px;
  background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius);
  color: var(--ink); text-decoration: none;
}
.boxes a:active { border-color: var(--accent); }
.box-name { font-weight: 600; overflow-wrap: anywhere; }
.box-meta { font-size: 14px; color: var(--muted); }

/* ---------- детали */
.parts { list-style: none; padding: 0; margin: 14px 0 0; display: flex; flex-direction: column; gap: 6px; }
.part {
  display: grid; grid-template-columns: 1fr auto; align-items: center; column-gap: 8px;
  background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius);
  border-left: 5px solid hsl(var(--hue) 45% 52%);
  padding: 6px 6px 6px 12px;
}
.part-main { display: flex; flex-direction: column; min-width: 0; color: var(--ink); text-decoration: none; padding: 4px 0; }
.part-title { font-weight: 600; font-size: 17px; overflow-wrap: anywhere; }
.part-sub { font-size: 14px; color: var(--muted); }
.part-note { font-size: 13px; color: var(--muted); font-style: italic; }
.part-loc {
  grid-column: 1 / -1; font-size: 14px; font-weight: 500; text-decoration: none;
  padding: 6px 0 4px; border-top: 1px dashed var(--line); margin-top: 4px;
}

.qty { display: flex; align-items: center; gap: 2px; }
.qty button { font: inherit; cursor: pointer; border: 0; color: var(--ink); -webkit-tap-highlight-color: transparent; touch-action: manipulation; }
.qbtn {
  width: 44px; height: 44px; border-radius: 8px; background: var(--bg);
  font-size: 22px !important; line-height: 1;
}
.qbtn:active { background: var(--line); }
.qnum {
  min-width: 56px; height: 44px; padding: 0 6px; background: none;
  font: 600 20px/1 var(--font-head) !important; font-variant-numeric: tabular-nums;
}
.qnum.zero { color: var(--zero); }
.qnum.bump { animation: bump .25s ease-out; }
@keyframes bump { 50% { transform: scale(1.18); } }
.qty.busy { opacity: .6; }

/* ---------- формы */
.form { display: flex; flex-direction: column; gap: 14px; }
.form.narrow, .login .form { max-width: 460px; }
.form label { display: flex; flex-direction: column; gap: 5px; font-size: 14px; font-weight: 500; color: var(--muted); }
input:not([type=checkbox]):not([type=radio]), select, textarea {
  font: inherit; font-size: 16px; color: var(--ink); background: var(--surface);
  border: 1.5px solid var(--line); border-radius: 8px; padding: 10px 12px; min-height: 46px; width: 100%;
}
input:focus, select:focus, textarea:focus { border-color: var(--accent); outline: none; }
.form label > input[hidden] { display: none; }
.form label > select + input { margin-top: 6px; }
.row2 { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.row2:empty { display: none; }
@media (max-width: 480px) { .row2 { grid-template-columns: 1fr; } }

.actions { display: flex; flex-wrap: wrap; gap: 8px; margin: 10px 0; }
.btn {
  display: inline-flex; align-items: center; justify-content: center; min-height: 44px; padding: 0 16px;
  border-radius: 8px; border: 1.5px solid var(--accent); background: transparent; color: var(--accent);
  font: 600 15px/1 var(--font); text-decoration: none; cursor: pointer;
}
.btn.primary { background: var(--accent); color: var(--accent-ink); }
.btn.ghost { border-color: var(--line); color: var(--ink); }
.btn.danger { border-color: var(--zero); color: var(--zero); }
.btn.small { min-height: 38px; padding: 0 10px; font-size: 14px; }
.danger-zone { margin-top: 36px; padding-top: 16px; border-top: 1px solid var(--line); }

.inline-add { display: flex; gap: 8px; margin: 18px 0; }
.inline-add input { flex: 1; }

/* ---------- справочники */
.dict { list-style: none; padding: 0; margin: 14px 0; display: flex; flex-direction: column; gap: 6px; }
.dict a {
  display: grid; grid-template-columns: 1fr auto; column-gap: 10px; padding: 12px 14px;
  background: var(--surface); border: 1px solid var(--line); border-left: 5px solid hsl(var(--hue) 45% 52%);
  border-radius: var(--radius); color: var(--ink); text-decoration: none;
}
.dict-name { font-weight: 600; }
.dict-meta { grid-column: 1; font-size: 14px; color: var(--muted); }
.dict-count {
  grid-column: 2; grid-row: 1 / span 2; align-self: center;
  font: 600 15px/1 var(--font-head); color: var(--muted); font-variant-numeric: tabular-nums;
}
.frow { display: grid; grid-template-columns: 1fr 110px; gap: 8px; margin-bottom: 8px; }
.pkgs { list-style: none; padding: 0; margin: 0; display: flex; flex-direction: column; gap: 6px; }
.pkg { display: flex; gap: 6px; align-items: center; }
.pkg input[name=name] { flex: 1; min-width: 0; }
.pkg .dict-count { min-width: 28px; text-align: center; }

.checks { border: 1px solid var(--line); border-radius: var(--radius); background: var(--surface); padding: 4px 14px 8px; margin: 0; min-width: 0; }
/* float переносит legend внутрь рамки — иначе браузер рисует его поверх линии */
.checks legend {
  float: left; width: 100%; padding: 8px 0; margin: 0 0 4px;
  font-weight: 600; border-bottom: 1px solid var(--line);
}
.checks legend + * { clear: both; }
.checks legend .chk { font-weight: 600 !important; padding: 0; }
.chk { flex-direction: row !important; align-items: center; gap: 10px !important; color: var(--ink) !important; font-weight: 400 !important; font-size: 16px !important; padding: 7px 0; }
.chk input { width: 20px; height: 20px; flex: none; margin: 0; accent-color: var(--accent); }

.empty { text-align: left; padding: 30px 0; }
.login { max-width: 460px; margin: 10vh auto 0; }

.toast {
  position: fixed; left: 50%; bottom: calc(20px + env(safe-area-inset-bottom, 0px)); transform: translate(-50%, 40px);
  background: var(--ink); color: var(--bg); padding: 10px 16px; border-radius: 8px; font-size: 15px;
  opacity: 0; transition: opacity .2s, transform .2s; pointer-events: none; max-width: 90vw;
}
.toast.show { opacity: 1; transform: translate(-50%, 0); }

@media (prefers-reduced-motion: reduce) {
  .qnum.bump { animation: none; }
  .toast { transition: none; }
}

/* ---------- таблички: текст поверх россыпи деталей лежит на светлой наклейке */
.plate {
  display: inline-block; background: var(--plate); padding: 2px 12px 4px; border-radius: 6px;
  box-shadow: var(--shadow); color: var(--ink); text-decoration: none;
}
.plate.small { font-size: 14px; padding: 4px 10px; color: var(--muted); }
.crumbs.plate { padding: 5px 12px; margin-bottom: 4px; }
.plate-text {
  background: var(--plate); padding: 10px 14px; border-radius: var(--radius); box-shadow: var(--shadow);
  color: var(--muted); max-width: 62ch;
}
.form.card, .form:not(.inline-add) { background: var(--plate); padding: 16px; border-radius: 14px; box-shadow: var(--shadow); }
.boxes a, .part, .dict a, .checks, .pkg { box-shadow: var(--shadow); }
.pkgs .pkg { background: var(--plate); padding: 6px; border-radius: var(--radius); }
.inline-add { background: var(--plate); padding: 8px; border-radius: var(--radius); box-shadow: var(--shadow); }
.btn.ghost { background: var(--surface); }
.btn:not(.primary):not(.ghost) { background: var(--surface); }
.btn { box-shadow: var(--shadow); }

.room { margin: 26px 0 8px; }
.room-name { font: 600 clamp(24px, 6vw, 32px)/1.05 var(--font-head); margin: 0 0 4px; }
.room .place { margin: 12px 0 0; }
.place-name { font-size: 18px; }
.box-add {
  display: block; padding: 12px 14px; border: 1.5px dashed var(--line); border-radius: var(--radius);
  background: var(--plate); color: var(--muted); text-decoration: none;
}
.danger-zone { border-top: 0; }
.login .display { font-size: clamp(40px, 12vw, 64px); }
