/* ── Токены: «Нефритовый дракон» ──────────────────────────
   25.04.1988 — год Земляного Дракона (戊辰) и знак Тельца (Земля, Венера).
   Нефрит и изумруд — основа, золото — акцент дракона.
   Светлая тема — по умолчанию, тёмная — по системе или по выбору (data-theme). */
:root {
  --bg: #eef2ec;
  --card: #fbfcf8;
  --field: #ffffff;
  --knob: #ffffff;
  --ink: #13241c;
  --ink-2: #3a4f45;
  --ink-3: #56695f;
  --line: #cfdbd2;
  --line-2: #b7c7bc;
  --acc: #0d6a4c;
  --acc-t: #0b5e43;
  --acc-s: #d9ece2;
  --on-acc: #ffffff;
  --gold: #7d5600;
  --gold-s: #f3e6c4;
  --gold-line: #c9a24a;
  --ok: #237a4b;
  --ok-t: #17663d;
  --ok-s: #dbefe1;
  --on-ok: #ffffff;
  --bad: #b42318;
  --bad-s: #fbe2dd;
  --on-bad: #ffffff;
  --warn: #7a5000;
  --warn-c: #c98a00;
  --warn-s: #f6e9c8;
  --route: #2f4f8f;
  --route-s: #e1e8f5;
  --shadow-col: #13241c;
  --backdrop: rgba(9, 19, 15, .5);
  --grad: linear-gradient(135deg, #0d6a4c 0%, #0f7a57 55%, #8a6a12 100%);
  --blob-o: .22;
  --scale-o: .07;
  --s1: #0d6a4c;
  --s2: #b07a00;
  --s3: #2c6aa8;
  --s4: #b4432e;
  --s5: #7a4fb0;
  --s6: #3f8f2f;
  --s7: #a8346e;
  --s8: #b42318;

  --shadow-sm: 0 1px 2px color-mix(in srgb, var(--shadow-col) 6%, transparent);
  --shadow: 0 6px 24px -8px color-mix(in srgb, var(--shadow-col) 14%, transparent), 0 2px 8px -4px color-mix(in srgb, var(--shadow-col) 7%, transparent);
  --shadow-lg: 0 24px 60px -20px color-mix(in srgb, var(--shadow-col) 28%, transparent);

  --radius: 16px;
  --radius-sm: 10px;
  --gutter: clamp(16px, 2.4vw, 40px);

  --font: "PAC Sans", ui-sans-serif, -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  --font-d: "PAC Serif", "Georgia", "Times New Roman", serif;
  --font-cjk: "PAC Seal", "Noto Serif SC", "SimSun", "Songti SC", "Microsoft YaHei", serif;
  --mono: ui-monospace, "Cascadia Code", Consolas, monospace;

  --ease: cubic-bezier(.22, .9, .3, 1);
  --ease-spring: cubic-bezier(.34, 1.56, .64, 1);
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #09130f;
    --card: #101d18;
    --field: #0c1813;
    --knob: #e6efe9;
    --ink: #edf5ef;
    --ink-2: #bfd0c6;
    --ink-3: #93a99d;
    --line: #22362d;
    --line-2: #2f4a3e;
    --acc: #3fc996;
    --acc-t: #5fd9aa;
    --acc-s: #163a2c;
    --on-acc: #06140e;
    --gold: #e8bd55;
    --gold-s: #3a2e10;
    --gold-line: #8f7330;
    --ok: #4fcf86;
    --ok-t: #6fdc9b;
    --ok-s: #143323;
    --on-ok: #06140e;
    --bad: #ff8e7e;
    --bad-s: #3d1a16;
    --on-bad: #1d0705;
    --warn: #f0c45a;
    --warn-c: #e8b43c;
    --warn-s: #3a2e10;
    --route: #a9c1f5;
    --route-s: #1c2a45;
    --shadow-col: #000000;
    --backdrop: rgba(0, 0, 0, .62);
    --grad: linear-gradient(135deg, #2fb383 0%, #3fc996 55%, #e0b44a 100%);
    --blob-o: .13;
    --scale-o: .05;
    --s1: #3fc996;
    --s2: #e8bd55;
    --s3: #7fb4f0;
    --s4: #ff9f7a;
    --s5: #c3a2f5;
    --s6: #9bd77f;
    --s7: #f39cc2;
    --s8: #ff8e7e;
    color-scheme: dark;
  }
}
:root[data-theme="dark"] {
  --bg: #09130f;
  --card: #101d18;
  --field: #0c1813;
  --knob: #e6efe9;
  --ink: #edf5ef;
  --ink-2: #bfd0c6;
  --ink-3: #93a99d;
  --line: #22362d;
  --line-2: #2f4a3e;
  --acc: #3fc996;
  --acc-t: #5fd9aa;
  --acc-s: #163a2c;
  --on-acc: #06140e;
  --gold: #e8bd55;
  --gold-s: #3a2e10;
  --gold-line: #8f7330;
  --ok: #4fcf86;
  --ok-t: #6fdc9b;
  --ok-s: #143323;
  --on-ok: #06140e;
  --bad: #ff8e7e;
  --bad-s: #3d1a16;
  --on-bad: #1d0705;
  --warn: #f0c45a;
  --warn-c: #e8b43c;
  --warn-s: #3a2e10;
  --route: #a9c1f5;
  --route-s: #1c2a45;
  --shadow-col: #000000;
  --backdrop: rgba(0, 0, 0, .62);
  --grad: linear-gradient(135deg, #2fb383 0%, #3fc996 55%, #e0b44a 100%);
  --blob-o: .13;
  --scale-o: .05;
  --s1: #3fc996;
  --s2: #e8bd55;
  --s3: #7fb4f0;
  --s4: #ff9f7a;
  --s5: #c3a2f5;
  --s6: #9bd77f;
  --s7: #f39cc2;
  --s8: #ff8e7e;
  color-scheme: dark;
}

/* ── База ───────────────────────────────────────────────── */
* { box-sizing: border-box; }

html, body { margin: 0; }

body {
  font-family: var(--font);
  color: var(--ink);
  background: var(--bg);
  min-height: 100vh;
  -webkit-font-smoothing: antialiased;
  font-size: 15px;
  line-height: 1.5;
}

button { font-family: inherit; cursor: pointer; }
input, select { font-family: inherit; font-size: 14px; }
code {
  font-family: var(--mono);
  font-size: 12.5px;
  background: var(--acc-s);
  color: var(--acc-t);
  padding: 2px 6px;
  border-radius: 6px;
}

.hidden { display: none !important; }
[hidden] { display: none !important; }

/* ── Анимированный фон ──────────────────────────────────── */
.bg {
  position: fixed;
  inset: 0;
  z-index: -1;
  overflow: hidden;
  pointer-events: none;
}
.blob {
  position: absolute;
  width: 560px;
  height: 560px;
  border-radius: 50%;
  opacity: var(--blob-o);
  pointer-events: none;
}
.blob-a {
  background: radial-gradient(circle, var(--acc), transparent 65%);
  top: -180px;
  right: -120px;
}
.blob-b {
  background: radial-gradient(circle, var(--gold-line), transparent 65%);
  bottom: -220px;
  left: -140px;
}

/* ── Кнопки ─────────────────────────────────────────────── */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  position: relative;
  overflow: hidden;
  border: 1px solid transparent;
  border-radius: var(--radius-sm);
  padding: 9px 16px;
  font-size: 14px;
  font-weight: 600;
  color: var(--ink);
  background: transparent;
  transition: transform .18s var(--ease-spring), box-shadow .2s var(--ease), background .2s var(--ease), border-color .2s var(--ease), color .2s var(--ease);
  white-space: nowrap;
}
.btn svg { width: 16px; height: 16px; flex: none; }
.btn:active { transform: scale(.97); }

.btn-primary {
  background: var(--grad);
  color: var(--on-acc);
  box-shadow: 0 4px 14px -4px color-mix(in srgb, var(--acc) 55%, transparent);
}
.btn-primary:hover { transform: translateY(-1px); box-shadow: 0 8px 22px -6px color-mix(in srgb, var(--acc) 60%, transparent); }

.btn-success {
  background: var(--ok);
  color: var(--on-ok);
  box-shadow: 0 4px 14px -4px color-mix(in srgb, var(--ok) 50%, transparent);
}
.btn-success:hover { transform: translateY(-1px); box-shadow: 0 8px 22px -6px color-mix(in srgb, var(--ok) 55%, transparent); }

.btn-ghost {
  border-color: var(--line);
  background: var(--card);
  color: var(--ink-2);
}
.btn-ghost:hover { border-color: var(--acc); color: var(--acc-t); background: var(--acc-s); }

.btn-danger {
  background: var(--bad);
  color: var(--on-bad);
  box-shadow: 0 4px 14px -4px color-mix(in srgb, var(--bad) 50%, transparent);
}
.btn-danger:hover { transform: translateY(-1px); box-shadow: 0 8px 22px -6px color-mix(in srgb, var(--bad) 55%, transparent); }

.btn-block { width: 100%; }

/* Ripple */
.ripple {
  position: absolute;
  border-radius: 50%;
  background: rgba(255, 255, 255, .45);
  transform: scale(0);
  animation: ripple .55s var(--ease) forwards;
  pointer-events: none;
}
.btn-ghost .ripple { background: color-mix(in srgb, var(--acc) 22%, transparent); }
@keyframes ripple { to { transform: scale(3.4); opacity: 0; } }

.icon-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 34px;
  height: 34px;
  border: 1px solid transparent;
  border-radius: var(--radius-sm);
  background: transparent;
  color: var(--ink-3);
  transition: color .2s var(--ease), background-color .2s var(--ease), border-color .2s var(--ease), transform .2s var(--ease), box-shadow .2s var(--ease);
}
.icon-btn:hover { background: var(--acc-s); color: var(--acc-t); border-color: var(--line); transform: translateY(-1px); }
.icon-btn svg { width: 17px; height: 17px; }

/* ── Вход ───────────────────────────────────────────────── */
.login-screen {
  position: fixed;
  inset: 0;
  z-index: 50;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px;
}
.login-card {
  width: 100%;
  max-width: 400px;
  background: var(--card);
  border-radius: 20px;
  border: 1px solid var(--line);
  box-shadow: var(--shadow-lg);
  padding: 36px 32px;
  text-align: left;
  animation: popIn .5s var(--ease-spring);
}
.login-mark { width: 56px; height: 56px; margin-bottom: 20px; }
.login-mark svg { width: 100%; height: 100%; filter: drop-shadow(0 6px 12px color-mix(in srgb, var(--acc) 35%, transparent)); }
.login-card h1 { margin: 0; font-size: 22px; letter-spacing: -.02em; }
.login-sub { margin: 6px 0 24px; color: var(--ink-2); font-size: 14px; }
.login-error { color: var(--bad); font-size: 13px; margin: 10px 0 0; }

/* ── Шапка ──────────────────────────────────────────────── */
.topbar {
  position: sticky;
  top: 0;
  z-index: 20;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 10px var(--gutter);
  background: color-mix(in srgb, var(--card) 96%, transparent);
  backdrop-filter: blur(8px);
  border-bottom: 1px solid var(--line);
  animation: fadeDown .5s var(--ease);
}
.brand { display: flex; align-items: center; gap: 12px; }
.brand-mark { width: 36px; height: 36px; }
.brand-text { display: flex; flex-direction: column; line-height: 1.2; }
.brand-name { font-weight: 700; font-size: 16px; letter-spacing: -.01em; }
.brand-sub { font-size: 12px; color: var(--ink-3); }

/* ── Макет контента ─────────────────────────────────────── */
.app {
  padding: 24px var(--gutter) 56px;
  animation: fadeUp .55s var(--ease);
}

.card {
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 24px;
  transition: box-shadow .25s var(--ease);
}
.card:hover { box-shadow: var(--shadow-lg); }
.card-head {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 16px;
  margin-bottom: 18px;
}
.card h3 { margin: 0; font-size: 17px; letter-spacing: -.01em; }
.card-sub { margin: 3px 0 0; font-size: 13px; color: var(--ink-3); }

/* ── Пустые состояния ───────────────────────────────────── */
.empty-state {
  display: flex;
  flex-direction: column;
  align-items: center;
  text-align: center;
  gap: 4px;
  padding: 36px 16px;
  color: var(--ink-3);
  border: 1.5px dashed var(--line);
  border-radius: var(--radius-sm);
  animation: fadeUp .4s var(--ease);
}
.empty-state svg { width: 42px; height: 42px; margin-bottom: 8px; color: var(--ink-3); opacity: .8; }
.empty-state p { margin: 0; font-weight: 600; color: var(--ink-2); }
.empty-state span { font-size: 13px; }

/* ── Списки и строки ────────────────────────────────────── */
.list { display: flex; flex-direction: column; gap: 10px; }

.row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 14px;
  padding: 13px 14px;
  border: 1px solid var(--line);
  border-radius: 12px;
  background: var(--bg);
  transition: border-color .2s var(--ease), background .2s var(--ease), transform .2s var(--ease), box-shadow .2s var(--ease);
  animation: fadeUp .35s var(--ease) both;
}
.row:hover { border-color: color-mix(in srgb, var(--acc) 45%, transparent); background: var(--card); box-shadow: var(--shadow-sm); }

.row-leaving { animation: rowOut .28s var(--ease) forwards; }
.row-highlight { animation: rowFlash 1.6s var(--ease); }
@keyframes rowOut {
  to { opacity: 0; transform: translateX(24px) scale(.97); max-height: 0; padding-top: 0; padding-bottom: 0; margin: 0; border-width: 0; }
}
@keyframes rowFlash {
  0%   { background: var(--ok-s); border-color: color-mix(in srgb, var(--ok) 50%, transparent); }
  100% { background: var(--bg); border-color: var(--line); }
}

.row-main { min-width: 0; flex: 1; }
.row-title { display: flex; align-items: center; gap: 8px; font-weight: 600; font-size: 14px; min-width: 0; }
.row-title b { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.row-sub { display: flex; align-items: center; gap: 8px; margin-top: 3px; font-size: 12.5px; color: var(--ink-3); }
.row-sub .mono { font-family: var(--mono); color: var(--ink-2); }

.row-actions { display: flex; align-items: center; gap: 6px; flex: none; }

/* Бейджи */
.badge {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  font-size: 11.5px;
  font-weight: 600;
  padding: 3px 9px;
  border-radius: 999px;
  white-space: nowrap;
}
.badge-slug { background: var(--acc-s); color: var(--acc-t); }
.badge-proxy { background: var(--ok-s); color: var(--ok-t); }
.badge-none { background: var(--warn-s); color: var(--warn); }
.badge-off { background: var(--line); color: var(--ink-2); }

.badge-dot { width: 7px; height: 7px; border-radius: 50%; }
.badge-dot.on { background: var(--ok); animation: pulse 2.2s var(--ease) infinite; }
.badge-dot.off { background: var(--ink-3); }
@keyframes pulse {
  0% { box-shadow: 0 0 0 0 color-mix(in srgb, var(--ok) 50%, transparent); }
  70% { box-shadow: 0 0 0 6px color-mix(in srgb, var(--ok) 0%, transparent); }
  100% { box-shadow: 0 0 0 0 color-mix(in srgb, var(--ok) 0%, transparent); }
}

/* PAC-ссылка */
.pac-link {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-top: 8px;
  max-width: 100%;
}
.pac-link input {
  flex: 1;
  min-width: 0;
  border: 1px solid var(--line);
  background: var(--field);
  border-radius: 8px;
  padding: 6px 10px;
  font-family: var(--mono);
  font-size: 12px;
  color: var(--ink-2);
}
.copy-btn {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  border: 1px solid var(--line);
  background: var(--field);
  border-radius: 8px;
  padding: 6px 12px;
  font-size: 12.5px;
  font-weight: 600;
  color: var(--ink-2);
  transition: color .2s var(--ease), background-color .2s var(--ease), border-color .2s var(--ease), transform .2s var(--ease), box-shadow .2s var(--ease);
}
.copy-btn:hover { border-color: var(--ok); color: var(--ok-t); background: var(--ok-s); }
.copy-btn svg { width: 14px; height: 14px; }
.copy-btn .check { display: none; }
.copy-btn.copied { border-color: var(--ok); color: var(--ok-t); background: var(--ok-s); }
.copy-btn.copied .clip { display: none; }
.copy-btn.copied .check { display: inline-block; animation: popIn .3s var(--ease-spring); }

/* ── Прокси: вертикальная карточка и доступ ─────────────── */
.proxy-row { flex-direction: column; align-items: stretch; gap: 14px; }
.row-top { display: flex; align-items: flex-start; justify-content: space-between; gap: 14px; }
.row-body { display: flex; flex-direction: column; gap: 10px; }

.access-bar {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 9px 12px;
  background: var(--field);
  border: 1px solid var(--line);
  border-radius: var(--radius-sm);
}
.access-label { font-size: 13px; font-weight: 600; color: var(--ink-2); }

.token-note {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 13px;
  color: var(--warn);
  background: var(--warn-s);
  border: 1px solid color-mix(in srgb, var(--warn-c) 35%, transparent);
  padding: 9px 12px;
  border-radius: var(--radius-sm);
}
.token-note svg { width: 16px; height: 16px; flex: none; }

.token-panel {
  border: 1px solid var(--line);
  border-radius: var(--radius-sm);
  padding: 12px;
  background: var(--field);
  animation: fadeUp .3s var(--ease);
}
.token-panel-head { display: flex; align-items: center; justify-content: space-between; gap: 10px; margin-bottom: 10px; }
.token-panel-title { font-size: 13px; font-weight: 700; color: var(--ink); }
.token-list { display: flex; flex-direction: column; gap: 8px; }
.token-empty { font-size: 13px; color: var(--ink-3); padding: 8px 2px; }

.token-item {
  border: 1px solid var(--line);
  border-radius: var(--radius-sm);
  padding: 10px 12px;
  background: var(--bg);
  transition: border-color .2s var(--ease), background .2s var(--ease);
}
.token-item:hover { border-color: color-mix(in srgb, var(--ok) 45%, transparent); background: var(--card); }
.token-head { display: flex; align-items: center; justify-content: space-between; gap: 10px; margin-bottom: 8px; }
.token-title { display: flex; align-items: center; gap: 8px; min-width: 0; }
.token-title b { font-size: 13.5px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.token-actions { display: flex; align-items: center; gap: 6px; flex: none; }
.token-item .pac-link { margin-top: 0; }

.btn-sm { padding: 6px 12px; font-size: 13px; }

.link-note { color: var(--ink-2); font-size: 13.5px; margin: 0 0 16px; }
.link-field { max-width: none; }
.link-field input { font-size: 12px; }

/* Тумблер */
.switch { position: relative; display: inline-flex; width: 44px; height: 25px; flex: none; }
.switch input { opacity: 0; width: 0; height: 0; position: absolute; }
.switch .slider {
  position: absolute;
  inset: 0;
  background: var(--line);
  border-radius: 999px;
  transition: background .25s var(--ease);
}
.switch .slider::before {
  content: "";
  position: absolute;
  width: 19px;
  height: 19px;
  left: 3px;
  top: 3px;
  background: var(--knob);
  border-radius: 50%;
  box-shadow: 0 1px 3px color-mix(in srgb, var(--shadow-col) 30%, transparent);
  transition: transform .25s var(--ease-spring);
}
.switch input:checked + .slider { background: var(--ok); }
.switch input:checked + .slider::before { transform: translateX(19px); }
.switch:focus-visible .slider { outline: 2px solid var(--acc); outline-offset: 2px; }

/* ── Формы ──────────────────────────────────────────────── */
.field { margin-bottom: 16px; }
.field label { display: block; font-size: 13px; font-weight: 600; color: var(--ink-2); margin-bottom: 6px; }
.field input, .field select {
  width: 100%;
  border: 1.5px solid var(--line);
  background: var(--field);
  border-radius: var(--radius-sm);
  padding: 10px 13px;
  color: var(--ink);
  outline: none;
  transition: border-color .2s var(--ease), box-shadow .2s var(--ease);
}
.field input:focus, .field select:focus {
  border-color: var(--acc);
  box-shadow: 0 0 0 4px color-mix(in srgb, var(--acc) 14%, transparent);
}
.field .hint { margin: 5px 0 0; font-size: 12px; color: var(--ink-3); }
.field-row { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
@media (max-width: 520px) { .field-row { grid-template-columns: 1fr; } }

/* ── Модалки ────────────────────────────────────────────── */
.modal { position: fixed; inset: 0; z-index: 60; display: flex; align-items: safe center; justify-content: center; padding: 24px; overflow-y: auto; }
.modal-backdrop { position: absolute; inset: 0; background: var(--backdrop); animation: fadeIn .25s var(--ease); }
.modal-dialog {
  position: relative;
  width: 100%;
  max-width: 460px;
  background: var(--card);
  border-radius: 20px;
  box-shadow: var(--shadow-lg);
  border: 1px solid var(--line);
  padding: 24px;
  max-height: calc(100vh - 48px);
  max-height: calc(100dvh - 48px);
  overflow-y: auto;
  animation: popIn .38s var(--ease-spring);
}
.modal-dialog.confirm { max-width: 400px; }
.modal-head { display: flex; align-items: center; justify-content: space-between; margin-bottom: 20px; }
.modal-head h3 { margin: 0; font-size: 18px; letter-spacing: -.01em; }
.confirm-text { color: var(--ink-2); margin: 0 0 22px; }
.confirm-actions { display: flex; justify-content: flex-end; gap: 10px; }
.modal-actions { display: flex; justify-content: flex-end; gap: 10px; margin-top: 24px; }

@keyframes fadeIn { from { opacity: 0; } }
@keyframes fadeUp {
  from { opacity: 0; transform: translateY(14px); }
  to   { opacity: 1; transform: translateY(0); }
}
@keyframes fadeDown {
  from { opacity: 0; transform: translateY(-14px); }
  to   { opacity: 1; transform: translateY(0); }
}
@keyframes popIn {
  from { opacity: 0; transform: scale(.94) translateY(8px); }
  to   { opacity: 1; transform: scale(1) translateY(0); }
}

/* ── Тосты ──────────────────────────────────────────────── */
.toasts {
  position: fixed;
  right: 20px;
  bottom: 20px;
  z-index: 80;
  display: flex;
  flex-direction: column;
  gap: 10px;
}
.toast {
  color: var(--ink);
  display: flex;
  align-items: center;
  gap: 10px;
  min-width: 260px;
  max-width: 380px;
  background: var(--field);
  border: 1px solid var(--line);
  border-left: 4px solid var(--ok);
  border-radius: 12px;
  box-shadow: var(--shadow-lg);
  padding: 12px 16px;
  font-size: 14px;
  animation: toastIn .4s var(--ease-spring);
}
.toast svg { width: 18px; height: 18px; flex: none; }
.toast.toast-error { border-left-color: var(--bad); }
.toast.toast-error svg { color: var(--bad); }
.toast.toast-info { border-left-color: var(--acc); }
.toast.toast-info svg { color: var(--acc); }
.toast.toast-success svg { color: var(--ok); }
.toast-leaving { animation: toastOut .3s var(--ease) forwards; }
@keyframes toastIn {
  from { opacity: 0; transform: translateX(40px) scale(.96); }
  to   { opacity: 1; transform: translateX(0) scale(1); }
}
@keyframes toastOut {
  to { opacity: 0; transform: translateX(40px) scale(.96); }
}

/* ── Справка ────────────────────────────────────────────── */
.help { margin-top: 24px; }
.help h3 { margin: 0 0 14px; font-size: 17px; }
.help ol { margin: 0 0 8px; padding-left: 22px; color: var(--ink-2); }
.help li { margin-bottom: 6px; }
.help-note { margin: 12px 0 0; font-size: 13.5px; color: var(--ink-2); background: var(--acc-s); border-radius: var(--radius-sm); padding: 12px 14px; }
.help-note-green { background: var(--ok-s); margin-top: 8px; }

/* ── Доступ по IP ────────────────────────────────────────── */
.access-card { margin-top: 24px; }

.badge-blocked { background: var(--bad-s); color: var(--bad); }

.firewall-note {
  font-size: 13px;
  color: var(--ink-3);
  background: var(--acc-s);
  border: 1px dashed color-mix(in srgb, var(--warn-c) 40%, transparent);
  border-radius: var(--radius-sm);
  padding: 12px 14px;
  margin-bottom: 16px;
}

.firewall-bar {
  display: flex;
  align-items: flex-end;
  justify-content: space-between;
  flex-wrap: wrap;
  gap: 12px;
  padding: 12px;
  background: var(--bg);
  border: 1px solid var(--line);
  border-radius: var(--radius-sm);
  margin-bottom: 14px;
}
.firewall-token { flex: 1; min-width: 260px; }
.fw-label { display: block; font-size: 12px; font-weight: 700; color: var(--ink-3); margin-bottom: 2px; }
.firewall-token .pac-link { margin-top: 6px; }
.firewall-actions { display: flex; gap: 8px; flex: none; }

.firewall-settings {
  display: flex;
  flex-direction: column;
  gap: 12px;
  padding: 14px;
  background: var(--bg);
  border: 1px solid var(--line);
  border-radius: var(--radius-sm);
}
.fw-settings-title { font-size: 13px; font-weight: 700; color: var(--ink); }
.fw-settings-row { display: flex; align-items: flex-end; gap: 20px; flex-wrap: wrap; }
.fw-port-field { width: 120px; }
.fw-port-field input {
  width: 100%;
  border: 1.5px solid var(--line);
  background: var(--field);
  border-radius: var(--radius-sm);
  padding: 7px 10px;
  font-family: var(--mono);
  font-size: 13px;
  color: var(--ink);
  outline: none;
  transition: border-color .2s var(--ease), box-shadow .2s var(--ease);
}
.fw-port-field input:focus { border-color: var(--acc); box-shadow: 0 0 0 4px color-mix(in srgb, var(--acc) 14%, transparent); }
.fw-chains-field { flex: 1; min-width: 240px; }
.fw-chains { display: flex; gap: 8px; flex-wrap: wrap; }
.fw-chain {
  display: inline-flex;
  align-items: center;
  gap: 7px;
  border: 1.5px solid var(--line);
  background: var(--field);
  border-radius: 999px;
  padding: 6px 12px;
  font-size: 12.5px;
  font-weight: 600;
  color: var(--ink-2);
  cursor: pointer;
  transition: border-color .2s var(--ease), background .2s var(--ease), color .2s var(--ease), transform .18s var(--ease-spring);
}
.fw-chain:hover { border-color: var(--acc); color: var(--acc-t); transform: translateY(-1px); }
.fw-chain input { position: absolute; opacity: 0; width: 0; height: 0; }
.fw-chain input:checked + span { color: var(--ok-t); }
.fw-chain:has(input:checked) { border-color: var(--ok); background: var(--ok-s); }
.fw-chain:has(input:focus-visible) { outline: 2px solid var(--acc); outline-offset: 2px; }

.firewall-settings .fw-settings-actions { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }

.access-row { align-items: center; }
.access-blocked { background: var(--bad-s); border-color: color-mix(in srgb, var(--bad) 35%, transparent); }
.access-blocked:hover { background: var(--card); border-color: color-mix(in srgb, var(--bad) 50%, transparent); }
.access-row .row-title .mono { font-size: 13.5px; color: var(--ink); }
.access-targets { display: inline-flex; flex-wrap: wrap; gap: 4px; }
.access-meta { color: var(--ink-3); white-space: nowrap; }


/* ── Состояние сервиса ──────────────────────────────────── */
.status-card { margin-bottom: 24px; }
.stat-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 10px; margin-top: 16px; }
@media (min-width: 720px) { .stat-grid { grid-template-columns: repeat(4, minmax(0, 1fr)); } }
.stat {
  padding: 12px 14px; border-radius: var(--radius-sm); border: 1px solid var(--line);
  background: var(--bg); min-width: 0; animation: fadeUp .28s var(--ease) both;
}
.stat-label { font-size: 12px; color: var(--ink-3); }
.stat-value { font-size: 18px; font-weight: 700; letter-spacing: -.01em; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.status-meta { margin: 12px 0 0; font-size: 12.5px; color: var(--ink-3); }

/* ── Правила по IP и подсетям ───────────────────────────── */
.rules-card { margin-bottom: 24px; }
.rule-targets { display: inline-flex; flex-wrap: wrap; gap: 4px; }
.badge-mono { font-family: var(--mono); background: var(--line); color: var(--ink-2); }
.badge-route { background: var(--route-s); color: var(--route); }
.field textarea {
  width: 100%; min-height: 78px; padding: 10px 12px; resize: vertical;
  border: 1px solid var(--line); border-radius: var(--radius-sm); background: var(--field);
  color: var(--ink); font: inherit; font-size: 14px;
  transition: border-color .18s var(--ease), box-shadow .18s var(--ease);
}
.field textarea:focus { outline: none; border-color: var(--acc); box-shadow: 0 0 0 4px color-mix(in srgb, var(--acc) 15%, transparent); }
.exception-list { display: flex; flex-direction: column; gap: 8px; margin-bottom: 8px; }
.exception-row { display: flex; flex-wrap: wrap; gap: 6px; align-items: center; }
.exception-row > select:first-child { flex: 1 1 180px; min-width: 0; }
.exception-row > select[data-exroute] { flex: 0 0 130px; }
.exception-row > select[data-exproxy] { flex: 0 0 160px; }
.exception-row input, .exception-row select {
  min-width: 0; padding: 8px 10px; border: 1px solid var(--line); border-radius: var(--radius-sm);
  background: var(--field); color: var(--ink);
}
.exception-row input:focus, .exception-row select:focus { outline: none; border-color: var(--acc); }
.field-label { display: block; font-size: 13px; font-weight: 600; color: var(--ink-2); margin-bottom: 6px; }
.checkbox-row { display: flex; align-items: center; gap: 10px; font-size: 14px; color: var(--ink-2); }
.checkbox-row input { width: 18px; height: 18px; accent-color: var(--ok-t); }


/* ── Подвал ─────────────────────────────────────────────── */
.app-footer {
  display: flex; flex-wrap: wrap; justify-content: center; gap: 8px;
  padding: 28px 16px 36px; font-size: 12.5px; color: var(--ink-3);
}
.app-footer span:first-child { font-weight: 600; }

/* ── Неактивные состояния кнопок ────────────────────────── */
.btn:disabled { opacity: .55; cursor: not-allowed; transform: none; box-shadow: none; }

.subsection { margin-top: 22px; padding-top: 18px; border-top: 1px dashed var(--line); }
.subsection-head { display: flex; justify-content: space-between; align-items: flex-start; gap: 12px; margin-bottom: 12px; flex-wrap: wrap; }
.subsection h4 { margin: 0; font-size: 15px; letter-spacing: -.01em; }

/* ── Доступность ────────────────────────────────────────── */
:focus-visible { outline: 2px solid var(--acc); outline-offset: 2px; }

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    animation-duration: .01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: .01ms !important;
  }
}

.combined-default { display: grid; gap: 6px; margin: 14px 0; }
.combined-default select { max-width: 360px; }

/* ── Порты ──────────────────────────────────────────────── */
.listener-addr { display: grid; grid-template-columns: auto minmax(0, 1fr); align-items: center; gap: 8px 12px; margin-bottom: 10px; }
.listener-addr .field-label { margin: 0; white-space: nowrap; }
.listener-addr .pac-link { margin: 0; }
@media (max-width: 520px) { .listener-addr { grid-template-columns: minmax(0, 1fr); } }
.listener-row .row-title { flex-wrap: wrap; }
.listener-row .row-main { min-width: 0; }
.listener-addr .pac-link input { min-width: 0; }
.listener-rt { flex-wrap: wrap; }
.listener-err { color: var(--bad); font-size: 12px; overflow-wrap: anywhere; }
.inline-field { margin: 10px 0 0 28px; }
.inline-field input { max-width: 140px; }

/* ── Индикатор доступности прокси ───────────────────────── */
.health-dot { display: inline-block; width: 12px; height: 12px; border-radius: 3px; flex: none; vertical-align: middle; }
.health-ok { background: var(--ok); box-shadow: 0 0 0 3px var(--ok-s); }
.health-bad { background: var(--bad); box-shadow: 0 0 0 3px var(--bad-s); }
.health-warn { background: var(--warn-c); box-shadow: 0 0 0 3px var(--warn-s); }
.health-unknown { background: var(--ink-3); opacity: .45; }
.health-checking { animation: pulse 1.2s var(--ease) infinite; }
.health-line { flex-wrap: wrap; gap: 6px 10px; }
.health-text { font-weight: 600; }
.health-text-ok { color: var(--ok-t); }
.health-text-bad { color: var(--bad); }
.health-text-warn { color: var(--warn); }
.health-text-unknown { color: var(--ink-3); font-weight: 500; }
.health-when { color: var(--ink-3); }
.health-btn { padding: 3px 10px; font-size: 12px; }

/* ── Режим PAC «через сервис» ───────────────────────────── */
.via-box { display: grid; gap: 6px; margin: 0 0 14px; padding: 12px 14px; border: 1px dashed var(--line); border-radius: 12px; }
.via-box > select { max-width: 460px; }
.via-box .field-label { margin-bottom: 4px; }
.via-box select, .via-box input {
  width: 100%;
  border: 1.5px solid var(--line);
  background: var(--field);
  border-radius: var(--radius-sm);
  padding: 9px 12px;
  color: var(--ink);
  outline: none;
}
.via-box select:focus, .via-box input:focus { border-color: var(--acc); box-shadow: 0 0 0 4px color-mix(in srgb, var(--acc) 15%, transparent); }
.via-box select:disabled { opacity: .6; }
.via-service { display: grid; gap: 6px; }
.via-service[hidden] { display: none; }
.via-box .hint { margin: 2px 0 0; font-size: 12px; color: var(--ink-3); }
.via-warn { margin: 0; font-size: 12.5px; color: var(--warn); }
.modal .via-box .field-row { grid-template-columns: minmax(0, 1fr); }
[data-healthdot]:empty { display: none; }

/* ── Режим PAC у пользователя общего PAC ────────────────── */
.token-mode { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; margin: 6px 0 8px; }
.token-mode-label { font-size: 12.5px; color: var(--ink-3); }
.token-mode select { border: 1.5px solid var(--line); background: var(--field); border-radius: var(--radius-sm); padding: 6px 10px; font-size: 13px; color: var(--ink); max-width: 100%; }
.token-mode select:focus { outline: none; border-color: var(--acc); }
#listsList .row-sub { flex-wrap: wrap; }
#listsList .row-sub .badge { white-space: normal; }


/* ── Дашборд ────────────────────────────────────────────── */
.dash-card { margin-bottom: 20px; }
.range-tabs { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 14px; }
.range-btn { border: 1px solid var(--line); background: var(--card); color: var(--ink-2); border-radius: 999px; padding: 6px 13px; font: inherit; font-size: 13px; font-weight: 600; cursor: pointer; }
.range-btn:hover { border-color: var(--ink-3); color: var(--ink); }
.range-btn.active { background: var(--ink); border-color: var(--ink); color: var(--bg); }
.stat-sub { font-size: 12px; color: var(--ink-3); margin-top: 2px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.dash-grid { display: grid; grid-template-columns: minmax(0, 1fr); gap: 18px; margin-top: 14px; }
@media (min-width: 900px) { .dash-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); } }
.dash-chart { min-width: 0; }
.dash-chart h4 { margin: 0 0 8px; font-size: 13.5px; font-weight: 700; color: var(--ink); }
#dashLatencyWrap { margin-top: 18px; }
.dash-note { margin: 12px 0 0; font-size: 12px; color: var(--ink-3); }
.chart { position: relative; min-width: 0; }
.chart svg { display: block; width: 100%; height: auto; overflow: visible; }
.chart-grid { stroke: var(--line); stroke-width: 1; }
.chart-axis { stroke: var(--line-2); stroke-width: 1; }
.chart-tick { font-size: 11px; fill: var(--ink-3); font-variant-numeric: tabular-nums; }
.chart-cross { stroke: var(--ink-3); stroke-width: 1; stroke-dasharray: 3 3; pointer-events: none; }
.chart-legend { display: flex; flex-wrap: wrap; gap: 4px 14px; margin: 0 0 6px; font-size: 12.5px; color: var(--ink-2); }
.chart-legend-item { display: inline-flex; align-items: center; gap: 6px; }
.chart-legend-item i, .chart-tip-row i { display: inline-block; width: 14px; height: 3px; border-radius: 2px; flex: none; }
.chart-tip { position: absolute; z-index: 5; pointer-events: none; min-width: 150px; max-width: 280px; padding: 8px 10px; background: var(--card); border: 1px solid var(--line); border-radius: 10px; box-shadow: 0 8px 24px color-mix(in srgb, var(--shadow-col) 12%, transparent); font-size: 12.5px; color: var(--ink-2); }
.chart-tip-time { font-size: 11.5px; color: var(--ink-3); margin-bottom: 4px; }
.chart-tip-row { display: flex; align-items: center; gap: 7px; line-height: 1.6; }
.chart-tip-row b { color: var(--ink); font-variant-numeric: tabular-nums; }
.dash-proxy { padding: 12px 0; border-top: 1px dashed var(--line); }
.dash-proxy:first-child { border-top: 0; }
.dash-proxy-head { display: flex; flex-wrap: wrap; justify-content: space-between; gap: 6px 16px; margin-bottom: 8px; }
.dash-proxy-name { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; min-width: 0; }
.dash-proxy-name .mono { font-family: var(--mono); font-size: 12.5px; color: var(--ink-3); }
.dash-proxy-stats { display: flex; flex-wrap: wrap; gap: 4px 16px; font-size: 12.5px; color: var(--ink-3); }
.dash-proxy-stats b { color: var(--ink); font-variant-numeric: tabular-nums; }
.avail-strip { position: relative; display: flex; gap: 2px; height: 18px; }
.avail-cell { flex: 1 1 0; min-width: 0; border-radius: 2px; }
.avail-ok { background: var(--ok); }
.avail-warn { background: var(--warn-c); }
.avail-bad { background: var(--bad); }
.avail-none { background: var(--line); }
.avail-cell:hover { outline: 2px solid var(--ink); outline-offset: 1px; }
.dash-table-wrap { overflow-x: auto; margin-top: 10px; }
.dash-table { width: 100%; border-collapse: collapse; font-size: 13px; font-variant-numeric: tabular-nums; }
.dash-table th { text-align: left; font-weight: 600; color: var(--ink-3); font-size: 12px; padding: 6px 10px; border-bottom: 1px solid var(--line); white-space: nowrap; }
.dash-table td { padding: 8px 10px; border-bottom: 1px solid var(--line); white-space: nowrap; color: var(--ink-2); }
.dash-table td b { color: var(--ink); }
.dash-table .mono { font-family: var(--mono); color: var(--ink-3); }

/* ── Исходящий IP ───────────────────────────────────────── */
.badge-warn { background: var(--warn-s); color: var(--warn); }
.egress-label { color: var(--ink-3); }
.egress-ip { font-family: var(--mono); font-size: 13px; color: var(--ink); }
.cc-list { display: inline-flex; flex-wrap: wrap; gap: 4px; }
.cc { display: inline-flex; align-items: baseline; gap: 4px; padding: 1px 7px; border-radius: 999px; background: var(--bg); border: 1px solid var(--line); font-size: 12px; font-weight: 600; color: var(--ink); cursor: help; white-space: nowrap; }
.cc small { font-size: 10.5px; font-weight: 500; color: var(--ink-3); }
.cc-none { font-weight: 500; color: var(--ink-3); }
.egress-current { display: flex; flex-wrap: wrap; align-items: center; gap: 6px 8px; margin-bottom: 8px; font-size: 13px; }
.egress-cell-warn { box-shadow: inset 0 0 0 2px var(--warn-c); }
.egress-periods { margin-top: 8px; }
.egress-periods summary { cursor: pointer; font-size: 13px; color: var(--ink-2); user-select: none; }
.egress-periods summary:hover { color: var(--ink); }
.egress-table-wrap { max-height: 360px; overflow: auto; }
.egress-table th { position: sticky; top: 0; background: var(--card); }
.egress-table td { vertical-align: top; }
.egress-dur { font-size: 11.5px; color: var(--ink-3); padding-left: 16px; }
.egress-swatch { display: inline-block; width: 10px; height: 10px; border-radius: 3px; margin-right: 6px; vertical-align: -1px; }
.egress-swatch-fail { background: var(--bad); }
.dash-table .egress-ip { color: var(--ink); }

/* ── Нефритовый дракон: шрифты, печать, созвездие, чешуя ─── */
body { transition: background-color .25s var(--ease), color .25s var(--ease); }
.login-card h1, .brand-name, .card h3, .modal-head h3, .help h3 {
  font-family: var(--font-d);
  font-weight: 500;
  letter-spacing: 0;
}
.brand-name { font-size: 18px; }
.card h3 { font-size: 18.5px; }
.login-card h1 { font-size: 25px; }
.dash-chart h4, .subsection h4 { font-family: var(--font); }

/* Печать 辰 — земная ветвь Дракона */
.seal {
  display: grid; place-items: center; flex: none;
  width: 38px; height: 38px; border-radius: 9px;
  background: var(--grad); color: var(--on-acc);
  font-family: var(--font-cjk); font-size: 21px; font-weight: 700; line-height: 1;
  box-shadow: inset 0 0 0 2px color-mix(in srgb, var(--on-acc) 28%, transparent), 0 6px 14px -6px color-mix(in srgb, var(--acc) 60%, transparent);
  user-select: none;
}
.login-mark.seal { width: 58px; height: 58px; border-radius: 14px; font-size: 32px; margin-bottom: 20px; }

/* Созвездие Тельца с Альдебараном и Плеядами */
.constellation { width: 92px; height: 34px; color: var(--gold-line); flex: none; }
.topbar-right { display: flex; align-items: center; gap: 12px; }
@media (max-width: 640px) { .constellation { display: none; } .topbar { padding: 12px 16px; } }

/* Чешуя дракона на фоне — едва заметно, только сверху */
.bg::before {
  content: ""; position: absolute; inset: 0; opacity: var(--scale-o); color: var(--acc);
  background:
    radial-gradient(circle at 50% 0, transparent 13px, currentColor 13.5px, currentColor 14.5px, transparent 15px) 0 0 / 28px 16px,
    radial-gradient(circle at 50% 0, transparent 13px, currentColor 13.5px, currentColor 14.5px, transparent 15px) 14px 8px / 28px 16px;
  -webkit-mask: linear-gradient(180deg, #000, transparent 420px);
          mask: linear-gradient(180deg, #000, transparent 420px);
}

/* Переключатель темы */
.theme-switch { display: inline-flex; gap: 2px; padding: 3px; border: 1px solid var(--line); background: var(--card); border-radius: 999px; }
.theme-btn {
  display: inline-flex; align-items: center; justify-content: center;
  width: 30px; height: 28px; border: 0; border-radius: 999px; background: transparent; color: var(--ink-3);
  transition: color .18s var(--ease), background-color .18s var(--ease);
}
.theme-btn svg { width: 16px; height: 16px; }
.theme-btn:hover { color: var(--ink); background: var(--acc-s); }
.theme-btn[aria-pressed="true"] { background: var(--ink); color: var(--bg); }

/* Плашка подсказок — золотая кромка, как у лаковой шкатулки */
.help-note { border-left: 3px solid var(--gold-line); background: var(--gold-s); }
.help-note-green { border-left-color: var(--acc); }

/* Выбор маршрута «Остальной трафик» — в стиле остальных полей */
.combined-default select {
  width: 100%; border: 1.5px solid var(--line); background: var(--field); color: var(--ink);
  border-radius: var(--radius-sm); padding: 9px 12px; outline: none;
  transition: border-color .2s var(--ease), box-shadow .2s var(--ease);
}
.combined-default select:focus { border-color: var(--acc); box-shadow: 0 0 0 4px color-mix(in srgb, var(--acc) 15%, transparent); }

/* ══ Вкладки в шапке, полная ширина, телефон ═══════════════ */
.topbar { gap: 10px 20px; flex-wrap: nowrap; padding-top: max(10px, env(safe-area-inset-top, 0px)); }
.brand { flex: none; }
.topbar-right { flex: none; }

.view-tabs {
  display: flex; flex: 1 1 auto; min-width: 0; gap: 2px; margin: 0; padding: 3px;
  background: transparent; border: 0; border-radius: 0;
  overflow-x: auto; scrollbar-width: none; -webkit-overflow-scrolling: touch;
  scroll-padding-inline: 12px;
}
.view-tabs::-webkit-scrollbar { display: none; }
.view-tab {
  display: inline-flex; align-items: center; gap: 7px; flex: none;
  padding: 8px 14px; border-radius: 999px; text-decoration: none; white-space: nowrap;
  font-size: 14px; font-weight: 600; color: var(--ink-2);
  transition: color .18s var(--ease), background-color .18s var(--ease);
}
.view-tab:hover { color: var(--ink); background: var(--acc-s); }
.view-tab.active, .view-tab.active:hover { background: var(--ink); color: var(--bg); }
.tab-count {
  min-width: 20px; padding: 0 6px; border-radius: 999px; text-align: center;
  font-size: 11.5px; line-height: 18px; font-variant-numeric: tabular-nums;
  background: var(--acc-s); color: var(--acc-t);
}
.view-tab.active .tab-count { background: color-mix(in srgb, var(--bg) 22%, transparent); color: var(--bg); }

/* Раздел занимает всю ширину; записи раскладываются в колонки по ширине экрана */
.view { display: flex; flex-direction: column; gap: 20px; animation: fadeUp .3s var(--ease); }
.view > .card { margin: 0; }
.combined-card, .status-card, .access-card, .help, .dash-card { margin: 0; }
#view-pac, #view-help { --cols-min: 560px; }
#listsList, #listenersList, #proxiesList, #resourcesList, #rulesList, #accessList {
  display: grid; gap: 12px; align-items: start;
  grid-template-columns: repeat(auto-fill, minmax(min(100%, var(--row-min, 520px)), 1fr));
}
#resourcesList, #accessList { --row-min: 420px; }
#proxiesList { --row-min: 560px; }
.help { max-width: none; }
.help ol, .help-lead { max-width: 80ch; }
.help-lead { margin: 0 0 18px; color: var(--ink-2); }
.help h3.help-sub { margin-top: 6px; }

/* Средние экраны: вкладки уходят второй строкой и прокручиваются */
@media (max-width: 1180px) {
  .topbar { flex-wrap: wrap; }
  .view-tabs { order: 3; flex-basis: 100%; margin: 0 calc(var(--gutter) * -1); padding: 2px var(--gutter) 4px; }
}

/* Телефон */
@media (max-width: 640px) {
  body { font-size: 14.5px; }
  .topbar { padding: max(8px, env(safe-area-inset-top, 0px)) max(12px, env(safe-area-inset-right, 0px)) 6px max(12px, env(safe-area-inset-left, 0px)); gap: 8px; }
  .brand-sub { display: none; }
  .brand-mark.seal { width: 34px; height: 34px; font-size: 19px; }
  .topbar-right { gap: 8px; }
  #logoutBtn { padding: 7px 11px; }
  .theme-btn { width: 28px; height: 26px; }
  .view-tab { padding: 7px 12px; font-size: 13.5px; }

  .app { padding: 14px max(12px, env(safe-area-inset-right, 0px)) 40px max(12px, env(safe-area-inset-left, 0px)); }
  .view { gap: 14px; }
  .card { padding: 16px 14px; border-radius: 14px; }
  .card-head { flex-wrap: wrap; gap: 10px; margin-bottom: 14px; }
  .card-head > div:first-child { flex: 1 1 220px; min-width: 0; }
  .card h3 { font-size: 18px; }

  .row { flex-wrap: wrap; padding: 12px; }
  .row-main { flex: 1 1 180px; }
  .row-top { flex-wrap: nowrap; }
  .row-top .row-main { flex: 1 1 0; }
  .row-top .row-actions { flex-wrap: nowrap; }
  .row-actions { flex-wrap: wrap; }
  .row-title { flex-wrap: wrap; }
  .row-title b { white-space: normal; overflow-wrap: anywhere; }
  .row-sub { flex-wrap: wrap; }
  .token-head { flex-wrap: nowrap; align-items: flex-start; }
  .token-title { flex: 1 1 0; flex-wrap: wrap; }
  .token-title b { white-space: normal; overflow-wrap: anywhere; }

  .pac-link { flex-wrap: wrap; }
  .pac-link input { flex: 1 1 100%; }
  .pac-link .copy-btn { flex: 1 1 auto; justify-content: center; }
  .pac-link .copy-btn { padding: 8px 12px; }

  .firewall-token, .fw-chains-field { min-width: 0; flex-basis: 100%; }
  .firewall-actions, .fw-settings-row { flex-wrap: wrap; }
  .exception-row > select[data-exroute], .exception-row > select[data-exproxy] { flex: 1 1 140px; }

  .stat-grid { gap: 8px; }
  .stat { padding: 10px 12px; }
  .stat-value { font-size: 16px; }
  .dash-proxy-head { flex-direction: column; }

  .modal { padding: 10px; align-items: flex-end; }
  .modal-dialog { padding: 18px 16px; border-radius: 18px; max-height: calc(100dvh - 20px); }
  .modal-actions, .confirm-actions { flex-wrap: wrap; }
  .modal-actions .btn, .confirm-actions .btn { flex: 1 1 auto; }

  .toasts { left: 12px; right: 12px; bottom: max(12px, env(safe-area-inset-bottom, 0px)); }
  .toast { min-width: 0; max-width: none; }
  .login-card { padding: 28px 20px; }
  .btn { padding: 9px 14px; }
}

/* Совсем узкие экраны */
@media (max-width: 380px) {
  .brand-name { font-size: 16px; }
  .theme-switch { padding: 2px; }
  .theme-btn { width: 26px; }
}

/* Касание: кнопки и переключатели крупнее */
@media (pointer: coarse) {
  .icon-btn { width: 40px; height: 40px; }
  .copy-btn { min-height: 36px; }
}

/* ── Доступ по IP: строки и история ─────────────────────── */
.card-actions { display: flex; flex-wrap: wrap; justify-content: flex-end; gap: 8px; }
.access-row {
  display: grid; grid-template-columns: minmax(0, 1fr) auto; align-items: center; gap: 8px 14px;
}
.access-row .row-main { display: grid; gap: 6px; min-width: 0; }
.access-row .row-title { flex-wrap: wrap; row-gap: 4px; }
.access-row .row-actions { align-self: center; }
.access-ip { font-size: 14px; font-weight: 600; color: var(--ink); overflow-wrap: anywhere; }
.access-row .access-targets { display: flex; flex-wrap: wrap; gap: 4px; }
.access-row .access-meta { white-space: normal; font-size: 12.5px; color: var(--ink-3); }
.access-row .access-meta b { color: var(--ink-2); font-variant-numeric: tabular-nums; }
.access-none { margin: 2px 0 0; font-size: 13.5px; color: var(--ink-3); }

.access-history { margin-top: 20px; }
.access-history h4 { display: flex; align-items: center; gap: 8px; }
.access-history .card-sub { max-width: 90ch; }
.access-history-row { background: transparent; border-style: dashed; }
.access-history-row:hover { background: var(--card); }
.access-history-row .access-ip { color: var(--ink-2); }
#accessHistoryList {
  display: grid; gap: 10px; align-items: start;
  grid-template-columns: repeat(auto-fill, minmax(min(100%, 420px), 1fr));
}

@media (max-width: 420px) {
  .access-row { grid-template-columns: minmax(0, 1fr); }
  .access-row .row-actions { justify-content: space-between; }
}
#firewallBar + .empty-state, #accessList { margin-top: 14px; }

/* ── Доступ по IP: страна, провайдер, первый/последний запрос ── */
#accessGeoBar:not(:empty) { margin-top: 12px; }
.access-geo-bar { flex-wrap: wrap; row-gap: 6px; }
.geo-bases { display: inline-flex; flex-wrap: wrap; gap: 6px; margin-left: auto; font-size: 12px; color: var(--ink-3); }
.geo-base { padding: 2px 8px; border-radius: 999px; background: var(--bg); border: 1px solid var(--line); }
.geo-base-bad { color: var(--bad); border-color: color-mix(in srgb, var(--bad) 35%, transparent); }

.access-geo { display: flex; flex-wrap: wrap; align-items: center; gap: 4px 12px; font-size: 13px; color: var(--ink-2); min-width: 0; }
.access-geo-muted { font-size: 12.5px; color: var(--ink-3); }
.geo-country { display: inline-flex; align-items: center; gap: 6px; font-weight: 600; color: var(--ink); cursor: help; }
.geo-cc {
  display: inline-grid; place-items: center; min-width: 26px; height: 18px; padding: 0 4px; border-radius: 4px;
  font-family: var(--mono); font-size: 11px; font-weight: 600; letter-spacing: .03em;
  background: var(--gold-s); color: var(--gold); border: 1px solid color-mix(in srgb, var(--gold-line) 55%, transparent);
}
.geo-org { display: inline-flex; align-items: baseline; gap: 6px; min-width: 0; overflow-wrap: anywhere; cursor: help; }
.geo-org small { font-family: var(--mono); font-size: 11px; color: var(--ink-3); white-space: nowrap; }

.access-row .access-meta { display: flex; flex-wrap: wrap; gap: 2px 14px; }
.access-row .access-meta > span { white-space: nowrap; }
@media (max-width: 420px) { .access-row .access-meta > span { white-space: normal; } }
