:root {
  color-scheme: light;
  --bg: #f4f4f1;
  --surface: #fcfcfb;
  --surface-2: #f0efec;
  --line: #e2e1dc;
  --line-strong: #cfcdc6;
  --text: #0b0b0b;
  --text-2: #52514e;
  --muted: #7a7974;
  --accent: #2a78d6;
  --accent-ink: #1c5cab;
  --accent-soft: #e6f0fc;
  --good: #0ca30c;
  --good-ink: #006300;
  --critical: #d03b3b;
  --warning: #fab219;
  --serious: #ec835a;
  --shadow: 0 1px 2px rgba(0, 0, 0, .06), 0 4px 16px rgba(0, 0, 0, .06);
  --radius: 10px;
  /* категориальная палитра: агенты (соседние территории — разные цвета) и дни недели */
  --c0: #2a78d6; --c1: #eb6834; --c2: #1baf7a; --c3: #eda100;
  --c4: #e87ba4; --c5: #008300; --c6: #4a3aa7; --c7: #e34948;
  --font: "Golos Text", system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
}

* { box-sizing: border-box; }
html, body { height: 100%; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 14px/1.4 var(--font);
  display: flex;
  flex-direction: column;
  min-height: 100vh;
}
body > * { flex: none; }
button { font: inherit; color: inherit; }
[hidden] { display: none !important; }
.muted { color: var(--muted); font-weight: 400; }
.num { font-variant-numeric: tabular-nums; }

/* ---------- шапка ---------- */
.top {
  display: flex; align-items: center; gap: 16px;
  padding: 10px 16px; background: var(--surface); border-bottom: 1px solid var(--line);
  flex-wrap: wrap;
}
.brand { display: flex; align-items: center; gap: 10px; min-width: 220px; }
.brand-mark { width: 30px; height: 30px; color: var(--accent); flex: none; }
.brand-title { font-weight: 650; font-size: 15px; }
.brand-sub { color: var(--text-2); font-size: 12.5px; }
.controls { display: flex; align-items: center; gap: 8px; flex: 1; flex-wrap: wrap; }
.player, .edit-tools { display: flex; align-items: center; gap: 6px; flex-wrap: wrap; }
.user { display: flex; align-items: center; gap: 10px; color: var(--text-2); font-size: 13px; }
.user a { color: var(--accent-ink); text-decoration: none; }

.btn {
  display: inline-flex; align-items: center; gap: 6px; height: 34px; padding: 0 12px;
  border: 1px solid var(--line-strong); border-radius: 8px; background: var(--surface); cursor: pointer;
  font-weight: 550; white-space: nowrap;
}
.btn:hover:not(:disabled) { background: var(--surface-2); }
.btn:disabled { opacity: .45; cursor: default; }
.btn svg { width: 16px; height: 16px; }
.btn.primary { background: var(--accent); border-color: var(--accent); color: #fff; }
.btn.primary:hover:not(:disabled) { background: var(--accent-ink); }
.btn.icon { width: 34px; padding: 0; justify-content: center; }
.btn.ghost { border-color: transparent; background: transparent; color: var(--text-2); }
.btn.ghost:hover:not(:disabled) { background: var(--surface-2); color: var(--text); }
.btn.link { border: 0; background: none; padding: 0; height: auto; color: var(--accent-ink); }
.btn:focus-visible, .seg button:focus-visible, .tab-head button:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
.seg { display: inline-flex; border: 1px solid var(--line-strong); border-radius: 8px; overflow: hidden; }
.seg button { border: 0; background: var(--surface); padding: 0 10px; height: 32px; cursor: pointer; color: var(--text-2); font-variant-numeric: tabular-nums; }
.seg button + button { border-left: 1px solid var(--line); }
.seg button.on { background: var(--text); color: #fff; }

.menu { position: relative; }
.menu-list {
  position: absolute; z-index: 1200; top: 40px; left: 0; width: 280px; padding: 6px;
  background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); box-shadow: var(--shadow);
}
.menu-list button {
  display: flex; flex-direction: column; align-items: flex-start; gap: 2px; width: 100%;
  padding: 8px 10px; border: 0; border-radius: 6px; background: none; cursor: pointer; text-align: left;
}
.menu-list button:hover { background: var(--surface-2); }
.menu-list span { color: var(--text-2); font-size: 12.5px; }

/* ---------- этапы ---------- */
.stepper { display: flex; gap: 2px; padding: 8px 16px; background: var(--surface); border-bottom: 1px solid var(--line); overflow-x: auto; }
.step {
  display: flex; align-items: center; gap: 8px; padding: 6px 12px 6px 8px; border-radius: 999px;
  color: var(--muted); white-space: nowrap; font-size: 13px;
}
.step b { display: inline-grid; place-items: center; width: 22px; height: 22px; border-radius: 50%; background: var(--surface-2); color: var(--text-2); font-size: 12px; font-weight: 600; }
.step.done { color: var(--text-2); }
.step.done b { background: var(--accent-soft); color: var(--accent-ink); }
.step.now { color: var(--text); background: var(--accent-soft); font-weight: 600; }
.step.now b { background: var(--accent); color: #fff; }
.step-sep { flex: none; width: 14px; align-self: center; height: 1px; background: var(--line-strong); }

.banner { padding: 8px 16px; background: #fff7e0; border-bottom: 1px solid #f1dfa6; color: #5c4400; font-size: 13.5px; display: flex; gap: 12px; align-items: center; }
.banner .btn { height: 28px; }

/* ---------- основная область ---------- */
.layout { display: grid; grid-template-columns: minmax(0, 1fr) 420px; grid-template-rows: minmax(0, 1fr); flex: 1 1 0; min-height: 440px; }
.map-wrap { position: relative; min-height: 0; }
#map { position: absolute; inset: 0; background: #e9e8e4; }
.side { display: flex; flex-direction: column; gap: 12px; padding: 12px; overflow-y: auto; border-left: 1px solid var(--line); background: var(--bg); min-height: 0; }
.card { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 14px; }

.comment { border-left: 4px solid var(--accent); }
.comment-stage { font-size: 12px; text-transform: uppercase; letter-spacing: .06em; color: var(--accent-ink); font-weight: 650; }
.comment-text { margin: 6px 0 0; font-size: 16px; line-height: 1.45; min-height: 46px; }
.comment-note { margin: 6px 0 0; color: var(--text-2); font-size: 13px; }
.comment-note:empty { display: none; }
.comment.flash { animation: flash .6s ease; }
@keyframes flash { from { background: var(--accent-soft); } to { background: var(--surface); } }

.kpis { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 8px; }
.kpi { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 10px 12px; }
.kpi-label { color: var(--text-2); font-size: 12.5px; }
.kpi-row { display: flex; align-items: baseline; gap: 6px; margin-top: 2px; flex-wrap: wrap; }
.kpi-was { color: var(--muted); font-size: 13px; font-variant-numeric: tabular-nums; }
.kpi-arrow { color: var(--muted); font-size: 12px; }
.kpi-now { font-size: 22px; font-weight: 650; font-variant-numeric: tabular-nums; letter-spacing: -.01em; }
.kpi-delta { font-size: 12.5px; font-weight: 600; font-variant-numeric: tabular-nums; }
.kpi-delta.better { color: var(--good-ink); }
.kpi-delta.worse { color: var(--critical); }
.kpi.pending .kpi-now { color: var(--muted); font-size: 16px; font-weight: 500; }

.tab-head { display: flex; gap: 4px; margin: -4px -4px 10px; }
.tab-head button { border: 0; background: none; padding: 6px 10px; border-radius: 6px; cursor: pointer; color: var(--text-2); font-weight: 550; }
.tab-head button.on { background: var(--surface-2); color: var(--text); }
.hint { color: var(--muted); font-size: 12.5px; margin: 0 0 10px; }

.bars { display: flex; flex-direction: column; gap: 4px; }
.bar-row {
  display: grid; grid-template-columns: 92px 1fr 52px; align-items: center; gap: 8px;
  padding: 4px 6px; border-radius: 6px; cursor: pointer; border: 1px solid transparent;
}
.bar-row:hover { background: var(--surface-2); }
.bar-row.focus { background: var(--accent-soft); }
.bar-row.drop { border-color: var(--accent); background: var(--accent-soft); }
.bar-name { display: flex; align-items: center; gap: 6px; font-size: 13px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.swatch { width: 10px; height: 10px; border-radius: 3px; flex: none; }
.bar-track { position: relative; height: 12px; background: var(--surface-2); border-radius: 4px; }
.bar-fill { position: absolute; left: 0; top: 0; bottom: 0; border-radius: 0 4px 4px 0; background: var(--muted); transition: width .35s ease; }
.bar-fill.over { background: var(--critical); }
.bar-cap { position: absolute; top: -3px; bottom: -3px; width: 2px; background: var(--text); left: 80%; }
.bar-val { text-align: right; font-size: 12.5px; font-variant-numeric: tabular-nums; color: var(--text-2); }
.bar-val.over { color: var(--critical); font-weight: 600; }

.table-wrap { overflow-x: auto; }
table.stats { width: 100%; border-collapse: collapse; font-size: 12.5px; font-variant-numeric: tabular-nums; }
.stats th, .stats td { padding: 5px 6px; text-align: right; border-bottom: 1px solid var(--line); white-space: nowrap; }
.stats th:first-child, .stats td:first-child { text-align: left; }
.stats thead th { color: var(--text-2); font-weight: 550; position: sticky; top: 0; background: var(--surface); }
.stats tbody tr { cursor: pointer; }
.stats tbody tr:hover { background: var(--surface-2); }
.stats tbody tr.focus { background: var(--accent-soft); }
.stats tfoot td { font-weight: 650; border-bottom: 0; }
.stats tfoot tr + tr td { font-weight: 400; color: var(--text-2); }
.stats .over { color: var(--critical); font-weight: 600; }
.selection { background: var(--accent-soft); border-radius: 8px; padding: 10px 12px; margin-bottom: 10px; font-size: 13px; }
.selection b { font-variant-numeric: tabular-nums; }

.log { margin: 0; padding: 0 0 0 22px; max-height: 360px; overflow-y: auto; font-size: 13px; color: var(--text-2); }
.log li { padding: 4px 0; border-bottom: 1px solid var(--line); }
.log li b { color: var(--text); font-weight: 600; }

/* ---------- карта ---------- */
.map-legend {
  position: absolute; z-index: 800; top: 12px; left: 56px; max-width: 60%;
  background: rgba(252, 252, 251, .94); border: 1px solid var(--line); border-radius: 8px; padding: 6px 10px;
  display: flex; flex-wrap: wrap; gap: 4px 12px; font-size: 12.5px; color: var(--text-2); box-shadow: var(--shadow);
}
.map-legend span { display: inline-flex; align-items: center; gap: 5px; }
.map-hint {
  position: absolute; z-index: 800; top: 12px; right: 12px; max-width: 320px;
  background: var(--text); color: #fff; border-radius: 8px; padding: 8px 12px; font-size: 13px; box-shadow: var(--shadow);
}
.days {
  position: absolute; z-index: 800; left: 12px; right: 12px; bottom: 12px;
  display: flex; gap: 6px; align-items: center; flex-wrap: wrap;
  background: rgba(252, 252, 251, .94); border: 1px solid var(--line); border-radius: 8px; padding: 6px 8px; box-shadow: var(--shadow);
}
.days .lbl { color: var(--muted); font-size: 12px; margin-right: 2px; }
.days button {
  border: 1px solid var(--line); background: var(--surface); border-radius: 6px; height: 26px; padding: 0 7px;
  font-size: 12px; cursor: pointer; color: var(--text-2);
}
.days button.on { background: var(--text); border-color: var(--text); color: #fff; }
.days .week { display: inline-flex; gap: 2px; padding-left: 6px; border-left: 1px solid var(--line); align-items: center; }
.days .week i { font-style: normal; font-size: 11.5px; color: var(--muted); margin-right: 2px; }

.home-icon { background: none; border: 0; }
.home-icon div {
  display: grid; place-items: center; width: 26px; height: 26px; border-radius: 7px; background: #fff;
  border: 2.5px solid currentColor; font-size: 11.5px; font-weight: 700; color: var(--text);
  box-shadow: 0 1px 3px rgba(0, 0, 0, .25); font-variant-numeric: tabular-nums;
}
.home-icon.focus div { width: 32px; height: 32px; font-size: 13px; box-shadow: 0 0 0 4px rgba(42, 120, 214, .25), 0 1px 3px rgba(0, 0, 0, .25); }
.home-icon.dim div { opacity: .55; }
.leaflet-container { font: inherit; }
/* подложка приглушена: на ней читаются цвета точек и линий */
.base-tiles { filter: grayscale(1) contrast(.82) brightness(1.08); }
.select-box { border: 1.5px dashed var(--accent); background: rgba(42, 120, 214, .08); position: absolute; z-index: 900; pointer-events: none; }

/* ---------- нижняя панель агента ---------- */
.drawer { background: var(--surface); border-top: 1px solid var(--line); }
.drawer-head { display: flex; align-items: baseline; gap: 10px; padding: 10px 16px 0; }
.drawer-title { font-weight: 650; font-size: 15px; }
.drawer-sub { color: var(--text-2); font-size: 13px; }
.drawer-body { display: grid; grid-template-columns: 380px minmax(0, 1fr) 340px; gap: 16px; padding: 8px 16px 14px; }
.box-title { font-size: 12.5px; font-weight: 600; color: var(--text-2); margin-bottom: 6px; }

.calendar { display: grid; grid-template-columns: 26px repeat(5, 1fr); gap: 3px; font-size: 11.5px; }
.calendar .h { color: var(--muted); text-align: center; }
.calendar .w { color: var(--muted); display: grid; place-items: center; }
.cell {
  position: relative; height: 40px; border-radius: 5px; background: var(--surface-2); cursor: pointer;
  border: 1.5px solid transparent; padding: 2px 4px; overflow: hidden; font-variant-numeric: tabular-nums;
}
.cell .fill { position: absolute; left: 0; bottom: 0; height: 3px; border-radius: 0 2px 0 0; opacity: .85; }
.cell .v { position: relative; font-weight: 650; color: var(--text); line-height: 1.2; }
.cell .m { position: relative; color: var(--text-2); line-height: 1.2; }
.cell.on { border-color: var(--text); }
.cell.over { background: #fbe7e7; }
.cell.over .m { color: var(--critical); font-weight: 600; }
.cell.off { background: repeating-linear-gradient(135deg, var(--surface-2) 0 4px, var(--surface) 4px 8px); cursor: default; }
.cell.drop { border-color: var(--accent); background: var(--accent-soft); }
.cell.pulse { animation: pulse .7s ease; }
@keyframes pulse { 0% { box-shadow: 0 0 0 0 rgba(42, 120, 214, .6); } 100% { box-shadow: 0 0 0 8px rgba(42, 120, 214, 0); } }

.gantt { position: relative; min-height: 96px; }
.gantt svg, .chart svg { display: block; width: 100%; }
.gantt-legend { display: flex; gap: 12px; font-size: 12px; color: var(--text-2); margin-top: 4px; flex-wrap: wrap; }
.gantt-legend span { display: inline-flex; gap: 5px; align-items: center; }
.chart { min-height: 110px; }
.empty { color: var(--muted); font-size: 13px; padding: 18px 0; }

/* ---------- всплывающее ---------- */
.toast {
  position: fixed; z-index: 2000; left: 50%; bottom: 24px; transform: translateX(-50%);
  background: var(--text); color: #fff; padding: 10px 16px; border-radius: 10px; box-shadow: var(--shadow);
  max-width: min(640px, calc(100vw - 32px)); font-size: 14px;
}
.toast.error { background: var(--critical); }
.toast b { font-variant-numeric: tabular-nums; }
.tip {
  position: fixed; z-index: 2100; pointer-events: none; background: var(--surface); border: 1px solid var(--line);
  border-radius: 8px; box-shadow: var(--shadow); padding: 8px 10px; font-size: 12.5px; max-width: 280px; color: var(--text);
}
.tip b { font-weight: 650; }
.tip .row { display: flex; justify-content: space-between; gap: 12px; color: var(--text-2); font-variant-numeric: tabular-nums; }
.ghost-drag {
  position: fixed; z-index: 2200; pointer-events: none; transform: translate(12px, 12px);
  background: var(--text); color: #fff; padding: 4px 8px; border-radius: 6px; font-size: 12.5px; white-space: nowrap;
}
body.dragging, body.dragging * { cursor: grabbing !important; }

.dialog { border: 1px solid var(--line); border-radius: 12px; padding: 20px; width: min(520px, calc(100vw - 32px)); box-shadow: var(--shadow); }
.dialog h2 { margin: 0 0 6px; font-size: 18px; }
.dialog p { margin: 0 0 12px; color: var(--text-2); }
.share-row { display: flex; gap: 8px; margin-bottom: 12px; }
.share-row input { flex: 1; height: 34px; border: 1px solid var(--line-strong); border-radius: 8px; padding: 0 10px; font: inherit; }

/* ---------- узкие экраны ---------- */
@media (max-width: 1100px) {
  .layout { grid-template-columns: 1fr; grid-template-rows: auto auto; flex: 1 0 auto; }
  .map-wrap { height: 60vh; }
  .side { overflow: visible; border-left: 0; }
  .drawer-body { grid-template-columns: 1fr; }
}
@media (max-width: 640px) {
  .top { padding: 8px 12px; gap: 8px; }
  .controls { order: 3; width: 100%; flex-wrap: nowrap; overflow-x: auto; }
  .player, .edit-tools { flex-wrap: nowrap; }
  .user { margin-left: auto; }
  .map-wrap { height: 62vh; }
  .comment-text { font-size: 15px; }
  .menu-list { position: fixed; top: 110px; left: 16px; right: 16px; width: auto; }  /* строка кнопок прокручивается и обрезала бы меню */
  .brand { min-width: 0; }
  .user span { display: none; }
  .stepper { padding: 6px 12px; }
  .side { padding: 12px 16px; }
  .map-legend { left: 52px; max-width: calc(100% - 64px); }
  .drawer-head, .drawer-body { padding-left: 16px; padding-right: 16px; }
}
