/* ============================================================
   SHK Dispatch — система маршрутизации команд рекламаций
   Направление: tech-utility (Datadog / GitHub)
   ============================================================ */

:root {
  --bg:      oklch(98% 0.005 250);
  --surface: oklch(100% 0 0);
  --fg:      oklch(22% 0.02 240);
  --muted:   oklch(50% 0.018 240);
  --border:  oklch(90% 0.008 240);
  --accent:  oklch(58% 0.16 145);

  --font-display: -apple-system, BlinkMacSystemFont, 'Inter', 'Segoe UI', system-ui, sans-serif;
  --font-body:    -apple-system, BlinkMacSystemFont, 'Inter', 'Segoe UI', system-ui, sans-serif;
  --font-mono:    'JetBrains Mono', 'IBM Plex Mono', ui-monospace, Menlo, monospace;

  /* производные нейтрали */
  --surface-2: oklch(96.5% 0.006 250);
  --border-strong: oklch(82% 0.012 240);
  --fg-soft: oklch(34% 0.02 240);

  /* акцент для заливок с белым текстом (контраст ≥ 4.5:1) */
  --accent-strong: oklch(44% 0.14 145);
  --accent-hover:  oklch(38% 0.13 145);
  --accent-tint:   oklch(95% 0.03 145);

  /* семантика статусов */
  --ok:      oklch(52% 0.14 145);
  --warn:    oklch(62% 0.14 70);
  --danger:  oklch(52% 0.19 25);
  --danger-hover: oklch(45% 0.18 25);
  --info:    oklch(52% 0.13 250);

  /* крафт-борд: семантика статусов (значения — порт
     craftos-parser/app/static/css/app.css, одна семантика = один цвет во всём проекте) */
  --st-open:     #e07b00;
  --st-assigned: #1a6feb;
  --st-today:    #1e8e4e;
  --st-repeat:   #7b3fbf;
  --st-missing:  #c0392b;
  --st-done:     #6b7683;

  /* приоритеты SLA / Problemtyp (маппинг из Settings) */
  --prio-critical: oklch(52% 0.19 25);   /* Überfällig / Notfall-SOS */
  --prio-urgent:   oklch(58% 0.16 45);   /* Dringend */
  --prio-high:     oklch(68% 0.13 80);   /* Hoch */
  --prio-mid:      oklch(52% 0.13 250);  /* Mittel */
  --prio-low:      oklch(58% 0.02 240);  /* Niedrig */

  /* категориальные цвета команд */
  --team-nord:  oklch(52% 0.13 230);
  --team-ost:   oklch(52% 0.15 300);
  --team-west:  oklch(55% 0.11 185);
  --team-sued:  oklch(56% 0.16 350);
  --team-mitte: oklch(52% 0.10 105);

  /* карта */
  --map-water: oklch(96.5% 0.008 235);
  --map-land:  oklch(99% 0.003 250);
  --map-land-line: oklch(86% 0.012 240);
  --map-city:  oklch(70% 0.012 240);

  --radius: 6px;
  --radius-lg: 10px;
  --shadow-panel: 0 8px 28px oklch(30% 0.02 240 / 0.14);
  --shadow-card: 0 1px 2px oklch(30% 0.02 240 / 0.07);
}

* { box-sizing: border-box; }

html, body { margin: 0; padding: 0; }

body {
  font-family: var(--font-body);
  font-size: 14px;
  line-height: 1.5;
  color: var(--fg);
  background: var(--bg);
  font-feature-settings: 'tnum' 1;
  -webkit-font-smoothing: antialiased;
}

h1, h2, h3, h4 { font-family: var(--font-display); margin: 0; }
h1 { font-size: 20px; font-weight: 650; letter-spacing: -0.01em; line-height: 1.2; }
h2 { font-size: 16px; font-weight: 650; letter-spacing: -0.01em; line-height: 1.25; }
h3 { font-size: 14px; font-weight: 600; line-height: 1.3; }

a { color: var(--accent-strong); text-underline-offset: 2px; }
a:hover { color: var(--accent-hover); }

.mono { font-family: var(--font-mono); font-size: 0.93em; }

.kicker {
  font-size: 11px; font-weight: 600; text-transform: uppercase;
  letter-spacing: 0.08em; color: var(--muted);
}

:focus-visible {
  outline: 2px solid var(--accent-strong);
  outline-offset: 2px;
  border-radius: 4px;
}

::selection { background: var(--accent-tint); }

/* ---------- кнопки ---------- */

.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 7px;
  font: inherit; font-size: 13px; font-weight: 570; letter-spacing: 0.01em;
  padding: 7px 14px; min-height: 34px;
  border-radius: var(--radius); cursor: pointer;
  border: 1px solid var(--border-strong);
  background: var(--surface); color: var(--fg);
  transition: background 0.12s, border-color 0.12s, transform 0.05s;
  white-space: nowrap;
}
.btn:hover { background: var(--surface-2); border-color: oklch(72% 0.015 240); }
.btn:active { transform: translateY(1px); }
.btn svg { width: 15px; height: 15px; flex: none; }

.btn-primary {
  background: var(--accent-strong); border-color: var(--accent-strong); color: #fff;
}
.btn-primary:hover { background: var(--accent-hover); border-color: var(--accent-hover); color: #fff; }

.btn-danger {
  background: var(--surface); border-color: var(--danger); color: var(--danger);
}
.btn-danger:hover { background: var(--danger); border-color: var(--danger); color: #fff; }

.btn-ghost { border-color: transparent; background: transparent; }
.btn-ghost:hover { background: var(--surface-2); border-color: transparent; }

.btn-sm { padding: 4px 10px; min-height: 28px; font-size: 12.5px; }
.btn[disabled] { opacity: 0.5; cursor: not-allowed; pointer-events: none; }

.icon-btn {
  display: inline-flex; align-items: center; justify-content: center;
  width: 32px; height: 32px; padding: 0; border-radius: var(--radius);
  border: 1px solid transparent; background: transparent; color: var(--fg-soft); cursor: pointer;
}
.icon-btn:hover { background: var(--surface-2); color: var(--fg); }
.icon-btn svg { width: 17px; height: 17px; }

/* ---------- бейджи и пилюли ---------- */

.pill {
  display: inline-flex; align-items: center; gap: 5px;
  font-size: 11px; font-weight: 620; letter-spacing: 0.06em; text-transform: uppercase;
  padding: 2px 8px; border-radius: 999px; line-height: 1.6;
  border: 1px solid var(--border); background: var(--surface-2); color: var(--fg-soft);
}
.pill .dot { width: 7px; height: 7px; border-radius: 50%; background: currentColor; }

.pill-critical { color: var(--prio-critical); border-color: color-mix(in oklch, var(--prio-critical) 35%, white); background: color-mix(in oklch, var(--prio-critical) 9%, white); }
.pill-urgent   { color: var(--prio-urgent);   border-color: color-mix(in oklch, var(--prio-urgent) 35%, white);   background: color-mix(in oklch, var(--prio-urgent) 10%, white); }
.pill-high     { color: oklch(52% 0.12 80);   border-color: color-mix(in oklch, var(--prio-high) 45%, white);     background: color-mix(in oklch, var(--prio-high) 13%, white); }
.pill-mid      { color: var(--prio-mid);      border-color: color-mix(in oklch, var(--prio-mid) 35%, white);      background: color-mix(in oklch, var(--prio-mid) 9%, white); }
.pill-low      { color: var(--muted); }
.pill-ok       { color: var(--ok); border-color: color-mix(in oklch, var(--ok) 35%, white); background: color-mix(in oklch, var(--ok) 9%, white); }

.stage-tag {
  display: inline-flex; align-items: center; gap: 5px;
  font-size: 11.5px; font-weight: 570; padding: 1px 8px; border-radius: 4px;
  border: 1px solid var(--border); color: var(--fg-soft); background: var(--surface);
}

/* бейдж источника рекламации (AirTable base: CEP/Avernus/...) */
.src-tag {
  display: inline-flex; align-items: center;
  font-size: 10.5px; font-weight: 570; padding: 1px 7px; border-radius: 4px;
  border: 1px solid var(--border); color: var(--muted); background: var(--surface-2);
}

/* маркер объекта на карте (map.js::objEl) — подсветка выбранного;
   класс .selected уже проставлялся и на пульте, но правила для него не было */
.map-obj.selected { outline: 2px solid var(--fg); outline-offset: 2px; }

/* ---------- верхняя панель (десктоп) ---------- */

.topbar {
  display: flex; align-items: center; gap: 14px;
  height: 54px; padding: 0 14px;
  background: var(--surface); border-bottom: 1px solid var(--border);
  position: relative; z-index: 40;
}
.topbar .brand {
  display: flex; align-items: center; gap: 9px;
  font-weight: 700; font-size: 14px; letter-spacing: -0.01em; color: var(--fg);
  text-decoration: none; margin-right: 4px;
}
.brand-mark {
  width: 26px; height: 26px; border-radius: 7px; flex: none;
  background: var(--accent-strong); color: #fff;
  display: inline-flex; align-items: center; justify-content: center;
}
.brand-mark svg { width: 15px; height: 15px; }

.topbar-nav { display: flex; gap: 2px; margin-left: auto; }
.topbar-nav a {
  display: inline-flex; align-items: center; gap: 7px;
  padding: 6px 11px; border-radius: var(--radius);
  font-size: 13px; font-weight: 560; color: var(--fg-soft); text-decoration: none;
}
.topbar-nav a svg { width: 15px; height: 15px; }
.topbar-nav a:hover { background: var(--surface-2); color: var(--fg); }
.topbar-nav a.active { background: var(--surface-2); color: var(--fg); box-shadow: inset 0 -2px 0 var(--fg); border-radius: var(--radius) var(--radius) 2px 2px; }

.date-switch {
  display: flex; align-items: center; gap: 2px;
  border: 1px solid var(--border-strong); border-radius: var(--radius);
  background: var(--surface); padding: 2px;
}
.date-switch .icon-btn { width: 28px; height: 28px; }
.date-switch .date-label {
  font-family: var(--font-mono); font-size: 12.5px; font-weight: 570;
  padding: 0 10px; min-width: 132px; text-align: center; cursor: pointer;
  border-radius: 4px; border: none; background: transparent; color: var(--fg);
  height: 28px;
}
.date-label:hover { background: var(--surface-2); }

.search-box {
  display: flex; align-items: center; gap: 8px;
  border: 1px solid var(--border-strong); border-radius: var(--radius);
  background: var(--surface); padding: 0 10px; height: 34px;
  width: clamp(170px, 20vw, 300px); flex: 1 1 auto; min-width: 0;
  color: var(--muted);
}
.search-box input {
  border: none; outline: none; background: transparent; font: inherit;
  font-size: 13px; color: var(--fg); width: 100%;
}
.search-box svg { width: 15px; height: 15px; flex: none; }

.sync-chip {
  display: inline-flex; align-items: center; gap: 7px;
  font-family: var(--font-mono); font-size: 11.5px; color: var(--fg-soft);
  border: 1px solid var(--border); border-radius: 999px;
  background: var(--surface); padding: 4px 11px 4px 8px; cursor: pointer;
}
.sync-chip:hover { background: var(--surface-2); }
.sync-chip .dot { width: 8px; height: 8px; border-radius: 50%; background: var(--ok); flex: none; }
.sync-chip.err .dot { background: var(--danger); }

.team-strip { display: flex; align-items: center; gap: 4px; flex: 1 1 0; min-width: 0; overflow-x: auto; }
.topbar-nav { flex: 0 0 auto; }
.topbar-user { flex: 0 0 auto; }
.team-chip {
  display: inline-flex; align-items: center; gap: 6px;
  border: 1px solid var(--border); border-radius: 999px; background: var(--surface);
  padding: 3px 10px 3px 6px; font-size: 12px; font-weight: 570; color: var(--fg-soft);
  cursor: pointer;
}
.team-chip:hover { background: var(--surface-2); border-color: var(--border-strong); }
.team-chip.selected { border-color: var(--fg); color: var(--fg); }
.team-chip .swatch { width: 10px; height: 10px; border-radius: 3px; flex: none; }
.team-chip .off { width: 6px; height: 6px; border-radius: 50%; background: var(--border-strong); }
.team-chip .on  { width: 6px; height: 6px; border-radius: 50%; background: var(--ok); }

/* ---------- крафт: суб-навигация (Планирование/Лента/Сводка) + синк-кнопка
   (задача 4, общие для craft.html/craft-feed.html/craft-stats.html) ---------- */

.craft-subnav { display: flex; gap: 2px; }
.craft-subnav a {
  display: inline-flex; align-items: center; padding: 6px 12px; border-radius: var(--radius);
  font-size: 12.5px; font-weight: 570; color: var(--fg-soft); text-decoration: none;
}
.craft-subnav a:hover { background: var(--surface-2); color: var(--fg); }
.craft-subnav a.active { background: var(--surface-2); color: var(--fg); box-shadow: inset 0 -2px 0 var(--accent-strong); }

/* .sync-chip (базовый вид уже определён ниже, у пульта) — здесь только
   состояния busy/err, общие для крафт-синка (craft-sync.js). Порт
   craftos-parser/app/static/css/app.css::.sync-btn[data-state]. */
.sync-chip.busy .dot { background: var(--st-assigned); animation: syncpulse 1s infinite; }
.sync-chip.err { color: var(--st-missing); border-color: color-mix(in oklch, var(--st-missing) 40%, var(--border)); }
.sync-chip.err .dot { background: var(--st-missing); animation: none; }
@keyframes syncpulse { 50% { opacity: .35; } }
@media (prefers-reduced-motion: reduce) { .sync-chip.busy .dot { animation: none; } }

/* ---------- сегментированный фильтр (крафт-лента) — порт .seg референса ---------- */
.seg { display: inline-flex; background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 3px; gap: 2px; flex-wrap: wrap; }
.seg button { font: inherit; border: 0; background: none; border-radius: 4px; padding: 5px 12px; font-size: 12.5px; font-weight: 560; cursor: pointer; color: var(--fg-soft); }
.seg button:hover { color: var(--fg); background: color-mix(in oklch, var(--fg) 6%, var(--surface)); }
.seg button[aria-pressed="true"] { background: var(--fg); color: var(--surface); }

/* ---------- лента изменений CraftOS (craft_changes, краткая история) ----------
   цвет левой полосы через --fc (тот же паттерн, что .craft-card::before/--sc
   в craft.html) — один цвет на field, без отдельных цветных бейджей. */
.feed-item {
  position: relative; display: flex; gap: 12px; padding: 10px 14px 10px 18px;
  border-bottom: 1px solid var(--border); font-size: 13px; align-items: flex-start;
}
.feed-item::before { content: ""; position: absolute; left: 5px; top: 9px; bottom: 9px; width: 4px; border-radius: 2px; background: var(--fc, var(--st-done)); }
.feed-item:last-child { border-bottom: 0; }
.feed-item[data-field="new"]    { --fc: var(--st-open); }
.feed-item[data-field="date"]   { --fc: var(--st-repeat); }
.feed-item[data-field="status"] { --fc: var(--st-assigned); }
.feed-item[data-field="team"]   { --fc: var(--st-today); }
.feed-item[data-field="gone"]   { --fc: var(--st-missing); }
.feed-item.crit { background: color-mix(in oklch, var(--danger) 8%, var(--surface)); }
.feed-time { font-family: var(--font-mono); font-size: 11.5px; color: var(--muted); white-space: nowrap; width: 84px; flex: none; padding-top: 2px; }
.feed-body { flex: 1; min-width: 0; }
.feed-badge {
  display: inline-flex; align-items: center; gap: 4px; font-size: 11px; font-weight: 620;
  padding: 1px 8px; border-radius: 999px; line-height: 1.6; background: var(--surface-2); color: var(--fg-soft); margin-right: 8px;
}
.feed-who { font-weight: 620; font-size: 13.5px; }
.feed-change { font-size: 12.5px; color: var(--fg-soft); margin-top: 2px; }
.feed-change .arrow { color: var(--muted); margin: 0 4px; }
.feed-account { font-family: var(--font-mono); font-size: 11px; color: var(--muted); white-space: nowrap; flex: none; padding-top: 2px; }

/* ---------- каркас пульта ---------- */

.cockpit {
  display: grid; grid-template-columns: 384px 1fr;
  height: calc(100vh - 54px); overflow: hidden;
}

.list-pane {
  background: var(--surface); border-right: 1px solid var(--border);
  display: flex; flex-direction: column; min-height: 0;
}

.tabs {
  display: flex; gap: 0; border-bottom: 1px solid var(--border);
  padding: 0 8px; flex: none; overflow-x: auto;
}
.tab {
  font: inherit; font-size: 12.5px; font-weight: 570; letter-spacing: 0.01em;
  color: var(--fg-soft); background: none; border: none; cursor: pointer;
  padding: 10px 10px 8px; border-bottom: 2px solid transparent;
  display: inline-flex; align-items: center; gap: 6px; white-space: nowrap;
}
.tab:hover { color: var(--fg); }
.tab.active { color: var(--accent-hover); border-bottom-color: var(--accent-strong); }
.tab .count {
  font-family: var(--font-mono); font-size: 10.5px; font-weight: 600;
  background: var(--surface-2); border: 1px solid var(--border);
  border-radius: 999px; padding: 0 6px; line-height: 1.5; color: var(--fg-soft);
}
.tab.active .count { background: var(--accent-tint); border-color: transparent; color: var(--accent-hover); }
.tab .count.alert { background: color-mix(in oklch, var(--danger) 10%, white); border-color: transparent; color: var(--danger); }

.list-toolbar {
  display: flex; align-items: center; justify-content: space-between;
  padding: 8px 12px; border-bottom: 1px solid var(--border); flex: none;
}
.sort-select {
  font: inherit; font-size: 12px; color: var(--fg-soft);
  border: 1px solid var(--border); border-radius: var(--radius);
  background: var(--surface); padding: 4px 8px; cursor: pointer;
}

.obj-list { overflow-y: auto; flex: 1; min-height: 0; }

.obj-row {
  display: grid; grid-template-columns: 4px 1fr auto; gap: 0 10px;
  padding: 10px 14px 10px 10px; border-bottom: 1px solid var(--border);
  cursor: pointer; background: var(--surface); width: 100%; text-align: left;
  border-left: none; border-right: none; border-top: none; font: inherit;
}
.obj-row:hover { background: var(--surface-2); }
.obj-row.selected { background: var(--accent-tint); }
.obj-row .prio-bar { border-radius: 2px; align-self: stretch; }
.obj-row .main { min-width: 0; }
.obj-row .ticket {
  font-family: var(--font-mono); font-size: 11px; color: var(--muted);
  display: block; margin-bottom: 1px;
}
.obj-row .name { font-weight: 600; font-size: 13.5px; }
.obj-row .addr {
  font-size: 12px; color: var(--muted);
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}
.obj-row .meta { display: flex; gap: 6px; margin-top: 5px; flex-wrap: wrap; }
.obj-row .side { text-align: right; display: flex; flex-direction: column; align-items: flex-end; gap: 4px; }
.obj-row .eta { font-family: var(--font-mono); font-size: 12px; color: var(--fg-soft); }
.obj-row .team-mini { display: inline-flex; align-items: center; gap: 5px; font-size: 11.5px; font-weight: 570; color: var(--fg-soft); }
.obj-row .team-mini .swatch { width: 8px; height: 8px; border-radius: 2px; }

.empty-state {
  padding: 44px 24px; text-align: center; color: var(--muted);
}
.empty-state svg { width: 28px; height: 28px; margin-bottom: 10px; color: var(--border-strong); }
.empty-state .t { font-weight: 600; color: var(--fg-soft); margin-bottom: 4px; }
.empty-state p { font-size: 12.5px; margin: 0; }

/* ---------- карта ---------- */

.map-wrap { position: relative; min-width: 0; background: var(--map-water); overflow: hidden; }
.map-wrap svg.geomap { display: block; width: 100%; height: 100%; }

.map-controls {
  position: absolute; top: 12px; right: 12px; z-index: 10;
  display: flex; flex-direction: column; gap: 8px; align-items: flex-end;
}
.map-toggles {
  background: var(--surface); border: 1px solid var(--border);
  border-radius: var(--radius-lg); box-shadow: var(--shadow-card);
  padding: 8px 12px; display: flex; flex-direction: column; gap: 6px;
}
.map-toggle { display: flex; align-items: center; gap: 8px; font-size: 12.5px; color: var(--fg-soft); cursor: pointer; }

.map-legend {
  position: absolute; left: 12px; bottom: 12px; z-index: 10;
  background: var(--surface); border: 1px solid var(--border);
  border-radius: var(--radius-lg); box-shadow: var(--shadow-card);
  padding: 10px 13px; font-size: 11.5px; color: var(--fg-soft);
  display: grid; gap: 5px;
}
.map-legend .row { display: flex; align-items: center; gap: 8px; }
.map-legend .sw { width: 11px; height: 11px; border-radius: 50%; flex: none; }

.map-banner {
  position: absolute; top: 12px; left: 50%; transform: translateX(-50%); z-index: 20;
  display: flex; align-items: center; gap: 9px;
  background: color-mix(in oklch, var(--warn) 12%, white);
  border: 1px solid color-mix(in oklch, var(--warn) 40%, white);
  color: oklch(40% 0.1 70);
  border-radius: var(--radius-lg); padding: 8px 14px; font-size: 12.5px; font-weight: 560;
  box-shadow: var(--shadow-card); max-width: 90%;
}
.map-banner.danger {
  background: color-mix(in oklch, var(--danger) 9%, white);
  border-color: color-mix(in oklch, var(--danger) 35%, white);
  color: var(--danger);
}
.map-banner svg { width: 15px; height: 15px; flex: none; }

.map-hovercard {
  position: absolute; z-index: 30; pointer-events: none;
  background: var(--surface); border: 1px solid var(--border-strong);
  border-radius: var(--radius); box-shadow: var(--shadow-panel);
  padding: 9px 12px; min-width: 190px; max-width: 260px;
}
.map-hovercard .ticket { font-family: var(--font-mono); font-size: 10.5px; color: var(--muted); }
.map-hovercard .name { font-weight: 620; font-size: 13px; }
.map-hovercard .addr { font-size: 11.5px; color: var(--muted); }
.map-hovercard .meta { display: flex; gap: 5px; margin-top: 5px; }
.map-hovercard .hovercard-idle {
  margin-top: 7px; font-size: 11.5px; font-weight: 600; line-height: 1.35;
  color: #b91c1c; background: rgba(220, 38, 38, .1);
  border: 1px solid rgba(220, 38, 38, .35); border-radius: 6px; padding: 5px 7px;
}

/* «пустая» команда на карте (0 объектов на неделе) — пульсирующее кольцо */
@keyframes odIdlePulse {
  0%   { box-shadow: 0 0 0 0 rgba(220, 38, 38, .55); }
  70%  { box-shadow: 0 0 0 11px rgba(220, 38, 38, 0); }
  100% { box-shadow: 0 0 0 0 rgba(220, 38, 38, 0); }
}
.map-home-idle .map-home-badge { animation: odIdlePulse 1.6s ease-out infinite; }

/* ---------- выдвижная панель ---------- */

.drawer {
  position: fixed; top: 54px; right: 0; bottom: 0; width: 408px; z-index: 60;
  background: var(--surface); border-left: 1px solid var(--border);
  box-shadow: var(--shadow-panel);
  transform: translateX(105%); transition: transform 0.22s ease;
  display: flex; flex-direction: column;
}
.drawer.open { transform: translateX(0); }
@media (prefers-reduced-motion: reduce) { .drawer { transition: none; } }

.drawer-head {
  display: flex; align-items: flex-start; gap: 10px;
  padding: 14px 16px; border-bottom: 1px solid var(--border); flex: none;
}
.drawer-head .grow { flex: 1; min-width: 0; }
.drawer-body { overflow-y: auto; flex: 1; padding: 14px 16px 20px; }
.drawer-foot {
  border-top: 1px solid var(--border); padding: 11px 16px;
  display: flex; gap: 8px; flex-wrap: wrap; flex: none; background: var(--surface);
}

.kv { display: grid; grid-template-columns: 128px 1fr; gap: 6px 14px; font-size: 13px; margin: 0; }
.kv dt { color: var(--muted); font-size: 12.5px; }
.kv dd { margin: 0; min-width: 0; overflow-wrap: break-word; }

.section-label {
  font-size: 11px; font-weight: 620; text-transform: uppercase; letter-spacing: 0.08em;
  color: var(--muted); margin: 18px 0 8px;
}
.drawer-body .section-label:first-child { margin-top: 0; }

.note-box {
  background: var(--surface-2); border: 1px solid var(--border);
  border-radius: var(--radius); padding: 10px 12px; font-size: 13px;
}

/* ---------- модальный диалог ---------- */

.modal-backdrop {
  position: fixed; inset: 0; z-index: 80;
  background: oklch(20% 0.02 240 / 0.42);
  display: none; align-items: center; justify-content: center; padding: 24px;
}
.modal-backdrop.open { display: flex; }
.modal {
  background: var(--surface); border-radius: 12px; box-shadow: var(--shadow-panel);
  width: 760px; max-width: 100%; max-height: calc(100vh - 60px);
  display: flex; flex-direction: column; overflow: hidden;
}
.modal-head { padding: 16px 20px 12px; border-bottom: 1px solid var(--border); display: flex; align-items: flex-start; gap: 12px; }
.modal-body { padding: 16px 20px; overflow-y: auto; }
.modal-foot { padding: 12px 20px; border-top: 1px solid var(--border); display: flex; gap: 8px; justify-content: flex-end; }

.cand-row {
  display: grid; grid-template-columns: 20px 1fr auto; align-items: center; gap: 12px;
  border: 1px solid var(--border); border-radius: var(--radius-lg);
  padding: 11px 14px; cursor: pointer; margin-bottom: 8px; background: var(--surface);
}
.cand-row:hover { border-color: var(--border-strong); background: var(--surface-2); }
.cand-row.selected { border-color: var(--accent-strong); background: var(--accent-tint); }
.cand-row input { accent-color: var(--accent-strong); width: 16px; height: 16px; }
.cand-row .tname { display: flex; align-items: center; gap: 8px; font-weight: 620; font-size: 13.5px; }
.cand-row .tname .swatch { width: 11px; height: 11px; border-radius: 3px; }
.cand-row .tsub { font-size: 12px; color: var(--muted); margin-top: 2px; }
.cand-row .tnum { text-align: right; font-family: var(--font-mono); font-size: 12.5px; color: var(--fg-soft); }
.cand-row .tnum .big { font-size: 15px; font-weight: 620; color: var(--fg); display: block; }
.cand-best {
  font-size: 10.5px; font-weight: 650; letter-spacing: 0.07em; text-transform: uppercase;
  color: var(--accent-hover); background: var(--accent-tint);
  border-radius: 4px; padding: 1px 6px;
}

/* ---------- планирование дня ---------- */

.plan-wrap { display: flex; flex-direction: column; height: calc(100vh - 54px); }
.plan-toolbar {
  display: flex; align-items: center; gap: 14px; padding: 10px 16px;
  border-bottom: 1px solid var(--border); background: var(--surface); flex: none;
}
.plan-main { display: grid; grid-template-columns: 300px 1fr; flex: 1; min-height: 0; }

.pool-pane {
  border-right: 1px solid var(--border); background: var(--surface);
  display: flex; flex-direction: column; min-height: 0;
}
.pool-head { padding: 12px 14px 8px; flex: none; }
.pool-list { overflow-y: auto; padding: 4px 10px 14px; flex: 1; }

.board { overflow-y: auto; overflow-x: hidden; display: grid; grid-template-columns: repeat(auto-fill, minmax(230px, 1fr)); gap: 12px; padding: 14px; align-items: start; align-content: start; background: var(--bg); }

.team-col {
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius-lg);
  width: 296px; flex: none; display: flex; flex-direction: column;
  max-height: 100%;
}
.team-col-head { padding: 11px 13px 9px; border-bottom: 1px solid var(--border); }
.team-col-head .trow { display: flex; align-items: center; gap: 8px; }
.team-col-head .swatch { width: 11px; height: 11px; border-radius: 3px; flex: none; }
.team-col-head .tname { font-weight: 650; font-size: 13.5px; flex: 1; }
.team-col-head .totals { font-family: var(--font-mono); font-size: 11.5px; color: var(--muted); margin-top: 4px; }
.team-col-body { padding: 8px; overflow-y: auto; min-height: 60px; }
.team-col-body.dragover { background: var(--accent-tint); border-radius: 0 0 var(--radius-lg) var(--radius-lg); }
.team-col-foot { padding: 8px; border-top: 1px solid var(--border); display: flex; gap: 6px; }

.stop-card {
  border: 1px solid var(--border); border-radius: var(--radius);
  background: var(--surface); box-shadow: var(--shadow-card);
  padding: 8px 10px; margin-bottom: 6px; cursor: grab; position: relative;
}
.stop-card:hover { border-color: var(--border-strong); }
.stop-card.dragging { opacity: 0.45; }
.stop-card .top { display: flex; align-items: center; gap: 8px; }
.stop-card .n {
  font-family: var(--font-mono); font-size: 11px; font-weight: 650;
  width: 20px; height: 20px; border-radius: 50%; flex: none;
  display: inline-flex; align-items: center; justify-content: center;
  background: var(--surface-2); border: 1px solid var(--border-strong); color: var(--fg-soft);
}
.stop-card .cname { font-weight: 600; font-size: 12.5px; flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.stop-card .eta { font-family: var(--font-mono); font-size: 11.5px; color: var(--fg-soft); }
.stop-card .sub { font-size: 11.5px; color: var(--muted); margin-top: 3px; padding-left: 28px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.stop-card .actions { display: flex; gap: 2px; margin-top: 5px; padding-left: 24px; }
.stop-card .lock-on { color: var(--accent-hover); }
.stop-card .mini-act {
  font-size: 11px; border: none; background: none; color: var(--muted); cursor: pointer;
  display: inline-flex; align-items: center; gap: 4px; padding: 2px 6px; border-radius: 4px; font-weight: 560;
}
.stop-card .mini-act:hover { background: var(--surface-2); color: var(--fg); }
.stop-card .mini-act svg { width: 12px; height: 12px; }

/* ---------- таблицы (админ, здоровье) ---------- */

.page { max-width: 1060px; margin: 0 auto; padding: 26px 24px 60px; }
.page-head { display: flex; align-items: flex-end; justify-content: space-between; gap: 16px; margin-bottom: 18px; }
.page-head p { color: var(--muted); margin: 5px 0 0; font-size: 13px; max-width: 62ch; }

.card {
  background: var(--surface); border: 1px solid var(--border);
  border-radius: var(--radius-lg); box-shadow: var(--shadow-card);
}
.card + .card { margin-top: 16px; }
.card-head { padding: 13px 18px; border-bottom: 1px solid var(--border); display: flex; align-items: center; justify-content: space-between; gap: 12px; }
.card-body { padding: 16px 18px; }

table.data { width: 100%; border-collapse: collapse; font-size: 13px; }
table.data th {
  text-align: left; font-size: 11px; font-weight: 620; text-transform: uppercase;
  letter-spacing: 0.07em; color: var(--muted); padding: 9px 14px;
  border-bottom: 1px solid var(--border); white-space: nowrap;
}
table.data td { padding: 10px 14px; border-bottom: 1px solid var(--border); vertical-align: middle; }
table.data tr:last-child td { border-bottom: none; }
table.data tr:hover td { background: var(--surface-2); }
table.data .num { font-family: var(--font-mono); font-size: 12.5px; }

/* ---------- формы ---------- */

.field { margin-bottom: 14px; }
.field > label { display: block; font-size: 12.5px; font-weight: 590; margin-bottom: 5px; color: var(--fg-soft); }
.field .hint { font-size: 11.5px; color: var(--muted); margin-top: 4px; }
.input, select.input, textarea.input {
  font: inherit; font-size: 13px; color: var(--fg);
  border: 1px solid var(--border-strong); border-radius: var(--radius);
  background: var(--surface); padding: 7px 10px; width: 100%; min-height: 34px;
}
.input:focus-visible { outline: 2px solid var(--accent-strong); outline-offset: 0; border-color: var(--accent-strong); }
.input.mono { font-family: var(--font-mono); font-size: 12.5px; }
.form-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 0 18px; }

.switch { position: relative; display: inline-flex; align-items: center; gap: 9px; cursor: pointer; font-size: 13px; }
.switch input { position: absolute; opacity: 0; width: 40px; height: 22px; margin: 0; cursor: pointer; }
.switch .track {
  width: 38px; height: 21px; border-radius: 999px; background: var(--border-strong);
  position: relative; transition: background 0.15s; flex: none;
}
.switch .track::after {
  content: ''; position: absolute; top: 2.5px; left: 3px; width: 16px; height: 16px;
  border-radius: 50%; background: #fff; box-shadow: var(--shadow-card); transition: left 0.15s;
}
.switch input:checked + .track { background: var(--accent-strong); }
.switch input:checked + .track::after { left: 19px; }
.switch input:focus-visible + .track { outline: 2px solid var(--accent-strong); outline-offset: 2px; }

/* ---------- статусы здоровья ---------- */

.health-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(230px, 1fr)); gap: 12px; }
.health-card {
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius-lg);
  padding: 14px 16px; box-shadow: var(--shadow-card);
}
.health-card .hrow { display: flex; align-items: center; gap: 9px; margin-bottom: 8px; }
.health-card .hrow .dot { width: 9px; height: 9px; border-radius: 50%; background: var(--ok); flex: none; }
.health-card.err .hrow .dot { background: var(--danger); }
.health-card .hname { font-weight: 640; font-size: 13.5px; flex: 1; }
.health-card .hmeta { font-size: 12px; color: var(--muted); display: grid; gap: 3px; }
.health-card .hmeta .mono { color: var(--fg-soft); }

.stat-tiles { display: grid; grid-template-columns: repeat(auto-fit, minmax(160px, 1fr)); gap: 12px; margin-bottom: 16px; }
.stat-tile { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius-lg); padding: 13px 16px; box-shadow: var(--shadow-card); }
.stat-tile .v { font-family: var(--font-mono); font-size: 24px; font-weight: 640; letter-spacing: -0.01em; line-height: 1.1; }
.stat-tile .l { font-size: 11.5px; color: var(--muted); margin-top: 4px; }

/* ---------- toast ---------- */

.toast {
  position: fixed; bottom: 20px; left: 50%; transform: translate(-50%, 16px);
  display: flex; align-items: center; gap: 12px;
  background: var(--fg); color: oklch(97% 0.005 250);
  border-radius: var(--radius-lg); padding: 10px 18px; font-size: 13px; font-weight: 560;
  box-shadow: var(--shadow-panel); opacity: 0; pointer-events: none;
  transition: opacity 0.18s, transform 0.18s; z-index: 200; max-width: 90vw;
}
.toast.show { opacity: 1; transform: translate(-50%, 0); pointer-events: auto; }
.toast.toast-warn { background: color-mix(in oklch, var(--warn), black 20%); }
.toast button {
  background: none; border: 1px solid oklch(100% 0 0 / .5); color: inherit;
  border-radius: 5px; padding: 3px 10px; font-size: 12.5px; font-weight: 620;
  cursor: pointer; flex: none; font-family: inherit;
}
.toast button:hover { background: oklch(100% 0 0 / .15); }

/* ---------- крафт-панель объекта: overlay для .drawer + рекомендации назначения (задача 2b/3) ---------- */

.drawer-scrim {
  position: fixed; inset: 0; z-index: 59; display: none;
  background: oklch(20% 0.02 240 / .28);
}
.drawer-scrim.open { display: block; }

.flow-bar { display: flex; align-items: center; gap: 8px; margin-bottom: 10px; }
.flow-prog {
  font-size: 11px; font-weight: 640; letter-spacing: 0.06em; text-transform: uppercase; color: var(--muted);
}
.flow-bar .btn { margin-left: auto; }

.rec-row {
  display: grid; grid-template-columns: 1fr auto; gap: 5px 10px;
  padding: 10px 0; border-bottom: 1px solid var(--border); align-items: center;
}
.rec-row:last-child { border-bottom: 0; }
.rec-main { display: flex; align-items: baseline; gap: 8px; flex-wrap: wrap; grid-column: 1; }
.rec-team { font-family: var(--font-mono); font-weight: 700; font-size: 13.5px; }
.rec-dist { font-variant-numeric: tabular-nums; font-size: 12.5px; color: var(--fg-soft); }
.rec-badges { grid-column: 1; display: flex; gap: 6px; flex-wrap: wrap; }
.rec-actions { grid-column: 2; grid-row: 1 / span 2; }

.rbadge {
  display: inline-flex; align-items: center; font-size: 11px; font-weight: 620;
  padding: 1px 8px; border-radius: 999px; line-height: 1.7; white-space: nowrap;
}
.rbadge-in   { background: var(--surface-2); color: var(--fg-soft); }
.rbadge-out  { background: color-mix(in oklch, var(--muted) 16%, var(--surface)); color: var(--muted); }
.rbadge-free { background: color-mix(in oklch, var(--st-today) 14%, var(--surface)); color: color-mix(in oklch, var(--st-today), black 15%); }
.rbadge-busy-craft { background: color-mix(in oklch, var(--st-open) 15%, var(--surface)); color: color-mix(in oklch, var(--st-open), black 12%); }
/* занята рекламацией — ключевая витрина объединения craft+reclamation, выделяем заливкой */
.rbadge-busy-reclamation { background: var(--danger); color: #fff; font-weight: 700; }

.near-row { display: flex; align-items: flex-start; gap: 10px; padding: 8px 0; border-bottom: 1px solid var(--border); }
.near-row:last-child { border-bottom: 0; }
.near-row input { width: 16px; height: 16px; accent-color: var(--accent-strong); flex: none; margin-top: 2px; }
.near-info { flex: 1; font-size: 13px; }
.near-info .muted { font-size: 12px; color: var(--muted); margin-top: 2px; }

/* ============================================================
   PWA (телефон)
   ============================================================ */

.pwa body { background: var(--bg); }
.pwa-shell {
  max-width: 430px; margin: 0 auto; min-height: 100vh;
  background: var(--bg); display: flex; flex-direction: column;
  border-left: 1px solid var(--border); border-right: 1px solid var(--border);
}
@media (max-width: 460px) { .pwa-shell { border: none; } }

.pwa-appbar {
  display: flex; align-items: center; gap: 10px;
  padding: 14px 16px 10px; background: var(--surface);
  border-bottom: 1px solid var(--border);
  position: sticky; top: 0; z-index: 30;
}
.pwa-appbar .team-dot { width: 12px; height: 12px; border-radius: 4px; background: var(--team-ost); flex: none; }
.pwa-appbar h1 { font-size: 17px; }
.pwa-appbar .spacer { flex: 1; }
.pwa-appbar a.icon-btn { width: 44px; height: 44px; }

.pwa-datebar { display: flex; gap: 6px; padding: 10px 16px; background: var(--surface); border-bottom: 1px solid var(--border); }
.pwa-datebar .seg {
  flex: 1; font: inherit; font-size: 13px; font-weight: 570; min-height: 44px;
  border: 1px solid var(--border-strong); background: var(--surface); color: var(--fg-soft);
  border-radius: var(--radius); cursor: pointer;
}
.pwa-datebar .seg.active { background: var(--fg); color: oklch(97% 0.005 250); border-color: var(--fg); }

.pwa-summary {
  display: flex; gap: 14px; padding: 12px 16px; background: var(--surface);
  border-bottom: 1px solid var(--border); font-size: 12px; color: var(--muted);
}
.pwa-summary b { display: block; font-family: var(--font-mono); font-size: 15px; font-weight: 640; color: var(--fg); }

.pwa-main { flex: 1; padding: 12px 12px 96px; }

.pwa-stop {
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius-lg);
  box-shadow: var(--shadow-card); margin-bottom: 10px; overflow: hidden;
}
.pwa-stop .body { padding: 12px 14px; display: block; width: 100%; text-align: left; background: none; border: none; font: inherit; cursor: pointer; }
.pwa-stop .row1 { display: flex; align-items: center; gap: 10px; }
.pwa-stop .n {
  font-family: var(--font-mono); font-size: 12px; font-weight: 650;
  width: 26px; height: 26px; border-radius: 50%; flex: none;
  display: inline-flex; align-items: center; justify-content: center;
  background: var(--surface-2); border: 1px solid var(--border-strong); color: var(--fg-soft);
}
.pwa-stop.state-done .n { background: var(--accent-tint); border-color: var(--accent-strong); color: var(--accent-hover); }
.pwa-stop .cname { font-weight: 640; font-size: 15px; flex: 1; }
.pwa-stop .eta { font-family: var(--font-mono); font-size: 13px; color: var(--fg-soft); }
.pwa-stop .addr { font-size: 13px; color: var(--muted); margin: 3px 0 0 36px; }
.pwa-stop .meta { display: flex; gap: 6px; margin: 7px 0 0 36px; flex-wrap: wrap; }
.pwa-stop .btns { display: flex; border-top: 1px solid var(--border); }
.pwa-stop .btns > * {
  flex: 1; min-height: 46px; font: inherit; font-size: 13px; font-weight: 580;
  display: inline-flex; align-items: center; justify-content: center; gap: 7px;
  background: none; border: none; border-right: 1px solid var(--border);
  color: var(--fg-soft); cursor: pointer; text-decoration: none;
}
.pwa-stop .btns > *:last-child { border-right: none; }
.pwa-stop .btns > *:hover { background: var(--surface-2); color: var(--fg); }
.pwa-stop .btns .go { color: var(--accent-hover); font-weight: 620; }
.pwa-stop .btns svg { width: 16px; height: 16px; }
.pwa-stop.state-done { opacity: 0.72; }

.pwa-bottom {
  position: fixed; bottom: 14px; left: 50%; transform: translateX(-50%); z-index: 40;
  display: flex; background: var(--fg); border-radius: 999px; padding: 4px;
  box-shadow: var(--shadow-panel);
}
.pwa-bottom a {
  display: inline-flex; align-items: center; gap: 7px; text-decoration: none;
  color: oklch(78% 0.01 250); font-size: 13px; font-weight: 580;
  padding: 10px 18px; border-radius: 999px; min-height: 44px;
}
.pwa-bottom a.active { background: oklch(97% 0.005 250); color: var(--fg); }
.pwa-bottom a svg { width: 16px; height: 16px; }

.pwa-fullbtn {
  display: flex; align-items: center; justify-content: center; gap: 9px;
  width: 100%; min-height: 50px; font: inherit; font-size: 15px; font-weight: 620;
  border-radius: var(--radius-lg); cursor: pointer;
  background: var(--accent-strong); color: #fff; border: 1px solid var(--accent-strong);
}
.pwa-fullbtn:hover { background: var(--accent-hover); border-color: var(--accent-hover); }
.pwa-fullbtn.secondary { background: var(--surface); color: var(--fg); border-color: var(--border-strong); }
.pwa-fullbtn.secondary:hover { background: var(--surface-2); }
.pwa-fullbtn svg { width: 18px; height: 18px; }

/* ---------- лаунчер ---------- */

.launcher { max-width: 980px; margin: 0 auto; padding: 40px 24px 80px; }
.launch-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(280px, 1fr)); gap: 14px; margin-top: 16px; }
.launch-card {
  display: block; text-decoration: none; color: inherit;
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius-lg);
  padding: 16px 18px; box-shadow: var(--shadow-card);
}
.launch-card:hover { border-color: var(--accent-strong); }
.launch-card .lc-t { font-weight: 650; font-size: 14.5px; display: flex; align-items: center; gap: 9px; }
.launch-card .lc-t svg { width: 17px; height: 17px; color: var(--accent-strong); flex: none; }
.launch-card p { font-size: 12.5px; color: var(--muted); margin: 7px 0 0; }
