:root {
  --bg: #0f1419;
  --card: #1a2332;
  --border: #2a3544;
  --text: #e7ecf3;
  --muted: #8b9cb3;
  --accent: #3b82f6;
  --accent-hover: #2563eb;
  --ok: #22c55e;
  --warn: #f59e0b;
  --error: #ef4444;
  --radius: 10px;
  font-family: "Segoe UI", system-ui, -apple-system, sans-serif;
}

* { box-sizing: border-box; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  min-height: 100vh;
}

a { color: var(--accent); text-decoration: none; }

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 1rem 1.5rem;
  border-bottom: 1px solid var(--border);
  background: #121a24;
  position: sticky;
  top: 0;
  z-index: 10;
}

.brand { font-size: 1.25rem; font-weight: 700; }
.badge {
  font-size: .7rem;
  background: var(--accent);
  color: #fff;
  padding: .15rem .45rem;
  border-radius: 4px;
  vertical-align: middle;
  margin-left: .4rem;
}

.container { max-width: 1200px; margin: 0 auto; padding: 1.5rem; }

.card {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 1.25rem;
  margin-bottom: 1.25rem;
}

.card-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 1rem;
}
.card-header h2 { margin: 0; font-size: 1.1rem; }

.stats-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(160px, 1fr));
  gap: 1rem;
  margin-bottom: 1rem;
}

.stat-label { color: var(--muted); font-size: .85rem; }
.stat-value { font-size: 2rem; font-weight: 700; margin-top: .25rem; }

.grid-2 {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 1.25rem;
}
@media (max-width: 800px) {
  .grid-2 { grid-template-columns: 1fr; }
}

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  border: none;
  border-radius: 8px;
  padding: .55rem 1rem;
  font-size: .9rem;
  cursor: pointer;
  text-decoration: none;
  color: inherit;
}
.btn-primary { background: var(--accent); color: #fff; }
.btn-primary:hover:not(:disabled) { background: var(--accent-hover); }
.btn-primary:disabled { opacity: .6; cursor: wait; }
.btn-ghost { background: transparent; border: 1px solid var(--border); }
.btn-ghost:hover { background: #243044; }
.btn-sm { padding: .35rem .65rem; font-size: .8rem; }

.banner {
  padding: .85rem 1rem;
  border-radius: var(--radius);
  margin-bottom: 1.25rem;
  border: 1px solid var(--border);
}
.banner-ok { background: #132419; border-color: #1f4a32; }
.banner-info { background: #152033; border-color: #2a4a7a; }
.banner-error { background: #2a1515; border-color: #6b2222; color: #fecaca; }

.table-wrap { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; font-size: .9rem; }
th, td { text-align: left; padding: .6rem .5rem; border-bottom: 1px solid var(--border); }
th { color: var(--muted); font-weight: 600; }

.url-input {
  width: 100%;
  min-width: 220px;
  background: #0f1419;
  border: 1px solid var(--border);
  color: var(--text);
  border-radius: 6px;
  padding: .4rem .5rem;
  font-size: .8rem;
}

.tag {
  display: inline-block;
  background: #243044;
  color: var(--muted);
  font-size: .75rem;
  padding: .15rem .4rem;
  border-radius: 4px;
}
.tag-warn { background: #3d2e14; color: #fcd34d; }
.tag-ok { background: #132419; color: #86efac; }
.tag-error { background: #3d1515; color: #fca5a5; }

.header-btns { display: flex; gap: .5rem; flex-wrap: wrap; }
.actions-cell { white-space: nowrap; }
.actions-cell .btn { margin: .1rem; }
.sub-links-cell { min-width: 200px; }
.sub-link-row {
  display: flex;
  align-items: center;
  gap: .25rem;
  margin-bottom: .3rem;
}
.sub-link-row:last-child { margin-bottom: 0; }
.sub-link-type {
  display: inline-block;
  width: 3.5rem;
  font-size: .75rem;
  font-weight: 600;
  color: var(--muted);
}
.qr-modal-card { text-align: center; max-width: 360px; }
.qr-canvas-wrap {
  display: flex;
  justify-content: center;
  margin: 1rem 0;
  padding: .75rem;
  background: #fff;
  border-radius: 10px;
}
.qr-modal-url {
  word-break: break-all;
  text-align: left;
  margin-bottom: 1rem;
  max-height: 4.5rem;
  overflow-y: auto;
}
.btn-danger:hover { border-color: #7f1d1d; color: #fca5a5; }

.modal { position: fixed; inset: 0; z-index: 50; display: flex; align-items: center; justify-content: center; }
.modal.hidden { display: none; }
.modal-backdrop { position: absolute; inset: 0; background: rgba(0,0,0,.6); }
.modal-card { position: relative; width: 100%; max-width: 420px; margin: 1rem; z-index: 1; }
.modal-card h3 { margin: 0 0 1rem; }

.section-hint { margin: 0 0 1rem; font-size: .9rem; }

.settings-form { margin-top: .5rem; }
.form-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
  gap: 1rem 1.25rem;
}
.form-group-wide { grid-column: 1 / -1; }
.form-group label { display: block; margin-bottom: .35rem; font-size: .9rem; color: var(--text); }
.form-group input[type="text"],
.form-group input[type="number"] {
  width: 100%;
  padding: .55rem .65rem;
  border-radius: 8px;
  border: 1px solid var(--border);
  background: #0f1419;
  color: var(--text);
  font-size: .9rem;
}
.form-group .hint { display: block; margin-top: .25rem; font-size: .75rem; color: var(--muted); }
.checkbox-group { display: flex; align-items: center; }
.checkbox-label {
  display: flex;
  align-items: center;
  gap: .5rem;
  cursor: pointer;
  font-size: .9rem;
}
.form-actions {
  display: flex;
  flex-wrap: wrap;
  gap: .75rem;
  margin-top: 1.25rem;
  padding-top: 1rem;
  border-top: 1px solid var(--border);
}

.muted { color: var(--muted); }
.small { font-size: .8rem; word-break: break-all; }

.source-list { list-style: none; padding: 0; margin: 0; }
.source-list li { padding: .65rem 0; border-bottom: 1px solid var(--border); }
.source-list li:last-child { border-bottom: none; }

.settings-dl { display: grid; grid-template-columns: 140px 1fr; gap: .5rem .75rem; margin: 0; }
.settings-dl dt { color: var(--muted); }
.settings-dl dd { margin: 0; word-break: break-all; }

.login-wrap {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 1rem;
}
.login-card { width: 100%; max-width: 380px; }
.login-card h1 { margin: 0 0 .25rem; }
.login-card label { display: block; margin: 1rem 0 .35rem; color: var(--muted); font-size: .9rem; }
.login-card input {
  width: 100%;
  padding: .65rem .75rem;
  border-radius: 8px;
  border: 1px solid var(--border);
  background: #0f1419;
  color: var(--text);
}
.login-card button { width: 100%; margin-top: 1rem; }

.alert { padding: .65rem .75rem; border-radius: 8px; margin: .75rem 0; }
.alert-error { background: #2a1515; color: #fecaca; border: 1px solid #6b2222; }

code { background: #0f1419; padding: .1rem .3rem; border-radius: 4px; font-size: .85em; }

.toast {
  position: fixed;
  bottom: 1.5rem;
  right: 1.5rem;
  background: #1f2937;
  border: 1px solid var(--border);
  padding: .75rem 1rem;
  border-radius: 8px;
  opacity: 0;
  transition: opacity .2s;
  z-index: 100;
}
.toast.show { opacity: 1; }

/* Tabs */
.tabs {
  display: flex;
  gap: .25rem;
  padding: .5rem 1.5rem;
  background: #121a24;
  border-bottom: 1px solid var(--border);
  overflow-x: auto;
  position: sticky;
  top: 57px;
  z-index: 9;
}
.tab {
  background: transparent;
  border: none;
  color: var(--muted);
  padding: .55rem 1rem;
  border-radius: 8px;
  cursor: pointer;
  font-size: .9rem;
  white-space: nowrap;
}
.tab:hover { color: var(--text); background: #1a2332; }
.tab.active { color: #fff; background: var(--accent); }

.tab-panel { display: none; }
.tab-panel.active { display: block; }

.group-cards {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(280px, 1fr));
  gap: 1rem;
}
.group-card { margin-bottom: 0; }
.group-card-head { display: flex; gap: .75rem; align-items: flex-start; margin-bottom: .75rem; }
.group-card-head h3 { margin: 0; font-size: 1rem; }
.group-dot {
  width: 10px; height: 10px; border-radius: 50%; flex-shrink: 0; margin-top: .35rem;
}
.group-dot.lg { width: 14px; height: 14px; margin-top: .25rem; }
.group-meta {
  display: grid;
  grid-template-columns: auto 1fr;
  gap: .25rem .75rem;
  font-size: .85rem;
  margin: 0 0 .75rem;
}
.group-meta dt { color: var(--muted); margin: 0; }
.group-meta dd { margin: 0; }
.group-card-actions { display: flex; flex-wrap: wrap; gap: .35rem; }
.group-summary-list { list-style: none; padding: 0; margin: 0; }
.group-summary-list li { padding: .5rem 0; border-bottom: 1px solid var(--border); display: flex; align-items: center; gap: .5rem; flex-wrap: wrap; }
.group-summary-list li:last-child { border-bottom: none; }
.quick-actions { display: flex; flex-direction: column; gap: .5rem; align-items: flex-start; }

.server-cards {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(320px, 1fr));
  gap: 1rem;
}
.server-card { margin: 0; border-left: 3px solid var(--srv-color, var(--accent)); }
.server-card-head { display: flex; gap: .75rem; align-items: flex-start; margin-bottom: .75rem; }
.server-card-title { flex: 1; min-width: 0; }
.server-card-title h3 { margin: 0; font-size: 1rem; }
.server-meta {
  display: grid;
  grid-template-columns: auto 1fr;
  gap: .25rem .75rem;
  font-size: .875rem;
  margin: 0 0 .75rem;
}
.server-meta dt { color: var(--muted); margin: 0; }
.server-meta dd { margin: 0; word-break: break-all; }
.load-bar-wrap { margin: .5rem 0; }
.load-bar {
  height: 6px;
  background: var(--border);
  border-radius: 3px;
  overflow: hidden;
  margin-bottom: .2rem;
}
.load-bar-fill { height: 100%; background: var(--accent); border-radius: 3px; }
.load-bar-alt .load-bar-fill { background: #8b5cf6; }
.server-card-actions { display: flex; flex-wrap: wrap; gap: .35rem; margin-top: .75rem; }
.server-users-details, .server-inbounds-details { margin-top: .5rem; font-size: .875rem; }
.server-users-list { list-style: none; padding: 0; margin: .5rem 0 0; }
.server-users-list li { padding: .35rem 0; border-bottom: 1px solid var(--border); display: flex; justify-content: space-between; gap: .5rem; }
.tag-health-ok { background: rgba(34,197,94,.15); color: #86efac; }
.tag-health-overloaded { background: rgba(239,68,68,.15); color: #fca5a5; }
.tag-health-panel_down, .tag-health-no_alive_inbounds { background: rgba(239,68,68,.12); color: #fca5a5; }
.tag-health-disabled { background: rgba(148,163,184,.15); color: #94a3b8; }
.tag-health-no_inventory, .tag-health-unknown { background: rgba(234,179,8,.12); color: #fcd34d; }

.analytics-summary .stat-value-sm { font-size: 1.05rem; line-height: 1.35; }
.analytics-table { width: 100%; font-size: .85rem; }
.analytics-table th { text-align: left; white-space: nowrap; }
.analytics-table td { vertical-align: top; padding: .55rem .4rem; }
.score-pill {
  display: inline-block;
  min-width: 2.5rem;
  text-align: center;
  padding: .15rem .45rem;
  border-radius: 999px;
  font-weight: 600;
  font-size: .8rem;
}
.score-high { background: rgba(34,197,94,.18); color: #86efac; }
.score-mid { background: rgba(234,179,8,.15); color: #fcd34d; }
.score-low { background: rgba(239,68,68,.15); color: #fca5a5; }
.tag-trend-growing { background: rgba(59,130,246,.15); color: #93c5fd; }
.tag-trend-declining { background: rgba(148,163,184,.15); color: #94a3b8; }
.tag-trend-stable { background: rgba(34,197,94,.12); color: #86efac; }
.tag-trend-unknown { background: rgba(148,163,184,.1); color: #94a3b8; }
.load-rank-list { list-style: none; padding: 0; margin: 0; }
.load-rank-list li {
  display: flex;
  gap: .75rem;
  padding: .65rem 0;
  border-bottom: 1px solid var(--border);
}
.load-rank-list li:last-child { border-bottom: none; }
.load-rank-pos {
  width: 1.5rem;
  height: 1.5rem;
  border-radius: 50%;
  background: var(--border);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: .75rem;
  flex-shrink: 0;
}
.load-rank-body { flex: 1; min-width: 0; }
.load-rank-body .load-bar { margin: .35rem 0; }

.private-check-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 1.25rem;
}
@media (max-width: 768px) {
  .private-check-grid { grid-template-columns: 1fr; }
}
.private-check-title {
  font-size: .95rem;
  margin: 0 0 .75rem;
  padding-bottom: .35rem;
  border-bottom: 2px solid var(--border);
}
.private-check-title.ok { border-color: #22c55e; color: #86efac; }
.private-check-title.dead { border-color: #ef4444; color: #fca5a5; }
.private-check-title.warn { border-color: #eab308; color: #fcd34d; }
.private-check-list {
  list-style: none;
  padding: 0;
  margin: 0;
  max-height: 360px;
  overflow-y: auto;
}
.private-check-item {
  padding: .5rem .65rem;
  margin-bottom: .35rem;
  border-radius: 6px;
  background: var(--surface);
  border: 1px solid var(--border);
  font-size: .85rem;
}
.private-check-item.alive { border-left: 3px solid #22c55e; }
.private-check-item.dead { border-left: 3px solid #ef4444; }
.private-check-label { font-weight: 500; word-break: break-all; }
.private-check-meta { margin-top: .2rem; }

.checkbox-list { display: flex; flex-direction: column; gap: .35rem; max-height: 160px; overflow-y: auto; padding: .5rem; border: 1px solid var(--border); border-radius: 8px; background: #0a0e14; }
.checkbox-row { display: flex; align-items: center; gap: .5rem; font-size: .875rem; cursor: pointer; }
.checkbox-row input { flex-shrink: 0; }

.group-pill {
  display: inline-block;
  font-size: .75rem;
  padding: .15rem .45rem;
  border-radius: 4px;
  background: color-mix(in srgb, var(--c, #3b82f6) 25%, transparent);
  border: 1px solid var(--c, #3b82f6);
}
.filter-select {
  padding: .35rem .5rem;
  border-radius: 6px;
  border: 1px solid var(--border);
  background: #0f1419;
  color: var(--text);
  font-size: .85rem;
}
.modal-wide { max-width: 520px; }
.code-area {
  width: 100%;
  font-family: ui-monospace, Consolas, monospace;
  font-size: .8rem;
  padding: .75rem;
  border-radius: 8px;
  border: 1px solid var(--border);
  background: #0a0e14;
  color: #a8d4a8;
  resize: vertical;
}
.form-group textarea,
.form-group select {
  width: 100%;
  padding: .55rem .65rem;
  border-radius: 8px;
  border: 1px solid var(--border);
  background: #0f1419;
  color: var(--text);
  font-size: .9rem;
}
