:root {
  color-scheme: dark;
  --bg: #131314;
  --surface: #1E1F20;
  --surface-2: #242628;
  --surface-elev: #28292C;
  --surface-hover: #2C2E30;
  --surface-active: rgba(138, 180, 248, 0.16);
  --border: #3C4043;
  --border-subtle: #2E3134;
  --border-strong: #5F6368;
  --text: #E8EAED;
  --text-muted: #9AA0A6;
  --text-dim: #757B80;
  --accent: #8AB4F8;
  --accent-hover: #AECBFA;
  --accent-soft: rgba(138, 180, 248, 0.16);
  --accent-border: rgba(138, 180, 248, 0.34);
  --accent-text: #AECBFA;
  --on-accent: #0B192C;
  --compose-bg: #8AB4F8;
  --compose-ink: #0B192C;
  --compose-hover: #AECBFA;
  --success: #81C995;
  --success-soft: rgba(129, 201, 149, 0.16);
  --warning: #FDD663;
  --warning-soft: rgba(253, 214, 99, 0.16);
  --danger: #F28B82;
  --danger-soft: rgba(242, 139, 130, 0.16);
  --shadow-sm: 0 1px 3px rgba(0, 0, 0, 0.35);
  --shadow-md: 0 6px 18px rgba(0, 0, 0, 0.45);
  --shadow-lg: 0 16px 40px rgba(0, 0, 0, 0.60);
  --font-sans: "Inter", -apple-system, BlinkMacSystemFont, sans-serif;
  --font-display: "Plus Jakarta Sans", "Inter", sans-serif;
  --font-mono: "JetBrains Mono", ui-monospace, monospace;
  --ease: cubic-bezier(0.16, 1, 0.3, 1);
  --radius: 12px;
  --radius-sm: 8px;
  --radius-pill: 999px;
}

html[data-theme="light"] {
  color-scheme: light;
  --bg: #F6F8FC;
  --surface: #FFFFFF;
  --surface-2: #F1F3F4;
  --surface-elev: #EAF1FB;
  --surface-hover: #F1F3F4;
  --surface-active: #D3E3FD;
  --border: #DADCE0;
  --border-subtle: #E8EAED;
  --border-strong: #BDC1C6;
  --text: #202124;
  --text-muted: #5F6368;
  --text-dim: #80868B;
  --accent: #1A73E8;
  --accent-hover: #1557B0;
  --accent-soft: #E8F0FE;
  --accent-border: #AECBFA;
  --accent-text: #174EA6;
  --on-accent: #FFFFFF;
  --compose-bg: #C2E7FF;
  --compose-ink: #001D35;
  --compose-hover: #B3DDF8;
  --success: #1E8E3E;
  --success-soft: #E6F4EA;
  --warning: #F9AB00;
  --warning-soft: #FEF7E0;
  --danger: #D93025;
  --danger-soft: #FCE8E6;
  --shadow-sm: 0 1px 2px rgba(60, 64, 67, 0.14), 0 1px 3px 1px rgba(60, 64, 67, 0.08);
  --shadow-md: 0 4px 12px rgba(60, 64, 67, 0.15), 0 1px 3px 1px rgba(60, 64, 67, 0.10);
  --shadow-lg: 0 12px 32px rgba(60, 64, 67, 0.22);
}

*, *::before, *::after {
  box-sizing: border-box;
}

html, body {
  margin: 0;
  padding: 0;
  height: 100%;
  max-width: 100%;
  overflow-x: hidden;
  background: var(--bg);
  color: var(--text);
  font-family: var(--font-sans);
  font-size: 14px;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
}

::-webkit-scrollbar {
  width: 7px;
  height: 7px;
}

::-webkit-scrollbar-track {
  background: transparent;
}

::-webkit-scrollbar-thumb {
  background: var(--border-strong);
  border-radius: 999px;
}

::-webkit-scrollbar-thumb:hover {
  background: var(--text-dim);
}

.hidden {
  display: none !important;
}

svg {
  width: 18px;
  height: 18px;
  fill: currentColor;
  flex-shrink: 0;
}

input, select, textarea, button {
  font-family: inherit;
  font-size: inherit;
  color: inherit;
}

button, a, .msg-row, .nav-item, .chip, .tab-btn {
  -webkit-tap-highlight-color: transparent;
}

.msg-row {
  user-select: none;
  -webkit-user-select: none;
  -webkit-touch-callout: none;
}

input:where(:not([type="checkbox"]):not([type="radio"]):not([type="color"]):not([type="file"])),
select {
  height: 36px;
  line-height: 1.2;
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 0 11px;
  outline: none;
  transition: border-color 0.16s var(--ease), background-color 0.16s var(--ease);
}

select {
  appearance: none;
  -webkit-appearance: none;
  padding-right: 30px;
  cursor: pointer;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='12' viewBox='0 0 24 24' fill='none' stroke='%2394A3B8' stroke-width='2.2' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpolyline points='6 9 12 15 18 9'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 10px center;
  background-size: 13px 13px;
}

textarea {
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 9px 11px;
  line-height: 1.5;
  outline: none;
  transition: border-color 0.16s var(--ease), background-color 0.16s var(--ease);
}

input[type="radio"] {
  width: 16px;
  height: 16px;
  padding: 0;
  margin: 0;
  accent-color: var(--accent);
  cursor: pointer;
  flex-shrink: 0;
}

input[type="checkbox"] {
  appearance: none;
  -webkit-appearance: none;
  width: 16px;
  height: 16px;
  padding: 0;
  margin: 0;
  border: 1.5px solid var(--border-strong);
  border-radius: 4px;
  background-color: var(--surface-2);
  cursor: pointer;
  flex-shrink: 0;
  display: inline-grid;
  place-content: center;
  transition: background-color 0.14s var(--ease), border-color 0.14s var(--ease);
}

input[type="checkbox"]:checked {
  background-color: var(--accent);
  border-color: var(--accent);
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 16 16' fill='none' stroke='%23ffffff' stroke-width='2.4' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='M3.5 8.2L6.6 11.3L12.6 4.8'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: center;
  background-size: 12px 12px;
}

input[type="color"] {
  width: 44px;
  height: 36px;
  padding: 3px;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background: var(--surface-2);
  cursor: pointer;
}

input:focus, select:focus, textarea:focus {
  border-color: var(--accent);
}

button {
  cursor: pointer;
  border: none;
  background: none;
}

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 7px;
  height: 36px;
  padding: 0 16px;
  border-radius: 999px;
  font-weight: 500;
  font-size: 13.5px;
  line-height: 1;
  white-space: nowrap;
  flex-shrink: 0;
  border: 1px solid var(--border);
  background: var(--surface);
  transition: background-color 0.16s var(--ease), border-color 0.16s var(--ease), transform 0.12s var(--ease);
}

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

.btn:active {
  transform: translateY(1px);
}

.btn-primary {
  background: var(--accent);
  border-color: var(--accent);
  color: var(--on-accent);
}

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

.btn-danger {
  background: var(--danger-soft);
  border-color: color-mix(in srgb, var(--danger) 35%, transparent);
  color: var(--danger);
}

.btn-full {
  width: 100%;
}

.btn-xs {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 5px;
  height: 28px;
  padding: 0 11px;
  border-radius: 999px;
  border: 1px solid var(--border);
  background: var(--surface-2);
  font-size: 12px;
  font-weight: 500;
  line-height: 1;
  white-space: nowrap;
  flex-shrink: 0;
  text-decoration: none;
  color: var(--text);
  transition: background-color 0.14s var(--ease), border-color 0.14s var(--ease), color 0.14s var(--ease);
}

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

.btn-xs svg {
  width: 14px;
  height: 14px;
}

select.btn-xs {
  padding-right: 26px;
  background-color: var(--surface-2);
}

.btn-accent-soft {
  background: var(--accent-soft);
  border-color: var(--accent-border);
  color: var(--accent-text);
  font-weight: 600;
}

.btn-accent-soft:hover {
  background: var(--accent);
  border-color: var(--accent);
  color: var(--on-accent);
}

.btn-danger-text {
  color: var(--danger);
}

.btn-danger-text:hover {
  background: var(--danger-soft);
  border-color: color-mix(in srgb, var(--danger) 35%, transparent);
}

.icon-btn {
  width: 34px;
  height: 34px;
  flex-shrink: 0;
  border-radius: 50%;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  color: var(--text-muted);
  transition: background-color 0.15s var(--ease), color 0.15s var(--ease);
}

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

.link-btn {
  color: var(--text-muted);
  font-size: 12.5px;
  padding: 4px 6px;
  border-radius: 5px;
  text-decoration: none;
  transition: color 0.14s var(--ease), background-color 0.14s var(--ease);
}

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

/* Auth Screen */
.auth-screen {
  min-height: 100vh;
  min-height: 100dvh;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: calc(16px + env(safe-area-inset-top, 0px)) 16px calc(16px + env(safe-area-inset-bottom, 0px));
  background: var(--bg);
}

.auth-card {
  width: 100%;
  max-width: 400px;
  background: var(--surface);
  border: 1px solid var(--border-subtle);
  border-radius: 20px;
  padding: 34px 30px;
  box-shadow: var(--shadow-md);
}

.auth-brand {
  display: flex;
  align-items: center;
  gap: 12px;
  margin-bottom: 26px;
}

.auth-logo {
  width: 34px;
  height: 34px;
}

.auth-title {
  margin: 0;
  font-family: var(--font-display);
  font-size: 21px;
  font-weight: 600;
  letter-spacing: -0.02em;
}

.auth-form {
  display: flex;
  flex-direction: column;
  gap: 16px;
  min-width: 0;
  max-width: 100%;
}

.field-group {
  display: flex;
  flex-direction: column;
  gap: 6px;
  min-width: 0;
  max-width: 100%;
}

.field-group > input:where(:not([type="checkbox"]):not([type="radio"]):not([type="color"]):not([type="file"])),
.field-group > select,
.field-group > textarea {
  width: 100%;
  max-width: 100%;
  min-width: 0;
}

.field-group label {
  font-size: 12.5px;
  font-weight: 500;
  color: var(--text-muted);
}

.input-addon-wrap {
  width: 100%;
  max-width: 100%;
  min-width: 0;
  height: 36px;
  display: flex;
  align-items: stretch;
}

.input-addon-wrap input {
  flex: 1 1 0%;
  min-width: 0;
  width: 0;
  height: 100%;
  border-top-right-radius: 0;
  border-bottom-right-radius: 0;
  border-right: none;
}

.input-addon {
  display: inline-flex;
  align-items: center;
  height: 100%;
  padding: 0 11px;
  background: var(--surface-elev);
  border: 1px solid var(--border);
  border-top-right-radius: var(--radius-sm);
  border-bottom-right-radius: var(--radius-sm);
  font-family: var(--font-mono);
  font-size: 12.5px;
  color: var(--text-muted);
  white-space: nowrap;
}

.input-addon-select {
  flex: 0 1 auto;
  min-width: 0;
  max-width: 55%;
  height: 100%;
  overflow: hidden;
  text-overflow: ellipsis;
  background-color: var(--surface-elev);
  border: 1px solid var(--border);
  border-radius: 0 var(--radius-sm) var(--radius-sm) 0;
  color: var(--text-muted);
  font-family: var(--font-mono);
  font-size: 12.5px;
  padding: 0 28px 0 10px;
}

.form-error {
  padding: 9px 12px;
  border-radius: var(--radius-sm);
  background: var(--danger-soft);
  border: 1px solid rgba(239, 68, 68, 0.3);
  color: var(--danger);
  font-size: 13px;
}

/* App Shell */
.app-shell {
  height: 100vh;
  height: 100dvh;
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

.topbar {
  height: 60px;
  flex-shrink: 0;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  padding: 0 16px;
  background: var(--bg);
  border-bottom: 1px solid var(--border-subtle);
}

.topbar-left {
  display: flex;
  align-items: center;
  gap: 10px;
  min-width: 212px;
}

.brand-lockup {
  display: flex;
  align-items: center;
  gap: 10px;
}

.brand-icon {
  width: 24px;
  height: 24px;
}

.brand-name {
  font-family: var(--font-display);
  font-weight: 600;
  font-size: 15.5px;
  letter-spacing: -0.02em;
}

.topbar-search {
  flex: 1;
  max-width: 580px;
  position: relative;
  display: flex;
  align-items: center;
}

.topbar-search .search-icon {
  position: absolute;
  left: 14px;
  width: 16px;
  height: 16px;
  color: var(--text-dim);
  pointer-events: none;
}

.topbar-search input {
  width: 100%;
  height: 44px;
  padding: 0 118px 0 40px;
  border-radius: 999px;
  background: var(--surface-2);
  border: 1px solid transparent;
  font-size: 13.5px;
  transition: background-color 0.16s var(--ease), border-color 0.16s var(--ease), box-shadow 0.16s var(--ease);
}

.topbar-search input:focus {
  background: var(--surface);
  border-color: var(--border);
  box-shadow: var(--shadow-sm);
}

.search-kbd {
  position: absolute;
  right: 84px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 20px;
  height: 20px;
  padding: 0 5px;
  border-radius: 4px;
  background: var(--surface-elev);
  border: 1px solid var(--border-strong);
  font-family: var(--font-mono);
  font-size: 11px;
  color: var(--text-dim);
  pointer-events: none;
}

.search-clear {
  position: absolute;
  right: 82px;
  font-size: 18px;
  color: var(--text-dim);
  padding: 0 5px;
}

.search-filter-btn {
  position: absolute;
  right: 6px;
  height: 32px;
  width: auto;
  padding: 0 12px;
  gap: 5px;
  border-radius: 999px;
  background: var(--surface);
  border: 1px solid var(--border-subtle);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  font-size: 12px;
  font-weight: 500;
  color: var(--text-muted);
  transition: background-color 0.14s var(--ease), border-color 0.14s var(--ease), color 0.14s var(--ease);
}

.search-filter-btn:hover,
.search-filter-btn.active {
  color: var(--accent-text);
  background: var(--accent-soft);
  border-color: var(--accent-border);
}

.search-filter-btn svg {
  width: 16px;
  height: 16px;
  fill: currentColor;
}

.topbar-right {
  display: flex;
  align-items: center;
  gap: 8px;
}

.topbar-action-btn {
  width: auto;
  padding: 0 13px;
  gap: 6px;
  border-radius: 999px;
  border: 1px solid var(--border);
  background: var(--surface);
  font-size: 12.5px;
  font-weight: 500;
  color: var(--text);
}

.topbar-sep {
  width: 1px;
  height: 20px;
  background: var(--border);
  margin: 0 4px;
}

.user-pill {
  display: flex;
  align-items: center;
  gap: 8px;
  height: 32px;
  padding: 3px 10px 3px 4px;
  border-radius: 999px;
  background: var(--surface-2);
  border: 1px solid var(--border);
  transition: background-color 0.14s var(--ease), border-color 0.14s var(--ease);
}

.user-pill[role="button"] {
  cursor: pointer;
}

.user-pill[role="button"]:hover {
  background: var(--surface-hover);
  border-color: var(--border-strong);
}

.user-avatar {
  width: 24px;
  height: 24px;
  border-radius: 50%;
  background: var(--accent);
  color: var(--on-accent);
  font-size: 11.5px;
  font-weight: 600;
  display: flex;
  align-items: center;
  justify-content: center;
  overflow: hidden;
  flex-shrink: 0;
}

.avatar-img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  border-radius: 50%;
  display: block;
}

.user-email {
  font-size: 12.5px;
  color: var(--text-muted);
  max-width: 190px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.mobile-only {
  display: none;
}

/* Workspace */
.workspace {
  flex: 1;
  display: flex;
  min-height: 0;
  overflow: hidden;
}

.sidebar {
  width: 256px;
  flex-shrink: 0;
  background: var(--bg);
  border-right: 1px solid var(--border-subtle);
  display: flex;
  flex-direction: column;
  min-height: 0;
}

.sidebar-top {
  padding: 14px 12px 10px;
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.btn-compose {
  width: 100%;
  justify-content: center;
  height: 48px;
  padding: 0 18px;
  font-weight: 600;
  border-radius: 16px;
  background: var(--compose-bg);
  color: var(--compose-ink);
  border: none;
  box-shadow: var(--shadow-sm);
  transition: background-color 0.16s var(--ease), box-shadow 0.16s var(--ease), transform 0.12s var(--ease);
}

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

.mailbox-switcher {
  display: flex;
  flex-direction: column;
  align-items: stretch;
  gap: 6px;
  padding: 9px 10px;
  border-radius: 8px;
  background: var(--surface-2);
  border: 1px solid var(--border);
}

.mailbox-switcher-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 6px;
}

.mailbox-switcher-label {
  font-size: 11px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--text-dim);
}

.mailbox-add-btn,
.nav-add-pill {
  height: 22px;
  padding: 0 8px;
  border-radius: 999px;
  font-size: 11px;
  font-weight: 600;
  line-height: 1;
  color: var(--accent);
  background: var(--accent-soft);
  border: 1px solid var(--accent-border);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  white-space: nowrap;
  transition: background-color 0.14s var(--ease), color 0.14s var(--ease);
}

.mailbox-add-btn:hover,
.nav-add-pill:hover {
  background: var(--accent);
  color: var(--on-accent);
}

.mailbox-switcher select {
  width: 100%;
  min-width: 0;
  height: 32px;
  font-size: 12.5px;
  padding: 0 28px 0 9px;
  background-color: var(--surface);
}

.sidebar-nav {
  flex: 1;
  overflow-y: auto;
  padding: 6px 12px 16px;
}

.nav-section {
  display: flex;
  flex-direction: column;
  gap: 3px;
}

.nav-section-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 8px 10px 4px;
  font-size: 11px;
  font-weight: 600;
  color: var(--text-dim);
  text-transform: uppercase;
  letter-spacing: 0.06em;
}

.mini-plus {
  width: 20px;
  height: 20px;
  border-radius: 4px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  color: var(--text-muted);
  font-size: 15px;
}

.mini-plus:hover {
  background: var(--surface-hover);
  color: var(--text);
}

.nav-item {
  width: 100%;
  height: 36px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  padding: 0 14px;
  border-radius: 999px;
  font-size: 13.5px;
  color: var(--text-muted);
  text-align: left;
  transition: background-color 0.14s var(--ease), color 0.14s var(--ease);
}

.nav-item svg {
  width: 16px;
  height: 16px;
  opacity: 0.78;
}

.nav-item:hover {
  background: var(--surface-hover);
  color: var(--text);
}

.nav-item:hover svg {
  opacity: 1;
}

.nav-item.active {
  background: var(--surface-active);
  color: var(--accent-text);
  font-weight: 600;
  box-shadow: none;
}

.nav-item.active svg {
  color: var(--accent);
  opacity: 1;
}

.nav-item-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  flex-shrink: 0;
}

.nav-label {
  flex: 1;
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  display: flex;
  align-items: center;
  gap: 9px;
}

.nav-label > span {
  overflow: hidden;
  text-overflow: ellipsis;
}

.nav-badge {
  font-family: var(--font-mono);
  font-size: 11px;
  font-weight: 600;
  padding: 1px 7px;
  border-radius: 999px;
  background: var(--accent);
  color: var(--on-accent);
}

.nav-empty {
  padding: 4px 10px 6px;
  font-size: 12px;
  color: var(--text-dim);
}

.nav-empty-action {
  width: 100%;
  height: 30px;
  padding: 0 10px;
  border-radius: var(--radius-sm);
  border: 1px dashed var(--border-strong);
  color: var(--text-dim);
  font-size: 12px;
  text-align: left;
  display: flex;
  align-items: center;
  gap: 6px;
  transition: background-color 0.14s var(--ease), border-color 0.14s var(--ease), color 0.14s var(--ease);
}

.nav-empty-action:hover {
  background: var(--surface-hover);
  border-color: var(--accent-border);
  color: var(--accent);
}

.nav-divider {
  height: 1px;
  background: var(--border);
  margin: 12px 6px;
}

.sidebar-footer {
  padding: 12px 14px;
  border-top: 1px solid var(--border);
  background: var(--surface-2);
}

.quota-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  margin-bottom: 6px;
  font-size: 11.5px;
  color: var(--text-dim);
}

.quota-bar {
  height: 5px;
  border-radius: 999px;
  background: var(--surface-elev);
  overflow: hidden;
}

.quota-fill {
  height: 100%;
  background: var(--accent);
  border-radius: 999px;
  width: 0%;
  transition: width 0.3s var(--ease);
}

.quota-text {
  font-family: var(--font-mono);
  font-size: 11px;
  color: var(--text-muted);
}

/* Main Pane */
.main-pane {
  flex: 1;
  min-width: 0;
  min-height: 0;
  display: flex;
  flex-direction: column;
  background: var(--bg);
}

.mail-workspace {
  flex: 1;
  display: flex;
  min-height: 0;
}

.mail-list-col {
  width: 400px;
  flex-shrink: 0;
  border-right: 1px solid var(--border);
  background: var(--surface);
  display: flex;
  flex-direction: column;
  min-height: 0;
}

.list-toolbar {
  padding: 14px 16px 12px;
  border-bottom: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  gap: 10px;
  background: var(--surface);
}

.list-toolbar-row {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
}

.pane-title {
  margin: 0;
  font-family: var(--font-display);
  font-size: 16px;
  font-weight: 600;
  letter-spacing: -0.015em;
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.pane-count {
  font-family: var(--font-mono);
  font-size: 11.5px;
  padding: 2px 7px;
  border-radius: 999px;
  background: var(--surface-2);
  border: 1px solid var(--border);
  color: var(--text-muted);
}

.pane-count:empty {
  display: none;
}

.list-toolbar-actions {
  margin-left: auto;
  display: inline-flex;
  align-items: center;
  gap: 6px;
  flex-shrink: 0;
}

.icon-btn-sm {
  width: 28px;
  height: 28px;
  border: 1px solid var(--border);
  background: var(--surface-2);
}

.icon-btn-sm svg {
  width: 15px;
  height: 15px;
}

.filter-chips {
  display: flex;
  gap: 4px;
  padding: 3px;
  border-radius: 8px;
  background: var(--surface-2);
  border: 1px solid var(--border);
}

.chip {
  flex: 1;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  height: 28px;
  padding: 0 9px;
  border-radius: 6px;
  font-size: 12px;
  font-weight: 500;
  line-height: 1;
  white-space: nowrap;
  color: var(--text-muted);
  background: transparent;
  transition: background-color 0.14s var(--ease), color 0.14s var(--ease);
}

.chip:hover {
  color: var(--text);
}

.chip.active {
  background: var(--surface-elev);
  color: var(--text);
  font-weight: 600;
  box-shadow: var(--shadow-sm);
}

.list-toolbar-row .checkbox-wrap,
.msg-checkbox {
  display: none !important;
}

.bulk-bar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 6px;
  flex-wrap: nowrap;
  padding: 6px 8px;
  border-radius: var(--radius-sm);
  background: var(--surface-elev);
  border: 1px solid var(--accent-border);
}

.bulk-bar-head {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  flex-shrink: 0;
}

.bulk-clear-btn {
  font-size: 16px;
  line-height: 1;
}

.bulk-count {
  min-width: 22px;
  height: 22px;
  padding: 0 6px;
  border-radius: 999px;
  background: var(--accent-soft);
  border: 1px solid var(--accent-border);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  font-family: var(--font-mono);
  font-size: 11.5px;
  font-weight: 600;
  color: var(--accent);
}

.bulk-actions {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  flex-wrap: nowrap;
}

.bulk-bar .detail-icon-btn {
  width: 28px;
  height: 28px;
}

.bulk-bar .detail-icon-btn svg {
  width: 15px;
  height: 15px;
}

.message-list {
  flex: 1;
  overflow-y: auto;
}

.empty-list-state {
  padding: 56px 20px;
}

.msg-row {
  position: relative;
  display: flex;
  align-items: flex-start;
  gap: 11px;
  padding: 13px 16px;
  border-bottom: 1px solid var(--border-subtle);
  cursor: pointer;
  transition: background-color 0.14s var(--ease), opacity 0.12s var(--ease), transform 0.12s var(--ease);
}

.msg-row.msg-row-leaving {
  opacity: 0;
  transform: translateX(-10px);
  pointer-events: none;
}

.msg-row:hover {
  background: var(--surface-hover);
}

.msg-row.unread {
  background: var(--surface-2);
  box-shadow: inset 3px 0 0 var(--accent);
}

.msg-row.selected {
  background: var(--surface-active);
}

.msg-row.checked {
  background: var(--accent-soft);
  box-shadow: inset 3px 0 0 var(--accent);
}

.msg-row.unread .msg-sender,
.msg-row.unread .msg-subject {
  font-weight: 600;
  color: var(--text);
}

.msg-row-checks {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 7px;
  padding-top: 2px;
}

.star-btn {
  color: var(--text-dim);
  font-size: 15px;
  line-height: 1;
  padding: 0;
  transition: color 0.12s var(--ease), transform 0.12s var(--ease);
}

.star-btn:hover {
  color: var(--warning);
}

.star-btn.starred {
  color: var(--warning);
}

.msg-avatar {
  position: relative;
  width: 34px;
  height: 34px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  font-family: var(--font-display);
  font-size: 13px;
  font-weight: 600;
  color: #FFFFFF;
  flex-shrink: 0;
  margin-top: 1px;
  overflow: hidden;
  transition: transform 0.14s var(--ease), background-color 0.14s var(--ease);
}

.msg-row.checked .msg-avatar::after {
  content: "✓";
  position: absolute;
  inset: 0;
  border-radius: 50%;
  background: var(--accent);
  color: #FFFFFF;
  display: flex;
  align-items: center;
  justify-content: center;
  font-family: var(--font-sans);
  font-size: 15px;
  font-weight: 700;
}

.msg-row-main {
  flex: 1;
  min-width: 0;
}

.msg-row-top {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  margin-bottom: 2px;
}

.msg-sender {
  font-size: 13.5px;
  color: var(--text-muted);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.msg-row-top-right {
  display: inline-flex;
  align-items: center;
  justify-content: flex-end;
  flex-shrink: 0;
  min-height: 22px;
}

.msg-date {
  font-family: var(--font-mono);
  font-size: 11px;
  color: var(--text-dim);
  flex-shrink: 0;
}

.msg-row-quick-actions {
  display: none;
  align-items: center;
  gap: 3px;
}

.msg-row:hover .msg-date,
.msg-row:focus-within .msg-date {
  display: none;
}

.msg-row:hover .msg-row-quick-actions,
.msg-row:focus-within .msg-row-quick-actions {
  display: inline-flex;
}

@media (hover: none) {
  .msg-row:hover .msg-date,
  .msg-row:focus-within .msg-date {
    display: inline;
  }
  .msg-row:hover .msg-row-quick-actions,
  .msg-row:focus-within .msg-row-quick-actions {
    display: none;
  }
}

.row-action-btn {
  width: 24px;
  height: 22px;
  border-radius: 5px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  color: var(--text-muted);
  background: var(--surface-elev);
  border: 1px solid var(--border);
  transition: background-color 0.12s var(--ease), color 0.12s var(--ease), border-color 0.12s var(--ease);
}

.row-action-btn:hover {
  background: var(--surface-active);
  border-color: var(--border-strong);
  color: var(--text);
}

.row-action-btn.danger:hover {
  color: var(--danger);
  border-color: rgba(239, 68, 68, 0.45);
  background: var(--danger-soft);
}

.row-action-btn svg {
  width: 13px;
  height: 13px;
  fill: currentColor;
}

.msg-subject-line {
  display: flex;
  align-items: center;
  gap: 6px;
  margin-bottom: 3px;
}

.unread-dot {
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: var(--accent);
  flex-shrink: 0;
}

.msg-subject {
  font-size: 13px;
  color: var(--text-muted);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  flex: 1;
}

.msg-thread-pill {
  font-family: var(--font-mono);
  font-size: 10.5px;
  padding: 0 6px;
  border-radius: 999px;
  background: var(--surface-elev);
  border: 1px solid var(--border);
  color: var(--text-muted);
}

.msg-snippet {
  font-size: 12.5px;
  color: var(--text-dim);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.msg-meta-pills {
  display: flex;
  align-items: center;
  gap: 6px;
  margin-top: 6px;
  flex-wrap: wrap;
}

.mini-pill {
  font-size: 11px;
  padding: 1px 7px;
  border-radius: 999px;
  background: var(--surface-elev);
  border: 1px solid var(--border);
  color: var(--text-muted);
}

.mini-pill.failed {
  color: var(--danger);
  background: var(--danger-soft);
  border-color: rgba(239, 68, 68, 0.35);
}

.mini-pill.scheduled {
  color: var(--warning);
  border-color: rgba(245, 158, 11, 0.35);
}

/* Reading Pane */
.mail-read-col {
  flex: 1;
  min-width: 0;
  min-height: 0;
  display: flex;
  flex-direction: column;
  overflow-y: auto;
  background: var(--bg);
}

.empty-read-state {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 10px;
  color: var(--text-dim);
}

.empty-read-state svg {
  width: 38px;
  height: 38px;
  opacity: 0.42;
}

.empty-read-card {
  max-width: 420px;
  padding: 32px 28px;
  border-radius: 14px;
  background: var(--surface);
  border: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  align-items: center;
  text-align: center;
  gap: 14px;
  box-shadow: var(--shadow-sm);
}

.empty-read-title {
  font-family: var(--font-display);
  font-size: 16px;
  font-weight: 600;
  color: var(--text);
}

.empty-read-actions {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  flex-wrap: wrap;
}

.empty-read-shortcuts {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 12px;
  flex-wrap: wrap;
  padding-top: 8px;
  border-top: 1px solid var(--border);
  font-size: 12px;
  color: var(--text-dim);
}

.empty-read-shortcuts > span {
  display: inline-flex;
  align-items: center;
  gap: 6px;
}

@keyframes paneFadeIn {
  from {
    opacity: 0.65;
    transform: translateY(4px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

.message-detail-pane {
  padding: 24px 30px 42px;
  max-width: 980px;
  width: 100%;
  margin: 0 auto;
  display: flex;
  flex-direction: column;
  gap: 18px;
}

.message-detail-pane.pane-enter {
  animation: paneFadeIn 140ms var(--ease) both;
}

.detail-header {
  display: flex;
  flex-direction: column;
  gap: 12px;
  padding-bottom: 16px;
  border-bottom: 1px solid var(--border);
}

.detail-top-bar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
}

.detail-nav-group {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  flex-shrink: 0;
  margin-left: auto;
}

.detail-nav-pos {
  font-family: var(--font-mono);
  font-size: 11.5px;
  color: var(--text-dim);
  margin-right: 4px;
  white-space: nowrap;
}

.detail-nav-btn {
  width: 28px;
  padding: 0;
  justify-content: center;
  font-size: 16px;
  line-height: 1;
}

.detail-nav-btn:disabled {
  opacity: 0.35;
  cursor: default;
  pointer-events: none;
}

.detail-subject {
  margin: 0;
  font-family: var(--font-display);
  font-size: 19px;
  font-weight: 600;
  letter-spacing: -0.02em;
  line-height: 1.35;
  overflow-wrap: anywhere;
  word-break: break-word;
}

.detail-actions {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  flex-wrap: wrap;
}

.detail-action-group {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  flex-wrap: wrap;
}

.detail-icon-actions {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  margin-left: auto;
}

.detail-icon-btn {
  width: 30px;
  height: 30px;
  padding: 0;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border);
  background: var(--surface-2);
  color: var(--text-muted);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  transition: background-color 0.14s var(--ease), color 0.14s var(--ease), border-color 0.14s var(--ease);
}

.detail-icon-btn svg {
  width: 16px;
  height: 16px;
}

.detail-icon-btn:hover {
  background: var(--surface-hover);
  border-color: var(--border-strong);
  color: var(--text);
}

.detail-icon-btn.active {
  color: var(--accent);
  background: var(--accent-soft);
  border-color: var(--accent-border);
}

.detail-icon-btn.danger {
  color: var(--danger);
}

.detail-icon-btn.danger:hover {
  border-color: rgba(239, 68, 68, 0.45);
  background: var(--danger-soft);
}

.read-receipt-banner {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 10px 14px;
  border-radius: var(--radius-sm);
  background: var(--accent-soft);
  border: 1px solid var(--accent-border);
  font-size: 13px;
}

.thread-item {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 12px;
  overflow: hidden;
  box-shadow: var(--shadow-sm);
}

.thread-item-head {
  padding: 15px 18px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  background: var(--surface-2);
  border-bottom: 1px solid var(--border);
}

.sender-block {
  display: flex;
  align-items: center;
  gap: 12px;
  min-width: 0;
}

.avatar-circle {
  width: 38px;
  height: 38px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  font-family: var(--font-display);
  font-weight: 600;
  color: #FFFFFF;
  flex-shrink: 0;
  overflow: hidden;
}

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

.sender-name-line {
  font-weight: 600;
  font-size: 14px;
  display: flex;
  align-items: center;
  gap: 6px;
  flex-wrap: wrap;
}

.sender-addr {
  font-family: var(--font-mono);
  font-size: 12px;
  color: var(--text-muted);
  font-weight: 400;
}

.rcpt-line {
  font-size: 12px;
  color: var(--text-dim);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.thread-date {
  font-family: var(--font-mono);
  font-size: 12px;
  color: var(--text-dim);
  flex-shrink: 0;
}

.thread-attachments-wrap {
  padding: 12px 18px 14px;
  background: var(--surface-2);
  border-bottom: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.thread-attachments-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  flex-wrap: wrap;
}

.thread-attachments-count {
  font-size: 12px;
  font-weight: 600;
  color: var(--text-muted);
}

.thread-attachments-actions {
  display: flex;
  align-items: center;
  gap: 6px;
  flex-wrap: wrap;
}

.att-zip-btn {
  text-decoration: none;
}

.att-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(230px, 1fr));
  gap: 8px;
}

.att-inline-tray {
  padding-top: 6px;
  border-top: 1px dashed var(--border);
}

.att-card {
  display: flex;
  align-items: stretch;
  min-width: 0;
  border-radius: var(--radius-sm);
  background: var(--surface);
  border: 1px solid var(--border);
  overflow: hidden;
  transition: border-color 0.14s var(--ease), background-color 0.14s var(--ease), transform 0.14s var(--ease);
}

.att-card:hover {
  border-color: var(--border-strong);
  background: var(--surface-hover);
}

.att-card-main {
  flex: 1 1 auto;
  min-width: 0;
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 8px 10px;
  background: transparent;
  border: none;
  color: inherit;
  text-align: left;
  cursor: pointer;
}

.att-thumb {
  width: 34px;
  height: 34px;
  border-radius: 5px;
  object-fit: cover;
  flex-shrink: 0;
  border: 1px solid var(--border);
  background: var(--surface-elev);
}

.att-badge {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 36px;
  height: 34px;
  padding: 0 6px;
  border-radius: 5px;
  font-family: var(--font-mono);
  font-size: 10.5px;
  font-weight: 700;
  letter-spacing: 0.02em;
  flex-shrink: 0;
  background: var(--surface-elev);
  color: var(--text-muted);
  border: 1px solid var(--border);
}

.att-badge-lg {
  min-width: 52px;
  height: 46px;
  font-size: 13px;
  border-radius: 8px;
}

.att-cat-pdf {
  background: var(--danger-soft);
  color: var(--danger);
  border-color: color-mix(in srgb, var(--danger) 28%, transparent);
}

.att-cat-image {
  background: var(--success-soft);
  color: var(--success);
  border-color: color-mix(in srgb, var(--success) 28%, transparent);
}

.att-cat-audio {
  background: var(--warning-soft);
  color: var(--warning);
  border-color: color-mix(in srgb, var(--warning) 28%, transparent);
}

.att-cat-video {
  background: rgba(197, 138, 249, 0.14);
  color: #C58AF9;
  border-color: rgba(197, 138, 249, 0.28);
}

.att-cat-doc,
.att-cat-mail {
  background: var(--accent-soft);
  color: var(--accent);
  border-color: var(--accent-border);
}

.att-cat-data,
.att-cat-archive {
  background: rgba(120, 217, 236, 0.14);
  color: #78D9EC;
  border-color: rgba(120, 217, 236, 0.28);
}

html[data-theme="light"] .att-cat-pdf { color: #D93025; }
html[data-theme="light"] .att-cat-image { color: #1E8E3E; }
html[data-theme="light"] .att-cat-audio { color: #E37400; }
html[data-theme="light"] .att-cat-video { color: #9334E6; }
html[data-theme="light"] .att-cat-doc,
html[data-theme="light"] .att-cat-mail { color: #1A73E8; }
html[data-theme="light"] .att-cat-data,
html[data-theme="light"] .att-cat-archive { color: #00897B; }

.att-card-info {
  flex: 1 1 auto;
  min-width: 0;
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.att-name {
  font-size: 12.5px;
  font-weight: 500;
  color: var(--text);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.att-size {
  font-family: var(--font-mono);
  font-size: 11px;
  color: var(--text-dim);
  white-space: nowrap;
}

.att-dl-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 34px;
  flex-shrink: 0;
  border-left: 1px solid var(--border);
  color: var(--text-muted);
  text-decoration: none;
  transition: background-color 0.14s var(--ease), color 0.14s var(--ease);
}

.att-dl-btn:hover {
  background: var(--accent-soft);
  color: var(--accent);
}

.att-dl-btn svg {
  width: 16px;
  height: 16px;
  fill: currentColor;
}

.compose-att-chip {
  padding-right: 4px;
}

.compose-att-preview-btn {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  background: transparent;
  border: none;
  color: inherit;
  font: inherit;
  padding: 0;
  cursor: pointer;
}

.compose-att-preview-btn:hover {
  color: var(--accent);
}

.compose-att-ext {
  padding: 1px 5px;
  border-radius: 4px;
  font-family: var(--font-mono);
  font-size: 10px;
  font-weight: 700;
  border: 1px solid var(--border);
}

.compose-att-dl-btn {
  background: transparent;
  border: none;
  color: var(--text-muted);
  cursor: pointer;
  padding: 0 4px;
  font-size: 13px;
  line-height: 1;
}

.compose-att-dl-btn:hover {
  color: var(--accent);
}

.email-iframe {
  width: 100%;
  border: none;
  display: block;
  min-height: 64px;
  background: var(--surface);
  color-scheme: dark;
}

html[data-theme="light"] .email-iframe {
  color-scheme: light;
}

.quick-reply-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 14px 16px;
  display: flex;
  flex-direction: column;
  gap: 10px;
  box-shadow: var(--shadow-sm);
}

.quick-reply-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
}

.quick-reply-to {
  font-family: var(--font-mono);
  font-size: 12px;
  color: var(--text-muted);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.quick-reply-card textarea {
  width: 100%;
  min-height: 88px;
  resize: vertical;
}

.quick-reply-actions {
  display: flex;
  justify-content: flex-end;
  align-items: center;
}

/* Module Views */
.module-view {
  flex: 1;
  min-width: 0;
  overflow-x: hidden;
  overflow-y: auto;
  padding: 26px 32px 44px;
}

.module-container {
  width: 100%;
  max-width: 1120px;
  min-width: 0;
  margin: 0 auto;
  display: flex;
  flex-direction: column;
  gap: 20px;
}

#settingsTabBody,
#adminTabBody {
  min-width: 0;
  max-width: 100%;
}

.module-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 14px;
  flex-wrap: wrap;
}

.module-header .badge {
  max-width: 100%;
  overflow: hidden;
  text-overflow: ellipsis;
}

.module-header h2 {
  margin: 0;
  font-family: var(--font-display);
  font-size: 22px;
  font-weight: 600;
  letter-spacing: -0.02em;
}

.module-actions {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
}

.card {
  min-width: 0;
  max-width: 100%;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 20px 22px;
  box-shadow: var(--shadow-sm);
}

.card-title {
  margin: 0 0 16px;
  font-family: var(--font-display);
  font-size: 15.5px;
  font-weight: 600;
  letter-spacing: -0.01em;
}

.card-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  flex-wrap: wrap;
  margin-bottom: 16px;
}

.card-head .card-title {
  margin: 0;
}

.kpi-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(min(100%, 150px), 1fr));
  gap: 12px;
}

.nowrap {
  white-space: nowrap;
}

.kpi-card {
  min-width: 0;
  max-width: 100%;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 11px;
  padding: 15px 17px;
  display: flex;
  flex-direction: column;
  gap: 5px;
  box-shadow: var(--shadow-sm);
}

.kpi-label {
  font-size: 11.5px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: var(--text-dim);
}

.kpi-value {
  font-family: var(--font-display);
  font-size: 22px;
  font-weight: 600;
  letter-spacing: -0.02em;
  color: var(--text);
}

.form-actions {
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: 8px;
  flex-wrap: wrap;
  margin-top: 4px;
}

.toolbar-inline {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
}

.table-scroll {
  width: 100%;
  max-width: 100%;
  min-width: 0;
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
}

.table-actions {
  display: inline-flex;
  align-items: center;
  justify-content: flex-end;
  gap: 6px;
  flex-wrap: nowrap;
}

.badge {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  height: 22px;
  padding: 0 9px;
  border-radius: 999px;
  font-size: 11.5px;
  font-weight: 500;
  background: var(--surface-elev);
  border: 1px solid var(--border);
  color: var(--text-muted);
  white-space: nowrap;
}

.badge-ok {
  background: rgba(16, 185, 129, 0.14);
  border-color: rgba(16, 185, 129, 0.32);
  color: var(--success);
}

.badge-warn {
  background: rgba(245, 158, 11, 0.14);
  border-color: rgba(245, 158, 11, 0.32);
  color: var(--warning);
}

.badge-accent {
  background: var(--accent-soft);
  border-color: var(--accent-border);
  color: var(--accent);
}

.badge-err {
  background: var(--danger-soft);
  border-color: rgba(239, 68, 68, 0.32);
  color: var(--danger);
}

.list-row-item {
  border-top: 1px solid var(--border);
  padding: 11px 0;
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 12px;
  min-width: 0;
  max-width: 100%;
}

.module-section-stack {
  display: flex;
  flex-direction: column;
  gap: 18px;
  min-width: 0;
  max-width: 100%;
}

.settings-quota-row {
  display: flex;
  align-items: center;
  gap: 12px;
}

.settings-quota-row .quota-bar {
  flex: 1;
  margin-bottom: 0;
}

.grid-2 {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(min(100%, 320px), 1fr));
  gap: 18px;
}

.form-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(min(100%, 210px), 1fr));
  gap: 12px;
}

.data-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 13.5px;
}

.data-table th {
  text-align: left;
  padding: 9px 12px;
  font-size: 11px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: var(--text-dim);
  background: var(--surface-2);
  border-bottom: 1px solid var(--border);
}

.data-table td {
  padding: 11px 12px;
  border-bottom: 1px solid var(--border-subtle);
  vertical-align: middle;
}

.data-table tbody tr:hover td {
  background: var(--surface-hover);
}

.empty-cell {
  text-align: center;
  color: var(--text-dim);
  padding: 26px 12px !important;
}

.contact-cell-name {
  display: flex;
  align-items: center;
  gap: 10px;
}

.avatar-sm {
  width: 28px;
  height: 28px;
  border-radius: 50%;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  font-family: var(--font-display);
  font-size: 11.5px;
  font-weight: 600;
  color: #FFFFFF;
  flex-shrink: 0;
  overflow: hidden;
}

.profile-avatar-editor {
  display: flex;
  align-items: center;
  gap: 14px;
  padding: 12px 14px;
  border-radius: var(--radius-sm);
  background: var(--surface-2);
  border: 1px solid var(--border);
  margin-bottom: 12px;
}

.profile-avatar-preview {
  width: 72px;
  height: 72px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  font-family: var(--font-display);
  font-size: 26px;
  font-weight: 600;
  color: #FFFFFF;
  flex-shrink: 0;
  overflow: hidden;
  border: 2px solid var(--border-strong);
}

.profile-avatar-actions {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
}

.external-sync-box {
  margin-top: 16px;
  padding-top: 14px;
  border-top: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.external-sync-badges {
  display: flex;
  align-items: center;
  gap: 6px;
  flex-wrap: wrap;
}

.external-sync-url-row {
  display: flex;
  align-items: center;
  gap: 8px;
}

.external-sync-url-row input {
  flex: 1;
  min-width: 0;
}

.avatar-cropper-wrap {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 14px;
}

.avatar-cropper-canvas {
  width: 256px;
  height: 256px;
  border-radius: var(--radius);
  border: 1px solid var(--border-strong);
  background: var(--surface-2);
  cursor: grab;
  touch-action: none;
}

.avatar-cropper-canvas:active {
  cursor: grabbing;
}

.avatar-cropper-controls {
  width: 100%;
  max-width: 280px;
  display: flex;
  align-items: center;
  gap: 10px;
}

.avatar-cropper-controls input[type="range"] {
  flex: 1;
}

.shortcut-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(min(100%, 190px), 1fr));
  gap: 10px;
}

.shortcut-item {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 9px 12px;
  border-radius: var(--radius-sm);
  background: var(--surface-2);
  border: 1px solid var(--border);
  font-size: 13px;
  color: var(--text-muted);
}

.kbd-key {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 28px;
  height: 24px;
  padding: 0 7px;
  border-radius: 5px;
  background: var(--surface-elev);
  border: 1px solid var(--border-strong);
  font-family: var(--font-mono);
  font-size: 11.5px;
  font-weight: 600;
  color: var(--text);
}

.mono {
  font-family: var(--font-mono);
  font-size: 12.5px;
}

.status-ok {
  color: var(--success);
  font-weight: 500;
}

.status-err {
  color: var(--danger);
  font-weight: 500;
}

.status-warn {
  color: var(--warning);
  font-weight: 500;
}

/* Composer Modal */
.modal-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(5, 7, 11, 0.72);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 20px;
  z-index: 50;
}

.composer-card {
  width: 100%;
  max-width: 840px;
  max-height: 92vh;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 18px;
  display: flex;
  flex-direction: column;
  overflow: hidden;
  box-shadow: var(--shadow-lg);
}

.generic-modal-card {
  width: 100%;
  max-width: 640px;
  max-height: 90vh;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 18px;
  display: flex;
  flex-direction: column;
  overflow: hidden;
  box-shadow: var(--shadow-lg);
}

.generic-modal-body {
  padding: 20px 22px;
  overflow-y: auto;
}

/* Attachment Lightbox / Preview Modal */
#attachmentPreviewModal {
  z-index: 65;
  padding: 18px;
}

.att-preview-modal-card {
  width: 100%;
  max-width: 1180px;
  height: 88vh;
  max-height: 92vh;
  background: var(--surface);
  border: 1px solid var(--border-strong);
  border-radius: 14px;
  display: flex;
  flex-direction: column;
  overflow: hidden;
  box-shadow: var(--shadow-lg);
}

.att-preview-modal-card.att-preview-fullscreen {
  max-width: 100vw;
  width: 100vw;
  height: 100vh;
  max-height: 100vh;
  border-radius: 0;
  border: none;
}

.att-preview-header {
  padding: 11px 16px;
  background: var(--surface-2);
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  flex-wrap: wrap;
}

.att-preview-title-group {
  display: flex;
  align-items: center;
  gap: 10px;
  min-width: 0;
  flex: 1 1 220px;
}

.att-preview-ext-badge {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  padding: 4px 8px;
  border-radius: 6px;
  font-family: var(--font-mono);
  font-size: 11px;
  font-weight: 700;
  flex-shrink: 0;
  border: 1px solid var(--border);
}

.att-preview-title-meta {
  min-width: 0;
  display: flex;
  flex-direction: column;
  gap: 1px;
}

.att-preview-title-meta h3 {
  margin: 0;
  font-family: var(--font-display);
  font-size: 14.5px;
  font-weight: 600;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.att-preview-meta {
  font-family: var(--font-mono);
  font-size: 11px;
  color: var(--text-dim);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.att-preview-toolbar {
  display: flex;
  align-items: center;
  gap: 6px;
  flex-wrap: wrap;
}

.att-preview-nav,
.att-preview-zoom,
.att-preview-view-tabs {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  padding-right: 6px;
  border-right: 1px solid var(--border);
}

.att-preview-counter,
.att-preview-zoom-val {
  font-family: var(--font-mono);
  font-size: 11.5px;
  color: var(--text-muted);
  min-width: 44px;
  text-align: center;
}

.att-preview-view-tabs .btn-xs.active {
  background: var(--accent-soft);
  color: var(--accent);
  border-color: var(--accent-border);
}

.att-preview-stage {
  flex: 1 1 auto;
  min-height: 0;
  overflow: auto;
  background: var(--bg);
  display: flex;
  flex-direction: column;
}

.att-preview-media-wrap {
  flex: 1 1 auto;
  min-height: 100%;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 20px;
  overflow: auto;
}

.att-preview-img {
  max-width: 100%;
  max-height: 100%;
  object-fit: contain;
  border-radius: 6px;
  transition: transform 0.16s var(--ease);
  transform-origin: center center;
  cursor: zoom-in;
}

.att-preview-img.is-zoomed {
  cursor: zoom-out;
}

.att-preview-pdf-frame {
  width: 100%;
  flex: 1 1 auto;
  height: 100%;
  min-height: 70vh;
  border: none;
  background: #FFFFFF;
}

.att-preview-doc-frame-wrap {
  flex: 1 1 auto;
  padding: 16px;
  display: flex;
  flex-direction: column;
}

.att-preview-html-frame {
  width: 100%;
  flex: 1 1 auto;
  min-height: 62vh;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--surface);
}

.att-preview-audio-card {
  margin: auto;
  padding: 28px 32px;
  width: 100%;
  max-width: 480px;
  background: var(--surface);
  border: 1px solid var(--border-strong);
  border-radius: 12px;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 14px;
  text-align: center;
}

.att-preview-audio-name {
  font-size: 14px;
  font-weight: 600;
  word-break: break-word;
}

.att-preview-audio {
  width: 100%;
}

.att-preview-video {
  max-width: 100%;
  max-height: 100%;
  border-radius: 8px;
  background: #000000;
}

.att-preview-code-wrap {
  padding: 16px 20px;
  flex: 1 1 auto;
  overflow: auto;
}

.att-preview-code {
  margin: 0;
  padding: 16px 18px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  font-family: var(--font-mono);
  font-size: 12.5px;
  line-height: 1.55;
  white-space: pre-wrap;
  word-break: break-word;
  color: var(--text);
}

.att-preview-doc {
  margin: 18px auto;
  padding: 28px 34px;
  width: min(820px, calc(100% - 32px));
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  line-height: 1.65;
  font-size: 14.5px;
}

.att-preview-doc p {
  margin: 0 0 12px;
}

.att-preview-doc p:last-child {
  margin-bottom: 0;
}

.att-csv-wrap {
  padding: 16px;
  flex: 1 1 auto;
  overflow: auto;
}

.att-csv-table {
  width: 100%;
  border-collapse: collapse;
  background: var(--surface);
  border: 1px solid var(--border);
  font-size: 12.5px;
}

.att-csv-table th,
.att-csv-table td {
  padding: 8px 11px;
  border: 1px solid var(--border);
  text-align: left;
  vertical-align: top;
  max-width: 320px;
  word-break: break-word;
}

.att-csv-table thead th {
  position: sticky;
  top: 0;
  background: var(--surface-elev);
  font-weight: 600;
  z-index: 2;
}

.att-ics-list {
  padding: 18px;
  display: flex;
  flex-direction: column;
  gap: 12px;
  max-width: 780px;
  width: 100%;
  margin: 0 auto;
}

.att-ics-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 18px 20px;
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.att-ics-title {
  margin: 0;
  font-family: var(--font-display);
  font-size: 16px;
}

.att-ics-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
  gap: 10px;
}

.att-ics-grid > div {
  display: flex;
  flex-direction: column;
  gap: 2px;
  font-size: 12.5px;
}

.att-ics-grid span {
  font-size: 11px;
  color: var(--text-dim);
}

.att-ics-attendees {
  font-size: 12.5px;
  color: var(--text-muted);
}

.att-ics-attendees span {
  color: var(--text-dim);
}

.att-ics-desc {
  margin: 0;
  padding: 12px;
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  font-family: var(--font-sans);
  font-size: 13px;
  white-space: pre-wrap;
}

.att-archive-wrap {
  padding: 18px;
  display: flex;
  flex-direction: column;
  gap: 14px;
  max-width: 920px;
  width: 100%;
  margin: 0 auto;
}

.att-archive-list {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  overflow: hidden;
}

.att-archive-row {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 9px 14px;
  border-bottom: 1px solid var(--border);
  font-size: 13px;
}

.att-archive-row:last-child {
  border-bottom: none;
}

.att-archive-row.is-dir {
  color: var(--text-muted);
  background: var(--surface-2);
}

.att-archive-name {
  flex: 1 1 auto;
  min-width: 0;
  font-family: var(--font-mono);
  font-size: 12.5px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.att-archive-size {
  font-family: var(--font-mono);
  font-size: 11.5px;
  color: var(--text-dim);
  flex-shrink: 0;
}

.att-archive-locked {
  font-size: 11.5px;
  color: var(--warning);
}

.att-archive-text-wrap {
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.att-archive-text-head {
  font-family: var(--font-mono);
  font-size: 12px;
  color: var(--text-muted);
}

.att-preview-eml-wrap {
  padding: 16px;
  display: flex;
  flex-direction: column;
  gap: 12px;
  flex: 1 1 auto;
}

.att-preview-eml-head {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 14px 16px;
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.att-preview-eml-head h4 {
  margin: 0;
  font-size: 15px;
}

.att-preview-eml-meta {
  display: flex;
  flex-direction: column;
  gap: 3px;
  font-size: 12.5px;
  color: var(--text-muted);
}

.att-preview-eml-meta span {
  color: var(--text-dim);
  margin-right: 4px;
}

.att-preview-eml-atts {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
}

.att-preview-fallback,
.att-preview-loading,
.att-preview-empty {
  margin: auto;
  padding: 32px 24px;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 10px;
  text-align: center;
  color: var(--text-muted);
}

.att-preview-fallback h4 {
  margin: 4px 0 0;
  color: var(--text);
  word-break: break-word;
}

.att-preview-fallback-msg {
  margin: 0 0 6px;
  font-size: 13px;
}

.composer-header {
  padding: 13px 18px;
  background: var(--surface-2);
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.composer-header h3 {
  margin: 0;
  font-family: var(--font-display);
  font-size: 15.5px;
  font-weight: 600;
}

.composer-header-actions {
  display: flex;
  align-items: center;
  gap: 8px;
}

.composer-body {
  display: flex;
  flex-direction: column;
  flex: 1;
  min-height: 0;
  overflow-y: auto;
}

.composer-row {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 7px 18px;
  border-bottom: 1px solid var(--border);
}

.composer-row label {
  width: 64px;
  flex-shrink: 0;
  font-size: 12.5px;
  color: var(--text-dim);
}

.composer-row input,
.composer-row select {
  flex: 1;
  height: 32px;
  background-color: transparent;
  border: none;
  padding: 0 4px;
}

.composer-row select {
  padding-right: 28px;
}

.chip-input-wrap {
  flex: 1;
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 5px;
  position: relative;
}

.chip-input-wrap input {
  min-width: 160px;
  flex: 1;
}

.addr-chip {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 2px 8px;
  border-radius: 999px;
  background: var(--surface-elev);
  border: 1px solid var(--border-strong);
  font-size: 12.5px;
}

.addr-chip button {
  color: var(--text-dim);
  font-size: 14px;
  line-height: 1;
}

.autocomplete-dropdown {
  position: absolute;
  top: 100%;
  left: 0;
  min-width: 280px;
  max-height: 220px;
  overflow-y: auto;
  background: var(--surface-elev);
  border: 1px solid var(--border-strong);
  border-radius: var(--radius-sm);
  box-shadow: var(--shadow-lg);
  z-index: 60;
}

.autocomplete-item {
  width: 100%;
  padding: 8px 12px;
  text-align: left;
  display: flex;
  justify-content: space-between;
  gap: 8px;
  font-size: 13px;
}

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

.editor-toolbar {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
  padding: 8px 16px;
  background: var(--surface-elev);
  border-bottom: 1px solid var(--border);
}

.toolbar-group {
  display: inline-flex;
  align-items: center;
  gap: 3px;
  flex-shrink: 0;
}

.toolbar-group-right {
  margin-left: auto;
  gap: 6px;
}

.editor-toolbar button {
  width: 28px;
  height: 28px;
  padding: 0;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  border-radius: 5px;
  font-size: 13px;
  color: var(--text-muted);
  transition: background-color 0.14s var(--ease), color 0.14s var(--ease);
}

.editor-toolbar button svg {
  width: 16px;
  height: 16px;
}

.editor-toolbar button:hover {
  background: var(--surface-hover);
  color: var(--text);
}

.editor-toolbar select {
  height: 28px;
  font-size: 12px;
  padding: 0 26px 0 8px;
  background-color: var(--surface);
}

.toolbar-sep {
  width: 1px;
  height: 16px;
  background: var(--border);
  margin: 0 2px;
}

.compose-editor {
  min-height: 240px;
  max-height: 360px;
  overflow-y: auto;
  padding: 15px 18px;
  outline: none;
  font-size: 14px;
  line-height: 1.6;
}

.compose-editor blockquote {
  border-left: 2px solid var(--border-strong);
  margin: 8px 0;
  padding-left: 12px;
  color: var(--text-muted);
}

.compose-editor a {
  color: var(--accent);
}

.compose-editor pre,
.compose-editor code {
  background: var(--surface-2);
  color: var(--text);
  border-radius: 6px;
  font-family: var(--font-mono);
}

.compose-editor hr {
  border: none;
  border-top: 1px solid var(--border);
  margin: 12px 0;
}

.compose-attachments-zone {
  padding: 9px 18px;
  border-top: 1px solid var(--border);
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  flex-wrap: wrap;
}

.compose-attachments-zone.drag-over {
  background: var(--accent-soft);
}

.attachment-chips {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  flex: 1;
}

.composer-footer {
  padding: 11px 18px;
  border-top: 1px solid var(--border);
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  flex-wrap: wrap;
  background: var(--surface-elev);
}

.composer-options {
  display: flex;
  align-items: center;
  gap: 10px;
  flex-wrap: wrap;
}

#attachFileBtn svg {
  width: 14px;
  height: 14px;
}

.toggle-inline {
  display: inline-flex;
  align-items: center;
  gap: 7px;
  font-size: 12.5px;
  color: var(--text-muted);
}

.toggle-inline input[type="datetime-local"] {
  padding: 4px 8px;
  font-size: 12px;
}

/* Toast */
.toast-stack {
  position: fixed;
  bottom: 18px;
  right: 18px;
  display: flex;
  flex-direction: column;
  gap: 8px;
  z-index: 100;
}

.toast {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 10px 14px;
  border-radius: var(--radius-sm);
  background: var(--surface-elev);
  border: 1px solid var(--border-strong);
  box-shadow: var(--shadow-sm);
  font-size: 13px;
  color: var(--text);
}

.toast-action-btn {
  padding: 3px 9px;
  border-radius: 5px;
  font-size: 12px;
  font-weight: 600;
  color: var(--accent);
  background: var(--accent-soft);
  border: 1px solid var(--accent-border);
  white-space: nowrap;
  transition: background-color 0.12s var(--ease), color 0.12s var(--ease);
}

.toast-action-btn:hover {
  background: var(--accent);
  color: var(--on-accent);
}

.toast.error {
  border-color: color-mix(in srgb, var(--danger) 50%, transparent);
  color: var(--danger);
}

.toast.success {
  border-color: color-mix(in srgb, var(--success) 45%, transparent);
}

.tabs-bar {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  flex-wrap: wrap;
  padding: 4px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  align-self: flex-start;
}

.tab-btn {
  height: 32px;
  padding: 0 13px;
  display: inline-flex;
  align-items: center;
  gap: 6px;
  border-radius: 6px;
  font-size: 13px;
  font-weight: 500;
  line-height: 1;
  white-space: nowrap;
  border: 1px solid transparent;
  color: var(--text-muted);
  transition: background-color 0.15s var(--ease), color 0.15s var(--ease), border-color 0.15s var(--ease);
}

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

.tab-btn.active {
  background: var(--accent-soft);
  border-color: var(--accent-border);
  color: var(--accent);
  font-weight: 600;
}

.nav-custom-row {
  position: relative;
  display: flex;
  align-items: center;
}

.nav-custom-row .nav-item {
  flex: 1;
  min-width: 0;
}

.nav-row-actions {
  display: none;
  align-items: center;
  gap: 2px;
  position: absolute;
  right: 6px;
  background: var(--surface-hover);
  border-radius: 4px;
  padding: 1px 2px;
}

.nav-custom-row:hover .nav-row-actions {
  display: inline-flex;
}

.nav-badge-muted {
  background: var(--surface-elev);
  color: var(--text-muted);
  border: 1px solid var(--border);
}

.copyable-addr {
  cursor: pointer;
  border-radius: 4px;
  padding: 1px 4px;
  transition: background-color 0.14s var(--ease), color 0.14s var(--ease);
}

.copyable-addr:hover {
  background: var(--surface-hover);
  color: var(--text);
}

.quick-contact-btn {
  height: 22px;
  padding: 0 8px;
  font-size: 11px;
}

.detail-labels-row {
  display: flex;
  align-items: center;
  gap: 6px;
  flex-wrap: wrap;
}

.rule-action-badges {
  display: flex;
  align-items: center;
  gap: 5px;
  flex-wrap: wrap;
}

.modal-backdrop.composer-minimized {
  inset: auto;
  right: 20px;
  bottom: 0;
  width: 360px;
  max-width: calc(100vw - 24px);
  padding: 0;
  background: transparent;
  pointer-events: auto;
}

.modal-backdrop.composer-minimized .composer-card {
  width: 100%;
  border-bottom-left-radius: 0;
  border-bottom-right-radius: 0;
  border-bottom: none;
}

.modal-backdrop.composer-minimized .composer-header {
  cursor: pointer;
}

.modal-backdrop.composer-minimized .composer-body {
  display: none;
}

.pin-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  color: var(--text-dim);
  width: 18px;
  height: 18px;
  padding: 0;
  border-radius: 4px;
  opacity: 0.45;
  transition: color 0.12s var(--ease), opacity 0.12s var(--ease), transform 0.12s var(--ease);
}

.msg-row:hover .pin-btn,
.pin-btn.pinned {
  opacity: 1;
}

.pin-btn:hover,
.pin-btn.pinned {
  color: var(--accent);
}

.msg-row.pinned {
  background: var(--accent-soft);
}

.snooze-pill {
  color: var(--accent);
  background: var(--accent-soft);
  border-color: var(--accent-border);
}

.unsubscribe-btn {
  border-color: var(--accent-border);
  color: var(--accent);
}

.sidebar-backdrop,
.mobile-bottom-nav,
.mobile-compose-fab {
  display: none;
}

@media (hover: none) {
  .nav-custom-row .nav-row-actions {
    display: inline-flex;
    position: static;
    background: transparent;
  }
  .pin-btn {
    opacity: 0.8;
  }
}

@media (max-width: 1024px) {
  .mail-list-col {
    width: 330px;
  }
}

@media (max-width: 820px) {
  .mobile-only {
    display: inline-flex;
  }

  /* Prevent iOS Safari zoom on input focus */
  input:where(:not([type="checkbox"]):not([type="radio"]):not([type="color"]):not([type="file"])),
  select,
  textarea {
    font-size: 16px;
  }

  .topbar {
    gap: 8px;
    padding: 0 10px;
    padding-top: env(safe-area-inset-top, 0px);
    height: calc(56px + env(safe-area-inset-top, 0px));
  }
  .topbar-left {
    min-width: auto;
    gap: 6px;
  }
  .topbar-search {
    min-width: 0;
  }
  .topbar-search input {
    height: 36px;
    font-size: 15px;
    padding: 0 38px 0 32px;
  }
  .topbar-search .search-icon {
    left: 10px;
  }
  .search-filter-btn {
    width: 28px;
    padding: 0;
  }
  .search-filter-btn span,
  .topbar-btn-label,
  .detail-btn-text,
  .search-kbd,
  .topbar-sep {
    display: none;
  }
  .topbar-action-btn {
    width: 34px;
    padding: 0;
  }
  .detail-icon-btn {
    width: 32px;
    height: 32px;
    padding: 0;
  }
  .search-clear {
    right: 36px;
  }
  .topbar-right {
    gap: 4px;
  }
  .user-pill {
    padding: 3px;
    height: 32px;
  }
  .user-email {
    display: none;
  }

  .sidebar-backdrop {
    display: block;
    position: fixed;
    inset: 0;
    top: calc(56px + env(safe-area-inset-top, 0px));
    background: rgba(32, 33, 36, 0.52);
    z-index: 39;
  }
  .sidebar {
    position: fixed;
    top: calc(56px + env(safe-area-inset-top, 0px));
    left: 0;
    bottom: 0;
    width: min(280px, 84vw);
    z-index: 40;
    transform: translateX(-100%);
    transition: transform 0.22s var(--ease);
    box-shadow: var(--shadow-lg);
    padding-bottom: env(safe-area-inset-bottom, 0px);
  }
  .sidebar.open {
    transform: translateX(0);
  }

  .mail-list-col {
    width: 100%;
    border-right: none;
  }
  .mail-read-col {
    display: none;
  }
  .mail-workspace.reading-mobile .mail-list-col {
    display: none;
  }
  .mail-workspace.reading-mobile .mail-read-col {
    display: flex;
  }

  .list-toolbar {
    padding: 12px 12px 10px;
    gap: 8px;
  }
  .filter-chips {
    overflow-x: auto;
    flex-wrap: nowrap;
    -webkit-overflow-scrolling: touch;
    scrollbar-width: none;
  }
  .filter-chips::-webkit-scrollbar {
    display: none;
  }
  .chip {
    flex: 0 0 auto;
    padding: 0 12px;
  }
  .bulk-bar {
    gap: 6px;
  }
  .bulk-actions {
    width: auto;
    overflow: visible;
    flex-wrap: nowrap;
  }

  .message-list {
    padding-bottom: 76px;
    -webkit-overflow-scrolling: touch;
  }
  .msg-row {
    padding: 12px;
    gap: 10px;
  }
  .msg-row-checks {
    gap: 10px;
  }
  .star-btn {
    padding: 4px;
    margin: -4px;
    font-size: 16px;
  }

  .message-detail-pane {
    padding: 14px 12px 28px;
    gap: 14px;
  }
  .detail-header {
    gap: 10px;
    padding-bottom: 12px;
  }
  .detail-subject {
    font-size: 16.5px;
    line-height: 1.35;
    width: 100%;
    min-width: 0;
    overflow-wrap: anywhere;
    word-break: break-word;
  }
  .sender-name-line,
  .sender-addr,
  .rcpt-line {
    min-width: 0;
    overflow-wrap: anywhere;
    word-break: break-word;
  }
  #mobileBackBtn {
    order: 0;
    height: 30px;
    padding: 0 10px;
    font-weight: 600;
  }
  .detail-actions {
    gap: 8px;
    flex-wrap: wrap;
    overflow: visible;
  }
  .detail-action-group {
    flex-wrap: wrap;
  }
  .read-receipt-banner {
    flex-wrap: wrap;
    gap: 8px;
  }
  .thread-item-head {
    padding: 12px 14px;
    flex-wrap: wrap;
    gap: 8px;
  }
  .thread-attachments-wrap {
    padding: 10px 14px 12px;
  }
  .att-grid {
    grid-template-columns: minmax(0, 1fr);
  }

  .module-view {
    padding: 16px 12px 28px;
    -webkit-overflow-scrolling: touch;
  }
  .card {
    padding: 16px 14px;
  }
  .grid-2 {
    grid-template-columns: minmax(0, 1fr);
  }
  .tabs-bar {
    display: flex;
    width: 100%;
    overflow-x: auto;
    flex-wrap: nowrap;
    -webkit-overflow-scrolling: touch;
    scrollbar-width: none;
  }
  .tabs-bar::-webkit-scrollbar {
    display: none;
  }
  .tab-btn {
    flex-shrink: 0;
  }

  /* Mobile Bottom Navigation */
  .mobile-bottom-nav {
    display: flex;
    align-items: stretch;
    justify-content: space-around;
    height: calc(58px + env(safe-area-inset-bottom, 0px));
    padding-bottom: env(safe-area-inset-bottom, 0px);
    background: var(--surface);
    border-top: 1px solid var(--border);
    z-index: 35;
    flex-shrink: 0;
  }
  .mobile-nav-btn {
    flex: 1;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 3px;
    font-size: 11px;
    font-weight: 500;
    color: var(--text-muted);
    padding: 4px 2px;
    min-width: 0;
  }
  .mobile-nav-btn svg {
    width: 20px;
    height: 20px;
  }
  .mobile-nav-btn.active {
    color: var(--accent);
    font-weight: 600;
  }
  .mobile-nav-icon-wrap {
    position: relative;
    display: inline-flex;
    align-items: center;
    justify-content: center;
  }
  .mobile-nav-badge {
    position: absolute;
    top: -5px;
    right: -10px;
    min-width: 16px;
    height: 16px;
    padding: 0 4px;
    border-radius: 999px;
    background: var(--accent);
    color: var(--on-accent);
    font-family: var(--font-mono);
    font-size: 10px;
    font-weight: 600;
    display: inline-flex;
    align-items: center;
    justify-content: center;
  }

  /* Mobile Floating Compose Button */
  .mobile-compose-fab {
    position: fixed;
    right: 16px;
    bottom: calc(72px + env(safe-area-inset-bottom, 0px));
    z-index: 34;
    height: 48px;
    padding: 0 18px;
    border-radius: 16px;
    background: var(--compose-bg);
    color: var(--compose-ink);
    font-weight: 600;
    font-size: 13.5px;
    display: inline-flex;
    align-items: center;
    gap: 8px;
    box-shadow: var(--shadow-md);
  }
  .mobile-compose-fab svg {
    width: 18px;
    height: 18px;
  }
  .app-shell.mobile-reading .mobile-compose-fab,
  .app-shell:not([data-active-view="mail"]) .mobile-compose-fab {
    display: none;
  }

  /* Full-screen Mobile Composer */
  #composerModal.modal-backdrop:not(.composer-minimized) {
    padding: 0;
    align-items: stretch;
  }
  #composerModal.modal-backdrop:not(.composer-minimized) .composer-card {
    width: 100%;
    max-width: 100%;
    height: 100vh;
    height: 100dvh;
    max-height: 100dvh;
    border-radius: 0;
    border: none;
    padding-top: env(safe-area-inset-top, 0px);
  }
  #composerModal.modal-backdrop.composer-minimized {
    right: 12px;
    left: 12px;
    bottom: calc(58px + env(safe-area-inset-bottom, 0px));
    width: auto;
    max-width: none;
  }
  .composer-row {
    padding: 7px 12px;
    gap: 8px;
    flex-wrap: wrap;
    min-width: 0;
  }
  .composer-row label {
    width: 52px;
  }
  .toggle-inline input[type="datetime-local"] {
    max-width: 100%;
    min-width: 0;
  }
  .editor-toolbar {
    flex-wrap: nowrap;
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
    padding: 8px 12px;
    scrollbar-width: none;
  }
  .toolbar-group-right {
    margin-left: 0;
  }
  .editor-toolbar::-webkit-scrollbar {
    display: none;
  }
  .editor-toolbar button,
  .editor-toolbar select {
    flex-shrink: 0;
  }
  .compose-editor {
    flex: 1;
    min-height: 160px;
    max-height: none;
    padding: 12px;
    font-size: 16px;
  }
  .compose-attachments-zone {
    padding: 9px 12px;
  }
  .composer-footer {
    padding: 10px 14px calc(10px + env(safe-area-inset-bottom, 0px));
  }
  .composer-submit {
    margin-left: auto;
  }

  /* Bottom-sheet Generic Modal */
  #genericModal.modal-backdrop {
    padding: 0;
    align-items: flex-end;
  }
  #genericModal .generic-modal-card {
    max-width: 100%;
    max-height: 90dvh;
    border-radius: 16px 16px 0 0;
    border-left: none;
    border-right: none;
    border-bottom: none;
    padding-bottom: env(safe-area-inset-bottom, 0px);
  }
  .generic-modal-body {
    padding: 16px 16px 20px;
  }
  #attachmentPreviewModal {
    padding: 0;
  }
  .att-preview-modal-card {
    max-width: 100vw;
    height: 100dvh;
    max-height: 100dvh;
    border-radius: 0;
    border: none;
  }
  .att-preview-header {
    padding: 10px 12px;
  }
  .att-preview-nav,
  .att-preview-zoom,
  .att-preview-view-tabs {
    border-right: none;
    padding-right: 0;
  }

  .toast-stack {
    left: 12px;
    right: 12px;
    bottom: calc(68px + env(safe-area-inset-bottom, 0px));
  }
}

@media (max-width: 720px) {
  .data-table:not(.kv-table) thead {
    display: none;
  }
  .data-table:not(.kv-table),
  .data-table:not(.kv-table) tbody {
    display: block;
    width: 100%;
  }
  .data-table:not(.kv-table) tbody tr {
    display: flex;
    flex-direction: column;
    gap: 7px;
    padding: 13px 0;
    border-bottom: 1px solid var(--border);
  }
  .data-table:not(.kv-table) tbody tr:first-child {
    padding-top: 2px;
  }
  .data-table:not(.kv-table) tbody tr:last-child {
    border-bottom: none;
    padding-bottom: 2px;
  }
  .data-table:not(.kv-table) tbody td {
    display: flex;
    align-items: flex-start;
    justify-content: space-between;
    gap: 12px;
    padding: 0;
    border: none;
    text-align: right;
    min-width: 0;
    overflow-wrap: anywhere;
    word-break: break-word;
  }
  .data-table:not(.kv-table) tbody td.empty-cell,
  .data-table:not(.kv-table) tbody td[colspan] {
    display: block;
    text-align: center;
    padding: 18px 8px !important;
  }
  .data-table:not(.kv-table) tbody td[data-label]::before {
    content: attr(data-label);
    font-family: var(--font-sans);
    font-size: 11px;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.04em;
    color: var(--text-dim);
    text-align: left;
    flex-shrink: 0;
    padding-top: 1px;
  }
  .data-table:not(.kv-table) tbody td:not([data-label]):not(.empty-cell):not([colspan]) {
    justify-content: flex-end;
    padding-top: 4px;
  }
  .data-table .table-actions {
    flex-wrap: wrap;
    width: 100%;
    justify-content: flex-end;
  }
  .data-table .contact-cell-name {
    flex-wrap: wrap;
    justify-content: flex-end;
    text-align: right;
  }
  .data-table .rule-action-badges {
    justify-content: flex-end;
  }

  .data-table.kv-table,
  .data-table.kv-table tbody {
    display: block;
    width: 100%;
  }
  .data-table.kv-table tbody tr {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    justify-content: space-between;
    gap: 6px 12px;
    padding: 11px 0;
    border-bottom: 1px solid var(--border-subtle);
  }
  .data-table.kv-table tbody tr:last-child {
    border-bottom: none;
    padding-bottom: 2px;
  }
  .data-table.kv-table tbody td {
    padding: 0;
    border: none;
    min-width: 0;
    overflow-wrap: anywhere;
    word-break: break-word;
  }
  .data-table.kv-table tbody td:first-child {
    width: 100%;
    font-size: 11.5px;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.04em;
    color: var(--text-dim);
  }
  .data-table.kv-table tbody td:nth-child(2) {
    flex: 1 1 200px;
    min-width: 0;
  }
  .data-table.kv-table tbody td:nth-child(3) {
    flex: 0 0 auto;
    margin-left: auto;
  }
}

@media (max-width: 540px) {
  .auth-card {
    padding: 24px 18px;
  }
  .form-grid {
    grid-template-columns: minmax(0, 1fr);
  }
  .kpi-grid {
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 8px;
  }
  .kpi-card {
    padding: 12px;
  }
  .kpi-value {
    font-size: 18px;
  }
  .module-header {
    gap: 10px;
  }
  .module-actions,
  .toolbar-inline {
    width: 100%;
  }
  .module-actions > input,
  .module-actions > select,
  .module-actions > .input-addon-wrap,
  .toolbar-inline > input,
  .toolbar-inline > select,
  .toolbar-inline > .input-addon-wrap {
    width: 100% !important;
    min-width: 0 !important;
    flex: 1 1 100%;
  }
  .thread-date {
    width: 100%;
    padding-left: 50px;
    font-size: 11px;
  }
  .list-row-item {
    flex-wrap: wrap;
    gap: 8px;
  }
}

@media (max-width: 480px) {
  .brand-name {
    display: none;
  }
}

/* Active Topbar Controls & Popovers */
.icon-btn.active {
  color: var(--accent);
  background: var(--accent-soft);
  border-color: var(--accent-border);
}

.adv-search-panel {
  position: absolute;
  top: calc(100% + 8px);
  left: 0;
  right: 0;
  min-width: 340px;
  padding: 16px;
  background: var(--surface);
  border: 1px solid var(--border-strong);
  border-radius: var(--radius);
  box-shadow: var(--shadow-lg);
  z-index: 60;
}

@media (max-width: 720px) {
  .adv-search-panel {
    position: fixed;
    top: 62px;
    left: 12px;
    right: 12px;
    min-width: 0;
    max-height: calc(100vh - 80px);
    overflow-y: auto;
  }
}

/* Mail Layout Modes (Desktop) */
@media (min-width: 821px) {
  .mail-workspace[data-mail-layout="bottom"] {
    flex-direction: column;
  }
  .mail-workspace[data-mail-layout="bottom"] .mail-list-col {
    width: 100%;
    height: 44%;
    min-height: 210px;
    max-height: 55%;
    border-right: none;
    border-bottom: 1px solid var(--border);
  }
  .mail-workspace[data-mail-layout="bottom"] .mail-read-col {
    flex: 1;
    min-height: 0;
    width: 100%;
  }

  .mail-workspace[data-mail-layout="list"] .mail-list-col {
    width: 100%;
    flex: 1;
    border-right: none;
  }
  .mail-workspace[data-mail-layout="list"] .mail-read-col {
    display: none;
  }
  .mail-workspace[data-mail-layout="list"].reading-list-open .mail-list-col {
    display: none;
  }
  .mail-workspace[data-mail-layout="list"].reading-list-open .mail-read-col {
    display: flex;
    width: 100%;
    flex: 1;
  }
  .mail-workspace[data-mail-layout="list"] .list-mode-back-btn {
    display: inline-flex;
  }
}

.list-mode-back-btn {
  display: none;
  align-items: center;
  gap: 5px;
  font-weight: 600;
  color: var(--accent);
  border-color: var(--accent-border);
  background: var(--accent-soft);
}

/* Compact Density Mode */
.mail-workspace[data-mail-density="compact"] .msg-row {
  padding: 7px 14px;
  gap: 9px;
}

.mail-workspace[data-mail-density="compact"] .msg-avatar {
  width: 28px;
  height: 28px;
  font-size: 12px;
}

.mail-workspace[data-mail-density="compact"] .msg-sender,
.mail-workspace[data-mail-density="compact"] .msg-subject {
  font-size: 12.5px;
}

.mail-workspace[data-mail-density="compact"] .msg-snippet {
  font-size: 11.5px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

/* Priority & Authenticity Pills */
.priority-badge {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 16px;
  height: 16px;
  padding: 0 4px;
  border-radius: 4px;
  background: var(--danger-soft);
  color: var(--danger);
  border: 1px solid rgba(239, 68, 68, 0.3);
  font-family: var(--font-mono);
  font-size: 10.5px;
  font-weight: 700;
  line-height: 1;
  flex-shrink: 0;
}

.security-pill {
  display: inline-flex;
  align-items: center;
  padding: 2px 8px;
  border-radius: 999px;
  font-size: 11px;
  font-weight: 500;
  background: rgba(16, 185, 129, 0.12);
  color: var(--success);
  border: 1px solid rgba(16, 185, 129, 0.25);
  white-space: nowrap;
}

/* Drag & Drop Targets */
.nav-item.drop-target {
  background: var(--accent-soft);
  color: var(--text);
  outline: 1px dashed var(--accent);
}

.msg-list.drag-over {
  outline: 2px dashed var(--accent);
  outline-offset: -4px;
  background: var(--accent-soft);
}

.msg-row.dragging {
  opacity: 0.45;
}

/* Message Context Menu */
.context-menu {
  position: fixed;
  z-index: 120;
  min-width: 210px;
  max-width: 260px;
  padding: 6px;
  background: var(--surface);
  border: 1px solid var(--border-strong);
  border-radius: var(--radius);
  box-shadow: var(--shadow-lg);
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.context-menu-item {
  width: 100%;
  text-align: left;
  padding: 7px 10px;
  border-radius: 6px;
  font-size: 13px;
  color: var(--text);
  background: transparent;
  transition: background-color 0.12s var(--ease);
}

.context-menu-item:hover {
  background: var(--surface-hover);
}

.context-menu-item.danger {
  color: var(--danger);
}

.context-menu-item.danger:hover {
  background: var(--danger-soft);
}

.context-menu-sep {
  height: 1px;
  margin: 4px 2px;
  background: var(--border);
}

/* Maximized Composer & Toolbar Color Picker */
#composerModal.modal-backdrop.composer-maximized {
  padding: 16px;
}

#composerModal.modal-backdrop.composer-maximized .composer-card {
  max-width: none;
  width: 100%;
  height: calc(100vh - 32px);
  max-height: calc(100vh - 32px);
}

.toolbar-color {
  width: 28px;
  height: 26px;
  padding: 2px;
  border: 1px solid var(--border);
  border-radius: 5px;
  background: var(--surface-2);
  cursor: pointer;
}

/* Action Popovers & Sidebar Folder Toggle */
.popover-wrap {
  position: relative;
  display: inline-flex;
  align-items: center;
}

.action-popover {
  position: absolute;
  top: calc(100% + 6px);
  left: 0;
  z-index: 95;
  min-width: 215px;
  padding: 6px;
  background: var(--surface);
  border: 1px solid var(--border-strong);
  border-radius: var(--radius);
  box-shadow: var(--shadow-lg);
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.action-popover-right {
  left: auto;
  right: 0;
}

.popover-item {
  width: 100%;
  text-align: left;
  display: flex;
  align-items: center;
  gap: 9px;
  padding: 7px 10px;
  border-radius: 6px;
  font-size: 13px;
  line-height: 1.3;
  color: var(--text);
  text-decoration: none;
  background: transparent;
  transition: background-color 0.14s var(--ease), color 0.14s var(--ease);
}

.popover-item svg {
  width: 15px;
  height: 15px;
  color: var(--text-muted);
  flex-shrink: 0;
}

.popover-item-label {
  flex: 1;
  min-width: 0;
}

.popover-state-badge {
  margin-left: auto;
  font-family: var(--font-mono);
  font-size: 11px;
  padding: 1px 7px;
  border-radius: 999px;
  background: var(--surface-2);
  border: 1px solid var(--border);
  color: var(--text-muted);
}

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

.popover-item.active,
.popover-item.btn-accent-soft {
  background: var(--accent-soft);
  color: var(--accent);
  font-weight: 600;
  border: none;
}

.popover-item.active svg {
  color: var(--accent);
}

.popover-item.danger {
  color: var(--danger);
}

.popover-item.danger:hover {
  background: var(--danger-soft);
}

.popover-field {
  padding: 3px 4px;
}

.popover-select {
  width: 100%;
  height: 30px;
  font-size: 12.5px;
  padding: 0 26px 0 8px;
  border-radius: 6px;
  background-color: var(--surface-2);
  border: 1px solid var(--border);
}

.nav-more-toggle {
  width: 100%;
  height: 30px;
  display: flex;
  align-items: center;
  gap: 9px;
  padding: 0 10px;
  margin-top: 4px;
  border-radius: var(--radius-sm);
  font-size: 12px;
  font-weight: 500;
  color: var(--text-dim);
  text-align: left;
  transition: background-color 0.14s var(--ease), color 0.14s var(--ease);
}

.nav-more-toggle svg {
  width: 15px;
  height: 15px;
  transition: transform 0.18s var(--ease);
}

.nav-more-toggle[aria-expanded="true"] svg {
  transform: rotate(180deg);
}

.nav-more-toggle:hover {
  background: var(--surface-hover);
  color: var(--text-muted);
}

.nav-more-group {
  display: flex;
  flex-direction: column;
  gap: 3px;
  padding-top: 2px;
}

.composer-submit {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
}

.btn-rewrite {
  display: inline-flex;
  align-items: center;
  gap: 6px;
}

.btn-rewrite svg {
  flex: 0 0 auto;
}

.btn-rewrite.is-loading svg {
  animation: spinRewrite 0.9s linear infinite;
}

@keyframes spinRewrite {
  from {
    transform: rotate(0deg);
  }
  to {
    transform: rotate(360deg);
  }
}

.rewrite-flash {
  animation: rewriteFlash 1.1s ease-out;
}

@keyframes rewriteFlash {
  0% {
    box-shadow: 0 0 0 2px var(--accent, #3b82f6);
    background-color: rgba(59, 130, 246, 0.14);
  }
  100% {
    box-shadow: 0 0 0 0 transparent;
  }
}
