:root {
  color-scheme: dark;
  --bg: #0b0b0d;
  --surface: #131316;
  --surface-2: #1a1a1e;
  --surface-hover: #202024;
  --border: #29292f;
  --text: #ececee;
  --text-dim: #97979f;
  --text-faint: #5f5f68;
  --accent: #4c8dff;
  --accent-hover: #6ba0ff;
  --accent-text: #04101f;
  --danger: #f0616b;
  --danger-bg: #3a1a1e;
  --radius-panel: 12px;
  --radius-control: 8px;
  --shadow: 0 12px 40px rgb(0 0 0 / 0.45);
}

@media (prefers-color-scheme: light) {
  :root {
    color-scheme: light;
    --bg: #f6f6f8;
    --surface: #ffffff;
    --surface-2: #f0f0f3;
    --surface-hover: #e9e9ee;
    --border: #e2e2e8;
    --text: #17171b;
    --text-dim: #6c6c76;
    --text-faint: #a4a4ac;
    --accent: #2f6fef;
    --accent-hover: #1f5adb;
    --accent-text: #ffffff;
    --danger: #d13a44;
    --danger-bg: #fbeaec;
    --shadow: 0 12px 32px rgb(20 20 30 / 0.10);
  }
}

* { box-sizing: border-box; }

html, body {
  height: 100%;
  margin: 0;
}

body {
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "PingFang SC", "Microsoft YaHei", system-ui, sans-serif;
  font-size: 14px;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
}

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

.shell {
  display: grid;
  grid-template-columns: 280px 1fr;
  height: 100dvh;
}

/* ---------- Sidebar ---------- */

.sidebar {
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  min-width: 0;
  background: var(--surface);
}

.sidebar__head {
  padding: 20px 16px 12px;
  display: flex;
  flex-direction: column;
  gap: 14px;
}

.brand {
  display: flex;
  align-items: center;
  gap: 8px;
  font-weight: 600;
  font-size: 15px;
  letter-spacing: -0.01em;
}

.brand__icon { font-size: 18px; color: var(--accent); }

.sidebar__toolbar {
  padding: 0 16px 12px;
}

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

.account-item {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 10px;
  border-radius: var(--radius-control);
  cursor: pointer;
  border: 1px solid transparent;
  margin-bottom: 2px;
  position: relative;
}

.account-item:hover { background: var(--surface-hover); }

.account-item.is-active {
  background: var(--surface-hover);
  border-color: var(--border);
}

.account-item__avatar {
  width: 30px;
  height: 30px;
  border-radius: 999px;
  background: color-mix(in srgb, var(--accent) 18%, transparent);
  color: var(--accent);
  display: flex;
  align-items: center;
  justify-content: center;
  font-weight: 600;
  font-size: 12px;
  flex-shrink: 0;
}

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

.account-item__email {
  font-size: 13px;
  font-weight: 500;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.account-item__sub {
  font-size: 11.5px;
  color: var(--text-dim);
  display: flex;
  gap: 6px;
  align-items: center;
  margin-top: 2px;
}

.account-item__delete {
  opacity: 0;
  background: none;
  border: none;
  color: var(--text-faint);
  cursor: pointer;
  padding: 4px;
  border-radius: 6px;
  display: flex;
}

.account-item:hover .account-item__delete { opacity: 1; }
.account-item__delete:hover { color: var(--danger); background: var(--danger-bg); }

.skeleton-list { display: flex; flex-direction: column; gap: 8px; padding: 8px; }
.skeleton-row {
  height: 48px;
  border-radius: var(--radius-control);
  background: linear-gradient(90deg, var(--surface-2) 25%, var(--surface-hover) 37%, var(--surface-2) 63%);
  background-size: 400% 100%;
  animation: shimmer 1.4s ease infinite;
}
@keyframes shimmer {
  0% { background-position: 100% 50%; }
  100% { background-position: 0% 50%; }
}
@media (prefers-reduced-motion: reduce) {
  .skeleton-row { animation: none; }
}

/* ---------- Main ---------- */

.main {
  display: flex;
  flex-direction: column;
  min-width: 0;
}

.main__header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 18px 28px;
  border-bottom: 1px solid var(--border);
  gap: 20px;
}

.main__title {
  display: flex;
  align-items: center;
  gap: 10px;
  min-width: 0;
}

.main__title h1 {
  font-size: 16px;
  font-weight: 600;
  margin: 0;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.main__actions {
  display: flex;
  align-items: center;
  gap: 12px;
  flex-shrink: 0;
}

.search {
  display: flex;
  align-items: center;
  gap: 8px;
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: var(--radius-control);
  padding: 7px 12px;
  color: var(--text-dim);
  width: 240px;
}

.search input {
  border: none;
  background: none;
  outline: none;
  width: 100%;
  color: var(--text);
}

.search input::placeholder { color: var(--text-faint); }

.main__body {
  flex: 1;
  overflow-y: auto;
  padding: 20px 28px 28px;
}

/* ---------- Tags / badges ---------- */

.tag {
  font-size: 11px;
  font-weight: 600;
  padding: 3px 9px;
  border-radius: 999px;
  background: var(--surface-2);
  color: var(--text-dim);
  border: 1px solid var(--border);
  text-transform: uppercase;
  letter-spacing: 0.03em;
}

.tag--accent {
  background: color-mix(in srgb, var(--accent) 16%, transparent);
  color: var(--accent);
  border-color: transparent;
}

/* ---------- Buttons ---------- */

.btn {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 9px 14px;
  border-radius: var(--radius-control);
  border: 1px solid var(--border);
  background: var(--surface-2);
  color: var(--text);
  font-weight: 500;
  cursor: pointer;
  white-space: nowrap;
  transition: transform 0.12s ease, background 0.12s ease;
}

.btn:hover { background: var(--surface-hover); }
.btn:active { transform: scale(0.98); }
.btn:disabled { opacity: 0.5; cursor: not-allowed; transform: none; }

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

.btn--ghost { background: transparent; }

.btn--sm { padding: 7px 12px; font-size: 12.5px; }
.btn--block { width: 100%; justify-content: center; }

.icon-btn {
  border: none;
  background: transparent;
  color: var(--text-dim);
  cursor: pointer;
  padding: 6px;
  border-radius: 8px;
  display: flex;
  font-size: 16px;
}
.icon-btn:hover { background: var(--surface-hover); color: var(--text); }

/* ---------- Message table ---------- */

.mail-table {
  border: 1px solid var(--border);
  border-radius: var(--radius-panel);
  overflow: hidden;
}

.mail-row {
  display: grid;
  grid-template-columns: 1fr 240px 160px;
  gap: 16px;
  align-items: center;
  padding: 13px 18px;
  cursor: pointer;
  border-bottom: 1px solid var(--border);
}

.mail-row:last-child { border-bottom: none; }
.mail-row:hover { background: var(--surface-hover); }

.mail-row__subject {
  font-weight: 500;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.mail-row__from, .mail-row__date {
  color: var(--text-dim);
  font-size: 12.5px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.mail-row--head {
  cursor: default;
  background: var(--surface-2);
  font-size: 11.5px;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: var(--text-faint);
  font-weight: 600;
  padding-top: 11px;
  padding-bottom: 11px;
}
.mail-row--head:hover { background: var(--surface-2); }

/* ---------- Pagination ---------- */

.pagination {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-top: 16px;
  color: var(--text-dim);
  font-size: 12.5px;
}

.pagination__controls {
  display: flex;
  gap: 6px;
}

/* ---------- Empty / loading states ---------- */

.empty-state {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  text-align: center;
  padding: 80px 24px;
  color: var(--text-dim);
}

.empty-state i {
  font-size: 40px;
  color: var(--text-faint);
  margin-bottom: 16px;
}

.empty-state h2 {
  font-size: 15px;
  color: var(--text);
  margin: 0 0 6px;
}

.empty-state p {
  max-width: 360px;
  margin: 0 0 20px;
}

/* ---------- Overlays / modal / detail panel ---------- */

.overlay {
  position: fixed;
  inset: 0;
  background: rgb(0 0 0 / 0.5);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 50;
}

.overlay[hidden] { display: none; }

.modal {
  width: 520px;
  max-width: calc(100vw - 32px);
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-panel);
  box-shadow: var(--shadow);
}

.modal__head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 18px 20px;
  border-bottom: 1px solid var(--border);
}

.modal__head h2 { font-size: 15px; margin: 0; }

.modal__body { padding: 18px 20px; display: flex; flex-direction: column; gap: 8px; }

.field-label {
  font-size: 12.5px;
  font-weight: 600;
  color: var(--text-dim);
}

#import-text {
  width: 100%;
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: var(--radius-control);
  color: var(--text);
  padding: 12px;
  resize: vertical;
  outline: none;
  font-family: ui-monospace, "SFMono-Regular", Consolas, monospace;
  font-size: 12.5px;
  line-height: 1.6;
}

#import-text:focus { border-color: var(--accent); }

.field-help { font-size: 12px; color: var(--text-dim); margin: 0; }

.modal__foot {
  display: flex;
  justify-content: flex-end;
  gap: 10px;
  padding: 16px 20px;
  border-top: 1px solid var(--border);
}

.detail-panel {
  position: fixed;
  top: 0;
  right: 0;
  bottom: 0;
  width: min(720px, 92vw);
  background: var(--surface);
  border-left: 1px solid var(--border);
  box-shadow: var(--shadow);
  display: flex;
  flex-direction: column;
}

.detail-panel__head {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 12px;
  padding: 20px 24px;
  border-bottom: 1px solid var(--border);
}

.detail-panel__head h2 {
  font-size: 15px;
  margin: 0 0 6px;
  line-height: 1.4;
}

.detail-panel__meta {
  display: flex;
  gap: 12px;
  font-size: 12px;
  color: var(--text-dim);
}

.detail-panel__frame {
  flex: 1;
  border: none;
  background: #fff;
}

/* ---------- Toasts ---------- */

.toast-stack {
  position: fixed;
  bottom: 20px;
  right: 20px;
  display: flex;
  flex-direction: column;
  gap: 8px;
  z-index: 100;
}

.toast {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-control);
  padding: 12px 16px;
  box-shadow: var(--shadow);
  font-size: 13px;
  display: flex;
  align-items: center;
  gap: 8px;
  min-width: 220px;
  animation: toast-in 0.2s ease;
}

.toast--error { border-color: var(--danger); color: var(--danger); }
.toast--success i { color: var(--accent); }

@keyframes toast-in {
  from { opacity: 0; transform: translateY(6px); }
  to { opacity: 1; transform: translateY(0); }
}

/* ---------- Responsive ---------- */

@media (max-width: 860px) {
  .shell { grid-template-columns: 1fr; }
  .sidebar { display: none; }
  .mail-row { grid-template-columns: 1fr; gap: 4px; }
  .mail-row__from, .mail-row__date { font-size: 11.5px; }
  .search { width: 160px; }
}
