/* ============================================================
   WStudio LeadGen Panel — брендовая тема (совпадает с wstudio.fun)
   Manrope + JetBrains Mono, sharp/minimal, dark + light
   ============================================================ */

:root[data-theme="dark"] {
  --bg: #080d18;
  --bg-elevated: #0d1524;
  --surface: #121d30;
  --surface-2: #0b1322;
  --surface-strong: #18263d;
  --border: #263750;
  --border-strong: #38506e;
  --control-border: #56708f;
  --text: #f4f7fc;
  --text-2: #cbd5e3;
  --text-3: #9fb0c6;  /* поднят контраст: было #8494ab, на грани WCAG AA */
  --brand: #897cff;
  --brand-hover: #9b90ff;
  --brand-soft: #272247;
  --brand-warm: #f26086;
  --brand-amber: #f39a4a;
  --signal: #48c6d8;
  --signal-soft: #112f3c;
  --on-brand: #080d18;
  /* семантические токены — как в admin.wstudio.fun */
  --ok: #39c788;
  --ok-soft: #102f25;
  --danger: #f16878;
  --danger-soft: #371b22;
  --warning: #f1b84b;
  --warning-soft: #372b14;
  --zebra: rgba(255, 255, 255, .085);
  --shadow: 0 18px 44px -22px rgba(0, 0, 0, .85);
}

:root[data-theme="light"] {
  --bg: #f3f5f8;
  --bg-elevated: #fff;
  --surface: #fff;
  --surface-2: #f8f9fb;
  --surface-strong: #e3e8f0;
  --border: #d2d9e4;
  --border-strong: #b8c3d1;
  --control-border: #7c899d;
  --text: #111722;
  --text-2: #3f4a5b;
  --text-3: #58636f;  /* поднят контраст для WCAG AA */
  --brand: #6252d8;
  --brand-hover: #5143bf;
  --brand-soft: #ece9ff;
  --brand-warm: #cf416b;
  --brand-amber: #bf691e;
  --signal: #066b7a;
  --signal-soft: #dcf7fa;
  --on-brand: #fff;
  /* семантические токены — как в admin.wstudio.fun */
  --ok: #087a4d;
  --ok-soft: #dff7ec;
  --danger: #b9364a;
  --danger-soft: #fde7ea;
  --warning: #965f00;
  --warning-soft: #fff0cc;
  --zebra: rgba(16, 24, 40, .055);
  --shadow: 0 16px 38px -24px rgba(16, 24, 40, .38);
}

:root {
  --mono: 'JetBrains Mono', ui-monospace, monospace;
  --r: 4px;
  --sp: 8px;
}

* { box-sizing: border-box; }

/* КРИТИЧНО: у .modal-backdrop / .search-wrap / .btn задан display:grid|flex,
   который перебивает атрибут [hidden]. Без !important скрытые элементы видны. */
[hidden] { display: none !important; }

html, body {
  margin: 0;
  padding: 0;
  height: 100%;
  background: var(--bg);
  color: var(--text);
  font-family: Manrope, -apple-system, BlinkMacSystemFont, 'Segoe UI',
               'Segoe UI Emoji', 'Apple Color Emoji', 'Noto Color Emoji', sans-serif;
  font-size: 14px;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
}

body { transition: background .18s ease, color .18s ease; }

/* ───────────────────────── layout ───────────────────────── */
.app {
  display: grid;
  grid-template-columns: 252px 1fr;
  height: 100vh;          /* фиксируем: сайдбар всегда на всю высоту */
  overflow: hidden;
}

.sidebar {
  background: var(--bg-elevated);
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  padding: 20px 14px;
  gap: 22px;
  height: 100%;
  overflow-y: auto;
}

.brand { display: flex; align-items: center; gap: 11px; padding: 0 6px; }

.brand-mark {
  width: 36px; height: 36px;
  flex: 0 0 36px;
  display: grid; place-items: center;
  background: var(--brand);
  color: var(--on-brand);
  font-weight: 800;
  font-size: 13px;
  letter-spacing: .02em;
  border-radius: var(--r);
  font-family: var(--mono);
}

.brand-text { display: flex; flex-direction: column; line-height: 1.25; min-width: 0; }
.brand-text strong { font-size: 15px; font-weight: 800; letter-spacing: -.01em; }
.brand-text span { font-size: 11px; color: var(--text-3); }

.nav { display: flex; flex-direction: column; gap: 2px; flex: 1; }

.nav-item {
  display: flex; align-items: center; gap: 10px;
  width: 100%;
  padding: 9px 11px;
  background: transparent;
  border: 1px solid transparent;
  border-radius: var(--r);
  color: var(--text-2);
  font: inherit;
  font-weight: 600;
  font-size: 13px;
  text-align: left;
  cursor: pointer;
  transition: background .14s ease, color .14s ease, border-color .14s ease;
}
.nav-item svg { width: 17px; height: 17px; flex: 0 0 17px; opacity: .82; }
.nav-item span { flex: 1; }
.nav-item:hover { background: var(--surface); color: var(--text); }
.nav-item.active {
  background: var(--brand-soft);
  color: var(--brand);
  border-color: var(--border);
}
.nav-item.active svg { opacity: 1; }

.badge {
  font-family: var(--mono);
  font-size: 10.5px;
  font-style: normal;
  font-weight: 600;
  padding: 2px 6px;
  min-width: 22px;
  text-align: center;
  border-radius: 2px;
  background: var(--surface-strong);
  color: var(--text-3);
}
.nav-item.active .badge { background: var(--brand); color: var(--on-brand); }
.badge.is-zero { background: transparent; color: var(--text-3); opacity: .6; }
.badge.accent[data-hot="1"] { background: var(--brand-warm); color: #fff; }

.sidebar-foot { display: flex; flex-direction: column; gap: 8px; }

.theme-btn, .site-link {
  display: flex; align-items: center; gap: 9px;
  padding: 8px 11px;
  border: 1px solid var(--border);
  border-radius: var(--r);
  background: var(--surface);
  color: var(--text-2);
  font: inherit; font-size: 12px; font-weight: 600;
  cursor: pointer;
  text-decoration: none;
  transition: border-color .14s ease, color .14s ease, background .14s ease;
}
.theme-btn:hover, .site-link:hover { border-color: var(--control-border); color: var(--text); }
.theme-btn svg, .site-link svg { width: 15px; height: 15px; }
.site-link { justify-content: space-between; font-family: var(--mono); font-size: 11px; }
:root[data-theme="dark"] .ico-sun { display: none; }
:root[data-theme="light"] .ico-moon { display: none; }

/* ───────────────────────── topbar ───────────────────────── */
.main { display: flex; flex-direction: column; min-width: 0; height: 100%; overflow-y: auto; }

.topbar {
  display: flex; align-items: flex-end; justify-content: space-between;
  gap: 20px;
  padding: 22px 26px 18px;
  border-bottom: 1px solid var(--border);
  background: var(--bg);
  position: sticky; top: 0; z-index: 20;
  flex-wrap: wrap;
}
.topbar h1 { margin: 0; font-size: 21px; font-weight: 800; letter-spacing: -.02em; }
.topbar p { margin: 3px 0 0; font-size: 12.5px; color: var(--text-3); }
.topbar-right { display: flex; align-items: center; gap: 9px; flex-wrap: wrap; }

.search-wrap { position: relative; display: flex; align-items: center; }
.search-wrap svg {
  position: absolute; left: 10px;
  width: 15px; height: 15px; color: var(--text-3); pointer-events: none;
}
.search-wrap input {
  height: 34px;
  padding: 0 12px 0 32px;
  width: 230px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--r);
  color: var(--text);
  font: inherit; font-size: 13px;
}
.search-wrap input:focus, .select:focus, .field input:focus, .field select:focus, .field textarea:focus {
  outline: none;
  border-color: var(--brand);
  box-shadow: 0 0 0 3px color-mix(in srgb, var(--brand) 18%, transparent);
}
.search-wrap input::placeholder { color: var(--text-3); }

.select {
  height: 34px;
  padding: 0 10px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--r);
  color: var(--text);
  font: inherit; font-size: 13px; font-weight: 600;
  cursor: pointer;
}

.btn {
  display: inline-flex; align-items: center; gap: 7px;
  height: 34px;
  padding: 0 13px;
  border-radius: var(--r);
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--text);
  font: inherit; font-size: 12.5px; font-weight: 700;
  cursor: pointer;
  white-space: nowrap;
  transition: background .14s ease, border-color .14s ease, color .14s ease;
}
.btn svg { width: 15px; height: 15px; }
.btn:hover { border-color: var(--control-border); }
.btn.primary { background: var(--brand); border-color: var(--brand); color: var(--on-brand); }
.btn.primary:hover { background: var(--brand-hover); border-color: var(--brand-hover); }
.btn.ghost { background: transparent; color: var(--text-2); }
.btn.ghost:hover { background: var(--surface); color: var(--text); }
.btn.danger { color: var(--brand-warm); border-color: var(--border); background: transparent; }
.btn.danger:hover { border-color: var(--brand-warm); }
.btn.sm { height: 28px; padding: 0 9px; font-size: 11.5px; }

.icon-btn {
  display: grid; place-items: center;
  width: 26px; height: 26px;
  background: transparent;
  border: 1px solid transparent;
  border-radius: var(--r);
  color: var(--text-2);          /* было text-3: линии 1px тонули на белом */
  cursor: pointer;
  transition: background .14s, color .14s, border-color .14s;
}
.icon-btn svg { width: 15px; height: 15px; }
.icon-btn:hover { background: var(--surface); color: var(--text); border-color: var(--border); }
.icon-btn.warm { color: var(--danger); }
.icon-btn.warm:hover { color: #fff; background: var(--danger); border-color: var(--danger); }

/* ───────────────────────── content ───────────────────────── */
.content { padding: 22px 26px 40px; flex: 1; min-width: 0; }

/* KPI */
.kpi-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(190px, 1fr));
  gap: 12px;
  margin-bottom: 26px;
}
.kpi {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--r);
  padding: 15px 16px;
  position: relative;
  overflow: hidden;
}
.kpi::before {
  content: ''; position: absolute; left: 0; top: 0; bottom: 0; width: 2px;
  background: var(--brand);
}
.kpi.warm::before { background: var(--brand-warm); }
.kpi.amber::before { background: var(--brand-amber); }
.kpi.signal::before { background: var(--signal); }
.kpi.brand::before { background: var(--brand); }
.kpi.ok::before { background: var(--ok); }
.kpi.violet::before { background: #a77bff; }
.kpi.teal::before { background: #2fb3a6; }
.kpi-label {
  font-size: 11px; font-weight: 700; color: var(--text-3);
  text-transform: uppercase; letter-spacing: .06em;
}
.kpi-value {
  font-family: var(--mono);
  font-size: 26px; font-weight: 600;
  margin-top: 7px; letter-spacing: -.02em;
  font-variant-numeric: tabular-nums;
  word-spacing: -.22em;   /* Intl даёт U+00A0 — в моно 26px он слишком широк */
  white-space: nowrap;
}
.kpi-hint { font-size: 11.5px; color: var(--text-3); margin-top: 3px; }
.kpi-value.zero { color: var(--text-3); }

/* Section blocks */
.section-title {
  font-size: 12px; font-weight: 800; letter-spacing: .07em;
  text-transform: uppercase; color: var(--text-3);
  margin: 0 0 11px;
}
.panel-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--r);
  padding: 18px 19px;
  margin-bottom: 16px;
}
.panel-card h3 { margin: 0 0 9px; font-size: 14.5px; font-weight: 800; }
.panel-card p { margin: 0 0 9px; color: var(--text-2); font-size: 13px; }
.panel-card ol, .panel-card ul { margin: 0; padding-left: 19px; color: var(--text-2); font-size: 13px; }
.panel-card li { margin-bottom: 5px; }
.panel-card li strong { color: var(--text); }
.two-col { display: grid; grid-template-columns: repeat(2, 1fr); gap: 14px; align-items: start; }
@media (max-width: 900px) { .two-col { grid-template-columns: 1fr; } }

/* ───────────────────────── table ───────────────────────── */
.table-wrap {
  border: 1px solid var(--border);
  border-radius: var(--r);
  background: var(--surface);
  overflow: auto;
  /* подсказка о горизонтальной прокрутке, если колонки не влезли */
  background-image: linear-gradient(to left, color-mix(in srgb, var(--brand) 9%, transparent), transparent 26px);
  background-attachment: local, scroll;
  /* было max-height: обрезало последнюю строку пополам.
     Теперь скроллится .main, а таблица показывает целые строки. */
}
table { width: 100%; border-collapse: collapse; font-size: 12.5px; table-layout: auto; }
thead th {
  position: sticky; top: 0; z-index: 2;
  background: var(--surface-strong);
  color: var(--text-2);
  text-align: left;
  font-size: 10.5px; font-weight: 800;
  letter-spacing: .055em;
  padding: 9px;
  border-bottom: 1px solid var(--border);
  white-space: normal;      /* было nowrap: длинные заголовки распирали таблицу */
  line-height: 1.25;
  vertical-align: bottom;
}
tbody td {
  padding: 8px 9px;
  border-bottom: 1px solid var(--border);
  vertical-align: middle;
  color: var(--text-2);
}
tbody tr:last-child td { border-bottom: none; }
tbody tr { transition: background .12s ease; }
tbody tr:nth-child(even) { background: var(--zebra); }
tbody tr:hover { background: var(--brand-soft); }
tbody td.strong { color: var(--text); font-weight: 700; }
td.num { font-family: var(--mono); text-align: right; font-variant-numeric: tabular-nums; }
th.num { text-align: right; }
td.actions { white-space: nowrap; text-align: right; }
td.actions .icon-btn + .icon-btn { margin-left: 2px; }
/* последняя колонка данных не должна упираться в край карточки */
thead th:last-child, tbody td:last-child { padding-right: 14px; }
.rel { padding-right: 4px; }
/* колонка мониторинга: контрол по центру, без лишней ширины */
td.mon-cell, th.mon-cell { text-align: center; }
td.actions .icon-btn { display: inline-grid; }

.mono { font-family: var(--mono); font-size: 11.5px; }
.panel-card li .mono, .panel-card p .mono {
  background: var(--surface-2); border: 1px solid var(--border);
  border-radius: 2px; padding: 1px 5px; line-height: 1.35;
}
a.link { color: var(--brand); text-decoration: none; }
tbody td .mono { color: var(--text-2); }
/* длинные хендлы (@arbitrazh_trafika_chat) распирали таблицу на ~180px */
tbody td a.mono, tbody td span.mono {
  display: inline-block; max-width: 132px;
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap; vertical-align: middle;
}
a.link:hover { text-decoration: underline; }
.trunc { max-width: 150px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; display: block; }
/* Сегменты — самые длинные чипы, не дают таблице сжаться */
.chip { max-width: 118px; overflow: hidden; text-overflow: ellipsis; vertical-align: middle; }
.msg-cell { max-width: 420px; }
.msg-cell .trunc { max-width: 420px; }

/* chips / statuses */
.chip {
  display: inline-block;
  font-size: 10.5px; font-weight: 700;
  padding: 2.5px 7px;
  border-radius: 2px;
  border: 1px solid var(--border-strong);
  background: var(--surface-2);
  color: var(--text-2);
  white-space: nowrap;
}
.chip.brand { border-color: var(--brand); color: var(--brand); background: var(--brand-soft); }
.chip.ok { border-color: var(--ok); color: var(--ok); background: var(--ok-soft); }
.chip.warm { border-color: var(--danger); color: var(--danger); background: var(--danger-soft); }
.chip.amber { border-color: var(--warning); color: var(--warning); background: var(--warning-soft); }
.chip.signal { border-color: var(--signal); color: var(--signal); background: var(--signal-soft); }
.chip.mute { color: var(--text-2); border-color: var(--border-strong); background: var(--surface-2); }

.rel-wrap { display: inline-flex; align-items: center; gap: 4px; }
.rel { display: inline-flex; gap: 2px; }
.rel i { width: 4px; height: 12px; background: var(--surface-strong); border-radius: 1px; }
.rel i.on { background: var(--brand); }
.rel-num { font-family: var(--mono); font-size: 11px; font-weight: 600; color: var(--text-2); line-height: 12px; }
.act-col { text-align: right; padding-right: 14px !important; }

/* Тумблер мониторинга: цель ≥26px, различим не только цветом (есть галочка/точка) */
.mon-toggle {
  display: inline-flex; align-items: center; justify-content: center;
  width: 24px; height: 24px;
  border: 1px solid var(--border); border-radius: var(--r);
  background: var(--surface-2); cursor: pointer; padding: 0;
  transition: border-color .14s, background .14s;
}
.mon-toggle:hover { border-color: var(--control-border); background: var(--surface-strong); }
.mon-toggle svg { width: 14px; height: 14px; color: var(--text-3); }
.mon-toggle:not(.on) { background: var(--surface); }

/* статус вступления: явная иконка вместо непонятного прочерка */
.stat-ico { display: inline-flex; }
.stat-ico svg { width: 15px; height: 15px; }
.stat-ico.yes svg { color: var(--ok); }
.stat-ico.no svg { color: var(--text-3); opacity: .75; }
.mon-toggle.on { border-color: var(--ok); background: color-mix(in srgb, var(--ok) 14%, transparent); }
.mon-toggle.on svg { color: var(--ok); }
.mon-toggle:focus-visible { outline: 2px solid var(--brand); outline-offset: 1px; }

.act-bar {
  display: flex; align-items: center; gap: 8px; flex-wrap: wrap;
  margin-bottom: 13px; padding: 11px 13px;
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--r);
}
.act-hint { font-size: 11.5px; color: var(--text-3); margin-left: auto; }

.thread {
  max-height: 260px; overflow-y: auto; margin-bottom: 15px;
  display: flex; flex-direction: column; gap: 8px;
}
.msg {
  padding: 9px 12px; border-radius: var(--r); font-size: 12.5px;
  border: 1px solid var(--border); background: var(--surface-2);
}
.msg.out { border-left: 2px solid var(--brand); }
.msg.in { border-left: 2px solid var(--ok); background: var(--surface); }
.msg-meta { font-size: 10.5px; color: var(--text-3); margin-bottom: 3px; font-weight: 700; }

.table-foot {
  margin-top: 11px; font-size: 12px; color: var(--text-2);
}
.table-foot b { color: var(--text); }

.empty {
  padding: 54px 20px;
  text-align: center;
  color: var(--text-3);
}
.empty svg { width: 34px; height: 34px; opacity: .4; margin-bottom: 11px; }
.empty p { margin: 0 0 4px; font-weight: 700; color: var(--text-2); font-size: 13.5px; }
.empty small { font-size: 12px; }

/* ───────────────────────── modal ───────────────────────── */
.modal-backdrop {
  position: fixed; inset: 0; z-index: 100;
  background: color-mix(in srgb, #04070e 72%, transparent);
  backdrop-filter: blur(3px);
  display: grid; place-items: center;
  padding: 22px;
}
.modal {
  width: min(720px, 100%);
  max-height: 88vh;
  display: flex; flex-direction: column;
  background: var(--bg-elevated);
  border: 1px solid var(--border-strong);
  border-radius: var(--r);
  box-shadow: var(--shadow);
}
.modal-head {
  display: flex; align-items: center; justify-content: space-between;
  padding: 15px 18px;
  border-bottom: 1px solid var(--border);
}
.modal-head h2 { margin: 0; font-size: 15.5px; font-weight: 800; }
.modal-body { padding: 18px; overflow: auto; }
.modal-foot {
  display: flex; justify-content: flex-end; gap: 9px;
  padding: 14px 18px;
  border-top: 1px solid var(--border);
}

.form-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(220px, 1fr)); gap: 13px; }
.field { display: flex; flex-direction: column; gap: 5px; }
.field.wide { grid-column: 1 / -1; }
.field label { font-size: 11px; font-weight: 700; color: var(--text-3); text-transform: uppercase; letter-spacing: .05em; }
.field input, .field select, .field textarea {
  height: 34px;
  padding: 0 10px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--r);
  color: var(--text);
  font: inherit; font-size: 13px;
  width: 100%;
}
.field textarea { height: auto; min-height: 74px; padding: 8px 10px; resize: vertical; line-height: 1.5; }
.field .hint { font-size: 11px; color: var(--text-3); }
.pwd-row { display: flex; gap: 6px; }
.pwd-row input { flex: 1; }

.toast-stack {
  position: fixed; bottom: 18px; right: 18px; z-index: 200;
  display: flex; flex-direction: column; gap: 8px;
}
.toast {
  background: var(--bg-elevated);
  border: 1px solid var(--border-strong);
  border-left: 2px solid var(--ok);
  border-radius: var(--r);
  padding: 10px 15px;
  font-size: 12.5px; font-weight: 600;
  box-shadow: var(--shadow);
  animation: slideIn .18s ease;
  max-width: 340px;
}
.toast.err { border-left-color: var(--brand-warm); }
@keyframes slideIn { from { opacity: 0; transform: translateX(14px); } to { opacity: 1; transform: none; } }

/* ───────────────────────── responsive ───────────────────────── */
@media (max-width: 1080px) {
  .app { grid-template-columns: 68px 1fr; }
  .brand-text, .nav-item span, .nav-item .badge, .theme-label, .site-link { display: none; }
  .sidebar { padding: 18px 10px; align-items: center; }
  .nav-item { justify-content: center; padding: 10px; }
  .brand { justify-content: center; padding: 0; }
  .sidebar-foot { width: 100%; }
  .theme-btn { justify-content: center; }
}
@media (max-width: 720px) {
  .topbar { padding: 16px 15px 14px; }
  .content { padding: 16px 15px 34px; }
  .search-wrap input { width: 100%; }
  .topbar-right { width: 100%; }
  .search-wrap { flex: 1; }
}
