:root {
  --fg: #1a1f2c;
  --fg-soft: #4a5568;
  --muted: #6b7280;
  --bg: #f5f6fa;
  --surface: #ffffff;
  --border: #e2e6ee;
  --border-strong: #cbd5e0;
  --accent: #2962ff;
  --accent-soft: #eef2ff;
  --good: #2e7d32;
  --good-soft: #e8f5e9;
  --warn: #c66700;
  --warn-soft: #fff3e0;
  --bad: #c62828;
  --bad-soft: #ffebee;
  --info: #0277bd;
  --info-soft: #e3f2fd;

  /* Sidebar */
  --sb-bg: #1a1f2c;
  --sb-bg-hover: #232a3a;
  --sb-bg-active: #2962ff;
  --sb-fg: #c6cdd9;
  --sb-fg-active: #ffffff;
  --sb-divider: #2a3041;
  --sb-section: #6b7280;

  --shadow-card: 0 1px 2px rgba(15, 23, 42, 0.04);
  --radius: 8px;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  font-family: ui-sans-serif, system-ui, -apple-system, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  color: var(--fg);
  background: var(--bg);
  font-size: 14px;
  line-height: 1.5;
}

a       { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }

h1 { font-size: 1.5rem; font-weight: 600; margin: 0; }
h2 { font-size: 1.05rem; font-weight: 600; margin: 28px 0 12px 0; color: var(--fg); }
h2 small { color: var(--muted); font-weight: 400; }

small { color: var(--muted); }

code {
  font-family: ui-monospace, "SF Mono", Consolas, monospace;
  font-size: 0.88em;
  background: var(--accent-soft);
  color: var(--fg);
  padding: 1px 6px;
  border-radius: 3px;
}
code.dim { background: transparent; color: var(--muted); padding: 0; font-size: 0.85em; }

/* ============================================================
   Layout: fixed sidebar + scrollable main content
   ============================================================ */

.layout {
  display: grid;
  grid-template-columns: 240px 1fr;
  min-height: 100vh;
}

.sidebar {
  background: var(--sb-bg);
  color: var(--sb-fg);
  display: flex;
  flex-direction: column;
  position: sticky;
  top: 0;
  height: 100vh;
  overflow-y: auto;
}

.content {
  padding: 28px 36px;
  max-width: 1400px;
  width: 100%;
}

/* ---- Sidebar brand ---- */

.sb-brand {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 18px 18px 14px 18px;
  border-bottom: 1px solid var(--sb-divider);
}
.sb-brand-mark {
  width: 32px; height: 32px;
  display: inline-flex; align-items: center; justify-content: center;
  border-radius: 7px;
  background: linear-gradient(135deg, #2962ff 0%, #5b8dff 100%);
  color: #fff;
  font-weight: 700;
  font-size: 0.85em;
  letter-spacing: 0.02em;
}
.sb-brand-text { line-height: 1.2; }
.sb-brand-name { color: #fff; font-weight: 600; font-size: 0.95em; }
.sb-brand-sub  { color: var(--sb-section); font-size: 0.75em; margin-top: 2px; }

/* ---- Sidebar CTA ---- */

.sb-cta {
  display: block;
  margin: 14px 14px 6px 14px;
  padding: 9px 14px;
  background: var(--accent);
  color: #fff !important;
  border-radius: 6px;
  font-weight: 500;
  font-size: 0.9em;
  text-align: center;
  transition: background 0.15s ease;
}
.sb-cta:hover { background: #1c4ed1; text-decoration: none; }
.sb-cta-plus { margin-right: 4px; font-weight: 700; }

/* ---- Sidebar nav ---- */

.sb-nav { padding: 8px 8px; flex: 1; }
.sb-section {
  color: var(--sb-section);
  font-size: 0.7em;
  text-transform: uppercase;
  letter-spacing: 0.07em;
  padding: 14px 12px 6px 12px;
  font-weight: 600;
}
.sb-item {
  display: flex; align-items: center; gap: 10px;
  padding: 8px 12px;
  border-radius: 5px;
  color: var(--sb-fg) !important;
  font-size: 0.92em;
  margin-bottom: 1px;
  transition: background 0.1s ease;
}
.sb-item:hover { background: var(--sb-bg-hover); text-decoration: none; }
.sb-item.active { background: var(--sb-bg-active); color: var(--sb-fg-active) !important; }
.sb-icon {
  display: inline-flex;
  width: 18px; justify-content: center;
  font-size: 0.95em;
  opacity: 0.85;
}

.sb-foot {
  padding: 12px 18px;
  border-top: 1px solid var(--sb-divider);
  font-size: 0.8em;
}
.sb-foot-link { color: var(--sb-section) !important; }
.sb-foot-link:hover { color: var(--sb-fg) !important; text-decoration: none; }

/* ============================================================
   Page header
   ============================================================ */

.page-head {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 16px;
  margin-bottom: 18px;
}
.page-head h1 { margin: 0; }
.page-head p.hint { margin: 6px 0 0 0; }
.page-head-actions { display: flex; gap: 8px; align-items: center; }

.hint  { color: var(--muted); font-size: 0.92em; }
.dim   { color: var(--muted); font-weight: 400; }
.empty { color: var(--muted); font-style: italic; padding: 20px; text-align: center; }
small.err { display: block; color: var(--bad); margin-top: 2px; font-style: italic; }

/* ============================================================
   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-card);
}
th, td {
  text-align: left;
  padding: 10px 14px;
  border-bottom: 1px solid var(--border);
  vertical-align: top;
}
th {
  background: #fafbfc;
  font-weight: 600;
  font-size: 0.82em;
  color: var(--fg-soft);
  text-transform: uppercase;
  letter-spacing: 0.03em;
}
tr:last-child td { border-bottom: none; }
tr.row-running td { background: #fffbe7; }
tr:hover td { background: #fafbfc; }

dl.meta {
  display: grid;
  grid-template-columns: max-content 1fr;
  gap: 8px 24px;
  background: var(--surface);
  padding: 16px 20px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow-card);
}
dl.meta dt { font-weight: 500; color: var(--muted); font-size: 0.9em; }
dl.meta dd { margin: 0; font-size: 0.95em; }

/* ============================================================
   Status pills
   ============================================================ */

.status {
  display: inline-block;
  font-size: 0.78em;
  font-weight: 500;
  padding: 2px 9px;
  border-radius: 12px;
  background: #eef0f3;
  color: var(--fg);
  white-space: nowrap;
  letter-spacing: 0.01em;
}
.status-completed,
.status-dispatched,
.status-inserted    { background: var(--good-soft); color: var(--good); }
.status-failed      { background: var(--bad-soft);  color: var(--bad); }
.status-cancelled   { background: #f3f4f6; color: var(--muted); }
.status-skipped,
.status-running,
.status-pending,
.status-dryrun      { background: var(--info-soft); color: var(--info); }
.status-datafetching,
.status-datafetched,
.status-rendering,
.status-rendered,
.status-dispatching { background: var(--warn-soft); color: var(--warn); }

.lvl       { font-size: 0.75em; padding: 1px 7px; border-radius: 8px; font-weight: 500; }
.lvl-info  { background: var(--info-soft); color: var(--info); }
.lvl-warn  { background: var(--warn-soft); color: var(--warn); }
.lvl-error { background: var(--bad-soft);  color: var(--bad); }

/* ============================================================
   Buttons
   ============================================================ */

.btn-primary, .btn-secondary, .btn-danger, button[type=submit] {
  display: inline-block;
  padding: 8px 14px;
  border-radius: 6px;
  font-size: 0.88em;
  font-weight: 500;
  font-family: inherit;
  border: 1px solid transparent;
  cursor: pointer;
  text-decoration: none;
  transition: background 0.12s ease, border-color 0.12s ease;
}
.btn-primary, button.btn-primary, button[type=submit] {
  background: var(--accent); color: #fff; border-color: var(--accent);
}
.btn-primary:hover, button[type=submit]:hover { background: #1c4ed1; text-decoration: none; }

.btn-secondary {
  background: #fff; color: var(--fg); border-color: var(--border-strong);
}
.btn-secondary:hover { background: #f7f8fa; text-decoration: none; }

.btn-danger {
  background: var(--bad); color: #fff; border-color: var(--bad);
}
.btn-danger:hover { background: #a41d1d; }

button[disabled] { opacity: 0.4; cursor: not-allowed; }

/* ============================================================
   Pulse marker for live tail
   ============================================================ */

.pulse {
  display: inline-block;
  margin-left: 8px;
  color: var(--accent) !important;
  font-weight: 500;
  animation: pulse 1.6s ease-in-out infinite;
}
@keyframes pulse { 0%,100%{opacity:.45} 50%{opacity:1} }

/* ============================================================
   Pre / log
   ============================================================ */

pre {
  background: #f4f5f7;
  padding: 10px 14px;
  border: 1px solid var(--border);
  border-radius: 6px;
  overflow: auto;
  max-height: 400px;
  font-size: 0.85em;
  font-family: ui-monospace, "SF Mono", Consolas, monospace;
}
pre.error { background: var(--bad-soft); border-color: #ffcdd2; color: var(--bad); }
pre.log {
  background: #161b25;
  color: #d8dde6;
  border-color: #161b25;
  max-height: 380px;
  font-size: 0.83em;
}

details summary {
  cursor: pointer;
  padding: 4px 0;
  color: var(--accent);
}

/* ============================================================
   Dashboard stat cards
   ============================================================ */

.stats {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(150px, 1fr));
  gap: 14px;
  margin: 0 0 28px 0;
}
.stat {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 16px 18px;
  box-shadow: var(--shadow-card);
}
.stat-num   { font-size: 1.85rem; font-weight: 600; color: var(--accent); line-height: 1.1; }
.stat-bad   { color: var(--bad); }
.stat-muted { color: var(--muted); }
.stat-label {
  color: var(--muted);
  font-size: 0.78em;
  margin-top: 4px;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  font-weight: 600;
}

/* ============================================================
   Pipeline progress
   ============================================================ */

.pipeline {
  display: flex;
  align-items: stretch;
  margin: 0 0 28px 0;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 18px 12px;
  box-shadow: var(--shadow-card);
  overflow: hidden;
}
.pipeline .stage {
  flex: 1 1 0;
  padding: 4px 18px;
  min-width: 0;
}
.pipeline .stage-head {
  display: flex; align-items: center; gap: 8px;
  font-size: 0.78em;
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: 0.06em;
  font-weight: 600;
  margin-bottom: 6px;
}
.pipeline .stage-num {
  display: inline-flex; align-items: center; justify-content: center;
  width: 22px; height: 22px;
  border-radius: 50%;
  background: var(--accent-soft);
  color: var(--accent);
  font-size: 0.78em;
  font-weight: 700;
}
.pipeline .stage-name { font-weight: 600; color: var(--fg); }
.pipeline .stage-metric {
  font-size: 1.7rem;
  font-weight: 600;
  line-height: 1.1;
  margin: 4px 0;
}
.pipeline .stage-metric .big { color: var(--accent); }
.pipeline .stage-metric .dim { font-size: 0.7em; color: var(--muted); }
.pipeline .stage-bar {
  height: 6px;
  background: #eef0f3;
  border-radius: 3px;
  margin: 8px 0 6px 0;
  overflow: hidden;
}
.pipeline .stage-bar-fill {
  height: 100%;
  background: var(--accent);
  border-radius: 3px;
  transition: width 0.5s ease;
}
.pipeline .stage-foot { font-size: 0.85em; color: var(--muted); }
.stage-pct { color: var(--accent); font-weight: 600; }
.pipeline .stage-arrow {
  display: flex; align-items: center;
  color: var(--border-strong);
  font-size: 1.2rem;
  padding: 0 4px;
  user-select: none;
}

/* ============================================================
   Running banner on batch detail
   ============================================================ */
.running-banner {
  display: flex;
  align-items: center;
  gap: 12px;
  background: linear-gradient(90deg, #fff8e1 0%, #fff 100%);
  border: 1px solid #ffe082;
  border-radius: var(--radius);
  padding: 12px 16px;
  margin: 0 0 16px 0;
}
.running-banner[hidden] { display: none !important; }
.spinner-sm {
  width: 18px; height: 18px;
  border: 2px solid var(--accent-soft);
  border-top-color: var(--accent);
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
  flex-shrink: 0;
}

/* ============================================================
   Tab badges (live-updated counts)
   ============================================================ */
.tab-badge {
  display: inline-block;
  background: var(--good-soft);
  color: var(--good);
  border-radius: 10px;
  padding: 1px 8px;
  font-size: 0.78em;
  font-weight: 500;
  margin-left: 4px;
}
.tab-badge[hidden] { display: none !important; }

/* ============================================================
   Advance-to-next-stage panel on batch detail
   ============================================================ */
.advance-panel {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  background: var(--accent-soft);
  border: 1px solid #c9d6ff;
  border-radius: var(--radius);
  padding: 14px 18px;
  margin: 0 0 20px 0;
}
.advance-actions { display: flex; gap: 8px; }

/* ============================================================
   Tabs
   ============================================================ */

.tabs {
  display: flex;
  gap: 2px;
  border-bottom: 1px solid var(--border);
  margin: 28px 0 18px 0;
}
.tabs .tab {
  background: transparent;
  border: 0;
  padding: 11px 18px;
  cursor: pointer;
  color: var(--muted);
  font-weight: 500;
  font-size: 0.92em;
  font-family: inherit;
  border-bottom: 2px solid transparent;
  margin-bottom: -1px;
}
.tabs .tab:hover { color: var(--fg); background: rgba(0,0,0,0.02); }
.tabs .tab.active { color: var(--accent); border-bottom-color: var(--accent); }
.tabs .tab .status { margin-left: 6px; }

.tab-panel { display: none; }
.tab-panel.active { display: block; }

/* ============================================================
   Recipient-tab toolbar (top-level template filter)
   ============================================================ */
.recipient-toolbar {
  display: flex;
  align-items: center;
  gap: 10px;
  flex-wrap: wrap;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 10px 16px;
  margin-bottom: 14px;
  box-shadow: var(--shadow-card);
}
.recipient-toolbar select {
  padding: 6px 10px;
  border: 1px solid var(--border-strong);
  border-radius: 5px;
  font-size: 0.92em;
  font-family: inherit;
  background: #fff;
  min-width: 240px;
}
.recipient-toolbar #status-filter-global {
  min-width: 180px;
}
.filter-status {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  padding: 4px 12px;
  background: var(--accent-soft);
  color: var(--accent);
  border-radius: 14px;
  font-size: 0.88em;
  font-weight: 500;
}
.filter-status[hidden] { display: none !important; }
.filter-status a { color: var(--accent); margin-left: 4px; }

/* ============================================================
   Per-template recipient sections
   ============================================================ */

.tpl-section {
  margin: 14px 0;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--surface);
  overflow: hidden;
  box-shadow: var(--shadow-card);
}
.tpl-section .tpl-header {
  display: flex;
  align-items: center;
  gap: 16px;
  padding: 13px 18px;
  background: #fafbfc;
  border-bottom: 1px solid var(--border);
  flex-wrap: wrap;
}
.tpl-section .tpl-header > div:first-child { font-size: 1em; }
.tpl-section .tpl-status-pills { display: flex; gap: 6px; flex-wrap: wrap; }
.tpl-section .tpl-filter {
  margin-left: auto;
  padding: 6px 11px;
  border: 1px solid var(--border-strong);
  border-radius: 5px;
  font-size: 0.88em;
  font-family: inherit;
  min-width: 220px;
  background: #fff;
}
.tpl-section .tpl-filter:focus {
  outline: none; border-color: var(--accent);
  box-shadow: 0 0 0 3px rgba(41,98,255,0.12);
}
.tpl-section table.recipient-table {
  border: 0;
  border-radius: 0;
  box-shadow: none;
}
.tpl-section table.recipient-table th { background: #fafbfc; }
.col-num { text-align: right; width: 60px; }
.recipient-table .drill { margin-left: 8px; white-space: nowrap; font-size: 0.9em; }

.pager {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 9px 18px;
  border-top: 1px solid var(--border);
  background: #fafbfc;
  font-size: 0.88em;
}
.pager button { padding: 4px 12px; }
.pager-status { color: var(--muted); }

/* ============================================================
   Active runs banner
   ============================================================ */

.active-banner {
  background: #fff8e1;
  border: 1px solid #ffe082;
  padding: 9px 14px;
  border-radius: 6px;
  margin: 8px 0 18px 0;
  font-size: 0.92em;
}

/* ============================================================
   Forms
   ============================================================ */

.run-form, .template-edit {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 22px 26px;
  max-width: 720px;
  box-shadow: var(--shadow-card);
}
.run-form .field {
  display: flex;
  flex-direction: column;
  gap: 5px;
  margin-bottom: 20px;
}
.run-form label { font-weight: 600; font-size: 0.9em; color: var(--fg); }
.run-form input[type=text],
.run-form input[type=date],
.run-form select {
  padding: 8px 11px;
  border: 1px solid var(--border-strong);
  border-radius: 5px;
  font-size: 0.95em;
  font-family: inherit;
  background: #fff;
}
.run-form input[type=text]:focus,
.run-form input[type=date]:focus,
.run-form select:focus,
.tpl-filter:focus {
  outline: none;
  border-color: var(--accent);
  box-shadow: 0 0 0 3px rgba(41,98,255,0.15);
}
.run-form .checks {
  display: flex;
  flex-wrap: wrap;
  gap: 10px 22px;
  padding: 4px 0;
}
.run-form .check, .run-form .radio {
  font-weight: 400;
  cursor: pointer;
  user-select: none;
}
.run-form .actions {
  display: flex;
  gap: 8px;
  padding-top: 14px;
  border-top: 1px solid var(--border);
  margin-top: 6px;
}
.quick-dates { display: flex; gap: 6px; margin-top: 6px; }
.quick-dates button { padding: 4px 10px; font-size: 0.83em; }

.search-form { display: flex; gap: 8px; align-items: center; }
.search-form input[type=text] {
  padding: 7px 11px;
  border: 1px solid var(--border-strong);
  border-radius: 5px;
  font-size: 0.92em;
  font-family: inherit;
  min-width: 280px;
  background: #fff;
}

/* ============================================================
   Payload table on the job page (Stage 2 data view)
   ============================================================ */
.payload-toolbar {
  display: flex;
  align-items: center;
  gap: 12px;
  flex-wrap: wrap;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 8px 12px;
  margin-bottom: 8px;
  box-shadow: var(--shadow-card);
}
.payload-toolbar input[type=text] {
  padding: 6px 10px;
  border: 1px solid var(--border-strong);
  border-radius: 5px;
  font-size: 0.92em;
  font-family: inherit;
  min-width: 260px;
}
#payload-count { font-size: 0.88em; }

.payload-table-wrap { overflow-x: auto; }
.payload-table { font-size: 0.88em; }
.payload-table th.sortable { cursor: pointer; user-select: none; }
.payload-table th.sortable:hover { color: var(--accent); }
.payload-table .sort-ind { color: var(--accent); font-size: 0.85em; }

.template-edit textarea {
  width: 100%;
  min-height: 360px;
  font-family: ui-monospace, "SF Mono", Consolas, monospace;
  font-size: 0.85em;
  padding: 12px;
  border: 1px solid var(--border-strong);
  border-radius: 5px;
  resize: vertical;
  background: #fff;
}
.template-edit .actions {
  display: flex;
  gap: 8px;
  margin-top: 10px;
}

/* ============================================================
   Filters bar (index page)
   ============================================================ */
.filters-bar {
  display: flex;
  gap: 8px;
  align-items: center;
  flex-wrap: wrap;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 10px 14px;
  margin-bottom: 16px;
  box-shadow: var(--shadow-card);
}
.filters-bar select,
.filters-bar input[type=text] {
  padding: 6px 10px;
  border: 1px solid var(--border-strong);
  border-radius: 5px;
  font-size: 0.9em;
  font-family: inherit;
  background: #fff;
}
.filters-bar input[type=text] { min-width: 150px; }
.filters-bar button { padding: 6px 14px; }

/* ============================================================
   Run preview output (run_new.html "Preview recipients")
   ============================================================ */
.preview-out {
  margin-top: 28px;
  padding-top: 20px;
  border-top: 1px solid var(--border);
}
.preview-out h2 small { color: var(--muted); font-weight: 400; }

/* ============================================================
   Big stage buttons on the simplified run form
   ============================================================ */
.stage-buttons {
  display: grid;
  /* 4 partial-pipeline buttons in a row, then "Full pipeline" spans the
     full second row (handled below). On narrow screens the partials wrap. */
  grid-template-columns: repeat(auto-fit, minmax(150px, 1fr));
  gap: 10px;
  margin-top: 8px;
}
.btn-stage {
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  text-align: left;
  padding: 16px 18px;
  background: #fff;
  border: 1px solid var(--border-strong);
  border-radius: var(--radius);
  cursor: pointer;
  transition: border-color 0.15s ease, box-shadow 0.15s ease;
  font-family: inherit;
  color: var(--fg);
}
.btn-stage:hover {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px rgba(41,98,255,0.10);
}
.btn-stage .stage-num {
  display: inline-flex;
  width: 22px; height: 22px;
  align-items: center; justify-content: center;
  background: var(--accent-soft);
  color: var(--accent);
  border-radius: 50%;
  font-size: 0.78em;
  font-weight: 700;
  margin-bottom: 6px;
}
.btn-stage strong { font-size: 1em; margin-bottom: 4px; }
.btn-stage small  { color: var(--muted); font-size: 0.82em; }

/* "Full pipeline" — span the whole grid row, accented as the primary CTA */
.btn-stage-full {
  grid-column: 1 / -1;
  background: var(--accent);
  border-color: var(--accent);
  color: #fff;
  padding: 18px 22px;
}
.btn-stage-full:hover {
  filter: brightness(1.05);
  box-shadow: 0 0 0 3px rgba(41,98,255,0.20);
}
.btn-stage-full .stage-num {
  background: rgba(255,255,255,0.22);
  color: #fff;
}
.btn-stage-full strong {
  color: #fff;
  font-size: 1.05em;
}
.btn-stage-full small  {
  color: rgba(255,255,255,0.85);
}

.btn-stage:disabled {
  opacity: 0.5;
  cursor: wait;
}

/* ============================================================
   Right-side drawer (drill-ins)
   ============================================================ */
.drawer { position: fixed; inset: 0; z-index: 1100; }
.drawer[hidden] { display: none !important; }
.drawer-backdrop {
  position: absolute; inset: 0;
  background: rgba(15,23,42,0.45);
  opacity: 0;
  transition: opacity 0.22s ease;
}
.drawer.open .drawer-backdrop { opacity: 1; }
.drawer-panel {
  position: absolute;
  top: 0; right: 0; bottom: 0;
  width: min(960px, 80vw);
  background: var(--surface);
  display: flex;
  flex-direction: column;
  transform: translateX(100%);
  transition: transform 0.25s cubic-bezier(0.2, 0, 0.2, 1);
  box-shadow: -8px 0 24px rgba(15,23,42,0.18);
}
.drawer.open .drawer-panel { transform: translateX(0); }
.drawer-header {
  display: flex; align-items: center; gap: 10px;
  padding: 12px 18px;
  border-bottom: 1px solid var(--border);
  background: #fafbfc;
}
.drawer-header h2 { font-size: 1.05em; font-weight: 600; flex: 1; margin: 0; }
.drawer-header a {
  font-size: 0.85em;
  color: var(--muted);
  text-decoration: none;
}
.drawer-header a:hover { color: var(--accent); text-decoration: underline; }
.drawer-close {
  background: transparent;
  border: 0;
  font-size: 1.6rem;
  line-height: 1;
  cursor: pointer;
  color: var(--muted);
  padding: 0 4px;
}
.drawer-close:hover { color: var(--fg); }
#drawer-iframe { flex: 1; border: 0; width: 100%; }

body.drawer-open { overflow: hidden; }

/* Embedded view (page rendered with ?embedded=1, no sidebar). */
.content-embedded {
  padding: 20px 24px;
  max-width: none;
  width: 100%;
}
body.embedded { background: var(--surface); }
body.embedded .page-head { border-bottom: 1px solid var(--border); padding-bottom: 12px; }

/* ============================================================
   Loading overlay + spinner
   ============================================================ */
.loading-overlay {
  position: fixed;
  inset: 0;
  background: rgba(255,255,255,0.85);
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 16px;
  z-index: 1000;
  backdrop-filter: blur(2px);
}
/* Class selector outranks the UA [hidden] rule, so we have to opt in here. */
.loading-overlay[hidden] { display: none !important; }
.spinner {
  width: 48px; height: 48px;
  border: 4px solid var(--accent-soft);
  border-top-color: var(--accent);
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }
.loading-text { color: var(--fg); font-weight: 500; }
.loading-dots::after {
  content: '';
  animation: dots 1.4s steps(4, end) infinite;
}
@keyframes dots {
  0%, 20% { content: ''; }
  40%     { content: '.'; }
  60%     { content: '..'; }
  80%, 100% { content: '...'; }
}

/* ============================================================
   Run-to-run diff verdicts
   ============================================================ */
.verdict {
  font-size: 0.78em;
  padding: 2px 9px;
  border-radius: 12px;
  font-weight: 500;
  letter-spacing: 0.02em;
  text-transform: lowercase;
}
.verdict-same      { background: #f3f4f6; color: var(--muted); }
.verdict-improved  { background: var(--good-soft); color: var(--good); }
.verdict-regressed { background: var(--bad-soft);  color: var(--bad); }
.verdict-added     { background: var(--info-soft); color: var(--info); }
.verdict-removed   { background: #fff3e0; color: var(--warn); }
.verdict-changed   { background: #ede7f6; color: #5e35b1; }

/* ========================================================================
 * QA pre-dispatch gate
 * ====================================================================== */
.qa-summary-strip {
  display: flex;
  gap: 12px;
  margin: 12px 0 18px;
  flex-wrap: wrap;
}
.qa-pill {
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  padding: 10px 16px;
  border-radius: 8px;
  background: #f8fafc;
  border: 1px solid #e5e7eb;
  min-width: 90px;
}
.qa-pill > span:first-of-type,
.qa-pill > strong {
  font-size: 1.6em;
  font-weight: 600;
  line-height: 1.1;
}
.qa-pill > small {
  font-size: 0.78em;
  color: var(--muted);
  text-transform: lowercase;
  letter-spacing: 0.04em;
  margin-top: 2px;
}
.qa-pill-passed  { background: var(--good-soft); border-color: var(--good); color: var(--good); }
.qa-pill-passed > small  { color: var(--good); }
.qa-pill-warned  { background: #fff8e6; border-color: var(--warn); color: var(--warn); }
.qa-pill-warned > small  { color: var(--warn); }
.qa-pill-failed  { background: var(--bad-soft); border-color: var(--bad); color: var(--bad); }
.qa-pill-failed > small  { color: var(--bad); }
.qa-pill-total   { background: #f1f5f9; }
.qa-pill-status  { background: #eef2ff; border-color: #c7d2fe; }

.qa-toolbar {
  margin: 12px 0;
  display: flex;
  gap: 8px;
  align-items: center;
}
.qa-toolbar select {
  padding: 4px 8px;
  border: 1px solid #d1d5db;
  border-radius: 4px;
  background: white;
}
.qa-jobs-table th.num,
.qa-jobs-table td.num {
  text-align: right;
  white-space: nowrap;
}
.qa-jobs-table td .status {
  margin-left: 4px;
}
.qa-legend {
  margin: 12px 0 18px;
  background: #f8fafc;
  border: 1px solid #e5e7eb;
  border-radius: 6px;
  padding: 10px 12px;
}
.qa-legend > summary {
  cursor: pointer;
  user-select: none;
  font-weight: 500;
}
.qa-rules { margin-top: 8px; }
.qa-rules code { font-size: 0.85em; }

/* QA panel inside job.html */
.qa-job-summary {
  margin: 8px 0 14px;
  padding: 10px 14px;
  border-radius: 6px;
  background: #f8fafc;
  border: 1px solid #e5e7eb;
}
.qa-job-summary.qa-fail   { background: var(--bad-soft);  border-color: var(--bad); }
.qa-job-summary.qa-warn   { background: #fff8e6;          border-color: var(--warn); }
.qa-job-summary.qa-pass   { background: var(--good-soft); border-color: var(--good); }
.qa-checks-table td code  { font-size: 0.85em; }
.qa-check-details { font-family: monospace; font-size: 0.85em; color: var(--muted); }
.btn-sm           { padding: 2px 8px; font-size: 0.85em; }

/* ========================================================================
 * QA test-suite view (batch page tab "③½ QA")
 * ====================================================================== */
.qa-head { display: flex; align-items: baseline; gap: 12px; margin-top: 12px; flex-wrap: wrap; }
.qa-head h2 { margin: 0; }
.qa-head-meta { font-size: 0.9em; color: var(--muted); display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }

.qa-section-head {
  margin-top: 28px;
  margin-bottom: 4px;
  font-size: 1.05em;
  font-weight: 600;
  border-top: 1px solid #e5e7eb;
  padding-top: 18px;
}
.qa-section-head:first-of-type { border-top: none; padding-top: 0; }
.qa-section-head small { font-weight: 400; }
.qa-section-hint { color: var(--muted); font-size: 0.88em; margin: 2px 0 14px; }

/* Collapsible section wrappers (Test results / Per-template results / Associates per manager) */
.qa-collapse-section            { margin-top: 0; }
.qa-collapse-section + .qa-collapse-section { margin-top: 8px; }
.qa-section-summary {
  cursor: pointer;
  user-select: none;
  list-style: none;
  display: flex;
  align-items: baseline;
  gap: 8px;
  padding: 8px 4px;
  margin-top: 18px;
  margin-bottom: 6px;
  border-radius: 4px;
  transition: background 0.12s ease;
}
.qa-section-summary::-webkit-details-marker { display: none; }
.qa-section-summary::marker                { content: ''; }
.qa-section-summary:hover                  { background: #f8fafc; }

/* Triangle/chevron indicator that rotates on open */
.qa-collapse-arrow {
  display: inline-block;
  font-size: 0.7em;
  color: var(--muted);
  transition: transform 0.18s ease;
  transform: rotate(-90deg);   /* pointing right when closed */
  width: 14px;
  text-align: center;
}
details[open] > summary > .qa-collapse-arrow { transform: rotate(0deg); }

/* Per-template inner sections inside Test results */
.qa-suite-tpl-collapsible           { padding: 0; }
.qa-suite-tpl-collapsible > summary {
  cursor: pointer;
  user-select: none;
  list-style: none;
}
.qa-suite-tpl-collapsible > summary::-webkit-details-marker { display: none; }
.qa-suite-tpl-collapsible > summary::marker                { content: ''; }
.qa-suite-tpl-collapsible > summary:hover                  { filter: brightness(1.1); }
.qa-suite-tpl-collapsible > summary > .qa-collapse-arrow {
  color: rgba(255,255,255,0.7);   /* visible on dark header */
  margin-right: 4px;
}

/* --- Per-template cards --- */
.qa-template-cards {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(220px, 1fr));
  gap: 14px;
  margin-bottom: 8px;
}
.qa-tpl-card {
  background: #fff;
  border: 1px solid #e5e7eb;
  border-radius: 8px;
  padding: 12px 14px;
  cursor: pointer;
  transition: border-color 0.12s, box-shadow 0.12s, transform 0.12s;
  position: relative;
}
.qa-tpl-card:hover { border-color: #94a3b8; box-shadow: 0 2px 6px rgba(0,0,0,0.04); }
.qa-tpl-card-active {
  border-color: var(--info);
  box-shadow: 0 0 0 2px rgba(59,130,246,0.15);
}
.qa-tpl-card.has-fail { border-left: 4px solid var(--bad);  }
.qa-tpl-card.has-warn { border-left: 4px solid var(--warn); }
.qa-tpl-card.all-pass { border-left: 4px solid var(--good); }

.qa-tpl-card-head {
  display: flex; justify-content: space-between; align-items: baseline;
  margin-bottom: 8px;
}
.qa-tpl-card-head strong { font-size: 0.95em; }
.qa-tpl-bar {
  display: flex;
  height: 8px;
  background: #e5e7eb;
  border-radius: 4px;
  overflow: hidden;
  margin-bottom: 8px;
}
.qa-tpl-bar-pass { background: var(--good); }
.qa-tpl-bar-warn { background: var(--warn); }
.qa-tpl-bar-fail { background: var(--bad);  }
.qa-tpl-counts {
  display: flex;
  gap: 12px;
  font-size: 0.82em;
  flex-wrap: wrap;
}
.qa-tpl-counts > span {
  display: inline-flex;
  align-items: center;
  gap: 4px;
}
.qa-tpl-counts .dot {
  display: inline-block;
  width: 8px; height: 8px;
  border-radius: 50%;
}
.qa-tpl-pass { color: var(--good); }
.qa-tpl-pass .dot { background: var(--good); }
.qa-tpl-warn { color: var(--warn); }
.qa-tpl-warn .dot { background: var(--warn); }
.qa-tpl-fail { color: var(--bad);  }
.qa-tpl-fail .dot { background: var(--bad); }

/* --- Failure clusters --- */
.qa-clusters {
  display: flex;
  flex-direction: column;
  gap: 8px;
}
.qa-cluster {
  border: 1px solid #e5e7eb;
  border-left-width: 4px;
  border-radius: 6px;
  background: #fafbfc;
  padding: 0;
}
.qa-cluster-fail { border-left-color: var(--bad);  background: #fef2f2; }
.qa-cluster-warn { border-left-color: var(--warn); background: #fffaeb; }
.qa-cluster > summary {
  padding: 10px 14px;
  cursor: pointer;
  user-select: none;
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
}
.qa-cluster > summary code  { font-weight: 600; }
.qa-cluster > summary em    { color: var(--muted); font-style: normal; font-size: 0.92em; flex-basis: 100%; }
.qa-cluster-badge {
  background: rgba(0,0,0,0.08);
  border-radius: 12px;
  padding: 2px 10px;
  font-size: 0.85em;
  font-weight: 600;
  min-width: 24px;
  text-align: center;
}
.qa-cluster-fail .qa-cluster-badge { background: var(--bad);  color: white; }
.qa-cluster-warn .qa-cluster-badge { background: var(--warn); color: white; }
.qa-cluster-body {
  border-top: 1px solid #e5e7eb;
  padding: 10px 14px;
  background: white;
}
.qa-cluster-body table { margin: 0; }
.qa-no-issues {
  margin: 12px 0;
  padding: 14px 18px;
  background: var(--good-soft);
  border: 1px solid var(--good);
  border-radius: 6px;
  color: var(--good);
  font-weight: 500;
}

/* --- Rule coverage matrix --- */
.qa-rules-matrix th.num,
.qa-rules-matrix td.num { text-align: right; white-space: nowrap; min-width: 56px; }
.qa-rules-matrix .qa-rule-row-fail { background: #fef2f2; }
.qa-rules-matrix .qa-rule-row-warn { background: #fffaeb; }
.qa-rules-matrix .qa-fail-num     { color: var(--bad); }
.qa-rules-matrix .qa-warn-num     { color: var(--warn); }
.qa-rule-mini-bar {
  display: flex;
  height: 6px;
  background: #e5e7eb;
  border-radius: 3px;
  overflow: hidden;
  min-width: 100px;
}

/* --- Filter status text --- */
.qa-filter-status { font-size: 0.85em; }

/* ========================================================================
 * Test-suite view (KGL_Email_QA-style nested layout)
 * ====================================================================== */
.qa-suite {
  display: flex;
  flex-direction: column;
  gap: 18px;
  margin: 12px 0 24px;
}
.qa-suite-tpl {
  border: 1px solid #e5e7eb;
  border-radius: 8px;
  overflow: hidden;
  background: white;
}
.qa-suite-tpl-head {
  background: #1f2937;
  color: #f3f4f6;
  padding: 10px 16px;
  display: flex;
  align-items: baseline;
  gap: 14px;
  flex-wrap: wrap;
}
.qa-suite-tpl-head strong {
  font-size: 1.0em;
  font-weight: 600;
}
.qa-suite-tpl-head .dim { color: #9ca3af; font-size: 0.88em; }
.qa-suite-tpl-head-issues { background: #1f2937; }
.qa-suite-pass-ratio {
  background: rgba(255,255,255,0.12);
  padding: 2px 10px;
  border-radius: 12px;
  font-size: 0.85em;
  font-weight: 500;
}

/* Each rule row is a <details>; we customise the marker */
.qa-suite-rule {
  border-top: 1px solid #f1f5f9;
  background: white;
}
.qa-suite-rule:first-of-type { border-top: none; }
.qa-suite-rule > summary {
  list-style: none;
  cursor: pointer;
  user-select: none;
  display: grid;
  grid-template-columns: 36px 28px 1fr auto;
  align-items: center;
  gap: 12px;
  padding: 10px 16px;
}
.qa-suite-rule > summary::-webkit-details-marker { display: none; }
.qa-suite-rule > summary::marker { content: ''; }

.qa-suite-icon {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 22px;
  height: 22px;
  border-radius: 50%;
  font-size: 0.85em;
  font-weight: 700;
  line-height: 1;
}
.qa-suite-icon-pass    { background: var(--good-soft); color: var(--good); }
.qa-suite-icon-warn    { background: #fff4d6;          color: var(--warn); }
.qa-suite-icon-fail    { background: var(--bad-soft);  color: var(--bad);  }
.qa-suite-icon-error   { background: var(--bad-soft);  color: var(--bad);  }
.qa-suite-icon-skipped { background: #f1f5f9;          color: var(--muted); }

.qa-suite-num {
  color: var(--muted);
  font-size: 0.95em;
  font-weight: 500;
  text-align: center;
}
.qa-suite-rule-name {
  font-weight: 500;
  color: #111827;
}
.qa-suite-rule-summary {
  color: var(--muted);
  font-size: 0.88em;
  text-align: right;
  white-space: nowrap;
}

/* Verdict-tinted rows */
.qa-suite-rule-fail    > summary { background: #fef2f2; }
.qa-suite-rule-error   > summary { background: #fef2f2; }
.qa-suite-rule-warn    > summary { background: #fffaeb; }
.qa-suite-rule-skipped > summary { background: #fafafa; }
.qa-suite-rule-fail    > summary .qa-suite-rule-summary,
.qa-suite-rule-error   > summary .qa-suite-rule-summary { color: var(--bad);  font-weight: 500; }
.qa-suite-rule-warn    > summary .qa-suite-rule-summary { color: var(--warn); font-weight: 500; }

.qa-suite-rule-body {
  padding: 0 16px 14px 76px;     /* aligned with the rule-name column */
  background: white;
}
.qa-suite-failures {
  margin: 0;
  border: 1px solid #e5e7eb;
  border-radius: 6px;
  overflow: hidden;
}
.qa-suite-failures th {
  background: #f8fafc;
  color: var(--muted);
  font-size: 0.78em;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  font-weight: 600;
  padding: 6px 10px;
  text-align: left;
}
.qa-suite-failures td {
  padding: 8px 10px;
  vertical-align: top;
  font-size: 0.92em;
}
.qa-suite-failure-row.qa-suite-failure-fail   { background: #fef9f9; }
.qa-suite-failure-row.qa-suite-failure-error  { background: #fef9f9; }
.qa-suite-failure-row.qa-suite-failure-warn   { background: #fffdf5; }
.qa-suite-details > summary { font-size: 0.85em; cursor: pointer; }
.qa-suite-details pre {
  margin: 4px 0 0;
  padding: 8px 10px;
  background: #1e293b;
  color: #e2e8f0;
  border-radius: 4px;
  font-size: 0.78em;
  max-height: 240px;
  overflow: auto;
}

/* Responsive: collapse the right-side summary onto its own line on narrow screens */
@media (max-width: 720px) {
  .qa-suite-rule > summary {
    grid-template-columns: 32px 24px 1fr;
    grid-template-rows: auto auto;
    row-gap: 4px;
  }
  .qa-suite-rule-summary { grid-column: 1 / -1; text-align: left; }
  .qa-suite-rule-body { padding-left: 16px; }
}

/* Attachments table on the per-job page */
.qa-attach-table th.num,
.qa-attach-table td.num { text-align: right; white-space: nowrap; }
.qa-attach-table .qa-attach-missing { background: var(--bad-soft); }
.qa-attach-table code { font-size: 0.85em; }

/* ========================================================================
 * Associates per manager (collapsible directory at the bottom of QA tab)
 * ====================================================================== */
.qa-associates {
  display: flex;
  flex-direction: column;
  gap: 4px;
  margin-bottom: 16px;
}
.qa-associate-mgr {
  border: 1px solid #e5e7eb;
  border-radius: 6px;
  background: #fff;
  overflow: hidden;
}
.qa-associate-mgr > summary {
  cursor: pointer;
  user-select: none;
  list-style: none;
  display: grid;
  grid-template-columns: 1fr auto auto;
  gap: 12px;
  align-items: center;
  padding: 8px 14px;
  background: #f8fafc;
  transition: background 0.12s ease;
}
.qa-associate-mgr > summary::-webkit-details-marker { display: none; }
.qa-associate-mgr > summary::marker                { content: ''; }
.qa-associate-mgr > summary:hover                  { background: #f1f5f9; }
.qa-associate-mgr[open] > summary                  { background: #eef2ff; border-bottom: 1px solid #e0e7ff; }

.qa-associate-mgr-name strong { font-size: 0.95em; }
.qa-associate-mgr-name small  { margin-left: 6px; }

.qa-associate-mgr-templates {
  display: inline-flex;
  gap: 4px;
  flex-wrap: wrap;
}
.qa-tpl-pill {
  display: inline-block;
  padding: 1px 8px;
  background: rgba(59,130,246,0.1);
  color: #1e40af;
  border-radius: 10px;
  font-size: 0.75em;
  font-weight: 500;
  white-space: nowrap;
}

.qa-associate-count {
  background: var(--accent);
  color: #fff;
  padding: 2px 12px;
  border-radius: 12px;
  font-size: 0.85em;
  font-weight: 600;
  white-space: nowrap;
}
.qa-associate-mgr-empty .qa-associate-count {
  background: #cbd5e1;
}

.qa-associate-body {
  padding: 8px 14px 12px;
}
.qa-associate-table {
  margin: 0;
  width: 100%;
  border-collapse: collapse;
}
.qa-associate-table th {
  background: transparent;
  text-align: left;
  font-size: 0.78em;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: var(--muted);
  font-weight: 600;
  padding: 6px 10px;
  border-bottom: 1px solid #e5e7eb;
}
.qa-associate-table td {
  padding: 6px 10px;
  border-bottom: 1px solid #f1f5f9;
  font-size: 0.92em;
}
.qa-associate-table tbody tr:hover { background: #f8fafc; }
.qa-associate-inactive { background: #fef9f9; }
.qa-associate-inactive strong { color: var(--bad); text-decoration: line-through; }

/* ========================================================================
 * Activity / audit timeline (replaces old technical /events page)
 * ====================================================================== */
.activity-list {
  display: flex;
  flex-direction: column;
  gap: 8px;
}
.activity-card {
  border: 1px solid #e5e7eb;
  border-radius: 8px;
  background: white;
  overflow: hidden;
  border-left-width: 4px;
}
.activity-card.activity-status-completed { border-left-color: var(--good); }
.activity-card.activity-status-failed    { border-left-color: var(--bad); }
.activity-card.activity-status-cancelled { border-left-color: #94a3b8; }
.activity-card.activity-status-paused    { border-left-color: var(--warn); }
.activity-card.activity-status-running   { border-left-color: var(--info); }
.activity-card.activity-status-pendingapproval { border-left-color: #a855f7; }

.activity-card > summary {
  cursor: pointer;
  user-select: none;
  list-style: none;
  padding: 12px 16px;
  display: flex;
  flex-direction: column;
  gap: 4px;
  transition: background 0.12s;
}
.activity-card > summary::-webkit-details-marker { display: none; }
.activity-card > summary::marker                { content: ''; }
.activity-card > summary:hover                  { background: #f8fafc; }
.activity-card[open] > summary                  { background: #f1f5f9; border-bottom: 1px solid #e5e7eb; }

.activity-card-row1 {
  display: flex; align-items: baseline; gap: 10px; flex-wrap: wrap;
}
.activity-title { font-size: 0.98em; }
.activity-title a { color: inherit; text-decoration: none; }
.activity-title a:hover { text-decoration: underline; }
.activity-templates { font-size: 0.85em; }
.activity-card-row2 { font-size: 0.85em; color: var(--muted); }
.activity-summary-placeholder { font-size: 0.85em; margin-top: 2px; font-style: italic; }
.activity-summary-placeholder.has-problems {
  color: var(--bad);
  font-style: normal;
  font-weight: 500;
}

.activity-body { padding: 14px 18px 18px; }
.activity-loading { padding: 12px 0; }

/* Top-of-body summary banner */
.activity-summary {
  background: #f8fafc;
  border: 1px solid #e5e7eb;
  border-radius: 6px;
  padding: 10px 14px;
  margin-bottom: 14px;
}
.activity-summary.has-problems {
  background: var(--bad-soft);
  border-color: var(--bad);
}
.activity-allgood {
  color: var(--good);
  font-weight: 500;
  margin-bottom: 6px;
}
.activity-problems {
  color: var(--bad);
  margin-bottom: 6px;
}
.activity-problems ul {
  margin: 4px 0 0 18px;
  padding: 0;
}
.activity-problems li { font-size: 0.92em; }
.activity-stats { font-size: 0.88em; color: var(--muted); }
.activity-stats strong { color: #111827; }

/* The timeline itself */
.activity-timeline {
  display: flex;
  flex-direction: column;
  gap: 4px;
  margin-top: 4px;
}
.activity-entry {
  display: grid;
  grid-template-columns: 150px 60px 1fr;
  align-items: baseline;
  gap: 10px;
  padding: 6px 8px;
  border-left: 3px solid transparent;
  border-radius: 3px;
  font-size: 0.92em;
}
.activity-entry .activity-when  { color: var(--muted); font-size: 0.85em; font-family: monospace; white-space: nowrap; }
.activity-entry .activity-icon  { font-weight: 600; font-size: 0.85em; color: var(--muted); }
.activity-entry .activity-label { font-weight: 500; }
.activity-entry .activity-detail{
  display: block;
  margin-top: 2px;
  grid-column: 3;
  font-size: 0.86em;
  color: var(--muted);
}
.activity-entry.sev-good { border-left-color: var(--good); background: #f0fdf4; }
.activity-entry.sev-warn { border-left-color: var(--warn); background: #fffaeb; }
.activity-entry.sev-bad  { border-left-color: var(--bad);  background: var(--bad-soft); }
.activity-entry.sev-info { border-left-color: #94a3b8;     background: #f8fafc; }
.activity-entry.sev-bad  .activity-label  { color: var(--bad); font-weight: 600; }
.activity-entry.sev-good .activity-icon   { color: var(--good); }
.activity-entry.sev-warn .activity-icon   { color: var(--warn); }
.activity-entry.sev-bad  .activity-icon   { color: var(--bad); }

@media (max-width: 720px) {
  .activity-entry { grid-template-columns: 1fr; }
  .activity-entry .activity-detail { grid-column: 1; }
}

/* Search toolbar above the associates list */
.qa-associates-toolbar {
  display: flex;
  align-items: center;
  gap: 10px;
  margin: 8px 0 14px;
}
.qa-associates-toolbar input[type="search"] {
  flex: 1 1 360px;
  max-width: 480px;
  padding: 8px 12px;
  border: 1px solid var(--border-strong);
  border-radius: var(--radius);
  font-family: inherit;
  font-size: 0.95em;
  background: white;
}
.qa-associates-toolbar input[type="search"]:focus {
  outline: none;
  border-color: var(--accent);
  box-shadow: 0 0 0 3px rgba(41,98,255,0.15);
}
#qa-associate-search-status {
  font-size: 0.88em;
  white-space: nowrap;
}

/* ------- "Expected vs Got" panel inside failure rows ------- */
.qa-suite-expected {
  margin: 0 0 10px;
  padding: 8px 12px;
  background: #eff6ff;
  border-left: 3px solid var(--info);
  border-radius: 4px;
  font-size: 0.9em;
}
.qa-suite-expected-label {
  font-weight: 600;
  color: var(--info);
  margin-right: 6px;
}
.qa-suite-expected-text { color: #1e3a8a; }

/* The "Got" cell — message + structured details */
.qa-got-msg {
  font-weight: 500;
  color: #111827;
  margin-bottom: 6px;
}
.qa-suite-failure-fail .qa-got-msg,
.qa-suite-failure-error .qa-got-msg { color: var(--bad);  }
.qa-suite-failure-warn .qa-got-msg                       { color: var(--warn); }

.qa-got-details {
  margin: 4px 0 0;
  display: grid;
  grid-template-columns: max-content 1fr;
  gap: 4px 14px;
  font-size: 0.88em;
}
.qa-got-details > dt {
  font-weight: 500;
  color: var(--muted);
  text-transform: none;
  white-space: nowrap;
}
.qa-got-details > dd {
  margin: 0;
  color: #111827;
  word-break: break-word;
  overflow-wrap: anywhere;
}
.qa-got-details > dd > code {
  background: rgba(0,0,0,0.04);
  padding: 1px 6px;
  border-radius: 3px;
  font-size: 0.95em;
}

.qa-got-list {
  list-style: none;
  margin: 0;
  padding: 0;
  display: flex;
  flex-direction: column;
  gap: 2px;
}
.qa-got-list > li > code {
  background: rgba(0,0,0,0.04);
  padding: 1px 6px;
  border-radius: 3px;
}

.qa-got-table {
  margin: 4px 0 0;
  border-collapse: collapse;
  font-size: 0.88em;
}
.qa-got-table th {
  background: #f8fafc;
  color: var(--muted);
  font-weight: 600;
  padding: 4px 8px;
  border: 1px solid #e5e7eb;
  text-align: left;
  text-transform: lowercase;
  font-size: 0.95em;
}
.qa-got-table td {
  padding: 4px 8px;
  border: 1px solid #e5e7eb;
  vertical-align: top;
}
.qa-got-table td code {
  background: transparent;
  padding: 0;
  font-size: 0.95em;
}

/* ========================================================================
 * Login screen
 * ====================================================================== */
.login-body {
  margin: 0;
  min-height: 100vh;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Oxygen,
               Ubuntu, Cantarell, "Helvetica Neue", sans-serif;
  color: #1f2937;
  background:
    radial-gradient(circle at 18% 16%,  rgba(59,130,246,0.18), transparent 38%),
    radial-gradient(circle at 88% 84%,  rgba(139,92,246,0.16), transparent 36%),
    linear-gradient(135deg, #0f172a 0%, #1e293b 100%);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px;
}
.login-shell {
  width: 100%;
  max-width: 420px;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 18px;
}
.login-card {
  width: 100%;
  background: #ffffff;
  border-radius: 14px;
  box-shadow:
    0 1px 0 rgba(255,255,255,0.05) inset,
    0 12px 40px rgba(0,0,0,0.35),
    0 2px 6px  rgba(0,0,0,0.18);
  padding: 36px 36px 28px;
}
.login-brand {
  display: flex;
  align-items: center;
  gap: 12px;
  margin-bottom: 28px;
}
.login-brand-mark {
  width: 44px; height: 44px;
  border-radius: 11px;
  background: linear-gradient(135deg, #3b82f6 0%, #6366f1 100%);
  color: #fff;
  font-weight: 700;
  font-size: 16px;
  letter-spacing: 0.04em;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  box-shadow: 0 4px 12px rgba(59,130,246,0.35);
}
.login-brand-text {
  display: flex;
  flex-direction: column;
  line-height: 1.15;
}
.login-brand-text strong {
  font-size: 1.05em;
  color: #0f172a;
  letter-spacing: -0.005em;
}
.login-brand-text span {
  font-size: 0.78em;
  color: #6b7280;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  margin-top: 2px;
}

.login-title {
  margin: 0 0 6px;
  font-size: 1.4em;
  font-weight: 600;
  color: #0f172a;
  letter-spacing: -0.01em;
}
.login-sub {
  margin: 0 0 22px;
  color: #6b7280;
  font-size: 0.94em;
}

.login-alert {
  display: flex;
  gap: 10px;
  align-items: center;
  background: #fef2f2;
  border: 1px solid #fecaca;
  color: #991b1b;
  padding: 10px 14px;
  border-radius: 8px;
  margin-bottom: 18px;
  font-size: 0.92em;
}
.login-alert-icon {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 22px;
  height: 22px;
  border-radius: 50%;
  background: #dc2626;
  color: #fff;
  font-weight: 700;
  font-size: 0.8em;
  flex-shrink: 0;
}

.login-form {
  display: flex;
  flex-direction: column;
  gap: 14px;
}
.login-field { display: flex; flex-direction: column; gap: 6px; }
.login-field > span {
  font-size: 0.82em;
  font-weight: 500;
  color: #374151;
  letter-spacing: 0.01em;
}
.login-field input[type="text"],
.login-field input[type="password"] {
  width: 100%;
  padding: 11px 14px;
  font-size: 0.96em;
  font-family: inherit;
  color: #111827;
  background: #f9fafb;
  border: 1px solid #d1d5db;
  border-radius: 8px;
  transition: border-color 0.12s ease, box-shadow 0.12s ease, background 0.12s ease;
  box-sizing: border-box;
}
.login-field input[type="text"]:focus,
.login-field input[type="password"]:focus {
  outline: none;
  background: #fff;
  border-color: #3b82f6;
  box-shadow: 0 0 0 3px rgba(59,130,246,0.18);
}

.login-password-wrap { position: relative; }
.login-password-wrap input { padding-right: 64px; }
.login-password-toggle {
  position: absolute;
  right: 8px;
  top: 50%;
  transform: translateY(-50%);
  background: transparent;
  border: 0;
  color: #6b7280;
  font-size: 0.78em;
  padding: 6px 10px;
  cursor: pointer;
  border-radius: 4px;
  font-family: inherit;
}
.login-password-toggle:hover { color: #3b82f6; background: rgba(59,130,246,0.06); }

.login-remember {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  font-size: 0.9em;
  color: #4b5563;
  margin-top: 2px;
  cursor: pointer;
  user-select: none;
}
.login-remember input[type="checkbox"] {
  width: 16px; height: 16px;
  accent-color: #3b82f6;
}

.login-submit {
  margin-top: 10px;
  padding: 12px 18px;
  font-size: 0.98em;
  font-weight: 600;
  font-family: inherit;
  color: #fff;
  background: linear-gradient(135deg, #3b82f6 0%, #4f46e5 100%);
  border: 0;
  border-radius: 8px;
  cursor: pointer;
  letter-spacing: 0.01em;
  transition: filter 0.12s ease, box-shadow 0.12s ease, transform 0.06s ease;
  box-shadow: 0 4px 12px rgba(59,130,246,0.30);
}
.login-submit:hover  { filter: brightness(1.05); box-shadow: 0 6px 16px rgba(59,130,246,0.38); }
.login-submit:active { transform: translateY(1px); }

.login-foot {
  margin-top: 20px;
  text-align: center;
  color: #9ca3af;
  font-size: 0.82em;
}
.login-tagline {
  margin: 4px 0 0;
  text-align: center;
  color: rgba(255,255,255,0.45);
  font-size: 0.82em;
}

@media (max-width: 480px) {
  .login-card { padding: 28px 24px 22px; }
  .login-title { font-size: 1.25em; }
}

/* Sidebar user block (shown when logged in) */
.sb-user {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 8px;
  margin-bottom: 8px;
  border-radius: 6px;
  background: rgba(255,255,255,0.05);
}
.sb-user-avatar {
  width: 32px;
  height: 32px;
  border-radius: 50%;
  background: linear-gradient(135deg, #3b82f6 0%, #6366f1 100%);
  color: #fff;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  font-weight: 600;
  font-size: 0.95em;
  flex-shrink: 0;
}
.sb-user-meta {
  display: flex;
  flex-direction: column;
  line-height: 1.25;
  overflow: hidden;
}
.sb-user-name {
  color: #e2e8f0;
  font-weight: 500;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  max-width: 130px;
}
.sb-logout {
  font-size: 0.82em;
  color: #94a3b8;
  text-decoration: none;
}
.sb-logout:hover { color: #ef4444; }

/* ========================================================================
 * Email history view (/history)
 * ====================================================================== */
.history-list { display: flex; flex-direction: column; gap: 8px; }
.history-day {
  border: 1px solid #e5e7eb;
  border-radius: 8px;
  background: white;
  border-left: 4px solid var(--good);
  overflow: hidden;
}
.history-day-has-problems { border-left-color: var(--warn); }
.history-day > summary {
  list-style: none;
  cursor: pointer;
  user-select: none;
  padding: 12px 16px;
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 16px;
  flex-wrap: wrap;
  background: #f8fafc;
}
.history-day > summary::-webkit-details-marker { display: none; }
.history-day > summary::marker                { content: ''; }
.history-day > summary:hover                  { background: #f1f5f9; }
.history-day[open] > summary                  { border-bottom: 1px solid #e5e7eb; }
.history-day-head-l {
  display: flex; align-items: baseline; gap: 10px;
}
.history-day-date { font-size: 1.05em; }
.history-day-arrow {
  display: inline-block; font-size: 0.7em; color: var(--muted);
  transition: transform 0.18s ease;
  transform: rotate(-90deg);
}
.history-day[open] > summary > .history-day-head-l > .history-day-arrow {
  transform: rotate(0deg);
}
.history-day-head-r {
  display: flex; gap: 8px; flex-wrap: wrap;
}
.history-stat {
  display: inline-block;
  padding: 2px 10px;
  border-radius: 12px;
  font-size: 0.85em;
  font-weight: 500;
}
.history-stat-sent { background: var(--good-soft); color: var(--good); }
.history-stat-held { background: #fff8e6;          color: var(--warn); }
.history-stat-err  { background: var(--bad-soft);  color: var(--bad);  }

.history-day-body { padding: 8px 16px 14px; }
.history-runs-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.92em;
}
.history-runs-table th {
  background: transparent;
  text-align: left;
  font-size: 0.78em;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: var(--muted);
  padding: 6px 10px;
  border-bottom: 1px solid #e5e7eb;
}
.history-runs-table td {
  padding: 8px 10px;
  border-bottom: 1px solid #f1f5f9;
  vertical-align: top;
}
.history-runs-table th.num,
.history-runs-table td.num { text-align: right; white-space: nowrap; }
.history-runs-table tr.history-run-has-problems { background: #fffdf7; }
.history-runs-table tr:hover { background: #f8fafc; }
.history-num-warn { color: var(--warn); }
.history-num-err  { color: var(--bad);  }
