/* Colors live in tokens. The dark set switches with the visitor's system setting. */
:root {
  color-scheme: light dark;
  --bg: #f5f6f8;
  --surface: #ffffff;
  --surface-2: #f0f2f5;
  --text: #1b2230;
  --muted: #566072;
  --border: #dfe3e9;
  --accent: #2a5bd7;
  --accent-text: #ffffff;
  --good: #16794a;
  --good-soft: #e3f4ea;
  --warn: #8a5a00;
  --warn-soft: #fbf1da;
  --bad: #b8322a;
  --bad-soft: #fbe6e4;
  --info-soft: #e6edfb;
  --shadow: 0 1px 2px rgb(20 28 44 / 6%);
  --radius: 12px;
  --mono: ui-monospace, SFMono-Regular, Menlo, Consolas, "Liberation Mono", monospace;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #11141a;
    --surface: #1a1e26;
    --surface-2: #232833;
    --text: #e7eaf0;
    --muted: #a0a9b8;
    --border: #2e3440;
    --accent: #86a8ff;
    --accent-text: #0f1420;
    --good: #5ccf96;
    --good-soft: #17352a;
    --warn: #e9bb60;
    --warn-soft: #3a2f16;
    --bad: #f58e85;
    --bad-soft: #3e1f1d;
    --info-soft: #1f2a44;
    --shadow: none;
  }
}

*, *::before, *::after { box-sizing: border-box; }

html { accent-color: var(--accent); -webkit-text-size-adjust: 100%; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 16px/1.5 system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
}

h1, h2, p, ul, dl, pre, fieldset { margin: 0; }
h1 { font-size: 1.6rem; line-height: 1.25; letter-spacing: -0.01em; }
h2 { font-size: 1.02rem; line-height: 1.3; }
ul { padding: 0; list-style: none; }
a { color: var(--accent); text-underline-offset: 2px; }
strong { font-weight: 600; }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }

.skip { position: absolute; left: -999px; }
.skip:focus { left: 16px; top: 8px; background: var(--surface); padding: 6px 10px; border-radius: 8px; z-index: 5; }

/* Header */
.top { background: var(--surface); border-bottom: 1px solid var(--border); }
.top-in {
  max-width: 1040px; margin: 0 auto; padding: 10px 16px;
  display: flex; flex-wrap: wrap; gap: 4px 20px; align-items: center; justify-content: space-between;
}
.brand { font-weight: 650; color: var(--text); text-decoration: none; letter-spacing: -0.01em; }
.top-nav { display: flex; flex-wrap: wrap; align-items: center; gap: 2px 16px; font-size: 0.94rem; }
.top-nav a { color: var(--muted); text-decoration: none; padding: 6px 0; }
.top-nav a:hover { color: var(--text); }

/* Page */
.page { max-width: 1040px; margin: 0 auto; padding: 24px 16px 56px; display: flex; flex-direction: column; gap: 16px; }
.page > *, .grid > * { min-width: 0; }
.narrow { max-width: 460px; }
.center { text-align: center; margin-inline: auto; }
.narrow-card { max-width: 620px; width: 100%; }
.muted { color: var(--muted); }
.small { font-size: 0.9rem; }
.big { font-size: 1.35rem; font-weight: 600; line-height: 1.3; }
.mono { font-family: var(--mono); font-size: 0.9em; }
.breakable { overflow-wrap: anywhere; }
.top-gap { margin-top: 16px; }

.crumb { font-size: 0.9rem; }
.crumb a { color: var(--muted); text-decoration: none; }
.crumb a::before { content: "← "; }
.site-head { display: flex; flex-direction: column; gap: 2px; }
.site-head h1 { overflow-wrap: anywhere; }

/* Section tabs wrap on a phone, so no section hides off the edge of the screen. */
.tabs { display: flex; flex-wrap: wrap; gap: 0 4px; border-bottom: 1px solid var(--border); margin-top: -4px; }
.tabs a {
  padding: 8px 12px; color: var(--muted); text-decoration: none; white-space: nowrap;
  border-bottom: 2px solid transparent; margin-bottom: -1px; font-size: 0.95rem;
}
.tabs a:hover { color: var(--text); }
.tabs a[aria-current="page"] { color: var(--text); border-bottom-color: var(--accent); font-weight: 600; }

/* Cards */
.card {
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius);
  box-shadow: var(--shadow); padding: 16px 18px;
  display: flex; flex-direction: column; gap: 10px; min-width: 0;
}
.card.center { align-items: center; padding: 32px 18px; }
.card.danger { border-color: var(--bad); }
.card-head { display: flex; flex-wrap: wrap; gap: 10px; align-items: center; justify-content: space-between; }
details.card summary { cursor: pointer; font-weight: 600; }
.grid { display: grid; gap: 16px; grid-template-columns: repeat(auto-fit, minmax(min(100%, 240px), 1fr)); }

.health { flex-direction: row; flex-wrap: wrap; align-items: center; justify-content: space-between; gap: 10px; }
.health.good { background: var(--good-soft); border-color: transparent; }
.health.warn { background: var(--warn-soft); border-color: transparent; }
.health.bad { background: var(--bad-soft); border-color: transparent; }
.health-title { font-size: 1.2rem; font-weight: 600; display: flex; align-items: center; gap: 10px; }

/* Status */
.dot { flex: none; display: inline-block; width: 10px; height: 10px; border-radius: 50%; background: var(--muted); }
.dot.good { background: var(--good); }
.dot.warn { background: var(--warn); }
.dot.bad { background: var(--bad); }
.status { display: inline-flex; align-items: center; gap: 8px; }
.tag {
  display: inline-block; padding: 1px 8px; border-radius: 999px; font-size: 0.8rem; font-weight: 500;
  background: var(--surface-2); color: var(--muted); white-space: nowrap;
}
.tag.warn { background: var(--warn-soft); color: var(--warn); }

.notice { padding: 10px 14px; border-radius: 10px; background: var(--info-soft); }
.notice.warn { background: var(--warn-soft); }
.notice.ok { background: var(--good-soft); }

/* Sites overview */
.site-grid { display: grid; gap: 16px; grid-template-columns: repeat(auto-fill, minmax(min(100%, 280px), 1fr)); }
.site-card { height: 100%; gap: 4px; color: var(--text); text-decoration: none; align-items: flex-start; }
.site-card:hover { border-color: var(--accent); }
.site-name { font-weight: 600; font-size: 1.08rem; overflow-wrap: anywhere; }
.site-card .status { margin-top: 8px; }

/* Lists of things: a line on a laptop, stacked on a phone. */
.rows { display: flex; flex-direction: column; }
.row {
  display: flex; flex-wrap: wrap; align-items: center; gap: 4px 16px; padding: 10px 0;
  border-top: 1px solid var(--border);
}
.row:first-child { border-top: 0; padding-top: 2px; }
.row:last-child { padding-bottom: 0; }
.row-main { display: flex; flex-wrap: wrap; align-items: center; gap: 4px 8px; flex: 1 1 240px; min-width: 0; overflow-wrap: anywhere; }
.row-meta { display: flex; flex-wrap: wrap; gap: 2px 14px; color: var(--muted); font-size: 0.9rem; min-width: 0; }

.facts { display: flex; flex-direction: column; gap: 4px; }
.facts div { display: flex; justify-content: space-between; gap: 12px; }
.facts dt { color: var(--muted); }
.facts dd { margin: 0; overflow-wrap: anywhere; text-align: end; }

progress { width: 100%; height: 8px; }

/* Buttons */
.button {
  display: inline-block; font: inherit; font-weight: 500; font-size: 0.95rem; line-height: 1.3;
  padding: 8px 14px; border-radius: 9px; border: 1px solid var(--border);
  background: var(--surface); color: var(--text); text-decoration: none; cursor: pointer; text-align: center;
}
.button:hover:not(:disabled) { border-color: var(--muted); }
.button.primary { background: var(--accent); border-color: var(--accent); color: var(--accent-text); }
.button.danger { background: var(--bad); border-color: var(--bad); color: var(--surface); }
.button:disabled { opacity: 0.5; cursor: not-allowed; }
.button.wide { width: 100%; }
.button.small-button { padding: 5px 11px; font-size: 0.9rem; }
.button-row { display: flex; flex-wrap: wrap; gap: 10px; align-items: center; }
.button-row.end { justify-content: flex-end; }
.link { font: inherit; background: none; border: 0; padding: 6px 0; color: var(--muted); cursor: pointer; }
.link:hover { color: var(--text); }

/* Forms */
.stack { display: flex; flex-direction: column; gap: 14px; }
.inline-form { display: flex; flex-wrap: wrap; gap: 12px; align-items: flex-end; }
.grow { flex: 1 1 200px; }
.field { display: flex; flex-direction: column; gap: 4px; min-width: 0; }
label { font-weight: 500; font-size: 0.94rem; }
.hint { color: var(--muted); font-size: 0.86rem; }
input:not([type="checkbox"]), select, textarea {
  font: inherit; width: 100%; padding: 9px 11px; border-radius: 9px;
  border: 1px solid var(--border); background: var(--surface); color: var(--text);
}
input:user-invalid, textarea:user-invalid { border-color: var(--bad); }
textarea { font-family: var(--mono); font-size: 0.86rem; resize: vertical; }
.code-input { font-family: var(--mono); font-size: 1.25rem; letter-spacing: 0.16em; }
.with-toggle { position: relative; }
.with-toggle input { padding-right: 60px; }
.with-toggle .link { position: absolute; right: 12px; top: 50%; transform: translateY(-50%); font-size: 0.86rem; }
.perm-set { border: 1px solid var(--border); border-radius: 10px; padding: 8px 14px 12px; display: grid; gap: 4px 16px; grid-template-columns: repeat(auto-fit, minmax(min(100%, 240px), 1fr)); min-width: 0; }
.perm-set legend { font-weight: 600; padding: 0 6px; overflow-wrap: anywhere; }
.check { font-weight: 400; display: flex; gap: 8px; align-items: center; }
.plain-list { padding-left: 20px; list-style: disc; display: flex; flex-direction: column; gap: 6px; }

/* Logs */
.log {
  background: var(--surface-2); border: 1px solid var(--border); border-radius: 10px; padding: 12px 14px;
  font-family: var(--mono); font-size: 0.8rem; line-height: 1.55;
  overflow: auto; max-height: 65vh; white-space: pre;
}
.log.short { max-height: none; }
.log.breakable { white-space: pre-wrap; }

/* Sign-in pages */
.auth-main { min-height: 100dvh; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 12px; padding: 24px 16px; }
.auth-card {
  width: 100%; max-width: 400px; background: var(--surface); border: 1px solid var(--border);
  border-radius: 16px; box-shadow: var(--shadow); padding: 28px 24px; display: flex; flex-direction: column; gap: 14px;
}
.auth-card h1 { font-size: 1.35rem; }
.qr { display: block; margin: 0 auto; border-radius: 8px; background: #fff; max-width: 100%; height: auto; }
.codes { display: grid; grid-template-columns: repeat(auto-fit, minmax(min(100%, 170px), 1fr)); gap: 6px 12px; background: var(--surface-2); border-radius: 10px; padding: 12px 14px; }

/* Confirm dialog */
dialog {
  border: 1px solid var(--border); border-radius: 14px; background: var(--surface); color: var(--text);
  padding: 20px; width: min(440px, calc(100vw - 32px));
}
dialog form { display: flex; flex-direction: column; gap: 12px; }
dialog h2 { font-size: 1.15rem; }
dialog::backdrop { background: rgb(10 14 22 / 50%); overflow: hidden; overscroll-behavior: contain; }
dialog:modal { overscroll-behavior: contain; }

@media (forced-colors: active) {
  .dot { forced-color-adjust: none; }
}
