:root {
  color-scheme: light dark;
  --bg: #f4f6f9;
  --surface: #ffffff;
  --text: #17202e;
  --muted: #4d5a6d;
  --border: #c9d1dc;
  --accent: #1a5fc0;
  --accent-text: #ffffff;
  --good: #14633a;
  --good-bg: #ddf3e6;
  --warn: #7a4a00;
  --warn-bg: #fdecc8;
  --bad: #8f1d1d;
  --bad-bg: #fbdcdc;
  --muted-bg: #e6eaf0;
  --focus: #b35c00;
  --radius: 6px;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #111722;
    --surface: #1a2332;
    --text: #e6ebf2;
    --muted: #a9b5c6;
    --border: #35435a;
    --accent: #6ea8ff;
    --accent-text: #08111f;
    --good: #7ee0a6;
    --good-bg: #123a27;
    --warn: #f3c46b;
    --warn-bg: #433007;
    --bad: #ff9c9c;
    --bad-bg: #4a1b1b;
    --muted-bg: #2a3548;
    --focus: #ffb454;
  }
}

* { box-sizing: border-box; }

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

a { color: var(--accent); }
code { font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace; font-size: 0.9em; overflow-wrap: anywhere; }
h1 { font-size: 1.5rem; margin: 0 0 1rem; }
h2 { font-size: 1.15rem; margin: 0 0 0.75rem; }
h3 { font-size: 1rem; margin: 1rem 0 0.25rem; }
h1:focus { outline: none; }
:focus-visible { outline: 3px solid var(--focus); outline-offset: 2px; }
main:focus { outline: none; }

.visually-hidden {
  position: absolute; width: 1px; height: 1px; margin: -1px; padding: 0;
  overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; border: 0;
}

.skip-link {
  position: absolute; left: 0.5rem; top: -4rem; z-index: 10;
  background: var(--accent); color: var(--accent-text); border: 0; border-radius: var(--radius);
  padding: 0.5rem 0.75rem; font: inherit;
}
.skip-link:focus { top: 0.5rem; }

.topbar {
  display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between; gap: 0.5rem 1rem;
  padding: 0.75rem 1rem; background: var(--surface); border-bottom: 1px solid var(--border);
}
.brand { color: var(--text); font-weight: 700; text-decoration: none; }
.account { display: flex; align-items: center; gap: 0.75rem; }
.account[hidden], .nav[hidden] { display: none; }
.whoami { color: var(--muted); }

.layout { display: block; max-width: 72rem; margin: 0 auto; padding: 1rem; }
@media (min-width: 52rem) {
  .layout { display: grid; grid-template-columns: 13rem minmax(0, 1fr); gap: 1.5rem; align-items: start; }
  .layout:has(.nav[hidden]) { grid-template-columns: minmax(0, 1fr); }
}

.nav ul { list-style: none; margin: 0 0 1rem; padding: 0; display: flex; flex-wrap: wrap; gap: 0.25rem; }
@media (min-width: 52rem) { .nav ul { flex-direction: column; flex-wrap: nowrap; } }
.nav a {
  display: block; padding: 0.5rem 0.75rem; border-radius: var(--radius); color: var(--text); text-decoration: none;
  min-height: 2.5rem;
}
.nav a:hover { background: var(--muted-bg); }
.nav a[aria-current="page"] { background: var(--accent); color: var(--accent-text); font-weight: 600; }
.nav-label { width: 100%; padding: 0.5rem 0.75rem 0; color: var(--muted); font-size: 0.8rem; text-transform: uppercase; letter-spacing: 0.05em; }

.main { min-width: 0; }
.stack > * + * { margin-top: 1rem; }
.card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 1rem; }
.meta, .hint { color: var(--muted); margin: 0.25rem 0; font-size: 0.9rem; }
.status-line { color: var(--muted); }
.status-line.error { color: var(--bad); }
.warning { background: var(--warn-bg); color: var(--warn); padding: 0.5rem 0.75rem; border-radius: var(--radius); }

.button {
  display: inline-block; background: var(--accent); color: var(--accent-text); border: 1px solid var(--accent);
  border-radius: var(--radius); padding: 0.5rem 1rem; font: inherit; text-decoration: none; cursor: pointer; min-height: 2.5rem;
}
.button.secondary { background: transparent; color: var(--accent); }
.button:disabled { opacity: 0.6; cursor: progress; }

.field { display: flex; flex-direction: column; gap: 0.25rem; margin-bottom: 0.75rem; }
.field label { font-weight: 600; }
input, select, textarea {
  font: inherit; color: var(--text); background: var(--bg); border: 1px solid var(--border);
  border-radius: var(--radius); padding: 0.5rem 0.625rem; min-height: 2.5rem; max-width: 100%;
}
textarea { resize: vertical; min-width: 0; }
fieldset { border: 1px solid var(--border); border-radius: var(--radius); padding: 0.75rem; min-width: 0; }
.login { max-width: 24rem; margin: 2rem auto; }
.form-message { min-height: 1.5rem; margin: 0 0 0.75rem; color: var(--bad); font-weight: 600; }
.filters { display: flex; flex-wrap: wrap; align-items: flex-end; gap: 0.5rem 1rem; }
.filters .field { margin-bottom: 0; }
.filters .button { align-self: flex-end; }

.table-wrap { overflow-x: auto; background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); }
table { border-collapse: collapse; width: 100%; }
th, td { text-align: left; padding: 0.5rem 0.75rem; border-bottom: 1px solid var(--border); vertical-align: top; }
th { color: var(--muted); font-size: 0.85rem; white-space: nowrap; }
tbody tr:last-child td { border-bottom: 0; }

.badge { display: inline-block; padding: 0 0.5rem; border-radius: 999px; font-size: 0.8rem; font-weight: 600; white-space: nowrap; }
.badge-good { background: var(--good-bg); color: var(--good); }
.badge-warn { background: var(--warn-bg); color: var(--warn); }
.badge-bad { background: var(--bad-bg); color: var(--bad); }
.badge-muted, .badge-neutral { background: var(--muted-bg); color: var(--muted); }

.pager { display: flex; flex-wrap: wrap; gap: 1rem; align-items: center; padding: 0.75rem 0; }
.empty { background: var(--surface); border: 1px dashed var(--border); border-radius: var(--radius); padding: 1.25rem; text-align: center; }
.empty-title { font-weight: 700; margin: 0 0 0.25rem; }
.error-panel { background: var(--bad-bg); color: var(--text); border: 1px solid var(--bad); border-radius: var(--radius); padding: 1rem; }
.error-title { color: var(--bad); font-weight: 700; margin: 0 0 0.25rem; }

.fields { display: grid; grid-template-columns: minmax(7rem, 12rem) minmax(0, 1fr); gap: 0.5rem 1rem; margin: 0; }
.fields dt { color: var(--muted); font-weight: 600; }
.fields dd { margin: 0; overflow-wrap: anywhere; }
.fields ul, .issues { margin: 0; padding-left: 1.25rem; }
.raw pre { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 0.75rem; overflow-x: auto; }

@media (max-width: 36rem) {
  .fields { grid-template-columns: minmax(0, 1fr); gap: 0; }
  .fields dd { margin-bottom: 0.5rem; }
}
@media (prefers-reduced-motion: reduce) { * { scroll-behavior: auto !important; } }
