:root {
  --brand-1: #6d4de6;
  --brand-2: #9b6cf6;
  --brand-1-dark: #5637c9;
  --brand-tint: rgba(109, 77, 230, .1);
  --ink: #16202e;
  --ink-soft: #626c7d;
  --line: #e6e5f0;
  --surface: #ffffff;
  --bg: #f6f5fb;
  --bg-soft: #f0eefa;
  --danger: #e0455b;
  --success: #1fa971;
  --warning: #b8860b;
  --radius: 14px;
  --radius-sm: 9px;
  --shadow-sm: 0 1px 2px rgba(22, 32, 46, 0.06);
  --shadow-md: 0 8px 24px rgba(22, 32, 46, 0.08);
  --shadow-lg: 0 20px 60px rgba(22, 32, 46, 0.16);
  font-synthesis: none;
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --ink: #eceef4;
    --ink-soft: #9aa1b4;
    --line: #33374a;
    --surface: #1c1e2b;
    --bg: #14151f;
    --bg-soft: #24263580;
    --brand-tint: rgba(155, 108, 246, .18);
  }
}
:root[data-theme="dark"] {
  --ink: #eceef4;
  --ink-soft: #9aa1b4;
  --line: #33374a;
  --surface: #1c1e2b;
  --bg: #14151f;
  --bg-soft: #24263580;
  --brand-tint: rgba(155, 108, 246, .18);
}

* { box-sizing: border-box; }

html, body {
  height: 100%;
}

body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  font-family: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Helvetica, Arial, sans-serif;
  font-size: 13px;
  -webkit-font-smoothing: antialiased;
  transition: background .2s ease, color .2s ease;
}

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

button { font-family: inherit; }

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  border: none;
  border-radius: 10px;
  padding: 11px 20px;
  font-size: 13px;
  font-weight: 600;
  cursor: pointer;
  transition: transform .15s ease, box-shadow .15s ease, background .15s ease, opacity .15s ease, border-color .15s ease, color .15s ease;
  white-space: nowrap;
  min-height: 40px;
}
.btn:active { transform: scale(.97); }
.btn:disabled { opacity: .55; cursor: not-allowed; transform: none; }
.btn:focus-visible, .btn-icon:focus-visible, select:focus-visible, input:focus-visible, textarea:focus-visible, [contenteditable]:focus-visible {
  outline: 2px solid var(--brand-1); outline-offset: 2px;
}

.btn-primary {
  color: #fff;
  background: linear-gradient(135deg, var(--brand-1), var(--brand-2));
  box-shadow: 0 6px 16px rgba(109, 77, 230, 0.32);
}
.btn-primary:hover:not(:disabled) { box-shadow: 0 10px 24px rgba(109, 77, 230, 0.4); transform: translateY(-1px); }

.btn-ghost {
  color: var(--ink);
  background: transparent;
}
.btn-ghost:hover:not(:disabled) { background: var(--bg-soft); }

.btn-outline {
  color: var(--ink);
  background: var(--surface);
  border: 1.5px solid var(--line);
}
.btn-outline:hover:not(:disabled) { border-color: var(--brand-1); color: var(--brand-1); background: rgba(109,77,230,.05); }

.btn-danger { color: #fff; background: var(--danger); box-shadow: 0 6px 16px rgba(224,69,91,.28); }
.btn-danger:hover:not(:disabled) { opacity: .9; transform: translateY(-1px); }

.btn-icon {
  width: 38px; height: 38px; padding: 0; border-radius: 50%;
  color: var(--ink-soft); background: transparent; border: none; cursor: pointer;
  display: inline-flex; align-items: center; justify-content: center;
  transition: background .15s ease, color .15s ease, transform .1s ease;
}
.btn-icon:hover:not(:disabled) { background: var(--bg-soft); color: var(--ink); }
.btn-icon:active:not(:disabled) { transform: scale(.92); }
.btn-icon.active { color: var(--brand-1); background: rgba(109,77,230,.1); }

.field {
  display: flex;
  flex-direction: column;
  gap: 6px;
  margin-bottom: 16px;
  text-align: left;
}
.field label {
  font-size: 12px;
  font-weight: 600;
  color: var(--ink-soft);
}
.field input, .field textarea, .field select,
select, .compose-body input, .compose-body textarea {
  font: inherit;
  padding: 12px 14px;
  border-radius: 10px;
  border: 1.5px solid var(--line);
  background: var(--surface);
  color: var(--ink);
  transition: border-color .15s ease, box-shadow .15s ease;
  width: 100%;
}
.field input:focus, .field textarea:focus, .field select:focus, select:focus {
  outline: none;
  border-color: var(--brand-1);
  box-shadow: 0 0 0 4px rgba(109,77,230,.12);
}

select {
  appearance: none;
  -webkit-appearance: none;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='%238a8fa3' stroke-width='2.4' 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 12px center;
  background-size: 15px;
  padding-right: 36px;
  cursor: pointer;
}

input[type="checkbox"] { accent-color: var(--brand-1); }

.logo-mark {
  display: inline-flex;
  align-items: center;
  gap: 10px;
}
.logo-img {
  display: block;
  height: 34px;
  width: auto;
  flex-shrink: 0;
}

/* ---------- animations ---------- */
@keyframes wmn-fade-up {
  from { opacity: 0; transform: translateY(14px); }
  to { opacity: 1; transform: translateY(0); }
}
@keyframes wmn-fade-in {
  from { opacity: 0; } to { opacity: 1; }
}
@keyframes wmn-pop {
  0% { opacity: 0; transform: scale(.94); }
  100% { opacity: 1; transform: scale(1); }
}
@keyframes wmn-spin { to { transform: rotate(360deg); } }
@keyframes wmn-shimmer {
  0% { background-position: -300px 0; }
  100% { background-position: 300px 0; }
}
@keyframes wmn-blob {
  0%, 100% { transform: translate(0,0) scale(1); }
  33% { transform: translate(4%, -6%) scale(1.08); }
  66% { transform: translate(-5%, 4%) scale(.96); }
}
@keyframes wmn-toast-in {
  from { opacity: 0; transform: translateY(12px) scale(.96); }
  to { opacity: 1; transform: translateY(0) scale(1); }
}

.spinner {
  width: 18px; height: 18px;
  border-radius: 50%;
  border: 2.5px solid rgba(255,255,255,.4);
  border-top-color: #fff;
  animation: wmn-spin .7s linear infinite;
  flex-shrink: 0;
}
.spinner.dark {
  border-color: rgba(22,32,46,.15);
  border-top-color: var(--brand-1);
}

.skeleton {
  background: linear-gradient(90deg, var(--bg-soft) 25%, var(--line) 37%, var(--bg-soft) 63%);
  background-size: 400px 100%;
  animation: wmn-shimmer 1.4s ease infinite;
  border-radius: 8px;
}

.toast-stack {
  position: fixed;
  right: 20px;
  bottom: 20px;
  z-index: 999;
  display: flex;
  flex-direction: column;
  gap: 10px;
}
.toast {
  min-width: 240px;
  max-width: 360px;
  padding: 13px 16px;
  border-radius: var(--radius-sm);
  background: #20222f;
  color: #fff;
  font-size: 13px;
  box-shadow: var(--shadow-lg);
  animation: wmn-toast-in .25s ease;
}
.toast.error { background: var(--danger); }
.toast.success { background: var(--success); }

/* ---------- auth pages (login / forgot / reset) ---------- */
.auth-page {
  min-height: 100%;
  display: flex;
  align-items: center;
  justify-content: center;
  position: relative;
  overflow: hidden;
  padding: 24px;
}
.auth-page::before, .auth-page::after {
  content: '';
  position: absolute;
  width: 480px; height: 480px;
  border-radius: 50%;
  filter: blur(70px);
  opacity: .35;
  animation: wmn-blob 16s ease-in-out infinite;
  z-index: 0;
}
.auth-page::before { background: var(--brand-1); top: -160px; left: -120px; }
.auth-page::after { background: var(--brand-2); bottom: -160px; right: -120px; animation-delay: -8s; }

.auth-card {
  position: relative;
  z-index: 1;
  width: 100%;
  max-width: 400px;
  background: var(--surface);
  border-radius: 20px;
  box-shadow: var(--shadow-lg);
  padding: 36px 34px 30px;
  text-align: center;
  animation: wmn-fade-up .5s cubic-bezier(.2,.8,.2,1);
}
.auth-card .logo-mark { justify-content: center; margin-bottom: 22px; }
.auth-card .logo-img { height: 44px; margin: 0 auto; }
.auth-card h1 {
  font-size: 19px;
  margin: 0 0 6px;
}
.auth-card p.sub {
  color: var(--ink-soft);
  font-size: 13px;
  margin: 0 0 26px;
}
.auth-card .btn-primary { width: 100%; padding: 13px; font-size: 14px; margin-top: 4px; }
.auth-card .foot-link { margin-top: 18px; font-size: 13px; color: var(--ink-soft); }
.auth-msg {
  border-radius: var(--radius-sm);
  padding: 11px 14px;
  font-size: 13px;
  text-align: left;
  margin-bottom: 18px;
  animation: wmn-pop .2s ease;
}
.auth-msg.error { background: #fdecef; color: #a4293b; }
.auth-msg.success { background: #e8f8f1; color: #146c47; }

/* ---------- app shell ---------- */
.app-shell {
  display: grid;
  grid-template-columns: 264px 1fr;
  grid-template-rows: 100vh;
  height: 100vh;
  overflow: hidden;
  animation: wmn-fade-in .35s ease;
}
.drawer-backdrop {
  display: none;
  position: fixed; inset: 0; background: rgba(15,20,30,.45); z-index: 149;
}
.bottom-tabbar { display: none; }

.sidebar {
  background: var(--surface);
  border-right: 1px solid var(--line);
  display: flex;
  flex-direction: column;
  padding: 20px 16px;
  min-height: 0;
}
.sidebar .logo-mark { padding: 4px 6px 22px; flex-shrink: 0; }
.compose-btn {
  width: 100%; margin-bottom: 20px; padding: 14px; flex-shrink: 0;
  border-radius: 14px; font-size: 14px;
}
.folder-list { list-style: none; margin: 0 0 6px; padding: 0; flex-shrink: 0; }
.folder-item {
  display: flex; align-items: center; gap: 12px;
  padding: 10px 12px;
  border-radius: 10px;
  color: var(--ink-soft);
  font-size: 13px;
  font-weight: 500;
  cursor: pointer;
  transition: background .15s ease, color .15s ease;
  margin-bottom: 2px;
}
.folder-item:hover { background: var(--bg-soft); color: var(--ink); }
.folder-item.active { background: var(--brand-tint); color: var(--brand-1); font-weight: 700; }
.folder-item svg { flex-shrink: 0; }
.folder-item .label { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.folder-count {
  font-size: 11px; font-weight: 700; line-height: 1;
  padding: 4px 8px; border-radius: 20px; flex-shrink: 0;
  background: var(--bg-soft); color: var(--ink-soft);
}

.folders-section { flex: 1; min-height: 0; display: flex; flex-direction: column; overflow: hidden; }
.folders-section-head {
  display: flex; align-items: center; justify-content: space-between;
  padding: 12px 12px 8px; flex-shrink: 0;
}
.folders-section-head span {
  font-size: 11px; font-weight: 800; letter-spacing: .06em;
  color: var(--ink-soft); text-transform: uppercase;
}
.custom-folder-list { list-style: none; margin: 0; padding: 0; flex: 1; min-height: 0; overflow-y: auto; }
.folder-color-icon { flex-shrink: 0; }

.storage-widget { padding: 12px; margin-top: 8px; flex-shrink: 0; }
.storage-widget .storage-label { display: flex; justify-content: space-between; font-size: 11px; color: var(--ink-soft); margin-bottom: 8px; }
.storage-bar { height: 6px; border-radius: 6px; background: var(--bg-soft); overflow: hidden; }
.storage-bar-fill { height: 100%; background: linear-gradient(90deg, var(--brand-1), var(--brand-2)); border-radius: 6px; }

.sidebar-foot {
  padding-top: 10px; margin-top: 6px;
  display: flex; align-items: center; justify-content: center; gap: 10px; flex-shrink: 0;
}

/* ---------- top bar ---------- */
.main-col { display: flex; flex-direction: column; min-height: 0; min-width: 0; }
.top-bar {
  display: flex; align-items: center; gap: 12px;
  padding: 14px 22px;
  border-bottom: 1px solid var(--line);
  background: var(--surface);
  flex-shrink: 0;
}
.hamburger-btn, .mobile-search-btn, .compose-fab, .mobile-title { display: none; }
.top-search { position: relative; flex: 1; max-width: 640px; }
.top-search input {
  font: inherit; width: 100%; color: var(--ink);
  padding: 11px 40px 11px 40px; border-radius: 12px;
  border: 1.5px solid transparent;
  background: var(--bg-soft);
  transition: border-color .15s ease, box-shadow .15s ease, background .15s ease;
}
.top-search input:focus { outline: none; background: var(--surface); border-color: var(--brand-1); box-shadow: 0 0 0 4px var(--brand-tint); }
.search-cancel-btn { position: absolute; right: 44px; top: 50%; transform: translateY(-50%); z-index: 1; }
.top-search .search-icon { position: absolute; left: 13px; top: 50%; transform: translateY(-50%); color: var(--ink-soft); pointer-events: none; }
.filter-btn { position: absolute; right: 4px; top: 50%; transform: translateY(-50%); }
.filter-popover {
  position: absolute; top: calc(100% + 8px); right: 0; z-index: 30;
  background: var(--surface); border: 1px solid var(--line); border-radius: 12px;
  box-shadow: var(--shadow-md); padding: 10px; min-width: 170px;
  animation: wmn-pop .15s ease;
}
.filter-popover label {
  display: flex; align-items: center; gap: 8px;
  font-size: 12.5px; padding: 7px 6px; border-radius: 8px; cursor: pointer;
}
.filter-popover label:hover { background: var(--bg-soft); }

.top-bar-right { display: flex; align-items: center; gap: 6px; margin-left: auto; }
.account-menu { position: relative; }
.account-btn {
  display: flex; align-items: center; gap: 8px;
  border: none; background: transparent; cursor: pointer;
  padding: 5px 10px 5px 5px; border-radius: 30px;
  transition: background .15s ease;
}
.account-btn:hover { background: var(--bg-soft); }
.account-btn .avatar { width: 32px; height: 32px; font-size: 12px; }
.account-btn .account-email { font-size: 12.5px; font-weight: 600; color: var(--ink); max-width: 160px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.account-dropdown {
  position: absolute; top: calc(100% + 8px); right: 0; z-index: 30;
  background: var(--surface); border: 1px solid var(--line); border-radius: 12px;
  box-shadow: var(--shadow-md); padding: 6px; min-width: 180px;
  animation: wmn-pop .15s ease;
}
.account-dropdown button {
  display: block; width: 100%; text-align: left; border: none; background: none; cursor: pointer;
  padding: 9px 10px; border-radius: 8px; font-size: 13px; color: var(--ink); font: inherit;
}
.account-dropdown button:hover { background: var(--bg-soft); }
.account-dropdown button.danger { color: var(--danger); }

/* ---------- quick filter tabs ---------- */
.quick-tabs {
  display: flex; align-items: center; gap: 4px;
  padding: 4px 18px 0;
  border-bottom: 1px solid var(--line);
  flex-shrink: 0;
}
.quick-tab {
  display: flex; align-items: center; gap: 7px;
  border: none; background: none; cursor: pointer; font: inherit;
  padding: 12px 6px; margin-right: 22px;
  font-size: 13px; font-weight: 600; color: var(--ink-soft);
  border-bottom: 2.5px solid transparent;
  transition: color .15s ease, border-color .15s ease;
  white-space: nowrap;
}
.quick-tab:hover { color: var(--ink); }
.quick-tab.active { color: var(--brand-1); border-color: var(--brand-1); }
.quick-tab .tab-badge {
  font-size: 10px; font-weight: 700; padding: 2px 7px; border-radius: 20px;
  background: var(--bg-soft); color: var(--ink-soft);
}
.quick-tab.active .tab-badge { background: var(--brand-tint); color: var(--brand-1); }

.content-columns { display: flex; flex: 1; min-height: 0; }

.list-pane {
  border-right: 1px solid var(--line);
  background: var(--surface);
  display: flex;
  flex-direction: column;
  min-width: 0;
  min-height: 0;
  width: 380px;
  flex-shrink: 0;
}
.list-pane-head {
  padding: 14px 18px 0;
  flex-shrink: 0;
}
.list-pane-head h2 { margin: 0; font-size: 16px; }

.list-toolbar {
  display: flex; align-items: center; gap: 4px;
  padding: 8px 14px;
  border-bottom: 1px solid var(--line);
  flex-shrink: 0;
}
.list-toolbar .list-range { font-size: 12px; color: var(--ink-soft); white-space: nowrap; }
.list-toolbar .spacer { flex: 1; }
.list-toolbar .btn-icon { width: 32px; height: 32px; }
.dropdown-wrap { position: relative; }
.kebab-dropdown, .move-dropdown {
  position: absolute; top: calc(100% + 6px); right: 0; z-index: 30;
  background: var(--surface); border: 1px solid var(--line); border-radius: 12px;
  box-shadow: var(--shadow-md); padding: 6px; min-width: 190px;
  animation: wmn-pop .15s ease; max-height: 260px; overflow-y: auto;
}
.kebab-dropdown button, .move-dropdown button {
  display: block; width: 100%; text-align: left; border: none; background: none; cursor: pointer;
  padding: 9px 10px; border-radius: 8px; font-size: 13px; color: var(--ink); font: inherit;
  white-space: nowrap;
}
.kebab-dropdown button:hover, .move-dropdown button:hover { background: var(--bg-soft); }

.ai-popover {
  position: absolute; bottom: calc(100% + 8px); left: 0; z-index: 30;
  background: var(--surface); border: 1px solid var(--line); border-radius: 12px;
  box-shadow: var(--shadow-md); padding: 12px; width: 300px;
  animation: wmn-pop .15s ease;
}
.ai-popover-title { font-size: 13px; font-weight: 700; margin-bottom: 6px; }
.ai-popover textarea {
  width: 100%; font: inherit; font-size: 12.5px; padding: 8px 10px;
  border-radius: 8px; border: 1.5px solid var(--line); background: var(--bg-soft); color: var(--ink);
  resize: vertical;
}
.ai-popover textarea:focus { outline: none; border-color: var(--brand-1); background: var(--surface); }
.ai-popover-foot { margin-top: 8px; }
#aiWrap .btn-outline .label { display: inline; }

.bulk-bar {
  display: flex; align-items: center; gap: 8px;
  padding: 9px 14px;
  background: var(--brand-tint);
  border-bottom: 1px solid var(--line);
  font-size: 12.5px; font-weight: 600; color: var(--brand-1);
  flex-shrink: 0;
}
.bulk-bar[hidden] { display: none; }
.bulk-bar .spacer { flex: 1; }
.bulk-bar .btn { padding: 7px 13px; min-height: 32px; font-size: 12px; }

.message-list { flex: 1; min-height: 0; overflow-y: auto; }
.message-row {
  display: flex;
  align-items: flex-start;
  gap: 10px;
  padding: 13px 16px;
  border-bottom: 1px solid var(--bg-soft);
  cursor: pointer;
  transition: background .12s ease;
  animation: wmn-fade-up .3s ease backwards;
}
.message-row:hover { background: var(--bg-soft); }
.message-row:hover .msg-avatar { opacity: 0; }
.message-row:hover .msg-select { opacity: 1; pointer-events: auto; }
.message-row.active { background: var(--brand-tint); }
.message-row.selected { background: var(--brand-tint); }
.message-row.selected .msg-avatar { opacity: 0; }
.message-row.selected .msg-select { opacity: 1; pointer-events: auto; }
.message-row.unread .msg-from, .message-row.unread .msg-subject { font-weight: 700; }
.msg-dot {
  width: 8px; height: 8px; border-radius: 50%; margin-top: 18px; flex-shrink: 0;
  background: var(--brand-1);
  opacity: 0;
}
.message-row.unread .msg-dot { opacity: 1; }

.msg-lead { position: relative; width: 40px; height: 40px; flex-shrink: 0; }
.msg-avatar {
  position: absolute; inset: 0; border-radius: 50%;
  background: linear-gradient(135deg, var(--brand-1), var(--brand-2));
  color: #fff; display: flex; align-items: center; justify-content: center;
  font-weight: 700; font-size: 13px; transition: opacity .12s ease;
}
.msg-select {
  position: absolute; inset: 0; margin: auto; width: 18px; height: 18px;
  opacity: 0; pointer-events: none; transition: opacity .12s ease;
}

.msg-body-col { flex: 1; min-width: 0; padding-top: 2px; }
.msg-top-line { display: flex; align-items: center; gap: 6px; }
.msg-from { font-size: 13px; color: var(--ink); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.msg-date { font-size: 11px; color: var(--ink-soft); flex-shrink: 0; margin-left: auto; }
.msg-subject { font-size: 13px; color: var(--ink); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; margin-top: 3px; }
.msg-preview { font-size: 12px; color: var(--ink-soft); margin-top: 2px; overflow: hidden; text-overflow: ellipsis; display: -webkit-box; -webkit-line-clamp: 1; -webkit-box-orient: vertical; }
.msg-star-col { flex-shrink: 0; margin-top: 9px; }
.msg-star-btn { color: var(--line); background: none; border: none; cursor: pointer; padding: 2px; display: flex; }
.msg-star-btn.starred { color: #e6b800; }
.msg-star-btn.starred svg { fill: #e6b800; }

.empty-state {
  display: flex; flex-direction: column; align-items: center; justify-content: center;
  height: 100%; color: var(--ink-soft); gap: 10px; padding: 40px; text-align: center;
  animation: wmn-fade-in .4s ease;
}
.empty-state svg { opacity: .5; }

.reading-pane {
  background: var(--bg);
  display: flex;
  flex-direction: column;
  min-width: 0;
  min-height: 0;
  flex: 1;
}
.reading-toolbar {
  display: flex; align-items: center; gap: 6px;
  padding: 10px 20px;
  border-bottom: 1px solid var(--line);
  background: var(--surface);
  flex-shrink: 0;
  flex-wrap: wrap;
}
.reading-toolbar .spacer { flex: 1; }
.toolbar-pill {
  display: inline-flex; align-items: center; gap: 7px;
  padding: 9px 15px; border-radius: 10px;
  border: 1.5px solid var(--line); background: var(--surface); color: var(--ink);
  font-size: 13px; font-weight: 600; cursor: pointer;
  transition: border-color .15s ease, color .15s ease, background .15s ease, transform .1s ease;
}
.toolbar-pill:hover { border-color: var(--brand-1); color: var(--brand-1); background: rgba(109,77,230,.05); }
.toolbar-pill:active { transform: scale(.96); }
.toolbar-pill svg { flex-shrink: 0; }

.reading-body { flex: 1; min-height: 0; overflow-y: auto; padding: 24px 16px 40px; animation: wmn-fade-up .3s ease; }
.reading-card {
  max-width: 1100px; margin: 0 auto;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow-sm);
  padding: 26px 36px 34px;
}
.reading-title-row { display: flex; align-items: flex-start; gap: 10px; margin-bottom: 18px; }
.reading-card h1 { font-size: 18px; margin: 0; line-height: 1.35; word-break: break-word; flex: 1; }
.reading-title-row .btn-icon { flex-shrink: 0; color: var(--line); }
.reading-title-row .btn-icon.active { color: #e6b800; background: none; }
.reading-title-row .btn-icon.active svg { fill: #e6b800; }
.reading-meta { display: flex; gap: 13px; align-items: flex-start; padding-bottom: 18px; margin-bottom: 20px; border-bottom: 1px solid var(--bg-soft); }
.reading-actions { display: flex; gap: 10px; margin-top: 28px; }
.avatar {
  width: 44px; height: 44px; border-radius: 50%; flex-shrink: 0;
  background: linear-gradient(135deg, var(--brand-1), var(--brand-2));
  color: #fff; display: flex; align-items: center; justify-content: center; font-weight: 700; font-size: 14px;
}
.reading-meta-text { flex: 1; min-width: 0; }
.reading-meta-text .name { font-weight: 700; font-size: 13.5px; }
.reading-meta-text .addr, .reading-meta-text .to-line { font-size: 12px; color: var(--ink-soft); margin-top: 1px; word-break: break-word; }
.reading-meta-date { font-size: 12px; color: var(--ink-soft); white-space: nowrap; }

.msg-html-frame { width: 100%; border: none; min-height: 160px; background: #fff; }
.msg-text { white-space: pre-wrap; font-size: 14px; line-height: 1.65; color: var(--ink); }

.remote-images-bar {
  display: flex; align-items: center; gap: 10px; flex-wrap: wrap;
  background: #fff8e6; border: 1px solid #f2dfa3; color: #7a5b00;
  padding: 10px 14px; border-radius: 10px; font-size: 12.5px; margin-bottom: 16px;
}

.attachments-bar { display: flex; flex-wrap: wrap; gap: 10px; margin-top: 24px; padding-top: 20px; border-top: 1px solid var(--bg-soft); }
.attachment-chip {
  display: flex; align-items: center; gap: 8px;
  padding: 9px 10px 9px 13px;
  background: var(--bg-soft); border: 1px solid transparent; border-radius: 10px;
  font-size: 12.5px; color: var(--ink);
  transition: box-shadow .15s ease, transform .15s ease, border-color .15s ease;
  min-height: 40px;
}
.attachment-chip:hover { box-shadow: var(--shadow-sm); transform: translateY(-1px); border-color: var(--line); text-decoration: none; }
.attachment-chip svg { color: var(--brand-1); flex-shrink: 0; }
.attachment-chip .att-size { color: var(--ink-soft); }
.attachment-chip[data-preview] { cursor: pointer; }
.att-thumb { width: 28px; height: 28px; object-fit: cover; border-radius: 6px; flex-shrink: 0; background: var(--surface); }
.att-download { display: inline-flex; color: var(--ink-soft); margin-left: 2px; padding: 4px; border-radius: 6px; }
.att-download:hover { color: var(--brand-1); background: var(--surface); }

/* ---------- attachment preview modal ---------- */
.preview-modal {
  width: min(880px, 92vw);
  max-height: calc(100vh - 48px);
  background: var(--surface);
  border-radius: 16px;
  box-shadow: var(--shadow-lg);
  display: flex; flex-direction: column;
  animation: wmn-pop .22s cubic-bezier(.2,.8,.2,1);
  overflow: hidden;
  margin: auto;
}
.preview-body { flex: 1; overflow: auto; background: var(--bg-soft); display: flex; }
.preview-image-wrap { margin: auto; padding: 20px; display: flex; }
.preview-image-wrap img { max-width: 100%; max-height: 78vh; border-radius: 8px; box-shadow: var(--shadow-md); margin: auto; }
.preview-pdf-frame { width: 100%; min-height: 78vh; border: none; background: #fff; }
.preview-text { width: 100%; margin: 0; padding: 20px; font-size: 12.5px; white-space: pre-wrap; word-break: break-word; background: #fff; }
#previewBackdrop { align-items: center; }

/* ---------- compose modal ---------- */
.modal-backdrop {
  position: fixed; inset: 0; background: rgba(15,20,30,.45);
  display: flex; align-items: flex-end; justify-content: flex-end;
  padding: 24px; z-index: 100;
  animation: wmn-fade-in .2s ease;
}
.compose-modal {
  width: 560px; max-width: 100%;
  max-height: calc(100vh - 48px);
  background: var(--surface);
  border-radius: 16px;
  box-shadow: var(--shadow-lg);
  display: flex; flex-direction: column;
  animation: wmn-pop .22s cubic-bezier(.2,.8,.2,1);
  overflow: hidden;
  transition: width .18s ease, height .18s ease, max-width .18s ease, max-height .18s ease, border-radius .18s ease;
}
.modal-backdrop.compose-fullscreen { align-items: stretch; justify-content: stretch; padding: 0; }
#composeBackdrop.compose-fullscreen .compose-modal {
  width: 100%; max-width: 100%; height: 100%; max-height: 100%; border-radius: 0;
}
#composeBackdrop.compose-fullscreen .compose-body { max-width: 760px; margin: 0 auto; width: 100%; }
#composeBackdrop.compose-fullscreen .rich-editor { min-height: 40vh; }
.compose-head {
  display: flex; align-items: center; justify-content: space-between;
  gap: 10px;
  padding: 14px 18px;
  background: linear-gradient(135deg, var(--brand-1), var(--brand-2));
  color: #fff;
}
.compose-head strong { font-size: 14px; flex: 1; }
.compose-head-actions { display: flex; align-items: center; gap: 2px; flex-shrink: 0; }
.compose-head .btn-icon { color: #fff; width: 30px; height: 30px; }
.compose-head .btn-icon:hover { background: rgba(255,255,255,.18); }
.compose-body { padding: 16px 18px; overflow-y: auto; }
.compose-body .field { margin-bottom: 12px; }

.editor-toolbar {
  display: flex; align-items: center; gap: 2px; flex-wrap: wrap;
  padding: 6px; border: 1.5px solid var(--line); border-bottom: none;
  border-radius: var(--radius-sm) var(--radius-sm) 0 0;
  background: var(--bg-soft);
}
.editor-toolbar .btn-icon { width: 30px; height: 30px; }
.toolbar-sep { width: 1px; height: 20px; background: var(--line); margin: 0 4px; }
.rich-editor {
  min-height: 200px;
  max-height: 42vh;
  overflow-y: auto;
  padding: 12px 14px;
  border: 1.5px solid var(--line);
  border-radius: 0 0 var(--radius-sm) var(--radius-sm);
  font-size: 14px;
  line-height: 1.55;
  background: var(--surface);
  color: var(--ink);
}
.rich-editor:focus { outline: none; border-color: var(--brand-1); box-shadow: 0 0 0 4px rgba(109,77,230,.12); }
.rich-editor blockquote { margin: 8px 0; }
.rich-editor a { color: var(--brand-1); }
.rich-editor:empty:before { content: attr(data-placeholder); color: var(--ink-soft); }
.compose-foot { display: flex; align-items: center; gap: 10px; padding: 12px 18px; border-top: 1px solid var(--line); }
.response-select {
  font: inherit; font-size: 12.5px; padding: 9px 10px;
  border-radius: var(--radius-sm); border: 1.5px solid var(--line); background: var(--surface); color: var(--ink);
}
.compose-foot .spacer { flex: 1; }
.file-chip {
  display: flex; align-items: center; gap: 6px;
  background: var(--bg-soft); padding: 6px 10px; border-radius: 8px; font-size: 12px;
}
.file-chip button { background: none; border: none; color: var(--ink-soft); cursor: pointer; font-size: 13px; line-height: 1; }
.compose-files { display: flex; flex-wrap: wrap; gap: 6px; margin: 8px 0; }

/* ---------- settings modal ---------- */
.settings-body .field { margin-bottom: 14px; }
.hint { font-size: 11.5px; color: var(--ink-soft); margin-top: -8px; margin-bottom: 14px; }

.settings-modal {
  width: min(760px, 94vw);
  height: min(600px, 82vh);
  background: var(--surface);
  border-radius: 16px;
  box-shadow: var(--shadow-lg);
  display: flex; flex-direction: column;
  animation: wmn-pop .22s cubic-bezier(.2,.8,.2,1);
  overflow: hidden;
  margin: auto;
}
.settings-layout { display: flex; flex: 1; min-height: 0; }
.settings-tabs {
  width: 168px; flex-shrink: 0;
  border-right: 1px solid var(--line);
  padding: 12px 8px;
  display: flex; flex-direction: column; gap: 2px;
  overflow-y: auto;
}
.settings-tab {
  text-align: left; border: none; background: none; cursor: pointer;
  padding: 9px 12px; border-radius: 8px;
  font-size: 13px; font-weight: 500; color: var(--ink-soft);
}
.settings-tab:hover { background: var(--bg-soft); color: var(--ink); }
.settings-tab.active { background: rgba(109,77,230,.1); color: var(--brand-1); font-weight: 700; }
.settings-content { flex: 1; min-width: 0; overflow-y: auto; padding: 20px 22px; }
.settings-content .field { margin-bottom: 14px; max-width: 420px; }
.settings-content select, .settings-content textarea { font: inherit; }

.settings-check {
  display: flex; align-items: center; gap: 8px;
  font-size: 13px; color: var(--ink);
  margin-bottom: 12px; cursor: pointer;
}
.settings-check input { width: 16px; height: 16px; }

.settings-row {
  display: flex; align-items: center; gap: 8px;
  padding: 11px 4px;
  border-bottom: 1px solid var(--bg-soft);
}
.settings-row-title { font-size: 13px; font-weight: 600; }
.settings-row-sub { font-size: 11.5px; color: var(--ink-soft); margin-top: 2px; }
.badge {
  display: inline-block; font-size: 10px; font-weight: 700;
  color: var(--brand-1); background: rgba(109,77,230,.1);
  padding: 2px 7px; border-radius: 20px; vertical-align: middle;
}
.btn-sm { padding: 6px 12px; font-size: 12px; }

/* ---------- labels ---------- */
.label-chips { display: inline-flex; gap: 5px; flex-shrink: 0; }
.label-chip {
  display: inline-flex; align-items: center; gap: 4px;
  font-size: 11px; font-weight: 700;
  padding: 2px 8px; border-radius: 20px;
  cursor: pointer; white-space: nowrap;
}
.label-chip-x {
  border: none; background: none; cursor: pointer; padding: 0;
  color: inherit; opacity: .65; font-size: 10px; line-height: 1;
}
.label-chip-x:hover { opacity: 1; }
#readingLabels:empty { display: none; }
#readingLabels { margin: -6px 0 18px; }
#readingLabels .label-chip { font-size: 11.5px; padding: 4px 10px; }
.label-filter-bar {
  display: flex; align-items: center; gap: 8px;
  padding: 10px 18px; font-size: 12.5px; color: var(--ink-soft);
  border-bottom: 1px solid var(--line); flex-shrink: 0;
}
.label-filter-bar .btn-icon { width: 26px; height: 26px; }
.settings-subform {
  margin-top: 12px; padding: 14px; border-radius: 10px;
  background: var(--bg-soft); border: 1px solid var(--line);
}
.settings-msg:empty { display: none; }

body.density-compact .message-row { padding: 7px 18px; }
body.density-compact .msg-subject { margin-top: 0; }

@media (max-width: 980px) {
  .app-shell { grid-template-columns: 76px 1fr; }
  .content-columns .list-pane { display: none; width: 100%; }
  .app-shell.show-list .content-columns .list-pane { display: flex; }
  .app-shell.show-list .reading-pane { display: none; }
  .folder-item .label, .folders-section-head span, .storage-widget { display: none; }
  .compose-btn span { display: none; }
  .sidebar { align-items: center; padding: 18px 8px; }
  .sidebar .logo-mark { width: 34px; height: 34px; overflow: hidden; padding: 4px 0 22px; }
  .sidebar .logo-img { width: auto; height: 34px; max-width: none; object-fit: cover; object-position: left; }
  .folder-item { justify-content: center; padding: 12px; }
  .folder-count { display: none; }
  .compose-btn { padding: 12px; }
  .folders-section-head { justify-content: center; }
  .account-btn .account-email { display: none; }
}

/* ---------- phone layout: hamburger drawer + bottom tab bar ---------- */
@media (max-width: 700px) {
  html, body { height: 100%; }
  .app-shell {
    height: 100dvh; grid-template-rows: 100dvh;
    grid-template-columns: 1fr;
  }

  .sidebar {
    position: fixed; top: 0; left: 0; bottom: 0; z-index: 150;
    width: 260px; align-items: stretch; padding: 18px 14px;
    transform: translateX(-100%);
    transition: transform .22s ease;
    box-shadow: var(--shadow-lg);
  }
  .app-shell.drawer-open .sidebar { transform: translateX(0); }
  .app-shell.drawer-open .drawer-backdrop { display: block; }
  .sidebar .logo-mark { width: auto; height: auto; overflow: visible; padding: 4px 6px 22px; }
  .sidebar .logo-img { width: auto; height: 34px; object-fit: initial; object-position: initial; }
  .folder-item .label, .folders-section-head span { display: inline; }
  .compose-btn span { display: inline; }
  .folder-item { justify-content: flex-start; padding: 10px 12px; }
  .folder-count { display: inline-block; }
  .folders-section-head { justify-content: space-between; }

  .top-bar { padding: 12px 14px; gap: 8px; }
  .hamburger-btn, .mobile-search-btn, .compose-fab { display: inline-flex; }
  .mobile-title { display: block; }
  .mobile-title h2 { margin: 0; font-size: 16px; line-height: 1.2; }
  .mobile-title .unread-sub { font-size: 11.5px; color: var(--brand-1); font-weight: 600; }
  .top-search { display: none; position: fixed; inset: 0 0 auto 0; z-index: 60; padding: 12px 14px; background: var(--surface); max-width: none; }
  .top-bar.search-mode .top-search { display: block; }
  .top-bar.search-mode .top-search input { padding-right: 78px; }
  .top-bar.search-mode .hamburger-btn, .top-bar.search-mode .mobile-title, .top-bar.search-mode .mobile-search-btn, .top-bar.search-mode .top-bar-right, .top-bar.search-mode .compose-fab { display: none; }
  .compose-fab {
    width: 42px; height: 42px; border-radius: 13px; padding: 0; border: none; cursor: pointer;
    background: linear-gradient(135deg, var(--brand-1), var(--brand-2)); color: #fff;
    align-items: center; justify-content: center; box-shadow: 0 6px 16px rgba(109,77,230,.32); flex-shrink: 0;
  }
  .account-btn .account-email { display: none; }

  .quick-tabs { padding: 0 14px; }
  .quick-tab { margin-right: 18px; padding: 10px 4px; }

  .list-toolbar .list-range { display: none; }

  .modal-backdrop { padding: 0; align-items: stretch; justify-content: stretch; }
  .compose-modal, .settings-modal, .preview-modal {
    width: 100%; max-width: 100%; height: 100dvh; max-height: 100dvh;
    border-radius: 0;
  }

  .settings-layout { flex-direction: column; }
  .settings-tabs {
    flex-direction: row; width: 100%; overflow-x: auto;
    border-right: none; border-bottom: 1px solid var(--line);
    padding: 8px; gap: 6px;
  }
  .settings-tab { flex-shrink: 0; }
  .settings-content { padding: 16px; }

  .compose-body { padding: 14px; }
  .compose-foot { flex-wrap: wrap; padding: 10px 14px; }
  .compose-foot .label { display: none; }
  .compose-foot #attachBtn, .compose-foot #saveDraftBtn { padding: 10px; }
  .response-select { max-width: 120px !important; font-size: 12px; }

  .reading-toolbar { padding: 8px 12px; }
  .toolbar-pill .label { display: none; }
  .toolbar-pill { padding: 9px; border-radius: 50%; }
  .reading-body { padding: 14px 10px 30px; }
  .reading-card { padding: 18px 16px 22px; border-radius: 12px; }
  .reading-card h1 { font-size: 16px; }

  .list-pane-head { padding: 12px 14px 0; }
  .message-row { padding: 12px 14px; }

  .auth-card { padding: 28px 22px 24px; border-radius: 16px; }

  .toast-stack { left: 12px; right: 12px; bottom: calc(70px + env(safe-area-inset-bottom)); }
  .toast { max-width: none; }

  .preview-body { padding: 0; }
  .preview-image-wrap { padding: 10px; }

  .content-columns { padding-bottom: calc(58px + env(safe-area-inset-bottom)); }
  .bottom-tabbar {
    display: flex; position: fixed; left: 0; right: 0; bottom: 0; z-index: 120;
    background: var(--surface); border-top: 1px solid var(--line);
    padding: 6px 4px calc(6px + env(safe-area-inset-bottom));
  }
  .bt-tab {
    flex: 1; display: flex; flex-direction: column; align-items: center; gap: 3px;
    border: none; background: none; cursor: pointer; font: inherit;
    padding: 6px 2px; border-radius: 10px; color: var(--ink-soft);
  }
  .bt-tab span { font-size: 10.5px; font-weight: 600; }
  .bt-tab.active { color: var(--brand-1); }
  .bt-tab.active .bt-tab-icon { background: var(--brand-tint); }
  .bt-tab-icon { display: flex; align-items: center; justify-content: center; width: 34px; height: 22px; border-radius: 10px; }
}
