/* Koala Den — Nocturnal Eucalyptus Glass UI */
:root {
  --bg: #070b10;
  --bg-2: #0c121b;
  --surface: rgba(17, 25, 36, 0.78);
  --surface-solid: #111924;
  --surface-hover: rgba(25, 36, 52, 0.88);
  --border: rgba(148, 163, 184, 0.14);
  --border-strong: rgba(52, 211, 153, 0.4);
  --text: #f1f5f9;
  --muted: #94a3b8;
  --accent: #34d399;
  --accent-2: #10b981;
  --sky: #38bdf8;
  --amber: #fbbf24;
  --danger: #f87171;
  --danger-bg: rgba(248, 113, 113, 0.12);
  --success-bg: rgba(52, 211, 153, 0.12);
  --sky-bg: rgba(56, 189, 248, 0.12);
  --radius: 18px;
  --radius-sm: 12px;
  --shadow: 0 20px 50px rgba(0, 0, 0, 0.45);
  --font: "Vazirmatn", "Segoe UI", Tahoma, system-ui, -apple-system, sans-serif;
  --mono: "JetBrains Mono", ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  min-height: 100vh;
  background: var(--bg);
  color: var(--text);
  font-family: var(--font);
  line-height: 1.7;
  overflow-x: hidden;
  -webkit-font-smoothing: antialiased;
}

/* ---------- Ambient background ---------- */
.ambient-bg {
  position: fixed;
  inset: 0;
  z-index: 0;
  pointer-events: none;
  overflow: hidden;
}
.orb {
  position: absolute;
  border-radius: 50%;
  filter: blur(110px);
  opacity: 0.18;
}
.orb-1 { width: 520px; height: 520px; background: #10b981; top: -180px; right: -120px; }
.orb-2 { width: 460px; height: 460px; background: #0ea5e9; bottom: -160px; left: -120px; }
.orb-3 { width: 320px; height: 320px; background: #6366f1; top: 45%; left: 35%; opacity: 0.08; }
.grid-overlay {
  position: absolute;
  inset: 0;
  background-image: radial-gradient(rgba(148, 163, 184, 0.08) 1px, transparent 1px);
  background-size: 28px 28px;
  mask-image: radial-gradient(ellipse at center, black 35%, transparent 80%);
}

.hidden { display: none !important; }
.muted { color: var(--muted); }
.small { font-size: 13px; }
.en { color: var(--muted); font-size: 12px; font-weight: 400; }
.en-title { color: var(--muted); font-size: 13px; font-weight: 500; margin-inline-start: 6px; }
.sep { border: none; border-top: 1px solid var(--border); margin: 18px 0; }

code, pre { font-family: var(--mono); }

/* ---------- Koala Emblem ---------- */
.koala-emblem {
  width: 48px;
  height: 48px;
  border-radius: 14px;
  background: linear-gradient(145deg, rgba(30, 41, 59, 0.9), rgba(15, 23, 42, 0.95));
  border: 1px solid var(--border-strong);
  padding: 6px;
  display: flex;
  align-items: center;
  justify-content: center;
  box-shadow: 0 8px 24px rgba(16, 185, 129, 0.15);
  flex-shrink: 0;
}
.koala-emblem-lg {
  width: 78px;
  height: 78px;
  border-radius: 22px;
  padding: 10px;
  margin: 0 auto 14px;
}
.koala-emblem svg { width: 100%; height: 100%; }

/* ---------- Login ---------- */
.login-shell {
  position: relative;
  z-index: 1;
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px;
}
.login-card {
  width: 100%;
  max-width: 460px;
  text-align: center;
}
.login-hero h1 {
  margin: 0 0 6px;
  font-size: 26px;
  font-weight: 800;
  background: linear-gradient(135deg, #f8fafc, #6ee7b7);
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
}
.login-hero p { margin: 0 0 22px; font-size: 14px; }
.login-card .form { text-align: start; }

/* ---------- App Shell ---------- */
.app-shell {
  position: relative;
  z-index: 1;
  display: grid;
  grid-template-columns: 270px 1fr;
  min-height: 100vh;
}

.sidebar {
  position: sticky;
  top: 0;
  height: 100vh;
  display: flex;
  flex-direction: column;
  padding: 22px 16px;
  background: rgba(10, 15, 23, 0.85);
  backdrop-filter: blur(18px);
  border-inline-end: 1px solid var(--border);
  gap: 20px;
}

.sidebar-brand {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 4px 6px;
}
.sidebar-brand h1 { margin: 0; font-size: 19px; font-weight: 800; line-height: 1.25; }
.origin-pill {
  display: inline-block;
  font-family: var(--mono);
  font-size: 11px;
  color: var(--accent);
  max-width: 165px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.side-nav {
  display: flex;
  flex-direction: column;
  gap: 6px;
  flex: 1;
}
.den-tab {
  display: flex;
  align-items: center;
  gap: 10px;
  width: 100%;
  text-align: start;
  font-family: var(--font);
  font-size: 14px;
  font-weight: 600;
  padding: 12px 14px;
  border-radius: var(--radius-sm);
  border: 1px solid transparent;
  background: transparent;
  color: var(--muted);
  cursor: pointer;
  transition: all 0.16s ease;
}
.den-tab:hover {
  background: rgba(255, 255, 255, 0.04);
  color: var(--text);
}
.den-tab.active {
  background: linear-gradient(135deg, rgba(52, 211, 153, 0.16), rgba(56, 189, 248, 0.08));
  border-color: rgba(52, 211, 153, 0.35);
  color: #fff;
  box-shadow: 0 6px 20px rgba(16, 185, 129, 0.12);
}
.nav-ico { font-size: 18px; line-height: 1; }

.sidebar-footer {
  display: flex;
  flex-direction: column;
  gap: 10px;
  padding-top: 12px;
  border-top: 1px solid var(--border);
}
.status-chip {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 12px;
  color: var(--muted);
  padding: 8px 12px;
  border-radius: 10px;
  background: rgba(255, 255, 255, 0.03);
  border: 1px solid var(--border);
}
.pulse-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--accent);
  box-shadow: 0 0 0 4px rgba(52, 211, 153, 0.2);
}

.main-content {
  padding: 24px 28px 48px;
  max-width: 1280px;
  width: 100%;
  margin: 0 auto;
}

/* ---------- KPI Stats ---------- */
.stats-grid {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 14px;
  margin-bottom: 22px;
}
.kpi-card {
  background: var(--surface);
  backdrop-filter: blur(14px);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 16px 18px;
  display: flex;
  flex-direction: column;
  gap: 4px;
}
.kpi-label { font-size: 12px; color: var(--muted); font-weight: 600; }
.kpi-val { font-size: 28px; font-weight: 800; line-height: 1.2; font-variant-numeric: tabular-nums; }
.kpi-green .kpi-val { color: var(--accent); }
.kpi-red .kpi-val { color: var(--danger); }
.kpi-blue .kpi-val { color: var(--sky); }

/* ---------- Cards ---------- */
.card {
  background: var(--surface);
  backdrop-filter: blur(16px);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 22px;
  box-shadow: var(--shadow);
}
.card h2 { margin: 0 0 14px; font-size: 18px; font-weight: 700; display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
.card h3 { margin: 12px 0 8px; font-size: 14px; font-weight: 700; color: var(--accent); }
.card-head { display: flex; align-items: center; justify-content: space-between; gap: 12px; margin-bottom: 14px; flex-wrap: wrap; }
.card-head h2 { margin: 0; }
.chip-tag {
  font-size: 11px;
  font-weight: 700;
  padding: 4px 10px;
  border-radius: 999px;
  background: var(--success-bg);
  color: var(--accent);
  border: 1px solid rgba(52, 211, 153, 0.3);
}

.users-layout {
  display: grid;
  grid-template-columns: 350px 1fr;
  gap: 20px;
  align-items: start;
}
.settings-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 20px;
  align-items: start;
}
.span-2 { grid-column: 1 / -1; }

/* ---------- Forms ---------- */
.form { display: flex; flex-direction: column; gap: 14px; }
.field { display: flex; flex-direction: column; gap: 6px; }
.field-label { font-weight: 600; font-size: 13px; color: #cbd5e1; }

.two-col { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.three-col { display: grid; grid-template-columns: repeat(3, 1fr); gap: 10px; }

input, textarea, select {
  width: 100%;
  padding: 10px 13px;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border);
  background: rgba(7, 11, 16, 0.85);
  color: var(--text);
  font-family: var(--font);
  font-size: 14px;
  outline: none;
  transition: border-color 0.15s, box-shadow 0.15s;
}
input[dir="ltr"], textarea[dir="ltr"], select[dir="ltr"] {
  font-family: var(--mono);
  font-size: 13px;
}
input:focus, textarea:focus, select:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px rgba(52, 211, 153, 0.15);
}
textarea { resize: vertical; line-height: 1.5; }
input[type="file"] { padding: 8px; font-size: 13px; }

/* ---------- Switches & Toggles ---------- */
.switch-row {
  display: flex;
  align-items: center;
  gap: 10px;
  font-weight: 600;
  font-size: 14px;
  cursor: pointer;
}
.switch-row input[type="checkbox"],
.switch-card input[type="checkbox"] {
  width: 18px;
  height: 18px;
  accent-color: var(--accent);
  cursor: pointer;
  flex-shrink: 0;
}
.toggle-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(150px, 1fr));
  gap: 8px;
}
.switch-card {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 9px 11px;
  border-radius: 10px;
  border: 1px solid var(--border);
  background: rgba(255, 255, 255, 0.02);
  font-size: 13px;
  font-weight: 600;
  cursor: pointer;
  transition: border-color 0.15s, background 0.15s;
}
.switch-card:hover { border-color: rgba(52, 211, 153, 0.35); background: rgba(52, 211, 153, 0.05); }

/* ---------- Buttons & Pills ---------- */
.btn {
  font-family: var(--font);
  font-size: 14px;
  font-weight: 700;
  padding: 10px 16px;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border);
  cursor: pointer;
  color: var(--text);
  background: rgba(30, 41, 59, 0.8);
  transition: all 0.15s ease;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  text-decoration: none;
}
.btn:hover { background: rgba(51, 65, 85, 0.9); border-color: rgba(148, 163, 184, 0.3); }
.btn:active { transform: scale(0.98); }
.btn:disabled { opacity: 0.5; cursor: wait; }
.btn-primary {
  background: linear-gradient(135deg, #34d399, #059669);
  color: #03150e;
  border-color: transparent;
  box-shadow: 0 6px 18px rgba(16, 185, 129, 0.25);
}
.btn-primary:hover { filter: brightness(1.06); background: linear-gradient(135deg, #34d399, #059669); }
.btn-ghost { background: transparent; border-color: var(--border); }
.btn-ghost:hover { background: rgba(255, 255, 255, 0.05); }
.btn-danger { background: var(--danger-bg); color: var(--danger); border-color: rgba(248, 113, 113, 0.35); }
.btn-danger:hover { background: rgba(248, 113, 113, 0.22); }
.btn-sm { padding: 6px 11px; font-size: 12px; border-radius: 9px; }
.btn-lg { padding: 12px 20px; font-size: 15px; }
.btn-block { width: 100%; }

.preset-pills { display: flex; flex-wrap: wrap; gap: 6px; }
.pill-btn {
  font-family: var(--font);
  font-size: 12px;
  font-weight: 600;
  padding: 5px 11px;
  border-radius: 999px;
  border: 1px solid var(--border);
  background: rgba(255, 255, 255, 0.03);
  color: var(--muted);
  cursor: pointer;
  transition: all 0.15s;
}
.pill-btn:hover { color: var(--text); border-color: var(--accent); }
.pill-btn.active { background: var(--success-bg); color: var(--accent); border-color: var(--accent); }

.tool-actions { display: flex; gap: 8px; flex-wrap: wrap; margin: 10px 0; }

/* ---------- Users list & toolbar ---------- */
.toolbar-controls { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }
.search-input { width: 185px; padding: 7px 11px; font-size: 13px; }
.filter-select { width: auto; min-width: 115px; padding: 7px 10px; font-size: 13px; }

.users-list { list-style: none; margin: 14px 0 0; padding: 0; display: flex; flex-direction: column; gap: 12px; }
.user-row {
  border: 1px solid var(--border);
  border-radius: 14px;
  padding: 15px 16px;
  background: rgba(7, 11, 16, 0.5);
  display: flex;
  flex-direction: column;
  gap: 10px;
  transition: border-color 0.15s;
}
.user-row:hover { border-color: rgba(52, 211, 153, 0.35); }
.user-top { display: flex; align-items: center; justify-content: space-between; gap: 10px; flex-wrap: wrap; }
.user-name { font-weight: 700; font-size: 16px; display: flex; align-items: center; gap: 8px; }
.user-note { font-size: 12px; color: var(--sky); background: var(--sky-bg); padding: 2px 8px; border-radius: 6px; }
.user-meta { font-size: 12px; color: var(--muted); display: flex; gap: 14px; flex-wrap: wrap; align-items: center; }
.user-uuid { display: flex; align-items: center; gap: 6px; }
.user-uuid code { font-size: 11px; background: #070b10; padding: 2px 8px; border-radius: 6px; border: 1px solid var(--border); }

.expiry-bar-wrap { display: flex; align-items: center; gap: 10px; }
.expiry-bar { flex: 1; height: 6px; border-radius: 999px; background: rgba(148, 163, 184, 0.14); overflow: hidden; }
.expiry-fill { height: 100%; border-radius: 999px; background: linear-gradient(90deg, var(--accent), var(--sky)); transition: width 0.3s; }
.expiry-fill.warn { background: linear-gradient(90deg, var(--amber), #f97316); }
.expiry-fill.dead { background: var(--danger); }
.expiry-text { font-size: 12px; font-weight: 600; min-width: 90px; text-align: end; }

.badge {
  font-size: 11px;
  font-weight: 700;
  padding: 3px 10px;
  border-radius: 999px;
}
.badge-active { background: var(--success-bg); color: var(--accent); border: 1px solid rgba(52, 211, 153, 0.35); }
.badge-expired { background: var(--danger-bg); color: var(--danger); border: 1px solid rgba(248, 113, 113, 0.35); }
.badge-disabled { background: rgba(251, 191, 36, 0.14); color: var(--amber); border: 1px solid rgba(251, 191, 36, 0.35); }
.user-actions { display: flex; gap: 6px; flex-wrap: wrap; }

/* ---------- Links & Code ---------- */
.new-user-result { margin-top: 16px; padding-top: 14px; border-top: 1px dashed var(--border); }
.success-banner { font-size: 12px; color: var(--accent); margin-bottom: 8px; font-weight: 600; }
.link-row { display: flex; gap: 8px; align-items: center; margin-bottom: 10px; }
.link-row code {
  flex: 1;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  background: #070b10;
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 8px 11px;
  font-size: 12px;
}
pre {
  background: #070b10;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 12px;
  overflow: auto;
  max-height: 300px;
  font-size: 12px;
  line-height: 1.5;
  direction: ltr;
  text-align: left;
  white-space: pre-wrap;
  word-break: break-word;
}

.chip-list { list-style: none; margin: 0 0 12px; padding: 0; display: flex; flex-direction: column; gap: 6px; }
.chip-list-wrap { flex-direction: row; flex-wrap: wrap; }
.chip-item {
  display: inline-flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 5px 10px;
  background: rgba(7, 11, 16, 0.6);
  font-size: 12px;
}
.chip-item code { font-size: 12px; }

/* ---------- Format Grid & Modal ---------- */
.fmt-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(155px, 1fr)); gap: 10px; margin: 12px 0 14px; }
.fmt-card {
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  gap: 2px;
  text-align: right;
  padding: 11px 13px;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border);
  background: rgba(7, 11, 16, 0.55);
  color: var(--text);
  cursor: pointer;
  font-family: inherit;
  transition: all 0.15s;
}
.fmt-card:hover { border-color: var(--accent); transform: translateY(-1px); }
.fmt-card.selected { background: var(--success-bg); border-color: var(--accent); box-shadow: 0 0 0 1px var(--accent); }
.fmt-icon { font-size: 20px; }
.fmt-name { font-size: 13px; font-weight: 700; }
.fmt-desc { font-size: 11px; color: var(--muted); }

.modal {
  position: fixed;
  inset: 0;
  background: rgba(3, 7, 12, 0.78);
  backdrop-filter: blur(8px);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 18px;
  z-index: 50;
}
.modal-box { width: 100%; max-width: 660px; max-height: 88vh; overflow: auto; }
.modal-head { display: flex; align-items: center; justify-content: space-between; gap: 12px; margin-bottom: 12px; }
.modal-head h3 { margin: 0; font-size: 17px; color: var(--text); }
.modal-actions { display: flex; justify-content: flex-end; gap: 8px; margin-top: 14px; }

.cfg-tabs { display: flex; flex-wrap: wrap; gap: 6px; margin-bottom: 14px; padding-bottom: 12px; border-bottom: 1px solid var(--border); }
.cfg-tab {
  font-family: var(--font);
  padding: 7px 12px;
  border-radius: 10px;
  border: 1px solid var(--border);
  background: rgba(7, 11, 16, 0.6);
  color: var(--muted);
  cursor: pointer;
  font-size: 12px;
  font-weight: 700;
}
.cfg-tab:hover { border-color: var(--accent); color: var(--text); }
.cfg-tab.active { background: var(--success-bg); border-color: var(--accent); color: var(--accent); }
.cfg-panel { display: none; }
.cfg-panel.active { display: block; }
.cfg-code { margin-top: 12px; }
.cfg-code summary { cursor: pointer; color: var(--muted); font-size: 12px; }

.format-row { display: flex; align-items: center; gap: 8px; margin-bottom: 8px; flex-wrap: wrap; }
.format-label { font-weight: 700; font-size: 12px; min-width: 96px; color: var(--accent); }
.format-row code {
  flex: 1;
  min-width: 170px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  background: #070b10;
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 6px 10px;
  font-size: 11px;
}

.qr-wrap { display: flex; flex-direction: column; align-items: center; gap: 10px; margin-top: 12px; }
.qr-box { background: #fff; padding: 12px; border-radius: 12px; line-height: 0; }
.qr-link { font-family: var(--mono); direction: ltr; font-size: 12px; word-break: break-all; text-align: center; }

.error {
  background: var(--danger-bg);
  color: var(--danger);
  border: 1px solid rgba(248, 113, 113, 0.35);
  border-radius: 10px;
  padding: 9px 12px;
  margin-top: 10px;
  font-size: 13px;
}
.hint {
  margin-top: 18px;
  text-align: start;
  background: var(--sky-bg);
  border: 1px solid rgba(56, 189, 248, 0.25);
  border-radius: var(--radius-sm);
  padding: 11px 14px;
  font-size: 13px;
}
.hint summary { cursor: pointer; font-weight: 700; }
.hint ol { margin: 8px 0 0; padding-inline-start: 18px; }
.hint code { background: rgba(0, 0, 0, 0.3); padding: 1px 6px; border-radius: 5px; font-size: 12px; }

.toast {
  position: fixed;
  bottom: 24px;
  left: 50%;
  transform: translateX(-50%);
  background: #0f172a;
  border: 1px solid var(--border-strong);
  color: var(--text);
  padding: 10px 20px;
  border-radius: 999px;
  box-shadow: var(--shadow);
  z-index: 100;
  font-size: 13px;
  font-weight: 600;
}

/* ---------- Tables ---------- */
.table-scroll { overflow-x: auto; margin-top: 8px; }
.divider-dashed { margin: 16px 0; border-top: 1px dashed var(--border); }
.sub-heading { margin: 0 0 6px; font-size: 14px; font-weight: 700; display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
.proxy-ip-table { width: 100%; border-collapse: collapse; font-size: 12px; min-width: 620px; }
.proxy-ip-table th, .proxy-ip-table td { padding: 7px 8px; border-bottom: 1px solid var(--border); text-align: right; white-space: nowrap; }
.proxy-ip-table th { color: var(--muted); font-weight: 600; background: rgba(7, 11, 16, 0.55); }
.proxy-ip-cell { display: inline-flex; align-items: center; gap: 6px; direction: ltr; }
.icon-mini-btn {
  background: rgba(148, 163, 184, 0.12);
  border: 1px solid var(--border);
  color: var(--text);
  border-radius: 7px;
  padding: 2px 7px;
  font-size: 11px;
  cursor: pointer;
}
.icon-mini-btn:hover { border-color: var(--accent); color: var(--accent); }
.icon-mini-btn:disabled { opacity: 0.45; cursor: wait; }
.pill-good { color: var(--accent); font-weight: 700; }
.pill-warn { color: var(--amber); font-weight: 700; }
.pill-bad { color: var(--danger); font-weight: 700; }

/* ---------- Responsive ---------- */
@media (max-width: 1020px) {
  .app-shell { grid-template-columns: 1fr; }
  .sidebar {
    position: static;
    height: auto;
    border-inline-end: none;
    border-bottom: 1px solid var(--border);
    padding: 14px 16px;
  }
  .side-nav {
    flex-direction: row;
    overflow-x: auto;
    padding-bottom: 4px;
  }
  .den-tab { white-space: nowrap; width: auto; }
  .sidebar-footer { flex-direction: row; justify-content: space-between; align-items: center; }
  .sidebar-footer .btn-block { width: auto; }
  .users-layout, .settings-grid { grid-template-columns: 1fr; }
  .stats-grid { grid-template-columns: repeat(2, 1fr); }
}
@media (max-width: 560px) {
  .main-content { padding: 16px 14px 36px; }
  .two-col, .three-col { grid-template-columns: 1fr; }
}
