/* Stratum — Карта командировок. Оформление: канон продукта (тёмное поле #141F2A, золото #E0A33E). */

:root {
  --ground: #0E1620;
  --ground-2: #141F2A;
  --panel: #17222E;
  --panel-2: #1C2937;
  --line: #26374a;
  --line-soft: #1f2e3d;
  --text: #E7EEF6;
  --text-dim: #93A6B8;
  --text-faint: #6C7F92;
  --gold: #E0A33E;
  --gold-dim: #9a7130;
  --now: #E0A33E;
  --planned: #5B8DB8;
  --past: #566a7d;
  --danger: #D9694F;
  --ok: #4FA98C;
  --r: 3px;
  --shadow: 0 10px 30px rgba(0, 0, 0, .45);
}

* { box-sizing: border-box; }

/* Атрибут hidden обязан выигрывать у наших display:flex. Без этого «ворота» с кодом
   остаются прозрачным слоем поверх карты и съедают ВСЕ клики (карта мертва), а каркас
   карты просвечивает ещё до ввода кода. Поймано только при прогоне живой страницы:
   селектор по классу перебивает браузерное правило [hidden]{display:none}. */
[hidden] { display: none !important; }

html, body {
  margin: 0; padding: 0; height: 100%;
  background: var(--ground);
  color: var(--text);
  font: 400 14px/1.45 -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, 'Helvetica Neue', Arial, sans-serif;
  -webkit-text-size-adjust: 100%;
}

a { color: var(--gold); text-decoration: none; }
a:hover { text-decoration: underline; }

/* ── Шапка ───────────────────────────────────────────────────────────── */
.top {
  height: 54px; flex: 0 0 54px;
  display: flex; align-items: center; gap: 12px;
  padding: 0 14px;
  background: var(--ground-2);
  border-bottom: 1px solid var(--line);
  position: relative; z-index: 900;
}
.top-mark { width: 26px; height: 26px; flex: 0 0 26px; display: block; }
.top-title { font-size: 14px; font-weight: 700; letter-spacing: .02em; white-space: nowrap; }
.top-sub {
  font-size: 11px; color: var(--text-faint); text-transform: uppercase; letter-spacing: .14em;
  white-space: nowrap;
}
.top-spacer { flex: 1 1 auto; }
.top-right { display: flex; align-items: center; gap: 14px; }

.live { display: flex; align-items: center; gap: 7px; font-size: 12px; color: var(--text-dim); white-space: nowrap; }
.live-dot { width: 7px; height: 7px; border-radius: 50%; background: var(--ok); flex: 0 0 7px; }
.live.stale .live-dot { background: var(--danger); }
.live.pulse .live-dot { animation: livepulse 1.1s ease-out; }
@keyframes livepulse {
  0% { box-shadow: 0 0 0 0 rgba(79, 169, 140, .7); }
  100% { box-shadow: 0 0 0 9px rgba(79, 169, 140, 0); }
}
@media (prefers-reduced-motion: reduce) { .live.pulse .live-dot { animation: none; } }

/* ── Каркас страницы карты ───────────────────────────────────────────── */
.shell { display: flex; flex-direction: column; height: 100%; }
.stage { flex: 1 1 auto; position: relative; min-height: 0; }
#map { position: absolute; inset: 0; background: var(--ground); }

/* Подложка OSM приводится к тёмной палитре фильтром: цветная карта убивает читаемость точек. */
.leaflet-tile-pane { filter: grayscale(1) invert(1) brightness(.88) contrast(.92) hue-rotate(188deg) saturate(.5); }
.leaflet-container { background: var(--ground); outline: none; }
.leaflet-control-attribution {
  background: rgba(14, 22, 32, .78) !important; color: var(--text-faint) !important;
  font-size: 10px !important; border-top-left-radius: var(--r);
}
.leaflet-control-attribution a { color: var(--text-dim) !important; }
.leaflet-bar { border: 1px solid var(--line) !important; box-shadow: none !important; }
.leaflet-bar a {
  background: var(--panel) !important; color: var(--text) !important;
  border-bottom-color: var(--line) !important;
}
.leaflet-bar a:hover { background: var(--panel-2) !important; }

/* ── Точки на карте ──────────────────────────────────────────────────── */
.pin { position: relative; }
.pin-body {
  display: flex; align-items: center; justify-content: center;
  width: 100%; height: 100%;
  border-radius: 50%;
  background: rgba(224, 163, 62, .16);
  border: 1.5px solid var(--now);
  color: var(--now);
  font-weight: 700; font-size: 12px;
  box-shadow: 0 0 0 4px rgba(224, 163, 62, .07), 0 4px 14px rgba(0, 0, 0, .5);
  transition: transform .12s ease, background .12s ease;
}
.pin.planned .pin-body {
  background: rgba(91, 141, 184, .16); border-color: var(--planned); color: #9cc4e4;
  box-shadow: 0 0 0 4px rgba(91, 141, 184, .07), 0 4px 14px rgba(0, 0, 0, .5);
}
.pin:hover .pin-body { transform: scale(1.12); background: rgba(224, 163, 62, .3); }
.pin.active .pin-body { background: var(--now); color: #14202b; }
.pin-label {
  position: absolute; left: 50%; transform: translateX(-50%);
  top: 100%; margin-top: 4px;
  font-size: 11px; font-weight: 600; color: var(--text);
  white-space: nowrap; pointer-events: none;
  text-shadow: 0 1px 3px rgba(0, 0, 0, .95), 0 0 8px rgba(0, 0, 0, .8);
}

/* ── Боковая панель ──────────────────────────────────────────────────── */
.side {
  position: absolute; top: 12px; left: 12px; bottom: 12px; width: 328px;
  display: flex; flex-direction: column;
  background: rgba(20, 31, 42, .93);
  border: 1px solid var(--line);
  border-radius: var(--r);
  box-shadow: var(--shadow);
  z-index: 800;
  overflow: hidden;
}
.side-stats { display: flex; border-bottom: 1px solid var(--line-soft); }
.stat { flex: 1 1 0; padding: 12px 14px; border-right: 1px solid var(--line-soft); }
.stat:last-child { border-right: 0; }
.stat-num { font-size: 22px; font-weight: 700; line-height: 1.1; font-variant-numeric: tabular-nums; }
.stat-num.gold { color: var(--gold); }
.stat-cap { font-size: 10px; color: var(--text-faint); text-transform: uppercase; letter-spacing: .12em; margin-top: 3px; }

.side-search { padding: 10px 12px; border-bottom: 1px solid var(--line-soft); }
input, select, button, textarea { font: inherit; }
.inp {
  width: 100%; padding: 8px 10px;
  background: var(--ground); color: var(--text);
  border: 1px solid var(--line); border-radius: var(--r);
  outline: none;
}
.inp:focus { border-color: var(--gold-dim); box-shadow: 0 0 0 2px rgba(224, 163, 62, .13); }
.inp::placeholder { color: var(--text-faint); }

.side-list { flex: 1 1 auto; overflow-y: auto; overscroll-behavior: contain; }
.city {
  padding: 10px 14px; border-bottom: 1px solid var(--line-soft);
  cursor: pointer; transition: background .1s ease;
}
.city:hover { background: rgba(224, 163, 62, .06); }
.city.active { background: rgba(224, 163, 62, .1); box-shadow: inset 2px 0 0 var(--gold); }
.city-head { display: flex; align-items: baseline; gap: 8px; }
.city-name { font-weight: 600; }
.city-count {
  margin-left: auto; font-size: 11px; color: var(--text-faint);
  font-variant-numeric: tabular-nums; white-space: nowrap;
}
.person { display: flex; gap: 8px; align-items: baseline; margin-top: 5px; font-size: 13px; }
.person-mark { width: 6px; height: 6px; border-radius: 50%; background: var(--now); flex: 0 0 6px; margin-top: 6px; }
.person.planned .person-mark { background: var(--planned); }
.person-name { color: var(--text); }
.person-meta { margin-left: auto; font-size: 11px; color: var(--text-faint); white-space: nowrap; font-variant-numeric: tabular-nums; }
.person-note { font-size: 11px; color: var(--text-faint); margin-left: 14px; }

.empty { padding: 22px 16px; color: var(--text-faint); font-size: 13px; text-align: center; }

/* Честная плашка про пробелы в данных: карта не притворяется полной. */
.gap {
  margin: 0; padding: 9px 14px;
  background: rgba(217, 105, 79, .1);
  border-top: 1px solid rgba(217, 105, 79, .3);
  font-size: 12px; color: #eab5a6;
}
.gap b { color: #f3c9bd; }

/* ── Управление датой ────────────────────────────────────────────────── */
.dates {
  position: absolute; left: 50%; transform: translateX(-50%); bottom: 16px;
  display: flex; align-items: center; gap: 10px;
  padding: 9px 12px;
  background: rgba(20, 31, 42, .95);
  border: 1px solid var(--line); border-radius: var(--r);
  box-shadow: var(--shadow); z-index: 800;
  max-width: calc(100% - 380px);
}
.btn {
  padding: 7px 12px;
  background: var(--panel-2); color: var(--text);
  border: 1px solid var(--line); border-radius: var(--r);
  cursor: pointer; white-space: nowrap;
}
.btn:hover { background: #223243; border-color: #2e4356; }
.btn:active { transform: translateY(1px); }
.btn.gold { background: var(--gold); color: #14202b; border-color: var(--gold); font-weight: 600; }
.btn.gold:hover { background: #edb14b; }
.btn.ghost { background: transparent; }
.btn.icon { padding: 7px 9px; line-height: 1; }
.btn:disabled { opacity: .45; cursor: default; }
.btn:focus-visible, .inp:focus-visible, .city:focus-visible { outline: 2px solid var(--gold); outline-offset: 1px; }

/* Подпись даты — кнопка (открывает календарь), но выглядеть должна как подпись:
   рамка и фон кнопки здесь только на наведении, иначе панель дат рябит. */
.date-label {
  min-width: 132px; text-align: center; font-weight: 600;
  font-variant-numeric: tabular-nums;
  padding: 4px 8px; border-radius: var(--r);
  background: transparent; border: 1px solid transparent;
  color: var(--text); font-family: inherit; font-size: inherit; cursor: pointer;
}
.date-label:hover { background: var(--panel-2); border-color: var(--line); }
.date-label[aria-expanded="true"] { background: var(--panel-2); border-color: var(--gold); }

/* Календарь. Открывается НАД панелью дат: панель и так стоит у нижнего края карты,
   вниз выпадающему блоку места нет. */
.date-pop {
  position: absolute; bottom: calc(100% + 8px); left: 50%; transform: translateX(-50%);
  min-width: 268px; display: flex; flex-direction: column; gap: 8px;
  padding: 12px; z-index: 900;
  background: rgba(20, 31, 42, .98);
  border: 1px solid var(--line); border-radius: var(--r); box-shadow: var(--shadow);
}
.date-pop[hidden] { display: none; }
.date-tabs { display: flex; gap: 6px; }
.date-tabs .btn { flex: 1; }
.date-tabs .btn.on { background: var(--gold); color: #14202b; border-color: var(--gold); font-weight: 600; }
.date-fields { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
.date-fields[hidden] { display: none; }
.date-fields label { color: var(--text-faint); font-size: 12px; }
.date-fields .inp { flex: 1; min-width: 130px; }
.date-quick { display: flex; gap: 6px; }
.date-quick .btn { flex: 1; padding: 6px 8px; font-size: 13px; }
.date-past { display: flex; align-items: center; gap: 7px; color: var(--text-faint); font-size: 12px; cursor: pointer; }
.date-past input { accent-color: var(--gold); }
.date-label small { display: block; font-size: 10px; font-weight: 400; color: var(--text-faint); text-transform: uppercase; letter-spacing: .1em; }
input[type=range] { width: 190px; accent-color: var(--gold); background: transparent; }

.legend {
  position: absolute; right: 12px; bottom: 16px;
  display: flex; flex-direction: column; gap: 6px;
  padding: 10px 12px;
  background: rgba(20, 31, 42, .93);
  border: 1px solid var(--line); border-radius: var(--r);
  font-size: 12px; color: var(--text-dim); z-index: 800;
}
.legend i { width: 9px; height: 9px; border-radius: 50%; display: inline-block; margin-right: 7px; }
.legend .l-now { background: var(--now); }
.legend .l-planned { background: var(--planned); }

/* ── Ворота PIN ──────────────────────────────────────────────────────── */
.gate {
  position: fixed; inset: 0; z-index: 3000;
  display: flex; align-items: center; justify-content: center;
  background: radial-gradient(circle at 50% 35%, #1a2735 0%, #0b1219 70%);
  padding: 20px;
}
.gate-card {
  width: 100%; max-width: 340px; text-align: center;
  background: var(--panel); border: 1px solid var(--line); border-radius: var(--r);
  padding: 26px 24px; box-shadow: var(--shadow);
}
.gate-mark { width: 46px; height: 46px; margin: 0 auto 14px; display: block; }
.gate-title { font-size: 16px; font-weight: 700; }
.gate-note { font-size: 12px; color: var(--text-dim); margin: 8px 0 18px; line-height: 1.5; }
.gate-err { color: #eab5a6; font-size: 12px; min-height: 1.3em; margin-top: 10px; }
.pin-input { text-align: center; letter-spacing: .5em; font-size: 20px; padding: 10px; }

/* ── Администраторская таблица ───────────────────────────────────────── */
.wrap { max-width: 1280px; margin: 0 auto; padding: 18px 16px 60px; }
.card {
  background: var(--panel); border: 1px solid var(--line); border-radius: var(--r);
  margin-bottom: 16px;
}
.card-head {
  display: flex; align-items: center; gap: 12px; flex-wrap: wrap;
  padding: 12px 14px; border-bottom: 1px solid var(--line-soft);
}
.card-title { font-weight: 700; }
.card-hint { font-size: 12px; color: var(--text-faint); }
.card-body { padding: 14px; }
.row-actions { margin-left: auto; display: flex; gap: 8px; flex-wrap: wrap; }

table.grid { width: 100%; border-collapse: collapse; font-size: 13px; }
table.grid th {
  text-align: left; font-size: 10px; font-weight: 700; text-transform: uppercase; letter-spacing: .1em;
  color: var(--text-faint); padding: 8px 8px; border-bottom: 1px solid var(--line);
  background: var(--ground-2); position: sticky; top: 0; z-index: 2;
}
table.grid td { padding: 0; border-bottom: 1px solid var(--line-soft); vertical-align: middle; }
table.grid tr.bad td { background: rgba(217, 105, 79, .07); }
table.grid input {
  width: 100%; padding: 7px 8px; background: transparent; color: var(--text);
  border: 1px solid transparent; border-radius: 2px; outline: none;
}
table.grid input:hover { border-color: var(--line-soft); }
table.grid input:focus { border-color: var(--gold-dim); background: var(--ground); box-shadow: 0 0 0 2px rgba(224, 163, 62, .12); }
table.grid td.narrow { width: 120px; }
table.grid td.tiny { width: 46px; text-align: center; }
.del {
  background: none; border: 0; color: var(--text-faint); cursor: pointer; padding: 6px 8px; line-height: 1;
  border-radius: 2px;
}
.del:hover { color: var(--danger); background: rgba(217, 105, 79, .1); }
.tag {
  display: inline-block; padding: 1px 6px; border-radius: 2px; font-size: 10px;
  text-transform: uppercase; letter-spacing: .08em; border: 1px solid;
}
.tag.unknown { color: #eab5a6; border-color: rgba(217, 105, 79, .5); background: rgba(217, 105, 79, .1); }
.tag.manual { color: #9cc4e4; border-color: rgba(91, 141, 184, .5); background: rgba(91, 141, 184, .1); }

.link-box {
  display: flex; gap: 8px; align-items: center; flex-wrap: wrap;
  background: var(--ground); border: 1px solid var(--line); border-radius: var(--r); padding: 10px 12px;
}
.link-box code { font-size: 12px; word-break: break-all; color: var(--gold); }
.save-state { font-size: 12px; color: var(--text-faint); }
.save-state.ok { color: var(--ok); }
.save-state.err { color: var(--danger); }
.paste-area { width: 100%; min-height: 90px; resize: vertical; }
.muted { color: var(--text-dim); }
.small { font-size: 12px; }

/* ── Узкий экран ─────────────────────────────────────────────────────── */
/* Первая версия ставила управление датой сверху, а ползунок оставляла — в 390px кнопка
   «Весь период» обрезалась, поверх неё лезли кнопки зума, а маркеры прятались за панелью.
   Поэтому на телефоне: панель фиксированной высоты, дата — компактной строкой прямо над
   ней, ползунок и зум убраны (шаг по дням стрелками, масштаб — щипком). */
@media (max-width: 900px) {
  .side {
    top: auto; left: 0; right: 0; bottom: 0; width: auto;
    height: 46%; max-height: 46%;
    border-radius: 0; border-left: 0; border-right: 0; border-bottom: 0;
  }
  .dates {
    left: 8px; right: 8px; transform: none;
    bottom: calc(46% + 8px);
    max-width: none; justify-content: center; gap: 6px;
    padding: 7px 8px;
  }
  .dates input[type=range] { display: none; }
  .date-label { min-width: 96px; font-size: 13px; }
  .dates .btn { padding: 6px 9px; font-size: 13px; }
  .legend { display: none; }
  .leaflet-control-zoom { display: none; }
  .top-sub { display: none; }
  .stat { padding: 9px 12px; }
  .stat-num { font-size: 18px; }
}
