:root {
  --bg: #080c14;
  --bg-elevated: #0e1420;
  --card: #121a28;
  --card-hover: #182234;
  --border: #1c2738;
  --border-light: #243044;
  --text: #e8eef7;
  --text-2: #9aabc2;
  --text-3: #64748b;
  --blue: #3b82f6;
  --blue-soft: rgba(59,130,246,.12);
  --green: #22c55e;
  --green-soft: rgba(34,197,94,.12);
  --purple: #a855f7;
  --purple-soft: rgba(168,85,247,.12);
  --orange: #f59e0b;
  --orange-soft: rgba(245,158,11,.12);
  --cyan: #06b6d4;
  --cyan-soft: rgba(6,182,212,.12);
  --red: #ef4444;
  --red-soft: rgba(239,68,68,.12);
  --radius: 14px;
  --shadow: 0 8px 32px rgba(0,0,0,.35);
}

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

body {
  font-family: 'Inter', system-ui, -apple-system, sans-serif;
  background: var(--bg);
  color: var(--text);
  min-height: 100vh;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
}

body::before {
  content: '';
  position: fixed;
  inset: 0;
  background:
    radial-gradient(ellipse 80% 50% at 20% -10%, rgba(59,130,246,.08), transparent),
    radial-gradient(ellipse 60% 40% at 90% 10%, rgba(168,85,247,.06), transparent);
  pointer-events: none;
  z-index: 0;
}

.app {
  position: relative;
  z-index: 1;
  max-width: 1320px;
  margin: 0 auto;
  padding: 1.25rem 1.5rem 3rem;
}

/* TOPBAR */
.topbar {
  display: flex;
  align-items: center;
  gap: 1.25rem;
  margin-bottom: 1.75rem;
  padding-bottom: 1.25rem;
  border-bottom: 1px solid var(--border);
  flex-wrap: wrap;
}

.brand { display: flex; align-items: center; gap: .75rem; min-width: 170px; }

.brand-icon {
  width: 40px; height: 40px;
  background: linear-gradient(135deg, var(--blue), var(--purple));
  border-radius: 11px;
  display: flex; align-items: center; justify-content: center;
  font-size: 1.2rem; color: #fff; font-weight: 700;
}

.brand-title { font-weight: 700; font-size: 1.05rem; letter-spacing: -.02em; }
.brand-sub { font-size: .75rem; color: var(--text-3); }

.tabs {
  display: flex; gap: .25rem;
  background: var(--bg-elevated);
  padding: .3rem; border-radius: 12px;
  border: 1px solid var(--border);
  flex-wrap: wrap;
}

.tab {
  background: transparent; border: none;
  color: var(--text-2); font-family: inherit;
  font-size: .82rem; font-weight: 500;
  padding: .45rem .9rem; border-radius: 9px;
  cursor: pointer; transition: all .15s;
}
.tab:hover { color: var(--text); }
.tab.active {
  background: var(--card); color: var(--text);
  box-shadow: 0 1px 3px rgba(0,0,0,.3);
}

.topbar-right { margin-left: auto; display: flex; align-items: center; gap: .6rem; }

.live-badge {
  display: flex; align-items: center; gap: .4rem;
  font-size: .8rem; color: var(--text-2);
  background: var(--card); border: 1px solid var(--border);
  padding: .35rem .75rem; border-radius: 999px;
}

.live-dot {
  width: 7px; height: 7px; border-radius: 50%;
  background: var(--orange); animation: pulse 1.4s ease infinite;
}
.live-badge.online .live-dot {
  background: var(--green); animation: none;
  box-shadow: 0 0 0 3px var(--green-soft);
}
.live-badge.error .live-dot { background: var(--red); animation: none; }

@keyframes pulse { 0%,100%{opacity:1} 50%{opacity:.35} }

.icon-btn {
  width: 36px; height: 36px; border-radius: 10px;
  border: 1px solid var(--border); background: var(--card);
  color: var(--text-2); cursor: pointer;
  display: flex; align-items: center; justify-content: center;
  transition: all .15s;
}
.icon-btn:hover { color: var(--text); border-color: var(--blue); background: var(--card-hover); }
.icon-btn.spinning svg { animation: spin .7s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }

.view { display: none; }
.view.active { display: block; }

/* STATS */
.stats-grid {
  display: grid;
  grid-template-columns: repeat(6, 1fr);
  gap: .9rem;
  margin-bottom: 2rem;
}

.stat {
  background: var(--card); border: 1px solid var(--border);
  border-radius: var(--radius); padding: 1rem 1.1rem;
  display: flex; align-items: center; gap: .85rem;
  box-shadow: var(--shadow); transition: border-color .15s;
}
.stat:hover { border-color: var(--border-light); }

.stat-icon {
  width: 40px; height: 40px; border-radius: 10px;
  display: flex; align-items: center; justify-content: center;
  font-size: 1.1rem; flex-shrink: 0;
}
.stat-icon.blue{background:var(--blue-soft);color:var(--blue)}
.stat-icon.green{background:var(--green-soft);color:var(--green)}
.stat-icon.purple{background:var(--purple-soft);color:var(--purple)}
.stat-icon.orange{background:var(--orange-soft);color:var(--orange)}
.stat-icon.cyan{background:var(--cyan-soft);color:var(--cyan)}
.stat-icon.red{background:var(--red-soft);color:var(--red)}

.stat-label { font-size: .7rem; color: var(--text-3); text-transform: uppercase; letter-spacing: .04em; font-weight: 500; }
.stat-value { font-size: 1.3rem; font-weight: 700; letter-spacing: -.03em; line-height: 1.2; }

.section-head {
  display: flex; align-items: center; justify-content: space-between;
  gap: 1rem; margin-bottom: 1rem; flex-wrap: wrap;
}
.section-head h2 { font-size: 1.05rem; font-weight: 600; letter-spacing: -.02em; }
.muted { color: var(--text-3); font-size: .8rem; }

.toolbar { display: flex; gap: .5rem; flex-wrap: wrap; }

.search, .select {
  background: var(--card); border: 1px solid var(--border);
  color: var(--text); font-family: inherit; font-size: .85rem;
  padding: .5rem .85rem; border-radius: 10px; outline: none;
  transition: border-color .15s;
}
.search { min-width: 220px; }
.search:focus, .select:focus { border-color: var(--blue); }
.select {
  cursor: pointer; appearance: none;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='12' viewBox='0 0 24 24' fill='none' stroke='%2394a3b8' stroke-width='2'%3E%3Cpath d='M6 9l6 6 6-6'/%3E%3C/svg%3E");
  background-repeat: no-repeat; background-position: right .7rem center;
  padding-right: 2rem;
}

/* NODE CARDS */
.nodes-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(340px, 1fr));
  gap: 1rem;
}

.node-card {
  background: var(--card); border: 1px solid var(--border);
  border-radius: var(--radius); padding: 1.25rem;
  box-shadow: var(--shadow); transition: transform .15s, border-color .15s;
}
.node-card:hover { transform: translateY(-2px); border-color: var(--border-light); }
.node-card.maintenance { border-color: rgba(245,158,11,.35); }

.node-top {
  display: flex; justify-content: space-between; align-items: flex-start;
  gap: .75rem; margin-bottom: 1rem;
}
.node-name { font-weight: 650; font-size: 1.05rem; letter-spacing: -.02em; }
.node-fqdn { font-size: .76rem; color: var(--text-3); margin-top: .15rem; word-break: break-all; }

.badge {
  font-size: .7rem; font-weight: 600; padding: .2rem .55rem;
  border-radius: 999px; white-space: nowrap;
}
.badge.online { background: var(--green-soft); color: var(--green); }
.badge.maintenance { background: var(--orange-soft); color: var(--orange); }
.badge.offline { background: var(--red-soft); color: var(--red); }

.res { margin-bottom: .8rem; }
.res-row { display: flex; justify-content: space-between; font-size: .78rem; margin-bottom: .28rem; }
.res-label { color: var(--text-3); }
.res-val { font-weight: 550; }

.bar { height: 6px; background: #1a2436; border-radius: 99px; overflow: hidden; }
.bar > i { display: block; height: 100%; border-radius: 99px; transition: width .4s ease; }
.bar.mem > i { background: linear-gradient(90deg, #2563eb, #60a5fa); }
.bar.disk > i { background: linear-gradient(90deg, #9333ea, #c084fc); }
.bar.cpu > i { background: linear-gradient(90deg, #059669, #34d399); }
.bar.warn > i { background: linear-gradient(90deg, #d97706, #fbbf24); }
.bar.danger > i { background: linear-gradient(90deg, #dc2626, #f87171); }

.node-foot {
  display: flex; flex-wrap: wrap; gap: .5rem 1rem;
  margin-top: .9rem; padding-top: .85rem;
  border-top: 1px solid var(--border);
  font-size: .76rem; color: var(--text-3);
}
.node-foot strong { color: var(--text); font-weight: 600; }

.live-mini {
  margin-top: .85rem; padding-top: .85rem;
  border-top: 1px dashed var(--border);
  font-size: .78rem;
}
.live-mini-title {
  font-size: .7rem; text-transform: uppercase; letter-spacing: .04em;
  color: var(--text-3); margin-bottom: .5rem; font-weight: 600;
}
.live-row {
  display: grid; grid-template-columns: 1fr 1fr; gap: .4rem .8rem;
}
.live-row span { color: var(--text-3); }
.live-row strong { color: var(--text); }

/* TABLE */
.table-card {
  background: var(--card); border: 1px solid var(--border);
  border-radius: var(--radius); overflow: hidden; box-shadow: var(--shadow);
}
.table-scroll { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; font-size: .875rem; }
th {
  text-align: left; padding: .85rem 1rem; background: #0c121c;
  color: var(--text-3); font-size: .7rem; font-weight: 600;
  text-transform: uppercase; letter-spacing: .05em;
  border-bottom: 1px solid var(--border); white-space: nowrap;
}
td { padding: .75rem 1rem; border-bottom: 1px solid var(--border); vertical-align: middle; }
tr:last-child td { border-bottom: none; }
tbody tr:hover td { background: var(--card-hover); }
.server-name { font-weight: 550; }
.ports { font-family: ui-monospace, SFMono-Regular, Menlo, monospace; font-size: .78rem; color: var(--text-2); }

.pill {
  display: inline-flex; align-items: center; gap: .3rem;
  font-size: .72rem; font-weight: 600; padding: .18rem .55rem; border-radius: 999px;
}
.pill::before { content: ''; width: 5px; height: 5px; border-radius: 50%; background: currentColor; }
.pill.running { background: var(--green-soft); color: var(--green); }
.pill.suspended { background: var(--red-soft); color: var(--red); }
.pill.offline, .pill.stopped { background: rgba(100,116,139,.15); color: var(--text-3); }
.pill.starting, .pill.stopping { background: var(--orange-soft); color: var(--orange); }
.pill.installed { background: var(--blue-soft); color: var(--blue); }

.table-footer {
  padding: .7rem 1rem; border-top: 1px solid var(--border);
  font-size: .8rem; color: var(--text-3); background: #0c121c;
}
.empty { text-align: center; padding: 2.5rem 1rem !important; color: var(--text-3); }

/* LIVE / NETWORK TAB */
.live-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(380px, 1fr));
  gap: 1.1rem;
}

.live-card {
  background: var(--card); border: 1px solid var(--border);
  border-radius: var(--radius); padding: 1.35rem; box-shadow: var(--shadow);
}
.live-card.error-state { border-color: rgba(239,68,68,.3); }

.live-head {
  display: flex; justify-content: space-between; align-items: center;
  margin-bottom: 1.1rem;
}
.live-head h3 { font-size: 1.05rem; font-weight: 650; }
.live-host { font-size: .75rem; color: var(--text-3); }

.metric-grid {
  display: grid; grid-template-columns: 1fr 1fr; gap: .9rem;
  margin-bottom: 1rem;
}
.metric {
  background: var(--bg-elevated); border-radius: 10px; padding: .75rem .85rem;
  border: 1px solid var(--border);
}
.metric-label { font-size: .7rem; color: var(--text-3); text-transform: uppercase; letter-spacing: .03em; margin-bottom: .2rem; }
.metric-value { font-size: 1.15rem; font-weight: 700; letter-spacing: -.02em; }
.metric-sub { font-size: .72rem; color: var(--text-3); margin-top: .15rem; }

.net-box {
  background: var(--bg-elevated); border: 1px solid var(--border);
  border-radius: 10px; padding: .85rem;
}
.net-title { font-size: .72rem; color: var(--text-3); text-transform: uppercase; letter-spacing: .03em; margin-bottom: .55rem; font-weight: 600; }
.net-row { display: flex; justify-content: space-between; font-size: .85rem; margin-bottom: .3rem; }
.net-row:last-child { margin-bottom: 0; }
.net-in { color: var(--green); }
.net-out { color: var(--blue); }

.info-box {
  background: var(--blue-soft); border: 1px solid rgba(59,130,246,.25);
  color: #93c5fd; border-radius: var(--radius);
  padding: 1.1rem 1.3rem; margin-bottom: 1.25rem; font-size: .9rem; line-height: 1.55;
}
.info-box strong { display: block; color: var(--blue); margin-bottom: .3rem; }
.info-box code { background: rgba(0,0,0,.25); padding: .1rem .35rem; border-radius: 4px; font-size: .82rem; }

.error-box {
  grid-column: 1 / -1;
  background: var(--red-soft); border: 1px solid rgba(239,68,68,.3);
  color: #fca5a5; border-radius: var(--radius);
  padding: 1.25rem 1.5rem; text-align: center;
}
.error-box strong { display: block; margin-bottom: .35rem; color: var(--red); }

.loading-box {
  grid-column: 1 / -1; text-align: center; padding: 3rem 1rem; color: var(--text-3);
}
.spinner {
  width: 28px; height: 28px; border: 2.5px solid var(--border);
  border-top-color: var(--blue); border-radius: 50%;
  margin: 0 auto .9rem; animation: spin .7s linear infinite;
}

.footer {
  display: flex; justify-content: space-between; align-items: center;
  margin-top: 2.5rem; padding-top: 1.25rem;
  border-top: 1px solid var(--border);
  font-size: .78rem; color: var(--text-3);
}

/* ========== TOOLS ========== */
.tools-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(360px, 1fr));
  gap: 1.1rem;
}
.tool-card {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 1.25rem;
  box-shadow: var(--shadow);
}
.tool-card h3 { font-size: 1rem; font-weight: 650; margin-bottom: .25rem; }
.tool-desc { font-size: .8rem; color: var(--text-3); margin-bottom: .9rem; line-height: 1.45; }
.tool-body { font-size: .85rem; line-height: 1.55; }

.cap-row {
  display: flex; justify-content: space-between; align-items: center;
  padding: .55rem 0; border-bottom: 1px solid var(--border); gap: .75rem;
}
.cap-row:last-child { border-bottom: none; }
.cap-name { font-weight: 550; }
.cap-meta { font-size: .75rem; color: var(--text-3); }
.cap-bars { flex: 1; max-width: 140px; }
.cap-bars .bar { margin-top: .25rem; height: 5px; }

.alert-item {
  display: flex; gap: .6rem; align-items: flex-start;
  padding: .5rem 0; border-bottom: 1px solid var(--border); font-size: .84rem;
}
.alert-item:last-child { border-bottom: none; }
.alert-item.warn { color: var(--orange); }
.alert-item.danger { color: var(--red); }
.alert-item.ok { color: var(--green); }

.agent-row {
  display: flex; justify-content: space-between; align-items: center;
  padding: .45rem 0; border-bottom: 1px solid var(--border);
}
.agent-row:last-child { border-bottom: none; }

.ports-list {
  max-height: 220px; overflow-y: auto;
  font-family: ui-monospace, SFMono-Regular, Menlo, monospace; font-size: .8rem;
}
.port-line {
  display: flex; justify-content: space-between; padding: .3rem 0;
  border-bottom: 1px solid var(--border); gap: .5rem;
}
.port-line:last-child { border-bottom: none; }
.port-num { color: var(--cyan); font-weight: 600; min-width: 50px; }

.btn-row { display: flex; flex-wrap: wrap; gap: .5rem; }
.btn {
  display: inline-flex; align-items: center; justify-content: center;
  background: var(--blue); color: #fff; border: none;
  font-family: inherit; font-size: .82rem; font-weight: 550;
  padding: .5rem .9rem; border-radius: 9px; cursor: pointer;
  text-decoration: none; transition: background .15s, opacity .15s;
}
.btn:hover { background: #2563eb; color: #fff; }
.btn.secondary {
  background: var(--bg-elevated); color: var(--text); border: 1px solid var(--border);
}
.btn.secondary:hover { border-color: var(--blue); background: var(--card-hover); }

.toast {
  position: fixed; bottom: 1.5rem; right: 1.5rem;
  background: var(--card); border: 1px solid var(--border); color: var(--text);
  padding: .7rem 1.1rem; border-radius: 10px; box-shadow: var(--shadow);
  font-size: .85rem; z-index: 100; opacity: 0; transform: translateY(8px);
  transition: all .2s; pointer-events: none;
}
.toast.show { opacity: 1; transform: translateY(0); }

@media (max-width: 1100px) {
  .stats-grid { grid-template-columns: repeat(3, 1fr); }
}
@media (max-width: 700px) {
  .stats-grid { grid-template-columns: repeat(2, 1fr); }
  .topbar { gap: 1rem; }
  .tabs { order: 3; width: 100%; justify-content: center; }
  .metric-grid { grid-template-columns: 1fr; }
  .search { min-width: 140px; }
}
