:root {
  color-scheme: light;
  --bg: #f4f5f7;
  --surface: #ffffff;
  --surface-2: #f8f9fb;
  --fg: #1c1d21;
  --muted: #646872;
  --line: #e1e3e8;
  --accent: #2557d6;
  --accent-fg: #ffffff;
  --ok: #1d8a4e;
  --warn: #b26a00;
  --bad: #c62f2f;
  --chip: #eef0f4;
  --shadow: 0 1px 2px rgba(16, 20, 30, .06), 0 1px 1px rgba(16, 20, 30, .04);
  --radius: 10px;
  --mono: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
}
@media (prefers-color-scheme: dark) {
  :root {
    color-scheme: dark;
    --bg: #131417;
    --surface: #1c1d22;
    --surface-2: #22242a;
    --fg: #e9eaee;
    --muted: #9a9ea8;
    --line: #2f3139;
    --accent: #6d97ff;
    --accent-fg: #0d1222;
    --ok: #4cc283;
    --warn: #e4a443;
    --bad: #f07272;
    --chip: #2a2c33;
    --shadow: none;
  }
}

* { box-sizing: border-box; }
html, body { margin: 0; }
body {
  background: var(--bg);
  color: var(--fg);
  font: 14px/1.5 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
}
a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }
h1 { font-size: 1.45rem; margin: 0; line-height: 1.25; }
h2 { font-size: 1.02rem; margin: 0 0 .75rem; }
h3 { font-size: .8rem; margin: 1.25rem 0 .5rem; text-transform: uppercase; letter-spacing: .05em; color: var(--muted); }
code, .mono { font-family: var(--mono); font-size: .92em; }
[hidden] { display: none !important; }

/* Layout */
.shell { display: grid; grid-template-columns: 220px 1fr; min-height: 100vh; }
.side {
  background: var(--surface);
  border-right: 1px solid var(--line);
  padding: 1.1rem .75rem;
  display: flex;
  flex-direction: column;
  gap: .15rem;
  position: sticky;
  top: 0;
  height: 100vh;
}
.side-top { display: flex; align-items: center; justify-content: space-between; padding: 0 .6rem .9rem; }
.brand { font-weight: 700; font-size: 1.05rem; display: flex; align-items: center; gap: .5rem; color: var(--fg); }
.brand:hover { text-decoration: none; }
.menu-btn { display: none; }
.brand-mark { width: 30px; height: 30px; display: block; }
.nav a {
  display: block;
  padding: .45rem .6rem;
  border-radius: 7px;
  color: var(--fg);
}
.nav a:hover { background: var(--surface-2); text-decoration: none; }
.nav a.active { background: var(--chip); font-weight: 600; }
.side-foot { margin-top: auto; padding: .6rem; color: var(--muted); font-size: .85rem; }
.side-foot button { margin-top: .4rem; }
.side-foot .version { font-size: .75rem; margin-top: .15rem; }
main { padding: 1.5rem 2rem 4rem; min-width: 0; max-width: 1280px; }
.page-head { display: flex; align-items: center; gap: 1rem; flex-wrap: wrap; margin-bottom: 1.25rem; }
.page-head .spacer { flex: 1; }
.sub { color: var(--muted); }

/* Tablets and phones: the sidebar becomes a sticky top bar with a menu button */
@media (max-width: 820px) {
  .shell { grid-template-columns: 1fr; }
  .side {
    position: sticky;
    top: 0;
    z-index: 5;
    height: auto;
    max-height: 100vh;
    overflow-y: auto;
    padding: calc(.5rem + env(safe-area-inset-top, 0px)) 1rem .5rem;
    gap: 0;
    border-right: 0;
    border-bottom: 1px solid var(--line);
  }
  .side-top { padding: 0; }
  .menu-btn {
    display: inline-flex;
    flex-direction: column;
    justify-content: center;
    gap: 5px;
    width: 44px;
    height: 44px;
    padding: 0 11px;
    margin-right: -.5rem;
    border: 0;
    background: transparent;
  }
  .menu-btn span { display: block; height: 2px; border-radius: 2px; background: var(--fg); transition: transform .15s, opacity .15s; }
  .side.open .menu-btn span:nth-child(1) { transform: translateY(7px) rotate(45deg); }
  .side.open .menu-btn span:nth-child(2) { opacity: 0; }
  .side.open .menu-btn span:nth-child(3) { transform: translateY(-7px) rotate(-45deg); }
  .side .nav, .side .side-foot { display: none; }
  .side.open .nav { display: flex; flex-direction: column; padding: .5rem 0; }
  .side.open .nav a { padding: .7rem .6rem; font-size: 1rem; }
  .side.open .side-foot {
    display: flex;
    align-items: center;
    justify-content: space-between;
    flex-wrap: wrap;
    gap: .25rem 1rem;
    margin: 0;
    padding: .75rem .6rem .25rem;
    border-top: 1px solid var(--line);
  }
  .side-foot button { margin-top: 0; }
  main { padding: 1rem 1rem calc(3rem + env(safe-area-inset-bottom, 0px)); }
  /* 16px stops iOS zooming into fields on focus */
  input[type=text], input[type=password], input[type=number], input[type=search], input[type=url], select, textarea { font-size: 16px; }
}

/* Phones */
@media (max-width: 640px) {
  h1 { font-size: 1.25rem; }
  .page-head { gap: .5rem .75rem; margin-bottom: 1rem; }
  .card { padding: 1rem; }
  .table-wrap { margin: 0 -1rem; padding: 0 1rem; }
  .hide-sm { display: none; }
  td.trunc { max-width: 160px; }
  th, td { padding: .5rem .45rem; }
  dl.kv { grid-template-columns: 1fr; gap: 0; }
  dl.kv dd { margin-bottom: .5rem; }
  .row { gap: 0 .75rem; }
  .row > .field { flex-basis: 100%; }
  .tiles { grid-template-columns: repeat(2, 1fr); gap: .75rem; }
  .tile .num { font-size: 1.6rem; }
  #toasts { left: 1rem; right: 1rem; bottom: calc(1rem + env(safe-area-inset-bottom, 0px)); }
  .toast { max-width: none; }
  .shot { max-width: 140px; }
}

/* Touch screens: bigger targets */
@media (pointer: coarse) {
  button, .btn { padding: .6rem 1rem; }
  button.small { padding: .45rem .75rem; }
  input[type=checkbox] { width: 1.25rem; height: 1.25rem; }
}

/* Cards and grids */
.card {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 1.1rem 1.2rem;
  min-width: 0;
}
.grid { display: grid; gap: 1rem; }
.grid-2 { grid-template-columns: repeat(auto-fit, minmax(min(360px, 100%), 1fr)); }
.grid-3 { grid-template-columns: repeat(auto-fit, minmax(min(280px, 100%), 1fr)); }
.stack > * + * { margin-top: 1rem; }
.tiles { display: grid; grid-template-columns: repeat(auto-fit, minmax(160px, 1fr)); gap: 1rem; margin-bottom: 1rem; }
.tile { color: var(--fg); }
.tile:hover { text-decoration: none; border-color: var(--accent); }
.tile .num { font-size: 1.9rem; font-weight: 650; line-height: 1.1; font-variant-numeric: tabular-nums; }
.tile .label { color: var(--muted); font-size: .85rem; }

/* Tables */
.table-wrap { overflow-x: auto; margin: 0 -1.2rem; padding: 0 1.2rem; }
table { width: 100%; border-collapse: collapse; }
th, td { text-align: left; padding: .55rem .6rem; border-bottom: 1px solid var(--line); vertical-align: top; }
th { font-size: .78rem; font-weight: 600; color: var(--muted); text-transform: uppercase; letter-spacing: .04em; white-space: nowrap; }
tbody tr:last-child td { border-bottom: 0; }
tbody tr.clickable { cursor: pointer; }
tbody tr.clickable:hover { background: var(--surface-2); }
td.num, th.num { text-align: right; font-variant-numeric: tabular-nums; }
td.trunc { max-width: 280px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.empty { color: var(--muted); padding: 1.5rem 0; text-align: center; }

/* Key/value lists */
dl.kv { display: grid; grid-template-columns: minmax(120px, max-content) 1fr; gap: .35rem 1rem; margin: 0; }
dl.kv dt { color: var(--muted); }
dl.kv dd { margin: 0; overflow-wrap: anywhere; }

/* Forms */
label { display: block; font-weight: 550; margin-bottom: .25rem; }
.field { margin-bottom: .85rem; }
.field .help { color: var(--muted); font-size: .85rem; font-weight: 400; margin-top: .2rem; }
.row { display: flex; gap: .75rem; flex-wrap: wrap; align-items: flex-end; }
.row > .field { flex: 1 1 160px; }
input[type=text], input[type=password], input[type=number], input[type=search], input[type=url], select, textarea {
  width: 100%;
  font: inherit;
  color: inherit;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 7px;
  padding: .45rem .6rem;
}
textarea { min-height: 4.5rem; resize: vertical; }
input:focus, select:focus, textarea:focus, button:focus-visible { outline: 2px solid var(--accent); outline-offset: 1px; }
input:disabled, select:disabled, textarea:disabled { opacity: .55; }
input[type=checkbox] { width: 1rem; height: 1rem; accent-color: var(--accent); vertical-align: -2px; }
.check { display: inline-flex; gap: .4rem; align-items: center; font-weight: 400; margin: 0; }
.error-text { color: var(--bad); font-size: .85rem; margin-top: .2rem; }

button, .btn {
  font: inherit;
  font-weight: 550;
  border: 1px solid var(--line);
  background: var(--surface);
  color: var(--fg);
  border-radius: 7px;
  padding: .42rem .85rem;
  cursor: pointer;
  white-space: nowrap;
}
button:hover { background: var(--surface-2); }
button.primary { background: var(--accent); border-color: var(--accent); color: var(--accent-fg); }
button.primary:hover { filter: brightness(1.07); }
button.danger { color: var(--bad); border-color: color-mix(in srgb, var(--bad) 40%, var(--line)); }
button.small { padding: .2rem .55rem; font-size: .85rem; }
button:disabled { opacity: .5; cursor: default; }
.actions { display: flex; gap: .5rem; flex-wrap: wrap; align-items: center; }

/* Chips and status */
.chip { display: inline-block; padding: .05rem .5rem; border-radius: 99px; background: var(--chip); font-size: .8rem; font-weight: 550; white-space: nowrap; }
.chip.ok { color: var(--ok); }
.chip.warn { color: var(--warn); }
.chip.bad { color: var(--bad); }
.dot { display: inline-block; width: .55rem; height: .55rem; border-radius: 50%; background: var(--muted); margin-right: .45rem; vertical-align: 1px; }
.dot.ok { background: var(--ok); }
.dot.bad { background: var(--bad); }

/* Policy editor */
.policy-group + .policy-group { margin-top: 1.25rem; }
.policy-row {
  display: grid;
  grid-template-columns: 1fr minmax(200px, 300px);
  gap: .4rem 1.25rem;
  padding: .7rem 0;
  border-top: 1px solid var(--line);
}
.policy-row .meta label { margin: 0; }
.policy-row .meta .help { color: var(--muted); font-size: .85rem; }
.policy-row .control { display: flex; flex-direction: column; gap: .35rem; }
.policy-row .inherit { color: var(--muted); font-size: .85rem; overflow-wrap: anywhere; }
.policy-row .src { font-size: .75rem; }
@media (max-width: 640px) { .policy-row { grid-template-columns: 1fr; } }

/* Enrollment */
.enroll-card { display: grid; grid-template-columns: 160px 1fr; gap: 1.1rem; align-items: start; }
.qr { width: 160px; height: 160px; border-radius: 6px; background: #fff; }
.code-big { font-family: var(--mono); font-size: 1.35rem; font-weight: 650; letter-spacing: .06em; }
@media (max-width: 520px) { .enroll-card { grid-template-columns: 1fr; } }

.shot { max-width: 220px; max-height: 160px; border: 1px solid var(--line); border-radius: 6px; display: block; }
.secret-box { background: var(--surface-2); border: 1px dashed var(--line); border-radius: 7px; padding: .6rem .75rem; font-family: var(--mono); overflow-wrap: anywhere; }

/* Login */
.login { min-height: 100vh; display: grid; place-items: center; padding: 1rem; }
.login .card { width: 100%; max-width: 360px; }
.login-logo { display: block; width: 112px; height: 112px; margin: 0 auto 1rem; }
.login h1 { text-align: center; }
.login .card > .sub { text-align: center; }
.login .sso { display: flex; flex-direction: column; gap: .5rem; margin-top: 1rem; }
.login .sso .btn { display: block; text-align: center; text-decoration: none; padding: .6rem 1rem; white-space: normal; }
.login .sso .btn:hover { background: var(--surface-2); }
.login .or { display: flex; align-items: center; gap: .75rem; color: var(--muted); font-size: .85rem; margin: 1rem 0 .25rem; }
.login .or::before, .login .or::after { content: ''; flex: 1; border-top: 1px solid var(--line); }
.banner { display: flex; gap: 1rem; align-items: center; justify-content: space-between; flex-wrap: wrap; border-color: var(--warn); }

/* Toasts */
#toasts { position: fixed; right: 1rem; bottom: 1rem; display: flex; flex-direction: column; gap: .5rem; z-index: 10; }
.toast { background: var(--fg); color: var(--bg); padding: .6rem .9rem; border-radius: 8px; box-shadow: 0 4px 14px rgba(0,0,0,.18); max-width: 420px; }
.toast.bad { background: var(--bad); color: #fff; }

.stack-gap { margin-top: 1rem; }

/* Card with a title and an action on one line */
.card-head { display: flex; align-items: center; justify-content: space-between; gap: .75rem; margin-bottom: .75rem; }
.card-head h2 { margin: 0; }

/* Device tags */
.tags { display: inline-flex; flex-wrap: wrap; gap: .25rem; margin-left: .4rem; vertical-align: middle; }
.chip.tag { font-weight: 500; color: var(--fg); text-decoration: none; }
.chip.tag:hover { background: var(--line); text-decoration: none; }

/* Screenshot gallery */
.shots { display: grid; grid-template-columns: repeat(auto-fill, minmax(180px, 1fr)); gap: .9rem; }
.shots figure { margin: 0; }
.shots img { width: 100%; height: auto; aspect-ratio: 4 / 3; object-fit: contain; background: var(--surface-2);
  border: 1px solid var(--line); border-radius: 6px; display: block; }
.shots .sub { margin-top: .25rem; font-size: .8rem; }
.shot-placeholder { aspect-ratio: 4 / 3; border: 1px dashed var(--line); border-radius: 6px; display: flex;
  flex-direction: column; align-items: center; justify-content: center; gap: .3rem; padding: .5rem; text-align: center; }

/* Schedules */
.days { display: flex; flex-wrap: wrap; gap: .4rem 1rem; }

/* Two-factor sign-in */
.code-input { font-family: var(--mono); font-size: 1.2rem; letter-spacing: .15em; }
.secret-box.recovery { display: grid; grid-template-columns: repeat(auto-fill, minmax(9rem, 1fr)); gap: .3rem 1rem; margin: .5rem 0; }

/* Health charts: one metric per chart, single accent colour, recessive axes */
.mini-charts { display: grid; grid-template-columns: repeat(auto-fit, minmax(260px, 1fr)); gap: 1rem 1.25rem; }
.mini-chart { margin: 0; }
.mini-chart figcaption { font-weight: 600; font-size: .9rem; margin-bottom: .25rem; }
.mini-chart figcaption .sub { font-weight: 400; }
.mini-chart svg { width: 100%; height: auto; max-height: 160px; display: block; overflow: visible; }
.mini-chart .bar { fill: var(--accent); }
.mini-chart .line { fill: none; stroke: var(--accent); stroke-width: 2; vector-effect: non-scaling-stroke; stroke-linejoin: round; }
.mini-chart .dot-mark { fill: var(--accent); stroke: var(--surface); stroke-width: 2; vector-effect: non-scaling-stroke; }
.mini-chart .grid-line { stroke: var(--line); stroke-width: 1; vector-effect: non-scaling-stroke; }
.mini-chart .axis-label { fill: var(--muted); font-size: 10px; }
.mini-chart .hit { fill: transparent; }
.mini-chart .hit:hover { fill: var(--fg); fill-opacity: .06; }

/* Profile history */
.changes { margin: 0; padding-left: 1.1rem; }
.changes li { margin: .1rem 0; }

/* Live view */
.live-frame { display: block; max-width: 100%; max-height: 70vh; margin-top: .75rem; border: 1px solid var(--line); border-radius: 6px; }
.empty-frame { aspect-ratio: 16 / 10; width: 100%; max-width: 640px; background: var(--surface-2); }

.side-foot .version a { color: inherit; text-decoration: underline; text-underline-offset: 2px; }
.side-foot .version a:hover { color: var(--accent); }

.release-notes { white-space: pre-wrap; font-family: inherit; background: var(--surface-2); border: 1px solid var(--line);
  border-radius: 7px; padding: .75rem; max-height: 22rem; overflow: auto; margin: 0 0 .75rem; }

/* Server settings: webhook rows */
.webhooks { display: flex; flex-direction: column; gap: .4rem; margin-bottom: .4rem; }
.webhook-row { display: flex; gap: .4rem; align-items: center; flex-wrap: wrap; }
.webhook-row input { flex: 1 1 14rem; min-width: 0; }

.warnings { list-style: none; padding: 0; margin: 0 0 .75rem; display: flex; flex-direction: column; gap: .4rem; }

.commits { margin: 0 0 .75rem; padding-left: 1.1rem; max-height: 16rem; overflow: auto; }
.commits li { margin: .15rem 0; }

/* Alert silences */
.silences { display: flex; flex-direction: column; gap: .4rem; margin-top: .5rem; }
.silence { display: flex; align-items: center; gap: .4rem; flex-wrap: wrap; }
.silence-form { display: flex; align-items: center; gap: .4rem; flex-wrap: wrap; }
.silence-form input[type=text] { flex: 1 1 10rem; min-width: 0; }

/* Settings: checkbox lists and event webhooks */
.choices { display: flex; flex-wrap: wrap; gap: .3rem 1rem; }
.event-hook { border: 1px solid var(--line); border-radius: 7px; padding: .5rem; display: flex; flex-direction: column; gap: .35rem; }

/* Audit filters */
.filters .field { flex: 1 1 10rem; }
