/* Resend — оформление админки.
   Написано вручную вместо Tailwind: нет сборки, нет CDN, строгий CSP.
   Тёмная тема по умолчанию — админка чаще открыта фоном рядом с Telegram. */

:root {
  --bg: #10131a;
  --panel: #171b24;
  --panel-2: #1d222d;
  --line: #262c39;
  --text: #e6e9ef;
  --muted: #8b93a7;
  --accent: #4c8dff;
  --accent-dim: #2b4c85;
  --ok: #3fb950;
  --warn: #d29922;
  --bad: #f85149;
  --radius: 10px;
  --mono: ui-monospace, "SF Mono", "Cascadia Code", Consolas, monospace;
}

@media (prefers-color-scheme: light) {
  :root {
    --bg: #f4f6fa;
    --panel: #ffffff;
    --panel-2: #f0f3f8;
    --line: #dde3ed;
    --text: #1b2030;
    --muted: #667085;
    --accent: #2563eb;
    --accent-dim: #bfd3ff;
  }
}

* { box-sizing: border-box; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 15px/1.55 -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  -webkit-font-smoothing: antialiased;
}

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

/* ─── каркас ─────────────────────────────────────────────────────────── */

.layout { display: flex; min-height: 100vh; }

.sidebar {
  width: 216px;
  flex: 0 0 216px;
  background: var(--panel);
  border-right: 1px solid var(--line);
  padding: 18px 12px;
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.brand {
  font-weight: 700;
  font-size: 17px;
  letter-spacing: -0.2px;
  padding: 4px 10px 14px;
  display: flex;
  align-items: center;
  gap: 8px;
}
.brand small { color: var(--muted); font-weight: 400; font-size: 11px; }

.nav-link {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 8px 10px;
  border-radius: 8px;
  color: var(--text);
  font-size: 14px;
}
.nav-link:hover { background: var(--panel-2); text-decoration: none; }
.nav-link.active { background: var(--accent-dim); color: #fff; }
@media (prefers-color-scheme: light) {
  .nav-link.active { color: var(--accent); }
}

.nav-count {
  background: var(--panel-2);
  color: var(--muted);
  border-radius: 20px;
  padding: 1px 8px;
  font-size: 12px;
  font-variant-numeric: tabular-nums;
}
.nav-link.active .nav-count { background: rgba(0,0,0,.25); color: inherit; }
.nav-count.hot { background: var(--warn); color: #1b2030; }

.sidebar-foot { margin-top: auto; padding: 10px; font-size: 12px; color: var(--muted); }

.main { flex: 1; min-width: 0; padding: 24px 28px 60px; max-width: 1400px; }

.page-head {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 16px;
  margin-bottom: 20px;
}
h1 { font-size: 22px; margin: 0 0 4px; letter-spacing: -0.3px; }
h2 { font-size: 16px; margin: 0 0 12px; }
h3 { font-size: 14px; margin: 0 0 8px; color: var(--muted); font-weight: 600; }
.subtitle { color: var(--muted); font-size: 13px; margin: 0; }

/* ─── карточки и сетки ───────────────────────────────────────────────── */

.card {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 16px;
}
.card + .card { margin-top: 14px; }
.card-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 12px;
  gap: 12px;
}

.grid { display: grid; gap: 14px; }
.grid-4 { grid-template-columns: repeat(auto-fit, minmax(180px, 1fr)); }
.grid-3 { grid-template-columns: repeat(auto-fit, minmax(260px, 1fr)); }
.grid-2 { grid-template-columns: repeat(auto-fit, minmax(320px, 1fr)); }
.split { display: grid; grid-template-columns: 1fr 1fr; gap: 14px; }
@media (max-width: 900px) { .split { grid-template-columns: 1fr; } }

.stat { }
.stat-value { font-size: 30px; font-weight: 650; letter-spacing: -1px; font-variant-numeric: tabular-nums; }
.stat-label { color: var(--muted); font-size: 13px; margin-top: 2px; }
.stat.ok .stat-value { color: var(--ok); }
.stat.warn .stat-value { color: var(--warn); }
.stat.bad .stat-value { color: var(--bad); }

/* ─── бейджи и кнопки ────────────────────────────────────────────────── */

.badge {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  padding: 2px 9px;
  border-radius: 20px;
  font-size: 12px;
  font-weight: 500;
  background: var(--panel-2);
  color: var(--muted);
  white-space: nowrap;
}
.badge.ok { background: rgba(63,185,80,.16); color: var(--ok); }
.badge.warn { background: rgba(210,153,34,.16); color: var(--warn); }
.badge.bad { background: rgba(248,81,73,.16); color: var(--bad); }
.badge.info { background: rgba(76,141,255,.16); color: var(--accent); }

.dot { width: 7px; height: 7px; border-radius: 50%; background: currentColor; }

.btn {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 7px 14px;
  border-radius: 8px;
  border: 1px solid var(--line);
  background: var(--panel-2);
  color: var(--text);
  font-size: 14px;
  font-family: inherit;
  cursor: pointer;
  white-space: nowrap;
}
.btn:hover { border-color: var(--accent); text-decoration: none; }
.btn:disabled { opacity: .45; cursor: not-allowed; }
.btn-primary { background: var(--accent); border-color: var(--accent); color: #fff; }
.btn-primary:hover { filter: brightness(1.1); }
.btn-danger { color: var(--bad); border-color: rgba(248,81,73,.4); }
.btn-danger:hover { background: rgba(248,81,73,.12); border-color: var(--bad); }
.btn-sm { padding: 4px 10px; font-size: 13px; }
.btn-block { width: 100%; justify-content: center; }

.actions { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; }

/* ─── формы ──────────────────────────────────────────────────────────── */

label { display: block; font-size: 13px; color: var(--muted); margin-bottom: 5px; }

input[type=text], input[type=password], input[type=number], input[type=url],
select, textarea {
  width: 100%;
  padding: 8px 11px;
  border-radius: 8px;
  border: 1px solid var(--line);
  background: var(--bg);
  color: var(--text);
  font: inherit;
  font-size: 14px;
}
textarea { resize: vertical; min-height: 76px; font-family: var(--mono); font-size: 13px; }
input:focus, select:focus, textarea:focus {
  outline: none;
  border-color: var(--accent);
  box-shadow: 0 0 0 3px rgba(76,141,255,.15);
}
select[multiple] { min-height: 130px; }

.field { margin-bottom: 14px; }
.field-row { display: flex; gap: 12px; }
.field-row > * { flex: 1; }
.hint { font-size: 12px; color: var(--muted); margin-top: 4px; }

.check { display: flex; align-items: flex-start; gap: 9px; margin-bottom: 10px; }
.check input { width: 16px; height: 16px; margin: 2px 0 0; flex: 0 0 auto; accent-color: var(--accent); }
.check label { margin: 0; color: var(--text); font-size: 14px; }
.check .hint { margin-top: 2px; }

.honeypot { position: absolute; left: -9999px; width: 1px; height: 1px; overflow: hidden; }

/* ─── таблицы ────────────────────────────────────────────────────────── */

table { width: 100%; border-collapse: collapse; font-size: 14px; }
th {
  text-align: left;
  font-weight: 500;
  color: var(--muted);
  font-size: 12px;
  text-transform: uppercase;
  letter-spacing: .4px;
  padding: 0 12px 8px;
  border-bottom: 1px solid var(--line);
}
td { padding: 10px 12px; border-bottom: 1px solid var(--line); vertical-align: top; }
tr:last-child td { border-bottom: none; }
tbody tr:hover { background: var(--panel-2); }
.num { font-variant-numeric: tabular-nums; text-align: right; }
.mono { font-family: var(--mono); font-size: 12.5px; }

/* ─── сообщения ──────────────────────────────────────────────────────── */

.alert {
  padding: 11px 14px;
  border-radius: 8px;
  margin-bottom: 16px;
  font-size: 14px;
  border: 1px solid;
}
.alert.error { background: rgba(248,81,73,.1); border-color: rgba(248,81,73,.35); color: var(--bad); }
.alert.ok { background: rgba(63,185,80,.1); border-color: rgba(63,185,80,.35); color: var(--ok); }
.alert.warn { background: rgba(210,153,34,.1); border-color: rgba(210,153,34,.35); color: var(--warn); }
.alert.info { background: rgba(76,141,255,.1); border-color: rgba(76,141,255,.35); }

.empty { text-align: center; padding: 44px 20px; color: var(--muted); }
.empty-title { font-size: 15px; color: var(--text); margin-bottom: 6px; }

/* ─── лента постов ───────────────────────────────────────────────────── */

.post { border: 1px solid var(--line); border-radius: var(--radius); background: var(--panel); margin-bottom: 14px; }
.post-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 11px 16px;
  border-bottom: 1px solid var(--line);
  flex-wrap: wrap;
}
.post-meta { display: flex; align-items: center; gap: 10px; font-size: 13px; color: var(--muted); flex-wrap: wrap; }
.post-body { display: grid; grid-template-columns: 1fr 1fr; }
@media (max-width: 900px) { .post-body { grid-template-columns: 1fr; } }
.post-side { padding: 14px 16px; min-width: 0; }
.post-side + .post-side { border-left: 1px solid var(--line); }
@media (max-width: 900px) { .post-side + .post-side { border-left: none; border-top: 1px solid var(--line); } }
.post-side h3 { display: flex; justify-content: space-between; }

.tg-text {
  font-size: 14px;
  line-height: 1.5;
  word-wrap: break-word;
  overflow-wrap: anywhere;
  max-height: 320px;
  overflow-y: auto;
}
.tg-text blockquote {
  margin: 6px 0;
  padding: 2px 0 2px 10px;
  border-left: 2px solid var(--accent-dim);
  color: var(--muted);
}
.tg-text code { background: var(--panel-2); padding: 1px 5px; border-radius: 4px; font-family: var(--mono); font-size: 12.5px; }
.tg-text pre { background: var(--panel-2); padding: 9px; border-radius: 6px; overflow-x: auto; font-size: 12.5px; }
.tg-text .spoiler { background: var(--muted); border-radius: 3px; color: transparent; }
.tg-text .spoiler:hover { background: transparent; color: inherit; }

.thumbs { display: flex; gap: 6px; flex-wrap: wrap; margin-top: 10px; }
.thumb {
  width: 62px; height: 62px;
  border-radius: 6px;
  object-fit: cover;
  border: 1px solid var(--line);
  background: var(--panel-2);
}
.thumb-stub {
  width: 62px; height: 62px;
  border-radius: 6px;
  border: 1px solid var(--line);
  background: var(--panel-2);
  display: flex; align-items: center; justify-content: center;
  font-size: 10px; color: var(--muted); text-align: center; padding: 3px;
}

.verdict { font-size: 13px; margin-top: 10px; padding: 8px 11px; border-radius: 7px; background: var(--panel-2); }

/* ─── редактор маршрута ──────────────────────────────────────────────── */

.rule-item {
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel-2);
  margin-bottom: 10px;
}
.rule-head {
  display: flex; align-items: center; gap: 10px;
  padding: 9px 12px;
  cursor: pointer;
}
.rule-head .grab { color: var(--muted); cursor: grab; font-size: 15px; }
.rule-title { flex: 1; font-size: 14px; }
.rule-body { padding: 4px 12px 12px; border-top: 1px solid var(--line); }

.preview-pane { position: sticky; top: 24px; }

/* ─── вход ───────────────────────────────────────────────────────────── */

.login-wrap { display: flex; align-items: center; justify-content: center; min-height: 100vh; padding: 20px; }
.login-card { width: 100%; max-width: 380px; }
.login-card .brand { justify-content: center; padding-bottom: 20px; font-size: 20px; }

/* ─── прочее ─────────────────────────────────────────────────────────── */

.row { display: flex; align-items: center; gap: 10px; }
.spread { display: flex; align-items: center; justify-content: space-between; gap: 12px; }
.muted { color: var(--muted); }
.small { font-size: 13px; }
.tiny { font-size: 12px; }
.nowrap { white-space: nowrap; }
.truncate { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.mt { margin-top: 14px; }
.mb { margin-bottom: 14px; }
.divider { height: 1px; background: var(--line); margin: 16px 0; }

.filters-bar { display: flex; gap: 10px; flex-wrap: wrap; align-items: flex-end; margin-bottom: 16px; }
.filters-bar .field { margin: 0; min-width: 150px; }

.pager { display: flex; gap: 8px; justify-content: center; margin-top: 18px; }

.htmx-request { opacity: .55; transition: opacity .15s; }

kbd {
  font-family: var(--mono); font-size: 11px;
  border: 1px solid var(--line); border-bottom-width: 2px;
  border-radius: 4px; padding: 1px 5px; background: var(--panel-2);
}
