/* =====================================================
   XUI Panel – Custom CSS (Bootstrap 5 RTL base)
   RTL layout: sidebar on the RIGHT, content on the LEFT
   ===================================================== */

@font-face {
  font-family: 'Shabnam';
  src: url('/assets/fonts/Shabnam.woff2') format('woff2');
  font-weight: 400;
  font-style: normal;
  font-display: swap;
}
@font-face {
  font-family: 'Shabnam';
  src: url('/assets/fonts/Shabnam-Bold.woff2') format('woff2');
  font-weight: 700;
  font-style: normal;
  font-display: swap;
}

:root {
  --sidebar-w: 260px;
  --topbar-h: 60px;
  --primary:        #6366f1;
  --primary-hover:  #4f46e5;
  --primary-light:  rgba(99,102,241,.1);
  --bg:             #f1f5f9;
  --card-bg:        #ffffff;
  --sidebar-bg:     #0f172a;
  --sidebar-text:   #94a3b8;
  --sidebar-hover:  rgba(255,255,255,.06);
  --sidebar-active: rgba(99,102,241,.15);
  --border:         #e2e8f0;
  --text:           #1e293b;
  --muted:          #64748b;
  --radius:         12px;
  --shadow:         0 1px 4px rgba(0,0,0,.07);
  --shadow-md:      0 4px 16px rgba(0,0,0,.1);
}

/* ── Dark Mode ────────────────────────────────────── */
[data-theme="dark"] {
  --bg:             #0f172a;
  --card-bg:        #1e293b;
  --sidebar-bg:     #020617;
  --border:         #334155;
  --text:           #e2e8f0;
  --muted:          #94a3b8;
  --shadow:         0 1px 4px rgba(0,0,0,.3);
  --shadow-md:      0 4px 16px rgba(0,0,0,.4);
}
[data-theme="dark"] .topbar    { background: #1e293b; }
[data-theme="dark"] .card      { background: #1e293b !important; }
[data-theme="dark"] .modal-content { background: #1e293b !important; }
[data-theme="dark"] .modal-header  { background: #0f172a !important; }
[data-theme="dark"] .table     { --bs-table-bg: transparent; color: var(--text); }
[data-theme="dark"] .table th  { background: #0f172a; color: var(--muted); border-color: var(--border); }
[data-theme="dark"] .table td  { border-color: var(--border); }
[data-theme="dark"] .table-hover tbody tr:hover { background: rgba(255,255,255,.04); }
[data-theme="dark"] .form-control,
[data-theme="dark"] .form-select {
  background: #0f172a; color: var(--text); border-color: var(--border);
}
[data-theme="dark"] .form-control:focus,
[data-theme="dark"] .form-select:focus {
  background: #0f172a; color: var(--text);
}
[data-theme="dark"] .list-group-item { background: transparent; color: var(--text); border-color: var(--border); }
[data-theme="dark"] .border          { border-color: var(--border) !important; }
[data-theme="dark"] .bg-white        { background: var(--card-bg) !important; }
[data-theme="dark"] .text-dark        { color: var(--text) !important; }
[data-theme="dark"] .input-group-text { background: #0f172a; color: var(--text); border-color: var(--border); }
[data-theme="dark"] .btn-close        { filter: invert(1); }
[data-theme="dark"] .auth-card        { background: #1e293b; color: var(--text); }
[data-theme="dark"] .progress         { background: #334155; }

/* Dark mode toggle button */
.dark-toggle {
  width: 36px; height: 36px;
  border-radius: 8px;
  border: 1px solid var(--border);
  background: none;
  cursor: pointer;
  font-size: 1rem;
  display: flex; align-items: center; justify-content: center;
  color: var(--text);
  transition: background .15s;
}
.dark-toggle:hover { background: var(--primary-light); }

*  { box-sizing: border-box; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family: 'Shabnam', 'Vazirmatn', 'Segoe UI', system-ui, sans-serif;
  font-size: 14px;
  line-height: 1.6;
}

/* ── Sidebar ─────────────────────────────────────── */
#sidebar {
  position: fixed;
  top: 0; right: 0; bottom: 0;          /* RTL: right side */
  width: var(--sidebar-w);
  background: var(--sidebar-bg);
  z-index: 1050;
  overflow-y: auto;
  overflow-x: hidden;
  display: flex;
  flex-direction: column;
  transition: transform .25s ease;
}

.sidebar-brand {
  display: flex;
  align-items: center;
  gap: .75rem;
  padding: 1.1rem 1.4rem;
  text-decoration: none;
  color: #fff;
  font-size: 1.05rem;
  font-weight: 700;
  border-bottom: 1px solid rgba(255,255,255,.06);
  flex-shrink: 0;
}

.brand-icon {
  width: 36px; height: 36px;
  background: var(--primary);
  border-radius: 10px;
  display: flex; align-items: center; justify-content: center;
  font-size: 1.1rem;
  flex-shrink: 0;
}

.sidebar-nav { flex: 1; padding: .75rem 0; }

.sidebar-nav ul { list-style: none; margin: 0; padding: 0; }

.nav-section {
  padding: .8rem 1.4rem .2rem;
  font-size: .67rem;
  font-weight: 600;
  letter-spacing: .1em;
  text-transform: uppercase;
  color: rgba(148,163,184,.45);
  cursor: default;
  user-select: none;
}

.sidebar-nav a {
  display: flex;
  align-items: center;
  gap: .7rem;
  padding: .55rem 1.4rem;
  color: var(--sidebar-text);
  text-decoration: none;
  font-size: .875rem;
  transition: all .15s;
  position: relative;
  border-radius: 0;
}

.sidebar-nav a .nav-icon {
  width: 20px;
  text-align: center;
  font-style: normal;
  font-size: 1rem;
  opacity: .7;
  flex-shrink: 0;
}

.sidebar-nav a:hover {
  color: #fff;
  background: var(--sidebar-hover);
}

.sidebar-nav a.active {
  color: #a5b4fc;
  background: var(--sidebar-active);
  font-weight: 600;
}

/* Active indicator bar – on the LEFT (inner edge of right-side sidebar) */
.sidebar-nav a.active::before {
  content: '';
  position: absolute;
  left: 0; top: 4px; bottom: 4px;
  width: 3px;
  background: var(--primary);
  border-radius: 0 3px 3px 0;
}

.sidebar-footer {
  padding: 1rem 1.4rem;
  border-top: 1px solid rgba(255,255,255,.06);
  flex-shrink: 0;
}

.sidebar-user {
  display: flex;
  align-items: center;
  gap: .65rem;
}

.s-avatar {
  width: 34px; height: 34px;
  border-radius: 50%;
  background: linear-gradient(135deg, var(--primary), #8b5cf6);
  display: flex; align-items: center; justify-content: center;
  color: #fff;
  font-weight: 700;
  font-size: .85rem;
  flex-shrink: 0;
}

.s-name  { color: #e2e8f0; font-size: .8125rem; font-weight: 600; line-height: 1.2; }
.s-role  { color: var(--sidebar-text); font-size: .72rem; line-height: 1.2; }

/* ── Main Wrapper ─────────────────────────────────── */
#main-wrapper {
  margin-right: var(--sidebar-w);   /* RTL: leave space for right-side sidebar */
  min-height: 100vh;
  display: flex;
  flex-direction: column;
}

/* ── Topbar ───────────────────────────────────────── */
.topbar {
  height: var(--topbar-h);
  background: var(--card-bg);
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  padding: 0 1.5rem;
  position: sticky;
  top: 0;
  z-index: 900;
  gap: 1rem;
  box-shadow: 0 1px 0 var(--border);
}

#sidebar-toggle {
  display: none;
  background: none;
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: .3rem .6rem;
  font-size: 1.1rem;
  cursor: pointer;
  color: var(--text);
  line-height: 1;
}

.topbar-spacer { flex: 1; }

.topbar-user {
  display: flex;
  align-items: center;
  gap: .65rem;
}

.t-avatar {
  width: 34px; height: 34px;
  border-radius: 50%;
  background: linear-gradient(135deg, var(--primary), #8b5cf6);
  display: flex; align-items: center; justify-content: center;
  color: #fff;
  font-weight: 700;
  font-size: .85rem;
  flex-shrink: 0;
}

.t-name { font-weight: 600; font-size: .875rem; line-height: 1.2; }
.t-role { font-size: .72rem; color: var(--muted); line-height: 1.2; }

/* ── Overlay (mobile) ─────────────────────────────── */
#sidebar-overlay {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,.45);
  z-index: 1040;
}

/* ── Main Content ─────────────────────────────────── */
.main-content {
  flex: 1;
  padding: 1.5rem;
}

/* ── Page Header ──────────────────────────────────── */
.page-header {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  margin-bottom: 1.5rem;
  gap: 1rem;
  flex-wrap: wrap;
}

.page-title   { font-size: 1.3rem; font-weight: 700; margin: 0 0 .15rem; }
.page-subtitle{ font-size: .8125rem; color: var(--muted); }

/* ── Stat Cards ───────────────────────────────────── */
.stat-card {
  background: var(--card-bg);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 1.25rem;
  box-shadow: var(--shadow);
  display: flex;
  align-items: center;
  gap: 1rem;
}

.stat-icon {
  width: 52px; height: 52px;
  border-radius: 14px;
  display: flex; align-items: center; justify-content: center;
  font-size: 1.4rem;
  flex-shrink: 0;
}

.stat-icon.indigo  { background: rgba(99,102,241,.12);  color: #6366f1; }
.stat-icon.green   { background: rgba(34,197,94,.12);   color: #16a34a; }
.stat-icon.amber   { background: rgba(245,158,11,.12);  color: #d97706; }
.stat-icon.rose    { background: rgba(244,63,94,.12);   color: #e11d48; }
.stat-icon.sky     { background: rgba(14,165,233,.12);  color: #0284c7; }

.stat-value { font-size: 1.8rem; font-weight: 700; line-height: 1; color: var(--text); }
.stat-label { font-size: .78rem; color: var(--muted); margin-top: .2rem; }

/* ── Cards ────────────────────────────────────────── */
.card {
  background: var(--card-bg);
  border: 1px solid var(--border) !important;
  border-radius: var(--radius) !important;
  box-shadow: var(--shadow);
}

.card-header-bar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 1rem;
}

/* ── Table ────────────────────────────────────────── */
.table th {
  font-size: .72rem;
  font-weight: 600;
  letter-spacing: .05em;
  text-transform: uppercase;
  color: var(--muted);
  background: #f8fafc;
  border-bottom: 1px solid var(--border);
  white-space: nowrap;
}

.table td { font-size: .875rem; }
.table > :not(caption) > * > * { vertical-align: middle; }
.table-hover tbody tr:hover { background: #f8fafc; }

/* ── Badges ───────────────────────────────────────── */
.role-badge {
  display: inline-flex;
  align-items: center;
  padding: .15em .7em;
  border-radius: 999px;
  font-size: .72rem;
  font-weight: 600;
}
.role-badge.admin    { background: rgba(99,102,241,.12); color: #6366f1; }
.role-badge.operator { background: rgba(245,158,11,.12); color: #b45309; }
.role-badge.user     { background: rgba(34,197,94,.12);  color: #15803d; }

.status-pill {
  display: inline-flex;
  align-items: center;
  gap: .3rem;
  font-size: .78rem;
}
.dot { width: 7px; height: 7px; border-radius: 50%; display: inline-block; }
.dot.on  { background: #22c55e; }
.dot.off { background: #94a3b8; }

/* ── Buttons ──────────────────────────────────────── */
.btn { border-radius: 8px; font-size: .875rem; font-weight: 500; }
.btn-sm { border-radius: 6px; font-size: .8rem; }
.btn-xs { border-radius: 5px; font-size: .75rem; padding: .15rem .5rem; }

.btn-primary          { background: var(--primary); border-color: var(--primary); }
.btn-primary:hover    { background: var(--primary-hover); border-color: var(--primary-hover); }
.btn-outline-primary  { color: var(--primary); border-color: var(--primary); }
.btn-outline-primary:hover { background: var(--primary-light); color: var(--primary); border-color: var(--primary); }

/* ── Forms ────────────────────────────────────────── */
.form-control, .form-select {
  border-radius: 8px;
  border-color: var(--border);
  font-size: .875rem;
}
.form-control:focus, .form-select:focus {
  border-color: var(--primary);
  box-shadow: 0 0 0 3px rgba(99,102,241,.15);
}
.form-label {
  font-size: .8125rem;
  font-weight: 600;
  color: var(--text);
  margin-bottom: .35rem;
}
.form-text { font-size: .775rem; color: var(--muted); }

/* ── Alerts / Flash ───────────────────────────────── */
.alert { border-radius: var(--radius); border: none; font-size: .875rem; }
.alert-success { background: rgba(34,197,94,.1);    color: #15803d; }
.alert-danger  { background: rgba(239,68,68,.1);    color: #dc2626; }
.alert-warning { background: rgba(245,158,11,.1);   color: #b45309; }
.alert-info    { background: rgba(99,102,241,.1);   color: #4338ca; }

/* ── Progress ─────────────────────────────────────── */
.usage-track {
  height: 8px;
  border-radius: 999px;
  background: #e2e8f0;
  overflow: hidden;
}
.usage-fill {
  height: 100%;
  border-radius: 999px;
  background: linear-gradient(90deg, var(--primary), #8b5cf6);
  transition: width .6s ease;
}
.usage-fill.warn   { background: linear-gradient(90deg, #f59e0b, #d97706); }
.usage-fill.danger { background: linear-gradient(90deg, #ef4444, #dc2626); }

/* ── Modals ───────────────────────────────────────── */
.modal-content {
  border: none !important;
  border-radius: var(--radius) !important;
  box-shadow: var(--shadow-md);
}
.modal-header { background: #f8fafc; border-bottom: 1px solid var(--border); border-radius: var(--radius) var(--radius) 0 0 !important; }
.modal-footer { border-top: 1px solid var(--border); }
.modal-title  { font-size: 1rem; font-weight: 700; }

/* ── Copy Input ───────────────────────────────────── */
.copy-wrap { position: relative; }
.copy-wrap .form-control { padding-left: 2.5rem; }
.copy-btn {
  position: absolute;
  left: .5rem;
  top: 50%;
  transform: translateY(-50%);
  background: none;
  border: none;
  cursor: pointer;
  color: var(--muted);
  padding: .2rem .3rem;
  border-radius: 5px;
  line-height: 1;
  font-size: 1rem;
}
.copy-btn:hover { background: #e2e8f0; color: var(--text); }

/* ── Auth Page ────────────────────────────────────── */
.auth-bg {
  min-height: 100vh;
  background: linear-gradient(135deg, #1a1d2e 0%, #0f172a 60%, #1e1040 100%);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 1rem;
}
.auth-card {
  background: #fff;
  border-radius: 20px;
  padding: 2.5rem 2rem;
  width: 100%;
  max-width: 420px;
  box-shadow: 0 20px 60px rgba(0,0,0,.35);
}
.auth-logo {
  width: 56px; height: 56px;
  background: var(--primary);
  border-radius: 16px;
  display: flex; align-items: center; justify-content: center;
  font-size: 1.75rem;
  margin: 0 auto 1.5rem;
}

/* ── Inbound card mini ────────────────────────────── */
.inbound-card {
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: .75rem 1rem;
  display: flex;
  align-items: center;
  gap: .75rem;
  transition: box-shadow .15s;
}
.inbound-card:hover { box-shadow: var(--shadow-md); border-color: #c7d2fe; }

.proto-badge {
  display: inline-block;
  padding: .15em .6em;
  border-radius: 6px;
  font-size: .72rem;
  font-weight: 700;
  text-transform: uppercase;
}
.proto-badge.vless   { background: rgba(99,102,241,.12);  color: #6366f1; }
.proto-badge.vmess   { background: rgba(14,165,233,.12);  color: #0284c7; }
.proto-badge.trojan  { background: rgba(244,63,94,.12);   color: #e11d48; }
.proto-badge.shadowsocks { background: rgba(34,197,94,.12); color: #15803d; }

/* ── Online users bar ────────────────────────────── */
.online-bar {
  display: flex; align-items: center; gap: .6rem;
  background: rgba(34,197,94,.08);
  border: 1px solid rgba(34,197,94,.2);
  border-radius: 10px;
  padding: .45rem .9rem;
  flex-wrap: wrap;
}
.online-bar-label {
  display: flex; align-items: center; gap: .35rem;
  font-size: .8rem; font-weight: 700; color: #15803d; white-space: nowrap; flex-shrink: 0;
}
[data-theme="dark"] .online-bar-label { color: #4ade80; }
.online-bar-pills  { display: flex; flex-wrap: wrap; gap: .25rem; align-items: center; }
.online-pill {
  background: #16a34a; color: #fff !important;
  font-size: .7rem; padding: .1rem .5rem;
  border-radius: 999px; font-weight: 600; white-space: nowrap;
}
.online-pill-more { font-size: .72rem; color: #15803d; font-weight: 600; }
[data-theme="dark"] .online-pill-more { color: #4ade80; }

/* ── Toggle pill (enable/disable switch in table) ─── */
button.ajax-toggle {
  display: inline-flex !important;
  align-items: center;
  justify-content: center;
  width: 42px;
  height: 24px;
  padding: 0 !important;
  border: none !important;
  background: transparent !important;
  box-shadow: none !important;
  outline: none;
  cursor: pointer;
  flex-shrink: 0;
  vertical-align: middle;
}
.toggle-pill {
  display: block;
  width: 42px;
  height: 24px;
  border-radius: 12px;
  position: relative;
  transition: background .2s;
  overflow: hidden;
  flex-shrink: 0;
}
.toggle-pill::after {
  content: '';
  position: absolute;
  width: 18px;
  height: 18px;
  border-radius: 50%;
  background: #fff;
  top: 3px;
  transition: left .18s;
  box-shadow: 0 1px 2px rgba(0,0,0,.25);
}
.toggle-pill.on           { background: #22c55e; }
.toggle-pill.on::after    { left: 21px; }
.toggle-pill.off          { background: #94a3b8; }
.toggle-pill.off::after   { left: 3px; }
button.ajax-toggle:disabled { opacity: .5; cursor: not-allowed; }

/* ── Sortable table headers ───────────────────────── */
.tbl-sort:hover { background: rgba(99,102,241,.06); }
.tbl-sort .si   { opacity:.35; font-size:.72rem; margin-right:2px; }

/* ── Public page ──────────────────────────────────── */
.page-header { flex-wrap: wrap; }

/* ── Scrollbar ────────────────────────────────────── */
#sidebar::-webkit-scrollbar { width: 3px; }
#sidebar::-webkit-scrollbar-thumb { background: rgba(255,255,255,.1); border-radius: 99px; }

/* ── Responsive ───────────────────────────────────── */
@media (max-width: 991.98px) {
  #sidebar {
    transform: translateX(100%);   /* slide out to right (off-screen) */
  }
  #sidebar.open {
    transform: translateX(0);
  }
  #main-wrapper {
    margin-right: 0;
  }
  #sidebar-toggle {
    display: inline-flex;
    align-items: center;
    justify-content: center;
  }
  #sidebar-overlay.show {
    display: block;
  }
  .main-content { padding: 1rem; }
  .page-header  { flex-direction: column; align-items: flex-start; }
}

@media (max-width: 575.98px) {
  .stat-card { padding: .9rem; }
  .stat-value { font-size: 1.5rem; }
  .auth-card  { padding: 1.75rem 1.25rem; }
}
