/* Soveraign Mail — dark brand theme (performance-first: solid fills, system fonts, no list effects) */
:root {
  /* Surfaces */
  --bg: #14181c;
  --bg-elevated: #1c2228;
  --bg-hover: #283038;
  --bg-active: #2e3842;
  --bg-input: #101418;
  --bg-table-head: #242c34;

  /* Lines & text */
  --border: #3a4652;
  --border-strong: #4d5c6b;
  --text: #a8b3bd;
  --text-strong: #e8eef2;
  --muted: #6f7b86;

  /* Brand & status */
  --primary: #3db8a8;
  --primary-hover: #2aa89a;
  --primary-muted: rgba(61, 184, 168, 0.14);
  --primary-muted-soft: rgba(61, 184, 168, 0.09);
  --danger: #e5534b;
  --danger-hover: #d0453d;
  --flash: #3d9a4a;
  --flash-muted: rgba(61, 154, 74, 0.18);
  --flash-error: #c93c37;
  --flash-error-muted: rgba(201, 60, 55, 0.15);
  --warning: #daaa3f;
  --warning-border: #9e6a03;
  --warning-muted: rgba(218, 170, 63, 0.12);
  --unread: #e8eef2;
  --focus-ring: rgba(61, 184, 168, 0.55);

  /* Elevation (rare UI only: modal / autocomplete) */
  --shadow-dropdown: 0 8px 24px rgba(0, 0, 0, 0.4);
  --shadow-modal: 0 16px 40px rgba(0, 0, 0, 0.5);
  --overlay: rgba(0, 0, 0, 0.58);

  /* Mail body island (do not invert HTML mail) */
  --mail-bg: #fff;
  --mail-text: #222;

  /* Layout */
  --sidebar-w: 220px;
  --radius: 8px;
  --radius-lg: 12px;
  --font: -apple-system, BlinkMacSystemFont, "Segoe UI", Helvetica, Arial, sans-serif;
  --font-mono: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  --control-transition: background-color 0.12s ease, border-color 0.12s ease, color 0.12s ease;
}

* { box-sizing: border-box; }

[hidden] {
  display: none !important;
}

html, body {
  margin: 0;
  padding: 0;
  height: 100%;
  font-family: var(--font);
  background: var(--bg);
  color: var(--text);
}

/* Thin themed scrollbars (cheap; list/reader only benefit) */
.msg-list-scroll,
.mail-read-pane .message-body,
.picker-list,
.autocomplete-list {
  scrollbar-width: thin;
  scrollbar-color: var(--bg-hover) var(--bg);
}

.msg-list-scroll::-webkit-scrollbar,
.mail-read-pane .message-body::-webkit-scrollbar,
.picker-list::-webkit-scrollbar,
.autocomplete-list::-webkit-scrollbar {
  width: 8px;
  height: 8px;
}

.msg-list-scroll::-webkit-scrollbar-track,
.mail-read-pane .message-body::-webkit-scrollbar-track,
.picker-list::-webkit-scrollbar-track,
.autocomplete-list::-webkit-scrollbar-track {
  background: var(--bg);
}

.msg-list-scroll::-webkit-scrollbar-thumb,
.mail-read-pane .message-body::-webkit-scrollbar-thumb,
.picker-list::-webkit-scrollbar-thumb,
.autocomplete-list::-webkit-scrollbar-thumb {
  background: var(--bg-hover);
  border-radius: 4px;
}

a { color: var(--primary); text-decoration: none; }
a:hover { text-decoration: underline; }

.app {
  display: flex;
  min-height: 100vh;
  min-height: 100dvh;
  height: 100vh;
  height: 100dvh;
  overflow: hidden;
}

.sidebar {
  width: var(--sidebar-w);
  background: var(--bg-elevated);
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  padding: 1rem 0.75rem;
  gap: 0.75rem;
  position: sticky;
  top: 0;
  height: 100vh;
  height: 100dvh;
}

.brand a {
  color: var(--text-strong);
  font-weight: 700;
  font-size: 1.05rem;
  text-decoration: none;
  display: flex;
  align-items: center;
  gap: 0.65rem;
}

.brand a:hover { text-decoration: none; }

.brand-logo {
  width: 2.0rem;
  height: 2.2rem;
  border-radius: 0.55rem;
  object-fit: cover;
  flex-shrink: 0;
}

.compose-btn { display: block; text-align: center; margin: 0.25rem 0 0.5rem; }

/* Secondary sidebar chrome is grouped for the mobile overflow menu but keeps
   the original desktop column order (wrapper collapses into its children). */
.sidebar-secondary {
  display: contents;
}

.sidebar-secondary .account-link { order: 1; }
.sidebar-secondary .compose-btn { order: 2; }
.folder-nav { order: 3; }
.sidebar-secondary .sidebar-settings { order: 4; }
.sidebar-secondary .sidebar-bottom { order: 5; }

/* Mobile-only overflow menu trigger (hidden on desktop). */
.mobile-menu-btn {
  display: none;
}

/* Folder picker: desktop keeps the plain column nav (wrapper collapses). */
.folder-picker {
  display: contents;
}

.folder-picker-btn {
  display: none;
}

/* Compose joins the bottom action pill on mobile list browsing. */
.compose-pill-btn {
  display: none;
}

.folder-nav {
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.folder-nav a,
.folder-nav button,
.nav-link-btn {
  color: var(--text);
  padding: 0.45rem 0.65rem;
  border-radius: var(--radius);
  text-decoration: none;
  transition: var(--control-transition);
}

.folder-nav button,
.nav-link-btn {
  background: none;
  border: none;
  font: inherit;
  text-align: left;
  cursor: pointer;
  width: 100%;
  color: var(--muted);
}

.folder-nav button:hover,
.nav-link-btn:hover {
  color: var(--text-strong);
}

.nav-link-btn.is-enabled {
  color: var(--text-strong);
}

.folder-nav a:hover,
.folder-nav button:hover,
.nav-link-btn:hover {
  background: var(--bg-hover);
  text-decoration: none;
  color: var(--text-strong);
}

.folder-nav a.active {
  background: var(--primary-muted);
  color: var(--text-strong);
  font-weight: 600;
  box-shadow: inset 3px 0 0 var(--primary);
}

.folder-nav a:focus-visible,
.folder-nav button:focus-visible,
.nav-link-btn:focus-visible {
  outline: 2px solid var(--focus-ring);
  outline-offset: 1px;
}

.sidebar-bottom {
  margin-top: auto;
  display: flex;
  flex-direction: column;
}

.sidebar-settings {
  margin-top: 0.35rem;
  margin-bottom: 0.65rem;
}

.settings-toggle {
  display: flex;
  align-items: center;
  justify-content: space-between;
}

/* Gear icon only shows in the mobile top bar; desktop keeps the text link. */
.settings-toggle .btn-icon {
  display: none;
}

.settings-toggle::after {
  content: "▸";
  color: var(--muted);
}

.settings-toggle[aria-expanded="true"]::after {
  content: "▾";
}

.settings-panel {
  display: flex;
  flex-direction: column;
  gap: 2px;
  max-height: 0;
  opacity: 0;
  overflow: hidden;
  visibility: hidden;
  transform: translateY(10px);
  transition: max-height 0.28s ease, opacity 0.22s ease, transform 0.28s ease,
    visibility 0s linear 0.28s;
}

.sidebar-settings.is-open .settings-panel {
  max-height: 180px;
  opacity: 1;
  visibility: visible;
  transform: translateY(0);
  transition: max-height 0.28s ease, opacity 0.22s ease, transform 0.28s ease,
    visibility 0s;
}

.settings-panel .nav-link-btn {
  padding-left: 1.1rem;
}

.settings-panel .nav-link-btn.settings-outlined {
  width: fit-content;
  align-self: flex-start;
  margin: 0.15rem 0.75rem 0.3rem 1.1rem;
  padding: 0.2rem 0.6rem;
  border: 1px solid var(--border);
  border-radius: 999px;
  font-size: 0.85rem;
  color: var(--text);
  text-align: center;
  white-space: nowrap;
}

.settings-panel .nav-link-btn.settings-outlined:hover,
.settings-panel .nav-link-btn.settings-outlined:focus-visible {
  border-color: var(--primary);
  color: var(--primary);
  background-color: var(--primary-muted);
  outline: none;
}

.settings-status {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.5rem;
  padding: 0.35rem 0.75rem 0.35rem 1.1rem;
  font-size: 0.85rem;
  color: var(--muted);
}

.settings-status.settings-action {
  cursor: pointer;
  border-radius: 6px;
  transition: background-color 0.15s ease;
}

.settings-status.settings-action:hover,
.settings-status.settings-action:focus-visible {
  background-color: rgba(128, 128, 128, 0.1);
  outline: none;
}

.settings-action-form {
  display: block;
  margin: 0;
  width: 100%;
}

/* Button reset so Unified mail matches the Notifications settings row.
   UA button styles + font/color:inherit were overriding .settings-status. */
button.settings-status.settings-toggle-btn {
  appearance: none;
  -webkit-appearance: none;
  width: 100%;
  margin: 0;
  border: 0;
  background: transparent;
  box-sizing: border-box;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.5rem;
  padding: 0.35rem 0.75rem 0.35rem 1.1rem;
  font-family: inherit;
  font-size: 0.85rem;
  font-weight: inherit;
  line-height: inherit;
  color: var(--muted);
  text-align: left;
  cursor: pointer;
}

.settings-badge {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 2.2rem;
  text-align: center;
  font-size: 0.7rem;
  font-weight: 600;
  padding: 0.1rem 0.45rem;
  border-radius: 999px;
  text-transform: uppercase;
  letter-spacing: 0.04em;
}

.settings-badge.is-on {
  color: var(--flash);
  border: 1px solid var(--flash);
}

.settings-badge.is-off {
  color: var(--muted);
  border: 1px solid var(--border);
}

.settings-badge.is-plain {
  text-transform: none;
  letter-spacing: 0;
  color: var(--primary);
  border: 1px solid var(--border);
}

.sidebar-footer {
  padding-top: 1rem;
  border-top: 1px solid var(--border);
}

.user-email {
  font-size: 0.8rem;
  color: var(--muted);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  margin-bottom: 0.5rem;
}

.sidebar-version {
  display: inline-block;
  align-self: flex-start;
  margin-top: 0.65rem;
  margin-bottom: 0.55rem;
  padding: 0.15rem 0.5rem;
  font-size: 0.72rem;
  line-height: 1.3;
  color: var(--muted);
  font-family: var(--font-mono);
  font-variant-numeric: tabular-nums;
  word-break: break-word;
  border: 1px solid var(--border);
  border-radius: 999px;
  background: transparent;
}

/* Compact debug timings — stacked rows fit the narrow sidebar */
.perf-stats {
  margin-bottom: 0.65rem;
  padding-bottom: 0.55rem;
  border-bottom: 1px solid var(--border);
  font-size: 0.7rem;
  line-height: 1.3;
  color: var(--muted);
  font-variant-numeric: tabular-nums;
  font-family: var(--font-mono);
  display: flex;
  flex-direction: column;
  gap: 0.15rem;
  min-width: 0;
}

.perf-row {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 0.5rem;
  min-width: 0;
}

.perf-label {
  flex: 0 0 auto;
  color: var(--muted);
  opacity: 0.85;
}

.perf-value {
  flex: 1 1 auto;
  text-align: right;
  color: var(--text);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.main {
  flex: 1;
  padding: 1.25rem 1.5rem 2rem;
  min-width: 0;
  min-height: 0;
  /* App shell is height-locked; non-split pages (contacts, compose, …) must scroll here */
  overflow: auto;
  -webkit-overflow-scrolling: touch;
}

.main-split {
  padding: 0;
  display: flex;
  flex-direction: column;
  height: 100%;
  max-height: 100vh;
  max-height: 100dvh;
  /* Override .main: panes own their own scroll regions */
  overflow: hidden;
  min-height: 0;
}

.main-split > .flash,
.main-split > .flash-error {
  margin: 0.75rem 1rem 0;
}

/* Split pane: list | reader */
.mail-split {
  display: grid;
  grid-template-columns: minmax(280px, 38%) 1fr;
  flex: 1;
  min-height: 0;
  height: 100%;
}

.mail-list-pane {
  display: flex;
  flex-direction: column;
  min-width: 0;
  border-right: 1px solid var(--border);
  background: var(--bg);
  height: 100%;
  overflow: hidden;
}

/* Soft pager: mute list briefly while the next page is fetched.
   Keep the pane interactive so the page-jump input still accepts
   clicks/typing while a load is in flight (loads are race-guarded). */
.mail-list-pane.is-loading {
  opacity: 0.72;
  transition: opacity 0.12s ease;
}

.mail-read-pane {
  display: flex;
  flex-direction: column;
  min-width: 0;
  min-height: 0;
  height: 100%;
  overflow: hidden; /* header stays put; body scrolls */
  padding: 1rem 1.25rem 1.5rem;
  background: var(--bg);
}

/* Soft open: keep prior content visible but muted until the new body arrives */
.mail-read-pane.is-loading {
  opacity: 0.72;
  transition: opacity 0.12s ease;
}

.message-body-loading {
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 2.5rem 1.5rem;
  gap: 0.75rem;
  color: var(--muted);
  font-size: 0.9rem;
}

.message-body-spinner {
  flex-shrink: 0;
  width: 20px;
  height: 20px;
  border: 2px solid var(--border);
  border-top-color: var(--primary);
  border-radius: 50%;
  animation: message-body-spin 0.65s linear infinite;
}

@keyframes message-body-spin {
  to { transform: rotate(360deg); }
}

.pane-header {
  padding: 0.85rem 1rem 0.5rem;
  margin-bottom: 0;
  flex-shrink: 0;
}

.pane-header h1 {
  font-size: 1.15rem;
}

.list-actions {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 0.35rem;
}

/* Mail search subheader (toggled like Select) */
.mail-search-panel {
  display: none;
  flex-direction: column;
  gap: 0.45rem;
  padding: 0.5rem 0.65rem 0.6rem;
  flex-shrink: 0;
  border-bottom: 1px solid var(--border);
  background: var(--bg-elevated);
}

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

.mail-search-panel.is-open,
.mail-search-panel:not([hidden]) {
  display: flex;
}

.mail-search-row {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 0.35rem;
}

.mail-search-input {
  flex: 1 1 8rem;
  min-width: 0;
  background: var(--bg-input);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  color: var(--text-strong);
  padding: 0.4rem 0.6rem;
  font: inherit;
  font-size: 0.88rem;
  transition: var(--control-transition);
}

.mail-search-input:focus-visible {
  outline: none;
  border-color: var(--primary);
  box-shadow: 0 0 0 3px var(--primary-muted);
}

.mail-search-input::placeholder {
  color: var(--muted);
}

.search-field-toggles {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 0.35rem;
}

.search-chip {
  display: inline-flex;
  align-items: center;
  gap: 0.3rem;
  padding: 0.2rem 0.55rem;
  border: 1px solid var(--border);
  border-radius: 999px;
  background: var(--bg);
  color: var(--text);
  font-size: 0.8rem;
  cursor: pointer;
  user-select: none;
}

.search-chip:has(input:checked) {
  background: var(--primary-muted);
  border-color: var(--primary);
  color: var(--text-strong);
}

.search-chip input {
  accent-color: var(--primary);
  margin: 0;
  cursor: pointer;
}

.contacts-toolbar {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 0.65rem;
  margin-bottom: 0.85rem;
}

.contacts-search {
  flex: 1 1 14rem;
  min-width: 0;
  margin: 0;
}

.contacts-search-input {
  width: 100%;
  background: var(--bg-input);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  color: var(--text-strong);
  padding: 0.5rem 0.65rem;
  font: inherit;
  font-size: 0.9rem;
  transition: var(--control-transition);
}

.contacts-search-input:focus-visible {
  outline: none;
  border-color: var(--primary);
  box-shadow: 0 0 0 3px var(--primary-muted);
}

.contacts-search-meta {
  font-size: 0.82rem;
  font-variant-numeric: tabular-nums;
}

.contacts-empty-filter {
  margin-top: 0.5rem;
}

.contact-name-form {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 0.35rem;
  margin: 0;
}

.contact-name-input {
  flex: 1 1 8rem;
  min-width: 0;
  max-width: 16rem;
  background: var(--bg-input);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  color: var(--text-strong);
  padding: 0.35rem 0.5rem;
  font: inherit;
  font-size: 0.88rem;
}

.contact-name-input:focus-visible {
  outline: none;
  border-color: var(--primary);
  box-shadow: 0 0 0 3px var(--primary-muted);
}

.contacts-table .contact-name-cell {
  min-width: 12rem;
}

.contact-whitelist-cell {
  white-space: nowrap;
}

.contact-whitelist-toggle {
  transition: background 0.2s, border-color 0.2s, color 0.2s;
}

.contact-whitelist-toggle[data-whitelisted="0"] {
  background: color-mix(in srgb, var(--danger, #c62828) 10%, transparent);
  border-color: var(--danger, #c62828);
  color: var(--danger, #c62828);
}

.contact-whitelist-toggle[data-whitelisted="1"] {
  background: color-mix(in srgb, var(--success, #2e7d32) 10%, transparent);
  border-color: var(--success, #2e7d32);
  color: var(--success, #2e7d32);
}

.contact-whitelist-changed {
  animation: contact-whitelist-flash 0.3s ease;
}

@keyframes contact-whitelist-flash {
  0%   { filter: brightness(1.4); }
  100% { filter: brightness(1); }
}

.contact-action-cell {
  white-space: nowrap;
  display: flex;
  flex-wrap: wrap;
  gap: 0.35rem;
}

.contact-action-cell .btn {
  white-space: nowrap;
  flex-shrink: 0;
}

.contacts-table td {
  overflow-wrap: anywhere;
}

.list-actions .btn[aria-pressed="true"] {
  background: var(--primary-muted);
  border-color: var(--primary);
  color: var(--text-strong);
}

.bulk-form {
  display: flex;
  flex-direction: column;
  flex: 1;
  min-height: 0;
}

.bulk-bar {
  display: none;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 0.45rem 0.75rem;
  padding: 0.45rem 0.65rem;
  border-bottom: 1px solid var(--border);
  background: var(--bg-elevated);
  flex-shrink: 0;
}

/* Author display rules beat the [hidden] UA style — re-assert hide */
.bulk-bar[hidden] {
  display: none !important;
}

.bulk-form.is-multiselect .bulk-bar,
.bulk-bar:not([hidden]) {
  display: flex;
}

.bulk-actions {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 0.35rem;
}

.bulk-count {
  font-size: 0.82rem;
  font-variant-numeric: tabular-nums;
}

.msg-list-scroll {
  flex: 1;
  overflow: auto;
  overflow-x: hidden;
  min-height: 0;
  position: relative;
}

.list-loading-overlay {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  background: rgba(20, 24, 28, 0.55);
  z-index: 5;
  gap: 0.75rem;
  color: var(--muted);
  font-size: 0.9rem;
}

.list-loading-spinner {
  flex-shrink: 0;
  width: 20px;
  height: 20px;
  border: 2px solid var(--border);
  border-top-color: var(--primary);
  border-radius: 50%;
  animation: message-body-spin 0.65s linear infinite;
}

.msg-list.compact {
  border: none;
  border-radius: 0;
  background: transparent;
}

.msg-list.compact td {
  padding: 0;
  vertical-align: top;
}

.msg-row-cell {
  padding: 0 !important;
}

.msg-row {
  display: flex;
  align-items: stretch;
  min-width: 0;
  width: 100%;
}

.msg-check {
  display: none;
  align-items: center;
  justify-content: center;
  flex: 0 0 2rem;
  padding: 0.5rem 0 0.5rem 0.35rem;
  cursor: pointer;
}

.msg-check[hidden] {
  display: none !important;
}

.msg-check input {
  width: 0.95rem;
  height: 0.95rem;
  accent-color: var(--primary);
  cursor: pointer;
}

.msg-list.is-multiselect .msg-check {
  display: flex;
}

.msg-list.is-multiselect .msg-check[hidden] {
  display: none !important;
}

/* Selection / focus: solid washes only — no per-row drop shadows */
.msg-list tr.selected td {
  background: var(--primary-muted);
  box-shadow: inset 3px 0 0 var(--primary);
}

.msg-list tr.row-focused td {
  background: var(--primary-muted-soft);
}

.msg-list tr.selected.row-focused td {
  background: var(--primary-muted);
}

.msg-list tr.is-checked td {
  background: var(--primary-muted-soft);
}

.msg-list tr.is-checked.selected td {
  background: var(--primary-muted);
}

/* Row leaving: slide out and fade before the row is removed */
.msg-list tr.is-removing td {
  transition: opacity 0.18s ease, transform 0.18s ease;
  opacity: 0;
  transform: translateX(1.25rem);
}

.msg-row-link {
  display: grid;
  grid-template-columns: 2rem minmax(0, 1fr) 6.5rem;
  align-items: start;
  gap: 0.5rem;
  color: inherit;
  text-decoration: none;
  min-width: 0;
  flex: 1;
  width: 100%;
  max-width: 100%;
  padding: 0.5rem 0.65rem;
}

.msg-list.is-multiselect .msg-row-link {
  padding-left: 0.25rem;
}

.msg-row-link:hover { text-decoration: none; color: inherit; }
.msg-row-link:focus-visible {
  outline: 2px solid var(--focus-ring);
  outline-offset: -2px;
  border-radius: var(--radius);
}

.msg-row-main {
  display: flex;
  flex-direction: column;
  gap: 0.15rem;
  min-width: 0;
  overflow: hidden;
}

.msg-row-flag {
  display: inline-flex;
  align-items: center;
  justify-content: center;
}

.msg-row-date {
  text-align: right;
  align-self: center;
  overflow: hidden;
  text-overflow: ellipsis;
}

.msg-from-line {
  display: flex;
  align-items: center;
  gap: 0.4rem;
  min-width: 0;
}

.msg-from {
  font-size: 0.88rem;
  color: var(--text-strong);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  min-width: 0;
  flex: 1 1 auto;
}

.msg-account {
  flex: 0 0 auto;
  max-width: 7.5rem;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  font-size: 0.68rem;
  font-weight: 600;
  letter-spacing: 0.02em;
  color: var(--muted);
  border: 1px solid var(--border);
  border-radius: 999px;
  padding: 0.05rem 0.4rem;
  line-height: 1.3;
}

.msg-subject-line {
  display: flex;
  align-items: center;
  gap: 0.4rem;
  min-width: 0;
}

.msg-subject {
  font-size: 0.82rem;
  color: var(--muted);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  min-width: 0;
  max-width: 100%;
  flex: 0 1 auto;
}

.msg-list tr.unread .msg-subject { color: var(--text); font-weight: 600; }

/* Always pin the pager to the bottom of the list pane (list scrolls above it). */
.mail-list-pane .pager {
  padding: 0.45rem 0.65rem 0.55rem;
  margin-top: auto;
  border-top: 1px solid var(--border);
  flex-shrink: 0;
  background: var(--bg-elevated);
  z-index: 4;
}

.reader-placeholder {
  flex: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 280px;
  border: 1px dashed var(--border);
  border-radius: var(--radius);
  color: var(--muted);
  background: var(--bg-elevated);
}

.reader-placeholder-inner { text-align: center; }
.reader-placeholder-icon { font-size: 2.5rem; margin-bottom: 0.5rem; opacity: 0.55; color: var(--primary); }

.reader-header { align-items: flex-start; }
.reader-title { min-width: 0; flex: 1; }
.reader-title {
  display: flex;
  flex-direction: column;
  align-items: stretch;
  gap: 0.45rem;
}
.reader-title h1 {
  font-size: 1.2rem;
  width: 100%;
  min-width: 0;
  word-break: normal;
  overflow-wrap: break-word;
}

.message-meta div {
  overflow-wrap: anywhere;
}

.asset-banner {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 0.75rem;
  background: var(--warning-muted);
  border: 1px solid var(--warning-border);
  color: var(--text-strong);
  padding: 0.65rem 0.85rem;
  border-radius: var(--radius);
  margin-bottom: 0.85rem;
  font-size: 0.9rem;
}

.asset-banner-ok {
  background: var(--flash-muted);
  border-color: var(--flash);
}

.asset-banner-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 0.4rem;
}

.mail-read-pane .reader-header,
.mail-read-pane .message-meta,
.mail-read-pane .asset-banner,
.mail-read-pane .attachments {
  flex-shrink: 0;
}

.mail-read-pane .message-body {
  flex: 1 1 auto;
  min-height: 0; /* critical for flex child scrolling */
  max-height: 100%;
  overflow: auto;
  -webkit-overflow-scrolling: touch;
}

@media (max-width: 960px) {
  .mail-split {
    grid-template-columns: 1fr;
    grid-template-rows: minmax(200px, 40%) 1fr;
  }
  .mail-list-pane {
    border-right: none;
    border-bottom: 1px solid var(--border);
    max-height: 40vh;
  }
}

.page-header {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 1rem;
  margin-bottom: 1rem;
}

.page-header h1 {
  margin: 0.25rem 0 0;
  color: var(--text-strong);
  font-size: 1.4rem;
}

.actions { display: flex; flex-wrap: wrap; gap: 0.4rem; align-items: center; }
form.inline { display: inline; margin: 0; }
.actions form.is-pending { opacity: 0.55; pointer-events: none; }
.bulk-form.is-pending [data-bulk-action] { pointer-events: none; opacity: 0.6; }
.btn-flag.is-flagged,
.btn-flag.is-flagged:hover {
  color: var(--warning);
  border-color: var(--warning-border);
  background: var(--warning-muted);
}

.btn {
  display: inline-block;
  background: var(--bg-hover);
  color: var(--text-strong);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 0.4rem 0.75rem;
  font-size: 0.9rem;
  cursor: pointer;
  text-decoration: none;
  transition: var(--control-transition);
}

.btn:hover {
  background: var(--bg-active);
  border-color: var(--border-strong);
  text-decoration: none;
}

.btn:focus-visible {
  outline: 2px solid var(--focus-ring);
  outline-offset: 2px;
}

.btn-primary {
  background: var(--primary);
  border-color: var(--primary);
  color: #fff;
}

.btn-primary:hover {
  background: var(--primary-hover);
  border-color: var(--primary-hover);
  color: #fff;
}

.btn-danger {
  color: #fff;
  background: var(--danger);
  border-color: var(--danger);
}

.btn-danger:hover {
  background: var(--danger-hover);
  border-color: var(--danger-hover);
  color: #fff;
}

.btn-ghost { background: transparent; width: 100%; }
.btn-ghost:hover { background: var(--bg-hover); }
.btn-block { width: 100%; }

.btn-sm {
  padding: 0.25rem 0.55rem;
  font-size: 0.8rem;
}

.icon-btn {
  display: inline-flex;
  align-items: center;
  position: relative;
}

.icon-btn .btn-icon {
  flex: none;
}

.icon-btn.is-spinning {
  pointer-events: none;
}

.icon-btn.is-spinning .btn-icon {
  animation: refresh-icon-spin 0.8s linear infinite;
}

@keyframes refresh-icon-spin {
  to { transform: rotate(360deg); }
}

.icon-btn .btn-label {
  position: absolute;
  top: calc(100% + 0.4rem);
  left: 50%;
  transform: translateX(-50%);
  white-space: nowrap;
  background: var(--bg-elevated);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  color: var(--text-strong);
  padding: 0.25rem 0.5rem;
  font-size: 0.8rem;
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.25);
  opacity: 0;
  pointer-events: none;
  transition: opacity .12s ease;
  z-index: 20;
}

.icon-btn .btn-label::after {
  content: "";
  position: absolute;
  bottom: 100%;
  left: 50%;
  transform: translateX(-50%);
  border: 5px solid transparent;
  border-bottom-color: var(--border);
}

.icon-btn:hover .btn-label,
.icon-btn:focus-visible .btn-label {
  opacity: 1;
}

/* Right-align tooltips in action groups so they never clip at the pane edge */
.actions .icon-btn .btn-label,
.list-actions .icon-btn .btn-label,
.bulk-actions .icon-btn .btn-label,
.ai-reply-actions .icon-btn .btn-label {
  left: auto;
  right: 0;
  transform: none;
}

/* Expanding label (old effect): text slides in beside the icon */
.icon-btn-expand .btn-label {
  position: static;
  display: inline-block;
  max-width: 0;
  overflow: hidden;
  white-space: nowrap;
  background: none;
  border: none;
  border-radius: 0;
  box-shadow: none;
  padding: 0;
  font-size: inherit;
  color: inherit;
  opacity: 0;
  transition: max-width .25s ease, opacity .15s ease, margin-left .25s ease;
}

.icon-btn-expand .btn-label::after {
  display: none;
}

.icon-btn-expand:hover .btn-label,
.icon-btn-expand:focus-visible .btn-label {
  max-width: 14em;
  opacity: 1;
  margin-left: 0.4em;
}

/* Persistent state label ("Searching…" / "Selecting…") — icon stays intact */
.icon-btn-expand .btn-label-state {
  display: none;
  max-width: 0;
  overflow: hidden;
  white-space: nowrap;
  opacity: 0;
}

.icon-btn-expand[aria-pressed="true"] .btn-label {
  display: none;
}

.icon-btn-expand[aria-pressed="true"] .btn-label-state {
  display: inline-block;
  max-width: 14em;
  opacity: 1;
  margin-left: 0.4em;
}

.flash {
  background: var(--flash-muted);
  border: 1px solid var(--flash);
  color: var(--text-strong);
  padding: 0.6rem 0.85rem;
  border-radius: var(--radius);
  margin-bottom: 1rem;
}

.flash-error {
  background: var(--flash-error-muted);
  border-color: var(--flash-error);
}

.empty {
  color: var(--muted);
  padding: 2rem;
  text-align: center;
  border: 1px dashed var(--border);
  border-radius: var(--radius);
  background: var(--bg-elevated);
}

.msg-list {
  width: 100%;
  border-collapse: collapse;
  table-layout: fixed;
  background: var(--bg-elevated);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  overflow: hidden;
}

.msg-list th, .msg-list td {
  padding: 0.55rem 0.75rem;
  border-bottom: 1px solid var(--border);
  text-align: left;
  font-size: 0.92rem;
}

.msg-list th {
  color: var(--muted);
  font-weight: 600;
  background: var(--bg-table-head);
}

.msg-list tr:hover td,
.msg-list tr:focus-within td { background: var(--bg-hover); }

/* Keep selection stronger than plain hover */
.msg-list tr.selected:hover td,
.msg-list tr.selected:focus-within td {
  background: var(--primary-muted);
}

.msg-list tr.unread td { color: var(--unread); font-weight: 600; }
.msg-list a { color: inherit; text-decoration: none; }
.msg-list a:hover { color: var(--primary); }

.col-flag { width: 2rem; color: var(--warning); }
.col-from { width: 20%; max-width: 14rem; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.col-date { width: 6.5rem; color: var(--muted); white-space: nowrap; }

@media (max-width: 720px) {
  .msg-row-link {
    grid-template-columns: 2rem minmax(0, 1fr);
  }

  .msg-row-date {
    display: none;
  }
}

.pager {
  margin-top: 1rem;
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 0.5rem 0.75rem;
}

.pager-nav {
  display: flex;
  align-items: center;
  gap: 0.3rem;
}

.pager-btn {
  min-width: 2rem;
  padding: 0.25rem 0.45rem;
  text-align: center;
  font-size: 1.1rem;
  line-height: 1;
  font-weight: 600;
}

.pager-btn.is-disabled {
  opacity: 0.35;
  cursor: default;
  pointer-events: none;
}

.pager-jump {
  display: inline-flex;
  align-items: center;
}

.pager-jump-input {
  width: 4rem;
  padding: 0.15rem 0.35rem;
  font-size: 0.8rem;
  text-align: center;
  font-variant-numeric: tabular-nums;
  background: var(--bg-input);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  color: var(--text);
}

.pager-jump-input:focus {
  border-color: var(--primary);
  outline: none;
  box-shadow: 0 0 0 2px var(--focus-ring);
}

.pager-jump-input::-webkit-outer-spin-button,
.pager-jump-input::-webkit-inner-spin-button {
  -webkit-appearance: none;
  margin: 0;
}

.pager-jump-input[type="number"] {
  -moz-appearance: textfield;
}

.pager-meta {
  display: flex;
  flex-wrap: wrap;
  align-items: baseline;
  gap: 0.35rem 0.65rem;
  font-size: 0.8rem;
  color: var(--text);
  font-variant-numeric: tabular-nums;
}

.pager-range {
  color: var(--text-strong);
  font-weight: 500;
}

.pager-size {
  font-size: 0.75rem;
}

.message-meta {
  background: var(--bg-elevated);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 0.85rem 1rem;
  margin-bottom: 1rem;
  line-height: 1.5;
  font-size: 0.92rem;
}

.message-meta strong {
  color: var(--muted);
  font-weight: 600;
}

.attachments {
  margin-bottom: 1rem;
  font-size: 0.92rem;
}

.attachments ul { margin: 0.35rem 0 0; padding-left: 1.2rem; }

.att-list {
  list-style: none;
  padding-left: 0 !important;
  margin: 0.5rem 0 0;
}

.att-item {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 0.5rem 0.75rem;
  padding: 0.45rem 0.65rem;
  background: var(--bg-elevated);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  margin-bottom: 0.4rem;
}

.att-name {
  color: var(--text-strong);
  font-weight: 500;
  word-break: break-all;
}

.att-size { font-size: 0.85rem; }

.att-actions {
  margin-left: auto;
  display: flex;
  gap: 0.35rem;
}

.att-hint {
  margin: 0.4rem 0 0;
  font-size: 0.8rem;
}

.message-body {
  background: var(--mail-bg);
  color: var(--mail-text);
  border-radius: var(--radius);
  border: 1px solid var(--border);
  min-height: 12rem;
  overflow: auto;
  -webkit-overflow-scrolling: touch;
}

.plain-body {
  margin: 0;
  padding: 1rem;
  white-space: pre-wrap;
  word-break: break-word;
  font-size: 0.95rem;
  line-height: 1.6;
  font-family: var(--font);
  background: var(--mail-bg);
  color: var(--mail-text);
}

.html-body-shell {
  min-width: 0;
}

.html-body-shell.is-fitted {
  overflow: hidden;
}

.html-body {
  padding: 1rem;
  color: var(--mail-text);
  background: var(--mail-bg);
  overflow-x: auto;
  line-height: 1.5;
  font-size: 1rem;
  /* height comes from content; parent .message-body scrolls */
}

/* Email HTML normalization — keep the message's own design (inline styles win),
   but guard against content wider than the pane. */
.html-body * {
  box-sizing: border-box;
  max-width: 100%;
}

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

.html-body table {
  max-width: 100%;
}

.html-body td,
.html-body th {
  padding: 0.4rem 0.6rem;
  vertical-align: top;
}

.html-body a {
  color: var(--primary);
  text-decoration: underline;
}

.html-body a:hover {
  color: var(--primary-hover);
}

.html-body blockquote {
  border-left: 3px solid var(--border-strong);
  margin: 1rem 0;
  padding: 0.1rem 0 0.1rem 1rem;
  color: var(--mail-text);
}

.html-body pre {
  background: #f6f8fa;
  border: 1px solid #d8dee4;
  border-radius: var(--radius);
  padding: 0.75rem;
  overflow-x: auto;
  font-size: 0.85rem;
  line-height: 1.5;
}

.html-body code {
  font-family: var(--font-mono);
  font-size: 0.9em;
  background: #f0f2f5;
  padding: 0.1rem 0.3rem;
  border-radius: 4px;
}

.html-body pre code {
  background: transparent;
  padding: 0;
}

.html-body hr {
  border: none;
  border-top: 1px solid var(--border);
  margin: 1.5rem 0;
}

.html-body h1,
.html-body h2,
.html-body h3,
.html-body h4,
.html-body h5,
.html-body h6 {
  color: var(--mail-text);
  margin: 1.2rem 0 0.6rem;
  line-height: 1.3;
}

.html-body h1 { font-size: 1.8rem; }
.html-body h2 { font-size: 1.5rem; }
.html-body h3 { font-size: 1.3rem; }
.html-body h4 { font-size: 1.1rem; }
.html-body h5 { font-size: 1rem; }
.html-body h6 { font-size: 0.95rem; }

.html-body p {
  margin: 0.75rem 0;
}

.html-body ul,
.html-body ol {
  margin: 0.75rem 0;
  padding-left: 1.5rem;
}

.html-body li {
  margin: 0.25rem 0;
}

.compose-form label {
  display: block;
  margin-bottom: 0.75rem;
  color: var(--muted);
  font-size: 0.85rem;
}

.compose-form input[type="text"],
.compose-form input[type="email"],
.compose-form input[type="password"],
.compose-form input[type="number"],
.compose-form textarea {
  display: block;
  width: 100%;
  margin-top: 0.3rem;
  background: var(--bg-input);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  color: var(--text-strong);
  padding: 0.5rem 0.65rem;
  font: inherit;
  transition: var(--control-transition);
}

.compose-form input:focus-visible,
.compose-form textarea:focus-visible {
  outline: none;
  border-color: var(--primary);
  box-shadow: 0 0 0 3px var(--primary-muted);
}

.compose-form textarea { resize: vertical; }

/* Compose attachments */
.compose-attachments {
  margin: 0.25rem 0 0.75rem;
  padding: 0.65rem 0.75rem;
  border: 1px dashed var(--border);
  border-radius: var(--radius);
}

.compose-attachment-label {
  display: block;
  margin-bottom: 0.35rem;
  color: var(--muted);
  font-size: 0.85rem;
  font-weight: 600;
}

.compose-attachments .att-list:empty { display: none; }

.compose-attachment-add {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 0.6rem;
  margin-top: 0.5rem;
}

.compose-attach-btn {
  display: inline-flex;
  align-items: center;
  gap: 0.35rem;
}

.compose-attach-btn .btn-text { line-height: 1; }

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

/* Original draft + suggested AI rewrite side by side */
.compose-body-split {
  display: flex;
  align-items: flex-start;
  gap: 1rem;
}

.compose-body-split .compose-body-original {
  flex: 1 1 55%;
  min-width: 0;
  margin-bottom: 0.75rem;
}

.ai-rewrite-panel {
  flex: 1 1 45%;
  min-width: 0;
  margin-top: 1.35rem;
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  background: var(--bg-elevated);
  padding: 0.7rem 0.85rem;
}

.ai-rewrite-panel-head {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  margin-bottom: 0.55rem;
}

.ai-rewrite-panel-head .ai-card-label {
  flex: 1;
  min-width: 0;
}

.ai-rewrite-panel-body {
  font-size: 0.85rem;
  color: var(--text);
  white-space: pre-wrap;
  word-break: break-word;
  max-height: 34rem;
  overflow-y: auto;
}

.recipient-field { margin-bottom: 0.85rem; }

.recipient-label-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.5rem;
  margin-bottom: 0.3rem;
}

.recipient-label-row label {
  margin-bottom: 0;
  color: var(--muted);
  font-size: 0.85rem;
}

.contact-pick-btn { flex-shrink: 0; }

.autocomplete-wrap {
  position: relative;
}

.autocomplete-wrap .recipient-input {
  display: block;
  width: 100%;
  background: var(--bg-input);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  color: var(--text-strong);
  padding: 0.5rem 0.65rem;
  font: inherit;
  transition: var(--control-transition);
}

.autocomplete-wrap .recipient-input:focus-visible {
  outline: none;
  border-color: var(--primary);
  box-shadow: 0 0 0 3px var(--primary-muted);
}

.autocomplete-list {
  position: absolute;
  z-index: 40;
  left: 0;
  right: 0;
  top: calc(100% + 2px);
  margin: 0;
  padding: 0.25rem 0;
  list-style: none;
  background: var(--bg-elevated);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow-dropdown);
  max-height: 240px;
  overflow: auto;
}

.autocomplete-list li {
  padding: 0.45rem 0.75rem;
  cursor: pointer;
  display: flex;
  flex-direction: column;
  gap: 0.1rem;
}

.autocomplete-list li:hover,
.autocomplete-list li.active {
  background: var(--bg-hover);
}

.ac-name {
  color: var(--text-strong);
  font-size: 0.9rem;
}

.ac-email {
  color: var(--muted);
  font-size: 0.8rem;
}

/* Contact picker modal */
.modal[hidden] { display: none !important; }

.modal {
  position: fixed;
  inset: 0;
  z-index: 100;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 1rem;
}

.modal-backdrop {
  position: absolute;
  inset: 0;
  background: var(--overlay);
}

.modal-card {
  position: relative;
  width: 100%;
  max-width: 420px;
  max-height: min(70vh, 520px);
  display: flex;
  flex-direction: column;
  background: var(--bg-elevated);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 1rem;
  box-shadow: var(--shadow-modal);
}

.modal-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 0.75rem;
}

.modal-header h2 {
  margin: 0;
  font-size: 1.1rem;
  color: var(--text-strong);
}

.picker-search {
  width: 100%;
  margin-bottom: 0.65rem;
  background: var(--bg-input);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  color: var(--text-strong);
  padding: 0.5rem 0.65rem;
  font: inherit;
  transition: var(--control-transition);
}

.picker-search:focus-visible {
  outline: none;
  border-color: var(--primary);
  box-shadow: 0 0 0 3px var(--primary-muted);
}

.picker-list {
  list-style: none;
  margin: 0;
  padding: 0;
  overflow: auto;
  flex: 1;
  min-height: 0;
}

.picker-item {
  padding: 0.55rem 0.65rem;
  border-radius: var(--radius);
  cursor: pointer;
  display: flex;
  flex-direction: column;
  gap: 0.1rem;
}

.picker-item:hover {
  background: var(--bg-hover);
}

.picker-empty {
  margin: 0.5rem 0 0;
  text-align: center;
}

.muted { color: var(--muted); }

/* Login */
.login-page {
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 100vh;
  min-height: 100dvh;
  padding: 1rem;
  background: var(--bg);
}

.login-card {
  width: 100%;
  max-width: 420px;
  background: var(--bg-elevated);
  border: 1px solid var(--border);
  border-top: 3px solid var(--primary);
  border-radius: var(--radius-lg);
  padding: 1.75rem;
}

.login-card h1 {
  margin: 0 0 0.35rem;
  color: var(--text-strong);
  font-size: 1.5rem;
  text-align: center;
}

.login-card > .muted {
  text-align: center;
}

.login-logo {
  display: block;
  width: 16rem;
  height: 20rem;
  object-fit: cover;
  border-radius: 0.9rem;
  margin: 0 auto 0.9rem;
}

.login-form label {
  display: block;
  margin-bottom: 0.85rem;
  color: var(--muted);
  font-size: 0.85rem;
}

.login-form input[type="email"],
.login-form input[type="password"],
.login-form input[type="text"],
.login-form input[type="number"] {
  display: block;
  width: 100%;
  margin-top: 0.3rem;
  background: var(--bg-input);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  color: var(--text-strong);
  padding: 0.55rem 0.65rem;
  font: inherit;
  transition: var(--control-transition);
}

.login-form input:focus-visible {
  outline: none;
  border-color: var(--primary);
  box-shadow: 0 0 0 3px var(--primary-muted);
}

/* Branded OAuth sign-in buttons (Google / Microsoft look-and-feel) */
.oauth-buttons {
  display: flex;
  flex-direction: column;
  gap: 0.6rem;
  margin-top: 1.25rem;
}

.oauth-login-btn {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 0.7rem;
  width: 100%;
  padding: 0.68rem 0.9rem;
  background: var(--bg-hover);
  border: 1px solid var(--border);
  border-radius: 10px;
  color: var(--text-strong);
  font-size: 0.95rem;
  font-weight: 600;
  letter-spacing: 0.01em;
  text-decoration: none;
  box-shadow: 0 1px 2px rgba(0, 0, 0, 0.25), 0 2px 8px rgba(0, 0, 0, 0.18);
  transition: transform 0.12s ease, box-shadow 0.12s ease, background-color 0.12s ease, border-color 0.12s ease;
  animation: oauth-in 0.35s ease both;
}

.oauth-login-btn:nth-child(2) { animation-delay: 0.07s; }

.oauth-login-btn svg {
  width: 21px;
  height: 21px;
  flex-shrink: 0;
  transition: transform 0.12s ease;
}

.oauth-login-btn:hover {
  background: var(--bg-active);
  border-color: var(--border-strong);
  transform: translateY(-1px);
  text-decoration: none;
  box-shadow: 0 2px 4px rgba(0, 0, 0, 0.3), 0 8px 20px rgba(0, 0, 0, 0.24);
}

.oauth-login-btn:hover svg { transform: scale(1.05); }

.oauth-login-btn:active {
  transform: translateY(0);
  box-shadow: 0 1px 2px rgba(0, 0, 0, 0.14);
}

.oauth-login-btn:focus-visible {
  outline: 2px solid var(--focus-ring);
  outline-offset: 2px;
}

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

.oauth-divider {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  margin: 1rem 0;
  color: var(--muted);
  font-size: 0.8rem;
}

.oauth-divider::before,
.oauth-divider::after {
  content: "";
  flex: 1;
  height: 1px;
  background: var(--border);
}

.advanced {
  margin: 0.5rem 0 1rem;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 0.5rem 0.75rem;
}

.advanced summary {
  cursor: pointer;
  color: var(--text);
  margin-bottom: 0.5rem;
}

.grid-2 {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 0.65rem;
}

.checkbox {
  display: flex !important;
  align-items: center;
  gap: 0.4rem;
  margin-top: 1.4rem !important;
}

@media (max-width: 800px) {
  .app {
    flex-direction: column;
    height: auto;
    min-height: 100dvh;
    overflow: visible;
  }
  /* Single-row top bar: logo + folder picker + overflow menu button. */
  .sidebar {
    width: 100%;
    height: auto;
    min-height: auto;
    position: sticky;
    top: 0;
    z-index: 30;
    flex-direction: row;
    align-items: center;
    gap: 0.55rem;
    padding: 0.5rem 0.6rem;
    padding-top: max(0.5rem, env(safe-area-inset-top, 0px));
    border-right: none;
    border-bottom: 1px solid var(--border);
    background: rgba(28, 34, 40, 0.92);
    backdrop-filter: blur(12px);
    -webkit-backdrop-filter: blur(12px);
  }
  .brand {
    order: 0;
    flex: 0 0 auto;
  }
  .brand a span {
    display: none;
  }
  .brand-logo {
    width: 1.7rem;
    height: 1.9rem;
    border-radius: 0.45rem;
  }
  /* Current folder + chevron opens the folder list as a dropdown grid. */
  .folder-picker {
    order: 1;
    flex: 1 1 auto;
    min-width: 0;
    position: relative;
  }
  .folder-picker-btn {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 0.4rem;
    width: 100%;
    padding: 0.45rem 0.65rem;
    background: var(--bg);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    color: var(--text-strong);
    font: inherit;
    font-size: 0.9rem;
    cursor: pointer;
    transition: var(--control-transition);
  }
  .folder-picker-btn:hover,
  .folder-picker-btn[aria-expanded="true"] {
    background: var(--bg-active);
    border-color: var(--border-strong);
  }
  .folder-picker-btn:focus-visible {
    outline: 2px solid var(--focus-ring);
    outline-offset: 2px;
  }
  .folder-picker-btn [data-folder-picker-label] {
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
  }
  .folder-picker-chevron {
    flex-shrink: 0;
    transition: transform 0.18s ease;
  }
  .folder-picker.is-open .folder-picker-chevron {
    transform: rotate(180deg);
  }
  .folder-picker .folder-nav {
    position: absolute;
    top: calc(100% + 0.35rem);
    left: 0;
    right: 0;
    z-index: 40;
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 0.3rem;
    padding: 0.5rem;
    background: var(--bg-elevated);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    box-shadow: var(--shadow-dropdown);
    max-height: 0;
    opacity: 0;
    overflow: hidden;
    visibility: hidden;
    transform: translateY(-6px);
    transition: max-height 0.28s ease, opacity 0.22s ease, transform 0.28s ease,
      visibility 0s linear 0.28s;
  }
  .folder-picker.is-open .folder-nav {
    max-height: 60vh;
    max-height: min(72dvh, 520px);
    opacity: 1;
    visibility: visible;
    transform: translateY(0);
    overflow-y: auto;
    transition: max-height 0.28s ease, opacity 0.22s ease, transform 0.28s ease,
      visibility 0s;
  }
  .folder-nav a {
    display: flex;
    align-items: center;
    justify-content: center;
    white-space: nowrap;
    padding: 0.55rem 0.4rem;
    background: var(--bg);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    color: var(--text);
    text-align: center;
  }
  .folder-nav a.active {
    background: var(--primary-muted);
    border-color: var(--primary);
    color: var(--text-strong);
    font-weight: 600;
    box-shadow: none;
  }
  .mobile-menu-btn {
    order: 3;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    flex: 0 0 auto;
    width: 2.25rem;
    height: 2.25rem;
    padding: 0;
    background: var(--bg);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    color: var(--text-strong);
    cursor: pointer;
    transition: var(--control-transition);
  }
  .mobile-menu-btn:hover,
  .mobile-menu-btn[aria-expanded="true"] {
    background: var(--bg-active);
    border-color: var(--border-strong);
  }
  .mobile-menu-btn:focus-visible {
    outline: 2px solid var(--focus-ring);
    outline-offset: 2px;
  }
  .mobile-menu-btn .btn-icon {
    width: 18px;
    height: 18px;
  }
  /* Secondary chrome (accounts, compose, logout) drops down as an overflow
     menu anchored under the bar. */
  .sidebar-secondary {
    display: flex;
    flex-direction: column;
    gap: 0.45rem;
    position: absolute;
    top: calc(100% + 0.35rem);
    left: 0.6rem;
    right: 0.6rem;
    z-index: 40;
    padding: 0.6rem;
    background: var(--bg-elevated);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    box-shadow: var(--shadow-dropdown);
    max-height: 0;
    opacity: 0;
    overflow: hidden;
    visibility: hidden;
    transform: translateY(-6px);
    transition: max-height 0.28s ease, opacity 0.22s ease, transform 0.28s ease,
      visibility 0s linear 0.28s;
  }
  .sidebar.is-menu-open .sidebar-secondary {
    max-height: 60vh;
    max-height: min(72dvh, 520px);
    opacity: 1;
    visibility: visible;
    transform: translateY(0);
    overflow-y: auto;
    transition: max-height 0.28s ease, opacity 0.22s ease, transform 0.28s ease,
      visibility 0s;
  }
  .sidebar-secondary > * {
    order: 0;
  }
  .compose-btn {
    margin: 0;
  }
  .sidebar-settings {
    order: 2;
    flex: 0 0 auto;
    margin: 0;
  }
  /* Settings lives in the top bar as a gear icon button; the panel drops
     down under the bar (anchored to the sticky sidebar). */
  .sidebar-settings .settings-toggle {
    width: 2.25rem;
    height: 2.25rem;
    padding: 0;
    justify-content: center;
    gap: 0.3rem;
    background: var(--bg);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    color: var(--text-strong);
    cursor: pointer;
    transition: var(--control-transition);
  }
  .sidebar-settings .settings-toggle:hover,
  .sidebar-settings .settings-toggle[aria-expanded="true"] {
    background: var(--bg-active);
    border-color: var(--border-strong);
  }
  .sidebar-settings .settings-toggle:focus-visible {
    outline: 2px solid var(--focus-ring);
    outline-offset: 2px;
  }
  .sidebar-settings .settings-toggle .btn-icon {
    display: inline-block;
    width: 18px;
    height: 18px;
  }
  .sidebar-settings .settings-toggle .settings-toggle-text,
  .sidebar-settings .settings-toggle::after {
    display: none;
  }
  .settings-panel {
    position: absolute;
    top: calc(100% + 0.35rem);
    right: 0.6rem;
    left: auto;
    z-index: 40;
    padding: 0.5rem 0.5rem 0.6rem;
    width: min(20rem, calc(100vw - 1.2rem));
    background: var(--bg-elevated);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    box-shadow: var(--shadow-dropdown);
    max-height: 0;
  }
  .sidebar-settings.is-open .settings-panel {
    max-height: 280px;
  }
  .sidebar-secondary .sidebar-bottom {
    margin-top: 0;
    gap: 0.55rem;
    padding-top: 0.55rem;
    border-top: 1px solid var(--border);
  }
  .sidebar-bottom .accounts-link-btn {
    margin-bottom: 0.15rem;
  }
  .sidebar-footer {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: 0.5rem 0.75rem;
    padding-top: 0.75rem;
  }
  .sidebar-version {
    display: none;
    margin-bottom: 0.5rem;
  }
  .sidebar-footer form {
    margin-left: auto;
  }
  .perf-stats {
    display: none;
  }
  .user-email {
    margin: 0;
    flex: 1 1 12rem;
  }
  .main {
    padding: 1rem 1rem 1.35rem;
    overflow: visible;
  }
  .grid-2 { grid-template-columns: 1fr; }
}

@media (max-width: 760px) {
  .main-split {
    display: block;
    height: auto;
    max-height: none;
    overflow: visible;
  }

  .main-split > .flash,
  .main-split > .flash-error {
    margin: 0 0 0.75rem;
  }

  .mail-split {
    display: block;
    height: auto;
    min-height: 0;
  }

  .mail-list-pane,
  .mail-read-pane {
    height: auto;
    min-height: 0;
    max-height: none;
    border: none;
    background: transparent;
    padding: 0;
    overflow: visible;
  }

  .mail-split.is-browsing .mail-read-pane {
    display: none;
  }

  .mail-split.is-reading .mail-list-pane {
    display: none;
  }

  /*
   * List browsing: fill the viewport under the sticky top chrome so the
   * pager stays pinned at the bottom. Messages scroll inside the list only —
   * no more scrolling to the end of every page to reach ‹ ›.
   * Selector pairs cover modern engines (:has) and a JS-toggled body class
   * fallback (mobile-browsing / mobile-reading) where :has is unsupported.
   */
  .app:has(.mail-split.is-browsing),
  body.mobile-browsing .app {
    height: 100dvh;
    min-height: 100dvh;
    max-height: 100dvh;
    overflow: hidden;
  }
  .app:has(.mail-split.is-browsing) .main,
  body.mobile-browsing .app .main {
    flex: 1 1 auto;
    min-height: 0;
    overflow: hidden;
    display: flex;
    flex-direction: column;
    /* No padding: the pager spans the full width, flush at the bottom.
       Inner sections carry their own horizontal inset. */
    padding: 0;
  }
  .app:has(.mail-split.is-browsing) .main-split,
  body.mobile-browsing .app .main-split {
    display: flex;
    flex-direction: column;
    flex: 1 1 auto;
    min-height: 0;
    height: auto;
    max-height: none;
    overflow: hidden;
  }
  .mail-split.is-browsing {
    display: flex;
    flex-direction: column;
    flex: 1 1 auto;
    min-height: 0;
    height: 100%;
  }
  .mail-split.is-browsing .mail-list-pane {
    display: flex;
    flex-direction: column;
    flex: 1 1 auto;
    min-height: 0;
    height: 100%;
    overflow: hidden;
  }
  .mail-split.is-browsing .bulk-form {
    flex: 1 1 auto;
    min-height: 0;
  }
  .mail-split.is-browsing .msg-list-scroll {
    flex: 1 1 auto;
    overflow: auto;
    -webkit-overflow-scrolling: touch;
    min-height: 0;
    max-height: none;
  }
  .mail-split.is-browsing .pager {
    flex-shrink: 0;
    margin-top: auto;
    position: sticky;
    bottom: 0;
    border-top: 1px solid var(--border);
    background: var(--bg-elevated);
    padding: 0.55rem 0.75rem;
    padding-bottom: max(0.55rem, env(safe-area-inset-bottom, 0px));
    box-shadow: 0 -6px 16px rgba(0, 0, 0, 0.18);
  }
  /* Browsing pane is edge-to-edge; keep content readable with its own inset. */
  .mail-split.is-browsing .mail-search-panel {
    padding-inline: 1rem;
  }
  .mail-split.is-browsing .bulk-bar {
    padding-inline: 1rem;
  }
  .mail-split.is-browsing .msg-list-scroll {
    padding-inline: 1rem;
  }

  /*
   * Floating action bar (list): the pane header only holds the list actions
   * on phones. Move it between the scroll area and the pager, styled as a
   * rounded pill (same look as the agb restaurant menu-jumpnav).
   */
  .mail-split.is-browsing .mail-list-pane .pane-header {
    order: 3;
    flex-shrink: 0;
    margin: 0;
    padding: 0.35rem 0 0;
    justify-content: center;
  }
  .mail-split.is-browsing .mail-list-pane .pane-header > div:first-child {
    display: none;
  }
  .mail-split.is-browsing .mail-search-panel {
    order: 1;
  }
  .mail-split.is-browsing .bulk-form {
    order: 2;
  }
  .mail-split.is-browsing .pager {
    order: 4;
  }
  .mail-split.is-browsing .mail-list-pane .list-actions {
    justify-content: center;
    width: auto;
    margin: 0 auto 0.55rem;
    padding: 0.4rem 0.6rem;
    gap: 0.5rem;
    background: rgba(28, 34, 40, 0.88);
    border: 1px solid var(--border);
    border-radius: 999px;
    box-shadow: 0 6px 18px rgba(0, 0, 0, 0.35);
    backdrop-filter: blur(12px);
    -webkit-backdrop-filter: blur(12px);
  }
  .mail-split.is-browsing .mail-list-pane .list-actions .icon-btn .btn-label {
    display: none;
  }

  /*
   * Compose: joins the browsing pill as the primary action and is removed
   * from the ⋯ menu there to avoid duplication. In reading mode (and on
   * other pages) it stays available inside the ⋯ menu.
   */
  body.mobile-browsing .sidebar-secondary .compose-btn,
  .app:has(.mail-split.is-browsing) .sidebar-secondary .compose-btn {
    display: none;
  }
  body.mobile-browsing .mail-split.is-browsing .mail-list-pane .list-actions .compose-pill-btn,
  .app:has(.mail-split.is-browsing) .mail-list-pane .list-actions .compose-pill-btn {
    display: inline-flex;
  }

  /* Reading mode: full-page scroll as before (no pinned pager). */
  .app:has(.mail-split.is-reading),
  body.mobile-reading .app {
    height: auto;
    min-height: 100dvh;
    max-height: none;
    overflow: visible;
  }
  .app:has(.mail-split.is-reading) .main,
  body.mobile-reading .app .main {
    flex: none;
    overflow: visible;
    display: block;
    /* Leave room for the floating action pill at the bottom. */
    padding-bottom: calc(4.75rem + env(safe-area-inset-bottom, 0px));
  }

  .mail-list-pane .pane-header,
  .mail-read-pane .pane-header {
    padding: 0 0 0.65rem;
  }

  /*
   * Floating action bar (reader): pin the message actions to the bottom as a
   * rounded pill, like native mobile mail apps. The header keeps only the
   * subject; users navigate back with the phone back gesture.
   */
  .mail-split.is-reading .mail-read-pane .reader-header .actions {
    position: fixed;
    left: 0.75rem;
    right: 0.75rem;
    bottom: calc(0.75rem + env(safe-area-inset-bottom, 0px));
    width: auto;
    z-index: 50;
    flex-wrap: nowrap;
    justify-content: flex-start;
    align-items: stretch;
    overflow-x: auto;
    overflow-y: hidden;
    scrollbar-width: none;
    /* Segmented pill: no gaps, children stretch edge-to-edge. */
    gap: 0;
    padding: 0.3rem;
    background: rgba(28, 34, 40, 0.9);
    border: 1px solid var(--border);
    border-radius: 999px;
    box-shadow: 0 6px 20px rgba(0, 0, 0, 0.4);
    backdrop-filter: blur(12px);
    -webkit-backdrop-filter: blur(12px);
  }
  .mail-split.is-reading .mail-read-pane .reader-header .actions::-webkit-scrollbar {
    display: none;
  }
  /* Every direct child (link or form) shares the width equally. */
  .mail-split.is-reading .mail-read-pane .reader-header .actions > * {
    flex: 1 1 0;
    min-width: 0;
  }
  .mail-split.is-reading .mail-read-pane .reader-header .actions > a.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
  }
  .mail-split.is-reading .mail-read-pane .reader-header .actions > form.inline {
    display: flex;
  }
  .mail-split.is-reading .mail-read-pane .reader-header .actions > form.inline .btn {
    flex: 1 1 auto;
    width: 100%;
    justify-content: center;
  }
  .mail-split.is-reading .mail-read-pane .reader-header .actions .btn {
    padding-left: 0.25rem;
    padding-right: 0.25rem;
  }
  .mail-split.is-reading .mail-read-pane .reader-header .actions .icon-btn .btn-label {
    display: none;
  }

  .mail-search-panel,
  .bulk-bar {
    padding-inline: 0;
    background: transparent;
  }

  .mail-search-panel {
    background: var(--bg-elevated);
  }

  .mail-search-row {
    flex-direction: column;
    align-items: stretch;
  }

  .mail-search-input {
    flex: none;
    width: 100%;
  }

  .mail-search-row .btn {
    width: 100%;
    text-align: center;
  }

  .mail-read-pane .message-body {
    overflow: visible;
    max-height: none;
  }

  .message-body.has-fitted-html {
    overflow-x: hidden;
  }

  .bulk-form {
    min-height: auto;
  }

  .page-header {
    gap: 0.75rem;
    margin-bottom: 0.8rem;
  }

  .reader-header,
  .page-header {
    flex-direction: column;
    align-items: stretch;
  }

  .page-header h1 {
    font-size: 1.2rem;
  }

  .list-actions,
  .actions,
  .asset-banner-actions {
    width: 100%;
  }

  .actions .btn,
  .list-actions .btn,
  .asset-banner-actions .btn {
    text-align: center;
  }

  .asset-banner {
    padding: 0.75rem;
  }

  .att-item {
    align-items: flex-start;
  }

  .att-actions {
    width: 100%;
    margin-left: 0;
    justify-content: flex-start;
  }

  .recipient-label-row {
    flex-direction: column;
    align-items: stretch;
    gap: 0.35rem;
  }

  .compose-body-split {
    flex-direction: column;
  }

  .compose-body-split .compose-body-original,
  .ai-rewrite-panel {
    flex: 1 1 auto;
    width: 100%;
    margin-top: 0;
  }

  .contact-pick-btn,
  .compose-form .actions .btn {
    width: 100%;
  }

  .compose-form .actions {
    flex-direction: column;
    align-items: stretch;
  }

  .contacts-toolbar {
    align-items: stretch;
  }

  .contacts-search {
    flex-basis: 100%;
  }

  .contacts-search-input {
    min-height: 2.7rem;
  }

  .contacts-table {
    border: none;
    background: transparent;
  }

  .contacts-table thead {
    display: none;
  }

  .contacts-table,
  .contacts-table tbody,
  .contacts-table tr,
  .contacts-table td {
    display: block;
    width: 100%;
  }

  .contacts-table tbody {
    display: grid;
    gap: 0.85rem;
  }

  .contacts-table tr {
    display: grid;
    gap: 0.55rem;
    border: 1px solid var(--border);
    border-radius: var(--radius);
    background: var(--bg-elevated);
    padding: 0.85rem;
  }

  .contacts-table td {
    border-bottom: none;
    padding: 0;
    min-width: 0;
  }

  .contacts-table td::before {
    content: attr(data-label);
    display: block;
    margin-bottom: 0.2rem;
    color: var(--muted);
    font-size: 0.72rem;
    letter-spacing: 0.03em;
    text-transform: uppercase;
  }

  .contact-name-form {
    display: grid;
    grid-template-columns: minmax(0, 1fr) auto;
    align-items: start;
    gap: 0.45rem;
  }

  .contact-name-input {
    max-width: none;
    min-width: 0;
  }

  .contact-name-cell {
    padding-bottom: 0.2rem !important;
    margin-bottom: 0.05rem;
    border-bottom: 1px solid var(--border);
  }

  .contact-name-cell::before {
    margin-bottom: 0.3rem;
  }

  .contact-action-cell {
    padding-top: 0.15rem !important;
  }

  /* Keep Mail + Allow side by side in the card layout: Mail shrinks,
     Allow keeps its intrinsic width instead of being pushed off-screen. */
  .contacts-table td.contact-action-cell {
    display: flex;
    flex-wrap: wrap;
    gap: 0.4rem;
  }

  .contact-action-cell .btn {
    width: auto;
    flex: 1 1 auto;
    min-width: 0;
  }

  .contact-action-cell .contact-whitelist-toggle {
    flex: 0 0 auto;
  }

  /* Accounts page: stack the card so long email addresses wrap instead of
     shoving the action buttons out of the viewport. */
  .account-card {
    flex-direction: column;
    align-items: stretch;
    gap: 0.65rem;
  }
  .account-info {
    gap: 0.5rem;
  }
  .account-email {
    overflow-wrap: anywhere;
    min-width: 0;
  }
  .account-actions {
    flex-wrap: wrap;
    justify-content: flex-start;
  }
  .account-display-name-form {
    flex-wrap: wrap;
  }

  .modal {
    align-items: flex-end;
    padding: 0.65rem;
  }

  .modal-card {
    max-width: none;
    max-height: min(85dvh, 640px);
    border-bottom-left-radius: 0;
    border-bottom-right-radius: 0;
  }

  .login-card {
    padding: 1.1rem;
  }

  .login-logo {
    width: 8rem;
    height: 10rem;
  }
}

@media (max-width: 420px) {
  .contact-name-form {
    grid-template-columns: 1fr;
  }

  .contact-name-form .btn {
    width: 100%;
  }
}

@media (prefers-reduced-motion: reduce) {
  .btn,
  .folder-nav a,
  .folder-nav button,
  .nav-link-btn,
  .settings-panel,
  .msg-list tr.is-removing td,
  .compose-form input,
  .compose-form textarea,
  .autocomplete-wrap .recipient-input,
  .picker-search,
  .login-form input,
  .oauth-login-btn,
  .oauth-login-btn svg {
    transition: none;
    animation: none;
  }
}

/* Accounts page */
.accounts-list {
  display: flex;
  flex-direction: column;
  gap: 0.75rem;
  margin-bottom: 1.5rem;
}
.account-card {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 1rem 1.25rem;
  background: var(--bg-elevated);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  gap: 1rem;
}
.account-info {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  flex-wrap: wrap;
}
.account-badge {
  display: inline-block;
  font-size: 0.75rem;
  font-weight: 600;
  padding: 0.15rem 0.5rem;
  border-radius: 999px;
  background: var(--primary);
  color: #fff;
}
.account-badge.is-linked {
  background: var(--primary-muted);
  color: var(--primary);
}
.account-badge.is-warning {
  background: var(--flash-error-muted);
  color: var(--flash-error);
}
.account-card-warning {
  border-color: var(--flash-error);
  background: var(--flash-error-muted);
}
.account-email {
  font-weight: 500;
  color: var(--text-strong);
}
.account-provider {
  font-size: 0.85rem;
  color: var(--muted);
  text-transform: capitalize;
}
.account-delete {
  display: contents;
  flex-shrink: 0;
}
.account-actions {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  flex-shrink: 0;
}
.account-display-name-form {
  display: flex;
  align-items: center;
  gap: 0.25rem;
}
.account-display-name-input {
  width: 8rem;
  padding: 0.2rem 0.45rem;
  font-size: 0.8rem;
  background: var(--bg);
  color: var(--text-strong);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-sizing: border-box;
}
.account-display-name-input:focus {
  border-color: var(--primary);
  outline: none;
}

/* Accounts add page */
.accounts-add-oauth {
  max-width: 36rem;
  margin-bottom: 0.25rem;
}
.accounts-add-oauth .oauth-buttons {
  margin-top: 0;
}
.accounts-add-form {
  display: flex;
  flex-direction: column;
  gap: 0.85rem;
  max-width: 36rem;
}
.accounts-add-card {
  background: var(--bg-elevated);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 1rem 1.15rem 1.1rem;
}
.accounts-add-card-title {
  margin: 0 0 0.85rem;
  font-size: 0.78rem;
  font-weight: 650;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: var(--muted);
}
.accounts-add-grid {
  display: grid;
  grid-template-columns: 1fr;
  gap: 0.75rem;
}
.accounts-add-grid-server {
  grid-template-columns: minmax(0, 1fr) 6.5rem;
  align-items: end;
}
.accounts-add-field {
  display: flex;
  flex-direction: column;
  gap: 0.3rem;
  margin: 0;
  min-width: 0;
}
.accounts-add-label {
  color: var(--muted);
  font-size: 0.85rem;
}
.accounts-add-form input[type="email"],
.accounts-add-form input[type="text"],
.accounts-add-form input[type="password"],
.accounts-add-form input[type="number"] {
  display: block;
  width: 100%;
  margin: 0;
  background: var(--bg-input);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  color: var(--text-strong);
  padding: 0.55rem 0.7rem;
  font: inherit;
  font-size: 0.95rem;
  transition: var(--control-transition);
}
.accounts-add-form input::placeholder {
  color: var(--muted);
}
.accounts-add-form input:hover {
  border-color: var(--border-strong);
}
.accounts-add-form input:focus-visible {
  outline: none;
  border-color: var(--primary);
  box-shadow: 0 0 0 3px var(--primary-muted);
}
.accounts-add-form input[type="number"] {
  font-variant-numeric: tabular-nums;
  -moz-appearance: textfield;
}
.accounts-add-form input[type="number"]::-webkit-outer-spin-button,
.accounts-add-form input[type="number"]::-webkit-inner-spin-button {
  -webkit-appearance: none;
  margin: 0;
}
.accounts-add-check {
  display: inline-flex;
  align-items: center;
  gap: 0.5rem;
  margin-top: 0.85rem;
  padding: 0.4rem 0.65rem;
  border: 1px solid var(--border);
  border-radius: 999px;
  background: var(--bg);
  color: var(--text);
  font-size: 0.85rem;
  cursor: pointer;
  user-select: none;
  width: fit-content;
  transition: var(--control-transition);
}
.accounts-add-check:hover {
  border-color: var(--border-strong);
  background: var(--bg-hover);
  color: var(--text-strong);
}
.accounts-add-check:has(input:checked) {
  background: var(--primary-muted);
  border-color: var(--primary);
  color: var(--text-strong);
}
.accounts-add-check input {
  accent-color: var(--primary);
  margin: 0;
  cursor: pointer;
}
.accounts-add-actions {
  margin-top: 0.35rem;
  padding-top: 0.15rem;
}
.accounts-separator {
  text-align: center;
  margin: 1rem 0;
}

@media (max-width: 560px) {
  .accounts-add-grid-server {
    grid-template-columns: 1fr;
  }
  .accounts-add-field-port {
    max-width: 8rem;
  }
}

/* Sidebar accounts button (bottom, above version) */
.accounts-link-btn {
  display: block;
  width: 100%;
  margin: 0;
  text-align: center;
  background: transparent;
  border: 1px solid var(--border);
  color: var(--text);
  padding: 0.5rem 0.75rem;
  border-radius: var(--radius);
  text-decoration: none;
  font-size: 0.9rem;
  transition: var(--control-transition);
}
.accounts-link-btn:hover {
  background: var(--bg-hover);
  color: var(--text-strong);
  text-decoration: none;
}
.accounts-link-btn:focus-visible {
  outline: 2px solid var(--focus-ring);
  outline-offset: 2px;
}

/* Account switcher rows above compose */
.account-link {
  justify-content: flex-start;
  align-items: center;
  gap: 0.45rem;
  text-decoration: none;
}
.account-link:hover,
.account-link:focus-visible {
  text-decoration: none;
}
.account-dot {
  display: inline-block;
  flex: 0 0 0.75rem;
  width: 0.75rem;
  font-size: 0.55rem;
  line-height: 1;
  text-align: center;
  color: transparent;
  /* fallback glyph is always present so size stays stable */
  user-select: none;
}
.account-dot.is-on {
  color: var(--primary);
}
.account-dot.is-off {
  color: transparent;
}

/* From dropdown in compose */
.from-select {
  display: block;
  width: 100%;
  padding: 0.5rem 0.75rem;
  background: var(--bg-input);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  color: var(--text-strong);
  font-size: 0.95rem;
  font: inherit;
  margin-top: 0.25rem;
  transition: var(--control-transition);
}
.from-select:focus-visible {
  outline: none;
  border-color: var(--primary);
  box-shadow: 0 0 0 3px var(--primary-muted);
}

/* --- AI add-on (optional, gated by AI_ENABLED + AI_GATEWAY_URL) ----------- */

.ai-spark {
  color: var(--primary);
  font-size: 1.05rem;
  line-height: 1;
}

.msg-triage {
  font-family: var(--font-mono);
  font-size: 0.66rem;
  letter-spacing: 0.04em;
  color: #9fe3d9;
  border: 1px solid rgba(61, 184, 168, 0.5);
  border-radius: 999px;
  padding: 1px 8px;
  white-space: nowrap;
  flex: none;
  max-width: 8rem;
  overflow: hidden;
  text-overflow: ellipsis;
}

/* Reader AI panel */
.ai-panel {
  margin: 0.9rem 0;
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  background: var(--bg-elevated);
  padding: 0.75rem 0.9rem;
}

.ai-panel-head {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  width: 100%;
  margin-bottom: 0.6rem;
  background: none;
  border: 0;
  padding: 0;
  color: inherit;
  font: inherit;
  text-align: left;
  cursor: pointer;
}

.ai-panel-head:hover strong,
.ai-panel-head:focus-visible strong {
  color: var(--primary);
}

.ai-panel-head:focus-visible {
  outline: 2px solid var(--focus-ring);
  outline-offset: 2px;
  border-radius: var(--radius);
}

.ai-panel-head strong {
  color: var(--text-strong);
  font-weight: 600;
}

.ai-panel-chevron {
  margin-left: auto;
  flex: none;
  color: var(--muted);
  transition: transform 0.15s ease;
}

.ai-panel.is-collapsed .ai-panel-chevron {
  transform: rotate(180deg);
}

.ai-panel.is-collapsed .ai-panel-head {
  margin-bottom: 0;
}

.ai-panel.is-collapsed .ai-panel-body {
  display: none;
}

.ai-quota {
  font-size: 0.75rem;
}

.ai-quota.is-low {
  color: var(--warning);
}

.ai-chips {
  display: flex;
  flex-wrap: wrap;
  gap: 0.4rem;
}

.ai-chip {
  font-family: var(--font-mono);
  font-size: 0.72rem;
  letter-spacing: 0.04em;
  color: #cfe4e0;
  border-color: rgba(61, 184, 168, 0.45);
  background: rgba(61, 184, 168, 0.07);
  border-radius: 999px;
  padding: 0.25rem 0.7rem;
}

.ai-chip:hover {
  border-color: var(--primary);
  color: var(--text-strong);
  background: var(--primary-muted);
}

.ai-chip:disabled {
  opacity: 0.55;
  cursor: default;
}

.ai-results {
  margin-top: 0.75rem;
  display: flex;
  flex-direction: column;
  gap: 0.6rem;
}

.ai-card {
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--bg);
  padding: 0.7rem 0.85rem;
}

.ai-card-label {
  font-family: var(--font-mono);
  font-size: 0.66rem;
  letter-spacing: 0.1em;
  text-transform: uppercase;
  color: var(--primary);
}

.ai-card p {
  margin: 0.3rem 0 0;
  font-size: 0.85rem;
  color: var(--text);
  white-space: pre-wrap;
  word-break: break-word;
}

.ai-card ul {
  margin: 0.4rem 0 0;
  padding-left: 1.1rem;
  font-size: 0.85rem;
  color: var(--text);
}

.ai-card li {
  margin: 0.15rem 0;
}

.ai-replies {
  font-size: 0.85rem;
  color: var(--muted);
}

.ai-reply {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  margin: 0.45rem 0;
  border-left: 2px solid var(--primary);
  padding-left: 0.6rem;
  color: var(--text-strong);
  font-style: italic;
}

.ai-reply-actions {
  margin-left: auto;
  display: inline-flex;
  align-items: center;
  gap: 0.25rem;
  flex: none;
  font-style: normal;
}

.ai-reply-actions .btn {
  font-style: normal;
  padding: 0.2rem 0.35rem;
  line-height: 1;
}

.ai-loading {
  color: var(--muted);
  font-size: 0.8rem;
}

.ai-error {
  color: var(--danger);
  font-size: 0.8rem;
}

.ai-triage-result {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  font-size: 0.85rem;
  color: var(--text);
}

.ai-card .ai-triage-result {
  margin-top: 0.35rem;
}

/* Compose AI toolbar */
.ai-compose {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 0.5rem;
  margin: 0.6rem 0 0.9rem;
  padding: 0.5rem 0.7rem;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--bg-elevated);
}

.ai-compose-label {
  color: var(--text-strong);
  font-size: 0.85rem;
  font-weight: 600;
}

.ai-compose-select {
  background: var(--bg-input);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  color: var(--text-strong);
  font: inherit;
  font-size: 0.8rem;
  padding: 0.25rem 0.4rem;
}

.ai-status {
  font-size: 0.8rem;
  margin-left: auto;
}
