/* ==========================================================================
   Synthrun Mail — mailbox surface
   Yahoo-inspired Material 3 / rounded system.
   ========================================================================== */

body {
  background: var(--bg);
  overflow: hidden;
}

/* ── Header ────────────────────────────────────────────────── */
header {
  height: var(--header-h);
  display: grid;
  grid-template-columns: var(--sidebar-w) minmax(0, 1fr) auto;
  align-items: center;
  gap: 12px;
  padding: 0 16px 0 0;
  background: var(--surface);
  border-bottom: 1px solid var(--line);
  position: relative;
  z-index: 20;
}

.h-left {
  display: flex;
  align-items: center;
  height: 100%;
  min-width: 0;
}

.sidebar-toggle {
  display: none;
  place-items: center;
  width: 44px;
  height: 44px;
  margin-left: 8px;
  border: 0;
  border-radius: var(--r-pill);
  background: transparent;
  color: var(--text);
  cursor: pointer;
}

.sidebar-toggle:hover {
  background: var(--surface-3);
}

.sidebar-toggle svg {
  width: 22px;
  height: 22px;
  stroke: currentColor;
  fill: none;
  stroke-width: 2;
  stroke-linecap: round;
}

.h-logo {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  width: calc(var(--sidebar-w) - 21px);
  height: 38px;
  margin-left: 10px;
  padding: 0 14px;
  border-radius: var(--r-pill);
  color: var(--text);
  font-size: 15px;
  font-weight: 800;
  letter-spacing: -0.02em;
  white-space: nowrap;
  transition: background var(--dur-2) var(--ease);
}

.h-logo:hover {
  background: var(--brand-soft);
}

.h-logo svg {
  width: 22px;
  height: 22px;
  stroke: var(--brand);
  fill: none;
  stroke-width: 1.8;
  stroke-linecap: round;
  stroke-linejoin: round;
  flex-shrink: 0;
}

.h-search {
  display: flex;
  align-items: center;
  gap: 10px;
  width: 100%;
  max-width: 600px;
  height: 40px;
  padding: 0 14px;
  border: 1px solid transparent;
  border-radius: var(--r-pill);
  background: var(--surface-3);
  transition: background var(--dur-2) var(--ease),
    border-color var(--dur-2) var(--ease),
    box-shadow var(--dur-2) var(--ease);
}

.h-search:hover {
  background: var(--surface-4);
}

.h-search:focus-within {
  background: var(--surface);
  border-color: var(--brand);
  box-shadow: 0 0 0 1px var(--brand);
}

.h-search svg {
  width: 18px;
  height: 18px;
  stroke: var(--muted);
  fill: none;
  stroke-width: 2;
  stroke-linecap: round;
  flex-shrink: 0;
}

.h-search input {
  width: 100%;
  border: 0;
  outline: 0;
  background: transparent;
  color: var(--text);
  font-size: 13px;
}

.h-search input::placeholder {
  color: var(--subtle);
}

.h-search input::-webkit-search-cancel-button {
  appearance: none;
}

.h-right {
  display: flex;
  align-items: center;
  gap: 4px;
}

/* ── User chip ─────────────────────────────────────────────── */
.user-chip {
  position: relative;
  display: flex;
  align-items: center;
  gap: 8px;
  height: 38px;
  min-width: 0;
  max-width: 200px;
  padding: 0 7px 0 4px;
  border: 1px solid var(--line);
  border-radius: var(--r-pill);
  background: var(--surface);
  cursor: pointer;
  user-select: none;
  transition: background var(--dur-2) var(--ease), border-color var(--dur-2) var(--ease);
}

.user-chip:hover {
  background: var(--surface-3);
  border-color: var(--line-strong);
}

.user-avatar {
  width: 28px;
  height: 28px;
  font-size: 11px;
  background: var(--brand);
  color: var(--on-brand);
}

.user-chip-email {
  flex: 1;
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  font-size: 12px;
  font-weight: 600;
  color: var(--text-2);
}

.user-chip-caret {
  width: 14px;
  height: 14px;
  stroke: var(--muted);
  fill: none;
  stroke-width: 2;
  stroke-linecap: round;
  flex-shrink: 0;
  transition: transform var(--dur-2) var(--ease);
}

.user-chip[aria-expanded="true"] .user-chip-caret {
  transform: rotate(180deg);
}

.user-menu {
  position: absolute;
  right: 0;
  top: calc(100% + 8px);
  min-width: 240px;
  max-width: min(300px, calc(100vw - 24px));
  display: none;
  z-index: 60;
  transform-origin: top right;
  animation: scale-in var(--dur-2) var(--ease-out);
}

.user-menu.show {
  display: block;
}

.user-menu-item {
  font-weight: 500;
}

.user-menu-item svg {
  width: 18px;
  height: 18px;
  stroke: currentColor;
  fill: none;
  stroke-width: 2;
  stroke-linecap: round;
  stroke-linejoin: round;
}

/* ── Account switcher ──────────────────────────────────────── */
.user-menu-accounts {
  display: flex;
  flex-direction: column;
  gap: 2px;
  max-height: 260px;
  overflow-y: auto;
}

.user-menu-accounts:empty {
  display: none;
}

.account-item {
  display: flex;
  align-items: center;
  gap: 9px;
  width: 100%;
  min-height: 44px;
  padding: 5px 8px;
  border: 0;
  border-radius: var(--r-sm);
  background: transparent;
  color: var(--text);
  text-align: left;
  cursor: pointer;
  transition: background var(--dur-1) var(--ease);
}

.account-item:hover {
  background: var(--surface-3);
}

.account-item.active {
  background: var(--brand-soft);
}

.account-avatar {
  display: grid;
  place-items: center;
  width: 28px;
  height: 28px;
  flex-shrink: 0;
  border-radius: 50%;
  background: var(--brand);
  color: var(--on-brand);
  font-size: 10px;
  font-weight: 700;
  letter-spacing: 0.02em;
}

.account-item:not(.active) .account-avatar {
  background: var(--surface-3);
  color: var(--text-2);
}

.account-meta {
  display: flex;
  flex-direction: column;
  min-width: 0;
  flex: 1;
  line-height: 1.25;
}

.account-email {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  font-size: 12.5px;
  font-weight: 600;
  color: var(--text);
}

.account-sub {
  font-size: 10.5px;
  font-weight: 500;
  color: var(--muted);
}

.account-badge {
  display: none;
  min-width: 20px;
  height: 20px;
  padding: 0 6px;
  border-radius: var(--r-pill);
  background: var(--brand);
  color: var(--on-brand);
  font-size: 10.5px;
  font-weight: 700;
  line-height: 20px;
  text-align: center;
  flex-shrink: 0;
}

.account-badge.has-count {
  display: inline-block;
}

.account-lock {
  width: 14px;
  height: 14px;
  flex-shrink: 0;
  fill: none;
  stroke: var(--muted);
  stroke-width: 1.8;
  stroke-linecap: round;
  stroke-linejoin: round;
}

.account-check {
  width: 16px;
  height: 16px;
  flex-shrink: 0;
  stroke: var(--brand);
  fill: none;
  stroke-width: 2.4;
  stroke-linecap: round;
  stroke-linejoin: round;
}

.account-empty {
  padding: 8px 10px;
  font-size: 12px;
  color: var(--muted);
}

/* ── App shell ─────────────────────────────────────────────── */
.app-body {
  height: calc(100vh - var(--header-h) - var(--status-h));
  display: grid;
  grid-template-columns: var(--sidebar-w) minmax(0, 1fr);
  min-height: 0;
  position: relative;
}

/* ── Sidebar ───────────────────────────────────────────────── */
aside {
  display: flex;
  flex-direction: column;
  gap: 4px;
  min-height: 0;
  padding: 12px 10px;
  overflow-y: auto;
  background: var(--surface);
  border-right: 1px solid var(--line);
}

aside hr {
  width: auto;
  height: 1px;
  margin: 8px 10px;
  border: 0;
  background: var(--line);
}

/* Mobile drawer-only brand row (hidden on desktop) */
.side-drawer-head,
.side-drawer-divider {
  display: none;
}

.compose-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  width: 100%;
  min-height: 44px;
  height: auto;
  margin-bottom: 8px;
  padding: 11px 16px;
  border: 0;
  border-radius: var(--r-pill);
  background: var(--brand);
  color: var(--on-brand);
  font-size: 14px;
  font-weight: 700;
  line-height: 1.2;
  letter-spacing: 0.01em;
  white-space: nowrap;
  flex: 0 0 auto;
  cursor: pointer;
  box-shadow: var(--shadow-2);
  transition: background var(--dur-2) var(--ease),
    box-shadow var(--dur-2) var(--ease),
    transform var(--dur-1) var(--ease);
}

.compose-btn:hover {
  background: var(--brand-hover);
  box-shadow: var(--shadow-3);
}

.compose-btn:active {
  transform: scale(0.98);
  background: var(--brand-press);
}

.compose-btn svg {
  width: 18px;
  height: 18px;
  stroke: currentColor;
  fill: none;
  stroke-width: 2;
  stroke-linecap: round;
  stroke-linejoin: round;
}

.side-section {
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.side-label {
  padding: 10px 12px 4px;
  color: var(--muted);
  font-size: 11px;
  font-weight: 700;
  letter-spacing: 0.01em;
}

.side-link {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  width: 100%;
  height: 38px;
  padding: 0 12px 0 14px;
  border: 0;
  border-radius: var(--r-pill);
  background: transparent;
  color: var(--text-2);
  font-size: 13px;
  font-weight: 500;
  text-align: left;
  cursor: pointer;
  transition: background var(--dur-2) var(--ease), color var(--dur-2) var(--ease);
}

.side-link:hover {
  background: var(--surface-3);
  color: var(--text);
}

.side-link.active {
  background: var(--brand-soft);
  color: var(--brand);
  font-weight: 700;
}

.side-link-left {
  display: inline-flex;
  align-items: center;
  gap: 11px;
  min-width: 0;
}

.side-link-left svg {
  width: 18px;
  height: 18px;
  stroke: currentColor;
  fill: none;
  stroke-width: 2;
  stroke-linecap: round;
  stroke-linejoin: round;
  flex-shrink: 0;
}

.side-link.active .side-link-left svg {
  fill: none;
}

.side-badge {
  min-width: 22px;
  height: 20px;
  padding: 0 6px;
  border-radius: var(--r-pill);
  background: var(--surface-3);
  color: var(--muted);
  font-size: 10px;
  font-weight: 700;
  line-height: 20px;
  text-align: center;
  flex-shrink: 0;
  transition: background var(--dur-2) var(--ease), color var(--dur-2) var(--ease);
}

/* Only the open folder carries the accent. */
.side-link.active .side-badge {
  background: var(--brand);
  color: var(--on-brand);
}

.side-badge.zero {
  background: transparent;
  color: var(--subtle);
  font-weight: 600;
}

.settings-section {
  margin-top: auto;
  padding-top: 12px;
}

.settings-btn {
  display: flex;
  align-items: center;
  gap: 10px;
  width: 100%;
  height: 42px;
  padding: 0 14px;
  border: 1px solid var(--line);
  border-radius: var(--r-pill);
  background: transparent;
  color: var(--text);
  font-size: 13px;
  font-weight: 600;
  cursor: pointer;
  transition: background var(--dur-2) var(--ease), border-color var(--dur-2) var(--ease);
}

.settings-btn:hover {
  background: var(--surface-3);
  border-color: var(--line-strong);
}

.settings-btn svg {
  width: 18px;
  height: 18px;
  stroke: currentColor;
  fill: none;
  stroke-width: 2;
  stroke-linecap: round;
}

/* ── Split panes ───────────────────────────────────────────── */
.mail-panel {
  display: grid;
  grid-template-columns: var(--thread-w) minmax(0, 1fr);
  min-width: 0;
  min-height: 0;
  position: relative;
}

.thread-list {
  display: flex;
  flex-direction: column;
  min-height: 0;
  background: var(--surface);
  border-right: 1px solid var(--line);
}

.resize-handle {
  position: absolute;
  top: 0;
  bottom: 0;
  width: 7px;
  z-index: 15;
  cursor: col-resize;
  display: none;
  background: transparent;
}

.resize-handle::after {
  content: '';
  position: absolute;
  top: 0;
  bottom: 0;
  left: 3px;
  width: 1px;
  background: transparent;
  transition: background var(--dur-2) var(--ease);
}

.resize-handle:hover::after,
.resize-handle.resizing::after {
  background: var(--brand);
}

#sidebarResize {
  left: var(--sidebar-w);
  transform: translateX(-4px);
}

#splitResize {
  left: var(--thread-w);
  transform: translateX(-4px);
}

.sidebar-backdrop {
  display: none;
}

/* ── Thread toolbar ────────────────────────────────────────── */
.thread-toolbar {
  display: flex;
  align-items: center;
  gap: 8px;
  height: 50px;
  padding: 0 12px;
  flex-shrink: 0;
  border-bottom: 1px solid var(--line);
}

.toolbar-label {
  color: var(--text);
  font-size: 16px;
  font-weight: 800;
  letter-spacing: -0.02em;
}

.toolbar-retention {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  color: var(--subtle);
  font-size: 11px;
  font-weight: 500;
}

.toolbar-selected-count {
  color: var(--brand);
  font-size: 11px;
  font-weight: 700;
}

.toolbar-right {
  display: flex;
  align-items: center;
  gap: 2px;
  margin-left: auto;
}

.bulk-actions {
  display: flex;
  align-items: center;
  gap: 2px;
}

.bulk-more-wrap {
  position: relative;
  display: inline-flex;
}

.bulk-more-dropdown {
  position: absolute;
  right: 0;
  top: calc(100% + 6px);
  min-width: 180px;
  display: none;
  z-index: 60;
  transform-origin: top right;
}

.bulk-more-dropdown.open {
  display: block;
  animation: scale-in var(--dur-2) var(--ease-out);
}

.bulk-more-item {
  font-weight: 500;
}

.bulk-more-item svg {
  width: 18px;
  height: 18px;
  flex-shrink: 0;
  stroke: currentColor;
  fill: none;
  stroke-width: 2;
  stroke-linecap: round;
  stroke-linejoin: round;
}

.bulk-more-labels {
  max-height: 180px;
  overflow-y: auto;
  border-top: 1px solid var(--line);
  margin-top: 6px;
  padding-top: 6px;
}

/* ── Thread list items ─────────────────────────────────────── */
.thread-items {
  flex: 1;
  min-height: 0;
  overflow-y: auto;
  overflow-x: hidden;
  padding: 6px;
  -webkit-overflow-scrolling: touch;
}

.thread-item {
  position: relative;
  display: grid;
  grid-template-columns: auto minmax(0, 1fr) auto;
  gap: 10px;
  padding: 10px 10px 10px 14px;
  margin-bottom: 2px;
  border: 1px solid transparent;
  border-radius: 18px;
  cursor: pointer;
  transition: background var(--dur-2) var(--ease), border-color var(--dur-2) var(--ease);
}

.thread-item:hover {
  background: var(--surface-3);
}

.thread-item.active {
  background: var(--brand-soft);
  border-color: transparent;
}

.thread-item.active .thread-from,
.thread-item.active .thread-subject {
  color: var(--text);
}

.thread-item.active .thread-time {
  color: var(--brand);
}

.thread-item.selected {
  background: var(--brand-soft-2);
}

.thread-item.unread {
  background: var(--surface);
}

.thread-item.unread:hover {
  background: var(--surface-3);
}

.thread-item.has-labels .thread-from {
  text-decoration: underline;
  text-decoration-color: var(--label-color, var(--brand));
  text-decoration-thickness: 2px;
  text-underline-offset: 3px;
  text-decoration-skip-ink: none;
}

.thread-avatar {
  position: relative;
  z-index: 1;
  display: grid;
  place-items: center;
  width: 34px;
  height: 34px;
  border: 0;
  border-radius: 50%;
  background: var(--brand-soft);
  background: color-mix(in srgb, var(--brand) 14%, transparent);
  color: var(--brand);
  cursor: pointer;
}

.thread-avatar-initials {
  font-size: 11.5px;
  font-weight: 700;
  letter-spacing: 0.015em;
  line-height: 1;
  user-select: none;
  transition: opacity var(--dur-1) var(--ease);
}

.thread-avatar-checkbox {
  position: absolute;
  inset: 0;
  display: none;
  place-items: center;
  border: 2px solid var(--line-strong);
  border-radius: 50%;
  background: var(--surface);
  z-index: 2;
  cursor: pointer;
}

.thread-avatar-checkbox svg {
  width: 18px;
  height: 18px;
  stroke: var(--text);
  fill: none;
  stroke-width: 2.5;
  stroke-linecap: round;
}

.thread-item:hover .thread-avatar-initials {
  opacity: 0.18;
}

.thread-item:hover .thread-avatar-checkbox {
  display: grid;
}

.thread-item.selected .thread-avatar {
  background: var(--brand);
  color: var(--on-brand);
}

.thread-item.selected .thread-avatar-initials {
  opacity: 0;
}

.thread-item.selected .thread-avatar-checkbox {
  display: grid;
  background: var(--brand);
  border-color: var(--brand);
}

.thread-item.selected .thread-avatar-checkbox svg {
  stroke: var(--on-brand);
}

.thread-body {
  min-width: 0;
  overflow: hidden;
}

.thread-meta {
  min-width: 0;
}

.thread-from {
  margin-bottom: 2px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  color: var(--muted);
  font-size: 12px;
  font-weight: 500;
}

.thread-item.unread .thread-from {
  color: var(--text);
  font-weight: 700;
}

.thread-subject {
  margin-bottom: 3px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  color: var(--text);
  font-size: 13px;
  font-weight: 600;
  line-height: 1.35;
}

.thread-item.unread .thread-subject {
  font-weight: 800;
}

.thread-preview {
  display: -webkit-box;
  overflow: hidden;
  color: var(--subtle);
  font-size: 12px;
  line-height: 1.45;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
}

.thread-aside {
  display: flex;
  flex-direction: column;
  align-items: flex-end;
  gap: 6px;
  padding-top: 2px;
}

.thread-time {
  color: var(--subtle);
  font-size: 11px;
  font-weight: 500;
  line-height: 1.4;
  white-space: nowrap;
}

.thread-item.unread .thread-time {
  color: var(--brand);
  font-weight: 700;
}

.thread-tags {
  display: flex;
  flex-wrap: wrap;
  gap: 4px;
  margin-top: 7px;
}

.thread-tag {
  padding: 2px 7px;
  border: 0;
  border-radius: var(--r-pill);
  background: var(--surface-3);
  color: var(--muted);
  font-size: 10px;
  font-weight: 600;
  line-height: 1.6;
}

.thread-item.active .thread-tag {
  background: var(--surface);
}

.tag-pending {
  background: var(--brand-soft-2);
  color: var(--brand);
}

.tag-error {
  background: var(--danger-soft);
  color: var(--danger);
}

.thread-dot {
  display: none;
}

/* Thread overflow menu */
.thread-menu-wrap {
  position: relative;
}

.thread-menu-btn {
  width: 26px;
  height: 26px;
  display: grid;
  place-items: center;
  padding: 0;
  border: 0;
  border-radius: var(--r-pill);
  background: transparent;
  color: var(--subtle);
  cursor: pointer;
  opacity: 0;
  transition: opacity var(--dur-1) var(--ease), background var(--dur-1) var(--ease);
}

.thread-item:hover .thread-menu-btn,
.thread-item.active .thread-menu-btn {
  opacity: 1;
}

.thread-menu-btn:hover {
  background: var(--surface-4);
  color: var(--text);
}

.thread-menu-btn svg {
  width: 16px;
  height: 16px;
  stroke: currentColor;
  fill: none;
  stroke-width: 2;
  stroke-linecap: round;
}

.thread-menu-dropdown {
  position: absolute;
  right: 0;
  top: calc(100% + 4px);
  min-width: 190px;
  max-height: 260px;
  overflow-y: auto;
  display: none;
  z-index: 60;
  transform-origin: top right;
}

.thread-menu-dropdown.open {
  display: block;
  animation: scale-in var(--dur-2) var(--ease-out);
}

.thread-menu-action svg {
  width: 16px;
  height: 16px;
  flex-shrink: 0;
  stroke: currentColor;
  fill: none;
  stroke-width: 2;
  stroke-linecap: round;
  stroke-linejoin: round;
}

.menu-label-item {
  font-weight: 500;
}

.menu-label-dot,
.label-dot {
  width: 10px;
  height: 10px;
  border-radius: 50%;
  flex-shrink: 0;
}

.menu-label-name {
  flex: 1;
}

.menu-label-check,
.label-check {
  min-width: 16px;
  color: var(--brand);
  font-size: 14px;
  font-weight: 700;
  text-align: center;
}

.menu-label-item.active-label {
  background: var(--brand-soft);
  color: var(--brand);
}

/* ── List extras ───────────────────────────────────────────── */
.search-scope-hint {
  padding: 8px 12px;
  border-bottom: 1px solid var(--line);
  color: var(--subtle);
  font-size: 11px;
  font-weight: 600;
}

.load-more-wrap {
  padding: 14px;
  text-align: center;
}

.load-more-btn {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  min-height: 34px;
  padding: 0 16px;
  border: 1px solid var(--line-strong);
  border-radius: var(--r-pill);
  background: transparent;
  color: var(--text);
  font-size: 12px;
  font-weight: 600;
  cursor: pointer;
  transition: background var(--dur-2) var(--ease);
}

.load-more-btn:hover:not(:disabled) {
  background: var(--surface-3);
}

.load-more-btn:disabled {
  opacity: 0.5;
  cursor: default;
}

.load-more-end {
  color: var(--subtle);
  font-size: 12px;
  font-weight: 500;
}

.empty-state {
  padding: 32px 20px;
  color: var(--muted);
  font-size: 13px;
  line-height: 1.7;
  text-align: center;
}

.empty-state p {
  margin: 3px 0;
}

.empty-state p strong {
  color: var(--text);
  font-size: 15px;
  font-weight: 700;
}

.empty-state svg {
  display: block;
  width: 40px;
  height: 40px;
  margin: 0 auto 10px;
  padding: 12px;
  border-radius: 50%;
  background: var(--brand-soft);
  stroke: var(--brand);
  fill: none;
  stroke-width: 2;
  stroke-linecap: round;
}

/* ── Reading pane ──────────────────────────────────────────── */
.mail-view {
  position: relative;
  display: flex;
  flex-direction: column;
  min-height: 0;
  overflow: hidden;
  background: var(--surface);
}

.mail-view-empty {
  flex: 1;
  display: grid;
  place-items: center;
  padding: 32px;
  color: var(--muted);
  text-align: center;
}

.mail-view-empty-inner {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 14px;
  max-width: 300px;
  animation: rise-in var(--dur-3) var(--ease-out);
}

.mail-view-empty svg {
  width: 72px;
  height: 72px;
  padding: 20px;
  border-radius: 22px;
  background: var(--brand-soft);
  stroke: var(--brand);
  fill: none;
  stroke-width: 1.6;
  stroke-linecap: round;
  stroke-linejoin: round;
}

.mail-view-empty h3 {
  margin: 0;
  color: var(--text);
  font-size: 19px;
  font-weight: 800;
  letter-spacing: -0.025em;
  line-height: 1.25;
}

.mail-view-empty p {
  margin: 0;
  color: var(--muted);
  font-size: 13.5px;
  line-height: 1.6;
}

#messageView {
  display: none;
  flex-direction: column;
  height: 100%;
  overflow: hidden;
}

.mail-header-bar {
  display: flex;
  align-items: center;
  gap: 12px;
  width: 100%;
  min-height: 0;
  padding: 18px max(22px, calc((100% - 680px) / 2)) 16px;
  flex-shrink: 0;
  background: var(--surface);
  border-bottom: 1px solid var(--line);
}

.mobile-back-btn {
  display: none;
  place-items: center;
  width: 40px;
  height: 40px;
  padding: 0;
  border: 0;
  border-radius: var(--r-pill);
  background: transparent;
  color: var(--muted);
  cursor: pointer;
  flex-shrink: 0;
}

.mobile-back-btn:hover {
  background: var(--surface-3);
}

.mobile-back-btn svg {
  width: 20px;
  height: 20px;
  stroke: currentColor;
  fill: none;
  stroke-width: 2;
  stroke-linecap: round;
}

.mail-reader-identity {
  display: flex;
  align-items: center;
  gap: 12px;
  min-width: 0;
  flex: 1 1 auto;
}

.mail-reader-avatar {
  display: grid;
  place-items: center;
  width: 40px;
  height: 40px;
  flex-shrink: 0;
  border: 0;
  border-radius: 50%;
  background: var(--brand-soft);
  background: color-mix(in srgb, var(--brand) 14%, transparent);
  color: var(--brand);
  font-size: 12.5px;
  font-weight: 700;
  letter-spacing: 0.02em;
  user-select: none;
}

.mail-reader-identity-text {
  min-width: 0;
}

.mail-reader-name-line {
  display: flex;
  align-items: baseline;
  flex-wrap: wrap;
  gap: 2px 8px;
  min-width: 0;
}

.mail-reader-name {
  overflow: hidden;
  color: var(--text);
  font-size: 15px;
  font-weight: 700;
  letter-spacing: -0.012em;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.mail-reader-address {
  min-width: 0;
  overflow: hidden;
  color: var(--muted);
  font-size: 12.5px;
  font-weight: 400;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.mail-reader-meta {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 2px 6px;
  margin-top: 3px;
  color: var(--muted);
  font-size: 12px;
  font-weight: 400;
  line-height: 1.4;
}

.mail-reader-folder {
  color: var(--text-2);
  font-weight: 600;
}

.mail-reader-meta-dot {
  color: var(--subtle);
}

.mail-header-actions {
  display: flex;
  align-items: center;
  gap: 2px;
  flex-shrink: 0;
  margin-left: auto;
}

.mail-header-actions .icon-btn {
  width: 36px;
  height: 36px;
  border-color: transparent;
  background: transparent;
  color: var(--muted);
}

.mail-header-actions .icon-btn:hover {
  background: var(--surface-3);
  border-color: transparent;
  color: var(--text);
}

.label-dropdown-wrap {
  position: relative;
}

.label-dropdown {
  position: absolute;
  right: 0;
  top: calc(100% + 6px);
  min-width: 190px;
  max-height: 240px;
  overflow-y: auto;
  display: none;
  z-index: 60;
  transform-origin: top right;
}

.label-dropdown.open {
  display: block;
  animation: scale-in var(--dur-2) var(--ease-out);
}

.label-dropdown-item {
  font-weight: 500;
}

.mail-body-scroll {
  flex: 1;
  min-height: 0;
  width: 100%;
  padding: 28px max(22px, calc((100% - 680px) / 2)) 32px;
  overflow-y: auto;
  overflow-x: hidden;
  -webkit-overflow-scrolling: touch;
  background: var(--surface);
}

.mail-reader {
  display: flex;
  flex-direction: column;
  min-height: 100%;
  animation: fade-in var(--dur-2) var(--ease);
}

.mail-reader-subject {
  margin: 0 0 8px;
  color: var(--text);
  font-size: clamp(22px, 2.6vw, 28px);
  font-weight: 800;
  letter-spacing: -0.028em;
  line-height: 1.2;
  overflow-wrap: break-word;
}

/* Conversation cards — one flat, expandable card per message. Cards are an
   opt-in study (?thread=card); the rail is the default thread style. */
.mail-thread-head {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-bottom: 8px;
}

.mail-thread-head .mail-reader-subject {
  margin-bottom: 0;
}

.mail-thread-count {
  display: inline-grid;
  place-items: center;
  min-width: 24px;
  height: 24px;
  padding: 0 8px;
  flex-shrink: 0;
  border-radius: var(--r-pill);
  background: var(--surface-3);
  color: var(--muted);
  font-size: 12px;
  font-weight: 700;
  line-height: 1;
}

.mail-thread-list {
  display: grid;
  gap: 10px;
}

.mail-thread-message {
  overflow: hidden;
  border: 1px solid var(--line);
  border-radius: 14px;
  background: var(--surface);
  transition: border-color var(--dur-2) var(--ease), background var(--dur-2) var(--ease);
}

.mail-thread-message.is-open {
  border-color: var(--line-strong);
}

.mail-thread-summary {
  display: flex;
  align-items: center;
  gap: 12px;
  width: 100%;
  padding: 12px 14px;
  border: 0;
  background: transparent;
  color: inherit;
  text-align: left;
  cursor: pointer;
}

.mail-thread-message:not(.is-open) .mail-thread-summary:hover {
  background: var(--surface-2);
}

.mail-thread-summary:focus-visible {
  outline: 2px solid var(--brand);
  outline-offset: -2px;
}

.mail-thread-avatar {
  display: grid;
  place-items: center;
  width: 32px;
  height: 32px;
  flex-shrink: 0;
  border: 0;
  border-radius: 50%;
  background: var(--brand-soft);
  background: color-mix(in srgb, var(--brand) 14%, transparent);
  color: var(--brand);
  font-size: 11px;
  font-weight: 700;
  letter-spacing: 0.02em;
  user-select: none;
}

.mail-thread-summary-main {
  display: grid;
  gap: 2px;
  min-width: 0;
  flex: 1;
}

.mail-thread-summary-line {
  display: flex;
  align-items: baseline;
  gap: 8px;
  min-width: 0;
}

.mail-thread-sender {
  overflow: hidden;
  color: var(--text);
  font-size: 13.5px;
  font-weight: 700;
  letter-spacing: -0.01em;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.mail-thread-time {
  margin-left: auto;
  flex-shrink: 0;
  color: var(--subtle);
  font-size: 11.5px;
  font-weight: 500;
  white-space: nowrap;
}

.mail-thread-snippet {
  overflow: hidden;
  color: var(--muted);
  font-size: 12.5px;
  line-height: 1.45;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.mail-thread-message.is-open .mail-thread-snippet {
  display: none;
}

.mail-thread-chevron {
  display: grid;
  place-items: center;
  width: 24px;
  height: 24px;
  flex-shrink: 0;
  color: var(--subtle);
  transition: transform var(--dur-2) var(--ease);
}

.mail-thread-message.is-open .mail-thread-chevron {
  transform: rotate(180deg);
}

.mail-thread-content {
  padding: 14px 16px 18px;
  border-top: 1px solid var(--line);
  animation: fade-in var(--dur-1) var(--ease);
}

.mail-thread-content[hidden] {
  display: none;
}

.mail-thread-meta {
  display: flex;
  flex-wrap: wrap;
  gap: 4px 6px;
  margin-bottom: 14px;
  color: var(--muted);
  font-size: 12px;
  line-height: 1.5;
}

.mail-thread-meta-dot {
  color: var(--subtle);
}

.mail-thread-details-toggle {
  margin-left: 2px;
}

.mail-thread-summary-wrap {
  position: relative;
}

.mail-thread--rail .mail-thread-delete {
  position: absolute;
  top: 50%;
  right: 8px;
  z-index: 2;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 24px;
  height: 24px;
  padding: 0;
  border: 0;
  border-radius: 6px;
  background: transparent;
  color: var(--subtle);
  opacity: 0;
  pointer-events: none;
  transform: translateY(-50%);
  cursor: pointer;
  transition: opacity var(--dur-1) var(--ease), color var(--dur-1) var(--ease), background var(--dur-1) var(--ease);
}

.mail-thread--rail .mail-thread-summary-wrap:hover .mail-thread-delete,
.mail-thread--rail .mail-thread-delete:focus-visible {
  opacity: 1;
  pointer-events: auto;
}

.mail-thread--rail .mail-thread-delete:hover {
  color: var(--danger);
  background: var(--danger-soft);
}

.mail-thread--rail .mail-thread-delete:disabled {
  opacity: 0.35;
  cursor: default;
}

.mail-thread-details {
  margin: 0 0 14px;
  padding: 10px 12px;
}

.mail-thread-message .mail-attachments {
  margin-top: 20px;
}

/* Conversation thread styles. The rail is the default; cards and folds are
   opt-in with ?thread=card / ?thread=fold. */
.mail-thread--fold .mail-thread-count,
.mail-thread--rail .mail-thread-count {
  background: transparent;
  border: 1px solid var(--line-strong);
}

.mail-thread--fold .mail-reader-rule,
.mail-thread--rail .mail-reader-rule {
  display: none;
}

.mail-thread--fold .mail-thread-list {
  display: block;
  margin-top: 8px;
  border-bottom: 1px solid var(--line);
}

.mail-thread--fold .mail-thread-message {
  overflow: visible;
  border: 0;
  border-top: 1px solid var(--line);
  border-radius: 0;
  background: transparent;
}

.mail-thread--fold .mail-thread-message.is-open {
  border-color: var(--line);
}

.mail-thread--fold .mail-thread-summary {
  align-items: flex-start;
  gap: 12px;
  padding: 14px 8px;
  border-radius: 8px;
}

.mail-thread--fold .mail-thread-message:not(.is-open) .mail-thread-summary:hover {
  background: var(--surface-2);
}

.mail-thread--fold .mail-thread-avatar {
  display: none;
}

.mail-thread--fold .mail-thread-foldmark {
  display: grid;
  place-items: center;
  width: 28px;
  height: 28px;
  margin-top: 1px;
  flex-shrink: 0;
  color: var(--subtle);
}

.mail-thread--fold .mail-thread-foldmark svg {
  width: 19px;
  height: 19px;
  fill: none;
  stroke: currentColor;
  stroke-width: 1.6;
  stroke-linecap: round;
  stroke-linejoin: round;
}

.mail-thread--fold .mail-thread-message.is-open .mail-thread-foldmark {
  color: var(--brand);
}

.mail-thread--fold .mail-thread-summary-main,
.mail-thread--rail .mail-thread-summary-main {
  gap: 3px;
}

.mail-thread--fold .mail-thread-summary-line,
.mail-thread--rail .mail-thread-summary-line {
  gap: 10px;
}

.mail-thread--fold .mail-thread-summary-main .mail-thread-snippet,
.mail-thread--rail .mail-thread-summary-main .mail-thread-snippet {
  line-height: 1.5;
}

.mail-thread--fold .mail-thread-chevron,
.mail-thread--rail .mail-thread-chevron {
  margin-top: 2px;
}

.mail-thread--fold .mail-thread-content {
  padding: 2px 8px 24px 48px;
  border-top: 0;
}

.mail-thread--fold .mail-thread-content::before,
.mail-thread--rail .mail-thread-content::before {
  content: "";
  display: block;
  height: 1px;
  margin: 0 0 16px;
  background: linear-gradient(90deg, var(--line-strong), var(--line) 45%, transparent 85%);
}

.mail-thread--rail .mail-thread-list {
  position: relative;
  display: block;
  margin-top: 10px;
  padding-left: 30px;
}

.mail-thread--rail .mail-thread-list::before {
  content: "";
  position: absolute;
  left: 7px;
  top: 14px;
  bottom: 18px;
  width: 1px;
  background: linear-gradient(180deg, var(--line-strong), var(--line) 55%, transparent);
}

.mail-thread--rail .mail-thread-message {
  position: relative;
  overflow: visible;
  border: 0;
  border-radius: 0;
  background: transparent;
}

.mail-thread--rail .mail-thread-message + .mail-thread-message {
  margin-top: 2px;
}

.mail-thread--rail .mail-thread-node {
  position: absolute;
  left: -30px;
  top: 17px;
  width: 15px;
  height: 15px;
  border: 1.5px solid var(--line-strong);
  border-radius: 50%;
  background: var(--surface);
  transition: background var(--dur-2) var(--ease), border-color var(--dur-2) var(--ease), box-shadow var(--dur-2) var(--ease);
}

.mail-thread--rail .mail-thread-message.is-open .mail-thread-node {
  border-color: var(--brand);
  background: var(--brand);
  box-shadow: 0 0 0 4px var(--brand-soft);
}

.mail-thread--rail .mail-thread-summary {
  align-items: flex-start;
  gap: 12px;
  padding: 12px 38px 12px 0;
}

.mail-thread--rail .mail-thread-message:not(.is-open) .mail-thread-summary:hover {
  background: linear-gradient(90deg, var(--surface-2), transparent 82%);
}

.mail-thread--rail .mail-thread-avatar {
  display: none;
}

.mail-thread--rail .mail-thread-content {
  padding: 0 8px 26px 0;
  border-top: 0;
}

.mail-thread--rail .mail-thread-content::before {
  background: linear-gradient(90deg, var(--line-strong), transparent 75%);
}

@media (max-width: 640px) {
  .mail-thread--fold .mail-thread-summary {
    gap: 10px;
    padding: 12px 6px;
  }

  .mail-thread--fold .mail-thread-foldmark {
    width: 24px;
    height: 24px;
  }

  .mail-thread--fold .mail-thread-foldmark svg {
    width: 17px;
    height: 17px;
  }

  .mail-thread--fold .mail-thread-content {
    padding: 2px 0 20px 38px;
  }

  .mail-thread--rail .mail-thread-list {
    padding-left: 26px;
  }

  .mail-thread--rail .mail-thread-list::before {
    left: 6px;
  }

  .mail-thread--rail .mail-thread-node {
    left: -26px;
    top: 15px;
    width: 13px;
    height: 13px;
  }

  .mail-thread--rail .mail-thread-summary {
    gap: 10px;
    padding: 11px 34px 11px 0;
  }

  .mail-thread--rail .mail-thread-delete {
    right: 6px;
    opacity: 0.65;
    pointer-events: auto;
  }

  .mail-thread--rail .mail-thread-content {
    padding: 0 0 22px;
  }
}

.mail-reader-subline {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 6px;
  margin-bottom: 18px;
  color: var(--muted);
  font-size: 12.5px;
  line-height: 1.5;
}

.mail-reader-recipient {
  min-width: 0;
  overflow-wrap: anywhere;
}

.mail-reader-subline-dot {
  color: var(--subtle);
}

.mail-reader-rule {
  height: 1px;
  margin-bottom: 22px;
  background: var(--line);
}

.mail-reader-notice {
  margin-bottom: 18px;
  padding: 10px 12px;
  border: 1px solid var(--line);
  border-radius: var(--r-sm);
  background: var(--surface-2);
  color: var(--muted);
  font-size: 12.5px;
  line-height: 1.5;
}

.mail-reader-body {
  max-width: 68ch;
  color: var(--text);
  font-size: 15px;
  line-height: 1.75;
  overflow-wrap: break-word;
  word-break: break-word;
  white-space: pre-wrap;
}

.mail-reader-body blockquote,
.mail-reader-body .gmail_quote {
  margin: 16px 0 0;
  padding-left: 14px;
  border-left: 2px solid var(--line-strong);
  color: var(--muted);
}

.mail-reader-body:not(.is-html) a {
  color: var(--brand);
  font-weight: 600;
  text-decoration: underline;
  text-underline-offset: 2px;
  overflow-wrap: anywhere;
}

.mail-reader-body.is-html {
  color: var(--text);
  white-space: normal;
  color-scheme: light dark;
}

.mail-reader-body.is-html img {
  max-width: 100%;
  height: auto;
}

.mail-reader-body.is-html a {
  color: var(--brand);
  font-weight: 600;
  text-decoration: underline;
  text-underline-offset: 2px;
}

.mail-reader-body.is-html table {
  max-width: 100% !important;
}

.mail-reader-body.is-html td {
  word-break: break-word;
}

.mail-details-toggle {
  padding: 0;
  border: 0;
  background: transparent;
  color: var(--muted);
  font: inherit;
  font-weight: 600;
  cursor: pointer;
  text-decoration: underline;
  text-decoration-color: var(--line-strong);
  text-underline-offset: 3px;
  transition: color var(--dur-2) var(--ease), text-decoration-color var(--dur-2) var(--ease);
}

.mail-details-toggle:hover {
  color: var(--text);
  text-decoration-color: currentColor;
}

.mail-details {
  display: grid;
  gap: 8px;
  max-width: 68ch;
  margin: 0 0 18px;
  padding: 12px 14px;
  border: 1px solid var(--line);
  border-radius: var(--r-sm);
  background: var(--surface-2);
}

.mail-details[hidden] {
  display: none !important;
}

.mail-details-row {
  display: grid;
  grid-template-columns: 88px 1fr;
  gap: 10px;
  font-size: 12px;
  line-height: 1.6;
}

.mail-details-row span:first-child {
  color: var(--muted);
  font-weight: 600;
}

.mail-details-row span:last-child {
  overflow-wrap: break-word;
  word-break: break-word;
}

.attachment-file-icon {
  display: block;
  width: 40px;
  height: 40px;
  border-radius: 11px;
  background: var(--surface-3);
  object-fit: cover;
  flex: 0 0 auto;
}

.mail-attachments {
  max-width: 68ch;
  margin-top: 28px;
  padding: 0;
}

.mail-attachments-title {
  display: flex;
  align-items: center;
  gap: 7px;
  margin-bottom: 10px;
  color: var(--muted);
  font-size: 12px;
  font-weight: 600;
}

.mail-attachments-count {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 18px;
  height: 18px;
  padding: 0 5px;
  border-radius: 999px;
  background: var(--surface-3);
  color: var(--text-2);
  font-size: 10px;
  font-weight: 700;
  line-height: 1;
}

.mail-attachments-list {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(210px, 1fr));
  gap: 10px;
}

.mail-attachment {
  display: flex;
  align-items: center;
  gap: 2px;
  min-width: 0;
  padding: 6px;
  border: 1px solid var(--line);
  border-radius: 12px;
  background: var(--surface-2);
  transition: background var(--dur-2) var(--ease), border-color var(--dur-2) var(--ease);
}

.mail-attachment:hover {
  background: var(--surface-3);
  border-color: var(--line-strong);
}

.mail-attachment-preview {
  display: flex;
  flex: 1;
  align-items: center;
  gap: 10px;
  min-width: 0;
  padding: 2px 4px 2px 2px;
  color: var(--text);
}

.mail-attachment-copy {
  display: flex;
  flex: 1;
  flex-direction: column;
  gap: 2px;
  min-width: 0;
}

.mail-attachment-download {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 30px;
  height: 30px;
  margin-right: 2px;
  border-radius: 50%;
  color: var(--muted);
  flex-shrink: 0;
  transition: color var(--dur-2) var(--ease), background var(--dur-2) var(--ease);
}

.mail-attachment-download:hover {
  background: var(--brand-soft);
  color: var(--brand);
}

.mail-attachment-name {
  width: 100%;
  overflow: hidden;
  font-size: 12.5px;
  font-weight: 600;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.mail-attachment-meta {
  color: var(--subtle);
  font-size: 10.5px;
  font-weight: 500;
  white-space: nowrap;
}

/* ── Reply bar ─────────────────────────────────────────────── */
.reply-bar {
  display: flex;
  align-items: center;
  gap: 4px;
  width: 100%;
  margin: 0;
  padding: 10px max(22px, calc((100% - 680px) / 2));
  flex-shrink: 0;
  border-top: 1px solid var(--line);
  background: var(--surface);
  overflow-x: auto;
}

.reply-btn,
.send-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 7px;
  min-height: 36px;
  padding: 0 16px;
  border: 1px solid var(--line-strong);
  border-radius: var(--r-pill);
  background: transparent;
  color: var(--text);
  font-size: 13px;
  font-weight: 600;
  letter-spacing: 0.01em;
  white-space: nowrap;
  cursor: pointer;
  transition: background var(--dur-2) var(--ease),
    border-color var(--dur-2) var(--ease),
    color var(--dur-2) var(--ease),
    transform var(--dur-1) var(--ease);
}

.reply-btn {
  min-height: 34px;
  padding: 0 16px;
  border-color: transparent;
  border-radius: var(--r-pill);
  background: var(--surface-3);
  color: var(--text);
}

.reply-btn:hover {
  background: var(--surface-4);
  color: var(--text);
}

/* Filled-tonal button: the Material middle ground between flat and filled. */
.reply-btn:not(.primary) {
  border-color: transparent;
  background: var(--surface-3);
  color: var(--text);
}

.reply-btn:not(.primary):hover {
  background: var(--surface-4);
  color: var(--text);
}

.reply-btn:active,
.send-btn:active {
  transform: scale(0.97);
}

.reply-btn svg,
.send-btn svg {
  width: 16px;
  height: 16px;
  stroke: currentColor;
  fill: none;
  stroke-width: 2;
  stroke-linecap: round;
  stroke-linejoin: round;
  flex-shrink: 0;
}

.reply-btn.primary {
  border-color: var(--brand);
  background: var(--brand);
  color: var(--on-brand);
  box-shadow: none;
}

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

.forward-menu {
  position: fixed;
  z-index: 60;
  display: grid;
  width: min(294px, calc(100vw - 24px));
  padding: 6px;
  gap: 2px;
  border: 1px solid var(--line);
  border-radius: 14px;
  background: var(--surface);
  box-shadow: var(--shadow-3);
}

.forward-menu[hidden] {
  display: none;
}

.forward-menu-item {
  display: flex;
  align-items: flex-start;
  gap: 10px;
  width: 100%;
  padding: 10px;
  border: 0;
  border-radius: 10px;
  background: transparent;
  color: var(--text);
  text-align: left;
  cursor: pointer;
}

.forward-menu-item:hover,
.forward-menu-item:focus-visible {
  outline: none;
  background: var(--surface-3);
}

.forward-menu-icon {
  display: grid;
  place-items: center;
  width: 34px;
  height: 34px;
  flex: 0 0 auto;
  border-radius: 9px;
  background: var(--surface-3);
  color: var(--text-2);
}

.forward-menu-item:hover .forward-menu-icon,
.forward-menu-item:focus-visible .forward-menu-icon {
  background: var(--surface-4);
}

.forward-menu-icon svg {
  width: 17px;
  height: 17px;
  stroke: currentColor;
  fill: none;
  stroke-width: 1.8;
  stroke-linecap: round;
  stroke-linejoin: round;
}

.forward-menu-copy {
  display: grid;
  gap: 2px;
  min-width: 0;
  padding-top: 1px;
}

.forward-menu-copy strong {
  color: var(--text);
  font-size: 12.5px;
  font-weight: 650;
  line-height: 1.3;
}

.forward-menu-copy span {
  color: var(--muted);
  font-size: 11px;
  line-height: 1.35;
}

/* ── Status bar ────────────────────────────────────────────── */
.status-bar {
  display: flex;
  align-items: center;
  gap: 12px;
  height: var(--status-h);
  padding: 0 14px;
  flex-shrink: 0;
  border-top: 1px solid var(--line);
  background: var(--surface);
}

.status-item {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  color: var(--muted);
  font-size: 11px;
  font-weight: 500;
  white-space: nowrap;
}

.status-item.ml {
  margin-left: auto;
}

.status-dot {
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: var(--success);
}

/* ── Loading overlay ───────────────────────────────────────── */
.app-loading-overlay {
  position: fixed;
  inset: 0;
  z-index: 300;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 22px;
  background: var(--surface);
  transition: opacity 0.4s var(--ease), visibility 0.4s var(--ease);
}

.app-loading-overlay.hidden {
  opacity: 0;
  visibility: hidden;
  pointer-events: none;
}

.app-loader {
  display: flex;
  align-items: center;
  gap: 10px;
  color: var(--text);
  user-select: none;
}

/* Settings is a separate document preloaded beside the mailbox. Showing it is
   just an overlay reveal, so mail keeps its scroll, reader and live data. */
.settings-frame-shell {
  position: fixed;
  top: var(--header-h);
  right: 0;
  bottom: 0;
  left: 0;
  z-index: 18;
  visibility: hidden;
  opacity: 0;
  pointer-events: none;
  background: var(--surface);
}

.settings-frame-shell.is-open {
  visibility: visible;
  opacity: 1;
  pointer-events: auto;
  animation: pane-in 0.35s var(--ease-out) backwards;
}

.settings-frame-shell.is-closing {
  visibility: visible;
  pointer-events: none;
  animation: pane-out 0.18s var(--ease) both;
}

.settings-frame-shell iframe {
  display: block;
  width: 100%;
  height: 100%;
  border: 0;
  background: var(--surface);
}

body.settings-frame-open {
  overflow: hidden;
}

.loader-spinner {
  width: 20px;
  height: 20px;
  border-radius: 50%;
  background-color: transparent;
  animation: mail-loader-rotate 1.5s linear infinite;
  z-index: 0;
}

/* Accent-driven gradient — tokens resolve live, so the loader follows
   whichever accent is selected (incl. dark-mode accent variants). */
@keyframes mail-loader-rotate {
  0% {
    transform: rotate(90deg);
    box-shadow:
      0 1px 1px 0 #fff inset,
      0 3px 5px 0 var(--brand) inset,
      0 4px 4px 0 var(--brand-press) inset;
  }
  50% {
    transform: rotate(270deg);
    background: var(--brand-soft);
    box-shadow:
      0 1px 1px 0 rgba(255, 255, 255, 0.85) inset,
      0 3px 5px 0 var(--brand-hover) inset,
      0 4px 4px 0 var(--brand-press) inset;
  }
  100% {
    transform: rotate(450deg);
    box-shadow:
      0 1px 1px 0 #fff inset,
      0 3px 5px 0 var(--brand) inset,
      0 4px 4px 0 var(--brand-press) inset;
  }
}

.loader-words {
  display: flex;
  align-items: flex-start;
  gap: 1px;
  line-height: 1.3;
  z-index: 1;
}

.split-char {
  display: inline-block;
  overflow: hidden;
  vertical-align: top;
}

.split-char-inner {
  display: inline-block;
  will-change: transform, opacity;
}

@media (prefers-reduced-motion: reduce) {
  .split-char {
    overflow: visible;
  }
}

/* ── Compose ───────────────────────────────────────────────── */
.compose-overlay {
  position: fixed;
  inset: 0;
  z-index: 120;
  display: none;
  align-items: flex-end;
  justify-content: flex-end;
  padding: 16px;
  background: var(--scrim);
}

@keyframes compose-scrim-in {
  from { opacity: 0; }
  to { opacity: 1; }
}

@keyframes compose-scrim-out {
  from { opacity: 1; }
  to { opacity: 0; }
}

@keyframes compose-pop-in {
  from { opacity: 0; transform: translateY(24px) scale(0.975); }
  to { opacity: 1; transform: translateY(0) scale(1); }
}

@keyframes compose-pop-out {
  from { opacity: 1; transform: translateY(0) scale(1); }
  to { opacity: 0; transform: translateY(24px) scale(0.975); }
}

@keyframes compose-sheet-in {
  from { transform: translateY(101%); }
  to { transform: translateY(0); }
}

@keyframes compose-sheet-out {
  from { transform: translateY(0); }
  to { transform: translateY(101%); }
}

.compose-overlay.show {
  display: flex;
  animation: compose-scrim-in 0.22s var(--ease-out);
}

.compose-overlay.closing {
  pointer-events: none;
  animation: compose-scrim-out 0.2s var(--ease) both;
}

.compose-modal {
  display: flex;
  flex-direction: column;
  width: min(620px, calc(100vw - 32px));
  height: min(620px, calc(100vh - 64px));
  overflow: hidden;
  border: 0;
  border-radius: 14px;
  background: var(--surface);
  box-shadow: var(--shadow-4);
  animation: compose-pop-in 0.3s var(--ease-out);
}

.compose-overlay.closing .compose-modal {
  animation: compose-pop-out 0.2s var(--ease) both;
}

.compose-header {
  position: relative;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  height: 46px;
  padding: 0 8px 0 16px;
  flex-shrink: 0;
  background: var(--surface);
  border-bottom: 1px solid var(--line);
}

.compose-title {
  color: var(--text);
  font-size: 14px;
  font-weight: 700;
}

.compose-header-controls {
  display: inline-flex;
  align-items: center;
  gap: 2px;
  flex-shrink: 0;
}

.compose-close,
.compose-maximize {
  width: 30px;
  height: 30px;
  display: grid;
  place-items: center;
  padding: 0;
  border: 0;
  border-radius: var(--r-pill);
  background: transparent;
  color: var(--muted);
  cursor: pointer;
  transition: background var(--dur-2) var(--ease), color var(--dur-2) var(--ease);
}

.compose-close:hover,
.compose-maximize:hover {
  background: var(--surface-3);
  color: var(--text);
}

.compose-close svg,
.compose-maximize svg {
  width: 16px;
  height: 16px;
  stroke: currentColor;
  fill: none;
  stroke-width: 2;
  stroke-linecap: round;
}

/* Fields */
.compose-field {
  display: grid;
  grid-template-columns: 56px minmax(0, 1fr);
  align-items: center;
  gap: 8px;
  min-height: 44px;
  padding: 0 16px;
  flex-shrink: 0;
  border-bottom: 1px solid var(--line);
  transition: box-shadow var(--dur-2) var(--ease);
}

.compose-field label {
  color: var(--muted);
  font-size: 11px;
  font-weight: 700;
}

.compose-field input {
  width: 100%;
  padding: 12px 0;
  border: 0;
  outline: 0;
  background: transparent;
  color: var(--text);
  font-size: 13px;
}

.compose-field input::placeholder {
  color: var(--subtle);
}

.compose-field.invalid {
  box-shadow: inset 0 -2px 0 var(--danger);
}

.compose-field.invalid label,
.compose-field.invalid input {
  color: var(--danger);
}

.compose-recipient-input {
  display: flex;
  align-items: flex-start;
  gap: 8px;
  min-width: 0;
  flex: 1;
}

.recipient-chips {
  position: relative;
  display: flex;
  flex: 1;
  flex-wrap: wrap;
  align-items: center;
  gap: 4px;
  min-height: 36px;
  padding: 4px 0;
}

.recipient-chips.invalid {
  box-shadow: inset 0 -2px 0 var(--danger);
}

.recipient-chips.invalid .chip-input {
  color: var(--danger);
}

.chip {
  gap: 2px;
  min-height: 22px;
  padding: 0 4px 0 8px;
  font-size: 11.5px;
}

.chip-remove {
  display: inline-grid;
  place-items: center;
  flex-shrink: 0;
  width: 16px;
  height: 16px;
  margin-left: 1px;
  padding: 0;
  border: 0;
  border-radius: 50%;
  background: transparent;
  color: inherit;
  font: inherit;
  line-height: 1;
  cursor: pointer;
  opacity: 0.65;
  transition: opacity var(--dur-1) var(--ease), background var(--dur-1) var(--ease);
}

.chip-remove:hover {
  background: color-mix(in srgb, currentColor 16%, transparent);
  opacity: 1;
}

.chip-remove svg {
  width: 9px;
  height: 9px;
  fill: none;
  stroke: currentColor;
  stroke-width: 1.8;
  stroke-linecap: round;
}

.chip-input {
  flex: 1;
  min-width: 90px;
  border: 0;
  outline: 0;
  background: transparent;
  color: var(--text);
  font-size: 13px;
}

.chip-input::placeholder {
  color: var(--subtle);
}

.compose-toggle-link {
  margin-top: 11px;
  padding: 2px 6px;
  border-radius: var(--r-xs);
  color: var(--brand);
  font-size: 11.5px;
  font-weight: 700;
  white-space: nowrap;
  cursor: pointer;
}

.compose-toggle-link:hover {
  background: var(--brand-soft);
}

.compose-toggle-link.hidden {
  display: none;
}

.compose-toggle-link.active {
  background: var(--brand-soft);
}

/* Editor */
.compose-body {
  flex: 1;
  min-height: 140px;
  padding: 12px 16px;
  overflow: auto;
}

.compose-body.hide {
  display: none;
}

.compose-body textarea {
  width: 100%;
  height: 100%;
  min-height: 160px;
  padding: 0;
  border: 0;
  outline: 0;
  resize: none;
  background: transparent;
  color: var(--text);
  font-family: var(--font);
  font-size: 13px;
  line-height: 1.65;
}

.compose-body textarea::placeholder {
  color: var(--subtle);
}

.compose-body.invalid,
.compose-body-html.invalid {
  box-shadow: inset 0 0 0 2px var(--danger);
}

.compose-body.invalid textarea,
.compose-body-html.invalid textarea {
  color: var(--danger);
}

.compose-body-html {
  display: none;
  flex: 1;
  min-height: 0;
  flex-direction: column;
}

.compose-body-html.show {
  display: flex;
}

/* Segmented view switch */
.html-editor-tabs {
  display: flex;
  gap: 2px;
  padding: 10px 12px 0;
  flex-shrink: 0;
  background: var(--surface);
}

.html-tab-btn {
  padding: 6px 12px;
  border: 0;
  border-radius: var(--r-pill);
  background: transparent;
  color: var(--muted);
  font-size: 12px;
  font-weight: 700;
  cursor: pointer;
  transition: background var(--dur-2) var(--ease), color var(--dur-2) var(--ease);
}

.html-tab-btn:hover {
  background: var(--surface-3);
  color: var(--text);
}

.html-tab-btn.active {
  background: var(--brand-soft);
  color: var(--brand);
}

.html-tab-btn.active::after {
  content: none;
}

/* Formatting bar */
.compose-format-bar {
  display: flex;
  align-items: center;
  gap: 2px;
  padding: 6px 12px;
  flex-shrink: 0;
  border-bottom: 1px solid var(--line);
  background: var(--surface-2);
}

.compose-format-btn {
  width: 28px;
  height: 28px;
  display: grid;
  place-items: center;
  padding: 0;
  border: 0;
  border-radius: var(--r-sm);
  background: transparent;
  color: var(--muted);
  cursor: pointer;
  font-family: var(--font);
  font-size: 13px;
  font-weight: 800;
  transition: background var(--dur-1) var(--ease), color var(--dur-1) var(--ease);
}

.compose-format-btn:hover {
  background: var(--surface-4);
  color: var(--text);
}

.compose-format-btn:active {
  transform: scale(0.94);
}

.compose-format-btn svg {
  width: 15px;
  height: 15px;
  stroke: currentColor;
  fill: none;
  stroke-width: 2;
  stroke-linecap: round;
  stroke-linejoin: round;
}

.compose-format-btn.is-italic {
  font-style: italic;
  font-family: Georgia, serif;
}

.compose-format-btn.is-underline {
  text-decoration: underline;
}

.compose-format-sep {
  width: 1px;
  height: 18px;
  margin: 0 4px;
  background: var(--line);
}

.html-editor-pane {
  display: none;
  flex: 1;
  min-height: 0;
  padding: 12px 16px;
  overflow: auto;
}

.html-editor-pane.active {
  display: block;
}

.html-editor-pane textarea {
  width: 100%;
  height: 100%;
  min-height: 160px;
  padding: 0;
  border: 0;
  outline: 0;
  resize: none;
  background: transparent;
  color: var(--text);
  font-family: var(--font);
  font-size: 13px;
  line-height: 1.65;
}

.html-preview-pane {
  display: none;
  flex: 1;
  min-height: 0;
  overflow: auto;
  border: 0;
  background: #ffffff;
}

.html-preview-pane.active {
  display: block;
}

/* Collapsed reply quote */
.compose-quote {
  flex-shrink: 0;
  padding: 8px 16px 0;
  background: var(--surface);
}

.compose-quote[hidden] {
  display: none;
}

.compose-quote-bar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
}

.compose-quote-toggle,
.compose-quote-code-toggle {
  padding: 2px 0;
  border: 0;
  background: transparent;
  color: var(--brand);
  font-family: var(--font);
  font-size: 11.5px;
  font-weight: 600;
  text-decoration: underline;
  text-underline-offset: 2px;
  cursor: pointer;
}

.compose-quote-toggle:hover,
.compose-quote-code-toggle:hover {
  color: var(--brand-hover);
}

.compose-quote-code-toggle {
  color: var(--muted);
  font-weight: 500;
}

.compose-quote-code-toggle[hidden] {
  display: none;
}

.compose-quote-panel {
  max-height: 220px;
  margin: 8px 0;
  padding: 10px 12px;
  overflow: auto;
  border: 1px solid var(--line);
  border-radius: var(--r-sm);
  background: var(--surface-2);
  color: var(--muted);
  font-size: 12.5px;
  line-height: 1.6;
}

.compose-quote-panel .gmail_attr,
.compose-quote-panel .gmail_quote,
.compose-quote-panel blockquote {
  color: var(--muted) !important;
}

.compose-quote-panel .gmail_quote {
  margin: 0 !important;
}

.compose-quote-panel blockquote {
  margin: 6px 0 0 !important;
  padding-left: 12px !important;
  border-left: 2px solid var(--line-strong) !important;
}

.compose-quote-code {
  margin: 0;
  white-space: pre-wrap;
  overflow-wrap: anywhere;
  color: var(--text-2);
  font-family: var(--font-mono);
  font-size: 11px;
  line-height: 1.55;
}

/* Attachments */
.compose-attachments {
  padding: 8px 16px;
  flex-shrink: 0;
  border-top: 1px solid var(--line);
  background: var(--surface);
}

.compose-attachments-bar {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 8px;
}

.compose-attachments-bar .reply-btn {
  min-height: 30px;
  padding: 0 12px;
  font-size: 12px;
  border-color: var(--line-strong);
  color: var(--text-2);
}

.compose-attachment-note,
.compose-upload-status {
  color: var(--muted);
  font-size: 11.5px;
  font-weight: 600;
}

.compose-upload-status {
  margin-left: auto;
}

.attachment-list {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(190px, 1fr));
  gap: 8px;
  max-height: 150px;
  margin-top: 10px;
  overflow-y: auto;
}

.attachment-chip {
  display: flex;
  align-items: center;
  gap: 8px;
  min-width: 0;
  padding: 6px 6px 6px 8px;
  border: 1px solid var(--line);
  border-radius: 12px;
  background: var(--surface-2);
}

.attachment-chip .attachment-file-icon {
  width: 32px;
  height: 32px;
  border-radius: 9px;
}

.attachment-chip-info {
  flex: 1;
  min-width: 0;
}

.attachment-chip-name {
  overflow: hidden;
  font-size: 12px;
  font-weight: 600;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.attachment-chip-meta {
  margin-top: 1px;
  overflow: hidden;
  color: var(--subtle);
  font-size: 10px;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.attachment-chip-remove {
  width: 26px;
  height: 26px;
  display: grid;
  place-items: center;
  padding: 0;
  border: 0;
  border-radius: var(--r-pill);
  background: transparent;
  color: var(--muted);
  cursor: pointer;
  flex-shrink: 0;
}

.attachment-chip-remove:hover {
  background: var(--danger-soft);
  color: var(--danger);
}

.attachment-chip-remove svg {
  width: 14px;
  height: 14px;
  stroke: currentColor;
  fill: none;
  stroke-width: 2;
  stroke-linecap: round;
}

.upload-progress {
  padding: 6px 0 0;
}

.upload-progress-track {
  position: relative;
  height: 3px;
  overflow: hidden;
  border-radius: var(--r-pill);
  background: var(--surface-3);
}

.upload-progress-bar {
  height: 100%;
  width: 0;
  border-radius: var(--r-pill);
  background: var(--brand);
  transition: width 0.3s var(--ease);
}

/* Footer */
.compose-footer {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 10px 16px;
  flex-shrink: 0;
  border-top: 1px solid var(--line);
  background: var(--surface);
}

.send-btn {
  min-height: 36px;
  padding: 0 18px;
  font-size: 13px;
  border-color: var(--brand);
  background: var(--brand);
  color: var(--on-brand);
  box-shadow: var(--shadow-1);
}

.send-btn:hover:not(:disabled) {
  background: var(--brand-hover);
  border-color: var(--brand-hover);
}

.send-btn:disabled {
  opacity: 0.45;
  cursor: not-allowed;
}

.compose-footer .reply-btn {
  min-height: 32px;
  padding: 0 10px;
  border-color: transparent;
  color: var(--muted);
  font-size: 12px;
}

.compose-footer .reply-btn:hover {
  background: var(--surface-3);
  color: var(--text);
}

.send-spinner {
  display: none;
  width: 14px;
  height: 14px;
  border: 2px solid rgba(255, 255, 255, 0.35);
  border-top-color: #ffffff;
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
}

.send-btn.loading .send-spinner {
  display: block;
}

.send-btn.loading .send-icon {
  display: none;
}

.compose-from-label {
  margin-left: auto;
  overflow: hidden;
  color: var(--muted);
  font-size: 11px;
  font-weight: 600;
  text-overflow: ellipsis;
  white-space: nowrap;
}

/* Maximized compose and desktop placement */
.compose-modal.is-maximized {
  position: fixed;
  inset: 16px;
  width: auto;
  height: auto;
  max-width: none;
  max-height: none;
  border-radius: 14px;
  transform: none !important;
  resize: none;
}

@media (min-width: 641px) {
  .compose-overlay {
    align-items: flex-end;
    justify-content: flex-end;
  }

  .compose-modal {
    position: fixed;
    right: 20px;
    bottom: 20px;
    top: auto;
    left: auto;
    width: min(620px, calc(100vw - 40px));
    height: min(620px, calc(100vh - 72px));
    max-height: none;
    resize: both;
  }
}


/* ── Compose overflow menu ──────────────────────────────────── */
.compose-more-wrap {
  position: relative;
  display: inline-flex;
}

.compose-more-btn {
  width: 30px;
  height: 30px;
  display: grid;
  place-items: center;
  padding: 0;
  border: 0;
  border-radius: var(--r-pill);
  background: transparent;
  color: var(--muted);
  cursor: pointer;
  transition: background var(--dur-2) var(--ease), color var(--dur-2) var(--ease);
}

.compose-more-btn:hover {
  background: var(--surface-3);
  color: var(--text);
}

.compose-more-btn svg {
  width: 16px;
  height: 16px;
  fill: currentColor;
  stroke: none;
}

.compose-more-menu {
  position: absolute;
  right: 0;
  top: calc(100% + 6px);
  min-width: 180px;
  display: none;
  flex-direction: column;
  padding: 6px;
  border: 1px solid var(--line);
  border-radius: var(--r-md);
  background: var(--surface);
  box-shadow: var(--shadow-3);
  z-index: 90;
  transform-origin: top right;
}

.compose-more-menu.open {
  display: flex;
  animation: scale-in var(--dur-2) var(--ease-out);
}

.compose-more-item {
  display: flex;
  align-items: center;
  min-height: 36px;
  padding: 0 12px;
  border: 0;
  border-radius: var(--r-sm);
  background: transparent;
  color: var(--text);
  font-size: 13px;
  font-weight: 500;
  text-align: left;
  cursor: pointer;
  white-space: nowrap;
}

.compose-more-item:hover {
  background: var(--surface-3);
}

.compose-more-item.is-danger {
  color: var(--danger);
}

.compose-more-item.is-danger:hover {
  background: var(--danger-soft);
}

/* ── Insert HTML panel ──────────────────────────────────────── */
.compose-html-insert {
  padding: 12px 16px;
  flex-shrink: 0;
  border-bottom: 1px solid var(--line);
  background: var(--surface-2);
}

.compose-html-insert[hidden] {
  display: none;
}

.compose-html-insert-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 8px;
  color: var(--text);
  font-size: 12px;
  font-weight: 700;
}

.compose-html-insert-close {
  width: 24px;
  height: 24px;
  display: grid;
  place-items: center;
  padding: 0;
  border: 0;
  border-radius: var(--r-pill);
  background: transparent;
  color: var(--muted);
  font-size: 16px;
  line-height: 1;
  cursor: pointer;
}

.compose-html-insert-close:hover {
  background: var(--surface-4);
  color: var(--text);
}

.compose-html-insert textarea {
  width: 100%;
  min-height: 90px;
  padding: 10px 12px;
  border: 1px solid var(--line);
  border-radius: var(--r-md);
  background: var(--surface);
  color: var(--text);
  font-family: var(--font-mono);
  font-size: 12px;
  line-height: 1.6;
  outline: none;
  resize: vertical;
}

.compose-html-insert textarea:focus {
  border-color: var(--brand);
  box-shadow: 0 0 0 1px var(--brand);
}

.compose-html-insert-actions {
  display: flex;
  justify-content: flex-end;
  gap: 6px;
  margin-top: 8px;
}

/* ── Reading-pane overflow menu ─────────────────────────────── */
.mail-more-wrap {
  position: relative;
  display: inline-flex;
}

.mail-more-menu {
  position: absolute;
  right: 0;
  top: calc(100% + 6px);
  display: none;
  flex-direction: column;
  align-items: stretch;
  gap: 1px;
  width: max-content;
  min-width: 210px;
  max-width: min(280px, calc(100vw - 32px));
  max-height: 320px;
  overflow-y: auto;
  padding: 6px;
  border: 1px solid var(--line);
  border-radius: var(--r-md);
  background: var(--surface);
  box-shadow: var(--shadow-3);
  z-index: 70;
  transform-origin: top right;
}

.mail-more-menu.open {
  display: flex;
  animation: scale-in var(--dur-2) var(--ease-out);
}

.mail-more-menu .menu-label-item {
  min-height: 34px;
}

.mail-more-menu .menu-divider {
  flex: 0 0 auto;
  height: 1px;
  margin: 6px 0;
  background: var(--line-strong);
}

.mail-more-menu .menu-label-name {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.mail-more-menu .menu-label-item svg {
  width: 16px;
  height: 16px;
  flex-shrink: 0;
  stroke: currentColor;
  fill: none;
  stroke-width: 2;
  stroke-linecap: round;
  stroke-linejoin: round;
}

.mail-more-heading {
  padding: 8px 10px 4px;
  color: var(--subtle);
  font-size: 10px;
  font-weight: 700;
  letter-spacing: 0.08em;
  text-transform: uppercase;
}

.mail-more-empty {
  padding: 8px 10px;
  color: var(--muted);
  font-size: 12px;
}

.mail-more-source {
  display: none !important;
}

/* ── Autocomplete ──────────────────────────────────────────── */
.autocomplete-dropdown {
  position: absolute;
  left: 0;
  right: 0;
  top: calc(100% + 4px);
  display: none;
  max-height: 200px;
  overflow-y: auto;
  z-index: 80;
}

.autocomplete-dropdown.show {
  display: block;
  animation: scale-in var(--dur-2) var(--ease-out);
}

.autocomplete-item {
  font-weight: 500;
}

.autocomplete-item-name {
  overflow: hidden;
  font-weight: 700;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.autocomplete-item-email {
  flex-shrink: 1;
  min-width: 0;
  overflow: hidden;
  color: var(--muted);
  text-overflow: ellipsis;
  white-space: nowrap;
}

.autocomplete-item-sep {
  color: var(--subtle);
}

/* ── Toast (snackbar) ──────────────────────────────────────── */
.toast {
  position: fixed;
  left: 50%;
  bottom: 24px;
  z-index: 400;
  max-width: calc(100vw - 40px);
  padding: 10px 16px;
  border-radius: var(--r-sm);
  background: #323232;
  color: #ffffff;
  box-shadow: var(--shadow-3);
  font-size: 13px;
  font-weight: 500;
  opacity: 0;
  pointer-events: none;
  transform: translateX(-50%) translateY(12px);
  transition: opacity var(--dur-2) var(--ease), transform var(--dur-3) var(--ease-out);
}

html[data-theme="dark"] .toast,
body[data-theme="dark"] .toast {
  background: #E8EAED;
  color: #1D1D1F;
}

.toast.show {
  opacity: 1;
  transform: translateX(-50%) translateY(0);
}

.toast.err {
  background: var(--danger);
  color: #ffffff;
}

/* ── Shortcuts ─────────────────────────────────────────────── */
.shortcuts-overlay {
  position: fixed;
  inset: 0;
  z-index: 200;
  display: none;
  align-items: center;
  justify-content: center;
  padding: 20px;
  background: var(--scrim);
  backdrop-filter: blur(3px);
  -webkit-backdrop-filter: blur(3px);
}

.shortcuts-overlay.show {
  display: flex;
  animation: fade-in var(--dur-2) var(--ease);
}

.shortcuts-modal {
  width: min(480px, calc(100vw - 40px));
  max-height: 82vh;
  overflow-y: auto;
  border: 0;
  border-radius: var(--r-xl);
  background: var(--surface);
  box-shadow: var(--shadow-4);
  animation: rise-in var(--dur-3) var(--ease-out);
}

.shortcuts-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 18px 20px;
  border-bottom: 1px solid var(--line);
  color: var(--text);
  font-size: 16px;
  font-weight: 700;
}

.shortcuts-grid {
  display: grid;
  grid-template-columns: auto 1fr;
  align-items: center;
  gap: 10px 16px;
  padding: 18px 20px;
  font-size: 14px;
}

.shortcuts-grid kbd {
  padding: 4px 9px;
  border: 1px solid var(--line-strong);
  border-radius: var(--r-xs);
  background: var(--surface-3);
  font-family: var(--font-mono);
  font-size: 12px;
  font-weight: 600;
  text-align: center;
  white-space: nowrap;
}



/* ── Density ───────────────────────────────────────────────── */
/* Comfortable — the default rhythm. */
body.density-comfortable .thread-item {
  padding: 10px;
}

body.density-comfortable .thread-subject {
  font-size: 13px;
}

body.density-comfortable .thread-preview {
  font-size: 12px;
  -webkit-line-clamp: 1;
}

body.density-comfortable .thread-from {
  font-size: 12px;
}

body.density-comfortable .thread-time {
  font-size: 11px;
}

body.density-comfortable .thread-avatar {
  width: 34px;
  height: 34px;
}

body.density-comfortable .thread-tags {
  margin-top: 4px;
}

/* Compact — one step tighter, for long lists. */
body.density-compact .thread-item {
  gap: 8px;
  padding: 7px 10px;
}

body.density-compact .thread-subject {
  margin-bottom: 2px;
  font-size: 12.5px;
}

body.density-compact .thread-preview {
  font-size: 11.5px;
  -webkit-line-clamp: 1;
}

body.density-compact .thread-from {
  margin-bottom: 1px;
  font-size: 11.5px;
}

body.density-compact .thread-time {
  font-size: 10.5px;
}

body.density-compact .thread-avatar {
  width: 28px;
  height: 28px;
}

body.density-compact .thread-avatar-initials {
  font-size: 10px;
}

body.density-compact .thread-tags {
  margin-top: 3px;
}

body.density-compact .thread-tag {
  padding: 1px 6px;
  font-size: 9px;
}

body.density-compact .thread-toolbar {
  height: 46px;
}

/* ── Gmail single-pane layout mode ─────────────────────────── */
body.layout-gmail .mail-panel {
  position: relative;
  grid-template-columns: 1fr;
  overflow: hidden;
}

body.layout-gmail .mail-view {
  position: absolute;
  inset: 0;
  z-index: 2;
  background: var(--surface-2);
  transform: translateX(100%);
  transition: transform var(--dur-4) var(--ease-drawer);
  will-change: transform;
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

body.layout-gmail .mail-panel.message-open .mail-view {
  transform: translateX(0);
}

body.layout-gmail .thread-list {
  position: absolute;
  inset: 0;
  width: 100%;
  z-index: 1;
  background: var(--surface);
  border-right: 0;
  transition: transform var(--dur-4) var(--ease-drawer);
}

body.layout-gmail .mail-panel.message-open .thread-list {
  transform: translateX(-30%);
}

body.layout-gmail #splitResize {
  display: none;
}

body.layout-gmail .mobile-back-btn {
  display: grid;
}

body.layout-gmail .mail-header-bar {
  border-radius: 0;
}

/* The reader is full-width in Gmail layout, so keep its content centred
   instead of pinning it to the far left of a wide screen. */
body.layout-gmail #messageView {
  align-items: center;
}

body.layout-gmail .mail-header-bar,
body.layout-gmail .mail-body-scroll {
  width: 100%;
  margin-left: auto;
  margin-right: auto;
}

body.layout-gmail .reply-bar {
  align-self: stretch;
}

/* ── Responsive ────────────────────────────────────────────── */
@media (min-width: 901px) {
  .resize-handle {
    display: block;
  }
}

@media (max-width: 1100px) {
  :root {
    --thread-w: 320px;
  }
}

@media (max-width: 900px) {
  header {
    grid-template-columns: auto minmax(0, 1fr) auto;
    gap: 8px;
    padding-right: 12px;
  }

  .sidebar-toggle {
    display: grid;
  }

  .h-logo {
    width: auto;
    margin-left: 0;
    padding: 0 8px;
    justify-content: flex-start;
  }

  .h-logo svg {
    width: 24px;
    height: 24px;
  }

  /* Drawer-only header: brand row → divider → Compose */
  .side-drawer-head {
    display: flex;
    align-items: center;
    margin: 2px 0 6px;
  }

  .drawer-logo {
    height: 40px;
    padding: 0 10px;
    font-size: 16px;
  }

  .drawer-logo svg {
    width: 24px;
    height: 24px;
  }

  .side-drawer-divider {
    height: 1px;
    margin: 4px 8px 10px;
    background: var(--line);
  }

  aside {
    position: fixed;
    top: 0;
    bottom: 0;
    left: 0;
    z-index: 40;
    width: 280px;
    padding: 16px 12px 24px;
    background: var(--surface);
    border-right: 1px solid var(--line);
    box-shadow: var(--shadow-3);
    transform: translateX(-100%);
    transition: transform var(--dur-4) var(--ease-drawer);
  }

  .sidebar-open aside {
    transform: translateX(0);
  }

  .sidebar-backdrop {
    position: fixed;
    inset: 0;
    z-index: 39;
    display: none;
    background: var(--scrim);
    backdrop-filter: blur(2px);
    -webkit-backdrop-filter: blur(2px);
  }

  .sidebar-open .sidebar-backdrop {
    display: block;
  }

  .app-body {
    grid-template-columns: 1fr;
  }

  .status-bar .status-item:nth-child(3) {
    display: none;
  }
}

@media (max-width: 720px) {
  :root {
    --header-h: 58px;
  }

  .user-chip {
    width: 38px;
    min-width: 38px;
    max-width: 38px;
    padding: 0;
    justify-content: center;
    border-radius: 50%;
  }

  .user-chip-email,
  .user-chip-caret {
    display: none;
  }

  .h-logo {
    font-size: 15px;
  }
}

@media (max-width: 640px) {
  :root {
    --header-h: 56px;
    --status-h: 0px;
    --thread-w: 100%;
  }

  header {
    gap: 6px;
    padding-right: 8px;
  }

  header .h-logo {
    padding: 0 4px;
    font-size: 0;
  }

  header .h-logo svg {
    width: 24px;
    height: 24px;
  }

  .h-search {
    height: 42px;
    padding: 0 14px;
  }

  .h-right {
    gap: 0;
  }

  .h-right .icon-btn {
    width: 38px;
    height: 38px;
  }

  #refreshBtn {
    display: none;
  }

  .status-bar {
    display: none;
  }

  .app-body {
    height: calc(100dvh - var(--header-h));
    overflow: hidden;
  }

  .mail-panel {
    position: relative;
    grid-template-columns: 1fr;
    height: 100%;
    overflow: hidden;
  }

  .thread-list {
    position: absolute;
    inset: 0;
    z-index: 1;
    width: 100%;
    border-right: 0;
    background: var(--surface);
    transform: translateX(0);
    transition: transform var(--dur-4) var(--ease-drawer);
  }

  .mail-view {
    position: absolute;
    inset: 0;
    z-index: 2;
    width: 100%;
    background: var(--surface-2);
    transform: translateX(100%);
    transition: transform var(--dur-4) var(--ease-drawer);
  }

  .mail-panel.message-open .mail-view {
    transform: translateX(0);
  }

  .mail-panel.message-open .thread-list {
    transform: translateX(-30%);
  }

  #messageView {
    display: none;
    flex: 1;
    min-height: 0;
    flex-direction: column;
    overflow: hidden;
  }

  #messageView[style*="flex"] {
    display: flex !important;
  }

  .mobile-back-btn {
    display: grid;
  }

  .thread-items {
    padding: 6px;
  }

  .thread-item {
    min-height: 76px;
    padding: 12px 10px;
    gap: 10px;
  }

  .thread-subject {
    font-size: 14px;
  }

  .thread-preview {
    font-size: 12px;
  }

  .thread-from {
    font-size: 12px;
  }

  .thread-time {
    font-size: 11px;
  }

  .mail-header-bar {
    align-items: center;
    min-height: 0;
    padding: 12px 14px;
    gap: 8px;
  }

  .mail-reader-identity {
    gap: 10px;
  }

  .mail-reader-avatar {
    width: 36px;
    height: 36px;
    font-size: 11.5px;
  }

  .mail-reader-name {
    font-size: 14px;
  }

  .mail-reader-address {
    font-size: 11.5px;
  }

  .mail-reader-meta {
    font-size: 11.5px;
  }

  .mail-header-actions {
    flex: 0 0 auto;
    margin-left: auto;
    gap: 2px;
  }

  .mail-header-actions .icon-btn {
    flex: 0 0 36px;
    width: 36px;
    height: 36px;
  }

  body.layout-gmail .reply-bar {
    align-self: stretch;
    margin: 0;
  }

  .mail-body-scroll {
    padding: 20px 14px 24px;
  }

  .mail-reader-subject {
    font-size: 21px;
    margin-bottom: 6px;
  }

  .mail-thread-head {
    gap: 8px;
    margin-bottom: 6px;
  }

  .mail-thread-count {
    min-width: 22px;
    height: 22px;
    padding: 0 7px;
    font-size: 11.5px;
  }

  .mail-thread-list {
    gap: 8px;
  }

  .mail-thread-message {
    border-radius: 12px;
  }

  .mail-thread-summary {
    gap: 10px;
    padding: 11px 12px;
  }

  .mail-thread-avatar {
    width: 30px;
    height: 30px;
    font-size: 10.5px;
  }

  .mail-thread-content {
    padding: 12px 12px 16px;
  }

  .mail-reader-subline {
    margin-bottom: 16px;
  }

  .mail-reader-rule {
    margin-bottom: 18px;
  }

  .mail-reader-body {
    font-size: 14.5px;
    line-height: 1.7;
    overflow-x: auto;
  }

  .mail-details {
    padding: 12px;
  }

  .mail-attachments {
    margin-top: 22px;
  }

  .reply-bar {
    margin: 0;
    padding: 10px 14px;
    gap: 4px;
    overflow-x: auto;
  }

  .reply-btn {
    min-height: 38px;
    padding: 0 16px;
    font-size: 13px;
  }

  .mail-view-empty svg {
    width: 56px;
    height: 56px;
  }

  .mail-view-empty h3 {
    font-size: 19px;
  }

  /* Compose becomes a bottom sheet */
  .compose-overlay {
    padding: 0;
    align-items: flex-end;
    justify-content: center;
  }

  .compose-overlay.show {
    animation: compose-scrim-in 0.25s var(--ease-out);
  }

  .compose-overlay.closing {
    animation: compose-scrim-out 0.26s var(--ease-drawer) both;
  }

  .compose-modal {
    position: relative;
    right: auto;
    bottom: auto;
    width: 100%;
    height: auto;
    min-height: 68dvh;
    max-height: calc(100dvh - var(--header-h));
    border-radius: 16px 16px 0 0;
    box-shadow: var(--shadow-4);
    resize: none;
    animation: compose-sheet-in 0.36s var(--ease-drawer);
  }

  .compose-overlay.closing .compose-modal {
    animation: compose-sheet-out 0.26s var(--ease-drawer) both;
  }

  /* Ambient touch: scrolling gestures still work, but the browser's native
     page pinch-zoom stays off everywhere — email content zooms via the
     JS-driven pinch handler instead. */
  body,
  #mailBodyScroll {
    touch-action: pan-x pan-y;
  }

  #composeMaxBtn {
    display: none !important;
  }

  .compose-field {
    grid-template-columns: 52px minmax(0, 1fr);
    padding: 0 14px;
  }

  .compose-body {
    min-height: 120px;
  }

  .compose-footer {
    flex-wrap: wrap;
    padding: 10px 16px;
  }

  .compose-from-label {
    width: 100%;
    margin-left: 0;
    text-align: left;
  }

  .chip {
    min-height: 24px;
  }

  .chip-input {
    min-width: 70px;
  }

  .toast {
    bottom: calc(84px + env(safe-area-inset-bottom, 0px));
  }

  .compose-overlay.show ~ .mobile-fab-compose {
    display: none;
  }

  .shortcuts-modal {
    width: 100%;
  }
}

@media (max-width: 380px) {
  .h-search {
    height: 40px;
    padding: 0 12px;
  }

  .thread-item {
    min-height: 68px;
    padding: 10px 8px;
  }

  .compose-field {
    grid-template-columns: 52px minmax(0, 1fr);
    padding: 0 12px;
  }
}

/* ── Print ─────────────────────────────────────────────────── */
@media print {
  header,
  aside,
  .sidebar-backdrop,
  .thread-list,
  .resize-handle,
  .reply-bar,
  .mail-header-actions,
  .status-bar,
  .toast,
  .compose-overlay,
  .shortcuts-overlay,
  .app-loading-overlay,
  .load-more-wrap,
  .search-scope-hint,
  .mail-details-toggle,
  .mobile-fab-compose {
    display: none !important;
  }

  html,
  body {
    height: auto !important;
    overflow: visible !important;
    background: #fff !important;
  }

  .app-body {
    display: block !important;
    height: auto !important;
  }

  .mail-panel {
    display: block !important;
  }

  .mail-view,
  #messageView {
    display: block !important;
    position: static !important;
    height: auto !important;
    overflow: visible !important;
    transform: none !important;
    background: #fff !important;
  }

  .mail-view-empty {
    display: none !important;
  }

  .mail-body-scroll {
    height: auto !important;
    overflow: visible !important;
    padding: 0 !important;
  }

  .mail-details {
    display: grid !important;
  }

  .mail-thread-details,
  .mail-thread-details-toggle,
  .mail-thread-delete {
    display: none !important;
  }

  .mail-thread-message {
    border: 0 !important;
    border-radius: 0 !important;
    break-inside: avoid;
  }

  .mail-thread-summary {
    padding: 8px 0 !important;
  }

  .mail-thread-avatar,
  .mail-thread-chevron {
    display: none !important;
  }

  .mail-thread-foldmark,
  .mail-thread-node,
  .mail-thread--fold .mail-thread-list::before,
  .mail-thread--rail .mail-thread-list::before,
  .mail-thread--fold .mail-thread-content::before,
  .mail-thread--rail .mail-thread-content::before {
    display: none !important;
  }

  .mail-thread--fold .mail-thread-list,
  .mail-thread--rail .mail-thread-list {
    padding-left: 0 !important;
    border-bottom: 0 !important;
  }

  .mail-thread-content,
  .mail-thread-content[hidden] {
    display: block !important;
    padding: 0 0 14px !important;
    border-top: 0 !important;
  }

  .mail-reader,
  .mail-view,
  #messageView {
    animation: none !important;
    box-shadow: none !important;
  }
}

/* ── Access denied ───────────────────────────────────────────── */
.access-denied {
  max-width: 380px;
  padding: 28px;
  border: 1px solid var(--line);
  border-radius: var(--r-lg);
  background: var(--surface);
  box-shadow: var(--shadow-2);
  text-align: center;
}

.access-denied-title {
  margin: 0 0 8px;
  color: var(--text);
  font-size: 18px;
  font-weight: 700;
  letter-spacing: -0.01em;
}

.access-denied-text {
  margin: 0 0 20px;
  color: var(--muted);
  font-size: 13px;
  line-height: 1.6;
}

.access-denied-actions {
  display: flex;
  justify-content: center;
  gap: 8px;
}
