:root {
  --bg: #0b0e14;
  --surface: #131720;
  --surface2: #1a1f2e;
  --border: #232a3b;
  --text: #e2e8f0;
  --text-dim: #8892a4;
  --accent: #6366f1;
  --accent-glow: rgba(99,102,241,.15);
  --green: #22c55e;
  --green-bg: rgba(34,197,94,.1);
  --yellow: #eab308;
  --yellow-bg: rgba(234,179,8,.1);
  --red: #ef4444;
  --red-bg: rgba(239,68,68,.1);
  --orange: #f97316;
  --orange-bg: rgba(249,115,22,.1);
}

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

body {
  font-family: 'Segoe UI', -apple-system, sans-serif;
  background: var(--bg);
  color: var(--text);
  min-height: 100vh;
}

/* ── Login page ────────────────────────────────────────────────────── */

.login-wrapper {
  display: grid;
  place-items: center;
  min-height: 100vh;
}

.login-box {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 16px;
  padding: 48px 40px 40px;
  width: 380px;
  max-width: 92vw;
}

.login-brand {
  display: flex;
  align-items: center;
  gap: 12px;
  font-size: 22px;
  font-weight: 700;
  margin-bottom: 8px;
  letter-spacing: -.3px;
}

.login-sub {
  font-size: 13px;
  color: var(--text-dim);
  margin-bottom: 32px;
}

.form-group {
  margin-bottom: 18px;
}

.form-group label {
  display: block;
  font-size: 12px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: .6px;
  color: var(--text-dim);
  margin-bottom: 6px;
}

.form-group input {
  width: 100%;
  padding: 10px 14px;
  border-radius: 8px;
  border: 1px solid var(--border);
  background: var(--surface2);
  color: var(--text);
  font-size: 14px;
  outline: none;
  transition: border-color .15s;
}

.form-group input:focus {
  border-color: var(--accent);
}

.login-btn {
  width: 100%;
  padding: 11px 0;
  border: none;
  border-radius: 8px;
  background: var(--accent);
  color: #fff;
  font-size: 14px;
  font-weight: 600;
  cursor: pointer;
  transition: opacity .15s;
  margin-top: 6px;
}
.login-btn:hover { opacity: .88; }
.login-btn:disabled { opacity: .5; cursor: wait; }

.login-error {
  margin-top: 14px;
  padding: 10px 14px;
  border-radius: 8px;
  background: var(--red-bg);
  color: var(--red);
  font-size: 13px;
  display: none;
}
.login-error.visible { display: block; }

/* ── Top bar ───────────────────────────────────────────────────────── */

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 16px 32px;
  border-bottom: 1px solid var(--border);
  background: var(--surface);
}
.topbar-brand {
  display: flex;
  align-items: center;
  gap: 12px;
  font-size: 18px;
  font-weight: 700;
  letter-spacing: -.3px;
}
.topbar-brand .eye {
  width: 32px; height: 32px;
  border-radius: 50%;
  background: conic-gradient(var(--accent), var(--green), var(--accent));
  display: grid; place-items: center;
}
.topbar-brand .eye::after {
  content: '';
  width: 12px; height: 12px;
  border-radius: 50%;
  background: var(--bg);
}
.topbar-right {
  display: flex;
  align-items: center;
  gap: 24px;
}
.topbar-meta {
  display: flex;
  align-items: center;
  gap: 24px;
  font-size: 13px;
  color: var(--text-dim);
}
.topbar-meta .live-dot {
  width: 8px; height: 8px;
  border-radius: 50%;
  background: var(--green);
  box-shadow: 0 0 6px var(--green);
  display: inline-block;
  margin-right: 4px;
}
.logout-btn {
  padding: 5px 14px;
  border-radius: 8px;
  border: 1px solid var(--border);
  background: transparent;
  color: var(--text-dim);
  font-size: 12px;
  font-weight: 600;
  cursor: pointer;
  transition: all .15s;
}
.logout-btn:hover { border-color: var(--red); color: var(--red); }

.container { max-width: 1440px; margin: 0 auto; padding: 24px 32px 64px; }

/* ── Loading overlay ───────────────────────────────────────────────── */

.loading-overlay {
  position: fixed;
  inset: 0;
  background: var(--bg);
  display: grid;
  place-items: center;
  z-index: 100;
  transition: opacity .3s;
}
.loading-overlay.hidden { opacity: 0; pointer-events: none; }
.spinner {
  width: 40px; height: 40px;
  border: 3px solid var(--border);
  border-top-color: var(--accent);
  border-radius: 50%;
  animation: spin .7s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* ── Summary cards ─────────────────────────────────────────────────── */

.summary-row {
  display: grid;
  grid-template-columns: repeat(5, 1fr);
  gap: 16px;
  margin-bottom: 28px;
}
.summary-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 20px 24px;
}
.summary-card .label {
  font-size: 12px;
  text-transform: uppercase;
  letter-spacing: .8px;
  color: var(--text-dim);
  margin-bottom: 8px;
}
.summary-card .value {
  font-size: 32px;
  font-weight: 700;
  letter-spacing: -1px;
}
.summary-card .sub {
  font-size: 12px;
  color: var(--text-dim);
  margin-top: 4px;
}
.val-green  { color: var(--green); }
.val-yellow { color: var(--yellow); }
.val-red    { color: var(--red); }
.val-accent { color: var(--accent); }

/* ── Section headers ───────────────────────────────────────────────── */

.section-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 16px;
  flex-wrap: wrap;
  gap: 12px;
}
.section-header h2 {
  font-size: 16px;
  font-weight: 600;
}

/* ── Trend section ─────────────────────────────────────────────────── */

.trend-row {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 16px;
  margin-bottom: 28px;
}
.trend-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 20px 24px;
}
.trend-card h3 {
  font-size: 14px;
  font-weight: 600;
  margin-bottom: 16px;
}
.trend-bar-row {
  display: flex;
  align-items: center;
  gap: 12px;
  margin-bottom: 8px;
  font-size: 13px;
}
.trend-bar-label { width: 56px; text-align: right; color: var(--text-dim); flex-shrink: 0; }
.trend-bar-track {
  flex: 1;
  height: 20px;
  background: var(--surface2);
  border-radius: 4px;
  overflow: hidden;
}
.trend-bar-fill {
  height: 100%;
  border-radius: 4px;
  transition: width .5s;
}
.trend-bar-val {
  width: 36px;
  text-align: right;
  font-weight: 600;
  flex-shrink: 0;
}

/* ── Status matrix table ───────────────────────────────────────────── */

.matrix-wrap {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 12px;
  overflow: hidden;
  margin-bottom: 28px;
}
.matrix-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 13px;
}
.matrix-table th {
  text-align: left;
  padding: 12px 16px;
  background: var(--surface2);
  color: var(--text-dim);
  font-weight: 600;
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: .6px;
  border-bottom: 1px solid var(--border);
  position: sticky;
  top: 0;
  z-index: 2;
}
.matrix-table th.center, .matrix-table td.center { text-align: center; }
.matrix-table td {
  padding: 12px 16px;
  border-bottom: 1px solid var(--border);
  vertical-align: middle;
}
.matrix-table tr:last-child td { border-bottom: none; }
.matrix-table tr:hover td { background: rgba(99,102,241,.04); }

.client-name { font-weight: 600; }
.client-id {
  font-size: 11px;
  color: var(--text-dim);
  font-family: 'Consolas', monospace;
  margin-top: 2px;
}

.health-badge {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  font-weight: 700;
  font-size: 14px;
  padding: 4px 12px;
  border-radius: 8px;
  min-width: 52px;
  justify-content: center;
}
.health-badge.crit { background: var(--red-bg); color: var(--red); }
.health-badge.warn { background: var(--yellow-bg); color: var(--yellow); }
.health-badge.ok   { background: var(--green-bg); color: var(--green); }

.status-dot {
  width: 24px; height: 24px;
  border-radius: 6px;
  display: inline-grid;
  place-items: center;
  font-size: 12px;
  font-weight: 700;
}
.status-dot.s-ok   { background: var(--green-bg); color: var(--green); }
.status-dot.s-warn { background: var(--yellow-bg); color: var(--yellow); }
.status-dot.s-crit { background: var(--red-bg); color: var(--red); }
.status-dot.s-na   { background: var(--surface2); color: var(--text-dim); }

/* ── Sparkline bars ────────────────────────────────────────────────── */

.spark {
  display: inline-flex;
  align-items: flex-end;
  gap: 2px;
  height: 24px;
  vertical-align: middle;
}
.spark .bar {
  width: 4px;
  border-radius: 1px;
  opacity: .55;
}

/* ── Expandable detail rows ────────────────────────────────────────── */

.detail-toggle { cursor: pointer; user-select: none; }
.detail-toggle .arrow {
  display: inline-block;
  transition: transform .2s;
  font-size: 10px;
  margin-right: 8px;
  color: var(--text-dim);
}
.detail-toggle.open .arrow { transform: rotate(90deg); }
.detail-row { display: none; }
.detail-row.open { display: table-row; }
.detail-row td {
  padding: 0 16px 16px 48px;
  background: rgba(99,102,241,.02);
}

.detail-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(280px, 1fr));
  gap: 12px;
  padding-top: 12px;
}
.detail-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 14px 16px;
}
.detail-card .dc-head {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 8px;
}
.detail-card .dc-title {
  font-size: 12px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: .5px;
  color: var(--text-dim);
}
.detail-card .dc-msgs {
  font-size: 12px;
  line-height: 1.7;
  color: var(--text);
}
.detail-card .dc-msgs .msg-line { padding: 2px 0; }
.msg-ok   { color: var(--green); }
.msg-warn { color: var(--yellow); }
.msg-crit { color: var(--red); }

/* ── Filters toolbar ───────────────────────────────────────────────── */

.filters {
  display: flex;
  gap: 10px;
  align-items: center;
  flex-wrap: wrap;
}
.filter-btn {
  padding: 6px 14px;
  border-radius: 8px;
  border: 1px solid var(--border);
  background: transparent;
  color: var(--text-dim);
  font-size: 12px;
  font-weight: 600;
  cursor: pointer;
  transition: all .15s;
}
.filter-btn:hover { border-color: var(--accent); color: var(--text); }
.filter-btn.active { background: var(--accent-glow); border-color: var(--accent); color: var(--accent); }

.search-input {
  padding: 6px 12px;
  border-radius: 8px;
  border: 1px solid var(--border);
  background: var(--surface2);
  color: var(--text);
  font-size: 12px;
  width: 200px;
  outline: none;
}
.search-input:focus { border-color: var(--accent); }
.search-input::placeholder { color: var(--text-dim); }

.legend {
  display: flex;
  gap: 20px;
  font-size: 12px;
  color: var(--text-dim);
  align-items: center;
}
.legend span {
  display: inline-flex;
  align-items: center;
  gap: 6px;
}
.legend .dot {
  width: 10px; height: 10px;
  border-radius: 3px;
}

/* ── Responsive ────────────────────────────────────────────────────── */

@media (max-width: 900px) {
  .summary-row { grid-template-columns: repeat(2, 1fr); }
  .trend-row   { grid-template-columns: 1fr; }
  .container   { padding: 16px; }
  .topbar      { padding: 12px 16px; }
}
