:root {
  --bg: #f4f5f7;
  --surface: #ffffff;
  --surface-2: #f0f2f5;
  --text: #15181d;
  --muted: #687080;
  --border: #e2e5ea;
  --accent: #16a34a;
  --accent-ink: #ffffff;
  --main: #16a34a;
  --main-soft: #e8f6ec;
  --reserve: #d97706;
  --reserve-soft: #fdf3e2;
  --ok: #15803d;   --ok-bg: #dcfce7;
  --warn: #b45309; --warn-bg: #fef3c7;
  --bad: #b91c1c;  --bad-bg: #fee2e2;
  --radius: 14px;
  --shadow: 0 1px 2px rgba(16, 24, 40, .05), 0 4px 16px rgba(16, 24, 40, .04);
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0f1115;
    --surface: #171a20;
    --surface-2: #1f232b;
    --text: #e8eaee;
    --muted: #8b93a3;
    --border: #2a2f39;
    --accent: #22c55e;
    --accent-ink: #06120a;
    --main: #22c55e;
    --main-soft: #13251a;
    --reserve: #f59e0b;
    --reserve-soft: #2a2010;
    --ok: #4ade80;   --ok-bg: #12301d;
    --warn: #fbbf24; --warn-bg: #33270c;
    --bad: #f87171;  --bad-bg: #3a1516;
    --shadow: none;
    color-scheme: dark;
  }
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 16px/1.5 system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
}
a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }
h1, h2, h3 { line-height: 1.2; margin: 0; }
h1 { font-size: 1.6rem; letter-spacing: -.01em; }
h2 { font-size: 1.2rem; }
h3 { font-size: 1.05rem; }
code, .mono, pre { font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace; font-size: .85em; }
.muted { color: var(--muted); }
.small { font-size: .875rem; }
.empty { padding: 24px 0; }
.wrap { max-width: 1040px; margin: 0 auto; padding: 0 16px; }

/* ---------- шапка */
.topbar { background: var(--surface); border-bottom: 1px solid var(--border); position: sticky; top: 0; z-index: 10; }
.topbar-in { display: flex; align-items: center; justify-content: space-between; height: 56px; gap: 12px; }
.brand { font-weight: 700; color: var(--text); display: flex; align-items: center; gap: 10px; font-size: 1.05rem; white-space: nowrap; }
.brand:hover { text-decoration: none; }
.brand-mark { width: 20px; height: 20px; border-radius: 7px; background: var(--accent); flex: 0 0 auto; }
.nav { display: flex; align-items: center; gap: 4px; overflow-x: auto; }
.nav a, .nav .link { color: var(--muted); padding: 6px 10px; border-radius: 8px; font-size: .95rem; white-space: nowrap; }
.nav a:hover, .nav .link:hover { color: var(--text); background: var(--surface-2); text-decoration: none; }
.nav a.on { color: var(--text); background: var(--surface-2); }
.nav a.btn { color: var(--accent-ink); background: var(--accent); }
.inline { display: inline; margin: 0; }
.link { background: none; border: 0; font: inherit; cursor: pointer; }

main.wrap { padding-top: 28px; padding-bottom: 40px; min-height: 60vh; }
.foot { color: var(--muted); font-size: .9rem; padding-bottom: 32px; }

/* ---------- кнопки */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  background: var(--accent); color: var(--accent-ink); border: 1px solid transparent;
  padding: 10px 16px; border-radius: 10px; font-family: inherit; font-weight: 600; font-size: .95rem; line-height: 1.2; cursor: pointer; white-space: nowrap;
}
.btn:hover { filter: brightness(1.06); text-decoration: none; }
.btn-sm { padding: 6px 12px; font-size: .85rem; border-radius: 8px; }
.btn-block { width: 100%; }
.btn-ghost { background: transparent; color: var(--text); border-color: var(--border); }
.btn-ghost:hover { background: var(--surface-2); }
.btn-danger { background: transparent; color: var(--bad); border-color: var(--bad); }
.btn.copied { background: var(--ok); color: #fff; }

/* ---------- заголовки страниц */
.hero {
  display: flex; align-items: center; justify-content: space-between; gap: 16px; flex-wrap: wrap;
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius);
  padding: 22px 24px; margin-bottom: 24px; box-shadow: var(--shadow);
}
.hero p { margin: 6px 0 0; }
.page-title { display: flex; align-items: baseline; justify-content: space-between; gap: 12px; flex-wrap: wrap; margin-bottom: 18px; }
.page-title.sub { margin-top: 36px; }
.section-h { margin: 32px 0 14px; }

.flash { padding: 12px 16px; border-radius: 10px; margin-bottom: 18px; border: 1px solid; }
.flash-ok { background: var(--ok-bg); border-color: transparent; color: var(--text); }
.flash-warn { background: var(--warn-bg); border-color: transparent; color: var(--text); }
.flash-err { background: var(--bad-bg); border-color: transparent; color: var(--bad); }
.flash pre { background: var(--surface); color: var(--text); padding: 10px 12px; border-radius: 8px; white-space: pre-wrap; word-break: break-all; margin: 8px 0; }

.personal {
  background: var(--surface); border: 1px solid var(--border); border-left: 4px solid var(--accent);
  border-radius: var(--radius); padding: 14px 18px; margin-bottom: 20px;
}

/* ---------- блоки VPN */
.svc-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(min(100%, 420px), 1fr)); gap: 18px; }
.svc {
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius);
  padding: 20px; box-shadow: var(--shadow); position: relative; overflow: hidden; min-width: 0;
}
.svc::before { content: ""; position: absolute; inset: 0 0 auto 0; height: 4px; background: var(--c); }
.svc-main { --c: var(--main); --soft: var(--main-soft); }
.svc-reserve { --c: var(--reserve); --soft: var(--reserve-soft); }
.svc-head { display: flex; justify-content: space-between; align-items: flex-start; gap: 10px; flex-wrap: wrap; margin-bottom: 16px; }
.svc-kicker { font-size: .75rem; text-transform: uppercase; letter-spacing: .08em; color: var(--c); font-weight: 700; margin-bottom: 2px; }
.svc-head h2 { font-size: 1.4rem; }
.svc-note { margin-top: 14px; padding: 12px 14px; background: var(--soft); border-radius: 10px; font-size: .95rem; }

.status { display: inline-block; font-size: .8rem; font-weight: 600; padding: 4px 10px; border-radius: 999px; white-space: nowrap; }
.status-ok { color: var(--ok); background: var(--ok-bg); }
.status-warn { color: var(--warn); background: var(--warn-bg); }
.status-bad { color: var(--bad); background: var(--bad-bg); }
.status-none { color: var(--muted); background: var(--surface-2); }

.key { display: flex; gap: 16px; align-items: flex-start; padding: 14px 0; border-top: 1px solid var(--border); }
.key:first-of-type { border-top: 0; padding-top: 0; }
.qr { flex: 0 0 148px; width: 148px; aspect-ratio: 1; background: #fff; border-radius: 10px; padding: 2px; border: 1px solid var(--border); }
.qr svg { display: block; width: 100%; height: 100%; }
.qr-err { display: block; font-size: .75rem; color: #b91c1c; padding: 10px; }
.key-body { min-width: 0; flex: 1; }
.key-label { font-weight: 700; margin-bottom: 2px; }
.key-hint { font-size: .8rem; color: var(--muted); margin-bottom: 8px; }
.key-text {
  display: block; background: var(--surface-2); border-radius: 8px; padding: 8px 10px;
  word-break: break-all; max-height: 5.6em; overflow: auto; font-size: .78rem; line-height: 1.4; user-select: all;
}
.key-actions { display: flex; gap: 8px; margin-top: 10px; flex-wrap: wrap; }

@media (max-width: 520px) {
  .key { flex-direction: column; align-items: stretch; }
  .qr { width: min(260px, 100%); flex-basis: auto; margin: 0 auto; }
  .svc { padding: 16px; }
}

.qr-overlay {
  position: fixed; inset: 0; background: rgba(0, 0, 0, .8); z-index: 100;
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 16px; cursor: zoom-out; padding: 16px;
}
.qr-big { background: #fff; padding: 12px; border-radius: 16px; width: min(90vw, 80vh, 560px); aspect-ratio: 1; }
.qr-big svg { width: 100%; height: 100%; display: block; }
.qr-close { color: #ddd; font-size: .9rem; }

.help { margin-top: 20px; background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 14px 18px; }
.help summary { cursor: pointer; font-weight: 600; }
.help > div { margin-top: 10px; }

/* ---------- новости */
.news-list { display: grid; gap: 14px; }
.news { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 18px 20px; box-shadow: var(--shadow); }
.news.pinned { border-color: var(--accent); }
.news-meta { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; font-size: .8rem; color: var(--muted); margin-bottom: 6px; }
.news h3 { margin-bottom: 6px; }
.news-body { overflow-wrap: anywhere; }
.tag { display: inline-block; font-size: .72rem; font-weight: 600; padding: 2px 8px; border-radius: 999px; background: var(--surface-2); color: var(--muted); }
.tag-pin { background: var(--main-soft); color: var(--accent); }

/* ---------- формы */
.auth { max-width: 400px; margin: 24px auto; background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 28px; box-shadow: var(--shadow); }
.auth h1 { margin-bottom: 6px; }
.auth > p { margin: 0 0 18px; }
.form { display: grid; gap: 14px; }
.form label { display: grid; gap: 6px; font-size: .9rem; font-weight: 600; color: var(--text); }
.form input:not([type=checkbox]), .form textarea, .form select, .toolbar input {
  width: 100%; font-family: inherit; font-size: 1rem; line-height: 1.4; color: var(--text); background: var(--surface);
  border: 1px solid var(--border); border-radius: 10px; padding: 10px 12px; min-width: 0;
}
.form textarea.mono { font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace; font-size: .85rem; }
.form input:focus, .form textarea:focus, .form select:focus, .toolbar input:focus { outline: 2px solid var(--accent); outline-offset: -1px; border-color: transparent; }
.form label.check { display: flex; align-items: center; gap: 8px; font-weight: 500; }
.form label.check input { width: 18px; height: 18px; accent-color: var(--accent); }
.form .row { display: grid; grid-template-columns: repeat(auto-fit, minmax(min(100%, 220px), 1fr)); gap: 14px; align-items: end; }
.input-group { display: flex; gap: 6px; }
.input-group .btn { flex: 0 0 auto; }
.form-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(min(100%, 440px), 1fr)); gap: 18px; align-items: start; }
.form-actions { display: flex; gap: 14px; align-items: center; flex-wrap: wrap; grid-column: 1 / -1; }
.card, fieldset.card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 18px 20px; margin: 0; display: grid; gap: 14px; box-shadow: var(--shadow); min-width: 0; }
fieldset.card legend { float: left; width: 100%; padding: 0; font-weight: 700; font-size: 1.05rem; margin-bottom: 2px; }
fieldset.card legend + * { clear: both; }
fieldset.svc-edit { border-top: 4px solid var(--c); }
.danger-zone { margin-top: 28px; padding-top: 18px; border-top: 1px dashed var(--border); }

/* ---------- админка */
.tabs { display: flex; gap: 4px; border-bottom: 1px solid var(--border); margin-bottom: 22px; overflow-x: auto; }
.tabs a { padding: 10px 14px; color: var(--muted); border-bottom: 2px solid transparent; margin-bottom: -1px; white-space: nowrap; }
.tabs a:hover { color: var(--text); text-decoration: none; }
.tabs a.on { color: var(--text); border-color: var(--accent); font-weight: 600; }
.toolbar { display: flex; gap: 10px; margin-bottom: 16px; }
.toolbar input { flex: 1; }
.table-wrap { overflow-x: auto; background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); box-shadow: var(--shadow); }
.table { width: 100%; border-collapse: collapse; font-size: .92rem; }
.table th { text-align: left; font-size: .78rem; text-transform: uppercase; letter-spacing: .04em; color: var(--muted); font-weight: 600; padding: 12px 14px; border-bottom: 1px solid var(--border); white-space: nowrap; }
.table td { padding: 12px 14px; border-bottom: 1px solid var(--border); vertical-align: top; }
.table tr:last-child td { border-bottom: 0; }
.table tr.off td { opacity: .55; }
.admin-news { display: flex; gap: 12px; align-items: flex-start; margin-bottom: 12px; }
.admin-news-main { flex: 1; min-width: 0; }
.admin-news-actions { display: grid; gap: 6px; }
.admin-news-actions form { margin: 0; }
@media (max-width: 600px) {
  .admin-news { flex-direction: column; }
  .admin-news-actions { display: flex; }
  .toolbar { flex-direction: column; }
}

/* ---------- v2: обновления, инструкции, аккаунт */
.svc.is-new { border-color: var(--c); box-shadow: 0 0 0 3px color-mix(in srgb, var(--c) 25%, transparent), var(--shadow); animation: glow 2.4s ease-in-out 3; }
@keyframes glow { 50% { box-shadow: 0 0 0 7px color-mix(in srgb, var(--c) 12%, transparent); } }
.new-banner {
  display: flex; align-items: center; justify-content: space-between; gap: 12px; flex-wrap: wrap;
  background: var(--soft); border: 1px solid var(--c); border-radius: 10px; padding: 10px 12px; margin: -4px 0 16px; font-size: .92rem;
}
.new-banner strong { color: var(--c); }
.svc-updated { margin-top: 12px; font-size: .8rem; color: var(--muted); text-align: right; }
.dot-new { color: var(--warn); font-weight: 600; }

.guide-link {
  display: flex; align-items: center; gap: 14px; margin-top: 18px; padding: 16px 18px; color: var(--text);
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); box-shadow: var(--shadow);
}
.guide-link:hover { text-decoration: none; border-color: var(--accent); }
.guide-link > span:nth-child(2) { display: grid; flex: 1; }
.guide-ico { width: 36px; height: 36px; border-radius: 10px; background: var(--main-soft); color: var(--accent); display: grid; place-items: center; font-weight: 800; flex: 0 0 auto; }
.guide-arrow { color: var(--muted); font-size: 1.2rem; }

.doc { max-width: 760px; margin: 0 auto; background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 24px 28px; box-shadow: var(--shadow); }
.doc h1 { margin-top: 4px; }
.doc-date { margin: 6px 0 18px; }
.doc-body { overflow-wrap: anywhere; }
.doc-body h2 { font-size: 1.25rem; margin: 26px 0 10px; }
.doc-body h3 { font-size: 1.08rem; margin: 20px 0 8px; }
.doc-body h4 { font-size: 1rem; margin: 16px 0 6px; }
.doc-body > :first-child { margin-top: 0; }
.doc-body p { margin: 0 0 12px; }
.doc-body ul, .doc-body ol { margin: 0 0 12px; padding-left: 22px; }
.doc-body li { margin: 3px 0; }
.doc-body code { background: var(--surface-2); padding: 1px 6px; border-radius: 6px; }
.doc-body figure { margin: 14px 0 18px; }
.doc-body img { display: block; max-width: 100%; max-height: 640px; height: auto; border-radius: 10px; border: 1px solid var(--border); }
.doc-body figcaption { font-size: .85rem; color: var(--muted); margin-top: 6px; }
.callout { background: var(--warn-bg); border-left: 4px solid var(--warn); border-radius: 8px; padding: 10px 14px; margin: 0 0 12px; }
@media (max-width: 520px) { .doc { padding: 18px 16px; } }

.split { display: flex; justify-content: space-between; gap: 12px; }
.card h2 { font-size: 1.1rem; }
.steps { margin: 0; padding-left: 20px; display: grid; gap: 4px; }
.btn-row { display: flex; gap: 8px; flex-wrap: wrap; }
.btn-row form { margin: 0; }
details summary { cursor: pointer; }
details.small[open] summary { margin-bottom: 8px; }
.bot-help { font-size: .9rem; line-height: 1.6; }
.bot-help code, .md-help code { background: var(--surface-2); padding: 1px 5px; border-radius: 5px; }

.guide-list { display: grid; gap: 10px; }
.guide-row { color: var(--text); display: flex; justify-content: space-between; align-items: center; gap: 12px; flex-wrap: wrap; }
.guide-row:hover { text-decoration: none; border-color: var(--accent); }
.guide-editor { display: grid; grid-template-columns: repeat(auto-fit, minmax(min(100%, 440px), 1fr)); gap: 18px; align-items: start; }
.guide-preview-wrap { position: sticky; top: 72px; max-height: calc(100vh - 90px); overflow: auto; }
.upload-bar { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; }
.upload-btn { cursor: pointer; }
.form label.upload-btn { display: inline-flex; font-weight: 600; }
@media (max-width: 600px) {
  .topbar-in { flex-wrap: wrap; height: auto; padding-top: 8px; padding-bottom: 6px; row-gap: 4px; }
  .nav { width: 100%; margin: 0 -10px; }
}
