/* Backfill: light operator UI. 4/8px spacing scale, 8px radius, 1px borders, no shadows. */
:root {
  --bg: #f5f6f8;
  --surface: #ffffff;
  --line: #e4e7ec;
  --line-strong: #cfd4dc;
  --text: #101828;
  --text-2: #344054;
  --muted: #566074;
  --accent: #6366f1;          /* focus rings, selection */
  --accent-strong: #4f46e5;   /* text and filled buttons: 6.3:1 on white */
  --accent-strong-hover: #4338ca;
  --accent-soft: #eef0ff;
  --err: #b42318; --err-bg: #fef3f2; --err-line: #fecdca;
  --warn: #93370d; --warn-bg: #fffaeb; --warn-line: #fedf89;
  --ok: #067647; --ok-bg: #ecfdf3; --ok-line: #abefc6;
  --s1: 4px; --s2: 8px; --s3: 12px; --s4: 16px; --s5: 24px; --s6: 32px; --s7: 48px;
  --radius: 8px;
  --page: 860px;
  --sans: system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  --mono: ui-monospace, SFMono-Regular, Menlo, Consolas, "Liberation Mono", monospace;
}

*, *::before, *::after { box-sizing: border-box; }
html { color-scheme: light; }
[hidden] { display: none !important; }
body { margin: 0; background: var(--bg); color: var(--text); font: 14px/1.5 var(--sans); -webkit-font-smoothing: antialiased; }
h1 { font-size: 24px; line-height: 1.25; letter-spacing: -0.01em; margin: 0 0 var(--s5); font-weight: 650; }
h2 { font-size: 15px; margin: 0; font-weight: 600; }
h3 { font-size: 14px; margin: 0; font-weight: 600; }
p { margin: 0; }
a { color: var(--accent-strong); }
.mono { font-family: var(--mono); font-size: 13px; }
.muted { color: var(--muted); }
.num { text-align: right; }
.spacer { flex: 1; }
.sr-only {
  position: absolute; width: 1px; height: 1px; margin: -1px; padding: 0;
  overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; border: 0;
}
.skip { position: absolute; left: var(--s2); top: -48px; background: var(--surface); border: 1px solid var(--line-strong); padding: var(--s2) var(--s3); border-radius: var(--radius); z-index: 20; }
.skip:focus { top: var(--s2); }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }

/* ---- shell ---- */
.top { background: var(--surface); border-bottom: 1px solid var(--line); }
.top-inner { max-width: 1100px; margin: 0 auto; padding: 0 var(--s4); height: 52px; display: flex; align-items: center; gap: var(--s6); }
.brand { font-weight: 700; letter-spacing: -0.01em; font-size: 15px; }
.top nav { display: flex; gap: var(--s5); height: 100%; }
.top nav a { display: flex; align-items: center; color: var(--muted); text-decoration: none; font-weight: 500; border-bottom: 2px solid transparent; margin-bottom: -1px; }
.top nav a:hover { color: var(--text); }
.top nav a[aria-current="page"] { color: var(--accent-strong); border-bottom-color: var(--accent-strong); }
.top-inner { position: relative; }
.top .signout { margin-left: auto; font-size: 12px; padding: 4px 10px; color: var(--muted); background: none; border: 1px solid var(--line-strong); border-radius: var(--radius); cursor: pointer; }
.top .signout:hover { color: var(--text); border-color: var(--text-2); }
.wrap { max-width: var(--page); margin: 0 auto; padding: var(--s6) var(--s4) 0; }
body[data-page="history"] .wrap { max-width: 1100px; }

.card { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: var(--s5); }
.stack { display: flex; flex-direction: column; gap: var(--s4); }

/* ---- controls ---- */
.field { display: flex; flex-direction: column; gap: 6px; min-width: 0; }
.lbl { font-size: 13px; font-weight: 600; color: var(--text-2); }
input[type="text"], input[type="date"], input[type="time"], input[type="number"], select, textarea {
  width: 100%; background: var(--surface); color: var(--text);
  border: 1px solid var(--line-strong); border-radius: var(--radius);
  padding: var(--s2) var(--s3); font: inherit; min-height: 38px;
}
textarea { resize: none; overflow: hidden; line-height: 1.55; }
input::placeholder, textarea::placeholder { color: #8791a3; }
input:hover, select:hover, textarea:hover { border-color: #98a2b3; }
input:focus-visible, select:focus-visible, textarea:focus-visible { outline: 2px solid var(--accent); outline-offset: 0; border-color: var(--accent); }
input[aria-invalid="true"], textarea[aria-invalid="true"], select[aria-invalid="true"] { border-color: var(--err); }
input[type="number"] { -moz-appearance: textfield; font-variant-numeric: tabular-nums; }
input[readonly] { color: var(--muted); background: var(--bg); cursor: default; }
.row { display: flex; gap: var(--s3); align-items: flex-start; }
.row > select { flex: 1; }

.err { color: var(--err); font-size: 13px; }
.err:empty { display: none; }
.err p + p { margin-top: var(--s1); }
.warn-text { color: var(--warn); font-size: 13px; }

.btn {
  display: inline-flex; align-items: center; justify-content: center; position: relative;
  background: var(--surface); color: var(--text); border: 1px solid var(--line-strong);
  border-radius: var(--radius); padding: var(--s2) var(--s4); min-height: 38px;
  font: inherit; font-weight: 600; text-decoration: none; cursor: pointer;
}
.btn:hover:not(:disabled) { background: var(--bg); border-color: #98a2b3; }
.btn:disabled, .btn[aria-disabled="true"] { opacity: 0.45; cursor: not-allowed; }
.btn.primary { background: var(--accent-strong); border-color: var(--accent-strong); color: #fff; }
.btn.primary:hover:not(:disabled) { background: var(--accent-strong-hover); border-color: var(--accent-strong-hover); }
.btn.ghost { border-color: transparent; background: transparent; color: var(--muted); font-weight: 500; }
.btn.ghost:hover:not(:disabled) { color: var(--text); background: var(--bg); border-color: transparent; }
.btn.danger { color: var(--err); }
.btn.danger:hover:not(:disabled) { border-color: var(--err); background: var(--err-bg); }
.btn.ghost.danger { color: var(--muted); }
.btn.ghost.danger:hover:not(:disabled) { color: var(--err); background: var(--err-bg); border-color: transparent; }
.btn.small { min-height: 30px; padding: 2px var(--s3); font-size: 13px; }
.btn.icon { min-width: 30px; min-height: 30px; padding: 2px; font-size: 11px; }

/* While busy the label is hidden and a centred spinner takes its place, so width never changes. */
.spinner {
  position: absolute; left: 50%; top: 50%; width: 14px; height: 14px; margin: -7px 0 0 -7px;
  border: 2px solid currentColor; border-right-color: transparent; border-radius: 50%; visibility: hidden;
}
.btn[aria-busy="true"] .label { visibility: hidden; }
.btn[aria-busy="true"] .spinner { visibility: visible; animation: spin 0.7s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }
@media (prefers-reduced-motion: reduce) { .btn[aria-busy="true"] .spinner { animation-duration: 2s; } }

.check { display: inline-flex; align-items: center; gap: var(--s2); cursor: pointer; white-space: nowrap; color: var(--text-2); }
.check input { width: 16px; height: 16px; accent-color: var(--accent-strong); margin: 0; }

/* ---- compose ---- */
#compose[data-ready="false"] { visibility: hidden; }
.details { display: flex; flex-direction: column; gap: var(--s4); }
.pair { display: flex; gap: var(--s3); align-items: flex-start; }
.pair .field { flex: 1; }
.pair .arrow { padding-top: 34px; color: var(--muted); }
.tz-row select { max-width: 360px; }

.section-head { display: flex; align-items: baseline; justify-content: space-between; margin: var(--s7) 0 var(--s3); }
.steps { list-style: none; padding: 0; margin: 0 0 var(--s4); display: flex; flex-direction: column; gap: var(--s3); }
.step { display: flex; flex-direction: column; gap: var(--s4); }
/* Inbound messages sit indented, like a conversation. */
.step[data-dir="in"] { margin-left: var(--s6); }
.step-head { display: flex; align-items: center; gap: var(--s3); }
.step-title { display: flex; align-items: center; }
.step .num {
  display: inline-grid; place-items: center; min-width: 24px; height: 24px; border-radius: 12px;
  background: var(--accent-soft); color: var(--accent-strong); font-size: 12px; font-weight: 700;
}
.step .from { color: var(--muted); font-size: 13px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; min-width: 0; }
.step-tools { display: flex; gap: var(--s1); margin-left: auto; }

fieldset.dir { border: 0; margin: 0; padding: 2px; display: inline-flex; gap: 2px; background: var(--bg); border-radius: var(--radius); flex: none; }
.seg { position: relative; }
.seg input { position: absolute; opacity: 0; inset: 0; margin: 0; cursor: pointer; }
.seg span { display: block; padding: 3px var(--s3); border-radius: 6px; color: var(--muted); font-size: 13px; font-weight: 500; }
.seg input:checked + span { background: var(--surface); color: var(--text); font-weight: 600; box-shadow: 0 0 0 1px var(--line-strong); }
.seg input:focus-visible + span { outline: 2px solid var(--accent); outline-offset: 1px; }
.seg input:disabled { cursor: not-allowed; }
.seg input:disabled + span { opacity: 0.4; }

.dt { align-items: flex-end; }
.dt .field { width: 170px; flex: none; }
.dt .field + .field { width: 156px; }
.dt .field + .field + .field { width: 84px; }
.note { font-size: 13px; margin-top: calc(-1 * var(--s2)); }
.readout { margin: 0 0 0 var(--s2); padding-bottom: 8px; flex: 1; min-width: 0; display: flex; flex-direction: column; font: 12.5px/1.5 var(--mono); }
.readout > div { display: flex; gap: var(--s2); }
.readout dt { color: var(--muted); width: 62px; flex: none; }
.readout dd { margin: 0; color: var(--text); overflow-wrap: anywhere; font-variant-numeric: tabular-nums; }
.readout dd[data-r="offset"], .readout dd[data-r="utc"] { color: var(--muted); }

.step-foot { display: flex; align-items: center; gap: var(--s4); }
.drop {
  flex: 1; display: block; border: 1px dashed var(--line-strong); border-radius: var(--radius);
  padding: var(--s2) var(--s3); cursor: pointer; color: var(--text-2); background: var(--bg);
}
.drop:hover, .drop.over { border-color: var(--accent); background: var(--accent-soft); }
.drop:focus-within { outline: 2px solid var(--accent); outline-offset: 2px; }
.atts { list-style: none; margin: calc(-1 * var(--s2)) 0 0; padding: 0; }
.atts:empty { display: none; }
.atts li { display: flex; align-items: center; gap: var(--s3); padding: var(--s1) 0; border-bottom: 1px solid var(--line); }
.atts li:last-child { border-bottom: 0; }
.atts .name { flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.atts .size { color: var(--muted); font: 12px var(--mono); }

.bar {
  position: sticky; bottom: 0; z-index: 5; margin: var(--s5) calc(-1 * var(--s4)) 0;
  padding: var(--s3) var(--s4); background: var(--surface); border-top: 1px solid var(--line);
  display: flex; align-items: center; gap: var(--s2); min-height: 64px;
}
.bar .status { font-size: 13px; color: var(--muted); margin-right: var(--s2); }
.bar .status[data-state="bad"] { color: var(--warn); font-weight: 500; }

/* ---- reply context ---- */
.reply-ctx { background: var(--accent-soft); border-color: #d5d9fb; padding: var(--s4); margin-bottom: var(--s5); display: flex; flex-direction: column; gap: var(--s1); }
.reply-head { display: flex; align-items: center; justify-content: space-between; gap: var(--s3); }
.reply-ctx .btn { background: var(--surface); }
details.raw summary { cursor: pointer; width: fit-content; padding: var(--s1) 0; color: var(--text-2); font-weight: 500; }
details.raw summary:hover { color: var(--text); }
#reply-error:not(:empty) { margin-bottom: var(--s3); }

/* ---- preview ---- */
.summary { margin-bottom: var(--s5); display: flex; flex-direction: column; gap: var(--s1); }
.sum-route { color: var(--muted); overflow-wrap: anywhere; }
.sum-subject { font-size: 20px; font-weight: 650; line-height: 1.3; letter-spacing: -0.01em; margin: 2px 0; }
.disclaimer { margin-top: var(--s3); padding: var(--s2) var(--s3); background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); color: var(--text-2); width: fit-content; max-width: 100%; }
.banner { border: 1px solid; border-radius: var(--radius); padding: var(--s3) var(--s4); margin-bottom: var(--s3); }
.banner h2 { font-size: 14px; margin-bottom: var(--s1); }
.banner ul { margin: 0; padding-left: var(--s4); }
.banner.error { color: var(--err); background: var(--err-bg); border-color: var(--err-line); }
.banner.warn { color: var(--warn); background: var(--warn-bg); border-color: var(--warn-line); }
.banner.ok { color: var(--ok); background: var(--ok-bg); border-color: var(--ok-line); }
.banner a { color: inherit; font-weight: 600; }
.msg { display: flex; flex-direction: column; gap: var(--s4); }
.msg-head { display: flex; align-items: center; gap: var(--s3); }
.msg-head .dir-note { color: var(--muted); }
.msg-head .at { margin-left: auto; font-size: 12px; }
.tag { margin-left: var(--s2); font-size: 12px; font-weight: 600; color: var(--accent-strong); background: var(--accent-soft); border-radius: 999px; padding: 1px var(--s3); }
table.hdr { width: 100%; border-collapse: collapse; }
table.hdr th, table.hdr td { text-align: left; vertical-align: top; padding: 6px 0; border-top: 1px solid var(--line); }
table.hdr th { width: 112px; color: var(--muted); font-weight: 500; white-space: nowrap; }
table.hdr td { overflow-wrap: anywhere; }
table.hdr td.unset { color: var(--muted); }
table.hdr td.date { font-variant-numeric: tabular-nums; }
/* Message-ID / In-Reply-To / References: present, but secondary. */
table.hdr tr.tech th, table.hdr tr.tech td { font: 12px/1.5 var(--mono); color: var(--muted); }
pre.body { margin: 0; padding: var(--s4); background: var(--bg); border-radius: var(--radius); font: 14px/1.6 var(--sans); white-space: pre-wrap; overflow-wrap: anywhere; }
.chips { list-style: none; margin: 0; padding: 0; display: flex; flex-wrap: wrap; gap: var(--s2); }
.chips:empty { display: none; }
.chips li { padding: 2px var(--s3); border: 1px solid var(--line-strong); border-radius: 999px; font-size: 12px; }
.chips .sz { color: var(--muted); font-family: var(--mono); margin-left: var(--s2); }
.raw-tools { display: flex; align-items: center; gap: var(--s3); margin: var(--s2) 0; }
pre.raw-box {
  margin: 0 0 var(--s2); padding: var(--s3); background: #101828; color: #e4e7ec;
  border-radius: var(--radius); max-height: 320px; overflow: auto; white-space: pre; font-size: 12.5px;
}
.crlf { color: #7c8aa5; user-select: none; }

/* ---- history ---- */
.table-wrap { overflow-x: auto; background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); }
table.jobs { width: 100%; border-collapse: collapse; }
table.jobs th { text-align: left; font-size: 12px; color: var(--muted); font-weight: 600; padding: var(--s3); background: var(--bg); border-bottom: 1px solid var(--line); white-space: nowrap; }
table.jobs th.num { text-align: right; }
table.jobs td { padding: var(--s3); border-bottom: 1px solid var(--line); vertical-align: middle; }
table.jobs tbody.job:last-child td { border-bottom: 0; }
table.jobs tbody.job:hover > .job-row td { background: #fafbfc; }
table.jobs td.nowrap { white-space: nowrap; }
table.jobs td.route { white-space: nowrap; }
table.jobs td.subj { min-width: 180px; font-weight: 500; }
table.jobs td.actions { white-space: nowrap; text-align: right; }
.subj-note { display: block; font-size: 12px; font-weight: 400; }
.btn.icon[data-r="toggle"] { font-size: 14px; color: var(--muted); }
table.jobs .job-detail td { background: var(--bg); padding-top: var(--s2); padding-bottom: var(--s3); }
table.verify { width: 100%; border-collapse: collapse; }
table.verify th { text-align: left; font-size: 12px; color: var(--muted); font-weight: 600; padding: var(--s1) var(--s3) var(--s1) 0; }
table.verify td { padding: var(--s1) var(--s3) var(--s1) 0; border-top: 1px solid var(--line); font-size: 13px; vertical-align: top; }
table.verify td.nowrap { white-space: nowrap; }
table.verify td.err-cell { color: var(--err); }

.pill { display: inline-block; padding: 1px 10px; border-radius: 999px; font-size: 12px; font-weight: 600; }
.pill.draft, .pill.not_run { color: #475467; background: #f2f4f7; }
.pill.previewed { color: #175cd3; background: #eff8ff; }
.pill.running, .pill.pending { color: #b54708; background: #fffaeb; }
.pill.done, .pill.verified { color: var(--ok); background: var(--ok-bg); }
.pill.failed { color: var(--err); background: var(--err-bg); }
.pill.purged { color: #6941c6; background: #f4f3ff; }

.empty { text-align: center; color: var(--muted); padding: 96px var(--s4); display: flex; flex-direction: column; gap: var(--s2); align-items: center; }

/* ---- dialog ---- */
dialog { background: var(--surface); color: var(--text); border: 1px solid var(--line); border-radius: 12px; padding: var(--s5); max-width: 420px; width: calc(100% - 32px); }
dialog::backdrop { background: rgba(16, 24, 40, 0.45); }
dialog h2 { margin-bottom: var(--s2); font-size: 16px; }
dialog p { color: var(--text-2); }
.dialog-actions { display: flex; justify-content: flex-end; gap: var(--s2); margin-top: var(--s5); }
