/* Визуальный язык — как в Detour: нейтральные поверхности, тонкие линии, один акцент. */

/* ============ tokens ============ */

:root,
:root[data-theme="dark"] {
  --bg: #111215;
  --surface: #17181c;
  --raised: #1d1f24;
  --hover: rgba(255, 255, 255, 0.045);
  --press: rgba(255, 255, 255, 0.08);
  --line: rgba(255, 255, 255, 0.07);
  --line-strong: rgba(255, 255, 255, 0.13);
  --text: #ececef;
  --text-2: #a3a6af;
  --muted: #6c707a;
  --accent: #4cc38a;
  --accent-hover: #5fd39a;
  --accent-soft: rgba(76, 195, 138, 0.14);
  --on-accent: #06140c;
  --warn: #e5a54b;
  --warn-soft: rgba(229, 165, 75, 0.1);
  --err: #ef6461;
  --err-soft: rgba(239, 100, 97, 0.12);
  --shadow: 0 16px 40px rgba(0, 0, 0, 0.5), 0 0 0 1px var(--line-strong);
  color-scheme: dark;
}

:root[data-theme="light"] {
  --bg: #fbfbfc;
  --surface: #ffffff;
  --raised: #ffffff;
  --hover: rgba(10, 12, 20, 0.04);
  --press: rgba(10, 12, 20, 0.075);
  --line: rgba(10, 12, 20, 0.08);
  --line-strong: rgba(10, 12, 20, 0.14);
  --text: #17181c;
  --text-2: #4f525a;
  --muted: #8a8d96;
  --accent: #1f9d62;
  --accent-hover: #1a8a56;
  --accent-soft: rgba(31, 157, 98, 0.1);
  --on-accent: #ffffff;
  --warn: #b7791f;
  --warn-soft: rgba(200, 130, 30, 0.1);
  --err: #d64541;
  --err-soft: rgba(220, 70, 66, 0.08);
  --shadow: 0 16px 40px rgba(20, 22, 30, 0.14), 0 0 0 1px var(--line-strong);
  color-scheme: light;
}

:root {
  --r: 8px;
  --r-lg: 12px;
  --sans: "Inter", "Segoe UI Variable Text", "Segoe UI", system-ui, -apple-system, "Helvetica Neue", sans-serif;
  --ease: cubic-bezier(0.2, 0, 0, 1);
  --safe-bottom: env(safe-area-inset-bottom, 0px);
  --tabs-h: 58px;
  --action-h: 0px;
}

/* ============ base ============ */

* { box-sizing: border-box; }
html, body { margin: 0; }
body {
  background: var(--bg);
  color: var(--text);
  font: 15px/1.45 var(--sans);
  -webkit-font-smoothing: antialiased;
  -webkit-tap-highlight-color: transparent;
  min-height: 100vh;
  padding-bottom: calc(var(--tabs-h) + var(--action-h) + var(--safe-bottom) + 16px);
}
button { font: inherit; color: inherit; background: none; border: 0; padding: 0; cursor: pointer; }
input, select { font: inherit; color: inherit; }
:focus { outline: none; }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 1px; }
svg { display: block; flex: none; }

.muted { color: var(--muted); }
.text-2 { color: var(--text-2); }
.accent { color: var(--accent); }
.warn { color: var(--warn); }
.err { color: var(--err); }
.small { font-size: 13px; }
.strong { font-weight: 600; }
.grow { flex: 1; min-width: 0; }
.ellipsis { min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.num { font-variant-numeric: tabular-nums; }

/* ============ шапка ============ */

#head { padding: 12px 16px 6px; }
.who { display: flex; align-items: center; gap: 10px; min-height: 40px; }
.who img { width: 34px; height: 34px; border-radius: 9px; image-rendering: pixelated; }
.who-name { font-weight: 650; font-size: 16px; }
.chat-btn {
  display: inline-flex; align-items: center; gap: 4px; max-width: 100%;
  margin-left: -6px; padding: 1px 6px; border-radius: 6px;
  color: var(--muted); font-size: 13px; transition: background 0.12s, color 0.12s;
}
.chat-btn:hover, .chat-btn:active { background: var(--hover); color: var(--text-2); }
.chat-btn[disabled] { cursor: default; }
.chat-btn[disabled]:hover { background: none; color: var(--muted); }

.stats {
  display: grid; grid-template-columns: repeat(3, 1fr);
  margin-top: 10px; border: 1px solid var(--line); border-radius: var(--r-lg); background: var(--surface);
}
.stat { padding: 9px 12px; min-width: 0; }
.stat + .stat { border-left: 1px solid var(--line); }
.stat-label { font-size: 12px; color: var(--muted); font-weight: 550; }
.stat-value { font-size: 17px; font-weight: 650; font-variant-numeric: tabular-nums; }
.meter { height: 3px; border-radius: 3px; background: var(--press); margin-top: 5px; overflow: hidden; }
.meter i { display: block; height: 100%; border-radius: 3px; background: var(--accent); transition: width 0.3s var(--ease); }
.meter.warn i { background: var(--warn); }
.meter.err i { background: var(--err); }

/* ============ контент ============ */

main { padding: 4px 16px 0; }
.section-title {
  display: flex; align-items: baseline; gap: 8px;
  margin: 20px 2px 8px; font-size: 13px; font-weight: 600; color: var(--muted);
}
.section-title .count { font-weight: 500; }
.section-title .side { margin-left: auto; font-weight: 500; }

.notice {
  display: flex; align-items: center; gap: 10px;
  padding: 10px 12px; margin: 8px 0; border-radius: var(--r);
  background: var(--warn-soft); color: var(--text); font-size: 14px;
}
.notice.err { background: var(--err-soft); }
.notice.ok { background: var(--accent-soft); }
.notice .grow { min-width: 0; }

.empty { display: flex; flex-direction: column; align-items: center; gap: 12px; padding: 48px 20px; color: var(--muted); text-align: center; }
.empty-icon { width: 48px; height: 48px; border-radius: 12px; display: grid; place-items: center; background: var(--hover); color: var(--muted); }
.empty-title { color: var(--text-2); font-size: 15px; font-weight: 600; }

/* ============ кнопки ============ */

.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 7px;
  height: 36px; padding: 0 14px; border-radius: var(--r);
  font-weight: 600; white-space: nowrap;
  transition: background 0.12s, border-color 0.12s, color 0.12s, transform 0.06s, opacity 0.12s;
}
.btn:active:not(:disabled) { transform: scale(0.98); }
.btn:disabled { cursor: default; opacity: 0.45; }
.btn-sm { height: 30px; padding: 0 11px; font-size: 13.5px; }
.btn-lg { height: 46px; font-size: 15.5px; border-radius: 10px; }
.btn.block { width: 100%; }
.btn-primary { background: var(--accent); color: var(--on-accent); }
.btn-primary:hover:not(:disabled) { background: var(--accent-hover); }
.btn-secondary { background: var(--surface); border: 1px solid var(--line-strong); color: var(--text); }
.btn-secondary:hover:not(:disabled) { background: var(--hover); }
.btn-ghost { color: var(--text-2); }
.btn-ghost:hover:not(:disabled), .btn-ghost:active:not(:disabled) { background: var(--hover); color: var(--text); }
.btn.loading { pointer-events: none; }
.btn.loading > * { opacity: 0; }
.btn.loading { position: relative; }
.btn.loading::after {
  content: ""; position: absolute; width: 16px; height: 16px; border-radius: 50%;
  border: 2px solid currentColor; border-right-color: transparent; animation: spin 0.7s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

.icon-btn {
  display: grid; place-items: center; width: 32px; height: 32px; border-radius: 8px; color: var(--text-2);
  transition: background 0.12s, color 0.12s;
}
.icon-btn:hover, .icon-btn:active, .icon-btn.open { background: var(--hover); color: var(--text); }

.segmented { display: flex; padding: 3px; gap: 2px; border-radius: 10px; background: var(--surface); border: 1px solid var(--line-strong); }
.segmented button {
  flex: 1; height: 32px; padding: 0 6px; border-radius: 7px; color: var(--muted); font-weight: 600; font-size: 14px;
  white-space: nowrap; transition: background 0.12s, color 0.12s;
}
.segmented button:hover { color: var(--text); }
.segmented button.on { background: var(--press); color: var(--text); }

/* ============ строки списков ============ */

.rows { display: flex; flex-direction: column; gap: 2px; }
.item {
  display: flex; align-items: center; gap: 12px;
  min-height: 56px; padding: 8px 10px; border-radius: var(--r);
  transition: background 0.1s;
}
button.item { width: 100%; text-align: left; }
button.item:hover, button.item:active { background: var(--hover); }
.item.selected { background: var(--accent-soft); }
.item.me { background: var(--accent-soft); }
.item-icon {
  flex: none; width: 36px; height: 36px; border-radius: 9px; display: grid; place-items: center;
  background: var(--hover); border: 1px solid var(--line); font-size: 19px;
}
.item-main { flex: 1; min-width: 0; display: flex; flex-direction: column; }
.item-title { font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.item-sub { font-size: 13px; color: var(--muted); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.item-side { flex: none; text-align: right; display: flex; flex-direction: column; align-items: flex-end; gap: 2px; }
.item-value { font-weight: 650; font-variant-numeric: tabular-nums; }
.radio {
  flex: none; width: 18px; height: 18px; border-radius: 50%; border: 2px solid var(--line-strong);
  display: grid; place-items: center; transition: border-color 0.12s;
}
.item.selected .radio { border-color: var(--accent); }
.item.selected .radio::after { content: ""; width: 8px; height: 8px; border-radius: 50%; background: var(--accent); }

.avatar {
  flex: none; width: 36px; height: 36px; border-radius: 50%; display: grid; place-items: center;
  font-weight: 700; font-size: 15px; color: #fff;
}
.place { flex: none; width: 24px; text-align: center; color: var(--muted); font-weight: 600; font-variant-numeric: tabular-nums; }

.chip {
  display: inline-flex; align-items: center; gap: 4px; height: 20px; padding: 0 7px; border-radius: 5px;
  background: var(--hover); border: 1px solid var(--line); color: var(--text-2); font-size: 12px; font-weight: 550; white-space: nowrap;
}
.chip.ok { color: var(--accent); background: var(--accent-soft); border-color: transparent; }
.chip.warn { color: var(--warn); background: var(--warn-soft); border-color: transparent; }

.item-sub.wrap { white-space: normal; }
.level { margin-left: 4px; font-size: 13px; font-weight: 500; color: var(--muted); font-variant-numeric: tabular-nums; }

/* ============ грядки ============ */

.beds { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 8px; }
.bed {
  display: flex; flex-direction: column; gap: 4px; min-height: 112px; padding: 12px;
  border-radius: var(--r-lg); background: var(--surface); border: 1px solid var(--line);
  text-align: left; transition: background 0.12s, border-color 0.12s, transform 0.06s;
}
.bed-emoji { font-size: 28px; line-height: 1.1; margin-bottom: 2px; }
.bed-name { font-weight: 600; font-size: 14px; }
.bed-state { font-size: 13px; color: var(--muted); font-variant-numeric: tabular-nums; }
.bed.ripe { border-color: color-mix(in srgb, var(--accent) 45%, transparent); background: var(--accent-soft); }
.bed.ripe .bed-state { color: var(--accent); font-weight: 600; }
.bed.free { align-items: center; justify-content: center; color: var(--muted); border-style: dashed; border-color: var(--line-strong); background: none; }
.bed.free:hover, .bed.free:active { background: var(--hover); color: var(--text-2); }
.bed.free:active { transform: scale(0.98); }
.bar { height: 4px; border-radius: 4px; background: var(--press); overflow: hidden; margin-top: auto; }
.bar i { display: block; height: 100%; border-radius: 4px; background: var(--accent); transition: width 1s linear; }

/* ============ закреплённое главное действие и вкладки ============ */

#action {
  position: fixed; left: 0; right: 0; z-index: 9;
  bottom: calc(var(--tabs-h) + var(--safe-bottom));
  padding: 10px 16px; display: flex; gap: 8px;
  background: linear-gradient(transparent, var(--bg) 22%);
}
#action[hidden] { display: none; }
#action .btn { flex: 1; min-width: 0; }
#action .btn span { overflow: hidden; text-overflow: ellipsis; }

#tabs {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 10;
  display: grid; grid-template-columns: repeat(5, 1fr);
  height: calc(var(--tabs-h) + var(--safe-bottom)); padding-bottom: var(--safe-bottom);
  background: var(--bg); border-top: 1px solid var(--line);
}
#tabs button {
  position: relative; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 3px;
  color: var(--muted); font-size: 11px; font-weight: 550; transition: color 0.12s;
}
#tabs button:hover { color: var(--text-2); }
#tabs button.on { color: var(--text); }
#tabs button.on svg { color: var(--accent); }
#tabs .badge { position: absolute; top: 7px; left: calc(50% + 7px); width: 7px; height: 7px; border-radius: 50%; background: var(--accent); box-shadow: 0 0 0 2px var(--bg); }

/* ============ шторка (модальное окно снизу) ============ */

#sheet { position: fixed; inset: 0; z-index: 50; }
.sheet-shade { position: absolute; inset: 0; background: rgba(4, 5, 8, 0.55); animation: fade 0.14s var(--ease); }
:root[data-theme="light"] .sheet-shade { background: rgba(20, 22, 30, 0.25); }
.sheet-card {
  position: absolute; left: 0; right: 0; bottom: 0; max-height: 88vh; overflow: auto;
  background: var(--raised); border-radius: 16px 16px 0 0; box-shadow: var(--shadow);
  padding: 0 0 calc(16px + var(--safe-bottom)); animation: rise 0.18s var(--ease);
}
.sheet-head { display: flex; align-items: center; gap: 10px; padding: 14px 10px 6px 18px; position: sticky; top: 0; background: var(--raised); z-index: 1; }
.sheet-head h2 { flex: 1; margin: 0; font-size: 16px; font-weight: 650; }
.sheet-body { padding: 4px 10px 0; }
.sheet-body.pad { padding: 4px 18px 0; }
.sheet-foot { display: flex; gap: 8px; padding: 14px 18px 0; }
.sheet-foot .btn { flex: 1; }
@keyframes rise { from { opacity: 0; transform: translateY(14px); } }
@keyframes fade { from { opacity: 0; } }

.field { display: flex; flex-direction: column; gap: 6px; margin: 10px 0; }
.field-label { font-size: 13px; font-weight: 550; color: var(--text-2); }
.input {
  height: 40px; padding: 0 12px; border-radius: var(--r); background: var(--bg); border: 1px solid var(--line-strong);
  transition: border-color 0.12s, box-shadow 0.12s; width: 100%;
}
.input:focus { border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-soft); }

/* всплывающее меню «⋯» */
.menu {
  position: fixed; z-index: 60; min-width: 210px; padding: 5px; border-radius: 10px;
  background: var(--raised); box-shadow: var(--shadow); animation: pop 0.1s var(--ease);
}
.menu button { width: 100%; display: flex; align-items: center; gap: 9px; height: 40px; padding: 0 10px; border-radius: 6px; text-align: left; white-space: nowrap; }
.menu button:hover, .menu button:active { background: var(--hover); }
.menu button:disabled { opacity: 0.45; cursor: default; }
.menu button:disabled:hover { background: none; }
.menu .menu-hint { margin-left: auto; padding-left: 16px; color: var(--muted); font-size: 13px; }
@keyframes pop { from { opacity: 0; transform: translateY(-3px) scale(0.98); } }

/* ============ тосты ============ */

/* сверху: снизу закреплённая кнопка и формы в шторках */
#toasts {
  position: fixed; z-index: 90; left: 16px; right: 16px; top: 10px;
  display: flex; flex-direction: column; align-items: center; gap: 8px; pointer-events: none;
}
.toast {
  display: flex; align-items: center; gap: 10px; max-width: 100%;
  padding: 10px 14px; border-radius: 10px; background: var(--raised); box-shadow: var(--shadow);
  font-size: 14px; animation: drop 0.18s var(--ease);
}
.toast.leaving { animation: out 0.16s var(--ease) forwards; }
.toast.ok svg { color: var(--accent); }
.toast.err svg { color: var(--err); }
@keyframes drop { from { opacity: 0; transform: translateY(-10px); } }
@keyframes out { to { opacity: 0; transform: translateY(-6px); } }

/* ============ итог действия: та же разметка, что уходит в чат ============ */

.rich { padding: 0 8px; }
.rich h2, .rich h3, .rich h4 { margin: 4px 0 10px; font-size: 16px; font-weight: 650; line-height: 1.3; }
.rich h4 { font-size: 15px; margin-top: 14px; }
.rich p { margin: 8px 0; }
.rich table { width: 100%; border-collapse: collapse; margin: 8px 0; font-size: 14px; font-variant-numeric: tabular-nums; }
.rich td, .rich th { padding: 7px 4px; text-align: left; border-bottom: 1px solid var(--line); }
.rich tr:last-child td { border-bottom: 0; }
.rich td[align=right], .rich th[align=right] { text-align: right; }
.rich td[align=center], .rich th[align=center] { text-align: center; }
.rich th { color: var(--muted); font-weight: 600; font-size: 12.5px; }
.rich blockquote { margin: 10px 0; padding: 10px 12px; background: var(--hover); border-radius: var(--r); }
.rich footer { color: var(--muted); font-size: 13px; margin-top: 10px; }
.rich details { margin: 8px 0; }
.rich summary { cursor: pointer; color: var(--text-2); font-weight: 600; }
.rich ul, .rich ol { padding-left: 20px; margin: 6px 0; }
.rich code { background: var(--hover); padding: 1px 5px; border-radius: 5px; }

/* ============ карта ============ */

html.map-mode, html.map-mode body { overflow: hidden; overscroll-behavior: none; }
.map-title { margin-top: 10px; }
.map-stage {
  position: relative; margin: 0 -16px; overflow: hidden; touch-action: none; user-select: none;
  background: var(--bg); border-top: 1px solid var(--line); border-bottom: 1px solid var(--line);
}
.map-stage svg { display: block; width: 100%; height: 100%; cursor: grab; }
.map-stage svg:active { cursor: grabbing; }
.map-zoom { position: absolute; top: 10px; right: 10px; display: flex; flex-direction: column; gap: 6px; }
.map-zoom .icon-btn { width: 38px; height: 38px; background: var(--raised); box-shadow: var(--shadow); color: var(--text); }
.map-card {
  position: absolute; left: 10px; right: 10px; bottom: 10px; padding: 8px 10px; border-radius: var(--r-lg);
  background: color-mix(in srgb, var(--raised) 94%, transparent); box-shadow: var(--shadow); backdrop-filter: blur(6px);
}
.map-card .item { padding: 2px 0; min-height: 0; }
.map-card .legend { margin: 2px 0; }
.card-line { font-size: 13px; color: var(--text-2); margin: 4px 0 2px; }
.city-fill { fill: var(--surface); }
.hex polygon { stroke: var(--bg); stroke-width: 1; vector-effect: non-scaling-stroke; }
.hex.shield polygon { stroke: var(--warn); stroke-dasharray: 3 2; }
.hex-sel { fill: none; stroke: var(--text); stroke-width: 2.5; vector-effect: non-scaling-stroke; pointer-events: none; }
.hex text { fill: #fff; font-size: 0.95px; font-weight: 700; text-anchor: middle; dominant-baseline: central; pointer-events: none; }
.hex.mine text { fill: var(--on-accent); font-size: 0.6px; letter-spacing: -0.04px; }
.hex.icon text { font-size: 0.85px; }
.far .hex.icon text { display: none; }  /* на общем плане значки сливаются */
.raion-border { fill: none; stroke: var(--text-2); stroke-opacity: 0.22; stroke-width: 0.8; vector-effect: non-scaling-stroke; pointer-events: none; }
.okrug-border { fill: none; stroke: var(--text-2); stroke-opacity: 0.7; stroke-width: 1.6; vector-effect: non-scaling-stroke; pointer-events: none; }
.mkad { fill: none; stroke: #e5a54b; stroke-opacity: 0.55; stroke-width: 1.5; vector-effect: non-scaling-stroke; pointer-events: none; }
.river { fill: none; stroke: #4a9eda; stroke-opacity: 0.9; stroke-width: 2.5; stroke-linecap: round; stroke-linejoin: round; vector-effect: non-scaling-stroke; pointer-events: none; }
.okrug-label {
  fill: var(--text); fill-opacity: 0.85; font-size: 1.25px; font-weight: 750; text-anchor: middle; dominant-baseline: central;
  paint-order: stroke; stroke: var(--bg); stroke-width: 0.3px; stroke-opacity: 0.75; pointer-events: none;
}
.kremlin { fill: #e5484d; font-size: 1.4px; text-anchor: middle; dominant-baseline: central; pointer-events: none; }
.legend-title { color: var(--text-2); font-weight: 600; }
.legend-item.osm { margin-left: auto; font-size: 11px; opacity: 0.8; }
.legend { display: flex; flex-wrap: wrap; gap: 6px 14px; margin: 6px 2px 4px; font-size: 12.5px; color: var(--muted); }
.legend-item { display: inline-flex; align-items: center; gap: 6px; }
.legend-item i { width: 10px; height: 10px; border-radius: 3px; opacity: 0.8; }
.hint { padding: 6px 10px 0; color: var(--muted); font-size: 13.5px; }
.inline-ico { display: inline-block; vertical-align: -1px; }
