/* Theme tokens: light by default, dark via system preference (auto) or an explicit choice. */
:root {
  --bg: #f4f5f8; --surface: #ffffff; --surface-2: #f0f2f6; --text: #171b26; --muted: #5f6779; --faint: #9aa1b1;
  --line: #e4e7ee; --accent: #4f5bd5; --accent-text: #ffffff; --focus: #4f5bd566;
  --up: #16a34a; --up-bg: #16a34a1a; --degraded: #d97706; --degraded-bg: #d977061f;
  --down: #dc2626; --down-bg: #dc26261a; --unknown: #8b93a5; --unknown-bg: #8b93a51f;
  --shadow: 0 1px 2px #1018280d, 0 1px 3px #1018281a; --shadow-hover: 0 4px 14px #10182814;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #0e1117; --surface: #161b24; --surface-2: #1d2330; --text: #e7eaf0; --muted: #98a0b3; --faint: #5d6578;
    --line: #262d3b; --accent: #8a94ff; --accent-text: #0e1117; --focus: #8a94ff66;
    --up: #34d27b; --up-bg: #34d27b1f; --degraded: #fbbf24; --degraded-bg: #fbbf241f;
    --down: #ff6b6b; --down-bg: #ff6b6b24; --unknown: #6b7387; --unknown-bg: #6b738726;
    --shadow: 0 1px 2px #0000004d; --shadow-hover: 0 6px 18px #00000059;
    color-scheme: dark;
  }
}
:root[data-theme="dark"] {
  --bg: #0e1117; --surface: #161b24; --surface-2: #1d2330; --text: #e7eaf0; --muted: #98a0b3; --faint: #5d6578;
  --line: #262d3b; --accent: #8a94ff; --accent-text: #0e1117; --focus: #8a94ff66;
  --up: #34d27b; --up-bg: #34d27b1f; --degraded: #fbbf24; --degraded-bg: #fbbf241f;
  --down: #ff6b6b; --down-bg: #ff6b6b24; --unknown: #6b7387; --unknown-bg: #6b738726;
  --shadow: 0 1px 2px #0000004d; --shadow-hover: 0 6px 18px #00000059;
  color-scheme: dark;
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0; background: var(--bg); color: var(--text);
  font: 15px/1.5 ui-sans-serif, system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial,
        "Apple Color Emoji", "Segoe UI Emoji", "Noto Color Emoji", sans-serif;
}
a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }
:focus-visible { outline: 3px solid var(--focus); outline-offset: 2px; border-radius: 6px; }
h1 { font-size: 1.6rem; line-height: 1.2; margin: 0; letter-spacing: -.01em; display: flex; align-items: center; gap: 12px; flex-wrap: wrap; }
h2 { font-size: 1rem; margin: 0; }
.muted { color: var(--muted); } .faint { color: var(--faint); }
main { max-width: 1120px; margin: 0 auto; padding: 28px 16px 64px; }

/* Header */
.top { position: sticky; top: 0; z-index: 10; background: color-mix(in srgb, var(--surface) 88%, transparent);
  backdrop-filter: saturate(1.4) blur(10px); border-bottom: 1px solid var(--line); }
.top-inner { max-width: 1120px; margin: 0 auto; padding: 10px 16px; display: flex; align-items: center; gap: 24px; }
.brand { display: flex; align-items: center; gap: 10px; font-weight: 700; font-size: 1.05rem; color: var(--text); }
.brand:hover { text-decoration: none; }
.logo { width: 24px; height: 24px; border-radius: 7px; background: var(--accent); position: relative; flex: none; }
.logo::after { content: ""; position: absolute; inset: 7px; border-radius: 50%; background: var(--accent-text); }
.logo.big { width: 48px; height: 48px; border-radius: 14px; margin: 0 auto 16px; display: block; }
.logo.big::after { inset: 15px; }
.tabs { display: flex; gap: 4px; }
.tabs a { color: var(--muted); padding: 6px 12px; border-radius: 8px; font-weight: 500; }
.tabs a:hover { background: var(--surface-2); color: var(--text); text-decoration: none; }
.tabs a[aria-current="page"] { color: var(--text); background: var(--surface-2); }
.top-right { margin-left: auto; display: flex; align-items: center; gap: 12px; }
.who { display: flex; align-items: center; gap: 10px; font-size: .9rem; }
.who form { margin: 0; }
.avatar { width: 30px; height: 30px; border-radius: 50%; display: grid; place-items: center; font-weight: 600; font-size: .85rem;
  background: var(--surface-2); color: var(--text); border: 1px solid var(--line); }
button.link { background: none; border: 0; color: var(--muted); cursor: pointer; font: inherit; padding: 4px 0; }
button.link:hover { color: var(--text); }
.icon-btn { width: 34px; height: 34px; display: grid; place-items: center; border-radius: 8px; border: 1px solid var(--line);
  background: var(--surface); color: var(--muted); cursor: pointer; padding: 0; }
.icon-btn:hover { color: var(--text); background: var(--surface-2); }
.icon-btn svg { width: 18px; height: 18px; display: none; }
#theme-toggle[data-mode="auto"] .i-auto, #theme-toggle[data-mode="light"] .i-light, #theme-toggle[data-mode="dark"] .i-dark,
#theme-toggle:not([data-mode]) .i-auto { display: block; }
.pill { font-size: .72rem; font-weight: 600; padding: 2px 8px; border-radius: 999px; }
.pill.warn { background: var(--degraded-bg); color: var(--degraded); }

/* Building blocks */
.card { background: var(--surface); border: 1px solid var(--line); border-radius: 14px; padding: 18px; box-shadow: var(--shadow); margin-bottom: 16px; }
.card.flush { padding: 0; overflow: hidden; }
.card.narrow { max-width: 420px; margin: 10vh auto 0; }
.center { text-align: center; }
.center h1 { justify-content: center; margin-bottom: 8px; }
.card-head { display: flex; align-items: baseline; justify-content: space-between; gap: 12px; margin-bottom: 14px; flex-wrap: wrap; }
.card-head.pad, .pad { padding: 16px 18px; margin: 0; }
.button { display: inline-block; margin-top: 12px; background: var(--accent); color: var(--accent-text); padding: 10px 22px;
  border-radius: 10px; font-weight: 600; }
.button:hover { text-decoration: none; filter: brightness(1.08); }
.button.secondary { background: var(--surface-2); color: var(--text); }
.page-head { display: flex; align-items: baseline; justify-content: space-between; gap: 12px; flex-wrap: wrap; margin-bottom: 18px; }
.section { color: var(--muted); font-size: .8rem; text-transform: uppercase; letter-spacing: .06em; margin: 32px 0 12px; }
.section.first { margin-top: 8px; }

.dot { display: inline-block; width: 9px; height: 9px; border-radius: 50%; background: var(--unknown); flex: none; }
.dot.up { background: var(--up); }
.dot.degraded { background: var(--degraded); }
.dot.down { background: var(--down); box-shadow: 0 0 0 3px var(--down-bg); animation: pulse 2s ease-in-out infinite; }
@keyframes pulse { 50% { box-shadow: 0 0 0 6px transparent; } }
@media (prefers-reduced-motion: reduce) { .dot.down { animation: none; } }

.badge { display: inline-flex; align-items: center; gap: 6px; font-size: .78rem; font-weight: 600; padding: 3px 10px 3px 8px;
  border-radius: 999px; white-space: nowrap; letter-spacing: 0; }
.badge.up { background: var(--up-bg); color: var(--up); }
.badge.degraded { background: var(--degraded-bg); color: var(--degraded); }
.badge.down { background: var(--down-bg); color: var(--down); }
.badge.unknown { background: var(--unknown-bg); color: var(--muted); }
.badge .dot { width: 7px; height: 7px; animation: none; box-shadow: none; }

.app-icon { width: 42px; height: 42px; border-radius: 11px; display: grid; place-items: center; flex: none; font-size: 22px; line-height: 1;
  background: var(--surface-2); }
.app-icon.letter { font-size: 18px; font-weight: 700; color: hsl(var(--h) 55% 45%); background: hsl(var(--h) 70% 50% / .14); }

/* Summary */
.summary { display: grid; grid-template-columns: repeat(4, 1fr); gap: 12px; margin-bottom: 20px; }
.stat { background: var(--surface); border: 1px solid var(--line); border-radius: 14px; padding: 14px 16px; box-shadow: var(--shadow);
  display: flex; flex-direction: column; gap: 2px; }
.stat .num { font-size: 1.7rem; font-weight: 700; line-height: 1.1; font-variant-numeric: tabular-nums; }
.stat .lbl { display: flex; align-items: center; gap: 7px; color: var(--muted); font-size: .85rem; }
.stat.is-down { border-color: color-mix(in srgb, var(--down) 45%, var(--line)); background: linear-gradient(var(--down-bg), var(--down-bg)), var(--surface); }
.stat.is-down .num { color: var(--down); }
.stat.is-degraded .num { color: var(--degraded); }

/* Tiles: names wrap, never truncated */
.tiles { list-style: none; padding: 0; margin: 0; display: grid; grid-template-columns: repeat(auto-fill, minmax(230px, 1fr)); gap: 12px; }
.tile a { display: flex; align-items: center; gap: 12px; height: 100%; padding: 14px; color: var(--text);
  background: var(--surface); border: 1px solid var(--line); border-radius: 14px; box-shadow: var(--shadow);
  transition: transform .12s ease, box-shadow .12s ease, border-color .12s ease; }
.tile a:hover { text-decoration: none; transform: translateY(-1px); box-shadow: var(--shadow-hover); border-color: color-mix(in srgb, var(--accent) 40%, var(--line)); }
.tile-text { display: flex; flex-direction: column; min-width: 0; flex: 1; }
.tile .name { font-weight: 600; overflow-wrap: anywhere; line-height: 1.3; }
.tile .host { color: var(--muted); font-size: .8rem; overflow-wrap: anywhere; }
.tile .dot { align-self: flex-start; margin-top: 4px; }
.tile.down a { border-color: color-mix(in srgb, var(--down) 50%, var(--line)); background: linear-gradient(var(--down-bg), var(--down-bg)), var(--surface); }
.tile.degraded a { border-color: color-mix(in srgb, var(--degraded) 45%, var(--line)); }
.tiles.compact { grid-template-columns: repeat(auto-fill, minmax(210px, 1fr)); }
.tiles.compact .app-icon { width: 34px; height: 34px; font-size: 18px; border-radius: 9px; }
.tiles.compact a { padding: 10px 12px; }

/* Tables */
table { border-collapse: collapse; width: 100%; font-size: .9rem; }
th, td { text-align: left; padding: 11px 14px; border-bottom: 1px solid var(--line); vertical-align: middle; }
th { color: var(--muted); font-weight: 500; font-size: .76rem; text-transform: uppercase; letter-spacing: .05em; background: var(--surface-2); }
tbody tr:last-child td { border-bottom: 0; }
tbody tr:hover td { background: color-mix(in srgb, var(--surface-2) 60%, transparent); }
th.num, td.num { text-align: right; font-variant-numeric: tabular-nums; white-space: nowrap; }
tr.row-down td:first-child { box-shadow: inset 3px 0 0 var(--down); }
tr.row-degraded td:first-child { box-shadow: inset 3px 0 0 var(--degraded); }
.app-cell { display: flex; align-items: center; gap: 12px; color: var(--text); }
.app-cell:hover { text-decoration: none; }
.app-cell:hover .name { color: var(--accent); }
.app-cell .app-icon { width: 32px; height: 32px; font-size: 17px; border-radius: 8px; }
.app-cell > span:last-child { display: flex; flex-direction: column; }
.app-cell .name { font-weight: 600; }
.reason { color: var(--muted); font-size: .82rem; }
.row-down .reason, .reason.big { color: var(--down); }
.row-degraded .reason { color: var(--degraded); }
.reason.big { font-size: .95rem; margin: 6px 0 0; font-weight: 500; }
.sig.down { color: var(--down); font-weight: 500; } .sig.degraded { color: var(--degraded); font-weight: 500; } .sig.unknown { color: var(--muted); }
.sub { color: var(--faint); font-size: .8rem; margin-left: 6px; font-variant-numeric: tabular-nums; }

/* Detail */
.back { display: inline-block; color: var(--muted); font-size: .9rem; margin-bottom: 16px; }
.detail-head { display: flex; gap: 16px; align-items: flex-start; margin-bottom: 22px; }
.detail-head .app-icon { width: 56px; height: 56px; font-size: 30px; border-radius: 14px; }
.detail-head p { margin: 4px 0 0; }
.grid-3 { display: grid; grid-template-columns: repeat(auto-fill, minmax(220px, 1fr)); gap: 12px; margin-bottom: 4px; }
.grid-3 .card { margin-bottom: 12px; }
.signal { display: flex; flex-direction: column; gap: 2px; border-top: 3px solid var(--up); }
.signal.degraded { border-top-color: var(--degraded); } .signal.down { border-top-color: var(--down); } .signal.unknown { border-top-color: var(--unknown); }
.signal .lbl { color: var(--muted); font-size: .78rem; text-transform: uppercase; letter-spacing: .05em; }
.signal .val { font-weight: 600; }
.signal .sub { margin: 0; }
.bars { display: flex; gap: 3px; height: 40px; }
.bar { flex: 1; border-radius: 4px; background: var(--surface-2); transition: transform .1s; }
.bar:hover { transform: scaleY(1.1); }
.bar.good { background: var(--up); } .bar.warn { background: var(--degraded); } .bar.bad { background: var(--down); }
.bar-axis { display: flex; justify-content: space-between; color: var(--faint); font-size: .75rem; margin-top: 6px; }

/* Small screens */
@media (max-width: 860px) { .hide-md { display: none; } }
@media (max-width: 640px) {
  main { padding-top: 20px; }
  .top-inner { gap: 12px; }
  .hide-sm { display: none; }
  .summary { grid-template-columns: repeat(2, 1fr); }
  .tiles, .tiles.compact { grid-template-columns: 1fr; }
  th, td { padding: 10px; }
  h1 { font-size: 1.35rem; }
}
