/* R4nmaru Email — 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; }

.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;
}

.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-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 {
  margin-bottom: 0.55rem;
  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;
}

/* 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;
}

.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);
}

.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;
}

.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;
}

.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 {
  font-size: 0.88rem;
  color: var(--text-strong);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  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%;
}

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

.mail-list-pane .pager {
  padding: 0.45rem 0.65rem 0.55rem;
  margin-top: 0;
  border-top: 1px solid var(--border);
  flex-shrink: 0;
  background: var(--bg-elevated);
}

.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 .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 {
  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-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;
}

.mobile-only {
  display: none !important;
}

.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: var(--bg-input);
  border: 1px solid var(--border);
  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: var(--bg-input);
  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; }

.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;
  }
  .sidebar {
    width: 100%;
    height: auto;
    min-height: auto;
    position: sticky;
    top: 0;
    z-index: 30;
    padding: 0.75rem 0.85rem 0.7rem;
    gap: 0.65rem;
    border-right: none;
    border-bottom: 1px solid var(--border);
  }
  .brand a span {
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
  }
  .compose-btn {
    margin: 0;
  }
  .folder-nav {
    flex-direction: row;
    flex-wrap: nowrap;
    gap: 0.35rem;
    overflow-x: auto;
    padding-bottom: 0.15rem;
    scrollbar-width: none;
  }
  .folder-nav::-webkit-scrollbar {
    display: none;
  }
  .folder-nav a,
  .folder-nav button,
  .nav-link-btn {
    flex: 0 0 auto;
    white-space: nowrap;
    background: var(--bg);
    border: 1px solid var(--border);
    padding: 0.5rem 0.75rem;
    width: auto;
    text-align: center;
  }
  .folder-nav a.active {
    box-shadow: none;
  }
  .settings-toggle {
    justify-content: center;
    gap: 0.3rem;
  }
  .sidebar-settings {
    position: relative;
    margin: 0;
  }
  .settings-panel {
    position: absolute;
    top: calc(100% + 0.5rem);
    left: 0;
    right: 0;
    z-index: 40;
    background: var(--bg-elevated);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 0.5rem 0.5rem 0.6rem;
    box-shadow: var(--shadow-dropdown);
    max-height: 0;
  }
  .sidebar-settings.is-open .settings-panel {
    max-height: 240px;
  }
  .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;
  }

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

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

  .mail-list-pane .pager {
    border-top: none;
    padding-bottom: 0;
  }

  .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;
  }

  .msg-list-scroll,
  .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;
  }

  .mobile-only {
    display: inline-flex !important;
  }

  .mobile-back {
    align-self: flex-start;
  }

  .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;
  }

  .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;
  }

  .contact-action-cell .btn {
    width: 100%;
  }

  .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;
  }
}
