:root {
  --bg: #0b0b0e;
  --surface: #131317;
  --surface-2: #1a1a20;
  --surface-3: #22222a;
  --line: #26262e;
  --text: #f2f1ec;
  --muted: #9a99a3;
  --accent: #d9b45c;
  --accent-ink: #1b1608;
  --ok: #3ec27e;
  --info: #6aa8ff;
  --warn: #f0a24a;
  --err: #ff6b6b;
  --radius: 14px;
  --mono: ui-monospace, "SFMono-Regular", Menlo, Consolas, "Liberation Mono", monospace;
}

* { box-sizing: border-box; }
html, body { margin: 0; }
body {
  min-height: 100vh;
  background: var(--bg);
  color: var(--text);
  font: 15px/1.5 system-ui, -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; }
h1, h2 { margin: 0; letter-spacing: -.01em; }
h1 { font-size: 22px; }
h2 { font-size: 17px; margin-bottom: 12px; }

.mono { font-family: var(--mono); font-size: 13px; }
.muted { color: var(--muted); }
.small { font-size: 13px; }
.nowrap { white-space: nowrap; }
.break { word-break: break-all; }
.ellipsis { max-width: 260px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

/* ---------- шапка ---------- */
.top { border-bottom: 1px solid var(--line); background: rgba(19, 19, 23, .9); position: sticky; top: 0; z-index: 5; }
.top-in { max-width: 1180px; margin: 0 auto; padding: 0 16px; height: 56px; display: flex; align-items: center; gap: 24px; }
.brand { display: flex; align-items: center; gap: 10px; color: var(--text); font-weight: 700; font-size: 16px; }
.brand:hover { text-decoration: none; }
.logo {
  display: inline-grid; place-items: center;
  width: 30px; height: 30px; border-radius: 9px;
  background: var(--surface-2); border: 1px solid var(--line);
  color: var(--accent); font-size: 14px;
}
.top nav { display: flex; gap: 4px; }
.top nav a { color: var(--muted); padding: 6px 12px; border-radius: 9px; }
.top nav a:hover { color: var(--text); text-decoration: none; }
.top nav a.on { color: var(--text); background: var(--surface-2); }
.logout { margin-left: auto; }
.link { background: none; border: 0; color: var(--muted); font: inherit; cursor: pointer; padding: 6px 0; }
.link:hover { color: var(--text); }

/* ---------- раскладка ---------- */
.wrap { max-width: 1180px; margin: 0 auto; padding: 24px 16px 48px; }
.wrap.narrow { max-width: 440px; }
.page-title { margin-bottom: 16px; }
.back { display: inline-block; margin-bottom: 12px; color: var(--muted); }

.panel {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 20px;
  margin-bottom: 16px;
}
.panel.center { text-align: center; }
.panel-head { display: flex; align-items: center; justify-content: space-between; gap: 12px; flex-wrap: wrap; margin-bottom: 14px; }
.count { color: var(--muted); font-weight: 400; font-size: 16px; margin-left: 4px; }

.grid.stats { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 12px; margin-bottom: 16px; }
.tile {
  display: flex; flex-direction: column; gap: 2px;
  background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius);
  padding: 16px; color: var(--text);
}
a.tile:hover { text-decoration: none; border-color: var(--surface-3); }
.tile-label { color: var(--muted); font-size: 12px; letter-spacing: .08em; text-transform: uppercase; }
.tile-value { font-size: 28px; line-height: 1.2; display: flex; align-items: center; gap: 8px; }
.tile-sub { color: var(--muted); font-size: 13px; }
.tile.warn .tile-value { color: var(--warn); }
.tile.bot .tile-value { font-size: 20px; padding: 4px 0; }
.dot { width: 10px; height: 10px; border-radius: 50%; background: var(--muted); flex-shrink: 0; }
.tile.bot.online .dot { background: var(--ok); box-shadow: 0 0 0 4px rgba(62, 194, 126, .18); }
.tile.bot.offline .dot { background: var(--err); }

/* ---------- формы ---------- */
label { display: block; font-size: 13px; color: var(--muted); margin: 12px 0 6px; }
input[type="text"], input[type="password"], input[type="search"], input[type="number"], textarea {
  width: 100%;
  background: var(--bg);
  color: var(--text);
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 10px 12px;
  font: inherit;
}
textarea { font: 14px/1.5 inherit; resize: vertical; }
input:focus, textarea:focus { outline: none; border-color: var(--accent); box-shadow: 0 0 0 3px rgba(217, 180, 92, .16); }
input[readonly] { font-family: var(--mono); font-size: 13px; color: var(--muted); }

.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  padding: 9px 14px;
  background: var(--surface-2); color: var(--text);
  border: 1px solid var(--line); border-radius: 10px;
  font: inherit; font-weight: 600; cursor: pointer; white-space: nowrap;
}
.btn:hover { background: var(--surface-3); text-decoration: none; }
.btn.primary { background: var(--accent); color: var(--accent-ink); border-color: transparent; }
.btn.primary:hover { filter: brightness(1.06); }
.btn.danger { color: var(--err); border-color: rgba(255, 107, 107, .35); }
.btn.wide { width: 100%; margin-top: 18px; padding: 12px; }
.stack > div:last-child { margin-top: 16px; display: flex; gap: 8px; flex-wrap: wrap; }
.row2 { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.narrow-form { max-width: 420px; }

.search { display: flex; gap: 8px; flex: 1; max-width: 460px; }
.copy-row { display: flex; gap: 8px; margin: 6px 0; }

.alert { padding: 10px 14px; border-radius: 10px; margin: 0 0 14px; border: 1px solid; }
.alert.ok { color: var(--ok); border-color: rgba(62, 194, 126, .35); background: rgba(62, 194, 126, .08); }
.alert.err { color: var(--err); border-color: rgba(255, 107, 107, .35); background: rgba(255, 107, 107, .08); }

.callout { border: 1px solid var(--line); background: var(--surface-2); border-radius: 12px; padding: 12px 16px; margin: 16px 0; }
.callout p { margin: 4px 0; }
.callout.ok { border-color: rgba(62, 194, 126, .35); }
.callout.warn { border-color: rgba(240, 162, 74, .4); background: rgba(240, 162, 74, .06); }

/* ---------- вкладки и таблица ---------- */
.tabs { display: flex; gap: 4px; flex-wrap: wrap; margin-bottom: 12px; }
.tabs a { color: var(--muted); padding: 6px 12px; border-radius: 9px; border: 1px solid transparent; }
.tabs a:hover { color: var(--text); text-decoration: none; }
.tabs a.on { color: var(--text); background: var(--surface-2); border-color: var(--line); }

.table-wrap { overflow-x: auto; margin: 0 -20px; padding: 0 20px; }
table { width: 100%; border-collapse: collapse; }
th { text-align: left; color: var(--muted); font-weight: 500; font-size: 12px; letter-spacing: .06em; text-transform: uppercase; padding: 8px 10px; border-bottom: 1px solid var(--line); }
td { padding: 11px 10px; border-bottom: 1px solid var(--line); vertical-align: middle; }
tbody tr:last-child td { border-bottom: 0; }
table.orders tbody tr { cursor: pointer; }
table.orders tbody tr:hover td { background: var(--surface-2); }

.pill {
  display: inline-block; padding: 2px 10px; border-radius: 999px;
  font-size: 12px; font-weight: 600; white-space: nowrap;
  background: var(--surface-3); color: var(--muted); border: 1px solid var(--line);
}
.pill.big { font-size: 13px; padding: 4px 12px; }
.s-waiting_input { color: var(--accent); border-color: rgba(217, 180, 92, .35); }
.s-submitted, .s-processing { color: var(--info); border-color: rgba(106, 168, 255, .35); }
.s-done { color: var(--ok); border-color: rgba(62, 194, 126, .35); }
.s-failed, .s-expired { color: var(--warn); border-color: rgba(240, 162, 74, .4); }
.s-revoked { color: var(--muted); }

.empty { padding: 36px 12px; text-align: center; color: var(--muted); }
.pager { display: flex; align-items: center; justify-content: center; gap: 12px; margin-top: 16px; }

/* ---------- карточка заказа ---------- */
.facts { display: grid; grid-template-columns: repeat(auto-fill, minmax(220px, 1fr)); gap: 12px 20px; margin: 4px 0 8px; }
.facts dt { color: var(--muted); font-size: 12px; letter-spacing: .06em; text-transform: uppercase; }
.facts dd { margin: 2px 0 0; }
.link-box { margin: 16px 0; }
.actions { display: flex; gap: 8px; flex-wrap: wrap; margin: 12px 0; }
.actions form { margin: 0; }

.timeline { list-style: none; margin: 0; padding: 0; }
.timeline li { position: relative; padding: 0 0 14px 18px; border-left: 2px solid var(--line); margin-left: 4px; }
.timeline li::before { content: ""; position: absolute; left: -6px; top: 6px; width: 10px; height: 10px; border-radius: 50%; background: var(--surface-3); border: 2px solid var(--line); }
.timeline li.src-buyer::before { background: var(--accent); }
.timeline li.src-bot::before { background: var(--info); }
.timeline li.src-admin::before { background: var(--ok); }
.timeline .when { color: var(--muted); margin-right: 8px; }
.timeline .who { color: var(--muted); font-size: 12px; margin-right: 8px; text-transform: uppercase; letter-spacing: .06em; }
.timeline p { margin: 2px 0 0; color: var(--muted); word-break: break-word; }

/* ---------- вход ---------- */
.auth { padding-top: 10vh; }
.auth-brand { display: flex; align-items: center; justify-content: center; gap: 10px; font-weight: 700; font-size: 20px; margin-bottom: 20px; }
.auth h1 { margin-bottom: 8px; }

@media (max-width: 900px) {
  .grid.stats { grid-template-columns: repeat(2, minmax(0, 1fr)); }
}
@media (max-width: 560px) {
  .top-in { gap: 12px; }
  .grid.stats { grid-template-columns: 1fr 1fr; gap: 8px; }
  .tile { padding: 12px; }
  .tile-value { font-size: 22px; }
  .row2 { grid-template-columns: 1fr; }
  .search { max-width: none; }
  .panel { padding: 16px; }
  .table-wrap { margin: 0 -16px; padding: 0 16px; }
  .copy-row { flex-wrap: wrap; }
  .copy-row input { flex-basis: 100%; }
}
