* {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

:root {
  color-scheme: dark;
  --bg-base: #0f172a;
  --bg-sidebar: #0c1424;
  --bg-card: #1e293b;
  --bg-hover: #273548;
  --bg-active: #1e3a5f;
  --border: #334155;
  --border-light: #1e293b;
  --text-primary: #f1f5f9;
  --text-secondary: #94a3b8;
  --text-muted: #64748b;
  --accent: #3b82f6;
  --accent-light: #1e3a5f;
  --accent-hover: #60a5fa;
  --danger: #ef4444;
  --danger-hover: #f87171;
  --shadow-sm: 0 1px 3px rgba(0,0,0,0.3);
  --shadow-md: 0 4px 12px rgba(0,0,0,0.35);
  --radius-sm: 6px;
  --radius-md: 10px;
  --radius-lg: 14px;
  --font: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', 'PingFang SC', 'Microsoft YaHei', sans-serif;
}

body {
  font-family: var(--font);
  background: var(--bg-base);
  color: var(--text-primary);
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
}

.hidden {
  display: none !important;
}

.login-screen {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px;
  background:
    radial-gradient(circle at top, rgba(59, 130, 246, 0.18), transparent 32%),
    linear-gradient(180deg, #0b1220 0%, #0f172a 100%);
}

.login-card {
  width: 100%;
  max-width: 420px;
  background: rgba(15, 23, 42, 0.92);
  border: 1px solid var(--border);
  border-radius: 20px;
  box-shadow: var(--shadow-md), 0 24px 60px rgba(0, 0, 0, 0.35);
  padding: 32px;
}

.login-brand {
  margin-bottom: 22px;
}

.login-brand p {
  margin-top: 12px;
  color: var(--text-secondary);
  font-size: 14px;
}

.login-form {
  display: flex;
  flex-direction: column;
  gap: 14px;
}

button,
input,
textarea,
select {
  font: inherit;
}

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

button:disabled {
  opacity: 0.45;
  cursor: not-allowed;
}

input,
textarea,
select {
  width: 100%;
  border: 1px solid var(--border);
  background: var(--bg-card);
  color: var(--text-primary);
  border-radius: var(--radius-sm);
  padding: 9px 12px;
  outline: none;
  transition: border-color 0.15s, box-shadow 0.15s;
  font-size: 14px;
}

input:focus,
textarea:focus,
select:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px rgba(37, 99, 235, 0.1);
}

.app-container {
  display: grid;
  grid-template-columns: 240px 320px 1fr;
  height: 100vh;
  overflow: hidden;
}

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

.sidebar-header {
  padding: 20px 16px 16px;
  display: flex;
  flex-direction: column;
  gap: 14px;
  border-bottom: 1px solid var(--border-light);
}

.logo {
  display: flex;
  align-items: center;
  gap: 10px;
  font-size: 16px;
  font-weight: 700;
  color: var(--text-primary);
}

.logo svg {
  color: var(--accent);
  flex-shrink: 0;
}

.compose-btn {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  background: var(--accent);
  color: #fff;
  border-radius: var(--radius-md);
  padding: 10px 14px;
  font-size: 14px;
  font-weight: 600;
  transition: background 0.15s, transform 0.1s;
  width: 100%;
}

.compose-btn:hover {
  background: var(--accent-hover);
  transform: translateY(-1px);
}

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

.account-section {
  flex: 1;
  overflow: hidden;
  display: flex;
  flex-direction: column;
  padding: 12px 0;
}

.section-header {
  padding: 4px 16px 8px;
  font-size: 11px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.5px;
  color: var(--text-muted);
}

.account-list {
  flex: 1;
  overflow-y: auto;
  padding: 0 8px;
}

.channel-group {
  margin-bottom: 4px;
}

.channel-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 8px 8px 4px;
  font-size: 13px;
  font-weight: 600;
  color: var(--text-secondary);
  cursor: pointer;
}

.channel-header:hover .chevron,
.channel-header:hover .channel-name {
  color: var(--accent);
}

.channel-name {
  display: flex;
  align-items: center;
  gap: 6px;
  color: var(--text-secondary);
  transition: color 0.15s;
}

.chevron {
  transition: transform 0.2s, color 0.15s;
  color: var(--text-muted);
}

.channel-header.collapsed .chevron {
  transform: rotate(-90deg);
}

.channel-accounts {
  overflow: hidden;
  transition: max-height 0.2s ease;
}

.channel-header.collapsed + .channel-accounts {
  display: none;
}

.account-item {
  display: flex;
  align-items: center;
  gap: 4px;
  padding: 2px 0;
}

.account-copy-btn {
  flex: 1;
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 8px 10px;
  border-radius: var(--radius-sm);
  font-size: 13px;
  color: var(--text-primary);
  transition: background 0.12s, color 0.12s;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  min-width: 0;
}

.account-copy-btn:hover {
  background: var(--bg-hover);
  color: var(--accent);
}

.account-item.active .account-copy-btn {
  background: var(--bg-active);
  color: var(--accent);
  font-weight: 600;
}

.account-delete-btn {
  width: 28px;
  height: 28px;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: var(--radius-sm);
  color: var(--text-muted);
  opacity: 0;
  transition: opacity 0.15s, background 0.15s, color 0.15s;
  flex-shrink: 0;
}

.account-item:hover .account-delete-btn {
  opacity: 1;
}

.account-delete-btn:hover {
  background: #fee2e2;
  color: var(--danger);
}

.empty-hint {
  padding: 16px;
  font-size: 13px;
  color: var(--text-muted);
  text-align: center;
}

.sidebar-footer {
  padding: 12px 16px;
  border-top: 1px solid var(--border-light);
  display: flex;
  justify-content: flex-end;
}

.icon-btn {
  width: 36px;
  height: 36px;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: var(--radius-sm);
  color: var(--text-muted);
  transition: background 0.15s, color 0.15s;
}

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

/* === Mail List Section === */
.mail-list-section {
  border-right: 1px solid var(--border);
  background: var(--bg-card);
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

.mail-list-header {
  padding: 16px 16px 12px;
  border-bottom: 1px solid var(--border-light);
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  flex-shrink: 0;
}

.header-left {
  min-width: 0;
}

#selected-account-title {
  font-size: 15px;
  font-weight: 700;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.account-info {
  font-size: 12px;
  color: var(--text-muted);
  display: block;
  margin-top: 2px;
}

.header-actions {
  display: flex;
  gap: 4px;
  flex-shrink: 0;
}

.action-btn {
  width: 34px;
  height: 34px;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: var(--radius-sm);
  color: var(--text-secondary);
  transition: background 0.15s, color 0.15s;
}

.action-btn:hover:not(:disabled) {
  background: var(--bg-hover);
  color: var(--accent);
}

.mail-list {
  flex: 1;
  overflow: hidden;
  display: flex;
  flex-direction: column;
}

.message-items {
  flex: 1;
  overflow-y: auto;
  padding: 8px;
}

.empty-state {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  height: 100%;
  gap: 12px;
  color: var(--text-muted);
  font-size: 14px;
}

.empty-state svg {
  opacity: 0.3;
}

.message-card {
  padding: 12px;
  border-radius: var(--radius-md);
  cursor: pointer;
  transition: background 0.12s;
  border: 1px solid transparent;
  margin-bottom: 4px;
}

.message-card:hover {
  background: var(--bg-hover);
}

.message-card.active {
  background: var(--accent-light);
  border-color: #bfdbfe;
}

.message-card h3 {
  font-size: 13px;
  font-weight: 600;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  margin-bottom: 4px;
}

.message-card p {
  font-size: 12px;
  color: var(--text-secondary);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.message-meta {
  font-size: 11px;
  color: var(--text-muted);
  margin-top: 3px;
}

/* === Mail Detail Section === */
.mail-detail-section {
  background: var(--bg-base);
  overflow: hidden;
  display: flex;
  flex-direction: column;
}

.mail-detail {
  flex: 1;
  overflow-y: auto;
  padding: 24px 32px;
}

.mail-detail.empty {
  display: flex;
  align-items: center;
  justify-content: center;
}

.mail-detail.empty .empty-state svg {
  opacity: 0.2;
}

.reading-header h3 {
  font-size: 18px;
  font-weight: 700;
  margin-bottom: 16px;
  line-height: 1.4;
}

.reading-meta-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px 16px;
  padding: 14px 16px;
  background: var(--bg-card);
  border-radius: var(--radius-md);
  box-shadow: var(--shadow-sm);
  margin-bottom: 20px;
}

.reading-meta-grid p {
  font-size: 13px;
  color: var(--text-secondary);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.reading-meta-grid strong {
  color: var(--text-primary);
  font-weight: 600;
}

.reading-divider {
  height: 1px;
  background: var(--border-light);
  margin: 0 0 20px;
}

.message-body {
  line-height: 1.8;
  font-size: 14px;
  color: var(--text-primary);
  max-width: 720px;
}

.message-body.text-body {
  white-space: pre-wrap;
  background: var(--bg-card);
  padding: 16px;
  border-radius: var(--radius-md);
  box-shadow: var(--shadow-sm);
}

.message-body.html-body {
  background: var(--bg-card);
  padding: 20px 24px;
  border-radius: var(--radius-md);
  box-shadow: var(--shadow-sm);
}

.message-body.html-body img {
  max-width: 100%;
  height: auto;
}

.message-body.html-body a {
  color: var(--accent);
}

/* === Modal === */
.modal {
  position: fixed;
  inset: 0;
  z-index: 1000;
  display: flex;
  align-items: center;
  justify-content: center;
}

.modal.hidden {
  display: none;
}

.modal-backdrop {
  position: absolute;
  inset: 0;
  background: rgba(0, 0, 0, 0.4);
  backdrop-filter: blur(2px);
}

.modal-content {
  position: relative;
  background: var(--bg-card);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-md), 0 20px 40px rgba(0,0,0,0.15);
  overflow: hidden;
  max-height: 90vh;
  display: flex;
  flex-direction: column;
}

.compose-modal-content {
  width: 620px;
}

.settings-modal-content {
  width: 520px;
}

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

.modal-header h3 {
  font-size: 17px;
  font-weight: 700;
}

.close-btn {
  width: 32px;
  height: 32px;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: var(--radius-sm);
  color: var(--text-muted);
  transition: background 0.15s, color 0.15s;
}

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

.compose-form,
.settings-content {
  padding: 20px 24px;
  overflow-y: auto;
}

.form-row {
  margin-bottom: 14px;
}

.form-row label {
  display: block;
  font-size: 13px;
  font-weight: 600;
  color: var(--text-secondary);
  margin-bottom: 6px;
}

.body-row {
  flex: 1;
  display: flex;
  flex-direction: column;
}

.body-row textarea {
  flex: 1;
  min-height: 220px;
  resize: vertical;
  font-family: inherit;
  line-height: 1.6;
}

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

.send-btn {
  background: var(--accent);
  color: #fff;
  border-radius: var(--radius-md);
  padding: 10px 24px;
  font-size: 14px;
  font-weight: 600;
  transition: background 0.15s;
}

.send-btn:hover:not(:disabled) {
  background: var(--accent-hover);
}

.settings-content {
  display: flex;
  flex-direction: column;
  gap: 20px;
}

.settings-section h4 {
  font-size: 14px;
  font-weight: 700;
  margin-bottom: 12px;
  color: var(--text-primary);
}

.settings-form {
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.batch-tip {
  margin-bottom: 10px;
  font-size: 12px;
  color: var(--text-muted);
}

.batch-textarea {
  min-height: 150px;
  resize: vertical;
  line-height: 1.7;
}

.inline-actions {
  display: flex;
  gap: 10px;
  flex-wrap: wrap;
}

.form-row.compact {
  margin-bottom: 0;
}

.form-row.split {
  display: flex;
  align-items: center;
  gap: 10px;
}

.form-row.split input {
  flex: 1;
}

.checkbox {
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: 13px;
  color: var(--text-secondary);
  white-space: nowrap;
  flex-shrink: 0;
  cursor: pointer;
}

.checkbox input {
  width: auto;
}

.add-btn {
  background: var(--accent);
  color: #fff;
  border-radius: var(--radius-md);
  padding: 10px 16px;
  font-size: 13px;
  font-weight: 600;
  transition: background 0.15s;
  margin-top: 4px;
}

.add-btn:hover:not(:disabled) {
  background: var(--accent-hover);
}

.secondary-btn {
  background: transparent;
  color: var(--text-secondary);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  padding: 10px 16px;
  font-size: 13px;
  font-weight: 600;
  transition: background 0.15s, border-color 0.15s, color 0.15s;
}

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

/* === Toast === */
.toast {
  position: fixed;
  bottom: 24px;
  right: 24px;
  padding: 12px 20px;
  border-radius: var(--radius-md);
  background: #1a1d21;
  color: #fff;
  font-size: 14px;
  font-weight: 500;
  box-shadow: var(--shadow-md);
  z-index: 2000;
  max-width: 360px;
}

.toast.error {
  background: var(--danger);
}

.toast.hidden {
  display: none;
}

@media (max-width: 1100px) {
  .app-container {
    grid-template-columns: 220px 280px 1fr;
  }
}

@media (max-width: 900px) {
  .app-container {
    grid-template-columns: 1fr;
  }

  .sidebar {
    display: none;
  }

  .mail-list-section {
    border-right: none;
  }
}
