:root {
  --bg: #f4f5f8;
  --surface: #ffffff;
  --surface-soft: #f8fafc;
  --surface-hover: #f1f5f9;
  --border: #e5e7eb;
  --border-strong: #d1d5db;
  --text: #0f172a;
  --text-muted: #64748b;
  --text-light: #94a3b8;
  --primary: #2563eb;
  --primary-dark: #1d4ed8;
  --primary-soft: #dbeafe;
  --primary-softer: #eff6ff;
  --danger: #dc2626;
  --warning: #d97706;
  --warning-soft: #fef3c7;
  --success: #059669;
  --accent: #0891b2;
  --accent-dark: #0e7490;
  --accent-gradient: linear-gradient(135deg, #0891b2, #0d9488);
  --header-height: 60px;
  --sidebar-width: 280px;
  --preview-width: 1.4fr;
  --radius-sm: 6px;
  --radius: 10px;
  --radius-lg: 14px;
  --shadow-sm: 0 1px 2px rgba(15, 23, 42, 0.04);
  --shadow: 0 4px 12px rgba(15, 23, 42, 0.06);
  --shadow-lg: 0 20px 40px rgba(15, 23, 42, 0.12);
}

* {
  box-sizing: border-box;
}

[hidden] {
  display: none !important;
}

html,
body {
  margin: 0;
  padding: 0;
  height: 100%;
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "PingFang SC", "Microsoft YaHei",
    "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  font-size: 14px;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
}

button {
  font: inherit;
  color: inherit;
  cursor: pointer;
}

input,
select,
button {
  font-family: inherit;
}

/* ---------- Login ---------- */

.auth-shell {
  min-height: 100vh;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 24px;
  background: linear-gradient(135deg, #ecfeff 0%, #f0fdfa 50%, #f8fafc 100%);
}

.auth-card {
  width: min(100%, 420px);
  background: var(--surface);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-lg);
  padding: 32px;
}

.auth-brand {
  display: flex;
  align-items: center;
  gap: 14px;
  margin-bottom: 28px;
}

.auth-logo {
  width: 44px;
  height: 44px;
  border-radius: 12px;
  background: var(--accent-gradient);
  color: #fff;
  display: flex;
  align-items: center;
  justify-content: center;
  font-weight: 700;
  font-size: 20px;
  letter-spacing: 0.5px;
}

.auth-title {
  margin: 0;
  font-size: 20px;
  font-weight: 600;
  color: var(--text);
}

.auth-subtitle {
  margin: 2px 0 0;
  font-size: 13px;
  color: var(--text-muted);
}

.auth-form {
  display: flex;
  flex-direction: column;
  gap: 16px;
}

.auth-field {
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.auth-field span {
  font-size: 12px;
  font-weight: 500;
  color: var(--text-muted);
}

.auth-field input {
  padding: 11px 13px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--surface);
  color: var(--text);
  font-size: 14px;
  transition: border-color 0.15s, box-shadow 0.15s;
}

.auth-field input:focus {
  outline: none;
  border-color: var(--primary);
  box-shadow: 0 0 0 3px var(--primary-soft);
}

.auth-error {
  min-height: 18px;
  color: var(--danger);
  font-size: 13px;
}

.captcha-row {
  display: grid;
  grid-template-columns: auto 1fr auto;
  gap: 8px;
  align-items: center;
}

.captcha-question {
  min-width: 88px;
  padding: 10px 12px;
  border-radius: var(--radius);
  background: var(--surface-soft);
  border: 1px solid var(--border);
  font-weight: 600;
  font-size: 14px;
  color: var(--primary-dark);
  text-align: center;
  user-select: none;
}

.captcha-row input {
  padding: 10px 11px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--surface);
  color: var(--text);
  font-size: 14px;
}

.captcha-row input:focus {
  outline: none;
  border-color: var(--primary);
  box-shadow: 0 0 0 3px var(--primary-soft);
}

.captcha-refresh {
  white-space: nowrap;
}

.auth-submit {
  margin-top: 4px;
  padding: 11px;
  font-size: 15px;
}

.auth-footer {
  margin-top: 18px;
  font-size: 12px;
  color: var(--text-muted);
}

/* ---------- Buttons & inputs ---------- */

.btn-primary {
  border: 0;
  background: var(--primary);
  color: #fff;
  padding: 9px 16px;
  border-radius: var(--radius);
  font-weight: 500;
  transition: background 0.15s, transform 0.15s;
}

.btn-primary:hover {
  background: var(--primary-dark);
}

.btn-primary:active {
  transform: translateY(1px);
}

.btn-primary:disabled {
  background: var(--border-strong);
  cursor: not-allowed;
}

.btn-ghost {
  background: transparent;
  border: 1px solid var(--border);
  color: var(--text);
  padding: 8px 14px;
  border-radius: var(--radius);
  font-weight: 500;
  transition: background 0.15s, border-color 0.15s, color 0.15s;
}

.btn-ghost:hover {
  background: var(--surface-hover);
  border-color: var(--border-strong);
}

.btn-sm {
  padding: 6px 12px;
  font-size: 13px;
}

.icon-btn {
  width: 36px;
  height: 36px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--surface);
  color: var(--text-muted);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  transition: background 0.15s, color 0.15s, border-color 0.15s;
}

.icon-btn:hover {
  background: var(--surface-hover);
  color: var(--text);
  border-color: var(--border-strong);
}

.icon-btn.ghost {
  border-color: transparent;
  background: transparent;
}

.icon-btn.ghost:hover {
  background: rgba(15, 23, 42, 0.06);
}

.input {
  padding: 8px 11px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--surface);
  color: var(--text);
  font-size: 13px;
  width: 100%;
}

.input:focus {
  outline: none;
  border-color: var(--primary);
  box-shadow: 0 0 0 3px var(--primary-soft);
}

/* ---------- App shell ---------- */

.app-shell {
  height: 100vh;
  display: flex;
  flex-direction: column;
  background: var(--bg);
}

.app-header {
  height: var(--header-height);
  flex: 0 0 auto;
  display: grid;
  grid-template-columns: minmax(180px, auto) 1fr minmax(380px, auto);
  align-items: center;
  gap: 16px;
  padding: 0 20px;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
}

.header-left,
.header-center,
.header-right {
  display: flex;
  align-items: center;
  gap: 12px;
}

.header-center {
  justify-content: center;
}

.header-right {
  justify-content: flex-end;
}

.sidebar-toggle {
  display: none;
}

.brand {
  display: flex;
  align-items: center;
  gap: 10px;
}

.brand-logo {
  width: 32px;
  height: 32px;
  border-radius: 9px;
  background: var(--accent-gradient);
  color: #fff;
  display: flex;
  align-items: center;
  justify-content: center;
  font-weight: 700;
  font-size: 15px;
}

.brand-name {
  font-weight: 600;
  font-size: 15px;
  letter-spacing: 0.2px;
}

.mailbox-chip {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  background: var(--primary-softer);
  border: 1px solid var(--primary-soft);
  border-radius: 999px;
  padding: 5px 8px 5px 12px;
  max-width: 100%;
  min-width: 0;
}

.mailbox-chip-icon {
  width: 22px;
  height: 22px;
  border-radius: 50%;
  background: var(--primary);
  color: #fff;
  font-size: 13px;
  display: flex;
  align-items: center;
  justify-content: center;
  flex: 0 0 auto;
}

.mailbox-chip-address {
  font-weight: 500;
  color: var(--primary-dark);
  font-size: 13px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  max-width: 320px;
}

.admin-badge {
  display: inline-flex;
  align-items: center;
  padding: 2px 8px;
  border-radius: 999px;
  background: var(--warning-soft);
  color: var(--warning);
  font-size: 11px;
  font-weight: 600;
}

.search-wrap {
  position: relative;
  display: flex;
  align-items: center;
  width: 280px;
}

.search-icon {
  position: absolute;
  left: 12px;
  color: var(--text-light);
  pointer-events: none;
}

.search-wrap input {
  width: 100%;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--surface-soft);
  padding: 8px 32px 8px 36px;
  font-size: 13px;
  color: var(--text);
  transition: border-color 0.15s, background 0.15s, box-shadow 0.15s;
}

.search-wrap input::placeholder {
  color: var(--text-light);
}

.search-wrap input:focus {
  outline: none;
  border-color: var(--primary);
  background: var(--surface);
  box-shadow: 0 0 0 3px var(--primary-soft);
}

.search-clear {
  position: absolute;
  right: 6px;
  border: 0;
  background: transparent;
  color: var(--text-light);
  font-size: 18px;
  width: 22px;
  height: 22px;
  border-radius: 50%;
}

.search-clear:hover {
  background: var(--surface-hover);
  color: var(--text);
}

.user-menu {
  position: relative;
}

.user-trigger {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  background: transparent;
  border: 1px solid transparent;
  border-radius: var(--radius);
  padding: 4px 10px 4px 4px;
  color: var(--text);
}

.user-trigger:hover {
  background: var(--surface-hover);
  border-color: var(--border);
}

.user-avatar {
  width: 30px;
  height: 30px;
  border-radius: 50%;
  background: var(--accent-gradient);
  color: #fff;
  font-weight: 600;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 13px;
}

.user-name {
  font-size: 13px;
  font-weight: 500;
}

.user-dropdown {
  position: absolute;
  top: calc(100% + 6px);
  right: 0;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  min-width: 140px;
  z-index: 20;
  padding: 6px;
}

.dropdown-item {
  width: 100%;
  border: 0;
  background: transparent;
  padding: 8px 10px;
  border-radius: var(--radius-sm);
  text-align: left;
  font-size: 13px;
  color: var(--text);
}

.dropdown-item:hover {
  background: var(--surface-hover);
}

/* ---------- Toast ---------- */

.copy-toast-wrap {
  position: fixed;
  top: calc(var(--header-height) + 12px);
  left: 0;
  right: 0;
  display: flex;
  justify-content: center;
  pointer-events: none;
  z-index: 40;
}

.copy-toast {
  background: rgba(15, 23, 42, 0.92);
  color: #fff;
  padding: 8px 16px;
  border-radius: 999px;
  font-size: 13px;
  opacity: 0;
  transform: translateY(-8px);
  transition: opacity 0.2s, transform 0.2s;
  box-shadow: var(--shadow-lg);
}

.copy-toast.show {
  opacity: 1;
  transform: translateY(0);
}

/* ---------- Body 3-pane ---------- */

.app-body {
  flex: 1;
  display: grid;
  grid-template-columns: var(--sidebar-width) minmax(320px, 1fr) var(--preview-width);
  min-height: 0;
  background: var(--bg);
}

/* ---------- Sidebar ---------- */

.sidebar {
  display: flex;
  flex-direction: column;
  background: var(--surface);
  border-right: 1px solid var(--border);
  overflow-y: auto;
  padding: 18px 16px 12px;
  gap: 22px;
}

.side-section-title {
  font-size: 11px;
  font-weight: 600;
  letter-spacing: 0.5px;
  text-transform: uppercase;
  color: var(--text-light);
  margin-bottom: 10px;
}

.mailbox-editor {
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.mailbox-editor-row {
  display: flex;
  align-items: center;
  gap: 6px;
}

.mailbox-editor-row .input {
  min-width: 0;
}

.mailbox-editor-row #localPart {
  flex: 1 1 0;
}

.mailbox-editor-row #domain {
  flex: 1.1 1 0;
}

.at-sign {
  color: var(--text-light);
  font-weight: 500;
}

.mailbox-editor-actions {
  display: flex;
  gap: 6px;
  flex-wrap: wrap;
}

.mailbox-editor-actions .btn-primary,
.mailbox-editor-actions .btn-ghost {
  flex: 1 1 auto;
}

.filter-list {
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.filter-item {
  display: flex;
  align-items: center;
  justify-content: space-between;
  border: 0;
  background: transparent;
  padding: 8px 10px;
  border-radius: var(--radius);
  font-size: 13px;
  color: var(--text);
  text-align: left;
}

.filter-item:hover {
  background: var(--surface-hover);
}

.filter-item.active {
  background: var(--primary-softer);
  color: var(--primary-dark);
  font-weight: 500;
}

.filter-count {
  font-size: 12px;
  color: var(--text-light);
  background: var(--surface-hover);
  padding: 0 7px;
  border-radius: 999px;
  min-width: 22px;
  text-align: center;
}

.filter-item.active .filter-count {
  background: var(--primary-soft);
  color: var(--primary-dark);
}

.view-toggle {
  display: flex;
  margin-top: 12px;
  background: var(--surface-soft);
  border-radius: var(--radius);
  padding: 3px;
  gap: 3px;
}

.view-btn {
  flex: 1;
  border: 0;
  background: transparent;
  padding: 7px;
  border-radius: 7px;
  font-size: 13px;
  color: var(--text-muted);
  transition: background 0.15s, color 0.15s;
}

.view-btn.active {
  background: var(--surface);
  color: var(--text);
  font-weight: 500;
  box-shadow: var(--shadow-sm);
}

.recent-list {
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.recent-item {
  width: 100%;
  border: 0;
  background: transparent;
  padding: 7px 10px;
  border-radius: var(--radius);
  font-size: 12.5px;
  color: var(--text);
  text-align: left;
  word-break: break-all;
  transition: background 0.15s, color 0.15s;
}

.recent-item:hover {
  background: var(--surface-hover);
}

.recent-item.active {
  background: var(--primary-softer);
  color: var(--primary-dark);
}

.side-empty {
  font-size: 12px;
  color: var(--text-light);
  padding: 4px 2px;
}

.side-footer {
  margin-top: auto;
  padding-top: 14px;
  border-top: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.side-meta {
  font-size: 11.5px;
  color: var(--text-light);
}

/* ---------- Message pane ---------- */

.message-pane {
  display: flex;
  flex-direction: column;
  background: var(--surface);
  border-right: 1px solid var(--border);
  min-width: 0;
}

.pane-header {
  flex: 0 0 auto;
  padding: 16px 20px 12px;
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 12px;
  border-bottom: 1px solid var(--border);
}

.pane-header-main {
  min-width: 0;
  flex: 1;
}

.pane-header-actions {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-shrink: 0;
}

.btn-mark-all-read {
  flex-shrink: 0;
  padding: 5px 12px;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background: var(--surface);
  color: var(--text-muted);
  font-size: 12px;
  font-weight: 500;
  cursor: pointer;
  transition: background 0.15s, border-color 0.15s, color 0.15s;
}

.btn-mark-all-read:hover:not(:disabled) {
  background: var(--surface-hover);
  border-color: var(--border-strong);
  color: var(--text);
}

.btn-mark-all-read:disabled {
  opacity: 0.55;
  cursor: not-allowed;
}

.pane-title {
  font-size: 16px;
  font-weight: 600;
  margin: 0;
}

.pane-subtitle {
  font-size: 12px;
  color: var(--text-muted);
  margin-top: 2px;
  min-height: 16px;
}

.new-mail-toast {
  font-size: 12px;
  font-weight: 500;
  color: var(--primary);
  background: var(--primary-softer);
  padding: 4px 10px;
  border-radius: 999px;
  opacity: 0;
  transition: opacity 0.4s;
}

.new-mail-toast.show {
  opacity: 1;
}

.message-list {
  flex: 1;
  overflow-y: auto;
  padding: 4px 0;
}

.message-item {
  display: grid;
  grid-template-columns: 32px 1fr auto;
  align-items: flex-start;
  gap: 12px;
  padding: 12px 18px;
  border-bottom: 1px solid var(--border);
  cursor: pointer;
  transition: background 0.12s;
  position: relative;
}

.message-item:hover {
  background: var(--surface-hover);
}

.message-item.selected {
  background: var(--primary-softer);
}

.message-item.selected::before {
  content: "";
  position: absolute;
  left: 0;
  top: 8px;
  bottom: 8px;
  width: 3px;
  background: var(--primary);
  border-radius: 0 2px 2px 0;
}

.message-avatar {
  width: 32px;
  height: 32px;
  border-radius: 50%;
  background: linear-gradient(135deg, #6366f1, #8b5cf6);
  color: #fff;
  font-size: 13px;
  font-weight: 600;
  display: flex;
  align-items: center;
  justify-content: center;
  flex: 0 0 32px;
}

.message-main {
  min-width: 0;
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.message-top {
  display: flex;
  align-items: center;
  gap: 8px;
}

.message-from-name {
  font-weight: 600;
  color: var(--text);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  flex: 1;
  min-width: 0;
}

.recipient-badge {
  flex: 0 1 auto;
  max-width: 180px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  border: 1px solid var(--border);
  background: var(--surface-soft);
  color: var(--text-muted);
  border-radius: 999px;
  padding: 1px 8px;
  font-size: 11px;
}

.message-subject {
  font-size: 13.5px;
  color: var(--text);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.message-preview {
  font-size: 12.5px;
  color: var(--text-muted);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.message-side {
  display: flex;
  flex-direction: column;
  align-items: flex-end;
  gap: 6px;
  min-width: 70px;
}

.message-date {
  font-size: 11.5px;
  color: var(--text-light);
  white-space: nowrap;
}

.unread-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--primary);
}

.message-item.message-read .message-from-name,
.message-item.message-read .message-subject {
  font-weight: 400;
  color: var(--text-muted);
}

.message-item.message-read .message-avatar {
  filter: saturate(0.4);
}

.empty-state {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  text-align: center;
  padding: 60px 24px;
  color: var(--text-muted);
}

.empty-icon {
  font-size: 36px;
  margin-bottom: 8px;
  filter: grayscale(0.2);
}

.empty-title {
  font-weight: 600;
  color: var(--text);
  font-size: 14px;
}

.empty-desc {
  margin-top: 4px;
  font-size: 12.5px;
  color: var(--text-muted);
  max-width: 280px;
}

.pagination {
  flex: 0 0 auto;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 10px 16px;
  border-top: 1px solid var(--border);
  background: var(--surface);
}

.pagination .btn-ghost:disabled {
  opacity: 0.5;
  cursor: not-allowed;
}

.page-info {
  font-size: 12px;
  color: var(--text-muted);
}

/* ---------- Sender groups (inline expansion) ---------- */

.sender-group {
  border-bottom: 1px solid var(--border);
}

.sender-group:last-child {
  border-bottom: none;
}

.sender-group-header {
  width: 100%;
  display: grid;
  grid-template-columns: 32px 1fr auto auto;
  align-items: center;
  gap: 12px;
  padding: 12px 18px;
  border: 0;
  background: transparent;
  text-align: left;
  transition: background 0.12s;
}

.sender-group-header:hover {
  background: var(--surface-hover);
}

.sender-group-expanded .sender-group-header {
  background: var(--surface-soft);
  border-bottom: 1px solid var(--border);
}

.sender-group-avatar {
  position: relative;
  width: 32px;
  height: 32px;
  border-radius: 50%;
  background: linear-gradient(135deg, #f59e0b, #ef4444);
  color: #fff;
  display: flex;
  align-items: center;
  justify-content: center;
  font-weight: 600;
  font-size: 13px;
}

.sender-unread-badge {
  position: absolute;
  top: -4px;
  right: -6px;
  min-width: 18px;
  height: 18px;
  padding: 0 5px;
  border-radius: 999px;
  background: var(--primary, #2563eb);
  color: #fff;
  font-size: 11px;
  font-weight: 600;
  line-height: 18px;
  text-align: center;
  border: 2px solid var(--surface, #fff);
  box-shadow: 0 0 0 1px rgba(37, 99, 235, 0.15);
}

.sender-group-has-unread .sender-title {
  color: var(--text);
}

.sender-group-has-unread .sender-latest {
  color: var(--text);
  font-weight: 500;
}

.sender-new-tag {
  display: inline-flex;
  align-items: center;
  margin-left: 6px;
  padding: 1px 7px;
  border-radius: 999px;
  background: linear-gradient(135deg, #ef4444, #f97316);
  color: #fff;
  font-size: 11px;
  font-weight: 600;
  letter-spacing: 0.2px;
  vertical-align: middle;
  animation: senderNewPulse 1.6s ease-in-out infinite;
}

@keyframes senderNewPulse {
  0%, 100% { box-shadow: 0 0 0 0 rgba(239, 68, 68, 0.45); }
  50% { box-shadow: 0 0 0 6px rgba(239, 68, 68, 0); }
}

.sender-group-new .sender-group-header {
  background: linear-gradient(90deg, rgba(239, 68, 68, 0.05), transparent 60%);
}

.sender-email-inline {
  color: var(--text-light);
  font-weight: 400;
  font-size: 12px;
  margin-left: 6px;
}

.sender-group-main {
  min-width: 0;
}

.sender-title {
  font-weight: 600;
  color: var(--text);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.sender-latest {
  font-size: 12.5px;
  color: var(--text-muted);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  margin-top: 2px;
}

.sender-recipient-summary {
  margin-top: 2px;
  color: var(--primary-dark);
  font-size: 12px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.sender-count {
  background: var(--surface-hover);
  color: var(--text-muted);
  border-radius: 999px;
  padding: 1px 9px;
  font-size: 12px;
  font-weight: 500;
}

.sender-group-expanded .sender-count {
  background: var(--primary-soft);
  color: var(--primary-dark);
}

.sender-chevron {
  width: 20px;
  height: 20px;
  color: var(--text-light);
  transition: transform 0.15s;
}

.sender-group-expanded .sender-chevron {
  transform: rotate(90deg);
}

.sender-group-body .message-item {
  padding-left: 56px;
  background: var(--surface-soft);
}

.sender-group-body .message-item:hover {
  background: var(--surface-hover);
}

.sender-group-body .message-item.selected {
  background: var(--primary-softer);
}

.sender-focus-btn {
  width: auto;
  margin: 8px 16px 14px 56px;
  padding: 6px 11px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  border: 1px solid var(--primary-soft, rgba(37, 99, 235, 0.18));
  background: var(--surface);
  color: var(--primary-dark, #1d4ed8);
  border-radius: 999px;
  font-size: 12.5px;
  font-weight: 600;
  cursor: pointer;
  box-shadow: var(--shadow-sm);
  transition: background 0.15s, border-color 0.15s, transform 0.05s,
    box-shadow 0.15s;
}

.sender-focus-btn:hover {
  background: var(--primary-softer, rgba(37, 99, 235, 0.14));
  border-color: var(--primary, #2563eb);
  box-shadow: 0 6px 16px rgba(37, 99, 235, 0.12);
}

.sender-focus-btn:active {
  transform: translateY(1px);
}

.sender-focus-btn svg {
  width: 13px;
  height: 13px;
}

.sender-focus-banner {
  display: flex;
  align-items: center;
  gap: 12px;
  margin: 8px 14px;
  padding: 10px 12px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow-sm);
  color: var(--text);
}

.sender-focus-back {
  flex-shrink: 0;
  display: inline-flex;
  align-items: center;
  gap: 5px;
  padding: 6px 10px;
  border-radius: 999px;
  border: 1px solid transparent;
  background: var(--surface-hover);
  color: var(--text-muted);
  font-size: 12px;
  font-weight: 600;
  line-height: 1.2;
  cursor: pointer;
  transition: background 0.15s, border-color 0.15s, color 0.15s;
}

.sender-focus-back:hover {
  background: var(--primary-softer, #eff6ff);
  border-color: var(--primary, #2563eb);
  color: var(--primary-dark, #1d4ed8);
}

.sender-focus-back svg {
  width: 13px;
  height: 13px;
  flex-shrink: 0;
}

.sender-focus-meta {
  display: flex;
  align-items: baseline;
  gap: 8px;
  min-width: 0;
  flex: 1;
}

.sender-focus-kicker {
  flex-shrink: 0;
  padding: 2px 7px;
  border-radius: 999px;
  background: var(--primary-softer, #eff6ff);
  font-size: 11px;
  font-weight: 600;
  letter-spacing: 0.02em;
  color: var(--primary-dark, #1d4ed8);
  line-height: 1.4;
}

.sender-focus-name {
  font-size: 14px;
  font-weight: 600;
  line-height: 1.35;
  color: var(--text);
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.sender-focus-email {
  font-size: 12px;
  line-height: 1.35;
  color: var(--text-muted);
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

@media (max-width: 520px) {
  .sender-focus-banner {
    flex-direction: column;
    align-items: stretch;
    gap: 10px;
    margin: 8px 10px;
    padding: 10px;
  }

  .sender-focus-back {
    align-self: flex-end;
    order: 2;
  }

  .sender-focus-meta {
    order: 1;
    flex-wrap: wrap;
    gap: 6px;
  }

  .sender-focus-name {
    white-space: normal;
    word-break: break-word;
  }

  .sender-focus-email {
    white-space: normal;
    word-break: break-all;
  }
}

/* ---------- Preview pane ---------- */

.preview-pane {
  display: flex;
  flex-direction: column;
  background: var(--surface);
  min-width: 0;
}

.preview-empty {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 40px;
  text-align: center;
}

.preview-content {
  display: flex;
  flex-direction: column;
  height: 100%;
  min-height: 0;
}

.preview-header {
  flex: 0 0 auto;
  padding: 16px 20px;
  border-bottom: 1px solid var(--border);
  display: grid;
  grid-template-columns: auto 1fr auto;
  gap: 12px;
  align-items: flex-start;
}

.preview-back {
  display: none;
}

.preview-titlebar {
  min-width: 0;
}

.preview-subject {
  margin: 0 0 8px;
  font-size: 16px;
  font-weight: 600;
  color: var(--text);
  word-break: break-word;
}

.preview-meta {
  display: grid;
  grid-template-columns: auto 1fr;
  gap: 4px 8px;
  font-size: 12.5px;
  color: var(--text);
}

.preview-meta > div {
  display: contents;
}

.preview-meta-label {
  color: var(--text-muted);
  font-size: 12px;
}

.preview-meta-value {
  word-break: break-all;
}

.preview-actions {
  display: flex;
  flex-direction: column;
  gap: 6px;
  align-items: flex-end;
}

.preview-body {
  flex: 1;
  min-height: 0;
  background: var(--bg);
}

.preview-frame {
  width: 100%;
  height: 100%;
  border: 0;
  background: #fff;
}

/* ---------- Responsive ---------- */

@media (max-width: 1280px) {
  :root {
    --sidebar-width: 240px;
  }

  .search-wrap {
    width: 220px;
  }

  .mailbox-chip-address {
    max-width: 220px;
  }
}

@media (max-width: 1024px) {
  .app-body {
    grid-template-columns: var(--sidebar-width) 1fr;
  }

  .preview-pane {
    position: fixed;
    inset: var(--header-height) 0 0 0;
    z-index: 30;
    transform: translateX(100%);
    transition: transform 0.22s ease;
    border-left: 1px solid var(--border);
    box-shadow: var(--shadow-lg);
  }

  .preview-pane.open {
    transform: translateX(0);
  }

  .preview-back {
    display: inline-flex;
  }
}

@media (max-width: 768px) {
  .app-header {
    grid-template-columns: auto 1fr auto;
    padding: 0 12px;
    gap: 8px;
  }

  .sidebar-toggle {
    display: inline-flex;
  }

  .brand-name {
    display: none;
  }

  .header-center {
    min-width: 0;
  }

  .header-right {
    gap: 6px;
  }

  .search-wrap {
    width: 160px;
  }

  .mailbox-chip-address {
    max-width: 140px;
    font-size: 12.5px;
  }

  .user-name {
    display: none;
  }

  .app-body {
    grid-template-columns: 1fr;
  }

  .sidebar {
    position: fixed;
    inset: var(--header-height) auto 0 0;
    width: 84vw;
    max-width: 320px;
    z-index: 35;
    transform: translateX(-100%);
    transition: transform 0.22s ease;
    box-shadow: var(--shadow-lg);
  }

  .sidebar.open {
    transform: translateX(0);
  }

  .sidebar-backdrop {
    position: fixed;
    inset: var(--header-height) 0 0 0;
    background: rgba(15, 23, 42, 0.4);
    z-index: 34;
    opacity: 0;
    pointer-events: none;
    transition: opacity 0.22s ease;
  }

  .sidebar-backdrop.show {
    opacity: 1;
    pointer-events: auto;
  }

  .pane-header {
    padding: 12px 14px 10px;
  }

  .message-item {
    padding: 10px 14px;
  }

  .sender-group-header {
    padding: 10px 14px;
  }

  .sender-group-body .message-item {
    padding-left: 50px;
  }

  .preview-header {
    padding: 12px 14px;
  }
}
