[hidden] { display: none !important; }

:root {
  --bg: #f6f7f4;
  --surface: #ffffff;
  --text: #1d2a1f;
  --muted: #5d6b60;
  --accent: #2f7d3a;
  --error: #b42318;
  --border: #dfe4dc;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #121612;
    --surface: #1b211c;
    --text: #e6ece6;
    --muted: #9aa79c;
    --accent: #6cc17a;
    --error: #ff8a80;
    --border: #2b342c;
  }
}

* { box-sizing: border-box; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 16px/1.5 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
}

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 12px 16px;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
}

.brand { color: var(--accent); font-weight: 700; text-decoration: none; }
.container { max-width: 960px; margin: 0 auto; padding: 16px; }

.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 16px;
}

.narrow { max-width: 420px; margin: 48px auto; text-align: center; }
.muted { color: var(--muted); }
.error { color: var(--error); }

button.link {
  background: none;
  border: none;
  color: var(--accent);
  cursor: pointer;
  font: inherit;
  padding: 0 0 0 8px;
}

.button {
  background: var(--accent);
  border: none;
  border-radius: 8px;
  color: var(--surface);
  cursor: pointer;
  font: inherit;
  font-weight: 600;
  min-height: 44px;
  padding: 10px 20px;
}

.button.secondary { background: var(--surface); color: var(--accent); border: 1px solid var(--accent); }
.button.danger { background: var(--error); }
a.button { display: inline-flex; align-items: center; text-decoration: none; }
.danger-text { color: var(--error) !important; }
a { color: var(--accent); }
h1 { font-size: 1.5rem; margin: 8px 0 12px; }
h2 { font-size: 1.15rem; margin: 0 0 8px; }
.small { font-size: 0.85rem; }
.big { font-size: 1.15rem; }

.nav {
  display: flex;
  gap: 4px;
  overflow-x: auto;
  padding: 8px 12px;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
}
.nav a {
  flex: none;
  padding: 8px 12px;
  border-radius: 8px;
  color: var(--text);
  text-decoration: none;
}
.nav a:hover { background: var(--bg); }

.flash { padding: 10px 14px; border-radius: 8px; border: 1px solid var(--border); background: var(--surface); }
.flash-error { border-color: var(--error); color: var(--error); }

.card + .card, .card + .button, section.card { margin-bottom: 12px; }

.stats { display: grid; grid-template-columns: repeat(4, 1fr); gap: 8px; margin-bottom: 16px; }
.stats div { background: var(--surface); border: 1px solid var(--border); border-radius: 12px; padding: 10px; text-align: center; }
.stats b { display: block; font-size: 1.4rem; }
.stats span { color: var(--muted); font-size: 0.8rem; }

.zone { margin: 20px 0; }
.zone-head { display: flex; justify-content: space-between; align-items: baseline; }
/* План зоны на странице карты: всегда портретом, как холст в редакторе — сверху дальний
   конец, внизу выход. Длинная зона прокручивается вместе со страницей. Клетка не уже 22px,
   иначе подписи не помещаются: тогда план прокручивается вбок. */
.plan-scroll { overflow-x: auto; overflow-y: hidden; margin: 0 -16px; padding: 12px 16px; }
.plan {
  position: relative;
  width: 100%;
  max-width: calc(var(--W) * 40px);
  min-width: calc(var(--W) * 22px);
  margin: 0 auto;
  aspect-ratio: var(--W) / var(--H);
}
.exit { text-align: center; margin: 0 0 12px; letter-spacing: 0.1em; }
.plan > .cell {
  position: absolute;
  left: calc(var(--x) / var(--W) * 100%);
  top: calc(var(--y) / var(--H) * 100%);
  width: calc(var(--w) / var(--W) * 100%);
  height: calc(var(--h) / var(--H) * 100%);
  min-height: 0;
  border-radius: 6px;
  padding: 4px;
  font-size: 0.75rem;
}
.plan > .mark {
  position: absolute;
  left: calc(var(--x) / var(--W) * 100%);
  top: calc(var(--y) / var(--H) * 100%);
  width: calc(var(--w) / var(--W) * 100%);
  height: calc(var(--h) / var(--H) * 100%);
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 2px;
  overflow: hidden;
  border: 1px dashed var(--border);
  border-radius: 6px;
  background: color-mix(in srgb, var(--muted) 10%, transparent);
  color: var(--muted);
  font-size: 0.7rem;
  text-align: center;
  line-height: 1.1;
}
.plan > .mark-text { border: none; background: none; }
/* Дорожка — деревянный настил: полосы досок поперёк хода. */
.plan > .mark-path, .item.mark[data-kind="path"] {
  border: none;
  background: repeating-linear-gradient(0deg, #b89a72 0 5px, #a3845c 5px 6px);
  color: #4a3a26;
  opacity: 0.55;
}
.plan > .mark-path.wide, .item.mark.wide[data-kind="path"] {
  background: repeating-linear-gradient(90deg, #b89a72 0 5px, #a3845c 5px 6px);
}
.plan > .point {
  position: absolute;
  left: calc(var(--x) / var(--W) * 100%);
  top: calc(var(--y) / var(--H) * 100%);
  z-index: 2;
  text-decoration: none;
  color: var(--text);
}
.diamond {
  position: absolute;
  width: 14px;
  height: 14px;
  transform: translate(-50%, -50%) rotate(45deg);
  background: var(--accent);
  border: 2px solid var(--surface);
  border-radius: 2px;
}
.plan .point.empty .diamond { background: var(--surface); border-color: var(--accent); }
.plan .point .label {
  position: absolute;
  left: 10px;
  top: -8px;
  max-width: 7em;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  font-size: 0.7rem;
  font-weight: 600;
  padding: 0 3px;
  border-radius: 4px;
  background: color-mix(in srgb, var(--surface) 85%, transparent);
  pointer-events: none; /* подпись не перехватывает нажатие по слоту под ней */
}
@media (max-width: 700px) {
  .plan .point .label { max-width: 3.5em; font-size: 0.65rem; }
}
.overview-zones { list-style: none; padding: 0; display: grid; gap: 8px; }
.overview-zones li { display: flex; flex-wrap: wrap; gap: 4px 12px; align-items: baseline; margin: 0; }
.overview-zones li > a:first-child { text-decoration: none; color: var(--text); }
.tiles { display: grid; grid-template-columns: repeat(auto-fill, minmax(130px, 1fr)); gap: 6px; }
.cell {
  display: flex;
  flex-direction: column;
  gap: 2px;
  min-height: 72px;
  padding: 6px;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--surface);
  color: var(--text);
  text-decoration: none;
  font-size: 0.8rem;
  overflow: hidden;
  overflow-wrap: break-word;
  hyphens: auto;
}
.cell .code { font-weight: 700; color: var(--muted); white-space: nowrap; }
.cell .mother { color: var(--accent); font-weight: 600; }
.cell .qty { font-weight: 700; }
.cell.empty { background: transparent; border-style: dashed; }
.cell.mixed { border: 2px solid var(--error); }
.add-place { margin-top: 8px; }
.add-place summary { cursor: pointer; color: var(--muted); }

.row-form { display: flex; flex-wrap: wrap; gap: 6px; align-items: center; margin: 6px 0; }
.row-form form { margin: 0; }
input, select, textarea {
  font: inherit;
  min-height: 44px;
  padding: 8px 10px;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--surface);
  color: var(--text);
  max-width: 100%;
}
input.short { width: 7.5em; }
.form { display: flex; flex-direction: column; gap: 10px; }
.form label { display: flex; flex-direction: column; gap: 4px; }
.form label.check, label.check { flex-direction: row; align-items: center; gap: 8px; }
fieldset { border: 1px solid var(--border); border-radius: 8px; display: flex; flex-direction: column; gap: 8px; }

.page-head { display: flex; flex-wrap: wrap; align-items: baseline; gap: 10px; }
.batch-head { display: flex; gap: 12px; align-items: flex-start; }
.batch-head p { margin: 2px 0; }
.actions { display: flex; flex-wrap: wrap; gap: 8px; }
details summary { cursor: pointer; margin: 8px 0; color: var(--accent); }
.walk { border-color: var(--accent); display: flex; flex-wrap: wrap; gap: 10px; align-items: center; }

.thumb { width: 64px; height: 64px; object-fit: cover; border-radius: 8px; flex: none; }
.thumb.placeholder { display: inline-block; background: var(--bg); border: 1px dashed var(--border); }
.gallery { display: grid; grid-template-columns: repeat(auto-fill, minmax(140px, 1fr)); gap: 10px; margin-bottom: 10px; }
.gallery figure { margin: 0; border: 1px solid var(--border); border-radius: 8px; overflow: hidden; }
.gallery figure.main { border: 2px solid var(--accent); }
.gallery img { width: 100%; aspect-ratio: 1; object-fit: cover; display: block; }
.gallery figcaption { display: flex; flex-wrap: wrap; gap: 4px; padding: 6px; align-items: center; }
.gallery figcaption form { margin: 0; }

.list { list-style: none; padding: 0; margin: 0; }
.list-item {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 12px;
  padding: 10px 0;
  border-bottom: 1px solid var(--border);
  color: var(--text);
  text-decoration: none;
}
a.list-item { justify-content: flex-start; }
.history { padding-left: 18px; }
.history li { margin: 4px 0; }
.shop-row.status-sale { border-left: 4px solid var(--accent); }
.shop-row.status-preorder { border-left: 4px solid #c88a12; }

/* Режим редактирования карты: тёмный холст с опорными точками в узлах сетки */
.edit-zone { margin-bottom: 16px; }
.toolbar { display: flex; flex-wrap: wrap; gap: 6px; align-items: center; margin: 8px 0; }
.toolbar .button { min-height: 36px; padding: 6px 12px; }
.toolbar .button[aria-pressed="true"] { background: var(--accent); color: #fff; }
.toolbar .selection { display: inline-flex; flex-wrap: wrap; gap: 6px; align-items: center; margin-left: auto; }
/* Место под кнопки занято всегда: иначе при выборе холст сдвигается под пальцем. */
.toolbar .selection.idle { visibility: hidden; }
.canvas-wrap {
  overflow: auto;
  height: min(70vh, 640px);
  border-radius: 12px;
  background: #15191a;
  border: 1px solid #2a3133;
  cursor: grab;
  touch-action: none;
}
.canvas-wrap.panning { cursor: grabbing; }
.canvas {
  --u: 24px;
  position: relative;
  background-color: #15191a;
  background-image: radial-gradient(circle, #4b5759 1.3px, transparent 1.6px);
  background-size: var(--u) var(--u);
  background-position: calc(var(--u) / -2) calc(var(--u) / -2);
}
.canvas.placing { cursor: crosshair; }
.item {
  position: absolute;
  box-sizing: border-box;
  user-select: none;
  touch-action: none;
}
.item.slot {
  border: 1px solid #5b8f62;
  border-radius: 6px;
  background: #1f2a22;
  color: #e6ece6;
  font-size: 0.75rem;
  cursor: move;
}
/* Текст обрезается внутри слота, а ручки размера выходят за его край. */
.slot-body { display: flex; flex-direction: column; gap: 1px; padding: 4px 6px; height: 100%; overflow: hidden; }
.item.slot.busy { background: #24402a; }
.item.slot b { white-space: nowrap; }
.item.slot .muted { color: #9aa79c; }
.item.mark {
  z-index: 0;
  border: 1px dashed #6f7d72;
  border-radius: 6px;
  background: rgba(160, 170, 160, 0.08);
  color: #b9c4bb;
  cursor: move;
}
.item.mark .mark-body {
  position: absolute; inset: 0; display: flex; align-items: center; justify-content: center;
  overflow: hidden; font-size: 0.75rem; text-align: center; line-height: 1.1; pointer-events: none;
}
.item.mark[data-kind="text"] { border-color: transparent; background: none; }
.item.selected { outline: 2px solid #8fd19a; outline-offset: 1px; }
.item.bad { border-color: var(--error); outline-color: var(--error); background: #3a1f1f; }
.item.point { width: 0; height: 0; cursor: move; z-index: 3; }
/* Невидимая зона касания вокруг ромбика: по нему легко попасть пальцем. */
.item.point::before { content: ""; position: absolute; width: var(--point-hit, 22px); height: var(--point-hit, 22px); transform: translate(-50%, -50%); border-radius: 50%; }
.item.point .diamond { width: 14px; height: 14px; border-color: #15191a; background: #6cc17a; }
.item.point.empty .diamond { background: #15191a; border-color: #6cc17a; }
.item.point.bad .diamond { background: var(--error); }
.item.point .label { position: absolute; left: 10px; top: -9px; color: #e6ece6; font-size: 0.7rem; white-space: nowrap; pointer-events: none; }
.handle { position: absolute; width: 12px; height: 12px; z-index: 2; }
.handle[data-dir="nw"] { left: -6px; top: -6px; cursor: nwse-resize; }
.handle[data-dir="ne"] { right: -6px; top: -6px; cursor: nesw-resize; }
.handle[data-dir="sw"] { left: -6px; bottom: -6px; cursor: nesw-resize; }
.handle[data-dir="se"] { right: -6px; bottom: -6px; cursor: nwse-resize; }
.handle[data-dir="n"], .handle[data-dir="s"] { left: 6px; right: 6px; width: auto; height: 8px; cursor: ns-resize; }
.handle[data-dir="n"] { top: -4px; }
.handle[data-dir="s"] { bottom: -4px; }
.handle[data-dir="e"], .handle[data-dir="w"] { top: 6px; bottom: 6px; height: auto; width: 8px; cursor: ew-resize; }
.handle[data-dir="e"] { right: -4px; }
.handle[data-dir="w"] { left: -4px; }
.item.selected .handle[data-dir="nw"], .item.selected .handle[data-dir="ne"],
.item.selected .handle[data-dir="sw"], .item.selected .handle[data-dir="se"] {
  background: #8fd19a; border-radius: 3px;
}
/* Пальцем: ручки крупные и работают только у выбранного слота, чтобы не мешать перетаскиванию. */
@media (pointer: coarse) {
  .item:not(.selected) .handle { pointer-events: none; }
  .handle[data-dir="nw"], .handle[data-dir="ne"], .handle[data-dir="sw"], .handle[data-dir="se"] {
    width: 26px; height: 26px;
  }
  .handle[data-dir="nw"] { left: -13px; top: -13px; }
  .handle[data-dir="ne"] { right: -13px; top: -13px; }
  .handle[data-dir="sw"] { left: -13px; bottom: -13px; }
  .handle[data-dir="se"] { right: -13px; bottom: -13px; }
  .handle[data-dir="n"] { top: -10px; height: 20px; }
  .handle[data-dir="s"] { bottom: -10px; height: 20px; }
  .handle[data-dir="e"] { right: -10px; width: 20px; }
  .handle[data-dir="w"] { left: -10px; width: 20px; }
  .item.selected .handle[data-dir="nw"], .item.selected .handle[data-dir="ne"],
  .item.selected .handle[data-dir="sw"], .item.selected .handle[data-dir="se"] {
    background: radial-gradient(circle, #8fd19a 5px, transparent 6px);
  }
  .item.selected .handle[data-dir="n"], .item.selected .handle[data-dir="s"],
  .item.selected .handle[data-dir="e"], .item.selected .handle[data-dir="w"] {
    background: radial-gradient(ellipse, rgb(143 209 154 / 0.5) 3px, transparent 4px);
  }
}
.size-hint { position: absolute; right: 4px; bottom: 2px; font-size: 0.65rem; color: #9aa79c; }
.tray {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  min-height: 48px;
  padding: 8px;
  border: 1px dashed var(--border);
  border-radius: 8px;
  margin-top: 8px;
}
.tray-item { min-height: 36px; padding: 6px 10px; }
dialog { border: 1px solid var(--border); border-radius: 12px; background: var(--surface); color: var(--text); max-width: 360px; width: calc(100% - 32px); }
dialog::backdrop { background: rgb(0 0 0 / 0.4); }

/* --- Публичная витрина ----------------------------------------------------------------------- */
.langs { display: flex; gap: 4px; }
.langs a { padding: 4px 8px; border-radius: 6px; text-decoration: none; color: var(--muted); }
.langs a[aria-current] { background: var(--bg); color: var(--text); font-weight: 600; }
.chips { display: flex; gap: 6px; overflow-x: auto; padding-bottom: 4px; margin-bottom: 12px; }
.chips a { white-space: nowrap; padding: 6px 12px; border: 1px solid var(--border); border-radius: 999px;
  text-decoration: none; color: var(--text); background: var(--surface); }
.chips a[aria-current] { background: var(--accent); border-color: var(--accent); color: #fff; }
.shelf { margin-bottom: 24px; }
.products { display: grid; grid-template-columns: repeat(auto-fill, minmax(min(200px, 45%), 1fr)); gap: 10px; }
.product { display: flex; flex-direction: column; gap: 8px; padding: 12px; }
.product h3 { margin: 0; font-size: 1.05rem; }
.product h3 a { color: var(--text); text-decoration: none; }
.product .button { margin-top: auto; justify-content: center; text-align: center; padding: 8px 10px; font-size: 0.9rem; }
.product-photo { display: block; aspect-ratio: 1; border-radius: 8px; overflow: hidden; background: var(--bg); }
.product-photo img { width: 100%; height: 100%; object-fit: cover; display: block; }
.no-photo { display: flex; height: 100%; align-items: center; justify-content: center; font-size: 3rem; }
.offer { display: flex; flex-wrap: wrap; gap: 4px 10px; align-items: baseline; }
.offer .price { font-size: 1.1rem; }
.offer + .button { margin-top: 10px; }
.badge { font-size: 0.8rem; padding: 2px 8px; border-radius: 999px; background: var(--bg); color: var(--muted); }
.badge.sale { background: var(--accent); color: #fff; }
.badge.preorder { border: 1px solid var(--accent); color: var(--accent); }
.button.whatsapp { background: #25d366; border-color: #25d366; color: #fff; }
.public-gallery { display: flex; gap: 8px; overflow-x: auto; scroll-snap-type: x mandatory; margin-bottom: 12px; }
.public-gallery a { flex: 0 0 min(85%, 420px); scroll-snap-align: start; }
.public-gallery img { width: 100%; aspect-ratio: 1; object-fit: cover; border-radius: 12px; display: block; }
.prose { margin: 16px 0; }
.footer { border-top: 1px solid var(--border); padding-top: 16px; padding-bottom: 32px; }
