:root {
  --navy: #1b2536;
  --navy-2: #2a3548;
  --green: #9bc53d;
  --green-dark: #6f9624;
  --green-soft: #eef6dc;
  --bg: #f7f6f3;
  --card: #ffffff;
  --ink: #1c1f24;
  --muted: #6b7280;
  --line: #e7e5df;
  --rack: #e8eae6;
  --warn: #d98a1c;
  --warn-soft: #fbf0dc;
  --bad: #c2463d;
  --bad-soft: #f9e3e1;
  --radius: 20px;
  --shadow: 0 1px 2px rgba(27, 37, 54, 0.06), 0 6px 20px rgba(27, 37, 54, 0.06);
}

* { box-sizing: border-box; }
html, body { margin: 0; }
body {
  font-family: 'Montserrat', system-ui, -apple-system, 'Segoe UI', sans-serif;
  background: var(--bg);
  color: var(--ink);
  font-size: 15px;
  line-height: 1.45;
  -webkit-tap-highlight-color: transparent;
}
button { font: inherit; color: inherit; cursor: pointer; }
.hidden { display: none !important; }
.muted { color: var(--muted); }
.small { font-size: 13px; }
.mt { margin-top: 20px; }

/* ---- Шапка ---- */
.topbar {
  position: sticky; top: 0; z-index: 20;
  display: flex; align-items: center; gap: 24px;
  padding: 12px 28px;
  background: var(--navy); color: #fff;
}
.brand { background: none; border: 0; padding: 0; font-weight: 800; font-size: 22px; letter-spacing: 0.5px; color: #fff; }
.brand-shelf { color: var(--green); margin-left: 6px; }
.store { flex: 1; min-width: 0; }
.store-name { font-weight: 600; font-size: 14px; }
.store-sub { font-size: 12px; color: #aeb7c6; }
.tabs { display: flex; gap: 4px; background: var(--navy-2); border-radius: 12px; padding: 4px; }
.tab { background: none; border: 0; color: #c9d1dd; padding: 8px 14px; border-radius: 9px; font-weight: 600; font-size: 13px; }
.tab.active { background: var(--green); color: var(--navy); }
.icon-btn { background: var(--navy-2); border: 0; color: #c9d1dd; width: 40px; height: 40px; border-radius: 12px; display: grid; place-items: center; }

main { padding: 20px 28px 40px; max-width: 1600px; margin: 0 auto; }
.view { display: none; }
.view.active { display: block; }

/* ---- Поиск ---- */
.searchbar {
  display: flex; align-items: center; gap: 12px;
  background: var(--card); border-radius: 18px; padding: 8px 8px 8px 20px;
  box-shadow: var(--shadow); border: 2px solid transparent;
}
.searchbar:focus-within { border-color: var(--green); }
.searchbar-icon { color: var(--muted); flex: none; }
.searchbar input { flex: 1; min-width: 0; border: 0; outline: 0; font: inherit; font-size: 19px; padding: 12px 0; background: none; }
.search-meta { display: flex; align-items: center; gap: 12px; margin: 12px 0 18px; flex-wrap: wrap; }
.badge { font-size: 12px; font-weight: 700; padding: 6px 10px; border-radius: 999px; background: #e3e6ea; color: var(--navy); white-space: nowrap; }
.badge--ai { background: var(--navy); color: var(--green); }
.chips { display: flex; gap: 8px; flex-wrap: wrap; }
.chip { border: 1px solid var(--line); background: var(--card); border-radius: 999px; padding: 7px 14px; font-size: 13px; }
.chip:hover { border-color: var(--green); }

.btn {
  border: 1px solid var(--line); background: var(--card); border-radius: 12px;
  padding: 11px 18px; font-weight: 600; font-size: 14px;
}
.btn:hover { border-color: var(--navy); }
.btn-primary { background: var(--green); border-color: var(--green); color: var(--navy); }
.btn-primary:hover { background: #8fb934; border-color: #8fb934; }
.btn-ghost { background: transparent; }
.btn-lg { padding: 14px 28px; font-size: 16px; border-radius: 14px; }

.layout { display: grid; grid-template-columns: minmax(340px, 430px) 1fr; gap: 20px; align-items: start; }
.col-left, .col-right { display: grid; gap: 16px; min-width: 0; }
.card { background: var(--card); border-radius: var(--radius); padding: 20px; box-shadow: var(--shadow); }
.card-title { font-weight: 700; font-size: 14px; margin-bottom: 12px; color: var(--navy); }

/* Главный экран */
.hero-title { font-size: 30px; line-height: 1.15; margin: 4px 0 10px; font-weight: 800; color: var(--navy); }
.hero-title span { color: var(--green-dark); }
.hero-text { color: var(--muted); margin: 0 0 18px; }
.steps { list-style: none; padding: 0; margin: 0 0 22px; display: grid; gap: 8px; counter-reset: s; }
.steps li { counter-increment: s; display: flex; align-items: baseline; gap: 8px; padding: 10px 12px; background: var(--bg); border-radius: 12px; }
.steps li::before { content: counter(s); font-weight: 800; color: var(--green-dark); width: 16px; }
.steps b { color: var(--navy); }
.steps span { color: var(--muted); font-size: 13px; }
.mini-grid { display: grid; grid-template-columns: repeat(4, 1fr); gap: 10px; }
.mini { background: none; border: 0; padding: 0; text-align: left; font-size: 12px; font-weight: 600; display: grid; gap: 6px; }

/* Обложки-заглушки */
.cover { border-radius: 8px; color: #fff; padding: 10px; display: flex; flex-direction: column; justify-content: space-between; flex: none; overflow: hidden; box-shadow: inset -6px 0 0 rgba(0, 0, 0, 0.15); }
.cover-title { font-weight: 700; font-size: 13px; line-height: 1.2; overflow-wrap: anywhere; hyphens: auto; }
.cover-author { font-size: 10px; opacity: 0.85; }
.cover--classic { background: #7a5c45; }
.cover--sf { background: #2f4b7c; }
.cover--modern { background: #8c4f6b; }
.cover--detective { background: #3d3f45; }
.cover--ya { background: #3f7d5a; }
.cover--lg { width: 96px; height: 138px; }
.cover--lg .cover-title { font-size: 12px; }
.cover--sm { width: 100%; aspect-ratio: 2 / 3; padding: 8px; }
.cover--sm .cover-title { font-size: 11px; }
.cover--sm .cover-author { display: none; }
.cover--xs { width: 52px; height: 74px; padding: 6px; }
.cover--xs .cover-title { font-size: 8.5px; }
.cover--xs .cover-author { display: none; }

/* Результаты */
.results { display: grid; gap: 10px; }
.results-head { font-weight: 700; color: var(--navy); padding: 0 4px; }
.result {
  display: flex; gap: 14px; text-align: left; width: 100%;
  background: var(--card); border: 2px solid transparent; border-radius: 16px; padding: 12px;
  box-shadow: var(--shadow);
}
.result.active { border-color: var(--green); }
.result-body { min-width: 0; }
.result-title { font-weight: 700; font-size: 15px; line-height: 1.25; }
.result-author { color: var(--muted); font-size: 13px; }
.result-meta { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; margin-top: 6px; }
.result-loc { font-size: 12px; font-weight: 600; color: var(--navy); }
.result-why { font-size: 12px; color: var(--muted); margin-top: 4px; }
.pill { font-size: 12px; font-weight: 700; padding: 3px 9px; border-radius: 999px; display: inline-block; }
.pill--ok { background: var(--green-soft); color: var(--green-dark); }
.pill--low { background: var(--warn-soft); color: var(--warn); }
.pill--none { background: var(--bad-soft); color: var(--bad); }
.loading { display: flex; align-items: center; gap: 12px; color: var(--muted); }
.spinner { width: 18px; height: 18px; border: 3px solid var(--line); border-top-color: var(--green); border-radius: 50%; animation: spin 0.8s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }
.empty h3 { margin: 0 0 8px; color: var(--navy); }
.empty p { color: var(--muted); margin: 0 0 14px; }
.note { font-size: 12px; background: var(--warn-soft); color: #7a4d0e; padding: 8px 10px; border-radius: 10px; }

/* Карточка книги */
.detail-main { display: grid; grid-template-columns: auto 1fr; gap: 16px; align-items: start; }
.eyebrow { font-size: 11px; font-weight: 700; color: var(--green-dark); text-transform: uppercase; letter-spacing: 0.4px; }
.detail-info h2 { margin: 4px 0 2px; font-size: 22px; line-height: 1.2; color: var(--navy); }
.author { color: var(--muted); font-weight: 600; }
.anno { margin: 8px 0 10px; font-size: 13px; display: -webkit-box; -webkit-line-clamp: 3; -webkit-box-orient: vertical; overflow: hidden; }
.loc { grid-column: 1 / -1; background: var(--navy); color: #fff; border-radius: 16px; padding: 14px 18px; }
.loc-label { font-size: 11px; font-weight: 700; text-transform: uppercase; letter-spacing: 0.5px; color: #aeb7c6; }
.loc-main { font-size: 24px; font-weight: 800; color: var(--green); margin-top: 4px; line-height: 1.15; }
.loc-main--none { color: #ff9b91; font-size: 20px; }
.loc-sub { font-weight: 600; margin-top: 4px; }
.loc-source { font-size: 11.5px; color: #aeb7c6; margin-top: 10px; line-height: 1.4; }
.stores { margin: 8px 0 0; padding-left: 18px; }
.tag { display: inline-block; font-size: 10.5px; font-weight: 700; padding: 2px 7px; border-radius: 6px; margin-right: 6px; text-transform: uppercase; letter-spacing: 0.3px; }
.tag--rule { background: #e3e6ea; color: var(--navy); }
.tag--exception { background: var(--warn-soft); color: var(--warn); }
.actions { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; margin-top: 14px; }
.actions .btn { padding: 10px 12px; font-size: 13px; }
.actions .btn-primary { grid-column: 1 / -1; font-size: 15px; padding: 12px; }

/* Карта */
.map-row { display: grid; grid-template-columns: 1fr 200px; gap: 16px; align-items: start; }
.map-row:has(> .shelf-card.hidden) { grid-template-columns: 1fr; }
.map svg, #shelf svg { width: 100%; height: auto; display: block; }
.floor { fill: var(--navy); }
.wall { fill: none; stroke: #3a4760; stroke-width: 3; }
.map-label { fill: #aeb7c6; font-size: 13px; font-weight: 600; }
.rack rect { fill: var(--rack); }
.rack-badge { fill: var(--navy-2); stroke: #4a5870; }
.rack-letter { fill: #fff; font-weight: 800; font-size: 15px; }
.rack-genre { fill: #6b7280; font-size: 12px; font-weight: 700; }
.rack .rack-name { fill: var(--navy); font-weight: 700; font-size: 13px; }
.rack > text.rack-genre:not([transform]) { fill: #aeb7c6; }
.rack--active rect { fill: var(--green); }
.rack--active .rack-badge { fill: var(--green); stroke: var(--green); }
.rack--active .rack-letter { fill: var(--navy); }
.rack--active .rack-genre { fill: var(--navy); }
.obstacle rect { fill: #2c3850; stroke: #4a5870; stroke-dasharray: 4 4; }
.obstacle text { fill: #aeb7c6; font-size: 13px; font-weight: 600; }
.route-bg { fill: none; stroke: rgba(155, 197, 61, 0.25); stroke-width: 12; stroke-linejoin: round; stroke-linecap: round; }
.route { fill: none; stroke: var(--green); stroke-width: 5; stroke-linejoin: round; stroke-linecap: round; stroke-dasharray: 14 10; animation: march 1s linear infinite; }
@keyframes march { to { stroke-dashoffset: -24; } }
.route-end { fill: var(--green); stroke: var(--navy); stroke-width: 3; }
.you circle { fill: #fff; }
.you .you-pulse { fill: rgba(255, 255, 255, 0.25); animation: pulse 1.8s ease-out infinite; transform-origin: center; transform-box: fill-box; }
@keyframes pulse { from { transform: scale(0.6); opacity: 1; } to { transform: scale(1.8); opacity: 0; } }
.you text { fill: #fff; font-weight: 700; font-size: 14px; }

/* Стеллаж сбоку */
.shelf-frame { fill: #f1f0ec; stroke: var(--line); }
.shelf-bg { fill: transparent; }
.shelf--active .shelf-bg { fill: var(--green-soft); stroke: var(--green); stroke-width: 2; }
.spine { fill: #c9ccc6; }
.spine--active { fill: var(--green-dark); }
.shelf-board { fill: #b8b3a8; }
.shelf-label { font-size: 11px; font-weight: 700; fill: var(--muted); }
.shelf--active .shelf-label { fill: var(--navy); }

/* Рекомендации */
.reco-list { display: grid; grid-template-columns: repeat(3, 1fr); gap: 12px; }
.reco-item { display: flex; gap: 12px; text-align: left; background: var(--bg); border: 0; border-radius: 14px; padding: 10px; }
.accessory { margin-top: 14px; font-size: 13px; padding: 10px 12px; border-radius: 12px; background: var(--green-soft); }

/* ---- Каталог и аналитика ---- */
.page-head { display: flex; flex-wrap: wrap; align-items: flex-end; gap: 8px 20px; margin-bottom: 18px; }
.page-head h1 { margin: 0; font-size: 26px; color: var(--navy); width: 100%; }
.page-head p { margin: 0; color: var(--muted); flex: 1; min-width: 260px; }
.page-actions { display: flex; gap: 10px; }
.rules { display: grid; grid-template-columns: repeat(3, 1fr); gap: 20px; margin-bottom: 20px; }
.rule { display: flex; gap: 14px; }
.rule ul { margin: 0; padding-left: 18px; }
.rule li { margin: 3px 0; }
.rule-num { flex: none; width: 34px; height: 34px; border-radius: 50%; background: var(--green); color: var(--navy); font-weight: 800; display: grid; place-items: center; }
.table-head { display: flex; justify-content: space-between; align-items: center; gap: 16px; flex-wrap: wrap; margin-bottom: 8px; }
.filter { border: 1px solid var(--line); border-radius: 10px; padding: 9px 12px; font: inherit; min-width: 260px; }
.table-wrap { overflow-x: auto; }
.table { width: 100%; border-collapse: collapse; font-size: 14px; }
.table th { text-align: left; font-size: 12px; color: var(--muted); font-weight: 700; padding: 8px 10px; border-bottom: 1px solid var(--line); white-space: nowrap; }
.table td { padding: 9px 10px; border-bottom: 1px solid var(--line); }
.table tbody tr[data-open] { cursor: pointer; }
.table tbody tr[data-open]:hover { background: var(--bg); }
.num { text-align: right; }
.kpis { display: grid; grid-template-columns: repeat(6, 1fr); gap: 16px; margin-bottom: 20px; }
.kpi-v { font-size: 30px; font-weight: 800; color: var(--navy); }
.kpi-l { color: var(--muted); font-size: 13px; }
.grid-2 { display: grid; grid-template-columns: 3fr 2fr; gap: 20px; align-items: start; }
.plain { list-style: none; padding: 0; margin: 0; }
.plain li { padding: 7px 0; border-bottom: 1px solid var(--line); }

/* ---- Уведомления и окна ---- */
.toast {
  position: fixed; left: 50%; bottom: 28px; transform: translate(-50%, 30px);
  background: var(--navy); color: #fff; padding: 14px 20px; border-radius: 16px; max-width: min(520px, calc(100% - 32px));
  box-shadow: 0 10px 30px rgba(0, 0, 0, 0.25); opacity: 0; pointer-events: none; transition: 0.25s; z-index: 50; font-size: 14px;
}
.toast.show { opacity: 1; transform: translate(-50%, 0); }
.toast b { color: var(--green); }
.toast-sub { margin-top: 6px; font-size: 12px; color: #aeb7c6; }
.modal { position: fixed; inset: 0; background: rgba(27, 37, 54, 0.55); display: grid; place-items: center; z-index: 40; padding: 16px; }
.modal-box { background: var(--card); border-radius: var(--radius); padding: 24px; width: min(460px, 100%); }
.modal-box h3 { margin: 0 0 8px; color: var(--navy); }
.modal-actions { display: flex; justify-content: flex-end; gap: 10px; margin-top: 18px; flex-wrap: wrap; }
.qr { display: grid; place-items: center; padding: 16px; background: var(--bg); border-radius: 16px; min-height: 232px; }
.qr-fallback { color: var(--muted); font-size: 13px; text-align: center; }
.switch-row { display: flex; align-items: center; gap: 10px; font-weight: 600; margin: 12px 0 4px; }
.switch-row input { width: 20px; height: 20px; accent-color: var(--green-dark); }
.field { display: grid; gap: 6px; font-weight: 600; font-size: 13px; margin-top: 12px; }
.field input { border: 1px solid var(--line); border-radius: 10px; padding: 10px 12px; font: inherit; font-weight: 400; }

/* ---- Планшет и телефон ---- */
@media (max-width: 1180px) {
  .kpis { grid-template-columns: repeat(3, 1fr); }
  .map-row { grid-template-columns: 1fr; }
  .shelf-card { max-width: 320px; }
}
@media (max-width: 920px) {
  .layout, .grid-2, .rules { grid-template-columns: 1fr; }
  .map-row { grid-template-columns: 1fr 180px; }
  .reco-list { grid-template-columns: 1fr; }
  .topbar { position: static; flex-wrap: wrap; gap: 10px 16px; padding: 10px 16px; }
  .store { order: 3; flex-basis: 100%; }
  main { padding: 16px; }
}
@media (max-width: 600px) {
  .tabs { order: 4; width: 100%; }
  .tab { flex: 1; padding: 8px 6px; font-size: 12px; }
  .searchbar input { font-size: 16px; }
  .btn-lg { padding: 12px 16px; }
  .map-row { grid-template-columns: 1fr; }
  .detail-main { grid-template-columns: 88px 1fr; gap: 14px; }
  .cover--lg { width: 88px; height: 126px; padding: 8px; }
  .cover--lg .cover-title { font-size: 11px; }
  .detail-info h2 { font-size: 20px; }
  .mini-grid { grid-template-columns: repeat(2, 1fr); }
  .kpis { grid-template-columns: repeat(2, 1fr); }
  .hero-title { font-size: 24px; }
}
