/* ==========================================================================
   Master Email Portal — Design System
   --------------------------------------------------------------------------
   1. Tokens          6. Sidebar
   2. Reset / base    7. Mail list
   3. Utilities       8. Email detail
   4. Controls        9. Login
   5. App shell      10. Responsive
   ========================================================================== */

/* ==========================================================================
   1. TOKENS
   ========================================================================== */

:root {
  /* Brand */
  --accent:            #0b57d0;
  --accent-hover:      #0842a0;
  --accent-soft:       #d3e3fd;
  --accent-border:     #a8c7fa;
  --accent-text:       #041e49;

  /* Surfaces */
  --bg:                #f6f8fc;
  --surface:           #ffffff;
  --surface-2:         #f2f6fc;
  --surface-3:         #e9eef6;
  --surface-hover:     #f5f8fd;
  --rail:              #f6f8fc;

  /* Ink */
  --text:              #1f1f1f;
  --text-2:            #444746;
  --text-3:            #5f6368;
  --text-4:            #80868b;

  /* Lines */
  --border:            #dadce0;
  --border-strong:     #c4c7c5;
  --border-soft:       #ebeef2;

  /* Status */
  --success:           #047857;
  --success-soft:      #ecfdf5;
  --danger:            #b91c1c;
  --danger-soft:       #fef2f2;
  --danger-border:     #fecaca;
  --warning:           #b45309;
  --warning-soft:      #fffbeb;

  /* Type */
  --font: "Google Sans", Roboto, -apple-system, BlinkMacSystemFont, "Segoe UI",
          Arial, "Noto Sans", sans-serif, "Apple Color Emoji", "Segoe UI Emoji";

  --fs-xs:   11px;
  --fs-sm:   12px;
  --fs-base: 13px;
  --fs-md:   14px;
  --fs-lg:   16px;
  --fs-xl:   20px;
  --fs-2xl:  24px;

  /* Space (4pt scale) */
  --s-1: 4px;  --s-2: 8px;  --s-3: 12px; --s-4: 16px;
  --s-5: 20px; --s-6: 24px; --s-8: 32px; --s-10: 40px;

  /* Radii */
  --r-sm: 6px; --r-md: 8px; --r-lg: 12px; --r-full: 999px;

  /* Elevation */
  --shadow-sm: 0 1px 2px rgba(16, 24, 40, .05);
  --shadow-md: 0 4px 12px rgba(16, 24, 40, .08);
  --shadow-lg: 0 12px 32px rgba(16, 24, 40, .14);

  /* Chrome */
  --topbar-h: 60px;
  --sidebar-w: 268px;
  --list-w: 400px;
  --row-py: 12px;          /* overridden by the density toggle */

  --ring: 0 0 0 3px rgba(11, 87, 208, .28);
  --speed: .16s;
}

/* Dark theme — applied via [data-theme="dark"], set by JS before first paint. */
[data-theme="dark"] {
  --accent:            #a8c7fa;
  --accent-hover:      #d3e3fd;
  --accent-soft:       #004a77;
  --accent-border:     #0842a0;
  --accent-text:       #d3e3fd;

  --bg:                #131314;
  --surface:           #1e1f20;
  --surface-2:         #232427;
  --surface-3:         #2d2f31;
  --surface-hover:     #272829;
  --rail:              #131314;

  --text:              #e3e3e3;
  --text-2:            #c4c7c5;
  --text-3:            #9aa0a6;
  --text-4:            #80868b;

  --border:            #333438;
  --border-strong:     #444746;
  --border-soft:       #2a2b2e;

  --success:           #34d399;
  --success-soft:      #04241c;
  --danger:            #fca5a5;
  --danger-soft:       #2a1215;
  --danger-border:     #6b2226;
  --warning:           #fbbf24;
  --warning-soft:      #2a1f05;

  --shadow-sm: 0 1px 2px rgba(0, 0, 0, .4);
  --shadow-md: 0 4px 12px rgba(0, 0, 0, .45);
  --shadow-lg: 0 12px 32px rgba(0, 0, 0, .55);

  --ring: 0 0 0 3px rgba(168, 199, 250, .35);
  color-scheme: dark;
}

/* Density */
[data-density="compact"] { --row-py: 7px; }

/* ==========================================================================
   2. RESET / BASE
   ========================================================================== */

*, *::before, *::after { box-sizing: border-box; }

html { -webkit-text-size-adjust: 100%; }

body {
  margin: 0;
  font-family: var(--font);
  font-size: var(--fs-md);
  line-height: 1.5;
  background: var(--bg);
  color: var(--text);
  -webkit-font-smoothing: antialiased;
}

a { color: inherit; text-decoration: none; }

h1, h2, h3, h4 { margin: 0; font-weight: 650; line-height: 1.25; }

img { max-width: 100%; }

/* One consistent focus treatment everywhere. */
:focus { outline: none; }
:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
  border-radius: var(--r-sm);
}

::selection { background: var(--accent-soft); color: var(--accent-text); }

/* Scrollbars */
* { scrollbar-width: thin; scrollbar-color: var(--border-strong) transparent; }
*::-webkit-scrollbar { width: 10px; height: 10px; }
*::-webkit-scrollbar-thumb {
  background: var(--border-strong);
  border-radius: var(--r-full);
  border: 3px solid transparent;
  background-clip: content-box;
}
*::-webkit-scrollbar-track { background: transparent; }

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    animation-duration: .01ms !important;
    transition-duration: .01ms !important;
  }
}

/* ==========================================================================
   3. UTILITIES
   ========================================================================== */

.sr-only {
  position: absolute; 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(--s-3); top: -100px; z-index: 999;
  background: var(--accent); color: #fff; padding: var(--s-3) var(--s-4);
  border-radius: var(--r-md); font-weight: 600; font-size: var(--fs-base);
  transition: top var(--speed);
}
.skip-link:focus { top: var(--s-3); }

.spacer { flex: 1; }
.muted  { color: var(--text-3); }

/* ==========================================================================
   4. CONTROLS
   ========================================================================== */

.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: var(--s-2);
  height: 36px; padding: 0 var(--s-4);
  border: 1px solid transparent; border-radius: var(--r-md);
  background: var(--accent); color: #fff;
  font: inherit; font-size: var(--fs-base); font-weight: 600;
  cursor: pointer; white-space: nowrap;
  transition: background var(--speed), border-color var(--speed), transform var(--speed);
}
.btn:hover  { background: var(--accent-hover); }
.btn:active { transform: translateY(1px); }

.btn--ghost {
  background: var(--surface); color: var(--text-2); border-color: var(--border-strong);
}
.btn--ghost:hover { background: var(--surface-3); color: var(--text); }

.btn--subtle { background: transparent; color: var(--text-2); border-color: transparent; }
.btn--subtle:hover { background: var(--surface-3); color: var(--text); }

.btn--sm   { height: 30px; padding: 0 var(--s-3); font-size: var(--fs-sm); }
.btn--icon { width: 36px; padding: 0; }
.btn--icon.btn--sm { width: 30px; }
.btn[aria-disabled="true"] { opacity: .4; pointer-events: none; }

.field {
  height: 36px; width: 100%; padding: 0 var(--s-3);
  border: 1px solid var(--border-strong); border-radius: var(--r-md);
  background: var(--surface); color: var(--text);
  font: inherit; font-size: var(--fs-base);
  transition: border-color var(--speed), box-shadow var(--speed);
}
.field:hover { border-color: var(--text-4); }
.field:focus { border-color: var(--accent); box-shadow: var(--ring); outline: none; }
.field::placeholder { color: var(--text-4); }

select.field {
  appearance: none; padding-right: var(--s-8); cursor: pointer;
  background-image: url("data:image/svg+xml;charset=utf8,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='12' viewBox='0 0 12 12'%3E%3Cpath d='M2.5 4.5L6 8l3.5-3.5' fill='none' stroke='%236b7280' stroke-width='1.6' stroke-linecap='round' stroke-linejoin='round'/%3E%3C/svg%3E");
  background-repeat: no-repeat; background-position: right var(--s-3) center;
}

.label {
  display: block; font-size: var(--fs-xs); font-weight: 650;
  color: var(--text-3); text-transform: uppercase; letter-spacing: .06em;
  margin-bottom: var(--s-2);
}

/* Badges & chips */
.badge {
  display: inline-flex; align-items: center; gap: var(--s-1);
  padding: 3px var(--s-2); border-radius: var(--r-sm);
  background: var(--surface-3); color: var(--text-2);
  font-size: var(--fs-xs); font-weight: 600; line-height: 1.5;
  white-space: nowrap; max-width: 200px;
  overflow: hidden; text-overflow: ellipsis;
}
.badge--accent { background: var(--accent-soft); color: var(--accent-text); }
.badge--attach { background: var(--success-soft); color: var(--success); }

.chip {
  display: inline-flex; align-items: center; gap: var(--s-2);
  height: 28px; padding: 0 var(--s-1) 0 var(--s-3);
  border: 1px solid var(--accent-border); border-radius: var(--r-full);
  background: var(--accent-soft); color: var(--accent-text);
  font-size: var(--fs-sm); font-weight: 600; max-width: 320px;
}
.chip__text { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.chip__x {
  display: inline-flex; align-items: center; justify-content: center; flex-shrink: 0;
  width: 20px; height: 20px; border-radius: var(--r-full);
  color: inherit; opacity: .6; font-size: 15px; line-height: 1;
}
.chip__x:hover { opacity: 1; background: rgba(0, 0, 0, .08); }
[data-theme="dark"] .chip__x:hover { background: rgba(255, 255, 255, .12); }

mark {
  background: #fef08a; color: #713f12;
  padding: 0 2px; border-radius: 3px; font-weight: 600;
}
[data-theme="dark"] mark { background: #78500a; color: #fef3c7; }

/* Panel */
.panel {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--r-lg);
  box-shadow: var(--shadow-sm);
}

kbd {
  display: inline-block; min-width: 20px; padding: 2px 6px;
  border: 1px solid var(--border-strong); border-bottom-width: 2px;
  border-radius: var(--r-sm); background: var(--surface-2);
  font-family: var(--font); font-size: var(--fs-xs); font-weight: 600;
  color: var(--text-3); text-align: center; line-height: 1.4;
}

/* ==========================================================================
   5. APP SHELL
   ========================================================================== */

.topbar {
  position: sticky; top: 0; z-index: 60;
  height: var(--topbar-h);
  display: flex; align-items: center; gap: var(--s-4);
  padding: 0 var(--s-4);
  background: var(--rail);
}

.topbar__lead { display: flex; align-items: center; gap: var(--s-2); flex-shrink: 0; }

.brand { display: flex; align-items: center; gap: var(--s-2); min-width: 0; }
.brand__mark {
  display: grid; place-items: center;
  width: 34px; height: 34px; flex-shrink: 0;
  border-radius: var(--r-md);
  background: linear-gradient(135deg, #0b57d0, #1a73e8);
  color: #fff; font-size: 17px;
}
.brand__name {
  font-size: 20px; font-weight: 400; color: var(--text-2); letter-spacing: .01em;
}

.topbar__actions { display: flex; align-items: center; gap: var(--s-2); margin-left: auto; }

.user-avatar {
  display: grid; place-items: center; width: 32px; height: 32px; flex-shrink: 0;
  border: 0; padding: 0;
  border-radius: var(--r-full); background: var(--accent); color: #fff;
  font: inherit; font-size: var(--fs-base); font-weight: 700;
  cursor: pointer;
  transition: box-shadow var(--speed);
}
.user-avatar:hover { box-shadow: 0 0 0 4px var(--surface-3); }
.user-avatar--lg { width: 40px; height: 40px; font-size: var(--fs-md); cursor: default; }

.user-menu { position: relative; }
.user-menu > summary { list-style: none; }
.user-menu > summary::-webkit-details-marker,
.user-menu > summary::marker { display: none; }
.user-menu[open] > .user-avatar { box-shadow: 0 0 0 4px var(--surface-3); }

.user-menu__panel {
  position: absolute; top: calc(100% + 8px); right: 0; z-index: 70;
  width: min(280px, calc(100vw - 24px));
  padding: var(--s-3);
  border: 1px solid var(--border); border-radius: var(--r-lg);
  background: var(--surface); color: var(--text);
  box-shadow: var(--shadow-lg);
}
.user-menu__id {
  display: flex; align-items: center; gap: var(--s-3);
  padding: var(--s-2) var(--s-2) var(--s-3);
  border-bottom: 1px solid var(--border-soft);
}
.user-menu__copy { min-width: 0; }
.user-menu__name {
  margin: 0; font-size: var(--fs-base); font-weight: 600;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.user-menu__meta { margin: 2px 0 0; font-size: var(--fs-sm); color: var(--text-3); }
.user-menu__item {
  display: flex; align-items: center;
  margin-top: var(--s-2); padding: 10px var(--s-3);
  border-radius: var(--r-md);
  color: var(--danger); font-size: var(--fs-base); font-weight: 600;
  text-decoration: none;
}
.user-menu__item:hover { background: var(--danger-soft); }

.sheet__copy { margin: 0; color: var(--text-2); font-size: var(--fs-base); line-height: 1.45; }
.sheet__actions {
  display: flex; justify-content: flex-end; gap: var(--s-2);
  margin-top: var(--s-5);
}
.btn--danger { background: #c5221f; color: #fff; }
.btn--danger:hover { background: #a50e0e; }


/* ---------------------------------------------------------------- search
   Gmail puts search in the top bar and hangs the advanced options off it
   as a dropdown, so the page below stays purely list + message.
   ----------------------------------------------------------------------- */

.searchbar {
  position: relative;
  display: flex; align-items: center; gap: var(--s-2);
  flex: 1 1 auto; max-width: 760px; min-width: 0;
}

.searchbar__field {
  flex: 1; min-width: 0;
  display: flex; align-items: center; gap: var(--s-2);
  height: 46px; padding: 0 var(--s-2) 0 var(--s-4);
  border-radius: var(--r-lg);
  background: var(--surface-3);
  transition: background var(--speed), box-shadow var(--speed);
}
.searchbar:focus-within .searchbar__field {
  background: var(--surface);
  box-shadow: var(--shadow-md);
}
.searchbar__icon { color: var(--text-3); font-size: var(--fs-lg); flex-shrink: 0; }

.searchbar__input {
  flex: 1; min-width: 0; height: 100%;
  border: 0; background: none; color: var(--text);
  font: inherit; font-size: var(--fs-lg);
}
.searchbar__input:focus { outline: none; }
.searchbar__input::placeholder { color: var(--text-3); }
.searchbar__input::-webkit-search-cancel-button { display: none; }

.searchbar__btn {
  position: relative; flex-shrink: 0;
  display: grid; place-items: center; width: 34px; height: 34px;
  border: 0; border-radius: var(--r-full); background: none;
  color: var(--text-3); font: inherit; font-size: var(--fs-md); cursor: pointer;
}
.searchbar__btn:hover { background: var(--surface-2); color: var(--text); }
.searchbar__filter {
  position: relative; flex-shrink: 0;
  display: grid; place-items: center; width: 46px; height: 46px;
  border: 0; border-radius: var(--r-full);
  background: var(--surface-3); color: var(--text-2);
  cursor: pointer;
  transition: background var(--speed), color var(--speed);
}
.searchbar__filter:hover { background: var(--border); color: var(--text); }
.searchbar__filter[aria-expanded="true"],
.searchbar__filter.is-on {
  background: var(--accent-soft); color: var(--accent-text);
}

.searchbar__count {
  position: absolute; top: 4px; right: 4px;
  min-width: 16px; height: 16px; padding: 0 4px;
  display: grid; place-items: center;
  border-radius: var(--r-full);
  background: var(--accent); color: #fff;
  font-size: 10px; font-weight: 700; line-height: 1;
}

.searchbar__panel {
  position: absolute; top: calc(100% + var(--s-2)); left: 0; right: 0; z-index: 70;
  padding: var(--s-4);
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--r-lg);
  box-shadow: var(--shadow-lg);
}
.searchbar__grid {
  display: grid; gap: var(--s-3);
  grid-template-columns: repeat(auto-fit, minmax(170px, 1fr));
}
.searchbar__presets {
  display: flex; flex-wrap: wrap; align-items: center; gap: var(--s-2);
  margin-top: var(--s-4); padding-top: var(--s-3);
  border-top: 1px solid var(--border-soft);
}
.searchbar__actions {
  display: flex; justify-content: flex-end; gap: var(--s-2);
  margin-top: var(--s-3);
}

/* Active filters, shown above the list. */
.chipbar {
  display: flex; flex-wrap: wrap; align-items: center; gap: var(--s-2);
  padding: var(--s-2) var(--s-1) 0;
}

.layout { display: flex; align-items: flex-start; }

.content {
  flex: 1; min-width: 0;
  padding: var(--s-5) var(--s-6) var(--s-10);
}

/* Empty state */
.empty {
  display: grid; place-items: center; text-align: center;
  padding: var(--s-10) var(--s-5); gap: var(--s-2);
}
.empty__icon { font-size: 40px; opacity: .55; }
.empty__title { font-size: var(--fs-lg); font-weight: 650; }
.empty__text { font-size: var(--fs-base); color: var(--text-3); max-width: 44ch; }

/* Toast */
.toast {
  position: fixed; left: 50%; bottom: var(--s-6); z-index: 200;
  transform: translate(-50%, 12px);
  padding: var(--s-3) var(--s-4); border-radius: var(--r-md);
  background: var(--text); color: var(--bg);
  font-size: var(--fs-base); font-weight: 600;
  box-shadow: var(--shadow-lg);
  opacity: 0; pointer-events: none;
  transition: opacity var(--speed), transform var(--speed);
}
.toast.is-on { opacity: 1; transform: translate(-50%, 0); }

/* ==========================================================================
   6. SIDEBAR
   ========================================================================== */

.sidebar {
  width: var(--sidebar-w); flex-shrink: 0;
  position: sticky; top: var(--topbar-h);
  height: calc(100vh - var(--topbar-h));
  display: flex; flex-direction: column;
  background: var(--rail);
  padding: var(--s-2) 0 var(--s-6);
  overflow-y: auto; overscroll-behavior: contain;
}

.side-group + .side-group { margin-top: var(--s-5); }
.side-group__title {
  display: flex; align-items: center; justify-content: space-between;
  padding: 0 var(--s-6); margin-bottom: var(--s-1);
  font-size: var(--fs-xs); font-weight: 700; letter-spacing: .07em;
  color: var(--text-4); text-transform: uppercase;
}

.side-role {
  display: flex;
  width: auto;
  margin: 0 var(--s-3) var(--s-3) var(--s-6);
}
.side-role .seg__btn {
  flex: 1;
  text-decoration: none;
}

.side-link {
  display: flex; align-items: center; gap: var(--s-4);
  height: 32px; padding: 0 var(--s-4) 0 var(--s-6);
  margin-right: var(--s-3);
  border-radius: 0 var(--r-full) var(--r-full) 0;
  font-size: var(--fs-md); font-weight: 500; color: var(--text-2);
  transition: background var(--speed), color var(--speed);
}
.side-link:hover { background: var(--surface-3); color: var(--text); }
.side-link.is-active {
  background: var(--accent-soft); color: var(--accent-text); font-weight: 700;
}
.side-link__icon {
  flex-shrink: 0;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 20px;
  height: 20px;
  color: inherit;
}
.gicon {
  display: block;
  width: 20px;
  height: 20px;
  fill: currentColor;
}
.side-link--sub .side-link__meta { display: none; }
.side-link__body { min-width: 0; flex: 1; }
.side-link__label {
  display: block; overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}
.side-link__meta {
  display: block; font-size: var(--fs-xs); color: var(--text-4);
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}
.side-link.is-active .side-link__meta { color: var(--accent-text); opacity: .8; }
.side-link__count {
  flex-shrink: 0; font-size: var(--fs-sm); font-weight: 650;
  color: var(--text-3); font-variant-numeric: tabular-nums;
}
.side-link.is-active .side-link__count { color: var(--accent-text); }

/* Mailbox node (details/summary tree) */
.mbox { margin-bottom: 2px; }

.mbox__head {
  display: flex; align-items: center; gap: var(--s-2);
  height: 40px; padding: 0 var(--s-4) 0 var(--s-2);
  margin-right: var(--s-3);
  border-radius: 0 var(--r-full) var(--r-full) 0; cursor: pointer;
  list-style: none;                       /* hide the native disclosure marker */
  transition: background var(--speed);
}
.mbox__head::-webkit-details-marker { display: none; }
.mbox__head::marker { content: ""; }
.mbox__head:hover { background: var(--surface-3); }
.mbox__head:focus-visible { outline: 2px solid var(--accent); outline-offset: -2px; }

.mbox.is-selected > .mbox__head { background: var(--accent-soft); }
.mbox.is-selected > .mbox__head .mbox__label { color: var(--accent-text); }

.mbox__caret {
  flex-shrink: 0; width: 12px; text-align: center;
  font-size: 9px; color: var(--text-4); line-height: 1;
  transition: transform var(--speed);
}
.mbox[open] > .mbox__head .mbox__caret { transform: rotate(90deg); }

.mbox__avatar { width: 26px; height: 26px; font-size: var(--fs-xs); flex-shrink: 0; }

.mbox__name { flex: 1; min-width: 0; display: block; }
.mbox__label {
  display: block; font-size: var(--fs-base); font-weight: 650; color: var(--text);
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}
.mbox__addr {
  display: block; font-size: var(--fs-xs); color: var(--text-4);
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}
.mbox__name:hover .mbox__label { color: var(--accent); }

/* Folder rows inside a mailbox, with a guide line back to the parent. */
.mbox__body {
  position: relative;
  margin: 2px 0 var(--s-3);
  padding-left: var(--s-1);
}
.mbox__body::before {
  content: ""; position: absolute;
  left: 25px; top: 2px; bottom: 2px; width: 1px;
  background: var(--border);
}

.side-link--sub {
  height: 30px; padding-left: 40px;
  font-size: var(--fs-base); font-weight: 500;
}
.side-link--sub .side-link__icon { width: 18px; height: 18px; }
.side-link--sub .side-link__icon .gicon { width: 18px; height: 18px; }

.side-search { position: relative; margin: 0 var(--s-3) var(--s-2) var(--s-4); }
.side-search .field { height: 32px; font-size: var(--fs-sm); padding-left: var(--s-8); }
.side-search__icon {
  position: absolute; left: var(--s-3); top: 50%; transform: translateY(-50%);
  color: var(--text-4); pointer-events: none;
  display: inline-flex; align-items: center; justify-content: center;
}
.side-search__icon .gicon { width: 16px; height: 16px; }
.side-empty {
  padding: var(--s-3); font-size: var(--fs-sm); color: var(--text-4); text-align: center;
}

/* Mobile drawer */
.scrim {
  position: fixed; inset: 0; z-index: 70;
  background: rgba(15, 23, 42, .5);
  opacity: 0; pointer-events: none; transition: opacity var(--speed);
}
.scrim.is-on { opacity: 1; pointer-events: auto; }

.nav-toggle { display: none; }

/* ==========================================================================
   7. MAIL LIST
   ========================================================================== */

/* Toolbar above list */
.list-toolbar {
  display: flex; align-items: center; gap: var(--s-2);
  min-height: 48px; padding: 0 var(--s-1);
}
.list-toolbar__title {
  display: flex; align-items: center; gap: var(--s-2);
  font-size: var(--fs-lg); font-weight: 650; min-width: 0;
}
.list-toolbar__icon {
  display: inline-flex; align-items: center; color: var(--text-3);
}
.list-toolbar__icon .gicon { width: 22px; height: 22px; }
.list-toolbar__name { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.list-toolbar__range {
  font-size: var(--fs-sm); color: var(--text-3);
  font-variant-numeric: tabular-nums; white-space: nowrap;
}
.list-toolbar__pager { display: flex; align-items: center; gap: 2px; }
.list-toolbar__pager .btn { font-size: var(--fs-xl); line-height: 1; }

.seg {
  display: inline-flex; padding: 2px; gap: 2px;
  background: var(--surface-3); border-radius: var(--r-md);
}
.seg__btn {
  display: inline-flex; align-items: center; justify-content: center;
  height: 28px; padding: 0 var(--s-3); border: 0; border-radius: var(--r-sm);
  background: transparent; color: var(--text-3);
  font: inherit; font-size: var(--fs-sm); font-weight: 600; cursor: pointer;
  white-space: nowrap;
  text-decoration: none;
}
.seg__btn:hover { color: var(--text); }
.seg__btn.is-on { background: var(--surface); color: var(--text); box-shadow: var(--shadow-sm); }

/* ------------------------------------------------------------- mail list
   Gmail row: avatar, sender, then subject and preview sharing one
   truncating line, with the clip and date pinned right.
   ----------------------------------------------------------------------- */

.mail-list {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--r-lg);
  overflow: hidden;
}

.mail-row {
  display: grid;
  grid-template-columns: 34px minmax(120px, 200px) minmax(0, 1fr) auto;
  gap: var(--s-4); align-items: center;
  padding: var(--row-py) var(--s-4);
  border-bottom: 1px solid var(--border-soft);
  color: var(--text);
  transition: background var(--speed), box-shadow var(--speed);
}
.mail-row:last-child { border-bottom: 0; }
.mail-row:hover {
  background: var(--surface-hover);
  box-shadow: inset 1px 0 0 var(--border), inset -1px 0 0 var(--border),
              0 1px 2px rgba(60, 64, 67, .3);
  z-index: 1; position: relative;
}
.mail-row:focus-visible {
  outline: none; background: var(--accent-soft);
  box-shadow: inset 3px 0 0 var(--accent);
}
.mail-row.is-cursor,
.mail-row.is-open {
  background: var(--accent-soft);
  box-shadow: inset 3px 0 0 var(--accent);
}
.mail-row.is-open .mail-row__subject { color: var(--accent-text); }

.avatar {
  display: grid; place-items: center;
  width: 30px; height: 30px; border-radius: var(--r-full);
  color: #fff; font-size: var(--fs-sm); font-weight: 700;
  text-transform: uppercase; user-select: none;
}
[data-density="compact"] .avatar { width: 24px; height: 24px; font-size: var(--fs-xs); }

.mail-row__from { min-width: 0; overflow: hidden; }
.mail-row__name {
  display: block; font-weight: 650; font-size: var(--fs-md);
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}
.mail-row__addr {
  display: block; font-size: var(--fs-xs); color: var(--text-4);
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}
[data-density="compact"] .mail-row__addr { display: none; }

/* One line: the parent truncates, the children stay inline. */
.mail-row__main {
  min-width: 0;
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
  font-size: var(--fs-md);
}
.mail-row__subject { font-weight: 600; color: var(--text); }
.mail-row__subject.is-empty { color: var(--text-4); font-style: italic; font-weight: 500; }
.mail-row__preview { color: var(--text-3); font-weight: 400; }
.mail-row__sep { color: var(--text-4); margin: 0 2px; }

.mail-row__end {
  display: flex; align-items: center; gap: var(--s-3);
  flex-shrink: 0; justify-content: flex-end;
}
.mail-row__clip { font-size: var(--fs-base); opacity: .7; }
.mail-row__date {
  font-size: var(--fs-sm); font-weight: 600; color: var(--text-3);
  text-align: right; font-variant-numeric: tabular-nums; white-space: nowrap;
  min-width: 62px;
}

/* Pagination */
.pager {
  display: flex; align-items: center; justify-content: space-between;
  gap: var(--s-3); flex-wrap: wrap; margin-top: var(--s-4);
}
.pager__status {
  font-size: var(--fs-base); color: var(--text-3); font-variant-numeric: tabular-nums;
}
.pager__nav { display: flex; align-items: center; gap: var(--s-1); }
.pager__num {
  display: grid; place-items: center; min-width: 34px; height: 34px; padding: 0 var(--s-2);
  border-radius: var(--r-md); font-size: var(--fs-base); font-weight: 600; color: var(--text-2);
  font-variant-numeric: tabular-nums;
}
.pager__num:hover { background: var(--surface-3); color: var(--text); }
.pager__num.is-on { background: var(--accent); color: #fff; }
.pager__gap { padding: 0 var(--s-1); color: var(--text-4); }
.pager__jump {
  display: flex; align-items: center; gap: var(--s-2);
  font-size: var(--fs-base); color: var(--text-3);
}
.pager__jump .field { width: 68px; height: 34px; text-align: center; }

/* --------------------------------------------------------------- workspace
   Single pane by default; two panes once a message is open. The list keeps
   its own scroll so the reader never pushes it off-screen.
   ------------------------------------------------------------------------ */

.workspace { display: flex; gap: var(--s-3); align-items: flex-start; min-width: 0; }

.mail-pane { flex: 1; min-width: 0; }

.read-pane {
  flex: 1 1 0; min-width: 0;
  position: sticky; top: calc(var(--topbar-h) + var(--s-4));
  max-height: calc(100vh - var(--topbar-h) - var(--s-8));
  overflow: hidden;
  display: flex; flex-direction: column;
}

/* Split mode: the list compacts to a fixed rail on the left. */
.workspace.is-split .mail-pane {
  flex: 0 0 var(--list-w);
  width: var(--list-w);
  position: sticky; top: calc(var(--topbar-h) + var(--s-4));
  max-height: calc(100vh - var(--topbar-h) - var(--s-8));
  display: flex; flex-direction: column;
}
.workspace.is-split .mail-list {
  flex: 1; overflow-y: auto; overscroll-behavior: contain;
}
.workspace.is-split .pager { margin-top: var(--s-2); }
.workspace.is-split .pager__status { font-size: var(--fs-sm); }
.workspace.is-split .pager__jump { display: none; }

/* Stacked rows once the list is a narrow rail. */
.workspace.is-split .mail-row {
  grid-template-columns: 36px minmax(0, 1fr) auto;
  grid-template-areas:
    "av from date"
    "av main main";
  gap: 2px var(--s-2);
  padding: var(--s-3);
  align-items: start;
}
.workspace.is-split .mail-row .avatar {
  grid-area: av; width: 30px; height: 30px; font-size: var(--fs-sm); align-self: center;
}
.workspace.is-split .mail-row__from { grid-area: from; }
.workspace.is-split .mail-row__addr { display: none; }
.workspace.is-split .mail-row__main { grid-area: main; }
.workspace.is-split .mail-row__date { grid-area: date; font-size: var(--fs-xs); }
.workspace.is-split .mail-row__preview { white-space: normal; }

/* The row you are reading. */
.mail-row.is-open {
  background: var(--accent-soft);
  box-shadow: inset 3px 0 0 var(--accent);
}
.mail-row.is-open .mail-row__subject { color: var(--accent-text); }

/* ==========================================================================
   8. EMAIL DETAIL
   ========================================================================== */

/* Reader shell — shared by the pane and the full page. */
.reader { display: flex; flex-direction: column; min-width: 0; }
.reader-page .reader { max-width: 1100px; }

.reader--pane { height: 100%; min-height: 0; }
.reader--pane .reader__sheet {
  flex: 1; min-height: 0; overflow-y: auto; overscroll-behavior: contain;
}
.reader--pane .reader__subject { font-size: var(--fs-xl); }
.reader--pane .reader__head,
.reader--pane .reader__identity,
.reader--pane .reader__body,
.reader--pane .attachments,
.reader--pane .reader__bodybar { padding-left: var(--s-5); padding-right: var(--s-5); }
.reader--pane .notice { margin-left: var(--s-5); margin-right: var(--s-5); }
.reader__close { flex-shrink: 0; }

/* Wide split view closes with ✕; the narrow takeover uses "← List" instead. */
.reader--pane .reader__back { display: none; }

.reader__bar {
  display: flex; align-items: center; gap: var(--s-2);
  flex-wrap: wrap; margin-bottom: var(--s-3);
}

.reader__head { padding: var(--s-6); border-bottom: 1px solid var(--border); }
.reader__subject {
  font-size: var(--fs-2xl); letter-spacing: -.02em; line-height: 1.3;
  overflow-wrap: anywhere;
}
.reader__tags { display: flex; flex-wrap: wrap; gap: var(--s-2); margin-top: var(--s-3); }

.reader__identity {
  display: flex; align-items: flex-start; gap: var(--s-3);
  padding: var(--s-4) var(--s-6);
  border-bottom: 1px solid var(--border-soft);
}
.reader__identity .avatar { width: 42px; height: 42px; font-size: var(--fs-lg); flex-shrink: 0; }
.reader__sender { min-width: 0; flex: 1; }
.reader__sender-name { font-weight: 650; font-size: var(--fs-md); overflow-wrap: anywhere; }
.reader__sender-to {
  font-size: var(--fs-base); color: var(--text-3); margin-top: 2px; overflow-wrap: anywhere;
}
.reader__when { font-size: var(--fs-base); color: var(--text-3); white-space: nowrap; }

.details-toggle {
  display: inline-flex; align-items: center; gap: var(--s-1);
  margin-top: var(--s-2); padding: 0; border: 0; background: none;
  font: inherit; font-size: var(--fs-sm); font-weight: 600;
  color: var(--accent); cursor: pointer;
}
.details-toggle:hover { text-decoration: underline; }

.meta-grid {
  display: grid; grid-template-columns: 92px minmax(0, 1fr);
  gap: var(--s-2) var(--s-4);
  margin: var(--s-3) 0 0; padding: var(--s-3);
  background: var(--surface-2); border: 1px solid var(--border-soft);
  border-radius: var(--r-md); font-size: var(--fs-base);
}
.meta-grid dt { color: var(--text-3); font-weight: 650; }
.meta-grid dd { margin: 0; overflow-wrap: anywhere; }

/* Body */
.reader__bodybar {
  display: flex; align-items: center; gap: var(--s-3); flex-wrap: wrap;
  padding: var(--s-2) var(--s-6);
  background: var(--surface-2); border-bottom: 1px solid var(--border-soft);
  font-size: var(--fs-sm); color: var(--text-3);
}

.notice {
  display: flex; align-items: center; gap: var(--s-3); flex-wrap: wrap;
  margin: var(--s-4) var(--s-6) 0; padding: var(--s-3) var(--s-4);
  background: var(--warning-soft); border: 1px solid var(--border);
  border-radius: var(--r-md); font-size: var(--fs-base); color: var(--warning);
}

.reader__body { padding: var(--s-6); }

.reader__text--code {
  font-family: ui-monospace, SFMono-Regular, Consolas, monospace;
  font-size: var(--fs-sm);
}

.reader__text {
  margin: 0; font-family: var(--font); font-size: var(--fs-md); line-height: 1.65;
  white-space: pre-wrap; overflow-wrap: anywhere; color: var(--text);
}

.reader__frame {
  display: block; width: 100%; min-height: 300px;
  border: 0; background: #fff; border-radius: var(--r-md);
}

/* Attachments */
.attachments { padding: var(--s-5) var(--s-6); border-top: 1px solid var(--border); }
.attachments__title {
  display: flex; align-items: center; gap: var(--s-2);
  font-size: var(--fs-md); margin-bottom: var(--s-3);
}

.attach-grid {
  display: grid; gap: var(--s-3);
  grid-template-columns: repeat(auto-fill, minmax(232px, 1fr));
}
.attach {
  display: flex; flex-direction: column;
  border: 1px solid var(--border); border-radius: var(--r-md);
  background: var(--surface); overflow: hidden;
  transition: border-color var(--speed), box-shadow var(--speed);
}
.attach:hover { border-color: var(--accent-border); box-shadow: var(--shadow-md); }

.attach__thumb {
  display: grid; place-items: center; height: 116px;
  background: var(--surface-2); border-bottom: 1px solid var(--border-soft);
  overflow: hidden;
}
.attach__thumb img { width: 100%; height: 100%; object-fit: cover; }
.attach__glyph { font-size: 34px; opacity: .8; }

.attach__body { padding: var(--s-3); display: flex; flex-direction: column; gap: 2px; }
.attach__name {
  font-size: var(--fs-base); font-weight: 650;
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}
.attach__meta { font-size: var(--fs-xs); color: var(--text-4); }
.attach__actions { display: flex; gap: var(--s-2); padding: 0 var(--s-3) var(--s-3); }
.attach__actions .btn { flex: 1; }

/* ==========================================================================
   9. LOGIN
   ========================================================================== */

.auth {
  min-height: 100vh; display: grid; place-items: center;
  padding: var(--s-5);
  background:
    radial-gradient(900px 500px at 12% -8%, var(--accent-soft), transparent 60%),
    radial-gradient(700px 460px at 108% 108%, var(--accent-soft), transparent 62%),
    var(--bg);
}
.auth__card { width: 100%; max-width: 392px; padding: var(--s-8); }
.auth__brand {
  display: flex; flex-direction: column; align-items: center;
  gap: var(--s-3); text-align: center;
}
.auth__brand .brand__mark { width: 48px; height: 48px; font-size: 24px; }
.auth__title { font-size: var(--fs-xl); letter-spacing: -.02em; }
.auth__sub { font-size: var(--fs-base); color: var(--text-3); }
.auth__form { display: flex; flex-direction: column; gap: var(--s-4); margin-top: var(--s-6); }
.auth-tabs { width: 100%; margin-top: var(--s-5); }
.auth-tabs .seg__btn { flex: 1; text-decoration: none; }
.auth__hint { margin: 0; font-size: var(--fs-sm); color: var(--text-3); }
.alert--ok {
  background: var(--success-soft); border-color: transparent; color: var(--success);
}
.auth__field { text-align: left; }
.auth__foot {
  margin-top: var(--s-5); padding-top: var(--s-4); border-top: 1px solid var(--border-soft);
  font-size: var(--fs-xs); color: var(--text-4); text-align: center;
}

.pw-wrap { position: relative; }
.pw-wrap .field { padding-right: 44px; }
.pw-toggle {
  position: absolute; right: var(--s-1); top: 50%; transform: translateY(-50%);
  width: 32px; height: 32px; display: grid; place-items: center;
  border: 0; border-radius: var(--r-sm); background: none;
  color: var(--text-3); cursor: pointer; font-size: var(--fs-md);
}
.pw-toggle:hover { background: var(--surface-3); color: var(--text); }

.alert {
  display: flex; align-items: flex-start; gap: var(--s-2);
  padding: var(--s-3); border-radius: var(--r-md);
  background: var(--danger-soft); border: 1px solid var(--danger-border);
  color: var(--danger); font-size: var(--fs-base); font-weight: 500;
}

/* Shortcuts dialog */
dialog.sheet {
  width: min(480px, calc(100vw - 32px)); padding: 0;
  border: 1px solid var(--border); border-radius: var(--r-lg);
  background: var(--surface); color: var(--text); box-shadow: var(--shadow-lg);
}
dialog.sheet::backdrop { background: rgba(15, 23, 42, .55); }
.sheet__head {
  display: flex; align-items: center; justify-content: space-between;
  padding: var(--s-4) var(--s-5); border-bottom: 1px solid var(--border);
}
.sheet__title { font-size: var(--fs-lg); }
.sheet__body { padding: var(--s-4) var(--s-5) var(--s-5); }
.sheet__row {
  display: flex; align-items: center; justify-content: space-between;
  gap: var(--s-4); padding: var(--s-2) 0;
  border-bottom: 1px solid var(--border-soft); font-size: var(--fs-base);
}
.sheet__row:last-child { border-bottom: 0; }

/* ==========================================================================
   10. RESPONSIVE
   ========================================================================== */

/* Not enough room for two panes: the reader takes over and the list hides,
   the way a phone mail app swaps between list and message. */
@media (max-width: 1080px) {
  .workspace.is-split { display: block; }
  .workspace.is-split .mail-pane { display: none; }
  .workspace.is-split .read-pane {
    position: static; max-height: none; width: auto;
  }
  .reader--pane { height: auto; }
  .reader--pane .reader__sheet { overflow: visible; max-height: none; }
  .reader--pane .reader__back { display: inline-flex; }
  .reader--pane .reader__close { display: none; }
}

@media (min-width: 1081px) and (max-width: 1400px) {
  :root { --list-w: 340px; }
}

@media (max-width: 1180px) {
  .mail-row {
    grid-template-columns: 30px minmax(100px, 160px) minmax(0, 1fr) auto;
    gap: var(--s-3);
  }
  .mail-row__addr { display: none; }
}

@media (max-width: 900px) {
  :root { --sidebar-w: 280px; }

  .nav-toggle { display: inline-flex; }

  .sidebar {
    position: fixed; top: 0; left: 0; z-index: 80;
    height: 100dvh; padding-top: var(--s-4);
    transform: translateX(-100%);
    transition: transform .22s cubic-bezier(.4, 0, .2, 1);
    box-shadow: var(--shadow-lg);
  }
  .sidebar.is-open { transform: translateX(0); }

  .content { padding: var(--s-4); }

  /* Card layout on small screens: sender + date, then subject. */
  .mail-row {
    grid-template-columns: 40px minmax(0, 1fr) auto;
    grid-template-areas:
      "av from date"
      "av main main";
    gap: 2px var(--s-3);
    padding: var(--s-3) var(--s-4);
    align-items: start;
  }
  .mail-row .avatar     { grid-area: av; align-self: center; }
  .mail-row__from       { grid-area: from; }
  .mail-row__main       { grid-area: main; }
  .mail-row__date       { grid-area: date; font-size: var(--fs-xs); }
  .mail-row__addr       { display: block; }

  .reader__head, .reader__identity, .reader__body,
  .attachments, .reader__bodybar { padding-left: var(--s-4); padding-right: var(--s-4); }
  .notice { margin-left: var(--s-4); margin-right: var(--s-4); }
  .meta-grid { grid-template-columns: 1fr; gap: var(--s-1); }
  .meta-grid dt { margin-top: var(--s-2); }
}

@media (max-width: 620px) {
  .topbar { padding: 0 var(--s-3); }
  
  .list-toolbar .seg { display: none; }
  .searchbar__field { height: 40px; padding-left: var(--s-3); }
  .searchbar__filter { width: 40px; height: 40px; }
  .searchbar__input { font-size: var(--fs-md); }
  .brand__name { display: none; }

  .reader__identity { flex-wrap: wrap; }
  .reader__when { width: 100%; }
  .attach-grid { grid-template-columns: 1fr; }
  .pager { justify-content: center; }
  .pager__jump { display: none; }
}

@media print {
  .topbar, .sidebar, .reader__bar, .attach__actions, .scrim { display: none !important; }
  body { background: #fff; }
  .panel { border: 0; box-shadow: none; }
  .content { padding: 0; }
}


/* ==========================================================================
   11. RISK REVIEW
   ========================================================================== */

.side-link__count--alert {
  background: var(--danger); color: #fff;
  padding: 1px 7px; border-radius: var(--r-full); font-size: var(--fs-xs);
}
[data-theme="dark"] .side-link__count--alert { color: #1f1f1f; }

/* Status tabs */
.risk-tabs {
  display: flex; align-items: center; gap: var(--s-1);
  flex-wrap: wrap; padding: 0 var(--s-1) var(--s-3);
  border-bottom: 1px solid var(--border); margin-bottom: var(--s-3);
}
.risk-tab {
  display: inline-flex; align-items: center; gap: var(--s-2);
  height: 32px; padding: 0 var(--s-3);
  border-radius: var(--r-full);
  font-size: var(--fs-base); font-weight: 600; color: var(--text-2);
}
.risk-tab:hover { background: var(--surface-3); color: var(--text); }
.risk-tab.is-on { background: var(--accent-soft); color: var(--accent-text); }
.risk-tab__n {
  min-width: 20px; padding: 0 5px; border-radius: var(--r-full);
  background: var(--surface-3); color: var(--text-3);
  font-size: var(--fs-xs); font-weight: 700; text-align: center;
}
.risk-tab.is-on .risk-tab__n { background: var(--accent); color: #fff; }

.risk-filter { width: auto; min-width: 170px; height: 32px; }

/* A finding row: score replaces the avatar, quote replaces the preview. */
.risk-row { grid-template-columns: 38px minmax(120px, 190px) minmax(0, 1fr) auto; }

.risk-score {
  display: grid; place-items: center;
  width: 34px; height: 34px; border-radius: var(--r-md);
  background: var(--warning-soft); color: var(--warning);
  font-size: var(--fs-base); font-weight: 700;
  font-variant-numeric: tabular-nums;
}
.risk-score--lg { width: 44px; height: 44px; font-size: var(--fs-lg); }

.risk-quote {
  display: block; margin-top: 1px;
  font-size: var(--fs-sm); color: var(--text-3); font-style: italic;
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}

.badge--amount {
  background: var(--warning-soft); color: var(--warning); font-weight: 700;
}
.badge--outbound { background: var(--danger-soft); color: var(--danger); }
.badge--inbound  { background: var(--accent-soft); color: var(--accent-text); }

/* Triage panel above the message */
.triage {
  padding: var(--s-4);
  background: var(--surface); border: 1px solid var(--border);
  border-radius: var(--r-lg); margin-bottom: var(--s-3);
  flex-shrink: 0;
}
.triage__head { display: flex; align-items: flex-start; gap: var(--s-3); }
.triage__title { display: flex; flex-wrap: wrap; gap: var(--s-2); }
.triage__evidence {
  margin: var(--s-2) 0 0;
  font-size: var(--fs-base); line-height: 1.55; color: var(--text-2);
  font-style: italic;
  border-left: 3px solid var(--warning); padding-left: var(--s-3);
}
.triage__actions {
  display: flex; flex-wrap: wrap; align-items: center; gap: var(--s-2);
  margin-top: var(--s-4); padding-top: var(--s-3);
  border-top: 1px solid var(--border-soft);
}
.triage__note { flex: 1; min-width: 180px; }
.triage__meta {
  margin: var(--s-2) 0 0; font-size: var(--fs-xs); color: var(--text-4);
}

@media (max-width: 900px) {
  .risk-row {
    grid-template-columns: 34px minmax(0, 1fr) auto;
    grid-template-areas: "av from date" "av main main";
  }
  .risk-row .risk-score { grid-area: av; }
}
