/* ==========================================================================
   Cityland Email Audit CRM — shared styles
   One file for every screen. No framework (no Tailwind).
   Sections:
     1. Design tokens
     2. Base / reset
     3. Layout
     4. Top bar + tabs (nav)
     5. Page header
     6. Buttons
     7. Stat cards
     8. Panel, toolbar, search, chips, filters panel
     9. Mail table (+ mobile card layout)
    10. Badges, sender, recipients
    11. Pagination
    12. Empty state
    13. Message drawer (modal)
    14. Message detail page
    15. Motion (keyframes, reveal, reduced motion)
   ========================================================================== */

/* 1. Design tokens ======================================================== */
:root {
  /* Font */
  --font-sans: "Plus Jakarta Sans", system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;

  /* Surfaces */
  --color-bg: #F7F7FB;              /* page background */
  --color-surface: #FFFFFF;         /* cards, panels, top bar */
  --color-surface-muted: #FAFAFD;   /* table head, inputs, filter panel */
  --color-surface-sunken: #F3F3F8;  /* tab track, secondary hover */

  /* Borders */
  --color-border: #ECEBF5;          /* card borders */
  --color-border-strong: #E2E1EE;   /* inputs, secondary buttons */
  --color-divider: #F0EFF7;         /* section dividers inside panels */
  --color-row-divider: #F3F2F9;     /* table rows */
  --color-border-dashed: #DAD8EA;   /* preview box */

  /* Text */
  --color-text: #1E1B4B;            /* headings + body */
  --color-text-body: #3B3866;       /* recipients */
  --color-text-label: #4B4870;      /* form labels, chip text */
  --color-text-muted: #5B5880;      /* secondary text */
  --color-text-icon: #6E6B90;       /* search icon */
  --color-text-subtle: #9A97B5;     /* "—" empty cells. NOTE: 2.7:1 on white, below WCAG AA; use #77749A if you need AA */
  --color-text-disabled: #A9A7C2;

  /* Brand / primary (indigo) */
  --color-primary: #4F46E5;
  --color-primary-hover: #4338CA;
  --color-primary-ink: #3730A3;
  --color-primary-soft: #EEF0FF;
  --color-primary-border: #E4E2FB;
  --color-row-hover: #F5F4FF;
  --color-focus: #6366F1;
  --color-focus-ring: rgba(99, 102, 241, 0.15);

  /* Success (Received) */
  --color-success: #10B981;
  --color-success-ink: #047857;
  --color-success-soft: #E7F8F1;

  /* Warning (missing dates, pilot tag) */
  --color-warning: #F59E0B;
  --color-warning-ink: #B45309;
  --color-warning-strong: #92400E;
  --color-warning-deep: #78350F;
  --color-warning-soft: #FEF0D2;
  --color-warning-track: #FDE9C4;
  --color-warning-surface: #FFFBF3;
  --color-warning-border: #F6E3BF;

  /* Orange (sender avatar, top sender) */
  --color-orange-ink: #C2410C;
  --color-orange-soft: #FDEFE4;
  --color-avatar-user-bg: #FDE7D4;
  --color-avatar-user-ink: #9A3412;

  /* Overlay */
  --color-scrim: rgba(30, 27, 75, 0.28);

  /* Spacing scale (px) */
  --space-1: 4px;
  --space-1-5: 6px;
  --space-2: 8px;
  --space-2-5: 10px;
  --space-3: 12px;
  --space-3-5: 14px;
  --space-4: 16px;
  --space-5: 20px;
  --space-6: 24px;
  --space-8: 32px;
  --space-14: 56px;
  --space-18: 72px;

  /* Radii */
  --radius-xs: 9px;    /* tab link, tab pill */
  --radius-sm: 10px;   /* small buttons, icon tiles, pagination, filter inputs */
  --radius-md: 12px;   /* buttons, search, chips, tab track */
  --radius-lg: 14px;   /* sender card, preview box */
  --radius-xl: 16px;   /* empty-state icon */
  --radius-2xl: 18px;  /* stat cards */
  --radius-3xl: 20px;  /* table panel */
  --radius-pill: 999px;

  /* Shadows */
  --shadow-tab-pill: 0 2px 8px -2px rgba(79, 70, 229, 0.25), 0 0 0 1px var(--color-primary-border);
  --shadow-card-hover: 0 18px 40px -20px rgba(79, 70, 229, 0.35);
  --shadow-primary-hover: 0 10px 24px -10px rgba(79, 70, 229, 0.7);
  --shadow-drawer: -24px 0 60px -30px rgba(30, 27, 75, 0.45);

  /* Motion */
  --ease-out: cubic-bezier(0.16, 1, 0.3, 1);
  --dur-fast: 150ms;
  --dur-base: 250ms;
  --dur-slow: 450ms;

  /* Layout */
  --container-max: 1320px;
  --container-pad: 24px;
  --topbar-tab-width: 92px;
}

/* 2. Base / reset ========================================================= */
*,
*::before,
*::after { box-sizing: border-box; }

html { -webkit-text-size-adjust: 100%; }

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

body.is-locked { overflow: hidden; }

a { color: var(--color-primary); }
a:hover { color: var(--color-primary-ink); }

h1, h2, h3, p, dl, dd { margin: 0; }

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

:focus-visible { outline: 2px solid var(--color-focus); outline-offset: 2px; }

.icon { width: 18px; height: 18px; flex-shrink: 0; display: block; }

.visually-hidden {
  position: absolute !important;
  width: 1px; height: 1px;
  padding: 0; margin: -1px;
  overflow: hidden; clip: rect(0, 0, 0, 0);
  white-space: nowrap; border: 0;
}

.skip-link {
  position: absolute; left: var(--space-4); top: -48px; z-index: 100;
  padding: var(--space-2) var(--space-3);
  border-radius: var(--radius-sm);
  background: var(--color-primary); color: #FFFFFF; font-weight: 700; text-decoration: none;
}
.skip-link:focus { top: var(--space-3); color: #FFFFFF; }

.truncate { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }

/* 3. Layout =============================================================== */
.container {
  width: 100%;
  max-width: var(--container-max);
  margin: 0 auto;
  padding-inline: var(--container-pad);
}

.page {
  display: flex;
  flex-direction: column;
  gap: var(--space-6);
  padding-block: var(--space-8) var(--space-14);
}

/* 4. Top bar + tabs ======================================================= */
.topbar {
  background: var(--color-surface);
  border-bottom: 1px solid var(--color-border);
}

.topbar__inner {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: var(--space-4) var(--space-8);
  padding-block: var(--space-3);
}

.brand {
  display: flex; align-items: center; gap: var(--space-2-5);
  color: inherit; text-decoration: none;
}
.brand:hover { color: inherit; }

.brand__mark {
  width: 36px; height: 36px;
  border-radius: var(--radius-sm);
  background: var(--color-primary); color: #FFFFFF;
  display: flex; align-items: center; justify-content: center;
}
.brand__mark .icon { width: 20px; height: 20px; }

.brand__text { display: flex; flex-direction: column; line-height: 1.3; }
.brand__name { font-size: 16px; font-weight: 800; letter-spacing: -0.02em; }
.brand__tag  { font-size: 11px; font-weight: 600; color: var(--color-warning-ink); }

.tabs {
  flex: 1 1 560px;
  min-width: 0;
  overflow-x: auto;
  scrollbar-width: none;
}
.tabs::-webkit-scrollbar { display: none; }

.tabs__track {
  position: relative;
  width: max-content;
  padding: var(--space-1);
  background: var(--color-surface-sunken);
  border-radius: var(--radius-md);
}

.tabs__list {
  position: relative;
  z-index: 1;
  display: flex;
  gap: var(--space-1);
  margin: 0; padding: 0;
  list-style: none;
}

.tabs__pill {
  position: absolute;
  top: var(--space-1); left: 0;
  width: var(--topbar-tab-width);
  height: 38px;
  border-radius: var(--radius-xs);
  background: var(--color-surface);
  box-shadow: var(--shadow-tab-pill);
  transition: transform var(--dur-slow) var(--ease-out), width var(--dur-slow) var(--ease-out), opacity 120ms linear;
  pointer-events: none;
  /* Hidden until JS places it on the real active tab — otherwise it flashes on All */
  opacity: 0;
}
.tabs__track.is-ready .tabs__pill { opacity: 1; }

.tabs__link {
  display: flex; align-items: center; justify-content: center;
  min-width: var(--topbar-tab-width);
  height: 38px;
  padding: 0 var(--space-3);
  border-radius: var(--radius-xs);
  font-size: 14px; font-weight: 600;
  color: var(--color-text-muted);
  text-decoration: none;
  transition: color var(--dur-base), background-color var(--dur-base);
  position: relative;
  z-index: 2;
  cursor: pointer;
}
.tabs__link:hover {
  color: var(--color-text);
  background: rgba(255, 255, 255, 0.65);
}
.tabs__link:active { transform: translateY(0.5px); }
.tabs__link.is-active,
.tabs__link.is-active:hover {
  color: var(--color-primary);
  font-weight: 700;
  background: transparent; /* sliding pill is the active surface */
}

/* Until the sliding pill is ready, paint the active tab itself so All does not flash */
.tabs__track:not(.is-ready) .tabs__link.is-active {
  background: var(--color-surface);
  box-shadow: var(--shadow-tab-pill);
}

.user { display: flex; align-items: center; gap: var(--space-3); }
.user__identity { display: flex; align-items: center; gap: var(--space-2-5); }
.user__text { display: flex; flex-direction: column; line-height: 1.3; }
.user__name { font-size: 13px; font-weight: 700; }
.user__signout {
  padding: 0; border: 0; background: none;
  font-size: 12px; font-weight: 500;
  color: var(--color-primary);
  text-decoration: underline; cursor: pointer;
}
.user__signout:hover { color: var(--color-primary-ink); }

.avatar {
  width: 36px; height: 36px; border-radius: 50%;
  background: var(--color-avatar-user-bg); color: var(--color-avatar-user-ink);
  display: flex; align-items: center; justify-content: center;
  font-size: 14px; font-weight: 700;
}

.icon-btn {
  width: 40px; height: 40px;
  border-radius: var(--radius-sm);
  border: 1px solid var(--color-border);
  background: var(--color-surface);
  color: var(--color-text-label);
  display: inline-flex; align-items: center; justify-content: center;
  cursor: pointer;
  transition: background-color var(--dur-base), transform var(--dur-fast);
}
.icon-btn:hover { background: var(--color-surface-sunken); transform: translateY(-1px); }
.icon-btn--sm { width: 38px; height: 38px; color: var(--color-text); }
.icon-btn--sm .icon { width: 16px; height: 16px; }

/* 5. Page header ========================================================== */
.page-header {
  display: flex; flex-wrap: wrap;
  align-items: flex-end; justify-content: space-between;
  gap: var(--space-4);
}
.page-header__title { font-size: 34px; font-weight: 800; letter-spacing: -0.03em; line-height: 1.2; }
.page-header__subtitle { margin-top: var(--space-1-5); font-size: 15px; color: var(--color-text-muted); }
.page-header__actions { display: flex; flex-wrap: wrap; gap: var(--space-2-5); }

/* 6. Buttons ============================================================== */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: var(--space-2);
  height: 44px;
  padding: 0 18px;
  border-radius: var(--radius-md);
  border: 1px solid transparent;
  font-size: 14px; font-weight: 600;
  text-decoration: none;
  white-space: nowrap;
  cursor: pointer;
  transition: transform var(--dur-fast), box-shadow 200ms, background-color 200ms;
}
.btn .icon { width: 16px; height: 16px; }
.btn:hover { transform: translateY(-1px); }
.btn:active { transform: translateY(0) scale(0.98); }

.btn--primary { background: var(--color-primary); color: #FFFFFF; font-weight: 700; }
.btn--primary:hover { background: var(--color-primary-hover); color: #FFFFFF; box-shadow: var(--shadow-primary-hover); }

.btn--secondary { background: var(--color-surface); border-color: var(--color-border-strong); color: var(--color-text); }
.btn--secondary:hover { background: var(--color-surface-sunken); color: var(--color-text); }
.btn--danger { background: #b42318; border-color: #912018; color: #fff; }
.btn--danger:hover { background: #912018; color: #fff; }

.btn--toolbar { height: 42px; padding: 0 14px; font-size: 13px; }
.btn--sm { height: 38px; padding: 0 var(--space-4); border-radius: var(--radius-sm); font-size: 13px; }
.btn--lg { height: 46px; }
.btn--block { flex: 1 1 0; }

/* 7. Stat cards =========================================================== */
.stats {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(240px, 1fr));
  gap: var(--space-4);
}

.stat-card {
  display: flex; flex-direction: column; gap: var(--space-3-5);
  padding: var(--space-5);
  background: var(--color-surface);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-2xl);
  transition: transform var(--dur-base) var(--ease-out), box-shadow var(--dur-base);
}
.stat-card:hover { transform: translateY(-3px); box-shadow: var(--shadow-card-hover); }

.stat-card__head { display: flex; align-items: center; justify-content: space-between; gap: var(--space-3); }
.stat-card__label { font-size: 13px; font-weight: 600; color: var(--color-text-muted); }

.stat-card__icon {
  width: 36px; height: 36px;
  border-radius: var(--radius-sm);
  display: flex; align-items: center; justify-content: center;
  flex-shrink: 0;
}
.stat-card__icon--primary { background: var(--color-primary-soft); color: var(--color-primary); }
.stat-card__icon--success { background: var(--color-success-soft); color: var(--color-success-ink); }
.stat-card__icon--orange  { background: var(--color-orange-soft);  color: var(--color-orange-ink); }
.stat-card__icon--warning { background: var(--color-warning-soft); color: var(--color-warning-ink); }

.stat-card__value {
  font-size: 34px; font-weight: 800; letter-spacing: -0.03em; line-height: 1.2;
  font-variant-numeric: tabular-nums;
}
.stat-card__value--md { font-size: 26px; letter-spacing: -0.02em; }
.stat-card__value-row { display: flex; align-items: baseline; flex-wrap: wrap; gap: var(--space-2); }
.stat-card__value-aside { font-size: 14px; font-weight: 700; color: var(--color-orange-ink); }

.stat-card__foot { display: flex; flex-direction: column; gap: var(--space-1-5); }
.stat-card__meta { font-size: 12px; color: var(--color-text-muted); }
.stat-card__link { font-size: 12px; font-weight: 600; color: var(--color-warning-strong); }
.stat-card__link:hover { color: var(--color-warning-deep); }

.stat-card--warning { background: var(--color-warning-surface); border-color: var(--color-warning-border); }
.stat-card--warning .stat-card__label { color: var(--color-warning-strong); }
.stat-card--warning .stat-card__value { color: var(--color-warning-deep); }

.progress {
  height: 6px;
  border-radius: var(--radius-pill);
  overflow: hidden;
  background: var(--color-primary-soft);
}
.progress__bar {
  height: 100%;
  border-radius: inherit;
  background: var(--color-primary);
  transform-origin: left;
  animation: grow 1.2s var(--ease-out) 0.35s both;
}
.progress--success { background: var(--color-success-soft); }
.progress--success .progress__bar { background: var(--color-success); }
.progress--warning { background: var(--color-warning-track); }
.progress--warning .progress__bar { background: var(--color-warning); }

/* 8. Panel, toolbar, search, chips, filters panel ========================= */
.panel {
  background: var(--color-surface);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-3xl);
  overflow: hidden;
}

.toolbar {
  display: flex; flex-wrap: wrap; align-items: center; gap: var(--space-2-5);
  padding: var(--space-4) var(--space-5);
  border-bottom: 1px solid var(--color-divider);
}

.search { flex: 1 1 300px; position: relative; display: flex; align-items: center; }
.search__icon { position: absolute; left: 14px; color: var(--color-text-icon); pointer-events: none; }
.search__icon .icon { width: 17px; height: 17px; }
.search__kbd {
  position: absolute; right: var(--space-3);
  padding: 1px 6px;
  border: 1px solid var(--color-border-strong); border-radius: 6px;
  background: var(--color-surface);
  font-size: 11px; font-weight: 600; color: var(--color-text-muted);
  pointer-events: none;
}
.search .input { padding-left: 40px; padding-right: 40px; }

.input {
  width: 100%;
  height: 42px;
  padding: 0 14px;
  border-radius: var(--radius-md);
  border: 1px solid var(--color-border-strong);
  background: var(--color-surface-muted);
  font-size: 14px;
  color: var(--color-text);
  transition: border-color 200ms, box-shadow 200ms;
}
.input::placeholder { color: var(--color-text-muted); opacity: 1; }
.input:focus { outline: none; border-color: var(--color-focus); box-shadow: 0 0 0 4px var(--color-focus-ring); }

.chip-group { display: flex; flex-wrap: wrap; gap: var(--space-2-5); margin: 0; padding: 0; border: 0; min-width: 0; }

.chip { position: relative; display: inline-flex; }
.chip input { position: absolute; opacity: 0; width: 1px; height: 1px; pointer-events: none; }
.chip span {
  display: inline-flex; align-items: center;
  height: 42px;
  padding: 0 14px;
  border-radius: var(--radius-md);
  border: 1px solid var(--color-border-strong);
  background: var(--color-surface);
  font-size: 13px; font-weight: 600;
  color: var(--color-text-label);
  cursor: pointer;
  transition: background-color 200ms, border-color 200ms, color 200ms;
}
.chip span:hover { border-color: #C7C4F5; }
.chip input:checked + span { border-color: var(--color-primary); background: var(--color-primary-soft); color: var(--color-primary-ink); }
.chip input:focus-visible + span { outline: 2px solid var(--color-focus); outline-offset: 2px; }

.filters-panel {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(170px, 1fr));
  gap: var(--space-3);
  padding: var(--space-4) var(--space-5);
  background: var(--color-surface-muted);
  border-bottom: 1px solid var(--color-divider);
}
.filters-panel[hidden] { display: none; }
.filters-panel.is-animating { animation: panel-in 350ms var(--ease-out) both; }

.field { display: flex; flex-direction: column; gap: var(--space-1-5); font-size: 12px; font-weight: 600; color: var(--color-text-label); }
.field .input { height: 38px; padding: 0 var(--space-3); border-radius: var(--radius-sm); background: var(--color-surface); font-size: 13px; font-weight: 400; }
.field select.input { padding: 0 var(--space-2-5); }

.filters-panel__actions { display: flex; align-items: flex-end; gap: var(--space-2); }

/* 9. Mail table =========================================================== */
.table-wrap { overflow-x: auto; }

.mail-table {
  width: 100%;
  min-width: 1000px;
  border-collapse: collapse;
  table-layout: fixed;
}

.mail-table col.col-date        { width: 116px; }
.mail-table col.col-direction   { width: 128px; }
.mail-table col.col-ai          { width: 68px; }
.mail-table col.col-sender      { width: 26%; }
.mail-table col.col-recipients  { width: 28%; }
.mail-table col.col-subject     { width: auto; }
.mail-table col.col-attachments { width: 112px; }
.mail-table col.col-go          { width: 52px; }

.mail-table th,
.mail-table td {
  padding: var(--space-3-5) var(--space-1-5);
  text-align: left;
  vertical-align: middle;
}
.mail-table th:first-child,
.mail-table td:first-child { padding-left: var(--space-5); }
.mail-table th:last-child,
.mail-table td:last-child { padding-right: var(--space-5); }

.mail-table thead th {
  padding-block: var(--space-3);
  font-size: 12px; font-weight: 700;
  color: var(--color-text-muted);
  background: var(--color-surface-muted);
  border-bottom: 1px solid var(--color-divider);
}

.mail-row {
  border-bottom: 1px solid var(--color-row-divider);
  background-color: var(--color-surface);
  cursor: pointer;
  transition: background-color var(--dur-fast);
  animation: rise 500ms var(--ease-out) both;
  animation-delay: calc(360ms + min(var(--i, 0), 20) * 35ms);
}
.mail-row:hover { background-color: var(--color-row-hover); }
.mail-row:last-child { border-bottom: 0; }

.cell-date { font-size: 13px; font-weight: 500; color: var(--color-text); }
.cell-date .is-missing { font-weight: 600; color: var(--color-warning-ink); }

.cell-subject .subject-link {
  display: block;
  font-size: 14px; font-weight: 600;
  color: var(--color-text);
  text-decoration: none;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.cell-subject .subject-link:hover { color: var(--color-primary); }

.cell-attachments { font-size: 13px; }
.attach-count { display: inline-flex; align-items: center; gap: var(--space-1); font-weight: 600; color: var(--color-text-label); }
.attach-count .icon { width: 14px; height: 14px; }

.muted-dash { color: var(--color-text-subtle); }

.cell-go { color: var(--color-primary); }
.cell-go .icon { width: 16px; height: 16px; margin-left: auto; }
.row-go { display: block; opacity: 0; transform: translateX(-6px); transition: opacity 200ms, transform 200ms; }
.mail-row:hover .row-go,
.mail-row:focus-within .row-go { opacity: 1; transform: none; }

.mail-row--empty { cursor: default; animation: none; }
.mail-row--empty:hover { background-color: var(--color-surface); }

/* Mobile: rows become cards */
@media (max-width: 760px) {
  .mail-table { min-width: 0; table-layout: auto; }
  .mail-table colgroup,
  .mail-table thead { display: none; }
  .mail-table tbody { display: block; }

  .mail-row {
    display: grid;
    grid-template-columns: auto auto 1fr;
    grid-template-areas:
      "sender     sender     date"
      "subject    subject    subject"
      "recipients recipients recipients"
      "direction  ai         attachments";
    align-items: center;
    gap: var(--space-2) var(--space-3);
    padding: var(--space-3-5) var(--space-4);
  }
  .mail-row > td { display: block; padding: 0 !important; min-width: 0; }
  .mail-row .cell-sender      { grid-area: sender; }
  .mail-row .cell-date        { grid-area: date; text-align: right; font-size: 12px; }
  .mail-row .cell-subject     { grid-area: subject; }
  .mail-row .cell-recipients  { grid-area: recipients; }
  .mail-row .cell-direction   { grid-area: direction; }
  .mail-row .cell-ai          { grid-area: ai; }
  .mail-row .cell-attachments { grid-area: attachments; text-align: right; }
  .mail-row .cell-go          { display: none !important; }
  .mail-row .cell-ai::before,
  .mail-row .cell-attachments::before {
    content: attr(data-label) " ";
    font-size: 12px; font-weight: 600; color: var(--color-text-muted);
  }
  .mail-row--empty { display: block; padding: 0; }
  .mail-row--empty > td { padding: 0 !important; }
}

/* 10. Badges, sender, recipients ========================================== */
.badge {
  display: inline-flex; align-items: center; gap: var(--space-1-5);
  padding: 5px var(--space-2-5);
  border-radius: var(--radius-pill);
  font-size: 12px; font-weight: 700;
  white-space: nowrap;
}
.badge__dot { width: 6px; height: 6px; border-radius: 50%; background: currentColor; }
.badge--received { background: var(--color-success-soft); color: var(--color-success-ink); }
.badge--received .badge__dot { background: var(--color-success); }
.badge--sent { background: var(--color-primary-soft); color: var(--color-primary-ink); }
.badge--sent .badge__dot { background: var(--color-primary); }
.badge--ai { background: var(--color-warning-soft); color: var(--color-warning-strong); }

.sender { display: flex; align-items: center; gap: var(--space-2-5); min-width: 0; }
.sender__text { display: flex; flex-direction: column; min-width: 0; line-height: 1.35; }
.sender__name { font-size: 14px; font-weight: 700; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.sender__email { font-size: 12px; color: var(--color-text-muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }

.avatar-initial {
  flex-shrink: 0;
  width: 34px; height: 34px; border-radius: 50%;
  background: var(--color-orange-soft); color: var(--color-orange-ink);
  display: flex; align-items: center; justify-content: center;
  font-size: 13px; font-weight: 800;
}
.avatar-initial--lg { width: 40px; height: 40px; font-size: 15px; }

.recipients { display: flex; align-items: center; gap: var(--space-1-5); min-width: 0; }
.recipients__primary { font-size: 13px; color: var(--color-text-body); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.recipients__more {
  flex-shrink: 0;
  padding: 3px var(--space-2);
  border-radius: var(--radius-pill);
  background: var(--color-primary-soft); color: var(--color-primary);
  font-size: 11px; font-weight: 700;
}

/* 11. Pagination ========================================================== */
.pagination {
  display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between;
  gap: var(--space-3);
  padding: var(--space-3-5) var(--space-5);
  border-top: 1px solid var(--color-divider);
}
.pagination__summary { font-size: 13px; color: var(--color-text-muted); }
.pagination__summary strong { color: var(--color-text); }
.pagination__list { display: flex; flex-wrap: wrap; align-items: center; gap: var(--space-1-5); margin: 0; padding: 0; list-style: none; }
.pagination__ellipsis { padding: 0 2px; color: var(--color-text-subtle); }

.page-link {
  display: inline-flex; align-items: center; justify-content: center;
  min-width: 36px; height: 36px;
  padding: 0 var(--space-3);
  border-radius: var(--radius-sm);
  border: 1px solid var(--color-border);
  background: var(--color-surface);
  font-size: 13px; font-weight: 600;
  color: var(--color-text);
  text-decoration: none;
  transition: transform var(--dur-fast), background-color 200ms;
}
.page-link:hover { background: var(--color-surface-sunken); color: var(--color-text); transform: translateY(-1px); }
.page-link--num { width: 36px; padding: 0; }
.page-link.is-current { background: var(--color-primary); border-color: var(--color-primary); color: #FFFFFF; font-weight: 700; }
.page-link.is-current:hover { transform: none; background: var(--color-primary); }
.page-link.is-disabled { background: var(--color-surface-muted); color: var(--color-text-disabled); pointer-events: none; }

@media (max-width: 560px) {
  .pagination { justify-content: center; }
  .pagination__item--num:not(.is-current-item) { display: none; }
  .pagination__ellipsis { display: none; }
}

/* 12. Empty state ========================================================= */
.empty-state {
  display: flex; flex-direction: column; align-items: center; gap: var(--space-2);
  padding: var(--space-18) var(--space-5);
  text-align: center;
  animation: panel-in 350ms var(--ease-out) both;
}
.empty-state__icon {
  width: 56px; height: 56px;
  border-radius: var(--radius-xl);
  background: var(--color-primary-soft); color: var(--color-primary);
  display: flex; align-items: center; justify-content: center;
}
.empty-state__icon .icon { width: 26px; height: 26px; }
.empty-state__title { margin-top: var(--space-1-5); font-size: 17px; font-weight: 800; }
.empty-state__text { font-size: 14px; color: var(--color-text-muted); }
.empty-state .btn { margin-top: var(--space-2); }

/* 13. Message drawer (modal) ============================================== */
.drawer { position: fixed; inset: 0; z-index: 50; }
.drawer[hidden] { display: none; }

.drawer__scrim {
  position: absolute; inset: 0;
  width: 100%; height: 100%;
  border: 0; padding: 0;
  background: var(--color-scrim);
  cursor: pointer;
  animation: fade 300ms ease both;
}

.drawer__panel {
  position: absolute; top: 0; right: 0; bottom: 0;
  width: min(440px, 100%);
  overflow-y: auto;
  display: flex; flex-direction: column; gap: var(--space-5);
  padding: var(--space-6);
  background: var(--color-surface);
  box-shadow: var(--shadow-drawer);
  animation: drawer-in var(--dur-slow) var(--ease-out) both;
}

.drawer.is-closing .drawer__scrim { animation: fade-out 250ms ease both; }
.drawer.is-closing .drawer__panel { animation: drawer-out 300ms var(--ease-out) both; }

.drawer__head { display: flex; align-items: center; justify-content: space-between; }
.drawer__eyebrow { font-size: 12px; font-weight: 600; color: var(--color-text-muted); }
.drawer__title { margin-top: var(--space-1); font-size: 26px; font-weight: 800; letter-spacing: -0.02em; line-height: 1.25; overflow-wrap: anywhere; }
.drawer__actions { display: flex; gap: var(--space-2-5); }

.sender-card {
  display: flex; align-items: center; gap: var(--space-3);
  padding: var(--space-3-5);
  border-radius: var(--radius-lg);
  background: var(--color-surface-muted);
  border: 1px solid var(--color-divider);
}
.sender-card .sender__text { min-width: 0; }
.sender-card .sender__email { font-size: 13px; }

.meta-list {
  display: grid;
  grid-template-columns: 100px minmax(0, 1fr);
  gap: var(--space-2-5) var(--space-3);
  font-size: 14px;
}
.meta-list dt { font-weight: 600; color: var(--color-text-muted); }
.meta-list dd { overflow-wrap: anywhere; }
.meta-list .is-warning { font-weight: 600; color: var(--color-warning-ink); }

.preview-box {
  padding: var(--space-4);
  border-radius: var(--radius-lg);
  border: 1px dashed var(--color-border-dashed);
  font-size: 14px; line-height: 1.6;
  color: var(--color-text-label);
  overflow-wrap: anywhere;
}

/* 14. Message detail page ================================================= */
.back-link {
  display: inline-flex; align-items: center; gap: var(--space-1-5);
  font-size: 13px; font-weight: 600;
  color: var(--color-text-muted);
  text-decoration: none;
}
.back-link .icon { width: 16px; height: 16px; }
.back-link:hover { color: var(--color-primary); }

.detail-header { display: flex; flex-direction: column; gap: var(--space-4); }
.detail-header__top { display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between; gap: var(--space-3); }
.detail-header__title { font-size: 30px; font-weight: 800; letter-spacing: -0.03em; line-height: 1.2; overflow-wrap: anywhere; }

.detail-layout {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 360px;
  gap: var(--space-6);
  align-items: start;
}
@media (max-width: 960px) {
  .detail-layout { grid-template-columns: minmax(0, 1fr); }
}

.panel--padded { padding: var(--space-6); display: flex; flex-direction: column; gap: var(--space-5); }
.panel__title { font-size: 15px; font-weight: 800; }

.message-body { font-size: 15px; line-height: 1.7; color: var(--color-text-body); overflow-wrap: anywhere; }
.message-body__frame { display: block; width: 100%; min-height: 520px; border: 0; resize: vertical; }

.attachment-list { display: flex; flex-direction: column; gap: var(--space-2); margin: 0; padding: 0; list-style: none; }
.attachment {
  display: flex; align-items: center; gap: var(--space-3);
  padding: var(--space-3);
  border-radius: var(--radius-md);
  border: 1px solid var(--color-border);
  color: var(--color-text); text-decoration: none;
  transition: background-color var(--dur-fast);
}
.attachment:hover { background: var(--color-row-hover); color: var(--color-text); }
.attachment__icon {
  width: 36px; height: 36px; border-radius: var(--radius-sm);
  background: var(--color-primary-soft); color: var(--color-primary);
  display: flex; align-items: center; justify-content: center; flex-shrink: 0;
}
.attachment__icon .icon { width: 16px; height: 16px; }
.attachment__text { display: flex; flex-direction: column; min-width: 0; }
.attachment__name { font-size: 13px; font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.attachment__size { font-size: 12px; color: var(--color-text-muted); }

.detail-actions { display: flex; flex-direction: column; gap: var(--space-2-5); }
.detail-actions .btn { width: 100%; }
.flash-list { list-style: none; margin: 0 0 1rem; padding: 0; display: grid; gap: 0.5rem; }
.flash { padding: 0.75rem 1rem; border-radius: 10px; border: 1px solid var(--color-border); background: var(--color-surface); }
.flash--success { border-color: #abefc6; background: #ecfdf3; color: #067647; }
.flash--error { border-color: #fecdca; background: #fef3f2; color: #b42318; }

/* Small screens: general */
@media (max-width: 560px) {
  :root { --container-pad: 16px; }
  .page { padding-block: var(--space-6) var(--space-8); }
  .page-header__title { font-size: 28px; }
  .page-header__actions { width: 100%; }
  .page-header__actions .btn { flex: 1 1 0; }
  .toolbar { padding: var(--space-3) var(--space-4); }
  .chip-group { width: 100%; }
  .chip { flex: 1 1 0; }
  .chip span { width: 100%; justify-content: center; padding: 0 var(--space-2); }
  .btn--toolbar { width: 100%; }
  .filters-panel { padding: var(--space-4); }
  .drawer__panel { padding: var(--space-5); }
  .detail-header__title { font-size: 24px; }
}

/* 15. Motion ============================================================== */
@keyframes rise      { from { opacity: 0; transform: translateY(16px); } to { opacity: 1; transform: none; } }
@keyframes grow      { from { transform: scaleX(0); } to { transform: scaleX(1); } }
@keyframes fade      { from { opacity: 0; } to { opacity: 1; } }
@keyframes fade-out  { from { opacity: 1; } to { opacity: 0; } }
@keyframes panel-in  { from { opacity: 0; transform: translateY(-8px) scale(0.99); } to { opacity: 1; transform: none; } }
@keyframes drawer-in { from { transform: translateX(100%); } to { transform: none; } }
@keyframes drawer-out{ from { transform: none; } to { transform: translateX(100%); } }

/* Page-load entrance — short so tab navigation does not feel like a double blink */
.reveal { animation: rise 220ms var(--ease-out) both; animation-delay: 0s; }

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    animation-duration: 0.01ms !important;
    animation-delay: 0s !important;
    transition-duration: 0.01ms !important;
  }
}


/* AI insight panel on message detail */
.ai-insight-head{display:flex;justify-content:space-between;align-items:center;gap:.75rem;margin-bottom:.35rem}
.ai-insight .panel__title{margin-top:1rem}
