/* RebelText operator console.
 *
 * One stylesheet, no build step, no framework. Tokens are defined on :root and
 * only redefined under prefers-color-scheme, so every colour has a light value
 * that exists whether or not the media query matches. */

:root {
  color-scheme: light dark;

  --bg: #f6f7f9;
  --surface: #ffffff;
  --border: #e2e5ea;
  --text: #16191d;
  --muted: #6b7280;
  --accent: #1f5fd6;
  --accent-text: #ffffff;
  --danger: #b42318;
  --danger-bg: #fef3f2;
  --ok-bg: #ecfdf3;
  --ok-text: #067647;
  --warn-bg: #fffaeb;
  --warn-text: #b54708;
  --info-bg: #eff4ff;
  --info-text: #2d4fa2;
  --shadow: 0 1px 2px rgb(16 24 40 / 6%);
  --radius: 8px;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #14161a;
    --surface: #1c1f25;
    --border: #2b2f37;
    --text: #e6e8ec;
    --muted: #9199a5;
    --accent: #6ea8fe;
    --accent-text: #10131a;
    --danger: #ff8a80;
    --danger-bg: #3a1f1d;
    --ok-bg: #14301f;
    --ok-text: #6ee7a8;
    --warn-bg: #33260f;
    --warn-text: #f5c26b;
    --info-bg: #1b2740;
    --info-text: #9dbcf5;
    --shadow: none;
  }
}

* { box-sizing: border-box; }

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

code {
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  font-size: 12px;
  color: var(--muted);
}

/* ── Top bar ─────────────────────────────────────────────────────────────── */

.topbar {
  display: flex;
  align-items: center;
  gap: 24px;
  padding: 0 24px;
  height: 56px;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
}

.brand {
  font-weight: 650;
  color: var(--text);
  text-decoration: none;
  letter-spacing: -0.01em;
}

.brand span {
  color: var(--muted);
  font-weight: 400;
}

.topbar nav {
  display: flex;
  gap: 4px;
  margin-right: auto;
}

.topbar nav a {
  padding: 6px 12px;
  border-radius: 6px;
  color: var(--muted);
  text-decoration: none;
}

.topbar nav a:hover { background: var(--bg); color: var(--text); }
.topbar nav a.active { background: var(--bg); color: var(--text); font-weight: 550; }

.signout { display: flex; align-items: center; gap: 12px; margin: 0; }
.who { color: var(--muted); font-size: 13px; }

/* ── Layout ──────────────────────────────────────────────────────────────── */

main {
  max-width: 1080px;
  margin: 0 auto;
  padding: 32px 24px 64px;
}

main.centered {
  display: flex;
  flex-direction: column;
  justify-content: center;
  min-height: 100vh;
  max-width: 400px;
}

h1 { font-size: 22px; letter-spacing: -0.01em; margin: 0 0 20px; }
h2 { font-size: 15px; margin: 0 0 12px; }

section { margin-bottom: 36px; }

.section-head {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 16px;
  margin-bottom: 12px;
}

.section-head h1, .section-head h2 { margin: 0; }
.more { color: var(--accent); text-decoration: none; font-size: 13px; }
.more:hover { text-decoration: underline; }

.muted { color: var(--muted); }
.right { text-align: right; }
.negative { color: var(--danger); }

.empty {
  padding: 32px;
  text-align: center;
  color: var(--muted);
  background: var(--surface);
  border: 1px dashed var(--border);
  border-radius: var(--radius);
}

/* ── Stats ───────────────────────────────────────────────────────────────── */

.stats {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(150px, 1fr));
  gap: 12px;
}

.stat {
  display: flex;
  flex-direction: column;
  gap: 2px;
  padding: 16px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
}

.stat-value {
  font-size: 24px;
  font-weight: 600;
  letter-spacing: -0.02em;
  font-variant-numeric: tabular-nums;
}

.stat-label { color: var(--muted); font-size: 12px; }

/* ── Tables ──────────────────────────────────────────────────────────────── */

table {
  width: 100%;
  border-collapse: collapse;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  overflow: hidden;
  box-shadow: var(--shadow);
}

th, td {
  padding: 10px 14px;
  text-align: left;
  border-bottom: 1px solid var(--border);
}

th {
  font-size: 12px;
  font-weight: 550;
  color: var(--muted);
  background: var(--bg);
}

tbody tr:last-child td { border-bottom: none; }
tbody tr:hover { background: var(--bg); }

td.right, th.right { text-align: right; font-variant-numeric: tabular-nums; }

.name { display: block; font-weight: 500; }

/* ── Pills ───────────────────────────────────────────────────────────────── */

.pill {
  display: inline-block;
  padding: 2px 8px;
  border-radius: 999px;
  font-size: 12px;
  font-weight: 500;
}

.pill-active { background: var(--ok-bg); color: var(--ok-text); }
.pill-suspended { background: var(--warn-bg); color: var(--warn-text); }
.pill-closed { background: var(--danger-bg); color: var(--danger); }

/* ── Forms ───────────────────────────────────────────────────────────────── */

.filters {
  display: flex;
  gap: 8px;
  margin-bottom: 16px;
  align-items: center;
}

input, select, button {
  font: inherit;
  padding: 8px 10px;
  border: 1px solid var(--border);
  border-radius: 6px;
  background: var(--surface);
  color: var(--text);
}

input[type="search"] { flex: 1; min-width: 0; }

input:focus-visible, select:focus-visible, button:focus-visible, a:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 1px;
}

button {
  background: var(--accent);
  color: var(--accent-text);
  border-color: transparent;
  font-weight: 550;
  cursor: pointer;
}

button:hover { filter: brightness(1.08); }

.signout button {
  background: transparent;
  color: var(--muted);
  border-color: var(--border);
  font-weight: 400;
  padding: 5px 10px;
}

.signout button:hover { color: var(--text); filter: none; }

.clear { color: var(--muted); text-decoration: none; font-size: 13px; padding: 0 4px; }
.clear:hover { color: var(--text); text-decoration: underline; }

/* ── Login ───────────────────────────────────────────────────────────────── */

.card {
  padding: 28px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
}

.login h1 { margin-bottom: 4px; }
.login .muted { font-size: 13px; margin: 0 0 20px; }

.login form { display: flex; flex-direction: column; gap: 6px; }
.login label { font-size: 13px; font-weight: 500; margin-top: 8px; }
.login button { margin-top: 18px; padding: 10px; }

.error {
  padding: 10px 14px;
  margin: 0 0 16px;
  background: var(--danger-bg);
  color: var(--danger);
  border: 1px solid currentcolor;
  border-radius: 6px;
  font-size: 13px;
}

/* ── Pager ───────────────────────────────────────────────────────────────── */

.pager {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 20px;
  margin-top: 16px;
  font-size: 13px;
}

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

/* ── Detail pages ────────────────────────────────────────────────────────── */

.crumbs {
  display: flex;
  gap: 8px;
  margin-bottom: 12px;
  font-size: 13px;
  color: var(--muted);
}

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

.subtitle { margin: -12px 0 24px; }

.small { font-size: 12px; }
.warn { color: var(--warn-text); }
.wrap { word-break: break-all; }

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

/* A second table directly under another reads as one continuous section. */
table.stacked { margin-top: 12px; }

.chips { display: flex; flex-wrap: wrap; gap: 8px; }

.chip {
  padding: 6px 12px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 999px;
  font-size: 13px;
  color: var(--muted);
}

.chip strong {
  color: var(--text);
  font-variant-numeric: tabular-nums;
}

/* Key/value table for a single record, rather than the column layout used for
   lists. */
table.kv th {
  width: 180px;
  background: transparent;
  color: var(--muted);
  font-weight: 400;
  vertical-align: top;
}

table.kv tbody tr:hover { background: transparent; }

pre.body {
  margin: 0;
  padding: 14px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  white-space: pre-wrap;
  word-break: break-word;
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  font-size: 13px;
}

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

/* ── Status pills ────────────────────────────────────────────────────────── */

/* Message lifecycle. Grouped by what an operator needs to notice: settled and
   fine, still moving, or wrong. */
.pill-msg-delivered, .pill-msg-sent { background: var(--ok-bg); color: var(--ok-text); }
.pill-msg-accepted, .pill-msg-queued, .pill-msg-sending,
.pill-msg-scheduled { background: var(--info-bg); color: var(--info-text); }
.pill-msg-failed, .pill-msg-undelivered,
.pill-msg-rejected { background: var(--danger-bg); color: var(--danger); }
.pill-msg-canceled { background: var(--bg); color: var(--muted); }

/* Webhook delivery. */
.pill-pending, .pill-sending { background: var(--info-bg); color: var(--info-text); }
.pill-delivered { background: var(--ok-bg); color: var(--ok-text); }
.pill-failed, .pill-dead { background: var(--danger-bg); color: var(--danger); }
.pill-disabled { background: var(--warn-bg); color: var(--warn-text); }

/* 10DLC registration. Approved is the only state that carries traffic. */
.pill-reg-approved { background: var(--ok-bg); color: var(--ok-text); }
.pill-reg-draft { background: var(--bg); color: var(--muted); }
.pill-reg-submitted, .pill-reg-pending { background: var(--info-bg); color: var(--info-text); }
.pill-reg-failed, .pill-reg-expired,
.pill-reg-suspended { background: var(--danger-bg); color: var(--danger); }

.pill-ledger { background: var(--bg); color: var(--muted); }
.pill-released, .pill-quarantined { background: var(--warn-bg); color: var(--warn-text); }

/* ── Actions ─────────────────────────────────────────────────────────────── */

.actions { display: flex; flex-direction: column; gap: 12px; }

.action {
  padding: 16px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
}

.action h3 { margin: 0 0 4px; font-size: 14px; }
.action .small { margin: 0 0 12px; }

.action-row {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  align-items: center;
  margin: 0 0 8px;
}

.action-row:last-child { margin-bottom: 0; }
.action-row input[type="text"] { flex: 1; min-width: 200px; }
.action-row input[type="number"] { width: 140px; }

/* A checkbox needs its label beside it rather than above, and needs to sit on
   the same baseline as the inputs it shares a row with. */
.check {
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: 13px;
  color: var(--muted);
  white-space: nowrap;
}

.check input { margin: 0; }

/* ── Editable rows ───────────────────────────────────────────────────────── */

/* Some tables are also forms: a brand's name and status are edited where they
   are read, rather than on a separate page that would show the same six fields
   with nothing else on it. A <form> cannot wrap table cells, so each row's form
   element sits in one cell and its inputs reach it by id — which means the
   controls must be sized down to look like table content rather than like a
   form dropped into a table. */
td input[type="text"], td select {
  width: 100%;
  min-width: 90px;
  padding: 4px 8px;
  font-size: 13px;
}

td input[type="text"] + code { display: block; margin-top: 3px; }
td .muted.small { display: block; }

/* An editable row ends in a cell holding a save button beside whatever else
   acts on that row. Those neighbours are usually forms, which are block boxes —
   so without a flex container here the button takes one line and each form
   takes another, and a one-line row stands up three lines tall. */
.row-actions {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: flex-end;
  gap: 6px;
}

/* Save and Quarantine do very different things, and a 6px gap between a benign
   button and a destructive one is a misclick waiting to happen. */
.row-actions .danger-group { margin-left: 18px; }

/* A table carrying form controls has a floor its cells cannot compress past —
   a select has to show enough of a campaign name to pick by. Below that width
   the table overflows, and what falls off the right edge is the actions column:
   the operator loses the buttons rather than a column of digits they could
   guess at. Scrolling the table keeps them reachable. */
.table-scroll {
  overflow-x: auto;
  /* The table paints its own border and radius, so the scroll box must not clip
     them off. */
  border-radius: var(--radius);
}

/* Destructive actions sit behind a disclosure. The CSP forbids inline script,
   so there is no confirm() to lean on — an explicit expand plus a mandatory
   reason is the friction instead, and it leaves a better audit row than a
   dialog would. */
details.danger summary {
  cursor: pointer;
  font-weight: 550;
  font-size: 14px;
  color: var(--danger);
}

details.danger[open] summary { margin-bottom: 8px; }
details.danger { border-color: color-mix(in srgb, var(--danger) 35%, var(--border)); }

button.destructive { background: var(--danger); color: #fff; }
button.small-btn { padding: 4px 10px; font-size: 12px; }

.flash-ok {
  padding: 10px 14px;
  margin: 0 0 16px;
  background: var(--ok-bg);
  color: var(--ok-text);
  border: 1px solid currentcolor;
  border-radius: 6px;
  font-size: 13px;
}

/* ── Tabs ────────────────────────────────────────────────────────────────── */

/* Each tab is a link to ?tab=, not a CSS or script toggle: the URL is the
   state, so a tab can be linked into a ticket and the back button works. */
.tabs {
  display: flex;
  flex-wrap: wrap;
  gap: 2px;
  margin: 0 0 24px;
  border-bottom: 1px solid var(--border);
}

.tab {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 8px 14px;
  color: var(--muted);
  text-decoration: none;
  font-size: 13px;
  border-bottom: 2px solid transparent;
  margin-bottom: -1px;
  white-space: nowrap;
}

.tab:hover { color: var(--text); }

.tab.active {
  color: var(--text);
  font-weight: 550;
  border-bottom-color: var(--accent);
}

.tab-count {
  padding: 1px 6px;
  border-radius: 999px;
  background: var(--bg);
  border: 1px solid var(--border);
  font-size: 11px;
  font-variant-numeric: tabular-nums;
}

.tab.active .tab-count {
  background: var(--accent);
  border-color: transparent;
  color: var(--accent-text);
}

/* The mutating tab is set apart from the read-only ones. */
.tab-danger { color: var(--danger); margin-left: auto; }
.tab-danger:hover { color: var(--danger); filter: brightness(1.15); }
.tab-danger.active { color: var(--danger); border-bottom-color: var(--danger); }

@media (max-width: 700px) {
  .tabs { overflow-x: auto; }
  .tab-danger { margin-left: 0; }
}

/* An action that needs one field alongside its button, inside a table cell. */
.inline-form { display: flex; gap: 6px; justify-content: flex-end; }
.inline-form input[type="text"] { width: 130px; padding: 4px 8px; font-size: 12px; }

/* ── Deliverability trace ────────────────────────────────────────────────── */

textarea {
  font: inherit;
  width: 100%;
  padding: 8px 10px;
  border: 1px solid var(--border);
  border-radius: 6px;
  background: var(--surface);
  color: var(--text);
  resize: vertical;
}

textarea.mono {
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  font-size: 12px;
}

.card form { display: flex; flex-direction: column; gap: 6px; }
.card label { font-size: 13px; font-weight: 500; margin-top: 8px; }
.card .small { margin: 2px 0 0; }
.card button { margin-top: 18px; padding: 10px; }

/* Volt webhooks. Event checkboxes wrap in one row under their legend, and each
   table row's delete stays a quiet disclosure rather than a card in a cell. */
.card fieldset { border: 0; padding: 0; margin: 8px 0 0; display: flex; flex-wrap: wrap; gap: 6px 16px; }
.card fieldset legend { font-size: 13px; font-weight: 500; padding: 0; margin-bottom: 6px; }
.card fieldset .check { margin-top: 0; }
td details.row-delete { display: inline-block; margin-left: 8px; text-align: left; }
td details.row-delete summary { cursor: pointer; font-size: 13px; color: var(--danger, #b42318); }
td details.row-delete[open] { display: block; margin: 8px 0 0; }
td details.row-delete button { margin-top: 6px; }
.volt-form { margin-bottom: 28px; }

/* The live banner is the page saying it is still watching. Paired with the meta
   refresh, which is what actually reloads. */
.live {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 14px;
  margin: 0 0 20px;
  background: var(--info-bg);
  color: var(--info-text);
  border: 1px solid currentcolor;
  border-radius: 6px;
  font-size: 13px;
}

.live-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: currentcolor;
  flex: none;
  animation: pulse 1.4s ease-in-out infinite;
}

@keyframes pulse { 0%, 100% { opacity: 1; } 50% { opacity: 0.25; } }

/* Respect a reduced-motion preference: the dot is decoration, and the banner
   still reads correctly without it moving. */
@media (prefers-reduced-motion: reduce) {
  .live-dot { animation: none; }
}

/* ── Timeline ────────────────────────────────────────────────────────────── */

.timeline { list-style: none; margin: 0; padding: 0; }

.tl {
  position: relative;
  display: flex;
  gap: 14px;
  padding: 0 0 18px 0;
}

/* The connecting rail, drawn from each marker down to the next. The last item
   does not get one, or the timeline would trail off into nothing. */
.tl::before {
  content: "";
  position: absolute;
  left: 5px;
  top: 16px;
  bottom: 0;
  width: 1px;
  background: var(--border);
}

.tl:last-child::before { display: none; }

.tl-marker {
  position: relative;
  z-index: 1;
  flex: none;
  width: 11px;
  height: 11px;
  margin-top: 4px;
  border-radius: 50%;
  background: var(--surface);
  border: 2px solid var(--muted);
}

.tl-ok .tl-marker { border-color: var(--ok-text); background: var(--ok-text); }
.tl-problem .tl-marker { border-color: var(--danger); background: var(--danger); }

.tl-pending .tl-marker { border-style: dashed; border-color: var(--border); }
.tl-pending .tl-label { font-style: italic; }

.tl-body { flex: 1; min-width: 0; }

.tl-head {
  display: flex;
  flex-wrap: wrap;
  align-items: baseline;
  gap: 10px;
}

.tl-label { font-weight: 500; }

.tl-stage {
  padding: 1px 7px;
  border-radius: 999px;
  background: var(--bg);
  border: 1px solid var(--border);
  color: var(--muted);
  font-size: 11px;
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
}

.tl-at { font-size: 12px; margin-left: auto; }

.tl-detail {
  font-size: 12px;
  margin-top: 2px;
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  word-break: break-word;
}

.live-action {
  margin-left: auto;
  color: inherit;
  font-weight: 550;
  white-space: nowrap;
}

.live-held { background: var(--warn-bg); color: var(--warn-text); }
