/* Админка «Шлюз» — стили перенесены из принятых карточек дизайн-системы
   (design/ в кокпите): палитра «Уголь и фиолетовый», типографика с плотной
   таблицей ~34 px, кирпичики. Цвета и правила — закон, своих не выдумываем. */

:root {
  --bg: #121016;
  --surface: #19161f;
  --surface2: #211d29;
  --line: #312b3d;
  --text: #ece9f1;
  --muted: #a09aad;
  --accent: #a78bfa;
  --accent-hover: #b7a1fb;
  --accent-text: #c4b0fc;
  --danger: #ef4444;
  --on-fill: #0b0d11;
}

* { margin: 0; padding: 0; box-sizing: border-box; }

html { color-scheme: dark; }

body {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  background: var(--bg);
  color: var(--text);
  font-size: 13px;
  min-height: 100vh;
}

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

.mono { font-family: ui-monospace, SFMono-Regular, Menlo, monospace; font-size: 12px; }
.num { font-variant-numeric: tabular-nums; }
.mut { color: var(--muted); }
.none { color: var(--muted); opacity: .6; }

/* ── Шапка ─────────────────────────────────────────────────────────── */

.top {
  display: flex; align-items: center; gap: 10px; height: 50px; padding: 0 18px;
  background: var(--surface); border-bottom: 1px solid var(--line);
  position: sticky; top: 0; z-index: 30;
}
.logo { font-size: 15px; font-weight: 800; letter-spacing: .3px; color: var(--text); }
.logo::before {
  content: ""; display: inline-block; width: 9px; height: 9px; border-radius: 50%;
  background: var(--accent); margin-right: 8px; vertical-align: 1px;
}
.top .spacer { flex: 1; }
.top .user { font-size: 12.5px; color: var(--muted); }
.top .out {
  font-size: 12.5px; font-weight: 600; color: var(--accent);
  background: none; border: 0; cursor: pointer; margin-left: 14px; padding: 0;
  font-family: inherit;
}
.top .out:hover { color: var(--accent-hover); }
.burger {
  display: none; background: none; border: 1px solid var(--line); border-radius: 8px;
  color: var(--text); font-size: 15px; line-height: 1; padding: 6px 10px; cursor: pointer;
}

/* ── Колонки: меню + содержимое ────────────────────────────────────── */

.cols { display: flex; align-items: stretch; min-height: calc(100vh - 50px); }

.nav {
  width: 212px; flex: none; background: var(--surface);
  border-right: 1px solid var(--line); padding: 12px 0 20px;
}
.ni { position: relative; display: block; padding: 9px 18px; font-size: 13px; color: var(--muted); }
a.ni:hover { color: var(--text); }
.ni.on { color: var(--accent-text); font-weight: 650; background: #a78bfa14; }
.ni.on::before {
  content: ""; position: absolute; left: 0; top: 6px; bottom: 6px; width: 3px;
  border-radius: 0 3px 3px 0; background: var(--accent);
}
.ni.off { color: var(--muted); opacity: .45; cursor: default; }
.ni.off .soon {
  float: right; font-style: normal; font-size: 10px; font-weight: 700;
  letter-spacing: .5px; border: 1px solid var(--line); border-radius: 5px;
  padding: 1px 5px; margin-top: 1px;
}

.main { flex: 1; min-width: 0; padding: 20px 22px 32px; }
h1 { font-size: 20px; font-weight: 700; letter-spacing: .2px; }

/* ── Сообщение после действия ──────────────────────────────────────── */

.flash {
  margin-top: 12px; padding: 10px 14px; border: 1px solid #22c55e55;
  border-radius: 10px; background: #22c55e14; color: #4ade80;
  font-size: 12.5px; font-weight: 600;
}

/* ── Фильтры ───────────────────────────────────────────────────────── */

.filters {
  background: var(--surface); border: 1px solid var(--line); border-radius: 14px;
  padding: 16px 18px; margin-top: 14px;
}
.frow { display: grid; grid-template-columns: repeat(6, 1fr); gap: 12px; }
.frow + .frow { margin-top: 12px; }
.frow.x5 { grid-template-columns: repeat(5, 1fr); }
.frow.x4 { grid-template-columns: repeat(4, 1fr) 2fr; }
.f .lbl {
  font-size: 11px; font-weight: 700; letter-spacing: .6px; text-transform: uppercase;
  color: var(--muted); margin-bottom: 6px;
}
.inp, .f select, .f input {
  width: 100%; height: 32px; padding: 0 10px; display: block;
  background: var(--bg); border: 1px solid var(--line); border-radius: 8px;
  font-size: 12.5px; color: var(--text); font-family: inherit;
}
.f input::placeholder { color: var(--muted); }
.f input:focus, .f select:focus { outline: none; border-color: var(--accent); }
.f input.mono { font-family: ui-monospace, Menlo, monospace; font-size: 12px; }
.f .range { display: flex; gap: 6px; }
.f .range input { min-width: 0; }
.fbot { display: flex; align-items: center; margin-top: 14px; gap: 14px; flex-wrap: wrap; }
.more {
  font-size: 12.5px; font-weight: 600; color: var(--accent); background: none;
  border: 0; cursor: pointer; padding: 0; font-family: inherit;
}
.more .cnt {
  display: inline-block; min-width: 17px; text-align: center; margin-left: 4px;
  background: #a78bfa22; border: 1px solid #a78bfa55; border-radius: 999px;
  font-size: 11px; padding: 1px 4px; vertical-align: 1px;
}
.spacer { flex: 1; }

/* ── Кнопки ────────────────────────────────────────────────────────── */

.btn {
  display: inline-block; padding: 8px 15px; border-radius: 9px; font-size: 13px;
  font-weight: 650; line-height: 1; border: 0; cursor: pointer; font-family: inherit;
  text-align: center;
}
.btn-main { background: var(--accent); color: var(--on-fill); }
.btn-main:hover { background: var(--accent-hover); color: var(--on-fill); }
.btn-ghost { background: transparent; color: var(--text); border: 1px solid var(--line); padding: 7px 14px; }
.btn-ghost:hover { color: var(--text); border-color: var(--muted); }
.btn-danger { background: transparent; color: #f87171; border: 1px solid #ef444488; padding: 7px 14px; }

/* ── Строка над таблицей: счёт, CSV, страницы ──────────────────────── */

.tbar { display: flex; align-items: center; margin: 14px 2px 10px; gap: 12px; flex-wrap: wrap; }
.tbar .found { font-size: 12.5px; color: var(--muted); }
.csv { font-size: 12.5px; font-weight: 600; color: var(--accent); }
.pag { display: flex; align-items: center; gap: 6px; font-size: 12.5px; color: var(--muted); font-variant-numeric: tabular-nums; }
.pag .pg {
  min-width: 26px; height: 26px; display: inline-flex; align-items: center; justify-content: center;
  border: 1px solid var(--line); border-radius: 7px; color: var(--text); padding: 0 4px;
}
.pag .pg.off { opacity: .4; pointer-events: none; }

/* ── Таблица ───────────────────────────────────────────────────────── */

.tblwrap { border: 1px solid var(--line); border-radius: 10px; overflow-x: auto; }
table { width: 100%; border-collapse: collapse; background: var(--surface); }
th {
  background: var(--surface2); color: var(--muted); text-align: left; padding: 8px 10px;
  font-size: 11px; font-weight: 700; letter-spacing: .6px; text-transform: uppercase;
  white-space: nowrap;
}
th.sort { color: var(--accent-text); }
th.sort::after { content: " ↓"; }
td { border-top: 1px solid var(--surface2); padding: 7px 10px; font-size: 12.5px; white-space: nowrap; }
td.mono { font-size: 12px; }
tr.rowlink { cursor: pointer; }
tr.rowlink:hover td { background: var(--surface2); }

/* Первая колонка (время) закреплена при прокрутке вбок — правило образца */
.tbl-sticky th:first-child, .tbl-sticky td:first-child {
  position: sticky; left: 0; background: var(--surface); z-index: 1;
}
.tbl-sticky th:first-child { background: var(--surface2); }
.tbl-sticky tr.rowlink:hover td:first-child { background: var(--surface2); }

/* ── Бейджи двух статусов: передача — контур, обработка — заливка ──── */

.bdg {
  display: inline-block; padding: 3px 9px; border-radius: 999px; font-size: 11.5px;
  font-weight: 600; line-height: 1.35; white-space: nowrap;
}
.bdg-o { background: transparent; border: 1px solid; }
.bdg-f { border: 1px solid transparent; color: var(--on-fill); }
.o-otsev   { color: #f87171; border-color: #f8717188; }
.o-prinyat { color: #b6bfcb; border-color: #b6bfcb66; }
.o-otpr    { color: #60a5fa; border-color: #60a5fa88; }
.o-set     { color: #2dd4bf; border-color: #2dd4bf88; }
.o-tresh   { color: #ef4444; border-color: #ef444499; }
.f-obrab   { background: #94a3b8; }
.f-sale    { background: #22c55e; }
.f-otmena  { background: #f59e0b; }
.f-spam    { background: #ef4444; }

/* ── Вердикты входящих постбэков ───────────────────────────────────── */

.vrd {
  display: inline-block; padding: 3px 8px; border-radius: 6px; font-size: 11px;
  font-weight: 700; letter-spacing: .3px; border: 1px solid; white-space: nowrap;
}
.v-ok   { color: #b6bfcb; border-color: #b6bfcb55; }
.v-err  { color: #fca5a5; border-color: #ef444488; }
.v-warn { color: #fcd34d; border-color: #fbbf2466; }

/* ── Вкладки ───────────────────────────────────────────────────────── */

.tabs { display: flex; gap: 22px; margin-top: 12px; border-bottom: 1px solid var(--line); }
.tab { padding: 9px 2px 10px; font-size: 13.5px; font-weight: 650; color: var(--muted); }
.tab:hover { color: var(--text); }
.tab.on { color: var(--accent-text); box-shadow: inset 0 -2px 0 var(--accent); }

/* ── Переключатель «Только плохое» ─────────────────────────────────── */

.switch {
  display: flex; align-items: center; gap: 8px; font-size: 12.5px; font-weight: 600;
  cursor: pointer; user-select: none;
}
.switch input { position: absolute; opacity: 0; width: 0; height: 0; }
.sw { width: 34px; height: 20px; border-radius: 999px; background: var(--line); position: relative; flex: none; transition: background .15s; }
.sw::after {
  content: ""; position: absolute; top: 3px; left: 3px; width: 14px; height: 14px;
  border-radius: 50%; background: var(--muted); transition: left .15s, background .15s;
}
.switch input:checked + .sw { background: var(--accent); }
.switch input:checked + .sw::after { left: 17px; background: var(--on-fill); }

/* ── Лента событий (чёрный ящик) ───────────────────────────────────── */

.feed { border: 1px solid var(--line); border-radius: 12px; overflow: hidden; }
.fev { background: var(--surface); }
.fev + .fev { border-top: 1px solid var(--surface2); }
.fev-row { display: flex; align-items: flex-start; gap: 10px; padding: 9px 14px; font-size: 12.5px; cursor: pointer; }
.fev-row:hover { background: var(--surface2); }
.fev .t { color: var(--muted); font-variant-numeric: tabular-nums; flex: none; width: 96px; }
.dot { width: 9px; height: 9px; border-radius: 50%; flex: none; margin-top: 4px; }
.d-ok { background: #9ca3af; } .d-warn { background: #fbbf24; } .d-err { background: #ef4444; }
.fev .typ {
  flex: none; width: 84px; text-align: center; font-size: 10.5px; font-weight: 700;
  letter-spacing: .5px; text-transform: uppercase; color: var(--muted);
  background: var(--surface2); border-radius: 6px; padding: 3px 6px; margin-top: -1px;
}
.fev .who { flex: none; width: 74px; color: var(--muted); overflow: hidden; text-overflow: ellipsis; }
.fev .who.man { color: var(--accent-text); font-weight: 650; }
.fev .tx { flex: 1; min-width: 0; line-height: 1.45; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.fev .tx b { font-weight: 650; }
.wartook { color: #fcd34d; }
.errtx { color: #fca5a5; }
.chip {
  font-family: ui-monospace, Menlo, monospace; font-size: 11.5px; background: var(--bg);
  border: 1px solid var(--line); border-radius: 5px; padding: 1px 5px;
}
.was { text-decoration: line-through; opacity: .65; }

/* Раскрытие строки: полный текст и подробности */
.fev-det { display: none; padding: 4px 14px 12px 129px; }
.fev.open .fev-det { display: block; }
.fev-det .full { font-size: 12.5px; line-height: 1.5; white-space: normal; margin-bottom: 8px; }
.raw {
  background: var(--bg); border: 1px solid var(--line); border-radius: 8px;
  padding: 10px 12px; font-family: ui-monospace, Menlo, monospace; font-size: 11.5px;
  color: #b6bfcb; overflow-x: auto; white-space: pre;
}
.purged { font-size: 11.5px; color: var(--muted); font-style: italic; }

/* ── Карточка лида ─────────────────────────────────────────────────── */

.back { font-size: 12.5px; font-weight: 600; color: var(--accent); }
.head { display: flex; align-items: center; gap: 12px; flex-wrap: wrap; margin-top: 12px; }
.head h1 { font-size: 20px; }
.head .id { font-family: ui-monospace, Menlo, monospace; font-size: 13px; color: var(--muted); }

.cards2 { display: grid; grid-template-columns: 1fr 340px; gap: 18px; margin-top: 18px; align-items: start; }

.panel { background: var(--surface); border: 1px solid var(--line); border-radius: 14px; padding: 18px 20px; }
.panel + .panel { margin-top: 18px; }
.sec-t {
  font-size: 11px; font-weight: 700; letter-spacing: .8px; text-transform: uppercase;
  color: var(--muted); margin-bottom: 12px;
}

.kv { display: flex; gap: 10px; padding: 6px 0; font-size: 12.5px; }
.kv + .kv { border-top: 1px solid var(--surface2); }
.kv .k { color: var(--muted); width: 118px; flex: none; }
.kv .v { min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.kv .v.mono { font-size: 12px; }
.kv .v b { font-weight: 700; color: #4ade80; }

.tags { display: grid; grid-template-columns: 1fr 1fr; gap: 2px 24px; }

/* История статусов лида */
.tl { position: relative; padding-left: 20px; }
.tl::before { content: ""; position: absolute; left: 5px; top: 8px; bottom: 8px; width: 2px; background: var(--line); }
.tev { position: relative; padding: 8px 0; }
.tev::before {
  content: ""; position: absolute; left: -19px; top: 14px; width: 8px; height: 8px;
  border-radius: 50%; background: var(--muted);
}
.tev.good::before { background: #22c55e; }
.tev .toprow { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; }
.tev .t { font-size: 12px; color: var(--muted); font-variant-numeric: tabular-nums; flex: none; }
.tev .src { font-size: 12px; color: var(--muted); }
.tev .keitaro { margin-top: 3px; font-size: 12px; color: var(--muted); }
.tev .keitaro .ok { color: #4ade80; font-weight: 650; }
.tev .keitaro .bad { color: #fcd34d; font-weight: 650; }

/* Журнал доставки */
.att { border: 1px solid var(--line); border-radius: 10px; overflow: hidden; }
.att-row { display: flex; align-items: center; gap: 12px; padding: 9px 12px; font-size: 12.5px; background: var(--surface); flex-wrap: wrap; }
.att-row + * { border-top: 1px solid var(--surface2); }
.att-row .n { color: var(--muted); flex: none; }
.att-row .code { font-family: ui-monospace, Menlo, monospace; font-size: 12px; }
.att-row .ok { color: #4ade80; font-weight: 650; }
.att-row .bad { color: #fcd34d; font-weight: 650; }
.att .raw { border: 0; border-radius: 0; }
.note { margin-top: 8px; font-size: 11.5px; color: var(--muted); }

/* ── Вход ──────────────────────────────────────────────────────────── */

.login-wrap { min-height: 100vh; display: flex; align-items: center; justify-content: center; padding: 20px; }
.login-panel {
  width: 100%; max-width: 360px; background: var(--surface); border: 1px solid var(--line);
  border-radius: 14px; padding: 26px 24px 24px;
}
.login-panel .logo { font-size: 17px; }
.login-panel .lbl {
  font-size: 11px; font-weight: 700; letter-spacing: .6px; text-transform: uppercase;
  color: var(--muted); margin: 18px 0 6px;
}
.login-panel input {
  width: 100%; height: 36px; padding: 0 10px; background: var(--bg);
  border: 1px solid var(--line); border-radius: 8px; font-size: 13px; color: var(--text);
}
.login-panel input:focus { outline: none; border-color: var(--accent); }
.login-panel .btn { width: 100%; margin-top: 16px; padding: 10px 15px; }
.login-err { margin-top: 12px; font-size: 12.5px; color: #fca5a5; }

/* ── Узкие окна ────────────────────────────────────────────────────── */

@media (max-width: 1150px) {
  .frow, .frow.x4, .frow.x5 { grid-template-columns: repeat(3, 1fr); }
  .cards2 { grid-template-columns: 1fr; }
}

@media (max-width: 900px) {
  .burger { display: block; }
  .nav {
    position: fixed; top: 50px; left: 0; bottom: 0; z-index: 40;
    transform: translateX(-100%); transition: transform .15s ease;
    border-right: 1px solid var(--line); overflow-y: auto;
  }
  body.nav-open .nav { transform: translateX(0); }
  .main { padding: 16px 14px 28px; }
  .fev .typ, .fev .who { display: none; }
  .fev-det { padding-left: 14px; }
}

@media (max-width: 700px) {
  .frow, .frow.x4, .frow.x5 { grid-template-columns: repeat(2, 1fr); }
  .tags { grid-template-columns: 1fr; }
}
