/* ========================================
   LingxiMail · 灵犀邮箱 样式系统
   设计风格：现代简约 + 紫罗兰主题 + 精致动效
   ======================================== */

/* ---------- CSS 变量 ---------- */
:root {
  /* 主题色 */
  --primary: #6366F1;
  --primary-dark: #4F46E5;
  --primary-light: #A5B4FC;
  --primary-bg: rgba(99, 102, 241, 0.08);
  
  /* 强调色 */
  --accent: #8B5CF6;
  --accent-bg: rgba(139, 92, 246, 0.1);
  
  /* 语义色 */
  --success: #10B981;
  --warning: #F59E0B;
  --danger: #EF4444;
  --info: #3B82F6;
  
  /* 中性色 */
  --bg: #F8FAFC;
  --bg-elev: #FFFFFF;
  --bg-hover: #F1F5F9;
  --bg-active: #E2E8F0;
  
  --border: #E2E8F0;
  --border-light: #F1F5F9;
  
  --text: #1E293B;
  --text-secondary: #64748B;
  --text-tertiary: #94A3B8;
  --text-inverse: #FFFFFF;
  
  /* 高亮色（搜索命中） */
  --highlight-bg: #FEF08A;
  --highlight-text: #92400E;
  
  /* 阴影 */
  --shadow-sm: 0 1px 2px rgba(15, 23, 42, 0.05);
  --shadow-md: 0 4px 6px -1px rgba(15, 23, 42, 0.08), 0 2px 4px -2px rgba(15, 23, 42, 0.06);
  --shadow-lg: 0 10px 15px -3px rgba(15, 23, 42, 0.1), 0 4px 6px -4px rgba(15, 23, 42, 0.08);
  --shadow-xl: 0 20px 25px -5px rgba(15, 23, 42, 0.1), 0 8px 10px -6px rgba(15, 23, 42, 0.08);
  
  /* 圆角 */
  --radius-sm: 6px;
  --radius-md: 8px;
  --radius-lg: 12px;
  --radius-xl: 16px;
  
  /* 尺寸 */
  --sidebar-w: 240px;
  --list-w: 380px;
  --topbar-h: 60px;
  
  /* 过渡 */
  --ease: cubic-bezier(0.4, 0, 0.2, 1);
  --ease-in-out: cubic-bezier(0.4, 0, 0.2, 1);
  
  /* 字体 */
  --font-sans: 'Noto Sans SC', -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
  --font-mono: 'JetBrains Mono', 'Fira Code', monospace;
}

/* ---------- 重置 & 基础 ---------- */
*, *::before, *::after {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

html {
  font-size: 14px;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
}

body {
  font-family: var(--font-sans);
  color: var(--text);
  background: var(--bg);
  line-height: 1.5;
  overflow: hidden;
  height: 100vh;
}

.hidden { display: none !important; }

button {
  font-family: inherit;
  cursor: pointer;
  border: none;
  background: none;
  color: inherit;
}

a {
  color: var(--primary);
  text-decoration: none;
  transition: color 0.15s var(--ease);
}
a:hover { color: var(--primary-dark); }

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

/* ========== 登录/注册页 ========== */
.auth-view {
  position: fixed;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
  z-index: 100;
}

.auth-bg {
  position: absolute;
  inset: 0;
  overflow: hidden;
}

.blob {
  position: absolute;
  border-radius: 50%;
  filter: blur(80px);
  opacity: 0.4;
  animation: float 20s ease-in-out infinite;
}

.blob-1 {
  width: 400px;
  height: 400px;
  background: #A78BFA;
  top: -100px;
  left: -100px;
  animation-delay: 0s;
}

.blob-2 {
  width: 350px;
  height: 350px;
  background: #60A5FA;
  bottom: -80px;
  right: -80px;
  animation-delay: -5s;
}

.blob-3 {
  width: 300px;
  height: 300px;
  background: #F472B6;
  top: 40%;
  left: 50%;
  animation-delay: -10s;
}

@keyframes float {
  0%, 100% { transform: translate(0, 0) scale(1); }
  33% { transform: translate(30px, -50px) scale(1.1); }
  66% { transform: translate(-20px, 30px) scale(0.9); }
}

.auth-card {
  position: relative;
  width: 420px;
  padding: 48px 40px;
  background: rgba(255, 255, 255, 0.95);
  border-radius: var(--radius-xl);
  box-shadow: var(--shadow-xl), 0 25px 50px -12px rgba(0, 0, 0, 0.25);
  backdrop-filter: blur(20px);
  animation: slideUp 0.5s var(--ease) both;
}

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

.auth-header {
  text-align: center;
  margin-bottom: 36px;
}

.logo {
  display: inline-flex;
  justify-content: center;
  align-items: center;
  width: 64px;
  height: 64px;
  background: linear-gradient(135deg, var(--primary) 0%, var(--accent) 100%);
  border-radius: 16px;
  margin-bottom: 16px;
  box-shadow: 0 8px 24px rgba(99, 102, 241, 0.4);
}

.logo svg {
  filter: drop-shadow(0 2px 4px rgba(0, 0, 0, 0.1));
}

.auth-title {
  font-size: 1.75rem;
  font-weight: 700;
  background: linear-gradient(135deg, var(--primary) 0%, var(--accent) 100%);
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  background-clip: text;
  margin-bottom: 4px;
}

.auth-subtitle {
  color: var(--text-secondary);
  font-size: 0.9rem;
}

.auth-form {
  display: flex;
  flex-direction: column;
  gap: 16px;
}

.form-group {
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.form-group label {
  font-size: 0.8rem;
  font-weight: 500;
  color: var(--text-secondary);
}

.form-group input[type="text"],
.form-group input[type="password"],
.form-group input[type="email"],
.form-group input[type="number"],
.form-group select,
.form-group textarea {
  padding: 10px 14px;
  border: 1.5px solid var(--border);
  border-radius: var(--radius-md);
  background: var(--bg);
  color: var(--text);
  transition: all 0.2s var(--ease);
  outline: none;
}

.form-group input:focus,
.form-group select:focus,
.form-group textarea:focus {
  border-color: var(--primary);
  background: var(--bg-elev);
  box-shadow: 0 0 0 3px var(--primary-bg);
}

.form-hint {
  font-size: 0.75rem;
  color: var(--text-tertiary);
}

.auth-switch {
  text-align: center;
  margin-top: 8px;
  font-size: 0.85rem;
  color: var(--text-secondary);
}

.auth-error {
  margin-top: 16px;
  padding: 10px 14px;
  background: #FEF2F2;
  border: 1px solid #FECACA;
  border-radius: var(--radius-md);
  color: var(--danger);
  font-size: 0.85rem;
  text-align: center;
  animation: shake 0.4s var(--ease);
}

@keyframes shake {
  0%, 100% { transform: translateX(0); }
  25% { transform: translateX(-4px); }
  75% { transform: translateX(4px); }
}

/* ---------- 按钮 ---------- */
.btn-primary {
  padding: 11px 20px;
  background: linear-gradient(135deg, var(--primary) 0%, var(--accent) 100%);
  color: var(--text-inverse);
  font-weight: 600;
  border-radius: var(--radius-md);
  transition: all 0.2s var(--ease);
  box-shadow: 0 2px 8px rgba(99, 102, 241, 0.3);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
}

.btn-primary:hover {
  transform: translateY(-1px);
  box-shadow: 0 4px 12px rgba(99, 102, 241, 0.4);
}

.btn-primary:active {
  transform: translateY(0);
}

.btn-primary:disabled {
  opacity: 0.6;
  cursor: not-allowed;
  transform: none;
}

.btn-secondary {
  padding: 10px 20px;
  background: var(--bg-hover);
  color: var(--text);
  font-weight: 500;
  border-radius: var(--radius-md);
  transition: all 0.2s var(--ease);
  border: 1.5px solid var(--border);
}

.btn-secondary:hover {
  background: var(--bg-active);
  border-color: var(--primary-light);
}

.btn-danger {
  padding: 10px 20px;
  background: var(--danger);
  color: var(--text-inverse);
  font-weight: 500;
  border-radius: var(--radius-md);
  transition: all 0.2s var(--ease);
}

.btn-danger:hover {
  background: #DC2626;
}

.btn-block {
  width: 100%;
}

/* ========== 主界面 ========== */
.main-view {
  display: flex;
  flex-direction: column;
  height: 100vh;
  background: var(--bg);
}

/* ---------- 顶部导航栏 ---------- */
.topbar {
  height: var(--topbar-h);
  background: var(--bg-elev);
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 20px;
  z-index: 50;
  flex-shrink: 0;
}

.topbar-left {
  display: flex;
  align-items: center;
  gap: 20px;
  flex: 1;
  max-width: 720px;
}

.logo-sm {
  display: flex;
  align-items: center;
}

.search-box {
  position: relative;
  flex: 1;
  display: flex;
  align-items: center;
  gap: 8px;
}

.search-icon {
  position: absolute;
  left: 14px;
  color: var(--text-tertiary);
  pointer-events: none;
}

.search-box input {
  width: 100%;
  padding: 9px 90px 9px 42px;
  border: 1.5px solid var(--border);
  border-radius: 24px;
  background: var(--bg);
  transition: all 0.2s var(--ease);
  outline: none;
  font-size: 0.875rem;
}

.search-box input:focus {
  border-color: var(--primary);
  background: var(--bg-elev);
  box-shadow: 0 0 0 3px var(--primary-bg);
}

.search-btn {
  position: absolute;
  right: 8px;
  padding: 6px 14px;
  background: var(--primary);
  color: var(--text-inverse);
  font-size: 0.8rem;
  font-weight: 500;
  border-radius: 20px;
  transition: all 0.2s var(--ease);
}

.search-btn:hover {
  background: var(--primary-dark);
}

.search-clear {
  position: absolute;
  right: 54px;
  color: var(--text-tertiary);
  padding: 4px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  transition: all 0.15s var(--ease);
}

.search-clear:hover {
  background: var(--bg-hover);
  color: var(--text-secondary);
}

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

.btn-compose {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 8px 16px;
  background: linear-gradient(135deg, var(--primary) 0%, var(--accent) 100%);
  color: var(--text-inverse);
  font-weight: 500;
  font-size: 0.875rem;
  border-radius: 24px;
  transition: all 0.2s var(--ease);
  box-shadow: 0 2px 8px rgba(99, 102, 241, 0.3);
}

.btn-compose:hover {
  transform: translateY(-1px);
  box-shadow: 0 4px 12px rgba(99, 102, 241, 0.4);
}

.icon-btn {
  width: 36px;
  height: 36px;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: 50%;
  color: var(--text-secondary);
  transition: all 0.15s var(--ease);
}

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

.user-dropdown {
  position: relative;
}

.user-btn {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 4px 12px 4px 4px;
  border-radius: 24px;
  transition: all 0.15s var(--ease);
}

.user-btn:hover {
  background: var(--bg-hover);
}

.avatar {
  width: 32px;
  height: 32px;
  border-radius: 50%;
  background: linear-gradient(135deg, var(--primary) 0%, var(--accent) 100%);
  color: var(--text-inverse);
  font-weight: 600;
  font-size: 0.85rem;
  display: flex;
  align-items: center;
  justify-content: center;
}

.user-name {
  font-weight: 500;
  font-size: 0.85rem;
}

.user-menu {
  position: absolute;
  top: calc(100% + 8px);
  right: 0;
  min-width: 160px;
  background: var(--bg-elev);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  box-shadow: var(--shadow-lg);
  padding: 6px;
  animation: menuOpen 0.15s var(--ease);
}

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

.user-menu a {
  display: block;
  padding: 8px 12px;
  border-radius: var(--radius-sm);
  font-size: 0.85rem;
  color: var(--text);
  transition: all 0.15s var(--ease);
}

.user-menu a:hover {
  background: var(--bg-hover);
  color: var(--primary);
}

.role-badge {
  font-size: 0.65rem;
  font-weight: 600;
  padding: 2px 6px;
  border-radius: 10px;
  background: var(--primary);
  color: var(--text-inverse);
  margin-left: 4px;
  letter-spacing: 0.02em;
}

.user-btn .role-badge {
  background: var(--primary-light);
  color: var(--primary-dark);
}

/* ---------- 主体布局 ---------- */
.main-body {
  flex: 1;
  display: flex;
  overflow: hidden;
}

/* ---------- 左侧文件夹栏 ---------- */
.sidebar {
  width: var(--sidebar-w);
  background: var(--bg-elev);
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  flex-shrink: 0;
  padding: 16px 12px;
}

.folder-nav {
  flex: 1;
  overflow-y: auto;
}

.folder-section {
  margin-bottom: 20px;
}

.folder-section-title {
  font-size: 0.7rem;
  font-weight: 600;
  color: var(--text-tertiary);
  text-transform: uppercase;
  letter-spacing: 0.08em;
  padding: 8px 12px 6px;
}

.folder-item {
  display: flex;
  align-items: center;
  gap: 12px;
  width: 100%;
  padding: 9px 12px;
  border-radius: var(--radius-md);
  font-size: 0.875rem;
  color: var(--text-secondary);
  transition: all 0.15s var(--ease);
  margin-bottom: 2px;
}

.folder-item:hover {
  background: var(--bg-hover);
  color: var(--text);
}

.folder-item.active {
  background: var(--primary-bg);
  color: var(--primary);
  font-weight: 500;
}

.folder-item svg {
  flex-shrink: 0;
}

.folder-item span:last-child {
  flex: 1;
  text-align: left;
}

.badge {
  min-width: 20px;
  padding: 2px 6px;
  background: var(--danger);
  color: var(--text-inverse);
  font-size: 0.7rem;
  font-weight: 600;
  border-radius: 10px;
  text-align: center;
}

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

.btn-refresh {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  width: 100%;
  padding: 8px;
  font-size: 0.8rem;
  color: var(--text-secondary);
  border-radius: var(--radius-md);
  transition: all 0.15s var(--ease);
}

.btn-refresh:hover {
  background: var(--bg-hover);
  color: var(--primary);
}

.btn-refresh.loading svg {
  animation: spin 1s linear infinite;
}

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

/* ---------- 邮件列表面板 ---------- */
.mail-list-panel {
  width: var(--list-w);
  background: var(--bg-elev);
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  flex-shrink: 0;
  overflow: hidden;
}

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

.list-title {
  font-size: 1.1rem;
  font-weight: 600;
  margin-bottom: 4px;
}

.list-meta {
  font-size: 0.75rem;
  color: var(--text-tertiary);
}

.list-toolbar {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 8px 14px;
  border-bottom: 1px solid var(--border-light);
  justify-content: space-between;
}

.divider {
  width: 1px;
  height: 20px;
  background: var(--border);
}

.icon-btn-sm {
  width: 30px;
  height: 30px;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: var(--radius-sm);
  color: var(--text-tertiary);
  transition: all 0.15s var(--ease);
}

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

.icon-btn-sm:disabled {
  opacity: 0.4;
  cursor: not-allowed;
}

.sort-toggle {
  display: flex;
  align-items: center;
  gap: 6px;
}

.page-info {
  font-size: 0.8rem;
  color: var(--text-secondary);
  min-width: 40px;
  text-align: center;
}

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

/* 邮件列表项 */
.mail-item {
  display: flex;
  flex-direction: column;
  gap: 4px;
  padding: 12px 18px;
  border-bottom: 1px solid var(--border-light);
  cursor: pointer;
  transition: all 0.15s var(--ease);
  position: relative;
}

.mail-item:hover {
  background: var(--bg-hover);
}

.mail-item.selected {
  background: var(--primary-bg);
}

.mail-item.unread .mail-from,
.mail-item.unread .mail-subject {
  font-weight: 600;
}

.mail-item.unread::before {
  content: '';
  position: absolute;
  left: 0;
  top: 50%;
  transform: translateY(-50%);
  width: 3px;
  height: 24px;
  background: var(--primary);
  border-radius: 0 2px 2px 0;
}

.mail-item.starred {
  background: #FFFBEB;
}

.mail-top {
  display: flex;
  align-items: center;
  gap: 8px;
}

.mail-from {
  flex: 1;
  font-size: 0.875rem;
  color: var(--text);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.mail-star {
  color: var(--text-tertiary);
  flex-shrink: 0;
  transition: all 0.15s var(--ease);
}

.mail-item.starred .mail-star {
  color: var(--warning);
  fill: var(--warning);
}

.mail-time {
  font-size: 0.7rem;
  color: var(--text-tertiary);
  flex-shrink: 0;
}

.mail-subject {
  font-size: 0.85rem;
  color: var(--text);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.mail-item.unread .mail-subject {
  color: var(--text);
}

.mail-item.read .mail-subject {
  color: var(--text-secondary);
}

.mail-snippet {
  font-size: 0.8rem;
  color: var(--text-tertiary);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.mail-attach {
  display: inline-flex;
  align-items: center;
  color: var(--text-tertiary);
  flex-shrink: 0;
}

/* 搜索高亮 */
mark.hl {
  background: var(--highlight-bg);
  color: var(--highlight-text);
  padding: 0 1px;
  border-radius: 2px;
  font-weight: inherit;
}

/* 列表空状态 & 加载 */
.list-empty, .list-loading {
  position: absolute;
  inset: 130px 0 0 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 16px;
  color: var(--text-tertiary);
}

.list-empty p {
  font-size: 0.9rem;
}

.spinner {
  width: 32px;
  height: 32px;
  border: 3px solid var(--border);
  border-top-color: var(--primary);
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
}

/* ---------- 邮件详情面板 ---------- */
.mail-detail-panel {
  flex: 1;
  background: var(--bg);
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

.detail-empty {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 20px;
  color: var(--text-tertiary);
}

.detail-empty p {
  font-size: 0.9rem;
}

.detail-content {
  flex: 1;
  overflow-y: auto;
  background: var(--bg-elev);
  margin: 20px;
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-sm);
  border: 1px solid var(--border-light);
}

.detail-toolbar {
  position: sticky;
  top: 0;
  display: flex;
  gap: 4px;
  padding: 10px 16px;
  background: var(--bg-elev);
  border-bottom: 1px solid var(--border-light);
  z-index: 10;
}

.detail-header {
  padding: 20px 28px 16px;
  border-bottom: 1px solid var(--border-light);
}

.detail-subject {
  font-size: 1.25rem;
  font-weight: 600;
  margin-bottom: 16px;
  line-height: 1.4;
}

.detail-meta {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 16px;
  margin-bottom: 8px;
}

.detail-sender {
  display: flex;
  align-items: center;
  gap: 12px;
}

.avatar-sm {
  width: 36px;
  height: 36px;
  border-radius: 50%;
  background: linear-gradient(135deg, var(--primary) 0%, var(--accent) 100%);
  color: var(--text-inverse);
  font-weight: 600;
  font-size: 0.85rem;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
}

.sender-info {
  display: flex;
  flex-direction: column;
}

.sender-name {
  font-weight: 500;
  font-size: 0.9rem;
}

.sender-addr {
  font-size: 0.78rem;
  color: var(--text-tertiary);
}

.detail-time {
  font-size: 0.8rem;
  color: var(--text-tertiary);
  white-space: nowrap;
  padding-top: 4px;
}

.detail-to, .detail-cc {
  font-size: 0.82rem;
  color: var(--text-secondary);
  padding-top: 4px;
}

.detail-to span.label, .detail-cc span.label {
  color: var(--text-tertiary);
  margin-right: 6px;
}

.detail-body {
  padding: 24px 28px;
  font-size: 0.92rem;
  line-height: 1.7;
  color: var(--text);
  word-break: break-word;
}

.detail-body img {
  max-width: 100%;
  height: auto;
  border-radius: var(--radius-sm);
  margin: 8px 0;
}

.detail-body pre {
  background: var(--bg);
  padding: 12px 16px;
  border-radius: var(--radius-md);
  overflow-x: auto;
  font-family: var(--font-mono);
  font-size: 0.82rem;
  margin: 12px 0;
}

.detail-body blockquote {
  border-left: 3px solid var(--primary-light);
  padding-left: 16px;
  margin: 12px 0;
  color: var(--text-secondary);
}

.detail-body a {
  color: var(--primary);
  text-decoration: underline;
}

.detail-attachments {
  padding: 16px 28px 24px;
  border-top: 1px solid var(--border-light);
}

.detail-attachments:empty {
  display: none;
}

.attach-title {
  font-size: 0.8rem;
  font-weight: 500;
  color: var(--text-secondary);
  margin-bottom: 10px;
}

.attach-item {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 10px 14px;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  margin-bottom: 8px;
  transition: all 0.15s var(--ease);
}

.attach-item:hover {
  border-color: var(--primary-light);
  background: var(--primary-bg);
}

.attach-icon {
  width: 36px;
  height: 36px;
  background: var(--primary-bg);
  border-radius: var(--radius-sm);
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--primary);
  flex-shrink: 0;
}

.attach-info {
  flex: 1;
  min-width: 0;
}

.attach-name {
  font-size: 0.85rem;
  font-weight: 500;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.attach-size {
  font-size: 0.75rem;
  color: var(--text-tertiary);
}

.attach-download {
  padding: 6px 12px;
  background: var(--primary);
  color: var(--text-inverse);
  font-size: 0.8rem;
  font-weight: 500;
  border-radius: var(--radius-sm);
  transition: all 0.15s var(--ease);
}

.attach-download:hover {
  background: var(--primary-dark);
}

/* ========== 模态框 ========== */
.modal {
  position: fixed;
  inset: 0;
  z-index: 200;
  display: flex;
  align-items: center;
  justify-content: center;
  animation: fadeIn 0.2s var(--ease);
}

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

.modal-backdrop {
  position: absolute;
  inset: 0;
  background: rgba(15, 23, 42, 0.5);
  backdrop-filter: blur(4px);
}

.modal-content {
  position: relative;
  background: var(--bg-elev);
  border-radius: var(--radius-xl);
  box-shadow: var(--shadow-xl);
  max-height: 90vh;
  display: flex;
  flex-direction: column;
  animation: modalIn 0.25s var(--ease);
}

@keyframes modalIn {
  from {
    opacity: 0;
    transform: scale(0.95) translateY(10px);
  }
  to {
    opacity: 1;
    transform: scale(1) translateY(0);
  }
}

.modal-sm { width: 360px; }
.modal-md { width: 480px; }
.modal-lg { width: 600px; }
.modal-xl { width: 760px; }

.modal-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 18px 24px;
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
}

.modal-header h2 {
  font-size: 1.05rem;
  font-weight: 600;
}

.modal-close {
  width: 32px;
  height: 32px;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: 50%;
  color: var(--text-tertiary);
  transition: all 0.15s var(--ease);
}

.modal-close:hover {
  background: var(--bg-hover);
  color: var(--text);
}

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

.mt-4 { margin-top: 16px; }

.form-row {
  display: flex;
  gap: 12px;
  margin-bottom: 4px;
}

.form-row .form-group:first-child { flex: 1; }

.form-group-sm {
  width: 90px;
  flex-shrink: 0;
}

.form-group-check {
  width: auto;
  flex-direction: row;
  align-items: center;
  gap: 8px;
}

.form-group-check label {
  font-size: 0.85rem;
  color: var(--text);
  font-weight: normal;
}

.form-actions {
  display: flex;
  justify-content: flex-end;
  gap: 12px;
  margin-top: 20px;
}

.checkbox-label {
  display: flex;
  align-items: center;
  gap: 8px;
  cursor: pointer;
  font-size: 0.85rem;
  color: var(--text-secondary);
}

.checkbox-label input[type="checkbox"] {
  width: 16px;
  height: 16px;
  accent-color: var(--primary);
}

/* Switch */
.switch {
  position: relative;
  display: inline-block;
  width: 40px;
  height: 22px;
}

.switch input {
  opacity: 0;
  width: 0;
  height: 0;
}

.slider {
  position: absolute;
  inset: 0;
  background: var(--bg-active);
  border-radius: 22px;
  transition: all 0.2s var(--ease);
  cursor: pointer;
}

.slider::before {
  content: '';
  position: absolute;
  width: 18px;
  height: 18px;
  left: 2px;
  bottom: 2px;
  background: white;
  border-radius: 50%;
  transition: all 0.2s var(--ease);
  box-shadow: var(--shadow-sm);
}

.switch input:checked + .slider {
  background: var(--primary);
}

.switch input:checked + .slider::before {
  transform: translateX(18px);
}

/* 账户列表 */
.accounts-list {
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.account-card {
  display: flex;
  align-items: center;
  gap: 14px;
  padding: 14px 16px;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  transition: all 0.15s var(--ease);
}

.account-card:hover {
  border-color: var(--primary-light);
  box-shadow: var(--shadow-sm);
}

.account-card-default {
  border-color: var(--primary-light);
  background: var(--primary-bg);
}

.account-icon {
  width: 44px;
  height: 44px;
  border-radius: 10px;
  background: linear-gradient(135deg, var(--primary) 0%, var(--accent) 100%);
  color: white;
  display: flex;
  align-items: center;
  justify-content: center;
  font-weight: 600;
  flex-shrink: 0;
}

.account-info {
  flex: 1;
  min-width: 0;
}

.account-addr {
  font-size: 0.9rem;
  font-weight: 500;
  margin-bottom: 2px;
}

.account-meta {
  font-size: 0.75rem;
  color: var(--text-tertiary);
  display: flex;
  gap: 10px;
}

.account-default-badge {
  display: inline-block;
  padding: 1px 8px;
  background: var(--primary);
  color: white;
  font-size: 0.7rem;
  border-radius: 10px;
  margin-left: 6px;
}

.account-actions {
  display: flex;
  gap: 4px;
}

.account-actions button {
  padding: 6px 8px;
  border-radius: var(--radius-sm);
  color: var(--text-tertiary);
  transition: all 0.15s var(--ease);
}

.account-actions button:hover {
  background: var(--bg-hover);
  color: var(--text);
}

.account-actions button.danger:hover {
  background: #FEF2F2;
  color: var(--danger);
}

/* 同步状态 */
.sync-status {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  font-size: 0.75rem;
  padding: 2px 8px;
  border-radius: 10px;
}

.sync-status.idle {
  background: var(--bg-hover);
  color: var(--text-secondary);
}

.sync-status.syncing {
  background: #DBEAFE;
  color: var(--info);
}

.sync-status.success {
  background: #D1FAE5;
  color: var(--success);
}

.sync-status.error {
  background: #FEE2E2;
  color: var(--danger);
}

/* 写邮件 */
.compose-modal .modal-body {
  padding: 24px;
}

.compose-field {
  margin-bottom: 16px;
}

.compose-field label {
  display: block;
  font-size: 0.78rem;
  font-weight: 500;
  color: var(--text-secondary);
  margin-bottom: 6px;
}

.compose-field input,
.compose-field select,
.compose-field textarea {
  width: 100%;
  padding: 10px 14px;
  border: 1.5px solid var(--border);
  border-radius: var(--radius-md);
  background: var(--bg);
  outline: none;
  transition: all 0.2s var(--ease);
}

.compose-field input:focus,
.compose-field select:focus,
.compose-field textarea:focus {
  border-color: var(--primary);
  background: var(--bg-elev);
  box-shadow: 0 0 0 3px var(--primary-bg);
}

.compose-body textarea {
  min-height: 220px;
  resize: vertical;
  font-size: 0.9rem;
  line-height: 1.7;
}

.compose-actions {
  display: flex;
  justify-content: flex-end;
  gap: 12px;
  padding-top: 8px;
}

/* ========== Toast ========== */
.toast-container {
  position: fixed;
  top: 80px;
  right: 20px;
  z-index: 300;
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.toast {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 12px 18px;
  background: var(--bg-elev);
  border-radius: var(--radius-md);
  box-shadow: var(--shadow-lg);
  border-left: 4px solid;
  min-width: 280px;
  animation: toastIn 0.3s var(--ease);
}

.toast.success { border-color: var(--success); }
.toast.error { border-color: var(--danger); }
.toast.info { border-color: var(--info); }
.toast.warning { border-color: var(--warning); }

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

.toast-icon {
  flex-shrink: 0;
}

.toast.success .toast-icon { color: var(--success); }
.toast.error .toast-icon { color: var(--danger); }
.toast.info .toast-icon { color: var(--info); }
.toast.warning .toast-icon { color: var(--warning); }

.toast-msg {
  flex: 1;
  font-size: 0.875rem;
}

/* ========== 滚动条美化 ========== */
::-webkit-scrollbar {
  width: 8px;
  height: 8px;
}

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

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

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

/* ========== 管理后台 ========== */
.admin-stats {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 14px;
  margin-bottom: 24px;
}

.stat-card {
  display: flex;
  align-items: center;
  gap: 14px;
  padding: 16px;
  background: var(--bg);
  border: 1px solid var(--border-light);
  border-radius: var(--radius-lg);
  transition: all 0.15s var(--ease);
}

.stat-card:hover {
  border-color: var(--primary-light);
  box-shadow: var(--shadow-sm);
}

.stat-icon {
  width: 44px;
  height: 44px;
  border-radius: 10px;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  color: white;
}

.stat-users { background: linear-gradient(135deg, #3B82F6, #6366F1); }
.stat-admin { background: linear-gradient(135deg, #8B5CF6, #6366F1); }
.stat-acct { background: linear-gradient(135deg, #10B981, #059669); }
.stat-mails { background: linear-gradient(135deg, #F59E0B, #D97706); }

.stat-value {
  font-size: 1.5rem;
  font-weight: 700;
  line-height: 1.2;
  color: var(--text);
}

.stat-label {
  font-size: 0.75rem;
  color: var(--text-tertiary);
}

.admin-section {
  margin-top: 8px;
}

.admin-section-title {
  display: flex;
  align-items: center;
  justify-content: space-between;
  font-size: 0.95rem;
  font-weight: 600;
  margin-bottom: 12px;
  color: var(--text);
}

.btn-sm {
  padding: 4px 12px;
  font-size: 0.78rem;
}

.admin-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.85rem;
}

.admin-table thead th {
  text-align: left;
  padding: 10px 12px;
  font-weight: 500;
  color: var(--text-tertiary);
  font-size: 0.75rem;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  border-bottom: 1px solid var(--border);
  background: var(--bg);
}

.admin-table tbody tr {
  transition: background 0.1s var(--ease);
  border-bottom: 1px solid var(--border-light);
}

.admin-table tbody tr:hover {
  background: var(--bg-hover);
}

.admin-table tbody td {
  padding: 12px;
  color: var(--text);
}

.role-tag {
  display: inline-block;
  padding: 2px 10px;
  border-radius: 10px;
  font-size: 0.72rem;
  font-weight: 600;
}

.role-tag.admin {
  background: var(--primary-bg);
  color: var(--primary);
}

.role-tag.user {
  background: var(--bg-hover);
  color: var(--text-secondary);
}

.admin-row-actions {
  display: flex;
  gap: 4px;
}

.admin-row-actions button {
  padding: 4px 10px;
  border-radius: var(--radius-sm);
  font-size: 0.78rem;
  color: var(--text-secondary);
  transition: all 0.15s var(--ease);
}

.admin-row-actions button:hover {
  background: var(--bg-hover);
  color: var(--text);
}

.admin-row-actions button.danger:hover {
  background: #FEF2F2;
  color: var(--danger);
}

/* ========== 响应式 ========== */
@media (max-width: 1024px) {
  :root {
    --sidebar-w: 60px;
    --list-w: 320px;
  }
  .folder-item span,
  .folder-section-title,
  .badge {
    display: none;
  }
  .folder-item {
    justify-content: center;
  }
  .search-box input {
    padding-right: 42px;
  }
  .search-btn {
    display: none;
  }
}

@media (max-width: 768px) {
  .main-body {
    flex-direction: column;
  }
  :root {
    --sidebar-w: 100%;
    --list-w: 100%;
  }
  .sidebar {
    flex-direction: row;
    padding: 8px;
    width: 100%;
    height: 56px;
    border-right: none;
    border-bottom: 1px solid var(--border);
    overflow-x: auto;
  }
  .folder-nav {
    display: flex;
    gap: 4px;
  }
  .folder-section {
    display: flex;
    gap: 4px;
    margin-bottom: 0;
  }
  .folder-section-title {
    display: none;
  }
  .sidebar-footer {
    display: none;
  }
  .topbar-right .user-name,
  .btn-compose span {
    display: none;
  }
  .detail-content {
    margin: 12px;
  }
}

/* ========== 登录页响应式 ========== */
@media (max-width: 560px) {
  .auth-view {
    padding: 72px 16px 40px;
    align-items: flex-start;
  }

  .auth-card {
    width: 100%;
    padding: 28px 22px;
    border-radius: 18px;
  }

  .auth-header { margin-bottom: 24px; }
  .logo { width: 52px; height: 52px; border-radius: 14px; margin-bottom: 12px; }
  .logo svg { width: 32px; height: 32px; }
  .auth-title { font-size: 1.45rem; }
  .auth-subtitle { font-size: 0.84rem; }
  .auth-form { gap: 14px; }
  .btn-primary.btn-block { padding: 12px; }

  .auth-footer {
    position: static;
    transform: none;
    margin: 18px 0 24px;
    text-align: center;
    width: 100%;
  }

  .back-home-wrap { top: 16px; left: 16px; }
}

