/* miniCRM — единый стиль. Токены светлой темы по design-system/DESIGN-linear.app.md.
   Шрифты системные: внешних CDN нет (правило из CLAUDE.md). */
:root {
  --ink: #08090a; --ink-2: #62666d; --ink-3: #8a8f98;
  --bg: #ffffff; --surface: #f7f8f8; --surface-2: #f0f1f2; --surface-3: #e9eaec;
  --line: #e6e7e9; --line-2: #d7d9dd; --line-soft: #f0f1f2;
  --accent: #5e6ad2; --accent-hover: #828fff; --accent-soft: #eceef7; --accent-ink: #414c9e;
  --ok: #27a644; --ok-bg: #e7f6ea; --ok-ink: #1c7a33;
  --warn: #c99a3d; --warn-bg: #f7f1e6; --warn-ink: #8a5a12;
  --danger: #b42318; --danger-bg: #fdf0f0; --danger-line: #e6d7d7;
  --r-6: 6px; --r-8: 8px; --r-12: 12px;
  --sidebar: 248px;
  /* масштаб интерфейса: 1 — исходный, 2 — вдвое крупнее.
     vh и медиазапрос ниже zoom не пересчитывает, их делим на этот же коэффициент */
  --ui-scale: 1.5;
  --font: -apple-system, "SF Pro Text", system-ui, "Segoe UI", Roboto, sans-serif;
  --mono: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
}

* { box-sizing: border-box; }
html { zoom: var(--ui-scale); }
html, body { margin: 0; padding: 0; }
body {
  font-family: var(--font); font-size: 14px; line-height: 1.5; letter-spacing: -0.05px;
  color: var(--ink); background: var(--bg); -webkit-font-smoothing: antialiased;
}
a { color: var(--accent); text-decoration: none; }
a:hover { color: #4a55bd; text-decoration: underline; }
h1 { font-size: 22px; font-weight: 600; letter-spacing: -0.4px; margin: 0; }
h2 { font-size: 15px; font-weight: 600; letter-spacing: -0.2px; margin: 0; }
h3 { font-size: 13px; font-weight: 600; margin: 0; }
p { margin: 0 0 10px; }
.muted { color: var(--ink-3); font-size: 12.5px; }
.mono { font-family: var(--mono); font-size: 12.5px; }
.error { color: var(--danger); }
.nowrap { white-space: nowrap; }

/* ── каркас ─────────────────────────────────────────────── */
.app { display: flex; min-height: calc(100vh / var(--ui-scale)); }
.sidebar {
  width: var(--sidebar); flex: 0 0 var(--sidebar); position: sticky; top: 0; height: calc(100vh / var(--ui-scale));
  background: var(--surface); border-right: 1px solid var(--line);
  padding: 20px 12px; display: flex; flex-direction: column; gap: 24px;
}
.brand { display: flex; flex-direction: column; gap: 2px; padding: 0 8px; }
.brand-row { display: flex; align-items: center; gap: 8px; }
.brand-mark { width: 20px; height: 20px; border-radius: var(--r-6); background: var(--accent); }
.brand-name { font-size: 15px; font-weight: 600; letter-spacing: -0.3px; color: var(--ink); }
.brand-sub { font-size: 12px; color: var(--ink-3); padding-left: 28px; }
.sidenav, .segments { display: flex; flex-direction: column; gap: 2px; }
.sidenav a, .segments a {
  display: flex; align-items: center; justify-content: space-between; gap: 8px;
  padding: 7px 8px; border-radius: var(--r-6); color: var(--ink-2); font-size: 14px;
}
.sidenav a:hover, .segments a:hover { background: var(--surface-3); color: var(--ink); text-decoration: none; }
.sidenav a.is-active { background: var(--surface-3); color: var(--ink); font-weight: 500; }
.segments a { font-size: 13px; }
.side-title { padding: 0 8px; font-size: 12px; font-weight: 500; letter-spacing: 0.4px;
  color: var(--ink-3); text-transform: uppercase; }
.side-count { font-family: var(--mono); font-size: 11px; color: var(--ink-3); }
.side-foot { margin-top: auto; padding: 12px 8px 0; border-top: 1px solid var(--line);
  display: flex; flex-direction: column; gap: 8px; }
.who { display: flex; align-items: center; gap: 8px; }
.avatar { width: 26px; height: 26px; border-radius: 9999px; background: var(--line);
  display: flex; align-items: center; justify-content: center;
  font-size: 11px; font-weight: 600; color: var(--ink-2); }
.who-lines { display: flex; flex-direction: column; line-height: 1.25; }
.who-lines b { font-size: 13px; font-weight: 400; }
.who-lines span { font-size: 11px; color: var(--ink-3); }

.content { flex: 1; min-width: 0; display: flex; flex-direction: column; }
.page-head {
  padding: 20px 28px 16px; border-bottom: 1px solid var(--line);
  display: flex; align-items: baseline; gap: 12px; flex-wrap: wrap;
}
.page-head .spacer { margin-left: auto; }
.page-body { padding: 20px 28px 100px; }
.stack { display: flex; flex-direction: column; gap: 16px; }
.cols { display: grid; gap: 24px; align-items: start; grid-template-columns: minmax(0, 1.4fr) minmax(280px, 1fr); }
.back { font-size: 13px; color: var(--ink-3); }

/* ── кнопки ─────────────────────────────────────────────── */
.btn, button, .button-link {
  font: inherit; font-size: 14px; padding: 8px 14px; border: 1px solid var(--line-2);
  border-radius: var(--r-8); background: var(--bg); color: var(--ink);
  cursor: pointer; display: inline-flex; align-items: center; gap: 6px; text-decoration: none;
}
.btn:hover, button:hover, .button-link:hover { background: var(--surface-2); text-decoration: none; color: var(--ink); }
.btn-primary, button[type=submit] {
  background: var(--accent); border-color: var(--accent); color: #fff; font-weight: 500;
}
.btn-primary:hover, button[type=submit]:hover { background: var(--accent-hover); border-color: var(--accent-hover); color: #fff; }
.btn-sm { padding: 5px 10px; font-size: 12px; border-radius: var(--r-6); }
button.btn-quiet, button.secondary { background: var(--bg); border-color: var(--line-2); color: var(--ink); font-weight: 400; }
button.btn-quiet:hover, button.secondary:hover { background: var(--surface-2); color: var(--ink); }
.btn-danger, button.danger { background: var(--bg); border-color: var(--danger-line); color: var(--danger); }
.btn-danger:hover, button.danger:hover { background: var(--danger-bg); color: var(--danger); }
.btn-ghost { border: 0; background: transparent; color: var(--ink-3); text-decoration: underline; padding: 4px 6px; font-size: 12px; }
.btn-dashed { border-style: dashed; color: var(--ink-2); }

/* ── поля ───────────────────────────────────────────────── */
input, select, textarea {
  font: inherit; font-size: 14px; color: var(--ink); background: var(--bg);
  border: 1px solid var(--line); border-radius: var(--r-8); padding: 7px 10px;
}
textarea { resize: vertical; line-height: 1.55; }
input[type=checkbox] { width: 14px; height: 14px; padding: 0; accent-color: var(--accent); }
input:focus-visible, select:focus-visible, textarea:focus-visible {
  outline: 2px solid rgba(94, 106, 210, .45); outline-offset: 0; border-color: var(--accent);
}
input[readonly] { background: var(--surface); color: var(--ink-3); border-color: var(--line-soft); }
.field { display: flex; flex-direction: column; gap: 6px; font-size: 12px; color: var(--ink-2); margin: 0; }
.field > input, .field > select, .field > textarea { color: var(--ink); }
.hint { font-size: 11.5px; color: var(--ink-3); }
.field-row { display: grid; grid-template-columns: repeat(auto-fit, minmax(180px, 1fr)); gap: 14px 16px; }
.check { display: inline-flex; align-items: center; gap: 8px; padding: 7px 12px;
  border: 1px solid var(--line); border-radius: var(--r-8); font-size: 13px; color: var(--ink-2); cursor: pointer; }
.check:has(input:checked) { border-color: var(--line-2); color: var(--ink); }
.inline-form { display: inline-flex; gap: 6px; align-items: center; }

/* ── панель фильтров ────────────────────────────────────── */
.filterbar { display: flex; gap: 10px 12px; align-items: flex-end; flex-wrap: wrap;
  padding: 14px 28px; border-bottom: 1px solid var(--line); background: var(--bg); }
.filterbar .field { min-width: 150px; }
.filterbar .field-search { min-width: 240px; flex: 0 1 260px; }
.filterbar .field input, .filterbar .field select { width: 100%; }
.filterbar .suffixed { display: flex; gap: 6px; align-items: center; }
.filterbar .suffixed input { width: 72px; }
.filterbar .checks { display: flex; gap: 8px; flex-wrap: wrap; }
.filterbar .check { white-space: nowrap; }
.filterbar .grow { margin-left: auto; }

/* ── таблицы ────────────────────────────────────────────── */
.table-scroll { overflow-x: auto; }
table { border-collapse: collapse; width: 100%; min-width: 900px; }
th { text-align: left; padding: 10px 8px; border-bottom: 1px solid var(--line);
  font-size: 12px; font-weight: 500; color: var(--ink-3); white-space: nowrap; }
th a { color: inherit; }
td { padding: 11px 8px; border-bottom: 1px solid var(--line-soft); vertical-align: middle; }
td.tight, th.tight { width: 34px; }
td.num, th.num { text-align: right; font-family: var(--mono); font-size: 12.5px; }
tbody tr:hover { background: var(--surface); }
tbody tr:has(input[name=client_ids]:checked) { background: #f6f7fb; }
td .name { font-weight: 500; color: var(--ink); white-space: nowrap; }
td .name:hover { color: var(--accent); text-decoration: none; }
.pager { display: flex; gap: 4px; align-items: center; padding: 16px 8px; font-size: 13px; color: var(--ink-3); }
.pager .pages { display: flex; gap: 4px; margin-left: auto; }
.pager b { padding: 4px 9px; border-radius: var(--r-6); background: var(--surface-2); color: var(--ink); }
.pager a { padding: 4px 9px; border-radius: var(--r-6); color: var(--ink-2); }

/* ── бейджи, чипы, карточки ─────────────────────────────── */
.badge { display: inline-flex; align-items: center; gap: 6px; padding: 2px 8px;
  border-radius: 9999px; font-size: 12px; background: var(--surface-2); color: var(--ink-2); white-space: nowrap; }
.badge::before { content: ""; width: 5px; height: 5px; border-radius: 9999px; background: #a4a8ad; }
.badge[data-state="ok"], .badge[data-state="subscribed"], .badge[data-state="sent"] { background: var(--ok-bg); color: var(--ok-ink); }
.badge[data-state="ok"]::before, .badge[data-state="subscribed"]::before, .badge[data-state="sent"]::before { background: var(--ok); }
.badge[data-state="scheduled"] { background: var(--accent-soft); color: var(--accent-ink); }
.badge[data-state="scheduled"]::before { background: var(--accent); }
.badge[data-state="fail"], .badge[data-state="error"], .badge[data-state="blocked"] { background: var(--danger-bg); color: var(--danger); }
.badge[data-state="fail"]::before, .badge[data-state="error"]::before, .badge[data-state="blocked"]::before { background: #d1554a; }
.badge[data-state="stuck"], .badge[data-state="sending"] { background: var(--warn-bg); color: var(--warn-ink); }
.badge[data-state="stuck"]::before, .badge[data-state="sending"]::before { background: var(--warn); }
.badge-plain { padding: 1px 6px; border: 1px solid var(--line); border-radius: 4px;
  font-size: 11px; color: var(--ink-2); background: transparent; }
.badge-plain::before { display: none; }
.flags { display: flex; gap: 4px; }
.state-row { display: flex; align-items: baseline; gap: 8px; flex-wrap: wrap; }
.chips { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }
.chip { display: inline-flex; align-items: center; gap: 6px; padding: 4px 10px;
  border: 1px solid var(--line-2); border-radius: 9999px; background: var(--bg); font-size: 12px; }
.chip .k { color: var(--ink-2); }
.chip .v { font-weight: 500; }
.card { border: 1px solid var(--line); border-radius: var(--r-12); background: var(--bg); }
.card-soft { background: var(--surface); }
.card-pad { padding: 18px; }
.card-head { padding: 14px 16px; border-bottom: 1px solid var(--line-soft);
  display: flex; align-items: baseline; gap: 10px; }
.card-head .spacer { margin-left: auto; }
.row { display: flex; align-items: center; gap: 12px; padding: 12px 16px; border-bottom: 1px solid var(--line-soft); }
.row:last-child { border-bottom: 0; }
.row .grow { flex: 1; min-width: 0; display: flex; flex-direction: column; gap: 3px; }
.row .title { font-size: 14px; font-weight: 500; color: var(--ink); }
.row .title:hover { color: var(--accent); text-decoration: none; }
.notice { border: 1px solid var(--danger-line); background: #fdf6f6; border-radius: var(--r-12);
  padding: 14px 16px; display: flex; flex-direction: column; gap: 8px; }
.notice b { color: var(--danger); font-size: 13px; }
.metrics { display: grid; grid-template-columns: repeat(auto-fit, minmax(180px, 1fr)); gap: 12px; }
.metric { border: 1px solid var(--line); border-radius: var(--r-12); padding: 16px;
  display: flex; flex-direction: column; gap: 6px; }
.metric .k { font-size: 12px; color: var(--ink-3); }
.metric .v { font-size: 26px; font-weight: 600; letter-spacing: -0.8px; }
.bar { height: 6px; border-radius: 9999px; background: var(--surface-2); overflow: hidden; }
.bar > span { display: block; height: 6px; background: var(--accent); }
.placeholder { border: 1px solid var(--line); border-radius: var(--r-8); background: var(--surface); }

/* ── табы ───────────────────────────────────────────────── */
.tabs { display: flex; gap: 2px; flex-wrap: wrap; }
.tabs button, .tabs a { border: 0; background: transparent; padding: 8px 12px 12px;
  font-size: 14px; color: var(--ink-2); box-shadow: inset 0 -2px 0 transparent; border-radius: 0; }
.tabs button:hover, .tabs a:hover { background: transparent; color: var(--ink); text-decoration: none; }
.tabs .is-active { color: var(--ink); font-weight: 500; box-shadow: inset 0 -2px 0 var(--ink); }
.tabs .count { font-family: var(--mono); font-size: 11px; color: var(--ink-3); }
[data-tab-panel] { display: none; }
[data-tab-panel].is-active { display: block; }

/* ── панель выделения ───────────────────────────────────── */
.selbar {
  display: none; position: fixed; bottom: 24px; z-index: 20;
  left: var(--sidebar); right: 0; width: fit-content; margin: 0 auto;
  max-width: calc(100% - 48px); flex-wrap: wrap; justify-content: center;
  align-items: center; gap: 14px; padding: 10px 12px 10px 18px;
  border-radius: var(--r-12); background: var(--ink); color: #f7f8f8;
  box-shadow: 0 12px 32px rgba(8, 9, 10, .28);
}
#selection:has(input[name=client_ids]:checked) .selbar { display: flex; }
.selbar .sep { width: 1px; height: 20px; background: #34343a; }
.selbar button { background: transparent; border: 0; color: #d0d6e0; font-size: 13px; padding: 6px 10px; border-radius: var(--r-8); }
.selbar button:hover { background: #18191a; color: #fff; }
.selbar button[type=submit] { background: var(--accent); color: #fff; font-weight: 500; padding: 7px 14px; }
.selbar button[type=submit]:hover { background: var(--accent-hover); }
.selbar .count { font-size: 13px; }

/* ── диалог подтверждения ─────────────────────────────── */
#confirm-dialog {
  border: 1px solid var(--line); border-radius: var(--r-12);
  padding: 20px 22px; background: var(--bg); color: var(--ink);
  box-shadow: 0 24px 48px rgba(8, 9, 10, .25);
  max-width: 420px; width: calc(100% - 32px);
}
#confirm-dialog::backdrop { background: rgba(8, 9, 10, .45); }
#confirm-dialog p { margin: 0; font-size: 14px; }
#confirm-dialog .chips { justify-content: flex-end; }

/* ── вход ───────────────────────────────────────────────── */
.auth { flex: 1; display: flex; align-items: center; justify-content: center;
  padding: 40px 20px; background: var(--surface); }
.auth .card { width: 100%; max-width: 340px; padding: 24px; display: flex; flex-direction: column; gap: 16px; }

/* ── адаптив ────────────────────────────────────────────── */
@media (max-width: 1350px) {  /* 900px × --ui-scale */
  .app { flex-direction: column; }
  .sidebar { width: auto; flex: none; position: static; height: auto;
    flex-direction: row; flex-wrap: wrap; align-items: center; gap: 12px; }
  .sidenav { flex-direction: row; flex-wrap: wrap; }
  .side-title, .segments, .side-foot { display: none; }
  .cols { grid-template-columns: minmax(0, 1fr); }
  .page-head, .filterbar, .page-body { padding-left: 16px; padding-right: 16px; }
  .selbar { left: 0; max-width: calc(100% - 32px); }
}
