/*
 * ammanager — токены и компоненты. Tailwind (CDN) отвечает только за раскладку
 * (flex/grid/отступы/брейкпоинты), цвет и типографика живут здесь, на CSS-переменных.
 * Светлая/тёмная тема — по системной настройке, без переключателя.
 * Контраст текста везде >= 4.5:1 (проверено по hex), полос пульса >= 3:1.
 */

:root {
  color-scheme: light dark;

  --bg: #f4f5f7;
  --surface: #ffffff;
  --surface-2: #f0f2f5;
  --line: #e3e6eb;
  --line-strong: #cdd2da;
  --ink: #14181f;
  --ink-2: #465062;
  --ink-3: #5f6878;
  --accent: #1f4fd1;
  --accent-hover: #1a43b3;
  --on-accent: #ffffff;
  --accent-soft: #e8eefc;
  --danger: #b42323;
  --danger-soft: #fbe6e6;
  --shadow: 0 1px 2px rgb(16 24 40 / 0.05), 0 1px 3px rgb(16 24 40 / 0.04);

  /* статусы: текст / подложка / полоса пульса */
  --st-alive: #17692f;      --st-alive-bg: #e5f3e9;      --st-alive-bar: #2f9e52;
  --st-out: #7f4d00;        --st-out-bg: #fbefd8;        --st-out-bar: #b67a0e;
  --st-locked: #9a3a0a;     --st-locked-bg: #fbe7da;     --st-locked-bar: #e0651f;
  --st-banned: #a31c1c;     --st-banned-bg: #fae3e3;     --st-banned-bar: #d33a3a;
  --st-captcha: #5531a8;    --st-captcha-bg: #eee8fa;    --st-captcha-bar: #8a63dd;
  --st-error: #465062;      --st-error-bg: #eceef1;      --st-error-bar: #8a93a1;
  --st-unknown: #5f6878;    --st-unknown-bg: #f0f1f3;    --st-unknown-bar: #d3d7dd;

  --font: -apple-system, BlinkMacSystemFont, "SF Pro Text", "Segoe UI Variable", "Segoe UI",
    Roboto, "Helvetica Neue", Arial, sans-serif;
  --mono: ui-monospace, "SF Mono", "JetBrains Mono", "Cascadia Mono", Menlo, Consolas, monospace;
  --radius: 10px;
  --radius-sm: 7px;
  --control-h: 36px;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0e1116;
    --surface: #161a21;
    --surface-2: #1d222b;
    --line: #262c36;
    --line-strong: #363e4b;
    --ink: #eceff4;
    --ink-2: #b0b8c4;
    --ink-3: #929ba9;
    --accent: #86a8ff;
    --accent-hover: #a2bcff;
    --on-accent: #0b1330;
    --accent-soft: #1b2440;
    --danger: #ff8f8f;
    --danger-soft: #2f1a1c;
    --shadow: none;

    --st-alive: #7bdb95;      --st-alive-bg: #18291f;      --st-alive-bar: #46c06a;
    --st-out: #f2c46b;        --st-out-bg: #2b2414;        --st-out-bar: #e8ae45;
    --st-locked: #ffa27a;     --st-locked-bg: #2e1e17;     --st-locked-bar: #f0864a;
    --st-banned: #ff9393;     --st-banned-bg: #2f1a1c;     --st-banned-bar: #f06464;
    --st-captcha: #bda6ff;    --st-captcha-bg: #221d33;    --st-captcha-bar: #a88bf0;
    --st-error: #b4bcc8;      --st-error-bg: #232831;      --st-error-bar: #7d8796;
    --st-unknown: #9aa3b0;    --st-unknown-bg: #1d2129;    --st-unknown-bar: #353c47;
  }
}

@media (prefers-contrast: more) {
  :root { --line: var(--line-strong); --ink-3: var(--ink-2); }
}

@media (pointer: coarse) {
  :root { --control-h: 44px; }
}

/* ---------------------------------------------------------------- база */

html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  font: 15px/1.5 var(--font);
  -webkit-font-smoothing: antialiased;
}
a { color: inherit; }
.mono { font-family: var(--mono); font-size: 0.92em; }
.num { font-variant-numeric: tabular-nums; }
.text-2 { color: var(--ink-2); }
.text-3 { color: var(--ink-3); }
.link { color: var(--accent); text-decoration: none; }
.link:hover { text-decoration: underline; }
.sr-only {
  position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px;
  overflow: hidden; clip: rect(0, 0, 0, 0); white-space: nowrap; border: 0;
}
:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; border-radius: 4px; }
.icon { display: inline-block; vertical-align: -3px; width: 16px; height: 16px; flex: none; stroke: currentColor; fill: none;
  stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; }

h1.title { font-size: 24px; line-height: 1.25; font-weight: 650; letter-spacing: -0.01em; margin: 0; }
h2.section { font-size: 15px; font-weight: 600; margin: 0; }
.eyebrow { font-size: 12px; font-weight: 600; letter-spacing: 0.04em; text-transform: uppercase; color: var(--ink-3); }

/* ---------------------------------------------------------------- шапка */

.topbar { background: var(--surface); border-bottom: 1px solid var(--line); }
.wordmark { font-weight: 700; letter-spacing: -0.02em; font-size: 16px; text-decoration: none;
  display: inline-flex; align-items: center; gap: 8px; }
.wordmark .beat { width: 22px; height: 14px; stroke: var(--accent); stroke-width: 2.2; fill: none;
  stroke-linecap: round; stroke-linejoin: round; }
.navlink { text-decoration: none; color: var(--ink-2); font-size: 14px; padding: 6px 2px;
  border-bottom: 2px solid transparent; }
.navlink:hover { color: var(--ink); }
.navlink[aria-current="page"] { color: var(--ink); border-bottom-color: var(--accent); }
.dot { width: 8px; height: 8px; border-radius: 50%; display: inline-block; flex: none; }

/* ---------------------------------------------------------------- карточки */

.card { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius);
  box-shadow: var(--shadow); }
.card-head { display: flex; align-items: center; justify-content: space-between; gap: 12px;
  padding: 14px 20px; border-bottom: 1px solid var(--line); }
.card-body { padding: 16px 20px; }

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

.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  min-height: var(--control-h); padding: 0 14px; border-radius: var(--radius-sm);
  font: 500 14px/1 var(--font); white-space: nowrap; text-decoration: none; cursor: pointer;
  border: 1px solid var(--line-strong); background: var(--surface); color: var(--ink);
  transition: background-color 120ms ease, border-color 120ms ease, color 120ms ease;
}
.btn:hover { background: var(--surface-2); }
.btn:disabled, .btn[aria-disabled="true"] { opacity: 0.45; cursor: not-allowed; }
.btn-primary { background: var(--accent); border-color: var(--accent); color: var(--on-accent); }
.btn-primary:hover { background: var(--accent-hover); border-color: var(--accent-hover); }
.btn-quiet { border-color: transparent; background: transparent; color: var(--ink-2); }
.btn-quiet:hover { background: var(--surface-2); color: var(--ink); }
.btn-danger { color: var(--danger); }
.btn-danger:hover { background: var(--danger-soft); }
.btn-sm { min-height: 32px; padding: 0 10px; font-size: 13px; }
@media (pointer: coarse) { .btn-sm { min-height: 40px; } }

/* htmx: пока запрос идёт — крутим иконку и не даём нажать ещё раз */
.htmx-request .spin, .htmx-request.spin { animation: spin 0.9s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }

/* ---------------------------------------------------------------- поля */

.label { display: block; font-size: 14px; font-weight: 550; margin-bottom: 6px; }
.hint { font-size: 13px; color: var(--ink-3); margin-top: 6px; }
.field {
  width: 100%; box-sizing: border-box; min-height: var(--control-h); padding: 7px 11px;
  border: 1px solid var(--line-strong); border-radius: var(--radius-sm);
  background: var(--surface); color: var(--ink); font: 14px/1.4 var(--font);
}
.field::placeholder { color: var(--ink-3); opacity: 1; }
.field:focus { outline: 2px solid var(--accent); outline-offset: -1px; border-color: var(--accent); }
textarea.field { resize: vertical; }
textarea.field.mono, input.field.mono { font-family: var(--mono); font-size: 13px; }
select.field { appearance: none; padding-right: 32px; background-repeat: no-repeat;
  background-position: right 10px center; background-size: 14px;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='%23888' stroke-width='2' stroke-linecap='round'%3E%3Cpath d='m6 9 6 6 6-6'/%3E%3C/svg%3E"); }
.check { display: flex; gap: 10px; align-items: flex-start; font-size: 14px; cursor: pointer; }
.check input { width: 18px; height: 18px; margin: 1px 0 0; accent-color: var(--accent); flex: none; }
.search { position: relative; }
.search .icon { position: absolute; left: 11px; top: 50%; transform: translateY(-50%); color: var(--ink-3); }
.search .field { padding-left: 34px; }
fieldset { border: 0; margin: 0; padding: 0; min-width: 0; }
legend { padding: 0; }

.alert { display: flex; gap: 10px; align-items: flex-start; padding: 12px 14px; border-radius: var(--radius-sm);
  font-size: 14px; background: var(--danger-soft); color: var(--danger); }
.alert-warn { background: var(--st-out-bg); color: var(--st-out); }

/* ---------------------------------------------------------------- статус */

.badge {
  display: inline-flex; align-items: center; gap: 6px; height: 22px; padding: 0 8px;
  border-radius: 6px; font: 600 12px/1 var(--font); letter-spacing: 0.02em; white-space: nowrap;
  color: var(--c); background: var(--b);
}
.badge::before { content: ""; width: 6px; height: 6px; border-radius: 50%; background: currentColor; }
.badge-lg { height: 28px; padding: 0 11px; font-size: 13px; border-radius: 8px; }
.st-ALIVE { --c: var(--st-alive); --b: var(--st-alive-bg); --bar: var(--st-alive-bar); }
.st-LOGGED_OUT { --c: var(--st-out); --b: var(--st-out-bg); --bar: var(--st-out-bar); }
.st-LOCKED { --c: var(--st-locked); --b: var(--st-locked-bg); --bar: var(--st-locked-bar); }
.st-BANNED { --c: var(--st-banned); --b: var(--st-banned-bg); --bar: var(--st-banned-bar); }
.st-CAPTCHA { --c: var(--st-captcha); --b: var(--st-captcha-bg); --bar: var(--st-captcha-bar); }
.st-PROXY_ERROR, .st-ERROR { --c: var(--st-error); --b: var(--st-error-bg); --bar: var(--st-error-bar); }
.st-UNKNOWN { --c: var(--st-unknown); --b: var(--st-unknown-bg); --bar: var(--st-unknown-bar); }

/* фильтр-чипы со счётчиками */
.chip {
  display: inline-flex; align-items: center; gap: 7px; min-height: 32px; padding: 0 11px;
  border-radius: 999px; border: 1px solid var(--line-strong); background: var(--surface);
  font-size: 13px; font-weight: 500; text-decoration: none; color: var(--ink-2); white-space: nowrap;
}
.chip:hover { color: var(--ink); background: var(--surface-2); }
.chip[aria-current="true"] { border-color: var(--ink); color: var(--ink); background: var(--surface-2); }
.chip .dot { background: var(--bar, var(--ink-3)); }
.chip .n { font-variant-numeric: tabular-nums; color: var(--ink); font-weight: 600; }
@media (pointer: coarse) { .chip { min-height: 40px; } }

/* ---------------------------------------------------------------- пульс (подпись продукта) */
/* Последние проверки слева направо, свежая справа. Как кардиограмма: живой аккаунт —
   ровная низкая линия, шум (капча/прокси/ошибка) — выше, инцидент (разлогин/лок/бан) —
   пик во всю высоту. Высота дублирует цвет, чтобы читалось и без него. */
.pulse { display: inline-flex; align-items: flex-end; gap: 2px; height: 22px; }
.pulse i { display: block; width: 4px; height: 40%; border-radius: 2px; background: var(--bar); }
.pulse i.soft { height: 70%; }
.pulse i.bad { height: 100%; }
.pulse i.empty { height: 3px; background: var(--line-strong); }
.pulse-lg { display: flex; width: 100%; height: 44px; gap: 3px; }
.pulse-lg i { flex: 1 1 0; width: auto; min-width: 2px; max-width: 10px; }
@media (max-width: 639px) { .pulse-lg { gap: 2px; } }

/* ---------------------------------------------------------------- таблица аккаунтов */

.acc-table { width: 100%; border-collapse: collapse; font-size: 14px; }
.acc-table th { text-align: left; font-size: 12px; font-weight: 600; color: var(--ink-3);
  padding: 10px 16px; border-bottom: 1px solid var(--line); white-space: nowrap; }
.acc-table td { padding: 12px 16px; border-bottom: 1px solid var(--line); vertical-align: middle; }
.acc-table tbody tr:last-child td { border-bottom: 0; }
.acc-table tbody tr:hover { background: var(--surface-2); }
.acc-table tr.is-off .acc-name, .acc-table tr.is-off .badge { opacity: 0.6; }
.acc-name { font-weight: 600; text-decoration: none; color: var(--ink); }
.acc-name:hover { color: var(--accent); }
.reason { max-width: 32ch; overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
  font-size: 13px; color: var(--ink-3); margin-top: 4px; }

/* телефон: строка таблицы -> карточка, без горизонтального скролла */
@media (max-width: 767px) {
  .acc-table thead { display: none; }
  .acc-table, .acc-table tbody { display: block; }
  .acc-table tbody tr {
    display: grid; grid-template-columns: 1fr auto; gap: 8px 12px; padding: 14px 16px;
    border-bottom: 1px solid var(--line);
    grid-template-areas: "name actions" "status status" "pulse time";
  }
  .acc-table tbody tr:last-child { border-bottom: 0; }
  .acc-table td { display: block; padding: 0; border: 0; }
  .acc-table td.c-name { grid-area: name; }
  .acc-table td.c-status { grid-area: status; }
  .acc-table td.c-pulse { grid-area: pulse; align-self: end; }
  .acc-table td.c-time { grid-area: time; text-align: right; }
  .acc-table td.c-actions { grid-area: actions; }
  .acc-table td.c-empty { grid-column: 1 / -1; }
  .reason { max-width: none; white-space: normal; }
}

/* ---------------------------------------------------------------- списки определений, история */

.facts { display: grid; grid-template-columns: repeat(auto-fit, minmax(130px, 1fr)); gap: 16px; margin: 0; }
.facts dt { font-size: 12px; color: var(--ink-3); margin-bottom: 2px; }
.facts dd { margin: 0; font-weight: 550; font-variant-numeric: tabular-nums; }
.kv { display: grid; grid-template-columns: max-content 1fr; gap: 8px 16px; margin: 0; font-size: 14px; }
.kv dt { color: var(--ink-3); }
.kv dd { margin: 0; min-width: 0; overflow-wrap: anywhere; }

.history { width: 100%; border-collapse: collapse; font-size: 14px; }
.history td { padding: 10px 20px; border-bottom: 1px solid var(--line); vertical-align: top; }
.history tr:last-child td { border-bottom: 0; }
@media (max-width: 639px) {
  .history, .history tbody { display: block; }
  .history tr { display: grid; grid-template-columns: auto 1fr; gap: 4px 12px; padding: 10px 16px;
    border-bottom: 1px solid var(--line); }
  .history td { padding: 0; border: 0; }
  .history td.h-reason { grid-column: 1 / -1; }
}

.secret { font-family: var(--mono); font-size: 13px; padding: 3px 8px; border-radius: 6px;
  background: var(--surface-2); border: 1px solid var(--line); user-select: all; }
.state { font-size: 13px; font-weight: 550; }
.state-ok { color: var(--st-alive); }
.state-warn { color: var(--st-out); }
.state-bad { color: var(--st-banned); }
.state-run { color: var(--accent); }
.notes { white-space: pre-wrap; font-size: 14px; color: var(--ink-2); }

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation-duration: 0.01ms !important; transition-duration: 0.01ms !important; }
}
