:root {
  color-scheme: light dark;
  --bg: #f4f5f7;
  --surface: #ffffff;
  --text: #1c1f24;
  --muted: #646b76;
  --border: #d9dce1;
  --accent: #2f6fde;
  --accent-text: #ffffff;
  --danger: #c4372d;
  --ok-bg: #e5f4ea;
  --ok-text: #1d6b36;
  --err-bg: #fbe7e5;
  --err-text: #9b2a22;
  --radius: 10px;
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  line-height: 1.5;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #14161a;
    --surface: #1d2026;
    --text: #e7e9ec;
    --muted: #9aa1ab;
    --border: #343841;
    --accent: #5b8ff0;
    --danger: #e0645a;
    --ok-bg: #173323;
    --ok-text: #8fd6a6;
    --err-bg: #3a1c1a;
    --err-text: #f2a29b;
  }
}

* { box-sizing: border-box; }
body { margin: 0; background: var(--bg); color: var(--text); }
main { max-width: 960px; margin: 0 auto; padding: 1.5rem 1rem 3rem; }
h1 { font-size: 1.6rem; margin: 0 0 1rem; }
h2 { font-size: 1.15rem; margin: 0 0 .75rem; }
a { color: var(--accent); }
code { font-size: .9em; word-break: break-all; }
.muted { color: var(--muted); }
.small { font-size: .875rem; }
.center { text-align: center; }
.warn { color: var(--danger); }
.visually-hidden { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }

/* top bar */
.topbar {
  display: flex; align-items: center; gap: 1.5rem; flex-wrap: wrap;
  padding: .6rem 1rem; background: var(--surface); border-bottom: 1px solid var(--border);
}
.brand { font-weight: 700; color: var(--text); text-decoration: none; }
.topbar nav { display: flex; gap: 1rem; flex: 1; }
.topbar nav a { color: var(--muted); text-decoration: none; padding: .25rem 0; }
.topbar nav a.active { color: var(--text); border-bottom: 2px solid var(--accent); }
.logout { display: flex; align-items: center; gap: .75rem; margin: 0; }
.who { color: var(--muted); font-size: .9rem; }

/* cards, forms */
.card {
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius);
  padding: 1.25rem; margin-bottom: 1rem;
}
.stack { display: flex; flex-direction: column; gap: .75rem; max-width: 26rem; margin-bottom: 1rem; }
label { display: flex; flex-direction: column; gap: .3rem; font-size: .925rem; }
label.check { flex-direction: row; align-items: center; gap: .5rem; }
fieldset { border: 1px solid var(--border); border-radius: var(--radius); padding: .75rem 1rem; margin: 0; }
legend { padding: 0 .3rem; font-size: .925rem; }
input:not([type=checkbox]) {
  font: inherit; padding: .55rem .7rem; border: 1px solid var(--border); border-radius: 8px;
  background: var(--bg); color: var(--text);
}
input[type=checkbox] { width: 1.1rem; height: 1.1rem; accent-color: var(--accent); }
input:focus-visible, button:focus-visible, a:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }

button, .button {
  font: inherit; cursor: pointer; padding: .55rem 1rem; border-radius: 8px;
  border: 1px solid var(--border); background: var(--surface); color: var(--text);
  text-decoration: none; display: inline-block;
}
button.primary, .button.primary { background: var(--accent); border-color: var(--accent); color: var(--accent-text); }
button.danger { background: transparent; border-color: var(--danger); color: var(--danger); }
button.link { border: 0; background: none; padding: 0; color: var(--accent); }
.actions { display: flex; flex-wrap: wrap; gap: .5rem; align-items: center; }
form.inline { display: inline; margin: 0; }

.alert { padding: .65rem .9rem; border-radius: 8px; margin: 0 0 1rem; }
.alert.error { background: var(--err-bg); color: var(--err-text); }
.alert.ok { background: var(--ok-bg); color: var(--ok-text); }

/* sign-in screens */
body.auth main { min-height: 100vh; display: grid; place-items: center; }
.auth-card { width: min(100%, 24rem); display: flex; flex-direction: column; gap: .85rem; }
.auth-card h1 { margin: 0; }
.auth-card p { margin: 0; }

/* service tiles */
.tiles { list-style: none; padding: 0; margin: 0; display: grid; gap: 1rem; grid-template-columns: repeat(auto-fill, minmax(200px, 1fr)); }
.tile {
  display: flex; flex-direction: column; gap: .25rem; height: 100%;
  padding: 1.4rem 1.25rem; border-radius: var(--radius); border: 1px solid var(--border);
  background: var(--surface); color: var(--text); text-decoration: none;
  transition: border-color .15s, transform .15s;
}
a.tile:hover { border-color: var(--accent); transform: translateY(-2px); }
.tile-name { font-size: 1.2rem; font-weight: 600; }
.tile-desc { color: var(--muted); font-size: .9rem; }
.tile.disabled { opacity: .55; }

/* admin */
.page-head { display: flex; justify-content: space-between; align-items: center; gap: 1rem; margin-bottom: 1rem; }
.page-head h1 { margin: 0; }
.table-wrap { overflow-x: auto; margin-bottom: 1rem; }
table { border-collapse: collapse; width: 100%; }
th, td { padding: .5rem .6rem; border-bottom: 1px solid var(--border); text-align: left; vertical-align: middle; }
thead th { font-size: .85rem; color: var(--muted); font-weight: 600; white-space: nowrap; }
tbody th { font-weight: 500; white-space: nowrap; }
tr.is-disabled th, tr.is-disabled td { opacity: .6; }
.badge {
  display: inline-block; font-size: .7rem; font-weight: 600; text-transform: uppercase; letter-spacing: .03em;
  padding: .1rem .4rem; border-radius: 4px; background: var(--bg); color: var(--muted); border: 1px solid var(--border);
  vertical-align: middle;
}
.badge.warn { color: var(--danger); border-color: var(--danger); }
.danger-zone { border-color: var(--danger); }
table.log td { font-size: .85rem; }
.qr { display: block; background: #fff; padding: 8px; border-radius: 8px; margin-bottom: .5rem; }
