/* VPN_Amazing_BOT Admin Panel — современная тёмная/светлая тема. */

:root {
  --bg: #0b1220;
  --bg-2: #0f1a2e;
  --surface: #131e36;
  --surface-2: #18253f;
  --surface-3: #1f2f4d;
  --border: #243352;
  --border-strong: #314772;
  --text: #e8eefc;
  --text-dim: #aab6cf;
  --text-muted: #6f7e9e;
  --primary: #4f7cff;
  --primary-hover: #6a8fff;
  --primary-soft: #1f2d56;
  --success: #2bbf7a;
  --success-soft: #1d3a2c;
  --warning: #f5a524;
  --warning-soft: #3b2c10;
  --danger: #f31260;
  --danger-soft: #3b1224;
  --info: #06b7db;
  --info-soft: #0a2f3a;
  --radius: 14px;
  --radius-sm: 8px;
  --shadow: 0 8px 24px rgba(0, 0, 0, 0.35);
  --shadow-lg: 0 24px 48px rgba(0, 0, 0, 0.45);
  --sidebar-w: 260px;
  --header-h: 64px;
}

[data-theme="light"] {
  --bg: #f4f7fb;
  --bg-2: #eef2f8;
  --surface: #ffffff;
  --surface-2: #f7f9fc;
  --surface-3: #eef2f7;
  --border: #e3e9f1;
  --border-strong: #c7d3e3;
  --text: #0e1a2c;
  --text-dim: #43536e;
  --text-muted: #708099;
  --primary: #2f5cf0;
  --primary-hover: #1d49db;
  --primary-soft: #e1ebff;
  --success: #198a52;
  --success-soft: #d6f1e3;
  --warning: #c47800;
  --warning-soft: #fbe7c0;
  --danger: #d70750;
  --danger-soft: #ffd6e3;
  --info: #097c92;
  --info-soft: #cdeef5;
  --shadow: 0 8px 24px rgba(20, 35, 70, 0.08);
  --shadow-lg: 0 24px 48px rgba(20, 35, 70, 0.12);
}

* { box-sizing: border-box; }
html, body { height: 100%; }
body {
  margin: 0;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto,
    "Helvetica Neue", Arial, "Noto Sans", sans-serif, "Apple Color Emoji",
    "Segoe UI Emoji";
  background: var(--bg);
  color: var(--text);
  -webkit-font-smoothing: antialiased;
  font-size: 14px;
  line-height: 1.55;
}

a { color: var(--primary); text-decoration: none; }
a:hover { color: var(--primary-hover); text-decoration: underline; }

code, pre, .mono {
  font-family: "JetBrains Mono", ui-monospace, SFMono-Regular, Menlo, Monaco,
    Consolas, "Courier New", monospace;
  font-size: 12.5px;
}

.app {
  display: grid;
  grid-template-columns: var(--sidebar-w) 1fr;
  min-height: 100vh;
}

/* ─── Sidebar ───────────────────────────────────────────── */
.sidebar {
  background: linear-gradient(180deg, var(--bg-2), var(--bg));
  border-right: 1px solid var(--border);
  padding: 18px 14px 24px;
  display: flex;
  flex-direction: column;
  position: sticky;
  top: 0;
  height: 100vh;
  overflow-y: auto;
}

.brand {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 6px 8px 18px;
  border-bottom: 1px solid var(--border);
  margin-bottom: 14px;
}
.brand-mark {
  width: 38px; height: 38px;
  border-radius: 10px;
  background: linear-gradient(135deg, var(--primary), #8b5cf6);
  display: grid; place-items: center;
  color: #fff; font-weight: 700; font-size: 18px;
  box-shadow: 0 6px 16px rgba(79, 124, 255, 0.35);
}
.brand-text { line-height: 1.1; }
.brand-title { font-weight: 700; font-size: 15px; letter-spacing: 0.2px; }
.brand-sub { color: var(--text-muted); font-size: 12px; }

.nav-group {
  padding: 14px 8px 6px;
  font-size: 11px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.07em;
  color: var(--text-muted);
}
.nav a {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 9px 10px;
  border-radius: 10px;
  color: var(--text-dim);
  font-weight: 500;
  transition: all 0.12s ease;
}
.nav a:hover { background: var(--surface); color: var(--text); text-decoration: none; }
.nav a.active {
  background: var(--primary-soft);
  color: var(--primary);
  font-weight: 600;
}
.nav .ico {
  width: 20px; height: 20px;
  display: inline-grid; place-items: center;
  font-size: 16px;
}

.sidebar-footer {
  margin-top: auto;
  padding: 12px 8px 4px;
  border-top: 1px solid var(--border);
  display: flex; align-items: center; gap: 10px;
}
.avatar {
  width: 36px; height: 36px; border-radius: 50%;
  background: linear-gradient(135deg, #fb7185, #f59e0b);
  display: grid; place-items: center; color: #fff; font-weight: 700;
  flex-shrink: 0;
}
.who { line-height: 1.15; min-width: 0; flex: 1; }
.who .name { font-weight: 600; color: var(--text); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.who .meta { font-size: 11px; color: var(--text-muted); }

/* ─── Main ──────────────────────────────────────────────── */
.main {
  min-width: 0;
  display: flex;
  flex-direction: column;
}
.topbar {
  position: sticky; top: 0; z-index: 20;
  min-height: var(--header-h);
  background: rgba(11, 18, 32, 0.85);
  -webkit-backdrop-filter: blur(10px);
  backdrop-filter: blur(10px);
  border-bottom: 1px solid var(--border);
  display: flex; align-items: center; justify-content: space-between;
  flex-wrap: wrap;
  gap: 12px 16px;
  padding: 10px 24px;
}
[data-theme="light"] .topbar { background: rgba(244, 247, 251, 0.85); }
.topbar h1 {
  margin: 0; font-size: 18px; font-weight: 600; color: var(--text);
  display: flex; align-items: center; flex-wrap: wrap;
  gap: 8px 10px;
  flex: 1 1 auto;
  min-width: 0;
  line-height: 1.35;
}
.topbar .row {
  flex-shrink: 0;
}
.crumbs { color: var(--text-muted); font-weight: 400; font-size: 13px; }

.content {
  padding: 24px;
  max-width: 1500px;
  width: 100%;
  min-width: 0;
}

/* ─── Cards ──────────────────────────────────────────────── */
.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 20px;
  box-shadow: var(--shadow);
}
.card + .card { margin-top: 18px; }
.card-header {
  display: flex; justify-content: space-between; align-items: center;
  flex-wrap: wrap;
  gap: 12px 16px;
  margin-bottom: 14px; padding-bottom: 12px;
  border-bottom: 1px solid var(--border);
}
.card-header > * {
  min-width: 0;
}
.card-header form.row {
  flex: 1 1 auto;
  min-width: 0;
}
.card-header form.row input[type="text"],
.card-header form.row input[type="search"] {
  flex: 1 1 160px;
  min-width: 0;
  max-width: 100%;
}
.card-header h2 { margin: 0; font-size: 16px; font-weight: 600; }
.card-title-meta { color: var(--text-muted); font-size: 12px; }

.grid { display: grid; gap: 16px; }
.grid-2 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
.grid-3 { grid-template-columns: repeat(3, minmax(0, 1fr)); }
.grid-4 { grid-template-columns: repeat(4, minmax(0, 1fr)); }
@media (max-width: 1100px) {
  .grid-4 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .grid-3 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
}
@media (max-width: 700px) { .grid-2, .grid-3, .grid-4 { grid-template-columns: minmax(0, 1fr); } }

/* ─── Stat tiles ─────────────────────────────────────────── */
.stat {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 18px 20px;
  position: relative;
  overflow: hidden;
}
.stat::after {
  content: ""; position: absolute; right: -40px; top: -40px;
  width: 140px; height: 140px;
  background: radial-gradient(closest-side, var(--primary-soft), transparent 70%);
  opacity: 0.7;
  z-index: 0;
  pointer-events: none;
}
.stat > * {
  position: relative;
  z-index: 1;
}
.stat .stat-label {
  color: var(--text-muted);
  font-size: 12px; font-weight: 600; text-transform: uppercase; letter-spacing: 0.06em;
}
.stat .stat-value {
  font-size: 26px; font-weight: 700; margin-top: 6px;
  display: flex; align-items: baseline; gap: 6px;
}
.stat .stat-suffix { font-size: 13px; color: var(--text-muted); font-weight: 500; }
.stat .stat-trend {
  font-size: 12px; margin-top: 8px;
  display: inline-flex; align-items: center; gap: 4px;
  padding: 3px 8px; border-radius: 999px; font-weight: 600;
}
.stat .stat-trend.up { background: var(--success-soft); color: var(--success); }
.stat .stat-trend.down { background: var(--danger-soft); color: var(--danger); }

/* ─── Buttons ────────────────────────────────────────────── */
.btn {
  display: inline-flex; align-items: center; gap: 7px;
  padding: 8px 14px;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border-strong);
  background: var(--surface-2);
  color: var(--text);
  font-weight: 600; font-size: 13px;
  cursor: pointer; transition: all 0.12s ease;
  text-decoration: none;
}
.btn:hover { background: var(--surface-3); color: var(--text); text-decoration: none; }
.btn-primary {
  background: var(--primary); border-color: var(--primary); color: #fff;
}
.btn-primary:hover { background: var(--primary-hover); border-color: var(--primary-hover); color: #fff; }
.btn-danger { background: var(--danger-soft); border-color: var(--danger); color: var(--danger); }
.btn-danger:hover { background: var(--danger); color: #fff; }
.btn-success { background: var(--success-soft); border-color: var(--success); color: var(--success); }
.btn-success:hover { background: var(--success); color: #fff; }
.btn-warning { background: var(--warning-soft); border-color: var(--warning); color: var(--warning); }
.btn-ghost { background: transparent; border-color: transparent; color: var(--text-dim); }
.btn-ghost:hover { background: var(--surface-2); color: var(--text); }
.btn-sm { padding: 5px 10px; font-size: 12px; }
.btn[disabled] { opacity: 0.55; cursor: not-allowed; }

.btn-row { display: flex; flex-wrap: wrap; gap: 8px; }
.actions {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: flex-end;
  gap: 6px;
}
.actions form {
  display: inline-flex;
  margin: 0;
}

/* ─── Tables ─────────────────────────────────────────────── */
.table {
  width: 100%;
  min-width: 0;
  border-collapse: separate; border-spacing: 0;
  font-size: 13px;
  table-layout: auto;
}
.table th, .table td {
  text-align: left; padding: 12px 14px;
  border-bottom: 1px solid var(--border);
  vertical-align: middle;
  min-width: 0;
}
.table th {
  color: var(--text-muted); font-weight: 600; font-size: 11.5px;
  text-transform: uppercase; letter-spacing: 0.05em;
  background: var(--surface-2);
}
/* Липкий заголовок только относительно .table-wrap (top: 64px ломал вёрстку внутри overflow) */
.table-wrap .table thead th {
  position: sticky;
  top: 0;
  z-index: 3;
  background: var(--surface-2);
  box-shadow: 0 1px 0 var(--border);
}
.table tr:hover td { background: var(--surface-2); }
.table tr:last-child td { border-bottom: none; }
.table-wrap {
  border: 1px solid var(--border);
  border-radius: var(--radius);
  overflow: auto;
  background: var(--surface);
  max-width: 100%;
  -webkit-overflow-scrolling: touch;
}
.table-empty {
  padding: 60px 20px; text-align: center; color: var(--text-muted);
}

/* ─── Badges ─────────────────────────────────────────────── */
.badge {
  display: inline-flex; align-items: center; gap: 4px;
  padding: 3px 9px; border-radius: 999px;
  font-size: 11px; font-weight: 700;
  text-transform: uppercase; letter-spacing: 0.04em;
  white-space: nowrap;
}
.badge-green { background: var(--success-soft); color: var(--success); }
.badge-red { background: var(--danger-soft); color: var(--danger); }
.badge-orange { background: var(--warning-soft); color: var(--warning); }
.badge-blue { background: var(--primary-soft); color: var(--primary); }
.badge-info { background: var(--info-soft); color: var(--info); }
.badge-gray { background: var(--surface-3); color: var(--text-muted); }

/* ─── Forms ─────────────────────────────────────────────── */
.form-grid { display: grid; gap: 14px; }
.form-grid.cols-2 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
.form-grid.cols-3 { grid-template-columns: repeat(3, minmax(0, 1fr)); }
@media (max-width: 700px) { .form-grid.cols-2, .form-grid.cols-3 { grid-template-columns: minmax(0, 1fr); } }

.field { display: flex; flex-direction: column; gap: 6px; min-width: 0; }
.field label { font-size: 12px; font-weight: 600; color: var(--text-dim); }
.field .hint { font-size: 11px; color: var(--text-muted); }

input[type="text"], input[type="number"], input[type="email"], input[type="datetime-local"],
input[type="date"], input[type="password"], input[type="url"], textarea, select {
  width: 100%;
  padding: 9px 12px;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border-strong);
  background: var(--surface-2);
  color: var(--text);
  font-size: 13px;
  font-family: inherit;
  transition: border-color 0.12s ease, box-shadow 0.12s ease;
}
textarea { resize: vertical; min-height: 80px; }
input:focus, textarea:focus, select:focus {
  outline: none;
  border-color: var(--primary);
  box-shadow: 0 0 0 3px var(--primary-soft);
}

.checkbox-row {
  display: inline-flex; align-items: center; gap: 8px;
  font-size: 13px; cursor: pointer; user-select: none;
}
.checkbox-row input[type="checkbox"] { width: 16px; height: 16px; accent-color: var(--primary); }

.search {
  position: relative;
  max-width: 380px;
  flex: 1 1 200px;
  min-width: 0;
}
.search input { padding-left: 36px; }
.search::before {
  content: "🔍"; position: absolute; left: 12px; top: 50%;
  transform: translateY(-50%); font-size: 14px; opacity: 0.7;
}

/* ─── Pagination ─────────────────────────────────────────── */
.pagination {
  display: flex; gap: 4px; align-items: center; justify-content: center;
  margin-top: 16px;
}
.pagination a, .pagination span {
  padding: 6px 12px;
  border-radius: 8px;
  background: var(--surface-2);
  color: var(--text-dim);
  border: 1px solid var(--border);
  font-size: 13px; font-weight: 600;
  text-decoration: none;
}
.pagination a:hover { background: var(--surface-3); color: var(--text); text-decoration: none; }
.pagination .current {
  background: var(--primary); color: #fff; border-color: var(--primary);
}
.pagination .disabled { opacity: 0.4; cursor: not-allowed; }

/* ─── Login page ─────────────────────────────────────────── */
.login-wrap {
  min-height: 100vh;
  display: grid; place-items: center;
  background:
    radial-gradient(circle at 80% 10%, rgba(79, 124, 255, 0.18), transparent 50%),
    radial-gradient(circle at 10% 80%, rgba(139, 92, 246, 0.18), transparent 50%),
    var(--bg);
  padding: 24px;
}
.login-card {
  width: 100%; max-width: 440px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 18px;
  padding: 36px 32px;
  box-shadow: var(--shadow-lg);
  text-align: center;
}
.login-logo {
  width: 64px; height: 64px;
  border-radius: 18px;
  margin: 0 auto 18px;
  display: grid; place-items: center;
  background: linear-gradient(135deg, var(--primary), #8b5cf6);
  color: #fff; font-size: 30px; font-weight: 700;
  box-shadow: 0 8px 24px rgba(79, 124, 255, 0.4);
}
.login-card h1 { margin: 0 0 6px; font-size: 22px; font-weight: 700; }
.login-card p { margin: 0 0 24px; color: var(--text-muted); font-size: 14px; }
.login-tg { margin-top: 18px; display: grid; place-items: center; min-height: 50px; }
.login-error {
  padding: 11px 14px; border-radius: 10px;
  background: var(--danger-soft); color: var(--danger);
  font-size: 13px; font-weight: 600; margin-bottom: 18px;
  border: 1px solid var(--danger);
}
.login-warn {
  padding: 11px 14px; border-radius: 10px;
  background: var(--warning-soft); color: var(--warning);
  font-size: 13px; margin-bottom: 18px; text-align: left;
  border: 1px solid var(--warning);
}

/* ─── KV list / detail ──────────────────────────────────── */
.kv {
  display: grid;
  grid-template-columns: minmax(0, 220px) minmax(0, 1fr);
  row-gap: 10px;
  column-gap: 12px;
  font-size: 13px;
}
.kv .k { color: var(--text-muted); font-weight: 600; }
.kv .v { color: var(--text); word-break: break-word; }
@media (max-width: 600px) { .kv { grid-template-columns: 1fr; } .kv .k { margin-top: 6px; } }

/* ─── Permission groups grid ────────────────────────────── */
.perm-groups {
  display: grid; gap: 14px;
  grid-template-columns: repeat(auto-fill, minmax(260px, 1fr));
}
.perm-group {
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 14px;
}
.perm-group h4 {
  margin: 0 0 10px; font-size: 13px; font-weight: 700;
  color: var(--text); text-transform: uppercase;
  letter-spacing: 0.05em;
}
.perm-group .item {
  display: flex; align-items: center; gap: 8px;
  padding: 4px 0; font-size: 13px;
}
.perm-group .item input { accent-color: var(--primary); }

/* ─── Misc ───────────────────────────────────────────────── */
.empty-state {
  text-align: center; padding: 60px 20px; color: var(--text-muted);
}
.muted { color: var(--text-muted); }
.right { text-align: right; }
.center { text-align: center; }
.nowrap { white-space: nowrap; }
.hr { height: 1px; background: var(--border); margin: 18px 0; border: 0; }
.spacer { flex: 1; }
.row { display: flex; gap: 12px; align-items: center; flex-wrap: wrap; }
.row.between { justify-content: space-between; }

.theme-toggle {
  width: 38px; height: 38px;
  border-radius: 10px;
  background: var(--surface-2);
  border: 1px solid var(--border);
  color: var(--text-dim);
  display: grid; place-items: center;
  cursor: pointer; font-size: 16px;
}
.theme-toggle:hover { background: var(--surface-3); color: var(--text); }

.copy-btn {
  background: transparent; border: 0; cursor: pointer;
  color: var(--primary); font-size: 12px; padding: 4px 6px;
  border-radius: 6px;
}
.copy-btn:hover { background: var(--primary-soft); }

.flash {
  padding: 12px 16px; border-radius: var(--radius-sm); margin-bottom: 14px;
  border: 1px solid var(--border);
}
.flash-error { background: var(--danger-soft); color: var(--danger); border-color: var(--danger); }
.flash-success { background: var(--success-soft); color: var(--success); border-color: var(--success); }

/* mini chart for dashboard */
.chart-bars { display: flex; align-items: flex-end; gap: 4px; height: 100px; padding: 8px 0; }
.chart-bars .bar {
  flex: 1; background: linear-gradient(180deg, var(--primary), var(--primary-hover));
  border-radius: 4px 4px 0 0; min-height: 4px;
  position: relative;
}
.chart-bars .bar:hover { background: linear-gradient(180deg, var(--primary-hover), var(--primary)); }
.chart-labels { display: flex; gap: 4px; margin-top: 4px; }
.chart-labels .lbl {
  flex: 1; text-align: center; font-size: 10px; color: var(--text-muted);
}

/* sidebar collapse on small screens */
@media (max-width: 900px) {
  .app { grid-template-columns: 1fr; }
  .sidebar {
    position: fixed; left: -300px; top: 0; bottom: 0; width: 280px;
    z-index: 100; transition: left 0.2s ease;
    box-shadow: var(--shadow-lg);
  }
  .sidebar.open { left: 0; }
  .menu-toggle { display: inline-grid !important; }
}
.menu-toggle { display: none; }

.scroll-x { overflow-x: auto; }
