/* ── Reset & Base ─────────────────────────────────────────── */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

:root {
  --bg:         #0a0e1a;
  --bg2:        #111627;
  --bg3:        #161d30;
  --surface:    #1a2235;
  --surface2:   #1e2a40;
  --border:     #243050;
  --border2:    #2d3d5e;
  --text:       #d4dff0;
  --text2:      #8899bb;
  --text3:      #546280;
  --accent:     #4f8ef7;
  --accent2:    #3a6fd4;
  --accent-glow:#4f8ef740;
  --green:      #3dd68c;
  --yellow:     #f5c842;
  --red:        #f05252;
  --orange:     #f97316;
  --purple:     #a78bfa;

  --rir-AFRINIC: #FF6B35;
  --rir-APNIC:   #4ECDC4;
  --rir-ARIN:    #45B7D1;
  --rir-LACNIC:  #96CEB4;
  --rir-RIPE:    #FFEAA7;

  --sidebar-w: 300px;
  --header-h:  60px;
  --font: 'Inter', 'Segoe UI', system-ui, sans-serif;
  --mono: 'JetBrains Mono', 'Fira Code', 'Cascadia Code', monospace;
}

html, body {
  height: 100%;
  background: var(--bg);
  color: var(--text);
  font-family: var(--font);
  font-size: 14px;
  line-height: 1.5;
  overflow: hidden;
}

/* ── Scrollbar ───────────────────────────────────────────── */
::-webkit-scrollbar { width: 6px; height: 6px; }
::-webkit-scrollbar-track { background: var(--bg2); }
::-webkit-scrollbar-thumb { background: var(--border2); border-radius: 3px; }
::-webkit-scrollbar-thumb:hover { background: var(--text3); }

/* ── Layout ──────────────────────────────────────────────── */
#app { display: flex; flex-direction: column; height: 100vh; }

/* ── Header ──────────────────────────────────────────────── */
header {
  height: var(--header-h);
  background: var(--bg2);
  border-bottom: 1px solid var(--border);
  display: flex; align-items: center; gap: 12px;
  padding: 0 16px;
  flex-shrink: 0;
  z-index: 100;
}

.logo {
  display: flex; align-items: center; gap: 8px;
  font-size: 16px; font-weight: 700;
  color: var(--accent);
  white-space: nowrap;
}
.logo svg { width: 28px; height: 28px; }

.search-bar {
  flex: 1; max-width: 500px;
  position: relative;
}
.search-bar input {
  width: 100%; height: 36px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 8px;
  color: var(--text);
  font-size: 13px;
  padding: 0 12px 0 36px;
  outline: none;
  transition: border-color 0.2s, box-shadow 0.2s;
}
.search-bar input:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-glow);
}
.search-bar .search-icon {
  position: absolute; left: 10px; top: 50%; transform: translateY(-50%);
  color: var(--text3); pointer-events: none;
}
.search-results-dropdown {
  position: absolute; top: calc(100% + 4px); left: 0; right: 0;
  background: var(--surface); border: 1px solid var(--border2);
  border-radius: 8px; z-index: 200; max-height: 400px;
  overflow-y: auto; box-shadow: 0 8px 32px #0007;
}
.search-result-item {
  padding: 8px 12px; cursor: pointer;
  border-bottom: 1px solid var(--border);
  display: flex; gap: 10px; align-items: center;
}
.search-result-item:last-child { border-bottom: none; }
.search-result-item:hover { background: var(--surface2); }
.search-result-item .cidr { font-family: var(--mono); font-size: 13px; color: var(--accent); }
.search-result-item .meta { font-size: 12px; color: var(--text2); }

.header-actions {
  display: flex; align-items: center; gap: 8px; margin-left: auto;
}

.btn {
  height: 34px; padding: 0 14px;
  border: none; border-radius: 6px;
  cursor: pointer; font-size: 13px; font-weight: 500;
  display: inline-flex; align-items: center; gap: 6px;
  transition: all 0.15s;
  white-space: nowrap;
}
.btn-primary { background: var(--accent); color: #fff; }
.btn-primary:hover { background: var(--accent2); }
.btn-ghost {
  background: transparent; color: var(--text2);
  border: 1px solid var(--border);
}
.btn-ghost:hover { background: var(--surface2); color: var(--text); }
.btn-sm { height: 28px; padding: 0 10px; font-size: 12px; }
.btn:disabled { opacity: 0.5; cursor: not-allowed; }
.btn .spinner { animation: spin 0.8s linear infinite; }
.btn-select-active { background: #3dd68c20 !important; color: var(--green) !important; border-color: #3dd68c60 !important; }

@keyframes spin { to { transform: rotate(360deg); } }

.rir-pill {
  display: inline-block; padding: 2px 8px;
  border-radius: 4px; font-size: 11px; font-weight: 600;
  text-transform: uppercase; letter-spacing: 0.5px;
}
.rir-AFRINIC { background: #FF6B3520; color: var(--rir-AFRINIC); border: 1px solid #FF6B3540; }
.rir-APNIC   { background: #4ECDC420; color: var(--rir-APNIC);   border: 1px solid #4ECDC440; }
.rir-ARIN    { background: #45B7D120; color: var(--rir-ARIN);    border: 1px solid #45B7D140; }
.rir-LACNIC  { background: #96CEB420; color: var(--rir-LACNIC);  border: 1px solid #96CEB440; }
.rir-RIPE    { background: #FFEAA720; color: #d4b800;            border: 1px solid #FFEAA740; }

/* ── Main Layout ─────────────────────────────────────────── */
.main-layout {
  display: flex;
  flex: 1;
  overflow: hidden;
}

/* ── Sidebar ─────────────────────────────────────────────── */
.sidebar {
  width: var(--sidebar-w);
  background: var(--bg2);
  border-right: 1px solid var(--border);
  display: flex; flex-direction: column;
  overflow: hidden; flex-shrink: 0;
}

.sidebar-header {
  padding: 12px 14px;
  border-bottom: 1px solid var(--border);
  display: flex; align-items: center; justify-content: space-between;
}
.sidebar-title { font-size: 12px; font-weight: 600; text-transform: uppercase;
  letter-spacing: 1px; color: var(--text3); }

.sidebar-tree {
  flex: 1; overflow-y: auto; padding: 6px 0;
}

/* Tree Nodes */
.tree-node { user-select: none; }

.tree-node-header {
  display: flex; align-items: center; gap: 6px;
  padding: 6px 10px; cursor: pointer;
  border-radius: 4px; margin: 1px 6px;
  transition: background 0.1s;
}
.tree-node-header:hover { background: var(--surface); }
.tree-node-header.active { background: var(--surface2); }

.tree-toggle {
  width: 16px; height: 16px;
  display: flex; align-items: center; justify-content: center;
  color: var(--text3); transition: transform 0.2s; flex-shrink: 0;
}
.tree-toggle.open { transform: rotate(90deg); }
.tree-toggle.leaf { opacity: 0; pointer-events: none; }

.tree-dot {
  width: 8px; height: 8px; border-radius: 50%;
  flex-shrink: 0;
}

.tree-label { flex: 1; font-size: 13px; min-width: 0; }
.tree-label .name { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.tree-count {
  font-size: 11px; color: var(--text3);
  background: var(--bg3); border-radius: 3px; padding: 1px 5px;
  flex-shrink: 0;
}

.tree-children { padding-left: 18px; }
.tree-children.hidden { display: none; }

/* RIR level */
.tree-rir .tree-node-header { padding: 7px 10px; }
.tree-rir .tree-label .name { font-weight: 600; font-size: 13px; }

/* Country level */
.tree-country .tree-label .name { font-size: 12px; }

/* Allocation level (3rd level in sidebar) */
.tree-alloc .tree-node-header { padding: 3px 10px; }
.tree-alloc .tree-node-header:hover { background: var(--surface); }

/* Flag emoji */
.flag { font-size: 16px; line-height: 1; }

/* ── Content Area ─────────────────────────────────────────── */
.content {
  flex: 1;
  display: flex;
  flex-direction: column;
  overflow: hidden;
  background: var(--bg);
}

/* Tabs */
.tabs-bar {
  display: flex; align-items: center; gap: 0;
  background: var(--bg2);
  border-bottom: 1px solid var(--border);
  padding: 0 16px;
  flex-shrink: 0;
}
.tab-btn {
  height: 44px; padding: 0 16px;
  background: none; border: none; cursor: pointer;
  color: var(--text2); font-size: 13px; font-weight: 500;
  border-bottom: 2px solid transparent;
  display: flex; align-items: center; gap: 6px;
  transition: all 0.15s;
}
.tab-btn:hover { color: var(--text); }
.tab-btn.active { color: var(--accent); border-bottom-color: var(--accent); }
.tab-badge {
  min-width: 18px; height: 18px; padding: 0 5px;
  background: var(--green); color: #0a0e1a;
  border-radius: 9px; font-size: 11px; font-weight: 700;
  display: inline-flex; align-items: center; justify-content: center;
}

.tab-content { display: none; flex: 1; overflow: hidden; flex-direction: column; }
.tab-content.active { display: flex; }

/* ── Dashboard Tab ───────────────────────────────────────── */
#tab-dashboard {
  overflow-y: auto; padding: 20px;
  gap: 20px;
}

.section-title {
  font-size: 11px; font-weight: 600; text-transform: uppercase;
  letter-spacing: 1px; color: var(--text3); margin-bottom: 12px;
}

.stats-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(180px, 1fr));
  gap: 12px; margin-bottom: 20px;
}
.stat-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 10px; padding: 16px;
}
.stat-card .label { font-size: 11px; color: var(--text3); margin-bottom: 6px; }
.stat-card .value { font-size: 22px; font-weight: 700; color: var(--text); }
.stat-card .sub { font-size: 11px; color: var(--text2); margin-top: 4px; }

.rir-cards {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(250px, 1fr));
  gap: 12px;
}
.rir-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 10px; padding: 16px;
  cursor: pointer; transition: border-color 0.2s, transform 0.1s;
  position: relative; overflow: hidden;
}
.rir-card:hover { border-color: var(--border2); transform: translateY(-1px); }
.rir-card::before {
  content: ''; position: absolute; left: 0; top: 0; bottom: 0;
  width: 3px;
}
.rir-card[data-rir="AFRINIC"]::before { background: var(--rir-AFRINIC); }
.rir-card[data-rir="APNIC"]::before   { background: var(--rir-APNIC); }
.rir-card[data-rir="ARIN"]::before    { background: var(--rir-ARIN); }
.rir-card[data-rir="LACNIC"]::before  { background: var(--rir-LACNIC); }
.rir-card[data-rir="RIPE"]::before    { background: var(--rir-RIPE); }

.rir-card .rir-name { font-weight: 700; font-size: 15px; margin-bottom: 8px; }
.rir-card .rir-stats { display: grid; grid-template-columns: 1fr 1fr; gap: 6px; }
.rir-card .rs-item { }
.rir-card .rs-label { font-size: 10px; color: var(--text3); }
.rir-card .rs-val { font-size: 14px; font-weight: 600; }

.status-badge {
  display: inline-flex; align-items: center; gap: 4px;
  padding: 2px 8px; border-radius: 4px; font-size: 11px; font-weight: 500;
}
.status-done    { background: #3dd68c20; color: var(--green); }
.status-downloading, .status-parsing, .status-saving {
  background: #4f8ef720; color: var(--accent);
}
.status-error   { background: #f0525220; color: var(--red); }
.status-never   { background: var(--bg3); color: var(--text3); }

.progress-bar-wrap {
  width: 100%; height: 4px; background: var(--bg3);
  border-radius: 2px; margin-top: 8px; overflow: hidden;
}
.progress-bar { height: 100%; border-radius: 2px; transition: width 0.3s; }

/* ── Allocations Tab ─────────────────────────────────────── */
#tab-allocations { flex-direction: column; }

.alloc-controls {
  display: flex; align-items: center; gap: 8px;
  padding: 10px 16px;
  background: var(--bg2);
  border-bottom: 1px solid var(--border);
  flex-wrap: wrap;
}

select {
  height: 32px; padding: 0 8px;
  background: var(--surface); border: 1px solid var(--border);
  border-radius: 6px; color: var(--text); font-size: 13px; outline: none;
  cursor: pointer;
}
select:focus { border-color: var(--accent); }

.alloc-info {
  margin-left: auto; font-size: 12px; color: var(--text3);
}

.table-wrap { flex: 1; overflow: auto; }

table {
  width: 100%; border-collapse: collapse;
  font-size: 13px;
}
thead th {
  position: sticky; top: 0;
  background: var(--bg2);
  border-bottom: 1px solid var(--border);
  padding: 10px 12px;
  text-align: left; font-weight: 600;
  color: var(--text2); white-space: nowrap;
  cursor: pointer; user-select: none;
}
thead th:hover { color: var(--text); }
thead th.sort-asc::after  { content: ' ↑'; color: var(--accent); }
thead th.sort-desc::after { content: ' ↓'; color: var(--accent); }

tbody tr {
  border-bottom: 1px solid var(--border);
  cursor: pointer;
  transition: background 0.1s;
}
tbody tr:hover { background: var(--surface); }
tbody tr.selected { background: var(--surface2) !important; }

td { padding: 8px 12px; vertical-align: middle; }
td.mono { font-family: var(--mono); font-size: 12px; }
td.cidr { color: var(--accent); font-family: var(--mono); }

.flag-cc {
  display: flex; align-items: center; gap: 6px;
}

.pagination {
  display: flex; align-items: center; gap: 8px; justify-content: center;
  padding: 12px; border-top: 1px solid var(--border);
  background: var(--bg2);
}
.page-info { font-size: 12px; color: var(--text3); }

/* ── Tree Viz Tab ────────────────────────────────────────── */
#tab-tree {
  overflow: hidden;
}

#tree-viz-container {
  flex: 1; overflow: hidden; position: relative;
  background: radial-gradient(ellipse at center, #141928 0%, #0a0e1a 100%);
}

#tree-viz-container svg {
  width: 100%; height: 100%;
}

.tree-tooltip {
  position: absolute; pointer-events: none;
  background: var(--surface);
  border: 1px solid var(--border2);
  border-radius: 8px;
  padding: 10px 14px;
  font-size: 13px;
  box-shadow: 0 4px 20px #0008;
  max-width: 260px;
  z-index: 300;
}
.tree-tooltip .tt-title { font-weight: 600; margin-bottom: 4px; }
.tree-tooltip .tt-row { display: flex; gap: 8px; font-size: 12px; color: var(--text2); }
.tree-tooltip .tt-val { color: var(--text); }

#tree-controls {
  position: absolute; bottom: 16px; right: 16px;
  display: flex; gap: 6px; flex-direction: column;
}

/* ── Detail Panel ────────────────────────────────────────── */
.detail-panel {
  width: 400px; flex-shrink: 0;
  background: var(--bg2);
  border-left: 1px solid var(--border);
  display: flex; flex-direction: column;
  overflow: hidden;
  transition: width 0.2s;
}
.detail-panel.hidden { width: 0; overflow: hidden; }

.detail-header {
  padding: 14px 16px;
  border-bottom: 1px solid var(--border);
  display: flex; align-items: center; gap: 10px;
}
.detail-header .cidr-big {
  font-family: var(--mono); font-size: 16px; font-weight: 700; color: var(--accent);
  flex: 1;
}
.detail-close {
  background: none; border: none; cursor: pointer;
  color: var(--text3); padding: 4px;
  border-radius: 4px; transition: all 0.1s;
}
.detail-close:hover { background: var(--surface); color: var(--text); }

.detail-body { flex: 1; overflow-y: auto; padding: 16px; }

.detail-section { margin-bottom: 20px; }
.detail-section-title {
  font-size: 10px; font-weight: 600; text-transform: uppercase;
  letter-spacing: 1px; color: var(--text3); margin-bottom: 10px;
  padding-bottom: 6px; border-bottom: 1px solid var(--border);
}

.detail-row {
  display: flex; gap: 8px; margin-bottom: 8px;
  align-items: flex-start;
}
.detail-row .dk {
  width: 110px; flex-shrink: 0;
  font-size: 12px; color: var(--text3);
}
.detail-row .dv {
  flex: 1; font-size: 13px; word-break: break-all;
}
.detail-row .dv.mono { font-family: var(--mono); font-size: 12px; }
.detail-row .dv a { color: var(--accent); text-decoration: none; }
.detail-row .dv a:hover { text-decoration: underline; }

.rdap-loader {
  text-align: center; padding: 20px;
  color: var(--text3); font-size: 13px;
}
.rdap-raw {
  background: var(--bg3); border: 1px solid var(--border);
  border-radius: 6px; padding: 10px;
  font-family: var(--mono); font-size: 11px;
  overflow-x: auto; white-space: pre;
  color: var(--text2); max-height: 300px; overflow-y: auto;
}

/* ── Country map hint ────────────────────────────────────── */
.country-chip {
  display: inline-flex; align-items: center; gap: 4px;
  padding: 2px 8px; border-radius: 4px;
  background: var(--surface2); font-size: 12px;
  cursor: pointer;
}
.country-chip:hover { background: var(--border); }

/* ── Toast notifications ─────────────────────────────────── */
#toast-container {
  position: fixed; bottom: 20px; right: 20px;
  display: flex; flex-direction: column; gap: 8px;
  z-index: 9999;
}
.toast {
  background: var(--surface);
  border: 1px solid var(--border2);
  border-radius: 8px; padding: 10px 16px;
  box-shadow: 0 4px 16px #0005;
  font-size: 13px; max-width: 320px;
  animation: toast-in 0.2s ease;
}
.toast.success { border-left: 3px solid var(--green); }
.toast.error   { border-left: 3px solid var(--red); }
.toast.info    { border-left: 3px solid var(--accent); }
@keyframes toast-in { from { opacity:0; transform:translateX(20px); } to { opacity:1; transform:none; } }

/* ── Empty state ─────────────────────────────────────────── */
.empty-state {
  display: flex; flex-direction: column;
  align-items: center; justify-content: center;
  flex: 1; padding: 40px;
  color: var(--text3); text-align: center;
  gap: 12px;
}
.empty-state svg { opacity: 0.3; }
.empty-state h3 { font-size: 16px; color: var(--text2); }
.empty-state p { font-size: 13px; max-width: 280px; }

/* ── Loading overlay ─────────────────────────────────────── */
.loading-dots::after {
  content: ''; animation: dots 1.5s infinite;
}
@keyframes dots {
  0%   { content: '.'; }
  33%  { content: '..'; }
  66%  { content: '...'; }
}

/* ── Misc ────────────────────────────────────────────────── */
.tag {
  display: inline-block; padding: 1px 6px;
  border-radius: 3px; font-size: 11px;
  background: var(--surface2); color: var(--text2);
}
.tag.allocated { background: #3dd68c20; color: var(--green); }
.tag.assigned  { background: #4f8ef720; color: var(--accent); }
.tag.reserved  { background: #f9731620; color: var(--orange); }

.num { font-family: var(--mono); font-size: 12px; }

.flex-gap { display:flex; align-items:center; gap:8px; }

/* ── RDAP Sync Tab ───────────────────────────────────────── */
.rdap-bar-wrap {
  width: 100%; height: 6px; background: var(--bg3);
  border-radius: 3px; overflow: hidden;
}
.rdap-bar {
  height: 100%; border-radius: 3px;
  transition: width 0.4s ease;
}
.rdap-overall-pct {
  margin-left: 10px; font-weight: 700; color: var(--accent);
}
.rdap-done-btn { color: var(--green) !important; border-color: #3dd68c30 !important; }

/* ── Owner / date cells ──────────────────────────────────── */
.owner-cell { max-width: 180px; }
.owner-name {
  font-size: 12px; color: var(--text);
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
  display: block; max-width: 180px;
}
.date-cell { color: var(--text3); font-family: var(--mono); font-size: 12px; white-space: nowrap; }

/* ── AS pills & handle cells ─────────────────────────────── */
.as-pill {
  display: inline-block; padding: 1px 5px;
  border-radius: 3px; font-size: 10px; font-family: var(--mono);
  background: #a78bfa20; color: var(--purple);
  border: 1px solid #a78bfa30; margin-right: 2px;
}
.mono-small {
  font-family: var(--mono); font-size: 11px; color: var(--text2);
}
.handle-as-cell {
  max-width: 160px; white-space: nowrap;
  overflow: hidden; text-overflow: ellipsis;
}

/* ── Command Space ───────────────────────────────────────── */
.command-space {
  flex-shrink: 0;
  background: var(--bg2);
  border-top: 1px solid var(--border);
  padding: 10px 16px 12px;
  display: flex; flex-direction: column; gap: 8px;
  width: 100%; box-sizing: border-box;
}

.cmd-topbar {
  display: flex; align-items: center; gap: 8px;
}

.cmd-title {
  font-size: 10px; font-weight: 700; text-transform: uppercase;
  letter-spacing: 1.2px; color: var(--accent);
  white-space: nowrap; flex-shrink: 0;
}

.cmd-result-info {
  font-size: 12px; color: var(--green); white-space: nowrap;
}

.cmd-hint {
  margin-left: auto;
  font-size: 11px; color: var(--text3); white-space: nowrap;
  font-family: var(--mono);
}

.cmd-input-wrap {
  display: flex; align-items: flex-start; gap: 10px;
  width: 100%; box-sizing: border-box;
  background: var(--surface);
  border: 1px solid var(--border2);
  border-radius: 8px;
  padding: 12px 14px;
  transition: border-color 0.2s, box-shadow 0.2s;
}
.cmd-input-wrap:focus-within {
  border-color: var(--accent);
  box-shadow: 0 0 0 2px var(--accent-glow);
}
.cmd-input-wrap.cmd-running {
  border-color: var(--accent);
}

#cmd-input {
  flex: 1; min-width: 0;
  background: none; border: none; outline: none; resize: none;
  color: var(--text); font-size: 15px; line-height: 1.6;
  font-family: var(--mono);
  padding: 0;
}
#cmd-input::placeholder {
  color: var(--text3); font-family: var(--font);
  font-size: 14px; line-height: 1.6;
}

.cmd-input-wrap .btn {
  flex-shrink: 0; align-self: flex-end;
  height: 36px; padding: 0 18px;
}

/* ── Tree node labels ────────────────────────────────────── */
.node-label { pointer-events: none; }

/* ── Login Overlay ───────────────────────────────────────── */
#login-overlay {
  position: fixed; inset: 0; z-index: 10000;
  background: var(--bg);
  display: flex; align-items: center; justify-content: center;
}

.login-card {
  width: 380px;
  background: var(--surface);
  border: 1px solid var(--border2);
  border-radius: 16px;
  padding: 36px 32px 32px;
  box-shadow: 0 16px 64px #0009;
  display: flex; flex-direction: column; gap: 24px;
}

.login-logo {
  display: flex; flex-direction: column; align-items: center; gap: 8px;
}

.login-brand {
  font-size: 26px; font-weight: 700; letter-spacing: -0.5px;
  color: var(--text);
}

.login-subtitle {
  font-size: 12px; color: var(--text3); letter-spacing: 0.5px;
}

.login-form {
  display: flex; flex-direction: column; gap: 16px;
}

.login-field {
  display: flex; flex-direction: column; gap: 6px;
}

.login-field label {
  font-size: 12px; font-weight: 600; color: var(--text2);
  text-transform: uppercase; letter-spacing: 0.6px;
}

.login-field input {
  background: var(--bg2);
  border: 1px solid var(--border2);
  border-radius: 8px;
  padding: 11px 14px;
  color: var(--text);
  font-size: 14px;
  font-family: var(--font);
  outline: none;
  transition: border-color 0.2s, box-shadow 0.2s;
}

.login-field input:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 2px var(--accent-glow);
}

.login-error {
  background: #f0525220;
  border: 1px solid #f0525240;
  border-radius: 7px;
  padding: 9px 12px;
  font-size: 13px;
  color: var(--red);
}

.login-btn {
  width: 100%; height: 44px; font-size: 15px; font-weight: 600;
  border-radius: 9px; margin-top: 4px;
}

/* ── Header user info ────────────────────────────────────── */
.header-user {
  display: flex; align-items: center; gap: 8px;
  padding: 0 12px 0 10px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 8px;
  height: 32px;
  font-size: 13px; color: var(--text2);
}

/* ── User Management Tab ─────────────────────────────────── */
.user-table {
  width: 100%; border-collapse: collapse; font-size: 13px;
}
.user-table th {
  background: var(--bg2); color: var(--text3);
  font-size: 11px; font-weight: 600; text-transform: uppercase;
  letter-spacing: 0.6px; padding: 10px 14px; text-align: left;
  border-bottom: 1px solid var(--border);
  position: sticky; top: 0;
}
.user-table td {
  padding: 10px 14px; border-bottom: 1px solid var(--border);
  color: var(--text);
}
.user-table tr:hover td { background: var(--surface); }
.user-actions { display: flex; gap: 6px; align-items: center; }

.role-badge {
  display: inline-block; padding: 2px 8px; border-radius: 4px;
  font-size: 11px; font-weight: 600; text-transform: uppercase; letter-spacing: 0.5px;
}
.role-admin { background: #4f8ef720; color: var(--accent); border: 1px solid #4f8ef740; }
.role-user  { background: var(--surface2); color: var(--text2); border: 1px solid var(--border); }

.btn-danger { color: var(--red) !important; }
.btn-danger:hover { background: #f0525215 !important; border-color: #f0525240 !important; }

.text-muted { color: var(--text3); font-size: 12px; }

/* ── Modals ──────────────────────────────────────────────── */
.modal-overlay {
  position: fixed; inset: 0; z-index: 8000;
  background: #0008; backdrop-filter: blur(2px);
}

.modal-box {
  position: fixed; z-index: 8001;
  top: 50%; left: 50%; transform: translate(-50%, -50%);
  width: 420px; max-width: calc(100vw - 32px);
  background: var(--surface);
  border: 1px solid var(--border2);
  border-radius: 14px;
  box-shadow: 0 16px 64px #0009;
  display: flex; flex-direction: column;
  overflow: hidden;
}

.modal-header {
  display: flex; align-items: center; justify-content: space-between;
  padding: 16px 20px;
  border-bottom: 1px solid var(--border);
  font-weight: 600; font-size: 15px; color: var(--text);
}

.modal-body {
  padding: 20px;
}

.modal-field {
  display: flex; flex-direction: column; gap: 6px; margin-bottom: 14px;
}
.modal-field label {
  font-size: 12px; font-weight: 600; color: var(--text2);
  text-transform: uppercase; letter-spacing: 0.6px;
}
.modal-field input,
.modal-field select {
  background: var(--bg2); border: 1px solid var(--border2);
  border-radius: 8px; padding: 10px 12px;
  color: var(--text); font-size: 14px; font-family: var(--font);
  outline: none;
}
.modal-field input:focus,
.modal-field select:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 2px var(--accent-glow);
}
.modal-error {
  background: #f0525220; border: 1px solid #f0525240;
  border-radius: 7px; padding: 8px 12px;
  font-size: 12px; color: var(--red); margin-bottom: 12px;
}
.modal-actions {
  display: flex; justify-content: flex-end; gap: 8px; margin-top: 4px;
}

/* ── Admin-only elements hidden by default ───────────────── */
.admin-only { display: none; }

/* ── Group-by-Handle table ───────────────────────────────── */
.handle-table {
  width: 100%; border-collapse: collapse; font-size: 13px;
}
.handle-table th {
  background: var(--bg2); color: var(--text3);
  font-size: 11px; font-weight: 600; text-transform: uppercase;
  letter-spacing: 0.6px; padding: 10px 14px; text-align: left;
  border-bottom: 1px solid var(--border);
  position: sticky; top: 0; user-select: none;
}
.handle-table th[data-hsort]:hover { color: var(--text); }
.handle-table td {
  padding: 9px 14px; border-bottom: 1px solid var(--border); color: var(--text);
}
.handle-table tbody tr:hover td { background: var(--surface); cursor: pointer; }
.handle-badge {
  background: #4f8ef715; border: 1px solid #4f8ef730;
  padding: 2px 7px; border-radius: 5px; color: var(--accent);
  font-size: 12px;
}
.flag-cluster { font-size: 18px; letter-spacing: 2px; }

/* "Group by Handle" button active state */
#btn-group-handle.active {
  background: var(--accent);
  color: #fff;
  border-color: var(--accent2);
}
#btn-group-handle.active:hover { background: var(--accent2); }

/* Handle filter breadcrumb pill */
.handle-filter-pill {
  display: inline-flex; align-items: center; gap: 6px;
  background: #4f8ef720; border: 1px solid #4f8ef740;
  border-radius: 6px; padding: 2px 8px;
  font-size: 12px; color: var(--accent);
}
.handle-filter-clear {
  background: none; border: none; cursor: pointer; color: var(--text3);
  font-size: 11px; padding: 0; line-height: 1;
}
.handle-filter-clear:hover { color: var(--red); }

.handle-back-btn {
  color: var(--accent) !important;
  border-color: #4f8ef730 !important;
  font-weight: 500;
}
.handle-back-btn:hover { background: #4f8ef715 !important; }

/* Divider in controls bar */
.controls-divider {
  width: 1px; height: 22px; background: var(--border); flex-shrink: 0;
}

/* ── Handle hover tooltip ────────────────────────────────── */
#handle-tooltip {
  position: fixed; pointer-events: none; z-index: 9500;
  background: var(--surface);
  border: 1px solid var(--border2);
  border-radius: 10px;
  padding: 14px 16px;
  min-width: 260px; max-width: 360px;
  box-shadow: 0 8px 32px #0009;
  font-size: 13px;
  line-height: 1.5;
}
#handle-tooltip .ht-handle {
  font-family: var(--mono); font-size: 13px; font-weight: 700;
  color: var(--accent); margin-bottom: 10px;
  padding-bottom: 8px; border-bottom: 1px solid var(--border);
}
#handle-tooltip .ht-row {
  display: flex; justify-content: space-between; align-items: baseline;
  gap: 12px; margin-bottom: 5px;
}
#handle-tooltip .ht-label {
  color: var(--text3); font-size: 11px; font-weight: 600;
  text-transform: uppercase; letter-spacing: 0.5px; white-space: nowrap;
}
#handle-tooltip .ht-val {
  color: var(--text); text-align: right; word-break: break-word;
}
#handle-tooltip .ht-flags {
  font-size: 18px; letter-spacing: 1px; line-height: 1.3;
}
#handle-tooltip hr.ht-divider {
  border: none; border-top: 1px solid var(--border); margin: 8px 0;
}
#handle-tooltip .ht-rirs {
  display: flex; gap: 4px; flex-wrap: wrap; justify-content: flex-end;
}

/* Responsive */
@media (max-width: 900px) {
  :root { --sidebar-w: 240px; }
  .detail-panel { width: 340px; }
}
@media (max-width: 680px) {
  .sidebar { display: none; }
  .detail-panel { display: none; }
}

/* ── Selected Tab ────────────────────────────────────────── */
.sel-sections {
  overflow-y: auto; padding: 12px 16px; display: flex; flex-direction: column; gap: 12px;
}
.sel-country-section {
  background: var(--surface); border: 1px solid var(--border); border-radius: 8px; overflow: hidden;
}
.sel-country-header {
  display: flex; align-items: center; gap: 10px;
  padding: 8px 14px;
  background: var(--bg3); border-bottom: 1px solid var(--border);
  font-weight: 600;
}
.sel-country-flag { font-size: 20px; line-height: 1; }
.sel-country-code { font-size: 14px; color: var(--text); }
.sel-country-count {
  min-width: 22px; height: 22px; padding: 0 6px;
  background: var(--accent); color: #fff;
  border-radius: 11px; font-size: 11px; font-weight: 700;
  display: inline-flex; align-items: center; justify-content: center;
  margin-left: 4px;
}
.sel-country-table { width: 100%; }
.sel-country-table thead th {
  background: var(--bg2); padding: 6px 10px; font-size: 11px; color: var(--text3);
  text-transform: uppercase; letter-spacing: 0.5px; border-bottom: 1px solid var(--border);
}
.sel-country-table tbody tr { cursor: pointer; transition: background 0.12s; }
.sel-country-table tbody tr:hover { background: var(--surface2); }
.sel-country-table tbody td { padding: 6px 10px; font-size: 12px; border-bottom: 1px solid var(--border); }
.sel-country-table tbody tr:last-child td { border-bottom: none; }
