:root {
  --bg: #0b101b;
  --bg-elev: #121a2a;
  --bg-card: #162033;
  --border: #24324a;
  --text: #e6edf7;
  --muted: #8ea0bc;
  --ok: #22c55e;
  --ok-bg: rgba(34, 197, 94, 0.14);
  --warn: #f59e0b;
  --warn-bg: rgba(245, 158, 11, 0.14);
  --down: #ef4444;
  --down-bg: rgba(239, 68, 68, 0.16);
  --unconf: #64748b;
  --unconf-bg: rgba(100, 116, 139, 0.18);
  --accent: #38bdf8;
  --radius: 14px;
}

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

body {
  font-family: "Inter", "Segoe UI", system-ui, -apple-system, sans-serif;
  background: radial-gradient(circle at top right, #13223a 0%, var(--bg) 52%);
  color: var(--text);
  min-height: 100vh;
  line-height: 1.45;
}

.app-shell {
  max-width: 1440px;
  margin: 0 auto;
  padding: 20px 24px 36px;
}

/* TOPBAR */
.topbar {
  display: flex;
  flex-wrap: wrap;
  justify-content: space-between;
  align-items: center;
  gap: 16px;
  padding: 16px 20px;
  background: rgba(18, 26, 42, 0.85);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  backdrop-filter: blur(10px);
  margin-bottom: 20px;
}

.brand { display: flex; align-items: center; gap: 14px; }
.brand-logo {
  width: 44px;
  height: 44px;
  border-radius: 12px;
  background: linear-gradient(135deg, #f59e0b, #ea580c);
  color: #0b101b;
  font-weight: 900;
  font-size: 18px;
  display: grid;
  place-items: center;
  letter-spacing: 0.5px;
}
.brand-title { font-size: 18px; font-weight: 800; display: flex; align-items: center; gap: 8px; }
.brand-tag {
  font-size: 11px;
  font-weight: 700;
  background: rgba(56, 189, 248, 0.16);
  color: var(--accent);
  padding: 2px 7px;
  border-radius: 6px;
}
.brand-sub { font-size: 12.5px; color: var(--muted); }

.topbar-actions { display: flex; flex-wrap: wrap; align-items: center; gap: 10px; }

.status-pill {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  padding: 7px 13px;
  border-radius: 999px;
  font-size: 13px;
  font-weight: 700;
  border: 1px solid transparent;
}
.status-pill .dot {
  width: 9px;
  height: 9px;
  border-radius: 50%;
  background: currentColor;
  box-shadow: 0 0 10px currentColor;
}
.status-ok { color: var(--ok); background: var(--ok-bg); border-color: rgba(34, 197, 94, 0.35); }
.status-warn { color: var(--warn); background: var(--warn-bg); border-color: rgba(245, 158, 11, 0.35); }
.status-down { color: var(--down); background: var(--down-bg); border-color: rgba(239, 68, 68, 0.45); }

/* MODE SWITCH */
.mode-switch {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  padding: 6px 10px;
  border-radius: 10px;
  background: var(--bg-card);
  border: 1px solid var(--border);
  cursor: pointer;
  user-select: none;
}
.mode-switch input { display: none; }
.mode-switch .slider {
  width: 32px;
  height: 18px;
  background: #334155;
  border-radius: 999px;
  position: relative;
  transition: background 0.2s;
}
.mode-switch .slider::after {
  content: "";
  position: absolute;
  top: 2px;
  left: 2px;
  width: 14px;
  height: 14px;
  background: #fff;
  border-radius: 50%;
  transition: transform 0.2s;
}
.mode-switch input:checked + .slider { background: var(--accent); }
.mode-switch input:checked + .slider::after { transform: translateX(14px); }
.mode-label { font-size: 12px; font-weight: 700; color: var(--text); }

/* BUTTONS */
.btn {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 8px 13px;
  border-radius: 10px;
  border: 1px solid var(--border);
  background: var(--bg-card);
  color: var(--text);
  font-size: 13px;
  font-weight: 600;
  cursor: pointer;
  text-decoration: none;
  transition: transform 0.12s, background 0.15s, border-color 0.15s;
}
.btn:hover { background: #1e2c45; border-color: #3a4f73; }
.btn:active { transform: scale(0.98); }
.btn:disabled { opacity: 0.55; cursor: wait; }
.btn-primary { background: #0284c7; border-color: #0ea5e9; color: #fff; }
.btn-primary:hover { background: #0369a1; }
.btn-warning { background: rgba(245, 158, 11, 0.16); border-color: rgba(245, 158, 11, 0.4); color: #fbbf24; }
.btn-warning:hover { background: rgba(245, 158, 11, 0.26); }
.btn-ghost { background: transparent; }
.btn-sm { padding: 5px 10px; font-size: 12px; border-radius: 8px; }
.hidden { display: none !important; }

/* KPI GRID */
.kpi-grid {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 14px;
  margin-bottom: 24px;
}
.kpi-card {
  background: var(--bg-elev);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 16px 18px;
}
.kpi-label { font-size: 12px; color: var(--muted); text-transform: uppercase; letter-spacing: 0.6px; }
.kpi-value { font-size: 28px; font-weight: 800; margin: 6px 0 4px; letter-spacing: -0.5px; }
.kpi-sub { font-size: 12.5px; color: var(--muted); }

/* SECTIONS */
.panel-section { margin-bottom: 26px; }
.section-header {
  display: flex;
  justify-content: space-between;
  align-items: flex-end;
  margin-bottom: 12px;
  gap: 12px;
}
.section-header h2 { font-size: 17px; font-weight: 800; }
.section-header p { font-size: 13px; color: var(--muted); margin-top: 2px; }
.section-count {
  font-size: 12px;
  color: var(--muted);
  background: var(--bg-elev);
  border: 1px solid var(--border);
  padding: 4px 10px;
  border-radius: 999px;
}

.cards-grid {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 14px;
}

/* SERVICE CARD */
.service-card {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 16px;
  display: flex;
  flex-direction: column;
  gap: 10px;
  position: relative;
  transition: border-color 0.2s, transform 0.15s;
}
.service-card:hover { border-color: #3b527a; transform: translateY(-1px); }
.service-card.state-down { border-color: rgba(239, 68, 68, 0.7); box-shadow: 0 0 0 1px rgba(239, 68, 68, 0.25); }
.service-card.state-warn { border-color: rgba(245, 158, 11, 0.6); }

.card-top { display: flex; justify-content: space-between; align-items: flex-start; gap: 8px; }
.card-title-wrap { display: flex; flex-direction: column; gap: 2px; }
.card-title { font-size: 15px; font-weight: 700; display: flex; align-items: center; gap: 7px; }
.card-num { font-size: 11px; color: var(--muted); font-weight: 700; }
.card-sub { font-size: 12px; color: var(--muted); }

.badges { display: flex; align-items: center; gap: 5px; flex-shrink: 0; }
.badge {
  font-size: 10.5px;
  font-weight: 700;
  padding: 3px 8px;
  border-radius: 999px;
  text-transform: uppercase;
  letter-spacing: 0.4px;
}
.badge-ok { background: var(--ok-bg); color: var(--ok); }
.badge-warn { background: var(--warn-bg); color: var(--warn); }
.badge-down { background: var(--down-bg); color: var(--down); }
.badge-unconfigured { background: var(--unconf-bg); color: #94a3b8; }
.badge-demo { background: rgba(56, 189, 248, 0.14); color: var(--accent); }
.badge-sim { background: rgba(168, 85, 247, 0.22); color: #d8b4fe; }

/* FINANCE METRIC */
.metric-row { display: flex; justify-content: space-between; align-items: baseline; gap: 10px; }
.metric-main { font-size: 24px; font-weight: 800; letter-spacing: -0.5px; }
.metric-main.text-down { color: var(--down); }
.metric-main.text-warn { color: var(--warn); }
.metric-main.text-ok { color: var(--text); }
.metric-meta { font-size: 12px; color: var(--muted); text-align: right; }

.progress-track {
  height: 7px;
  background: #0d1524;
  border-radius: 999px;
  overflow: hidden;
  border: 1px solid rgba(255, 255, 255, 0.05);
}
.progress-fill { height: 100%; border-radius: 999px; transition: width 0.35s ease; }
.fill-ok { background: linear-gradient(90deg, #16a34a, #22c55e); }
.fill-warn { background: linear-gradient(90deg, #d97706, #f59e0b); }
.fill-down { background: linear-gradient(90deg, #dc2626, #ef4444); }

.card-message {
  font-size: 12.5px;
  color: #cbd5e1;
  background: rgba(11, 16, 27, 0.55);
  border: 1px solid rgba(255, 255, 255, 0.05);
  border-radius: 9px;
  padding: 8px 10px;
  min-height: 38px;
}

/* HISTORY BARS (UPTIME KUMA STYLE) */
.uptime-strip {
  display: flex;
  align-items: center;
  gap: 3px;
  height: 16px;
}
.uptime-bar {
  flex: 1;
  height: 100%;
  border-radius: 3px;
  background: #233047;
}
.uptime-bar.ok { background: var(--ok); }
.uptime-bar.warn { background: var(--warn); }
.uptime-bar.down { background: var(--down); }

.card-footer {
  display: flex;
  justify-content: space-between;
  align-items: center;
  font-size: 11.5px;
  color: var(--muted);
  margin-top: auto;
  padding-top: 6px;
  border-top: 1px solid rgba(255, 255, 255, 0.05);
}

/* BOTTOM GRID */
.bottom-grid {
  display: grid;
  grid-template-columns: 1.25fr 1fr;
  gap: 16px;
}
.panel-box {
  background: var(--bg-elev);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 16px 18px;
}
.box-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 12px;
}
.box-header h3 { font-size: 15px; font-weight: 700; }

.alerts-list {
  display: flex;
  flex-direction: column;
  gap: 8px;
  max-height: 320px;
  overflow-y: auto;
}
.alert-item {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  padding: 10px 12px;
  border-radius: 10px;
  background: var(--bg-card);
  border-left: 3px solid var(--muted);
  font-size: 12.5px;
}
.alert-item.sev-critical { border-left-color: var(--down); }
.alert-item.sev-warning { border-left-color: var(--warn); }
.alert-item.sev-recovery { border-left-color: var(--ok); }
.alert-time { color: var(--muted); font-size: 11.5px; white-space: nowrap; }

.config-matrix {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 8px;
}
.cfg-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 8px 10px;
  background: var(--bg-card);
  border-radius: 9px;
  font-size: 12px;
}
.mini-pill {
  font-size: 11px;
  font-weight: 700;
  padding: 2px 8px;
  border-radius: 999px;
  background: var(--unconf-bg);
  color: var(--muted);
}
.mini-pill.ok { background: var(--ok-bg); color: var(--ok); }

.footer {
  margin-top: 24px;
  display: flex;
  justify-content: space-between;
  font-size: 12px;
  color: var(--muted);
}

.toast {
  position: fixed;
  right: 22px;
  bottom: 22px;
  background: #1e293b;
  border: 1px solid #38bdf8;
  color: #f8fafc;
  padding: 12px 16px;
  border-radius: 12px;
  font-size: 13px;
  font-weight: 600;
  box-shadow: 0 10px 30px rgba(0, 0, 0, 0.45);
  z-index: 999;
}

@media (max-width: 1100px) {
  .cards-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .kpi-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .bottom-grid { grid-template-columns: 1fr; }
}
@media (max-width: 680px) {
  .cards-grid, .kpi-grid, .config-matrix { grid-template-columns: 1fr; }
}
