/* ============================================================
   Simorgh — design system v3 (premium dark, RTL-first)
   Self-hosted Vazirmatn · zero dependencies · CSP-safe
   v3: unified sub link, daily quotas, dashboard chart,
       mobile drawer, skeletons, view transitions.
   ============================================================ */

@font-face {
  font-family: 'Vazirmatn';
  src: url('/fonts/Vazirmatn-Regular.woff2') format('woff2');
  font-weight: 400;
  font-display: swap;
}
@font-face {
  font-family: 'Vazirmatn';
  src: url('/fonts/Vazirmatn-Medium.woff2') format('woff2');
  font-weight: 500;
  font-display: swap;
}
@font-face {
  font-family: 'Vazirmatn';
  src: url('/fonts/Vazirmatn-SemiBold.woff2') format('woff2');
  font-weight: 600;
  font-display: swap;
}
@font-face {
  font-family: 'Vazirmatn';
  src: url('/fonts/Vazirmatn-Bold.woff2') format('woff2');
  font-weight: 700;
  font-display: swap;
}

:root {
  /* palette */
  --bg: #060a14;
  --bg-soft: #0a1020;
  --surface: #0e1528;
  --surface-2: #131d36;
  --surface-3: #1a2444;
  --border: rgba(148, 163, 184, 0.13);
  --border-strong: rgba(148, 163, 184, 0.25);
  --text: #eaeefb;
  --text-soft: #b3bdd6;
  --muted: #7e89a6;
  --accent: #6d6cf7;
  --accent-2: #26d5f3;
  --accent-grad: linear-gradient(135deg, #7c6cf9 0%, #26d5f3 100%);
  --accent-soft: rgba(109, 108, 247, 0.15);
  --ok: #38d996;
  --ok-soft: rgba(56, 217, 150, 0.13);
  --warn: #fbc02d;
  --warn-soft: rgba(251, 192, 45, 0.13);
  --danger: #fb7185;
  --danger-soft: rgba(251, 113, 133, 0.13);
  /* geometry */
  --r-xl: 22px;
  --r-lg: 16px;
  --r-md: 12px;
  --r-sm: 9px;
  --shadow-1: 0 1px 2px rgba(2, 6, 23, 0.5);
  --shadow-2: 0 10px 28px rgba(2, 6, 23, 0.45);
  --shadow-3: 0 24px 64px rgba(2, 6, 23, 0.62);
  --mono: 'Sarasa Mono SC', ui-monospace, 'Cascadia Mono', 'JetBrains Mono', Consolas, monospace;
  --sidebar-w: 262px;
}

* { box-sizing: border-box; }

/* ⚠ THE v3 critical fix: any rule that sets display on a component class
   (grid/flex) used to override the `hidden` attribute (UA stylesheet loses to
   class specificity) — which stacked setup+login+panel on one scrollable page.
   This rule wins over everything and keeps view switching authoritative. */
[hidden] { display: none !important; }

html { scrollbar-color: #2a3655 transparent; }

body {
  margin: 0;
  font-family: 'Vazirmatn', 'Segoe UI', Tahoma, sans-serif;
  background:
    radial-gradient(1200px 560px at 88% -14%, rgba(109, 108, 247, 0.16), transparent 62%),
    radial-gradient(950px 520px at -12% 112%, rgba(38, 213, 243, 0.09), transparent 56%),
    var(--bg);
  color: var(--text);
  min-height: 100vh;
  font-size: 14.5px;
  line-height: 1.75;
  -webkit-font-smoothing: antialiased;
}

::selection { background: rgba(109, 108, 247, 0.38); }

a { color: var(--accent-2); text-decoration: none; }
a:hover { text-decoration: underline; }

code { font-family: var(--mono); direction: ltr; unicode-bidi: embed; }

/* ============ auth screens (setup / login) ============ */

.auth-wrap {
  min-height: 100vh;
  min-height: 100dvh;
  display: grid;
  place-items: center;
  padding: 26px 18px;
  position: relative;
  overflow: hidden;
}

/* animated aurora behind auth cards — pure CSS, CSP-safe */
.auth-wrap::before {
  content: '';
  position: absolute;
  inset: -40%;
  background:
    radial-gradient(closest-side at 30% 35%, rgba(109, 108, 247, 0.22), transparent),
    radial-gradient(closest-side at 70% 65%, rgba(38, 213, 243, 0.14), transparent),
    radial-gradient(closest-side at 55% 20%, rgba(56, 217, 150, 0.08), transparent);
  filter: blur(46px);
  animation: aurora 18s ease-in-out infinite alternate;
  pointer-events: none;
}
@keyframes aurora {
  0% { transform: rotate(0deg) scale(1); }
  50% { transform: rotate(8deg) scale(1.08); }
  100% { transform: rotate(-6deg) scale(1.02); }
}

.auth-card {
  width: min(410px, 100%);
  position: relative;
  background: linear-gradient(180deg, rgba(19, 29, 54, 0.88), rgba(14, 21, 40, 0.94));
  border: 1px solid var(--border-strong);
  border-radius: var(--r-xl);
  box-shadow: var(--shadow-3);
  padding: 38px 34px 32px;
  backdrop-filter: blur(18px);
  animation: cardIn 0.5s cubic-bezier(0.2, 0.9, 0.3, 1.2);
}
@keyframes cardIn {
  from { opacity: 0; transform: translateY(22px) scale(0.97); }
}

.brand-mark {
  width: 64px;
  height: 64px;
  border-radius: 18px;
  background: var(--accent-grad);
  display: grid;
  place-items: center;
  font-size: 30px;
  box-shadow: 0 14px 34px rgba(109, 108, 247, 0.45), inset 0 0 0 1px rgba(255, 255, 255, 0.18);
  margin: 0 auto 16px;
  position: relative;
}
.brand-mark::after {
  content: '';
  position: absolute;
  inset: -7px;
  border-radius: 24px;
  border: 1px dashed rgba(109, 108, 247, 0.45);
  animation: spin 14s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

.auth-card h1 {
  text-align: center;
  margin: 0 0 4px;
  font-size: 1.4rem;
  font-weight: 700;
  letter-spacing: 0.4px;
  background: linear-gradient(90deg, #c7d2fe, #a5f3fc);
  -webkit-background-clip: text;
  background-clip: text;
  color: transparent;
}
.auth-card .sub {
  text-align: center;
  color: var(--muted);
  font-size: 0.85rem;
  margin: 0 0 24px;
}
.auth-card .sub code { color: var(--accent-2); font-size: 0.78rem; }

.pw-wrap { position: relative; }
.pw-wrap input { padding-inline-end: 42px !important; }
.pw-eye {
  position: absolute;
  inset-inline-end: 10px;
  top: 50%;
  transform: translateY(-50%);
  background: none;
  border: none;
  color: var(--muted);
  cursor: pointer;
  font-size: 1rem;
  padding: 6px;
  line-height: 1;
}
.pw-eye:hover { color: var(--text); }

/* ============ app shell (sidebar + content) ============ */

.shell { display: flex; min-height: 100vh; }

.sidebar {
  width: var(--sidebar-w);
  flex-shrink: 0;
  background: linear-gradient(180deg, rgba(12, 18, 36, 0.97), rgba(8, 12, 26, 0.99));
  border-inline-end: 1px solid var(--border);
  position: sticky;
  top: 0;
  height: 100vh;
  display: flex;
  flex-direction: column;
  padding: 20px 14px 14px;
  z-index: 40;
}

.side-brand {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 4px 10px 20px;
}
.side-brand .mark {
  width: 42px;
  height: 42px;
  border-radius: 13px;
  background: var(--accent-grad);
  display: grid;
  place-items: center;
  font-size: 21px;
  box-shadow: 0 8px 22px rgba(109, 108, 247, 0.4);
  flex-shrink: 0;
}
.side-brand .t { font-weight: 700; font-size: 1.05rem; line-height: 1.3; letter-spacing: 0.3px; }
.side-brand .t small { display: block; color: var(--muted); font-weight: 400; font-size: 0.71rem; }

.nav-group { margin: 8px 0; }
.nav-group .lbl {
  font-size: 0.67rem;
  color: var(--muted);
  letter-spacing: 1.6px;
  padding: 0 12px 6px;
}

.nav-item {
  display: flex;
  align-items: center;
  gap: 11px;
  padding: 9px 12px;
  border-radius: var(--r-sm);
  color: var(--text-soft);
  cursor: pointer;
  font-size: 0.92rem;
  border: 1px solid transparent;
  transition: background 0.15s, color 0.15s, border-color 0.15s;
  user-select: none;
  margin: 2px 0;
  position: relative;
}
.nav-item:hover { background: var(--surface-2); color: var(--text); text-decoration: none; }
.nav-item.active {
  background: linear-gradient(90deg, var(--accent-soft), rgba(109, 108, 247, 0.05));
  color: #cfd8ff;
  border-color: rgba(109, 108, 247, 0.35);
  font-weight: 600;
}
.nav-item.active::before {
  content: '';
  position: absolute;
  inset-inline-start: -14px;
  top: 20%;
  bottom: 20%;
  width: 3px;
  border-radius: 4px;
  background: var(--accent-grad);
}
.nav-item .ico { width: 21px; text-align: center; font-size: 1.02rem; flex-shrink: 0; }

.side-foot {
  margin-top: auto;
  border-top: 1px solid var(--border);
  padding: 14px 10px 4px;
}
.side-admin { display: flex; align-items: center; gap: 10px; margin-bottom: 12px; }
.side-admin .ava {
  width: 38px;
  height: 38px;
  border-radius: 11px;
  background: var(--surface-3);
  display: grid;
  place-items: center;
  font-size: 16px;
  border: 1px solid var(--border-strong);
  flex-shrink: 0;
}
.side-admin .n { font-size: 0.85rem; font-weight: 600; line-height: 1.3; }
.side-admin .n small { display: block; color: var(--muted); font-weight: 400; font-size: 0.69rem; }

.content { flex: 1; min-width: 0; display: flex; flex-direction: column; }

.topbar {
  position: sticky;
  top: 0;
  z-index: 30;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  padding: 14px 30px;
  border-bottom: 1px solid var(--border);
  background: rgba(6, 10, 20, 0.82);
  backdrop-filter: blur(14px);
}
.topbar h1 { margin: 0; font-size: 1.16rem; font-weight: 700; letter-spacing: 0.3px; }
.topbar .crumb { color: var(--muted); font-size: 0.77rem; margin-top: 2px; }
.topbar-right { display: flex; align-items: center; gap: 10px; }

.main { padding: 26px 30px 70px; max-width: 1280px; width: 100%; margin: 0 auto; }

/* view switching animation */
.page { animation: pageIn 0.32s cubic-bezier(0.2, 0.8, 0.3, 1); }
@keyframes pageIn {
  from { opacity: 0; transform: translateY(10px); }
}

/* ============ cards & sections ============ */

.card {
  background: linear-gradient(180deg, rgba(19, 29, 54, 0.55), rgba(14, 21, 40, 0.72));
  border: 1px solid var(--border);
  border-radius: var(--r-lg);
  padding: 22px 24px;
  box-shadow: var(--shadow-1);
  margin-bottom: 20px;
}
.card > h2 {
  margin: 0 0 6px;
  font-size: 1.03rem;
  font-weight: 700;
  display: flex;
  align-items: center;
  gap: 8px;
}
.card > .desc { color: var(--muted); font-size: 0.84rem; margin: 0 0 16px; line-height: 1.9; }
.card > .desc a { text-decoration: underline; }

.grid-2 { display: grid; grid-template-columns: 1fr 1fr; gap: 20px; align-items: start; }
.grid-2 > .card { margin-bottom: 0; }

/* ============ stat cards ============ */

.stats { display: grid; grid-template-columns: repeat(auto-fill, minmax(198px, 1fr)); gap: 14px; margin-bottom: 22px; }
.stat {
  background: linear-gradient(180deg, rgba(19, 29, 54, 0.65), rgba(14, 21, 40, 0.8));
  border: 1px solid var(--border);
  border-radius: var(--r-md);
  padding: 16px 18px 14px;
  position: relative;
  overflow: hidden;
  transition: transform 0.15s, border-color 0.15s;
}
.stat:hover { transform: translateY(-2px); border-color: var(--border-strong); }
.stat::before {
  content: '';
  position: absolute;
  inset-inline-start: 0;
  top: 0;
  bottom: 0;
  width: 3px;
  background: var(--accent-grad);
  opacity: 0.75;
}
.stat.ok::before { background: var(--ok); }
.stat.warn::before { background: var(--warn); }
.stat.danger::before { background: var(--danger); }
.stat .v { font-size: 1.32rem; font-weight: 700; line-height: 1.45; letter-spacing: 0.2px; }
.stat .v small { font-size: 0.8rem; color: var(--muted); font-weight: 400; }
.stat .k { color: var(--muted); font-size: 0.77rem; margin-top: 1px; }
.stat .ico {
  position: absolute;
  inset-inline-end: 14px;
  top: 13px;
  width: 30px;
  height: 30px;
  display: grid;
  place-items: center;
  font-size: 1.05rem;
  border-radius: 9px;
  background: rgba(109, 108, 247, 0.12);
  opacity: 0.8;
}
.stat.ok .ico { background: var(--ok-soft); }
.stat.warn .ico { background: var(--warn-soft); }
.stat.danger .ico { background: var(--danger-soft); }

/* ============ traffic chart (dashboard, inline SVG) ============ */

.chart-card { position: relative; }
.chart-head { display: flex; align-items: baseline; justify-content: space-between; gap: 12px; flex-wrap: wrap; }
.chart-head .big { font-size: 1.5rem; font-weight: 700; }
.chart-head .big small { font-size: 0.78rem; color: var(--muted); font-weight: 400; }
.chart-legend { display: flex; gap: 14px; color: var(--muted); font-size: 0.74rem; }
.chart-legend i { display: inline-block; width: 9px; height: 9px; border-radius: 3px; margin-inline-end: 5px; }
.chart-legend .l1 i { background: var(--accent); }
.chart-legend .l2 i { background: var(--accent-2); }
#traffic-chart { width: 100%; height: 190px; display: block; margin-top: 10px; }
.chart-empty { color: var(--muted); text-align: center; padding: 44px 0 30px; font-size: 0.85rem; }

/* ============ buttons ============ */

.btn {
  background: var(--surface-2);
  color: var(--text);
  border: 1px solid var(--border-strong);
  border-radius: var(--r-sm);
  padding: 8px 16px;
  font: inherit;
  font-size: 0.88rem;
  cursor: pointer;
  transition: border-color 0.15s, background 0.15s, transform 0.06s, box-shadow 0.15s;
  white-space: nowrap;
}
.btn:hover { border-color: var(--accent); background: var(--surface-3); }
.btn:active { transform: translateY(1px); }
.btn:disabled { opacity: 0.55; cursor: wait; }

.btn.primary {
  background: var(--accent-grad);
  border: none;
  color: #fff;
  font-weight: 600;
  box-shadow: 0 8px 22px rgba(109, 108, 247, 0.35);
}
.btn.primary:hover { filter: brightness(1.12); background: var(--accent-grad); box-shadow: 0 10px 26px rgba(109, 108, 247, 0.45); }

.btn.ghost { background: transparent; border-color: transparent; color: var(--text-soft); }
.btn.ghost:hover { background: var(--surface-2); border-color: var(--border); }

.btn.danger { color: var(--danger); border-color: rgba(251, 113, 133, 0.35); background: transparent; }
.btn.danger:hover { background: var(--danger-soft); border-color: var(--danger); }

.btn.ok { color: var(--ok); border-color: rgba(56, 217, 150, 0.35); background: transparent; }
.btn.ok:hover { background: var(--ok-soft); border-color: var(--ok); }

.btn.sm { padding: 5px 11px; font-size: 0.8rem; border-radius: 8px; }

.actions { display: flex; gap: 8px; flex-wrap: wrap; margin-top: 14px; align-items: center; }

/* ============ forms ============ */

.form { display: grid; gap: 14px; }
label.f { display: grid; gap: 7px; font-size: 0.84rem; color: var(--text-soft); }
label.f .hint { color: var(--muted); font-size: 0.73rem; }
label.f input, label.f select, label.f textarea {
  background: var(--bg-soft);
  color: var(--text);
  border: 1px solid var(--border-strong);
  border-radius: var(--r-sm);
  padding: 10px 13px;
  font: inherit;
  outline: none;
  transition: border-color 0.15s, box-shadow 0.15s;
  width: 100%;
}
label.f input:focus, label.f select:focus, label.f textarea:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px rgba(109, 108, 247, 0.2);
}
.form-row { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.form-row-3 { display: grid; grid-template-columns: 1fr 1fr 1fr; gap: 12px; }

.chk { display: flex; align-items: center; gap: 9px; font-size: 0.87rem; cursor: pointer; color: var(--text-soft); }
.chk input { width: 17px; height: 17px; accent-color: var(--accent); }

.switch { position: relative; display: inline-block; width: 44px; height: 24px; flex-shrink: 0; }
.switch input { opacity: 0; width: 0; height: 0; }
.switch .sl {
  position: absolute; inset: 0;
  background: var(--surface-3);
  border: 1px solid var(--border-strong);
  border-radius: 999px;
  transition: 0.2s;
}
.switch .sl::before {
  content: '';
  position: absolute;
  width: 17px; height: 17px;
  inset-inline-start: 3px; top: 2.5px;
  background: var(--muted);
  border-radius: 50%;
  transition: 0.2s;
}
.switch input:checked + .sl { background: var(--accent-soft); border-color: var(--accent); }
.switch input:checked + .sl::before { transform: translateX(-18px); background: var(--accent-2); }

/* ============ tables ============ */

.tbl-wrap { overflow-x: auto; border: 1px solid var(--border); border-radius: var(--r-md); }
.tbl { width: 100%; border-collapse: collapse; font-size: 0.86rem; }
.tbl th, .tbl td { text-align: right; padding: 11px 14px; border-bottom: 1px solid var(--border); }
.tbl th {
  color: var(--muted);
  font-weight: 500;
  font-size: 0.73rem;
  letter-spacing: 0.5px;
  background: rgba(14, 21, 40, 0.6);
  position: sticky;
  top: 0;
  z-index: 1;
}
.tbl tr:last-child td { border-bottom: none; }
.tbl tbody tr { transition: background 0.12s; }
.tbl tbody tr:hover { background: rgba(19, 29, 54, 0.5); }
.tbl td .acts { display: flex; gap: 6px; flex-wrap: wrap; }

.mono-cell { font-family: var(--mono); font-size: 0.74rem; color: var(--muted); direction: ltr; text-align: left; }

.u-name { display: flex; align-items: center; gap: 10px; }
.u-ava {
  width: 34px;
  height: 34px;
  border-radius: 10px;
  flex-shrink: 0;
  display: grid;
  place-items: center;
  font-size: 0.8rem;
  font-weight: 700;
  color: #fff;
  background: linear-gradient(135deg, var(--accent), var(--accent-2));
  opacity: 0.9;
}
.u-name .nm { font-weight: 600; line-height: 1.35; }
.u-name .nm small { display: block; color: var(--muted); font-weight: 400; font-size: 0.7rem; direction: ltr; text-align: right; }

/* progress bars inside tables / cards */
.pbar { height: 5px; background: var(--surface-3); border-radius: 99px; overflow: hidden; min-width: 90px; }
.pbar > span { display: block; height: 100%; background: var(--accent-grad); border-radius: 99px; transition: width 0.3s; }
.pbar.warn > span { background: var(--warn); }
.pbar.danger > span { background: var(--danger); }
.pbar.ok > span { background: var(--ok); }
.qcell { min-width: 150px; }
.qcell .row1 { display: flex; justify-content: space-between; font-size: 0.78rem; margin-bottom: 5px; gap: 8px; }
.qcell .row1 .lbl2 { color: var(--muted); font-size: 0.7rem; }
.qcell.daily { min-width: 130px; }
.qcell.daily .row1 { font-size: 0.74rem; }

/* ============ badges ============ */

.badge {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  padding: 2.5px 10px;
  border-radius: 999px;
  font-size: 0.72rem;
  font-weight: 600;
  border: 1px solid var(--border-strong);
  color: var(--text-soft);
  background: var(--surface-2);
  white-space: nowrap;
}
.badge.ok { color: var(--ok); border-color: rgba(56, 217, 150, 0.4); background: var(--ok-soft); }
.badge.warn { color: var(--warn); border-color: rgba(251, 192, 45, 0.4); background: var(--warn-soft); }
.badge.danger { color: var(--danger); border-color: rgba(251, 113, 133, 0.4); background: var(--danger-soft); }
.badge.acc { color: #c7d2fe; border-color: rgba(109, 108, 247, 0.4); background: var(--accent-soft); }
.badge .dot { width: 6px; height: 6px; border-radius: 50%; background: currentColor; }
.badge .dot.pulse { animation: pulse 1.6s ease infinite; }
@keyframes pulse { 50% { opacity: 0.35; } }

/* ============ modal ============ */

.overlay {
  position: fixed;
  inset: 0;
  background: rgba(3, 6, 14, 0.74);
  backdrop-filter: blur(7px);
  display: grid;
  place-items: center;
  z-index: 100;
  padding: 20px;
  animation: fade 0.16s ease;
}
@keyframes fade { from { opacity: 0; } }
@keyframes rise { from { opacity: 0; transform: translateY(14px) scale(0.98); } }

.modal {
  width: min(580px, 100%);
  max-height: 88vh;
  overflow-y: auto;
  background: linear-gradient(180deg, #141d3c, #0f1630);
  border: 1px solid var(--border-strong);
  border-radius: var(--r-xl);
  box-shadow: var(--shadow-3);
  padding: 26px 26px 22px;
  animation: rise 0.22s ease;
}
.modal h2 { margin: 0 0 4px; font-size: 1.09rem; }
.modal .desc { color: var(--muted); font-size: 0.82rem; margin: 0 0 18px; }
.modal .modal-acts { display: flex; gap: 10px; justify-content: flex-start; margin-top: 20px; }

/* ============ toast ============ */

.toasts {
  position: fixed;
  bottom: 20px;
  inset-inline-start: 20px;
  z-index: 200;
  display: flex;
  flex-direction: column;
  gap: 10px;
  max-width: min(400px, calc(100vw - 40px));
}
.toast {
  background: #141d3c;
  border: 1px solid var(--border-strong);
  border-inline-start: 3px solid var(--accent);
  border-radius: var(--r-sm);
  padding: 12px 16px;
  font-size: 0.86rem;
  box-shadow: var(--shadow-2);
  animation: rise 0.2s ease;
}
.toast.ok { border-inline-start-color: var(--ok); }
.toast.err { border-inline-start-color: var(--danger); }
.toast.warn { border-inline-start-color: var(--warn); }

/* ============ result panel (after user creation) ============ */

.result-panel {
  margin-top: 18px;
  border: 1px dashed rgba(109, 108, 247, 0.55);
  background: var(--accent-soft);
  border-radius: var(--r-md);
  padding: 18px;
}
.result-panel h3 { margin: 0 0 4px; font-size: 0.96rem; color: #c7d2fe; }
.linkbox {
  display: flex;
  align-items: center;
  gap: 8px;
  background: var(--bg-soft);
  border: 1px solid var(--border-strong);
  border-radius: var(--r-sm);
  padding: 8px 12px;
  margin: 10px 0 4px;
}
.linkbox code {
  flex: 1;
  font-size: 0.78rem;
  color: var(--accent-2);
  word-break: break-all;
  direction: ltr;
  text-align: left;
}

/* ============ QR ============ */

.qr-box {
  background: #fff;
  border-radius: var(--r-md);
  padding: 12px;
  display: inline-block;
  margin: 12px 0 4px;
  box-shadow: var(--shadow-2);
}
.qr-box canvas { display: block; }

/* ============ misc ============ */

.muted { color: var(--muted); font-size: 0.84rem; }
.error-text { color: var(--danger); font-size: 0.84rem; margin: 6px 0 0; }
.empty { color: var(--muted); font-size: 0.85rem; text-align: center; padding: 28px 10px; }

textarea.code {
  background: var(--bg-soft);
  color: var(--text);
  border: 1px solid var(--border-strong);
  border-radius: var(--r-sm);
  padding: 10px 13px;
  font: inherit;
  outline: none;
  font-family: var(--mono);
  font-size: 0.76rem;
  direction: ltr;
  text-align: left;
  width: 100%;
  min-height: 110px;
  resize: vertical;
}
textarea.code:focus { border-color: var(--accent); }

pre.links {
  white-space: pre-wrap;
  word-break: break-all;
  background: var(--bg-soft);
  border: 1px solid var(--border);
  border-radius: var(--r-sm);
  padding: 12px 14px;
  margin: 10px 0 0;
  font-family: var(--mono);
  font-size: 0.72rem;
  color: var(--text-soft);
  direction: ltr;
  text-align: left;
  max-height: 300px;
  overflow: auto;
}

.kv { display: grid; gap: 9px; margin: 12px 0 0; }
.kv .row {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: var(--r-sm);
  padding: 9px 14px;
  font-size: 0.82rem;
}
.kv .row .k2 { color: var(--muted); flex-shrink: 0; }
.kv .row .v2 { font-weight: 600; }
.kv .row code { color: var(--accent-2); font-size: 0.76rem; word-break: break-all; }

.toolbar { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; margin-bottom: 16px; }
.toolbar input[type='search'] {
  background: var(--bg-soft);
  color: var(--text);
  border: 1px solid var(--border-strong);
  border-radius: var(--r-sm);
  padding: 8px 13px;
  font: inherit;
  outline: none;
  min-width: 220px;
  flex: 1;
  max-width: 360px;
}
.toolbar input:focus { border-color: var(--accent); }

/* ============ skeletons ============ */

.skel {
  position: relative;
  overflow: hidden;
  background: var(--surface-2);
  border-radius: var(--r-sm);
  color: transparent !important;
  min-height: 1em;
}
.skel::after {
  content: '';
  position: absolute;
  inset: 0;
  background: linear-gradient(90deg, transparent, rgba(148, 163, 184, 0.12), transparent);
  animation: shimmer 1.3s infinite;
}
@keyframes shimmer { from { transform: translateX(-100%); } to { transform: translateX(100%); } }

/* ============ sub page (public) ============ */

.sub-wrap { max-width: 660px; margin: 0 auto; padding: 34px 18px 80px; position: relative; }

.sub-hero { text-align: center; margin-bottom: 24px; }
.sub-hero .brand-mark { margin-bottom: 12px; }
.sub-hero h1 { margin: 0; font-size: 1.35rem; letter-spacing: 0.3px; }
.sub-hero .who { color: var(--text-soft); margin-top: 4px; font-size: 0.95rem; }
.sub-hero .who b { color: #c7d2fe; }

.sub-status {
  border-radius: var(--r-md);
  padding: 14px 18px;
  font-size: 0.9rem;
  margin-bottom: 20px;
  display: flex;
  align-items: center;
  gap: 10px;
  border: 1px solid;
}
.sub-status.ok { background: var(--ok-soft); border-color: rgba(56, 217, 150, 0.35); color: #a7f3d0; }
.sub-status.warn { background: var(--warn-soft); border-color: rgba(251, 192, 45, 0.35); color: #fde68a; }
.sub-status.danger { background: var(--danger-soft); border-color: rgba(251, 113, 133, 0.35); color: #fecdd3; }

.quota-big { margin-bottom: 20px; }
.quota-big .bar { height: 10px; background: var(--surface-3); border-radius: 99px; overflow: hidden; }
.quota-big .bar > span { display: block; height: 100%; border-radius: 99px; background: var(--accent-grad); transition: width 0.5s; }
.quota-big .bar.warn > span { background: var(--warn); }
.quota-big .bar.danger > span { background: var(--danger); }
.quota-big .nums { display: flex; justify-content: space-between; color: var(--muted); font-size: 0.8rem; margin-top: 7px; }
.quota-big .nums b { color: var(--text-soft); }

.sub-stats { display: grid; grid-template-columns: repeat(4, 1fr); gap: 12px; margin-bottom: 20px; }
.sub-stats .cell {
  background: linear-gradient(180deg, rgba(19, 29, 54, 0.65), rgba(14, 21, 40, 0.8));
  border: 1px solid var(--border);
  border-radius: var(--r-md);
  padding: 14px 15px;
  text-align: center;
}
.sub-stats .cell .v { font-weight: 700; font-size: 1.02rem; }
.sub-stats .cell .k { color: var(--muted); font-size: 0.71rem; margin-top: 3px; }

.cfg {
  background: linear-gradient(180deg, rgba(19, 29, 54, 0.65), rgba(14, 21, 40, 0.8));
  border: 1px solid var(--border);
  border-radius: var(--r-md);
  padding: 15px 17px;
  margin-bottom: 12px;
  transition: border-color 0.15s;
}
.cfg:hover { border-color: var(--border-strong); }
.cfg .head { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; }
.cfg .head .proto { flex-shrink: 0; }
.cfg .head .host { font-family: var(--mono); font-size: 0.78rem; color: var(--text-soft); direction: ltr; word-break: break-all; flex: 1; min-width: 120px; text-align: left; }
.cfg .qr-slot { margin-top: 8px; display: none; }
.cfg.open .qr-slot { display: block; }
.cfg .linkrow { margin-top: 10px; display: none; }
.cfg.open .linkrow { display: block; }

/* one-click import app grid on the sub page */
.import-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; margin-top: 12px; }
.import-btn {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 12px 14px;
  border-radius: var(--r-md);
  border: 1px solid var(--border-strong);
  background: var(--surface-2);
  color: var(--text);
  cursor: pointer;
  font: inherit;
  font-size: 0.86rem;
  font-weight: 600;
  transition: border-color 0.15s, background 0.15s, transform 0.06s;
  text-decoration: none;
}
.import-btn:hover { border-color: var(--accent); background: var(--surface-3); transform: translateY(-1px); text-decoration: none; }
.import-btn .app-ico {
  width: 34px; height: 34px;
  border-radius: 10px;
  display: grid;
  place-items: center;
  font-size: 1.05rem;
  background: var(--surface-3);
  border: 1px solid var(--border-strong);
  flex-shrink: 0;
}
.import-btn small { display: block; color: var(--muted); font-weight: 400; font-size: 0.68rem; margin-top: 1px; }

.sub-foot { text-align: center; color: var(--muted); font-size: 0.74rem; margin-top: 34px; }

/* ============ mobile drawer ============ */

.drawer-back {
  position: fixed;
  inset: 0;
  background: rgba(3, 6, 14, 0.6);
  backdrop-filter: blur(3px);
  z-index: 60;
  animation: fade 0.15s ease;
}
.mobilebar { display: none; }
.hamburger {
  display: none;
  width: 40px; height: 40px;
  border-radius: 11px;
  border: 1px solid var(--border-strong);
  background: var(--surface-2);
  color: var(--text);
  cursor: pointer;
  font-size: 1.1rem;
  line-height: 1;
}

/* ============ responsive ============ */

@media (max-width: 1080px) {
  .main { padding: 22px 22px 60px; }
  .stats { grid-template-columns: repeat(auto-fill, minmax(170px, 1fr)); }
}

@media (max-width: 980px) {
  /* mobilebar lives INSIDE .shell (a flex row on desktop) — switch the shell
     to a column so the bar spans the top and .content keeps the full width */
  .shell { flex-direction: column; }
  /* grid/flex items keep min-width:auto — a wide table then inflates its
     1fr track and overflows the page. Let tracks shrink to zero and let the
     .tbl-wrap (overflow-x:auto) do its job instead. */
  .card, .grid-2 > *, .stats > *, .content, .main, .page { min-width: 0; max-width: 100%; }
  .sidebar {
    position: fixed;
    inset-inline-start: 0;
    top: 0;
    bottom: 0;
    transform: translateX(100%);
    transition: transform 0.25s ease;
    box-shadow: var(--shadow-3);
    height: 100dvh;
    z-index: 70;
    overflow-y: auto;
  }
  [dir='rtl'] .sidebar { transform: translateX(100%); }
  .sidebar.open { transform: translateX(0); }
  .shell .mobilebar {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 10px;
    padding: 12px 16px;
    border-bottom: 1px solid var(--border);
    background: rgba(6, 10, 20, 0.92);
    position: sticky;
    top: 0;
    z-index: 50;
    backdrop-filter: blur(14px);
  }
  .hamburger { display: grid; place-items: center; }
  .topbar { position: static; padding: 13px 16px; background: transparent; backdrop-filter: none; }
  .topbar .crumb { display: none; }
  .main { padding: 16px 14px 60px; }
  .grid-2 { grid-template-columns: 1fr; }
  .form-row, .form-row-3 { grid-template-columns: 1fr 1fr; }
  .sub-stats { grid-template-columns: repeat(2, 1fr); }
  .import-grid { grid-template-columns: 1fr; }
  .stats { grid-template-columns: repeat(2, 1fr); gap: 10px; }
  .stat .v { font-size: 1.18rem; }
}


/* ============ radar v2 (clean-IP engine) ============ */

.radar-stats { margin-bottom: 16px; }
.radar-sub-count { display: flex; gap: 14px; align-items: flex-end; flex-wrap: wrap; margin-top: 14px; }
.radar-sub-count .f { display: flex; flex-direction: column; gap: 5px; font-size: 0.78rem; color: var(--muted); }
.radar-sub-count input {
  width: 110px;
  background: var(--surface-2, #0a1020);
  color: var(--text, #e6e9f5);
  border: 1px solid var(--border);
  border-radius: 9px;
  padding: 7px 10px;
  font-size: 0.86rem;
  font-family: inherit;
}
.apply-card { border-color: rgba(109, 108, 247, 0.35); }
.apply-card .ctl.chk { display: flex; gap: 7px; align-items: center; font-size: 0.8rem; color: var(--muted); margin-top: 12px; }
.apply-card .ctl.chk input { accent-color: var(--accent); width: 15px; height: 15px; }
#apply-result { margin: 12px 0 0; font-size: 0.82rem; line-height: 2; color: var(--ok); }

.card-head { display: flex; justify-content: space-between; align-items: flex-start; gap: 14px; flex-wrap: wrap; margin-bottom: 8px; }
.card-head h2 { margin: 0; }
.tbl-ctl { display: flex; gap: 12px; align-items: center; flex-wrap: wrap; }
.ctl { display: flex; gap: 7px; align-items: center; font-size: 0.8rem; color: var(--muted); }
.ctl select, .ctl input[type="checkbox"] { accent-color: var(--accent); }
.ctl select {
  background: var(--surface-2, #0a1020);
  color: var(--text, #e6e9f5);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 5px 9px;
  font-size: 0.8rem;
  font-family: inherit;
}

.rtbl .badge.front { background: rgba(38, 213, 243, 0.12); color: var(--accent-2); border: 1px solid rgba(38, 213, 243, 0.35); }
.score-pill {
  display: inline-block;
  min-width: 44px;
  text-align: center;
  padding: 2px 9px;
  border-radius: 999px;
  font-weight: 700;
  font-size: 0.8rem;
  font-variant-numeric: tabular-nums;
  border: 1px solid var(--border);
}
.score-pill.s-hi { color: var(--ok); background: var(--ok-soft); border-color: rgba(56, 217, 150, 0.4); }
.score-pill.s-mid { color: #fbbf24; background: rgba(251, 191, 36, 0.1); border-color: rgba(251, 191, 36, 0.35); }
.score-pill.s-lo { color: var(--danger); background: var(--danger-soft); border-color: rgba(251, 113, 133, 0.3); }
.mini-bar { display: inline-block; width: 64px; height: 5px; border-radius: 999px; background: rgba(148, 163, 184, 0.15); overflow: hidden; vertical-align: middle; margin-inline-start: 6px; }
.mini-bar > i { display: block; height: 100%; background: var(--accent-grad); }
.mono-cell { font-family: "Sarasa Mono SC", ui-monospace, monospace; direction: ltr; }
.tls-cell { font-size: 0.72rem; color: var(--muted); direction: ltr; text-align: right; }

.radar-info {
  font-size: 0.8rem;
  color: var(--accent-2);
  background: rgba(38, 213, 243, 0.07);
  border: 1px solid rgba(38, 213, 243, 0.25);
  border-radius: 10px;
  padding: 9px 13px;
  line-height: 1.9;
  margin: 0 0 14px;
}

/* ============================================================
   RESPONSIVE v4 (phase 14) — all devices, all pages
   phone ≤760 · small phone ≤460 · short landscape · touch
   ============================================================ */

/* ---- phones (≤760px): full mobile experience ---- */
@media (max-width: 760px) {
  html { -webkit-text-size-adjust: 100%; }
  body { font-size: 0.9rem; }

  /* layout */
  .main { padding: 14px 12px 88px; }
  .topbar { padding: 10px 12px; }
  .topbar h1 { font-size: 1.02rem; }
  .topbar-right { gap: 7px; }
  .topbar .clock, .topbar .crumb { display: none; }

  /* cards */
  .card { padding: 16px 14px 18px; border-radius: var(--r-lg); }
  .card > h2 { font-size: 0.98rem; }
  .card > .desc { font-size: 0.78rem; line-height: 1.85; }

  /* stats */
  .stats { grid-template-columns: repeat(2, 1fr); gap: 9px; margin-bottom: 16px; }
  .stat { padding: 12px; }
  .stat .v { font-size: 1.08rem; }
  .stat .k { font-size: 0.68rem; }
  .stat .ico { width: 32px; height: 32px; font-size: 0.95rem; border-radius: 9px; }

  /* forms — single column, big touch targets */
  .form-row, .form-row-3 { grid-template-columns: 1fr; gap: 10px; }
  .form .f input, .form .f select, .form .f textarea,
  .modal .form .f input, .modal .form .f select {
    min-height: 46px;
    font-size: 0.95rem;
  }
  textarea { width: 100%; }

  /* buttons — thumb-friendly */
  .btn { min-height: 44px; padding: 10px 18px; font-size: 0.88rem; }
  .btn.sm { min-height: 38px; padding: 7px 12px; }
  .btn.big { width: 100%; font-size: 1rem; }
  .actions { flex-wrap: wrap; }
  .actions .btn { flex: 1 1 auto; }

  /* modal → bottom sheet */
  .modal {
    width: 100%;
    max-width: 100%;
    max-height: 92dvh;
    border-radius: var(--r-xl) var(--r-xl) 0 0;
    padding: 20px 16px max(24px, env(safe-area-inset-bottom));
    position: fixed;
    inset-inline: 0;
    bottom: 0;
    margin: 0;
  }
  .overlay { align-items: flex-end; padding: 0; }
  .modal .modal-acts { flex-wrap: wrap; }
  .modal .modal-acts .btn { flex: 1 1 46%; }

  /* tables → card mode (works with data-label attributes) */
  .tbl-wrap.tbl-cards { overflow-x: visible; border: none; }
  .tbl-cards table.tbl, .tbl-cards table.rtbl { border: none; }
  .tbl-cards thead { display: none; }
  .tbl-cards tbody { display: flex; flex-direction: column; gap: 10px; }
  .tbl-cards tr {
    display: block;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--r-md);
    padding: 12px 13px;
  }
  .tbl-cards td {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
    padding: 5px 0;
    border: none;
    text-align: start;
  }
  .tbl-cards td::before {
    content: attr(data-label);
    color: var(--muted);
    font-size: 0.7rem;
    flex-shrink: 0;
    font-weight: 500;
  }
  .tbl-cards td:last-child { justify-content: flex-start; }
  .tbl-cards td:last-child::before { display: none; }
  .tbl-cards .acts { flex-wrap: wrap; gap: 6px; }
  .tbl-cards .acts .btn { flex: 0 1 auto; }
  /* keep horizontal scroll for wide data tables (radar/audit/shop/hosts) */
  .tbl-wrap:not(.tbl-cards) { margin-inline: -2px; }
  .tbl-wrap:not(.tbl-cards) .tbl, .tbl-wrap:not(.tbl-cards) .rtbl { font-size: 0.78rem; }
  .tbl th, .tbl td { padding: 8px 9px; }
  .rtbl th, .rtbl td { padding: 7px 8px; }
  .u-name .nm small { font-size: 0.62rem; }

  /* progress bars in cards */
  .pbar { height: 6px; }

  /* toasts — full-width bottom */
  .toasts {
    bottom: max(12px, env(safe-area-inset-bottom));
    inset-inline: 12px;
    max-width: none;
  }
  .toast { width: 100%; font-size: 0.84rem; }

  /* ---- sub page (public /s/token) ---- */
  .sub-wrap { padding: 22px 12px 70px; }
  .sub-hero h1 { font-size: 1.22rem; }
  .sub-hero .who { font-size: 0.86rem; }
  .sub-stats { grid-template-columns: 1fr 1fr; gap: 9px; }
  .sub-stats .cell { padding: 12px 10px; }
  .sub-stats .v { font-size: 0.95rem; }
  .sub-stats .k { font-size: 0.66rem; }
  .linkbox { flex-wrap: wrap; }
  .linkbox code { font-size: 0.72rem; word-break: break-all; }
  .linkbox .btn { flex: 1 1 30%; }
  .qr-box { justify-content: center; }
  .qr-box canvas { max-width: 82vw; height: auto !important; }
  .import-grid { grid-template-columns: 1fr; }
  .cfg .head { gap: 7px; }
  .cfg .head .host { font-size: 0.7rem; min-width: 100px; flex: 1 1 40%; order: 9; }
  .cfg .head .btn { flex: 1 1 auto; }
  .cfg .linkrow .linkbox code { font-size: 0.66rem; }

  /* dashboard chart */
  .chart-card svg { width: 100%; height: auto; }

  /* radar quick actions */
  .scan-row { flex-direction: column; align-items: stretch; }
  .scan-row .btn { width: 100%; }
}

/* ---- small phones (≤460px) ---- */
@media (max-width: 460px) {
  body { font-size: 0.86rem; }
  .main { padding: 12px 9px 80px; }
  .topbar h1 { font-size: 0.95rem; }
  .stats { grid-template-columns: 1fr 1fr; }
  .stat { padding: 10px; }
  .stat .v { font-size: 0.98rem; }
  .stat .ico { width: 28px; height: 28px; font-size: 0.85rem; }
  .card { padding: 14px 12px 16px; }
  .sub-stats { grid-template-columns: 1fr 1fr; }
  .grid-2 { gap: 14px; }
  .form .f input, .form .f select { font-size: 0.92rem; }
  .tbl th, .tbl td { padding: 7px 7px; }
  .rtbl th, .rtbl td { padding: 6px 6px; font-size: 0.72rem; }
  .mobilebar { padding: 10px 11px; }
  .mobilebar .brand { font-size: 0.9rem; }
  .hamburger { width: 44px; height: 44px; }
  .modal .modal-acts .btn { flex: 1 1 100%; }
}

/* ---- short landscape (phones rotated) ---- */
@media (max-height: 540px) and (orientation: landscape) {
  .modal { max-height: 96dvh; overflow-y: auto; }
  .sidebar { height: 100dvh; }
}

/* ---- touch devices: comfortable hit areas ---- */
@media (pointer: coarse) {
  .btn { min-height: 42px; }
  .btn.sm { min-height: 36px; }
  .nav-item { min-height: 46px; padding-block: 11px; }
  .import-btn { min-height: 54px; }
  .chip, .badge { min-height: 26px; }
  input, select, textarea { font-size: max(0.95rem, 16px); } /* no iOS zoom on focus */
}

/* ---- very wide screens ---- */
@media (min-width: 1600px) {
  .main { max-width: 1440px; }
}

/* ---- print (sub page) ---- */
@media print {
  body { background: #fff; color: #111; }
  .card, .sub-hero, .linkbox, .qr-box { border-color: #ddd; }
  .btn, .import-grid, .toasts, .sub-foot, #btn-refresh { display: none !important; }
}

/* ---- reduced motion ---- */
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation-duration: 0.01ms !important; transition-duration: 0.01ms !important; }
}
