:root {
  --bg: #f3efe8;
  --panel: #fffdfa;
  --panel-strong: #ffffff;
  --ink: #1f2321;
  --muted: #69706b;
  --line: #d8d1c7;
  --accent: #1d5c4a;
  --accent-strong: #144739;
  --danger: #a23d2c;
  --shadow: 0 18px 40px rgba(31, 35, 33, 0.08);
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  min-height: 100vh;
  min-height: 100svh;
  color: var(--ink);
  font-family: "Segoe UI", "PingFang SC", sans-serif;
  background:
    linear-gradient(180deg, rgba(29, 92, 74, 0.04), transparent 220px),
    var(--bg);
  overflow: hidden;
}

button,
input,
select {
  font: inherit;
}

button {
  border: 1px solid var(--line);
  border-radius: 12px;
  padding: 10px 14px;
  background: var(--panel-strong);
  color: var(--ink);
  cursor: pointer;
}

button.primary {
  border-color: var(--accent);
  background: var(--accent);
  color: #fff;
}

button.primary:hover {
  background: var(--accent-strong);
}

button:disabled {
  opacity: 0.45;
  cursor: not-allowed;
}

button.danger {
  color: var(--danger);
}

input,
select {
  width: 100%;
  border: 1px solid var(--line);
  border-radius: 12px;
  background: #fff;
  padding: 11px 12px;
}

.hidden {
  display: none !important;
}

.panel-kicker {
  margin: 0 0 6px;
  color: var(--muted);
  font-size: 12px;
}

.auth-shell {
  min-height: 100vh;
  display: grid;
  place-items: center;
  padding: 24px;
}

.auth-panel {
  width: min(420px, 100%);
}

.auth-card {
  padding: 28px;
  border: 1px solid var(--line);
  border-radius: 22px;
  background: var(--panel);
  box-shadow: var(--shadow);
}

.auth-card h1,
.auth-card h2,
.topbar h1,
.panel-head h2,
.modal-head h2 {
  margin: 0;
  font-family: Georgia, "Times New Roman", serif;
  font-weight: 600;
}

.auth-card p {
  margin: 0 0 18px;
  color: var(--muted);
}

.auth-card form {
  display: grid;
  gap: 12px;
}

.auth-card label,
.mailbox-form label {
  display: grid;
  gap: 8px;
  color: var(--muted);
  font-size: 13px;
}

.app-shell {
  height: 100vh;
  height: 100svh;
  padding: 20px;
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

.topbar {
  display: flex;
  justify-content: space-between;
  gap: 16px;
  align-items: center;
  margin-bottom: 18px;
}

.topbar-title p {
  margin: 6px 0 0;
  color: var(--muted);
}

.topbar-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  align-items: center;
}

.mobile-menu-wrap {
  position: relative;
  display: none;
}

.mobile-action-menu {
  position: absolute;
  top: calc(100% + 8px);
  right: 0;
  min-width: 132px;
  padding: 6px;
  border: 1px solid var(--line);
  border-radius: 14px;
  background: rgba(255, 253, 250, 0.98);
  box-shadow: var(--shadow);
  z-index: 20;
}

.mobile-action-menu button {
  width: 100%;
  border-color: transparent;
  background: transparent;
  text-align: left;
}

.mobile-action-menu button:hover {
  background: #fff;
}

.mobile-switcher {
  display: none;
}

.workspace {
  flex: 1;
  min-height: 0;
  display: grid;
  grid-template-columns: 280px 360px minmax(0, 1fr);
  gap: 16px;
  overflow: hidden;
}

.sidebar,
.panel,
.modal-card {
  border: 1px solid var(--line);
  border-radius: 22px;
  background: var(--panel);
  box-shadow: var(--shadow);
}

.sidebar,
.panel {
  min-height: 0;
  height: 100%;
  padding: 16px;
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

.mail-panel,
.detail-panel {
  min-width: 0;
}

.panel-head,
.modal-head {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  align-items: center;
}

.mailbox-list,
.email-list {
  flex: 1;
  margin-top: 16px;
  display: grid;
  gap: 10px;
  min-height: 0;
}

.mailbox-list {
  grid-auto-rows: 84px;
  align-content: start;
  overflow-y: auto;
  overflow-x: hidden;
}

.email-list {
  grid-auto-rows: 82px;
  align-content: start;
  flex: 1;
  overflow-y: auto;
  overflow-x: hidden;
  min-width: 0;
}

.mailbox-item,
.email-item {
  min-width: 0;
  width: 100%;
  padding: 14px;
  text-align: left;
  border: 1px solid var(--line);
  border-radius: 16px;
  background: #fff;
  overflow: hidden;
}

.mailbox-item {
  height: 84px;
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 8px 10px 8px 14px;
}

.mailbox-main {
  flex: 1;
  min-width: 0;
  height: 100%;
  padding: 0;
  border: 0;
  background: transparent;
  text-align: left;
  display: flex;
  flex-direction: column;
  justify-content: center;
  border-radius: 12px;
}

.email-item {
  height: 82px;
  display: flex;
  flex-direction: column;
  justify-content: center;
  gap: 4px;
}

.mailbox-item.active,
.email-item.active {
  border-color: var(--accent);
  box-shadow: inset 0 0 0 1px rgba(29, 92, 74, 0.22);
}

.mailbox-item strong,
.email-item strong {
  display: block;
  margin-bottom: 6px;
  overflow-wrap: anywhere;
  word-break: break-word;
}

.mailbox-item strong {
  display: -webkit-box;
  -webkit-line-clamp: 1;
  -webkit-box-orient: vertical;
  overflow: hidden;
}

.email-item strong {
  display: -webkit-box;
  -webkit-line-clamp: 1;
  -webkit-box-orient: vertical;
  overflow: hidden;
  margin-bottom: 0;
}

.subtle {
  color: var(--muted);
  font-size: 13px;
  overflow-wrap: anywhere;
  word-break: break-word;
}

.mailbox-item .subtle {
  display: -webkit-box;
  -webkit-line-clamp: 1;
  -webkit-box-orient: vertical;
  overflow: hidden;
}

.mailbox-edit {
  flex: 0 0 auto;
}

.email-item .subtle {
  display: -webkit-box;
  -webkit-line-clamp: 1;
  -webkit-box-orient: vertical;
  overflow: hidden;
}

.mailbox-status {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  justify-content: flex-end;
}

.status-pill {
  display: inline-flex;
  align-items: center;
  min-height: 34px;
  padding: 0 12px;
  border: 1px solid var(--line);
  border-radius: 999px;
  background: #fff;
  color: var(--muted);
  font-size: 13px;
}

.status-tag {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  min-height: 34px;
  padding: 0 10px 0 12px;
  border: 1px solid var(--line);
  border-radius: 999px;
  background: #fff;
  color: var(--muted);
  font-size: 13px;
}

.status-tag-icon-only {
  min-width: 34px;
  justify-content: center;
  padding: 0 10px;
}

.status-tag-icon {
  font-size: 15px;
  line-height: 1;
}

.status-tag.loading .status-tag-icon {
  animation: sync-spin 1.8s linear infinite;
}

.email-list.empty,
.email-detail.empty {
  display: grid;
  place-items: center;
  color: var(--muted);
}

.email-detail {
  margin-top: 16px;
  flex: 1;
  min-height: 0;
  overflow-y: auto;
  overflow-x: hidden;
  border: 1px solid var(--line);
  border-radius: 18px;
  background: var(--panel-strong);
  padding: 18px;
}

.detail-meta {
  display: grid;
  gap: 8px;
  margin-bottom: 20px;
}

.detail-body {
  display: grid;
  gap: 16px;
}

.detail-body pre {
  margin: 0;
  padding: 14px;
  white-space: pre-wrap;
  word-break: break-word;
  border-radius: 14px;
  background: #f7f3ec;
}

.detail-html-empty {
  padding: 14px;
  border: 1px solid var(--line);
  border-radius: 14px;
  background: #fff;
}

.detail-html-empty pre {
  margin: 0;
  white-space: pre-wrap;
  word-break: break-word;
}

.detail-html-frame {
  width: 100%;
  min-height: 320px;
  height: 320px;
  border: 1px solid var(--line);
  border-radius: 14px;
  background: #fff;
  overflow: hidden;
  display: block;
  scrollbar-width: none;
}

.attachment-list {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
}

.attachment-list a {
  color: var(--accent);
  text-decoration: none;
}

.modal {
  position: fixed;
  inset: 0;
  display: grid;
  place-items: center;
  padding: 20px;
  background: rgba(31, 35, 33, 0.26);
}

.modal-card {
  width: min(860px, 100%);
  max-height: min(90vh, 980px);
  padding: 20px;
  overflow: auto;
}

.modal-card-compact {
  width: min(420px, 100%);
}

.modal-sheet {
  align-items: end;
}

.email-sheet-card {
  width: min(760px, 100%);
}

.email-sheet-card .email-detail {
  margin-top: 12px;
  min-height: 0;
  max-height: none;
  height: calc(80svh - 88px);
}

.icon-btn {
  width: 40px;
  height: 40px;
  padding: 0;
  font-size: 24px;
  line-height: 1;
}

.icon-btn-plain {
  border-color: transparent;
  background: transparent;
  color: var(--muted);
}

.icon-btn-plain:hover {
  border-color: var(--line);
  background: #fff;
  color: var(--ink);
}

.mailbox-form {
  margin-top: 16px;
}

.grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 12px;
}

.grid-single {
  grid-template-columns: 1fr;
}

.full {
  grid-column: 1 / -1;
}

.toggle {
  display: flex !important;
  align-items: center;
  justify-content: space-between;
  min-height: 46px;
}

.toggle input {
  width: 18px;
  height: 18px;
}

.modal-actions {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  flex-wrap: wrap;
  margin-top: 18px;
}

.modal-actions-end {
  justify-content: flex-end;
}

.action-group {
  display: flex;
  gap: 10px;
  flex-wrap: wrap;
}

.toast {
  position: fixed;
  right: 20px;
  bottom: 20px;
  max-width: 360px;
  padding: 12px 14px;
  border-radius: 14px;
  background: rgba(31, 35, 33, 0.94);
  color: #fff;
  box-shadow: var(--shadow);
}

@keyframes sync-spin {
  from {
    transform: rotate(0deg);
  }
  to {
    transform: rotate(360deg);
  }
}

@media (max-width: 1200px) {
  body {
    overflow: auto;
  }

  .app-shell {
    height: auto;
    min-height: 100vh;
    min-height: 100svh;
    overflow: visible;
  }

  .workspace {
    grid-template-columns: 1fr;
    overflow: visible;
  }

  .sidebar,
  .panel {
    height: auto;
    min-height: 0;
  }

  .mailbox-list,
  .email-list,
  .email-detail {
    max-height: 34svh;
  }

  .email-list,
  .email-detail {
    min-height: 220px;
  }
}

@media (max-width: 720px) {
  body {
    overflow: hidden;
  }

  .app-shell {
    min-height: 100vh;
    min-height: 100svh;
    height: 100vh;
    height: 100svh;
    padding: 12px;
    overflow: hidden;
  }

  .topbar {
    flex-direction: row;
    align-items: flex-start;
    justify-content: space-between;
    gap: 12px;
  }

  .topbar h1 {
    font-size: 26px;
  }

  .topbar-title p {
    margin-top: 4px;
    font-size: 13px;
  }

  .topbar-title {
    min-width: 0;
    flex: 1;
  }

  .topbar-actions {
    flex: 0 0 auto;
    margin-left: auto;
    justify-content: flex-end;
  }

  .desktop-action {
    display: none;
  }

  .mobile-menu-wrap {
    display: block;
  }

  .topbar-actions .icon-btn {
    width: 40px;
  }

  .mobile-switcher {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 8px;
    margin-bottom: 12px;
    padding: 4px;
    border: 1px solid var(--line);
    border-radius: 18px;
    background: rgba(255, 253, 250, 0.92);
  }

  .mobile-switcher button {
    min-height: 40px;
    border-color: transparent;
    background: transparent;
    color: var(--muted);
  }

  .mobile-switcher button.active {
    border-color: var(--accent);
    background: var(--accent);
    color: #fff;
  }

  .mailbox-status,
  .modal-actions,
  .action-group {
    flex-direction: column;
  }

  .workspace {
    display: block;
    flex: 1;
    min-height: 0;
    overflow: hidden;
  }

  .panel-head {
    gap: 10px;
  }

  .sidebar,
  .panel {
    height: 100%;
    padding: 14px;
    border-radius: 18px;
  }

  .app-shell.mobile-layout .sidebar,
  .app-shell.mobile-layout .mail-panel,
  .app-shell.mobile-layout .detail-panel {
    display: none;
  }

  .app-shell.mobile-layout[data-mobile-section="mailboxes"] .sidebar,
  .app-shell.mobile-layout[data-mobile-section="emails"] .mail-panel {
    display: flex;
  }

  .mailbox-list {
    grid-auto-rows: 76px;
    max-height: none;
  }

  .email-list {
    grid-auto-rows: 74px;
    max-height: none;
  }

  .email-detail {
    max-height: none;
    min-height: 320px;
    padding: 14px;
  }

  .detail-panel {
    display: none !important;
  }

  .mailbox-item {
    height: 76px;
    border-radius: 14px;
  }

  .email-item {
    height: 74px;
    border-radius: 14px;
    padding: 12px;
  }

  .status-tag {
    width: 100%;
    justify-content: space-between;
  }

  .modal {
    padding: 10px;
    align-items: end;
  }

  .modal-card,
  .modal-card-compact {
    width: 100%;
    max-height: 88svh;
    border-radius: 20px 20px 16px 16px;
    padding: 16px;
  }

  .email-sheet-card {
    max-height: 80svh;
  }

  .email-sheet-card .email-detail {
    height: calc(80svh - 84px);
    padding: 14px;
  }

  .grid {
    grid-template-columns: 1fr;
  }
}

@media (max-width: 520px) {
  .app-shell {
    padding: 10px;
  }

  .workspace {
    gap: 10px;
  }

  .topbar h1 {
    font-size: 22px;
  }

  .panel-kicker {
    margin-bottom: 4px;
  }

  .icon-btn {
    width: 36px;
    height: 36px;
    font-size: 20px;
  }

  .mailbox-main strong,
  .email-item strong {
    font-size: 14px;
  }

  .subtle,
  .status-pill,
  .status-tag {
    font-size: 12px;
  }

  .detail-meta {
    gap: 6px;
    margin-bottom: 16px;
  }

  .detail-html-frame {
    min-height: 240px;
  }

  .toast {
    right: 10px;
    left: 10px;
    bottom: 10px;
    max-width: none;
  }
}
