:root {
  --bg: #f7f7f9;
  --surface: #ffffff;
  --text: #1c1e21;
  --text-muted: #5f6368;
  --border: #e2e4e8;
  --accent: #2f5fd6;
  --accent-contrast: #ffffff;
  --warning-bg: #fff4e0;
  --warning-text: #7a4b00;
  --error-bg: #fdecea;
  --error-text: #9c1c11;
  --ok: #17792f;
  --bad: #c02626;
  --code-bg: #f0f1f4;
  --shadow: 0 1px 3px rgba(0, 0, 0, 0.08);
  /* Tells the browser which palette to use for native form-control chrome (input/select/
     textarea backgrounds, scrollbars) when our own CSS doesn't cover something. Without this,
     a control we forget to style explicitly can silently fall back to a light native background
     while inheriting our (light-colored) dark-mode text — exactly the "light grey on white"
     illegible-field bug this rule prevents. */
  color-scheme: light;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #16171b;
    --surface: #1e2025;
    --text: #e7e8ea;
    --text-muted: #9a9ea6;
    --border: #2c2f36;
    --accent: #6f96f0;
    --accent-contrast: #0c1220;
    --warning-bg: #3a2c0d;
    --warning-text: #f0c674;
    --error-bg: #3a1616;
    --error-text: #f28b82;
    --ok: #4fd67a;
    --bad: #f28b82;
    --code-bg: #26282e;
    --shadow: 0 1px 3px rgba(0, 0, 0, 0.4);
    color-scheme: dark;
  }
}

* { box-sizing: border-box; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  line-height: 1.55;
}

a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }

.site-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0.75rem 1.5rem;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  box-shadow: var(--shadow);
}

.site-title {
  font-weight: 700;
  font-size: 1.1rem;
  color: var(--text);
}

.site-header nav {
  display: flex;
  align-items: center;
  gap: 1.25rem;
}

.logout-form { margin: 0; }
.logout-form button {
  background: none;
  border: none;
  color: var(--accent);
  cursor: pointer;
  font: inherit;
  padding: 0;
}
.logout-form button:hover { text-decoration: underline; }

main {
  max-width: 1040px;
  margin: 0 auto;
  padding: 2rem 1.5rem 4rem;
}

h1 { font-size: 1.6rem; margin-bottom: 1.25rem; }
h2 { font-size: 1.1rem; margin: 1.75rem 0 0.6rem; color: var(--text); }

.content-stamp { color: var(--text-muted); font-size: 0.85rem; }

.manifest-form {
  display: flex;
  flex-wrap: wrap;
  gap: 0.9rem;
  align-items: end;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 1rem;
  box-shadow: var(--shadow);
}

.manifest-form label {
  display: flex;
  flex-direction: column;
  gap: 0.3rem;
  font-size: 0.8rem;
  color: var(--text-muted);
  min-width: 160px;
}

/* One rule for every text-ish form control, applied globally rather than scoped per section —
   the previous per-section rules (.manifest-form input, .inline-label input, ...) left gaps
   where a control got no explicit border/background/width at all and fell back to the browser's
   native control chrome. That's the root cause of both complaints: fields sized to the browser's
   ~20-character default (too narrow) and, in dark mode, our light text color landing on the
   browser's white native background instead of our own (illegible). */
input[type="text"], input[type="password"], select {
  border: 1px solid var(--border);
  border-radius: 5px;
  padding: 0.45rem 0.6rem;
  background: var(--bg);
  color: var(--text);
  font: inherit;
  font-size: 0.9rem;
  width: 100%;
  min-width: 220px;
}

textarea {
  border: 1px solid var(--border);
  border-radius: 5px;
  padding: 0.45rem 0.6rem;
  background: var(--bg);
  color: var(--text);
  font: inherit;
  font-size: 0.9rem;
  width: 100%;
  box-sizing: border-box;
}

button {
  background: var(--accent);
  color: var(--accent-contrast);
  border: none;
  border-radius: 5px;
  padding: 0.5rem 1.1rem;
  font: inherit;
  font-weight: 600;
  cursor: pointer;
}
button:hover { filter: brightness(1.08); }

.reset-link { font-size: 0.85rem; margin-left: 0.25rem; }

.warning, .warnings-section li.warning {
  background: var(--warning-bg);
  color: var(--warning-text);
  border-radius: 5px;
  padding: 0.5rem 0.75rem;
  font-size: 0.9rem;
}

.error {
  background: var(--error-bg);
  color: var(--error-text);
  border-radius: 5px;
  padding: 0.6rem 0.85rem;
}

.matched-groups ul, .warnings-section ul {
  list-style: none;
  padding: 0;
  margin: 0;
  display: flex;
  flex-direction: column;
  gap: 0.35rem;
}

.ruling-group { margin-top: 1.5rem; }

.ruling-list {
  list-style: none;
  padding: 0;
  margin: 0;
  display: flex;
  flex-direction: column;
  gap: 0.9rem;
}

.ruling-list > li {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 0.85rem 1rem;
  box-shadow: var(--shadow);
}

.ruling-link { font-size: 1rem; }
.ruling-meta { display: block; color: var(--text-muted); font-size: 0.78rem; margin-top: 0.15rem; }
.ruling-summary { margin: 0.45rem 0 0; color: var(--text); font-size: 0.92rem; }
.shadowed { color: var(--text-muted); font-style: italic; }

.back-link { display: inline-block; margin-bottom: 1rem; font-size: 0.9rem; }

.ruling-detail {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 1.75rem 2rem;
  box-shadow: var(--shadow);
  margin-bottom: 1.5rem;
}

.ruling-detail .ruling-meta-line {
  color: var(--text-muted);
  font-size: 0.85rem;
  margin: 0 0 0.2rem;
}

.ruling-detail h2 { margin-top: 1.5rem; }
.ruling-detail p { margin: 0.6rem 0; }
.ruling-detail code {
  background: var(--code-bg);
  border-radius: 4px;
  padding: 0.1rem 0.35rem;
  font-size: 0.88em;
}
.ruling-detail pre {
  background: var(--code-bg);
  border-radius: 6px;
  padding: 0.9rem 1rem;
  overflow-x: auto;
}
.ruling-detail pre code { background: none; padding: 0; }

.subtitle { color: var(--text-muted); font-size: 0.9rem; }

section pre {
  background: var(--code-bg);
  border-radius: 6px;
  padding: 0.75rem 0.9rem;
  overflow-x: auto;
  font-size: 0.85rem;
  white-space: pre-wrap;
  word-break: break-word;
}

.manual-call textarea { font-family: ui-monospace, "SF Mono", Consolas, monospace; }
.manual-call form { display: flex; flex-direction: column; gap: 0.5rem; align-items: start; margin-bottom: 0.75rem; }

.status-ok { color: var(--ok); font-weight: 600; }
.status-bad { color: var(--bad); font-weight: 600; }

.login-body {
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 100vh;
  margin: 0;
  background: var(--bg);
}

.login-form {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 2.5rem;
  box-shadow: var(--shadow);
  display: flex;
  flex-direction: column;
  gap: 0.9rem;
  width: 340px;
}

.login-form h1 { font-size: 1.3rem; margin: 0 0 0.5rem; text-align: center; }
.login-form label { display: flex; flex-direction: column; gap: 0.3rem; font-size: 0.85rem; color: var(--text-muted); }

/* Inline <code> outside ruling-detail (which has its own rule) — headers, help text, nav */
h1 code, h2 code, p code, dt code, li code {
  background: var(--code-bg);
  border-radius: 4px;
  padding: 0.1rem 0.35rem;
  font-size: 0.88em;
}

.help-text { color: var(--text-muted); font-size: 0.85rem; margin: 0.3rem 0 0.75rem; }
.example-link { font-size: 0.85rem; margin: 0 0 0.5rem; }

/* .manual-call form uses align-items: start (so the Call button stays content-sized rather than
   stretching full-width), which means a field's width has to come from the field itself, not
   from the parent stretching it. Short fields (a ruling ID) get a comfortable fixed cap; the
   .wide-field modifier (used on the manifest-JSON textareas) opts out for fields that need real
   room to show JSON. */
.inline-label { display: flex; flex-direction: column; gap: 0.3rem; font-size: 0.8rem; color: var(--text-muted); max-width: 320px; }
.inline-label.wide-field { max-width: 100%; }

/* Generic elevated-card treatment — originally just for Help's sections, now shared by
   Test Harness too so its Health/Tools/manual-call blocks aren't bare text floating on the
   page background like the rest of the app's sections are. */
.panel {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 1.25rem 1.5rem;
  box-shadow: var(--shadow);
  margin-bottom: 1.25rem;
}
.panel h2 { margin-top: 0; }
.panel p { margin: 0.6rem 0; }

.tool-list dt { font-weight: 600; margin-top: 0.9rem; }
.tool-list dt:first-child { margin-top: 0; }
.tool-list dd { margin: 0.25rem 0 0; color: var(--text-muted); }

.manifest-fields { border-collapse: collapse; margin: 0.75rem 0; width: 100%; }
.manifest-fields td { padding: 0.4rem 0.75rem 0.4rem 0; border-bottom: 1px solid var(--border); font-size: 0.9rem; vertical-align: top; }
.manifest-fields td:first-child { white-space: nowrap; }

/* Compact ID index atop the raw all-rulings dump — deliberately NOT .ruling-list, which gives
   every <li> a full elevated-card treatment meant for title+summary entries, not a bare link. */
.toc {
  list-style: none;
  padding: 0.75rem 1rem;
  margin: 1rem 0;
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem 1rem;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 8px;
  font-size: 0.85rem;
}
.toc li { list-style: none; }
