/*
  RSSVpn — ui.css
  Shared design system for the public site and the admin SPA. No external fonts, no gradients, no glow.

  Tokens: --bg --surface --surface-2 --border --border-strong --text --text-2 --muted
          --accent --accent-hover --accent-text --accent-weak --ok(-weak) --warn(-weak) --bad(-weak)
          --radius (8px) --font --mono
  Theme:  follows prefers-color-scheme; <html data-theme="light|dark"> forces one (set by ui.js toggle).

  Layout:     .wrap .section .stack(-sm/-lg) .row .row-between .grid-2 .grid-3 .spacer
  Header:     .site-header .header-row .brand .brand-mark .nav .site-footer
  Buttons:    .btn + .btn-primary | .btn-ghost | .btn-danger | .btn-sm | .btn-lg | .btn-block | .btn-icon
  Forms:      .field .label .input .select .textarea .hint .field-error .check
  Surfaces:   .card .card-pad .card-head .card-title .divider .kv (key/value rows) .list
  Status:     .badge + .badge-ok | .badge-warn | .badge-bad | .badge-info | .badge-muted
              .alert + .alert-error | .alert-warn | .alert-ok | .alert-info
  Widgets:    .tabs .tab .tabpanel  .copyline .copyline-text  .qr-box  .spinner  .skeleton
              .toast-host .toast  .dialog  .kbd  .code  .empty  .table-wrap .table
  Text:       .muted .small .mono .h1 .h2 .h3 .lead .nowrap .sr-only
*/

:root {
  color-scheme: light;
  --bg: #f5f6f8;
  --surface: #ffffff;
  --surface-2: #f0f2f5;
  --border: #e0e3e8;
  --border-strong: #c7cdd6;
  --text: #14171c;
  --text-2: #3f4651;
  --muted: #646c78;
  --accent: #2f6fed;
  --accent-hover: #255fd6;
  --accent-text: #ffffff;
  --accent-weak: #eaf1fe;
  --ok: #17784b;
  --ok-weak: #e7f5ed;
  --warn: #935800;
  --warn-weak: #fcf2e0;
  --bad: #c0352f;
  --bad-weak: #fcebea;
  --focus: #2f6fed;
  --overlay: rgba(15, 18, 24, 0.45);
  --radius: 8px;
  --radius-sm: 6px;
  --font: system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, "Noto Sans", sans-serif;
  --mono: ui-monospace, "SFMono-Regular", "Cascadia Mono", "Segoe UI Mono", Consolas, "Liberation Mono", monospace;
  --header-h: 64px;
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    color-scheme: dark;
    --bg: #0e1014;
    --surface: #16191e;
    --surface-2: #1d2128;
    --border: #2a2f37;
    --border-strong: #3a414c;
    --text: #e9ebee;
    --text-2: #c3c8d0;
    --muted: #949ca8;
    --accent: #5a8dff;
    --accent-hover: #7aa3ff;
    --accent-text: #0b1020;
    --accent-weak: #1a2640;
    --ok: #4cc58a;
    --ok-weak: #13281e;
    --warn: #e2a64b;
    --warn-weak: #2c2214;
    --bad: #f0736b;
    --bad-weak: #2e1716;
    --focus: #7aa3ff;
    --overlay: rgba(0, 0, 0, 0.6);
  }
}

:root[data-theme="dark"] {
  color-scheme: dark;
  --bg: #0e1014;
  --surface: #16191e;
  --surface-2: #1d2128;
  --border: #2a2f37;
  --border-strong: #3a414c;
  --text: #e9ebee;
  --text-2: #c3c8d0;
  --muted: #949ca8;
  --accent: #5a8dff;
  --accent-hover: #7aa3ff;
  --accent-text: #0b1020;
  --accent-weak: #1a2640;
  --ok: #4cc58a;
  --ok-weak: #13281e;
  --warn: #e2a64b;
  --warn-weak: #2c2214;
  --bad: #f0736b;
  --bad-weak: #2e1716;
  --focus: #7aa3ff;
  --overlay: rgba(0, 0, 0, 0.6);
}

/* ---------- base ---------- */
*, *::before, *::after { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; text-size-adjust: 100%; }
html, body { margin: 0; padding: 0; }
body {
  background: var(--bg);
  color: var(--text);
  font-family: var(--font);
  font-size: 16px;
  line-height: 1.5;
  min-height: 100vh;
  display: flex;
  flex-direction: column;
  overflow-x: hidden;
  -webkit-font-smoothing: antialiased;
}
main { flex: 1 0 auto; }
img, svg { display: block; max-width: 100%; }
a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; text-underline-offset: 2px; }
p { margin: 0 0 16px; }
p:last-child { margin-bottom: 0; }
h1, h2, h3, h4 { margin: 0; color: var(--text); font-weight: 650; letter-spacing: -0.01em; }
h1, .h1 { font-size: 32px; line-height: 40px; letter-spacing: -0.02em; }
h2, .h2 { font-size: 24px; line-height: 32px; }
h3, .h3 { font-size: 18px; line-height: 24px; }
ul, ol { margin: 0; padding-left: 24px; }
hr, .divider { border: 0; border-top: 1px solid var(--border); margin: 24px 0; }
code, .mono { font-family: var(--mono); font-size: 0.92em; }
::selection { background: var(--accent-weak); }

:focus { outline: none; }
:focus-visible {
  outline: 2px solid var(--focus);
  outline-offset: 2px;
  border-radius: 4px;
}

.sr-only {
  position: absolute !important; width: 1px; height: 1px; padding: 0; margin: -1px;
  overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; border: 0;
}
.skip-link { position: absolute; left: 8px; top: -48px; z-index: 100; padding: 8px 16px; background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); }
.skip-link:focus { top: 8px; }

/* ---------- text helpers ---------- */
.muted { color: var(--muted); }
.text-2 { color: var(--text-2); }
.small { font-size: 14px; line-height: 20px; }
.tiny { font-size: 12px; line-height: 16px; }
.lead { font-size: 18px; line-height: 28px; color: var(--text-2); }
.nowrap { white-space: nowrap; }
.center { text-align: center; }
.strike { text-decoration: line-through; }
.num { font-variant-numeric: tabular-nums; }

/* ---------- layout ---------- */
.wrap { width: 100%; max-width: 1040px; margin: 0 auto; padding: 0 16px; }
.wrap-narrow { max-width: 720px; }
.section { padding-top: 48px; padding-bottom: 48px; }
.section + .section { border-top: 1px solid var(--border); }
.section-head { margin-bottom: 24px; }
.section-head p { margin-top: 8px; }
.stack > * + * { margin-top: 16px; }
.stack-sm > * + * { margin-top: 8px; }
.stack-lg > * + * { margin-top: 24px; }
.row { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
.row-lg { gap: 16px; }
.row-between { display: flex; align-items: center; justify-content: space-between; gap: 16px; flex-wrap: wrap; }
.spacer { flex: 1 1 auto; }
.grid-2, .grid-3 { display: grid; gap: 16px; grid-template-columns: 1fr; }
[hidden] { display: none !important; }

@media (min-width: 768px) {
  .wrap { padding: 0 24px; }
  .section { padding-top: 64px; padding-bottom: 64px; }
  h1, .h1 { font-size: 40px; line-height: 48px; }
  h2, .h2 { font-size: 28px; line-height: 36px; }
  .grid-2 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .grid-3 { grid-template-columns: repeat(3, minmax(0, 1fr)); }
}

/* ---------- header / footer ---------- */
.site-header {
  position: sticky; top: 0; z-index: 20;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
}
.header-row {
  display: flex; align-items: center; gap: 8px 16px; flex-wrap: wrap;
  min-height: 56px; padding-top: 8px; padding-bottom: 8px;
}
.brand {
  display: inline-flex; align-items: center; gap: 8px;
  color: var(--text); font-weight: 650; font-size: 17px; letter-spacing: -0.01em;
  margin-right: auto; padding: 4px 0;
}
.brand:hover { text-decoration: none; }
.brand-mark { width: 28px; height: 28px; flex: none; }
/* phones: a full-width row under the brand; -8px on both sides lines the link text up with the page
   gutter (the width must grow by the same 16px, a negative margin alone only shifts the box) */
.nav { display: flex; gap: 4px; order: 3; width: calc(100% + 16px); margin: 0 -8px; overflow-x: auto; scrollbar-width: none; }
.nav::-webkit-scrollbar { display: none; }
.nav a {
  color: var(--text-2); padding: 6px 8px; border-radius: var(--radius-sm); font-size: 15px; white-space: nowrap;
}
.nav a:hover { color: var(--text); background: var(--surface-2); text-decoration: none; }
.nav a[aria-current="page"] { color: var(--text); font-weight: 600; }
@media (max-width: 379px) { /* 360px phones: all four links fit, no hidden half-link */
  .nav { gap: 0; }
  .nav a { padding: 6px 6px; font-size: 14px; }
}
@media (min-width: 720px) {
  .header-row { flex-wrap: nowrap; min-height: var(--header-h); }
  .nav { order: 0; width: auto; margin: 0; }
  .nav a { padding: 8px 12px; }
}

.site-footer { border-top: 1px solid var(--border); background: var(--surface); padding: 24px 0; margin-top: 48px; }
.site-footer .row-between { align-items: flex-start; }
.footer-links { display: flex; gap: 8px 16px; flex-wrap: wrap; }
.footer-links a { color: var(--text-2); }

/* ---------- buttons ---------- */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  min-height: 40px; padding: 8px 16px;
  font: inherit; font-size: 15px; font-weight: 550; line-height: 22px;
  color: var(--text); background: var(--surface);
  border: 1px solid var(--border-strong); border-radius: var(--radius);
  cursor: pointer; text-decoration: none; white-space: nowrap;
  transition: background-color .12s ease, border-color .12s ease, color .12s ease;
  -webkit-tap-highlight-color: transparent;
}
.btn:hover { background: var(--surface-2); text-decoration: none; }
.btn:active { transform: translateY(1px); }
.btn:disabled, .btn[aria-disabled="true"] { opacity: .55; cursor: not-allowed; transform: none; }
.btn svg { width: 18px; height: 18px; flex: none; }
.btn-primary { background: var(--accent); border-color: var(--accent); color: var(--accent-text); }
.btn-primary:hover { background: var(--accent-hover); border-color: var(--accent-hover); }
.btn-ghost { background: transparent; border-color: transparent; color: var(--text-2); }
.btn-ghost:hover { background: var(--surface-2); color: var(--text); }
.btn-danger { color: var(--bad); border-color: var(--border-strong); }
.btn-danger:hover { background: var(--bad-weak); border-color: var(--bad); }
.btn-danger-solid { background: var(--bad); border-color: var(--bad); color: #fff; }
.btn-sm { min-height: 32px; padding: 4px 12px; font-size: 14px; line-height: 20px; }
.btn-lg { min-height: 48px; padding: 12px 24px; font-size: 16px; }
.btn-block { display: flex; width: 100%; }
.btn-icon { min-height: 40px; width: 40px; padding: 0; }
.btn-icon.btn-sm { width: 32px; }
.btn.is-loading { pointer-events: none; opacity: .8; }
.btn.is-loading::before {
  content: ""; width: 16px; height: 16px; border-radius: 50%;
  border: 2px solid currentColor; border-right-color: transparent; animation: hk-spin .7s linear infinite;
}

/* theme toggle: show moon in light theme, sun in dark theme */
.theme-toggle .icon-sun { display: none; }
:root[data-theme="dark"] .theme-toggle .icon-sun { display: block; }
:root[data-theme="dark"] .theme-toggle .icon-moon { display: none; }
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) .theme-toggle .icon-sun { display: block; }
  :root:not([data-theme="light"]) .theme-toggle .icon-moon { display: none; }
}

/* ---------- forms ---------- */
.field { display: flex; flex-direction: column; gap: 8px; }
.field + .field { margin-top: 16px; }
.label { font-size: 14px; line-height: 20px; font-weight: 550; color: var(--text-2); }
.label .muted { font-weight: 400; }
.input, .select, .textarea {
  width: 100%; min-height: 40px; padding: 8px 12px;
  font: inherit; font-size: 16px; line-height: 22px; color: var(--text);
  background: var(--surface); border: 1px solid var(--border-strong); border-radius: var(--radius);
  transition: border-color .12s ease;
}
.input::placeholder, .textarea::placeholder { color: var(--muted); opacity: .8; }
.input:hover, .select:hover, .textarea:hover { border-color: var(--muted); }
.input:focus-visible, .select:focus-visible, .textarea:focus-visible { outline: 2px solid var(--focus); outline-offset: -1px; border-color: var(--focus); border-radius: var(--radius); }
.input[aria-invalid="true"] { border-color: var(--bad); }
.input.mono { font-family: var(--mono); font-size: 14px; }
.textarea { min-height: 96px; resize: vertical; }
.select { appearance: none; padding-right: 36px; background-image: none; }
.select-wrap { position: relative; }
.select-wrap::after { content: ""; position: absolute; right: 14px; top: 50%; width: 8px; height: 8px; margin-top: -6px; border-right: 1.5px solid var(--muted); border-bottom: 1.5px solid var(--muted); transform: rotate(45deg); pointer-events: none; }
.hint { font-size: 14px; line-height: 20px; color: var(--muted); }
.field-error { font-size: 14px; line-height: 20px; color: var(--bad); }
.input-row { display: flex; gap: 8px; }
.input-row .input { flex: 1 1 auto; min-width: 0; }
.check { display: inline-flex; align-items: center; gap: 8px; cursor: pointer; }
.check input { width: 18px; height: 18px; accent-color: var(--accent); margin: 0; }

/* ---------- surfaces ---------- */
.card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); }
.card-pad { padding: 16px; }
@media (min-width: 768px) { .card-pad { padding: 24px; } }
.card-head { display: flex; align-items: center; justify-content: space-between; gap: 16px; padding: 16px; border-bottom: 1px solid var(--border); }
.card-title { font-size: 16px; font-weight: 650; line-height: 24px; }
.card-sub { background: var(--surface-2); }

.kv { display: grid; grid-template-columns: minmax(0, 1fr) auto; gap: 0; margin: 0; }
.kv dt, .kv dd { margin: 0; padding: 12px 0; border-bottom: 1px solid var(--border); }
.kv dt { color: var(--muted); }
.kv dd { text-align: right; font-weight: 550; overflow-wrap: anywhere; }
.kv dt:last-of-type, .kv dd:last-of-type { border-bottom: 0; }

.list { list-style: none; margin: 0; padding: 0; }
.list > li { padding: 12px 0; border-bottom: 1px solid var(--border); }
.list > li:last-child { border-bottom: 0; }

.checklist { list-style: none; padding: 0; margin: 0; display: grid; gap: 8px; }
.checklist li { display: flex; gap: 12px; align-items: flex-start; }
.checklist li::before {
  content: ""; flex: none; width: 16px; height: 10px; margin-top: 5px;
  border-left: 2px solid var(--accent); border-bottom: 2px solid var(--accent);
  transform: translateY(-2px) rotate(-45deg) scale(.8);
}

.steps { list-style: none; margin: 0; padding: 0; counter-reset: step; display: grid; gap: 16px; }
.steps > li { counter-increment: step; position: relative; padding-left: 40px; min-height: 28px; }
.steps > li::before {
  content: counter(step); position: absolute; left: 0; top: -1px;
  width: 28px; height: 28px; border-radius: 50%;
  display: flex; align-items: center; justify-content: center;
  font-size: 14px; font-weight: 650; color: var(--accent); background: var(--accent-weak);
}

/* ---------- status ---------- */
.badge {
  display: inline-flex; align-items: center; gap: 6px; height: 24px; padding: 0 8px;
  font-size: 13px; font-weight: 600; line-height: 1; white-space: nowrap;
  border-radius: 999px; background: var(--surface-2); color: var(--text-2); border: 1px solid var(--border);
}
.badge::before { content: ""; width: 6px; height: 6px; border-radius: 50%; background: currentColor; }
.badge-plain::before { display: none; }
.badge-ok { background: var(--ok-weak); color: var(--ok); border-color: transparent; }
.badge-warn { background: var(--warn-weak); color: var(--warn); border-color: transparent; }
.badge-bad { background: var(--bad-weak); color: var(--bad); border-color: transparent; }
.badge-info { background: var(--accent-weak); color: var(--accent); border-color: transparent; }
.badge-muted { color: var(--muted); }

.alert {
  display: flex; gap: 12px; align-items: flex-start;
  padding: 12px 16px; border-radius: var(--radius); border: 1px solid var(--border);
  background: var(--surface-2); color: var(--text);
}
.alert > .alert-body { flex: 1 1 auto; min-width: 0; }
.alert-title { font-weight: 650; }
.alert-error { background: var(--bad-weak); border-color: transparent; }
.alert-error .alert-title { color: var(--bad); }
.alert-warn { background: var(--warn-weak); border-color: transparent; }
.alert-warn .alert-title { color: var(--warn); }
.alert-ok { background: var(--ok-weak); border-color: transparent; }
.alert-ok .alert-title { color: var(--ok); }
.alert-info { background: var(--accent-weak); border-color: transparent; }

.status-icon {
  width: 48px; height: 48px; border-radius: 50%; flex: none;
  display: flex; align-items: center; justify-content: center;
  background: var(--surface-2); color: var(--muted);
}
.status-icon svg { width: 24px; height: 24px; }
.status-icon.ok { background: var(--ok-weak); color: var(--ok); }
.status-icon.warn { background: var(--warn-weak); color: var(--warn); }
.status-icon.bad { background: var(--bad-weak); color: var(--bad); }
.status-icon.info { background: var(--accent-weak); color: var(--accent); }

/* ---------- widgets ---------- */
.spinner {
  display: inline-block; width: 16px; height: 16px; flex: none; border-radius: 50%;
  border: 2px solid var(--border-strong); border-top-color: var(--accent);
  animation: hk-spin .8s linear infinite;
}
.spinner-lg { width: 24px; height: 24px; border-width: 3px; }
@keyframes hk-spin { to { transform: rotate(360deg); } }

.skeleton {
  display: block; height: 16px; border-radius: 4px; background: var(--surface-2);
  animation: hk-pulse 1.4s ease-in-out infinite;
}
@keyframes hk-pulse { 50% { opacity: .55; } }
@media (prefers-reduced-motion: reduce) {
  .skeleton, .spinner, .btn.is-loading::before { animation-duration: 2.4s; }
  * { scroll-behavior: auto !important; }
}

.tabs {
  display: flex; gap: 4px; padding: 4px; margin: 0;
  background: var(--surface-2); border: 1px solid var(--border); border-radius: var(--radius);
  overflow-x: auto; scrollbar-width: none;
}
.tabs::-webkit-scrollbar { display: none; }
.tab {
  flex: 1 0 auto; min-height: 36px; padding: 6px 12px;
  font: inherit; font-size: 15px; font-weight: 550; color: var(--text-2);
  background: transparent; border: 1px solid transparent; border-radius: var(--radius-sm);
  cursor: pointer; white-space: nowrap;
}
.tab:hover { color: var(--text); }
.tab[aria-selected="true"] { background: var(--surface); color: var(--text); border-color: var(--border); }
.tabpanel { padding-top: 16px; }

.copyline {
  display: flex; align-items: stretch; gap: 0;
  border: 1px solid var(--border-strong); border-radius: var(--radius); background: var(--surface-2);
  overflow: hidden;
}
.copyline-text {
  flex: 1 1 auto; min-width: 0; padding: 10px 12px;
  font-family: var(--mono); font-size: 14px; line-height: 20px; color: var(--text);
  overflow-wrap: anywhere; word-break: break-all; user-select: all;
}
.copyline .btn { border: 0; border-left: 1px solid var(--border-strong); border-radius: 0; min-height: 0; background: var(--surface); }
.copyline .btn:hover { background: var(--surface-2); }

.qr-box {
  display: inline-flex; padding: 12px; background: #ffffff; color: #000000;
  border: 1px solid var(--border); border-radius: var(--radius);
}
.qr-box svg { width: 200px; height: 200px; }
.qr-box.qr-sm svg { width: 160px; height: 160px; }

.kbd {
  display: inline-block; min-width: 20px; padding: 0 6px; height: 20px; line-height: 18px;
  font-family: var(--mono); font-size: 12px; text-align: center; color: var(--text-2);
  border: 1px solid var(--border-strong); border-bottom-width: 2px; border-radius: 4px; background: var(--surface);
}
.code {
  display: block; padding: 12px; font-family: var(--mono); font-size: 13px; line-height: 20px;
  background: var(--surface-2); border: 1px solid var(--border); border-radius: var(--radius);
  overflow-x: auto; white-space: pre;
}
.empty { padding: 32px 16px; text-align: center; color: var(--muted); }

/* tables (admin) */
.table-wrap { overflow-x: auto; border: 1px solid var(--border); border-radius: var(--radius); background: var(--surface); }
.table { width: 100%; border-collapse: collapse; font-size: 14px; line-height: 20px; }
.table th, .table td { padding: 10px 12px; text-align: left; border-bottom: 1px solid var(--border); vertical-align: middle; }
.table th { font-weight: 600; color: var(--muted); background: var(--surface-2); white-space: nowrap; font-size: 13px; }
.table tr:last-child td { border-bottom: 0; }
.table tbody tr:hover td { background: var(--surface-2); }
.table .actions { text-align: right; white-space: nowrap; }

/* toast */
.toast-host {
  position: fixed; z-index: 200; left: 16px; right: 16px; bottom: 16px;
  display: flex; flex-direction: column; align-items: center; gap: 8px; pointer-events: none;
}
@media (min-width: 768px) { .toast-host { left: auto; right: 24px; bottom: 24px; align-items: flex-end; } }
.toast {
  pointer-events: auto; max-width: 420px; width: max-content; max-width: min(420px, 100%);
  padding: 10px 16px; border-radius: var(--radius);
  background: var(--text); color: var(--bg); font-size: 15px; line-height: 22px;
  box-shadow: 0 4px 16px rgba(0, 0, 0, .12);
  animation: hk-toast-in .16s ease-out;
}
.toast-error { background: var(--bad); color: #fff; }
.toast-ok { background: var(--text); }
.toast.is-leaving { opacity: 0; transition: opacity .2s ease; }
@keyframes hk-toast-in { from { opacity: 0; transform: translateY(8px); } }

/* dialog */
.dialog {
  width: min(480px, calc(100vw - 32px)); max-height: calc(100vh - 32px); padding: 0;
  color: var(--text); background: var(--surface);
  border: 1px solid var(--border); border-radius: var(--radius);
  box-shadow: 0 16px 48px rgba(0, 0, 0, .18);
}
.dialog::backdrop { background: var(--overlay); }
.dialog-head { display: flex; align-items: center; justify-content: space-between; gap: 16px; padding: 16px 16px 0 24px; }
.dialog-body { padding: 16px 24px 24px; }
.dialog-foot { display: flex; gap: 8px; justify-content: flex-end; padding: 0 24px 24px; flex-wrap: wrap; }

/* details / faq */
.faq { border-top: 1px solid var(--border); }
.faq details { border-bottom: 1px solid var(--border); }
.faq summary {
  display: flex; align-items: center; justify-content: space-between; gap: 16px;
  padding: 16px 0; cursor: pointer; list-style: none; font-weight: 600;
}
.faq summary::-webkit-details-marker { display: none; }
.faq summary::after {
  content: ""; flex: none; width: 8px; height: 8px; margin-right: 4px;
  border-right: 1.5px solid var(--muted); border-bottom: 1.5px solid var(--muted);
  transform: rotate(45deg); transition: transform .15s ease;
}
.faq details[open] summary::after { transform: rotate(-135deg); }
.faq details > div { padding: 0 0 16px; color: var(--text-2); max-width: 680px; }
.alert .row { margin-top: 8px; }
