/* ============================================================
   DotOneNet — global app stylesheet
   Layers:  1) base reset & typography
            2) layout shells (topbar, sidebar, page)
            3) components (btn, card, table, form, badge, etc.)
            4) toasts & dialogs
            5) RTL polish
   ============================================================ */

/* ---------- 1. Base ---------- */
*,*::before,*::after { box-sizing: border-box; }
html { scroll-behavior: smooth; }
body {
  font-family: 'Vazirmatn', system-ui, -apple-system, 'Segoe UI', Tahoma, sans-serif;
  background: var(--bg-page);
  color: var(--text-primary);
  margin: 0;
  font-size: var(--text-14);
  line-height: 1.55;
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
}
.mono, code, kbd, samp, pre, [class*='font-mono'] {
  font-family: 'JetBrains Mono', ui-monospace, SFMono-Regular, Menlo, monospace;
}
a { color: var(--brand); text-decoration: none; transition: color .15s; }
a:hover { color: var(--brand-hover); }
img, svg { max-width: 100%; vertical-align: middle; }
h1,h2,h3,h4 { margin: 0; font-weight: 700; color: var(--text-primary); }
h1 { font-size: var(--text-28); }
h2 { font-size: var(--text-22); }
h3 { font-size: var(--text-18); }
p  { margin: 0; }
hr { border: 0; border-top: 1px solid var(--border); margin: var(--sp-4) 0; }
::selection { background: var(--brand-subtle); color: var(--brand); }

button { font-family: inherit; }

/* Skip-to-content link: visible only when focused via keyboard. */
.skip-link {
  position: fixed; top: -100px; inset-inline-start: 0;
  z-index: 1000;
  padding: var(--sp-3) var(--sp-4);
  background: var(--brand); color: #fff; font-weight: 700;
  border-radius: 0 0 var(--r-md) var(--r-md);
  transition: top .15s;
}
.skip-link:focus, .skip-link:focus-visible {
  top: 0; outline: 3px solid var(--bg-page); outline-offset: 2px;
}

/* ---------- 2. Topbar (public) ---------- */
.topbar {
  position: sticky; top: 0; z-index: 30;
  display: flex; align-items: center; gap: var(--sp-6);
  padding: var(--sp-3) var(--sp-6);
  background: color-mix(in srgb, var(--bg-page) 85%, transparent);
  backdrop-filter: blur(16px);
  border-bottom: 1px solid var(--border);
}
.topbar .brand {
  display: flex; align-items: center; gap: var(--sp-2);
  font-weight: 700; font-size: var(--text-18);
  color: var(--text-primary);
}
.topbar-nav { display: flex; gap: var(--sp-1); margin-inline-start: var(--sp-6); }
.topbar-nav a {
  padding: var(--sp-2) var(--sp-3);
  border-radius: var(--r-md);
  color: var(--text-secondary);
  font-weight: 500;
}
.topbar-nav a:hover, .topbar-nav a.on {
  background: var(--bg-hover); color: var(--text-primary);
}
.topbar-actions { margin-inline-start: auto; display: flex; align-items: center; gap: var(--sp-2); }

/* ---------- 2. Sidebar (auth panels) ----------
   Internal-scrolling dashboard layout (à la Slack/GitHub):
   - .app-shell is the viewport-sized frame (height: 100vh, overflow: hidden).
   - .sidebar and .panel-main each scroll *inside* themselves.
   - This avoids the position:sticky + grid + align-self quirk where the
     outer body sometimes refuses to scroll on some browsers/zoom levels.
*/
.app-shell {
  display: grid;
  grid-template-columns: 260px 1fr;
  height: 100vh;
  height: 100svh;          /* small-viewport (mobile address bar safe) */
  overflow: hidden;
}
.sidebar {
  width: 260px; height: 100vh; height: 100svh;
  background: var(--bg-surface); border-inline-end: 1px solid var(--border);
  display: flex; flex-direction: column;
  z-index: 40;
}
.sidebar-head, .sidebar-foot {
  padding: var(--sp-4); border-bottom: 1px solid var(--border);
  display: flex; align-items: center; justify-content: space-between;
}
.sidebar-foot { border-bottom: 0; border-top: 1px solid var(--border); flex-direction: column; gap: var(--sp-3); align-items: stretch; }
.sidebar-head .brand { display: flex; align-items: center; gap: var(--sp-2); font-weight: 700; }
.sidebar-close { display: none; background: transparent; border: 0; color: var(--text-secondary); cursor: pointer; }
.sidebar-nav { flex: 1; overflow-y: auto; padding: var(--sp-3); display: flex; flex-direction: column; gap: 2px; }
.sidebar-nav a {
  display: flex; align-items: center; gap: var(--sp-3);
  padding: var(--sp-2-5) var(--sp-3);
  border-radius: var(--r-md);
  color: var(--text-secondary);
  font-weight: 500;
  font-size: var(--text-14);
}
.sidebar-nav a:hover { background: var(--bg-hover); color: var(--text-primary); }
.sidebar-nav a.on    { background: var(--brand-subtle); color: var(--brand); }
.sidebar-nav i { width: 18px; height: 18px; }

/* Collapsible task groups in the sidebar. */
.sidebar-nav .nav-group { margin: 0; }
.sidebar-nav .nav-group > summary {
  display: flex; align-items: center; gap: var(--sp-3);
  padding: var(--sp-2-5) var(--sp-3);
  border-radius: var(--r-md);
  color: var(--text-secondary);
  font-weight: 500;
  font-size: var(--text-14);
  cursor: pointer;
  list-style: none;
  user-select: none;
}
.sidebar-nav .nav-group > summary::-webkit-details-marker { display: none; }
.sidebar-nav .nav-group > summary:hover { background: var(--bg-hover); color: var(--text-primary); }
.sidebar-nav .nav-group.has-active > summary { color: var(--text-primary); }
.sidebar-nav .nav-group > summary .nav-chevron {
  margin-inline-start: auto;
  width: 16px; height: 16px;
  transition: transform .2s ease;
  color: var(--text-tertiary);
}
.sidebar-nav .nav-group[open] > summary .nav-chevron { transform: rotate(180deg); }
.sidebar-nav .nav-sub {
  display: flex; flex-direction: column; gap: 2px;
  margin-top: 2px;
  padding-inline-start: var(--sp-5);
  border-inline-start: 1px solid var(--border);
  margin-inline-start: calc(var(--sp-3) + 9px);
}
.sidebar-nav .nav-sub a {
  padding: var(--sp-2) var(--sp-3);
  font-size: var(--text-13);
  gap: var(--sp-2-5);
}
.sidebar-nav .nav-sub a i { width: 16px; height: 16px; }

.me { display: flex; align-items: center; gap: var(--sp-2-5); }
.me-avatar {
  width: 36px; height: 36px; border-radius: var(--r-pill);
  background: var(--brand-subtle); color: var(--brand);
  display: flex; align-items: center; justify-content: center;
  font-weight: 700; font-family: 'JetBrains Mono', monospace;
}
.me-name { font-weight: 600; font-size: var(--text-13); color: var(--text-primary); }
.me-role { font-size: var(--text-12); color: var(--text-secondary); }

.panel-main {
  padding: var(--sp-6);
  min-width: 0;
  min-height: 0;            /* allow flex/grid child to actually shrink */
  overflow-y: auto;         /* the main content scrolls inside its column */
  overscroll-behavior-y: contain;
  -webkit-overflow-scrolling: touch;  /* momentum scroll on iOS */
}
.panel-topbar {
  display: flex; align-items: center; gap: var(--sp-4);
  margin-bottom: var(--sp-6);
}
.panel-topbar .panel-title h1 { font-size: var(--text-22); }
.panel-topbar .panel-title p  { color: var(--text-secondary); font-size: var(--text-13); margin-top: 4px; }
.panel-topbar-actions { margin-inline-start: auto; display: flex; gap: var(--sp-2); }
.hamburger { display: none; background: transparent; border: 0; color: var(--text-primary); }

@media (max-width: 980px) {
  .app-shell { grid-template-columns: 1fr; }
  .sidebar {
    position: fixed; inset-inline-start: 0; top: 0; bottom: 0;
    transform: translateX(-100%);
    transition: transform .2s ease;
  }
  .body-rtl .sidebar { transform: translateX(100%); }
  .sidebar.open { transform: translateX(0) !important; }
  .sidebar-close { display: inline-flex; }
  .hamburger { display: inline-flex; }
}

/* ---------- 3. Buttons ---------- */
.btn {
  --bg: var(--bg-surface);
  --fg: var(--text-primary);
  --bd: var(--border);
  display: inline-flex; align-items: center; gap: var(--sp-2);
  padding: var(--sp-2-5) var(--sp-4);
  background: var(--bg); color: var(--fg);
  border: 1px solid var(--bd); border-radius: var(--r-md);
  font-weight: 600; font-size: var(--text-14);
  cursor: pointer; transition: all .15s;
  text-decoration: none; line-height: 1;
}
.btn:hover { filter: brightness(1.07); }
.btn:active { transform: translateY(1px); }
.btn:disabled { opacity: .55; cursor: not-allowed; }
.btn i { width: 16px; height: 16px; }
.btn-sm { padding: var(--sp-1-5) var(--sp-3); font-size: var(--text-13); }
.btn-lg { padding: var(--sp-3) var(--sp-5); font-size: var(--text-16); }
.btn-primary { --bg: var(--brand); --fg: #fff; --bd: var(--brand); }
.btn-primary:hover { --bg: var(--brand-hover); --bd: var(--brand-hover); }
.btn-ghost   { --bg: transparent; --bd: var(--border); }
.btn-danger  { --bg: var(--danger); --fg: #fff; --bd: var(--danger); }
.btn-success { --bg: var(--success); --fg: #fff; --bd: var(--success); }
.btn-block   { width: 100%; justify-content: center; }
.icon-btn {
  width: 36px; height: 36px; display: inline-flex; align-items: center; justify-content: center;
  border-radius: var(--r-md); background: var(--bg-surface); color: var(--text-secondary);
  border: 1px solid var(--border); cursor: pointer;
}
.icon-btn:hover { color: var(--text-primary); background: var(--bg-hover); }

.theme-toggle { width: 36px; height: 36px; padding: 0; border-radius: var(--r-md);
  background: var(--bg-surface); border: 1px solid var(--border); color: var(--text-primary); cursor: pointer; }

/* ---------- 3. Cards & containers ---------- */
.card {
  background: var(--bg-surface); border: 1px solid var(--border);
  border-radius: var(--r-lg); padding: var(--sp-5);
}
.card-pad-lg { padding: var(--sp-6); }
.card-head {
  display: flex; align-items: center; justify-content: space-between;
  margin-bottom: var(--sp-4);
}
.card-head h2 { font-size: var(--text-18); }
.muted   { color: var(--text-secondary); }
.faded   { color: var(--text-tertiary); }
.container { max-width: 1240px; margin-inline: auto; padding-inline: var(--sp-6); }
.container-sm { max-width: 760px; }
.center-page { display: flex; min-height: 100vh; align-items: center; justify-content: center; padding: var(--sp-4); }

/* ---------- 3. Form controls ---------- */
.field { display: flex; flex-direction: column; gap: var(--sp-1-5); margin-bottom: var(--sp-4); }
.label { font-weight: 600; font-size: var(--text-13); color: var(--text-primary); }
.help  { font-size: var(--text-12); color: var(--text-secondary); }
.input, .select, .textarea {
  width: 100%;
  background: var(--bg-page);
  border: 1px solid var(--border);
  border-radius: var(--r-md);
  padding: var(--sp-2-5) var(--sp-3);
  color: var(--text-primary);
  font-family: inherit; font-size: var(--text-14);
  transition: border-color .12s, box-shadow .12s;
}
.input:focus, .select:focus, .textarea:focus {
  outline: 0; border-color: var(--brand);
  box-shadow: 0 0 0 3px var(--brand-subtle);
}
.input::placeholder, .textarea::placeholder { color: var(--text-tertiary); }
.textarea { resize: vertical; min-height: 90px; }
.input-group {
  display: flex; align-items: stretch;
  border: 1px solid var(--border); border-radius: var(--r-md);
  background: var(--bg-page); overflow: hidden;
}
.input-group .input { border: 0; }
.input-group .ig-addon {
  display: inline-flex; align-items: center; padding: 0 var(--sp-3);
  background: var(--bg-hover); color: var(--text-secondary);
  border-inline-end: 1px solid var(--border);
  /* iOS Safari needs cursor:pointer for reliable click dispatch on
     non-anchor buttons. Without it, the eye-icon tap is silently lost
     ~30% of the time, especially after the input changes type. */
  cursor: pointer;
  -webkit-tap-highlight-color: rgba(0,0,0,0.05);
  min-height: 44px; /* WCAG + iOS touch target */
  touch-action: manipulation; /* kill 300ms double-tap delay */
}
/* svg/i inside the addon must not steal the click — let the button receive it. */
.input-group .ig-addon > * { pointer-events: none; }
/* Compact input with a trailing suffix label (e.g. "ریال"). The input
   keeps its own border/focus styling; the suffix sits on top of it at the
   trailing edge. Works in both LTR and RTL because we use logical insets. */
.input-affix { position: relative; display: block; }
.input-affix .input { padding-inline-end: 56px; }
.input-affix-end {
  position: absolute;
  inset-inline-end: 10px;
  top: 50%; transform: translateY(-50%);
  font-size: var(--text-12);
  color: var(--text-secondary);
  background: var(--bg-page);
  padding: 2px 6px;
  border-radius: var(--r-sm);
  pointer-events: none;
  font-weight: 600;
}
.checkbox, .radio { display: inline-flex; align-items: center; gap: var(--sp-2); font-size: var(--text-13); cursor: pointer; }

/* ---------- 3. Badges & chips ---------- */
.badge {
  display: inline-flex; align-items: center; gap: 4px;
  padding: 2px var(--sp-2); border-radius: var(--r-pill);
  font-size: var(--text-12); font-weight: 600;
  background: var(--bg-hover); color: var(--text-secondary);
}
.badge-success { background: color-mix(in srgb, var(--success) 15%, transparent); color: var(--success); }
.badge-warn    { background: color-mix(in srgb, var(--warning) 15%, transparent); color: var(--warning); }
.badge-danger  { background: color-mix(in srgb, var(--danger)  15%, transparent); color: var(--danger);  }
.badge-info    { background: var(--brand-subtle); color: var(--brand); }

/* ---------- VIP / private-plan markers ---------- */
.vip-mark {
  display: inline-flex; align-items: center; gap: 4px;
  padding: 2px 6px; border-radius: var(--r-pill);
  background: color-mix(in srgb, var(--warning) 18%, transparent);
  color: var(--warning); font-size: var(--text-11); font-weight: 700;
  white-space: nowrap;
}
.vip-mark i { width: 12px; height: 12px; }
.vip-mark-sm   { padding: 0 4px; font-size: 10px; }
.vip-mark-sm i { width: 10px; height: 10px; }
.vip-mark-lg   { padding: 4px 10px; font-size: var(--text-13); }
.vip-mark-lg i { width: 14px; height: 14px; }
.vip-icon      { width: 14px; height: 14px; color: var(--warning); vertical-align: middle; }

/* Table rows containing a VIP customer: subtle warning tint + start-edge accent (RTL-safe) */
.table tr.row-vip td {
  background: color-mix(in srgb, var(--warning) 6%, transparent);
}
.table tr.row-vip td:first-child {
  border-inline-start: 3px solid var(--warning);
}
.table tr.row-vip-soft td {
  background: color-mix(in srgb, var(--warning) 3%, transparent);
}

/* ---------- 3. Table ---------- */
.table-wrap {
  background: var(--bg-surface); border: 1px solid var(--border);
  border-radius: var(--r-lg); overflow: hidden;
}
.table { width: 100%; border-collapse: collapse; }
.table th, .table td {
  padding: var(--sp-3) var(--sp-4);
  text-align: start; font-size: var(--text-13);
  border-bottom: 1px solid var(--border);
}
.table th {
  background: var(--bg-hover);
  font-weight: 600; color: var(--text-secondary);
  font-size: var(--text-12); text-transform: uppercase; letter-spacing: .03em;
}
.table tbody tr:hover { background: var(--bg-hover); }
.table tbody tr:last-child td { border-bottom: 0; }

/* ---------- 3. KPI grid ---------- */
.kpi-grid { display: grid; gap: var(--sp-4); grid-template-columns: repeat(auto-fit, minmax(220px, 1fr)); margin-bottom: var(--sp-6); }
.kpi { padding: var(--sp-4); background: var(--bg-surface); border: 1px solid var(--border); border-radius: var(--r-lg); transition: transform .15s, border-color .15s, box-shadow .15s; }
/* When the KPI is wrapped in <a>, give it visual affordance */
a.kpi, .kpi[role="link"], .kpi[tabindex] { cursor: pointer; text-decoration: none; color: inherit; }
a.kpi:hover, .kpi[role="link"]:hover, .kpi[tabindex]:hover {
  transform: translateY(-1px);
  border-color: var(--brand);
  box-shadow: var(--shadow-md);
}
.kpi-label { color: var(--text-secondary); font-size: var(--text-13); margin-bottom: var(--sp-2); display: flex; align-items: center; gap: 6px; }
.kpi-value { font-size: var(--text-28); font-weight: 700; }
.kpi-meta  { color: var(--text-secondary); font-size: var(--text-12); margin-top: 4px; }

/* ---------- 3. Progress ---------- */
.progress {
  height: 8px; border-radius: var(--r-pill); background: var(--bg-hover); overflow: hidden;
}
.progress-bar { height: 100%; background: var(--brand); border-radius: var(--r-pill); transition: width .3s; }
.progress-bar.warn   { background: var(--warning); }
.progress-bar.danger { background: var(--danger); }

/* ---------- 3. Empty / loading / skeleton ---------- */
.empty {
  padding: var(--sp-8) var(--sp-4); text-align: center;
  display: flex; flex-direction: column; gap: var(--sp-2); align-items: center;
  color: var(--text-secondary);
}
.empty i { width: 40px; height: 40px; color: var(--text-tertiary); }
.skeleton { background: linear-gradient(90deg, var(--bg-hover) 0%, var(--bg-surface) 50%, var(--bg-hover) 100%);
  background-size: 200% 100%; animation: shimmer 1.4s infinite; border-radius: var(--r-md); }
@keyframes shimmer { 0% { background-position: 200% 0; } 100% { background-position: -200% 0; } }
.spin { animation: spin .8s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }
/* Standalone spinner — drop into any container that needs loading feedback */
.spinner {
  display: inline-block;
  width: 24px; height: 24px;
  border: 3px solid var(--bg-hover);
  border-top-color: var(--brand);
  border-radius: 50%;
  animation: spin .7s linear infinite;
  vertical-align: middle;
}
.spinner-sm { width: 16px; height: 16px; border-width: 2px; }
.spinner-lg { width: 40px; height: 40px; border-width: 4px; }

/* ---------- 4. Toasts & dialogs ---------- */
.toasts { position: fixed; top: var(--sp-4); inset-inline-end: var(--sp-4); display: flex; flex-direction: column; gap: var(--sp-2); z-index: 100; pointer-events: none; }
.toast {
  display: flex; align-items: center; gap: var(--sp-2);
  background: var(--bg-surface); border: 1px solid var(--border); border-radius: var(--r-md);
  padding: var(--sp-3) var(--sp-4); min-width: 260px; max-width: 380px;
  box-shadow: var(--shadow-md);
  transform: translateX(20px); opacity: 0; transition: all .2s;
  pointer-events: auto;
}
.body-rtl .toast { transform: translateX(-20px); }
.toast.in { transform: translateX(0); opacity: 1; }
.toast.out { opacity: 0; }
.toast i { width: 18px; height: 18px; }
.toast-success { border-color: var(--success); color: var(--success); animation: toastPop .25s ease; }
.toast-success span { color: var(--text-primary); }
@keyframes toastPop {
  0%   { transform: scale(.92); }
  60%  { transform: scale(1.04); }
  100% { transform: scale(1); }
}
.toast-error   { border-color: var(--danger);  color: var(--danger);  }
.toast-error   span { color: var(--text-primary); }
.toast-info    { border-color: var(--brand);   color: var(--brand);   }
.toast-info    span { color: var(--text-primary); }

.dialog-scrim {
  position: fixed; inset: 0; z-index: 90;
  background: rgba(0,0,0,.55); backdrop-filter: blur(4px);
  display: flex; align-items: center; justify-content: center; padding: var(--sp-4);
}
.dialog-box {
  background: var(--bg-surface); border: 1px solid var(--border); border-radius: var(--r-lg);
  width: 100%; max-width: 480px; max-height: calc(100vh - var(--sp-8));
  display: flex; flex-direction: column;
}
.dialog-head { display: flex; align-items: center; justify-content: space-between; padding: var(--sp-4); border-bottom: 1px solid var(--border); flex: 0 0 auto; }
.dialog-body { padding: var(--sp-4); color: var(--text-secondary); overflow-y: auto; flex: 1 1 auto; min-height: 0; }
.dialog-foot { display: flex; justify-content: flex-end; gap: var(--sp-2); padding: var(--sp-4); border-top: 1px solid var(--border); flex: 0 0 auto; flex-wrap: wrap; }

/* ---------- 5. RTL polish ---------- */
.body-rtl { font-family: 'Vazirmatn', system-ui, sans-serif; }
.body-rtl .table th, .body-rtl .table td { text-align: right; }

/* numbers/IDs should stay LTR even inside RTL */
.ltr, .mono, code, kbd, samp { direction: ltr; unicode-bidi: isolate; }

/* utility */
.row { display: flex; gap: var(--sp-3); align-items: center; flex-wrap: wrap; }
.col { display: flex; flex-direction: column; gap: var(--sp-3); }
.gap-2 { gap: var(--sp-2); }
.gap-4 { gap: var(--sp-4); }
.grow  { flex: 1; }
.hidden { display: none !important; }
.text-center { text-align: center; }
.text-end { text-align: end; }
.mt-2 { margin-top: var(--sp-2); }
.mt-4 { margin-top: var(--sp-4); }
.mt-6 { margin-top: var(--sp-6); }
.mb-4 { margin-bottom: var(--sp-4); }
.mb-6 { margin-bottom: var(--sp-6); }

/* Mobile sidebar scrim — only locks scroll on small screens. */
@media (max-width: 980px) {
  body.sidebar-locked { overflow: hidden; }
  /* The main content scrolls internally now, so lock that too. */
  body.sidebar-locked .panel-main { overflow: hidden; }
  body.sidebar-locked::before {
    content: ''; position: fixed; inset: 0; background: rgba(0,0,0,.45); z-index: 35;
  }
}

/* Default scroll chaining stays auto so wheel events bubble from .sidebar-nav
   to <body> once the sidebar reaches its top/bottom — letting the user keep
   scrolling the page even with their mouse hovering the menu. */
.sidebar-nav { overscroll-behavior-y: auto; }

/* ============================================================
   Responsive polish
   - Tighten paddings on small screens
   - Allow public topbar nav to wrap / collapse
   - Wider plan/kpi grids on tiny devices
   - Force dialog/toast to be mobile-safe
   ============================================================ */

/* ≤ 980px: panels collapse (handled above) + extra padding tweaks */
@media (max-width: 980px) {
  .panel-main { padding: var(--sp-4); }
  .panel-topbar { gap: var(--sp-2); margin-bottom: var(--sp-4); }
  .panel-topbar .panel-title h1 { font-size: var(--text-18); }
  .panel-topbar .panel-title p { font-size: var(--text-12); }
  .topbar { padding: var(--sp-2) var(--sp-3); gap: var(--sp-3); flex-wrap: wrap; }
  .topbar-nav { margin-inline-start: 0; gap: 0; flex-wrap: wrap; }
  .topbar-nav a { padding: var(--sp-1-5) var(--sp-2); }
  .topbar-actions { gap: var(--sp-1-5); margin-inline-start: 0; }
  .container { padding-inline: var(--sp-4); }
  .kpi-grid { grid-template-columns: repeat(auto-fit, minmax(160px, 1fr)); gap: var(--sp-3); }
  .kpi { padding: var(--sp-3); }
  .kpi-value { font-size: var(--text-22); }
  .card { padding: var(--sp-4); }
  .card-pad-lg { padding: var(--sp-4); }
}

/* ≤ 640px: phone-grade. */
@media (max-width: 640px) {
  .panel-main { padding: var(--sp-3); }
  .panel-topbar .panel-title p { display: none; }
  /* WCAG 2.5.5: tap targets must be ≥ 44×44 — override earlier 32px rule */
  .panel-topbar-actions .icon-btn { width: 44px; height: 44px; }
  .topbar { padding: var(--sp-2); }
  .topbar .brand span { display: none; }      /* keep just logo on tiny screens */
  .topbar-nav a { font-size: var(--text-13); }
  .container { padding-inline: var(--sp-3); }
  h1 { font-size: var(--text-22); }
  h2 { font-size: var(--text-18); }
  .btn { padding: var(--sp-2) var(--sp-3); font-size: var(--text-13); }
  .btn-lg { padding: var(--sp-2-5) var(--sp-4); font-size: var(--text-14); }
  .row { gap: var(--sp-2); }
  .row.gap-4 { gap: var(--sp-2); }
  .field { margin-bottom: var(--sp-3); }
  /* Stack pairs of grow fields so the inputs never share a row when they'd
     otherwise be < 200px wide. */
  .row > .field.grow { flex: 1 1 100%; min-width: 0; }
  .kpi-grid { grid-template-columns: 1fr 1fr; }
  .table th, .table td { padding: var(--sp-2) var(--sp-2-5); font-size: var(--text-12); }
  /* Wrap legacy tables horizontally on very small screens. .table-cards opts
     out — they convert to card layout instead via the .table-cards rules above. */
  .table-wrap:not(.table-cards-wrap) { overflow-x: auto; }
  .table:not(.table-cards) { min-width: 520px; }
  .sidebar { width: 86vw; }
  .dialog-box { max-width: 96vw; }
  .toasts { inset-inline-end: var(--sp-2); top: var(--sp-2); }
}

/* ≤ 380px: ultra small. */
@media (max-width: 380px) {
  .panel-main { padding: var(--sp-2); }
  /* Keep 2-column KPIs even on the smallest phones — single-column makes
     the dashboard feel infinitely long. Smaller font compensates for width. */
  .kpi-grid { grid-template-columns: 1fr 1fr; gap: var(--sp-2); }
  .kpi { padding: var(--sp-2-5); }
  .kpi-value { font-size: var(--text-18); }
  .kpi-label { font-size: var(--text-11); }
  .kpi-meta  { font-size: var(--text-10); }
  .panel-topbar .panel-title h1 { font-size: var(--text-16); }
  .action-chip { padding: 6px 10px; font-size: var(--text-12); }
}

/* ============================================================
   12e. KPI loading state
   When a KPI value is still '—' (initial), give it a subtle shimmer
   so the user knows data is loading, not missing. Removed as soon
   as JS writes the real value into the element.
   ============================================================ */
/* KPI shimmer removed 2026-05-30 — only admin/dashboard.js set the
   data-loaded flag, so KPIs on reseller/user pages stayed `transparent`
   forever. Show the real value (or "—") immediately on all panels. */
.kpi-value { /* shimmer disabled */ }

/* ============================================================
   12c. Button loading state
   Add .is-loading to any button to show a spinner WITHOUT replacing
   its label. The text fades out, a spinner overlays it. Layout stable.
   ============================================================ */
.btn.is-loading,
.action-chip.is-loading,
.icon-btn.is-loading {
  position: relative;
  pointer-events: none;
  color: transparent !important;
}
.btn.is-loading > *,
.action-chip.is-loading > *,
.icon-btn.is-loading > * {
  opacity: 0;
}
.btn.is-loading::after,
.action-chip.is-loading::after,
.icon-btn.is-loading::after {
  content: '';
  position: absolute;
  top: 50%; left: 50%;
  width: 16px; height: 16px;
  margin: -8px 0 0 -8px;
  border: 2px solid currentColor;
  border-top-color: transparent;
  border-radius: 50%;
  animation: btnSpin .7s linear infinite;
  color: var(--text-primary);
  opacity: 1 !important;
}
.btn-primary.is-loading::after,
.btn-danger.is-loading::after,
.btn-success.is-loading::after { color: #fff; }
@keyframes btnSpin {
  to { transform: rotate(360deg); }
}

/* Disabled state should propagate cursor to children */
.btn:disabled, .btn:disabled *,
.action-chip:disabled, .action-chip:disabled *,
.icon-btn:disabled, .icon-btn:disabled * {
  cursor: not-allowed !important;
}

/* ============================================================
   12a. Form validation feedback
   - .field-error: inline error message under the input
   - [aria-invalid=true]: red ring on the input
   - .field-success: green checkmark for validated state
   ============================================================ */
.field-error {
  display: flex; align-items: center; gap: 6px;
  margin-top: 6px; padding: 4px 8px;
  background: var(--danger-subtle);
  color: var(--danger);
  border-radius: var(--r-md);
  font-size: var(--text-12);
  font-weight: 500;
  animation: errorShake .22s ease;
}
.field-error::before {
  content: '⚠'; font-size: 14px; font-weight: 700;
}
.field-success {
  margin-top: 6px;
  color: var(--success);
  font-size: var(--text-12);
  font-weight: 500;
}
.input[aria-invalid="true"],
.select[aria-invalid="true"],
.textarea[aria-invalid="true"] {
  border-color: var(--danger);
  box-shadow: 0 0 0 3px var(--danger-subtle);
}
.input[aria-invalid="true"]:focus,
.select[aria-invalid="true"]:focus,
.textarea[aria-invalid="true"]:focus {
  border-color: var(--danger);
  box-shadow: 0 0 0 3px color-mix(in srgb, var(--danger) 30%, transparent);
}
@keyframes errorShake {
  0%,100% { transform: translateX(0); }
  25%     { transform: translateX(-3px); }
  75%     { transform: translateX(3px); }
}

/* ============================================================
   12b. Accessibility — visible focus on EVERY interactive element
   WCAG 2.4.7 (AA). Uses :focus-visible so mouse clicks don't show
   the ring, only keyboard navigation does.
   ============================================================ */
a:focus-visible,
button:focus-visible,
.btn:focus-visible,
.action-chip:focus-visible,
.icon-btn:focus-visible,
.theme-toggle:focus-visible,
.hamburger:focus-visible,
.sidebar-close:focus-visible,
.lang-btn:focus-visible,
.seg-btn:focus-visible,
[role="button"]:focus-visible,
[tabindex]:focus-visible {
  outline: 3px solid var(--brand);
  outline-offset: 2px;
  box-shadow: 0 0 0 3px var(--brand-subtle);
  border-radius: var(--r-md);
}
/* Inputs already have their own focus ring — keep them consistent */
.input:focus-visible, .select:focus-visible, .textarea:focus-visible {
  outline: 2px solid var(--brand);
  outline-offset: 0;
}
/* Cards/links: subtler ring */
.card:focus-within,
.kpi:focus-within {
  box-shadow: 0 0 0 2px var(--brand-subtle);
}

/* ============================================================
   12d. Utility classes — replace common inline styles
   The 5 most-repeated inline-style patterns now have named classes.
   Existing pages keep working; new code should use these.
   ============================================================ */
.flex-between { display: flex; align-items: center; justify-content: space-between; gap: var(--sp-2); }
.flex-center  { display: flex; align-items: center; justify-content: center; gap: var(--sp-2); }
.text-ltr     { direction: ltr; text-align: left; }
.text-rtl     { direction: rtl; text-align: right; }
.text-sm      { font-size: var(--text-12); }
.text-xs      { font-size: var(--text-11); }
.full-w       { width: 100%; }
.no-shrink    { flex-shrink: 0; }
.icon-inline  { width: 14px; height: 14px; vertical-align: middle; }
.divider      { margin: var(--sp-5) 0; border: 0; border-top: 1px solid var(--border); }
.stack-sm     { display: flex; flex-direction: column; gap: var(--sp-2); }
.stack-md     { display: flex; flex-direction: column; gap: var(--sp-3); }
.wrap-anywhere { word-break: break-word; overflow-wrap: anywhere; }

/* ============================================================
   12. Mobile overflow guards
   - Dialogs never exceed viewport width on mobile (form min-widths inside
     get clamped down by the dialog box)
   - Long words / URLs wrap instead of pushing the layout
   ============================================================ */
@media (max-width: 640px) {
  .dialog-body, .dialog-body * { max-width: 100% !important; }
  .dialog-body form, .dialog-body .col, .dialog-body .row {
    min-width: 0 !important;
  }
  /* Long URLs / mono blocks must break, not push the page */
  .mono, code, pre, .input, .textarea {
    word-break: break-word;
    overflow-wrap: anywhere;
  }
  /* Pre blocks (e.g. API examples) scroll horizontally inside themselves */
  pre { overflow-x: auto; }
}

/* ============================================================
   6. Mobile-app hardening layer
   - Zero horizontal overflow
   - Safe-area-inset for notch / home indicator
   - 44x44 minimum touch targets on mobile
   - Native-app feel: no tap highlight, no rubber-band overflow
   - .hscroll utility for swipeable carousels
   - Topbar nav becomes a horizontal swipe strip instead of wrapping
   ============================================================ */

html, body {
  max-width: 100%;
  overflow-x: hidden;
}
body {
  overscroll-behavior-y: contain;
  -webkit-tap-highlight-color: transparent;
  padding-left:  env(safe-area-inset-left);
  padding-right: env(safe-area-inset-right);
}

/* Sticky/fixed shells respect notches */
.topbar          { padding-top: max(var(--sp-3), env(safe-area-inset-top)); }
.sidebar         { padding-top: env(safe-area-inset-top); padding-bottom: env(safe-area-inset-bottom); }
.sidebar-foot    { padding-bottom: max(var(--sp-4), env(safe-area-inset-bottom)); }
.toasts          { top: max(var(--sp-4), env(safe-area-inset-top)); }

/* Horizontal scrollable container (swipeable carousel).
   Drop this class on any flex row that should swipe instead of wrap. */
.hscroll {
  display: flex;
  gap: var(--sp-3);
  overflow-x: auto;
  overflow-y: hidden;
  scroll-snap-type: x mandatory;
  -webkit-overflow-scrolling: touch;
  overscroll-behavior-x: contain;
  scrollbar-width: none;
  -ms-overflow-style: none;
}
.hscroll::-webkit-scrollbar { display: none; }
.hscroll > * { scroll-snap-align: start; flex: 0 0 auto; }

/* ≤ 980px: app-like touch targets + wrap-friendly topbar layout */
@media (max-width: 980px) {
  /* Topbar: allow wrap onto two rows so the actions never get clipped on
     narrow phones. Row 1 = brand + actions, row 2 = nav (horizontal scroll). */
  .topbar {
    flex-wrap: wrap;
    overflow: visible;
    row-gap: var(--sp-2);
    column-gap: var(--sp-2);
  }
  .topbar-actions { order: 2; margin-inline-start: auto; flex-wrap: wrap; }
  .topbar-nav {
    order: 3;
    flex-basis: 100%;
    flex-wrap: nowrap;
    overflow-x: auto;
    scrollbar-width: none;
    -ms-overflow-style: none;
    scroll-snap-type: x proximity;
    -webkit-overflow-scrolling: touch;
    min-width: 0;
    margin-inline-start: 0;
    padding-bottom: 2px;
  }
  .topbar-nav::-webkit-scrollbar { display: none; }
  .topbar-nav a {
    flex: 0 0 auto;
    min-height: 40px;
    display: inline-flex;
    align-items: center;
    padding: 0 var(--sp-3);
    scroll-snap-align: start;
  }

  /* Touch targets: 44x44 minimum on anything tappable */
  .btn               { min-height: 44px; }
  .btn-sm            { min-height: 40px; }   /* still ≥ minimum w/ icon padding */
  .icon-btn,
  .theme-toggle,
  .hamburger,
  .sidebar-close     { min-width: 44px; min-height: 44px; }
  .sidebar-nav a     { min-height: 44px; padding-block: var(--sp-3); }
  .lang-btn          { min-height: 36px; min-width: 36px; padding: var(--sp-1-5) var(--sp-3); }
  .checkbox,
  .radio             { min-height: 32px; padding-block: 4px; }
  .input, .select    { min-height: 44px; font-size: var(--text-16); } /* 16px = no iOS auto-zoom */
  .textarea          { font-size: var(--text-16); }

  /* Drawer should reach the very top edge */
  .sidebar { top: 0; }

  /* Tables already wrap horizontally — make them snap nicely */
  .table-wrap { scroll-snap-type: x proximity; -webkit-overflow-scrolling: touch; }

  /* Dialogs hug the bottom of the viewport like a bottom sheet */
  .dialog-scrim { padding: var(--sp-3); align-items: flex-end; }
  .dialog-box {
    max-width: 100%;
    border-radius: var(--r-xl) var(--r-xl) var(--r-md) var(--r-md);
    margin-bottom: env(safe-area-inset-bottom);
  }
}

/* ≤ 640px: phone-grade touch hardening overrides earlier 32px icon-btn */
@media (max-width: 640px) {
  .panel-topbar-actions .icon-btn { width: 44px; height: 44px; }
  .topbar { gap: var(--sp-2); padding-inline: var(--sp-3); }
  .btn { padding-block: var(--sp-2-5); }
}

/* Respect reduced motion (cuts the smooth-scroll + skeleton shimmer) */
@media (prefers-reduced-motion: reduce) {
  html { scroll-behavior: auto; }
  *, *::before, *::after {
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.01ms !important;
  }
}

/* ============================================================
   7. Labeled icon buttons (icon + text caption)
   - .btn-icon-text is for buttons that should always show both icon and text
   - .icon-btn[data-label] auto-renders a tiny caption underneath the icon
   - On hover, an inline tooltip is shown for plain icon-only buttons
   ============================================================ */
.icon-btn[data-label] {
  position: relative;
  flex-direction: column;
  width: auto; min-width: 44px;
  height: auto; min-height: 44px;
  padding: 4px 8px;
  font-size: 11px;
  gap: 2px;
}
.icon-btn[data-label]::after {
  content: attr(data-label);
  color: var(--text-secondary);
  font-size: 11px;
  font-weight: 500;
  white-space: nowrap;
}
.icon-btn[data-label] i { width: 18px; height: 18px; }

/* ============================================================
   Icon buttons inside table rows: always render the title text
   beside the icon. Outside tables (panel toolbars / dialog close)
   they stay icon-only and tooltips handle the labeling.
   ============================================================ */
.table td .icon-btn,
.table-cards td .icon-btn {
  width: auto; min-width: 0; height: auto; min-height: 32px;
  flex-direction: row;
  gap: 6px;
  padding: 6px 10px;
  font-size: var(--text-12);
  font-weight: 600;
  border-radius: var(--r-pill);
  background: var(--bg-page);
}
.table td .icon-btn::after,
.table-cards td .icon-btn::after {
  content: attr(title);
  font-size: var(--text-12);
  font-weight: 600;
  color: inherit;
  white-space: nowrap;
}
/* When data-label is preferred (e.g. caller already set it for a11y) */
.table td .icon-btn[data-label]::after,
.table-cards td .icon-btn[data-label]::after { content: attr(data-label); }
/* Hide the loading-state pseudo content so it doesn't overlap text */
.table td .icon-btn.is-loading::after,
.table-cards td .icon-btn.is-loading::after { content: none; }
/* Hover affordance matches .action-chip for visual consistency */
.table td .icon-btn:hover,
.table-cards td .icon-btn:hover { border-color: var(--brand); color: var(--brand); }
.table td .icon-btn i,
.table-cards td .icon-btn i { width: 14px; height: 14px; }

/* Action toolbars: never push the table off-screen on mobile.
   Allow row to wrap so all chips remain visible. */
.table td.actions,
.table td.actions-bar,
.table td.row,
.table-cards td.actions,
.table-cards td.actions-bar { flex-wrap: wrap; gap: var(--sp-2); }

/* Touch-safe sizing inside mobile card layout */
@media (max-width: 640px) {
  .table-cards td .icon-btn { min-height: 36px; padding: 8px 12px; }
}

/* Plain icon-only buttons get a hover tooltip from title="…" via [data-tooltip] helper */
[data-tooltip] { position: relative; }
[data-tooltip]:hover::before,
[data-tooltip]:focus-visible::before {
  content: attr(data-tooltip);
  position: absolute; bottom: calc(100% + 6px); left: 50%;
  transform: translateX(-50%);
  background: var(--bg-page); color: var(--text-primary);
  border: 1px solid var(--border); border-radius: var(--r-md);
  padding: 4px 8px; font-size: 11px; font-weight: 600;
  white-space: nowrap; pointer-events: none; z-index: 50;
  box-shadow: var(--shadow-sm);
}

/* ============================================================
   8. Auto card-view for tables on phones (≤640px)
   Mark a <table> with .table-cards to opt-in. Headers must use
   `data-label="…"` on each <td> OR be in the same column order
   as the <th>s — we use a JS shim in app.js that copies <th>
   text into td[data-label] when missing.
   ============================================================ */
@media (max-width: 640px) {
  .table-cards { min-width: 0; }
  .table-cards thead { display: none; }
  .table-cards, .table-cards tbody, .table-cards tr, .table-cards td { display: block; width: 100%; }
  .table-cards tr {
    background: var(--bg-surface);
    border: 1px solid var(--border);
    border-radius: var(--r-lg);
    margin-bottom: var(--sp-3);
    padding: var(--sp-3);
  }
  .table-cards tbody tr:hover { background: var(--bg-surface); }
  .table-cards td {
    display: flex; align-items: center; justify-content: space-between;
    gap: var(--sp-3);
    padding: 6px 0 !important;
    border-bottom: 1px dashed var(--border) !important;
    font-size: var(--text-13);
  }
  .table-cards td:last-child { border-bottom: 0 !important; }
  .table-cards td::before {
    content: attr(data-label);
    font-weight: 600;
    font-size: var(--text-12);
    color: var(--text-secondary);
    text-transform: uppercase;
    letter-spacing: 0.03em;
    flex: 0 0 40%;
  }
  /* Hide the auto-label when the cell is intentionally empty (e.g., action cell) */
  .table-cards td[data-label=""]::before,
  .table-cards td:not([data-label])::before { display: none; }
  /* Action cells (buttons) span full width and stack their label above */
  .table-cards td.actions,
  .table-cards td.actions-bar,
  .table-cards td:has(> .btn),
  .table-cards td:has(> .action-chip),
  .table-cards td:has(> .icon-btn),
  .table-cards td:has(> .row) {
    flex-wrap: wrap;
    justify-content: flex-start;
  }
  /* Push the auto-label onto its own line for action cells so the buttons
     have full width to wrap into. */
  .table-cards td:has(> .action-chip)::before,
  .table-cards td:has(> .icon-btn)::before,
  .table-cards td.actions-bar::before {
    flex: 0 0 100%;
    margin-bottom: 4px;
  }
  /* Make the table-wrapper transparent in card mode */
  .table-cards-wrap { background: transparent !important; border: 0 !important; }
  /* Inside cards, .row should also wrap */
  .table-cards td > .row { flex-wrap: wrap; }
}

/* ============================================================
   9. Action toolbar — row of labeled chip-buttons
   Use:  <div class="actions-bar"> <button class="action-chip">…</button> … </div>
   Each chip shows icon + label on every screen size; wraps on mobile.
   ============================================================ */
.actions-bar {
  display: flex; flex-wrap: wrap; gap: var(--sp-2);
}
.action-chip {
  display: inline-flex; align-items: center; gap: 6px;
  padding: 6px 12px;
  background: var(--bg-page);
  border: 1px solid var(--border);
  border-radius: var(--r-pill);
  color: var(--text-primary);
  font-size: var(--text-13);
  font-weight: 600;
  cursor: pointer;
  transition: all .15s;
  text-decoration: none;
  line-height: 1.2;
}
.action-chip:hover { background: var(--bg-hover); border-color: var(--brand); color: var(--brand); }
.action-chip.danger:hover { border-color: var(--danger); color: var(--danger); }
.action-chip.success { background: color-mix(in srgb, var(--success) 8%, transparent); }
.action-chip.success:hover { border-color: var(--success); color: var(--success); }
.action-chip i { width: 14px; height: 14px; }
.action-chip.disabled { opacity: 0.5; pointer-events: none; }
@media (max-width: 640px) {
  .action-chip { padding: 8px 12px; font-size: var(--text-13); min-height: 36px; }
}

/* ============================================================
  10. Status dot — small colored circle in front of label
   ============================================================ */
.dot { display: inline-block; width: 8px; height: 8px; border-radius: 50%; background: var(--text-tertiary); margin-inline-end: 6px; vertical-align: middle; }
.dot.ok    { background: var(--success); box-shadow: 0 0 6px color-mix(in srgb, var(--success) 70%, transparent); }
.dot.warn  { background: var(--warning); }
.dot.err   { background: var(--danger);  }
.dot.pulse { animation: pulseDot 1.5s infinite ease-in-out; }
@keyframes pulseDot { 0%,100% { opacity: 1; } 50% { opacity: .4; } }

/* ============================================================
  11. Settings groups — card with section header + body grid
   ============================================================ */
.settings-grid { display: grid; gap: var(--sp-4); grid-template-columns: repeat(auto-fit, minmax(320px, 1fr)); }
.settings-card { background: var(--bg-surface); border: 1px solid var(--border); border-radius: var(--r-lg); padding: var(--sp-5); }
.settings-card-head {
  display: flex; align-items: center; gap: var(--sp-2);
  font-size: var(--text-16); font-weight: 700; color: var(--text-primary);
  margin-bottom: var(--sp-4);
  padding-bottom: var(--sp-3);
  border-bottom: 1px solid var(--border);
}
.settings-card-head i { width: 18px; height: 18px; color: var(--brand); }
.settings-card .help { line-height: 1.6; }

/* Plan builder — graphical card for plan creation/edit */
.plan-builder { display: grid; grid-template-columns: 1fr 1fr; gap: var(--sp-5); }
@media (max-width: 980px) { .plan-builder { grid-template-columns: 1fr; } }
.plan-preview {
  background: linear-gradient(135deg, color-mix(in srgb, var(--brand) 14%, var(--bg-surface)), var(--bg-surface));
  border: 1px solid var(--border);
  border-radius: var(--r-xl);
  padding: var(--sp-5);
  position: relative;
  overflow: hidden;
}
.plan-preview::before {
  content: ''; position: absolute; inset: -40% -40% auto auto;
  width: 220px; height: 220px;
  background: radial-gradient(closest-side, var(--brand-subtle), transparent);
  pointer-events: none;
}
.plan-preview .pp-price { font-size: 36px; font-weight: 800; color: var(--brand); line-height: 1; margin: var(--sp-3) 0; }
.plan-preview .pp-name  { font-size: 20px; font-weight: 700; }
.plan-preview .pp-desc  { color: var(--text-secondary); margin-top: var(--sp-2); }
.plan-preview .pp-features { list-style: none; padding: 0; margin: var(--sp-4) 0 0; display: grid; gap: 8px; }
.plan-preview .pp-features li { display: flex; align-items: center; gap: 8px; }
.plan-preview .pp-features i { width: 16px; height: 16px; color: var(--success); }
.plan-preview .pp-badge { position: absolute; top: 12px; inset-inline-end: 12px; }

/* Dashboard widgets */
.system-health-grid {
  display: grid; gap: var(--sp-3);
  grid-template-columns: repeat(auto-fit, minmax(170px, 1fr));
}
.health-tile {
  background: var(--bg-page);
  border: 1px solid var(--border);
  border-radius: var(--r-md);
  padding: var(--sp-3);
}
.health-tile .h-label { color: var(--text-secondary); font-size: var(--text-12); display: flex; align-items: center; gap: 6px; }
.health-tile .h-value { font-size: var(--text-22); font-weight: 700; margin-top: 4px; }
.health-tile .h-meta  { color: var(--text-tertiary); font-size: var(--text-11); margin-top: 2px; }
.health-tile .h-bar   { margin-top: var(--sp-2); }

/* Live indicator (top-right of dashboard) */
.live-pill { display: inline-flex; align-items: center; gap: 6px; padding: 4px 10px; border-radius: var(--r-pill); background: color-mix(in srgb, var(--success) 12%, transparent); color: var(--success); font-size: var(--text-12); font-weight: 700; }
.live-pill .dot { margin: 0; }

/* ============================================================
   MOBILE POLISH v2 — 2026-05-30
   - Uniform button rows (consistent height + wrap behaviour)
   - Form rows that auto-stack
   - Safer dialog scrolling on long content
   - Pricing/plan card buttons always full-width on phone
   - Card grids tighter on 360–400px (entry-level phones)
   - Sticky toolbars that respect the keyboard
   ============================================================ */

/* (a) Action toolbars: same look, predictable wrap. Each chip grows equally
       inside .actions-bar.uniform — caller opts in by adding the class. */
.actions-bar.uniform {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(120px, 1fr));
  gap: var(--sp-2);
}
.actions-bar.uniform > .action-chip,
.actions-bar.uniform > .btn { justify-content: center; }

/* (b) Default actions-bar on phones: enforce minimum chip width so they don't
       collapse to ugly single-icon nubs, and keep neat alignment. */
@media (max-width: 480px) {
  .actions-bar:not(.uniform) {
    gap: var(--sp-2);
  }
  .actions-bar:not(.uniform) > .action-chip,
  .actions-bar:not(.uniform) > .btn-sm {
    flex: 1 1 auto;
    min-width: 96px;
    justify-content: center;
  }
}

/* (c) Form rows: any `.row.gap-2/.row.gap-3` containing form fields stacks
       vertically below 520px so labels stay above their inputs. */
@media (max-width: 520px) {
  .row.gap-2:has(> .field),
  .row.gap-3:has(> .field),
  .row.gap-4:has(> .field) {
    flex-direction: column;
    align-items: stretch;
  }
  .row > .field.grow,
  .row > .field         { width: 100%; min-width: 0; }
  /* Tighten label-input gap when we're in a single column */
  .field .label { margin-bottom: 4px; }
}

/* (d) Sticky modal/dialog footer: action buttons stay reachable when content
       is taller than the viewport. */
.dialog-foot,
.modal-foot {
  position: sticky;
  bottom: 0;
  background: var(--bg-surface);
  border-top: 1px solid var(--border);
  padding-top: var(--sp-3);
  margin-top: var(--sp-4);
  z-index: 2;
}
@media (max-width: 480px) {
  .dialog-foot, .modal-foot {
    /* On phones, stack primary/secondary CTAs full-width for thumb reach. */
    flex-direction: column-reverse;
    align-items: stretch;
    gap: var(--sp-2);
  }
  .dialog-foot > .btn, .modal-foot > .btn { width: 100%; }
}

/* (e) Plan cards (public + panel pricing): tighter spacing on tiny phones,
       buttons always full-width, no horizontal scroll. */
@media (max-width: 480px) {
  .plan-grid { grid-template-columns: 1fr; gap: var(--sp-3); }
  .plan-card { padding: var(--sp-4); }
  .plan-card .btn { width: 100%; justify-content: center; }
  .plan-price .amount { font-size: var(--text-28); }
}

/* (f) KPI grid super-small: stay 2-up but reduce padding (was already 2-up at 640) */
@media (max-width: 360px) {
  .kpi-grid { gap: var(--sp-2); }
  .kpi { padding: var(--sp-2); }
  .kpi-value { font-size: var(--text-16); }
  .kpi-label { font-size: var(--text-11); }
}

/* (g) Segmented switchers (currency/audience tabs in pricing): wrap nicely
       so 3+ currency tabs don't push the page wider than viewport. */
.seg { flex-wrap: wrap; }
@media (max-width: 480px) {
  .seg { max-width: 100% !important; }
  .seg-btn { flex: 1 1 calc(50% - 4px); min-height: 40px; }
}

/* (h) Gateway picker chips (payment-method dialog): each option full-width
       on phone — radio + label always aligned. */
@media (max-width: 520px) {
  .gw-option { padding: 12px 14px; }
  .gw-list   { gap: 8px; }
}

/* (i) Containers can't overflow horizontally — last-mile guard so any third-party
       embed (gateway redirect form, oxapay widget) stays inside the viewport. */
.panel-main > *,
main > * { max-width: 100%; }
img, video, iframe, svg { max-width: 100%; height: auto; }
table.table { max-width: 100%; }

/* (j) Empty-state illustration smaller on phones — keeps content above the fold */
@media (max-width: 480px) {
  .empty { padding: var(--sp-6) var(--sp-3); }
  .empty i { width: 36px !important; height: 36px !important; }
  .empty p { font-size: var(--text-13); }
}

/* (k) Topbar (panel) actions: hide labels when extremely narrow so the topbar
       doesn't wrap onto three rows on a 320px screen. */
@media (max-width: 380px) {
  .panel-topbar-actions .btn-sm .btn-label,
  .panel-topbar-actions .btn .btn-label { display: none; }
}

/* (l) Tap area: links inside .muted / footer rows are easy to miss with a thumb;
       give them a small hit-slop without changing visual height. */
@media (pointer: coarse) {
  .table-cards a, .table-cards button,
  .kpi a, .card-head a {
    position: relative;
  }
  .table-cards a::after, .kpi a::after {
    content: ''; position: absolute; inset: -6px;
  }
}

/* (m) Use modern overscroll smoothing to feel native */
.panel-main, .sidebar, .dialog-body { -webkit-overflow-scrolling: touch; }

/* ============================================================
   PLAN-CARD SERVICE COLOURING — 2026-05-30
   - OpenVPN cards (.plan-svc-openvpn) → orange accent
   - V2Ray   cards (.plan-svc-v2ray)   → purple accent
   - A small badge sits in the top corner (in addition to the border)
   - Single-plan grids cap card width so it doesn't stretch absurdly wide
   - Customer-facing CSS only — no JS, no DB change beyond plan→panel binding
   ============================================================ */

/* Service tokens (kept local — fall back gracefully on browsers without
   color-mix: the solid base colour still applies). */
.plan-card {
  --svc-color: var(--brand);
  --svc-soft:  var(--brand-subtle, rgba(108,79,248,.10));
  position: relative;
  transition: border-color .15s, box-shadow .15s, transform .15s;
}
.plan-card.plan-svc-openvpn {
  --svc-color: #f59e0b;       /* amber-500 — اطمینان از کنتراست در dark/light */
  --svc-soft:  rgba(245,158,11,.12);
  border-color: var(--svc-color);
  box-shadow: 0 0 0 3px var(--svc-soft);
}
.plan-card.plan-svc-v2ray {
  --svc-color: #8b5cf6;       /* violet-500 */
  --svc-soft:  rgba(139,92,246,.12);
  border-color: var(--svc-color);
  box-shadow: 0 0 0 3px var(--svc-soft);
}

/* Service badge (top-left in RTL, mirrors automatically). */
.plan-svc-badge {
  position: absolute;
  top: -10px;
  inset-inline-start: var(--sp-4);
  display: inline-flex;
  align-items: center;
  gap: 4px;
  background: var(--svc-color);
  color: #fff;
  font-size: var(--text-11);
  font-weight: 700;
  padding: 4px 10px;
  border-radius: var(--r-pill);
  letter-spacing: 0.02em;
  line-height: 1;
  box-shadow: 0 2px 6px rgba(0,0,0,.15);
}
.plan-svc-badge i { width: 12px; height: 12px; }

/* When a service-colored card is ALSO featured, the featured ring keeps its
   colour but we promote the service border to a brighter outline so the
   service identity wins (admin can still see "featured" via the inner tag). */
.plan-card.plan-featured.plan-svc-openvpn,
.plan-card.plan-featured.plan-svc-v2ray {
  box-shadow: 0 0 0 3px var(--svc-soft), 0 6px 20px rgba(0,0,0,.06);
}

/* Buy button takes the service colour when not featured (featured uses brand). */
.plan-card.plan-svc-openvpn:not(.plan-featured) .btn-primary,
.plan-card.plan-svc-v2ray:not(.plan-featured) .btn-primary {
  background: var(--svc-color);
  border-color: var(--svc-color);
}
.plan-card.plan-svc-openvpn:not(.plan-featured) .btn-ghost:hover,
.plan-card.plan-svc-v2ray:not(.plan-featured) .btn-ghost:hover {
  background: var(--svc-soft);
  color: var(--svc-color);
  border-color: var(--svc-color);
}
.plan-card.plan-svc-openvpn .plan-list i,
.plan-card.plan-svc-v2ray   .plan-list i {
  color: var(--svc-color);
}

/* Avoid a single card stretching to full panel width. Pricing pages with one
   plan looked oversized; cap each card width and centre the grid. */
.plan-grid { justify-content: center; }
.plan-card { max-width: 360px; width: 100%; margin-inline: auto; }
@media (min-width: 720px) {
  .plan-grid { gap: var(--sp-4); }
}
@media (max-width: 480px) {
  .plan-card { max-width: 100%; }   /* phones already use full width */
}

/* Service badge floats correctly above the featured/private tag — they live
   on the same edge, so shift the private/featured tag to the opposite side. */
.plan-card.plan-svc-openvpn .plan-tag,
.plan-card.plan-svc-v2ray   .plan-tag {
  inset-inline-start: auto;
  inset-inline-end:   var(--sp-4);
}


/* ============================================================
   CREDENTIALS CARD — 2026-05-30
   Used in user/dashboard and reseller share-dialog. Each row is a
   label + readonly input + copy button (optionally + reveal). The
   layout grows nicely on phone (label-above-input) and aligns on
   desktop (label-left, input grows).
   ============================================================ */
.creds-card {
  background: var(--bg-page);
  border: 1px solid var(--border);
  border-radius: var(--r-lg);
  padding: var(--sp-3);
}
.creds-row { display: flex; flex-direction: column; gap: 4px; }
.creds-row + .creds-row { margin-top: var(--sp-3); padding-top: var(--sp-3); border-top: 1px dashed var(--border); }
.creds-row .creds-label {
  font-size: var(--text-12);
  font-weight: 600;
  color: var(--text-secondary);
  display: flex; align-items: center; gap: 6px;
}
.creds-row .creds-label i { width: 14px; height: 14px; color: var(--brand); }

/* Copy button visual feedback */
.is-copied {
  background: color-mix(in srgb, var(--success) 18%, transparent) !important;
  color: var(--success) !important;
  border-color: var(--success) !important;
  transition: background .2s, color .2s, border-color .2s;
}

/* Share toolbar (Telegram / SMS / WhatsApp / Copy-all) */
.share-bar {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(140px, 1fr));
  gap: var(--sp-2);
  margin-top: var(--sp-3);
}
.share-btn {
  display: inline-flex; align-items: center; justify-content: center;
  gap: 8px;
  padding: 10px 14px;
  border: 1px solid var(--border);
  border-radius: var(--r-md);
  background: var(--bg-surface);
  color: var(--text-primary);
  font-weight: 600; font-size: var(--text-13);
  cursor: pointer;
  transition: transform .12s, border-color .15s, background .15s, color .15s;
  min-height: 44px;
  text-decoration: none;
}
.share-btn:hover { transform: translateY(-1px); }
.share-btn i { width: 16px; height: 16px; }
.share-btn.tg       { border-color: #229ED9; color: #229ED9; }
.share-btn.tg:hover { background: #229ED9; color: #fff; }
.share-btn.sms      { border-color: var(--brand); color: var(--brand); }
.share-btn.sms:hover{ background: var(--brand); color: #fff; }
.share-btn.wa       { border-color: #25D366; color: #25D366; }
.share-btn.wa:hover { background: #25D366; color: #fff; }
.share-btn.copy-all { border-color: var(--text-tertiary); }
.share-btn.copy-all:hover { border-color: var(--text-primary); }
.share-btn[disabled] { opacity: .5; cursor: not-allowed; pointer-events: none; }

/* ============================================================
   Service-kind inline badge (OpenVPN / V2Ray) — used in the
   reseller customers list, add-customer form, and anywhere a
   subscription's engine type should be labelled at a glance.
   orange = OpenVPN, violet = V2Ray (same palette as plan cards).
   ============================================================ */
.svc-badge { display: inline-flex; align-items: center; gap: 4px; margin-inline-start: 6px; padding: 1px 8px; font-size: 11px; font-weight: 700; border-radius: 999px; vertical-align: middle; line-height: 1.6; }
.svc-badge i { width: 13px; height: 13px; }
.svc-openvpn { background: rgba(245,158,11,.15); color: #b45309; }
.svc-v2ray   { background: rgba(139,92,246,.15); color: #6d28d9; }

/* Online presence dot — green pulse when a customer's VPN session is open
   right now (engine reports them in radacct without acctstoptime). Grey
   when offline. Used in reseller + admin customer lists. */
.online-dot { display: inline-block; width: 9px; height: 9px; border-radius: 50%; background: #22c55e; box-shadow: 0 0 0 0 rgba(34,197,94,.6); animation: onlinePulse 2s infinite; vertical-align: middle; margin-inline-end: 6px; }
.online-dot.off { background: #cbd5e1; animation: none; box-shadow: none; }
@keyframes onlinePulse { 0% { box-shadow: 0 0 0 0 rgba(34,197,94,.55); } 70% { box-shadow: 0 0 0 6px rgba(34,197,94,0); } 100% { box-shadow: 0 0 0 0 rgba(34,197,94,0); } }
