:root {
  --bg: #f4f5f8;
  --surface: #ffffff;
  --surface-2: #f0f2f6;
  --border: #e1e4ea;
  --text: #171a21;
  --muted: #6a7180;
  --accent: #3b5bdb;
  --accent-text: #ffffff;
  --accent-soft: #e7ecff;
  --danger: #d6336c;
  --danger-soft: #fdebf1;
  --ok: #2b8a3e;
  --ok-soft: #e6f6ea;
  --amnezia: #7048e8;
  --amnezia-soft: #efeaff;
  --wg: #c2410c;
  --wg-soft: #fff0e6;
  --radius: 12px;
  --shadow: 0 1px 2px rgba(16, 24, 40, .05), 0 1px 3px rgba(16, 24, 40, .06);
  --mono: ui-monospace, "Cascadia Code", "JetBrains Mono", Consolas, monospace;
  color-scheme: light;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0f1115;
    --surface: #171a21;
    --surface-2: #1e222b;
    --border: #2a2f3a;
    --text: #e8eaef;
    --muted: #8d94a3;
    --accent: #6f8cff;
    --accent-text: #0f1115;
    --accent-soft: #1e2645;
    --danger: #ff6b9a;
    --danger-soft: #3a1a26;
    --ok: #69db7c;
    --ok-soft: #173020;
    --amnezia: #b197fc;
    --amnezia-soft: #2a2145;
    --wg: #ffa36b;
    --wg-soft: #3a2416;
    --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: 15px/1.5 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
}

h1, h2, h3 { margin: 0; line-height: 1.25; }
h1 { font-size: 1.6rem; font-weight: 700; letter-spacing: -.01em; }
h2 { font-size: 1.05rem; font-weight: 600; margin-bottom: 14px; }
h3 { font-size: 1rem; font-weight: 600; }
a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }

.muted { color: var(--muted); }
.small { font-size: .85rem; }
.inline { display: inline; margin: 0; }
[hidden] { display: none !important; }

/* ---- layout ---- */
.container { max-width: 1120px; margin: 0 auto; padding: 28px 16px 64px; }
.page-head {
  display: flex; align-items: flex-end; justify-content: space-between;
  gap: 16px; margin-bottom: 22px;
}
.page-head p { margin: 6px 0 0; }
.grid-2 { display: grid; grid-template-columns: minmax(0, 1.4fr) minmax(0, 1fr); gap: 20px; align-items: start; }
.grid-2.wide-left { grid-template-columns: minmax(0, 1.6fr) minmax(0, 1fr); }
.stack { display: flex; flex-direction: column; gap: 14px; }
.stack-lg { display: flex; flex-direction: column; gap: 20px; }
.row { display: flex; gap: 10px; align-items: flex-end; }
.row > * { min-width: 0; }
.row input { flex: 1; }
.grow { flex: 1; }

@media (max-width: 860px) {
  .grid-2, .grid-2.wide-left { grid-template-columns: 1fr; }
}

/* ---- top bar ---- */
.topbar {
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  position: sticky; top: 0; z-index: 10;
}
.topbar-inner {
  max-width: 1120px; margin: 0 auto; padding: 0 16px;
  height: 58px; display: flex; align-items: center; justify-content: space-between; gap: 12px;
}
.brand { display: flex; align-items: center; gap: 10px; font-weight: 700; color: var(--text); white-space: nowrap; }
.brand:hover { text-decoration: none; }
.brand-mark {
  width: 22px; height: 22px; border-radius: 7px; display: inline-block; flex: none;
  background: linear-gradient(135deg, var(--accent), var(--amnezia));
}
.brand-mark.big { width: 44px; height: 44px; border-radius: 13px; }
.nav { display: flex; align-items: center; gap: 4px; overflow-x: auto; }
.nav a, .nav .link {
  color: var(--muted); padding: 7px 11px; border-radius: 8px; white-space: nowrap;
  font: inherit; font-weight: 500;
}
.nav a:hover, .nav .link:hover { background: var(--surface-2); color: var(--text); text-decoration: none; }
.nav a.active { color: var(--text); background: var(--surface-2); }
.link { background: none; border: 0; cursor: pointer; }

@media (max-width: 560px) {
  .brand { font-size: 0; gap: 0; }
  .nav a, .nav .link { padding: 7px 8px; font-size: .9rem; }
}

/* ---- cards ---- */
.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 20px;
  min-width: 0;
}
.card.narrow { max-width: 460px; }
.card-head { display: flex; align-items: center; justify-content: space-between; gap: 12px; margin-bottom: 14px; }
.card-head h2 { margin: 0; }
.card.empty { text-align: center; padding: 48px 20px; }
.card.empty h2, .card.empty h1 { margin-bottom: 6px; }
.danger-zone { border-color: color-mix(in srgb, var(--danger) 35%, var(--border)); }

.stat {
  display: flex; flex-direction: column; align-items: flex-end;
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius);
  padding: 10px 18px; box-shadow: var(--shadow);
}
.stat-num { font-size: 1.7rem; font-weight: 700; line-height: 1.1; font-variant-numeric: tabular-nums; }
.stat-label { color: var(--muted); font-size: .85rem; }

.crumb { display: inline-block; margin-bottom: 10px; color: var(--muted); font-size: .9rem; }

/* ---- forms ---- */
label { display: flex; flex-direction: column; gap: 6px; font-weight: 500; font-size: .92rem; }
label.check { flex-direction: row; align-items: center; gap: 9px; font-weight: 400; }
input:not([type=checkbox]):not([type=file]), select, textarea {
  width: 100%;
  font: inherit; font-weight: 400; color: var(--text);
  background: var(--surface); border: 1px solid var(--border); border-radius: 9px;
  padding: 9px 11px;
}
textarea { font-family: var(--mono); font-size: .82rem; resize: vertical; }
input:focus, select:focus, textarea:focus { outline: 2px solid var(--accent); outline-offset: -1px; border-color: transparent; }
input[type=checkbox] { width: 17px; height: 17px; accent-color: var(--accent); }
input[type=file] { font: inherit; font-weight: 400; color: var(--muted); }
input.search { max-width: 220px; padding: 7px 10px; }

.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  font: inherit; font-weight: 500; font-size: .9rem;
  padding: 8px 14px; border-radius: 9px; cursor: pointer; white-space: nowrap;
  background: var(--surface-2); color: var(--text); border: 1px solid var(--border);
}
.btn:hover { text-decoration: none; border-color: var(--muted); }
.btn.primary { background: var(--accent); color: var(--accent-text); border-color: var(--accent); }
.btn.primary:hover { filter: brightness(1.08); }
.btn.danger { background: var(--danger); color: #fff; border-color: var(--danger); }
.btn.danger-ghost { color: var(--danger); background: transparent; }
.btn.danger-ghost:hover { background: var(--danger-soft); border-color: var(--danger); }
.btn.done { color: var(--ok); border-color: var(--ok); background: var(--ok-soft); }
.btn.wide { width: 100%; padding: 11px; }

/* ---- flash ---- */
.flash {
  padding: 11px 14px; border-radius: 10px; margin-bottom: 16px; font-weight: 500;
  background: var(--ok-soft); color: var(--ok); border: 1px solid color-mix(in srgb, var(--ok) 30%, transparent);
}
.flash-error { background: var(--danger-soft); color: var(--danger); border-color: color-mix(in srgb, var(--danger) 30%, transparent); }

/* ---- tokens ---- */
.token-list { display: flex; flex-direction: column; gap: 14px; }
.token {
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius);
  padding: 16px; box-shadow: var(--shadow); min-width: 0;
}
.card .token { box-shadow: none; background: var(--surface-2); }
.token-head { display: flex; align-items: center; gap: 10px; margin-bottom: 12px; flex-wrap: wrap; }
.token-title { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.token-value {
  margin: 0 0 12px; padding: 12px; max-height: 150px; overflow: auto;
  font: .8rem/1.5 var(--mono); white-space: pre-wrap; word-break: break-all;
  background: var(--bg); border: 1px solid var(--border); border-radius: 9px;
}
.token-actions { display: flex; gap: 8px; flex-wrap: wrap; }
.qr { margin-top: 14px; }
.qr img {
  display: block; width: 260px; max-width: 100%; height: auto;
  background: #fff; padding: 10px; border-radius: 10px;
}

.badge {
  font-size: .75rem; font-weight: 600; padding: 3px 9px; border-radius: 999px; white-space: nowrap;
}
.badge-amnezia { color: var(--amnezia); background: var(--amnezia-soft); }
.badge-wireguard { color: var(--wg); background: var(--wg-soft); }

details.edit { margin-top: 12px; }
details.edit summary { cursor: pointer; color: var(--muted); font-size: .9rem; font-weight: 500; }
details.edit[open] summary { margin-bottom: 12px; }

/* ---- table ---- */
.table-wrap { overflow-x: auto; margin: 0 -20px -20px; }
table { width: 100%; border-collapse: collapse; }
th, td { text-align: left; padding: 11px 20px; border-top: 1px solid var(--border); vertical-align: middle; }
th { font-size: .78rem; text-transform: uppercase; letter-spacing: .04em; color: var(--muted); font-weight: 600; border-top: 0; }
tbody tr { cursor: pointer; }
tbody tr:hover { background: var(--surface-2); }
.num { text-align: right; }
.count {
  display: inline-block; min-width: 30px; text-align: center; font-weight: 600; font-variant-numeric: tabular-nums;
  padding: 2px 8px; border-radius: 999px; background: var(--accent-soft); color: var(--accent);
}
.clip { max-width: 220px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.tag {
  font-size: .72rem; font-weight: 600; padding: 2px 7px; border-radius: 6px; margin-left: 6px;
  background: var(--accent-soft); color: var(--accent); vertical-align: middle;
}
.tag-off { background: var(--danger-soft); color: var(--danger); }
.dot { display: inline-block; width: 8px; height: 8px; border-radius: 50%; margin-right: 7px; }
.dot-on { background: var(--ok); }
.dot-off { background: var(--danger); }

/* ---- auth ---- */
main.auth { min-height: 100vh; display: flex; flex-direction: column; align-items: center; justify-content: center; padding: 24px 16px; }
main.auth .flash { width: 100%; max-width: 380px; }
.auth-card { width: 100%; max-width: 380px; padding: 28px; }
.auth-head { text-align: center; margin-bottom: 22px; }
.auth-head .brand-mark { margin-bottom: 14px; }
.auth-head p { margin: 6px 0 0; }

/* ---- dashboard hint ---- */
.hint-card {
  display: flex; align-items: center; justify-content: space-between; gap: 12px 20px; flex-wrap: wrap;
  padding: 14px 18px; margin-bottom: 18px; border-radius: var(--radius);
  background: var(--accent-soft); border: 1px solid color-mix(in srgb, var(--accent) 25%, transparent);
  color: var(--text);
}
.hint-card:hover { text-decoration: none; border-color: var(--accent); }
.hint-card > span:first-child { display: flex; flex-direction: column; }
.hint-arrow { color: var(--accent); font-weight: 600; white-space: nowrap; }

/* ---- platform icons ---- */
.pf-icon {
  flex: none; width: 44px; height: 44px; border-radius: 11px;
  display: inline-flex; align-items: center; justify-content: center;
  color: var(--muted); background: var(--surface-2);
}
.pf-icon svg { width: 24px; height: 24px; fill: currentColor; }
.pf-icon .pf-cut { fill: var(--pf-bg, var(--surface-2)); }
.pf-icon .pf-cut-stroke { stroke: var(--pf-bg, var(--surface-2)); }
.pf-windows { color: #1f7ae0; background: #e5f0fd; --pf-bg: #e5f0fd; }
.pf-android { color: #2f9e44; background: #e6f6ea; --pf-bg: #e6f6ea; }
.pf-ios, .pf-macos { color: #495057; background: #eceef1; --pf-bg: #eceef1; }
.pf-linux { color: #b7791f; background: #fdf3e1; --pf-bg: #fdf3e1; }
@media (prefers-color-scheme: dark) {
  .pf-windows { color: #74b0ff; background: #172a45; --pf-bg: #172a45; }
  .pf-android { color: #69db7c; background: #173020; --pf-bg: #173020; }
  .pf-ios, .pf-macos { color: #ced4da; background: #262a33; --pf-bg: #262a33; }
  .pf-linux { color: #f6c860; background: #3a2e14; --pf-bg: #3a2e14; }
}

/* ---- download cards ---- */
.guide-downloads { margin-bottom: 20px; }
.guide-downloads h2 { margin-bottom: 12px; }
.dl-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(270px, 1fr)); gap: 12px; }
.dl-card {
  display: flex; align-items: center; gap: 14px; padding: 14px 16px;
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius);
  box-shadow: var(--shadow); color: var(--text); min-width: 0;
}
.dl-card:hover { text-decoration: none; border-color: var(--accent); }
.dl-info { display: flex; flex-direction: column; min-width: 0; flex: 1; }
.dl-platform { font-size: .75rem; font-weight: 600; text-transform: uppercase; letter-spacing: .04em; color: var(--muted); }
.dl-title { font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.dl-meta { font-size: .8rem; color: var(--muted); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.dl-btn {
  flex: none; width: 38px; height: 38px; border-radius: 10px;
  display: inline-flex; align-items: center; justify-content: center;
  background: var(--accent); color: var(--accent-text);
}
.dl-btn svg { width: 20px; height: 20px; }

/* ---- guide content (shared by the page and the editor) ---- */
.guide-card { padding: 28px 32px; }
@media (max-width: 560px) { .guide-card { padding: 20px 16px; } }
.ql-snow .ql-editor.guide-content, #editor .ql-editor {
  font: 16px/1.65 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif; color: var(--text);
}
.guide-card .ql-editor { height: auto; overflow: visible; padding: 0; }
.guide-content h1, .guide-content h2, .guide-content h3,
#editor .ql-editor h1, #editor .ql-editor h2, #editor .ql-editor h3 { margin: 1.3em 0 .5em; line-height: 1.3; }
.guide-content > :first-child, #editor .ql-editor > :first-child { margin-top: 0; }
.ql-snow .ql-editor h1 { font-size: 1.7em; }
.ql-snow .ql-editor h2 { font-size: 1.35em; }
.ql-snow .ql-editor h3 { font-size: 1.12em; }
.ql-snow .ql-editor p, .ql-snow .ql-editor ol { margin-bottom: .6em; }
.ql-snow .ql-editor img {
  display: inline-block; max-width: 100%; height: auto; margin: 8px 0;
  border-radius: 10px; border: 1px solid var(--border);
}
.guide-card img { cursor: zoom-in; }
.ql-snow .ql-editor a { color: var(--accent); text-decoration: none; font-weight: 500; }
.ql-snow .ql-editor a:hover { text-decoration: underline; }
.ql-snow .ql-editor blockquote {
  border-left: 4px solid var(--accent); background: var(--accent-soft);
  margin: 12px 0; padding: 10px 14px; border-radius: 0 10px 10px 0;
}
.ql-snow .ql-editor .ql-code-block-container, .ql-snow .ql-editor pre {
  background: var(--surface-2); color: var(--text); border: 1px solid var(--border);
  border-radius: 9px; padding: 10px 14px; font: .85rem/1.5 var(--mono);
}

/* ---- editor ---- */
.head-actions { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; justify-content: flex-end; }
.editor-status { font-size: .85rem; color: var(--muted); }
.editor-status.error { color: var(--danger); }
.editor-card { padding: 0; margin-bottom: 20px; }
.editor-card .ql-toolbar.ql-snow {
  position: sticky; top: 58px; z-index: 5;
  background: var(--surface); border: 0; border-bottom: 1px solid var(--border);
  border-radius: var(--radius) var(--radius) 0 0; padding: 10px 12px;
}
.editor-card .ql-container.ql-snow { border: 0; font-size: 16px; }
.editor-card .ql-editor { min-height: 480px; padding: 24px 28px; }
.editor-card .ql-editor.ql-blank::before { color: var(--muted); font-style: normal; left: 28px; }
.editor-foot {
  display: flex; align-items: center; justify-content: space-between; gap: 12px; flex-wrap: wrap;
  padding: 12px 16px; border-top: 1px solid var(--border);
}
.editor-foot p { margin: 0; }
.insert-download select { width: auto; max-width: 260px; }
kbd {
  font: .78rem var(--mono); padding: 1px 5px; border-radius: 5px;
  border: 1px solid var(--border); background: var(--surface-2);
}

/* Quill toolbar in our colors (incl. dark theme) */
.ql-snow .ql-stroke { stroke: var(--text); }
.ql-snow .ql-fill, .ql-snow .ql-stroke.ql-fill { fill: var(--text); }
.ql-snow .ql-picker { color: var(--text); }
.ql-snow .ql-picker-options { background: var(--surface); border-color: var(--border) !important; box-shadow: 0 6px 20px rgba(0,0,0,.18); }
.ql-snow.ql-toolbar button:hover .ql-stroke, .ql-snow.ql-toolbar button.ql-active .ql-stroke,
.ql-snow.ql-toolbar .ql-picker-label:hover .ql-stroke, .ql-snow.ql-toolbar .ql-picker-label.ql-active .ql-stroke { stroke: var(--accent); }
.ql-snow.ql-toolbar button:hover .ql-fill, .ql-snow.ql-toolbar button.ql-active .ql-fill { fill: var(--accent); }
.ql-snow.ql-toolbar button:hover, .ql-snow.ql-toolbar button.ql-active,
.ql-snow.ql-toolbar .ql-picker-label:hover, .ql-snow.ql-toolbar .ql-picker-label.ql-active,
.ql-snow.ql-toolbar .ql-picker-item:hover, .ql-snow.ql-toolbar .ql-picker-item.ql-selected { color: var(--accent); }
.ql-snow .ql-tooltip {
  background: var(--surface); color: var(--text); border-color: var(--border);
  box-shadow: 0 6px 20px rgba(0,0,0,.18); border-radius: 9px; z-index: 6;
}
.ql-snow .ql-tooltip input[type=text] { width: 240px; padding: 5px 8px; height: auto; }

/* Quill labels in Russian */
.ql-snow .ql-picker.ql-header { width: 128px; }
.ql-snow .ql-picker.ql-header .ql-picker-label::before,
.ql-snow .ql-picker.ql-header .ql-picker-item::before { content: 'Обычный текст'; }
.ql-snow .ql-picker.ql-header .ql-picker-label[data-value="1"]::before,
.ql-snow .ql-picker.ql-header .ql-picker-item[data-value="1"]::before { content: 'Заголовок 1'; }
.ql-snow .ql-picker.ql-header .ql-picker-label[data-value="2"]::before,
.ql-snow .ql-picker.ql-header .ql-picker-item[data-value="2"]::before { content: 'Заголовок 2'; }
.ql-snow .ql-picker.ql-header .ql-picker-label[data-value="3"]::before,
.ql-snow .ql-picker.ql-header .ql-picker-item[data-value="3"]::before { content: 'Заголовок 3'; }
.ql-snow .ql-tooltip::before { content: 'Ссылка:'; }
.ql-snow .ql-tooltip[data-mode=link]::before { content: 'Адрес ссылки:'; }
.ql-snow .ql-tooltip a.ql-action::after { content: 'Изменить'; }
.ql-snow .ql-tooltip a.ql-remove::before { content: 'Убрать'; }
.ql-snow .ql-tooltip.ql-editing a.ql-action::after { content: 'Сохранить'; }

/* ---- downloads admin ---- */
.dl-admin-list { list-style: none; margin: 0 0 18px; padding: 0; display: flex; flex-direction: column; gap: 10px; }
.dl-admin { border: 1px solid var(--border); border-radius: var(--radius); padding: 12px 14px; background: var(--surface-2); }
.dl-admin .pf-icon { background: var(--surface); --pf-bg: var(--surface); }
.dl-admin-main { display: flex; align-items: center; gap: 12px; flex-wrap: wrap; }
.dl-admin-actions { display: flex; gap: 8px; }
.dl-edit-forms { display: flex; flex-direction: column; gap: 16px; }
.row.wrap { flex-wrap: wrap; }
.row.wrap > label:not(.grow) { flex: none; }
.dl-upload { border-top: 1px solid var(--border); padding-top: 16px; }
.dl-admin-list:empty + .dl-upload { border-top: 0; padding-top: 0; }
.progress {
  position: relative; height: 26px; border-radius: 8px; overflow: hidden;
  background: var(--surface-2); border: 1px solid var(--border);
}
.progress span { position: absolute; inset: 0 auto 0 0; width: 0; background: var(--accent-soft); transition: width .2s; }
.progress em { position: relative; display: block; font-style: normal; font-size: .82rem; line-height: 24px; padding: 0 10px; }

/* ---- lightbox ---- */
.lightbox {
  position: fixed; inset: 0; z-index: 100; background: rgba(0,0,0,.82);
  display: flex; align-items: center; justify-content: center; padding: 20px; cursor: zoom-out;
}
.lightbox img { max-width: 100%; max-height: 100%; border-radius: 8px; background: #fff; }
