/* Emvia Billing Pilot — UI styles
 * Brand: orange "e" + gray "mvia" wordmark from emvia.cx
 * Primary accent: #EE9C30 (warm orange)
 * Neutrals: cool gray scale, white content cards
 */
:root {
  --brand-orange: #A85500;
  --brand-orange-hover: #8F4E00;
  --brand-orange-tint: #FEF5E7;
  --brand-orange-soft: #FCEBD0;
  --brand-gray: #A6A8AB;

  --fg: #1D2939;
  --fg-soft: #344054;
  --muted: #667085;
  --muted-soft: #98A2B3;
  --border: #E4E7EC;
  --border-soft: #F2F4F7;
  --bg: #F9FAFB;
  --bg-elev: #FFFFFF;
  --sidebar-bg: #FFFFFF;

  --danger: #B42318;
  --danger-bg: #FEF3F2;
  --warning: #B54708;
  --warning-bg: #FFFAEB;
  --success: #027A48;
  --success-bg: #ECFDF3;
  --info: #175CD3;
  --info-bg: #EFF8FF;

  --radius-sm: 6px;
  --radius: 10px;
  --radius-lg: 14px;
  --shadow-sm: 0 1px 2px rgba(16,24,40,0.05);
  --shadow: 0 4px 12px rgba(16,24,40,0.08);
  --shadow-lg: 0 20px 40px rgba(16,24,40,0.12);

  --sidebar-w: 244px;
}

* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; }

/* Restore [hidden] attribute behavior — the UA stylesheet ([hidden]{display:none})
 * has the same specificity as our class rules, and class rules later in the
 * cascade (.state-loading {display:flex} etc) win. That meant <div hidden> was
 * NOT actually hidden when the element also had a class with explicit display.
 * With !important here, JS can reliably toggle .hidden to show/hide. */
[hidden] { display: none !important; }
body {
  font-family: 'Nunito', -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  font-size: 14px;
  line-height: 1.5;
  color: var(--fg);
  background: var(--bg);
  -webkit-font-smoothing: antialiased;
}

/* ─── App shell ────────────────────────────────────────────────────────────── */
.app-shell {
  display: grid;
  grid-template-columns: var(--sidebar-w) 1fr;
  min-height: 100vh;
}

/* ─── Sidebar ──────────────────────────────────────────────────────────────── */
.sidebar {
  background: var(--sidebar-bg);
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  position: sticky;
  top: 0;
  height: 100vh;
}

.brand {
  padding: 22px 22px 18px;
  border-bottom: 1px solid var(--border-soft);
  font-weight: 800;
  line-height: 1;
  letter-spacing: -0.02em;
}
.brand-logo {
  display: block;
  width: auto;
  height: 36px;
  max-width: 100%;
}
.brand-sub {
  display: block;
  margin-top: 6px;
  color: var(--muted);
  font-size: 11px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.08em;
}

.nav {
  flex: 1;
  overflow-y: auto;
  padding: 16px 12px;
}
.nav-group + .nav-group { margin-top: 18px; }
.nav-group-title {
  display: block;
  padding: 0 12px 6px;
  font-size: 11px;
  font-weight: 700;
  color: var(--muted-soft);
  text-transform: uppercase;
  letter-spacing: 0.08em;
}
.nav-item {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  width: 100%;
  background: transparent;
  border: 0;
  padding: 8px 12px;
  border-radius: 8px;
  cursor: pointer;
  color: var(--fg-soft);
  font: inherit;
  font-weight: 600;
  text-align: left;
}
.nav-item:hover:not(.active) {
  background: var(--bg);
  color: var(--fg);
}
.nav-item.active {
  background: var(--brand-orange-tint);
  color: var(--brand-orange-hover);
}
.nav-item .nav-count {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 22px;
  height: 20px;
  padding: 0 7px;
  border-radius: 999px;
  background: var(--border-soft);
  color: var(--muted);
  font-size: 11px;
  font-weight: 700;
}
.nav-item.active .nav-count {
  background: var(--brand-orange);
  color: white;
}
.nav-item .nav-count.zero {
  opacity: 0;
}

.sidebar-footer {
  padding: 14px 18px;
  border-top: 1px solid var(--border-soft);
}
#user-bar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  font-size: 12px;
  color: var(--muted);
}
#user-bar .user-email {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  flex: 1;
  font-weight: 600;
  color: var(--fg-soft);
}
.signout-btn {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  flex-shrink: 0;
}
.signout-icon { display: block; }

/* Top-right account menu — always-visible Sign-out fallback for viewports
 * where the sidebar footer collapses. Native <dialog> modals render in the
 * browser top-layer, so z-index here only competes with normal flow. */
.account-menu { position: relative; }
.account-menu-panel {
  position: absolute;
  right: 0;
  top: calc(100% + 6px);
  min-width: 220px;
  background: var(--bg-elev);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 8px;
  z-index: 100;
}
.account-menu-email {
  padding: 8px 10px;
  font-size: 12px;
  color: var(--muted);
  border-bottom: 1px solid var(--border-soft);
  margin-bottom: 4px;
  word-break: break-all;
}
.account-menu-item {
  display: block;
  width: 100%;
  padding: 8px 10px;
  border-radius: var(--radius-sm);
  background: transparent;
  border: 0;
  font: inherit;
  text-align: left;
  cursor: pointer;
  color: var(--fg);
}
.account-menu-item:hover { background: var(--bg); }

/* Bulk-actions bar — orange-tinted prompt at the top of the table when
 * Pending Review has eligible rows. Shows count + Approve-all action. */
.bulk-actions {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin: 0 0 14px;
  padding: 12px 16px;
  background: var(--brand-orange-tint);
  border: 1px solid var(--brand-orange);
  border-radius: var(--radius);
}
.bulk-actions-summary {
  font-size: 13px;
  color: var(--fg-soft);
  font-weight: 600;
}
.bulk-actions .btn-primary[disabled] {
  opacity: 0.6;
  cursor: not-allowed;
}

.muted-small {
  margin: 8px 0 0;
  font-size: 12px;
  color: var(--muted);
  line-height: 1.5;
}
.muted-small code {
  font-size: 11px;
  background: var(--border-soft);
  padding: 1px 5px;
  border-radius: 4px;
}

/* ─── Main column ──────────────────────────────────────────────────────────── */
.main-col {
  display: flex;
  flex-direction: column;
  min-width: 0;
}

.topbar {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  padding: 22px 28px 18px;
  background: var(--bg);
  border-bottom: 1px solid var(--border);
  position: sticky;
  top: 0;
  z-index: 5;
}
.topbar h1 {
  margin: 0;
  font-size: 22px;
  font-weight: 700;
  color: var(--fg);
  letter-spacing: -0.01em;
}
.page-sub {
  margin: 4px 0 0;
  font-size: 13px;
  color: var(--muted);
}
.topbar-actions { display: flex; gap: 8px; align-items: center; }
.topbar-meta {
  font-size: 12px;
  color: var(--muted);
  margin-right: 8px;
  font-variant-numeric: tabular-nums;
}

.content {
  flex: 1;
  padding: 22px 28px 40px;
}

/* ─── Buttons ──────────────────────────────────────────────────────────────── */
.btn {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  font: inherit;
  font-weight: 600;
  padding: 8px 14px;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border);
  background: var(--bg-elev);
  color: var(--fg-soft);
  cursor: pointer;
  transition: background-color 0.12s, border-color 0.12s, color 0.12s, box-shadow 0.12s;
}
.btn:hover { background: var(--bg); }
.btn:active { transform: translateY(1px); }
.btn:disabled { opacity: 0.5; cursor: not-allowed; }

.btn-primary {
  background: var(--brand-orange);
  color: white;
  border-color: var(--brand-orange);
}
.btn-primary:hover {
  background: var(--brand-orange-hover);
  border-color: var(--brand-orange-hover);
}
.btn-primary:disabled { background: var(--brand-orange); border-color: var(--brand-orange); }

.btn-warning {
  background: var(--warning-bg);
  color: var(--warning);
  border-color: #F4B95F;
}
.btn-warning:hover { background: #FCE7BA; }

.btn-ghost {
  background: transparent;
  border-color: transparent;
  color: var(--muted);
}
.btn-ghost:hover { background: var(--bg-elev); color: var(--fg-soft); }

.btn-sm {
  padding: 6px 10px;
  font-size: 12px;
}

.icon-btn {
  background: transparent;
  border: 0;
  padding: 6px;
  border-radius: var(--radius-sm);
  cursor: pointer;
  color: var(--muted);
  display: inline-flex;
}
.icon-btn:hover { background: var(--bg); color: var(--fg); }

/* ─── Table / card ─────────────────────────────────────────────────────────── */
.card {
  background: var(--bg-elev);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow-sm);
  overflow: hidden;
}
table {
  width: 100%;
  border-collapse: collapse;
}
thead th {
  background: #FCFCFD;
  color: var(--muted);
  font-size: 11px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  text-align: left;
  padding: 12px 16px;
  border-bottom: 1px solid var(--border);
  position: sticky;
  top: 0;
}
thead th.num { text-align: right; }
thead th.actions { text-align: right; }
tbody td {
  padding: 14px 16px;
  border-bottom: 1px solid var(--border-soft);
  color: var(--fg-soft);
  vertical-align: middle;
}
tbody td.num { text-align: right; font-variant-numeric: tabular-nums; font-weight: 600; color: var(--fg); }
tbody td.actions { text-align: right; }
tbody tr:last-child td { border-bottom: 0; }
tbody tr.row-clickable { cursor: pointer; transition: background-color 0.08s; }
tbody tr.row-clickable:hover { background: var(--brand-orange-tint); }
tbody td.customer { font-weight: 700; color: var(--fg); }
tbody td.muted-cell { color: var(--muted); }

/* ─── Badges ───────────────────────────────────────────────────────────────── */
.badge {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  padding: 3px 10px;
  border-radius: 999px;
  font-size: 11px;
  font-weight: 700;
  letter-spacing: 0.01em;
  text-transform: capitalize;
  white-space: nowrap;
}
.badge::before {
  content: '';
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: currentColor;
}
.badge.pending_review                { background: var(--info-bg);    color: var(--info); }
.badge.pending_review_low_confidence { background: var(--warning-bg); color: var(--warning); }
.badge.possible_match_hold           { background: var(--warning-bg); color: var(--warning); }
.badge.customer_unknown              { background: var(--danger-bg);  color: var(--danger); }
.badge.held_by_ops                   { background: #F4F4F5;           color: #475467; }
.badge.approval_dispatched           { background: var(--info-bg);    color: var(--info); }
.badge.submitted_pending_attachment  { background: var(--info-bg);    color: var(--info); }
.badge.submitted                     { background: var(--success-bg); color: var(--success); }
.badge.already_in_bill               { background: var(--success-bg); color: var(--success); }
.badge.rolled_up_child               { background: #F4F4F5;           color: #475467; }
.badge.exception                     { background: var(--danger-bg);  color: var(--danger); }

/* ─── Alerts / states ──────────────────────────────────────────────────────── */
.alert {
  padding: 12px 16px;
  border-radius: var(--radius);
  border: 1px solid;
  font-weight: 500;
  margin-bottom: 16px;
}
.alert-danger {
  background: var(--danger-bg);
  border-color: #FECDCA;
  color: var(--danger);
}
.alert-success {
  background: var(--success-bg);
  border-color: #A6F4C5;
  color: var(--success);
}

.state-loading {
  display: flex;
  align-items: center;
  gap: 10px;
  color: var(--muted);
  padding: 22px 4px;
}
.spinner {
  width: 18px; height: 18px;
  border: 2px solid var(--border);
  border-top-color: var(--brand-orange);
  border-radius: 50%;
  animation: spin 0.7s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

.empty-state {
  text-align: center;
  padding: 64px 20px;
  color: var(--muted);
}
.empty-state .empty-icon {
  width: 64px; height: 64px;
  background: var(--brand-orange-tint);
  color: var(--brand-orange);
  border-radius: 50%;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  margin-bottom: 12px;
}
.empty-state h2 {
  margin: 0 0 4px;
  font-size: 16px;
  font-weight: 700;
  color: var(--fg);
}
.empty-state p { margin: 0; }

/* G6 R2: Needs Catalog Entry resolve modal */
.resolve-summary {
  display: grid;
  grid-template-columns: max-content 1fr;
  column-gap: 16px;
  row-gap: 6px;
  margin-bottom: 16px;
  padding: 12px 14px;
  background: var(--bg);
  border-radius: 8px;
  border: 1px solid var(--border);
}
.resolve-summary-row { display: contents; }
.resolve-summary-label { font-size: 12px; color: var(--muted); font-weight: 600; align-self: center; }
.resolve-summary-value { font-size: 14px; color: var(--fg); align-self: center; }
.resolve-section {
  margin-bottom: 16px;
  padding-bottom: 16px;
  border-bottom: 1px solid var(--border-soft);
}
.resolve-section:last-child {
  border-bottom: none;
  padding-bottom: 0;
}
.resolve-section-title {
  margin: 0 0 8px;
  font-size: 12px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--muted);
}
.resolve-context-list {
  list-style: none;
  margin: 0;
  padding: 0;
  font-family: ui-monospace, "SF Mono", Consolas, monospace;
  font-size: 13px;
}
.resolve-context-list li {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  padding: 4px 8px;
  border-radius: 4px;
}
.resolve-context-list li.matched { color: var(--muted); }
.resolve-context-list li.unmapped {
  background: var(--brand-orange-tint);
  color: var(--fg);
  font-weight: 600;
}
.resolve-context-list li.current {
  background: var(--brand-orange);
  color: white;
  font-weight: 700;
}
.resolve-current {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 16px;
}
.resolve-current-header {
  display: flex;
  align-items: baseline;
  gap: 12px;
  margin-bottom: 12px;
  padding-bottom: 12px;
  border-bottom: 1px dashed var(--border-soft);
}
.resolve-line-counter {
  font-size: 12px;
  color: var(--muted);
  font-weight: 600;
}
.resolve-line-text {
  font-size: 15px;
  font-weight: 700;
  color: var(--fg);
  flex: 1;
}
.resolve-line-amount {
  font-size: 15px;
  font-weight: 700;
  color: var(--fg);
  font-variant-numeric: tabular-nums;
}
.resolve-banner {
  margin-bottom: 12px;
  padding: 10px 12px;
  background: var(--brand-orange-tint);
  border-left: 3px solid var(--brand-orange);
  border-radius: 4px;
  font-size: 13px;
  color: var(--fg);
}
.resolve-field {
  display: block;
  margin-bottom: 12px;
}
.resolve-field > span,
.resolve-field > legend {
  display: block;
  margin-bottom: 4px;
  font-size: 12px;
  font-weight: 600;
  color: var(--fg-soft);
}
.resolve-field input[type="text"],
.resolve-field select {
  width: 100%;
  padding: 8px 10px;
  font: inherit;
  background: white;
  border: 1px solid var(--border);
  border-radius: 6px;
}
.resolve-field input[type="text"]:focus,
.resolve-field select:focus {
  outline: 2px solid var(--brand-orange);
  outline-offset: -1px;
}
.resolve-radio {
  display: flex;
  gap: 8px;
  padding: 8px 10px;
  margin-bottom: 4px;
  border-radius: 6px;
  cursor: pointer;
  font-size: 13px;
  line-height: 1.4;
}
.resolve-radio:hover { background: var(--bg); }
.resolve-radio input[type="radio"] {
  margin: 2px 0 0;
  accent-color: var(--brand-orange);
}
.resolve-advanced {
  margin: 8px 0 12px;
  padding: 8px 0;
  font-size: 13px;
}
.resolve-advanced summary {
  cursor: pointer;
  color: var(--muted);
  font-weight: 600;
  padding: 4px 0;
}
.resolve-advanced > .resolve-field { margin-top: 8px; }

/* Placeholder card for tabs whose real screen ships at a later G6 R-gate. */
.placeholder-view {
  text-align: center;
  padding: 64px 20px;
  color: var(--muted);
}
.placeholder-view .placeholder-icon {
  width: 64px; height: 64px;
  background: var(--brand-orange-tint);
  color: var(--brand-orange);
  border-radius: 50%;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  margin-bottom: 12px;
}
.placeholder-view h2 {
  margin: 0 0 8px;
  font-size: 16px;
  font-weight: 700;
  color: var(--fg);
}
.placeholder-view p {
  margin: 0 auto;
  max-width: 56ch;
  line-height: 1.5;
}

/* G6 R3: Admin > Mappings + Admin > Fallback Rules read-only browse */
.admin-view { padding: 0; }
.admin-view-header {
  padding: 14px 18px;
  border-bottom: 1px solid var(--border);
  background: var(--bg);
  display: flex;
  align-items: center;
  justify-content: space-between;
  border-radius: var(--radius-lg) var(--radius-lg) 0 0;
}
.admin-view-summary {
  font-size: 13px;
  color: var(--fg-soft);
  font-weight: 600;
}
.admin-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 13px;
}
.admin-table thead th {
  text-align: left;
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--muted);
  font-weight: 700;
  padding: 12px 16px;
  border-bottom: 1px solid var(--border);
  background: var(--bg-card);
  position: sticky;
  top: 0;
}
.admin-table tbody td {
  padding: 10px 16px;
  border-bottom: 1px solid var(--border-soft);
  vertical-align: top;
}
.admin-table tbody tr:hover { background: var(--bg); }

.mapping-detail-fields {
  display: grid;
  grid-template-columns: max-content 1fr;
  column-gap: 16px;
  row-gap: 6px;
  margin: 0;
  font-size: 13px;
}
.mapping-detail-fields dt {
  color: var(--muted);
  font-weight: 600;
  align-self: center;
}
.mapping-detail-fields dd {
  margin: 0;
  color: var(--fg);
  font-family: ui-monospace, "SF Mono", Consolas, monospace;
  font-size: 12px;
  word-break: break-all;
  align-self: center;
}

/* ─── Modal dialogs ────────────────────────────────────────────────────────── */
dialog.modal {
  border: 0;
  border-radius: var(--radius-lg);
  padding: 0;
  max-width: 560px;
  width: 92vw;
  box-shadow: var(--shadow-lg);
  background: var(--bg-elev);
  color: var(--fg);
}
dialog.modal::backdrop { background: rgba(16,24,40,0.4); backdrop-filter: blur(2px); }
dialog.modal.modal-wide { max-width: 720px; }
dialog.modal form { margin: 0; }

.modal-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 18px 22px;
  border-bottom: 1px solid var(--border-soft);
}
.modal-header h2 {
  margin: 0;
  font-size: 17px;
  font-weight: 700;
  color: var(--fg);
}
.modal-body { padding: 20px 22px; }
.modal-footer {
  display: flex;
  gap: 8px;
  justify-content: flex-end;
  padding: 14px 22px 18px;
  border-top: 1px solid var(--border-soft);
}

.field {
  display: flex;
  flex-direction: column;
  gap: 6px;
}
.field > span {
  font-size: 12px;
  font-weight: 600;
  color: var(--fg-soft);
}
.field input[type=text] {
  font: inherit;
  padding: 10px 12px;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border);
  background: var(--bg-elev);
}
.field input[type=text]:focus {
  outline: 2px solid var(--brand-orange);
  outline-offset: -1px;
  border-color: transparent;
}

/* Detail dialog content */
#invoice-detail dl {
  display: grid;
  grid-template-columns: 140px 1fr;
  gap: 10px 18px;
  margin: 0;
}
#invoice-detail dt {
  color: var(--muted);
  font-size: 12px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  padding-top: 2px;
}
#invoice-detail dd {
  margin: 0;
  font-weight: 500;
  color: var(--fg);
}
#invoice-detail a {
  color: var(--brand-orange-hover);
  font-weight: 600;
  text-decoration: none;
}
#invoice-detail a:hover { text-decoration: underline; }
#invoice-detail h3.detail-customer {
  margin: 0 0 6px;
  font-size: 18px;
  font-weight: 700;
  color: var(--fg);
}
#invoice-detail .detail-amount {
  font-size: 22px;
  font-weight: 800;
  color: var(--fg);
}

/* ─── Detail dialog: dual amounts (new charges vs statement total) ─────────── */
.detail-amount {
  font-size: 22px;
  font-weight: 700;
  color: var(--fg);
  display: flex;
  align-items: baseline;
  gap: 10px;
}
.detail-amount-secondary {
  font-size: 14px;
  font-weight: 600;
  color: var(--muted);
  display: flex;
  align-items: baseline;
  gap: 10px;
  margin-top: 2px;
}
.amount-tag {
  font-size: 10px;
  font-weight: 700;
  color: var(--brand-orange-hover);
  background: var(--brand-orange-tint);
  padding: 2px 8px;
  border-radius: 999px;
  text-transform: uppercase;
  letter-spacing: 0.04em;
}
.amount-tag-muted {
  font-size: 10px;
  font-weight: 600;
  color: var(--muted);
  background: var(--bg);
  padding: 2px 8px;
  border-radius: 999px;
  text-transform: uppercase;
  letter-spacing: 0.04em;
}

/* ─── Discrepancy comparison panel (detail dialog) ─────────────────────────── */
.comparison-slot { margin-top: 18px; }
.comparison-loading {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 14px 0;
  color: var(--muted);
  font-size: 13px;
}
.comparison-error {
  margin-top: 16px;
  padding: 10px 12px;
  background: var(--danger-bg);
  border: 1px solid #FECDCA;
  border-radius: var(--radius-sm);
  color: var(--danger);
  font-size: 13px;
}

.comparison-panel {
  margin-top: 14px;
  padding: 16px;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: var(--radius);
}
.comparison-title {
  margin: 0 0 10px;
  font-size: 13px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: var(--muted);
}
.comparison-title a { color: var(--brand-orange-hover); text-decoration: none; }
.comparison-title a:hover { text-decoration: underline; }

.comparison-table {
  width: 100%;
  border-collapse: collapse;
  background: var(--bg-elev);
  border-radius: var(--radius-sm);
  overflow: hidden;
}
.comparison-table th,
.comparison-table td {
  padding: 8px 12px;
  font-size: 13px;
  text-align: left;
  border-bottom: 1px solid var(--border-soft);
  vertical-align: top;
}
.comparison-table thead th {
  background: #FCFCFD;
  color: var(--muted);
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  font-weight: 700;
}
.comparison-table th:first-child,
.comparison-table td:first-child {
  font-weight: 600;
  color: var(--fg-soft);
  width: 32%;
}
.comparison-table tbody tr:last-child td { border-bottom: 0; }
.cmp-row-mismatch { background: var(--warning-bg); }
.cmp-row-mismatch td { color: var(--warning); }
.cmp-marker { width: 36px; text-align: center; font-size: 14px; font-weight: 700; }
.cmp-match-yes { color: var(--success); }
.cmp-match-no  { color: var(--danger); }
.cmp-match-na  { color: var(--muted-soft); }
.cmp-empty { color: var(--muted-soft); }
.cmp-delta {
  display: inline-block;
  margin-left: 6px;
  padding: 1px 8px;
  border-radius: 999px;
  background: rgba(180, 35, 24, 0.1);
  color: var(--danger);
  font-size: 11px;
  font-weight: 700;
  font-variant-numeric: tabular-nums;
}
.comparison-actions {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
  margin-top: 14px;
  padding-top: 14px;
  border-top: 1px solid var(--border);
}
.cmp-clean {
  margin: 14px 0 0;
  padding: 10px 12px;
  background: var(--success-bg);
  color: var(--success);
  border-radius: var(--radius-sm);
  font-size: 13px;
  font-weight: 600;
}
.cmp-hint {
  margin: 0;
  padding: 8px 12px;
  font-size: 12px;
  color: var(--muted);
}
.cmp-hint code { background: var(--border-soft); padding: 0 4px; border-radius: 3px; }

/* ─── Auth screen (forgot-password) ────────────────────────────────────────── */
.auth-screen {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 40px 20px;
  background: var(--bg);
}
.auth-card {
  position: relative;
  width: 100%;
  max-width: 440px;
  background: var(--bg-elev);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow);
  padding: 36px 32px 28px;
}
.auth-back-link {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  width: 100%;
  margin-top: 18px;
  padding: 10px 12px;
  font-size: 14px;
  font-weight: 700;
  color: var(--brand-orange);
  text-decoration: none;
  border-radius: var(--radius-sm);
  border-top: 1px solid var(--border-soft);
  padding-top: 18px;
}
.auth-back-link:hover {
  color: var(--brand-orange-hover);
  background: var(--brand-orange-tint);
}
.auth-logo {
  display: block;
  height: 44px;
  width: auto;
  margin: 12px auto 18px;
}
.auth-title {
  margin: 0 0 8px;
  font-size: 24px;
  font-weight: 800;
  color: var(--fg);
  text-align: center;
}
.auth-sub {
  margin: 0 0 22px;
  font-size: 14px;
  color: var(--muted);
  text-align: center;
}
.auth-form { display: flex; flex-direction: column; gap: 16px; }
.auth-field { display: flex; flex-direction: column; gap: 6px; }
.auth-field > span {
  font-size: 13px;
  font-weight: 600;
  color: var(--fg-soft);
}
.auth-field input {
  height: 44px;
  padding: 0 14px;
  font: inherit;
  color: var(--fg);
  background: var(--bg-elev);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  outline: none;
}
.auth-field input:focus {
  border-color: var(--brand-orange);
  box-shadow: 0 0 0 3px var(--brand-orange-soft);
}
.auth-submit { width: 100%; height: 44px; margin-top: 4px; }
.auth-secondary { width: 100%; }
.auth-error {
  margin: 0;
  padding: 10px 12px;
  border-radius: var(--radius-sm);
  background: var(--danger-bg);
  border: 1px solid var(--danger);
  color: var(--danger);
  font-size: 13px;
  font-weight: 600;
}
.auth-success { text-align: center; padding: 4px 0 12px; }
.auth-success-icon {
  width: 64px;
  height: 64px;
  margin: 4px auto 14px;
  border-radius: 50%;
  background: var(--success-bg);
  color: var(--success);
  display: inline-flex;
  align-items: center;
  justify-content: center;
}
.auth-success h2 { margin: 0 0 8px; font-size: 20px; font-weight: 800; color: var(--fg); }
.auth-success p  { margin: 0 0 22px; color: var(--muted); font-size: 14px; }

/* ─── Responsive: collapse sidebar on narrow viewports ─────────────────────── */
@media (max-width: 880px) {
  :root { --sidebar-w: 64px; }
  .brand-sub, .nav-group-title,
  .nav-item span.nav-label, #user-bar .user-email { display: none; }
  .nav-item { justify-content: center; padding: 10px; }
  .brand { padding: 18px 0; text-align: center; overflow: hidden; }
  /* Show just the "e" of the emvia mark when the sidebar collapses. */
  .brand-logo { height: 30px; margin: 0 auto; max-width: 36px; object-fit: cover; object-position: left center; }
  .topbar, .content { padding-left: 16px; padding-right: 16px; }

  /* Sidebar-footer Sign-out: collapse to icon-only so it fits in the 64px
   * sidebar. The label hides; the SVG icon + title="Sign out" keeps it
   * clickable and accessible. Without this, the ~70px button overflowed the
   * 64px sidebar and clipped out of Stephanie's viewport (Trello #138). */
  .sidebar-footer { padding: 12px 8px; }
  #user-bar { justify-content: center; }
  .signout-label { display: none; }
  .signout-btn { padding: 6px 8px; }

  /* Topbar account button: collapse "Account" label so the icon-only button
   * fits without crowding the Refresh button. The menu panel keeps its full
   * 220px width via absolute positioning. */
  #account-btn-label { display: none; }
  .topbar-meta { font-size: 11px; margin-right: 4px; }
}

/* ─── G8 Phase 8b: Backfill Review tab ─────────────────────────────────── */

.backfill-customer-picker { padding: 16px 4px 24px; }
.backfill-customer-list {
  list-style: none; margin: 0; padding: 0;
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(280px, 1fr));
  gap: 12px;
}
.backfill-customer-card {
  background: #fff;
  border: 1px solid var(--border, #e5e7eb);
  border-radius: 8px;
  padding: 14px 16px;
  cursor: pointer; text-align: left; font: inherit; color: inherit;
  transition: border-color .12s, background-color .12s, transform .05s;
  width: 100%;
}
.backfill-customer-card:hover {
  border-color: var(--brand-orange);
  background: var(--brand-orange-tint);
}
.backfill-customer-card:active { transform: translateY(1px); }
.backfill-customer-card .name {
  display: block; font-weight: 700; font-size: 15px; margin-bottom: 6px;
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}
.backfill-customer-card .counts {
  display: flex; gap: 12px; font-size: 12px; color: var(--muted, #6b7280);
}
.backfill-customer-card .counts strong { color: #1f2937; }
.backfill-customer-card .counts .staged strong { color: #3730A3; }
.backfill-customer-card .counts .blocked strong { color: var(--warning, #b45309); }

.backfill-queue { margin-top: 8px; }
.backfill-queue .admin-table th, .backfill-queue .admin-table td { vertical-align: top; }
.backfill-queue .empty-row { text-align: center; padding: 24px; }

.backfill-itemization {
  display: flex; flex-direction: column; gap: 3px;
  font-size: 12px; line-height: 1.4;
}
.backfill-itemization .header { font-weight: 600; color: #1f2937; margin-bottom: 2px; }
.backfill-itemization .line { display: flex; justify-content: space-between; gap: 10px; }
.backfill-itemization .line .item-name { color: #374151; }
.backfill-itemization .line .item-amount { font-variant-numeric: tabular-nums; color: #1f2937; }
.backfill-itemization .more { color: var(--muted, #6b7280); font-style: italic; }
.backfill-itemization.current .header { font-style: italic; color: var(--muted, #6b7280); }

.backfill-actions { display: flex; flex-direction: column; gap: 6px; align-items: stretch; }
.backfill-actions .btn { white-space: nowrap; }

.backfill-blocked-reason {
  margin-top: 4px;
  font-size: 11px;
  color: var(--warning, #b45309);
  font-family: ui-monospace, SFMono-Regular, Consolas, monospace;
  word-break: break-word;
  display: -webkit-box;
  -webkit-line-clamp: 3;
  -webkit-box-orient: vertical;
  overflow: hidden;
}

/* Status pills for backfill_status. */
.badge.staged_for_review     { background: #E0E7FF; color: #3730A3; }
.badge.blocked_tier4         { background: var(--warning-bg, #FEF3C7); color: var(--warning, #b45309); }
.badge.blocked_sum_mismatch  { background: var(--warning-bg, #FEF3C7); color: var(--warning, #b45309); }
.badge.blocked_extract_error { background: #F3F4F6; color: #6B7280; }
.badge.blocked_no_lines      { background: #F3F4F6; color: #6B7280; }
.badge.approved_by_operator  { background: var(--success-bg, #D1FAE5); color: var(--success, #065F46); }
.badge.in_flight             { background: var(--info-bg, #DBEAFE); color: var(--info, #1E40AF); }
.badge.backfilled            { background: var(--success-bg, #D1FAE5); color: var(--success, #065F46); }
.badge.verification_failed   { background: var(--danger-bg, #FEE2E2); color: var(--danger, #B91C1C); }
.badge.abandoned             { background: #EFEFEF; color: #6B7280; }
