:root {
  --bg: #0f1420;
  --card: #171d2e;
  --card-2: #1c2338;
  --line: #2a3350;
  --text: #e8ecf6;
  --muted: #8b95b0;
  --accent: #3b82f6;
  --green: #22c55e;
  --red: #ef4444;
  --land: #232c46;
  --land-stock: #2e4a7a;
  --land-hover: #3a5da0;
  --ocean: #10162a;
}

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

body {
  background: var(--bg);
  color: var(--text);
  font-family: "Segoe UI", system-ui, -apple-system, sans-serif;
  min-height: 100vh;
}

/* ---------- top bar ---------- */
.topbar {
  display: flex;
  align-items: center;
  gap: 24px;
  padding: 14px 24px;
  background: var(--card);
  border-bottom: 1px solid var(--line);
}
.brand { font-size: 18px; font-weight: 700; letter-spacing: 0.5px; }
.brand-mark { color: var(--accent); }
.crumbs { color: var(--muted); font-size: 13px; }
.crumbs .sep { margin: 0 6px; opacity: 0.5; }
.crumbs .here { color: var(--text); }
.topbar-actions { margin-left: auto; display: flex; gap: 10px; }

.btn {
  border: 1px solid var(--line);
  background: transparent;
  color: var(--text);
  padding: 8px 16px;
  border-radius: 8px;
  font-size: 13px;
  cursor: pointer;
}
.btn:hover { border-color: var(--accent); }
.btn-primary { background: var(--accent); border-color: var(--accent); }
.btn-primary:hover { filter: brightness(1.15); }
.btn-ghost { color: var(--muted); }
.btn-buy {
  background: var(--green);
  border-color: var(--green);
  color: #06220f;
  font-weight: 600;
  padding: 5px 12px;
}
.btn-buy[disabled] { background: var(--line); border-color: var(--line); color: var(--muted); cursor: not-allowed; }

/* ---------- layout ---------- */
.layout {
  display: grid;
  grid-template-columns: 1fr 360px;
  gap: 16px;
  padding: 16px 24px;
  height: calc(100vh - 61px);
}

.map-card {
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: 12px;
  display: flex;
  flex-direction: column;
  overflow: hidden;
}
.map-toolbar {
  display: flex;
  align-items: center;
  gap: 16px;
  padding: 12px 16px;
  border-bottom: 1px solid var(--line);
}
.map-toolbar h2 { font-size: 15px; font-weight: 600; }
.region-tabs {
  display: flex;
  gap: 4px;
  background: var(--card-2);
  border: 1px solid var(--line);
  border-radius: 9px;
  padding: 3px;
}
.region-tab {
  border: 0;
  background: transparent;
  color: var(--muted);
  font-size: 13px;
  padding: 5px 14px;
  border-radius: 7px;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  gap: 7px;
}
.region-tab img {
  width: 20px;
  height: auto;
  border-radius: 3px;
  display: block;
}
.region-tab:hover { color: var(--text); }
.region-tab.active { background: var(--accent); color: #fff; font-weight: 600; }
.region-head {
  font-size: 11px;
  font-weight: 700;
  letter-spacing: 1px;
  text-transform: uppercase;
  color: var(--muted);
  margin: 14px 0 8px;
}
.region-head:first-of-type { margin-top: 0; }
.legend { margin-left: auto; color: var(--muted); font-size: 12px; display: flex; align-items: center; gap: 6px; }
.dot { width: 10px; height: 10px; border-radius: 50%; display: inline-block; margin-left: 10px; }
.dot-green { background: var(--green); }
.dot-red { background: var(--red); }

#map { flex: 1; background: var(--ocean); position: relative; }
#map svg { display: block; }

/* map elements */
.country { fill: var(--land); stroke: var(--line); }
.country.has-data { fill: var(--land-stock); cursor: pointer; }
.country.has-data:hover { fill: var(--land-hover); }
.country.selected { fill: var(--land-hover); }

.badge-circle { stroke: var(--card); cursor: pointer; }
.badge-text { fill: #fff; font-weight: 700; text-anchor: middle; cursor: pointer; pointer-events: none; }

.city-dot { stroke: #fff; cursor: pointer; }
.city-label {
  fill: var(--text);
  paint-order: stroke;
  stroke: var(--ocean);
  font-weight: 600;
  cursor: pointer;
}
.city-count { fill: var(--muted); paint-order: stroke; stroke: var(--ocean); }

/* ---------- side panel ---------- */
.side-panel {
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: 12px;
  padding: 16px;
  overflow-y: auto;
}
.panel-loading { color: var(--muted); }
.panel-title { font-size: 15px; font-weight: 600; margin-bottom: 4px; }
.panel-sub { color: var(--muted); font-size: 12px; margin-bottom: 14px; }

.country-row {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 10px 12px;
  border: 1px solid var(--line);
  border-radius: 10px;
  margin-bottom: 8px;
  cursor: pointer;
  background: var(--card-2);
}
.country-row:hover { border-color: var(--accent); }
.country-row .flag { font-size: 22px; }
.country-row .cname { font-size: 14px; font-weight: 600; }
.country-row .cmeta { font-size: 11px; color: var(--muted); }
.count-pill {
  margin-left: auto;
  min-width: 30px;
  text-align: center;
  padding: 3px 9px;
  border-radius: 999px;
  font-size: 12px;
  font-weight: 700;
  color: #fff;
}
.pill-green { background: var(--green); }
.pill-red { background: var(--red); }

.city-block {
  border: 1px solid var(--line);
  border-radius: 10px;
  margin-bottom: 10px;
  background: var(--card-2);
  overflow: hidden;
}
.city-block.highlight { border-color: var(--accent); box-shadow: 0 0 0 1px var(--accent); }
.city-head {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 12px;
  font-weight: 600;
  font-size: 14px;
}
.isp-row {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 9px 12px;
  border-top: 1px solid var(--line);
  font-size: 13px;
}
.isp-logo {
  position: relative;
  flex: none;
  width: 28px;
  height: 28px;
  border-radius: 7px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  color: #fff;
  font-size: 13px;
  font-weight: 700;
  overflow: hidden;
}
.isp-logo img {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  padding: 3px;
  background: #fff;
  object-fit: contain;
}
.isp-name { font-weight: 600; }

/* ---------- login screen ---------- */
.login-body { overflow: hidden; }
.login-split { display: grid; grid-template-columns: 1.5fr 1fr; height: 100vh; }
.login-hero { position: relative; background: var(--ocean); overflow: hidden; }
#hero-map { position: absolute; inset: 0; }
.hero-country { fill: var(--land); stroke: var(--line); stroke-width: 0.5; }
.hero-country.lit { fill: var(--land-stock); }
.hero-dot { fill: var(--green); }
.hero-halo {
  fill: var(--green);
  opacity: 0.25;
  transform-box: fill-box;
  transform-origin: center;
  animation: pulse 2.5s ease-in-out infinite;
}
@keyframes pulse {
  0%, 100% { transform: scale(0.6); opacity: 0.35; }
  50% { transform: scale(1.15); opacity: 0.1; }
}
.hero-overlay {
  position: relative;
  z-index: 1;
  height: 100%;
  display: flex;
  flex-direction: column;
  justify-content: flex-end;
  padding: 40px 48px;
  background: linear-gradient(180deg, rgba(16,22,42,0.55) 0%, rgba(16,22,42,0.05) 40%, rgba(16,22,42,0.75) 100%);
  pointer-events: none;
}
.hero-brand { font-size: 20px; position: absolute; top: 28px; left: 48px; }
.hero-overlay h1 { font-size: 32px; line-height: 1.2; margin-bottom: 10px; }
.hero-sub { color: var(--muted); font-size: 15px; margin-bottom: 26px; }
.hero-stats { display: flex; gap: 36px; }
.stat-n { font-size: 28px; font-weight: 700; color: var(--green); }
.stat-label { color: var(--muted); font-size: 12px; text-transform: uppercase; letter-spacing: 1px; }

.login-panel {
  display: flex;
  align-items: center;
  justify-content: center;
  background: var(--card);
  border-left: 1px solid var(--line);
}
.login-card { width: 320px; }
.login-card h2 { font-size: 22px; margin-bottom: 4px; }
.login-sub { color: var(--muted); font-size: 13px; margin-bottom: 24px; }
.field { display: block; margin-bottom: 16px; }
.field span { display: block; font-size: 12px; color: var(--muted); margin-bottom: 6px; }
.field input {
  width: 100%;
  background: var(--card-2);
  border: 1px solid var(--line);
  border-radius: 8px;
  color: var(--text);
  padding: 10px 12px;
  font-size: 14px;
}
.field input:focus { outline: none; border-color: var(--accent); }
.btn-block { width: 100%; padding: 11px; font-size: 14px; font-weight: 600; }
.login-error {
  background: rgba(239, 68, 68, 0.12);
  border: 1px solid var(--red);
  color: #fca5a5;
  border-radius: 8px;
  padding: 9px 12px;
  font-size: 13px;
  margin-bottom: 14px;
}
.login-hint { color: var(--muted); font-size: 12px; margin-top: 18px; text-align: center; }
.login-hint code { color: var(--text); background: var(--card-2); padding: 1px 5px; border-radius: 4px; }

/* ---------- top-bar session widget ---------- */
.user-chip {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  font-size: 13px;
  font-weight: 600;
  padding: 7px 12px;
  background: var(--card-2);
  border: 1px solid var(--line);
  border-radius: 8px;
}
.role-badge {
  font-size: 10px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.5px;
  padding: 2px 7px;
  border-radius: 999px;
  color: #fff;
}
.role-user { background: var(--accent); }
.role-admin { background: var(--red); }

/* ---------- admin panel ---------- */
.admin-body { overflow-y: auto; }
.admin-layout { display: grid; grid-template-columns: 240px 1fr; min-height: 100vh; }
.admin-sidebar {
  background: var(--card);
  border-right: 1px solid var(--line);
  padding: 20px 0;
  position: sticky;
  top: 0;
  height: 100vh;
  overflow-y: auto;
}
.admin-brand { font-size: 18px; padding: 0 20px 18px; }
.brand-accent { color: var(--accent); }
.admin-nav { display: flex; flex-direction: column; }
.admin-nav a {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 9px 20px;
  color: var(--muted);
  font-size: 13.5px;
  cursor: pointer;
  border-left: 3px solid transparent;
}
.admin-nav a:hover { color: var(--text); background: var(--card-2); }
.admin-nav a.active {
  color: var(--text);
  background: var(--card-2);
  border-left-color: var(--accent);
  font-weight: 600;
}
.nav-ico { width: 18px; text-align: center; opacity: 0.75; }

.admin-main { display: flex; flex-direction: column; min-width: 0; }
.admin-topbar {
  display: flex;
  align-items: center;
  gap: 16px;
  padding: 12px 24px;
  background: var(--card);
  border-bottom: 1px solid var(--line);
}
.stat-pills { display: flex; flex-wrap: wrap; gap: 8px; flex: 1; justify-content: center; }
.pill {
  background: rgba(59, 130, 246, 0.15);
  border: 1px solid var(--accent);
  color: #b9d2fb;
  font-size: 12px;
  padding: 4px 12px;
  border-radius: 999px;
  white-space: nowrap;
}
.admin-profile { margin-left: auto; }
.profile-chip { display: flex; align-items: center; gap: 10px; }
.profile-avatar {
  width: 34px; height: 34px;
  border-radius: 50%;
  background: var(--accent);
  color: #fff;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  font-weight: 700;
}
.profile-name { font-size: 13px; font-weight: 600; display: flex; flex-direction: column; line-height: 1.2; }
.profile-name small { color: var(--muted); font-weight: 400; }

.admin-content { padding: 20px 24px; }
.page-head { display: flex; align-items: center; justify-content: space-between; margin-bottom: 16px; }
.page-head h2 { font-size: 17px; }

.filter-row { display: flex; gap: 16px; align-items: flex-end; margin-bottom: 14px; }
.filter span { display: block; font-size: 11.5px; color: var(--muted); margin-bottom: 5px; }
.filter select, .table-foot select {
  background: var(--card-2);
  border: 1px solid var(--line);
  color: var(--text);
  border-radius: 7px;
  padding: 8px 10px;
  font-size: 13px;
  min-width: 150px;
}
.btn-trash { margin-left: auto; font-size: 15px; padding: 8px 12px; }

.table-card {
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: 12px;
  overflow: hidden;
}
.table-tabs { display: flex; border-bottom: 1px solid var(--line); }
.ttab {
  background: transparent;
  border: 0;
  border-right: 1px solid var(--line);
  color: var(--muted);
  font-size: 12.5px;
  font-weight: 700;
  letter-spacing: 1px;
  padding: 11px 22px;
  cursor: pointer;
}
.ttab.active { color: var(--text); background: var(--card-2); box-shadow: inset 0 -2px 0 var(--accent); }

.admin-table { width: 100%; border-collapse: collapse; font-size: 13px; }
.admin-table th {
  text-align: left;
  color: var(--muted);
  font-size: 12px;
  font-weight: 600;
  padding: 12px 14px;
  border-bottom: 1px solid var(--line);
  white-space: nowrap;
}
.admin-table td { padding: 11px 14px; border-bottom: 1px solid rgba(42, 51, 80, 0.5); white-space: nowrap; }
.admin-table tbody tr:hover { background: var(--card-2); }
.mono { font-family: Consolas, monospace; font-size: 12px; }
.empty-cell { text-align: center; color: var(--muted); padding: 30px !important; }

.status-dot { display: inline-block; width: 9px; height: 9px; border-radius: 50%; margin-right: 6px; }
.dot-on { background: var(--green); }
.dot-off { background: var(--red); }
.port-b { font-size: 13px; }
.port-http { color: var(--green); }
.port-socks { color: #eab308; }
.port-both { color: var(--green); font-size: 9px; vertical-align: 2px; }
.usage-tag { font-size: 11px; font-weight: 700; letter-spacing: 0.5px; padding: 3px 10px; border-radius: 999px; }
.u-avail { background: rgba(34, 197, 94, 0.15); color: var(--green); }
.u-used { background: rgba(234, 179, 8, 0.15); color: #eab308; }

.actions-menu { position: relative; display: inline-block; }
.btn-actions { font-size: 11.5px; letter-spacing: 0.5px; padding: 6px 14px; }
.actions-drop {
  position: absolute;
  right: 0;
  top: calc(100% + 4px);
  background: var(--card-2);
  border: 1px solid var(--line);
  border-radius: 8px;
  min-width: 170px;
  z-index: 20;
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.4);
}
.actions-drop a { display: block; padding: 9px 14px; font-size: 12.5px; color: var(--text); cursor: pointer; }
.actions-drop a:hover { background: var(--card); }

.table-foot {
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: 12px;
  padding: 12px 16px;
  color: var(--muted);
  font-size: 12.5px;
}
.table-foot select { min-width: 70px; padding: 5px 8px; }
.foot-range { margin: 0 8px; }
.pg-btn {
  background: transparent;
  border: 1px solid var(--line);
  color: var(--text);
  border-radius: 6px;
  width: 30px; height: 30px;
  cursor: pointer;
}
.pg-btn:disabled { opacity: 0.35; cursor: default; }

.graph-wrap { padding: 20px; }
.graph-row { display: grid; grid-template-columns: 160px 1fr 90px; gap: 14px; align-items: center; margin-bottom: 10px; }
.graph-label { font-size: 12.5px; color: var(--muted); text-align: right; }
.graph-track { background: var(--card-2); border-radius: 6px; height: 18px; overflow: hidden; }
.graph-bar { background: linear-gradient(90deg, var(--accent), #7c3aed); height: 100%; border-radius: 6px; }
.graph-val { font-size: 12.5px; }

.placeholder-card { padding: 60px 30px; text-align: center; color: var(--muted); }
.placeholder-big { font-size: 22px; font-weight: 700; color: var(--text); margin-bottom: 8px; }

/* ---------- configuration page ---------- */
.flag-img { width: 26px; border-radius: 3px; vertical-align: -4px; }
.config-add-bar { display: flex; align-items: center; gap: 12px; margin-bottom: 16px; }
.config-add-label { color: var(--muted); font-size: 13px; }
.config-add-bar select {
  background: var(--card-2);
  border: 1px solid var(--line);
  color: var(--text);
  border-radius: 7px;
  padding: 8px 10px;
  font-size: 13px;
  min-width: 220px;
}
.config-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(330px, 1fr)); gap: 14px; }
.config-card { background: var(--card); border: 1px solid var(--line); border-radius: 12px; overflow: hidden; }
.config-card.off { opacity: 0.55; }
.config-head { display: flex; align-items: center; gap: 10px; padding: 12px 14px; border-bottom: 1px solid var(--line); }
.config-head .cname { font-weight: 600; font-size: 14px; }
.region-tag {
  font-size: 10px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.5px;
  color: var(--muted);
  border: 1px solid var(--line);
  border-radius: 999px;
  padding: 2px 8px;
}
.cstock { margin-left: auto; color: var(--muted); font-size: 12px; }
.config-isps { padding: 4px 0; }
.config-isp { display: flex; align-items: center; gap: 10px; padding: 7px 14px; }
.config-isp .isp-nm { font-size: 13px; font-weight: 600; }
.custom-tag { color: var(--muted); font-weight: 400; font-size: 10px; text-transform: uppercase; letter-spacing: 0.5px; }
.config-empty { color: var(--muted); font-size: 12.5px; }
.add-isp-row { display: flex; gap: 8px; padding: 10px 14px; border-top: 1px solid var(--line); }
.add-isp-row input {
  flex: 1;
  background: var(--card-2);
  border: 1px solid var(--line);
  border-radius: 7px;
  color: var(--text);
  padding: 7px 10px;
  font-size: 13px;
}
.add-isp-row input:focus { outline: none; border-color: var(--accent); }

.switch { margin-left: auto; flex: none; display: inline-block; }
.config-head .switch { margin-left: 12px; }
.switch input { display: none; }
.slider {
  display: inline-block;
  width: 38px;
  height: 22px;
  border-radius: 999px;
  background: var(--line);
  position: relative;
  cursor: pointer;
  transition: background 0.2s;
  vertical-align: middle;
}
.slider::after {
  content: "";
  position: absolute;
  top: 3px;
  left: 3px;
  width: 16px;
  height: 16px;
  border-radius: 50%;
  background: #fff;
  transition: left 0.2s;
}
.switch input:checked + .slider { background: var(--green); }
.switch input:checked + .slider::after { left: 19px; }
.config-isp .switch { margin-left: auto; }
.isp-del {
  background: transparent;
  border: 0;
  color: var(--muted);
  font-size: 13px;
  width: 22px;
  height: 22px;
  margin-left: 8px;
  border-radius: 5px;
  cursor: pointer;
}
.isp-del:hover { color: #fff; background: var(--red); }
.isp-del-spacer { width: 22px; margin-left: 8px; flex: none; }

/* storefront with admin sidebar (admins only) */
body.with-admin-sidebar {
  display: grid;
  grid-template-columns: 240px 1fr;
  grid-template-rows: auto 1fr;
}
body.with-admin-sidebar > .admin-sidebar { grid-row: 1 / span 2; }
body.with-admin-sidebar > .topbar { grid-column: 2; }
body.with-admin-sidebar > .layout { grid-column: 2; min-width: 0; }
.isp-type { color: var(--muted); font-size: 11px; }
.isp-right { margin-left: auto; display: flex; align-items: center; gap: 10px; }
.isp-price { color: var(--text); font-size: 13px; font-weight: 600; }
.isp-price small { color: var(--muted); font-weight: 400; }
