:root {
  --paper: #f4f4ef;
  --surface: #ffffff;
  --ink: #17201c;
  --muted: #667069;
  --line: #d7dcd7;
  --line-strong: #b9c1bb;
  --accent: #16724a;
  --accent-dark: #0e5637;
  --accent-soft: #e2f1e8;
  --danger: #b53a32;
  --danger-soft: #f8e8e6;
  --signal: #d2a53a;
  --shadow: 0 18px 55px rgba(23, 32, 28, 0.09);
  --radius: 6px;
  color-scheme: light;
  font-family: "Microsoft YaHei UI", "Segoe UI", sans-serif;
  font-size: 16px;
  letter-spacing: 0;
}

* {
  box-sizing: border-box;
}

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

body {
  background-color: var(--paper);
  background-image:
    linear-gradient(rgba(23, 32, 28, 0.035) 1px, transparent 1px),
    linear-gradient(90deg, rgba(23, 32, 28, 0.035) 1px, transparent 1px);
  background-size: 28px 28px;
  color: var(--ink);
}

button,
input,
select {
  font: inherit;
  letter-spacing: 0;
}

button {
  cursor: pointer;
}

button:disabled {
  cursor: wait;
  opacity: 0.6;
}

[hidden] {
  display: none !important;
}

.topbar {
  align-items: center;
  background: rgba(244, 244, 239, 0.96);
  border-bottom: 1px solid var(--line);
  display: flex;
  height: 64px;
  justify-content: space-between;
  padding: 0 28px;
  position: sticky;
  top: 0;
  z-index: 20;
}

.brand {
  align-items: center;
  color: var(--ink);
  display: inline-flex;
  gap: 11px;
  text-decoration: none;
}

.brand-mark {
  align-items: center;
  background: var(--ink);
  border-radius: 4px;
  color: white;
  display: inline-flex;
  height: 34px;
  justify-content: center;
  width: 34px;
}

.brand-mark svg {
  height: 18px;
  width: 18px;
}

.brand h1 {
  font-family: Georgia, "Songti SC", serif;
  font-size: 20px;
  font-weight: 700;
  margin: 0;
}

.topbar-actions,
.status-indicator,
.toolbar-actions,
.pane-actions,
.address-line,
.message-meta {
  align-items: center;
  display: flex;
}

.topbar-actions {
  gap: 16px;
}

.status-indicator {
  color: var(--muted);
  font-size: 13px;
  gap: 7px;
}

.status-dot {
  background: var(--accent);
  border: 3px solid var(--accent-soft);
  border-radius: 50%;
  height: 10px;
  width: 10px;
}

.app-shell {
  min-height: calc(100vh - 64px);
  overflow: hidden;
}

.loading-view {
  align-items: center;
  color: var(--muted);
  display: flex;
  gap: 10px;
  justify-content: center;
  min-height: calc(100vh - 64px);
}

.spinner {
  animation: spin 0.8s linear infinite;
  border: 2px solid var(--line);
  border-radius: 50%;
  border-top-color: var(--accent);
  height: 18px;
  width: 18px;
}

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

.auth-layout {
  display: grid;
  grid-template-columns: minmax(320px, 520px) minmax(260px, 1fr);
  margin: 0 auto;
  max-width: 1120px;
  min-height: calc(100vh - 64px);
}

.auth-panel {
  align-self: center;
  padding: 72px 72px 84px 24px;
}

.auth-aside {
  align-items: center;
  background: var(--ink);
  color: white;
  display: flex;
  flex-direction: column;
  justify-content: center;
  min-height: calc(100vh - 64px);
  overflow: hidden;
  position: relative;
}

.auth-aside::before,
.auth-aside::after {
  border: 1px solid rgba(255, 255, 255, 0.14);
  content: "";
  height: 280px;
  position: absolute;
  transform: rotate(45deg);
  width: 280px;
}

.auth-aside::before {
  left: -170px;
  top: -130px;
}

.auth-aside::after {
  bottom: -150px;
  right: -140px;
}

.stamp {
  align-items: center;
  border: 1px solid rgba(255, 255, 255, 0.45);
  display: flex;
  height: 96px;
  justify-content: center;
  transform: rotate(-6deg);
  width: 96px;
}

.stamp svg {
  height: 42px;
  width: 42px;
}

.auth-aside p {
  color: #c4d0c8;
  font-family: Consolas, monospace;
  font-size: 12px;
  margin-top: 28px;
}

.section-heading h2,
.create-header h2 {
  font-family: Georgia, "Songti SC", serif;
  font-size: 38px;
  line-height: 1.15;
  margin: 8px 0 34px;
}

.eyebrow {
  color: var(--muted);
  display: block;
  font-family: Consolas, monospace;
  font-size: 11px;
  font-weight: 700;
  line-height: 1.2;
  text-transform: uppercase;
}

.form-stack {
  display: grid;
  gap: 12px;
}

label {
  color: var(--ink);
  font-size: 13px;
  font-weight: 700;
}

input,
select {
  background: var(--surface);
  border: 1px solid var(--line-strong);
  border-radius: var(--radius);
  color: var(--ink);
  height: 46px;
  min-width: 0;
  outline: none;
  padding: 0 13px;
  width: 100%;
}

input:focus,
select:focus,
button:focus-visible {
  box-shadow: 0 0 0 3px rgba(22, 114, 74, 0.18);
  outline: 1px solid var(--accent);
  outline-offset: 1px;
}

.password-field {
  position: relative;
}

.password-field input {
  padding-right: 52px;
}

.password-field .icon-button {
  position: absolute;
  right: 5px;
  top: 5px;
}

.button,
.icon-button,
.segment {
  align-items: center;
  border: 1px solid transparent;
  border-radius: var(--radius);
  display: inline-flex;
  justify-content: center;
  transition: background-color 140ms ease, border-color 140ms ease, color 140ms ease, transform 140ms ease;
}

.button {
  gap: 8px;
  height: 42px;
  padding: 0 16px;
}

.button svg,
.icon-button svg,
.segment svg {
  height: 17px;
  width: 17px;
}

.button-wide {
  justify-content: space-between;
  margin-top: 8px;
  width: 100%;
}

.button-primary {
  background: var(--accent);
  color: white;
}

.button-primary:hover {
  background: var(--accent-dark);
  transform: translateY(-1px);
}

.button-secondary {
  background: var(--surface);
  border-color: var(--line-strong);
  color: var(--ink);
}

.button-secondary:hover,
.button-quiet:hover,
.icon-button:hover {
  background: #eaedea;
}

.button-quiet {
  background: transparent;
  color: var(--muted);
}

.icon-button {
  background: transparent;
  color: var(--muted);
  height: 36px;
  padding: 0;
  width: 36px;
}

.icon-button.danger {
  color: var(--danger);
}

.icon-button.danger:hover {
  background: var(--danger-soft);
}

.create-layout {
  margin: 0 auto;
  max-width: 820px;
  padding: 76px 28px;
}

.create-form {
  border-top: 1px solid var(--line-strong);
  padding-top: 24px;
}

.segmented {
  background: #e6e9e5;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  display: inline-grid;
  gap: 3px;
  grid-template-columns: repeat(2, minmax(130px, 1fr));
  padding: 3px;
}

.segment {
  background: transparent;
  color: var(--muted);
  gap: 7px;
  height: 40px;
  padding: 0 14px;
}

.segment.is-active {
  background: var(--surface);
  border-color: var(--line);
  color: var(--ink);
  box-shadow: 0 1px 3px rgba(23, 32, 28, 0.08);
}

.custom-fields {
  align-items: end;
  display: grid;
  gap: 14px;
  grid-template-columns: minmax(180px, 1fr) 24px minmax(180px, 1fr);
  margin: 26px 0;
}

.field-group {
  display: grid;
  gap: 8px;
}

.at-sign {
  align-items: center;
  color: var(--muted);
  display: flex;
  height: 46px;
  justify-content: center;
}

.create-form > .button {
  margin-top: 26px;
}

.mailbox-layout {
  min-height: calc(100vh - 64px);
  padding: 0 28px 28px;
}

.mailbox-toolbar {
  align-items: center;
  display: flex;
  height: 92px;
  justify-content: space-between;
  margin: 0 auto;
  max-width: 1440px;
}

.address-line {
  gap: 8px;
  margin-top: 6px;
}

.address-line strong {
  font-family: Georgia, "Songti SC", serif;
  font-size: 22px;
  overflow-wrap: anywhere;
}

.mail-workspace {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  display: grid;
  grid-template-columns: minmax(290px, 360px) minmax(0, 1fr);
  height: calc(100vh - 184px);
  margin: 0 auto;
  max-width: 1440px;
  min-height: 480px;
  overflow: hidden;
}

.mail-list-pane {
  border-right: 1px solid var(--line);
  display: grid;
  grid-template-rows: auto minmax(0, 1fr);
  min-width: 0;
  position: relative;
}

.pane-heading,
.detail-toolbar {
  align-items: center;
  border-bottom: 1px solid var(--line);
  display: flex;
  justify-content: space-between;
}

.pane-heading {
  min-height: 82px;
  padding: 16px 18px;
}

.pane-heading h2 {
  font-family: Georgia, "Songti SC", serif;
  font-size: 20px;
  margin: 5px 0 0;
}

.count {
  color: var(--muted);
  font-family: Consolas, monospace;
  font-size: 13px;
  margin-left: 4px;
}

.pane-actions {
  gap: 3px;
}

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

.mail-item {
  background: transparent;
  border: 0;
  border-bottom: 1px solid var(--line);
  color: var(--ink);
  display: grid;
  gap: 6px;
  min-height: 96px;
  padding: 15px 18px;
  text-align: left;
  width: 100%;
}

.mail-item:hover,
.mail-item.is-active {
  background: #edf3ef;
}

.mail-item.is-active {
  box-shadow: inset 3px 0 0 var(--accent);
}

.mail-item-top {
  align-items: center;
  display: flex;
  gap: 12px;
  justify-content: space-between;
}

.mail-item-sender,
.mail-item-subject {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.mail-item-sender {
  font-size: 13px;
  font-weight: 700;
}

.mail-item-time {
  color: var(--muted);
  flex: 0 0 auto;
  font-family: Consolas, monospace;
  font-size: 10px;
}

.mail-item-subject {
  color: var(--muted);
  font-size: 13px;
}

.empty-state,
.detail-placeholder {
  align-items: center;
  color: var(--muted);
  display: flex;
  flex-direction: column;
  gap: 12px;
  justify-content: center;
}

.empty-state {
  inset: 82px 0 0;
  pointer-events: none;
  position: absolute;
}

.empty-state svg,
.detail-placeholder svg {
  color: var(--line-strong);
  height: 34px;
  width: 34px;
}

.empty-state strong {
  color: var(--muted);
  font-size: 13px;
}

.mail-detail {
  min-width: 0;
  overflow: hidden;
  position: relative;
}

.detail-placeholder {
  height: 100%;
}

.detail-content {
  display: grid;
  grid-template-rows: auto minmax(0, 1fr);
  height: 100%;
}

.detail-toolbar {
  gap: 14px;
  min-height: 82px;
  padding: 14px 20px;
}

.detail-title-block {
  min-width: 0;
  width: 100%;
}

.detail-title-block h2 {
  font-family: Georgia, "Songti SC", serif;
  font-size: 20px;
  margin: 0 0 6px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.message-meta {
  color: var(--muted);
  font-size: 11px;
  gap: 14px;
}

.mail-body {
  background: white;
  border: 0;
  height: 100%;
  min-height: 0;
  width: 100%;
}

.mobile-only {
  display: none;
}

.toast-region {
  bottom: 22px;
  display: grid;
  gap: 8px;
  max-width: min(390px, calc(100vw - 32px));
  position: fixed;
  right: 22px;
  z-index: 50;
}

.toast {
  background: var(--ink);
  border-left: 4px solid var(--signal);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  color: white;
  font-size: 13px;
  padding: 13px 16px;
}

.toast.is-error {
  border-left-color: var(--danger);
}

@media (max-width: 760px) {
  .topbar {
    height: 58px;
    padding: 0 16px;
  }

  .brand h1 {
    font-size: 18px;
  }

  .status-indicator {
    display: none !important;
  }

  .button-quiet span {
    display: none;
  }

  .app-shell {
    min-height: calc(100vh - 58px);
  }

  .auth-layout {
    display: block;
    min-height: calc(100vh - 58px);
  }

  .auth-panel {
    padding: 76px 22px 40px;
  }

  .auth-aside {
    display: none;
  }

  .section-heading h2,
  .create-header h2 {
    font-size: 32px;
  }

  .create-layout {
    padding: 58px 18px;
  }

  .segmented {
    width: 100%;
  }

  .custom-fields {
    align-items: stretch;
    grid-template-columns: minmax(0, 1fr);
  }

  .at-sign {
    display: none;
  }

  .create-form > .button {
    width: 100%;
  }

  .mailbox-layout {
    padding: 0;
  }

  .mailbox-toolbar {
    gap: 10px;
    height: 82px;
    padding: 0 14px;
  }

  .address-block {
    min-width: 0;
  }

  .address-line strong {
    font-size: 16px;
    max-width: calc(100vw - 168px);
  }

  .button-secondary span {
    display: none;
  }

  .mail-workspace {
    border-left: 0;
    border-radius: 0;
    border-right: 0;
    box-shadow: none;
    display: block;
    height: calc(100vh - 140px);
    min-height: 420px;
  }

  .mail-list-pane,
  .mail-detail {
    border-right: 0;
    height: 100%;
    width: 100%;
  }

  .mailbox-layout.show-detail .mail-list-pane {
    display: none;
  }

  .mailbox-layout:not(.show-detail) .mail-detail {
    display: none;
  }

  .mobile-only {
    display: inline-flex;
    flex: 0 0 36px;
  }

  .detail-toolbar {
    padding: 12px 10px;
  }

  .detail-title-block h2 {
    font-size: 17px;
  }

  .toast-region {
    bottom: 14px;
    right: 16px;
  }
}

@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    scroll-behavior: auto !important;
    transition-duration: 0.01ms !important;
  }
}
