:root {
  color-scheme: light;
  --ink: #13201f;
  --muted: #64706f;
  --soft: #eef3f0;
  --line: #d8e1dc;
  --paper: #f7f8f4;
  --panel: #fffffb;
  --panel-strong: #f1f6f3;
  --nav: #102422;
  --accent: #0f766e;
  --accent-strong: #0b514d;
  --accent-soft: #dff1ec;
  --warn: #ba4c35;
  --shadow: 0 18px 42px rgba(33, 47, 43, 0.12);
  --radius: 8px;
}

* {
  box-sizing: border-box;
}

[hidden] {
  display: none !important;
}

body {
  margin: 0;
  min-height: 100vh;
  color: var(--ink);
  background:
    linear-gradient(135deg, rgba(15, 118, 110, 0.08), transparent 34%),
    linear-gradient(315deg, rgba(16, 36, 34, 0.08), transparent 30%),
    var(--paper);
  font-family: "Aptos", "Segoe UI", sans-serif;
  letter-spacing: 0;
}

button,
input,
textarea {
  font: inherit;
}

button {
  min-height: 40px;
  border: 1px solid transparent;
  border-radius: 6px;
  cursor: pointer;
  transition: background-color 180ms ease, border-color 180ms ease, color 180ms ease, opacity 180ms ease;
}

button:focus-visible,
input:focus-visible,
textarea:focus-visible {
  outline: 3px solid rgba(15, 118, 110, 0.22);
  outline-offset: 2px;
}

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

input,
textarea {
  width: 100%;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: #fff;
  color: var(--ink);
  min-height: 42px;
  padding: 0 12px;
}

textarea {
  min-height: 118px;
  padding: 12px;
  resize: vertical;
  line-height: 1.55;
}

.shell {
  min-height: 100vh;
}

.login-panel {
  min-height: 100vh;
  display: grid;
  place-items: center;
  padding: 24px;
}

.login-box {
  width: min(440px, 100%);
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 32px;
}

.login-box h1,
.topbar h1 {
  margin: 0;
  font-size: clamp(26px, 3vw, 38px);
  font-weight: 800;
}

.eyebrow,
.list-kicker {
  margin: 0 0 7px;
  color: var(--accent);
  font-size: 11px;
  font-weight: 800;
  text-transform: uppercase;
}

.login-form {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 8px;
  margin-top: 24px;
}

.login-form button,
.search-button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  background: var(--accent);
  color: white;
  font-weight: 800;
  padding: 0 22px;
}

.login-form button:hover,
.search-button:hover {
  background: var(--accent-strong);
}

.error-text {
  color: var(--warn);
  min-height: 20px;
}

.workspace {
  width: min(1480px, 100%);
  margin: 0 auto;
  padding: 26px;
}

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  margin-bottom: 22px;
}

.ghost-button {
  border-color: rgba(15, 118, 110, 0.45);
  background: transparent;
  color: var(--accent-strong);
  padding: 0 16px;
}

.ghost-button:hover {
  background: var(--accent-soft);
}

.controls {
  display: grid;
  grid-template-columns: minmax(360px, 1fr) auto;
  gap: 12px;
  align-items: stretch;
  background: rgba(255, 255, 251, 0.86);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 14px;
  margin-bottom: 14px;
}

.control-card {
  display: grid;
  gap: 8px;
}

.control-card label {
  color: var(--muted);
  font-size: 12px;
  font-weight: 800;
}

.search-button {
  align-self: end;
  min-height: 44px;
}

.search-button.loading::before {
  content: "";
  width: 14px;
  height: 14px;
  border: 2px solid rgba(255, 255, 255, 0.46);
  border-top-color: white;
  border-radius: 999px;
  animation: spin 780ms linear infinite;
}

.query-notice {
  color: var(--warn);
  border-bottom: 1px solid var(--line);
  padding: 0 14px;
  font-size: 13px;
  line-height: 1.5;
}

.query-notice:not(:empty) {
  padding-top: 12px;
  padding-bottom: 12px;
  background: #fff5ee;
}

.content-grid {
  display: grid;
  grid-template-columns: minmax(390px, 0.88fr) minmax(520px, 1.32fr);
  gap: 14px;
}

.mail-list,
.mail-detail {
  min-height: 68vh;
  background: rgba(255, 255, 251, 0.92);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  overflow: hidden;
}

.list-head {
  display: grid;
  grid-template-columns: minmax(78px, auto) minmax(180px, 1fr) auto;
  align-items: center;
  gap: 12px;
  border-bottom: 1px solid var(--line);
  padding: 14px;
  background: var(--panel-strong);
}

.list-head strong {
  display: block;
  font-size: 22px;
}

.list-filter {
  display: flex;
  align-items: center;
}

.list-filter input {
  min-height: 38px;
  background: rgba(255, 255, 251, 0.92);
}

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

.pager button {
  min-height: 34px;
  background: #dbe9e5;
  color: var(--accent-strong);
  font-weight: 800;
  padding: 0 12px;
}

.pager button:not(:disabled):hover {
  background: var(--accent-soft);
}

.rows {
  position: relative;
  max-height: calc(68vh - 76px);
  overflow: auto;
}

.rows.loading::after {
  content: "查询中...";
  position: sticky;
  top: 0;
  z-index: 2;
  display: grid;
  place-items: center;
  min-height: 42px;
  border-bottom: 1px solid var(--line);
  background: rgba(255, 255, 251, 0.9);
  color: var(--accent-strong);
  font-size: 12px;
  font-weight: 800;
}

.mail-group {
  border-bottom: 1px solid var(--line);
}

.mail-group-head {
  display: grid;
  grid-template-columns: 18px minmax(0, 1fr) auto;
  align-items: center;
  gap: 8px;
  width: 100%;
  min-height: 34px;
  border: 0;
  border-radius: 0;
  padding: 8px 14px;
  background: #f8faf7;
  color: var(--muted);
  font-size: 12px;
  font-weight: 800;
  text-align: left;
}

.mail-group-head:hover {
  background: #eef6f2;
  color: var(--accent-strong);
}

.mail-group-head strong {
  justify-self: end;
}

.group-caret {
  position: relative;
  justify-self: center;
  align-self: center;
  width: 18px;
  height: 18px;
  border: 1px solid rgba(15, 118, 110, 0.25);
  border-radius: 4px;
  background: white;
}

.group-caret::before,
.group-caret::after {
  content: "";
  position: absolute;
  top: 50%;
  left: 50%;
  width: 8px;
  height: 1.5px;
  border-radius: 999px;
  background: var(--accent-strong);
  transform: translate(-50%, -50%);
}

.group-caret::after {
  opacity: 0;
  transform: translate(-50%, -50%) rotate(90deg);
}

.mail-group-head.collapsed .group-caret::after {
  opacity: 1;
}

.group-address {
  min-width: 0;
  overflow-wrap: anywhere;
}

.mail-group-body {
  display: grid;
}

.mail-group-empty {
  padding: 14px;
  color: var(--warn);
  background: #fff8f3;
  font-size: 13px;
}

.mail-row {
  display: grid;
  gap: 6px;
  width: 100%;
  border: 0;
  border-top: 1px solid rgba(216, 225, 220, 0.72);
  border-radius: 0;
  background: transparent;
  color: var(--ink);
  text-align: left;
  padding: 14px;
}

.mail-row:hover,
.mail-row.active {
  background: #e8f2ee;
}

.mail-row strong {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  font-size: 15px;
}

.meta {
  color: var(--muted);
  font-size: 13px;
}

.mail-detail {
  padding: 22px;
  overflow: auto;
}

.empty-state {
  min-height: 58vh;
  display: grid;
  place-content: center;
  color: var(--muted);
  text-align: center;
}

.detail-head {
  display: flex;
  align-items: start;
  justify-content: space-between;
  gap: 12px;
  border-bottom: 1px solid var(--line);
  padding-bottom: 16px;
  margin-bottom: 16px;
}

.detail-head h2 {
  margin: 4px 0 0;
  font-size: clamp(22px, 2.3vw, 32px);
}

.mail-body {
  line-height: 1.6;
  overflow-wrap: anywhere;
}

.mail-body iframe {
  width: 100%;
  min-height: 520px;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: white;
}

.mail-body pre {
  white-space: pre-wrap;
  background: var(--soft);
  border-radius: 6px;
  padding: 14px;
  overflow: auto;
}

@media (prefers-reduced-motion: reduce) {
  * {
    transition: none !important;
    animation: none !important;
  }
}

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

@media (max-width: 900px) {
  .workspace {
    padding: 14px;
  }

  .topbar {
    align-items: start;
  }

  .controls,
  .content-grid {
    grid-template-columns: 1fr;
  }

  .list-head {
    grid-template-columns: 1fr;
    align-items: stretch;
  }

  .pager {
    justify-content: space-between;
  }

  .mail-list,
  .mail-detail {
    min-height: auto;
  }

  .rows {
    max-height: 52vh;
  }
}
