:root {
  --bg:          #0c0f14;
  --bg-grid:     #11151c;
  --panel:       #141a23;
  --panel-2:     #1a212c;
  --line:        #232c3a;
  --line-soft:   #1c2430;
  --text:        #e6edf5;
  --muted:       #7c8a9e;
  --faint:       #4d5a6c;

  --ok:    #3fd68b;
  --warn:  #f5b13d;
  --crit:  #ff5d5d;
  --down:  #8a93a3;
  --accent:#4ea1ff;

  --ok-dim:   rgba(63,214,139,.14);
  --warn-dim: rgba(245,177,61,.14);
  --crit-dim: rgba(255,93,93,.16);

  --mono: "IBM Plex Mono", ui-monospace, monospace;
  --sans: "IBM Plex Sans", system-ui, sans-serif;
  --radius: 12px;
}

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

/* The dashboard toggles overlays via the [hidden] attribute in JS. Because some
   of them set an explicit `display` below, this rule is required so `hidden`
   wins (otherwise the Add Server modal / detail drawer stay stuck open). */
[hidden] { display: none !important; }

body {
  font-family: var(--sans);
  color: var(--text);
  background:
    linear-gradient(var(--line-soft) 1px, transparent 1px) 0 0 / 100% 44px,
    linear-gradient(90deg, var(--line-soft) 1px, transparent 1px) 0 0 / 44px 100%,
    radial-gradient(1200px 600px at 80% -10%, #16202d 0%, transparent 60%),
    var(--bg);
  min-height: 100vh;
  letter-spacing: .1px;
}

/* faint moving scanline for atmosphere */
.scanline {
  position: fixed; inset: 0; pointer-events: none; z-index: 5;
  background: linear-gradient(transparent 0%, rgba(78,161,255,.025) 50%, transparent 100%);
  background-size: 100% 6px; opacity: .5;
}

/* ---------- top bar ---------- */
.topbar {
  display: flex; align-items: center; gap: 28px;
  padding: 18px 28px; border-bottom: 1px solid var(--line);
  background: rgba(12,15,20,.72); backdrop-filter: blur(8px);
  position: sticky; top: 0; z-index: 10;
}
.brand { display: flex; align-items: center; gap: 14px; }
.logo-img {
  width: 40px; height: 40px; object-fit: contain; display: block;
  filter: drop-shadow(0 0 10px rgba(78,161,255,.45));
}
.brand h1 { font-size: 17px; letter-spacing: 2px; font-weight: 700; }
.tagline { font-size: 11px; color: var(--muted); letter-spacing: 2px; text-transform: uppercase; }

.summary { display: flex; gap: 26px; margin-left: 8px; }
.stat { display: flex; align-items: baseline; gap: 8px; font-family: var(--mono); }
.stat b { font-size: 22px; font-weight: 600; }
.stat label { font-size: 11px; color: var(--muted); text-transform: uppercase; letter-spacing: 1px; }

.controls { margin-left: auto; display: flex; align-items: center; gap: 12px; }
.pulse {
  width: 9px; height: 9px; border-radius: 50%; background: var(--ok);
  box-shadow: 0 0 0 0 rgba(63,214,139,.6); animation: pulse 2.2s infinite;
}
@keyframes pulse {
  0%   { box-shadow: 0 0 0 0 rgba(63,214,139,.5); }
  70%  { box-shadow: 0 0 0 10px rgba(63,214,139,0); }
  100% { box-shadow: 0 0 0 0 rgba(63,214,139,0); }
}

.btn {
  font-family: var(--sans); font-size: 13px; font-weight: 600;
  padding: 9px 16px; border-radius: 8px; cursor: pointer;
  border: 1px solid var(--line); transition: all .15s ease;
}
.btn.ghost { background: transparent; color: var(--text); }
.btn.ghost:hover { background: var(--panel-2); border-color: var(--accent); }
.btn.solid { background: var(--accent); color: #04101f; border-color: var(--accent); }
.btn.solid:hover { box-shadow: 0 0 18px rgba(78,161,255,.45); transform: translateY(-1px); }

/* ---------- grid ---------- */
main { padding: 26px 28px 60px; }
.grid {
  display: grid; gap: 18px;
  grid-template-columns: repeat(auto-fill, minmax(330px, 1fr));
}

.card {
  background: linear-gradient(180deg, var(--panel) 0%, var(--panel-2) 100%);
  border: 1px solid var(--line); border-radius: var(--radius);
  padding: 18px; position: relative; overflow: hidden;
  cursor: pointer; transition: transform .18s ease, border-color .18s ease, box-shadow .18s ease;
  animation: rise .45s cubic-bezier(.2,.7,.3,1) backwards;
}
.card:hover { transform: translateY(-3px); border-color: var(--accent); box-shadow: 0 12px 30px rgba(0,0,0,.4); }
@keyframes rise { from { opacity: 0; transform: translateY(14px); } to { opacity: 1; transform: translateY(0); } }

/* left status rail */
.card::before {
  content: ""; position: absolute; left: 0; top: 0; bottom: 0; width: 4px;
  background: var(--down);
}
.card.ok::before   { background: var(--ok);   box-shadow: 0 0 16px var(--ok); }
.card.warn::before { background: var(--warn); box-shadow: 0 0 16px var(--warn); }
.card.crit::before,
.card.down::before { background: var(--crit); box-shadow: 0 0 16px var(--crit); }
.card.offline { opacity: .62; }

.card-head { display: flex; align-items: flex-start; justify-content: space-between; gap: 10px; margin-bottom: 14px; }
.card-head h3 { font-size: 16px; font-weight: 600; }
.card-head .sid { font-family: var(--mono); font-size: 11px; color: var(--muted); }

.pill {
  font-family: var(--mono); font-size: 11px; font-weight: 600;
  padding: 4px 10px; border-radius: 20px; text-transform: uppercase; letter-spacing: 1px;
  white-space: nowrap;
}
.pill.ok   { color: var(--ok);   background: var(--ok-dim); }
.pill.warn { color: var(--warn); background: var(--warn-dim); }
.pill.crit,
.pill.down { color: var(--crit); background: var(--crit-dim); }
.pill.unknown { color: var(--down); background: rgba(138,147,163,.14); }

/* meters */
.meters { display: grid; gap: 9px; margin-bottom: 14px; }
.meter { display: grid; grid-template-columns: 42px 1fr 56px; align-items: center; gap: 10px; }
.meter .lbl { font-family: var(--mono); font-size: 10px; color: var(--muted); text-transform: uppercase; }
.meter .track { height: 7px; background: var(--bg-grid); border-radius: 6px; overflow: hidden; }
.meter .fill { display: block; height: 100%; border-radius: 6px; transition: width .5s ease, background .3s ease; box-shadow: inset 0 -1px 0 rgba(0,0,0,.25); background: var(--accent); }
/* Fallback colors when an older app.js tags the fill with a level class.
   The current app.js sets the color inline (continuous green→red), which wins. */
.meter .fill.ok   { background: linear-gradient(90deg, #2fa86c, #3fd68b); }
.meter .fill.warn { background: linear-gradient(90deg, #c98a1f, #f5b13d); }
.meter .fill.crit { background: linear-gradient(90deg, #c93b3b, #ff5d5d); }
.meter .val { font-family: var(--mono); font-size: 12px; text-align: right; color: var(--text); transition: color .3s ease; }

/* services */
.svc-row { display: flex; flex-wrap: wrap; gap: 6px; margin-bottom: 12px; }
.svc {
  display: inline-flex; align-items: center; gap: 6px;
  font-family: var(--mono); font-size: 11px;
  padding: 3px 9px; border-radius: 6px; background: var(--bg-grid); border: 1px solid var(--line-soft);
}
.svc .d { width: 7px; height: 7px; border-radius: 50%; }
.svc .d.ok { background: var(--ok); }
.svc .d.warn { background: var(--warn); }
.svc .d.down, .svc .d.crit { background: var(--crit); }
.svc .d.unknown { background: var(--down); }

.card-foot { display: flex; justify-content: space-between; font-family: var(--mono); font-size: 11px; color: var(--faint); }

.dot { width: 9px; height: 9px; border-radius: 50%; display: inline-block; }
.dot.ok { background: var(--ok); } .dot.warn { background: var(--warn); } .dot.down { background: var(--crit); }

.empty { text-align: center; padding: 80px 20px; }
.empty p { margin: 6px 0; font-size: 16px; }
.muted { color: var(--muted); } .faint { color: var(--faint); }

/* ---------- drawer ---------- */
.overlay { position: fixed; inset: 0; background: rgba(4,6,10,.6); z-index: 20; }
.drawer {
  position: fixed; top: 0; right: 0; bottom: 0; width: min(560px, 94vw);
  background: var(--panel); border-left: 1px solid var(--line); z-index: 30;
  display: flex; flex-direction: column; animation: slidein .28s ease;
  box-shadow: -20px 0 60px rgba(0,0,0,.5);
}
@keyframes slidein { from { transform: translateX(100%); } to { transform: translateX(0); } }
.drawer-head { display: flex; justify-content: space-between; align-items: flex-start; padding: 22px 24px; border-bottom: 1px solid var(--line); }
.drawer-head h2 { font-size: 20px; }
.drawer-body { padding: 22px 24px; overflow-y: auto; }
.icon-btn { background: var(--panel-2); border: 1px solid var(--line); color: var(--text); width: 34px; height: 34px; border-radius: 8px; cursor: pointer; font-size: 15px; }
.icon-btn:hover { border-color: var(--crit); color: var(--crit); }

.section-title { font-family: var(--mono); font-size: 11px; text-transform: uppercase; letter-spacing: 1.5px; color: var(--muted); margin: 22px 0 10px; }
.kv { display: grid; grid-template-columns: 1fr auto; gap: 6px 14px; font-family: var(--mono); font-size: 13px; }
.kv .k { color: var(--muted); }

.disk { margin: 8px 0; }
.disk .disk-head { display: flex; justify-content: space-between; font-family: var(--mono); font-size: 12px; margin-bottom: 4px; }
.svc-detail { display: flex; justify-content: space-between; align-items: center; padding: 8px 0; border-bottom: 1px solid var(--line-soft); font-size: 13px; }
.svc-detail .name { font-weight: 600; }
.svc-detail .meta { font-family: var(--mono); font-size: 11px; color: var(--muted); }

.range { display: flex; gap: 6px; margin-bottom: 10px; }
.range button { font-family: var(--mono); font-size: 11px; padding: 4px 10px; border-radius: 6px; background: var(--bg-grid); border: 1px solid var(--line-soft); color: var(--muted); cursor: pointer; }
.range button.active { color: var(--accent); border-color: var(--accent); }
.chart-box { background: var(--bg-grid); border: 1px solid var(--line-soft); border-radius: 10px; padding: 12px; margin-bottom: 14px; height: 180px; }

.drawer .danger { margin-top: 26px; }
.btn.danger { background: transparent; color: var(--crit); border-color: rgba(255,93,93,.4); }
.btn.danger:hover { background: var(--crit-dim); }

/* ---------- modal ---------- */
.modal-wrap { position: fixed; inset: 0; background: rgba(4,6,10,.66); z-index: 40; display: flex; align-items: center; justify-content: center; padding: 20px; }
.modal { background: var(--panel); border: 1px solid var(--line); border-radius: 14px; padding: 26px; width: min(440px, 100%); animation: rise .25s ease; }
.modal h2 { margin-bottom: 6px; }
.modal label { display: block; font-size: 12px; color: var(--muted); margin-top: 14px; }
.modal input { width: 100%; margin-top: 6px; padding: 10px 12px; background: var(--bg-grid); border: 1px solid var(--line); border-radius: 8px; color: var(--text); font-family: var(--mono); font-size: 13px; }
.modal input:focus { outline: none; border-color: var(--accent); }
.req { color: var(--crit); }
.modal-actions { display: flex; justify-content: flex-end; gap: 10px; margin-top: 22px; }
.form-error { color: var(--crit); font-size: 13px; margin-top: 10px; min-height: 16px; }

@media (max-width: 640px) {
  .topbar { flex-wrap: wrap; gap: 14px; }
  .summary { order: 3; width: 100%; }
  .controls { margin-left: 0; }
}

/* ---------- toolbar: tabs + search ---------- */
.toolbar {
  display: flex; align-items: center; gap: 16px; flex-wrap: wrap;
  padding: 14px 28px 0;
}
.tabs { display: inline-flex; background: var(--panel); border: 1px solid var(--line); border-radius: 9px; padding: 3px; }
.tab {
  font-family: var(--sans); font-size: 13px; font-weight: 600; color: var(--muted);
  background: transparent; border: 0; padding: 7px 16px; border-radius: 7px; cursor: pointer;
  transition: all .15s ease;
}
.tab:hover { color: var(--text); }
.tab.active { background: var(--panel-2); color: var(--accent); box-shadow: inset 0 0 0 1px var(--line); }

.search {
  margin-left: auto; display: flex; align-items: center; gap: 8px;
  background: var(--panel); border: 1px solid var(--line); border-radius: 9px;
  padding: 7px 12px; min-width: 280px; flex: 0 1 360px;
}
.search:focus-within { border-color: var(--accent); box-shadow: 0 0 0 3px rgba(78,161,255,.12); }
.search-ico { color: var(--faint); font-size: 15px; }
.search input {
  flex: 1; background: transparent; border: 0; outline: none;
  color: var(--text); font-family: var(--mono); font-size: 13px;
}
.search input::placeholder { color: var(--faint); }
.search-count { font-family: var(--mono); font-size: 11px; white-space: nowrap; }

/* ---------- table view ---------- */
.table-wrap { padding: 8px 28px 60px; overflow-x: auto; }
.srv-table { width: 100%; border-collapse: separate; border-spacing: 0 10px; font-size: 13px; min-width: 780px; }
.srv-table thead th {
  text-align: left; font-family: var(--mono); font-size: 11px; text-transform: uppercase;
  letter-spacing: 1px; color: var(--muted); font-weight: 600; padding: 2px 16px 6px; white-space: nowrap;
}
.srv-table th.num { text-align: right; }
.srv-table th.sortable { cursor: pointer; user-select: none; }
.srv-table th.sortable:hover { color: var(--text); }
.srv-table th.sortable::after { content: "↕"; opacity: .35; margin-left: 6px; font-size: 10px; }
.srv-table th.sorted[data-dir="asc"]::after { content: "▲"; opacity: 1; color: var(--accent); }
.srv-table th.sorted[data-dir="desc"]::after { content: "▼"; opacity: 1; color: var(--accent); }

/* each server renders as its own raised bar with a clear background */
.srv-table tbody td {
  background: linear-gradient(180deg, var(--panel) 0%, var(--panel-2) 100%);
  border-top: 1px solid var(--line); border-bottom: 1px solid var(--line);
  padding: 12px 16px; vertical-align: middle;
}
.srv-table tbody td:first-child {
  border-left: 1px solid var(--line); border-top-left-radius: 12px; border-bottom-left-radius: 12px;
}
.srv-table tbody td:last-child {
  border-right: 1px solid var(--line); border-top-right-radius: 12px; border-bottom-right-radius: 12px;
}
.t-row { cursor: pointer; }
.t-row td { transition: background .14s ease, border-color .14s ease; }
.t-row:hover td { background: var(--panel-2); border-color: var(--accent); }

.t-name { display: flex; align-items: center; gap: 12px; }
.t-rail { width: 4px; height: 34px; border-radius: 3px; background: var(--down); flex: none; }
.t-rail.ok { background: var(--ok); box-shadow: 0 0 10px var(--ok); }
.t-rail.warn { background: var(--warn); box-shadow: 0 0 10px var(--warn); }
.t-rail.crit, .t-rail.down { background: var(--crit); box-shadow: 0 0 10px var(--crit); }
.t-title { font-weight: 600; font-size: 14px; }
.t-sub { font-family: var(--mono); font-size: 11px; color: var(--muted); }

/* compact green→red meters inside metric cells */
.t-meter { display: flex; align-items: center; gap: 10px; min-width: 118px; }
.t-track { flex: 1; height: 6px; min-width: 54px; background: var(--bg-grid); border-radius: 5px; overflow: hidden; }
.t-fill { display: block; height: 100%; border-radius: 5px; background: var(--accent); transition: width .4s ease; }
.t-fill.ok   { background: linear-gradient(90deg, #2fa86c, #3fd68b); }
.t-fill.warn { background: linear-gradient(90deg, #c98a1f, #f5b13d); }
.t-fill.crit { background: linear-gradient(90deg, #c93b3b, #ff5d5d); }
.t-num { font-family: var(--mono); font-size: 12px; min-width: 40px; text-align: right; }
.t-num.muted { color: var(--faint); }
.t-seen { font-family: var(--mono); font-size: 11px; color: var(--muted); white-space: nowrap; }

@media (max-width: 680px) {
  .toolbar { padding: 12px 16px 0; }
  .search { margin-left: 0; min-width: 0; width: 100%; }
  .table-wrap { padding: 8px 12px 50px; }
}
