/* ==============================
   Design Tokens
   ============================== */
:root {
  --bg-base: #0d0f14;
  --bg-raised: #13151c;
  --bg-surface: #191c26;
  --bg-hover: #1e2233;
  --bg-active: #242840;
  --border: #252a3a;
  --border-focus: #4f8ef7;
  --text-primary: #e1e4ec;
  --text-secondary: #8b92a5;
  --text-muted: #5a6178;
  --accent: #4f8ef7;
  --accent-hover: #6ba0ff;
  --danger: #e54d5a;
  --success: #3cc68a;
  --warning: #f5a623;
  --radius-sm: 6px;
  --radius-md: 10px;
  --radius-lg: 16px;
  --shadow-sm: 0 1px 3px rgba(0,0,0,.3);
  --shadow-md: 0 4px 12px rgba(0,0,0,.4);
  --shadow-lg: 0 8px 32px rgba(0,0,0,.5);
  --sidebar-w: 240px;
  --list-w: 380px;
  --transition: .18s ease;
  accent-color: var(--accent);
}

:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}

/* ==============================
   Reset & Base
   ============================== */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

html, body {
  height: 100%;
  font-family: 'Inter', system-ui, -apple-system, sans-serif;
  font-size: 14px;
  line-height: 1.5;
  color: var(--text-primary);
  background: var(--bg-base);
  -webkit-font-smoothing: antialiased;
  overflow: hidden;
}

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

.icon { width: 18px; height: 18px; display: inline-block; vertical-align: middle; flex-shrink: 0; }

/* ==============================
   Buttons
   ============================== */
.btn {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 8px 16px;
  border: none;
  border-radius: var(--radius-sm);
  font-family: inherit;
  font-size: 13px;
  font-weight: 500;
  cursor: pointer;
  transition: background var(--transition), color var(--transition), box-shadow var(--transition);
  white-space: nowrap;
}
.btn:disabled { opacity: .5; cursor: not-allowed; }

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

.btn-ghost {
  background: transparent;
  color: var(--text-secondary);
}
.btn-ghost:hover:not(:disabled) { background: var(--bg-hover); color: var(--text-primary); }

.btn-sm { padding: 5px 10px; font-size: 12px; }
.btn-full { width: 100%; justify-content: center; }

.btn-icon {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 32px;
  height: 32px;
  border: none;
  border-radius: var(--radius-sm);
  background: transparent;
  color: var(--text-secondary);
  cursor: pointer;
  transition: background var(--transition), color var(--transition);
}
.btn-icon:hover { background: var(--bg-hover); color: var(--text-primary); }

.btn-spinner {
  display: inline-block;
  width: 18px;
  height: 18px;
  border: 2px solid rgba(255,255,255,.3);
  border-top-color: #fff;
  border-radius: 50%;
  animation: spin .6s linear infinite;
}

@keyframes spin { to { transform: rotate(360deg); } }
@keyframes spinning { to { transform: rotate(360deg); } }
.spinning { animation: spinning .6s linear infinite; }

/* ==============================
   Forms
   ============================== */
.form-group { margin-bottom: 16px; }
.form-label { display: block; margin-bottom: 6px; font-size: 13px; font-weight: 500; color: var(--text-secondary); }

.form-control {
  width: 100%;
  padding: 10px 14px;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background: var(--bg-base);
  color: var(--text-primary);
  font-family: inherit;
  font-size: 14px;
  outline: none;
  transition: border-color var(--transition);
}
.form-control:focus { border-color: var(--border-focus); }
.form-control::placeholder { color: var(--text-muted); }

.form-error {
  margin: 8px 0;
  padding: 8px 12px;
  border-radius: var(--radius-sm);
  background: rgba(229,77,90,.12);
  color: var(--danger);
  font-size: 13px;
}

/* ==============================
   Login Screen
   ============================== */
.login-screen {
  display: flex;
  align-items: center;
  justify-content: center;
  height: 100vh;
  background: var(--bg-base);
}

.login-card {
  width: 100%;
  max-width: 380px;
  padding: 40px 32px;
  background: var(--bg-raised);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-lg);
  text-align: center;
}

.login-logo { margin-bottom: 20px; }
.login-title { font-size: 22px; font-weight: 600; margin-bottom: 4px; }
.login-subtitle { font-size: 13px; color: var(--text-secondary); margin-bottom: 28px; }
.login-form { text-align: left; }

/* ==============================
   App Shell (3-column)
   ============================== */
.app {
  display: grid;
  grid-template-columns: var(--sidebar-w) var(--list-w) 1fr;
  height: 100vh;
  overflow: hidden;
}

/* ==============================
   Sidebar
   ============================== */
.sidebar {
  display: flex;
  flex-direction: column;
  background: var(--bg-raised);
  border-right: 1px solid var(--border);
  overflow: hidden;
}

.sidebar-top { padding: 16px; }

.sidebar-brand {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-bottom: 16px;
}
.brand-name { font-weight: 600; font-size: 15px; }

.btn-compose {
  display: flex;
  align-items: center;
  gap: 8px;
  width: 100%;
  padding: 10px 16px;
  border: none;
  border-radius: var(--radius-md);
  background: var(--accent);
  color: #fff;
  font-family: inherit;
  font-size: 14px;
  font-weight: 500;
  cursor: pointer;
  transition: background var(--transition);
}
.btn-compose:hover { background: var(--accent-hover); }

.sidebar-nav {
  flex: 1;
  padding: 8px;
  display: flex;
  flex-direction: column;
  gap: 2px;
  overflow-y: auto;
}

.nav-item {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 9px 12px;
  border-radius: var(--radius-sm);
  color: var(--text-secondary);
  font-size: 13px;
  font-weight: 500;
  transition: background var(--transition), color var(--transition);
  text-decoration: none;
}
.nav-item:hover { background: var(--bg-hover); color: var(--text-primary); }
.nav-item.active { background: var(--bg-active); color: var(--text-primary); }

.nav-icon { width: 18px; height: 18px; }
.nav-label { flex: 1; }

.nav-badge {
  padding: 1px 7px;
  border-radius: 10px;
  background: var(--accent);
  color: #fff;
  font-size: 11px;
  font-weight: 600;
  line-height: 1.5;
}

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

.sidebar-footer-item {
  display: flex;
  align-items: center;
  gap: 10px;
  width: 100%;
  padding: 9px 12px;
  border: none;
  border-radius: var(--radius-sm);
  background: transparent;
  color: var(--text-secondary);
  font-family: inherit;
  font-size: 13px;
  cursor: pointer;
  transition: background var(--transition), color var(--transition);
}
.sidebar-footer-item:hover { background: var(--bg-hover); color: var(--text-primary); }

/* ==============================
   Email List Pane
   ============================== */
.list-pane {
  display: flex;
  flex-direction: column;
  background: var(--bg-base);
  border-right: 1px solid var(--border);
  overflow: hidden;
}

.list-header { padding: 12px 16px; border-bottom: 1px solid var(--border); }

.search-bar {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 6px 12px;
  background: var(--bg-surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  transition: border-color var(--transition);
}
.search-bar:focus-within { border-color: var(--border-focus); }
.search-icon { color: var(--text-muted); }

.search-input {
  flex: 1;
  border: none;
  background: transparent;
  color: var(--text-primary);
  font-family: inherit;
  font-size: 13px;
  outline: none;
}
.search-input::placeholder { color: var(--text-muted); }

.search-clear { width: 24px; height: 24px; }

.batch-toolbar {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-top: 8px;
  padding: 6px 0;
}
.selected-count { font-size: 12px; color: var(--text-secondary); margin-right: auto; }
.batch-actions { display: flex; gap: 4px; }

.list-label-row {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 10px 16px;
}
.folder-label { font-size: 16px; font-weight: 600; flex: 1; }
.folder-count { font-size: 12px; color: var(--text-muted); }

.email-list {
  flex: 1;
  overflow-y: auto;
  scrollbar-width: thin;
  scrollbar-color: var(--bg-hover) transparent;
}

.list-footer { padding: 8px 16px; text-align: center; }
.load-more { width: 100%; }
.list-loading, .empty-state { padding: 40px 16px; text-align: center; color: var(--text-muted); }

/* Email Rows */
.email-row {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 12px 16px;
  border-bottom: 1px solid var(--border);
  cursor: pointer;
  transition: background var(--transition);
}
.email-row:hover { background: var(--bg-hover); }
.email-row.active { background: var(--bg-active); }
.email-row.unread { font-weight: 600; }
.email-row.unread .row-sender { color: var(--text-primary); }
.email-row.checked { background: rgba(79,142,247,.08); }

.row-checkbox-wrap {
  display: flex;
  align-items: center;
  cursor: pointer;
}
.row-checkbox {
  width: 16px;
  height: 16px;
  accent-color: var(--accent);
  cursor: pointer;
}

.row-star { width: 28px; height: 28px; color: var(--text-muted); }
.email-row.starred .row-star { color: var(--warning); }

.row-avatar {
  width: 36px;
  height: 36px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  color: rgba(255,255,255,.85);
  font-size: 12px;
  font-weight: 600;
  flex-shrink: 0;
}

.row-content { flex: 1; min-width: 0; }
.row-top { display: flex; justify-content: space-between; align-items: baseline; gap: 8px; }
.row-sender { font-size: 13px; color: var(--text-secondary); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.row-date { font-size: 11px; color: var(--text-muted); white-space: nowrap; flex-shrink: 0; }
.row-subject { font-size: 13px; margin-top: 2px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.row-snippet { font-size: 12px; color: var(--text-muted); margin-top: 1px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.row-attach { color: var(--text-muted); width: 14px; height: 14px; flex-shrink: 0; }

/* ==============================
   Reading Pane
   ============================== */
.reader-pane {
  display: flex;
  flex-direction: column;
  overflow: hidden;
  background: var(--bg-base);
}

.reader-empty {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  height: 100%;
  color: var(--text-muted);
  gap: 12px;
}
.reader-empty-icon { width: 80px; height: 80px; opacity: .4; }
.reader-empty-title { font-size: 16px; font-weight: 500; color: var(--text-secondary); }
.reader-empty-hint { font-size: 13px; }
.reader-empty-hint kbd {
  padding: 2px 6px;
  border: 1px solid var(--border);
  border-radius: 4px;
  background: var(--bg-surface);
  font-size: 12px;
}

.reader-content {
  flex: 1;
  overflow-y: auto;
  padding: 24px;
  scrollbar-width: thin;
  scrollbar-color: var(--bg-hover) transparent;
}

.reader-loading, .reader-error {
  padding: 40px;
  text-align: center;
  color: var(--text-muted);
}

.reader-header { margin-bottom: 20px; }
.reader-header-top { display: flex; gap: 14px; margin-bottom: 16px; }

.reader-avatar {
  width: 44px;
  height: 44px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  color: rgba(255,255,255,.85);
  font-size: 14px;
  font-weight: 600;
  flex-shrink: 0;
}

.reader-meta { flex: 1; min-width: 0; }
.reader-from { font-size: 15px; font-weight: 600; margin-bottom: 2px; }
.reader-addresses { font-size: 12px; color: var(--text-muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.reader-date { font-size: 12px; color: var(--text-muted); margin-top: 2px; }
.reader-subject { font-size: 18px; font-weight: 600; margin-bottom: 12px; line-height: 1.3; }

.reader-actions { display: flex; gap: 6px; flex-wrap: wrap; margin-bottom: 16px; }

/* Attachments */
.reader-attachments {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
  padding: 12px 0;
  border-top: 1px solid var(--border);
  border-bottom: 1px solid var(--border);
  margin-bottom: 16px;
}

.attachment-chip {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 6px 12px;
  background: var(--bg-surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  color: var(--text-secondary);
  font-size: 12px;
  text-decoration: none;
  transition: background var(--transition);
}
.attachment-chip:hover { background: var(--bg-hover); color: var(--text-primary); }

/* Email body */
.reader-body-frame {
  width: 100%;
  min-height: 200px;
  border: none;
  background: var(--bg-base);
  border-radius: var(--radius-sm);
}

.reader-body-text pre {
  white-space: pre-wrap;
  word-wrap: break-word;
  font-family: inherit;
  font-size: 14px;
  line-height: 1.6;
  color: var(--text-primary);
}

/* Thread */
.reader-thread { margin-top: 24px; border-top: 1px solid var(--border); padding-top: 16px; }

.thread-msg { margin-bottom: 8px; }
.thread-msg-header {
  display: flex;
  justify-content: space-between;
  padding: 8px 12px;
  border-radius: var(--radius-sm);
  cursor: pointer;
  font-size: 13px;
  color: var(--text-secondary);
  transition: background var(--transition);
}
.thread-msg-header:hover { background: var(--bg-hover); }
.thread-msg-from { font-weight: 500; }
.thread-msg-date { color: var(--text-muted); font-size: 12px; }
.thread-msg-body { padding: 12px; }
.thread-msg-body pre {
  white-space: pre-wrap;
  word-wrap: break-word;
  font-family: inherit;
  font-size: 13px;
  color: var(--text-secondary);
}

/* ==============================
   Compose Windows
   ============================== */
#compose-container {
  position: fixed;
  bottom: 0;
  right: 24px;
  display: flex;
  gap: 12px;
  align-items: flex-end;
  z-index: 100;
  pointer-events: none;
}

.compose-window {
  width: 480px;
  max-height: 520px;
  background: var(--bg-raised);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg) var(--radius-lg) 0 0;
  box-shadow: var(--shadow-lg);
  display: flex;
  flex-direction: column;
  pointer-events: auto;
  animation: slideUp .2s ease;
}
.compose-window.minimized { max-height: 42px; overflow: hidden; }
.compose-window.minimized .compose-body { display: none; }

@keyframes slideUp { from { transform: translateY(20px); opacity: 0; } to { transform: translateY(0); opacity: 1; } }

.compose-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 10px 16px;
  background: var(--bg-surface);
  border-bottom: 1px solid var(--border);
  border-radius: var(--radius-lg) var(--radius-lg) 0 0;
  cursor: pointer;
}
.compose-title { font-size: 13px; font-weight: 600; }
.compose-header-actions { display: flex; gap: 4px; }

.compose-body {
  display: flex;
  flex-direction: column;
  flex: 1;
  overflow: hidden;
}

.compose-field {
  display: flex;
  align-items: center;
  padding: 6px 16px;
  border-bottom: 1px solid var(--border);
  gap: 8px;
}
.compose-field label {
  font-size: 12px;
  color: var(--text-muted);
  width: 56px;
  flex-shrink: 0;
}
.compose-field input, .compose-field select {
  flex: 1;
  border: none;
  background: transparent;
  color: var(--text-primary);
  font-family: inherit;
  font-size: 13px;
  outline: none;
  padding: 4px 0;
}

.compose-editor {
  flex: 1;
  padding: 16px;
  min-height: 200px;
  overflow-y: auto;
  color: var(--text-primary);
  font-family: inherit;
  font-size: 14px;
  line-height: 1.6;
  outline: none;
}
.compose-editor:empty::before {
  content: attr(placeholder);
  color: var(--text-muted);
}

.compose-toolbar {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 10px 16px;
  border-top: 1px solid var(--border);
}

/* ==============================
   Settings Panel
   ============================== */
.overlay {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,.5);
  z-index: 200;
}

.settings-panel {
  position: fixed;
  top: 0;
  right: 0;
  width: 420px;
  max-width: 100vw;
  height: 100vh;
  background: var(--bg-raised);
  border-left: 1px solid var(--border);
  box-shadow: var(--shadow-lg);
  display: flex;
  flex-direction: column;
  z-index: 201;
  animation: slideLeft .2s ease;
}

@keyframes slideLeft { from { transform: translateX(30px); opacity: 0; } to { transform: translateX(0); opacity: 1; } }

.settings-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 16px 20px;
  border-bottom: 1px solid var(--border);
}
.settings-title { font-size: 16px; font-weight: 600; }

.settings-nav {
  display: flex;
  gap: 4px;
  padding: 12px 20px;
  border-bottom: 1px solid var(--border);
  overflow-x: auto;
}

.settings-nav-item {
  padding: 6px 12px;
  border: none;
  border-radius: var(--radius-sm);
  background: transparent;
  color: var(--text-secondary);
  font-family: inherit;
  font-size: 12px;
  font-weight: 500;
  cursor: pointer;
  white-space: nowrap;
  transition: background var(--transition), color var(--transition);
}
.settings-nav-item:hover { background: var(--bg-hover); color: var(--text-primary); }
.settings-nav-item.active { background: var(--bg-active); color: var(--text-primary); }

.settings-body {
  flex: 1;
  overflow-y: auto;
  padding: 20px;
}

.settings-section { margin-bottom: 24px; }
.settings-section h3 { font-size: 14px; font-weight: 600; margin-bottom: 16px; color: var(--text-primary); }

.settings-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 12px;
}
.settings-row label { font-size: 13px; color: var(--text-secondary); flex-shrink: 0; }
.settings-row input[type="text"],
.settings-row input[type="email"],
.settings-row select,
.settings-row textarea { max-width: 240px; }

.settings-hint { font-size: 12px; color: var(--text-muted); }
.settings-loading, .settings-error { padding: 40px; text-align: center; color: var(--text-muted); }

.settings-actions {
  display: flex;
  gap: 8px;
  padding-top: 16px;
  border-top: 1px solid var(--border);
}

/* ==============================
   Context Menu
   ============================== */
.context-menu {
  position: fixed;
  min-width: 160px;
  background: var(--bg-raised);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  box-shadow: var(--shadow-lg);
  padding: 4px;
  z-index: 300;
}

.ctx-item {
  display: block;
  width: 100%;
  padding: 8px 12px;
  border: none;
  background: transparent;
  color: var(--text-primary);
  font-family: inherit;
  font-size: 13px;
  text-align: left;
  cursor: pointer;
  border-radius: var(--radius-sm);
  transition: background var(--transition);
}
.ctx-item:hover { background: var(--bg-hover); }

/* ==============================
   Toast Notifications
   ============================== */
.toast-container {
  position: fixed;
  bottom: 24px;
  left: 50%;
  transform: translateX(-50%);
  display: flex;
  flex-direction: column-reverse;
  gap: 8px;
  z-index: 400;
  pointer-events: none;
}

.toast {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 16px;
  background: var(--bg-raised);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  box-shadow: var(--shadow-md);
  font-size: 13px;
  color: var(--text-primary);
  pointer-events: auto;
  animation: toastIn .25s ease;
  max-width: 400px;
}
.toast.removing { animation: toastOut .2s ease forwards; }

.toast-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  flex-shrink: 0;
}
.toast.info .toast-dot { background: var(--accent); }
.toast.success .toast-dot { background: var(--success); }
.toast.error .toast-dot { background: var(--danger); }
.toast.warning .toast-dot { background: var(--warning); }

.toast-text { flex: 1; }

@keyframes toastIn { from { transform: translateY(12px); opacity: 0; } to { transform: translateY(0); opacity: 1; } }
@keyframes toastOut { to { transform: translateY(12px); opacity: 0; } }

/* ==============================
   Scrollbar
   ============================== */
::-webkit-scrollbar { width: 6px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: var(--bg-hover); border-radius: 3px; }
::-webkit-scrollbar-thumb:hover { background: var(--bg-active); }

/* ==============================
   Responsive - Hamburger + Layout
   ============================== */

/* List header row with hamburger */
.list-header-row {
  display: flex;
  align-items: center;
  gap: 8px;
}
.list-header-row .search-bar { flex: 1; }

/* Hamburger button: hidden on desktop */
.hamburger-btn { display: none; }

/* Back button in reader: hidden on desktop */
.reader-mobile-back { display: none; }

/* Sidebar overlay: always hidden on desktop */
.sidebar-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,.5);
  z-index: 199;
  backdrop-filter: blur(2px);
}

/* Tablet: narrower columns */
@media (max-width: 1024px) {
  .app { grid-template-columns: 200px 300px 1fr; }
  :root { --sidebar-w: 200px; --list-w: 300px; }
  .compose-window { width: 400px; }
}

/* Mobile: single column + drawer sidebar */
@media (max-width: 768px) {
  .app {
    grid-template-columns: 1fr;
    grid-template-rows: 1fr;
  }

  /* Show hamburger button */
  .hamburger-btn { display: inline-flex; flex-shrink: 0; }

  /* Sidebar: off-screen drawer */
  .sidebar {
    position: fixed;
    top: 0;
    left: 0;
    width: 280px;
    height: 100vh;
    z-index: 200;
    transform: translateX(-100%);
    transition: transform .25s ease;
    box-shadow: none;
  }
  .app.sidebar-open .sidebar {
    transform: translateX(0);
    box-shadow: var(--shadow-lg);
  }

  /* List pane: full width, always visible by default */
  .list-pane {
    border-right: none;
    grid-column: 1;
    grid-row: 1;
  }

  /* Reader pane: full screen, hidden by default on mobile */
  .reader-pane {
    position: fixed;
    inset: 0;
    z-index: 50;
    display: none;
  }
  .app.show-reader .reader-pane {
    display: flex;
  }

  /* Show mobile back button */
  .reader-mobile-back {
    display: flex;
    padding: 8px 12px;
    border-bottom: 1px solid var(--border);
    background: var(--bg-raised);
  }

  /* Compose: full width on mobile */
  #compose-container { right: 0; left: 0; }
  .compose-window {
    width: 100%;
    max-height: 70vh;
    border-radius: var(--radius-lg) var(--radius-lg) 0 0;
  }

  /* Settings page: single column with horizontal tabs on top */
  .settings-page { grid-template-columns: 1fr; grid-template-rows: auto 1fr; }
  .settings-page-sidebar {
    border-right: none;
    border-bottom: 1px solid var(--border);
    overflow-y: visible;
    overflow-x: auto;
  }
  .settings-page-nav {
    flex-direction: row;
    overflow-x: auto;
    padding: 8px;
    gap: 4px;
  }
  .settings-page-nav .settings-nav-item {
    padding: 8px 12px;
    font-size: 12px;
    white-space: nowrap;
  }
  .settings-page-body { padding: 20px 16px; }

  /* Toast: wider on mobile */
  .toast { max-width: calc(100vw - 32px); }
  .toast-container { left: 16px; right: 16px; transform: none; }

  /* Audit log: single column on mobile */
  .audit-row { grid-template-columns: 1fr; gap: 4px; }

  /* Email row: larger touch targets */
  .email-row { padding: 14px 12px; }
  .row-avatar { width: 40px; height: 40px; }
}

/* Small mobile: even tighter */
@media (max-width: 480px) {
  .login-card { padding: 28px 20px; margin: 0 12px; }
  .reader-content { padding: 16px 12px; }
  .reader-subject { font-size: 16px; }
  .reader-actions { gap: 4px; }
  .reader-actions .btn { padding: 6px 8px; font-size: 11px; }
  .settings-row { flex-direction: column; align-items: flex-start; gap: 6px; }
  .settings-row input[type="text"],
  .settings-row input[type="email"],
  .settings-row select,
  .settings-row textarea { max-width: 100%; width: 100%; }
}

/* ==============================
   Settings Full Page
   ============================== */
.settings-page {
  position: fixed;
  inset: 0;
  display: grid;
  grid-template-columns: 260px 1fr;
  background: var(--bg-base);
  z-index: 50;
  animation: fadeIn .15s ease;
}

@keyframes fadeIn { from { opacity: 0; } to { opacity: 1; } }

.settings-page-sidebar {
  background: var(--bg-raised);
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  overflow-y: auto;
}

.settings-page-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 20px 16px 12px;
  border-bottom: 1px solid var(--border);
}

.settings-page-title {
  font-size: 18px;
  font-weight: 700;
  color: var(--text-primary);
}

.settings-page-nav {
  display: flex;
  flex-direction: column;
  gap: 2px;
  padding: 12px 8px;
}

.settings-page-nav .settings-nav-item {
  width: 100%;
  text-align: left;
  padding: 10px 14px;
  border-radius: var(--radius-sm);
  font-size: 14px;
}

.settings-page-body {
  overflow-y: auto;
  padding: 32px 48px;
}

/* Cap section content width without capping the column */
.settings-page-body .settings-section,
.settings-page-body .settings-actions {
  max-width: 640px;
}

/* Must be last to override any display property via source order */
.hidden { display: none; }

/* ==============================
   Light Theme
   ============================== */
[data-theme="light"] {
  --bg-base: #f5f6f8;
  --bg-raised: #ffffff;
  --bg-surface: #eef0f4;
  --bg-hover: #e5e8ef;
  --bg-active: #dde0ea;
  --border: #d1d5e0;
  --border-focus: #4f8ef7;
  --text-primary: #1a1d26;
  --text-secondary: #4a5068;
  --text-muted: #8b92a5;
  --accent: #4f8ef7;
  --accent-hover: #3a7ae0;
  --danger: #c72b38;
  --success: #1e9e6a;
  --warning: #d4880e;
  --shadow-sm: 0 1px 3px rgba(0,0,0,.1);
  --shadow-md: 0 4px 12px rgba(0,0,0,.12);
  --shadow-lg: 0 8px 32px rgba(0,0,0,.16);
  accent-color: var(--accent);
}

@media (prefers-color-scheme: light) {
  :root:not([data-theme="dark"]) {
    --bg-base: #f5f6f8;
    --bg-raised: #ffffff;
    --bg-surface: #eef0f4;
    --bg-hover: #e5e8ef;
    --bg-active: #dde0ea;
    --border: #d1d5e0;
    --text-primary: #1a1d26;
    --text-secondary: #4a5068;
    --text-muted: #8b92a5;
    --shadow-sm: 0 1px 3px rgba(0,0,0,.1);
    --shadow-md: 0 4px 12px rgba(0,0,0,.12);
    --shadow-lg: 0 8px 32px rgba(0,0,0,.16);
  }
}

/* ==============================
   Density Variants
   ============================== */
[data-density="compact"] .email-row { padding: 7px 16px; }
[data-density="compact"] .nav-item { padding: 6px 12px; }
[data-density="compact"] .form-control { padding: 7px 12px; }
[data-density="cozy"] .email-row { padding: 16px; }
[data-density="cozy"] .nav-item { padding: 12px 14px; }

/* ==============================
   Font Size Variants
   ============================== */
[data-fontsize="13"] { font-size: 13px; }
[data-fontsize="14"] { font-size: 14px; }
[data-fontsize="16"] { font-size: 16px; }

/* ==============================
   Theme Toggle Buttons
   ============================== */
.theme-toggle {
  display: flex;
  gap: 4px;
  background: var(--bg-surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 3px;
}

.theme-btn {
  flex: 1;
  padding: 6px 12px;
  border: none;
  border-radius: calc(var(--radius-sm) - 2px);
  background: transparent;
  color: var(--text-secondary);
  font-family: inherit;
  font-size: 12px;
  font-weight: 500;
  cursor: pointer;
  transition: background var(--transition), color var(--transition);
}
.theme-btn:hover { background: var(--bg-hover); color: var(--text-primary); }
.theme-btn.active { background: var(--bg-raised); color: var(--text-primary); box-shadow: var(--shadow-sm); }

/* ==============================
   Toggle Switch
   ============================== */
.toggle-switch {
  position: relative;
  display: inline-flex;
  align-items: center;
  cursor: pointer;
}
.toggle-switch input { position: absolute; opacity: 0; width: 0; height: 0; }
.toggle-track {
  width: 40px;
  height: 22px;
  background: var(--bg-hover);
  border: 1px solid var(--border);
  border-radius: 11px;
  transition: background var(--transition);
  position: relative;
}
.toggle-switch input:checked + .toggle-track { background: var(--accent); border-color: var(--accent); }
.toggle-thumb {
  position: absolute;
  top: 2px;
  left: 2px;
  width: 16px;
  height: 16px;
  background: #fff;
  border-radius: 50%;
  transition: transform var(--transition);
  box-shadow: var(--shadow-sm);
}
.toggle-switch input:checked + .toggle-track .toggle-thumb { transform: translateX(18px); }

/* ==============================
   Settings Rows (form elements)
   ============================== */
.form-control-sm {
  padding: 6px 10px;
  font-size: 13px;
}
.settings-row .form-control { flex: 1; max-width: 260px; }
.settings-row { flex-wrap: wrap; }

/* ==============================
   Mailbox List
   ============================== */
.mailbox-list { display: flex; flex-direction: column; gap: 10px; margin-bottom: 16px; }
.mailbox-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 12px 16px;
  background: var(--bg-surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
}
.mailbox-info { flex: 1; min-width: 0; }
.mailbox-address { font-size: 13px; font-weight: 500; margin-bottom: 6px; }
.mailbox-name { width: 100%; max-width: 220px; }
.mailbox-actions { display: flex; gap: 4px; flex-shrink: 0; }
.badge-default {
  display: inline-block;
  padding: 1px 7px;
  background: var(--accent);
  color: #fff;
  border-radius: 10px;
  font-size: 10px;
  font-weight: 600;
  margin-left: 6px;
  vertical-align: middle;
}
.btn-danger { color: var(--danger); }
.btn-danger:hover { background: rgba(229,77,90,.1); color: var(--danger); }

/* ==============================
   Filter Rules
   ============================== */
.filter-list { display: flex; flex-direction: column; gap: 8px; margin-bottom: 16px; }
.filter-row {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 12px;
  padding: 12px 16px;
  background: var(--bg-surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
}
.filter-inactive { opacity: .55; }
.filter-info { flex: 1; min-width: 0; }
.filter-name { font-size: 13px; font-weight: 600; margin-bottom: 4px; }
.filter-conditions { font-size: 12px; color: var(--text-muted); margin-bottom: 4px; }
.filter-action { font-size: 12px; color: var(--text-secondary); }
.filter-btns { display: flex; gap: 4px; flex-shrink: 0; }

/* ==============================
   Audit Log
   ============================== */
.audit-log { display: flex; flex-direction: column; gap: 6px; }
.audit-row {
  display: grid;
  grid-template-columns: 160px 1fr auto auto;
  gap: 8px;
  align-items: center;
  padding: 8px 12px;
  background: var(--bg-surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  font-size: 12px;
}
.audit-event { font-weight: 500; color: var(--text-secondary); }
.audit-event-login_success { color: var(--success); }
.audit-event-login_failed { color: var(--danger); }
.audit-event-password_changed { color: var(--warning); }
.audit-event-password_change_failed { color: var(--danger); }
.audit-detail { color: var(--text-muted); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.audit-ip { color: var(--text-muted); font-family: monospace; }
.audit-date { color: var(--text-muted); white-space: nowrap; }

/* ==============================
   Shortcut Reference
   ============================== */
.shortcut-list { display: flex; flex-direction: column; gap: 8px; }
.shortcut-row {
  display: flex;
  align-items: center;
  gap: 16px;
  padding: 8px 12px;
  background: var(--bg-surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
}
.shortcut-row kbd {
  padding: 3px 8px;
  background: var(--bg-raised);
  border: 1px solid var(--border);
  border-radius: 4px;
  font-family: monospace;
  font-size: 12px;
  min-width: 80px;
  text-align: center;
  box-shadow: var(--shadow-sm);
  color: var(--text-primary);
}
.shortcut-row span { color: var(--text-secondary); font-size: 13px; }

/* ==============================
   Remote Image Blocked Bar
   ============================== */
.reader-image-bar {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 8px 16px;
  background: var(--bg-surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  margin-bottom: 12px;
  font-size: 12px;
  color: var(--text-secondary);
}
.reader-image-bar .icon { color: var(--warning); flex-shrink: 0; }
.reader-image-bar span { flex: 1; }

/* ==============================
   Security Session Info
   ============================== */
.security-session-info {
  display: flex;
  flex-direction: column;
  gap: 6px;
  margin-top: 8px;
}
.security-item {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 8px 12px;
  background: var(--bg-surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  font-size: 13px;
}
.security-label { color: var(--text-secondary); }
.security-value { color: var(--text-primary); font-weight: 500; font-family: monospace; font-size: 12px; }

