:root {
  --bg: #eef2f0;
  --ink: #14201c;
  --muted: #5d6b64;
  --panel: #f7faf8;
  --line: #d5e0da;
  --accent: #0f6b4c;
  --accent-ink: #ffffff;
  --danger: #9b2c2c;
  --unread: #0f6b4c;
  --shadow: 0 18px 40px rgba(20, 32, 28, 0.08);
  --font-display: "Source Han Serif SC", "Noto Serif SC", "Songti SC", Georgia, serif;
  --font-body: "IBM Plex Sans", "PingFang SC", "Microsoft YaHei", sans-serif;
}

* {
  box-sizing: border-box;
}

html,
body {
  margin: 0;
  min-height: 100%;
  color: var(--ink);
  font-family: var(--font-body);
  background:
    radial-gradient(circle at top left, rgba(15, 107, 76, 0.12), transparent 40%),
    linear-gradient(160deg, #f4f7f5 0%, #e7eee9 45%, #dfe8e3 100%);
}

button,
input {
  font: inherit;
}

.hidden {
  display: none !important;
}

.view {
  min-height: 100vh;
}

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

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

.brand,
.brand-inline {
  margin: 0 0 8px;
  color: var(--accent);
  font-family: var(--font-display);
  font-size: 1.5rem;
  letter-spacing: 0.04em;
}

.login-panel h1 {
  margin: 0;
  font-family: var(--font-display);
  font-size: 2rem;
  font-weight: 600;
}

.login-desc,
.user-line,
.status-line {
  color: var(--muted);
}

.login-desc {
  margin: 10px 0 28px;
  line-height: 1.5;
}

#login-form {
  display: grid;
  gap: 16px;
}

label {
  display: grid;
  gap: 8px;
  font-size: 0.92rem;
  color: var(--muted);
}

input {
  width: 100%;
  padding: 12px 14px;
  border: 1px solid var(--line);
  border-radius: 0;
  background: #fff;
  color: var(--ink);
}

input:focus {
  outline: 2px solid rgba(15, 107, 76, 0.25);
  border-color: var(--accent);
}

button {
  border: 0;
  cursor: pointer;
  padding: 12px 16px;
  background: var(--accent);
  color: var(--accent-ink);
}

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

.btn-secondary {
  background: transparent;
  color: var(--ink);
  border: 1px solid var(--line);
}

.error {
  margin: 0;
  color: var(--danger);
  font-size: 0.92rem;
}

.topbar {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 16px;
  padding: 18px 22px;
  border-bottom: 1px solid var(--line);
  background: rgba(247, 250, 248, 0.92);
  backdrop-filter: blur(8px);
  position: sticky;
  top: 0;
  z-index: 2;
}

.topbar-actions {
  display: flex;
  gap: 8px;
}

.topbar-detail {
  justify-content: flex-start;
  gap: 8px;
  padding: 10px 12px;
  min-height: 44px;
}

.btn-back {
  display: inline-flex;
  align-items: center;
  gap: 2px;
  padding: 6px 8px;
  background: transparent;
  color: var(--accent);
  border: 0;
  font-size: 0.95rem;
  line-height: 1;
}

.back-icon {
  font-size: 1.6rem;
  line-height: 0.8;
  font-weight: 300;
}

.detail-title {
  margin: 0;
  flex: 1;
  text-align: center;
  font-size: 0.98rem;
  color: var(--ink);
  padding-right: 52px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.user-line {
  margin: 4px 0 0;
  font-size: 0.9rem;
}

.list-main,
.detail-main {
  width: min(920px, calc(100% - 32px));
  margin: 0 auto;
  padding: 20px 0 48px;
}

.status-line {
  margin-bottom: 12px;
  min-height: 1.2em;
}

.message-list {
  list-style: none;
  margin: 0;
  padding: 0;
  display: grid;
  gap: 10px;
}

.message-item {
  display: grid;
  gap: 6px;
  padding: 16px 18px;
  background: var(--panel);
  border: 1px solid var(--line);
  cursor: pointer;
  text-align: left;
  transition: border-color 0.2s ease, transform 0.2s ease;
}

.message-item:hover {
  border-color: rgba(15, 107, 76, 0.45);
  transform: translateY(-1px);
}

.message-item.unread .subject {
  color: var(--unread);
  font-weight: 650;
}

.subject {
  margin: 0;
  font-size: 1.05rem;
}

.from,
.date {
  margin: 0;
  color: var(--muted);
  font-size: 0.9rem;
}

.pager {
  display: flex;
  justify-content: center;
  align-items: center;
  gap: 14px;
  margin-top: 22px;
}

.detail-card {
  padding: 24px;
  background: var(--panel);
  border: 1px solid var(--line);
  box-shadow: var(--shadow);
  overflow-x: hidden;
  max-width: 100%;
}

.detail-card h1 {
  margin: 0 0 18px;
  font-family: var(--font-display);
  font-size: 1.7rem;
  line-height: 1.3;
}

.meta-block {
  margin-bottom: 18px;
  padding-bottom: 14px;
  border-bottom: 1px solid var(--line);
}

.meta-toggle {
  width: 100%;
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 12px;
  padding: 4px 0;
  border: 0;
  background: transparent !important;
  color: inherit !important;
  text-align: left;
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
  appearance: none;
}

.meta-toggle:focus,
.meta-toggle:active,
.meta-toggle:hover {
  background: transparent !important;
  color: inherit !important;
  outline: none;
  box-shadow: none;
  opacity: 1;
}

.meta-toggle-body {
  min-width: 0;
  flex: 1;
}

.meta-summary {
  min-width: 0;
}

.meta-from-brief {
  margin: 0;
  font-size: 1rem;
  font-weight: 600;
  color: var(--ink);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.meta-date-brief {
  margin: 6px 0 0;
  font-size: 0.85rem;
  color: var(--muted);
}

.meta-chevron {
  flex-shrink: 0;
  width: 44px;
  height: 44px;
  margin-top: -4px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  background: transparent;
  color: #9aa39e;
}

.meta-chevron::before {
  content: '';
  width: 9px;
  height: 9px;
  border-right: 2px solid currentColor;
  border-bottom: 2px solid currentColor;
  transform: translateY(-2px) rotate(45deg);
  transition: transform 0.15s ease;
}

.meta-toggle:focus .meta-chevron,
.meta-toggle:active .meta-chevron,
.meta-toggle:hover .meta-chevron,
.meta-toggle[aria-expanded='true'] .meta-chevron {
  background: transparent;
  color: #9aa39e;
}

.meta-toggle[aria-expanded='true'] .meta-chevron::before {
  transform: translateY(2px) rotate(-135deg);
}

.meta {
  display: grid;
  gap: 12px;
}

.meta-row {
  display: flex;
  align-items: center;
  gap: 10px;
  flex-wrap: wrap;
}

.meta-label {
  flex-shrink: 0;
  width: 3.2em;
  color: var(--muted);
  font-size: 0.88rem;
}

.meta-chip {
  margin: 0;
  display: inline-block;
  max-width: 100%;
  padding: 5px 12px;
  border-radius: 999px;
  font-size: 0.88rem;
  line-height: 1.35;
  word-break: break-all;
}

.meta-chip-from {
  background: #2f7bff;
  color: #fff;
}

.meta-chip-to {
  background: #2fa36b;
  color: #fff;
}

.meta-time {
  margin: 0;
  color: var(--ink);
  font-size: 0.92rem;
}

.attachments {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-bottom: 18px;
}

.attachments a {
  color: var(--accent);
  text-decoration: none;
  border: 1px solid var(--line);
  padding: 8px 10px;
  background: #fff;
  max-width: 100%;
  overflow-wrap: anywhere;
}

.mail-body {
  line-height: 1.7;
  overflow-wrap: anywhere;
  overflow-x: auto;
  max-width: 100%;
}

.mail-body pre {
  white-space: pre-wrap;
  font-family: var(--font-body);
}

.mail-body img,
.mail-body video {
  max-width: 100%;
  height: auto;
  display: inline-block;
  vertical-align: middle;
}

.mail-body table {
  max-width: 100% !important;
  width: 100% !important;
}

.mail-body td,
.mail-body th {
  word-break: break-word;
}

@media (max-width: 640px) {
  .login-panel {
    padding: 28px 20px;
  }

  .topbar {
    align-items: center;
    flex-direction: row;
    padding: 12px 14px;
  }

  .topbar-detail {
    padding: 8px 10px;
  }

  .list-main,
  .detail-main {
    width: calc(100% - 24px);
    padding: 16px 0 40px;
  }

  .detail-card {
    padding: 14px;
  }

  .topbar-actions .btn-secondary {
    padding: 8px 10px;
    font-size: 0.88rem;
  }
}
