@import url('https://fonts.googleapis.com/css2?family=Inter:wght@300;400;500;600;700&display=swap');

:root {
  --bg:          #16181d;
  --bg2:         #1d2027;
  --card:        #242830;
  --card2:       #2a2f38;
  --border:      #313640;
  --text:        #e8eaf0;
  --muted:       #8892a4;
  --accent:      #5b8ef0;
  --accent-h:    #4a7de0;
  --green:       #22c55e;
  --red:         #ef4444;
  --orange:      #f97316;
  --purple:      #a855f7;
  --pink:        #ec4899;
  --cyan:        #06b6d4;
  --yellow:      #eab308;
  --sidebar-w:   260px;
  --input:       #1d2027;
}

*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

html { overflow-x: hidden; }

body {
  font-family: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
  background: var(--bg);
  color: var(--text);
  min-height: 100vh;
  font-size: 14px;
  line-height: 1.6;
  overflow-x: hidden;
}

/* ── LAYOUT ─────────────────────────────────── */
.app-shell { display: flex; min-height: 100vh; overflow-x: hidden; max-width: 100vw; }

/* ── SIDEBAR ────────────────────────────────── */
.sidebar {
  width: var(--sidebar-w);
  background: var(--bg2);
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  position: fixed;
  top: 0; left: 0;
  height: 100vh;
  z-index: 1100;
  transition: transform 0.25s ease;
}

.sidebar-logo {
  padding: 22px 20px 18px;
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  gap: 12px;
}

.sidebar-logo-icon {
  width: 42px; height: 42px;
  background: linear-gradient(135deg, var(--accent), var(--purple));
  border-radius: 12px;
  display: flex; align-items: center; justify-content: center;
  font-size: 20px; font-weight: 800; color: #fff;
  flex-shrink: 0;
}

.sidebar-logo-text { font-size: 14px; font-weight: 700; line-height: 1.2; }
.sidebar-logo-text span { display: block; font-size: 11px; font-weight: 400; color: var(--muted); margin-top: 1px; }

.sidebar-user {
  padding: 16px 20px;
  border-bottom: 1px solid var(--border);
  display: flex; align-items: center; gap: 12px;
}

.sidebar-avatar {
  width: 38px; height: 38px;
  background: linear-gradient(135deg, var(--accent), var(--cyan));
  border-radius: 10px;
  display: flex; align-items: center; justify-content: center;
  font-weight: 700; font-size: 15px; color: #fff;
  flex-shrink: 0;
}

.sidebar-user-info { flex: 1; min-width: 0; }
.sidebar-user-info strong { display: block; font-size: 13px; font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.sidebar-user-info small { font-size: 11px; color: var(--muted); }

.sidebar-nav {
  flex: 1;
  padding: 10px 12px;
  display: flex; flex-direction: column; gap: 2px;
  overflow-y: auto;
}

.nav-item {
  display: flex; align-items: center; gap: 12px;
  padding: 10px 12px;
  border-radius: 10px;
  color: var(--muted);
  text-decoration: none;
  font-size: 13px; font-weight: 500;
  transition: all 0.15s;
  position: relative;
}

.nav-item:hover { background: var(--card); color: var(--text); }

.nav-item.active {
  background: rgba(91,142,240,.14);
  color: var(--accent);
}

.nav-item.active::after {
  content: '';
  position: absolute; right: 10px; top: 50%; transform: translateY(-50%);
  width: 6px; height: 6px;
  background: var(--accent);
  border-radius: 50%;
}

.nav-icon { width: 18px; height: 18px; flex-shrink: 0; display: flex; align-items: center; justify-content: center; }

.sidebar-footer { padding: 12px; border-top: 1px solid var(--border); }
.sidebar-footer .nav-item:hover { background: rgba(239,68,68,.1); color: var(--red); }

/* ── VPN SIDEBAR WIDGET ─────────────────────── */
.vpn-sidebar-widget {
  padding: 10px 12px;
  border-top: 1px solid var(--border);
  position: relative;
}

.vpn-sidebar-btn {
  width: 100%;
  display: flex; align-items: center; gap: 9px;
  padding: 9px 11px;
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: 9px;
  color: var(--muted);
  cursor: pointer;
  font-size: 12px; font-family: inherit; font-weight: 500;
  text-align: left;
  transition: border-color .15s, color .15s, background .15s;
}
.vpn-sidebar-btn:hover { border-color: var(--accent); color: var(--text); background: var(--card2); }
.vpn-sidebar-btn.vpn-is-connected { border-color: var(--green); color: var(--text); }

.vpn-sidebar-icon { flex-shrink: 0; display: flex; align-items: center; }
.vpn-sidebar-label { flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

.vpn-sidebar-dot {
  width: 7px; height: 7px; border-radius: 50%; flex-shrink: 0;
}
.vpn-sidebar-dot.dot-on  { background: var(--green); box-shadow: 0 0 5px var(--green); }
.vpn-sidebar-dot.dot-off { background: var(--muted); }

.vpn-sidebar-popup {
  position: absolute;
  bottom: calc(100% + 6px);
  left: 12px; right: 12px;
  background: var(--card2);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 14px;
  z-index: 300;
  box-shadow: 0 10px 30px rgba(0,0,0,.55);
}
.vpn-popup-header {
  font-size: 10px; font-weight: 700; text-transform: uppercase;
  letter-spacing: .07em; color: var(--muted); margin-bottom: 8px;
}
.vpn-popup-name  { font-weight: 600; font-size: 13px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; margin-bottom: 3px; }
.vpn-popup-proxy { font-size: 10px; color: var(--muted); word-break: break-all; margin-bottom: 10px; }

/* ── SEARCHABLE VPN SELECT ──────────────────── */
.vpn-sel-wrap { position: relative; }

.vpn-sel-btn {
  display: flex; align-items: center; gap: 6px;
  padding: 6px 10px;
  background: var(--input);
  border: 1px solid var(--border);
  border-radius: 6px;
  color: var(--text);
  font-size: 12px; font-family: inherit;
  cursor: pointer;
  min-width: 160px; max-width: 200px;
  transition: border-color .15s;
}
.vpn-sel-btn:hover          { border-color: var(--accent); }
.vpn-sel-btn.vpn-sel-active { border-color: var(--green); }
.vpn-sel-btn.vpn-sel-direct { border-color: var(--cyan); color: var(--cyan); }

.vpn-sel-dropdown {
  position: fixed;  /* fixed escapes overflow:auto/.table-wrap clipping */
  min-width: 260px; width: 300px; max-width: 320px;
  background: var(--card2);
  border: 1px solid var(--border);
  border-radius: 8px;
  z-index: 9999;
  box-shadow: 0 8px 32px rgba(0,0,0,.6);
  overflow: hidden;
}
.vpn-sel-search {
  width: 100%; padding: 8px 10px;
  background: var(--card); border: none; border-bottom: 1px solid var(--border);
  color: var(--text); font-size: 12px; font-family: inherit; outline: none;
}
.vpn-sel-options { max-height: 200px; overflow-y: auto; }
.vpn-sel-opt {
  padding: 7px 12px; font-size: 12px; cursor: pointer; color: var(--text);
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
  display: flex; align-items: center; gap: 4px;
}
.vpn-sel-opt:hover { background: var(--card); }
.vpn-sel-opt.vpn-sel-cur { color: var(--accent); font-weight: 600; }

/* ── MAIN ───────────────────────────────────── */
.main-wrap {
  margin-left: var(--sidebar-w);
  flex: 1;
  display: flex; flex-direction: column;
  min-height: 100vh;
  min-width: 0;
  overflow-x: hidden;
  max-width: 100%;
}

.main-header {
  background: var(--bg2);
  border-bottom: 1px solid var(--border);
  padding: 0 28px;
  height: 64px;
  display: flex; align-items: center; gap: 16px;
  position: sticky; top: 0; z-index: 100;
}

.main-header h1 { font-size: 20px; font-weight: 700; flex: 1; }

.header-search {
  display: flex; align-items: center; gap: 8px;
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 8px 14px;
  width: 260px;
}

.header-search input {
  background: none; border: none;
  color: var(--text); font-size: 13px; width: 100%; outline: none;
}

.header-search input::placeholder { color: var(--muted); }

.main-content { padding: 24px 28px; flex: 1; width: 100%; min-width: 0; }

/* ── FLASH ──────────────────────────────────── */
.flash {
  padding: 12px 16px; border-radius: 10px; margin-bottom: 20px;
  font-size: 13px; font-weight: 500;
  display: flex; align-items: center; gap: 10px;
}
.flash.success { background: rgba(34,197,94,.1); border: 1px solid rgba(34,197,94,.3); color: #4ade80; }
.flash.error   { background: rgba(239,68,68,.1);  border: 1px solid rgba(239,68,68,.3);  color: #f87171; }

/* ── CARDS ──────────────────────────────────── */
.card {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: 14px;
  padding: 20px;
  margin-bottom: 20px;
  min-width: 0;
  max-width: 100%;
}

.card-header {
  display: flex; align-items: center; justify-content: space-between;
  margin-bottom: 18px;
}

.card-title { font-size: 15px; font-weight: 600; }

/* ── KPI CARDS ──────────────────────────────── */
.kpi-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(130px, 1fr));
  gap: 10px;
  margin-bottom: 16px;
  width: 100%;
  align-items: stretch;
}

.kpi-card {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 14px 16px 16px;
  display: flex; flex-direction: column; gap: 6px;
  position: relative; overflow: hidden;
  min-width: 0;
}

.kpi-card::after {
  content: '';
  position: absolute;
  bottom: 0; left: 0; right: 0;
  height: 3px; border-radius: 0 0 12px 12px;
}
.kpi-card.blue::after   { background: linear-gradient(90deg, var(--accent), var(--cyan)); }
.kpi-card.green::after  { background: linear-gradient(90deg, var(--green), #86efac); }
.kpi-card.orange::after { background: linear-gradient(90deg, var(--orange), var(--yellow)); }
.kpi-card.purple::after { background: linear-gradient(90deg, var(--purple), var(--pink)); }
.kpi-card.cyan::after   { background: linear-gradient(90deg, var(--cyan), #67e8f9); }

.kpi-top { display: flex; align-items: center; justify-content: space-between; margin-bottom: 2px; }
.kpi-label { font-size: 10px; font-weight: 600; color: var(--muted); text-transform: uppercase; letter-spacing: .5px; }

.kpi-icon {
  width: 30px; height: 30px; border-radius: 8px;
  display: flex; align-items: center; justify-content: center; font-size: 14px;
}
.kpi-icon.blue   { background: rgba(91,142,240,.15); color: var(--accent); }
.kpi-icon.green  { background: rgba(34,197,94,.15);  color: var(--green); }
.kpi-icon.orange { background: rgba(249,115,22,.15); color: var(--orange); }
.kpi-icon.purple { background: rgba(168,85,247,.15); color: var(--purple); }
.kpi-icon.cyan   { background: rgba(6,182,212,.15);  color: var(--cyan); }

.kpi-value { font-size: 24px; font-weight: 700; line-height: 1; }
.kpi-footer { font-size: 10px; color: var(--muted); }

/* ── CHARTS GRID ────────────────────────────── */
.charts-grid {
  display: grid;
  grid-template-columns: 1fr 1.7fr;
  gap: 16px;
  margin-bottom: 20px;
  width: 100%;
  min-width: 0;
}

.chart-wrap {
  position: relative; height: 200px;
  width: 100%; min-width: 0;
  display: flex; align-items: center; justify-content: center;
  overflow: hidden;
}

canvas { display: block; max-width: 100%; }

.donut-center {
  position: absolute; text-align: center; pointer-events: none;
}
.donut-center .val { font-size: 22px; font-weight: 700; }
.donut-center .lbl { font-size: 11px; color: var(--muted); }

.chart-legend {
  display: grid; grid-template-columns: 1fr 1fr;
  gap: 10px; margin-top: 16px;
}

.legend-item { display: flex; align-items: center; gap: 8px; font-size: 12px; }
.legend-dot { width: 10px; height: 10px; border-radius: 3px; flex-shrink: 0; }
.legend-item strong { display: block; font-size: 15px; font-weight: 600; margin-top: 1px; }
.legend-item span { color: var(--muted); font-size: 11px; }

/* ── GRID HELPERS ───────────────────────────── */
.grid-2 { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; }
.grid-3 { display: grid; grid-template-columns: repeat(3,1fr); gap: 16px; }
.gap-16 { gap: 16px; }

/* ── TABLES ─────────────────────────────────── */
.table-wrap {
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
  width: 100%;
  max-width: 100%;
  display: block;
}

table { width: 100%; border-collapse: collapse; font-size: 13px; }
thead tr { border-bottom: 1px solid var(--border); }

th {
  padding: 10px 14px; text-align: left;
  font-size: 11px; font-weight: 600; color: var(--muted);
  text-transform: uppercase; letter-spacing: .5px; white-space: nowrap;
}

td { padding: 12px 14px; border-bottom: 1px solid var(--border); vertical-align: middle; }
tr:last-child td { border-bottom: none; }
tbody tr:hover { background: var(--card2); transition: background .1s; }

/* ── BADGES ─────────────────────────────────── */
.badge {
  display: inline-flex; align-items: center; gap: 4px;
  padding: 3px 10px; border-radius: 999px;
  font-size: 11px; font-weight: 600;
}
.badge-ok,
.badge-enabled,
.badge-success { background: rgba(34,197,94,.1); color: #4ade80; border: 1px solid rgba(34,197,94,.25); }
.badge-off,
.badge-disabled,
.badge-error   { background: rgba(239,68,68,.1);  color: #f87171; border: 1px solid rgba(239,68,68,.25); }
.badge-warning { background: rgba(234,179,8,.1);  color: #facc15; border: 1px solid rgba(234,179,8,.25); }
.badge-info    { background: rgba(91,142,240,.1); color: #93b4f8; border: 1px solid rgba(91,142,240,.25); }

/* ── FORMS ──────────────────────────────────── */
.form-group { margin-bottom: 16px; }
.form-row { display: flex; gap: 16px; flex-wrap: wrap; }
.form-row > * { flex: 1; min-width: 200px; }

label {
  display: block;
  font-size: 12px; font-weight: 600; color: var(--muted);
  text-transform: uppercase; letter-spacing: .4px;
  margin-bottom: 6px;
}

input, select, textarea {
  width: 100%;
  background: var(--bg);
  border: 1px solid var(--border);
  color: var(--text);
  border-radius: 8px;
  padding: 10px 12px;
  font-size: 13px; font-family: inherit;
  transition: border-color .15s;
  outline: none;
}

input:focus, select:focus, textarea:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px rgba(91,142,240,.1);
}

option {
  background: var(--card);
  color: var(--text);
}

option:hover, option:checked {
  background: var(--accent);
  color: #fff;
}

input[type="checkbox"] { width: auto; accent-color: var(--accent); }
input[type="time"] { width: auto; }
input[readonly] { opacity: .7; cursor: default; }

.checkbox-row { display: flex; align-items: center; gap: 8px; margin-bottom: 14px; }
.checkbox-row input { margin: 0; }
.checkbox-row label { margin: 0; text-transform: none; font-size: 13px; color: var(--text); letter-spacing: 0; font-weight: 500; }

/* ── BUTTONS ────────────────────────────────── */
button, .btn {
  border: none; border-radius: 8px;
  padding: 9px 18px; cursor: pointer;
  font-size: 13px; font-weight: 600; font-family: inherit;
  text-decoration: none;
  display: inline-flex; align-items: center; gap: 6px;
  transition: all .15s; white-space: nowrap;
}

.btn, button.btn { background: var(--accent); color: #fff; }
.btn:hover, button.btn:hover { background: var(--accent-h); }

.btn-secondary { background: var(--card2); color: var(--text); border: 1px solid var(--border); }
.btn-secondary:hover { background: var(--border); }

.btn-danger  { background: rgba(239,68,68,.1);  color: #f87171; border: 1px solid rgba(239,68,68,.25); }
.btn-danger:hover  { background: rgba(239,68,68,.2); }

.btn-success { background: rgba(34,197,94,.1);  color: #4ade80; border: 1px solid rgba(34,197,94,.25); }
.btn-success:hover { background: rgba(34,197,94,.2); }

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

/* ── ACTION STACK (legacy compat) ───────────── */
.action-stack { display: flex; flex-direction: column; gap: 6px; }
.action-stack form { margin: 0; }
.action-stack button { width: 100%; }
.action-btns { display: flex; gap: 6px; flex-wrap: wrap; align-items: center; }
.row { display: flex; gap: 12px; flex-wrap: wrap; align-items: flex-start; }
.row > * { flex: 1; min-width: 140px; }

/* ── LOADING OVERLAY ────────────────────────── */
#loading-overlay {
  position: fixed; inset: 0;
  background: rgba(0,0,0,.75);
  backdrop-filter: blur(4px);
  display: none; align-items: center; justify-content: center;
  z-index: 9999;
}
#loading-overlay.show { display: flex; }
#loading-text {
  background: var(--card); border: 1px solid var(--border);
  color: var(--text); padding: 20px 32px; border-radius: 14px;
  font-weight: 600; font-size: 14px;
  display: flex; align-items: center; gap: 12px;
}
.spinner {
  width: 20px; height: 20px;
  border: 2px solid var(--border);
  border-top-color: var(--accent);
  border-radius: 50%;
  animation: spin .8s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* ── MISC ───────────────────────────────────── */
pre {
  background: var(--bg); border: 1px solid var(--border);
  border-radius: 8px; padding: 14px;
  font-size: 12px; overflow-x: auto;
  white-space: pre-wrap; word-break: break-word; color: #a8b4d0;
}

small, .muted { color: var(--muted); }
.text-green  { color: var(--green); }
.text-red    { color: var(--red); }
.text-accent { color: var(--accent); }

.section-title { font-size: 17px; font-weight: 700; margin-bottom: 16px; }

details summary { cursor: pointer; color: var(--muted); font-size: .85em; }
details pre { margin-top: 8px; }

/* ── PAGINATION ─────────────────────────────── */
.pagination {
  display: flex; gap: 6px; flex-wrap: wrap;
  align-items: center; margin-top: 16px;
  padding-top: 16px; border-top: 1px solid var(--border);
}
.page-link {
  padding: 6px 12px; border-radius: 7px;
  background: var(--card2); color: var(--muted);
  text-decoration: none; font-size: 12px; font-weight: 600;
  border: 1px solid var(--border); transition: all .15s;
}
.page-link:hover { background: var(--border); color: var(--text); }
.page-link.active { background: var(--accent); color: #fff; border-color: var(--accent); }

/* ── SUPERADMIN BADGE / NAV ─────────────────── */
.badge-sa {
  background: rgba(245,158,11,.18);
  color: #f59e0b;
  border: 1px solid rgba(245,158,11,.3);
}
.nav-item-sa { color: #f59e0b !important; }
.nav-item-sa .nav-icon svg { stroke: #f59e0b; }
.nav-item-sa:hover,
.nav-item-sa.active { background: rgba(245,158,11,.12) !important; }
.nav-section-divider {
  height: 1px;
  background: var(--border);
  margin: 6px 10px;
}

/* ── SUPERADMIN PAGE HEADER ─────────────────── */
.sa-page-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-wrap: wrap;
  gap: 12px;
  margin-bottom: 20px;
}

/* ── ADMIN ACCOUNT ROWS ─────────────────────── */
.admin-row {
  border-top: 1px solid var(--border);
  padding: 14px 0;
}
.admin-row:first-of-type { border-top: none; padding-top: 0; }
.admin-row-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  flex-wrap: wrap;
}

/* ── PERMISSION MATRIX ──────────────────────── */
.perm-matrix {
  border: 1px solid var(--border);
  border-radius: 8px;
  overflow: hidden;
}
.perm-matrix-head {
  display: grid;
  grid-template-columns: 1fr 110px 110px 120px;
  gap: 0;
  background: var(--card2);
  padding: 8px 12px;
  font-size: 11px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: .06em;
  color: var(--muted);
  border-bottom: 1px solid var(--border);
}
.perm-matrix-row {
  display: grid;
  grid-template-columns: 1fr 110px 110px 120px;
  align-items: center;
  padding: 6px 12px;
  border-bottom: 1px solid var(--border);
  transition: background .1s;
}
.perm-matrix-row:last-child { border-bottom: none; }
.perm-matrix-row:hover { background: rgba(255,255,255,.025); }
.perm-feat-label {
  font-size: 13px;
  font-weight: 500;
  color: var(--text);
}
.perm-radio-opt {
  display: flex;
  align-items: center;
  gap: 7px;
  padding: 5px 8px;
  border-radius: 5px;
  cursor: pointer;
  font-size: 12px;
  font-weight: 500;
  transition: background .12s;
  user-select: none;
  width: fit-content;
}
.perm-radio-opt input[type=radio] {
  accent-color: var(--accent);
  width: 13px; height: 13px;
  cursor: pointer;
  flex-shrink: 0;
}
.perm-none:has(input:checked) { background: rgba(239,68,68,.1);  color: var(--red); }
.perm-view:has(input:checked) { background: rgba(99,102,241,.12); color: var(--accent); }
.perm-edit:has(input:checked) { background: rgba(34,197,94,.12);  color: var(--green); }
.perm-none:hover { background: rgba(239,68,68,.07); }
.perm-view:hover { background: rgba(99,102,241,.07); }
.perm-edit:hover { background: rgba(34,197,94,.07); }
@media (max-width: 640px) {
  .perm-matrix-head,
  .perm-matrix-row { grid-template-columns: 1fr; gap: 4px; }
  .perm-matrix-head { display: none; }
  .perm-matrix-row { padding: 10px 12px; }
}

/* ── PASSWORD FIELD HELPERS ─────────────────── */
.pw-wrap {
  display: flex;
  gap: 6px;
  align-items: stretch;
}
.pw-input {
  flex: 1;
  min-width: 0;
}
.pw-btns {
  display: flex;
  gap: 3px;
  flex-shrink: 0;
}
.pw-btn {
  background: var(--card2);
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 0 9px;
  font-size: 14px;
  cursor: pointer;
  color: var(--text);
  transition: background .12s, border-color .12s;
  line-height: 1;
  display: flex;
  align-items: center;
}
.pw-btn:hover { background: var(--border); border-color: var(--accent); }
.pw-btn.copied { border-color: var(--green); color: var(--green); }

/* ── PERMISSION PRESETS BAR ─────────────────── */
.preset-bar {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 6px;
  padding: 8px 10px;
  background: var(--card2);
  border: 1px solid var(--border);
  border-radius: 8px 8px 0 0;
  border-bottom: none;
}
.preset-bar-label {
  font-size: 11px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: .05em;
  color: var(--muted);
  margin-right: 2px;
}
.preset-btn {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: 5px;
  color: var(--text);
  cursor: pointer;
  font-size: 12px;
  font-family: inherit;
  padding: 4px 10px;
  transition: background .12s, border-color .12s, color .12s;
  white-space: nowrap;
}
.preset-btn:hover  { background: var(--accent); border-color: var(--accent); color: #fff; }
.preset-btn.applied { background: rgba(34,197,94,.15); border-color: var(--green); color: var(--green); }
/* Matrix that follows a preset bar gets its top corners square */
.preset-bar + .perm-matrix { border-radius: 0 0 8px 8px; }

/* ── VIEW-ONLY NOTICE ───────────────────────── */
.view-only-notice {
  display: flex;
  align-items: center;
  gap: 8px;
  background: rgba(99,102,241,.08);
  border: 1px solid rgba(99,102,241,.25);
  border-radius: 8px;
  padding: 10px 14px;
  font-size: 13px;
  color: var(--accent);
  margin-bottom: 16px;
}

/* ── CONNECTED USER CARDS ───────────────────── */
.cu-card {
  background: var(--card2);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 8px 10px;
  margin-bottom: 6px;
}
.cu-top {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 6px;
  margin-bottom: 3px;
}
.cu-user {
  font-size: 12px;
  font-weight: 600;
  color: var(--text);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  flex: 1;
}
.cu-meta {
  display: flex;
  align-items: center;
  gap: 5px;
  font-size: 10px;
  color: var(--muted);
}
.cu-time {
  font-size: 10px;
  color: var(--muted);
  margin-top: 2px;
}

/* World map responsive */
.connected-users-grid {
  grid-template-columns: 1fr 280px;
}
@media (max-width: 900px) {
  .connected-users-grid { grid-template-columns: 1fr; }
  .connected-users-grid > div:last-child {
    border-left: none;
    border-top: 1px solid var(--border);
    max-height: 200px;
  }
  #world-map { height: 220px !important; }
}
@media (max-width: 640px) {
  #world-map { height: 180px !important; }
}
@media (max-width: 380px) {
  #world-map { height: 150px !important; }
}

/* ── MODAL ──────────────────────────────────── */
.modal-backdrop {
  position: fixed; inset: 0; background: rgba(0,0,0,.65);
  backdrop-filter: blur(3px); z-index: 1000;
  display: flex; align-items: center; justify-content: center; padding: 20px;
}
.modal-box {
  background: var(--card); border: 1px solid var(--border);
  border-radius: 16px; width: 100%; max-width: 680px;
  max-height: 90vh; overflow-y: auto;
  box-shadow: 0 24px 64px rgba(0,0,0,.7);
}
.modal-header {
  display: flex; align-items: center; justify-content: space-between;
  padding: 18px 22px; border-bottom: 1px solid var(--border);
  position: sticky; top: 0; background: var(--card); z-index: 1; border-radius: 16px 16px 0 0;
}
.modal-header h3 { font-size: 15px; font-weight: 700; margin: 0; }
.modal-close {
  background: var(--card2); border: 1px solid var(--border);
  border-radius: 6px; color: var(--muted); cursor: pointer;
  font-size: 16px; width: 28px; height: 28px; display: flex;
  align-items: center; justify-content: center;
  transition: background .1s, color .1s;
}
.modal-close:hover { background: var(--border); color: var(--text); }
.modal-body { padding: 22px; }

/* ── MAP LEGEND ─────────────────────────────── */
.map-legend {
  position: absolute; bottom: 10px; left: 10px; z-index: 999;
  background: rgba(22,24,29,.85); border: 1px solid var(--border);
  border-radius: 8px; padding: 8px 12px;
  display: flex; gap: 12px; flex-wrap: wrap;
}
.map-legend-item { display: flex; align-items: center; gap: 5px; font-size: 11px; color: var(--text); }
.map-legend-dot { width: 10px; height: 10px; border-radius: 50%; border: 1.5px solid rgba(255,255,255,.4); flex-shrink: 0; }

/* ── LEAFLET MAP Z-INDEX FIX ────────────────── */
/* Leaflet's .leaflet-tile-pane has z-index:200 and .leaflet-top has z-index:1000.
 * Without a stacking-context boundary these compete with the sidebar (z-index:1100).
 * isolation:isolate creates a new stacking context on the map container, trapping
 * all Leaflet z-indexes inside it so they can't bleed above the sidebar overlay. */
.leaflet-container { isolation: isolate; }

/* Ensure the map wrapper also doesn't let tiles escape */
#world-map { position: relative; z-index: 0; }

/* ── CONTENT NAV GROUP ──────────────────────── */
.nav-group-toggle {
  width: 100%; text-align: left; background: none;
  border: none; border-radius: 10px;
  color: var(--muted); cursor: pointer;
  font-size: 13px; font-weight: 500;
  padding: 10px 12px; display: flex; align-items: center; gap: 12px;
  transition: all 0.15s;
}
.nav-group-toggle:hover { background: var(--card); color: var(--text); }
.nav-group-toggle.active { color: var(--accent); }
.nav-chevron { transition: transform 0.15s; color: var(--muted); flex-shrink: 0; }
.nav-sub { padding-left: 16px; font-size: 12px; }
.nav-sub-wrap { padding-left: 8px; border-left: 2px solid var(--border); margin: 2px 12px 2px 18px; display: flex; flex-direction: column; gap: 1px; }

/* ── MULTI-VPN WIDGET ───────────────────────── */
.vpn-connected-count {
  display: inline-flex; align-items: center; justify-content: center;
  background: var(--green); color: #fff;
  border-radius: 999px; font-size: 10px; font-weight: 700;
  min-width: 16px; height: 16px; padding: 0 4px; margin-left: 2px;
}
.vpn-popup-vpn-row {
  display: flex; align-items: center; justify-content: space-between;
  gap: 8px; padding: 6px 0; border-bottom: 1px solid var(--border);
}
.vpn-popup-vpn-row:last-child { border-bottom: none; }

/* ── CONNECTED USERS FILTER BAR ─────────────── */
.cu-filter-bar {
  display: flex; gap: 6px; flex-wrap: wrap; align-items: center;
  padding: 8px; border-bottom: 1px solid var(--border);
  background: var(--bg2);
}
.cu-filter-bar input, .cu-filter-bar select {
  padding: 5px 8px; font-size: 11px; border-radius: 6px;
  background: var(--card); border: 1px solid var(--border); color: var(--text);
  height: 28px;
}
.cu-filter-bar input { flex: 1; min-width: 80px; }
.cu-filter-bar select { min-width: 90px; }

/* ── VPN ASSIGNMENT TOOLTIP ─────────────────── */
.vpn-clients-pill {
  cursor: pointer; position: relative;
  display: inline-flex; align-items: center; gap: 4px;
}
.vpn-clients-pill .vpn-clients-tooltip {
  display: none; position: absolute; bottom: calc(100% + 4px); left: 0;
  background: var(--card2); border: 1px solid var(--border);
  border-radius: 8px; padding: 8px 12px; min-width: 160px; max-width: 280px;
  font-size: 11px; color: var(--text); z-index: 9999;
  box-shadow: 0 8px 24px rgba(0,0,0,.6);
  white-space: normal; word-break: break-word;
}
.vpn-clients-pill:hover .vpn-clients-tooltip { display: block; }

/* ── CHANNEL LIST VIEW ──────────────────────── */
.channel-list-row {
  display: flex; align-items: center; gap: 12px;
  padding: 8px 12px; border-bottom: 1px solid var(--border);
  transition: background .1s;
}
.channel-list-row:hover { background: var(--card2); }
.channel-list-row:last-child { border-bottom: none; }
.channel-list-thumb {
  width: 48px; height: 36px; border-radius: 5px;
  object-fit: contain; background: #111827; padding: 3px; flex-shrink: 0;
}
.channel-list-placeholder {
  width: 48px; height: 36px; border-radius: 5px;
  background: #111827; display: flex; align-items: center; justify-content: center;
  font-size: 14px; flex-shrink: 0;
}
.view-toggle-btn {
  background: var(--card2); border: 1px solid var(--border);
  border-radius: 6px; color: var(--muted); cursor: pointer;
  padding: 5px 10px; font-size: 13px; display: flex; align-items: center;
  gap: 4px; transition: all .15s;
}
.view-toggle-btn.active { background: var(--accent); border-color: var(--accent); color: #fff; }

/* ── SSL STATUS ALERT ───────────────────────── */
.ssl-alert {
  display: flex; align-items: center; gap: 10px;
  padding: 12px 16px; border-radius: 10px; margin-bottom: 16px; font-size: 13px;
}
.ssl-alert.warning { background: rgba(234,179,8,.1); border: 1px solid rgba(234,179,8,.3); color: #facc15; }
.ssl-alert.ok { background: rgba(34,197,94,.1); border: 1px solid rgba(34,197,94,.3); color: #4ade80; }
.ssl-alert.error { background: rgba(239,68,68,.1); border: 1px solid rgba(239,68,68,.3); color: #f87171; }

/* ── VPN CONNECTED BANNER ───────────────────── */
.vpn-connected-banner {
  display: flex; align-items: center; gap: 10px; flex-wrap: wrap;
  padding: 10px 16px; border-radius: 10px; margin-bottom: 16px;
  background: rgba(34,197,94,.08); border: 1px solid rgba(34,197,94,.25);
  font-size: 13px;
}
.vpn-connected-tag {
  display: inline-flex; align-items: center; gap: 6px;
  background: var(--card2); border: 1px solid var(--green);
  border-radius: 999px; padding: 3px 10px; font-size: 12px; color: var(--green);
}
.vpn-connected-dot {
  width: 6px; height: 6px; border-radius: 50%; background: var(--green);
  box-shadow: 0 0 4px var(--green);
}

/* ── LOGIN PAGE ─────────────────────────────── */
.login-page {
  min-height: 100vh;
  display: flex; align-items: center; justify-content: center;
  background: var(--bg); padding: 24px;
}
.login-card {
  width: 100%; max-width: 420px;
  background: var(--card); border: 1px solid var(--border);
  border-radius: 20px; padding: 40px;
}
.login-logo { display: flex; align-items: center; gap: 14px; margin-bottom: 36px; }
.login-logo-icon {
  width: 52px; height: 52px;
  background: linear-gradient(135deg, var(--accent), var(--purple));
  border-radius: 14px; display: flex; align-items: center; justify-content: center;
  font-size: 24px; color: #fff;
}
.login-logo-text { font-size: 18px; font-weight: 700; }
.login-logo-text small { display: block; font-size: 12px; font-weight: 400; color: var(--muted); margin-top: 2px; }
.login-card h2 { font-size: 21px; font-weight: 700; margin-bottom: 4px; }
.login-card p { color: var(--muted); font-size: 13px; margin-bottom: 24px; }
.login-card .form-group { margin-bottom: 16px; }
.login-card input { margin-top: 0; }
.login-full { width: 100%; justify-content: center; padding: 12px; margin-top: 8px; }

/* ── HAMBURGER ──────────────────────────────── */
.hamburger {
  display: none;
  flex-direction: column; justify-content: center; align-items: center;
  gap: 5px;
  width: 38px; height: 38px;
  background: var(--card2); border: 1px solid var(--border);
  border-radius: 8px; cursor: pointer; flex-shrink: 0;
  padding: 0;
}
.hamburger span {
  display: block; width: 18px; height: 2px;
  background: var(--text); border-radius: 2px;
  transition: all .2s;
}

/* ── SIDEBAR OVERLAY ────────────────────────── */
#sidebar-overlay {
  display: none;
  position: fixed; inset: 0;
  background: rgba(0,0,0,.55);
  z-index: 1050;
}
#sidebar-overlay.show { display: block; }

/* ── RESPONSIVE ─────────────────────────────── */

/* Large tablet / laptop (≤ 1024px) */
@media (max-width: 1024px) {
  .main-content { padding: 20px 22px; }
  .charts-grid { grid-template-columns: 1fr 1.4fr; }
}

/* Tablet / large phone (≤ 900px): sidebar becomes a slide-in drawer */
@media (max-width: 900px) {
  .hamburger { display: flex; }
  .sidebar { transform: translateX(calc(-1 * var(--sidebar-w))); }
  .sidebar.open { transform: translateX(0); box-shadow: 8px 0 32px rgba(0,0,0,.65); }
  .main-wrap { margin-left: 0; width: 100%; max-width: 100vw; }
  .charts-grid { grid-template-columns: 1fr; }
  .grid-2 { grid-template-columns: 1fr; }
  .grid-3 { grid-template-columns: 1fr 1fr; }
  .main-header { padding: 0 16px; gap: 12px; }
  .main-header h1 { font-size: 17px; }
  .chart-wrap { height: 220px; }
  .col-hide-tablet { display: none; }
  .kpi-grid { grid-template-columns: repeat(auto-fit, minmax(110px, 1fr)); }
  .modal-backdrop { padding: 16px; }
}

/* Mobile (≤ 640px) */
@media (max-width: 640px) {
  .main-content { padding: 12px; overflow-x: hidden; width: 100%; max-width: 100vw; }
  .col-hide-mobile { display: none; }
  .header-search { display: none; }

  /* 5-column KPI row */
  .kpi-grid { grid-template-columns: repeat(5, minmax(0, 1fr)); gap: 6px; width: 100%; }
  .kpi-card { padding: 10px 5px 12px; border-radius: 10px; }
  .kpi-icon { display: none; }
  .kpi-top { justify-content: flex-start; }
  .kpi-label { font-size: 9px; letter-spacing: 0; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; max-width: 100%; }
  .kpi-value { font-size: 15px; margin-top: 4px; }
  .kpi-footer { display: none; }

  .grid-3 { grid-template-columns: 1fr; }
  .card { padding: 14px; margin-bottom: 14px; }
  .card-header { flex-wrap: wrap; gap: 8px; }
  .charts-grid { grid-template-columns: 1fr; gap: 12px; width: 100%; }
  .chart-wrap { height: 200px; width: 100%; }
  .chart-legend { grid-template-columns: 1fr 1fr; gap: 8px; }
  .action-btns { flex-direction: column; align-items: stretch; }
  .action-btns .btn { justify-content: center; }
  th, td { padding: 10px 8px; }
  .btn { padding: 8px 14px; }
  .btn-sm { padding: 5px 10px; font-size: 11px; }
  .form-row > * { min-width: 100%; flex: none; width: 100%; }
  .login-card { padding: 28px 20px; }
  .modal-backdrop { padding: 12px; }
  .modal-box { border-radius: 12px; max-height: 88vh; }
  .modal-body { padding: 16px; }
  .main-header h1 { font-size: 16px; }
  .pagination { gap: 4px; }
  .page-link { padding: 5px 9px; font-size: 11px; }
  /* VPN popup on mobile: flip to open above, ensure it fits */
  .vpn-sidebar-popup { left: 8px; right: 8px; }
  /* Table: hide less critical columns by default */
  .col-hide-sm { display: none; }
}

/* Small mobile (≤ 480px): further compaction */
@media (max-width: 480px) {
  .main-content { padding: 10px 8px; }
  .card { padding: 12px; }
  .card-header { gap: 6px; }
  th, td { padding: 8px 6px; font-size: 12px; }
  .kpi-value { font-size: 13px; }
  .kpi-label { font-size: 8px; }
  .main-header h1 { font-size: 15px; }
  /* Stack card-header buttons on very small phones */
  .card-header > div[style*="display:flex"] { flex-wrap: wrap; gap: 6px; }
}

/* Fold phones / extra-small (≤ 380px) */
@media (max-width: 380px) {
  :root { --sidebar-w: min(280px, 92vw); }
  .main-content { padding: 8px 6px; }
  .card { padding: 10px; border-radius: 10px; margin-bottom: 10px; }

  /* 3-column KPI (wraps to 2nd row for 4th and 5th) */
  .kpi-grid { grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 4px; }
  .kpi-card { padding: 8px 3px 10px; border-radius: 8px; }
  .kpi-label { font-size: 8px; }
  .kpi-value { font-size: 12px; }

  .main-header { height: 52px; padding: 0 10px; gap: 8px; }
  .main-header h1 { font-size: 13px; }

  th, td { padding: 6px 4px; font-size: 11px; }
  .btn { padding: 7px 10px; font-size: 12px; }
  .btn-sm { padding: 4px 7px; font-size: 10px; }
  .badge { font-size: 9px; padding: 2px 5px; }

  /* Bottom-sheet style modal on tiny screens */
  .modal-backdrop { padding: 0; align-items: flex-end; }
  .modal-box { border-radius: 16px 16px 0 0; max-height: 92vh; width: 100%; }

  .vpn-sidebar-popup { left: 4px; right: 4px; }
}
