:root {
  --bg: #f6f7f9;
  --panel: #ffffff;
  --panel-2: #f0f2f5;
  --border: #e2e5ea;
  --text: #16191f;
  --muted: #5f6673;
  --up: #16a34a;
  --down: #dc2626;
  --pending: #d97706;
  --maint: #2563eb;
  --paused: #9aa1ad;
  --empty: #dfe3e8;
  --accent: #2563eb;
  --minor: #ca8a04;
  --major: #ea580c;
  --critical: #dc2626;
  --radius: 10px;
  --down-glow: rgba(220, 38, 38, .25);
  --sel: rgba(37, 99, 235, .12);
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0e1116;
    --panel: #161a21;
    --panel-2: #1d222b;
    --border: #2a303b;
    --text: #e6e9ef;
    --muted: #949cab;
    --up: #22c55e;
    --down: #ef4444;
    --pending: #f59e0b;
    --maint: #60a5fa;
    --paused: #6b7280;
    --empty: #2a303b;
    --accent: #60a5fa;
    --minor: #eab308;
    --major: #fb923c;
    --critical: #ef4444;
    --down-glow: rgba(239, 68, 68, .25);
    --sel: rgba(96, 165, 250, .14);
    color-scheme: dark;
  }
}
* { box-sizing: border-box; }
[hidden] { display: none !important; }
html, body { margin: 0; }
body {
  background: var(--bg);
  color: var(--text);
  font: 15px/1.5 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  -webkit-font-smoothing: antialiased;
}
a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }
button, input, select, textarea { font: inherit; color: inherit; }
.wrap { max-width: 920px; margin: 0 auto; padding: 32px 16px 64px; }
.muted { color: var(--muted); }
.small { font-size: 13px; }
.tabular { font-variant-numeric: tabular-nums; }

/* status colours */
.s-0 { --c: var(--down); }
.s-1 { --c: var(--up); }
.s-2 { --c: var(--pending); }
.s-3 { --c: var(--maint); }
.s-4 { --c: var(--minor); }
.s-paused, .s-null { --c: var(--paused); }
.dot { width: 10px; height: 10px; border-radius: 50%; background: var(--c); flex: none; display: inline-block; }
.s-0 .dot, .dot.s-0 { box-shadow: 0 0 0 4px var(--down-glow); }

.pill {
  display: inline-flex; align-items: center; gap: 6px;
  padding: 2px 10px; border-radius: 999px; font-size: 12px; font-weight: 600;
  position: relative; isolation: isolate; color: var(--c);
  white-space: nowrap;
}

.pill::before { content: ""; position: absolute; inset: 0; border-radius: inherit; background: var(--c); opacity: .15; z-index: -1; }

.panel { background: var(--panel); border: 1px solid var(--border); border-radius: var(--radius); }

/* ---------- public status page ---------- */
.sp-head { display: flex; align-items: center; gap: 14px; margin-bottom: 24px; }
.sp-head h1 { font-size: 26px; margin: 0; letter-spacing: -0.01em; }
.sp-head p { margin: 2px 0 0; }
.overall {
  display: flex; align-items: center; gap: 12px;
  padding: 18px 20px; border-radius: var(--radius); margin-bottom: 20px;
  background: var(--c); color: #fff; font-weight: 600; font-size: 17px;
}
.overall.up { --c: var(--up); }
.overall.down { --c: var(--down); }
.overall.degraded { --c: var(--minor); }
.overall.partial { --c: var(--major); }
.overall.major { --c: var(--critical); }
.overall.maintenance { --c: var(--maint); }
.overall svg { flex: none; }
.notice { padding: 14px 18px; margin-bottom: 14px; border-left: 4px solid var(--c); }
.notice h3 { margin: 0 0 4px; font-size: 15px; }
.notice p { margin: 0; white-space: pre-wrap; }
.notice .when { margin-top: 6px; }
.st-info { --c: var(--accent); }
.st-primary { --c: var(--up); }
.st-warning { --c: var(--pending); }
.st-danger { --c: var(--down); }
.st-dark { --c: var(--muted); }
.st-maint { --c: var(--maint); }

.mon-list { padding: 4px 0; }
.mon { padding: 14px 20px; border-top: 1px solid var(--border); }
.mon:first-child { border-top: 0; }
.mon-row { display: flex; align-items: center; gap: 10px; }
.mon-name { font-weight: 600; flex: 1; min-width: 0; overflow-wrap: anywhere; }
.mon-name a { color: inherit; }
.mon-up { font-size: 13px; color: var(--muted); white-space: nowrap; }
.bars { display: flex; gap: 2px; height: 30px; margin-top: 10px; align-items: stretch; }
.bars span { flex: 1; border-radius: 2px; background: var(--c, var(--empty)); min-width: 2px; position: relative; }
.bars span.none { background: var(--empty); }
.bars span.tl { background-color: var(--empty); }
.bars span:hover { filter: brightness(1.2); }
.bar-legend { display: flex; justify-content: space-between; font-size: 12px; color: var(--muted); margin-top: 4px; }
details.children { margin-top: 10px; }
details.children > summary {
  cursor: pointer; font-size: 13px; color: var(--muted); list-style: none; display: inline-flex; gap: 6px; align-items: center;
}
details.children > summary::-webkit-details-marker { display: none; }
details.children > summary::before { content: "▸"; transition: transform .15s; }
details.children[open] > summary::before { transform: rotate(90deg); }
.child-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(260px, 1fr)); gap: 8px; margin-top: 10px; }
.child { background: var(--panel-2); border-radius: 8px; padding: 10px 12px; }
.child .mon-row { gap: 8px; }
.child .mon-name { font-weight: 500; font-size: 14px; }
.child .bars { height: 18px; margin-top: 8px; gap: 1px; }
.tip {
  position: fixed; z-index: 10; pointer-events: none; padding: 6px 10px; border-radius: 6px; font-size: 12px;
  background: var(--text); color: var(--bg); white-space: nowrap; transform: translate(-50%, -100%); margin-top: -8px;
}
/* incidents & maintenance */
.imp-none { --c: var(--muted); }
.imp-minor { --c: var(--minor); }
.imp-major { --c: var(--major); }
.imp-critical { --c: var(--critical); }
.imp-maintenance { --c: var(--maint); }
.ev { padding: 16px 20px; margin-bottom: 14px; border-left: 4px solid var(--c); }
.ev header { display: flex; align-items: flex-start; gap: 10px; justify-content: space-between; margin-bottom: 4px; }
.ev h3 { margin: 0; font-size: 16px; overflow-wrap: anywhere; }
.ev-desc { margin: 4px 0; white-space: pre-wrap; }
.affected { margin-top: 6px; display: flex; flex-wrap: wrap; gap: 4px; align-items: center; }
.tag { display: inline-block; padding: 1px 8px; border-radius: 999px; background: var(--panel-2); border: 1px solid var(--border); font-size: 12px; color: var(--muted); }
.timeline { list-style: none; margin: 12px 0 0; padding: 0 0 0 16px; border-left: 2px solid var(--border); }
.timeline li { position: relative; padding: 0 0 12px; }
.timeline li:last-child { padding-bottom: 0; }
.timeline li::before { content: ""; position: absolute; left: -22px; top: 6px; width: 10px; height: 10px; border-radius: 50%; background: var(--panel); border: 2px solid var(--c, var(--muted)); }
.timeline li:first-child::before { background: var(--c, var(--muted)); }
.tl-head { display: flex; gap: 10px; align-items: baseline; flex-wrap: wrap; }
.timeline p { margin: 2px 0 0; white-space: pre-wrap; overflow-wrap: anywhere; }
.hist-day { padding: 12px 0; border-bottom: 1px solid var(--border); }
.hist-day h4 { margin: 0 0 6px; font-size: 15px; }
.hist-day p { margin: 0; }
.hist-item { margin: 6px 0; padding-left: 12px; border-left: 3px solid var(--c); }
.hist-item > summary { cursor: pointer; list-style: none; display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }
.hist-item > summary::-webkit-details-marker { display: none; }
.hist-title { font-weight: 600; color: var(--c); }
.hist-item[open] { padding-bottom: 6px; }

.sp-foot { margin-top: 28px; text-align: center; font-size: 13px; color: var(--muted); }
.section-title { font-size: 13px; font-weight: 600; text-transform: uppercase; letter-spacing: .06em; color: var(--muted); margin: 26px 0 10px; }

@media (max-width: 560px) {
  .wrap { padding-top: 20px; }
  .sp-head h1 { font-size: 21px; }
  .mon { padding: 12px 14px; }
  .bars { height: 24px; gap: 1px; }
}

/* ---------- admin ---------- */
.adm-top {
  position: sticky; top: 0; z-index: 5; background: var(--panel); border-bottom: 1px solid var(--border);
}
.adm-top .wrap { padding-block: 10px; display: flex; align-items: center; gap: 16px; flex-wrap: wrap; max-width: 1180px; }
.adm-top .brand { display: flex; align-items: center; gap: 8px; font-weight: 700; }
.tabs { display: flex; gap: 4px; flex-wrap: wrap; flex: 1; }
.tabs button { background: none; border: 0; padding: 6px 12px; border-radius: 6px; cursor: pointer; color: var(--muted); }
.tabs button.on { background: var(--panel-2); color: var(--text); font-weight: 600; }
.adm .wrap { max-width: 1180px; }
.btn {
  display: inline-flex; align-items: center; gap: 6px; padding: 7px 14px; border-radius: 7px; cursor: pointer;
  border: 1px solid var(--border); background: var(--panel); font-weight: 500;
}
.btn:hover { background: var(--panel-2); }
.btn.primary { background: var(--accent); border-color: var(--accent); color: #fff; }
.btn.danger { color: var(--down); }
.btn.sm { padding: 4px 10px; font-size: 13px; }
.btn:disabled { opacity: .5; cursor: default; }
.toolbar { display: flex; gap: 8px; align-items: center; margin-bottom: 14px; flex-wrap: wrap; }
.toolbar input[type=search] { flex: 1; min-width: 180px; }
input[type=text], input[type=password], input[type=number], input[type=search], input[type=url], input[type=time], input[type=datetime-local], select, textarea {
  width: 100%; padding: 8px 10px; border: 1px solid var(--border); border-radius: 7px; background: var(--panel);
}
textarea { min-height: 80px; resize: vertical; }
label.f { display: block; margin-bottom: 12px; }
label.f > span { display: block; font-size: 13px; font-weight: 600; margin-bottom: 4px; }
label.f small { display: block; color: var(--muted); font-size: 12px; margin-top: 3px; }
label.chk { display: flex; align-items: center; gap: 8px; margin-bottom: 10px; cursor: pointer; }
.grid2 { display: grid; grid-template-columns: repeat(auto-fit, minmax(200px, 1fr)); gap: 0 14px; }

.adm-layout { display: grid; grid-template-columns: minmax(0, 1fr) minmax(0, 1fr); gap: 16px; align-items: start; }
@media (max-width: 900px) { .adm-layout { grid-template-columns: minmax(0, 1fr); } }
.mlist .row {
  display: flex; align-items: center; gap: 10px; padding: 9px 14px; border-top: 1px solid var(--border); cursor: pointer;
}
.mlist .row:first-child { border-top: 0; }
.mlist .row:hover { background: var(--panel-2); }
.mlist .row.sel { background: var(--sel); }
.mlist .nm { flex: 1; min-width: 0; }
.mlist .nm b { font-weight: 600; display: block; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.mlist .nm i { font-style: normal; font-size: 12px; color: var(--muted); display: block; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.mlist .mini { display: flex; gap: 1px; height: 18px; width: 120px; flex: none; }
.mlist .mini span { flex: 1; background: var(--c, var(--empty)); border-radius: 1px; }
.mlist .pct { width: 62px; text-align: right; font-size: 13px; flex: none; }
@media (max-width: 560px) { .mlist .mini { display: none; } }
.detail { padding: 18px; position: sticky; top: 70px; }
.detail h2 { margin: 0 0 4px; font-size: 20px; overflow-wrap: anywhere; }
.kv { display: grid; grid-template-columns: max-content minmax(0, 1fr); gap: 4px 14px; font-size: 14px; margin: 14px 0; }
.kv dt { color: var(--muted); }
.kv dd { margin: 0; overflow-wrap: anywhere; min-width: 0; }
.kv dd img { max-width: 100%; height: auto; vertical-align: middle; }
.code { font-family: ui-monospace, SFMono-Regular, Menlo, monospace; font-size: 12.5px; background: var(--panel-2); padding: 2px 6px; border-radius: 4px; overflow-wrap: anywhere; }
.chart { width: 100%; height: 90px; display: block; margin: 8px 0 4px; }
.beats { max-height: 320px; overflow: auto; border: 1px solid var(--border); border-radius: 8px; }
.beats table, table.list { width: 100%; border-collapse: collapse; font-size: 13px; }
.beats td, table.list td, table.list th { padding: 6px 10px; border-top: 1px solid var(--border); text-align: left; vertical-align: top; }
table.list th { font-size: 12px; color: var(--muted); font-weight: 600; border-top: 0; }
.stats { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; margin: 12px 0; }
.stats div { background: var(--panel-2); border-radius: 8px; padding: 8px 10px; }
.stats b { display: block; font-size: 18px; }
.stats span { font-size: 12px; color: var(--muted); }

dialog {
  border: 1px solid var(--border); border-radius: 12px; padding: 0; width: min(640px, calc(100vw - 32px));
  background: var(--panel); color: var(--text);
  /* dvh = the visible viewport on phones (100vh runs under Safari's toolbar, hiding Save/Cancel) */
  max-height: calc(100vh - 40px); max-height: calc(100dvh - 24px); overflow-y: auto; overscroll-behavior: contain;
}
dialog::backdrop { background: rgb(0 0 0 / .45); }
dialog form { padding: 20px; }
dialog h2 { margin: 0 0 16px; font-size: 19px; }
/* Save/Cancel stay visible while a long form scrolls (full-bleed bar flush with the dialog's bottom edge). */
.dlg-actions {
  display: flex; justify-content: flex-end; gap: 8px; margin: 8px -20px -20px; padding: 12px 20px;
  position: sticky; bottom: 0; background: var(--panel); border-top: 1px solid var(--border);
}
.err { color: var(--down); font-size: 14px; min-height: 1.2em; }
.toast {
  position: fixed; bottom: 20px; left: 50%; transform: translateX(-50%); z-index: 100;
  background: var(--text); color: var(--bg); padding: 10px 18px; border-radius: 8px; font-size: 14px;
}
.login { max-width: 360px; margin: 12vh auto; padding: 28px; }
.login h1 { margin: 0 0 18px; font-size: 22px; display: flex; gap: 10px; align-items: center; }
.empty { padding: 30px; text-align: center; color: var(--muted); }
@media (max-width: 700px) {
  .adm-top { position: static; }
  .adm-top .wrap { gap: 8px 12px; }
  .adm-top .brand { flex: 1; }
  .tabs { order: 3; flex: 0 0 100%; flex-wrap: nowrap; overflow-x: auto; -webkit-overflow-scrolling: touch; }
  .tabs button { flex: none; }
  .detail { position: static; }
}

/* admin: incidents & maintenance */
.picker { max-height: 220px; overflow: auto; border: 1px solid var(--border); border-radius: 8px; padding: 8px 10px; margin-top: 4px; }
.picker .chk { margin-bottom: 4px; }
.days { display: flex; flex-wrap: wrap; gap: 4px 14px; margin-top: 4px; }
.days .chk { margin-bottom: 0; }
.tl-acts { margin-left: auto; font-size: 12px; }
button.link { background: none; border: 0; padding: 0; color: var(--accent); cursor: pointer; font-size: 12px; }
button.link.danger { color: var(--down); }
details.hist-row { padding: 10px 14px; margin-bottom: 8px; }
details.hist-row > summary { cursor: pointer; display: flex; gap: 10px; align-items: center; flex-wrap: wrap; list-style: none; }
details.hist-row > summary::-webkit-details-marker { display: none; }
details.hist-row .ev { margin: 12px 0 4px; }

/* admin: activity log */
details.arow { padding: 10px 14px; border-top: 1px solid var(--border); }
details.arow:first-child { border-top: 0; }
details.arow > summary { cursor: pointer; display: flex; gap: 10px; align-items: center; flex-wrap: wrap; list-style: none; }
details.arow > summary::-webkit-details-marker { display: none; }
details.arow > summary > span:nth-child(3) { flex: 1; min-width: 12em; }
details.arow.undone > summary { opacity: .6; }
details.arow table.list td { overflow-wrap: anywhere; }
