:root {
  color-scheme: light;
  --bg: #f4f5f7;
  --panel: #ffffff;
  --text: #1b1f24;
  --muted: #5f6873;
  --faint: #8b939c;
  --line: #e3e6ea;
  --hover: #f1f3f5;
  --online: #1f9d55;
  --online-bg: #e3f5ea;
  --offline: #d64040;
  --offline-bg: #fbe7e7;
  --unknown: #c3c8ce;
  --unknown-text: #6b7480;
  --unknown-bg: #eceef1;
  --accent: #2f6fd6;
  --shadow: 0 1px 2px rgb(0 0 0 / 0.05), 0 1px 1px rgb(0 0 0 / 0.03);
}
@media (prefers-color-scheme: dark) {
  :root {
    color-scheme: dark;
    --bg: #111317;
    --panel: #1a1d22;
    --text: #e6e8eb;
    --muted: #a0a7b0;
    --faint: #737b85;
    --line: #2a2f36;
    --hover: #22262c;
    --online: #3ccf7a;
    --online-bg: #15301f;
    --offline: #f06565;
    --offline-bg: #3a1a1a;
    --unknown: #4a5059;
    --unknown-text: #a0a7b0;
    --unknown-bg: #262a30;
    --accent: #6ea0ff;
    --shadow: none;
  }
}

* { box-sizing: border-box; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 14px/1.45 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
}
.wrap { max-width: 1240px; margin: 0 auto; padding: 24px 20px 40px; }
h1, h2, h3 { margin: 0; font-weight: 600; }
.label { font-size: 12px; color: var(--muted); text-transform: uppercase; letter-spacing: 0.04em; }
.empty { color: var(--faint); margin: 8px 0; }
[hidden] { display: none !important; }

/* Hero */
.hero {
  display: grid;
  grid-template-columns: 1fr auto auto;
  gap: 32px;
  align-items: center;
  background: var(--panel);
  border: 1px solid var(--line);
  border-left: 5px solid var(--state);
  border-radius: 12px;
  padding: 20px 24px;
  box-shadow: var(--shadow);
  --state: var(--unknown);
  --state-bg: var(--unknown-bg);
  --state-text: var(--unknown-text);
}
.hero[data-state="online"] { --state: var(--online); --state-bg: var(--online-bg); --state-text: var(--online); }
.hero[data-state="offline"] { --state: var(--offline); --state-bg: var(--offline-bg); --state-text: var(--offline); }
.badge {
  display: inline-flex; align-items: center; gap: 8px;
  padding: 3px 10px; border-radius: 999px;
  background: var(--state-bg); color: var(--state-text);
  font-weight: 600; font-size: 13px;
}
.dot { width: 8px; height: 8px; border-radius: 50%; background: var(--state); }
.hero[data-state="online"] .dot { animation: pulse 2s ease-in-out infinite; }
@keyframes pulse { 50% { opacity: 0.35; } }
@media (prefers-reduced-motion: reduce) { .hero .dot { animation: none !important; } }
.hero h1 { font-size: 22px; margin-top: 8px; overflow-wrap: anywhere; }
.meta { margin: 4px 0 0; color: var(--muted); }
.hero-uptime, .hero-users { text-align: right; }
.uptime, .users-count { font-size: 28px; font-weight: 650; font-variant-numeric: tabular-nums; }
.users-count .of { font-size: 16px; color: var(--muted); font-weight: 500; }
.since { color: var(--muted); font-size: 12px; }

.notice {
  margin-top: 12px; padding: 10px 14px; border-radius: 8px;
  background: var(--offline-bg); color: var(--offline); font-weight: 500;
}
.notice.soft { background: var(--unknown-bg); color: var(--unknown-text); }

/* Panels */
.grid { display: grid; grid-template-columns: minmax(0, 1.3fr) minmax(0, 1fr); gap: 20px; margin-top: 20px; align-items: start; }
.panel {
  background: var(--panel); border: 1px solid var(--line); border-radius: 12px;
  padding: 18px 20px; box-shadow: var(--shadow); min-width: 0;
}
.panel-head { display: flex; justify-content: space-between; align-items: baseline; gap: 12px; flex-wrap: wrap; margin-bottom: 12px; }
.panel h2 { font-size: 16px; }
.panel h3 { font-size: 13px; color: var(--muted); margin: 22px 0 8px; font-weight: 600; }
.hint { color: var(--faint); font-size: 12px; }
.toggle { color: var(--muted); font-size: 13px; display: inline-flex; gap: 6px; align-items: center; cursor: pointer; }

/* Channel tree */
.tree ul { list-style: none; margin: 0; padding: 0; }
.tree ul ul { padding-left: 18px; border-left: 1px solid var(--line); margin-left: 9px; }
.row {
  display: flex; align-items: center; gap: 8px;
  padding: 4px 6px; border-radius: 6px; min-height: 28px;
}
.row:hover { background: var(--hover); }
.chan { cursor: default; }
.chan.has-kids { cursor: pointer; }
.chan .caret { width: 12px; color: var(--faint); font-size: 10px; flex: none; transition: transform 0.15s; }
.chan.collapsed .caret { transform: rotate(-90deg); }
.chan .name { font-weight: 550; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.chan.empty-chan .name { font-weight: 400; color: var(--muted); }
.chan .count {
  margin-left: auto; flex: none; font-size: 12px; color: var(--muted);
  font-variant-numeric: tabular-nums;
}
.chan .count.has { color: var(--accent); font-weight: 600; }
.tag { font-size: 11px; color: var(--faint); border: 1px solid var(--line); border-radius: 4px; padding: 0 5px; flex: none; }
.spacer { color: var(--faint); font-size: 12px; padding: 6px 6px; min-height: 0; }
.spacer.center { justify-content: center; }
.spacer.right { justify-content: flex-end; }
.spacer.repeat .name, .spacer.line .name { flex: 1; overflow: hidden; white-space: nowrap; letter-spacing: 0.1em; }
.spacer:hover { background: none; }

.user { padding-left: 26px; gap: 8px; }
.user .avatar {
  width: 8px; height: 8px; border-radius: 50%; flex: none;
  background: var(--online); box-shadow: 0 0 0 3px var(--online-bg);
}
.user.away .avatar { background: var(--faint); box-shadow: 0 0 0 3px var(--unknown-bg); }
.user.talking .avatar { background: var(--accent); box-shadow: 0 0 0 3px color-mix(in srgb, var(--accent) 25%, transparent); }
.user .nick { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.user.away .nick { color: var(--muted); }
.user .icons { display: inline-flex; gap: 4px; color: var(--offline); flex: none; }
.user .icons svg { width: 14px; height: 14px; }
.user .icons .away-i { color: var(--faint); }
.user .time { margin-left: auto; color: var(--faint); font-size: 12px; font-variant-numeric: tabular-nums; flex: none; }

/* Availability */
.tiles { display: grid; grid-template-columns: repeat(3, 1fr); gap: 10px; }
.tile { border: 1px solid var(--line); border-radius: 10px; padding: 10px 12px; }
.tile .pct { font-size: 22px; font-weight: 650; font-variant-numeric: tabular-nums; margin-top: 2px; }
.tile .pct.good { color: var(--online); }
.tile .pct.bad { color: var(--offline); }
.tile .sub { font-size: 12px; color: var(--faint); }

.timeline {
  position: relative; height: 28px; border-radius: 6px; overflow: hidden;
  background: var(--unknown-bg);
}
.seg { position: absolute; top: 0; bottom: 0; }
.seg.online { background: var(--online); }
.seg.offline { background: var(--offline); min-width: 2px; }
.seg.unknown { background: var(--unknown); }
.seg:hover { filter: brightness(1.15); }
.ticks { position: relative; height: 18px; margin-top: 4px; font-size: 11px; color: var(--faint); }
.ticks span { position: absolute; transform: translateX(-50%); white-space: nowrap; }
.ticks span::before {
  content: ""; position: absolute; left: 50%; top: -36px; height: 32px;
  border-left: 1px dashed color-mix(in srgb, var(--faint) 45%, transparent);
}
.legend { display: flex; gap: 16px; margin-top: 8px; font-size: 12px; color: var(--muted); flex-wrap: wrap; }
.sw { display: inline-block; width: 10px; height: 10px; border-radius: 3px; margin-right: 6px; vertical-align: -1px; }
.sw.online { background: var(--online); }
.sw.offline { background: var(--offline); }
.sw.unknown { background: var(--unknown); }

.outages { list-style: none; margin: 0; padding: 0; }
.outages li:not(.empty) {
  display: grid; grid-template-columns: 1fr auto; gap: 2px 12px;
  padding: 8px 0; border-top: 1px solid var(--line);
}
.outages li:first-child { border-top: 0; }
.outages .when { font-weight: 500; }
.outages .dur { font-variant-numeric: tabular-nums; color: var(--offline); font-weight: 600; text-align: right; }
.outages .why { grid-column: 1 / -1; font-size: 12px; color: var(--faint); }
.outages .live { color: var(--offline); font-weight: 600; }

.foot {
  margin-top: 16px; color: var(--faint); font-size: 12px;
  display: flex; justify-content: space-between; gap: 8px 16px; flex-wrap: wrap;
}
#foot { margin-left: auto; }
.link { background: none; border: 0; padding: 0; font: inherit; color: var(--accent); cursor: pointer; }
.link:hover { text-decoration: underline; }

/* Sign-in form in the channels panel */
.login { display: grid; gap: 10px; max-width: 320px; margin: 8px 0; }
.login p { margin: 0 0 4px; color: var(--muted); }
.login input {
  font: inherit; color: var(--text); background: var(--bg);
  border: 1px solid var(--line); border-radius: 8px; padding: 8px 10px;
}
.login input:focus { outline: 2px solid var(--accent); outline-offset: -1px; border-color: transparent; }
.login button {
  font: inherit; font-weight: 600; color: #fff; background: var(--accent);
  border: 0; border-radius: 8px; padding: 8px 12px; cursor: pointer; justify-self: start;
}
.login button:disabled { opacity: 0.6; cursor: default; }
.login-error { color: var(--offline) !important; font-size: 13px; }
.login-ok { color: var(--online) !important; font-size: 13px; }

dialog {
  background: var(--panel); color: var(--text);
  border: 1px solid var(--line); border-radius: 12px;
  padding: 20px 22px; width: min(360px, calc(100vw - 32px));
  box-shadow: 0 12px 40px rgb(0 0 0 / 0.3);
}
dialog::backdrop { background: rgb(0 0 0 / 0.45); }
dialog .login { margin: 0; max-width: none; }
dialog h2 { font-size: 16px; margin-bottom: 4px; }
.actions { display: flex; gap: 8px; flex-wrap: wrap; }
.login button.secondary { background: none; color: var(--muted); border: 1px solid var(--line); }

.tip {
  position: fixed; z-index: 10; pointer-events: none;
  background: var(--text); color: var(--bg);
  padding: 6px 9px; border-radius: 6px; font-size: 12px; line-height: 1.4;
  max-width: 280px; box-shadow: 0 4px 14px rgb(0 0 0 / 0.2);
}

@media (max-width: 900px) {
  .grid { grid-template-columns: 1fr; }
  .hero { grid-template-columns: 1fr 1fr; gap: 16px; }
  .hero-main { grid-column: 1 / -1; }
  .hero-uptime { text-align: left; }
}
@media (max-width: 480px) {
  .wrap { padding: 16px 16px 32px; }
  .tiles { grid-template-columns: 1fr 1fr 1fr; gap: 6px; }
  .tile .pct { font-size: 18px; }
  .uptime, .users-count { font-size: 22px; }
}
