:root {
  --bg: #0f1216;
  --panel: #171b21;
  --panel-2: #1e242c;
  --border: #2a313b;
  --text: #e6e9ee;
  --muted: #97a1af;
  --accent: #4c8dff;
  --accent-2: #2b6fe0;
  --ok: #3fb950;
  --warn: #d29922;
  --err: #f85149;
  --radius: 10px;
}

* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; min-height: 100%; }
#app { min-height: 100vh; }
body {
  background: var(--bg);
  color: var(--text);
  font: 14px/1.5 -apple-system, "Segoe UI", Roboto, Arial, sans-serif;
  -webkit-font-smoothing: antialiased;
}
a { color: var(--accent); cursor: pointer; }

/* ------- auth (login / register / reset) ------- */
.login-wrap { min-height: 100vh; display: grid; place-items: center; padding: 24px; }
.login-card {
  width: 380px; max-width: 100%; background: var(--panel); border: 1px solid var(--border);
  border-radius: var(--radius); padding: 28px;
}
.login-card h1 { font-size: 18px; margin: 0 0 4px; }
.login-card p.sub { color: var(--muted); margin: 0 0 20px; font-size: 13px; }
.login-card .auth-links { margin: 14px 0 0; font-size: 13px; display: flex; justify-content: space-between; gap: 12px; }
.login-card .auth-links a { text-decoration: none; }
.auth-note { font-size: 12px; margin: 12px 0 0; }
.auth-note.ok { color: var(--ok); }
.auth-note.error { color: var(--err); }

/* ------- shell ------- */
.shell { display: flex; align-items: stretch; min-height: 100vh; }
.sidebar { flex: 0 0 232px; max-width: 232px; background: var(--panel); border-right: 1px solid var(--border);
  padding: 18px 12px; display: flex; flex-direction: column; }
.brand { font-weight: 700; font-size: 15px; padding: 6px 10px 18px; letter-spacing: .2px; }
.brand small { display: block; color: var(--muted); font-weight: 400; font-size: 11px; letter-spacing: 0; }
.nav { display: flex; flex-direction: column; gap: 2px; }
.nav button {
  text-align: left; background: transparent; border: 0; color: var(--muted); padding: 9px 12px;
  border-radius: 8px; cursor: pointer; font-size: 14px; display: flex; align-items: center; gap: 9px;
}
.nav button:hover { background: var(--panel-2); color: var(--text); }
.nav button.active { background: var(--accent-2); color: #fff; }
.nav .ico { width: 16px; text-align: center; opacity: .9; }
.sidebar .spacer { flex: 1; }
.who { color: var(--muted); font-size: 12px; padding: 10px; border-top: 1px solid var(--border); }
.who b { color: var(--text); display: block; font-weight: 600; word-break: break-all; }

.main { flex: 1; min-width: 0; padding: 24px 28px; }
.page-head { display: flex; align-items: center; justify-content: space-between; margin-bottom: 18px; gap: 12px; }
.page-head h2 { margin: 0; font-size: 20px; }
.page-head .desc { color: var(--muted); font-size: 13px; margin-top: 2px; }

/* ------- cards / grid ------- */
.cards { display: grid; grid-template-columns: repeat(auto-fill, minmax(200px, 1fr)); gap: 14px; margin-bottom: 20px; }
.stat { background: var(--panel); border: 1px solid var(--border); border-radius: var(--radius); padding: 16px; }
.stat.hl { border-color: var(--accent-2); }
.stat .label { color: var(--muted); font-size: 12px; text-transform: uppercase; letter-spacing: .4px; }
.stat .value { font-size: 26px; font-weight: 700; margin-top: 6px; }
.stat .value small { font-size: 13px; color: var(--muted); font-weight: 400; }

.card { background: var(--panel); border: 1px solid var(--border); border-radius: var(--radius); padding: 18px; margin-bottom: 18px; }
.card h3 { margin: 0 0 4px; font-size: 15px; }
.card .hint { color: var(--muted); font-size: 12px; margin: 0 0 14px; }

/* ------- forms ------- */
label.field { display: block; margin-bottom: 12px; }
label.field > span { display: block; color: var(--muted); font-size: 12px; margin-bottom: 5px; }
/* Чекбокс акцепта оферты: подпись справа от квадрата, а не над ним, как у остальных полей. */
label.field--check { display: flex; align-items: flex-start; gap: 8px; }
label.field--check > input { width: auto; margin: 2px 0 0; flex: none; }
label.field--check > span { margin: 0; line-height: 1.4; }
input, textarea, select {
  width: 100%; background: var(--panel-2); border: 1px solid var(--border); color: var(--text);
  border-radius: 8px; padding: 9px 11px; font: inherit; outline: none;
}
input:focus, textarea:focus, select:focus { border-color: var(--accent); }
textarea { resize: vertical; min-height: 90px; }
.form-row { display: grid; grid-template-columns: repeat(auto-fit, minmax(160px, 1fr)); gap: 12px; }

button.btn {
  background: var(--accent-2); color: #fff; border: 0; border-radius: 8px; padding: 9px 16px;
  font: inherit; font-weight: 600; cursor: pointer;
}
button.btn:hover { background: var(--accent); }
button.btn.ghost { background: transparent; border: 1px solid var(--border); color: var(--text); font-weight: 500; }
button.btn.ghost:hover { background: var(--panel-2); }
button.btn.sm { padding: 5px 10px; font-size: 12px; font-weight: 500; }
button.btn:disabled { opacity: .5; cursor: not-allowed; }
.row-end { display: flex; justify-content: flex-end; gap: 8px; }
.row-start { display: flex; justify-content: flex-start; gap: 8px; flex-wrap: wrap; }

/* ------- ref link ------- */
.reflink-row { display: flex; gap: 8px; align-items: stretch; }
.reflink-row input { font-family: ui-monospace, Menlo, Consolas, monospace; font-size: 13px; }
.reflink-row button { white-space: nowrap; }
.code-chip { display: inline-block; background: var(--panel-2); border: 1px solid var(--border); border-radius: 6px;
  padding: 3px 9px; font-family: ui-monospace, Menlo, Consolas, monospace; font-size: 13px; color: var(--text); }

/* ------- table ------- */
table.tbl { width: 100%; border-collapse: collapse; font-size: 13px; }
table.tbl th, table.tbl td { text-align: left; padding: 9px 10px; border-bottom: 1px solid var(--border); }
table.tbl th { color: var(--muted); font-weight: 600; font-size: 12px; text-transform: uppercase; letter-spacing: .3px; }
table.tbl tr:last-child td { border-bottom: 0; }
.tbl-wrap { overflow-x: auto; }
.nowrap { white-space: nowrap; }
.num { text-align: right; font-variant-numeric: tabular-nums; }

/* ------- badges ------- */
.badge { display: inline-block; padding: 2px 9px; border-radius: 999px; font-size: 11px; font-weight: 600; }
.badge.active { background: rgba(63,185,80,.15); color: var(--ok); }
.badge.expired, .badge.blocked { background: rgba(248,81,73,.15); color: var(--err); }
.badge.disabled { background: rgba(151,161,175,.15); color: var(--muted); }
.badge.warn { background: rgba(210,153,34,.15); color: var(--warn); }
.badge.yes { background: rgba(63,185,80,.15); color: var(--ok); }
.badge.no { background: rgba(151,161,175,.15); color: var(--muted); }

/* ------- alert banner ------- */
.alert {
  display: flex; align-items: center; gap: 12px; margin: 0 0 16px;
  background: rgba(76,141,255,.10); border: 1px solid rgba(76,141,255,.35);
  color: var(--text); border-radius: var(--radius); padding: 12px 14px; font-size: 13px;
}
.alert.warn { background: rgba(210,153,34,.10); border-color: rgba(210,153,34,.35); }
.alert .a-ico { font-size: 16px; line-height: 1; }

/* ------- материалы: готовые тексты и справка ------- */
/* Заголовок группы: экран длинный по природе, без группировки он читается полотном. */
.mt-sec { display: flex; align-items: baseline; gap: 12px; margin: 26px 0 10px; flex-wrap: wrap; }
.mt-sec:first-of-type { margin-top: 8px; }
.mt-sec h3 { margin: 0; font-size: 15px; letter-spacing: .2px; }
.mt-sec span { color: var(--muted); font-size: 12.5px; }
.mt-sec::after { content: ''; flex: 1; height: 1px; background: var(--border); }
/* Бланк КП сразу за текстом КП. Кнопка ПОД описанием и прижата влево: у правого края
   её не замечали, взгляд идёт по левой кромке карточки. */
.mt-inline { border-top: 1px solid var(--border); margin-top: 6px; padding-top: 14px; }
.mt-inline h4 { margin: 0 0 4px; font-size: 14px; }
.mt-inline .hint { margin: 0 0 12px; max-width: 68ch; }
.mt-inline .btn { text-decoration: none; display: inline-block; }
.mt-cols { columns: 2; column-gap: 26px; }
.mt-cols li { break-inside: avoid; }
@media (max-width: 720px) { .mt-cols { columns: 1; } }
textarea.tpl { min-height: 200px; line-height: 1.55; font-size: 13px; }
.mt-list { margin: 0; padding-left: 20px; color: var(--text); font-size: 13px; }
.mt-list li { margin-bottom: 8px; }
.mt-list li:last-child { margin-bottom: 0; }
.mt-acc { border-top: 1px solid var(--border); }
.mt-acc:first-of-type { border-top: 0; }
/* summary флексом, а не с ::before-маркером: с inline-маркером вторая строка заголовка
   уезжала под плюсик и блок «ехал». Маркер справа, текст остаётся ровным столбцом. */
.mt-acc > summary {
  cursor: pointer; list-style: none; display: flex; align-items: baseline; gap: 12px;
  padding: 11px 2px; font-size: 14px; font-weight: 600; color: var(--text);
}
.mt-acc > summary::-webkit-details-marker { display: none; }
/* Маркер СЛЕВА и отдельным flex-элементом фиксированной ширины: справа его не замечали,
   а inline-маркером вторая строка заголовка уезжала под плюсик. */
.mt-acc > summary::before {
  content: '+'; flex: 0 0 18px; color: var(--accent); font-size: 17px; line-height: 1.25;
  font-weight: 700; text-align: center;
}
.mt-acc[open] > summary::before { content: '−'; }
.mt-acc > summary:hover { color: #fff; }
.mt-acc > summary:hover::before { color: var(--accent); }
/* Текст ответа выравнивается по тексту заголовка, а не по маркеру. */
.mt-acc-body { padding: 0 2px 14px 30px; max-width: 84ch; }
.mt-acc-body p { color: var(--muted); font-size: 13.5px; line-height: 1.62; margin: 0 0 9px; }
.mt-acc-body p:last-child { margin-bottom: 0; }
.mt-acc-body b { color: var(--text); font-weight: 600; }

.muted { color: var(--muted); }
.mono { font-family: ui-monospace, Menlo, Consolas, monospace; font-size: 12px; }

.toast {
  position: fixed; right: 20px; bottom: 20px; max-width: 380px; padding: 12px 16px; border-radius: 8px;
  background: var(--panel-2); border: 1px solid var(--border); color: var(--text); box-shadow: 0 8px 30px rgba(0,0,0,.4);
  opacity: 0; transform: translateY(8px); transition: .2s; z-index: 50;
}
.toast.show { opacity: 1; transform: none; }
.toast.ok { border-color: var(--ok); }
.toast.error { border-color: var(--err); }

.empty { color: var(--muted); padding: 24px; text-align: center; }
.loading { color: var(--muted); padding: 16px; }

@media (max-width: 720px) {
  .shell { flex-direction: column; }
  .sidebar { width: 100%; height: auto; position: static; padding: 12px; }
  .nav { flex-direction: row; flex-wrap: wrap; }
  .nav button { flex: 1 1 auto; justify-content: center; }
  .sidebar .spacer { display: none; }
  .who { border-top: 1px solid var(--border); margin-top: 8px; }
}
