:root {
  --bg: #0b0c10;
  --bg-2: #111318;
  --panel: #15171d;
  --panel-2: #1b1e26;
  --line: #262a34;
  --line-2: #323745;
  --text: #e8eaf0;
  --muted: #8b91a1;
  --faint: #5d6373;
  --accent: #8b7bff;
  --accent-2: #4fd1ff;
  --ok: #3ecf8e;
  --warn: #f5b84b;
  --bad: #ff6b6b;
  --prism: linear-gradient(120deg, #ff7ab6 0%, #a78bfa 35%, #60a5fa 65%, #4fd1c5 100%);
  --radius: 12px;
  --mono: ui-monospace, 'JetBrains Mono', 'SFMono-Regular', Menlo, Consolas, monospace;
  color-scheme: dark;
}

* { box-sizing: border-box; }
html, body { margin: 0; }
body {
  background: var(--bg);
  color: var(--text);
  font: 14px/1.5 -apple-system, BlinkMacSystemFont, 'Segoe UI', Inter, Roboto, sans-serif;
  -webkit-font-smoothing: antialiased;
}
a { color: var(--accent-2); text-decoration: none; }
a:hover { text-decoration: underline; }
code, pre, .mono { font-family: var(--mono); font-size: 12.5px; }
code { background: var(--panel-2); border: 1px solid var(--line); border-radius: 6px; padding: 1px 6px; }
pre {
  background: #0e1015; border: 1px solid var(--line); border-radius: 10px; padding: 14px 16px;
  overflow-x: auto; margin: 0; line-height: 1.55; position: relative;
}
pre code { background: none; border: 0; padding: 0; }
h1, h2, h3 { margin: 0; font-weight: 600; letter-spacing: -0.01em; }
h1 { font-size: 22px; }
h2 { font-size: 16px; }
h3 { font-size: 14px; }
p { margin: 0; }
.muted { color: var(--muted); }
.faint { color: var(--faint); }
.small { font-size: 12px; }
.ok { color: var(--ok); }
.bad { color: var(--bad); }
.warn { color: var(--warn); }
.right { text-align: right; }
.nowrap { white-space: nowrap; }
.hidden { display: none !important; }

/* ---- Каркас ---- */
.shell { display: grid; grid-template-columns: 232px 1fr; min-height: 100vh; }
.side {
  background: var(--bg-2); border-right: 1px solid var(--line); padding: 20px 14px;
  display: flex; flex-direction: column; gap: 4px; position: sticky; top: 0; height: 100vh;
}
.brand { display: flex; align-items: center; gap: 10px; padding: 4px 10px 18px; font-weight: 700; font-size: 16px; }
.brand-mark {
  width: 26px; height: 26px; border-radius: 8px; background: var(--prism);
  clip-path: polygon(50% 0, 100% 85%, 0 85%); flex: none;
}
.brand small { display: block; font-weight: 500; font-size: 11px; color: var(--muted); letter-spacing: 0.04em; }
.nav a {
  display: flex; align-items: center; gap: 10px; padding: 8px 10px; border-radius: 8px;
  color: var(--muted); font-weight: 500;
}
.nav a:hover { background: var(--panel); color: var(--text); text-decoration: none; }
.nav a.active { background: var(--panel-2); color: var(--text); }
.nav svg { width: 16px; height: 16px; flex: none; }
.side-foot { margin-top: auto; padding: 10px; border-top: 1px solid var(--line); display: flex; flex-direction: column; gap: 8px; }
.main { padding: 28px 36px 60px; max-width: 1180px; width: 100%; }
.page-head { display: flex; align-items: flex-end; justify-content: space-between; gap: 16px; margin-bottom: 22px; flex-wrap: wrap; }
.page-head p { margin-top: 4px; }

/* ---- Карточки ---- */
.card { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); padding: 18px 20px; }
.card + .card, .stack > * + * { margin-top: 16px; }
.card-head { display: flex; align-items: center; justify-content: space-between; gap: 12px; margin-bottom: 14px; }
.grid { display: grid; gap: 16px; }
.grid-4 { grid-template-columns: repeat(4, minmax(0, 1fr)); }
.grid-3 { grid-template-columns: repeat(3, minmax(0, 1fr)); }
.grid-2 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
.stat .label { color: var(--muted); font-size: 12px; font-weight: 500; }
.stat .value { font-size: 24px; font-weight: 650; margin-top: 4px; letter-spacing: -0.02em; font-variant-numeric: tabular-nums; }
.stat .sub { color: var(--faint); font-size: 12px; margin-top: 2px; }
.balance-hero { position: relative; overflow: hidden; }
.balance-hero::before {
  content: ''; position: absolute; inset: 0; background: var(--prism); opacity: 0.08; pointer-events: none;
}
.balance-hero .value { font-size: 32px; }

/* ---- Кнопки и поля ---- */
.btn {
  appearance: none; border: 1px solid var(--line-2); background: var(--panel-2); color: var(--text);
  padding: 8px 14px; border-radius: 9px; font: inherit; font-weight: 550; cursor: pointer;
  display: inline-flex; align-items: center; gap: 8px; white-space: nowrap;
}
.btn:hover { border-color: #444b5c; background: #20242e; }
.btn:disabled { opacity: 0.5; cursor: default; }
.btn.primary { background: var(--text); color: #0b0c10; border-color: var(--text); }
.btn.primary:hover { background: #fff; }
.btn.danger { color: var(--bad); }
.btn.danger:hover { border-color: var(--bad); }
.btn.ghost { background: transparent; border-color: transparent; color: var(--muted); }
.btn.ghost:hover { color: var(--text); background: var(--panel-2); }
.btn.sm { padding: 4px 10px; font-size: 12.5px; border-radius: 7px; }
.row { display: flex; gap: 10px; align-items: center; flex-wrap: wrap; }
label.field { display: flex; flex-direction: column; gap: 6px; font-size: 12.5px; color: var(--muted); font-weight: 500; }
input, select, textarea {
  background: #0e1015; border: 1px solid var(--line-2); color: var(--text); border-radius: 9px;
  padding: 9px 12px; font: inherit; outline: none; width: 100%;
}
input:focus, select:focus, textarea:focus { border-color: var(--accent); box-shadow: 0 0 0 3px rgba(139, 123, 255, 0.18); }
input[type='checkbox'] { width: auto; }
.form { display: flex; flex-direction: column; gap: 14px; }

/* ---- Таблицы ---- */
.table-wrap { overflow-x: auto; margin: 0 -20px; padding: 0 20px; }
table { width: 100%; border-collapse: collapse; font-variant-numeric: tabular-nums; }
th {
  text-align: left; font-size: 11.5px; text-transform: uppercase; letter-spacing: 0.05em; color: var(--faint);
  font-weight: 600; padding: 8px 10px; border-bottom: 1px solid var(--line);
}
td { padding: 10px; border-bottom: 1px solid var(--line); vertical-align: middle; }
tr:last-child td { border-bottom: 0; }
tbody tr:hover td { background: rgba(255, 255, 255, 0.015); }
tr.clickable { cursor: pointer; }
.empty { text-align: center; color: var(--faint); padding: 30px 10px; }

/* ---- Бейджи ---- */
.badge {
  display: inline-flex; align-items: center; gap: 5px; padding: 2px 8px; border-radius: 999px; font-size: 11.5px;
  font-weight: 600; background: var(--panel-2); border: 1px solid var(--line-2); color: var(--muted);
}
.badge.ok { color: var(--ok); border-color: rgba(62, 207, 142, 0.3); background: rgba(62, 207, 142, 0.08); }
.badge.bad { color: var(--bad); border-color: rgba(255, 107, 107, 0.3); background: rgba(255, 107, 107, 0.08); }
.badge.warn { color: var(--warn); border-color: rgba(245, 184, 75, 0.3); background: rgba(245, 184, 75, 0.08); }
.badge.cat-text { color: #a78bfa; }
.badge.cat-audio { color: #4fd1c5; }
.badge.cat-realtime { color: #ff7ab6; }
.badge.cat-embedding { color: #60a5fa; }

/* ---- Табы ---- */
.tabs { display: flex; gap: 4px; border-bottom: 1px solid var(--line); margin-bottom: 14px; flex-wrap: wrap; }
.tabs button {
  background: none; border: 0; color: var(--muted); padding: 8px 12px; font: inherit; font-weight: 550;
  cursor: pointer; border-bottom: 2px solid transparent; margin-bottom: -1px;
}
.tabs button.active { color: var(--text); border-color: var(--accent); }

/* ---- График ---- */
.bars { display: flex; align-items: flex-end; gap: 3px; height: 140px; padding-top: 8px; }
.bars .bar { flex: 1; background: linear-gradient(180deg, #a78bfa, #60a5fa); border-radius: 3px 3px 0 0; min-height: 2px; opacity: 0.85; position: relative; }
.bars .bar:hover { opacity: 1; }
.bars .bar.zero { background: var(--line); }
.bars-axis { display: flex; justify-content: space-between; color: var(--faint); font-size: 11px; margin-top: 6px; }
.meter { height: 6px; background: var(--panel-2); border-radius: 99px; overflow: hidden; }
.meter > div { height: 100%; background: var(--prism); }

/* ---- Модалки и уведомления ---- */
.modal-bg {
  position: fixed; inset: 0; background: rgba(5, 6, 9, 0.7); backdrop-filter: blur(4px);
  display: flex; align-items: center; justify-content: center; padding: 16px; z-index: 50;
}
.modal { background: var(--panel); border: 1px solid var(--line-2); border-radius: 14px; width: 100%; max-width: 460px; padding: 22px; box-shadow: 0 30px 80px rgba(0, 0, 0, 0.5); }
.modal h2 { margin-bottom: 14px; }
.modal .actions { display: flex; justify-content: flex-end; gap: 10px; margin-top: 18px; }
.toasts { position: fixed; bottom: 20px; right: 20px; display: flex; flex-direction: column; gap: 8px; z-index: 60; }
.toast { background: var(--panel-2); border: 1px solid var(--line-2); padding: 10px 14px; border-radius: 10px; box-shadow: 0 10px 30px rgba(0, 0, 0, 0.4); max-width: 360px; }
.toast.bad { border-color: rgba(255, 107, 107, 0.5); }
.secret {
  display: flex; gap: 8px; align-items: center; background: #0e1015; border: 1px dashed var(--accent);
  border-radius: 10px; padding: 10px 12px; font-family: var(--mono); font-size: 12.5px; word-break: break-all;
}
.secret span { flex: 1; }
.copy-btn { position: absolute; top: 8px; right: 8px; }
.alert { border: 1px solid rgba(245, 184, 75, 0.35); background: rgba(245, 184, 75, 0.07); color: #f3d18e; padding: 10px 14px; border-radius: 10px; }
.alert.bad { border-color: rgba(255, 107, 107, 0.35); background: rgba(255, 107, 107, 0.07); color: #ffb3b3; }

/* ---- Вход ---- */
.login-wrap { min-height: 100vh; display: flex; align-items: center; justify-content: center; padding: 16px; position: relative; overflow: hidden; }
.login-wrap::before {
  content: ''; position: absolute; width: 700px; height: 700px; border-radius: 50%; background: var(--prism);
  filter: blur(140px); opacity: 0.13; top: -260px; left: 50%; transform: translateX(-50%);
}
.login { width: 100%; max-width: 380px; position: relative; }
.login .brand { justify-content: center; font-size: 20px; padding-bottom: 24px; }
.login .brand-mark { width: 32px; height: 32px; }

/* ---- Документация ---- */
.doc h2 { margin: 28px 0 10px; }
.doc h2:first-child { margin-top: 0; }
.doc p, .doc ul { color: #c6cad4; margin: 8px 0; }
.doc ul { padding-left: 20px; }
.doc li { margin: 4px 0; }

/* ---- Мобильная вёрстка ---- */
.mobile-bar { display: none; }
@media (max-width: 900px) {
  .shell { grid-template-columns: 1fr; }
  .side { position: fixed; inset: 0 30% 0 0; z-index: 40; transform: translateX(-105%); transition: transform 0.2s; height: 100vh; }
  .side.open { transform: none; box-shadow: 0 0 60px rgba(0, 0, 0, 0.6); }
  .mobile-bar { display: flex; align-items: center; gap: 10px; padding: 12px 16px; border-bottom: 1px solid var(--line); background: var(--bg-2); position: sticky; top: 0; z-index: 30; }
  .main { padding: 20px 16px 50px; }
  .grid-4 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .grid-3, .grid-2 { grid-template-columns: 1fr; }
}

/* ---- Редактор цен ---- */
.price-rows { display: flex; flex-direction: column; gap: 10px; max-height: 55vh; overflow-y: auto; }
.price-row { display: grid; grid-template-columns: 1fr auto 64px; gap: 12px; align-items: center; padding-bottom: 10px; border-bottom: 1px solid var(--line); }
.price-row:last-child { border-bottom: 0; }
.topup { display: inline-flex; align-items: center; gap: 6px; }
