:root {
  --bg: #f1f5f9;
  --bg2: #ffffff;
  --card: #ffffff;
  --border: rgba(15, 23, 42, 0.08);
  --text: #0f172a;
  --muted: #64748b;
  --up: #059669;
  --degraded: #d97706;
  --down: #dc2626;
  --unknown: #64748b;
  --brand: #0f172a;
  --mono: "JetBrains Mono", ui-monospace, monospace;
  --sans: "Plus Jakarta Sans", "Outfit", system-ui, sans-serif;
  --shadow: 0 1px 3px rgba(15, 23, 42, 0.06), 0 4px 12px rgba(15, 23, 42, 0.04);
}

* { box-sizing: border-box; }
html, body {
  margin: 0;
  min-height: 100%;
  background: var(--bg);
  color: var(--text);
  font-family: var(--sans);
  -webkit-font-smoothing: antialiased;
}

.hidden { display: none !important; }

.login-screen {
  min-height: 100vh;
  display: grid;
  place-items: center;
  background:
    radial-gradient(circle at 20% 20%, rgba(15, 23, 42, 0.04), transparent 40%),
    var(--bg);
}

.login-card {
  width: min(420px, 92vw);
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: 1rem;
  padding: 2rem;
  display: flex;
  flex-direction: column;
  gap: 1rem;
  box-shadow: var(--shadow);
}

.login-badge {
  font: 700 0.65rem var(--mono);
  letter-spacing: 0.16em;
  color: var(--muted);
}

.login-card h1 { margin: 0; font-size: 1.5rem; font-weight: 800; }
.login-card p { margin: 0; color: var(--muted); font-size: 0.9rem; }
.login-card label {
  display: flex;
  flex-direction: column;
  gap: 0.35rem;
  font-size: 0.8rem;
  font-weight: 600;
  color: var(--muted);
}
.login-card input {
  background: #fff;
  border: 1px solid #e2e8f0;
  border-radius: 0.75rem;
  padding: 0.75rem 0.9rem;
  color: var(--text);
  font: inherit;
}
.login-card input:focus {
  outline: none;
  border-color: #0f172a;
  box-shadow: 0 0 0 2px rgba(15, 23, 42, 0.08);
}
.login-card button {
  margin-top: 0.5rem;
  border: none;
  border-radius: 0.75rem;
  padding: 0.85rem;
  background: #0f172a;
  color: white;
  font: 700 0.95rem var(--sans);
  cursor: pointer;
  transition: background 0.15s ease;
}
.login-card button:hover { background: #1e293b; }
.login-error { color: var(--down); font-size: 0.85rem; }

.app {
  max-width: 1400px;
  margin: 0 auto;
  padding: 1rem 1.25rem 1.5rem;
  opacity: 0;
  animation: fadeIn 0.35s ease forwards;
}
@keyframes fadeIn {
  from { opacity: 0; transform: translateY(4px); }
  to { opacity: 1; transform: none; }
}

.topbar {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  margin-bottom: 1rem;
  flex-wrap: wrap;
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: 1rem;
  padding: 0.85rem 1rem;
  box-shadow: var(--shadow);
}

.brand { display: flex; align-items: center; gap: 0.75rem; flex: 1; min-width: 0; }
.brand h1 { margin: 0; font-size: 1.05rem; font-weight: 800; letter-spacing: -0.02em; }
.brand p { margin: 0.1rem 0 0; color: var(--muted); font-size: 0.75rem; }

.pulse-dot {
  width: 10px;
  height: 10px;
  border-radius: 50%;
  background: var(--up);
  box-shadow: 0 0 0 0 rgba(5, 150, 105, 0.45);
  animation: pulse 2s infinite;
  flex-shrink: 0;
}
@keyframes pulse {
  0% { box-shadow: 0 0 0 0 rgba(5, 150, 105, 0.4); }
  70% { box-shadow: 0 0 0 8px rgba(5, 150, 105, 0); }
  100% { box-shadow: 0 0 0 0 rgba(5, 150, 105, 0); }
}

.overall-pill {
  padding: 0.45rem 0.85rem;
  border-radius: 999px;
  font: 700 0.72rem var(--sans);
  letter-spacing: 0.06em;
  border: 1px solid transparent;
}
.overall-pill.up { background: #ecfdf5; color: var(--up); border-color: #a7f3d0; }
.overall-pill.degraded { background: #fffbeb; color: var(--degraded); border-color: #fde68a; }
.overall-pill.down { background: #fef2f2; color: var(--down); border-color: #fecaca; }
.overall-pill.unknown { background: #f8fafc; color: var(--unknown); border-color: #e2e8f0; }

.btn-ghost {
  background: #fff;
  border: 1px solid #e2e8f0;
  color: var(--muted);
  border-radius: 0.65rem;
  padding: 0.45rem 0.75rem;
  font-size: 0.8rem;
  font-weight: 600;
  cursor: pointer;
  transition: all 0.15s ease;
}
.btn-ghost:hover { background: #f8fafc; color: var(--text); border-color: #cbd5e1; }

.stats-row {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 0.65rem;
  margin-bottom: 0.65rem;
}
.stat-card {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: 1rem;
  padding: 0.85rem 1rem;
  box-shadow: var(--shadow);
}
.stat-card .label {
  color: var(--muted);
  font-size: 0.68rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.07em;
}
.stat-card .value {
  font: 800 1.45rem var(--sans);
  margin-top: 0.15rem;
  letter-spacing: -0.03em;
}

.infra-grid {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 0.65rem;
  margin-bottom: 0.85rem;
}
.infra-card {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: 1rem;
  padding: 0.85rem 1rem;
  position: relative;
  overflow: hidden;
  box-shadow: var(--shadow);
}
.infra-card::before {
  content: "";
  position: absolute;
  inset: 0 auto 0 0;
  width: 3px;
  background: #cbd5e1;
  border-radius: 3px 0 0 3px;
}
.infra-card.up::before { background: var(--up); }
.infra-card.degraded::before { background: var(--degraded); }
.infra-card.down::before { background: var(--down); }
.infra-card h3 { margin: 0 0 0.35rem; font-size: 0.88rem; font-weight: 800; }
.infra-card .meta { color: var(--muted); font-size: 0.76rem; line-height: 1.55; }

.layout {
  display: grid;
  grid-template-columns: 1fr 300px;
  gap: 0.75rem;
  align-items: start;
}

.panel-head {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  margin-bottom: 0.65rem;
  padding: 0 0.15rem;
}
.panel-head h2 { margin: 0; font-size: 0.92rem; font-weight: 800; }
.muted { color: var(--muted); font-size: 0.72rem; font-weight: 600; }

.services-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(220px, 1fr));
  gap: 0.65rem;
}

.service-card {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: 1rem;
  padding: 0.8rem 0.9rem;
  box-shadow: var(--shadow);
  transition: border-color 0.15s ease, box-shadow 0.15s ease;
}
.service-card:hover {
  border-color: rgba(15, 23, 42, 0.12);
  box-shadow: 0 4px 14px rgba(15, 23, 42, 0.07);
}
.service-card .head { display: flex; justify-content: space-between; gap: 0.5rem; align-items: start; }
.service-card h3 { margin: 0; font-size: 0.88rem; font-weight: 800; }
.service-card .group {
  color: var(--muted);
  font-size: 0.65rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  margin-top: 0.1rem;
}
.status-chip {
  font: 700 0.62rem var(--sans);
  letter-spacing: 0.05em;
  padding: 0.2rem 0.45rem;
  border-radius: 999px;
  white-space: nowrap;
}
.status-chip.up { background: #ecfdf5; color: var(--up); }
.status-chip.degraded { background: #fffbeb; color: var(--degraded); }
.status-chip.down { background: #fef2f2; color: var(--down); }
.status-chip.unknown { background: #f1f5f9; color: var(--unknown); }

.service-card .lines {
  margin-top: 0.55rem;
  display: flex;
  flex-direction: column;
  gap: 0.2rem;
  font-size: 0.72rem;
  color: var(--muted);
  line-height: 1.45;
}
.service-card .lines a { color: #2563eb; font-weight: 600; text-decoration: none; }
.service-card .lines a:hover { text-decoration: underline; }

.incidents-panel {
  position: sticky;
  top: 0.75rem;
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: 1rem;
  padding: 0.85rem;
  max-height: calc(100vh - 1.5rem);
  overflow: hidden;
  display: flex;
  flex-direction: column;
  box-shadow: var(--shadow);
}

.incidents-list {
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  gap: 0.45rem;
  padding-right: 0.15rem;
}

.incident-item {
  border: 1px solid #e2e8f0;
  border-radius: 0.75rem;
  padding: 0.6rem 0.7rem;
  background: #f8fafc;
  animation: slideIn 0.25s ease;
}
@keyframes slideIn {
  from { opacity: 0; transform: translateY(-4px); }
  to { opacity: 1; transform: none; }
}
.incident-item .time { color: var(--muted); font-size: 0.65rem; font-weight: 600; }
.incident-item .msg { margin-top: 0.2rem; font-size: 0.8rem; line-height: 1.4; color: var(--text); }
.incident-item.down .msg { color: #b91c1c; }
.incident-item.degraded .msg { color: #b45309; }

.toast-stack {
  position: fixed;
  right: 1rem;
  bottom: 1rem;
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
  z-index: 1000;
}
.toast {
  min-width: 280px;
  max-width: 420px;
  background: #fff;
  border: 1px solid #e2e8f0;
  border-left: 4px solid var(--down);
  border-radius: 0.75rem;
  padding: 0.75rem 0.9rem;
  box-shadow: 0 12px 32px rgba(15, 23, 42, 0.12);
  animation: slideIn 0.2s ease;
}
.toast.degraded { border-left-color: var(--degraded); }
.toast.up { border-left-color: var(--up); }
.toast .title {
  font: 700 0.68rem var(--sans);
  text-transform: uppercase;
  letter-spacing: 0.07em;
  color: var(--muted);
}
.toast .body { margin-top: 0.25rem; font-size: 0.85rem; color: var(--text); }

/* ─── Embed mode (dashboard Settings iframe) ─── */
body.is-embed {
  background: #f1f5f9;
}
body.is-embed .app {
  max-width: none;
  padding: 0.5rem 0.65rem 1rem;
  animation: none;
  opacity: 1;
}
body.is-embed .topbar {
  margin-bottom: 0.65rem;
  padding: 0.65rem 0.85rem;
  border-radius: 0.85rem;
}
body.is-embed .brand h1 { font-size: 0.95rem; }
body.is-embed .btn-logout { display: none !important; }
body.is-embed .layout {
  grid-template-columns: 1fr;
  gap: 0.65rem;
}
body.is-embed .incidents-panel {
  position: static;
  max-height: 280px;
}
body.is-embed .services-grid {
  grid-template-columns: repeat(auto-fill, minmax(200px, 1fr));
}
body.is-embed .stats-row,
body.is-embed .infra-grid {
  gap: 0.5rem;
}

@media (max-width: 1100px) {
  .layout { grid-template-columns: 1fr; }
  .incidents-panel { position: static; max-height: 360px; }
  .stats-row, .infra-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
}

@media (max-width: 640px) {
  .stats-row, .infra-grid { grid-template-columns: 1fr 1fr; }
  .app { padding: 0.75rem; }
}
