:root {
  color-scheme: light dark;
  font-family: Inter, "Segoe UI", "PingFang SC", "Hiragino Sans GB", "Microsoft YaHei", sans-serif;
  --bg: #f7f7f8;
  --surface: #fff;
  --surface-2: #fafafa;
  --surface-3: #f1f1f3;
  --text: #121214;
  --muted: #6b6b74;
  --faint: #a1a1a9;
  --line: #e6e6e9;
  --line-strong: #d4d4d8;
  --accent: #121214;
  --on-accent: #fff;
  --up: #1a8a5b;
  --up-soft: #e6f6ee;
  --down: #d1434e;
  --down-soft: #fdeeef;
  --down-strong: #d1434e;
  --pending: #c07f1c;
  --pending-soft: #fcf3e1;
  --off: #8a8a93;
  --off-soft: #f1f1f3;
  --shadow: 0 1px 2px rgb(0 0 0 / 4%);
  --shadow-lg: 0 24px 64px rgb(0 0 0 / 16%);
  --radius: 12px;
  --mono: "JetBrains Mono", "IBM Plex Mono", "SFMono-Regular", Consolas, monospace;
  color: var(--text);
  background: var(--bg);
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0c0c0d;
    --surface: #151517;
    --surface-2: #19191c;
    --surface-3: #222226;
    --text: #f2f2f3;
    --muted: #a0a0a8;
    --faint: #6e6e76;
    --line: #26262a;
    --line-strong: #36363c;
    --accent: #f2f2f3;
    --on-accent: #121214;
    --up: #45c98d;
    --up-soft: #15342a;
    --down: #ff7a83;
    --down-soft: #3c1d24;
    --down-strong: #c23a46;
    --pending: #f0b052;
    --pending-soft: #3a2c15;
    --off: #8a8a93;
    --off-soft: #222226;
    --shadow: none;
    --shadow-lg: 0 24px 64px rgb(0 0 0 / 60%);
  }
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }
body { margin: 0; min-height: 100dvh; line-height: 1.55; background: var(--bg); -webkit-font-smoothing: antialiased; }
button, input, select, textarea { font: inherit; color: inherit; }
h1, h2, h3, p, dl, dd { margin: 0; }
h1 { font-size: clamp(1.45rem, 2.4vw, 1.75rem); line-height: 1.25; letter-spacing: -.03em; font-weight: 680; }
h2 { font-size: 1rem; font-weight: 650; letter-spacing: -.01em; }
h3 { font-size: .9rem; font-weight: 650; }
a { color: inherit; }
.muted { color: var(--muted); }
.mono, time { font-family: var(--mono); font-variant-numeric: tabular-nums; }
.sr-only { position: absolute; width: 1px; height: 1px; overflow: hidden; clip-path: inset(50%); white-space: nowrap; }
.shell { width: min(1360px, calc(100% - clamp(32px, 6vw, 96px))); margin: 0 auto; }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
code { padding: 0 .3rem; border-radius: 4px; background: var(--surface-3); font: .85em var(--mono); }

/* Top bar */
.topbar { position: sticky; top: 0; z-index: 20; background: color-mix(in srgb, var(--surface) 88%, transparent); border-bottom: 1px solid var(--line); backdrop-filter: blur(10px); }
.topbar-inner { display: flex; align-items: center; justify-content: space-between; gap: .6rem 1rem; min-height: 56px; flex-wrap: wrap; }
.brand { display: inline-flex; align-items: center; gap: .55rem; font-weight: 680; font-size: 1rem; letter-spacing: -.02em; text-decoration: none; }
.brand-mark { display: inline-grid; place-items: center; flex: none; width: 28px; height: 28px; border-radius: 8px; background: linear-gradient(135deg, #5a86ff, #3a62e8); color: #fff; font-size: 17px; line-height: 1; }
.bi { line-height: 1; }
.topbar-tools { display: flex; align-items: center; gap: .5rem .9rem; flex-wrap: wrap; }
.health { display: inline-flex; align-items: center; gap: .45rem; font-size: .8rem; color: var(--muted); white-space: nowrap; }
.health-dot { width: .5rem; height: .5rem; border-radius: 50%; background: var(--off); }
.health[data-status=UP] .health-dot { background: var(--up); }
.health[data-status=DOWN] .health-dot { background: var(--down); }
body:not([data-view=app]) .account { display: none; }
.avatar { display: inline-grid; place-items: center; flex: none; width: 32px; height: 32px; padding: 0; border: 0; border-radius: 50%; background: var(--accent); color: var(--on-accent); font-size: .85rem; font-weight: 700; line-height: 1; }
button.avatar { cursor: pointer; }
button.avatar:hover { opacity: .85; }
.avatar.large { width: 56px; height: 56px; font-size: 1.35rem; }

/* Buttons and inputs */
.button { display: inline-flex; align-items: center; justify-content: center; gap: .4rem; padding: .42rem .85rem; border: 1px solid var(--line-strong); border-radius: 8px; background: var(--surface); color: var(--text); font-size: .85rem; font-weight: 580; line-height: 1.45; text-decoration: none; white-space: nowrap; cursor: pointer; transition: background .12s, border-color .12s, color .12s; }
.button:hover:enabled, a.button:hover { background: var(--surface-3); }
.button:disabled { cursor: not-allowed; opacity: .45; }
.button.small { padding: .25rem .6rem; font-size: .8rem; }
.button.primary { background: var(--accent); border-color: var(--accent); color: var(--on-accent); }
.button.primary:hover:enabled, a.button.primary:hover { background: var(--accent); opacity: .86; }
.button.primary.danger { background: var(--down-strong); border-color: var(--down-strong); color: #fff; }
.button.quiet { border-color: transparent; background: transparent; color: var(--muted); padding-inline: .55rem; }
.button.quiet:hover:enabled { background: var(--surface-3); color: var(--text); }
.button.quiet.danger { color: var(--down); }
.button.quiet.danger:hover:enabled { background: var(--down-soft); color: var(--down); }
.button.block { width: 100%; padding-block: .6rem; }
.link { padding: 0; border: 0; background: none; color: var(--text); font-size: inherit; font-weight: 600; text-decoration: underline; text-underline-offset: 3px; text-decoration-color: var(--line-strong); cursor: pointer; }
.link:hover { text-decoration-color: currentColor; }
.icon-button { display: inline-grid; place-items: center; width: 32px; height: 32px; border: 0; border-radius: 8px; background: transparent; color: var(--muted); font-size: .95rem; line-height: 1; cursor: pointer; }
.icon-button:hover { background: var(--surface-3); color: var(--text); }
#refresh .bi { display: inline-block; }
body[aria-busy=true] #refresh .bi { animation: spin .8s linear infinite; }
input:not([type=checkbox]), select, textarea {
  width: 100%; min-width: 0; padding: .5rem .7rem; border: 1px solid var(--line-strong); border-radius: 8px;
  background: var(--surface); color: var(--text); font-size: .9rem; transition: border-color .12s, box-shadow .12s;
}
input:not([type=checkbox]):focus, select:focus, textarea:focus { outline: none; border-color: var(--accent); box-shadow: 0 0 0 3px var(--surface-3); }
textarea { resize: vertical; font-family: var(--mono); font-size: .85rem; }
input[type=checkbox] { width: 1rem; height: 1rem; accent-color: var(--accent); }
.field { display: grid; align-content: start; gap: .3rem; min-width: 0; font-size: .85rem; font-weight: 600; }
.field small, .hint { color: var(--muted); font-size: .78rem; font-weight: 400; }
.field-label { display: flex; align-items: center; justify-content: space-between; gap: .5rem; }
.field-label .link { font-size: .78rem; font-weight: 500; color: var(--muted); }
.field.checkbox { display: flex; align-items: center; gap: .5rem; font-weight: 500; }

/* Notices */
.notice { padding: .6rem .9rem; border: 1px solid var(--line-strong); border-radius: 10px; background: var(--surface); font-size: .85rem; overflow-wrap: anywhere; }
.notice:empty { display: none; }
.notice[data-kind=error], .dialog-error { border-color: color-mix(in srgb, var(--down) 35%, transparent); background: var(--down-soft); color: var(--down); }
#notice { position: fixed; z-index: 30; top: 68px; left: 50%; translate: -50% 0; width: max-content; max-width: min(520px, calc(100% - 2rem)); box-shadow: var(--shadow-lg); animation: drop .18s ease-out; }
.dialog-error { margin: 0 1.25rem 1rem; }

/* Views */
main.shell { padding-bottom: 4rem; }
.view-login, .view-app { display: none; }
body[data-view=login] .view-login { display: grid; }
body[data-view=app] .view-app { display: block; }
.view-loading { display: grid; place-items: center; min-height: 50vh; }
body[data-view] .view-loading { display: none; }
.spinner { width: 24px; height: 24px; border: 2.5px solid var(--line-strong); border-top-color: var(--text); border-radius: 50%; animation: spin .8s linear infinite; }

.auth-view { justify-items: center; align-content: start; gap: 1rem; padding-top: clamp(32px, 10vh, 104px); }
.auth-card { width: min(380px, 100%); padding: 2rem; border: 1px solid var(--line); border-radius: 16px; background: var(--surface); box-shadow: var(--shadow); }
.auth-form { display: grid; gap: .95rem; }
.auth-form .button.block { margin-top: .3rem; }
.auth-switch { text-align: center; color: var(--muted); font-size: .85rem; }

/* Dashboard */
.page-heading { display: flex; align-items: flex-end; justify-content: space-between; flex-wrap: wrap; gap: .75rem; padding: clamp(22px, 3.5vw, 36px) 0 1.1rem; }
.page-heading .muted { margin-top: .15rem; font-size: .8rem; }
.stats { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: .75rem; }
.stat { display: grid; gap: .1rem; padding: .85rem 1.1rem; border: 1px solid var(--line); border-radius: var(--radius); background: var(--surface); box-shadow: var(--shadow); }
.stat-label { display: inline-flex; align-items: center; gap: .45rem; color: var(--muted); font-size: .8rem; font-weight: 550; }
.stat-value { font: 650 1.6rem/1.3 var(--mono); letter-spacing: -.02em; }
.stat[data-alert=true] .stat-value { color: var(--down); }
.status-dot { display: inline-block; flex: none; width: .5rem; height: .5rem; border-radius: 50%; background: var(--off); }
.status-dot[data-status=UP] { background: var(--up); }
.status-dot[data-status=DOWN] { background: var(--down); }
.status-dot[data-status=PENDING] { background: var(--pending); }
.status-dot[data-status=EMPTY] { background: transparent; border: 1.5px solid var(--line-strong); }

.workspace { display: grid; grid-template-columns: minmax(230px, 280px) minmax(0, 1fr); gap: 1rem; margin-top: 1rem; align-items: start; }
.checks-panel { container-type: inline-size; }
.panel { min-width: 0; border: 1px solid var(--line); border-radius: var(--radius); background: var(--surface); box-shadow: var(--shadow); overflow: hidden; }
.panel-head { display: flex; align-items: center; justify-content: space-between; flex-wrap: wrap; gap: .6rem; padding: .75rem .9rem .75rem 1.1rem; border-bottom: 1px solid var(--line); }
.panel-title { display: flex; align-items: center; gap: .5rem; min-width: 0; flex-wrap: wrap; }
.count { display: inline-grid; place-items: center; min-width: 1.4rem; padding: 0 .4rem; border-radius: 999px; background: var(--surface-3); color: var(--muted); font: 600 .72rem/1.6 var(--mono); }
.selection { display: inline-flex; align-items: center; gap: .45rem; min-width: 0; }
.selection strong { font-size: .95rem; overflow-wrap: anywhere; }
.actions { display: flex; align-items: center; gap: .25rem; flex-wrap: wrap; }
.apps-panel { position: sticky; top: 72px; }
.app-search { padding: .6rem .7rem 0; }
.app-search input { padding-block: .38rem; font-size: .85rem; }
.app-list { display: grid; gap: 2px; padding: .45rem; max-height: calc(100dvh - 200px); overflow-y: auto; }
.app-list:empty { display: none; }
.app-item { display: grid; grid-template-columns: auto minmax(0, 1fr) auto; align-items: center; gap: .6rem; width: 100%; padding: .55rem .65rem; border: 0; border-radius: 8px; background: transparent; text-align: left; cursor: pointer; }
.app-item:hover { background: var(--surface-2); }
.app-item[aria-current=true] { background: var(--surface-3); }
.app-name { font-weight: 600; font-size: .9rem; overflow-wrap: anywhere; }
.app-counts { display: flex; justify-content: flex-end; gap: .25rem; font-size: .72rem; white-space: nowrap; }
.app-counts:empty { display: none; }
.chip { padding: 0 .4rem; border-radius: 5px; background: var(--off-soft); color: var(--muted); font-weight: 600; line-height: 1.6; }
.chip[data-status=UP] { background: var(--up-soft); color: var(--up); }
.chip[data-status=DOWN] { background: var(--down-soft); color: var(--down); }
.chip[data-status=PENDING] { background: var(--pending-soft); color: var(--pending); }

.empty-state { display: grid; place-content: center; justify-items: center; gap: .3rem; min-height: 160px; padding: 1.5rem; color: var(--muted); font-size: .85rem; text-align: center; }
.empty-state strong { color: var(--text); font-size: .95rem; }

.table-wrap { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; font-size: .85rem; text-align: left; }
th, td { padding: .7rem .9rem; vertical-align: middle; border-bottom: 1px solid var(--line); }
th { padding-block: .5rem; color: var(--muted); font-size: .72rem; font-weight: 600; white-space: nowrap; }
tbody tr:last-child td { border-bottom: 0; }
tbody tr:hover td { background: var(--surface-2); }
#check-rows tr[data-status=DOWN] td:first-child { box-shadow: inset 3px 0 0 var(--down); }
.check-main { min-width: 14rem; }
.row-title { display: flex; align-items: center; gap: .45rem; flex-wrap: wrap; }
.row-title strong { font-weight: 620; overflow-wrap: anywhere; }
.tag { padding: 0 .35rem; border-radius: 4px; background: var(--surface-3); color: var(--muted); font: 600 .66rem/1.6 var(--mono); }
.row-sub { display: block; margin-top: .1rem; color: var(--muted); font-size: .78rem; overflow-wrap: anywhere; }
.row-error, .error-text { color: var(--down); }
.row-error { display: block; margin-top: .2rem; font: .76rem/1.45 var(--mono); overflow-wrap: anywhere; }
.check-time, .check-latency { color: var(--muted); white-space: nowrap; }
.check-time time { font-size: .78rem; }
.check-actions { width: 1%; }
.row-actions { justify-content: flex-end; flex-wrap: nowrap; gap: 0; }
.row-actions .button { padding: .28rem .5rem; font-size: .78rem; }
.status { display: inline-flex; align-items: center; gap: .38rem; padding: .08rem .55rem; border-radius: 999px; background: var(--off-soft); color: var(--muted); font-size: .76rem; font-weight: 650; white-space: nowrap; }
.status::before { content: ""; width: .42rem; height: .42rem; border-radius: 50%; background: currentColor; }
.status[data-status=UP] { background: var(--up-soft); color: var(--up); }
.status[data-status=DOWN] { background: var(--down-soft); color: var(--down); }
.status[data-status=PENDING] { background: var(--pending-soft); color: var(--pending); }

/* Dialogs */
dialog { width: min(580px, calc(100% - 2rem)); max-height: calc(100dvh - 3rem); padding: 0; border: 1px solid var(--line); border-radius: 16px; background: var(--surface); color: var(--text); box-shadow: var(--shadow-lg); }
dialog[open] { animation: pop .16s ease-out; }
dialog::backdrop { background: rgb(0 0 0 / 42%); }
dialog form { margin: 0; }
.dialog-head { display: flex; align-items: center; justify-content: space-between; gap: .75rem; padding: 1rem 1rem .9rem 1.25rem; border-bottom: 1px solid var(--line); }
.dialog-head h2 { font-size: 1.05rem; }
.form-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 1rem; padding: 1.25rem; }
.wide { grid-column: 1 / -1; }
.group { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 1rem; margin: 0; padding: 0; border: 0; min-width: 0; }
.dialog-actions { display: flex; justify-content: flex-end; flex-wrap: wrap; gap: .5rem; padding: .85rem 1.25rem; border-top: 1px solid var(--line); }
.settings-dialog { width: min(380px, calc(100% - 2rem)); }
.settings-profile { display: grid; justify-items: center; gap: .55rem; padding: 1.5rem 1.25rem 1rem; text-align: center; }
.settings-profile strong { font-size: 1rem; overflow-wrap: anywhere; }
.settings-list { display: grid; gap: 2px; padding: .25rem .6rem .8rem; }
.settings-item { display: flex; align-items: center; gap: .75rem; width: 100%; padding: .7rem .75rem; border: 0; border-radius: 10px; background: transparent; font-size: .9rem; font-weight: 550; text-align: left; cursor: pointer; }
.settings-item:hover { background: var(--surface-3); }
.settings-item .bi { color: var(--muted); }
.settings-item .bi-chevron-right { margin-left: auto; color: var(--faint); font-size: .75rem; }
.settings-item.danger, .settings-item.danger .bi { color: var(--down); }
.settings-dialog .dialog-error { margin-top: -.25rem; }
.confirm-dialog { width: min(420px, calc(100% - 2rem)); }
.confirm-body { display: grid; gap: .4rem; padding: 1.35rem 1.35rem 1.15rem; }
.confirm-body p { font-size: .875rem; overflow-wrap: anywhere; }

.history-dialog { width: min(920px, calc(100% - 2rem)); }
.detail-title { display: flex; align-items: center; gap: .6rem; min-width: 0; flex-wrap: wrap; }
.detail-title h2 { overflow-wrap: anywhere; }
.detail-target { margin: .9rem 1.25rem 0; color: var(--muted); font-size: .8rem; overflow-wrap: anywhere; }
.details { display: grid; grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); gap: .75rem 1rem; margin: .9rem 1.25rem 1.1rem; }
.detail { min-width: 0; }
.detail dt { color: var(--muted); font-size: .72rem; }
.detail dd { font-size: .85rem; font-weight: 600; overflow-wrap: anywhere; }
.trend { margin: 0 1.25rem 1.1rem; }
.trend-head { display: flex; align-items: baseline; justify-content: space-between; flex-wrap: wrap; gap: .4rem 1rem; margin-bottom: .6rem; }
.trend-summary { color: var(--muted); font-size: .78rem; }
.trend-summary strong { color: var(--text); font-family: var(--mono); }
.trend-bars { display: flex; align-items: flex-end; gap: 2px; height: 56px; padding-bottom: 1px; border-bottom: 1px solid var(--line); }
.trend-bars.empty { display: none; }
.bar { flex: 1 1 0; max-width: 14px; min-height: 4px; border-radius: 3px 3px 0 0; background: var(--up); opacity: .8; }
.bar:hover { opacity: 1; }
.bar[data-status=DOWN] { background: var(--down); }
.history-head { display: flex; align-items: center; justify-content: space-between; padding: .55rem 1rem .55rem 1.25rem; border-top: 1px solid var(--line); }
#history-empty { padding: .5rem 1.25rem 1rem; font-size: .85rem; }
#history-rows td:last-child { overflow-wrap: anywhere; font-size: .78rem; }
.pager { display: flex; align-items: center; justify-content: space-between; flex-wrap: wrap; gap: .6rem; padding: .7rem 1.25rem; border-top: 1px solid var(--line); color: var(--muted); font-size: .8rem; }
.pager select { width: auto; padding: .22rem .5rem; font-size: .8rem; }
.pager-nav { display: inline-flex; align-items: center; gap: .6rem; }
.pager-nav .button { padding: .28rem .7rem; font-size: .8rem; }

@keyframes spin { to { rotate: 360deg; } }
@keyframes pop { from { opacity: 0; transform: translateY(6px) scale(.985); } }
@keyframes drop { from { opacity: 0; translate: -50% -6px; } }
@media (prefers-reduced-motion: reduce) { *, ::before, ::after { animation: none !important; transition: none !important; } }

/* The check list turns into cards whenever its panel is too narrow for five columns, whatever the viewport. */
@container (max-width: 720px) {
  #check-table, #check-table tbody { display: block; }
  #check-table thead { position: absolute; width: 1px; height: 1px; overflow: hidden; clip-path: inset(50%); }
  #check-table tbody tr { display: grid; grid-template-columns: minmax(0, 1fr) auto; gap: .3rem .75rem; padding: .8rem 1rem; }
  #check-table tbody tr + tr { border-top: 1px solid var(--line); }
  #check-table td { min-width: 0; padding: 0; border: 0; background: none; box-shadow: none; }
  #check-rows tr[data-status=DOWN] { box-shadow: inset 3px 0 0 var(--down); }
  #check-rows tr[data-status=DOWN] td:first-child { box-shadow: none; }
  .check-main { grid-column: 1; min-width: 0; }
  .check-state { grid-column: 2; grid-row: 1; justify-self: end; }
  .check-time, .check-latency { display: block; font-size: .76rem; }
  .check-time { grid-column: 1; }
  .check-time time[data-relative]::before { content: attr(data-label) " "; font-family: inherit; }
  .check-latency { grid-column: 2; justify-self: end; }
  .check-actions { grid-column: 1 / -1; width: auto; }
  .row-actions { justify-content: flex-start; flex-wrap: wrap; margin-left: -.5rem; }
}
@media (max-width: 860px) {
  .workspace { grid-template-columns: 1fr; }
  .apps-panel { position: static; }
  .app-list { max-height: 260px; }
  .shell { width: calc(100% - 2rem); }
}
@media (max-width: 660px) {
  .topbar-inner { padding-block: .5rem; }
  .stats { grid-template-columns: repeat(2, minmax(0, 1fr)); gap: .5rem; }
  .stat { padding: .6rem .85rem; }
  .stat-value { font-size: 1.3rem; }
  .apps-panel .empty-state { min-height: 120px; }
  #history-table-wrap table { min-width: 34rem; }
  .form-grid, .group { grid-template-columns: 1fr; gap: .8rem; }
  .form-grid { padding: 1rem; }
  dialog { max-height: calc(100dvh - 1rem); width: calc(100% - 1rem); }
  .auth-card { padding: 1.5rem 1.25rem; }
  th, td { padding-inline: .7rem; }
  .pager { justify-content: center; }
}
