:root {
  --bg: #060912;
  --bg-2: #0a0e18;
  --card: rgba(20, 26, 36, 0.78);
  --card-2: rgba(27, 34, 45, 0.86);
  --row-alt: rgba(255,255,255,0.018);
  --row-hover: rgba(255,255,255,0.045);
  --border: rgba(255,255,255,0.07);
  --border-2: rgba(255,255,255,0.13);
  --inner: rgba(255,255,255,0.04);
  --text: #e6edf3;
  --muted: #8b97a6;
  --muted-2: #c6cdd6;
  --green: #22c55e;
  --green-glow: rgba(34,197,94,0.35);
  --yellow: #eab308;
  --orange: #f97316;
  --red: #ef4444;
  --red-glow: rgba(239,68,68,0.35);
  --blue: #60a5fa;
  --purple: #a78bfa;
  --cyan: #22d3ee;
  --bar: rgba(255,255,255,0.08);
  --radius: 14px;
}
html[data-theme="light"] {
  --bg: #f0f3f9;
  --bg-2: #e6ebf3;
  --card: rgba(255, 255, 255, 0.86);
  --card-2: rgba(244, 246, 250, 0.95);
  --row-alt: rgba(0,0,0,0.02);
  --row-hover: rgba(0,0,0,0.04);
  --border: rgba(15,20,25,0.07);
  --border-2: rgba(15,20,25,0.16);
  --inner: rgba(15,20,25,0.04);
  --text: #0f1419;
  --muted: #5b6573;
  --muted-2: #2a3340;
  --bar: rgba(15,20,25,0.10);
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  background:
    radial-gradient(800px 600px at 12% -10%, rgba(96,165,250,0.10), transparent 60%),
    radial-gradient(900px 600px at 92% 10%, rgba(167,139,250,0.08), transparent 60%),
    radial-gradient(700px 600px at 50% 110%, rgba(34,211,238,0.05), transparent 60%),
    var(--bg);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica,
    Arial, sans-serif, "Apple Color Emoji";
  font-size: 13px;
  line-height: 1.45;
  min-height: 100vh;
}

a { color: var(--blue); text-decoration: none; }
a:hover { text-decoration: underline; }
.muted { color: var(--muted); }
.small { font-size: 11px; }

input, select, button, textarea {
  font: inherit;
  color: var(--text);
  background: var(--card-2);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 5px 9px;
  outline: none;
}
input:focus, select:focus, textarea:focus { border-color: var(--blue); }
button { cursor: pointer; }
button.primary { background: var(--blue); color: #0b0d10; border-color: transparent; font-weight: 600; }
button.danger  { background: transparent; color: var(--red); border-color: var(--red); }
button.icon-btn {
  width: 30px; height: 30px; padding: 0;
  border-radius: 8px;
  display: inline-flex; align-items: center; justify-content: center;
  font-size: 16px;
}

.topbar {
  display: flex; align-items: center; gap: 20px;
  max-width: 1320px; margin: 0 auto;
  padding: 14px 24px 4px;
}
.brand {
  display: flex; align-items: center; gap: 10px;
  font-size: 16px; font-weight: 700; letter-spacing: -0.01em;
  white-space: nowrap;
}
.brand .logo {
  width: 12px; height: 12px; border-radius: 50%;
  background: var(--blue); box-shadow: 0 0 0 4px rgba(96,165,250,0.20);
}
.tabs { display: flex; gap: 14px; flex: 1; }
.tabs .tab {
  color: var(--muted); padding: 6px 12px; border-radius: 999px;
  font-size: 13px; font-weight: 500;
  border: 1px solid transparent;
}
.tabs .tab.active {
  color: var(--text); background: var(--card);
  border-color: var(--border);
  backdrop-filter: blur(8px);
}
.navlinks { display: flex; gap: 10px; color: var(--muted); font-size: 12px; align-items: center; }
.navlinks a { color: var(--muted); }
.navlinks a:hover { color: var(--text); }

.overview {
  max-width: 1320px; margin: 12px auto 0;
  padding: 0 24px;
  display: grid;
  grid-template-columns: repeat(6, 1fr);
  gap: 10px;
}
@media (max-width: 1100px) { .overview { grid-template-columns: repeat(3, 1fr); } }
@media (max-width: 700px)  { .overview { grid-template-columns: repeat(2, 1fr); } }
.tile {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 14px 16px;
  backdrop-filter: blur(8px);
}
.tile-k { color: var(--muted); font-size: 11px; text-transform: uppercase; letter-spacing: 0.06em; }
.tile-v { font-size: 24px; font-weight: 700; margin-top: 2px; font-variant-numeric: tabular-nums; }
.tile-v.ok   { color: var(--green); }
.tile-v.warn { color: var(--yellow); }
.tile-v.crit { color: var(--red); }
.tile-sub { font-size: 11px; color: var(--muted); margin-top: 2px; font-variant-numeric: tabular-nums; }

.region-bar {
  max-width: 1320px; margin: 12px auto 0;
  padding: 0 24px;
  display: flex; align-items: center; gap: 12px;
  flex-wrap: wrap;
}
.region-chips { display: flex; gap: 8px; flex-wrap: wrap; }
.region-chip {
  display: inline-flex; align-items: center; gap: 8px;
  padding: 5px 12px;
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: 999px;
  color: var(--muted-2);
  font-size: 12px;
  font-weight: 500;
  cursor: pointer;
  backdrop-filter: blur(8px);
}
.region-chip[data-active="1"] {
  border-color: var(--blue);
  color: var(--text);
  box-shadow: 0 0 0 2px rgba(96,165,250,0.18);
}
.region-chip .flag { font-size: 16px; line-height: 1; }
.region-chip .count {
  background: var(--inner);
  padding: 1px 7px;
  border-radius: 999px;
  font-size: 11px;
  color: var(--muted);
  font-variant-numeric: tabular-nums;
}

.controls {
  max-width: 1320px; margin: 12px auto 0;
  padding: 0 24px;
  display: flex; align-items: center; justify-content: space-between;
  gap: 10px; flex-wrap: wrap;
}
.chips { display: flex; gap: 6px; flex-wrap: wrap; }
.chip {
  padding: 5px 12px; border-radius: 999px;
  border: 1px solid var(--border);
  background: transparent;
  color: var(--muted); font-size: 12px;
}
.chip[data-active="1"] {
  background: var(--card-2); color: var(--text); border-color: var(--border-2);
}
.ctl-right { display: flex; gap: 10px; align-items: center; }
.seg {
  display: flex; border: 1px solid var(--border);
  border-radius: 8px; overflow: hidden;
}
.seg-btn {
  background: transparent; border: none;
  padding: 5px 14px; border-radius: 0;
  color: var(--muted); font-size: 12px;
}
.seg-btn[data-active="1"] { background: var(--card-2); color: var(--text); }

main#grid {
  max-width: 1320px; margin: 14px auto 0;
  padding: 0 24px 40px;
}

/* ============ CARD VIEW (the main layout) ============ */
main#grid.view-card .nodes {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(310px, 1fr));
  gap: 12px;
}

.card {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 14px;
  backdrop-filter: blur(10px);
  display: flex; flex-direction: column;
  gap: 10px;
  transition: transform 0.15s ease, box-shadow 0.15s ease, border-color 0.15s ease;
}
.card:hover {
  border-color: var(--border-2);
  box-shadow: 0 6px 24px rgba(0,0,0,0.25);
  transform: translateY(-1px);
}

.card-head {
  display: flex; align-items: center; gap: 8px;
}
.card-head .flag { font-size: 18px; line-height: 1; }
.card-head .name {
  font-weight: 700; font-size: 14px;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
  flex: 1; min-width: 0;
}
.card-head .v4 {
  font-size: 10px; color: var(--muted);
  padding: 2px 6px; border: 1px solid var(--border-2);
  border-radius: 4px; font-weight: 500;
}
.card-head .dot {
  width: 9px; height: 9px; border-radius: 50%;
  background: var(--muted); flex-shrink: 0;
}
.dot.online  { background: var(--green); box-shadow: 0 0 0 3px var(--green-glow); }
.dot.offline { background: var(--red);   box-shadow: 0 0 0 3px var(--red-glow); }

.pair {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 12px;
}
.metric-block {
  display: flex; flex-direction: column; gap: 4px;
  min-width: 0;
}
.metric-block .mb-head {
  display: flex; align-items: center; justify-content: space-between;
  font-size: 11px; color: var(--muted);
}
.metric-block .mb-head .lbl {
  display: inline-flex; align-items: center; gap: 4px;
}
.metric-block .mb-head .lbl .ic { color: var(--muted); }
.metric-block .mb-head .pct {
  color: var(--text); font-weight: 600; font-size: 12px;
  font-variant-numeric: tabular-nums;
}
.metric-block .bar {
  height: 5px; background: var(--bar);
  border-radius: 4px; overflow: hidden; position: relative;
}
.metric-block .bar > span {
  display: block; height: 100%;
  border-radius: 4px; transition: width 0.4s ease;
}
.metric-block .mb-sub {
  font-size: 11px; color: var(--muted);
  font-variant-numeric: tabular-nums;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.bar.lvl-low  > span { background: linear-gradient(90deg, #16a34a, #22c55e); }
.bar.lvl-med  > span { background: linear-gradient(90deg, #ca8a04, #eab308); }
.bar.lvl-high > span { background: linear-gradient(90deg, #c2410c, #f97316); }
.bar.lvl-crit > span { background: linear-gradient(90deg, #b91c1c, #ef4444); }
.bar.violet   > span { background: linear-gradient(90deg, #8b5cf6, #a78bfa); }
.bar.cyan     > span { background: linear-gradient(90deg, #0891b2, #22d3ee); }

.net-row {
  display: grid; grid-template-columns: 1fr 1fr; gap: 12px;
}
.net-cell { display: flex; flex-direction: column; gap: 3px; }
.net-cell .speed {
  font-size: 14px; font-weight: 600;
  font-variant-numeric: tabular-nums;
  display: inline-flex; align-items: center; gap: 4px;
}
.net-cell .speed.down { color: var(--green); }
.net-cell .speed.up   { color: var(--blue); }
.net-cell .total {
  font-size: 11px; color: var(--muted);
  font-variant-numeric: tabular-nums;
}

.quality {
  display: flex; flex-direction: column; gap: 5px;
}
.quality .q-head {
  display: flex; justify-content: space-between; align-items: center;
  font-size: 11px; color: var(--muted);
}
.quality .q-head .lat   { color: var(--text); font-weight: 600; font-variant-numeric: tabular-nums; }
.quality .q-head .loss  { color: var(--text); font-weight: 600; font-variant-numeric: tabular-nums; }
.quality .q-bar {
  display: flex; gap: 1px;
  height: 8px;
}
.quality .q-bar .q-cell {
  flex: 1;
  border-radius: 1px;
  background: var(--bar);
}
.quality .q-bar .q-cell.ok    { background: linear-gradient(180deg, #16a34a, #22c55e); }
.quality .q-bar .q-cell.warn  { background: linear-gradient(180deg, #ca8a04, #eab308); }
.quality .q-bar .q-cell.bad   { background: linear-gradient(180deg, #c2410c, #f97316); }
.quality .q-bar .q-cell.crit  { background: linear-gradient(180deg, #b91c1c, #ef4444); }
.quality .q-bar .q-cell.gone  { background: var(--bar); }

.footer-row {
  display: grid; grid-template-columns: 1fr 1fr; gap: 12px;
  border-top: 1px dashed var(--border);
  padding-top: 10px;
}
.footer-row .fr-cell { display: flex; flex-direction: column; gap: 2px; }
.footer-row .fr-cell .k { font-size: 10px; color: var(--muted); text-transform: uppercase; letter-spacing: 0.05em; }
.footer-row .fr-cell .v {
  font-size: 14px; font-weight: 600;
  font-variant-numeric: tabular-nums;
}
.footer-row .fr-cell .v.expires { color: var(--orange); }
.footer-row .fr-cell .v.expires.warn { color: var(--yellow); }
.footer-row .fr-cell .v.expires.crit { color: var(--red); }
.footer-row .fr-cell .v.online { color: var(--blue); }

.offline-banner {
  font-size: 11px; color: var(--red);
  background: rgba(239,68,68,0.08);
  border: 1px solid rgba(239,68,68,0.35);
  padding: 5px 8px; border-radius: 6px;
}

/* ============ LIST VIEW (table) ============ */
main#grid.view-list .nodes-table {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  overflow: hidden;
  backdrop-filter: blur(10px);
}
table.nodes {
  width: 100%; border-collapse: collapse;
  font-variant-numeric: tabular-nums;
}
table.nodes thead th {
  background: var(--card-2);
  color: var(--muted);
  font-size: 10px;
  text-transform: uppercase; letter-spacing: 0.06em; font-weight: 600;
  text-align: left;
  padding: 9px 10px;
  border-bottom: 1px solid var(--border);
  white-space: nowrap;
}
table.nodes tbody td {
  padding: 9px 10px;
  border-bottom: 1px solid var(--border);
  font-size: 12px;
  vertical-align: middle;
  white-space: nowrap;
}
table.nodes tbody tr:nth-child(even) td { background: var(--row-alt); }
table.nodes tbody tr:hover td { background: var(--row-hover); }
table.nodes tbody tr:last-child td { border-bottom: none; }
table.nodes .cell-name { display: flex; align-items: center; gap: 7px; font-weight: 600; }
table.nodes .cell-name .flag { font-size: 14px; }
table.nodes .cell-os { color: var(--muted); font-size: 11px; }
table.nodes .micro-bar {
  height: 5px; width: 56px; display: inline-block;
  vertical-align: middle; background: var(--bar);
  border-radius: 3px; overflow: hidden; margin-right: 6px;
}
table.nodes .micro-bar > span {
  display: block; height: 100%; border-radius: 3px;
  transition: width 0.4s ease;
}
table.nodes .micro-bar.lvl-low  > span { background: linear-gradient(90deg, #16a34a, #22c55e); }
table.nodes .micro-bar.lvl-med  > span { background: linear-gradient(90deg, #ca8a04, #eab308); }
table.nodes .micro-bar.lvl-high > span { background: linear-gradient(90deg, #c2410c, #f97316); }
table.nodes .micro-bar.lvl-crit > span { background: linear-gradient(90deg, #b91c1c, #ef4444); }
table.nodes .expiry-cell.warn { color: var(--yellow); }
table.nodes .expiry-cell.crit { color: var(--red); }
table.nodes .traffic-stack { display: flex; flex-direction: column; gap: 2px; }
table.nodes .traffic-stack .used { font-size: 12px; }
table.nodes .traffic-stack .quota { font-size: 10px; color: var(--muted); }

footer {
  text-align: center; color: var(--muted);
  padding: 20px; font-size: 12px;
}
.empty {
  background: var(--card);
  border: 1px dashed var(--border);
  border-radius: var(--radius);
  text-align: center;
  padding: 60px 20px;
  color: var(--muted);
}

@media (max-width: 900px) {
  .overview { grid-template-columns: repeat(2, 1fr); }
  table.nodes .col-os, table.nodes .col-load, table.nodes .col-arch { display: none; }
}
@media (max-width: 600px) {
  .topbar { flex-wrap: wrap; gap: 10px; padding: 14px; }
  .controls, .overview, .region-bar { padding: 0 14px; }
  main#grid { padding: 14px; }
}

/* ============ Admin ============ */
.admin-shell { max-width: 1100px; margin: 0 auto; padding: 0 24px 60px; }
.admin-section {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 16px 18px;
  margin-top: 14px;
  backdrop-filter: blur(8px);
}
.admin-section h2 { margin: 0 0 10px; font-size: 14px; font-weight: 600; }
.field { display: flex; flex-direction: column; gap: 4px; }
.field label { font-size: 10px; color: var(--muted); text-transform: uppercase; letter-spacing: 0.05em; }
.grid-form { display: grid; gap: 10px; grid-template-columns: repeat(auto-fit, minmax(170px, 1fr)); }
.cmd-box {
  margin-top: 12px; padding: 12px 14px;
  background: #06090d; border: 1px solid var(--border-2);
  border-radius: 8px;
  font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
  font-size: 11.5px; word-break: break-all;
  color: #d3e1ff; position: relative;
}
.cmd-box button { position: absolute; top: 8px; right: 8px; font-size: 11px; padding: 3px 8px; }
table.hosts { width: 100%; border-collapse: collapse; }
table.hosts th, table.hosts td {
  text-align: left; padding: 7px 6px;
  border-bottom: 1px solid var(--border);
  font-size: 12px; vertical-align: middle;
}
table.hosts th { color: var(--muted); font-size: 10px; text-transform: uppercase; letter-spacing: 0.05em; font-weight: 600; }
table.hosts td input, table.hosts td select { width: 100%; }
table.hosts td.actions { white-space: nowrap; text-align: right; }
table.hosts td.actions button { margin-left: 6px; }
