/*
  Стили веб-панели администратора encar.
  Свой CSS, без внешних шрифтов/CDN (панель работает офлайн). Светлая тема — по
  умолчанию, тёмная — через prefers-color-scheme. Палитра согласована с
  encar/api/templates/consumer_guide.html, чтобы админка и публичный гайд по API
  выглядели частью одного продукта.
*/

:root {
  --ground: #f6f8fb;
  --surface: #ffffff;
  --surface-2: #eef2f7;
  --ink: #17202e;
  --muted: #5b6879;
  --faint: #8494a6;
  --border: #e0e6ee;
  --border-strong: #cdd6e1;
  --accent: #1f5fd6;
  --accent-soft: #e8f0fd;
  --accent-ink: #1546a0;
  --ok: #147a4d;
  --ok-soft: #e2f4ea;
  --warn: #9a5b00;
  --warn-soft: #f8ecd6;
  --crit: #bb3838;
  --crit-soft: #f8e4e4;
  --code-bg: #0f1826;
  --code-ink: #dce6f2;
  --code-border: #223047;
  --shadow: 0 1px 2px rgba(20, 30, 48, .06), 0 8px 24px -12px rgba(20, 30, 48, .18);
  --mono: "SFMono-Regular", "SF Mono", "JetBrains Mono", "Fira Code", ui-monospace, Menlo, Consolas, monospace;
  --sans: -apple-system, BlinkMacSystemFont, "Segoe UI", system-ui, Roboto, "Helvetica Neue", Arial, sans-serif;
}

@media (prefers-color-scheme: dark) {
  :root {
    --ground: #0e1420;
    --surface: #161e2b;
    --surface-2: #1d2735;
    --ink: #e7edf5;
    --muted: #9aa8bb;
    --faint: #6e7d92;
    --border: #26313f;
    --border-strong: #33404f;
    --accent: #5f9bff;
    --accent-soft: #182842;
    --accent-ink: #a9c8ff;
    --ok: #57c98d;
    --ok-soft: #14301f;
    --warn: #e2a44f;
    --warn-soft: #33270f;
    --crit: #ef7676;
    --crit-soft: #351818;
    --code-bg: #0a121e;
    --code-ink: #d5e2f1;
    --code-border: #1b2839;
    --shadow: 0 1px 2px rgba(0, 0, 0, .3), 0 10px 30px -14px rgba(0, 0, 0, .55);
  }
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  background: var(--ground);
  color: var(--ink);
  font-family: var(--sans);
  font-size: 15px;
  line-height: 1.5;
}

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

h1, h2, h3 { line-height: 1.25; margin: 0 0 .5em; }
h1 { font-size: 22px; display: flex; align-items: center; gap: 10px; }
h2 { font-size: 16px; color: var(--muted); font-weight: 600; }

code, .mono {
  font-family: var(--mono);
  font-size: .92em;
}

/* ---------- Шапка ---------- */

.site-header {
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  box-shadow: var(--shadow);
}

.site-header__inner {
  max-width: 1080px;
  margin: 0 auto;
  padding: 14px 20px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
}

.brand {
  font-weight: 700;
  color: var(--ink);
  font-size: 16px;
}
.brand:hover { text-decoration: none; color: var(--accent); }

.site-nav {
  display: flex;
  align-items: center;
  gap: 12px;
}

.site-nav__user {
  color: var(--muted);
  font-size: 13px;
}

/* ---------- Контейнер ---------- */

.container {
  max-width: 1080px;
  margin: 0 auto;
  padding: 24px 20px 60px;
}

.page-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 20px;
  flex-wrap: wrap;
}

/* ---------- Флеш-сообщения ---------- */

.flash {
  border-radius: 10px;
  padding: 12px 16px;
  margin-bottom: 18px;
  border: 1px solid var(--border);
  font-size: 14px;
}
.flash-info    { background: var(--accent-soft); border-color: color-mix(in srgb, var(--accent) 35%, transparent); color: var(--accent-ink); }
.flash-success { background: var(--ok-soft); border-color: color-mix(in srgb, var(--ok) 35%, transparent); color: var(--ok); }
.flash-error   { background: var(--crit-soft); border-color: color-mix(in srgb, var(--crit) 35%, transparent); color: var(--crit); }

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

.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 18px 20px;
  box-shadow: var(--shadow);
  margin-bottom: 18px;
}

.danger-zone {
  border-color: color-mix(in srgb, var(--crit) 35%, var(--border));
}
.danger-zone h2 { color: var(--crit); }

/* ---------- Формы ---------- */

.form {
  display: flex;
  flex-direction: column;
  gap: 14px;
  max-width: 480px;
}

.form label,
.login-card label {
  display: flex;
  flex-direction: column;
  gap: 6px;
  font-size: 13px;
  color: var(--muted);
  font-weight: 600;
}

input[type="text"],
input[type="password"],
input[type="number"] {
  font: inherit;
  font-size: 14px;
  color: var(--ink);
  background: var(--surface);
  border: 1px solid var(--border-strong);
  border-radius: 8px;
  padding: 9px 11px;
  outline: none;
}
input:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-soft);
}

.hint {
  font-weight: 400;
  color: var(--faint);
  font-size: 12px;
}

.checkbox-field {
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.checkbox-label {
  display: flex;
  flex-direction: row;
  align-items: center;
  gap: 8px;
  font-size: 13px;
  color: var(--muted);
  font-weight: 600;
}
.checkbox-label input[type="checkbox"] {
  width: 16px;
  height: 16px;
  margin: 0;
}

.inline-form {
  display: inline-block;
  margin: 0;
}

.actions {
  display: flex;
  gap: 10px;
  flex-wrap: wrap;
  margin-top: 8px;
}

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

.btn {
  font: inherit;
  font-size: 14px;
  font-weight: 600;
  border-radius: 20px;
  padding: 8px 16px;
  border: 1px solid var(--border-strong);
  background: var(--surface);
  color: var(--ink);
  cursor: pointer;
  box-shadow: var(--shadow);
  display: inline-block;
}
.btn:hover { text-decoration: none; border-color: var(--accent); color: var(--accent); }

.btn-primary {
  background: var(--accent);
  border-color: var(--accent);
  color: #fff;
}
.btn-primary:hover { color: #fff; opacity: .92; border-color: var(--accent); }

.btn-danger {
  background: var(--crit);
  border-color: var(--crit);
  color: #fff;
}
.btn-danger:hover { color: #fff; opacity: .9; border-color: var(--crit); }

.btn-ghost {
  background: transparent;
  box-shadow: none;
}

.btn-sm {
  padding: 4px 10px;
  font-size: 12px;
}

.btn-block {
  width: 100%;
  text-align: center;
}

/* ---------- Бейджи ---------- */

.badge {
  display: inline-block;
  font-size: 12px;
  font-weight: 700;
  padding: 3px 10px;
  border-radius: 20px;
  vertical-align: middle;
}
.badge-ok  { background: var(--ok-soft); color: var(--ok); }
.badge-off { background: var(--surface-2); color: var(--faint); border: 1px solid var(--border-strong); }

/* ---------- Таблицы ---------- */

.table-wrap {
  overflow-x: auto;
  border: 1px solid var(--border);
  border-radius: 10px;
  background: var(--surface);
}

.table {
  width: 100%;
  border-collapse: collapse;
  font-size: 14px;
  min-width: 640px;
}

.table th, .table td {
  padding: 10px 14px;
  text-align: left;
  border-bottom: 1px solid var(--border);
  white-space: nowrap;
}

.table th {
  color: var(--muted);
  font-weight: 600;
  font-size: 12px;
  text-transform: uppercase;
  letter-spacing: .03em;
  background: var(--surface-2);
}

.table tbody tr:last-child td { border-bottom: none; }
.table tbody tr:hover { background: var(--surface-2); }

.empty-state {
  color: var(--muted);
  padding: 24px;
  text-align: center;
  border: 1px dashed var(--border-strong);
  border-radius: 10px;
  background: var(--surface);
}

/* ---------- Расход / прогресс-бар ---------- */

.usage {
  display: flex;
  flex-direction: column;
  gap: 6px;
  min-width: 140px;
}

.usage-text {
  font-family: var(--mono);
  font-size: 12px;
  color: var(--muted);
  white-space: nowrap;
}

.progress {
  width: 100%;
  height: 6px;
  border-radius: 4px;
  background: var(--surface-2);
  overflow: hidden;
}

.progress-bar {
  height: 100%;
  background: var(--accent);
  border-radius: 4px;
}

/* ---------- Токены ---------- */

.token-masked, .token-full {
  font-family: var(--mono);
  background: var(--code-bg);
  color: var(--code-ink);
  border: 1px solid var(--code-border);
  border-radius: 6px;
  padding: .15em .5em;
}

.token-cell {
  white-space: nowrap;
}
.token-cell .token-masked {
  margin-right: 8px;
}

.token-box {
  display: flex;
  align-items: center;
  gap: 12px;
  flex-wrap: wrap;
  margin-bottom: 18px;
}

.token-full {
  font-size: 15px;
  padding: 12px 16px;
  word-break: break-all;
  flex: 1 1 320px;
}

.callout {
  border-radius: 10px;
  padding: 14px 16px;
  border: 1px solid var(--border);
  background: var(--surface);
  border-left: 3px solid var(--accent);
  margin-bottom: 18px;
}
.callout-warn {
  border-left-color: var(--warn);
  background: var(--warn-soft);
  color: var(--warn);
}

/* ---------- Логин ---------- */

.login-wrap {
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: calc(100vh - 40px);
}

.login-card {
  width: 100%;
  max-width: 340px;
  display: flex;
  flex-direction: column;
  gap: 16px;
}

.login-card h1 {
  font-size: 18px;
  text-align: center;
}
