:root {
  color-scheme: dark;
  --bg: #12141c;
  --card: #1b1e2b;
  --card-alt: #232739;
  --text: #f1f2f6;
  --muted: #9aa0ac;
  --faint: #6b7180;
  --accent: #17a398;
  --up: #2ec27e;
  --degraded: #f0a63d;
  --down: #f0555a;
  --unknown: #5c6273;
  --border: rgba(255, 255, 255, 0.08);
}

* { box-sizing: border-box; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  padding: 28px 24px 60px;
}

a { color: inherit; }

.wrap { max-width: 1180px; margin: 0 auto; display: flex; flex-direction: column; gap: 26px; }

h1 { font-size: 1.45rem; margin: 0; letter-spacing: -0.01em; }
.sub { color: var(--muted); font-size: 0.84rem; margin-top: 4px; }

.header-row { display: flex; justify-content: space-between; align-items: flex-start; gap: 16px; flex-wrap: wrap; }
.header-actions { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; }
.logout-link { color: var(--muted); font-size: 0.82rem; margin-left: 6px; }
.logout-link:hover { color: var(--text); }

.btn {
  border: 1px solid var(--accent);
  background: transparent;
  color: var(--accent);
  border-radius: 8px;
  padding: 8px 14px;
  font-size: 0.84rem;
  font-weight: 600;
  cursor: pointer;
  transition: background 0.15s, color 0.15s, opacity 0.15s;
  white-space: nowrap;
}
.btn:hover:not(:disabled) { background: var(--accent); color: #0a1512; }
.btn:disabled { opacity: 0.4; cursor: default; }
.btn.warn { border-color: var(--degraded); color: var(--degraded); }
.btn.warn:hover:not(:disabled) { background: var(--degraded); color: #1b1305; }
.btn.danger { border-color: var(--down); color: var(--down); }
.btn.danger:hover:not(:disabled) { background: var(--down); color: #1f0707; }
.btn.small { padding: 6px 11px; font-size: 0.78rem; }
.btn.ghost { border-color: var(--border); color: var(--muted); }
.btn.ghost:hover:not(:disabled) { background: var(--card-alt); color: var(--text); }

.stats { display: grid; grid-template-columns: repeat(4, 1fr); gap: 14px; }
.stat {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: 14px;
  padding: 16px 18px;
}
.stat .num { font-size: 1.9rem; font-weight: 700; letter-spacing: -0.02em; font-variant-numeric: tabular-nums; }
.stat .lbl { color: var(--muted); font-size: 0.8rem; margin-top: 2px; display: flex; align-items: center; gap: 7px; }

.tabs { display: flex; gap: 6px; border-bottom: 1px solid var(--border); margin-bottom: -6px; }
.tab {
  background: transparent;
  border: none;
  border-bottom: 2px solid transparent;
  color: var(--muted);
  font-size: 0.95rem;
  font-weight: 650;
  padding: 10px 16px 12px;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  gap: 8px;
  margin-bottom: -1px;
}
.tab:hover { color: var(--text); }
.tab.active { color: var(--text); border-bottom-color: var(--accent); }
.tab .badge { font-size: 0.72rem; font-weight: 700; padding: 2px 8px; border-radius: 999px; background: var(--card-alt); color: var(--muted); }
.tab .badge.bad { background: rgba(240, 85, 90, 0.15); color: var(--down); }

.group-title { font-size: 1.05rem; font-weight: 700; margin: 0 0 4px; display: flex; align-items: center; gap: 10px; }
.group-title .count { color: var(--muted); font-weight: 500; font-size: 0.85rem; }
.section-title { color: var(--muted); font-size: 0.76rem; text-transform: uppercase; letter-spacing: 0.08em; margin: 16px 0 10px; }

.grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(340px, 1fr)); gap: 14px; }

.app-card {
  background: var(--card);
  border: 1px solid var(--border);
  border-left: 3px solid var(--unknown);
  border-radius: 14px;
  padding: 16px 18px;
  display: flex;
  flex-direction: column;
  gap: 12px;
}
.app-card.up { border-left-color: var(--up); }
.app-card.degraded { border-left-color: var(--degraded); }
.app-card.down { border-left-color: var(--down); background: linear-gradient(0deg, rgba(240, 85, 90, 0.06), rgba(240, 85, 90, 0.06)), var(--card); }

.app-head { display: flex; justify-content: space-between; gap: 10px; align-items: flex-start; }
.app-name { font-weight: 650; font-size: 0.98rem; line-height: 1.3; }
.app-meta { color: var(--muted); font-size: 0.76rem; margin-top: 3px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; max-width: 260px; }
.app-meta a { text-decoration: none; }
.app-meta a:hover { text-decoration: underline; }

.pill {
  font-size: 0.72rem;
  font-weight: 700;
  padding: 4px 9px;
  border-radius: 999px;
  display: inline-flex;
  align-items: center;
  gap: 6px;
  white-space: nowrap;
  background: var(--card-alt);
}
.pill.up { color: var(--up); }
.pill.degraded { color: var(--degraded); }
.pill.down { color: var(--down); }
.pill.unknown { color: var(--muted); }

.dot { width: 8px; height: 8px; border-radius: 50%; background: var(--unknown); flex-shrink: 0; }
.dot.up { background: var(--up); }
.dot.degraded { background: var(--degraded); }
.dot.down { background: var(--down); box-shadow: 0 0 0 3px rgba(240, 85, 90, 0.2); }

.timeline { display: grid; grid-template-columns: repeat(48, 1fr); gap: 2px; height: 22px; }
.timeline span { border-radius: 2px; background: var(--card-alt); }
.timeline span.up { background: var(--up); opacity: 0.8; }
.timeline span.degraded { background: var(--degraded); }
.timeline span.down { background: var(--down); }
.timeline-legend { display: flex; justify-content: space-between; color: var(--faint); font-size: 0.68rem; margin-top: -6px; }

.metrics { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; }
.metric .v { font-size: 0.95rem; font-weight: 650; font-variant-numeric: tabular-nums; }
.metric .k { color: var(--muted); font-size: 0.7rem; margin-top: 1px; }

.procs { display: flex; flex-wrap: wrap; gap: 6px; }
.proc {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  font-size: 0.72rem;
  color: var(--muted);
  background: var(--card-alt);
  border-radius: 6px;
  padding: 4px 8px;
  max-width: 100%;
}
.proc span { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

.problem { font-size: 0.78rem; color: #ffb3b5; background: rgba(240, 85, 90, 0.08); border-radius: 8px; padding: 8px 10px; line-height: 1.4; word-break: break-word; }
.problem.unknown { color: var(--muted); background: var(--card-alt); }
.proc .q { width: 12px; text-align: center; color: var(--degraded); font-size: 0.72rem; }
.problem.degraded { color: #ffd59b; background: rgba(240, 166, 61, 0.08); }

.app-actions { display: flex; gap: 8px; justify-content: flex-end; }

.bottom { display: grid; grid-template-columns: 1fr 1fr; gap: 14px; }
.card { background: var(--card); border: 1px solid var(--border); border-radius: 14px; padding: 18px; }
.card h2 { font-size: 0.95rem; margin: 0 0 12px; }
.log { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 8px; max-height: 320px; overflow-y: auto; }
.log li { font-size: 0.8rem; display: flex; gap: 10px; align-items: baseline; }
.log .when { color: var(--faint); font-variant-numeric: tabular-nums; white-space: nowrap; min-width: 92px; }
.log .what { color: var(--text); }
.log .muted { color: var(--muted); }
.empty { color: var(--faint); font-size: 0.8rem; }

.modal-bg { position: fixed; inset: 0; background: rgba(5, 6, 10, 0.7); display: none; align-items: center; justify-content: center; padding: 16px; z-index: 10; }
.modal-bg.open { display: flex; }
.modal { background: var(--card); border: 1px solid var(--border); border-radius: 14px; padding: 22px; max-width: 420px; width: 100%; }
.modal h3 { margin: 0 0 8px; font-size: 1.05rem; }
.modal p { color: var(--muted); font-size: 0.86rem; margin: 0 0 8px; line-height: 1.45; }
.modal .warnline { color: var(--degraded); }
.modal .row { display: flex; justify-content: flex-end; gap: 8px; margin-top: 16px; }

.info-modal { max-width: 560px; max-height: calc(100vh - 32px); overflow-y: auto; }
.info-head { display: flex; justify-content: space-between; align-items: flex-start; gap: 12px; margin-bottom: 14px; }
.info-head h3 { margin: 0; }
.info-desc p { color: var(--text); font-size: 0.9rem; line-height: 1.55; margin: 0 0 10px; }
.info-list { display: grid; grid-template-columns: 130px 1fr; gap: 8px 14px; margin: 16px 0 0; padding-top: 14px; border-top: 1px solid var(--border); font-size: 0.82rem; }
.info-list dt { color: var(--muted); }
.info-list dd { margin: 0; word-break: break-word; }
.info-list code { font-size: 0.78rem; background: var(--card-alt); padding: 1px 6px; border-radius: 4px; }
@media (max-width: 520px) { .info-list { grid-template-columns: 1fr; gap: 2px; } .info-list dd { margin-bottom: 8px; } }

.toast { position: fixed; bottom: 22px; left: 50%; transform: translateX(-50%); background: var(--card-alt); border: 1px solid var(--border); border-radius: 10px; padding: 10px 16px; font-size: 0.85rem; display: none; z-index: 20; max-width: calc(100% - 32px); }
.toast.show { display: block; }
.toast.err { border-color: var(--down); color: #ffb3b5; }

.spinner { display: inline-block; width: 12px; height: 12px; border: 2px solid currentColor; border-right-color: transparent; border-radius: 50%; animation: spin 0.7s linear infinite; vertical-align: -2px; }
@keyframes spin { to { transform: rotate(360deg); } }

@media (max-width: 760px) {
  body { padding: 20px 16px 50px; }
  .stats { grid-template-columns: repeat(2, 1fr); }
  .bottom { grid-template-columns: 1fr; }
  .grid { grid-template-columns: 1fr; }
  .app-meta { max-width: 200px; }
}
