:root {
  --bg: #0d1117;
  --panel: #161b22;
  --panel-2: #1c2330;
  --border: #2a3340;
  --text: #e6edf3;
  --muted: #8b98a9;
  --primary: #ff2d7e;
  --primary-ink: #ffffff;
  --green: #2ea043;
  --red: #f85149;
  --amber: #d29922;
  --blue: #58a6ff;
  --teal: #39c5cf;
  --orange: #f0883e;
  --radius: 12px;
  --shadow: 0 6px 24px rgba(0, 0, 0, 0.35);
  --sidebar-bg: rgba(13, 17, 23, 0.6);
  --nav-active-bg: rgba(255, 45, 126, 0.16);
  --nav-hover-bg: rgba(255, 45, 126, 0.08);
}

/* Light theme (toggled via the sidebar; persisted in localStorage). */
:root[data-theme="light"] {
  --bg: #f6f8fa;
  --panel: #ffffff;
  --panel-2: #eef1f5;
  --border: #d6dde4;
  --text: #1f2328;
  --muted: #59636e;
  --blue: #0969da;
  --teal: #1b7c83;
  --orange: #bc4c00;
  --shadow: 0 6px 20px rgba(140, 149, 159, 0.25);
  --sidebar-bg: #ffffff;
  --nav-active-bg: rgba(255, 45, 126, 0.18);
  --nav-hover-bg: rgba(31, 35, 40, 0.06);
}
:root[data-theme="light"] .nav-item { color: #3a444e; }
:root[data-theme="light"] .brand { color: var(--text); }
:root[data-theme="light"] body {
  background: radial-gradient(1200px 600px at 70% -10%, #eaf0f8 0%, var(--bg) 55%);
}

* { box-sizing: border-box; }

/* The hidden attribute must always beat layout classes (.fullscreen/.shell set
   display:grid, which would otherwise override the UA [hidden]{display:none}
   and leave the loading overlay permanently on screen). */
[hidden] { display: none !important; }

body {
  margin: 0;
  background: radial-gradient(1200px 600px at 70% -10%, #182030 0%, var(--bg) 55%);
  color: var(--text);
  font: 15px/1.55 -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  min-height: 100vh;
}

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 14px 22px;
  border-bottom: 1px solid var(--border);
  background: rgba(13, 17, 23, 0.6);
  backdrop-filter: blur(8px);
  position: sticky;
  top: 0;
  z-index: 5;
}
.brand {
  display: flex;
  align-items: center;
  gap: 10px;
  color: var(--text);
  text-decoration: none;
  font-weight: 700;
  letter-spacing: 0.2px;
}
.user-chip { display: flex; align-items: center; gap: 12px; }
.user-email { color: var(--muted); font-size: 14px; }

.wrap { max-width: 760px; margin: 0 auto; padding: 40px 22px 80px; }

.card {
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 36px;
  box-shadow: var(--shadow);
}
.center { text-align: center; max-width: 440px; margin: 8vh auto 0; }
.center h1 { margin: 0 0 8px; font-size: 24px; }

h1 { font-size: 26px; margin: 0 0 6px; }
h2 { font-size: 19px; margin: 0 0 6px; }
.muted { color: var(--muted); margin: 0; }
.fineprint { color: var(--muted); font-size: 12.5px; margin-top: 16px; }
.error { color: var(--red); font-size: 13px; margin-top: 12px; }

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 9px;
  border: 1px solid var(--border);
  background: var(--panel-2);
  color: var(--text);
  padding: 9px 16px;
  border-radius: 9px;
  font-size: 14px;
  font-weight: 600;
  cursor: pointer;
  transition: transform 0.05s ease, background 0.15s ease, border-color 0.15s ease;
}
.btn:hover { border-color: #3a4757; }
.btn:active { transform: translateY(1px); }
.btn-ghost:hover { background: #222a36; }
.btn-primary {
  background: var(--primary);
  color: var(--primary-ink);
  border-color: transparent;
}
.btn-primary:hover { filter: brightness(1.05); }
.btn-lg { padding: 12px 22px; font-size: 15px; margin-top: 22px; }

.divider {
  display: flex;
  align-items: center;
  gap: 12px;
  margin: 20px 0 4px;
  color: var(--muted);
  font-size: 12px;
}
.divider::before,
.divider::after {
  content: "";
  flex: 1;
  height: 1px;
  background: var(--border);
}

.magic-form {
  display: flex;
  flex-direction: column;
  gap: 12px;
  margin-top: 22px;
}
.magic-form input {
  width: 100%;
  padding: 12px 14px;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 9px;
  color: var(--text);
  font-size: 15px;
  text-align: center;
}
.magic-form input:focus {
  outline: none;
  border-color: var(--primary);
}
.magic-form .btn-lg { margin-top: 0; }
.sent {
  margin-top: 22px;
  color: var(--green);
  font-size: 14px;
}

.spinner {
  width: 26px; height: 26px;
  border: 3px solid var(--border);
  border-top-color: var(--primary);
  border-radius: 50%;
  margin: 0 auto 14px;
  animation: spin 0.8s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

.page-head { margin-bottom: 18px; }

/* Connector rows */
.connectors { display: flex; flex-direction: column; gap: 12px; }
.connector {
  display: flex;
  flex-direction: column;
  gap: 12px;
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 16px 18px;
}
/* The account's primary line: icon · meta · status badge · cleaning control. */
.connector-main {
  display: flex;
  align-items: center;
  gap: 16px;
}
.connector .ic {
  width: 38px; height: 38px;
  display: grid; place-items: center;
  background: var(--panel-2);
  border-radius: 9px;
  /* Brand-tinted "integration tile": the type icon carries the accent (these
     are identity markers), while utility icons elsewhere stay neutral. */
  border: 1px solid color-mix(in srgb, var(--primary) 40%, transparent);
  flex: none;
}
.connector .ic svg { width: 20px; height: 20px; stroke: var(--primary); }

/* Inline SVG icons (buttons, chips, confirmations) — sit on the text baseline
   and inherit the surrounding color. Replaces every former emoji glyph. */
.ico {
  width: 1em; height: 1em;
  vertical-align: -0.15em;
  flex: none;
}
.connector .meta { flex: 1; min-width: 0; }
.connector .acct { font-weight: 600; }
.connector .sub { color: var(--muted); font-size: 13px; }
.connector .sub.err { color: var(--red); }

.badge {
  font-size: 12px;
  font-weight: 700;
  padding: 4px 10px;
  border-radius: 999px;
  text-transform: capitalize;
  flex: none;
}
.badge.active { background: rgba(46, 160, 67, 0.16); color: var(--green); }
.badge.error { background: rgba(248, 81, 73, 0.16); color: var(--red); }
.badge.pending { background: rgba(210, 153, 34, 0.16); color: var(--amber); }
.badge.disabled { background: #222a36; color: var(--muted); }

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

/* Add cards */
.add-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.add-card {
  text-align: left;
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 18px;
  cursor: pointer;
  color: var(--text);
  display: flex;
  flex-direction: column;
  gap: 4px;
  transition: border-color 0.15s ease, background 0.15s ease;
}
.add-card:hover { border-color: var(--primary); background: var(--panel-2); }
.add-card[disabled] {
  cursor: default;
  opacity: 0.55;
}
.add-card[disabled]:hover { border-color: var(--border); background: var(--panel); }
.soon {
  font-size: 10.5px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.4px;
  padding: 2px 7px;
  border-radius: 999px;
  background: rgba(210, 153, 34, 0.16);
  color: var(--amber);
  vertical-align: middle;
  margin-left: 6px;
}
.add-title { font-weight: 700; }
.add-sub { color: var(--muted); font-size: 13px; }
.connect-status {
  margin-top: 14px;
  font-size: 13.5px;
  padding: 10px 14px;
  border-radius: 9px;
}
.connect-status.ok { background: rgba(46, 160, 67, 0.14); color: var(--green); }
.connect-status.err { background: rgba(248, 81, 73, 0.14); color: var(--red); }

/* Dialog */
.dialog {
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--panel);
  color: var(--text);
  padding: 26px;
  width: min(440px, 92vw);
  box-shadow: var(--shadow);
}
.dialog::backdrop { background: rgba(0, 0, 0, 0.55); backdrop-filter: blur(2px); }
.dialog h2 { margin-top: 0; }
.dialog label { display: block; font-size: 13px; color: var(--muted); margin-top: 14px; }
.dialog input {
  width: 100%;
  margin-top: 5px;
  padding: 9px 11px;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 8px;
  color: var(--text);
  font-size: 14px;
}
.dialog .row { display: flex; gap: 12px; }
.dialog .grow { flex: 1; }
.dialog .port { width: 96px; }

/* Telegram connect: the numbered api-key walkthrough inside the dialog. */
.tg-howto { margin: 10px 0 0; padding-left: 20px; font-size: 13px; }
.tg-howto li { margin-top: 6px; line-height: 1.45; }
.tg-howto + .muted { font-size: 12.5px; margin-top: 10px; }
.tg-fields { margin: 6px 0; padding-left: 18px; list-style: disc; }
.tg-fields li { margin-top: 3px; }
.dialog-actions {
  display: flex;
  justify-content: flex-end;
  gap: 10px;
  margin: 22px 0 0;
  padding: 0;
}

/* Email preview modal -------------------------------------------------- */
.email-dialog {
  width: 88vw;
  max-width: 1600px;
  max-height: 90vh;
  padding: 0;
  overflow: hidden;
}
.email-form {
  display: flex;
  flex-direction: column;
  max-height: 90vh;
  overflow: hidden;
}
.email-head {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 12px;
  padding: 22px 24px 14px;
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
}
.email-head-text { min-width: 0; }
.email-head h2 {
  margin: 0;
  font-size: 17px;
  line-height: 1.3;
  word-break: break-word;
}
.email-meta { margin: 5px 0 0; font-size: 12px; }
.btn-icon { padding: 4px 9px; font-size: 15px; line-height: 1; }
.email-body {
  padding: 22px 34px;
  flex: 1;
  min-height: 0;
  overflow-y: auto;
  overscroll-behavior: contain;
}
/* Full-width text — the whole point of the wide dialog is to stop wrapping. */
.email-summary {
  margin: 0 0 16px;
  font-size: 14px;
  line-height: 1.5;
  color: var(--text);
}
.email-entities {
  display: grid;
  grid-template-columns: max-content 1fr;
  gap: 6px 16px;
  margin: 0 0 16px;
  font-size: 13px;
}
.email-entities dt { color: var(--muted); }
.email-entities dd { margin: 0; word-break: break-word; }
.email-text {
  white-space: pre-wrap;
  word-break: break-word;
  font-size: 13px;
  line-height: 1.55;
  color: var(--text);
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 12px 14px;
}
.email-actions {
  margin: 0;
  padding: 14px 24px 20px;
  border-top: 1px solid var(--border);
  flex-shrink: 0;
}

/* Hover-peek card: example emails for a rule, shown on sender hover.
   Centered + modal-sized so it reads the same as the click modal. */
.rule-peek {
  position: fixed;
  left: 50%;
  top: 50%;
  transform: translate(-50%, -50%);
  z-index: 60;
  width: min(680px, 94vw);
  max-height: 82vh;
  overflow: hidden;
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 12px;
  box-shadow: var(--shadow);
  padding: 22px 24px;
  pointer-events: none;
}
.rule-peek-head {
  font-size: 17px;
  font-weight: 600;
  word-break: break-word;
}
.rule-peek-badges {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 8px;
  margin: 9px 0 14px;
}
.rule-peek-meta { font-size: 12px; color: var(--muted); }
.rule-peek-why {
  font-size: 13px;
  line-height: 1.45;
  color: var(--muted);
  margin-bottom: 14px;
}
.rule-peek-ex {
  border-top: 1px solid var(--border);
  padding-top: 12px;
  margin-top: 12px;
}
.rule-peek-ex:first-of-type { border-top: none; padding-top: 0; margin-top: 0; }
.rule-peek-subj { font-size: 14px; font-weight: 600; }
.rule-peek-snip {
  margin-top: 4px;
  font-size: 13px;
  line-height: 1.5;
  color: var(--muted);
}
.rule-peek-date { margin-top: 5px; font-size: 11px; color: var(--muted); }

/* Clickable sender bucket in the rules table */
.sender-link {
  cursor: pointer;
  text-decoration: underline;
  text-decoration-color: var(--border);
  text-underline-offset: 2px;
}
.sender-link:hover { text-decoration-color: var(--text); }

/* Example email cards inside the rule modal */
.rule-example {
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 11px 13px;
  margin-bottom: 10px;
  background: var(--bg);
}
.rule-example-subj { font-size: 13px; font-weight: 600; color: var(--text); }
.rule-example-snip {
  margin-top: 4px;
  font-size: 12.5px;
  line-height: 1.45;
  color: var(--muted);
}
.rule-example-date { margin-top: 6px; font-size: 11px; color: var(--muted); }

/* ===================================================================== */
/* App shell: sidebar + content                                          */
/* ===================================================================== */
.fullscreen { min-height: 100vh; display: grid; place-items: center; padding: 24px; }
.fullscreen .center { margin: 0; }
.brand-lg { font-size: 20px; justify-content: center; margin-bottom: 18px; }

.shell {
  display: grid;
  grid-template-columns: 240px 1fr;
  min-height: 100vh;
}

.sidebar {
  display: flex;
  flex-direction: column;
  gap: 6px;
  padding: 18px 14px;
  border-right: 1px solid var(--border);
  background: var(--sidebar-bg);
  position: sticky;
  top: 0;
  height: 100vh;
}
.sidebar .brand { padding: 6px 8px 16px; }

.nav { display: flex; flex-direction: column; gap: 4px; }
.nav-secondary { margin-top: auto; }

.nav-item {
  display: flex;
  align-items: center;
  gap: 11px;
  padding: 9px 11px;
  border-radius: 9px;
  color: var(--muted);
  text-decoration: none;
  font-weight: 600;
  font-size: 14px;
  transition: background 0.12s ease, color 0.12s ease;
}
.nav-item:hover { background: var(--nav-hover-bg); color: var(--text); }
.nav-item.active { background: var(--nav-active-bg); color: var(--text); }
.nav-item.active .nav-ic { color: var(--primary); }
.nav-ic { width: 18px; height: 18px; flex: none; fill: currentColor; color: inherit; }

.sidebar-foot {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-top: 10px;
  padding: 10px 8px 2px;
  border-top: 1px solid var(--border);
}
.side-email {
  flex: 1;
  min-width: 0;
  font-size: 12.5px;
  color: var(--muted);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.icon-btn {
  display: inline-grid;
  place-items: center;
  width: 32px; height: 32px;
  border: 1px solid var(--border);
  background: var(--panel-2);
  color: var(--muted);
  border-radius: 8px;
  cursor: pointer;
  flex: none;
}
.icon-btn:hover { color: var(--text); border-color: #3a4757; }

.content {
  padding: 40px 40px 80px;
  width: 100%;
  min-width: 0;
}
.row-between { display: flex; align-items: flex-start; justify-content: space-between; gap: 18px; }
.row-between .btn { flex: none; }

/* Stat cards */
.stat-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(160px, 1fr)); gap: 12px; }
.stat-card {
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 16px 18px;
}
.stat-label { color: var(--muted); font-size: 12.5px; text-transform: uppercase; letter-spacing: 0.4px; }
.stat-val { font-size: 24px; font-weight: 700; margin: 4px 0 2px; }
.stat-sub { color: var(--muted); font-size: 12.5px; }

/* Recent activity */
.recent { display: flex; flex-direction: column; gap: 10px; }
.recent-item {
  display: flex;
  align-items: center;
  gap: 14px;
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 13px 16px;
}
.recent-item .meta { flex: 1; min-width: 0; }
.recent-item .acct { font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.recent-item .sub { color: var(--muted); font-size: 12.5px; }
.recent-item .when { color: var(--muted); font-size: 12.5px; flex: none; }
.badge.tag { background: var(--panel-2); color: var(--muted); }

/* Pill note (billing stub) */
.pill-note {
  display: flex;
  align-items: center;
  gap: 8px;
  color: var(--muted);
  font-size: 13px;
  margin: 14px 0 18px;
}

/* Rules: read-only reference list + shared cell helpers */
.btn-sm { padding: 5px 12px; font-size: 13px; }

.cell-sender { font-weight: 600; white-space: nowrap; max-width: 320px; overflow: hidden; text-overflow: ellipsis; }
.cell-num { white-space: nowrap; font-variant-numeric: tabular-nums; }

/* Secondary link to the read-only reference (under the wizard) */
.rules-allref-link { margin-top: 14px; text-align: center; }
.linklike {
  background: none;
  border: none;
  padding: 0;
  font: inherit;
  font-size: 13px;
  color: var(--muted);
  text-decoration: underline;
  text-underline-offset: 2px;
  cursor: pointer;
}
.linklike:hover { color: var(--primary); }

/* Read-only "All rules" state chips */
.state-chip {
  display: inline-block;
  font-size: 11px;
  font-weight: 700;
  letter-spacing: 0.3px;
  padding: 2px 9px;
  border-radius: 999px;
  white-space: nowrap;
}
.state-chip.state-proposed { background: rgba(210, 153, 34, 0.16); color: var(--amber); }
.state-chip.state-approved { background: rgba(46, 160, 67, 0.18); color: var(--green); }
.state-chip.state-declined { background: var(--panel-2); color: var(--muted); }
.state-chip.state-off { background: var(--panel-2); color: var(--muted); }

.domain-chip {
  display: inline-block;
  margin-left: 8px;
  font-size: 10.5px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.4px;
  padding: 1px 7px;
  border-radius: 999px;
  background: var(--nav-active-bg);
  color: var(--primary);
  vertical-align: middle;
}

/* sender_class badge variants — translucent fill + theme-aware text color so
   both light and dark themes stay readable. */
.badge.class-spam { background: rgba(248, 81, 73, 0.15); color: var(--red); }
.badge.class-marketing { background: rgba(240, 136, 62, 0.15); color: var(--orange); }
.badge.class-newsletter { background: rgba(88, 166, 255, 0.15); color: var(--blue); }
.badge.class-notification { background: var(--panel-2); color: var(--muted); }
.badge.class-transactional { background: rgba(57, 197, 207, 0.15); color: var(--teal); }
.badge.class-human { background: rgba(46, 160, 67, 0.15); color: var(--green); }
.badge.class-other { background: var(--panel-2); color: var(--muted); }
.badge.action {
  background: var(--panel-2);
  color: var(--text);
  border: 1px solid var(--border);
}


/* ===================================================================== */
/* Cleaning wizard: staged proposal approval                             */
/* ===================================================================== */
.wizard { margin-top: 22px; }

/* Rule-type tabs (Archive · Notify · …) — the "bullets" by action type. */
.rule-tabs {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
  margin-bottom: 20px;
  border-bottom: 1px solid var(--border);
  padding-bottom: 0;
}
.rule-tab {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  background: none;
  border: none;
  border-bottom: 2px solid transparent;
  color: var(--muted);
  padding: 8px 4px 10px;
  margin-bottom: -1px;
  font: inherit;
  font-size: 14px;
  font-weight: 600;
  cursor: pointer;
}
.rule-tab[data-tab]:hover { color: var(--text); }
.rule-tab.current {
  color: var(--text);
  border-bottom-color: var(--primary);
}
.rule-tab.soon { cursor: default; opacity: 0.6; }
.rule-tab-count {
  font-size: 11px;
  font-weight: 700;
  padding: 1px 7px;
  border-radius: 999px;
  background: var(--panel-2);
  color: var(--muted);
}
.rule-tab.current .rule-tab-count { background: var(--primary); color: var(--primary-ink); }
.rule-tab-soon {
  font-size: 10px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  padding: 1px 6px;
  border-radius: 999px;
  background: var(--panel-2);
  color: var(--muted);
}

/* Tab pane: header + toolbar + list + apply bar. */
.rule-pane { animation: none; }
.rule-pane-soon { padding: 8px 2px; }
.rule-toolbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  flex-wrap: wrap;
  margin-bottom: 12px;
}
.rule-counts { font-size: 13px; }
.rule-apply-bar {
  display: flex;
  flex-direction: column;
  gap: 12px;
  margin-top: 18px;
  padding-top: 16px;
  border-top: 1px solid var(--border);
}
.rule-apply-btns { display: flex; align-items: center; gap: 10px; }

/* In-modal category picker: pick a terminal bubble to reclassify/move the rule.
   The current category is filled + non-clickable; the others are outlined. */
.rule-cat-picker {
  margin-bottom: 16px;
  padding-bottom: 14px;
  border-bottom: 1px solid var(--border);
}
.rule-cat-label { font-size: 12.5px; margin-bottom: 8px; }
.rule-cat-bubbles { display: flex; gap: 8px; flex-wrap: wrap; }
.rule-cat-bubble {
  border: 1px solid var(--border);
  background: var(--panel);
  color: var(--muted);
  border-radius: 999px;
  padding: 6px 14px;
  font: inherit;
  font-size: 13px;
  font-weight: 600;
  cursor: pointer;
}
.rule-cat-bubble:not(.current):hover {
  border-color: var(--primary);
  color: var(--text);
}
.rule-cat-bubble.current {
  background: var(--primary);
  color: var(--primary-ink);
  border-color: var(--primary);
  cursor: default;
}
.rule-empty { padding: 8px 2px; }
.rule-empty .wizard-actions { margin-top: 12px; }

/* Master "select all" row — same checkbox column as the rules, set apart with a
   lighter background + a label instead of a sender. */
.rule-selectall {
  background: var(--panel-2);
  cursor: pointer;
}
.rule-selectall-label {
  font-weight: 600;
  color: var(--text);
}

/* Preview tabs (Notify / Act): classified but the actuator isn't built. An
   honest note above a read-only (no-checkbox) list. */
.rule-preview-note {
  font-size: 13.5px;
  color: var(--muted);
  background: var(--panel-2);
  border: 1px dashed var(--border);
  border-radius: 8px;
  padding: 10px 12px;
  margin: 0 0 14px;
}
.wizard-row-readonly { cursor: default; }

/* The row whose sender opened the modal — a clear accent so you know which item
   the modal is about. Works for wizard rows and the all-rules table. */
.wizard-row.row-active {
  background: var(--nav-active-bg);
  box-shadow: inset 3px 0 0 var(--primary);
}
tr.row-active { background: var(--nav-active-bg); }
tr.row-active td:first-child { box-shadow: inset 3px 0 0 var(--primary); }

/* Stage body */
.wizard-step {
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 24px 24px 20px;
}
.wizard-head { margin-bottom: 18px; }
.wizard-head h2 { margin: 0 0 8px; }
.wizard-headline {
  font-size: 20px;
  font-weight: 700;
  color: var(--text);
  margin-bottom: 6px;
}
.wizard-head .muted { font-size: 13.5px; max-width: 60ch; }

/* Per-page selected/unselected filter chips (above the list). Reuses the
   pill/badge idiom: an "on" chip is filled, an "off" chip is muted/outlined. */
.wizard-filter {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-bottom: 14px;
  flex-wrap: wrap;
}
.wizard-chip {
  display: inline-flex;
  align-items: center;
  gap: 7px;
  padding: 5px 12px;
  border-radius: 999px;
  border: 1px solid var(--border);
  background: transparent;
  color: var(--muted);
  font-size: 13px;
  font-weight: 600;
  cursor: pointer;
  transition: background 120ms ease, color 120ms ease, border-color 120ms ease;
}
.wizard-chip:hover { border-color: var(--primary); }
.wizard-chip .wizard-chip-count {
  font-size: 11px;
  font-weight: 700;
  padding: 1px 7px;
  border-radius: 999px;
  background: var(--panel-2);
  color: var(--muted);
}
.wizard-chip.on {
  background: var(--nav-active-bg);
  border-color: var(--primary);
  color: var(--text);
}
.wizard-chip.on .wizard-chip-count {
  background: var(--primary);
  color: var(--primary-ink);
}
.wizard-filter-note {
  font-size: 13px;
  padding: 8px 2px;
  margin: 0;
}

/* Sections down the single Review page: Safe to sweep / Worth filing / Needs
   your judgment. A light header groups each, with the section's sender count. */
.wizard-sections { display: flex; flex-direction: column; gap: 22px; }
.wizard-section-head {
  display: flex;
  align-items: center;
  gap: 9px;
  margin-bottom: 2px;
}
.wizard-section-title {
  font-size: 15px;
  font-weight: 700;
  color: var(--text);
}
.wizard-section-count {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 22px;
  height: 20px;
  padding: 0 7px;
  border-radius: 999px;
  background: var(--border);
  color: var(--muted);
  font-size: 12px;
  font-weight: 700;
}
.wizard-section-blurb { font-size: 13px; margin: 0 0 10px; }

/* Compact selectable rows (Clean / Organize) */
.wizard-list { display: flex; flex-direction: column; gap: 8px; }
/* Single-row fade + collapse when a toggle pushes it out of the active filter.
   Animates opacity + box model to nothing over ~150ms, then JS removes it. */
.wizard-row {
  transition: opacity 150ms ease, height 150ms ease, margin 150ms ease,
    padding 150ms ease, border-width 150ms ease;
}
.wizard-row-leaving {
  opacity: 0;
  height: 0 !important;
  min-height: 0;
  padding-top: 0;
  padding-bottom: 0;
  margin-top: 0;
  margin-bottom: 0;
  border-width: 0;
  overflow: hidden;
  pointer-events: none;
}
.wizard-row {
  display: flex;
  align-items: center;
  gap: 12px;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 9px;
  padding: 10px 14px;
  cursor: pointer;
}
.wizard-row:hover { border-color: #3a4757; }
.wizard-check {
  width: 16px; height: 16px;
  margin: 0;
  accent-color: var(--primary);
  cursor: pointer;
  flex: none;
}
.wizard-sender {
  font-weight: 600;
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  flex: 1;
}
.wizard-badges { display: inline-flex; gap: 6px; flex: none; }
.wizard-vol, .wizard-unread {
  color: var(--muted);
  font-size: 13px;
  flex: none;
  text-align: right;
}
.wizard-vol { min-width: 92px; }
.wizard-unread { min-width: 92px; }
.wizard-source { flex: none; }

/* Stage action bar (Done / empty states) */
.wizard-actions {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-top: 20px;
  flex-wrap: wrap;
}

/* Back / Next bar (checklist + apply pages): Next on the right, Back ghost */
.wizard-nav {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-top: 22px;
}
.wizard-nav [data-wiz="next"],
.wizard-nav [data-wiz="apply-all"] {
  margin-left: auto;
}
.wizard-nav .btn[hidden] { display: none; }

/* Review & apply: two stacked labeled lists */
.wizard-applylist { margin-top: 18px; }
.wizard-applylist + .wizard-applylist { margin-top: 22px; }
.wizard-applylist-head {
  font-size: 13px;
  font-weight: 700;
  letter-spacing: 0.02em;
  text-transform: uppercase;
  color: var(--muted);
  padding-bottom: 8px;
  margin-bottom: 10px;
  border-bottom: 1px solid var(--border);
}
.wizard-applylist-cleaned .wizard-applylist-head { color: var(--green); }
.wizard-applylist-empty {
  font-size: 13px;
  padding: 6px 2px 2px;
  margin: 0;
}

/* Done summary */
.wizard-done { text-align: center; padding: 40px 28px 32px; }
.wizard-done-icon {
  width: 52px; height: 52px;
  margin: 0 auto 14px;
  display: grid;
  place-items: center;
  border-radius: 999px;
  background: rgba(46, 160, 67, 0.18);
  color: var(--green);
  font-size: 26px;
  font-weight: 700;
}
.wizard-done h2 { margin: 0 0 10px; }
.wizard-done-summary {
  max-width: 56ch;
  margin: 0 auto 8px;
  color: var(--text);
  line-height: 1.55;
}
.wizard-done .muted { max-width: 56ch; margin: 0 auto; font-size: 13px; }
.wizard-done .wizard-actions { justify-content: center; margin-top: 22px; }

/* Cleaning CTA on the wizard Done step (a link to Integrations). */
.wizard-done-cta { margin: 22px auto 6px; }
/* Check all / Uncheck all, right-aligned in the filter bar. */
.wizard-bulk { margin-left: auto; display: flex; gap: 6px; }

@media (max-width: 560px) {
  .wizard-row { flex-wrap: wrap; }
  .wizard-vol, .wizard-unread { min-width: 0; }
}

/* Settings */
.settings-form { display: flex; flex-direction: column; gap: 16px; max-width: 620px; }
.setting-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 18px;
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 16px 18px;
}
.setting-title { font-weight: 600; }
.setting-sub { color: var(--muted); font-size: 13px; margin-top: 2px; }
select {
  background: var(--bg);
  border: 1px solid var(--border);
  color: var(--text);
  border-radius: 8px;
  padding: 9px 11px;
  font-size: 14px;
  flex: none;
}
select:focus { outline: none; border-color: var(--primary); }
.form-actions { display: flex; align-items: center; gap: 12px; }
.save-status { font-size: 13px; }
.save-status.ok { color: var(--green); }
.save-status.err { color: var(--red); }

@media (max-width: 760px) {
  .shell { grid-template-columns: 1fr; }
  .sidebar {
    flex-direction: row;
    flex-wrap: wrap;
    align-items: center;
    height: auto;
    position: static;
    border-right: none;
    border-bottom: 1px solid var(--border);
    gap: 4px;
  }
  .sidebar .brand { width: 100%; padding: 4px 8px 10px; }
  .nav { flex-direction: row; flex-wrap: wrap; }
  .nav-secondary { margin-top: 0; margin-left: auto; }
  .nav-item span:not(.side-email) { display: none; }
  .sidebar-foot { border-top: none; margin: 0; padding: 0; }
  .side-email { display: none; }
  .content { padding: 28px 20px 64px; }
}

@media (max-width: 560px) {
  .add-grid { grid-template-columns: 1fr; }
}

/* ===================================================================== */
/* Theme toggle (sidebar)                                                */
/* ===================================================================== */
.theme-toggle {
  width: 100%;
  background: none;
  border: none;
  font: inherit;
  text-align: left;
  cursor: pointer;
}
.theme-toggle .nav-ic { display: inline-grid; place-items: center; }

/* ===================================================================== */
/* Filter bar + data table (Recent activity)                             */
/* ===================================================================== */
.filter-bar { display: flex; gap: 10px; margin: 0 0 14px; flex-wrap: wrap; }
.filter-input, .filter-select {
  background: var(--bg);
  border: 1px solid var(--border);
  color: var(--text);
  border-radius: 9px;
  padding: 9px 12px;
  font-size: 14px;
}
.filter-input { flex: 1; min-width: 200px; }
.filter-input:focus, .filter-select:focus { outline: none; border-color: var(--primary); }

.data-table {
  width: 100%;
  border-collapse: collapse;
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  overflow: hidden;
}
.data-table thead th {
  text-align: left;
  font-size: 12px;
  text-transform: uppercase;
  letter-spacing: 0.5px;
  color: var(--muted);
  padding: 11px 16px;
  border-bottom: 1px solid var(--border);
  background: var(--panel-2);
}
.data-table tbody td {
  padding: 12px 16px;
  border-bottom: 1px solid var(--border);
  vertical-align: middle;
}
.data-table tbody tr:last-child td { border-bottom: none; }
.data-table tbody tr:hover { background: var(--panel-2); }
.cell-title { font-weight: 600; max-width: 520px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.cell-subject { font-weight: 600; max-width: 280px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.cell-desc { color: var(--muted); max-width: 420px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.cell-when { color: var(--muted); font-size: 13px; white-space: nowrap; }
.data-table tbody tr.row-link { cursor: pointer; }
.data-table tbody tr.row-link:hover { background: var(--nav-active-bg); }
.cell-src { white-space: nowrap; }
.cell-source { white-space: nowrap; }
.src-link { color: var(--primary); text-decoration: none; }
.src-link:hover { text-decoration: underline; }
.provider-badge {
  display: inline-block;
  font-size: 11px;
  font-weight: 700;
  padding: 1px 8px;
  border-radius: 999px;
  background: var(--nav-active-bg);
  color: var(--primary);
  margin-right: 8px;
  vertical-align: middle;
}
.source-acct { vertical-align: middle; }
.muted-cell { color: var(--muted); }

/* ===================================================================== */
/* Chat                                                                  */
/* ===================================================================== */
.chat {
  display: flex;
  flex-direction: column;
  height: calc(100vh - 200px);
  min-height: 420px;
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  overflow: hidden;
}
.chat-log {
  flex: 1;
  overflow-y: auto;
  padding: 20px;
  display: flex;
  flex-direction: column;
  gap: 14px;
}
.chat-msg { display: flex; }
.chat-msg.user { justify-content: flex-end; }
.chat-msg .bubble {
  max-width: 76%;
  padding: 11px 15px;
  border-radius: 14px;
  line-height: 1.5;
  white-space: pre-wrap;
}
.chat-msg.assistant .bubble {
  background: var(--panel-2);
  border: 1px solid var(--border);
  border-bottom-left-radius: 4px;
}
.chat-msg.user .bubble {
  background: var(--primary);
  color: var(--primary-ink);
  border-bottom-right-radius: 4px;
  font-weight: 500;
}
.chat-results { display: flex; flex-direction: column; gap: 10px; margin-top: 12px; }
.chat-result {
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 11px 13px;
}
.chat-result.clickable { cursor: pointer; }
.idx-bar {
  height: 8px;
  border-radius: 6px;
  background: var(--border);
  overflow: hidden;
  margin: 8px 0 6px;
}
.idx-fill {
  height: 100%;
  border-radius: 6px;
  background: var(--accent, #c026d3);
  transition: width 0.6s ease;
}
.idx-meta { font-size: 12px; color: var(--muted); }
.chat-result.clickable:hover,
.chat-result.clickable:focus-visible {
  border-color: var(--accent, #c026d3);
  outline: none;
}
.cr-title { font-weight: 600; }
.cr-sum { color: var(--muted); font-size: 13px; margin: 3px 0 6px; }
.cr-meta { display: flex; gap: 10px; align-items: center; font-size: 12.5px; color: var(--muted); flex-wrap: wrap; }
.chat-input {
  display: flex;
  gap: 10px;
  padding: 14px;
  border-top: 1px solid var(--border);
  background: var(--panel-2);
}
.chat-input input {
  flex: 1;
  background: var(--bg);
  border: 1px solid var(--border);
  color: var(--text);
  border-radius: 10px;
  padding: 11px 14px;
  font-size: 14px;
}
.chat-input input:focus { outline: none; border-color: var(--primary); }

/* Per-account cleaning-enabled indicator (Integrations) */
/* Per-account Read/Write toggle: a two-state segmented control on the main row.
   The "active" segment is filled with the accent; the other is a quiet button. */
.connector-mode {
  display: inline-flex;
  flex: none;
  border: 1px solid var(--border);
  border-radius: 9px;
  overflow: hidden;
  background: var(--panel-2);
}
.connector-mode .mode-opt {
  appearance: none;
  border: none;
  background: transparent;
  color: var(--muted);
  font-size: 13px;
  font-weight: 600;
  padding: 6px 14px;
  cursor: pointer;
  transition: background 0.15s ease, color 0.15s ease;
}
.connector-mode .mode-opt + .mode-opt { border-left: 1px solid var(--border); }
.connector-mode .mode-opt:hover { color: var(--text); }
.connector-mode .mode-opt.active {
  background: var(--primary);
  color: var(--primary-ink);
}
/* Helper line under the connector's main row, aligned with the account text. */
.connector-mode-help {
  margin-left: 54px;
  color: var(--muted);
  font-size: 12.5px;
}
.connector-mode-help .mode-status { color: var(--green); }
.connector-mode-help .mode-status.err { color: var(--red); }
/* Disconnect: quiet by default, danger-tinted on hover. */
.btn-danger { color: var(--red); }
.btn-danger:hover { border-color: var(--red); background: rgba(248, 81, 73, 0.1); }

/* Rules "Analyze all accounts" bar: timeframe <select> + button + status. Sits
   at the top of the Rules wizard view (above the stepper / empty state). */
.rules-analyze-bar {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 10px;
  margin-bottom: 16px;
  padding: 12px 14px;
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 10px;
}
.rules-analyze-bar .rules-analyze-hint {
  color: var(--muted);
  font-size: 13px;
}
.rules-analyze-bar .rules-analyze-status {
  color: var(--muted);
  font-size: 13px;
  margin-left: auto;
}
.rules-analyze-bar .rules-analyze-status.err { color: var(--red); }

/* Live Analyze progress: spinner + determinate bar while in flight, swapping to
   a check-mark completion line + "Re-evaluate rules" button when every account is done.
   Takes the full bar width (its own flex row) so the bar can stretch. */
.analyze-progress {
  flex: 1 0 100%;
  display: flex;
  flex-direction: column;
  gap: 8px;
}
.analyze-progress-row {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 13px;
}
.analyze-progress-label { color: var(--text); }
.analyze-progress-label.analyze-complete { color: var(--muted); }
.analyze-complete-mark { color: var(--primary); font-weight: 700; }

/* Small inline spinner (distinct from the big page .spinner). */
.analyze-spinner {
  width: 14px; height: 14px;
  border: 2px solid var(--border);
  border-top-color: var(--primary);
  border-radius: 50%;
  display: inline-block;
  flex: none;
  animation: spin 0.8s linear infinite;
}

/* Determinate progress bar — --primary fill on a --panel-2 track. Cross-browser
   styling needs both the WebKit and Moz pseudo-elements. */
.analyze-bar {
  -webkit-appearance: none;
  appearance: none;
  width: 100%;
  height: 8px;
  border: 1px solid var(--border);
  border-radius: 999px;
  overflow: hidden;
  background: var(--panel-2);
}
.analyze-bar::-webkit-progress-bar {
  background: var(--panel-2);
  border-radius: 999px;
}
.analyze-bar::-webkit-progress-value {
  background: var(--primary);
  border-radius: 999px;
  transition: width 0.3s ease;
}
.analyze-bar::-moz-progress-bar {
  background: var(--primary);
  border-radius: 999px;
}
.analyze-reeval { align-self: flex-start; }

/* Source chip: a muted pill showing which mailbox a (universal) rule came from.
   Used in the wizard rows and the read-only all-rules table. */
.source-chip {
  display: inline-block;
  max-width: 18ch;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  vertical-align: middle;
  padding: 2px 8px;
  border-radius: 999px;
  background: var(--panel-2);
  color: var(--muted);
  border: 1px solid var(--border);
  font-size: 12px;
}
.source-chip.source-chip-empty {
  border-style: dashed;
}

/* --- Spaces nav item (grayed "Soon") ------------------------------------- */
.nav-soon { opacity: 0.55; cursor: default; }
.nav-soon:hover { background: none; }
.nav-soon-tag {
  margin-left: auto;
  font-size: 10px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  padding: 1px 6px;
  border-radius: 999px;
  background: var(--panel-2);
  color: var(--muted);
}

/* --- Dashboard = "what needs you" : the Act queue ------------------------- */
.act-queue { display: flex; flex-direction: column; gap: 8px; }
.act-item {
  display: grid;
  grid-template-columns: 180px 1fr auto;
  align-items: center;
  gap: 16px;
  padding: 12px 14px;
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 10px;
  cursor: pointer;
}
.act-item:hover { border-color: var(--primary); }
.act-item.act-active { box-shadow: inset 3px 0 0 var(--primary); background: var(--nav-active-bg); }
.act-unread .act-subj { font-weight: 700; color: var(--text); }
.act-who { font-weight: 600; color: var(--text); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.act-main { min-width: 0; }
.act-subj { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.act-snip { font-size: 13px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.act-meta { display: flex; align-items: center; gap: 10px; white-space: nowrap; }
.act-time { font-size: 12px; }
.act-badge {
  font-size: 11px;
  font-weight: 700;
  padding: 2px 8px;
  border-radius: 999px;
}
.act-badge.no-rule { background: var(--nav-active-bg); color: var(--primary); }
.act-badge.has-rule { background: var(--panel-2); color: var(--muted); }
.dash-indexed { margin-top: 28px; }
.dash-indexed > summary {
  cursor: pointer;
  font-weight: 600;
  color: var(--muted);
  padding: 8px 0;
}

/* --- Co-pilot side panel (the private workspace) -------------------------- */
.copilot {
  position: fixed;
  top: 0;
  right: 0;
  width: min(420px, 92vw);
  height: 100vh;
  background: var(--panel);
  border-left: 1px solid var(--border);
  box-shadow: -8px 0 24px rgba(0, 0, 0, 0.18);
  padding: 20px;
  overflow-y: auto;
  z-index: 50;
  display: flex;
  flex-direction: column;
  gap: 18px;
}
.copilot-head { display: flex; justify-content: space-between; align-items: flex-start; gap: 12px; }
.copilot-subj { font-size: 16px; font-weight: 700; color: var(--text); }
.copilot-from { font-size: 13px; margin-top: 2px; }
.copilot-body { display: flex; flex-direction: column; gap: 10px; }
.copilot-snip {
  font-size: 13.5px;
  color: var(--text);
  background: var(--panel-2);
  border-radius: 8px;
  padding: 12px;
  margin: 0;
  max-height: 30vh;
  overflow-y: auto;
}
.copilot-sec { border-top: 1px solid var(--border); padding-top: 14px; }
.copilot-soon { font-size: 13px; margin: 6px 0 0; }

/* Inline message accordion in the Act queue (the reading surface). */
.act-item-wrap { display: flex; flex-direction: column; }
.act-accordion {
  border: 1px solid var(--border);
  border-top: none;
  border-radius: 0 0 10px 10px;
  background: var(--panel-2);
  padding: 14px 16px;
  margin-top: -2px;
}
.act-body {
  font-size: 13.5px;
  color: var(--text);
  line-height: 1.5;
  word-break: break-word;
  max-height: 55vh;
  overflow: auto;
  margin: 0 0 12px;
}
.act-body p { margin: 0 0 10px; }
.act-body a { color: var(--primary); }
.act-body img { max-width: 100%; height: auto; }
.act-body h1, .act-body h2, .act-body h3 { margin: 14px 0 6px; line-height: 1.3; }
.act-body h1 { font-size: 18px; } .act-body h2 { font-size: 16px; } .act-body h3 { font-size: 14.5px; }
.act-body ul, .act-body ol { margin: 0 0 10px; padding-left: 22px; }
.act-body li { margin: 2px 0; }
.act-body blockquote { margin: 0 0 10px; padding-left: 12px; border-left: 3px solid var(--border); color: var(--muted); }
.act-body pre { background: var(--panel); border: 1px solid var(--border); border-radius: 6px; padding: 10px; overflow-x: auto; font-size: 12.5px; }
.act-body code { background: var(--panel); padding: 1px 5px; border-radius: 4px; font-size: 12.5px; }
.act-body pre code { background: none; padding: 0; }
.act-body table { border-collapse: collapse; max-width: 100%; }
.act-body td, .act-body th { border: 1px solid var(--border); padding: 4px 8px; }
.act-body hr { border: none; border-top: 1px solid var(--border); margin: 12px 0; }
.act-accordion-foot { display: flex; gap: 10px; }
.act-item-wrap:has(.act-accordion:not([hidden])) .act-item { border-radius: 10px 10px 0 0; }

/* Act-queue section dividers ("Needs you" / "To classify"). */
.act-divider {
  font-size: 12px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--muted);
  margin: 14px 2px 4px;
}
.act-queue > .act-divider:first-child { margin-top: 0; }

/* Recently handled digest (time-windowed). */
.handled-summary { font-size: 13px; margin: 0 0 10px; }
.handled-list { display: flex; flex-direction: column; gap: 4px; }
.handled-item {
  display: grid;
  grid-template-columns: 1fr auto 70px 90px;
  align-items: center;
  gap: 12px;
  padding: 8px 12px;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--panel);
  text-decoration: none;
  color: var(--text);
}
.handled-item:hover { border-color: var(--primary); }
.handled-who { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-weight: 500; }
.handled-n { text-align: right; font-variant-numeric: tabular-nums; font-weight: 700; }
.handled-when { text-align: right; font-size: 12px; }

/* Source-label chips on an Act item: where the user's own filters already filed it. */
.act-labels { display: flex; flex-wrap: wrap; gap: 4px; margin-top: 4px; }
.act-label-chip {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  padding: 1px 7px;
  font-size: 11px;
  border-radius: 10px;
  background: var(--chip-bg, #eef1f5);
  color: var(--muted, #5a6472);
  border: 1px solid var(--border);
}
/* Folder glyph as a currentColor-tinted SVG mask (no emoji). */
.act-label-chip::before {
  content: "";
  display: inline-block;
  width: 11px; height: 11px;
  background-color: currentColor;
  -webkit-mask: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24'%3E%3Cpath d='M3 6a2 2 0 0 1 2-2h4l2 2h8a2 2 0 0 1 2 2v9a2 2 0 0 1-2 2H5a2 2 0 0 1-2-2V6z'/%3E%3C/svg%3E") center/contain no-repeat;
          mask: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24'%3E%3Cpath d='M3 6a2 2 0 0 1 2-2h4l2 2h8a2 2 0 0 1 2 2v9a2 2 0 0 1-2 2H5a2 2 0 0 1-2-2V6z'/%3E%3C/svg%3E") center/contain no-repeat;
}

/* One-off Done + rule-undo in the co-pilot panel + per-row quick Done. */
.copilot-done { width: 100%; }
.copilot-hint { font-size: 12px; margin: 6px 0 0; }
.copilot-undo { width: 100%; margin-top: 10px; color: var(--danger, #b4232a); }
.act-done { opacity: 0; transition: opacity 0.12s; font-size: 13px; padding: 2px 8px; }
.act-item:hover .act-done, .act-item.act-active .act-done { opacity: 1; }
.act-done:hover { color: var(--primary); }
.act-toast-action {
  margin-left: 12px;
  padding: 1px 10px;
  font-weight: 600;
  text-decoration: underline;
}

/* Dashboard tabs: Act + handled-category browsers. */
.dash-tabs { display: flex; gap: 4px; border-bottom: 1px solid var(--border); margin: 4px 0 18px; }
.dash-tab {
  appearance: none;
  background: none;
  border: none;
  border-bottom: 2px solid transparent;
  padding: 8px 14px;
  margin-bottom: -1px;
  font: inherit;
  font-weight: 600;
  color: var(--muted, #5a6472);
  cursor: pointer;
}
.dash-tab:hover { color: var(--text); }
.dash-tab.current { color: var(--primary); border-bottom-color: var(--primary); }
.handled-sub { margin: 0 0 14px; font-size: 13px; }

/* Handled browser rows: chronological, with per-message undo. */
.handled-list { display: flex; flex-direction: column; gap: 4px; }
.handled-item {
  display: grid;
  grid-template-columns: 180px 1fr auto auto;
  align-items: center;
  gap: 12px;
  padding: 8px 12px;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--panel);
}
.handled-who { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-weight: 500; }
.handled-main { min-width: 0; }
.handled-subj { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.handled-snip { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-size: 12px; }
.handled-when { font-size: 12px; white-space: nowrap; }
.handled-undo { opacity: 0; transition: opacity 0.12s; font-size: 15px; padding: 2px 8px; }
.handled-item:hover .handled-undo { opacity: 1; }
.handled-undo:hover { color: var(--primary); }

/* --- MCP page: agent tokens + connect snippets (zipppo-rtr.1) ------------- */
.mcp-card {
  border: 1px solid var(--border);
  border-radius: 10px;
  background: var(--panel);
  padding: 16px 18px;
  margin-bottom: 16px;
}
.mcp-mint { display: flex; gap: 10px; margin-top: 12px; }
.mcp-mint input {
  flex: 1;
  padding: 8px 12px;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--bg);
  color: var(--text);
  font: inherit;
}
.mcp-minted {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-top: 12px;
  padding: 10px 12px;
  border: 1px dashed var(--primary);
  border-radius: 8px;
  background: color-mix(in srgb, var(--primary) 6%, transparent);
}
.mcp-minted code {
  flex: 1;
  overflow-x: auto;
  white-space: nowrap;
  font-size: 13px;
}
.form-error { margin-top: 10px; color: #d02b45; font-size: 13px; }
.mcp-snippet {
  border: 1px solid var(--border);
  border-radius: 8px;
  margin-top: 12px;
  overflow: hidden;
}
.mcp-snippet-head {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 8px 12px;
  border-bottom: 1px solid var(--border);
  font-size: 13px;
  font-weight: 600;
}
.mcp-snippet pre {
  margin: 0;
  padding: 12px;
  overflow-x: auto;
  font-size: 12.5px;
  line-height: 1.5;
}
.mcp-tokens { margin-top: 12px; }
.mcp-revoked td { opacity: 0.5; }

/* Bring-your-own-source: the risk disclosure must be unmissable, not fine print. */
.byo-warn {
  margin-top: 12px;
  padding: 12px 14px;
  border: 1px solid #d97706;
  border-left-width: 4px;
  border-radius: 8px;
  background: color-mix(in srgb, #d97706 8%, transparent);
  font-size: 13.5px;
  line-height: 1.5;
}


/* Billing actions row */
.bill-actions { margin-top: 18px; }

/* Plan cards on the Billing page */
.plan-grid { display: grid; grid-template-columns: repeat(3, 1fr); gap: 14px; }
.plan-card {
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--panel);
  padding: 20px;
  display: flex;
  flex-direction: column;
  gap: 10px;
}
.plan-featured { border-color: var(--primary); }
.plan-name { font-weight: 700; font-size: 16px; }
.plan-price { font-size: 28px; font-weight: 700; }
.plan-price span { font-size: 14px; font-weight: 500; color: var(--muted); }
.plan-feats { margin: 0; padding-left: 18px; color: var(--muted); font-size: 13.5px; flex: 1; }
.plan-feats li { margin: 4px 0; }
.plan-cta { width: 100%; }
@media (max-width: 900px) { .plan-grid { grid-template-columns: 1fr; } }

/* Billing detail blocks + limits table */
.bill-detail-grid { display: grid; grid-template-columns: 1fr; gap: 0; }
.table-scroll { overflow-x: auto; }

/* --- Dashboard Board (visual canvas over dashboard_items + handled_items) --- */
.dash-controls {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 16px;
  flex-wrap: wrap;
}
.seg {
  display: inline-flex;
  border: 1px solid var(--border);
  border-radius: 9px;
  overflow: hidden;
}
.seg-btn {
  padding: 7px 16px;
  border: none;
  background: var(--panel);
  color: var(--muted);
  font: inherit;
  font-weight: 600;
  cursor: pointer;
}
.seg-btn.current { background: var(--primary); color: var(--primary-ink); }
.board-groupby {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  color: var(--muted);
  font-size: 13px;
}
.board-groupby select {
  padding: 6px 10px;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--bg);
  color: var(--text);
  font: inherit;
}

.board {
  display: flex;
  gap: 14px;
  overflow-x: auto;
  padding-bottom: 10px;
  align-items: flex-start;
}
.board-col {
  flex: 0 0 320px;
  max-width: 320px;
  background: var(--panel-2);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 10px;
  display: flex;
  flex-direction: column;
  gap: 10px;
  max-height: calc(100vh - 230px);
}
.board-col-head {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 4px 4px 2px;
}
.board-dot { width: 9px; height: 9px; border-radius: 50%; flex: none; }
.board-col-label { font-weight: 700; font-size: 14px; }
.board-col-count { margin-left: auto; color: var(--muted); font-size: 13px; }
.board-col-body {
  display: flex;
  flex-direction: column;
  gap: 10px;
  overflow-y: auto;
}
.board-card {
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 12px 13px;
  cursor: pointer;
  transition: border-color 0.12s ease, transform 0.05s ease;
}
.board-card:hover { border-color: var(--primary); }
.board-card:active { transform: translateY(1px); }
.board-unread { border-left: 3px solid var(--primary); }
.board-card-who {
  display: flex;
  align-items: center;
  gap: 8px;
  font-weight: 700;
  font-size: 13.5px;
}
.board-card-name { min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.board-card-inbox {
  margin-left: auto;
  display: inline-flex;
  align-items: center;
  gap: 5px;
  flex: none;
  font-weight: 500;
  font-size: 11px;
  color: var(--muted);
  background: var(--panel-2);
  border: 1px solid var(--border);
  border-radius: 999px;
  padding: 1px 8px 1px 6px;
}
.board-inbox-dot { width: 7px; height: 7px; border-radius: 50%; }
.board-card-subj {
  font-weight: 600;
  font-size: 14px;
  margin: 3px 0;
  overflow: hidden;
  text-overflow: ellipsis;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
}
.board-card-snip {
  color: var(--muted);
  font-size: 12.5px;
  line-height: 1.45;
  overflow: hidden;
  text-overflow: ellipsis;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
}
.board-card-foot {
  display: flex;
  align-items: center;
  gap: 6px;
  margin-top: 10px;
  flex-wrap: wrap;
}
.board-card-badge {
  font-size: 10.5px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.3px;
  padding: 2px 7px;
  border-radius: 999px;
}
.b-needs { background: rgba(248, 81, 73, 0.16); color: var(--red); }
.b-triage { background: rgba(210, 153, 34, 0.16); color: var(--amber); }
.b-handled { background: rgba(46, 160, 67, 0.16); color: var(--green); }
.board-card-chip {
  font-size: 10.5px;
  padding: 2px 7px;
  border-radius: 999px;
  background: var(--panel-2);
  color: var(--muted);
  border: 1px solid var(--border);
}
.board-card-time { margin-left: auto; color: var(--muted); font-size: 11.5px; }
@media (max-width: 640px) {
  .board-col { flex-basis: 82vw; max-width: 82vw; }
}

/* Board "show more" pager */
.board-more {
  border: 1px dashed var(--border);
  background: transparent;
  color: var(--muted);
  border-radius: 8px;
  padding: 8px;
  font: inherit;
  font-size: 12.5px;
  cursor: pointer;
}
.board-more:hover { border-color: var(--primary); color: var(--text); }

.email-truncnote { margin-top: 18px; font-size: 12.5px; }

/* Board column dismiss (X) + hidden-restore bar */
.board-col-x {
  border: none;
  background: transparent;
  color: var(--muted);
  cursor: pointer;
  font-size: 12px;
  line-height: 1;
  padding: 2px 4px;
  border-radius: 5px;
  margin-left: 4px;
}
.board-col-x:hover { color: var(--red); background: rgba(248, 81, 73, 0.12); }
.board-hidden-bar {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-left: auto;      /* anchor to the right of the tab row */
  align-self: center;
  color: var(--muted);
  font-size: 12.5px;
}

/* Draggable board columns (Sender/Topic reorder) */
.board-col[draggable="true"] .board-col-head { cursor: grab; }
.board-col.dragging { opacity: 0.5; }
.board-col.drag-over { outline: 2px dashed var(--primary); outline-offset: 2px; }

/* Board inbox filter (multi-inbox only) */
.board-inbox-wrap { margin-left: auto; display: inline-flex; align-items: center; }
/* When the filter is visible it holds the right anchor; the hidden-bar then
   just flows after it (no extra auto-margin needed). */
.board-inbox-wrap:not([hidden]) ~ .board-hidden-bar { margin-left: 12px; }
#board-inbox {
  padding: 5px 10px;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--bg);
  color: var(--text);
  font: inherit;
  font-size: 12.5px;
}
