:root {
  --teal: #0e4b4a;
  --teal-2: #0a3b3a;
  --teal-3: #072d2c;
  --cream: #f8f2e6;
  --cream-2: #f1e8d8;
  --paper: #fffdf8;
  --gold: #c6a15b;
  --gold-dark: #8d6f34;
  --ink: #1d2b2a;
  --muted: #60706d;
  --line: #ddd2bf;
  --line-strong: #c9bda8;
  --danger: #9b2f2f;
  --danger-bg: #fbeceb;
  --warn: #8a5c16;
  --warn-bg: #fbf2df;
  --ok: #2f6b4f;
  --ok-bg: #eaf3ed;
  --review: #7a4f12;
  --shadow: 0 10px 30px rgba(21, 47, 45, 0.08);
  --radius: 14px;
}

* { box-sizing: border-box; }
html { font-size: 17px; }
body {
  margin: 0;
  background:
    radial-gradient(1200px 600px at 80% -10%, rgba(198, 161, 91, 0.18), transparent 60%),
    radial-gradient(900px 500px at -10% 20%, rgba(14, 75, 74, 0.10), transparent 60%),
    var(--cream);
  color: var(--ink);
  font-family: "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  line-height: 1.55;
}

a { color: var(--teal); text-decoration-thickness: 1px; text-underline-offset: 3px; }
a:hover { color: var(--gold-dark); }
h1, h2, h3 { font-family: Georgia, "Times New Roman", serif; line-height: 1.18; margin: 0 0 0.4em; letter-spacing: -0.01em; }
h1 { font-size: clamp(2rem, 4vw, 2.8rem); }
h2 { font-size: 1.45rem; }
h3 { font-size: 1.15rem; }
p { margin: 0 0 0.9em; }
code, pre { font-family: "SFMono-Regular", Consolas, "Liberation Mono", Menlo, monospace; }
code { background: rgba(14, 75, 74, 0.08); padding: 0.1em 0.35em; border-radius: 5px; font-size: 0.88em; }
hr { border: 0; border-top: 1px solid var(--line); margin: 1.2rem 0; }
.muted { color: var(--muted); }
.small { font-size: 0.88rem; }
.error-text { color: var(--danger); font-weight: 600; }
.sr-only { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); }
.preserve-lines { white-space: pre-line; }

.topbar {
  position: sticky;
  top: 0;
  z-index: 30;
  display: flex;
  align-items: center;
  gap: 1.2rem;
  padding: 0.9rem 1.6rem;
  background: linear-gradient(180deg, var(--teal), var(--teal-2));
  color: var(--cream);
  box-shadow: 0 4px 20px rgba(7, 45, 44, 0.22);
}
.brand { display: flex; align-items: center; gap: 0.75rem; color: var(--cream); text-decoration: none; min-width: 250px; }
.brand:hover { color: #fff; }
.brand-avatar { width: 46px; height: 46px; border-radius: 50%; object-fit: cover; border: 2px solid var(--gold); background: var(--cream-2); }
.brand-copy b { display: block; font-family: Georgia, serif; font-size: 1.08rem; letter-spacing: 0.01em; }
.brand-copy small { display: block; color: #e8dcc4; font-size: 0.78rem; letter-spacing: 0.08em; text-transform: uppercase; }
.tabs { display: flex; gap: 0.25rem; flex: 1; flex-wrap: wrap; }
.tabs a { color: #e8e0cf; text-decoration: none; padding: 0.45rem 0.7rem; border-radius: 8px; font-weight: 600; font-size: 0.92rem; }
.tabs a:hover { background: rgba(255, 255, 255, 0.1); color: #fff; }
.tabs a.is-active { background: var(--cream); color: var(--teal); }
.top-actions { display: flex; align-items: center; gap: 0.5rem; flex-wrap: wrap; }
.mode-pill { display: inline-flex; align-items: center; padding: 0.3rem 0.6rem; border-radius: 999px; font-size: 0.72rem; font-weight: 800; letter-spacing: 0.08em; background: var(--cream-2); color: var(--teal); }
.mode-pill.mode-auto { background: var(--gold); color: var(--teal-3); }
.mode-pill.mode-preview { background: #e8dcc4; }
.nav-toggle { display: none; background: transparent; color: var(--cream); border: 1px solid rgba(255, 255, 255, 0.4); border-radius: 8px; padding: 0.4rem 0.7rem; font: inherit; }

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 0.35rem;
  border: 1px solid var(--teal);
  border-radius: 9px;
  padding: 0.58rem 0.95rem;
  background: var(--teal);
  color: #fff;
  font: inherit;
  font-weight: 700;
  font-size: 0.92rem;
  text-decoration: none;
  cursor: pointer;
  transition: transform 0.05s ease, background 0.15s ease, opacity 0.15s ease;
}
.btn:hover { background: var(--teal-2); color: #fff; }
.btn:active { transform: translateY(1px); }
.btn.primary { background: var(--teal); border-color: var(--teal); }
.btn.ghost { background: transparent; color: var(--teal); border-color: var(--line-strong); }
.btn.ghost:hover { background: rgba(14, 75, 74, 0.06); color: var(--teal); }
.btn.gold { background: var(--gold); border-color: var(--gold); color: var(--teal-3); }
.btn.danger { background: var(--danger); border-color: var(--danger); }
.btn.danger:hover { background: #7f2323; }
.btn.small { padding: 0.38rem 0.68rem; font-size: 0.84rem; border-radius: 7px; }
.btn:disabled { opacity: 0.45; cursor: not-allowed; }
.inline-form { display: inline; margin: 0; }
.button-row { display: flex; gap: 0.55rem; flex-wrap: wrap; align-items: center; margin-top: 1rem; }

.banner {
  margin: 0;
  padding: 0.9rem 1.6rem;
  border-bottom: 1px solid var(--line);
  font-size: 0.96rem;
}
.banner:empty { display: none; }
.banner-danger { background: var(--danger-bg); color: #6f1e1e; border-left: 6px solid var(--danger); }
.banner-warn { background: var(--warn-bg); color: #6b470f; border-left: 6px solid var(--gold); }
.banner ul { margin: 0.4rem 0 0 1.2rem; padding: 0; }

.main { max-width: 1420px; margin: 0 auto; padding: 1.6rem; }
.footer { max-width: 1420px; margin: 2rem auto 1rem; padding: 1rem 1.6rem; display: flex; gap: 1rem; flex-wrap: wrap; justify-content: space-between; color: var(--muted); font-size: 0.82rem; border-top: 1px solid var(--line); }
.footer a { color: var(--teal); }

.flashes { display: grid; gap: 0.5rem; margin-bottom: 1rem; }
.flash { padding: 0.75rem 1rem; border-radius: 10px; border: 1px solid var(--line); background: var(--paper); }
.flash-success { border-color: #b9d6c5; background: var(--ok-bg); color: #245c42; }
.flash-error { border-color: #e5bcbc; background: var(--danger-bg); color: #7d2424; }
.flash-warning { border-color: #e3cf9f; background: var(--warn-bg); color: #6b470f; }

.page-head { display: flex; align-items: flex-end; justify-content: space-between; gap: 1.5rem; margin: 0.5rem 0 1.3rem; }
.page-head-actions { display: flex; gap: 0.6rem; flex-wrap: wrap; align-items: center; }
.kicker { margin: 0 0 0.35rem; text-transform: uppercase; letter-spacing: 0.13em; font-size: 0.72rem; font-weight: 800; color: var(--gold-dark); }
.lede { max-width: 78ch; font-size: 1.02rem; color: #334542; }
.breadcrumb { margin: 0 0 0.6rem; font-size: 0.85rem; color: var(--muted); }

.stat-grid { display: grid; grid-template-columns: repeat(6, minmax(0, 1fr)); gap: 0.75rem; margin-bottom: 1.4rem; }
.stat { background: var(--paper); border: 1px solid var(--line); border-radius: var(--radius); padding: 0.9rem 1rem; box-shadow: var(--shadow); }
.stat span { display: block; text-transform: uppercase; letter-spacing: 0.08em; font-size: 0.68rem; font-weight: 800; color: var(--muted); }
.stat b { display: block; font-family: Georgia, serif; font-size: 1.75rem; color: var(--teal); line-height: 1.2; margin-top: 0.2rem; }
.stat small { display: block; color: var(--muted); font-size: 0.78rem; margin-top: 0.2rem; }

.two-col { display: grid; grid-template-columns: minmax(0, 1.35fr) minmax(0, 1fr); gap: 1rem; align-items: start; }
.section { margin-top: 1.7rem; }
.section-head { display: flex; align-items: flex-end; justify-content: space-between; gap: 1rem; margin-bottom: 0.8rem; }
.section-note { color: var(--muted); font-size: 0.87rem; max-width: 52ch; text-align: right; }
.panel { background: var(--paper); border: 1px solid var(--line); border-radius: var(--radius); padding: 1.15rem 1.25rem; box-shadow: var(--shadow); }
.panel-head { display: flex; align-items: flex-start; justify-content: space-between; gap: 1rem; margin-bottom: 0.8rem; }
.notice { margin-top: 1rem; padding: 0.8rem 1rem; border-radius: 10px; border: 1px solid var(--line); background: var(--cream); }
.notice-warn { background: var(--warn-bg); border-color: #e3cf9f; }
.notice ul { margin: 0.4rem 0 0 1.2rem; padding: 0; }

.meta-grid { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 0.7rem; margin-top: 0.9rem; }
.meta-grid > div { border-top: 1px solid var(--line); padding-top: 0.45rem; }
.meta-grid span { display: block; font-size: 0.72rem; text-transform: uppercase; letter-spacing: 0.08em; color: var(--muted); font-weight: 800; }
.meta-grid b { font-size: 0.92rem; }
.facts { display: grid; gap: 0.15rem; margin: 0; }
.facts > div { display: flex; justify-content: space-between; gap: 1rem; padding: 0.38rem 0; border-bottom: 1px solid var(--line); }
.facts > div:last-child { border-bottom: 0; }
.facts dt { color: var(--muted); font-size: 0.86rem; }
.facts dd { margin: 0; text-align: right; font-weight: 600; font-size: 0.9rem; }
.facts.compact > div { padding: 0.25rem 0; }

.post-preview {
  margin: 0.4rem 0 0.8rem;
  padding: 1rem 1.1rem;
  background: var(--cream);
  color: var(--ink);
  border: 1px solid var(--line-strong);
  border-left: 5px solid var(--gold);
  border-radius: 10px;
  white-space: pre-wrap;
  overflow-wrap: anywhere;
  font-size: 1rem;
  line-height: 1.6;
}
.post-preview.compact { font-size: 0.84rem; padding: 0.7rem 0.8rem; margin: 0.5rem 0; line-height: 1.5; }

.badge { display: inline-flex; align-items: center; padding: 0.24rem 0.5rem; border-radius: 999px; border: 1px solid var(--line); background: var(--cream); color: var(--ink); font-size: 0.7rem; font-weight: 800; text-transform: uppercase; letter-spacing: 0.05em; white-space: nowrap; }
.badge.urgent { background: var(--gold); border-color: var(--gold); color: var(--teal-3); }
.health-ok, .status-published, .eligibility-eligible { background: var(--ok-bg); border-color: #b9d6c5; color: var(--ok); }
.health-attention, .health-degraded, .status-unknown, .status-held, .status-retryable, .eligibility-review { background: var(--warn-bg); border-color: #e3cf9f; color: var(--review); }
.health-failed, .health-blocked, .status-failed, .status-expired, .eligibility-rejected, .eligibility-suppressed { background: var(--danger-bg); border-color: #e5bcbc; color: var(--danger); }
.status-reserved, .status-sending, .status-publishing, .status-queued { background: #e9f0ef; border-color: #b9cfcd; color: var(--teal); }
.status-external { background: #f0e9dc; border-color: var(--line-strong); color: #6b5b3c; }
.eligibility-duplicate, .eligibility-grouped, .eligibility-posted { background: #e9e5ef; border-color: #cdc4da; color: #4e3c66; }

.empty { padding: 1.4rem; text-align: center; color: var(--muted); border: 1px dashed var(--line-strong); border-radius: var(--radius); background: rgba(255, 253, 248, 0.5); }

.table-wrap { overflow-x: auto; border: 1px solid var(--line); border-radius: var(--radius); background: var(--paper); box-shadow: var(--shadow); }
table { width: 100%; border-collapse: collapse; font-size: 0.88rem; }
th, td { text-align: left; padding: 0.65rem 0.75rem; border-bottom: 1px solid var(--line); vertical-align: top; }
th { background: var(--cream-2); color: var(--teal); font-size: 0.72rem; text-transform: uppercase; letter-spacing: 0.08em; }
tr:last-child td { border-bottom: 0; }
td code { overflow-wrap: anywhere; }

.event-list { list-style: none; margin: 0; padding: 0; display: grid; gap: 0.5rem; }
.event-list li { display: grid; grid-template-columns: auto 1fr auto; gap: 0.7rem; align-items: start; padding: 0.55rem 0; border-bottom: 1px solid var(--line); }
.event-list li:last-child { border-bottom: 0; }
.event-list b { text-transform: capitalize; }
.event-list p { margin: 0.15rem 0 0; color: var(--muted); font-size: 0.85rem; overflow-wrap: anywhere; }
.event-list time { color: var(--muted); font-size: 0.8rem; white-space: nowrap; }
.event-level { display: inline-block; padding: 0.12rem 0.4rem; border-radius: 5px; background: var(--cream-2); font-size: 0.64rem; font-weight: 800; text-transform: uppercase; letter-spacing: 0.06em; }
.event-level.error { background: var(--danger-bg); color: var(--danger); }
.event-level.warning { background: var(--warn-bg); color: var(--review); }

.filters { display: flex; gap: 0.7rem; align-items: flex-end; flex-wrap: wrap; margin-bottom: 1.1rem; }
.filters label { display: grid; gap: 0.25rem; min-width: 160px; }
.filters label span { font-size: 0.72rem; font-weight: 800; text-transform: uppercase; letter-spacing: 0.07em; color: var(--muted); }

.candidate-list { display: grid; gap: 0.8rem; }
.candidate-card { display: grid; grid-template-columns: minmax(0, 1.55fr) minmax(280px, 1fr); gap: 1.1rem; background: var(--paper); border: 1px solid var(--line); border-radius: var(--radius); padding: 1rem 1.1rem; box-shadow: var(--shadow); }
.candidate-badges { display: flex; gap: 0.4rem; flex-wrap: wrap; margin-bottom: 0.45rem; }
.candidate-card h2 { font-size: 1.22rem; margin-bottom: 0.4rem; }
.candidate-card h2 a { color: var(--ink); text-decoration: none; }
.candidate-card h2 a:hover { color: var(--teal); text-decoration: underline; }
.candidate-meta { display: flex; flex-wrap: wrap; gap: 0.35rem 1rem; color: var(--muted); font-size: 0.82rem; }
.candidate-meta b { color: var(--ink); font-weight: 700; }
.reason { margin: 0.6rem 0; color: #3c4f4c; font-size: 0.9rem; }
.candidate-links { font-size: 0.8rem; color: var(--muted); }
.candidate-side { border-left: 1px solid var(--line); padding-left: 1rem; }
.quick-actions { display: flex; gap: 0.4rem; flex-wrap: wrap; }

.form-card { background: var(--paper); border: 1px solid var(--line); border-radius: var(--radius); padding: 1.3rem 1.4rem; box-shadow: var(--shadow); }
.form-card h2 { margin-top: 0; }
.form-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 0.9rem 1rem; }
.field { display: grid; gap: 0.3rem; }
.field.wide { grid-column: 1 / -1; }
.field > span { font-size: 0.78rem; font-weight: 800; text-transform: uppercase; letter-spacing: 0.06em; color: var(--muted); }
.field input, .field select, .field textarea {
  width: 100%;
  padding: 0.6rem 0.7rem;
  border: 1px solid var(--line-strong);
  border-radius: 8px;
  background: #fff;
  color: var(--ink);
  font: inherit;
}
.field input:focus, .field select:focus, .field textarea:focus { outline: 2px solid var(--gold); outline-offset: 1px; }
.field small { color: var(--muted); font-size: 0.78rem; }
.check-stack { display: grid; gap: 0.5rem; margin: 1rem 0; }
.check { display: flex; gap: 0.6rem; align-items: flex-start; font-size: 0.92rem; }
.check input { margin-top: 0.25rem; }
.check.field { grid-column: 1 / -1; }

.job-list { display: grid; gap: 0.9rem; }
.job-card { background: var(--paper); border: 1px solid var(--line); border-radius: var(--radius); padding: 1rem 1.15rem; box-shadow: var(--shadow); }
.job-head { display: flex; justify-content: space-between; gap: 1rem; }
.job-head h2 { font-size: 1.2rem; margin-bottom: 0.3rem; }
.job-head h2 a { color: var(--ink); text-decoration: none; }
.job-head h2 a:hover { color: var(--teal); text-decoration: underline; }
.job-side { display: grid; gap: 0.2rem; text-align: right; min-width: 190px; }
.job-actions { display: flex; gap: 0.5rem; align-items: flex-start; flex-wrap: wrap; }
.resolve-box { flex-basis: 100%; border-top: 1px solid var(--line); margin-top: 0.6rem; padding-top: 0.7rem; background: var(--warn-bg); border-radius: 9px; padding: 0.8rem; }
.resolve-form { display: flex; gap: 0.5rem; flex-wrap: wrap; align-items: flex-end; margin-top: 0.5rem; }
.resolve-form label { display: grid; gap: 0.2rem; min-width: 230px; flex: 1; }
.resolve-form label span { font-size: 0.72rem; font-weight: 800; text-transform: uppercase; color: var(--muted); }
.resolve-form input { padding: 0.5rem 0.6rem; border: 1px solid var(--line-strong); border-radius: 7px; font: inherit; background: #fff; }

.source-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(380px, 1fr)); gap: 0.9rem; }
.source-card { background: var(--paper); border: 1px solid var(--line); border-radius: var(--radius); padding: 1rem 1.1rem; box-shadow: var(--shadow); }
.source-head { display: flex; justify-content: space-between; gap: 0.8rem; align-items: flex-start; }
.source-head h2 { font-size: 1.15rem; margin-bottom: 0.1rem; }

.weight-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(180px, 1fr)); gap: 0.5rem; }
.weight { display: flex; justify-content: space-between; padding: 0.55rem 0.7rem; border: 1px solid var(--line); border-radius: 9px; background: var(--paper); }
.weight b { color: var(--teal); }
.rule-list { display: grid; gap: 0.8rem; }
.rule-card { background: var(--paper); border: 1px solid var(--line); border-radius: var(--radius); padding: 1rem 1.1rem; box-shadow: var(--shadow); }
.rule-head { display: flex; justify-content: space-between; gap: 1rem; }
.rule-head h3 { margin-bottom: 0.2rem; }
.rule-score { text-align: right; }
.rule-score b { display: block; font-family: Georgia, serif; font-size: 1.7rem; color: var(--teal); line-height: 1; }
.rule-score span { font-size: 0.72rem; color: var(--muted); }
.rule-meta { display: flex; gap: 0.4rem; flex-wrap: wrap; margin: 0.45rem 0; }
.rule-groups { display: grid; gap: 0.55rem; }
.rule-groups > div { border-top: 1px solid var(--line); padding-top: 0.45rem; }
.rule-groups b { font-size: 0.76rem; text-transform: uppercase; letter-spacing: 0.06em; color: var(--muted); }
.rule-groups p { margin: 0.2rem 0 0; font-size: 0.85rem; }

details { margin-top: 0.8rem; }
summary { cursor: pointer; font-weight: 700; color: var(--teal); }
.raw-json { max-height: 28rem; overflow: auto; background: var(--cream); border: 1px solid var(--line); border-radius: 9px; padding: 0.8rem; font-size: 0.78rem; white-space: pre-wrap; overflow-wrap: anywhere; }
.checklist { margin: 0.2rem 0 0 1.1rem; padding: 0; }
.checklist li { margin-bottom: 0.45rem; }

.login-body { display: grid; place-items: center; min-height: 100vh; padding: 1.5rem; }
.login-card { width: min(540px, 100%); background: var(--paper); border: 1px solid var(--line); border-radius: 20px; padding: 1.6rem; box-shadow: 0 30px 80px rgba(14, 75, 74, 0.16); }
.login-brand { display: flex; align-items: center; gap: 0.9rem; margin-bottom: 1rem; }
.login-brand img { width: 64px; height: 64px; border-radius: 50%; object-fit: cover; border: 3px solid var(--gold); background: var(--cream-2); }
.login-brand h1 { font-size: 1.45rem; margin-bottom: 0.1rem; }
.login-brand p { margin: 0; color: var(--gold-dark); font-size: 0.8rem; text-transform: uppercase; letter-spacing: 0.1em; font-weight: 800; }
.login-form { display: grid; gap: 0.9rem; margin-top: 1rem; }

@media (max-width: 1180px) {
  .stat-grid { grid-template-columns: repeat(3, minmax(0, 1fr)); }
  .two-col { grid-template-columns: 1fr; }
  .candidate-card { grid-template-columns: 1fr; }
  .candidate-side { border-left: 0; border-top: 1px solid var(--line); padding-left: 0; padding-top: 0.8rem; }
  .meta-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
}
@media (max-width: 860px) {
  html { font-size: 16px; }
  .topbar { flex-wrap: wrap; padding: 0.75rem 1rem; }
  .brand { min-width: 0; flex: 1; }
  .nav-toggle { display: inline-flex; }
  .tabs { display: none; order: 4; flex-basis: 100%; }
  .tabs.is-open { display: flex; }
  .top-actions { order: 3; }
  .main { padding: 1rem; }
  .page-head { flex-direction: column; align-items: flex-start; }
  .section-head { flex-direction: column; align-items: flex-start; }
  .section-note { text-align: left; }
  .stat-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .form-grid { grid-template-columns: 1fr; }
  .field.wide { grid-column: auto; }
  .source-grid { grid-template-columns: 1fr; }
  .footer { flex-direction: column; }
  .job-head { flex-direction: column; }
  .job-side { text-align: left; }
  .meta-grid { grid-template-columns: 1fr; }
}

.cover-banner { margin: 0.2rem 0 1.1rem; border-radius: var(--radius); overflow: hidden; border: 1px solid var(--line-strong); box-shadow: var(--shadow); background: var(--teal); }
.cover-banner img { display: block; width: 100%; height: auto; max-height: 260px; object-fit: cover; }
@media (max-width: 860px) { .cover-banner img { max-height: 150px; } }
