:root {
  /* Earthy jungle, refined: a solid pine green brand, warm walnut-brown and a
     deep slate-blue as secondary accents, over a warm cream ground. */
  --brand: #2f7d57;
  --brand-dark: #25624a;
  --on-brand: #0e211a;          /* near-black text for green chips/avatars/buttons */
  --accent-blue: #2c5d7c;       /* slate/ocean blue — links, references, info */
  --accent-blue-dark: #224b66;
  --accent-brown: #6f4a30;      /* walnut/bark — date dividers, warm marks */
  --bg: #f4f3ec;
  --surface: #ffffff;
  --border: #e3ded2;
  --text: #20271f;
  --text-muted: #5f665b;
  --hover-bg: rgba(0, 0, 0, 0.04);
  --radius: 8px;
  --font: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
}

/*
  Theme override: "System" (no data-theme) follows the OS via the media query
  below; "Light"/"Dark" force the palette regardless of the OS. Accent overrides
  just the brand color over whichever theme is active. Set on <html> server-side
  from the user's saved cookies (NavModelAdvice) so there's no flash.
*/
:root[data-theme="dark"] {
  --bg: #0f1512;
  --surface: #161d18;
  --border: #2a342d;
  --text: #e6efe8;
  --text-muted: #8a978d;
  --brand: #5fb98a;
  --brand-dark: #4aa276;
  --on-brand: #0e211a;
  --accent-blue: #7fb0d2;
  --accent-blue-dark: #6fa3c6;
  --accent-brown: #c39a6f;
  --hover-bg: rgba(255, 255, 255, 0.06);
}
:root[data-theme="light"] {
  --bg: #f4f3ec;
  --surface: #ffffff;
  --border: #e3ded2;
  --text: #20271f;
  --text-muted: #5f665b;
  --brand: #2f7d57;
  --brand-dark: #25624a;
  --on-brand: #0e211a;
  --accent-blue: #2c5d7c;
  --accent-blue-dark: #224b66;
  --accent-brown: #6f4a30;
  --hover-bg: rgba(0, 0, 0, 0.04);
}
/* Accent color override lives at the END of this file (see bottom) so it wins
   over both the light :root and the dark-mode block regardless of theme. */

*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

body {
  font-family: var(--font);
  background: var(--bg);
  color: var(--text);
  min-height: 100vh;
}

/* ── Scrollbars ─────────────────────────────────────── */
/* Slightly thicker than the OS default and tinted with the theme: a
   transparent track over the page ground with a brand-tinted thumb that
   darkens on hover. Driven by the same CSS vars as everything else, so it
   follows light/dark/accent automatically. */
* {
  scrollbar-width: thin;                 /* Firefox */
  scrollbar-color: var(--brand) transparent;
}
*::-webkit-scrollbar { width: 16px; height: 16px; }
*::-webkit-scrollbar-track { background: transparent; }
*::-webkit-scrollbar-thumb {
  background: var(--brand);
  border-radius: 999px;
  /* Transparent border clipped to the padding box insets the thumb so it
     reads as a rounded pill with breathing room, not a full-width bar. */
  border: 4px solid transparent;
  background-clip: padding-box;
}
*::-webkit-scrollbar-thumb:hover { background: var(--brand-dark); }
*::-webkit-scrollbar-corner { background: transparent; }

/* ── App Header ─────────────────────────────────────── */
.app-header {
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  padding: 0 24px;
  height: 56px;
  display: flex;
  align-items: center;
  position: sticky;
  top: 0;
  z-index: 100;
}
.brand { font-size: 20px; font-weight: 700; color: var(--brand); }

/* ── Thread List Page ───────────────────────────────── */
.thread-page {
  /* Left-anchored (not centered) so the sender rail hugs the left edge,
     aligned under the header gutter; capped so it isn't absurd on ultrawide. */
  max-width: 1680px;
  margin: 0;
  padding: 28px 24px;
}
.section-title {
  font-size: 22px;
  font-weight: 700;
  margin-bottom: 16px;
}
.thread-list {
  background: var(--surface);
  border-radius: var(--radius);
  border: 1px solid var(--border);
  overflow: hidden;
}
.thread-item {
  display: block;
  padding: 14px 20px;
  border-bottom: 1px solid var(--border);
  text-decoration: none;
  color: inherit;
  transition: background 0.1s;
}
.thread-item:last-child { border-bottom: none; }
.thread-item:hover { background: #f9fafb; }
.thread-subject {
  font-weight: 600;
  font-size: 15px;
  overflow: hidden;
  white-space: nowrap;
  text-overflow: ellipsis;
  flex: 1;
  min-width: 0;
}
.thread-meta {
  font-size: 13px;
  color: var(--text-muted);
  display: flex;
  align-items: baseline;
  margin-top: 4px;
}

/* ── Billing Banners ────────────────────────────────── */
.trial-banner {
  display: flex;
  align-items: center;
  gap: 16px;
  background: #eef3ff;
  border: 1px solid #c8d6ff;
  color: #1d2d5c;
  padding: 12px 16px;
  border-radius: var(--radius);
  margin-bottom: 20px;
  font-size: 14px;
}
.trial-banner-text { flex: 1; }
.trial-banner-cta {
  padding: 7px 14px;
  font-size: 13px;
  flex-shrink: 0;
}
.trial-banner-link {
  color: var(--brand-dark);
  font-weight: 600;
  text-decoration: none;
  white-space: nowrap;
}
.trial-banner-link:hover { text-decoration: underline; }
.trial-banner-urgent {
  background: #fff4e5;
  border-color: #ffd9a8;
  color: #6b3a00;
}
.verify-email-banner {
  display: flex;
  align-items: center;
  gap: 16px;
  background: #fff8e6;
  border: 1px solid #f0d68b;
  color: #6b4a00;
  padding: 12px 16px;
  border-radius: var(--radius);
  margin-bottom: 20px;
  font-size: 14px;
}
.verify-email-text { flex: 1; }
.verify-email-form { margin: 0; }
.verify-email-cta {
  padding: 7px 14px;
  font-size: 13px;
  flex-shrink: 0;
}
.trial-banner-compact {
  margin: 0;
  border-radius: 0;
  border-left: none;
  border-right: none;
  border-top: none;
  font-size: 13px;
  padding: 8px 24px;
}

.lockout-banner {
  text-align: center;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 48px 24px;
}
.lockout-banner h2 {
  font-size: 22px;
  font-weight: 700;
  margin-bottom: 10px;
}
.lockout-banner p {
  font-size: 15px;
  color: var(--text-muted);
  margin-bottom: 24px;
  max-width: 460px;
  margin-left: auto;
  margin-right: auto;
}

/* ── Upgrade Modal ──────────────────────────────────── */
.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(15, 23, 42, 0.55);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px;
  z-index: 1000;
  animation: modalFadeIn 140ms ease-out;
}
@keyframes modalFadeIn {
  from { opacity: 0; }
  to   { opacity: 1; }
}
.modal-card {
  position: relative;
  background: var(--surface);
  border-radius: 12px;
  box-shadow: 0 20px 50px rgba(0, 0, 0, 0.25);
  padding: 36px 32px 28px;
  max-width: 560px;
  width: 100%;
  text-align: center;
}
.modal-close {
  position: absolute;
  top: 12px;
  right: 14px;
  border: 0;
  background: transparent;
  font-size: 24px;
  line-height: 1;
  color: var(--text-muted);
  cursor: pointer;
  padding: 4px 8px;
}
.modal-close:hover { color: var(--text); }
.modal-title {
  font-size: 22px;
  font-weight: 700;
  margin-bottom: 8px;
}
.modal-sub {
  font-size: 14px;
  color: var(--text-muted);
  margin-bottom: 22px;
  line-height: 1.5;
}
.plan-compare {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 12px;
  margin-bottom: 22px;
  text-align: left;
}
.plan-compare-col {
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 16px;
  background: var(--bg);
}
.plan-compare-featured {
  border-color: var(--brand);
  background: var(--surface);
  box-shadow: 0 2px 12px rgba(47, 133, 90, 0.12);
}
.plan-compare-tag {
  font-size: 10px;
  font-weight: 600;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: var(--text-muted);
  margin-bottom: 6px;
}
.plan-compare-featured .plan-compare-tag { color: var(--brand); }
.plan-compare-name {
  font-size: 15px;
  font-weight: 700;
  margin-bottom: 10px;
}
.plan-compare-features {
  list-style: none;
  padding: 0;
  margin: 0;
  font-size: 13px;
  line-height: 1.7;
  color: var(--text-muted);
}
.plan-compare-features li::before {
  content: "✓";
  color: var(--brand);
  margin-right: 6px;
  font-weight: 700;
}
.modal-cta-form { margin: 0; }
.modal-cta {
  width: 100%;
  padding: 12px 16px;
  font-size: 15px;
  font-weight: 600;
  border: 0;
  cursor: pointer;
}
.billing-period-toggle {
  display: flex;
  gap: 0;
  margin: 0 0 12px;
  padding: 4px;
  background: var(--surface-muted, rgba(148, 163, 184, 0.12));
  border: 1px solid var(--border);
  border-radius: 999px;
}
.billing-period-toggle-btn {
  flex: 1;
  padding: 8px 14px;
  border: 0;
  background: transparent;
  color: var(--text-muted);
  font-size: 13px;
  font-weight: 600;
  border-radius: 999px;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  transition: background 0.12s ease, color 0.12s ease;
}
.billing-period-toggle-btn-active {
  background: var(--surface);
  color: var(--text);
  box-shadow: 0 1px 2px rgba(15, 23, 42, 0.08);
}
.billing-period-toggle-badge {
  display: inline-block;
  padding: 2px 8px;
  border-radius: 999px;
  background: rgba(16, 185, 129, 0.15);
  color: #047857;
  font-size: 11px;
  font-weight: 700;
  letter-spacing: 0.02em;
}
.trial-nudge-annual {
  margin-top: 12px;
  padding-top: 12px;
  border-top: 1px dashed var(--border);
}
.trial-nudge-annual-pitch {
  font-size: 13px;
  color: var(--text-muted);
  margin: 0 0 10px;
  line-height: 1.5;
}
.modal-cta-annual {
  background: transparent;
  border: 1px solid var(--brand);
  color: var(--brand);
}
.modal-cta-annual:hover {
  background: rgba(47, 133, 90, 0.08);
}
.modal-dismiss-link {
  display: inline-block;
  margin-top: 12px;
  background: transparent;
  border: 0;
  color: var(--text-muted);
  font-size: 13px;
  cursor: pointer;
  padding: 4px 8px;
}
.modal-dismiss-link:hover { color: var(--text); text-decoration: underline; }
@media (max-width: 520px) {
  .modal-card { padding: 28px 20px 20px; }
  .plan-compare { grid-template-columns: 1fr; }
}

/* ── Empty State ────────────────────────────────────── */
.empty-state {
  text-align: center;
  padding: 64px 24px;
}
.empty-state h2 {
  font-size: 22px;
  font-weight: 700;
  margin-bottom: 10px;
}
.empty-state p {
  font-size: 15px;
  color: var(--text-muted);
  margin-bottom: 24px;
}

/* ── Onboarding Checklist ───────────────────────────── */
.onboarding-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 40px 32px;
  text-align: center;
}
.onboarding-title {
  font-size: 22px;
  font-weight: 700;
  margin-bottom: 8px;
}
.onboarding-sub {
  font-size: 15px;
  color: var(--text-muted);
  margin-bottom: 24px;
}
.onboarding-steps {
  list-style: none;
  padding: 0;
  margin: 0 auto 28px;
  max-width: 320px;
  text-align: left;
}
.onboarding-step {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 10px 0;
  font-size: 15px;
  color: var(--text-muted);
}
.onboarding-step-mark {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 28px;
  height: 28px;
  border-radius: 50%;
  flex-shrink: 0;
  background: var(--bg);
  border: 1px solid var(--border);
  font-size: 13px;
  font-weight: 700;
  color: var(--text-muted);
}
.onboarding-step-current .onboarding-step-mark {
  background: var(--brand);
  color: #fff;
  border-color: var(--brand);
}
.onboarding-step-current .onboarding-step-text {
  font-weight: 600;
  color: var(--text);
}
.onboarding-step-done .onboarding-step-mark {
  background: #d1fae5;
  color: #047857;
  border-color: #6ee7b7;
}
.onboarding-cta {
  min-width: 200px;
}

/* ── Onboarding Progress Bar (always-visible on /threads) ───── */
.onboarding-progress {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 16px 20px;
  margin-bottom: 20px;
  display: flex;
  flex-direction: column;
  gap: 12px;
}
.onboarding-progress-header {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 12px;
}
.onboarding-progress-title {
  font-size: 15px;
  font-weight: 600;
  color: var(--text);
}
.onboarding-progress-count {
  font-size: 13px;
  color: var(--text-muted);
}
.onboarding-progress-bar {
  height: 6px;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 999px;
  overflow: hidden;
}
.onboarding-progress-bar-fill {
  height: 100%;
  background: var(--brand);
  border-radius: inherit;
  transition: width 240ms ease;
}
.onboarding-progress-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  flex-wrap: wrap;
}
.onboarding-progress-steps {
  list-style: none;
  padding: 0;
  margin: 0;
  display: flex;
  flex-wrap: wrap;
  gap: 6px 20px;
}
.onboarding-progress-step {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  font-size: 14px;
  color: var(--text-muted);
}
.onboarding-progress-step-mark {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 22px;
  height: 22px;
  border-radius: 50%;
  background: var(--bg);
  border: 1px solid var(--border);
  font-size: 12px;
  font-weight: 700;
  color: var(--text-muted);
  flex-shrink: 0;
}
.onboarding-progress-step-current .onboarding-progress-step-mark {
  background: var(--brand);
  border-color: var(--brand);
  color: #fff;
}
.onboarding-progress-step-current .onboarding-progress-step-text {
  color: var(--text);
  font-weight: 600;
}
.onboarding-progress-step-done .onboarding-progress-step-mark {
  background: #d1fae5;
  color: #047857;
  border-color: #6ee7b7;
}
.onboarding-progress-step-done .onboarding-progress-step-text {
  text-decoration: line-through;
  opacity: 0.75;
}
.onboarding-progress-cta {
  white-space: nowrap;
}
@media (max-width: 640px) {
  .onboarding-progress {
    padding: 14px 16px;
  }
  .onboarding-progress-row {
    flex-direction: column;
    align-items: stretch;
  }
  .onboarding-progress-cta {
    align-self: flex-start;
  }
}
.onboarding-nudge {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  flex-wrap: wrap;
  margin-top: 4px;
  padding: 12px 14px;
  background: rgba(47, 133, 90, 0.06);
  border: 1px dashed var(--brand);
  border-radius: var(--radius);
}
.onboarding-nudge-text {
  display: flex;
  flex-direction: column;
  gap: 2px;
  flex: 1 1 240px;
  min-width: 0;
}
.onboarding-nudge-headline {
  font-size: 14px;
  font-weight: 600;
  color: var(--text);
}
.onboarding-nudge-body {
  font-size: 13px;
  color: var(--text-muted);
  line-height: 1.45;
}
.onboarding-nudge-form {
  margin: 0;
  flex: 0 0 auto;
}
.onboarding-nudge-cta {
  white-space: nowrap;
}
@media (prefers-color-scheme: dark) {
  .onboarding-nudge {
    background: rgba(47, 133, 90, 0.12);
  }
}
@media (max-width: 640px) {
  .onboarding-nudge {
    flex-direction: column;
    align-items: stretch;
  }
  .onboarding-nudge-cta {
    align-self: flex-start;
  }
}

/* ── Pagination ─────────────────────────────────────── */
.pagination {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 16px 0 4px;
}
.page-link {
  padding: 7px 16px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 6px;
  color: var(--text);
  text-decoration: none;
  font-size: 14px;
}
.page-link:hover { background: #f3f4f6; }
.page-info { font-size: 14px; color: var(--text-muted); }

/* ── Buttons ────────────────────────────────────────── */
.btn {
  display: inline-block;
  padding: 10px 24px;
  border-radius: 6px;
  font-size: 15px;
  font-weight: 500;
  cursor: pointer;
  text-decoration: none;
  border: none;
  font-family: var(--font);
  line-height: 1.4;
}
.btn-primary { background: var(--brand); color: #fff; }
.btn-primary:hover { background: var(--brand-dark); }

/* ── Conversation Header ────────────────────────────── */
.conv-header {
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  padding: 12px 24px;
  display: flex;
  align-items: center;
  gap: 16px;
  position: sticky;
  top: 0;
  z-index: 10;
}
.back-link {
  color: var(--brand);
  text-decoration: none;
  font-size: 14px;
  font-weight: 500;
  white-space: nowrap;
  flex-shrink: 0;
}
.back-link:hover { text-decoration: underline; }
.conv-header h1 {
  font-size: 16px;
  font-weight: 600;
  overflow: hidden;
  white-space: nowrap;
  text-overflow: ellipsis;
  flex: 1;
  min-width: 0;
}

/* ── Conversation Body ──────────────────────────────── */
.conv-body {
  max-width: 1180px;
  margin: 0 auto;
  display: flex;
  flex-direction: column;
  height: calc(100vh - 57px);
  height: calc(100dvh - 57px);
}

/* ── Messages Area ──────────────────────────────────── */
.messages {
  flex: 1;
  overflow-y: auto;
  padding: 24px 24px 8px;
  display: flex;
  flex-direction: column;
  gap: 20px;
}
.messages-empty {
  flex: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--text-muted);
  font-size: 15px;
}

/* ── Bubble Run ─────────────────────────────────────── */
.bubble-run {
  display: flex;
  gap: 12px;
  align-items: flex-start;
}

/* ── Avatar ─────────────────────────────────────────── */
.avatar {
  width: 36px;
  height: 36px;
  border-radius: 50%;
  background: var(--brand);
  color: var(--on-brand);
  font-size: 13px;
  font-weight: 700;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  user-select: none;
}

/* ── Bubble Group ───────────────────────────────────── */
.bubble-group {
  flex: 1;
  min-width: 0;
}
.bubble-sender {
  font-size: 12px;
  font-weight: 600;
  color: var(--text-muted);
  margin-bottom: 5px;
}
.bubble {
  background: var(--surface);
  padding: 10px 14px;
  border-radius: 4px 16px 16px 16px;
  border: 1px solid rgba(0, 0, 0, 0.04);
  box-shadow: 0 1px 3px rgba(0, 0, 0, 0.08);
  font-size: 14px;
  line-height: 1.65;
  /* Fill the width of the bubble group (chat-pane minus padding and the
     avatar gutter) rather than hugging the text. */
  display: block;
  max-width: none;
  word-wrap: break-word;
  overflow-wrap: break-word;
  margin-bottom: 3px;
  transition: box-shadow 0.15s;
}
.bubble:hover { box-shadow: 0 2px 8px rgba(0, 0, 0, 0.14); }
.bubble p { margin-bottom: 0.5em; }
.bubble p:last-child { margin-bottom: 0; }
.bubble a { color: var(--accent-blue-dark); }
.bubble-time {
  font-size: 11px;
  color: var(--text-muted);
  margin-top: 2px;
  margin-bottom: 4px;
}

/* ── "In reply to" jump link ────────────────────────── */
.reply-ref {
  display: inline-block;
  font-size: 11px;
  font-weight: 600;
  color: var(--accent-blue-dark);
  text-decoration: none;
  margin-bottom: 5px;
  opacity: 0.9;
}
.reply-ref:hover { text-decoration: underline; opacity: 1; }
.bubble-flash { animation: bubbleFlash 1.2s ease; }
@keyframes bubbleFlash {
  0%   { box-shadow: 0 0 0 3px var(--brand); }
  100% { box-shadow: 0 1px 3px rgba(0, 0, 0, 0.08); }
}

/* ── Outbound ("you") messages ──────────────────────── */
.bubble-run-me { flex-direction: row-reverse; }
.bubble-run-me .bubble-sender { text-align: right; }
.bubble-me {
  background: rgba(47, 133, 90, 0.12);
  border-color: rgba(47, 133, 90, 0.24);
  border-radius: 16px 4px 16px 16px;
}
@media (prefers-color-scheme: dark) {
  .bubble-me {
    background: rgba(95, 185, 138, 0.16);
    border-color: rgba(95, 185, 138, 0.30);
  }
}

/* ── Attachment chips inside a bubble ───────────────── */
.bubble-attachments {
  list-style: none;
  margin: 0;
  padding: 0;
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
}
.bubble-text + .bubble-attachments { margin-top: 8px; }
.bubble-attachment {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  max-width: 100%;
  padding: 4px 10px;
  border-radius: 8px;
  background: rgba(0, 0, 0, 0.04);
  border: 1px solid var(--border);
  font-size: 12.5px;
}
.bubble-attachment-name {
  overflow: hidden;
  white-space: nowrap;
  text-overflow: ellipsis;
}
@media (prefers-color-scheme: dark) {
  .bubble-attachment { background: rgba(255, 255, 255, 0.06); }
}

/* ── Sender chat: cross-thread thread badges ────────── */
.sender-chat-intro {
  font-size: 13px;
  color: var(--text-muted);
  background: rgba(47, 133, 90, 0.06);
  border: 1px solid rgba(47, 133, 90, 0.20);
  border-radius: var(--radius);
  padding: 10px 14px;
  margin: 16px 24px 0;
}
.sender-chat-intro strong { color: var(--brand-dark); word-break: break-all; }
.thread-badge {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  max-width: 100%;
  margin-bottom: 6px;
  padding: 2px 9px;
  border-radius: 999px;
  background: rgba(44, 93, 124, 0.10);
  border: 1px solid rgba(44, 93, 124, 0.24);
  color: var(--accent-blue-dark);
  text-decoration: none;
  font-size: 11px;
  font-weight: 600;
  line-height: 1.5;
  transition: background 0.12s, border-color 0.12s;
}
.thread-badge:hover {
  background: rgba(44, 93, 124, 0.16);
  border-color: var(--accent-blue);
}
.thread-badge-icon { opacity: 0.7; flex-shrink: 0; }
.thread-badge-subject {
  overflow: hidden;
  white-space: nowrap;
  text-overflow: ellipsis;
}
@media (prefers-color-scheme: dark) {
  .sender-chat-intro {
    background: rgba(47, 133, 90, 0.12);
    border-color: rgba(47, 133, 90, 0.30);
  }
  .thread-badge {
    color: var(--accent-blue);
    background: rgba(127, 176, 210, 0.12);
    border-color: rgba(127, 176, 210, 0.30);
  }
}
@media (max-width: 640px) {
  .sender-chat-intro { margin: 12px 16px 0; }
}

/* ── Reply Area ─────────────────────────────────────── */
.reply-area {
  background: var(--surface);
  border-top: 1px solid var(--border);
  padding: 16px 24px;
  flex-shrink: 0;
}
.reply-form textarea {
  flex: 1;
  min-width: 0;
  min-height: 80px;
  padding: 10px 14px;
  border: 1px solid var(--border);
  border-radius: 8px;
  font-family: var(--font);
  font-size: 14px;
  resize: vertical;
  outline: none;
  color: var(--text);
  background: var(--bg);
  transition: border-color 0.15s, box-shadow 0.15s;
}
.reply-form textarea:focus {
  border-color: var(--brand);
  box-shadow: 0 0 0 3px rgba(47, 133, 90, 0.12);
  background: #fff;
}
.reply-form textarea.error { border-color: #dc2626; }
/* Optional subject line above the message — full width, matching the textarea. */
.reply-subject {
  width: 100%;
  margin-bottom: 8px;
  padding: 9px 14px;
  border: 1px solid var(--border);
  border-radius: 8px;
  font-family: var(--font);
  font-size: 14px;
  color: var(--text);
  background: var(--bg);
  outline: none;
  transition: border-color 0.15s, box-shadow 0.15s;
}
.reply-subject:focus {
  border-color: var(--brand);
  box-shadow: 0 0 0 3px rgba(47, 133, 90, 0.12);
  background: #fff;
}
.reply-subject:disabled { background: rgba(0, 0, 0, 0.04); color: var(--text-muted); cursor: not-allowed; }
/* Row under the message: reply toggle + attachment picker. */
.reply-meta {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 8px 14px;
  margin-top: 8px;
}
.reply-toggle {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  font-size: 13px;
  color: var(--text-muted);
  cursor: pointer;
}
.reply-toggle input { accent-color: var(--brand); }
/* Textarea + send button sit side by side; align-items:stretch makes the
   button exactly as tall as the (resizable) reply box, both inside the
   padded reply-area container. */
.reply-row {
  display: flex;
  align-items: stretch;
  gap: 12px;
}
.reply-send {
  flex-shrink: 0;
  align-self: stretch;
  display: inline-flex;
  align-items: center;
  justify-content: center;
}

/* Attachment picker under the reply row. */
.reply-attach {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 8px 12px;
  margin-top: 8px;
}
.reply-attach-btn {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 6px 12px;
  border: 1px solid var(--border);
  border-radius: 6px;
  background: var(--surface);
  color: var(--text);
  font-size: 13px;
  font-weight: 600;
  cursor: pointer;
  white-space: nowrap;
  transition: border-color 0.12s, background 0.12s;
}
.reply-attach-btn:hover { border-color: var(--brand); background: rgba(47, 133, 90, 0.06); }
.reply-attach-list {
  list-style: none;
  margin: 0;
  padding: 0;
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  min-width: 0;
}
.reply-attach-item {
  display: inline-flex;
  align-items: center;
  max-width: 240px;
  padding: 3px 10px;
  border-radius: 999px;
  background: rgba(44, 93, 124, 0.10);
  border: 1px solid rgba(44, 93, 124, 0.22);
  color: var(--accent-blue-dark);
  font-size: 12px;
  overflow: hidden;
  white-space: nowrap;
  text-overflow: ellipsis;
}
.field-error {
  font-size: 12px;
  color: #dc2626;
  margin-top: 4px;
}
.alert {
  padding: 10px 14px;
  border-radius: 6px;
  font-size: 14px;
  margin-bottom: 12px;
}
.alert-success {
  background: #ecfdf5;
  color: #065f46;
  border: 1px solid #a7f3d0;
}

/* Read-only reply area shown to teammates following a shared thread link. */
.reply-area-readonly {
  background: var(--bg);
  color: var(--text);
}
.reply-readonly-text {
  margin: 0;
  font-size: 13px;
  color: #475569;
  text-align: center;
}
@media (prefers-color-scheme: dark) {
  .reply-readonly-text { color: #94a3b8; }
}


/* ── Header Nav (replaces inline styles) ────────────── */
.header-nav {
  margin-left: auto;
  display: flex;
  gap: 12px;
  align-items: center;
}
.header-nav a {
  font-size: 14px;
  color: var(--brand);
  text-decoration: none;
  font-weight: 500;
}
.header-nav a:hover { text-decoration: underline; }
/* Buttons in the header are links too; keep their own contrasting text color
   instead of inheriting the brand-colored link text (which matched the
   brand-colored button background and made the label illegible). */
.header-nav a.btn-primary { color: var(--on-brand); }
.header-nav a.btn-primary:hover { color: var(--on-brand); text-decoration: none; }
.header-nav a.btn-secondary { color: var(--text); }
.header-nav a.btn-secondary:hover { text-decoration: none; }

/* ── Message count badge ────────────────────────────── */
.msg-count {
  font-size: 12px;
  color: var(--text-muted);
  white-space: nowrap;
  flex-shrink: 0;
}

/* ── Day Separator ──────────────────────────────────── */
.day-separator {
  display: flex;
  align-items: center;
  gap: 10px;
  color: var(--accent-brown);
  font-size: 11px;
  font-weight: 700;
  letter-spacing: 0.05em;
  text-transform: uppercase;
  padding: 6px 0;
  pointer-events: none;
  user-select: none;
  position: sticky;
  top: 0;
  background: var(--bg);
  /* The messages list uses a 20px flex gap; without this the gap above the
     pinned label is transparent and a scrolling bubble peeks over the date.
     The solid box-shadow paints that 20px strip so nothing shows above it. */
  box-shadow: 0 -20px 0 var(--bg);
  z-index: 6;
}
.day-separator::before,
.day-separator::after {
  content: '';
  flex: 1;
  height: 1px;
  background: var(--border);
}

/* ── Mobile ─────────────────────────────────────────── */
@media (max-width: 640px) {
  .thread-page { padding: 16px 12px; }
  .conv-header { padding: 10px 16px; }
  .messages { padding: 16px 16px 8px; }
  .reply-area { padding: 12px 16px; }
  .bubble { max-width: 100%; border-radius: 4px 14px 14px 14px; }
}

/* ── Keyboard focus indicator for thread list ──────── */
.thread-item.kb-focus {
  background: #eef2ff;
  outline: 2px solid var(--brand);
  outline-offset: -2px;
}

/* ── Keyboard shortcut hint ─────────────────────────── */
.kbd-hint {
  font-size: 12px;
  color: var(--text-muted);
  margin-left: auto;
  letter-spacing: 0.02em;
}
.kbd-hint kbd {
  display: inline-block;
  padding: 1px 5px;
  border: 1px solid var(--border);
  border-radius: 3px;
  font-size: 11px;
  font-family: var(--font);
  background: var(--bg);
  margin: 0 1px;
}

/* ── Dark Mode ──────────────────────────────────────── */
@media (prefers-color-scheme: dark) {
  /* "System" mode only — an explicit Light choice opts out so the OS can't
     force dark on it. Explicit Dark is handled by :root[data-theme="dark"]. */
  :root:not([data-theme="light"]) {
    /* Jungle after dark — deep forest charcoal, luminous green, with warmer
       brown and cooler blue accents lifted for contrast on the dark ground. */
    --bg: #0f1512;
    --surface: #161d18;
    --border: #2a342d;
    --text: #e6efe8;
    --text-muted: #8a978d;
    --brand: #5fb98a;
    --brand-dark: #4aa276;
    --on-brand: #0e211a;
    --accent-blue: #7fb0d2;
    --accent-blue-dark: #6fa3c6;
    --accent-brown: #c39a6f;
    --hover-bg: rgba(255, 255, 255, 0.06);
  }

  .thread-item:hover   { background: #1a2233; }
  .thread-item.kb-focus { background: #1a2a4a; outline-color: var(--brand); }
  .page-link:hover     { background: #1a2233; }
  .kbd-hint kbd        { background: var(--surface); }

  .bubble              { border-color: rgba(255, 255, 255, 0.05); }
  .bubble:hover        { box-shadow: 0 2px 10px rgba(0, 0, 0, 0.5); }

  .reply-form textarea {
    background: var(--bg);
    color: var(--text);
    border-color: var(--border);
  }
  .reply-form textarea:focus {
    background: #0d1117;
    box-shadow: 0 0 0 3px rgba(88, 166, 255, 0.15);
  }

  .alert-success {
    background: #0a2a1a;
    color: #6ee7b7;
    border-color: #064e3b;
  }

  .plan-card {
    background: var(--surface);
    border-color: var(--border);
  }
  .plan-card-featured {
    box-shadow: 0 4px 20px rgba(47, 133, 90, 0.25);
  }
  .billing-option {
    background: var(--surface);
    color: var(--text-muted);
    border-color: var(--border);
  }
  .billing-option.is-active {
    background: var(--brand);
    color: #fff;
  }
  .faq-item {
    background: var(--surface);
    border-color: var(--border);
  }
  .marketing-footer {
    border-top-color: var(--border);
  }

  .trial-banner {
    background: #14233f;
    border-color: #1f3a73;
    color: #cfe0ff;
  }
  .trial-banner-link { color: #7fd1a8; }
  .trial-banner-urgent {
    background: #3a2410;
    border-color: #7a4a18;
    color: #ffd9a8;
  }
  .lockout-banner {
    background: var(--surface);
    border-color: var(--border);
  }
  .modal-overlay { background: rgba(0, 0, 0, 0.65); }
  .modal-card { box-shadow: 0 20px 50px rgba(0, 0, 0, 0.55); }
  .plan-compare-col { background: #0d1117; }
  .plan-compare-featured {
    background: var(--surface);
    box-shadow: 0 2px 12px rgba(47, 133, 90, 0.2);
  }
  .billing-period-toggle {
    background: #0d1117;
  }
  .billing-period-toggle-btn-active {
    background: #1f2937;
    box-shadow: 0 1px 2px rgba(0, 0, 0, 0.45);
  }
  .billing-period-toggle-badge {
    background: rgba(16, 185, 129, 0.2);
    color: #6ee7b7;
  }
  .modal-cta-annual:hover {
    background: rgba(47, 133, 90, 0.18);
  }
}

/* ── Marketing pages (pricing, future landing) ─────── */
.marketing {
  max-width: 1100px;
  margin: 0 auto;
  padding: 48px 16px 80px;
}
.hero-narrow {
  text-align: center;
  margin-bottom: 40px;
}
.hero-narrow h1 {
  font-size: 36px;
  font-weight: 800;
  margin-bottom: 12px;
  letter-spacing: -0.02em;
}
.hero-sub {
  font-size: 18px;
  color: var(--text-muted);
  margin-bottom: 28px;
}

.billing-toggle {
  display: inline-flex;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 999px;
  padding: 4px;
  gap: 4px;
}
.billing-option {
  font: inherit;
  cursor: pointer;
  border: none;
  background: transparent;
  color: var(--text-muted);
  padding: 8px 18px;
  border-radius: 999px;
  font-size: 14px;
  font-weight: 600;
  transition: background 0.12s, color 0.12s;
}
.billing-option:hover { color: var(--text); }
.billing-option.is-active {
  background: var(--brand);
  color: #fff;
}
.save-badge {
  display: inline-block;
  margin-left: 6px;
  padding: 1px 6px;
  font-size: 11px;
  background: rgba(16, 185, 129, 0.15);
  color: #047857;
  border-radius: 4px;
  font-weight: 700;
}

.plan-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
  gap: 20px;
  margin-bottom: 64px;
}
.plan-card {
  position: relative;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 28px 22px;
  display: flex;
  flex-direction: column;
}
.plan-card-featured {
  border-color: var(--brand);
  box-shadow: 0 4px 20px rgba(47, 133, 90, 0.18);
  transform: translateY(-4px);
}
.plan-tag {
  position: absolute;
  top: -12px;
  left: 50%;
  transform: translateX(-50%);
  background: var(--brand);
  color: #fff;
  font-size: 11px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  padding: 4px 10px;
  border-radius: 999px;
  white-space: nowrap;
}
/* Free "limited time" badge — amber so it reads as an offer, not "most popular". */
.plan-tag-free { background: #b7791f; }
.plan-name {
  font-size: 16px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--text-muted);
  margin-bottom: 12px;
}
.plan-price {
  margin-bottom: 8px;
  display: flex;
  align-items: baseline;
  gap: 4px;
}
.price-amount {
  font-size: 36px;
  font-weight: 800;
  letter-spacing: -0.02em;
  color: var(--text);
}
.price-period {
  font-size: 14px;
  color: var(--text-muted);
}
.plan-annual-cash {
  display: none;
  margin: -2px 0 10px;
  font-size: 13px;
  font-weight: 600;
  color: var(--brand);
  letter-spacing: -0.005em;
}
.plan-annual-cash.is-visible { display: block; }
.plan-blurb {
  font-size: 14px;
  color: var(--text-muted);
  margin-bottom: 18px;
  min-height: 40px;
}
.plan-features {
  list-style: none;
  margin: 0 0 24px;
  padding: 0;
  flex: 1;
}
.plan-features li {
  position: relative;
  padding: 6px 0 6px 22px;
  font-size: 14px;
  border-bottom: 1px solid var(--border);
}
.plan-features li:last-child { border-bottom: none; }
.plan-features li::before {
  content: "✓";
  position: absolute;
  left: 0;
  top: 6px;
  color: var(--brand);
  font-weight: 700;
}
.plan-cta {
  width: 100%;
  text-align: center;
}

.faq {
  max-width: 720px;
  margin: 0 auto;
}
.faq h2 {
  font-size: 24px;
  font-weight: 700;
  margin-bottom: 20px;
  text-align: center;
}
.faq-item {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 14px 18px;
  margin-bottom: 10px;
}
.faq-item summary {
  cursor: pointer;
  font-weight: 600;
  font-size: 15px;
  list-style: none;
}
.faq-item summary::-webkit-details-marker { display: none; }
.faq-item[open] summary { margin-bottom: 8px; }
.faq-item p {
  color: var(--text-muted);
  font-size: 14px;
  line-height: 1.5;
}

.marketing-footer {
  max-width: 1100px;
  margin: 0 auto;
  padding: 24px 16px;
  border-top: 1px solid var(--border);
  display: flex;
  justify-content: space-between;
  font-size: 13px;
  color: var(--text-muted);
}
.marketing-footer nav { display: flex; gap: 16px; }
.marketing-footer a { color: var(--text-muted); text-decoration: none; }
.marketing-footer a:hover { color: var(--text); }

.nav-active { font-weight: 700; color: var(--brand); }

@media (max-width: 640px) {
  .plan-card-featured { transform: none; }
  .hero-narrow h1 { font-size: 28px; }
}

/* ── Auth pages (login / register) ──────────────────── */
.auth-page {
  max-width: 440px;
  margin: 0 auto;
  padding: 56px 16px;
}
.auth-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 32px;
  box-shadow: 0 1px 3px rgba(0, 0, 0, 0.04);
}
.auth-card h1 {
  font-size: 24px;
  font-weight: 700;
  margin-bottom: 8px;
}
.auth-sub {
  color: var(--text-muted);
  font-size: 14px;
  margin-bottom: 20px;
}
.auth-billing-badge {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  background: rgba(47, 133, 90, 0.08);
  border: 1px solid rgba(47, 133, 90, 0.30);
  border-radius: 8px;
  padding: 10px 14px;
  margin-bottom: 18px;
  font-size: 13px;
  font-weight: 600;
}
.auth-billing-badge-label { color: var(--brand); }
.auth-billing-badge-bonus {
  color: #047857;
  background: rgba(16, 185, 129, 0.15);
  padding: 2px 8px;
  border-radius: 999px;
  font-size: 11px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.04em;
}
.auth-form {
  display: flex;
  flex-direction: column;
  gap: 16px;
}
.auth-label {
  display: flex;
  flex-direction: column;
  gap: 6px;
  font-size: 14px;
  font-weight: 600;
}
.auth-label input[type="email"],
.auth-label input[type="password"],
.auth-label input[type="text"] {
  font: inherit;
  padding: 10px 12px;
  border: 1px solid var(--border);
  border-radius: 6px;
  background: var(--surface);
  color: var(--text);
}
.auth-label input:focus {
  outline: 2px solid var(--brand);
  outline-offset: -1px;
  border-color: var(--brand);
}
.auth-label input.error { border-color: #dc2626; }
.auth-hint, .auth-optional {
  color: var(--text-muted);
  font-size: 12px;
  font-weight: 400;
}
.auth-optional { font-style: normal; }
.auth-checkbox {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 14px;
  color: var(--text-muted);
}
.auth-submit { margin-top: 4px; }
.auth-alt {
  text-align: center;
  font-size: 14px;
  color: var(--text-muted);
  margin-top: 20px;
}
.auth-alt a { color: var(--brand); text-decoration: none; }
.auth-alt a:hover { text-decoration: underline; }

.btn-oauth {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 12px;
  width: 100%;
  padding: 11px 16px;
  font: inherit;
  font-weight: 600;
  font-size: 15px;
  color: var(--text);
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 6px;
  text-decoration: none;
  min-height: 44px;
  transition: background 0.12s, border-color 0.12s;
}
.btn-oauth:hover { background: rgba(47, 133, 90, 0.06); border-color: var(--brand); }
.btn-oauth:focus {
  outline: 2px solid var(--brand);
  outline-offset: 2px;
  border-color: var(--brand);
}
.btn-oauth-icon { width: 20px; height: 20px; flex-shrink: 0; }
.auth-divider {
  display: flex;
  align-items: center;
  gap: 12px;
  margin: 16px 0 4px;
  color: var(--text-muted);
  font-size: 12px;
  letter-spacing: 0.08em;
  text-transform: uppercase;
}
.auth-divider::before,
.auth-divider::after {
  content: '';
  flex: 1;
  height: 1px;
  background: var(--border);
}
.alert-error {
  background: #fef2f2;
  color: #b91c1c;
  border: 1px solid #fecaca;
  border-radius: 6px;
  padding: 10px 12px;
  font-size: 14px;
  margin-bottom: 16px;
}
.alert-info {
  background: #eff6ff;
  color: #1d4ed8;
  border: 1px solid #bfdbfe;
  border-radius: 6px;
  padding: 10px 12px;
  font-size: 14px;
  margin-bottom: 16px;
}

/* Header logout button — looks like the surrounding links */
.header-logout { display: inline; margin: 0; }
.link-button {
  background: none;
  border: none;
  color: inherit;
  font: inherit;
  cursor: pointer;
  padding: 0;
  text-decoration: none;
}
.link-button:hover { color: var(--brand); }

@media (prefers-color-scheme: dark) {
  .alert-error {
    background: #2a1414;
    color: #fecaca;
    border-color: #5a2a2a;
  }
  .alert-info {
    background: #0f1a30;
    color: #bfdbfe;
    border-color: #1e3a8a;
  }
}

/* ── Connect-a-mailbox wizard ───────────────────────── */
.wizard-page { max-width: 560px; }
.wizard-steps {
  list-style: none;
  display: flex;
  gap: 8px;
  margin: 0 0 24px;
  padding: 0;
  font-size: 12px;
  color: var(--text-muted);
}
.wizard-step {
  flex: 1;
  padding: 8px 10px;
  border-radius: 6px;
  background: var(--bg);
  text-align: center;
  border: 1px solid var(--border);
  font-weight: 600;
  letter-spacing: 0.01em;
}
.wizard-step.is-active {
  background: var(--brand);
  color: #fff;
  border-color: var(--brand);
}
.provider-grid {
  list-style: none;
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 12px;
  margin: 24px 0 16px;
  padding: 0;
}
.provider-card {
  display: flex;
  flex-direction: column;
  gap: 4px;
  padding: 16px;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 8px;
  text-decoration: none;
  color: var(--text);
  transition: border-color 0.12s, background 0.12s;
}
.provider-card:hover {
  border-color: var(--brand);
  background: var(--surface);
}
.provider-name { font-weight: 700; font-size: 15px; }
.provider-host { font-size: 12px; color: var(--text-muted); font-family: ui-monospace, SFMono-Regular, monospace; }
.provider-card-other { grid-column: 1 / -1; }

.wizard-advanced {
  border: 1px dashed var(--border);
  border-radius: 6px;
  padding: 8px 12px;
  font-size: 13px;
  color: var(--text-muted);
}
.wizard-advanced summary {
  cursor: pointer;
  font-weight: 600;
  padding: 4px 0;
  list-style: none;
}
.wizard-advanced summary::-webkit-details-marker { display: none; }
.wizard-advanced[open] { padding-bottom: 4px; }
.wizard-advanced[open] summary { margin-bottom: 8px; color: var(--text); }
.wizard-advanced .auth-label,
.wizard-advanced .auth-checkbox { margin-top: 10px; }

@media (max-width: 480px) {
  .provider-grid { grid-template-columns: 1fr; }
  .wizard-steps { font-size: 11px; }
}

@media (prefers-color-scheme: dark) {
  .provider-card { background: #0d1117; }
  .provider-card:hover { background: var(--surface); }
}

/* ── Mailboxes index: rows + sync-now ───────────────── */
.mailbox-row {
  display: flex;
  align-items: flex-start;
  gap: 16px;
  padding: 14px 20px;
  border-bottom: 1px solid var(--border);
  background: var(--surface);
}
.mailbox-row:last-child { border-bottom: none; }
.mailbox-row-main { flex: 1; min-width: 0; }
.mailbox-meta { display: block; }
.mailbox-error {
  margin-top: 6px;
  padding: 8px 10px;
  background: #fef2f2;
  border: 1px solid #fecaca;
  border-radius: 6px;
  font-size: 13px;
}
.mailbox-error-msg { color: #b91c1c; font-weight: 600; }
.mailbox-error-hint { color: #7f1d1d; margin-top: 2px; }
.mailbox-suspended-badge {
  display: inline-block;
  margin-left: 8px;
  padding: 2px 8px;
  font-size: 11px;
  font-weight: 600;
  letter-spacing: 0.02em;
  text-transform: uppercase;
  color: #92400e;
  background: #fef3c7;
  border: 1px solid #fcd34d;
  border-radius: 999px;
  vertical-align: middle;
}
.mailbox-sync-form { margin: 0; flex-shrink: 0; }
.mailbox-delete-form { margin: 0; flex-shrink: 0; }
.mailbox-actions {
  display: flex;
  flex-direction: column;
  gap: 8px;
  flex-shrink: 0;
}
.mailbox-remove-btn {
  width: 100%;
  padding: 6px 14px;
  font-size: 13px;
  background: var(--surface);
  color: #b91c1c;
  border: 1px solid var(--border);
}
.mailbox-remove-btn:hover { background: #fef2f2; border-color: #fecaca; }
@media (prefers-color-scheme: dark) {
  .mailbox-remove-btn { color: #fca5a5; }
  .mailbox-remove-btn:hover { background: #2a1414; border-color: #5a2a2a; }
}
.btn-secondary {
  background: var(--surface);
  color: var(--text);
  border: 1px solid var(--border);
}
.btn-secondary:hover { background: #f3f4f6; }
.mailbox-sync-btn { padding: 6px 14px; font-size: 13px; }
.mailbox-add-cta { margin-top: 24px; margin-bottom: 28px; }

@media (prefers-color-scheme: dark) {
  .mailbox-error {
    background: #2a1414;
    border-color: #5a2a2a;
  }
  .mailbox-error-msg { color: #fecaca; }
  .mailbox-error-hint { color: #fca5a5; }
  .mailbox-suspended-badge {
    color: #fde68a;
    background: #3a2a0a;
    border-color: #78551a;
  }
  .btn-secondary {
    background: var(--surface);
    color: var(--text);
    border-color: var(--border);
  }
  .btn-secondary:hover { background: #1f242c; }
}

@media (max-width: 480px) {
  .mailbox-row { flex-direction: column; align-items: stretch; gap: 10px; }
  .mailbox-sync-btn { width: 100%; }
}

/* ── Landing page ───────────────────────────────────── */
.btn-lg { padding: 12px 24px; font-size: 16px; }
.btn-compact { padding: 6px 14px; font-size: 13px; }

.landing { padding-top: 56px; }

.landing-hero {
  text-align: center;
  max-width: 760px;
  margin: 0 auto 56px;
}
.landing-hero h1 {
  font-size: 48px;
  font-weight: 800;
  letter-spacing: -0.03em;
  line-height: 1.08;
  margin-bottom: 18px;
}
.landing-hero-sub {
  font-size: 19px;
  line-height: 1.55;
  color: var(--text-muted);
  margin-bottom: 28px;
}
.landing-hero-ctas {
  display: inline-flex;
  gap: 12px;
  flex-wrap: wrap;
  justify-content: center;
  margin-bottom: 14px;
}
.landing-hero-fineprint {
  font-size: 13px;
  color: var(--text-muted);
}

.landing-screenshot {
  max-width: 640px;
  margin: 0 auto 80px;
  padding: 28px 24px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 16px;
  box-shadow: 0 10px 30px rgba(15, 23, 42, 0.08);
}
.screenshot-mock {
  display: flex;
  flex-direction: column;
  gap: 14px;
}
.mock-bubble {
  display: flex;
  align-items: flex-end;
  gap: 10px;
  max-width: 80%;
}
.mock-bubble-them { align-self: flex-start; }
.mock-bubble-me { align-self: flex-end; flex-direction: row-reverse; }
.mock-avatar {
  width: 36px;
  height: 36px;
  border-radius: 50%;
  background: var(--brand);
  color: var(--on-brand);
  font-size: 13px;
  font-weight: 700;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
}
.mock-bubble-body {
  background: var(--bg);
  border-radius: 14px;
  padding: 10px 14px;
}
.mock-bubble-me .mock-bubble-body {
  background: var(--brand);
  color: #fff;
}
.mock-sender {
  font-size: 12px;
  font-weight: 700;
  color: var(--text-muted);
  margin-bottom: 2px;
}
.mock-msg { font-size: 14px; line-height: 1.4; }
.mock-time {
  font-size: 11px;
  color: var(--text-muted);
  margin-top: 4px;
}
.mock-bubble-me .mock-time { color: rgba(255, 255, 255, 0.75); }

/* ── Landing demo video (click-to-play facade) ───────── */
.landing-video {
  max-width: 760px;
  margin: 0 auto 80px;
  padding: 0 16px;
}
.landing-video-wrap {
  position: relative;
  width: 100%;
  aspect-ratio: 16 / 9;
  background: #0d1117;
  border: 1px solid var(--border);
  border-radius: 16px;
  overflow: hidden;
  box-shadow: 0 10px 30px rgba(15, 23, 42, 0.12);
}
.landing-video-poster {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  border: 0;
  margin: 0;
  padding: 0;
  cursor: pointer;
  background-color: #0d1117;
  background-size: cover;
  background-position: center;
  background-repeat: no-repeat;
  color: #fff;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 14px;
  transition: filter 120ms ease;
}
.landing-video-poster:hover { filter: brightness(1.08); }
.landing-video-poster:focus-visible {
  outline: 3px solid var(--brand);
  outline-offset: -3px;
}
.landing-video-play {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 72px;
  height: 72px;
  border-radius: 50%;
  background: rgba(255, 255, 255, 0.95);
  color: var(--brand);
  font-size: 28px;
  padding-left: 6px;
  box-shadow: 0 6px 20px rgba(0, 0, 0, 0.35);
}
.landing-video-label {
  font-size: 14px;
  font-weight: 600;
  letter-spacing: 0.02em;
  background: rgba(0, 0, 0, 0.5);
  padding: 4px 10px;
  border-radius: 999px;
}
.landing-video-iframe {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  border: 0;
}
@media (max-width: 640px) {
  .landing-video-play { width: 56px; height: 56px; font-size: 22px; }
}

.landing-section-title {
  font-size: 28px;
  font-weight: 800;
  text-align: center;
  letter-spacing: -0.02em;
  margin-bottom: 32px;
}

.landing-features { margin-bottom: 80px; }
.feature-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(240px, 1fr));
  gap: 18px;
}
.feature-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 22px;
}
.feature-card h3 {
  font-size: 17px;
  font-weight: 700;
  margin-bottom: 8px;
}
.feature-card p {
  font-size: 14px;
  color: var(--text-muted);
  line-height: 1.5;
}
.feature-card code {
  font-size: 12px;
  background: var(--bg);
  padding: 1px 5px;
  border-radius: 4px;
}

.landing-how { margin-bottom: 80px; }
.how-steps {
  list-style: none;
  max-width: 640px;
  margin: 0 auto;
  padding: 0;
  display: flex;
  flex-direction: column;
  gap: 20px;
}
.how-steps li {
  display: flex;
  gap: 16px;
  align-items: flex-start;
}
.how-step-num {
  flex-shrink: 0;
  width: 36px;
  height: 36px;
  border-radius: 50%;
  background: var(--brand);
  color: #fff;
  font-weight: 700;
  display: flex;
  align-items: center;
  justify-content: center;
}
.how-steps h3 {
  font-size: 16px;
  font-weight: 700;
  margin-bottom: 4px;
}
.how-steps p {
  font-size: 14px;
  color: var(--text-muted);
  line-height: 1.5;
}

.landing-pricing-recap { margin-bottom: 80px; }
.pricing-recap-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
  gap: 16px;
  max-width: 820px;
  margin: 0 auto 18px;
}
.pricing-recap-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 22px;
  text-align: center;
}
.pricing-recap-card-featured {
  border-color: var(--brand);
  box-shadow: 0 4px 16px rgba(47, 133, 90, 0.15);
}
.pricing-recap-name {
  font-size: 13px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--text-muted);
  margin-bottom: 8px;
}
.pricing-recap-price {
  font-size: 28px;
  font-weight: 800;
  margin-bottom: 6px;
}
.pricing-recap-price span {
  font-size: 13px;
  font-weight: 500;
  color: var(--text-muted);
}
.pricing-recap-blurb {
  font-size: 13px;
  color: var(--text-muted);
}
.landing-pricing-link {
  text-align: center;
  font-size: 14px;
}
.landing-pricing-link a { color: var(--brand); font-weight: 600; text-decoration: none; }
.landing-pricing-link a:hover { text-decoration: underline; }

.landing-final-cta {
  text-align: center;
  padding: 56px 24px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 16px;
}
.landing-final-cta h2 {
  font-size: 28px;
  font-weight: 800;
  letter-spacing: -0.02em;
  margin-bottom: 10px;
}
.landing-final-cta p {
  font-size: 16px;
  color: var(--text-muted);
  margin-bottom: 22px;
}

/* ── Demo mode (anonymous /demo conversation) ─────────── */
.demo-banner {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 16px;
  background: linear-gradient(90deg, #2f855a 0%, #1f6f55 100%);
  color: #fff;
  padding: 10px 24px;
  font-size: 14px;
  line-height: 1.4;
}
.demo-banner-text { max-width: 720px; }
.demo-banner-text strong { font-weight: 700; }
.demo-banner .btn { flex-shrink: 0; }
.demo-banner .btn-primary {
  background: #fff;
  color: var(--brand-dark);
}
.demo-banner .btn-primary:hover { background: #f0f4ff; }

.demo-footer {
  background: var(--surface);
  border-top: 1px solid var(--border);
  padding: 24px;
  text-align: center;
}
.demo-footer-text {
  font-size: 15px;
  color: var(--text-muted);
  margin-bottom: 14px;
}
.demo-footer-ctas {
  display: flex;
  gap: 12px;
  justify-content: center;
  flex-wrap: wrap;
}
@media (max-width: 640px) {
  .demo-banner { flex-direction: column; align-items: stretch; text-align: center; gap: 10px; padding: 12px 16px; }
  .demo-banner .btn { align-self: center; }
}

@media (prefers-color-scheme: dark) {
  .landing-screenshot {
    box-shadow: 0 10px 40px rgba(0, 0, 0, 0.4);
  }
  .mock-bubble-body { background: #0d1117; }
  .feature-card,
  .pricing-recap-card,
  .landing-final-cta {
    background: var(--surface);
    border-color: var(--border);
  }
  .feature-card code { background: #0d1117; }
}

@media (max-width: 640px) {
  .landing-hero h1 { font-size: 34px; }
  .landing-hero-sub { font-size: 16px; }
  .landing-section-title { font-size: 22px; }
  .landing-final-cta h2 { font-size: 22px; }
  .btn-lg { padding: 10px 18px; font-size: 15px; }
}

/* ── Legal pages (privacy / terms / refund) ──────────── */
.legal-page {
  max-width: 760px;
  margin: 0 auto;
  padding: 40px 16px 56px;
}
.legal-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 40px 44px;
  box-shadow: 0 1px 3px rgba(0, 0, 0, 0.04);
}
.legal-card h1 {
  font-size: 28px;
  font-weight: 700;
  margin-bottom: 8px;
  color: var(--text);
}
.legal-body { color: var(--text); line-height: 1.65; font-size: 15px; }
.legal-body h2 {
  font-size: 19px;
  font-weight: 700;
  margin-top: 28px;
  margin-bottom: 10px;
  color: var(--text);
}
.legal-body h3 {
  font-size: 16px;
  font-weight: 600;
  margin-top: 20px;
  margin-bottom: 6px;
  color: var(--text);
}
.legal-body p { margin-bottom: 12px; }
.legal-body ul { margin: 0 0 12px 20px; }
.legal-body li { margin-bottom: 6px; }
.legal-body a { color: var(--brand); }
.legal-body code {
  font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
  font-size: 13px;
  background: rgba(0, 0, 0, 0.04);
  padding: 1px 5px;
  border-radius: 4px;
}
.legal-updated {
  font-size: 13px;
  color: var(--text-muted);
  margin-bottom: 20px;
}
.legal-note {
  margin-top: 28px;
  padding: 12px 14px;
  background: rgba(47, 133, 90, 0.06);
  border-left: 3px solid var(--brand);
  border-radius: 4px;
  font-size: 13px;
  color: var(--text-muted);
}

.auth-legal {
  margin-top: 16px;
  font-size: 12px;
  color: var(--text-muted);
  text-align: center;
}
.auth-legal a { color: var(--text-muted); text-decoration: underline; }
.auth-legal a:hover { color: var(--text); }

/* ── Cookie consent banner ───────────────────────────── */
.cookie-banner {
  position: fixed;
  left: 16px;
  right: 16px;
  bottom: 16px;
  z-index: 200;
  max-width: 720px;
  margin: 0 auto;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: 0 6px 24px rgba(0, 0, 0, 0.12);
  padding: 14px 18px;
  display: flex;
  align-items: center;
  gap: 16px;
  font-size: 14px;
  color: var(--text);
}
.cookie-banner[hidden] { display: none; }
.cookie-banner-text { flex: 1; line-height: 1.45; }
.cookie-banner a { color: var(--brand); }

@media (max-width: 560px) {
  .cookie-banner { flex-direction: column; align-items: stretch; text-align: left; }
  .cookie-banner-text { font-size: 13px; }
}

@media (prefers-color-scheme: dark) {
  .legal-card { background: var(--surface); border-color: var(--border); }
  .legal-body code { background: rgba(255, 255, 255, 0.08); }
  .legal-note {
    background: rgba(47, 133, 90, 0.12);
  }
  .cookie-banner {
    background: var(--surface);
    border-color: var(--border);
    box-shadow: 0 6px 24px rgba(0, 0, 0, 0.45);
  }
}

/* ── Inbox search ──────────────────────────────────── */
.visually-hidden {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
}
.inbox-search {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-bottom: 18px;
}
.inbox-search-input {
  flex: 1;
  min-width: 0;
  padding: 9px 12px;
  font-size: 14px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--surface);
  color: var(--text);
  outline: none;
  transition: border-color 0.15s, box-shadow 0.15s;
}
.inbox-search-input:focus {
  border-color: var(--brand);
  box-shadow: 0 0 0 3px rgba(99, 102, 241, 0.18);
}
.inbox-search-submit {
  padding: 9px 16px;
  font-size: 14px;
  flex-shrink: 0;
}
.inbox-search-clear {
  color: var(--text-muted);
  font-size: 13px;
  text-decoration: none;
  padding: 4px 8px;
  flex-shrink: 0;
}
.inbox-search-clear:hover { color: var(--text); text-decoration: underline; }

.search-empty {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 36px 20px;
  text-align: center;
}
.search-empty-title {
  font-size: 18px;
  font-weight: 700;
  margin-bottom: 6px;
  overflow-wrap: anywhere;
}
.search-empty-sub {
  color: var(--text-muted);
  font-size: 14px;
  margin-bottom: 18px;
}

.body-search-nag {
  display: flex;
  align-items: center;
  gap: 16px;
  background: linear-gradient(135deg, rgba(47, 133, 90, 0.10), rgba(58, 107, 224, 0.06));
  border: 1px solid rgba(47, 133, 90, 0.35);
  border-radius: var(--radius);
  padding: 14px 18px;
  margin-bottom: 16px;
}
.body-search-nag-text { flex: 1; display: flex; flex-direction: column; gap: 2px; }
.body-search-nag-text strong { color: var(--text); font-size: 14px; }
.body-search-nag-text span { color: var(--text-muted); font-size: 13px; overflow-wrap: anywhere; }
.body-search-nag-cta-form { margin: 0; flex-shrink: 0; }
.body-search-nag-cta { white-space: nowrap; }

@media (max-width: 560px) {
  .inbox-search { flex-wrap: wrap; }
  .inbox-search-input { flex-basis: 100%; }
  .inbox-search-submit { flex: 1; }
  .body-search-nag { flex-direction: column; align-items: stretch; }
  .body-search-nag-cta { width: 100%; }
}
@media (prefers-color-scheme: dark) {
  .inbox-search-input { background: var(--surface); }
  .inbox-search-input:focus {
    box-shadow: 0 0 0 3px rgba(47, 133, 90, 0.28);
  }
  .body-search-nag {
    background: linear-gradient(135deg, rgba(47, 133, 90, 0.18), rgba(58, 107, 224, 0.10));
    border-color: rgba(47, 133, 90, 0.45);
  }
}

/* ── Sender drill-down rail ──────────────────────────── */
.thread-layout { display: block; }
.thread-layout-with-rail {
  display: grid;
  grid-template-columns: 260px minmax(0, 1fr);
  gap: 24px;
  align-items: start;
}
.thread-main { min-width: 0; }
.sender-rail {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  position: sticky;
  top: 24px;
  max-height: calc(100vh - 48px);
  overflow-y: auto;
}
.sender-rail-details { padding: 4px 0; }
.sender-rail-summary {
  list-style: none;
  cursor: pointer;
  padding: 12px 16px 8px;
  font-size: 12px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: var(--text-muted);
  display: flex;
  align-items: center;
  justify-content: space-between;
}
.sender-rail-summary::-webkit-details-marker { display: none; }
.sender-rail-toggle-hint {
  transition: transform 0.15s;
  font-size: 11px;
}
.sender-rail-details:not([open]) .sender-rail-toggle-hint {
  transform: rotate(-90deg);
}
.sender-rail-row {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 8px 12px;
  text-decoration: none;
  color: var(--text);
  border-left: 3px solid transparent;
  transition: background 0.1s;
}
.sender-rail-row:hover { background: #f9fafb; }
.sender-rail-active {
  background: rgba(47, 133, 90, 0.10);
  border-left-color: var(--brand);
}
.sender-rail-avatar {
  width: 30px;
  height: 30px;
  border-radius: 50%;
  background: var(--brand);
  color: var(--on-brand);
  font-size: 12px;
  font-weight: 700;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
}
.sender-rail-avatar-everyone {
  background: var(--border);
  color: var(--text-muted);
  font-weight: 400;
  font-size: 18px;
  line-height: 1;
}
.sender-rail-text {
  flex: 1;
  min-width: 0;
  display: flex;
  flex-direction: column;
  gap: 1px;
}
.sender-rail-name {
  font-size: 13px;
  font-weight: 600;
  overflow: hidden;
  white-space: nowrap;
  text-overflow: ellipsis;
}
.sender-rail-email {
  font-size: 11px;
  color: var(--text-muted);
  overflow: hidden;
  white-space: nowrap;
  text-overflow: ellipsis;
}
.sender-rail-count {
  font-size: 12px;
  color: var(--text-muted);
  background: rgba(0, 0, 0, 0.04);
  border-radius: 10px;
  padding: 2px 8px;
  flex-shrink: 0;
}
.sender-rail-active .sender-rail-count {
  background: rgba(47, 133, 90, 0.20);
  color: var(--brand-dark);
}
.sender-pill {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 8px 14px;
  background: rgba(47, 133, 90, 0.08);
  border: 1px solid rgba(47, 133, 90, 0.30);
  border-radius: var(--radius);
  margin-bottom: 14px;
  font-size: 13px;
}
.sender-pill-label { flex: 1; color: var(--text); }
.sender-pill-label strong { color: var(--brand-dark); word-break: break-all; }
.sender-pill-chat {
  color: var(--brand-dark);
  text-decoration: none;
  font-size: 12px;
  font-weight: 600;
  white-space: nowrap;
  flex-shrink: 0;
}
.sender-pill-chat:hover { text-decoration: underline; }
.sender-pill-clear {
  color: var(--text-muted);
  text-decoration: none;
  font-size: 12px;
  flex-shrink: 0;
}
.sender-pill-clear:hover { color: var(--text); text-decoration: underline; }

@media (max-width: 760px) {
  .thread-layout-with-rail {
    grid-template-columns: 1fr;
    gap: 14px;
  }
  .sender-rail {
    position: static;
    max-height: none;
  }
  .sender-rail-details:not([open]) { padding-bottom: 4px; }
}
@media (prefers-color-scheme: dark) {
  .sender-rail-row:hover { background: rgba(255, 255, 255, 0.04); }
  .sender-rail-avatar-everyone {
    background: rgba(255, 255, 255, 0.10);
    color: var(--text-muted);
  }
  .sender-rail-count {
    background: rgba(255, 255, 255, 0.06);
  }
  .sender-rail-active {
    background: rgba(47, 133, 90, 0.18);
  }
  .sender-rail-active .sender-rail-count {
    background: rgba(47, 133, 90, 0.28);
    color: #bfe3cf;
  }
  .sender-pill {
    background: rgba(47, 133, 90, 0.14);
    border-color: rgba(47, 133, 90, 0.40);
  }
}

.filter-chips {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  align-items: center;
  margin: 0 0 14px;
}
.filter-chip {
  display: inline-block;
  padding: 6px 12px;
  border-radius: 999px;
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--text);
  font-size: 13px;
  text-decoration: none;
  line-height: 1.3;
  transition: background 120ms, border-color 120ms, color 120ms;
}
.filter-chip:hover {
  border-color: var(--brand);
  color: var(--brand-dark);
}
.filter-chip-active {
  background: var(--brand);
  border-color: var(--brand);
  color: #fff;
  font-weight: 600;
}
.filter-chip-active:hover {
  background: var(--brand-dark);
  border-color: var(--brand-dark);
  color: #fff;
}
.filter-chip-clear {
  font-size: 12px;
  color: var(--text-muted);
  text-decoration: none;
  margin-left: 4px;
}
.filter-chip-clear:hover { color: var(--text); text-decoration: underline; }

.thread-item-unread .thread-subject {
  font-weight: 700;
}
.thread-item-unread::before {
  content: "";
  display: inline-block;
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--brand);
  margin-right: 8px;
  vertical-align: middle;
}

@media (prefers-color-scheme: dark) {
  .filter-chip {
    background: var(--surface);
    border-color: var(--border);
  }
  .filter-chip:hover {
    border-color: var(--brand);
    color: #bfe3cf;
  }
}

/* ── Saved searches rail + save-form ─────────────────── */
.saved-search-row {
  display: flex;
  align-items: center;
  border-left: 3px solid transparent;
}
.saved-search-row:hover { background: #f9fafb; }
.saved-search-active {
  background: rgba(47, 133, 90, 0.10);
  border-left-color: var(--brand);
}
.saved-search-link {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 8px 12px;
  flex: 1;
  min-width: 0;
  text-decoration: none;
  color: var(--text);
}
.saved-search-icon {
  color: var(--accent-brown);
  font-size: 14px;
  width: 18px;
  text-align: center;
  flex-shrink: 0;
}
.saved-search-name {
  font-size: 13px;
  font-weight: 600;
  overflow: hidden;
  white-space: nowrap;
  text-overflow: ellipsis;
  min-width: 0;
}
.saved-search-active .saved-search-name { color: var(--brand-dark); }
.saved-search-count {
  font-size: 12px;
  color: var(--text-muted);
  background: rgba(0, 0, 0, 0.04);
  border-radius: 10px;
  padding: 2px 8px;
  margin-left: auto;
  flex-shrink: 0;
}
.saved-search-active .saved-search-count {
  background: rgba(47, 133, 90, 0.20);
  color: var(--brand-dark);
}
.saved-search-new {
  font-size: 11px;
  font-weight: 700;
  color: #fff;
  background: var(--brand);
  border-radius: 10px;
  padding: 2px 7px;
  margin-left: auto;
  flex-shrink: 0;
  line-height: 1;
  letter-spacing: 0.02em;
}
.saved-search-new + .saved-search-count { margin-left: 6px; }
.saved-search-delete-form {
  margin: 0;
  padding: 0 8px 0 0;
  display: flex;
  align-items: center;
}
.saved-search-delete {
  background: none;
  border: none;
  color: var(--text-muted);
  font-size: 18px;
  line-height: 1;
  cursor: pointer;
  padding: 4px 6px;
  border-radius: 4px;
}
.saved-search-delete:hover {
  color: #b91c1c;
  background: rgba(185, 28, 28, 0.08);
}

.save-search-form {
  display: flex;
  gap: 8px;
  align-items: center;
  background: rgba(47, 133, 90, 0.06);
  border: 1px dashed rgba(47, 133, 90, 0.40);
  border-radius: var(--radius);
  padding: 10px 12px;
  margin: 0 0 14px;
}
.save-search-name-input {
  flex: 1;
  min-width: 0;
  padding: 8px 12px;
  border: 1px solid var(--border);
  border-radius: 6px;
  background: var(--surface);
  color: var(--text);
  font-size: 14px;
  font-family: var(--font);
}
.save-search-name-input:focus {
  outline: none;
  border-color: var(--brand);
  box-shadow: 0 0 0 3px rgba(47, 133, 90, 0.18);
}
.save-search-submit { white-space: nowrap; }

.saved-search-flash {
  margin: 0 0 12px;
  padding: 10px 14px;
  border-radius: var(--radius);
  font-size: 14px;
}
.saved-search-flash-success {
  background: rgba(34, 197, 94, 0.10);
  border: 1px solid rgba(34, 197, 94, 0.35);
  color: #166534;
}
.saved-search-flash-error {
  background: rgba(220, 38, 38, 0.10);
  border: 1px solid rgba(220, 38, 38, 0.35);
  color: #b91c1c;
}

@media (max-width: 560px) {
  .save-search-form { flex-direction: column; align-items: stretch; }
  .save-search-submit { width: 100%; }
}
@media (prefers-color-scheme: dark) {
  .saved-search-row:hover { background: rgba(255, 255, 255, 0.04); }
  .saved-search-active { background: rgba(47, 133, 90, 0.18); }
  .saved-search-active .saved-search-name { color: #bfe3cf; }
  .saved-search-count { background: rgba(255, 255, 255, 0.06); }
  .saved-search-active .saved-search-count {
    background: rgba(47, 133, 90, 0.28);
    color: #bfe3cf;
  }
  .save-search-form {
    background: rgba(47, 133, 90, 0.10);
    border-color: rgba(47, 133, 90, 0.45);
  }
  .saved-search-flash-success { color: #86efac; }
  .saved-search-flash-error { color: #fca5a5; }
}

/* ── Account page ───────────────────────────────────── */
.account-page {
  max-width: 560px;
  margin: 0 auto;
  padding: 32px 16px 56px;
}
.account-title {
  font-size: 24px;
  font-weight: 700;
  margin-bottom: 20px;
}
.account-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 24px;
  box-shadow: 0 1px 3px rgba(0, 0, 0, 0.04);
  margin-bottom: 20px;
}
.account-card-title {
  font-size: 18px;
  font-weight: 700;
  margin-bottom: 12px;
}
.account-summary {
  display: grid;
  grid-template-columns: 140px 1fr;
  gap: 8px 16px;
  font-size: 14px;
}
.account-summary dt {
  color: var(--text-muted);
  font-weight: 600;
}
.account-summary dd {
  color: var(--text);
  word-break: break-all;
}
.account-verified-badge,
.account-unverified-badge {
  display: inline-block;
  font-size: 11px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  padding: 2px 8px;
  border-radius: 999px;
  margin-left: 6px;
  vertical-align: 1px;
}
.account-verified-badge {
  background: #dcfce7;
  color: #166534;
  border: 1px solid #bbf7d0;
}
.account-unverified-badge {
  background: #fef3c7;
  color: #92400e;
  border: 1px solid #fde68a;
}
@media (max-width: 520px) {
  .account-summary {
    grid-template-columns: 1fr;
    gap: 2px 0;
  }
  .account-summary dd { margin-bottom: 8px; }
}
.account-billing-actions {
  margin-top: 12px;
  margin-bottom: 0;
  font-size: 13px;
}
.danger-link { color: #b91c1c; }
.danger-link:hover { color: #7f1d1d; }
@media (prefers-color-scheme: dark) {
  .danger-link { color: #fca5a5; }
  .danger-link:hover { color: #fecaca; }
}
.cancel-reason-form { gap: 10px; }
.cancel-reason-option {
  display: flex;
  align-items: flex-start;
  gap: 10px;
  padding: 10px 12px;
  border: 1px solid var(--border);
  border-radius: 8px;
  cursor: pointer;
  font-size: 14px;
}
.cancel-reason-option input[type="radio"] {
  margin-top: 3px;
  flex-shrink: 0;
}
.cancel-reason-option:hover { border-color: var(--brand); }
.cancel-reason-actions {
  display: flex;
  align-items: center;
  gap: 16px;
  margin-top: 4px;
  flex-wrap: wrap;
}
@media (prefers-color-scheme: dark) {
  .account-verified-badge {
    background: rgba(34, 197, 94, 0.15);
    color: #86efac;
    border-color: rgba(34, 197, 94, 0.35);
  }
  .account-unverified-badge {
    background: rgba(245, 158, 11, 0.15);
    color: #fcd34d;
    border-color: rgba(245, 158, 11, 0.35);
  }
}
.account-activity {
  list-style: none;
  margin: 0;
  padding: 0;
  font-size: 14px;
}
.account-activity-row {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  gap: 12px;
  padding: 8px 0;
  border-bottom: 1px solid var(--border);
}
.account-activity-row:last-child {
  border-bottom: 0;
}
.account-activity-type {
  color: var(--text);
  font-weight: 600;
}
.account-activity-meta {
  color: var(--text-muted);
  font-size: 12px;
  text-align: right;
  white-space: nowrap;
}
.account-activity-ip {
  margin-left: 8px;
  font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
}

/* ── PWA install banner ────────────────────────────── */
.install-banner {
  position: fixed;
  left: 16px;
  right: 16px;
  bottom: 16px;
  z-index: 210;
  max-width: 560px;
  margin: 0 auto;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: 0 6px 24px rgba(0, 0, 0, 0.14);
  font-size: 14px;
  color: var(--text);
}
.install-banner[hidden] { display: none; }
.install-banner-body {
  display: flex;
  align-items: center;
  gap: 14px;
  padding: 12px 14px 12px 14px;
}
.install-banner-body[hidden] { display: none; }
.install-banner-mark {
  flex-shrink: 0;
  width: 36px;
  height: 36px;
  border-radius: 9px;
  background: var(--brand);
  color: #fff;
  font-weight: 700;
  letter-spacing: -0.02em;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 13px;
}
.install-banner-text {
  flex: 1;
  display: flex;
  flex-direction: column;
  gap: 2px;
  line-height: 1.35;
  min-width: 0;
}
.install-banner-title { color: var(--text); }
.install-banner-sub { color: var(--text-muted); font-size: 13px; }
.install-banner-share {
  display: inline-block;
  font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
  padding: 0 4px;
}
.install-banner-cta { flex-shrink: 0; }
.install-banner-dismiss {
  flex-shrink: 0;
  background: transparent;
  border: 0;
  color: var(--text-muted);
  font-size: 22px;
  line-height: 1;
  padding: 4px 8px;
  cursor: pointer;
  border-radius: 6px;
}
.install-banner-dismiss:hover { color: var(--text); background: rgba(0, 0, 0, 0.04); }

@media (max-width: 560px) {
  .install-banner { left: 8px; right: 8px; bottom: 8px; }
  .install-banner-body { flex-wrap: wrap; gap: 10px; padding: 12px; }
  .install-banner-text { flex-basis: 100%; order: -1; }
  .install-banner-cta { flex: 1; }
}

@media (prefers-color-scheme: dark) {
  .install-banner {
    background: var(--surface);
    border-color: var(--border);
    box-shadow: 0 6px 24px rgba(0, 0, 0, 0.5);
  }
  .install-banner-dismiss:hover { background: rgba(255, 255, 255, 0.06); }
}

/* ── Mobile audit (≤640px, 375px-viewport baseline) ──────────
   Safe-area insets for iOS notch/home bar (env() resolves to 0
   in non-standalone tabs so this is a no-op there), ≥44px tap
   targets per WCAG 2.5.5, sticky reply form via the 100dvh
   conv-body height set above, and a visible back-arrow button
   replacing the desktop text link. All wired through the
   existing --brand / --surface / --border tokens so dark mode
   inherits with no extra overrides. */

.app-header {
  padding-top: env(safe-area-inset-top, 0);
  padding-left: calc(24px + env(safe-area-inset-left, 0));
  padding-right: calc(24px + env(safe-area-inset-right, 0));
}
.conv-header {
  padding-top: calc(12px + env(safe-area-inset-top, 0));
  padding-left: calc(24px + env(safe-area-inset-left, 0));
  padding-right: calc(24px + env(safe-area-inset-right, 0));
}
.reply-area {
  padding-bottom: calc(16px + env(safe-area-inset-bottom, 0));
  padding-left: calc(24px + env(safe-area-inset-left, 0));
  padding-right: calc(24px + env(safe-area-inset-right, 0));
}

.admin-page {
  max-width: 960px;
  margin: 0 auto;
  padding: 32px 16px 56px;
}
.admin-title {
  font-size: 24px;
  font-weight: 700;
  margin-bottom: 4px;
}
.admin-sub {
  color: var(--text-muted);
  margin: 0 0 24px;
}
.admin-kpis {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
  gap: 12px;
  margin-bottom: 24px;
}
.admin-kpi {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 16px;
  display: flex;
  flex-direction: column;
  gap: 4px;
}
.admin-kpi-label {
  font-size: 12px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: var(--text-muted);
}
.admin-kpi-value {
  font-size: 24px;
  font-weight: 700;
  color: var(--text);
}
.admin-kpi-sub {
  font-size: 12px;
  color: var(--text-muted);
}
.admin-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 20px 24px;
  margin-bottom: 20px;
}
.admin-card-title {
  font-size: 16px;
  font-weight: 700;
  margin: 0 0 12px;
}
.admin-card-sub {
  font-size: 13px;
  color: var(--text-muted);
  margin: -8px 0 12px;
}
.admin-empty {
  color: var(--text-muted);
  font-size: 14px;
  margin: 0;
}
.admin-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 14px;
}
.admin-table th,
.admin-table td {
  padding: 8px 10px;
  border-bottom: 1px solid var(--border);
  text-align: left;
}
.admin-table th {
  font-weight: 700;
  color: var(--text-muted);
  font-size: 12px;
  text-transform: uppercase;
  letter-spacing: 0.04em;
}
.admin-table tr:last-child td {
  border-bottom: 0;
}
.admin-table .admin-num {
  text-align: right;
  font-variant-numeric: tabular-nums;
}
.admin-toolbar {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 16px 20px;
  margin-bottom: 24px;
}
.admin-toolbar-form {
  display: flex;
  align-items: center;
  gap: 12px;
  flex-wrap: wrap;
  margin: 0;
}
.admin-toolbar-hint {
  font-size: 13px;
  color: var(--text-muted);
}
.admin-toolbar-result {
  font-size: 13px;
  color: var(--text);
  margin: 12px 0 0;
}
.admin-btn {
  background: var(--brand);
  color: #fff;
  border: 0;
  border-radius: 8px;
  padding: 8px 14px;
  font-weight: 600;
  font-size: 14px;
  cursor: pointer;
  min-height: 36px;
}
.admin-btn:hover { filter: brightness(1.05); }
.admin-btn:focus-visible { outline: 2px solid var(--brand); outline-offset: 2px; }
.admin-btn-sm {
  padding: 4px 10px;
  font-size: 13px;
  min-height: 28px;
}
.admin-winback-form {
  margin: 0;
}
.admin-winback-sent {
  font-size: 13px;
  color: var(--text-muted);
  font-variant-numeric: tabular-nums;
}
.admin-winback-recovered {
  display: inline-block;
  padding: 2px 8px;
  font-size: 12px;
  font-weight: 600;
  letter-spacing: 0.02em;
  text-transform: uppercase;
  border-radius: 999px;
  background: #d1fae5;
  color: #065f46;
  border: 1px solid #6ee7b7;
}
.admin-winback-recovered-inline {
  text-transform: none;
  letter-spacing: 0;
  font-weight: 500;
}
@media (prefers-color-scheme: dark) {
  .admin-winback-recovered {
    background: #064e3b;
    color: #a7f3d0;
    border-color: #10b981;
  }
}

.admin-funnel-row {
  display: flex;
  align-items: stretch;
  gap: 12px;
  margin-bottom: 16px;
  flex-wrap: wrap;
}
.admin-funnel-step {
  flex: 1 1 160px;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 12px 14px;
  display: flex;
  flex-direction: column;
  gap: 2px;
  min-width: 140px;
}
.admin-funnel-label {
  font-size: 12px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: var(--text-muted);
}
.admin-funnel-count {
  font-size: 22px;
  font-weight: 700;
  color: var(--text);
}
.admin-funnel-rate {
  font-size: 12px;
  color: var(--text-muted);
}
.admin-funnel-delta {
  font-size: 12px;
  color: var(--text-muted);
  margin-top: 2px;
}
.admin-funnel-arrow {
  align-self: center;
  font-size: 18px;
  color: var(--text-muted);
}
@media (max-width: 560px) {
  .admin-funnel-arrow { display: none; }
}

@media (max-width: 640px) {
  .header-nav { gap: 4px; }
  .header-nav a,
  .header-nav .link-button {
    min-height: 44px;
    display: inline-flex;
    align-items: center;
    padding: 0 10px;
  }
  .kbd-hint { display: none; }

  .back-link {
    min-height: 44px;
    min-width: 44px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    border-radius: 8px;
    background: rgba(47, 133, 90, 0.10);
    font-size: 15px;
    padding: 0 12px;
  }
  .conv-header { gap: 10px; padding-bottom: 10px; }
  .conv-header h1 { font-size: 15px; }

  .thread-item {
    padding: 16px 18px;
    min-height: 64px;
  }

  .sender-rail-row { padding: 12px 14px; min-height: 44px; }
  .sender-rail-summary { padding: 14px 16px 10px; min-height: 44px; }
  .sender-pill-clear {
    min-height: 44px;
    display: inline-flex;
    align-items: center;
    padding: 0 10px;
  }

  .filter-chip,
  .filter-chip-clear {
    min-height: 44px;
    display: inline-flex;
    align-items: center;
    padding-left: 14px;
    padding-right: 14px;
  }

  .inbox-search-input,
  .inbox-search-submit { min-height: 44px; }
  .inbox-search-clear {
    min-height: 44px;
    display: inline-flex;
    align-items: center;
    padding: 0 10px;
  }

  /* Sticky reply form clears the iOS home bar; the 100dvh height on
     .conv-body keeps it above the on-screen keyboard. */
  .reply-area {
    position: sticky;
    bottom: 0;
    padding-top: 12px;
  }
  .reply-form textarea { min-height: 96px; font-size: 16px; }
  .reply-form .btn { min-height: 44px; padding: 10px 20px; }

  .page-link {
    min-height: 44px;
    display: inline-flex;
    align-items: center;
    padding: 0 14px;
  }
}

/* ── Sender chat workspace (left rail + chat pane) ───── */
.brand-link { text-decoration: none; }
.brand-link:hover { text-decoration: none; }

.workspace { display: block; }
.workspace-with-rail {
  margin-left: 248px;
  display: grid;
  grid-template-columns: 260px minmax(0, 1fr);
  height: 100vh;
  height: 100dvh;
}
/* In the full-height workspace the rail becomes a flush left column that
   scrolls on its own, rather than the rounded sticky card used on /threads. */
.workspace-with-rail .sender-rail {
  position: static;
  top: auto;
  height: 100%;
  max-height: none;
  border: none;
  border-right: 1px solid var(--border);
  border-radius: 0;
  overflow-y: auto;
}

.chat-pane {
  min-width: 0;
  display: flex;
  flex-direction: column;
  height: 100%;
  overflow: hidden;
}
/* When a sender signature is pinned, the workspace grows a third column for it.
   :has() keeps this scoped to pages that actually render the panel, so the
   2-column layout (e.g. /threads) is untouched. */
.workspace-with-rail:has(.signature-rail) {
  grid-template-columns: 260px minmax(0, 1fr) 300px;
}
.signature-rail {
  min-width: 0;
  height: 100%;
  overflow-y: auto;
  background: var(--surface);
  border-left: 1px solid var(--border);
  padding: 24px 20px;
}
.signature-card { position: sticky; top: 0; }
.signature-card-label {
  font-size: 12px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: var(--text-muted);
  margin-bottom: 10px;
}
.signature-card-name {
  font-size: 14px;
  font-weight: 600;
  margin-bottom: 2px;
}
.signature-card-email {
  font-size: 12px;
  color: var(--text-muted);
  word-break: break-word;
  margin-bottom: 12px;
}
.signature-card-empty {
  font-size: 13px;
  font-style: italic;
  color: var(--text-muted);
}
.signature-card-body {
  font-size: 13px;
  line-height: 1.5;
  color: var(--text-muted);
  word-break: break-word;
}
.signature-card-body a { color: var(--brand); }
.signature-card-body img { max-width: 100%; height: auto; }
.chat-subheader {
  display: flex;
  align-items: center;
  gap: 14px;
  padding: 12px 24px;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
}
.chat-subheader-avatar {
  width: 40px;
  height: 40px;
  border-radius: 50%;
  background: var(--brand);
  color: var(--on-brand);
  font-size: 14px;
  font-weight: 700;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  user-select: none;
}
.chat-subheader-id { flex: 1; min-width: 0; }
.chat-subheader-name {
  font-size: 16px;
  font-weight: 700;
  overflow: hidden;
  white-space: nowrap;
  text-overflow: ellipsis;
}
.chat-subheader-meta { font-size: 12px; color: var(--text-muted); }
.chat-view-toggle { flex-shrink: 0; white-space: nowrap; }

.chat-pane .messages {
  /* Fill the whole chat pane (base .messages padding keeps the side gutters)
     so bubbles can run full-width instead of a centered reading column. */
  width: 100%;
}

@media (max-width: 760px) {
  .workspace-with-rail {
    margin-left: 0;
    display: block;
    height: auto;
  }
  .workspace-with-rail .sender-rail {
    height: auto;
    border-right: none;
    border-bottom: 1px solid var(--border);
  }
  .chat-pane { height: auto; overflow: visible; }
  .chat-subheader { padding: 10px 16px; }
  .chat-pane .messages { padding: 16px 16px 8px; }
  /* Stacked block layout: the pinned panel drops below the chat. */
  .signature-rail {
    height: auto;
    border-left: none;
    border-top: 1px solid var(--border);
  }
  .signature-card { position: static; }
}

/* ── Texting-style chats list (/chats) ──────────────── */
.chats-screen {
  margin-left: 248px;
  max-width: 760px;
  padding: 24px 24px 64px;
}
.chats-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  margin-bottom: 16px;
  flex-wrap: wrap;
}
.chats-title { font-size: 24px; font-weight: 700; margin: 0; }
.chats-actions { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; }
.chats-new-btn { display: inline-flex; align-items: center; gap: 6px; white-space: nowrap; }

/* New-message compose page */
.compose-page { max-width: 640px; margin: 0; padding: 28px 28px 56px; }
.compose-header { display: flex; align-items: center; gap: 12px; margin-bottom: 18px; }
.compose-title { font-size: 22px; font-weight: 700; margin: 0; }
.compose-from {
  font-size: 13px;
  color: var(--text-muted);
  margin-left: auto;
  overflow: hidden;
  white-space: nowrap;
  text-overflow: ellipsis;
  max-width: 45%;
}
.compose-attach { margin: 4px 0; }
.compose-actions { display: flex; justify-content: flex-end; gap: 10px; margin-top: 10px; }
@media (max-width: 760px) {
  .compose-page { padding: 20px 16px 48px; }
}
.chats-notice { margin-bottom: 12px; }
/* Search styled to match the site's inputs: surface fill, soft border,
   brand focus ring. */
.chats-search { display: flex; align-items: center; gap: 8px; }
.chats-search input[type="search"] {
  width: 260px;
  max-width: 100%;
  padding: 9px 12px;
  font-size: 14px;
  color: var(--text);
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  transition: border-color 0.12s, box-shadow 0.12s;
}
.chats-search input[type="search"]::placeholder { color: var(--text-muted); }
.chats-search input[type="search"]:focus {
  outline: none;
  border-color: var(--brand);
  box-shadow: 0 0 0 3px rgba(47, 125, 87, 0.18);
}
.chats-search-clear {
  font-size: 13px;
  color: var(--text-muted);
  text-decoration: none;
}
.chats-search-clear:hover { color: var(--brand); text-decoration: underline; }
.chats-searching { font-size: 13px; color: var(--text-muted); margin: 0 0 12px; }
.chats-empty {
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  gap: 14px;
  color: var(--text-muted);
  padding: 32px 0;
}
.chat-list { list-style: none; margin: 0; padding: 0; }
.chat-list-row {
  display: flex;
  align-items: center;
  gap: 11px;
  padding: 9px 10px;
  text-decoration: none;
  color: var(--text);
  border-bottom: 1px solid var(--border);
}
.chat-list-row:hover { background: var(--hover-bg); }
.chat-list-row-active,
.chat-list-row-active:hover { background: rgba(47, 125, 87, 0.12); }
.chat-list-avatar {
  width: 38px;
  height: 38px;
  flex-shrink: 0;
  border-radius: 50%;
  background: var(--brand);
  color: var(--on-brand);
  font-size: 13px;
  font-weight: 700;
  display: flex;
  align-items: center;
  justify-content: center;
}
.chat-list-main { flex: 1; min-width: 0; display: flex; flex-direction: column; gap: 2px; }
.chat-list-top { display: flex; align-items: baseline; justify-content: space-between; gap: 10px; }
.chat-list-namewrap { display: flex; align-items: baseline; gap: 6px; flex: 1; min-width: 0; overflow: hidden; }
.chat-list-name {
  font-size: 14px;
  font-weight: 600;
  overflow: hidden;
  white-space: nowrap;
  text-overflow: ellipsis;
  min-width: 0;
  flex-shrink: 0;
  max-width: 60%;
}
.chat-list-sender {
  display: inline-flex;
  align-items: baseline;
  gap: 4px;
  min-width: 0;
  overflow: hidden;
}
.chat-list-sender-email {
  font-size: 12px;
  color: var(--text-muted);
  overflow: hidden;
  white-space: nowrap;
  text-overflow: ellipsis;
}
.chat-list-sender-more { font-size: 11px; color: var(--text-muted); flex-shrink: 0; }
.chat-list-time { font-size: 11.5px; color: var(--text-muted); flex-shrink: 0; white-space: nowrap; }
.chat-list-preview {
  font-size: 12.5px;
  color: var(--text-muted);
  overflow: hidden;
  white-space: nowrap;
  text-overflow: ellipsis;
}
.chat-list-badges { display: flex; flex-direction: column; align-items: flex-end; gap: 6px; flex-shrink: 0; }
.chat-list-group {
  font-size: 11px;
  color: var(--text-muted);
  background: rgba(0, 0, 0, 0.04);
  border-radius: 10px;
  padding: 1px 8px;
}
.chat-list-unread .chat-list-name { font-weight: 700; color: var(--brand-dark); }
.chat-list-unread .chat-list-preview { color: var(--text); font-weight: 500; }
.chats-pager {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 16px;
  margin-top: 20px;
}
.chats-pager-status { font-size: 13px; color: var(--text-muted); }

/* ── Single chat view (/chats/{key}) ────────────────── */
/* Columns: secondary conversation rail · chat pane · (optional) signatures. */
/* The unified chats workspace: the conversation list on the left, and the open
   conversation (or a placeholder) swapped in place on the right. With nothing
   open the list is wide (a roomy dashboard); selecting a chat animates it down
   to its compact width as the conversation slides in. */
.chat-workspace {
  margin-left: 248px;
  display: grid;
  grid-template-columns: min(760px, 58vw) minmax(0, 1fr);
  height: 100vh;
  height: 100dvh;
  transition: grid-template-columns 0.3s ease;
}
.chat-workspace.chat-open {
  grid-template-columns: 380px minmax(0, 1fr);
}
@media (prefers-reduced-motion: reduce) {
  .chat-workspace { transition: none; }
}
/* The right side holds the chat pane + signature panel (a 2-col grid when a
   chat is open) or a centered placeholder when nothing is selected. */
.chat-pane-wrap { min-width: 0; height: 100%; overflow: hidden; }
.chat-pane-wrap.has-chat { display: grid; grid-template-columns: minmax(0, 1fr) 340px; }
.chat-pane-wrap:not(.has-chat) { display: flex; align-items: center; justify-content: center; }
.chat-empty-pane { padding: 32px; text-align: center; color: var(--text-muted); }
.chat-empty-icon { font-size: 40px; opacity: 0.5; margin-bottom: 8px; }
.chat-empty-pane p { font-size: 14px; }

/* Conversation list rail. */
.chat-rail {
  min-width: 0;
  height: 100%;
  overflow-y: auto;
  background: var(--surface);
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
}
.chat-rail-head {
  position: sticky;
  top: 0;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  padding: 12px 14px;
  z-index: 1;
}
.chat-rail-head-top { display: flex; align-items: center; justify-content: space-between; gap: 8px; }
.chat-rail-title {
  font-size: 16px;
  font-weight: 700;
  color: var(--text);
}
.rail-search { display: block; margin-top: 10px; }
.rail-search input[type="search"] { width: 100%; }
.dash-tiles.rail-tiles { gap: 6px; margin: 10px 0 0; }
.rail-tiles .dash-tile { padding: 7px 6px; border-radius: 9px; align-items: center; text-align: center; }
.rail-tiles .dash-tile-count { font-size: 16px; }
.rail-tiles .dash-tile-label { font-size: 10.5px; }
.rail-empty { padding: 24px 14px; font-size: 13px; }
.rail-notice { margin: 10px 14px 0; }
.rail-pager { margin: auto 0 0; padding: 10px 14px; gap: 10px; }
/* The rail reuses the .chat-list row styling so opening a chat doesn't feel like
   a different screen — same rows, just a narrower scrolling column. */
.chat-rail-list { padding: 0; }
.chat-back {
  display: none;
  font-size: 20px;
  line-height: 1;
  text-decoration: none;
  color: var(--text-muted);
  padding: 4px 8px;
  border-radius: var(--radius);
}
.chat-back:hover { background: var(--hover-bg); color: var(--text); }

/* Group member list + per-person signature dropdowns in the side panel. */
.member-list { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 4px; }
.member-summary {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 8px 4px;
  cursor: pointer;
  list-style: none;
}
.member-summary::-webkit-details-marker { display: none; }
.member-summary-static { cursor: default; }
.member-avatar {
  width: 28px;
  height: 28px;
  flex-shrink: 0;
  border-radius: 50%;
  background: var(--brand);
  color: var(--on-brand);
  font-size: 11px;
  font-weight: 700;
  display: flex;
  align-items: center;
  justify-content: center;
}
.member-name {
  flex: 1;
  min-width: 0;
  display: flex;
  flex-direction: column;
}
.member-name-label {
  font-size: 13px;
  font-weight: 600;
  overflow: hidden;
  white-space: nowrap;
  text-overflow: ellipsis;
}
.member-name-email {
  font-size: 11px;
  color: var(--text-muted);
  overflow: hidden;
  white-space: nowrap;
  text-overflow: ellipsis;
}
.member-chevron { font-size: 11px; color: var(--text-muted); transition: transform 0.15s; }
.member-details[open] .member-chevron { transform: rotate(180deg); }
.member-signature { padding: 0 4px 10px 38px; }

@media (max-width: 760px) {
  .chats-screen { margin-left: 0; padding: 16px 16px 48px; }
  .chats-search input[type="search"] { width: 100%; }
  /* One column on phones: the list fills the screen, and opening a chat swaps to
     the pane full-width (the "←" back link returns to the list). */
  .chat-workspace { margin-left: 0; display: block; height: auto; }
  .chat-pane-wrap { display: none; }
  .chat-pane-wrap.has-chat { display: block; }
  .chat-workspace.chat-open .chat-rail { display: none; }
  .chat-back { display: inline-block; }
}

/* ── Left sidebar app shell ─────────────────────────── */
.app-shell { min-height: 100vh; }
.app-nav {
  position: fixed;
  top: 0;
  left: 0;
  bottom: 0;
  width: 248px;
  background: var(--surface);
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  gap: 4px;
  padding: 16px 12px;
  overflow-y: auto;
  z-index: 100;
}
.app-nav-brand {
  font-size: 20px;
  font-weight: 800;
  color: var(--brand);
  text-decoration: none;
  padding: 4px 10px 12px;
}
.app-nav-links { display: flex; flex-direction: column; gap: 2px; }
.app-nav-link {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 9px 10px;
  border-radius: 8px;
  color: var(--text);
  text-decoration: none;
  font-size: 14px;
  font-weight: 600;
}
.app-nav-link:hover { background: var(--hover-bg); }
.app-nav-link-active { background: rgba(47, 133, 90, 0.12); color: var(--brand-dark); }
.app-nav-link-button {
  width: 100%;
  background: none;
  border: none;
  cursor: pointer;
  font: inherit;
  text-align: left;
}
.app-nav-ico { width: 18px; text-align: center; flex-shrink: 0; }
.app-nav-form { margin: 0; }

.app-nav-section {
  margin-top: 14px;
  display: flex;
  flex-direction: column;
  gap: 2px;
}
.app-nav-divider {
  border: none;
  border-top: 1px solid var(--border);
  margin: 12px 4px;
}
.app-nav-section-title {
  font-size: 11px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--text-muted);
  padding: 4px 10px;
}
.app-nav-mailboxes { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 2px; }
.app-nav-mailbox {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 9px 10px;
  border-radius: 8px;
  color: var(--text);
  text-decoration: none;
  font-size: 14px;
  font-weight: 600;
}
.app-nav-mailbox:hover { background: var(--hover-bg); }
.app-nav-mailbox-active {
  background: rgba(47, 133, 90, 0.12);
  color: var(--brand-dark);
}
.app-nav-mailbox-active .app-nav-mailbox-ico { color: var(--brand-dark); opacity: 1; }
.app-nav-mailbox-ico {
  width: 18px;
  text-align: center;
  flex-shrink: 0;
  font-size: 13px;
  color: var(--text-muted);
  opacity: 0.85;
}
.app-nav-mailbox-addr { overflow: hidden; white-space: nowrap; text-overflow: ellipsis; }
.app-nav-empty { font-size: 13px; color: var(--text-muted); padding: 2px 10px 4px; }
.app-nav-add {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  margin-top: 4px;
  padding: 7px 10px;
  border-radius: 8px;
  border: 1px dashed var(--border);
  color: var(--brand-dark);
  text-decoration: none;
  font-size: 13px;
  font-weight: 600;
}
.app-nav-add:hover { border-color: var(--brand); background: rgba(47, 133, 90, 0.06); }

.app-nav-footer {
  margin-top: auto;
  padding-top: 12px;
  border-top: 1px solid var(--border);
  display: flex;
  align-items: center;
  gap: 8px;
}
.app-nav-profile { display: flex; align-items: center; gap: 8px; flex: 1; min-width: 0; }
.app-nav-avatar {
  width: 30px;
  height: 30px;
  border-radius: 50%;
  background: var(--brand);
  color: var(--on-brand);
  display: flex;
  align-items: center;
  justify-content: center;
  font-weight: 700;
  font-size: 13px;
  flex-shrink: 0;
}
.app-nav-name { font-size: 13px; font-weight: 600; overflow: hidden; white-space: nowrap; text-overflow: ellipsis; }
.app-nav-signout {
  background: none;
  border: 1px solid var(--border);
  border-radius: 6px;
  color: var(--text-muted);
  cursor: pointer;
  font: inherit;
  font-size: 12px;
  font-weight: 600;
  padding: 6px 10px;
  white-space: nowrap;
}
.app-nav-signout:hover { color: var(--text); border-color: var(--text-muted); }

/* Content area sits to the right of the fixed nav. */
.app-main { margin-left: 248px; min-height: 100vh; }
.app-main .thread-page { margin: 0; }

/* ── Settings: secondary nav beside the primary app nav ─────── */
.settings-shell { display: flex; align-items: stretch; min-height: 100vh; }
.settings-nav {
  width: 220px;
  flex-shrink: 0;
  border-right: 1px solid var(--border);
  padding: 28px 16px;
}
.settings-nav-title {
  font-size: 12px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--text-muted);
  padding: 0 12px 10px;
}
.settings-nav-group { display: flex; flex-direction: column; gap: 2px; }
.settings-nav-link {
  display: block;
  padding: 7px 12px;
  border-radius: 8px;
  color: var(--text);
  text-decoration: none;
  font-size: 13.5px;
  font-weight: 600;
}
.settings-nav-link:hover { background: var(--hover-bg); }
.settings-nav-link-active { background: rgba(47, 133, 90, 0.12); color: var(--brand-dark); }
.settings-content { flex: 1; min-width: 0; }

/* Settings pages: left-aligned and compact (not centered). */
.settings-page {
  max-width: 640px;
  margin: 0;
  padding: 28px 28px 56px;
}
.settings-page .account-title { font-size: 22px; font-weight: 700; margin-bottom: 4px; }
.settings-intro { color: var(--text-muted); font-size: 13.5px; margin: 0 0 22px; }

/* Compact the real (form) cards so they sit tighter and left-aligned. */
.settings-page .account-card { padding: 18px 20px; margin-bottom: 14px; }
.settings-page .account-card-title { font-size: 15px; margin-bottom: 12px; }

/* Flat, compact account page: no card boxes — sections split by a divider, and
   every field/value laid out as a left label + right control on one line. */
.account-flat .account-title { margin-bottom: 8px; }
.acct-section { padding: 16px 0; border-top: 1px solid var(--border); }
.acct-section-first { border-top: none; padding-top: 0; }
.acct-section-danger .acct-section-title { color: #b91c1c; }
.acct-section-title { font-size: 14px; font-weight: 700; margin: 0 0 10px; }
.acct-section-sub { font-size: 12.5px; color: var(--text-muted); margin: -4px 0 12px; }
.acct-row { display: flex; align-items: center; gap: 16px; padding: 4px 0; }
.acct-label {
  flex: 0 0 150px;
  font-size: 13px;
  font-weight: 600;
  color: var(--text-muted);
}
.acct-value { flex: 1; min-width: 0; font-size: 14px; }
.acct-form { margin-top: 2px; }
.acct-input {
  flex: 1;
  width: 100%;
  max-width: 300px;
  font: inherit;
  font-size: 14px;
  padding: 8px 11px;
  border: 1px solid var(--border);
  border-radius: 6px;
  background: var(--surface);
  color: var(--text);
}
.acct-input:focus { outline: 2px solid var(--brand); outline-offset: -1px; border-color: var(--brand); }
.acct-field { flex: 1; max-width: 300px; display: flex; flex-direction: column; gap: 4px; }
/* Submit row: aligned with the input column, button pinned bottom-right, in line
   with the hint (which is pushed to the left). */
.acct-row-foot { padding-top: 10px; }
.acct-foot {
  flex: 1;
  max-width: 300px;
  display: flex;
  align-items: center;
  gap: 16px;
  justify-content: flex-end;
}
.acct-foot .auth-hint { margin-right: auto; }
/* Coming-soon rows: title + desc on the left, the (disabled) control on the right. */
.acct-row-soon { align-items: center; justify-content: space-between; padding: 8px 0; }
.acct-soon-main { flex: 1; min-width: 0; }
.acct-soon-title {
  font-size: 13.5px;
  font-weight: 600;
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
}
.acct-soon-desc { font-size: 12.5px; color: var(--text-muted); margin-top: 2px; }
.acct-row-soon > :last-child { flex-shrink: 0; }
@media (max-width: 640px) {
  .acct-row { flex-direction: column; align-items: stretch; gap: 4px; }
  .acct-label { flex-basis: auto; }
  .acct-input, .acct-field { max-width: none; }
  .acct-row-action { align-items: flex-start; }
}

/* Coming-soon pill, used inline next to a row title. */
.settings-coming-soon {
  flex-shrink: 0;
  font-size: 10px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: var(--brand-dark);
  background: rgba(47, 133, 90, 0.12);
  border-radius: 999px;
  padding: 2px 8px;
  white-space: nowrap;
  vertical-align: middle;
}

/* Grouped setting rows: title + description on the left, a (disabled) control
   on the right. Compact, divider between rows. */
.settings-section {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  margin-bottom: 14px;
  overflow: hidden;
}
.settings-section-head { padding: 13px 18px; border-bottom: 1px solid var(--border); }
.settings-section-title { font-size: 14px; font-weight: 700; }
.settings-section-sub { font-size: 12.5px; color: var(--text-muted); margin-top: 2px; }
.settings-row {
  display: flex;
  align-items: center;
  gap: 16px;
  padding: 12px 18px;
}
.settings-row + .settings-row { border-top: 1px solid var(--border); }
.settings-row-main { flex: 1; min-width: 0; }
.settings-row-title {
  font-size: 13.5px;
  font-weight: 600;
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
}
.settings-row-desc { font-size: 12.5px; color: var(--text-muted); margin-top: 2px; line-height: 1.4; }
.settings-row-control { flex-shrink: 0; }
.settings-section-danger { border-color: #e7b4b4; }
.settings-section-danger .settings-section-title { color: #b91c1c; }

/* Disabled mock controls for the coming-soon rows. */
.settings-row-control .btn[disabled] { opacity: 0.55; cursor: not-allowed; }
.settings-switch {
  display: inline-block;
  position: relative;
  width: 38px;
  height: 22px;
  border-radius: 999px;
  background: var(--border);
  opacity: 0.7;
}
.settings-switch::after {
  content: "";
  position: absolute;
  top: 3px;
  left: 3px;
  width: 16px;
  height: 16px;
  border-radius: 50%;
  background: #fff;
  box-shadow: 0 1px 2px rgba(0, 0, 0, 0.2);
}
.settings-select {
  font: inherit;
  font-size: 13px;
  padding: 6px 10px;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--surface);
  color: var(--text-muted);
  opacity: 0.7;
  cursor: not-allowed;
}
.settings-swatch {
  display: inline-block;
  width: 22px;
  height: 22px;
  border-radius: 50%;
  background: var(--brand);
  opacity: 0.7;
  border: 2px solid var(--surface);
  box-shadow: 0 0 0 1px var(--border);
}
.danger-button { color: #b91c1c; border-color: #e7b4b4; }

/* Appearance: segmented theme control + accent swatches. */
.seg {
  display: inline-flex;
  border: 1px solid var(--border);
  border-radius: 8px;
  overflow: hidden;
  background: var(--surface);
}
.seg-option input { position: absolute; opacity: 0; pointer-events: none; }
.seg-option span {
  display: block;
  padding: 7px 14px;
  font-size: 13px;
  font-weight: 600;
  color: var(--text-muted);
  cursor: pointer;
  white-space: nowrap;
}
.seg-option + .seg-option span { border-left: 1px solid var(--border); }
.seg-option input:checked + span { background: var(--brand); color: var(--on-brand); }
.seg-option input:focus-visible + span { outline: 2px solid var(--brand); outline-offset: -2px; }

.settings-row-control-wide { flex: 1; }
.swatches { display: flex; flex-wrap: wrap; gap: 10px; }
.swatch {
  position: relative;
  display: inline-flex;
  align-items: center;
  gap: 8px;
  padding: 7px 13px 7px 9px;
  border: 1px solid var(--border);
  border-radius: 999px;
  cursor: pointer;
  font-size: 13px;
  font-weight: 600;
  color: var(--text);
}
.swatch input { position: absolute; opacity: 0; pointer-events: none; }
.swatch-dot {
  width: 16px;
  height: 16px;
  border-radius: 50%;
  background: var(--swatch, var(--brand));
  flex-shrink: 0;
  box-shadow: inset 0 0 0 1px rgba(0, 0, 0, 0.12);
}
.swatch:has(input:checked) { border-color: var(--swatch); box-shadow: 0 0 0 2px var(--swatch); }
.swatch:has(input:focus-visible) { outline: 2px solid var(--swatch); outline-offset: 2px; }
.swatch-green  { --swatch: #2f7d57; }
.swatch-blue   { --swatch: #2f7fe8; }
.swatch-teal   { --swatch: #1f9e8f; }
.swatch-purple { --swatch: #8a63e8; }
.swatch-rose   { --swatch: #db3f80; }
.swatch-orange { --swatch: #e0742e; }
.appearance-actions { margin-top: 6px; }

@media (prefers-color-scheme: dark) {
  .danger-button,
  .settings-section-danger .settings-section-title { color: #fca5a5; }
  .settings-section-danger { border-color: #5a2a2a; }
  .settings-switch::after { background: #e5e7eb; }
}

@media (max-width: 760px) {
  .settings-shell { flex-direction: column; }
  .settings-nav {
    width: auto;
    border-right: none;
    border-bottom: 1px solid var(--border);
    padding: 14px 16px;
  }
  .settings-nav-title { padding: 0 8px 8px; }
  .settings-nav-group { flex-direction: row; flex-wrap: wrap; gap: 6px; }
  .settings-page { padding: 24px 16px 48px; }
}

/* ── Chats: active-account heading + rail label ─────────────── */
.chats-heading { display: flex; align-items: baseline; gap: 10px; flex-wrap: wrap; min-width: 0; }
.chats-account {
  font-size: 13px;
  font-weight: 600;
  color: var(--text-muted);
  overflow: hidden;
  white-space: nowrap;
  text-overflow: ellipsis;
}
.chat-rail-account {
  display: block;
  font-size: 12px;
  color: var(--text-muted);
  overflow: hidden;
  white-space: nowrap;
  text-overflow: ellipsis;
  margin-top: 2px;
}
.chat-rail-head-top { display: flex; align-items: center; justify-content: space-between; gap: 8px; }
.chat-rail-new { white-space: nowrap; }

/* ── Dashboard: account list + triage tiles ─────────────── */
.app-nav-dashboard { font-weight: 700; }
.chats-account-all { font-weight: 600; }

.dash-tiles {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 10px;
  margin-bottom: 18px;
}
.dash-tile {
  display: flex;
  flex-direction: column;
  gap: 2px;
  padding: 12px 14px;
  border: 1px solid var(--border);
  border-radius: 12px;
  background: var(--surface);
  text-decoration: none;
  color: var(--text);
  transition: border-color 0.12s, background 0.12s;
}
.dash-tile:hover { border-color: var(--brand); }
.dash-tile-active { border-color: var(--brand); background: rgba(47, 133, 90, 0.08); }
.dash-tile-count { font-size: 22px; font-weight: 800; line-height: 1.1; }
.dash-tile-label { font-size: 12px; color: var(--text-muted); font-weight: 600; }
.dash-tile-unread .dash-tile-count { color: var(--brand-dark); }

/* Per-conversation account tag on the Dashboard. */
.chat-list-accounts { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 5px; }
.acct-badge {
  display: inline-block;
  max-width: 100%;
  padding: 2px 9px;
  border-radius: 999px;
  border: 1px solid var(--acct, var(--border));
  background: var(--acct-bg, transparent);
  font-size: 11px;
  font-weight: 600;
  color: var(--acct, var(--text-muted));
  overflow: hidden;
  white-space: nowrap;
  text-overflow: ellipsis;
}
.acct-color-0 { --acct: #2f855a; --acct-bg: rgba(47, 133, 90, 0.08); }
.acct-color-1 { --acct: #3182ce; --acct-bg: rgba(49, 130, 206, 0.08); }
.acct-color-2 { --acct: #b7791f; --acct-bg: rgba(183, 121, 31, 0.10); }
.acct-color-3 { --acct: #805ad5; --acct-bg: rgba(128, 90, 213, 0.08); }
.acct-color-4 { --acct: #d53f8c; --acct-bg: rgba(213, 63, 140, 0.08); }
.acct-color-5 { --acct: #319795; --acct-bg: rgba(49, 151, 149, 0.08); }

@media (max-width: 760px) {
  .dash-tiles { grid-template-columns: repeat(2, 1fr); }
}

@media (max-width: 760px) {
  .app-nav {
    position: static;
    width: auto;
    flex-direction: row;
    flex-wrap: wrap;
    align-items: center;
    gap: 4px 8px;
    padding: 10px 14px;
    border-right: none;
    border-bottom: 1px solid var(--border);
  }
  .app-nav-brand { padding: 0 8px 0 0; }
  .app-nav-links { flex-direction: row; flex-wrap: wrap; }
  /* Keep the account switcher reachable on phones — it's the primary chat
     navigation now — but lay it out as a wrapping row instead of a column. */
  .app-nav-section {
    flex-basis: 100%;
    flex-direction: row;
    flex-wrap: wrap;
    align-items: center;
    gap: 4px 8px;
    margin-top: 6px;
  }
  .app-nav-section-title { flex-basis: 100%; padding: 0 8px; }
  .app-nav-mailboxes { flex-direction: row; flex-wrap: wrap; }
  .app-nav-add { margin-top: 0; }
  .app-nav-divider { display: none; }
  .app-nav-footer { margin: 0 0 0 auto; padding: 0; border: none; }
  .app-nav-profile { display: none; }
  .app-main { margin-left: 0; }
}

/* ── Inbox list: sender + date per row ──────────────── */
.thread-list-head {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 16px;
}
.thread-list-head .section-title { margin-bottom: 0; }
.thread-item-head {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 12px;
}
.thread-date { font-size: 13px; color: var(--text-muted); white-space: nowrap; flex-shrink: 0; }
.thread-from {
  font-weight: 600;
  color: var(--brand-dark);
}
.thread-meta .thread-from::after {
  content: "·";
  margin: 0 6px 0 8px;
  color: var(--text-muted);
  font-weight: 400;
}
.thread-meta .thread-from:only-child::after { content: none; }

/* ── Accent color override ──────────────────────────────
   Last in the file so it wins over the light :root, the explicit
   :root[data-theme] blocks, AND the dark-mode media block (all equal
   specificity) in every theme. Only retints the brand. */
:root[data-accent="blue"]   { --brand: #2f7fe8; --brand-dark: #2568cc; --on-brand: #ffffff; }
:root[data-accent="teal"]   { --brand: #1f9e8f; --brand-dark: #178479; --on-brand: #ffffff; }
:root[data-accent="purple"] { --brand: #8a63e8; --brand-dark: #7445d8; --on-brand: #ffffff; }
:root[data-accent="rose"]   { --brand: #db3f80; --brand-dark: #c22e6c; --on-brand: #ffffff; }
:root[data-accent="orange"] { --brand: #e0742e; --brand-dark: #c25f1f; --on-brand: #ffffff; }
