:root {
  --bg: #0f1115;
  --surface: #181b22;
  --border: #2a2f3a;
  --text: #e6e8ec;
  --muted: #8b93a3;
  --accent: #d11a2a;
  --radius: 10px;
}
* { box-sizing: border-box; }
body {
  margin: 0;
  font-family: -apple-system, Segoe UI, Roboto, Helvetica, Arial, sans-serif;
  background: var(--bg);
  color: var(--text);
}
.muted { color: var(--muted); }
.small { font-size: 12px; }
.form .small { display: block; margin-top: 4px; }
.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 20px;
}

/* --- auth --- */
.auth { min-height: 100vh; display: grid; place-items: center; padding: 24px; }
.auth-card { width: 100%; max-width: 360px; }
.auth-card h1 { margin: 0 0 4px; font-size: 22px; }
.auth-card label { display: block; margin: 14px 0 0; font-size: 13px; color: var(--muted); }
.auth-card input {
  width: 100%; margin-top: 6px; padding: 10px 12px;
  background: var(--bg); border: 1px solid var(--border); border-radius: 8px; color: var(--text);
}
.auth-card button {
  width: 100%; margin-top: 18px; padding: 11px; border: 0; border-radius: 8px;
  background: var(--accent); color: #fff; font-weight: 600; cursor: pointer;
}
.alert { margin-top: 14px; padding: 10px 12px; border-radius: 8px; background: #3a1416; color: #ffb3b8; font-size: 13px; }

/* --- dashboard --- */
.topbar {
  display: flex; align-items: center; gap: 24px;
  padding: 12px 24px; border-bottom: 1px solid var(--border); background: var(--surface);
}
.brand { font-weight: 700; }
.badge { font-size: 11px; color: var(--muted); border: 1px solid var(--border); border-radius: 6px; padding: 1px 6px; }
.nav { display: flex; gap: 18px; }
.nav-link { color: var(--muted); text-decoration: none; font-size: 14px; }
.nav-link:hover { color: var(--text); }
.topbar-right { margin-left: auto; display: flex; align-items: center; gap: 14px; }
.btn-link { color: var(--accent); text-decoration: none; font-size: 14px; }
.content { max-width: 1100px; margin: 0 auto; padding: 24px; display: grid; gap: 16px; }
.section h2 { margin: 0 0 6px; font-size: 17px; }
.nav-link.active { color: var(--text); font-weight: 600; }

/* --- dashboard tiles --- */
.tiles { display: grid; grid-template-columns: repeat(auto-fill, minmax(160px, 1fr)); gap: 14px; margin-bottom: 16px; }
.tile { text-decoration: none; color: var(--text); padding: 18px 20px; transition: border-color .15s; }
.tile:hover { border-color: var(--muted); }
.tile-num { font-size: 30px; font-weight: 700; line-height: 1; }
.tile-cap { margin-top: 6px; font-size: 13px; color: var(--muted); }
.tile-ok .tile-num { color: #7ee2a0; }
.tile-bad .tile-num { color: #ffb3b8; }
.bal-row { display: flex; justify-content: space-between; align-items: center; padding: 6px 0; border-bottom: 1px solid var(--border); font-size: 14px; }
.bal-row:last-child { border-bottom: 0; }

/* --- buttons --- */
.btn {
  display: inline-block; padding: 8px 14px; border: 0; border-radius: 8px;
  background: var(--accent); color: #fff; font-size: 14px; font-weight: 600;
  text-decoration: none; cursor: pointer;
}
.btn-sm { padding: 5px 10px; font-size: 13px; }
.btn-ghost { background: transparent; border: 1px solid var(--border); color: var(--text); font-weight: 500; }
.btn-danger { color: #f87171; background: none; border: 0; cursor: pointer; font-size: 14px; }

/* --- section head --- */
.section-head { display: flex; align-items: center; justify-content: space-between; margin-bottom: 12px; gap: 12px; }
.section-head h2 { margin: 0; }
.head-actions { display: flex; align-items: center; gap: 12px; flex-wrap: wrap; }

/* --- table --- */
.tbl { width: 100%; border-collapse: collapse; font-size: 14px; }
.tbl th { text-align: left; color: var(--muted); font-weight: 500; font-size: 12px; padding: 8px 10px; border-bottom: 1px solid var(--border); }
.tbl td { padding: 10px; border-bottom: 1px solid var(--border); vertical-align: middle; }
.tbl .actions { white-space: nowrap; text-align: right; }
.tbl .actions .btn-link { margin-left: 10px; }
.mono { font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace; font-size: 12px; color: var(--muted); }
.test-cell { margin-left: 8px; }

/* --- pills --- */
.pill { display: inline-block; padding: 2px 8px; border-radius: 999px; font-size: 12px; border: 1px solid var(--border); color: var(--muted); }
.pill-ok { background: #14321c; border-color: #1f5130; color: #7ee2a0; }
.pill-bad { background: #3a1416; border-color: #5b1f24; color: #ffb3b8; }
.pill-muted { color: var(--muted); }

/* --- form --- */
.form label { display: block; margin: 14px 0 0; font-size: 13px; color: var(--muted); }
.form input, .form select {
  width: 100%; margin-top: 6px; padding: 10px 12px;
  background: var(--bg); border: 1px solid var(--border); border-radius: 8px; color: var(--text);
}
.form .grid2 { display: grid; grid-template-columns: 1fr 1fr; gap: 14px; }
.form-actions { margin-top: 20px; display: flex; align-items: center; gap: 14px; }

/* htmx indicator */
.test-cell.htmx-request::after { content: "⏳"; }

/* --- mappings / catalog --- */
.filter { margin-bottom: 14px; }
.inline { display: inline-flex; align-items: center; gap: 8px; font-size: 13px; color: var(--muted); }
.inline select, .form .check { width: auto; }
.sep { border: 0; border-top: 1px solid var(--border); margin: 20px 0 8px; }
.sub { font-size: 14px; color: var(--muted); margin: 6px 0; }
.catalog-box { margin-top: 8px; }
.catalog-box:empty { margin-top: 0; }
.cat-list { list-style: none; margin: 0; padding: 0; display: grid; gap: 6px; max-height: 320px; overflow-y: auto; }
.cat-item { display: flex; align-items: center; gap: 12px; padding: 8px 10px; border: 1px solid var(--border); border-radius: 8px; }
.cat-item:hover { border-color: var(--muted); }
.cat-img { width: 48px; height: 48px; min-width: 48px; object-fit: cover; border-radius: 6px; background: var(--bg); }
.cat-name { flex: 1; min-width: 0; font-size: 14px; }
.pkg { margin-top: 10px; padding: 12px; border: 1px solid var(--border); border-radius: 8px; }
.pkg-name { font-weight: 600; margin-bottom: 8px; font-size: 14px; }
.regions { display: grid; grid-template-columns: repeat(auto-fill, minmax(200px, 1fr)); gap: 4px; }
.region-row { display: flex; align-items: center; gap: 8px; padding: 6px 8px; border-radius: 6px; cursor: pointer; font-size: 13px; }
.region-row:hover { background: var(--bg); }
.region-row input { width: auto; margin: 0; }
.region-row .region-name { font-weight: 500; }
.flag { width: 20px; height: 14px; min-width: 20px; object-fit: cover; border-radius: 2px; }
.picked { margin-top: 16px; font-size: 14px; padding: 10px 12px; background: var(--bg); border: 1px solid var(--border); border-radius: 8px; }
.check { display: flex; align-items: center; gap: 8px; margin-top: 14px; color: var(--text); }
.check input { width: auto; }

/* --- orders detail --- */
.kv { display: grid; grid-template-columns: 160px 1fr; gap: 6px 14px; font-size: 14px; margin-top: 10px; }
.kv .k { color: var(--muted); }
.kv .v { word-break: break-word; }
.timeline { list-style: none; margin: 8px 0 0; padding: 0; display: grid; gap: 6px; }
.timeline li { display: flex; align-items: baseline; gap: 10px; flex-wrap: wrap; font-size: 13px; padding: 6px 8px; border-left: 2px solid var(--border); }
.order-actions { display: flex; gap: 10px; margin-top: 16px; flex-wrap: wrap; }
.order-actions form { display: inline; }
.nav-badge { margin-left: 6px; font-size: 11px; padding: 1px 6px; }
.filter { display: flex; gap: 18px; margin-bottom: 14px; }

/* --- test link (mappings) --- */
.test-link { margin-top: 6px; display: grid; gap: 4px; }
.test-link a { font-size: 13px; }
.test-link input { width: 100%; padding: 5px 7px; background: var(--bg); border: 1px solid var(--border); border-radius: 6px; color: var(--muted); font-size: 11px; }

/* --- buyer redeem landing --- */
.redeem { min-height: 100vh; display: grid; place-items: center; padding: 24px; }
.redeem-card { width: 100%; max-width: 460px; text-align: center; }
.redeem-card h1 { font-size: 20px; margin: 0 0 4px; }
.redeem-card .game { font-size: 15px; color: var(--text); margin: 0 0 16px; }
.redeem-card p { font-size: 14px; line-height: 1.5; text-align: left; }
.redeem-form { display: flex; flex-direction: column; gap: 10px; margin: 16px 0 8px; }
.redeem-form input { padding: 12px 14px; background: var(--bg); border: 1px solid var(--border); border-radius: 8px; color: var(--text); font-size: 14px; }
.redeem-form .btn { padding: 12px; font-size: 15px; }
.redeem .hint { margin: 12px 0; text-align: left; }
.redeem .hint summary { cursor: pointer; color: var(--accent); font-size: 13px; }
.redeem .small { font-size: 12px; }
.status { font-size: 18px; font-weight: 700; margin: 12px 0; }
.status-ok { color: #7ee2a0; }
.status-wait { color: var(--text); }
.status-err { color: #ffb3b8; }

/* --- webhook copy box --- */
.webhook-box { margin-top: 18px; padding-top: 16px; border-top: 1px solid var(--border); }
.webhook-box label { display: block; font-size: 13px; margin-bottom: 6px; }
.copy-row { display: flex; gap: 8px; }
.copy-row input { flex: 1; padding: 9px 11px; background: var(--bg); border: 1px solid var(--border); border-radius: 8px; color: var(--text); font-size: 12px; }
.copy-row .btn { white-space: nowrap; }

/* --- codevault additions --- */
.cards-row { display: flex; gap: 14px; flex-wrap: wrap; margin: 14px 0; }
.stat { min-width: 180px; text-align: center; }
.stat-value { font-size: 32px; font-weight: 700; }
.stat-label { font-size: 13px; color: var(--muted); margin-top: 4px; }
.filter-row { margin: 10px 0; display: flex; gap: 10px; }
.revealed { background: var(--bg); border: 1px solid var(--border); border-radius: 6px; padding: 3px 8px; user-select: all; }
tr.unread { font-weight: 600; }
button.danger { background: #8b2635; }
.qr-box { background: #fff; border-radius: 10px; padding: 12px; display: inline-block; margin: 8px 0; }
.qr-box svg { display: block; width: 220px; height: 220px; }

/* --- codevault: единый вид кнопок/ссылок/полей в контенте админки --- */
.content a { color: var(--accent); }
.content a:visited { color: var(--accent); }
.stat-label a, .stat-label a:visited { color: var(--muted); text-decoration: underline; }
.stat-label a:hover { color: var(--text); }

.content button, .card button {
  padding: 8px 14px; border: 0; border-radius: 8px;
  background: var(--accent); color: #fff;
  font-family: inherit; font-size: 14px; font-weight: 600; cursor: pointer;
}
.content button:hover, .card button:hover { filter: brightness(1.12); }
.content button:disabled { opacity: .5; cursor: default; }

/* кнопки-ссылки (в т.ч. <button class="btn-link"> в формах) — без плашки */
button.btn-link, .content button.btn-link, .card button.btn-link {
  background: none; border: 0; padding: 0; margin: 0;
  color: var(--accent); font-weight: 500; font-size: 14px; cursor: pointer;
}
button.btn-link:hover { filter: none; text-decoration: underline; }

/* опасные действия — приглушённый тёмно-красный (после генерик-правила!) */
.content button.danger, .card button.danger { background: #8b2635; }

/* поля форм в контенте */
.content input[type="text"], .content input[type="password"], .content input[type="number"],
.content input[type="date"], .content select, .content input[type="file"] {
  background: var(--bg); border: 1px solid var(--border); border-radius: 8px;
  color: var(--text); padding: 8px 10px; font-family: inherit; font-size: 14px;
}
.card label { display: block; margin: 10px 0 0; font-size: 13px; color: var(--muted); }
.card label input, .card label select { display: block; margin-top: 6px; width: 100%; max-width: 420px; }
.card form > button[type="submit"] { margin-top: 14px; }
.card label input[type="checkbox"] { display: inline; width: auto; margin-right: 6px; }
details > summary { cursor: pointer; }
details > summary.btn-link { display: inline; color: var(--accent); }

/* --- формы-карточки: строго столбцом --- */
form.card, .card form { display: grid; gap: 2px; justify-items: start; max-width: 520px; }
form.card label, .card form label { display: block; width: 100%; margin: 10px 0 0; font-size: 13px; color: var(--muted); }
form.card label input:not([type="checkbox"]), form.card label select,
.card form label input:not([type="checkbox"]), .card form label select {
  display: block; margin-top: 6px; width: 100%;
}
form.card button[type="submit"], .card form button[type="submit"] { margin-top: 16px; }
form.card label input[type="checkbox"], .card form label input[type="checkbox"] {
  display: inline-block; width: auto; margin-right: 6px; vertical-align: middle;
}

/* --- таблицы админки (.table) --- */
.table {
  width: 100%; border-collapse: separate; border-spacing: 0;
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius);
  overflow: hidden; font-size: 14px;
}
.table th, .table td {
  text-align: left; vertical-align: middle;
  padding: 10px 14px; border-bottom: 1px solid var(--border);
}
.table thead th {
  color: var(--muted); font-size: 12px; font-weight: 600;
  text-transform: uppercase; letter-spacing: .04em;
  background: rgba(255, 255, 255, .02);
}
.table tbody tr:last-child td { border-bottom: 0; }
.table tbody tr:hover td { background: rgba(255, 255, 255, .025); }
.table td form { display: inline; }

/* --- проверка API площадки --- */
.check-result { display: grid; gap: 4px; padding: 8px 0; font-size: 13px; }
.check-row.check-ok { color: #7ee2a0; }
.check-row.check-fail { color: #ffb3b8; }
.check-tr td { border-bottom: 0 !important; }
.htmx-indicator-slot.htmx-request::after { content: "проверяю…"; color: var(--muted); font-size: 13px; }

/* --- ссылка-кнопка ---------------------------------------------------------
   `.content a { color: var(--accent) }` перебивало цвет `.btn` (специфичность
   выше на один элемент), и текст становился красным на красном фоне: кнопка
   выглядела пустой. Возвращаем контрастный цвет именно ссылкам-кнопкам. */
.content a.btn, .content a.btn:visited,
.card a.btn, .card a.btn:visited { color: #fff; }
.content a.btn-ghost, .content a.btn-ghost:visited { color: var(--text); }

/* --- переключатель админок -------------------------------------------------
   Узкая полоса слева с иконками сервисов. Разворачивается при наведении,
   чтобы были видны названия, но место в раскрытом виде не занимает: ширина
   тела страницы считается по свёрнутому состоянию. */
:root { --apps-w: 56px; }

.apps {
  position: fixed; top: 0; left: 0; bottom: 0; width: var(--apps-w);
  background: #0b0d11; border-right: 1px solid var(--border);
  display: flex; flex-direction: column; gap: 6px; padding: 10px 8px;
  z-index: 20; overflow: hidden; transition: width .15s ease;
}
.apps:hover { width: 232px; box-shadow: 4px 0 18px rgba(0, 0, 0, .45); }

.apps-item {
  display: flex; align-items: center; gap: 12px;
  height: 40px; padding: 0 8px; border-radius: 10px;
  text-decoration: none; color: var(--muted); white-space: nowrap;
  border: 1px solid transparent;
}
.apps-item:hover { background: var(--surface); color: var(--text); }

.apps-icon { font-size: 20px; line-height: 1; flex: 0 0 24px; text-align: center; }
.apps-name { font-size: 14px; opacity: 0; transition: opacity .12s ease; }
.apps:hover .apps-name { opacity: 1; }

/* Текущий сервис: подсвечен и никуда не ведёт по смыслу */
.apps-current { background: var(--surface); color: var(--text); border-color: var(--accent); }

/* Освобождаем место под полосу отступом на body, а не margin-left у .content:
   тот перебивал `margin: 0 auto` и приклеивал всю страницу к левому краю.
   Класс ставит admin_base.html — на странице логина полосы нет. */
body.has-rail { padding-left: var(--apps-w); }

@media (max-width: 720px) {
  :root { --apps-w: 44px; }
  .apps { padding: 8px 6px; }
  .apps-icon { font-size: 18px; }
}

/* --- выбор вариантов номиналов (F14) --- */
.variants-box { width: 100%; }
.variants-list { display: flex; flex-wrap: wrap; gap: 6px; margin: 6px 0; }
button.variant-pick {
  background: var(--bg); border: 1px solid var(--border); color: var(--text);
  font-weight: 400; padding: 6px 10px; border-radius: 8px; font-size: 13px;
}
button.variant-pick:hover { border-color: var(--accent); filter: none; }
button.variant-created { border-color: #7ee2a0; }

/* --- топбар: 17 пунктов меню не влезают в 1400px — переносим строки, не даём горизонтальной прокрутке --- */
.topbar { flex-wrap: wrap; row-gap: 6px; padding: 10px 24px; }
.nav { flex-wrap: wrap; gap: 6px 16px; }
.nav-link { white-space: nowrap; }
.topbar-right { flex-shrink: 0; }
.brand { white-space: nowrap; }
html, body { overflow-x: hidden; }
/* широкие таблицы прокручиваются внутри себя, а не двигают страницу */
.content { max-width: 1240px; }
.table-wrap { overflow-x: auto; }

/* --- косметика из ревью вёрстки --- */
/* input[type=file]: браузерная белая кнопка → в тон темы */
.content input[type="file"] { padding: 6px 8px; color: var(--muted); }
.content input[type="file"]::file-selector-button {
  background: var(--accent); color: #fff; border: 0; border-radius: 6px;
  padding: 6px 12px; margin-right: 10px; font-family: inherit; font-size: 13px; cursor: pointer;
}
/* кнопка-ссылка внутри формы-столбца — с отступом от полей */
form.card > button.btn-link, .card form > button.btn-link { margin: 6px 0 2px; }
/* пояснения под таблицами-шаблонами — читаемый размер */
.card p.muted { font-size: 13px; line-height: 1.5; }

/* --- подбор по каталогу поставщика (форма связки) --- */
.card form fieldset.catalog-picker {
  width: 100%; margin: 14px 0 0; padding: 10px 12px 12px;
  border: 1px solid var(--border); border-radius: 8px;
}
.catalog-picker legend { padding: 0 6px; font-size: 13px; color: var(--muted); }
.catalog-picker .hint { margin: 4px 0 8px; font-size: 13px; line-height: 1.5; color: var(--muted); }
.catalog-picker .row { display: flex; flex-wrap: wrap; align-items: center; gap: 8px; }
.catalog-picker .row input[type="search"] {
  flex: 1 1 200px; min-width: 160px; margin: 0;
  background: var(--bg); border: 1px solid var(--border); border-radius: 8px;
  color: var(--text); padding: 8px 10px; font-family: inherit; font-size: 14px;
}
.card button.btn-secondary { background: transparent; color: var(--text); border: 1px solid var(--border); font-weight: 500; }
.catalog-picker label { margin-top: 10px; }
.catalog-picker label select { max-width: 100%; }
.catalog-picker .table { margin-top: 10px; font-size: 13px; }
.catalog-picker .table th, .catalog-picker .table td { padding: 6px 10px; }
.catalog-picker .table-wrap { max-height: 320px; overflow: auto; }
.catalog-picker .alert { margin-top: 10px; }
.htmx-indicator { display: none; font-size: 13px; }
.htmx-request .htmx-indicator, .htmx-request.htmx-indicator { display: inline; }
.catalog-picker .table tbody tr.picked td { background: rgba(126, 226, 160, .08); }

/* --- спиннер ожидания на странице выдачи (on-demand) --- */
.spinner {
  display: inline-block; width: 18px; height: 18px; margin-right: 10px; vertical-align: -3px;
  border: 3px solid rgba(255, 255, 255, .18); border-top-color: var(--accent); border-radius: 50%;
  animation: spin .8s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }
@media (prefers-reduced-motion: reduce) { .spinner { animation-duration: 2s; } }

/* поле поиска над длинным select'ом */
.card label input.select-search, form.card label input.select-search {
  margin: 6px 0 4px; font-size: 13px; padding: 6px 10px;
}

/* --- здоровье связок (сверка маппинга с площадкой) --- */
.health-ok { color: #7ee2a0; }
.health-warn { color: #ffd479; }
.health-crit { color: #ffb3b8; }
.health-info { color: var(--muted); }
