:root {
  --bg: #f3f5fa;
  --surface: #ffffff;
  --surface-2: #f8fafc;
  --border: #e2e8f0;
  --border-strong: #cbd5e1;
  --text: #0f172a;
  --muted: #64748b;
  --primary: #4f46e5;
  --primary-600: #4338ca;
  --primary-50: #eef2ff;
  --ok: #047857;
  --ok-50: #ecfdf5;
  --warn: #b45309;
  --warn-50: #fffbeb;
  --err: #b91c1c;
  --err-50: #fef2f2;
  --info: #0369a1;
  --info-50: #f0f9ff;
  --primary-200: #c7d2fe;
  --ok-200: #a7f3d0;
  --ok-900: #064e3b;
  --warn-200: #fde68a;
  --warn-900: #78350f;
  --err-200: #fecaca;
  --err-900: #7f1d1d;
  --info-200: #bae6fd;
  --info-900: #0c4a6e;
  --input: #fff;
  --row-hover: #fafbff;
  --tariff-selected: #fbfbff;
  --radius: 14px;
  --radius-sm: 9px;
  --shadow: 0 1px 2px rgba(15, 23, 42, .04), 0 6px 20px rgba(15, 23, 42, .05);
  --font: system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  --mono: ui-monospace, "SFMono-Regular", Consolas, "Liberation Mono", monospace;
}

/* --- тёмная тема (выбирается в «Настройках») --- */
html[data-theme="dark"] {
  color-scheme: dark;
  --bg: #0b1120;
  --surface: #121a2b;
  --surface-2: #182236;
  --border: #243049;
  --border-strong: #33415e;
  --text: #e2e8f0;
  --muted: #94a3b8;
  --primary: #818cf8;
  --primary-600: #a5b4fc;
  --primary-50: rgba(129, 140, 248, .14);
  --primary-200: rgba(129, 140, 248, .45);
  --ok: #34d399;
  --ok-50: rgba(52, 211, 153, .12);
  --ok-200: rgba(52, 211, 153, .35);
  --ok-900: #a7f3d0;
  --warn: #fbbf24;
  --warn-50: rgba(251, 191, 36, .12);
  --warn-200: rgba(251, 191, 36, .35);
  --warn-900: #fde68a;
  --err: #f87171;
  --err-50: rgba(248, 113, 113, .12);
  --err-200: rgba(248, 113, 113, .38);
  --err-900: #fecaca;
  --info: #38bdf8;
  --info-50: rgba(56, 189, 248, .12);
  --info-200: rgba(56, 189, 248, .35);
  --info-900: #bae6fd;
  --input: #0e1626;
  --row-hover: #172034;
  --tariff-selected: rgba(129, 140, 248, .08);
  --shadow: 0 1px 2px rgba(0, 0, 0, .35), 0 6px 20px rgba(0, 0, 0, .25);
}
/* Кнопки и значки с белым текстом: на светлых акцентах тёмной темы он бы не читался */
html[data-theme="dark"] .btn--primary { background: #5558e8; border-color: #5558e8; }
html[data-theme="dark"] .btn--primary:hover:not(:disabled) { background: #4f46e5; border-color: #4f46e5; }
html[data-theme="dark"] .btn--ok { background: #059669; border-color: #059669; }
html[data-theme="dark"] .btn--ok:hover { background: #047857; }
html[data-theme="dark"] .nav__count { background: #d97706; }
html[data-theme="dark"] .tariff.is-selected::after { background: #5558e8; }
html[data-theme="dark"] .guide__steps li::before { background: var(--border-strong); }
html[data-theme="dark"] .modal__backdrop { background: rgba(2, 6, 23, .7); }

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 15px/1.5 var(--font);
}
body.modal-open { overflow: hidden; }
a { color: var(--primary); text-decoration: none; }
a:hover { text-decoration: underline; }
h1 { font-size: 26px; line-height: 1.25; margin: 0 0 6px; letter-spacing: -.01em; }
h2 { font-size: 18px; margin: 0 0 12px; }
h3 { font-size: 15px; margin: 18px 0 8px; }
p { margin: 0 0 10px; }
.muted { color: var(--muted); }
.small { font-size: 13px; }
.mono { font-family: var(--mono); font-size: 13px; word-break: break-all; }
.nowrap { white-space: nowrap; }
.num { text-align: right; font-variant-numeric: tabular-nums; }
[hidden] { display: none !important; }

/* --- шапка --- */
.topbar { background: var(--surface); border-bottom: 1px solid var(--border); position: sticky; top: 0; z-index: 20; }
.topbar__inner {
  max-width: 1240px; margin: 0 auto; padding: 0 20px;
  display: flex; align-items: center; gap: 16px; min-height: 60px;
}
.brand { display: flex; align-items: center; gap: 9px; font-weight: 700; color: var(--text); white-space: nowrap; }
.brand:hover { text-decoration: none; }
.brand__mark {
  width: 30px; height: 30px; border-radius: 9px; display: grid; place-items: center;
  background: linear-gradient(135deg, #6366f1, #8b5cf6); color: #fff; font-size: 15px;
}
.nav { display: flex; gap: 2px; overflow-x: auto; flex: 1; scrollbar-width: none; }
.nav::-webkit-scrollbar { display: none; }
.nav a {
  padding: 8px 9px; border-radius: 8px; color: var(--muted); font-size: 14px; font-weight: 500; white-space: nowrap;
}
.nav a:hover { background: var(--surface-2); color: var(--text); text-decoration: none; }
.nav a.is-active { background: var(--primary-50); color: var(--primary-600); }
.nav__count {
  display: inline-block; min-width: 18px; padding: 0 5px; margin-left: 4px; border-radius: 9px;
  background: var(--warn); color: #fff; font-size: 11px; line-height: 18px; text-align: center;
}
.userbox { display: flex; align-items: center; gap: 10px; white-space: nowrap; font-size: 14px; }
.userbox form { margin: 0; }

.container { max-width: 1240px; margin: 0 auto; padding: 26px 20px 60px; }
.page-head { display: flex; justify-content: space-between; align-items: flex-end; gap: 16px; flex-wrap: wrap; margin-bottom: 20px; }
.page-head p { margin: 0; }
.page-head__actions { display: flex; gap: 8px; flex-wrap: wrap; }

/* --- карточки и сетки --- */
.card {
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius);
  box-shadow: var(--shadow); padding: 22px; margin-bottom: 20px;
}
.card--soft { background: var(--surface-2); box-shadow: none; }
.card--flush { padding: 0; overflow: hidden; }
.card--flush > .card__head { padding: 18px 22px 0; }
.card__head { display: flex; justify-content: space-between; align-items: center; gap: 12px; margin-bottom: 14px; flex-wrap: wrap; }
.card__head h2 { margin: 0; }
.card__title { display: flex; align-items: center; gap: 10px; font-size: 17px; margin: 0 0 14px; }
.card__title + * { margin-top: 0; }
.step-num {
  width: 26px; height: 26px; border-radius: 50%; display: grid; place-items: center; flex: none;
  background: var(--primary-50); color: var(--primary-600); font-size: 14px; font-weight: 700;
}
.grid { display: grid; gap: 20px; }
.grid-2 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
.grid-3 { grid-template-columns: repeat(3, minmax(0, 1fr)); }
.stats { display: grid; grid-template-columns: repeat(auto-fit, minmax(170px, 1fr)); gap: 14px; margin-bottom: 20px; }
.stat {
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius);
  padding: 16px 18px; box-shadow: var(--shadow);
}
.stat__label { color: var(--muted); font-size: 13px; }
.stat__value { font-size: 26px; font-weight: 700; margin-top: 2px; font-variant-numeric: tabular-nums; }
.stat__hint { color: var(--muted); font-size: 12.5px; margin-top: 2px; }
.stat--ok .stat__value { color: var(--ok); }
.stat--err .stat__value { color: var(--err); }
.stat--warn .stat__value { color: var(--warn); }

/* --- кнопки --- */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  min-height: 38px; padding: 8px 15px; border-radius: var(--radius-sm);
  border: 1px solid var(--border-strong); background: var(--surface); color: var(--text);
  font: inherit; font-weight: 600; cursor: pointer; white-space: nowrap; text-decoration: none;
  transition: background .15s, border-color .15s, box-shadow .15s;
}
.btn:hover { background: var(--surface-2); text-decoration: none; }
.btn:focus-visible { outline: 3px solid rgba(79, 70, 229, .3); outline-offset: 1px; }
.btn:disabled { opacity: .55; cursor: not-allowed; }
.btn--primary { background: var(--primary); border-color: var(--primary); color: #fff; }
.btn--primary:hover:not(:disabled) { background: var(--primary-600); }
.btn--ok { background: var(--ok); border-color: var(--ok); color: #fff; }
.btn--ok:hover { background: #065f46; }
.btn--danger { color: var(--err); border-color: var(--err-200); }
.btn--danger:hover { background: var(--err-50); }
.btn--ghost { background: transparent; border-color: transparent; color: var(--primary); }
.btn--ghost:hover { background: var(--primary-50); }
.btn--sm { min-height: 30px; padding: 4px 10px; font-size: 13px; }
.btn--lg { min-height: 48px; padding: 12px 20px; font-size: 16px; }
.btn--block { width: 100%; }
.btn-link { background: none; border: 0; padding: 0; color: var(--primary); font: inherit; cursor: pointer; }
.btn-link:hover { text-decoration: underline; }
.inline-form { display: inline; margin: 0; }
.actions { display: flex; gap: 6px; flex-wrap: wrap; align-items: center; }

/* --- формы --- */
.field { display: block; margin-bottom: 16px; }
.field__label { display: block; font-weight: 600; font-size: 14px; margin-bottom: 6px; }
.field__hint { display: block; color: var(--muted); font-size: 13px; margin-top: 5px; }
input[type=text], input[type=password], input[type=number], input[type=date], input[type=search], select, textarea {
  width: 100%; padding: 10px 12px; border: 1px solid var(--border-strong); border-radius: var(--radius-sm);
  background: var(--input); color: var(--text); font: inherit; transition: border-color .15s, box-shadow .15s;
}
textarea { resize: vertical; min-height: 90px; font-family: var(--mono); font-size: 13px; }
input:focus, select:focus, textarea:focus { outline: none; border-color: var(--primary); box-shadow: 0 0 0 3px rgba(79, 70, 229, .15); }
.check { display: flex; gap: 9px; align-items: flex-start; margin-bottom: 12px; cursor: pointer; }
.check input { margin-top: 4px; width: 16px; height: 16px; accent-color: var(--primary); flex: none; }
.checks { display: grid; grid-template-columns: repeat(auto-fill, minmax(190px, 1fr)); gap: 4px 16px; }
.form-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 0 18px; }
.form-grid .span-2 { grid-column: 1 / -1; }
.form-actions { display: flex; gap: 10px; flex-wrap: wrap; margin-top: 6px; }
.filters { display: flex; flex-wrap: wrap; gap: 10px; align-items: flex-end; }
.filters .field { margin: 0; min-width: 150px; flex: 1 1 150px; }
.filters .field__label { font-size: 12.5px; color: var(--muted); font-weight: 500; }
.filters .field--wide { flex-basis: 100%; }
.filters .btn { flex: none; }

/* --- статусы и сообщения --- */
.badge {
  display: inline-block; padding: 2px 9px; border-radius: 999px; font-size: 12.5px; font-weight: 600;
  white-space: nowrap; background: var(--surface-2); color: var(--muted); border: 1px solid var(--border);
}
.badge--ok { background: var(--ok-50); color: var(--ok); border-color: var(--ok-200); }
.badge--err { background: var(--err-50); color: var(--err); border-color: var(--err-200); }
.badge--warn { background: var(--warn-50); color: var(--warn); border-color: var(--warn-200); }
.badge--info { background: var(--info-50); color: var(--info); border-color: var(--info-200); }
.chip { display: inline-block; padding: 1px 7px; border-radius: 999px; background: var(--ok-50); color: var(--ok); font-size: 11.5px; font-weight: 600; }
.notice { border-radius: var(--radius-sm); padding: 12px 14px; margin-bottom: 16px; border: 1px solid; font-size: 14px; }
.notice ol, .notice ul { margin: 6px 0 0; padding-left: 20px; }
.notice li + li { margin-top: 3px; }
.notice--warn { background: var(--warn-50); border-color: var(--warn-200); color: var(--warn-900); }
.notice--err { background: var(--err-50); border-color: var(--err-200); color: var(--err-900); }
.notice--info { background: var(--info-50); border-color: var(--info-200); color: var(--info-900); }
.notice--ok { background: var(--ok-50); border-color: var(--ok-200); color: var(--ok-900); }
.flash { border-radius: var(--radius-sm); padding: 12px 16px; margin-bottom: 16px; border: 1px solid; font-weight: 500; }
.flash--ok { background: var(--ok-50); border-color: var(--ok-200); color: var(--ok-900); }
.flash--err { background: var(--err-50); border-color: var(--err-200); color: var(--err-900); }
.flash--warn { background: var(--warn-50); border-color: var(--warn-200); color: var(--warn-900); }
.banner { display: flex; justify-content: space-between; align-items: center; gap: 14px; flex-wrap: wrap; }
.banner form { margin: 0; }

/* --- таблицы --- */
.table-wrap { overflow-x: auto; -webkit-overflow-scrolling: touch; }
.table { width: 100%; border-collapse: collapse; font-size: 14px; }
.table th {
  text-align: left; font-weight: 600; color: var(--muted); font-size: 12.5px; text-transform: uppercase; letter-spacing: .03em;
  padding: 10px 12px; border-bottom: 1px solid var(--border); background: var(--surface-2); white-space: nowrap;
}
.table td { padding: 11px 12px; border-bottom: 1px solid var(--border); vertical-align: top; }
.table tr:last-child td { border-bottom: 0; }
.table tbody tr:hover td { background: var(--row-hover); }
.table .muted { font-size: 13px; }
.table-note { max-width: 320px; color: var(--muted); font-size: 13px; }
.empty { text-align: center; color: var(--muted); padding: 34px 16px; }
.pager { display: flex; justify-content: center; align-items: center; gap: 12px; padding: 14px; }
.pager__info { color: var(--muted); font-size: 14px; }

.kv { display: grid; grid-template-columns: minmax(140px, 220px) 1fr; gap: 8px 16px; margin: 0; }
.kv dt { color: var(--muted); }
.kv dd { margin: 0; word-break: break-word; }
.list-plain { list-style: none; margin: 0; padding: 0; }
.list-plain li { display: flex; justify-content: space-between; gap: 12px; padding: 7px 0; border-bottom: 1px dashed var(--border); }
.list-plain li:last-child { border-bottom: 0; }

/* --- активация --- */
.activate-grid { display: grid; grid-template-columns: minmax(0, 1fr) 340px; gap: 20px; align-items: start; }
.usage { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius-sm); padding: 8px 14px; font-size: 14px; }
.usage__label { color: var(--muted); margin-right: 6px; }
.tariffs { display: grid; grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); gap: 12px; margin-bottom: 26px; }
.tariff {
  position: relative; text-align: left; display: flex; flex-direction: column; gap: 3px;
  padding: 16px; border-radius: 12px; border: 2px solid var(--border); background: var(--surface);
  font: inherit; color: inherit; cursor: pointer; transition: border-color .15s, box-shadow .15s, transform .1s;
}
.tariff:hover:not(:disabled) { border-color: #a5b4fc; }
.tariff:active:not(:disabled) { transform: scale(.99); }
.tariff.is-selected { border-color: var(--primary); box-shadow: 0 0 0 4px rgba(79, 70, 229, .12); background: var(--tariff-selected); }
.tariff.is-selected::after {
  content: "✓"; position: absolute; top: 10px; right: 12px; width: 22px; height: 22px; border-radius: 50%;
  background: var(--primary); color: #fff; font-size: 13px; display: grid; place-items: center; font-weight: 700;
}
.tariff:disabled { cursor: not-allowed; opacity: .6; background: var(--surface-2); }
.tariff__name { font-size: 20px; font-weight: 800; letter-spacing: -.01em; }
.tariff__title { font-size: 13.5px; color: var(--muted); }
.tariff__desc { font-size: 12.5px; color: var(--muted); }
.tariff__off { font-size: 12px; color: var(--warn); font-weight: 600; margin-top: 4px; }
.segmented { display: inline-flex; background: var(--surface-2); border: 1px solid var(--border); border-radius: 11px; padding: 4px; margin-bottom: 16px; flex-wrap: wrap; }
.segmented__btn {
  border: 0; background: transparent; padding: 8px 14px; border-radius: 8px; font: inherit; font-weight: 600;
  color: var(--muted); cursor: pointer; display: inline-flex; gap: 7px; align-items: center;
}
.segmented__btn.is-active { background: var(--surface); color: var(--text); box-shadow: 0 1px 3px rgba(15, 23, 42, .1); }
.session-preview { margin: -6px 0 14px; padding: 9px 12px; border-radius: var(--radius-sm); font-size: 13.5px; background: var(--info-50); color: var(--info-900); }
.session-preview.is-good { background: var(--ok-50); color: var(--ok-900); }
.session-preview.is-bad { background: var(--err-50); color: var(--err-900); }
.guide__steps { counter-reset: step; list-style: none; padding: 0; margin: 0 0 14px; }
.guide__steps li { counter-increment: step; position: relative; padding-left: 38px; margin-bottom: 16px; font-size: 14px; }
.guide__steps li::before {
  content: counter(step, decimal-leading-zero); position: absolute; left: 0; top: 0; width: 28px; height: 28px; border-radius: 8px;
  background: var(--text); color: #fff; font-size: 12px; font-weight: 700; display: grid; place-items: center;
}
.guide__steps a { display: inline-block; margin-top: 4px; font-weight: 600; }

.progress { max-width: 640px; margin: 0 auto 20px; text-align: center; padding: 32px 26px; }
.progress h2 { margin-bottom: 4px; }
.steps { display: flex; justify-content: center; gap: 8px; margin: 22px 0 14px; flex-wrap: wrap; }
.step {
  display: flex; align-items: center; gap: 7px; padding: 7px 12px; border-radius: 999px; font-size: 13.5px;
  background: var(--surface-2); color: var(--muted); border: 1px solid var(--border);
}
.step::before { content: ""; width: 8px; height: 8px; border-radius: 50%; background: var(--border-strong); }
.step.is-active { color: var(--primary-600); border-color: var(--primary-200); background: var(--primary-50); }
.step.is-active::before { background: var(--primary); animation: pulse 1s infinite alternate; }
.step.is-done { color: var(--ok); border-color: var(--ok-200); background: var(--ok-50); }
.step.is-done::before { background: var(--ok); }
@keyframes pulse { from { opacity: .35; } to { opacity: 1; } }
.spinner {
  width: 42px; height: 42px; margin: 0 auto 14px; border-radius: 50%;
  border: 4px solid var(--primary-50); border-top-color: var(--primary); animation: spin .9s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }
.result { border-radius: 12px; padding: 22px; margin-top: 6px; text-align: center; }
.result__icon { font-size: 40px; line-height: 1; margin-bottom: 8px; }
.result h3 { margin: 0 0 6px; font-size: 20px; }
.result--ok { background: var(--ok-50); color: var(--ok-900); }
.result--warn { background: var(--warn-50); color: var(--warn-900); }
.result--err { background: var(--err-50); color: var(--err-900); }
.result__service { margin-top: 10px; font-size: 13px; opacity: .85; word-break: break-word; }

/* --- окно подтверждения --- */
.modal { position: fixed; inset: 0; z-index: 50; display: grid; place-items: center; padding: 16px; }
.modal__backdrop { position: absolute; inset: 0; background: rgba(15, 23, 42, .55); }
.modal__dialog {
  position: relative; width: min(480px, 100%); background: var(--surface); border-radius: 16px;
  padding: 24px; box-shadow: 0 24px 60px rgba(15, 23, 42, .3); animation: pop .15s ease-out;
}
@keyframes pop { from { transform: scale(.96); opacity: 0; } to { transform: none; opacity: 1; } }
.modal__title { font-size: 20px; margin: 0 0 4px; }
.modal__rows { margin: 16px 0; border: 1px solid var(--border); border-radius: 12px; overflow: hidden; }
.modal__row { display: flex; justify-content: space-between; gap: 16px; padding: 10px 14px; border-bottom: 1px solid var(--border); font-size: 14.5px; }
.modal__row:last-child { border-bottom: 0; }
.modal__row span:first-child { color: var(--muted); flex: none; }
.modal__row b { text-align: right; word-break: break-all; }
.modal__actions { display: flex; gap: 10px; justify-content: flex-end; flex-wrap: wrap; }

/* --- вход --- */
.auth { min-height: 100vh; display: grid; place-items: center; padding: 20px; }
.auth__card { width: min(400px, 100%); }
.auth__brand { display: flex; justify-content: center; margin-bottom: 18px; font-size: 18px; }

/* --- справка --- */
.prose { max-width: 820px; }
.prose h2 { margin-top: 30px; }
.prose li { margin-bottom: 6px; }
.prose table { margin: 8px 0 14px; }

details.more summary { cursor: pointer; color: var(--primary); font-weight: 600; margin: 4px 0 10px; }

/* --- выбор темы в «Настройках» --- */
.themes { display: grid; grid-template-columns: repeat(2, minmax(0, 170px)); gap: 12px; margin-bottom: 10px; }
.theme-option {
  display: grid; gap: 9px; padding: 10px; border: 2px solid var(--border); border-radius: 12px;
  background: var(--surface); cursor: pointer; transition: border-color .15s, box-shadow .15s;
}
.theme-option:hover { border-color: var(--primary-200); }
.theme-option:has(input:checked) { border-color: var(--primary); box-shadow: 0 0 0 4px var(--primary-50); }
.theme-option__label { display: flex; align-items: center; gap: 8px; font-weight: 600; }
.theme-option__label input { margin: 0; width: 16px; height: 16px; accent-color: var(--primary); }
.theme-option__preview { display: grid; align-content: start; gap: 6px; height: 64px; padding: 10px; border-radius: 8px; border: 1px solid; }
.theme-option__preview i { display: block; height: 8px; border-radius: 4px; }
.theme-option__preview i:first-child { width: 45%; background: #6366f1; }
.theme-option__preview i:nth-child(2) { width: 85%; }
.theme-option__preview i:nth-child(3) { width: 62%; }
.theme-option__preview--light { background: #f3f5fa; border-color: #e2e8f0; }
.theme-option__preview--light i:not(:first-child) { background: #cbd5e1; }
.theme-option__preview--dark { background: #0b1120; border-color: #243049; }
.theme-option__preview--dark i:not(:first-child) { background: #33415e; }

@media (max-width: 980px) {
  .activate-grid { grid-template-columns: 1fr; }
  .grid-2, .grid-3 { grid-template-columns: 1fr; }
}
@media (max-width: 720px) {
  .topbar__inner { flex-wrap: wrap; gap: 6px 12px; padding: 8px 16px; }
  .nav { order: 3; flex-basis: 100%; }
  .userbox { margin-left: auto; }
  .container { padding: 18px 16px 48px; }
  .card:not(.card--flush) { padding: 18px 16px; }
  .card--flush > .card__head { padding: 16px 16px 0; }
  .segmented { display: flex; }
  .segmented__btn { flex: 1; flex-direction: column; gap: 2px; justify-content: center; }
  h1 { font-size: 22px; }
  .form-grid { grid-template-columns: 1fr; }
  .kv { grid-template-columns: 1fr; gap: 2px; }
  .kv dd { margin-bottom: 8px; }
  .modal__actions .btn { flex: 1; }
}
