/* ---------- tokens ---------- */
:root {
  --bg:        #f6f7f9;
  --surface:   #ffffff;
  --border:    #e3e5e9;
  --border-strong: #d3d6dc;
  --text:      #1c1f24;
  --text-mut:  #5b6270;
  --text-dim:  #8a909c;
  --accent:    #1f2937;
  --row-hover: #f4f5f7;

  /* state colors — muted, not saturated */
  --st-pending-bg:    #fdf5e2;
  --st-pending-fg:    #8a5a00;
  --st-pending-bd:    #f0dca8;

  --st-processing-bg: #e5efff;
  --st-processing-fg: #1d4ed8;
  --st-processing-bd: #c2d5fa;

  --st-completed-bg:  #e3f4e6;
  --st-completed-fg:  #1f7a3a;
  --st-completed-bd:  #b9dfc1;

  --st-failed-bg:     #fde8e7;
  --st-failed-fg:     #b42318;
  --st-failed-bd:     #f4c4c0;

  --r:    6px;
  --r-sm: 4px;
  --r-lg: 8px;

  --shadow-sm: 0 1px 2px rgba(16,24,40,0.04);

  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto,
               "Helvetica Neue", Arial, "Liberation Sans", sans-serif;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-size: 14px;
  line-height: 1.45;
  -webkit-font-smoothing: antialiased;
}

a { color: inherit; }

button, input, select, textarea {
  font: inherit;
  color: inherit;
}

/* ---------- navbar ---------- */
.nav {
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  height: 52px;
  display: flex;
  align-items: center;
  padding: 0 20px;
  position: sticky;
  top: 0;
  z-index: 10;
}
.nav-brand {
  display: flex;
  align-items: center;
  gap: 10px;
  font-weight: 600;
  font-size: 14px;
  letter-spacing: -0.005em;
}
.nav-mark {
  width: 22px;
  height: 22px;
  border-radius: var(--r-sm);
  background: var(--text);
  color: var(--surface);
  display: grid;
  place-items: center;
  font-size: 11px;
  font-weight: 700;
  letter-spacing: 0;
}
.nav-spacer { flex: 1; }
.nav-user {
  display: flex;
  align-items: center;
  gap: 10px;
  font-size: 13px;
  color: var(--text-mut);
}
.nav-user-avatar {
  width: 26px;
  height: 26px;
  border-radius: 50%;
  background: #e6e8ed;
  color: var(--text-mut);
  display: grid;
  place-items: center;
  font-size: 11px;
  font-weight: 600;
}
.nav-link-btn {
  background: transparent;
  border: 0;
  font-size: 13px;
  color: var(--text-mut);
  cursor: pointer;
  padding: 4px 8px;
  border-radius: var(--r-sm);
}
.nav-link-btn:hover { background: var(--row-hover); color: var(--text); }

/* ---------- shell ---------- */
.shell {
  display: grid;
  grid-template-columns: 220px 1fr;
  min-height: calc(100vh - 52px);
}

/* ---------- sidebar ---------- */
.side {
  background: var(--surface);
  border-right: 1px solid var(--border);
  padding: 14px 10px;
  display: flex;
  flex-direction: column;
  gap: 16px;
  position: sticky;
  top: 52px;
  align-self: start;
  height: calc(100vh - 52px);
  overflow-y: auto;
}
.side-group {
  display: flex;
  flex-direction: column;
  gap: 1px;
}
.side-label {
  font-size: 10.5px;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--text-dim);
  font-weight: 600;
  padding: 4px 10px 6px;
}
.side-item {
  appearance: none;
  background: transparent;
  border: 0;
  width: 100%;
  text-align: left;
  display: flex;
  align-items: center;
  gap: 9px;
  padding: 6px 10px;
  border-radius: var(--r);
  cursor: pointer;
  font-size: 13px;
  color: var(--text-mut);
  height: 30px;
  position: relative;
}
.side-item:hover { background: var(--row-hover); color: var(--text); }
.side-item[aria-current="page"] {
  background: #eef0f3;
  color: var(--text);
  font-weight: 500;
}
.side-item[aria-current="page"]::before {
  content: "";
  position: absolute;
  left: 3px;
  top: 7px;
  bottom: 7px;
  width: 2px;
  border-radius: 2px;
  background: var(--text);
}
.side-icon {
  width: 16px;
  height: 16px;
  flex-shrink: 0;
  color: currentColor;
  opacity: 0.8;
}
.side-item[aria-current="page"] .side-icon { opacity: 1; }
.side-count {
  margin-left: auto;
  font-size: 11px;
  color: var(--text-dim);
  font-variant-numeric: tabular-nums;
  background: #f1f2f5;
  padding: 1px 6px;
  border-radius: 999px;
  border: 1px solid var(--border);
}
.side-item[aria-current="page"] .side-count {
  background: var(--surface);
}
.side-foot {
  margin-top: auto;
  padding: 8px 10px;
  font-size: 11px;
  color: var(--text-dim);
  line-height: 1.4;
  border-top: 1px solid var(--border);
}
.side-foot .side-env {
  display: inline-flex;
  align-items: center;
  gap: 6px;
}
.side-env-dot {
  width: 6px; height: 6px; border-radius: 50%;
  background: var(--st-completed-fg);
  box-shadow: 0 0 0 2px var(--st-completed-bg);
}

/* mobile sidebar trigger */
.nav-menu {
  display: none;
  width: 32px; height: 32px;
  border-radius: var(--r);
  border: 1px solid var(--border-strong);
  background: var(--surface);
  align-items: center;
  justify-content: center;
  margin-right: 10px;
  cursor: pointer;
}

/* ---------- page ---------- */
.page {
  max-width: 1280px;
  margin: 0 auto;
  padding: 24px 24px 64px;
  min-width: 0;
}

/* ---------- placeholder view ---------- */
.placeholder {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--r-lg);
  padding: 56px 28px;
  text-align: center;
  color: var(--text-mut);
}
.placeholder-icon {
  width: 36px;
  height: 36px;
  margin: 0 auto 10px;
  border-radius: 50%;
  background: #eef0f3;
  display: grid;
  place-items: center;
  color: var(--text-mut);
}
.placeholder-title {
  font-size: 15px;
  font-weight: 600;
  color: var(--text);
  margin: 0 0 4px;
}
.placeholder-sub {
  font-size: 13px;
  margin: 0;
}
.placeholder-tag {
  display: inline-block;
  margin-top: 14px;
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--text-dim);
  border: 1px dashed var(--border-strong);
  padding: 3px 8px;
  border-radius: 999px;
}

/* ---------- table row clickable ---------- */
.tbl tbody tr.clickable { cursor: pointer; }
.tbl tbody tr.clickable:focus-visible {
  outline: 2px solid #98a2b3;
  outline-offset: -2px;
}

/* ---------- detail view ---------- */
.crumbs {
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: 12px;
  color: var(--text-mut);
  margin-bottom: 10px;
}
.crumbs a, .crumbs button {
  background: transparent;
  border: 0;
  padding: 0;
  cursor: pointer;
  color: var(--text-mut);
  text-decoration: none;
  font-size: 12px;
}
.crumbs a:hover, .crumbs button:hover {
  color: var(--text);
  text-decoration: underline;
}
.crumbs-sep { color: var(--text-dim); }
.crumbs-cur { color: var(--text); }

.detail-head {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--r-lg);
  padding: 18px 20px;
  margin-bottom: 16px;
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 16px;
  flex-wrap: wrap;
}
.detail-head-left { display: flex; flex-direction: column; gap: 8px; min-width: 0; }
.detail-head-title {
  font-size: 19px;
  font-weight: 600;
  letter-spacing: -0.01em;
  display: flex;
  align-items: center;
  gap: 12px;
  flex-wrap: wrap;
  margin: 0;
}
.detail-head-id {
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  font-size: 12px;
  color: var(--text-mut);
  background: #f1f2f5;
  padding: 2px 7px;
  border-radius: var(--r-sm);
  border: 1px solid var(--border);
  font-weight: 500;
}
.detail-head-desc {
  color: var(--text-mut);
  font-size: 13px;
  margin: 0;
  max-width: 64ch;
}
.detail-head-right {
  display: flex;
  align-items: center;
  gap: 8px;
}

.detail-grid {
  display: grid;
  grid-template-columns: 1fr 320px;
  gap: 16px;
}
@media (max-width: 980px) {
  .detail-grid { grid-template-columns: 1fr; }
}

.panel {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--r-lg);
  overflow: hidden;
}
.panel-head {
  padding: 11px 16px;
  border-bottom: 1px solid var(--border);
  background: #fafbfc;
  font-size: 12px;
  font-weight: 600;
  color: var(--text-mut);
  text-transform: uppercase;
  letter-spacing: 0.04em;
  display: flex;
  align-items: center;
  justify-content: space-between;
}
.panel-head-actions {
  display: flex;
  gap: 6px;
}
.panel-body { padding: 14px 16px; }
.panel + .panel { margin-top: 14px; }

/* key-value list */
.kv {
  display: grid;
  grid-template-columns: 140px 1fr;
  gap: 8px 16px;
  font-size: 13px;
}
.kv dt {
  color: var(--text-mut);
  font-size: 12.5px;
  padding-top: 1px;
}
.kv dd {
  margin: 0;
  color: var(--text);
  font-variant-numeric: tabular-nums;
  word-break: break-word;
}
.kv dd.mono {
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  font-size: 12.5px;
}

/* timeline */
.timeline {
  list-style: none;
  margin: 0;
  padding: 0;
}
.timeline li {
  position: relative;
  padding: 0 0 14px 22px;
  font-size: 13px;
}
.timeline li::before {
  content: "";
  position: absolute;
  left: 6px;
  top: 4px;
  bottom: -2px;
  width: 1px;
  background: var(--border);
}
.timeline li:last-child::before { display: none; }
.timeline-dot {
  position: absolute;
  left: 2px;
  top: 4px;
  width: 9px;
  height: 9px;
  border-radius: 50%;
  background: var(--surface);
  border: 2px solid var(--text-dim);
  box-shadow: 0 0 0 2px var(--surface);
}
.timeline-dot.info  { border-color: var(--text-dim); }
.timeline-dot.ok    { border-color: var(--st-completed-fg); background: var(--st-completed-fg); }
.timeline-dot.error { border-color: var(--st-failed-fg); background: var(--st-failed-fg); }
.timeline-dot.wait  { border-color: var(--st-processing-fg); }
.timeline-time {
  font-size: 11.5px;
  color: var(--text-dim);
  font-variant-numeric: tabular-nums;
  margin-bottom: 2px;
}
.timeline-msg {
  color: var(--text);
  line-height: 1.45;
}
.timeline li.error .timeline-msg { color: var(--st-failed-fg); }

/* email source card */
.email-card {
  background: #fafbfc;
  border: 1px solid var(--border);
  border-radius: var(--r);
  padding: 12px 14px;
  font-size: 13px;
}
.email-card-row {
  display: grid;
  grid-template-columns: 60px 1fr;
  gap: 6px 12px;
  margin-bottom: 4px;
}
.email-card-row:last-child { margin-bottom: 0; }
.email-card-row dt { color: var(--text-dim); font-size: 12px; }
.email-card-row dd { margin: 0; color: var(--text); }

/* attachment row */
.att {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 10px 12px;
  border: 1px solid var(--border);
  border-radius: var(--r);
  background: var(--surface);
}
.att + .att { margin-top: 8px; }
.att-icon {
  width: 32px;
  height: 32px;
  background: #f1f2f5;
  border-radius: var(--r-sm);
  display: grid;
  place-items: center;
  color: var(--text-mut);
  flex-shrink: 0;
}
.att-info { min-width: 0; flex: 1; }
.att-name {
  font-size: 13px;
  font-weight: 500;
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.att-meta {
  font-size: 11.5px;
  color: var(--text-dim);
  font-variant-numeric: tabular-nums;
  margin-top: 2px;
}

/* stats strip (used in detail header summary) */
.stats {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(140px, 1fr));
  gap: 1px;
  background: var(--border);
  border: 1px solid var(--border);
  border-radius: var(--r-lg);
  overflow: hidden;
  margin-bottom: 16px;
}
.stat {
  background: var(--surface);
  padding: 12px 14px;
}
.stat-label {
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: var(--text-dim);
  font-weight: 600;
  margin-bottom: 4px;
}
.stat-value {
  font-size: 18px;
  font-weight: 600;
  letter-spacing: -0.01em;
  font-variant-numeric: tabular-nums;
}
.stat-sub {
  font-size: 11.5px;
  color: var(--text-mut);
  margin-top: 2px;
}

/* subject column in emails table */
.col-subject {
  max-width: 380px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  font-weight: 500;
}
/* narrower variant for short subject-like identifiers (providers table) */
.col-subject-sm {
  max-width: 180px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  font-weight: 500;
  font-size: 12.5px;
}
.col-from {
  max-width: 220px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.col-from-name { font-size: 13px; }
.col-from-email { font-size: 11.5px; color: var(--text-dim); margin-top: 1px; }
.att-pill {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  font-size: 11.5px;
  color: var(--text-mut);
  background: #f1f2f5;
  border: 1px solid var(--border);
  padding: 1px 7px;
  border-radius: 999px;
  font-variant-numeric: tabular-nums;
}

.page-head {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  margin-bottom: 18px;
  gap: 16px;
  flex-wrap: wrap;
}
.page-title {
  font-size: 20px;
  font-weight: 600;
  letter-spacing: -0.01em;
  margin: 0;
}
.page-sub {
  font-size: 13px;
  color: var(--text-mut);
  margin: 4px 0 0;
}
.page-meta {
  font-size: 12px;
  color: var(--text-dim);
  font-variant-numeric: tabular-nums;
}

/* ---------- toolbar / filters ---------- */
.toolbar {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--r-lg);
  border-bottom-left-radius: 0;
  border-bottom-right-radius: 0;
  border-bottom: 0;
  padding: 10px 12px;
  display: flex;
  align-items: center;
  gap: 12px;
  flex-wrap: wrap;
}
.toolbar-group {
  display: flex;
  align-items: center;
  gap: 8px;
}
.toolbar-label {
  font-size: 12px;
  color: var(--text-mut);
  font-weight: 500;
}
.toolbar-spacer { flex: 1; }

/* search input */
.input,
.select {
  background: var(--surface);
  border: 1px solid var(--border-strong);
  border-radius: var(--r);
  height: 30px;
  padding: 0 9px;
  font-size: 13px;
  color: var(--text);
  outline: none;
  transition: border-color .12s, box-shadow .12s;
}
.input:focus, .select:focus {
  border-color: #98a2b3;
  box-shadow: 0 0 0 3px rgba(31,41,55,0.06);
}
.input { min-width: 220px; }
.input-id { min-width: 0; width: 86px; }
.input::placeholder { color: var(--text-dim); }

.textarea {
  width: 100%;
  min-height: 92px;
  resize: vertical;
  background: var(--surface);
  border: 1px solid var(--border-strong);
  border-radius: var(--r);
  padding: 8px 9px;
  font-size: 13px;
  color: var(--text);
  outline: none;
  transition: border-color .12s, box-shadow .12s;
}
.textarea:focus {
  border-color: #98a2b3;
  box-shadow: 0 0 0 3px rgba(31,41,55,0.06);
}
.textarea::placeholder { color: var(--text-dim); }

.select {
  appearance: none;
  -webkit-appearance: none;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='10' height='6' viewBox='0 0 10 6'%3E%3Cpath fill='none' stroke='%235b6270' stroke-width='1.4' stroke-linecap='round' stroke-linejoin='round' d='M1 1l4 4 4-4'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 8px center;
  padding-right: 26px;
}

/* segmented control */
.seg {
  display: inline-flex;
  background: #f1f2f5;
  border: 1px solid var(--border);
  border-radius: var(--r);
  padding: 2px;
  gap: 2px;
}
.seg-btn {
  appearance: none;
  border: 0;
  background: transparent;
  font-size: 12px;
  font-weight: 500;
  color: var(--text-mut);
  padding: 4px 10px;
  height: 24px;
  border-radius: var(--r-sm);
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  gap: 6px;
  white-space: nowrap;
}
.seg-btn:hover { color: var(--text); }
.seg-btn[aria-pressed="true"] {
  background: var(--surface);
  color: var(--text);
  box-shadow: var(--shadow-sm), 0 0 0 1px var(--border);
}
.seg-count {
  font-size: 11px;
  color: var(--text-dim);
  font-variant-numeric: tabular-nums;
}
.seg-btn[aria-pressed="true"] .seg-count { color: var(--text-mut); }

/* refresh button */
.btn {
  appearance: none;
  background: var(--surface);
  border: 1px solid var(--border-strong);
  height: 30px;
  padding: 0 11px;
  font-size: 13px;
  border-radius: var(--r);
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  gap: 6px;
  color: var(--text);
  transition: background .12s, border-color .12s;
}
.btn:hover { background: #fafbfc; border-color: #b9bec7; }
.btn-primary {
  background: var(--text);
  color: var(--surface);
  border-color: var(--text);
}
.btn-primary:hover { background: #2a3140; border-color: #2a3140; }
.btn-icon { padding: 0 8px; width: 30px; justify-content: center; }
.btn-small { height: 26px; padding: 0 8px; font-size: 12px; }

.form-actions {
  display: flex;
  justify-content: flex-end;
  gap: 8px;
  margin-top: 10px;
}

.notice {
  border: 1px solid var(--border);
  border-radius: var(--r);
  padding: 8px 10px;
  font-size: 13px;
  margin-bottom: 12px;
}
.notice-ok {
  background: var(--st-completed-bg);
  border-color: var(--st-completed-bd);
  color: var(--st-completed-fg);
}
.notice-error {
  background: var(--st-failed-bg);
  border-color: var(--st-failed-bd);
  color: var(--st-failed-fg);
}

.note-form {
  border-bottom: 1px solid var(--border);
  padding-bottom: 14px;
  margin-bottom: 14px;
}
.note-list {
  display: grid;
  gap: 10px;
}
.note-item {
  border: 1px solid var(--border);
  border-radius: var(--r);
  background: #fafbfc;
  padding: 10px 12px;
}
.note-meta {
  display: flex;
  justify-content: space-between;
  gap: 10px;
  color: var(--text-dim);
  font-size: 11.5px;
  margin-bottom: 7px;
  font-variant-numeric: tabular-nums;
}
.note-meta strong {
  color: var(--text-mut);
  font-weight: 600;
}
.note-body {
  white-space: pre-wrap;
  overflow-wrap: anywhere;
  font-size: 13px;
  color: var(--text);
}
.col-note {
  max-width: 220px;
  white-space: nowrap;
}
.note-excerpt {
  display: inline-block;
  max-width: 160px;
  margin-left: 6px;
  color: var(--text-mut);
  overflow: hidden;
  text-overflow: ellipsis;
  vertical-align: middle;
}

/* ---------- table card ---------- */
.tablewrap {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--r-lg);
  border-top-left-radius: 0;
  border-top-right-radius: 0;
  overflow: hidden;
}
.tablescroll {
  overflow-x: auto;
}

.tbl {
  width: 100%;
  border-collapse: separate;
  border-spacing: 0;
  font-size: 13px;
}
.tbl th, .tbl td {
  text-align: left;
  padding: 9px 12px;
  border-bottom: 1px solid var(--border);
  white-space: nowrap;
  vertical-align: middle;
}
.tbl thead th {
  background: #fafbfc;
  font-weight: 500;
  color: var(--text-mut);
  font-size: 11.5px;
  letter-spacing: 0.02em;
  text-transform: uppercase;
  position: sticky;
  top: 0;
  border-bottom: 1px solid var(--border);
  height: 36px;
  padding-top: 0;
  padding-bottom: 0;
}
.tbl tbody tr:hover { background: var(--row-hover); }
.tbl tbody tr:last-child td { border-bottom: 0; }

.col-id {
  font-family: ui-monospace, SFMono-Regular, "SF Mono", Menlo, Consolas, monospace;
  font-size: 12px;
  color: var(--text-mut);
}
.col-desc {
  max-width: 320px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.col-date {
  font-variant-numeric: tabular-nums;
  color: var(--text-mut);
  font-size: 12.5px;
}
.col-email {
  color: var(--text-mut);
  font-size: 12.5px;
  max-width: 220px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.col-error {
  max-width: 260px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  color: var(--st-failed-fg);
  font-size: 12.5px;
}
.col-provider { font-weight: 500; }
.col-action { width: 1%; }
.row-link { text-decoration: none; }
.row-link:hover { text-decoration: underline; }

.sort-btn {
  background: transparent;
  border: 0;
  padding: 0;
  font: inherit;
  color: inherit;
  letter-spacing: inherit;
  text-transform: inherit;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  gap: 4px;
}
.sort-btn:hover { color: var(--text); }
.sort-ind { opacity: 0; font-size: 10px; }
.sort-btn[data-active="true"] .sort-ind { opacity: 1; }

/* ---------- badges ---------- */
.badge {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  font-size: 11.5px;
  font-weight: 500;
  padding: 2px 8px 2px 6px;
  border-radius: 999px;
  border: 1px solid transparent;
  letter-spacing: 0.01em;
  line-height: 1.6;
}
.badge-dot {
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: currentColor;
}
.badge-pending     { background: var(--st-pending-bg);    color: var(--st-pending-fg);    border-color: var(--st-pending-bd); }
.badge-processing  { background: var(--st-processing-bg); color: var(--st-processing-fg); border-color: var(--st-processing-bd); }
.badge-completed   { background: var(--st-completed-bg);  color: var(--st-completed-fg);  border-color: var(--st-completed-bd); }
.badge-failed      { background: var(--st-failed-bg);     color: var(--st-failed-fg);     border-color: var(--st-failed-bd); }

/* email states */
.badge-new        { background: var(--st-processing-bg); color: var(--st-processing-fg); border-color: var(--st-processing-bd); }
.badge-matched    { background: #eef0fb; color: #3b3f8f; border-color: #d9dcf2; }
.badge-processed  { background: var(--st-completed-bg);  color: var(--st-completed-fg);  border-color: var(--st-completed-bd); }
.badge-ignored    { background: #eef0f3; color: var(--text-mut); border-color: var(--border); }
.badge-error      { background: var(--st-failed-bg);     color: var(--st-failed-fg);     border-color: var(--st-failed-bd); }

/* generic on/off badges */
.badge-ok        { background: var(--st-completed-bg); color: var(--st-completed-fg); border-color: var(--st-completed-bd); }
.badge-muted     { background: #eef0f3; color: var(--text-mut); border-color: var(--border); }

.badge-processing .badge-dot { animation: pulse 1.6s ease-in-out infinite; }
@keyframes pulse {
  0%, 100% { opacity: 1; }
  50%      { opacity: 0.35; }
}

/* ---------- pagination ---------- */
.pager {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 10px 12px;
  border-top: 1px solid var(--border);
  background: #fafbfc;
  flex-wrap: wrap;
}
.pager-info {
  font-size: 12.5px;
  color: var(--text-mut);
  font-variant-numeric: tabular-nums;
}
.pager-nav {
  display: inline-flex;
  align-items: center;
  gap: 4px;
}
.page-btn {
  min-width: 30px;
  height: 30px;
  padding: 0 9px;
  border: 1px solid var(--border-strong);
  background: var(--surface);
  border-radius: var(--r);
  cursor: pointer;
  font-size: 13px;
  color: var(--text);
  font-variant-numeric: tabular-nums;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 4px;
}
.page-btn:hover:not(:disabled) { background: #fafbfc; border-color: #b9bec7; }
.page-btn[aria-current="true"] {
  background: var(--text);
  color: var(--surface);
  border-color: var(--text);
}
.page-btn:disabled {
  opacity: 0.45;
  cursor: not-allowed;
}
.page-ellipsis {
  color: var(--text-dim);
  padding: 0 4px;
  user-select: none;
}

/* ---------- empty / states ---------- */
.empty {
  padding: 56px 24px;
  text-align: center;
  color: var(--text-mut);
  font-size: 13.5px;
}
.empty.compact {
  padding: 18px 12px;
  border: 1px dashed var(--border);
  border-radius: var(--r);
  background: #fafbfc;
}
.empty-icon {
  width: 32px;
  height: 32px;
  margin: 0 auto 10px;
  border: 1px dashed var(--border-strong);
  border-radius: 50%;
  display: grid;
  place-items: center;
  color: var(--text-dim);
}

/* ---------- mobile cards ---------- */
.cards { display: none; }

@media (max-width: 960px) {
  .shell { grid-template-columns: 1fr; }
  .side {
    position: fixed;
    top: 52px;
    left: 0;
    bottom: 0;
    width: 240px;
    z-index: 20;
    transform: translateX(-100%);
    transition: transform .18s ease;
    box-shadow: 0 8px 24px rgba(16,24,40,0);
  }
  .side[data-open="true"] {
    transform: translateX(0);
    box-shadow: 0 8px 24px rgba(16,24,40,0.08);
  }
  .side-backdrop {
    position: fixed;
    inset: 52px 0 0 0;
    background: rgba(16,24,40,0.32);
    z-index: 19;
  }
  .nav-menu { display: inline-flex; }
}

@media (max-width: 760px) {
  .page { padding: 16px 12px 48px; }
  .toolbar { border-radius: var(--r-lg); border-bottom: 1px solid var(--border); margin-bottom: 10px; }
  .tablewrap { border-radius: var(--r-lg); }
  .tablescroll { display: none; }
  .cards { display: block; }
  .input { min-width: 0; width: 100%; }
  .toolbar-group.search { width: 100%; }
}

.card {
  padding: 12px 14px;
  border-bottom: 1px solid var(--border);
}
.card:last-child { border-bottom: 0; }
.card-link {
  display: block;
  color: inherit;
  text-decoration: none;
}
.card-link:hover { background: var(--row-hover); }
.card-top {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  margin-bottom: 6px;
}
.card-id {
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  font-size: 12px;
  color: var(--text-mut);
}
.card-provider { font-weight: 600; font-size: 14px; }
.card-desc {
  color: var(--text-mut);
  font-size: 13px;
  margin: 2px 0 8px;
  overflow: hidden;
  text-overflow: ellipsis;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
}
.card-grid {
  display: grid;
  grid-template-columns: auto 1fr;
  gap: 4px 12px;
  font-size: 12px;
}
.card-grid dt { color: var(--text-dim); }
.card-grid dd { margin: 0; color: var(--text-mut); font-variant-numeric: tabular-nums; }

.kv-compact {
  grid-template-columns: 54px 1fr;
  gap: 5px 12px;
}
.text-error { color: var(--st-failed-fg); }
.email-audit {
  border: 1px solid var(--border);
  border-radius: var(--r);
  padding: 12px;
  background: var(--surface);
}
.email-audit + .email-audit { margin-top: 10px; }
.email-audit-head {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 10px;
}
.email-audit-title {
  font-weight: 600;
  font-size: 13.5px;
}
.email-audit-meta {
  font-size: 11.5px;
  color: var(--text-dim);
  margin-top: 2px;
  font-variant-numeric: tabular-nums;
}
.att-list { margin-top: 10px; }

/* ---------- auth ---------- */
.auth {
  min-height: 100vh;
  display: grid;
  place-items: center;
  padding: 24px;
  background:
    radial-gradient(circle at 1px 1px, rgba(0,0,0,0.04) 1px, transparent 0) 0 0/22px 22px,
    var(--bg);
}
.auth-card {
  width: 100%;
  max-width: 360px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--r-lg);
  padding: 28px 26px 22px;
  box-shadow: var(--shadow-sm);
}
.auth-brand {
  display: flex;
  align-items: center;
  gap: 10px;
  font-weight: 600;
  font-size: 14px;
  margin-bottom: 18px;
}
.auth-title {
  font-size: 18px;
  font-weight: 600;
  margin: 0 0 4px;
  letter-spacing: -0.01em;
}
.auth-sub {
  font-size: 13px;
  color: var(--text-mut);
  margin: 0 0 18px;
}
.field {
  display: block;
  margin-bottom: 12px;
}
.field-label {
  display: block;
  font-size: 12px;
  color: var(--text-mut);
  margin-bottom: 5px;
  font-weight: 500;
}
.field .input {
  width: 100%;
  height: 34px;
}
.auth-foot {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-top: 16px;
  gap: 10px;
}
.auth-help {
  font-size: 11.5px;
  color: var(--text-dim);
  margin-top: 14px;
  text-align: center;
}
.auth-error {
  font-size: 12px;
  color: var(--st-failed-fg);
  background: var(--st-failed-bg);
  border: 1px solid var(--st-failed-bd);
  padding: 6px 9px;
  border-radius: var(--r);
  margin-bottom: 12px;
}

.checkbox {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  font-size: 12.5px;
  color: var(--text-mut);
  cursor: pointer;
  user-select: none;
}
.checkbox input { margin: 0; }

/* ---------- email body viewer ---------- */
.email-body-frame {
  width: 100%;
  height: 480px;
  border: 1px solid var(--border);
  border-radius: var(--r);
  background: #fff;
  display: block;
}
.email-body-plain {
  background: var(--surface);
  padding: 12px 14px;
  border-radius: var(--r);
  border: 1px solid var(--border);
  white-space: pre-wrap;
  word-break: break-word;
  max-height: 480px;
  overflow: auto;
  font-size: .82rem;
  line-height: 1.55;
  font-family: var(--font-mono, ui-monospace, monospace);
}

/* Failure reason — detail panel */
.panel.panel-error {
  border-color: var(--st-failed-bd, #f0c7c1);
  background: var(--st-failed-bg);
}
.panel.panel-error .panel-head {
  color: var(--st-failed-fg);
  background: transparent;
}
.failure-reason {
  color: var(--st-failed-fg);
  font-size: .92rem;
  line-height: 1.5;
  margin: 0 0 8px;
  white-space: pre-wrap;
  word-break: break-word;
}
.failure-hint {
  color: var(--text-mut);
  font-size: .82rem;
  margin: 0;
}
.failure-hint code {
  background: rgba(0, 0, 0, .06);
  padding: 1px 5px;
  border-radius: 4px;
  font-size: .9em;
}

/* Failure reason — row hint in incoming_emails list */
.row-failure {
  color: var(--st-failed-fg);
  font-size: 11.5px;
  font-weight: 400;
  margin-top: 2px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  max-width: 100%;
}
