:root {
  color-scheme: light;
  --bg: #f4f6f8;
  --panel: #ffffff;
  --text: #20242a;
  --muted: #64717f;
  --line: #d9e0e7;
  --accent: #176b87;
  --accent-strong: #0e4f66;
  --error: #b3261e;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  min-height: 100vh;
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "Microsoft YaHei", sans-serif;
  line-height: 1.5;
}

a {
  color: inherit;
}

code {
  border: 1px solid var(--line);
  border-radius: 5px;
  background: #eef3f6;
  padding: 2px 5px;
  font-family: Consolas, "SFMono-Regular", monospace;
  font-size: 0.92em;
}

.shell {
  width: min(1120px, calc(100% - 32px));
  margin: 0 auto;
  padding: 32px 0;
}

.panel {
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel);
  padding: 24px;
  box-shadow: 0 12px 28px rgba(32, 36, 42, 0.06);
}

.intro {
  display: grid;
  gap: 22px;
  max-width: 840px;
  margin: 7vh auto 0;
}

.eyebrow {
  margin: 0 0 6px;
  color: var(--accent);
  font-size: 13px;
  font-weight: 700;
  text-transform: uppercase;
}

h1,
h2,
p {
  margin-top: 0;
}

h1 {
  margin-bottom: 10px;
  font-size: clamp(28px, 4vw, 42px);
  line-height: 1.15;
  letter-spacing: 0;
}

h2 {
  margin-bottom: 0;
  font-size: 18px;
  line-height: 1.3;
}

.muted,
.notes {
  color: var(--muted);
}

.notes p:last-child,
.error-panel p:last-of-type {
  margin-bottom: 0;
}

.format-box {
  display: grid;
  gap: 8px;
}

.format-box span {
  color: var(--muted);
  font-size: 14px;
}

.format-box code {
  display: block;
  overflow-x: auto;
  padding: 12px;
  white-space: nowrap;
}

.public-login .button {
  justify-self: start;
}

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

.topbar h1 {
  margin-bottom: 0;
  word-break: break-word;
}

.button {
  display: inline-flex;
  min-height: 40px;
  align-items: center;
  justify-content: center;
  border: 1px solid var(--accent);
  border-radius: 6px;
  background: var(--accent);
  color: #fff;
  padding: 0 16px;
  text-decoration: none;
  white-space: nowrap;
}

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

.button:disabled {
  cursor: wait;
  opacity: 0.62;
}

.button.secondary {
  border-color: var(--line);
  background: #fff;
  color: var(--text);
}

.button.secondary:hover {
  background: #eef3f6;
}

.button.danger {
  border-color: var(--error);
  background: var(--error);
}

.button.danger:hover {
  background: #8f1d17;
}

.button.compact {
  min-height: 32px;
  padding: 0 10px;
  font-size: 13px;
}

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

.auth-panel {
  max-width: 520px;
  margin: 10vh auto 0;
}

.form {
  display: grid;
  gap: 16px;
}

.form label {
  display: grid;
  gap: 7px;
}

.form label span {
  color: var(--muted);
  font-size: 14px;
}

input:not([type="checkbox"]),
textarea,
select {
  width: 100%;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: #fff;
  color: var(--text);
  padding: 11px 12px;
  font: inherit;
}

textarea {
  min-height: 180px;
  resize: vertical;
  font-family: Consolas, "SFMono-Regular", monospace;
}

input:not([type="checkbox"]):focus,
textarea:focus,
select:focus {
  outline: 2px solid rgba(23, 107, 135, 0.22);
  border-color: var(--accent);
}

.admin-toolbar,
.bulk-bar,
.pagination-bar {
  display: flex;
  gap: 12px;
  align-items: end;
  flex-wrap: wrap;
  margin-bottom: 14px;
}

.bulk-bar,
.pagination-bar {
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fbfcfd;
  padding: 12px;
}

.inline-field {
  display: grid;
  gap: 6px;
  min-width: 160px;
}

.inline-field.search-field {
  min-width: min(320px, 100%);
  flex: 1 1 280px;
}

.inline-field.page-field {
  min-width: 96px;
  width: 120px;
}

.inline-field span {
  color: var(--muted);
  font-size: 13px;
}

.pagination-bar {
  align-items: center;
}

.pagination-bar .muted {
  margin-left: auto;
}

.alert {
  border: 1px solid var(--line);
  border-radius: 8px;
  margin-bottom: 16px;
  padding: 12px 14px;
}

.alert.success {
  border-color: rgba(16, 124, 65, 0.35);
  background: #eef8f2;
  color: #0f6a3a;
}

.alert.error {
  border-color: rgba(179, 38, 30, 0.35);
  background: #fff1ef;
  color: var(--error);
}

.alert.warning {
  border-color: rgba(138, 90, 0, 0.35);
  background: #fff8e1;
  color: #8a5a00;
}

.table-wrap {
  overflow-x: auto;
}

.mailbox-table {
  width: 100%;
  border-collapse: collapse;
  min-width: 1080px;
}

.mailbox-table th,
.mailbox-table td {
  border-bottom: 1px solid var(--line);
  padding: 11px 10px;
  text-align: left;
  vertical-align: top;
}

.mailbox-table th {
  color: var(--muted);
  font-size: 13px;
  font-weight: 700;
}

.mailbox-table th:first-child,
.mailbox-table td:first-child {
  width: 42px;
}

.mailbox-table td {
  overflow-wrap: anywhere;
}

.mailbox-row {
  cursor: pointer;
}

.mailbox-row:hover {
  background: #f7fafb;
}

.mailbox-row:focus-visible {
  outline: 2px solid rgba(23, 107, 135, 0.28);
  outline-offset: -2px;
  background: #f7fafb;
}

.mailbox-row input,
.mailbox-row button,
.mailbox-row select {
  cursor: auto;
}

.status-pill {
  display: inline-flex;
  min-width: 64px;
  align-items: center;
  justify-content: center;
  border-radius: 999px;
  padding: 3px 9px;
  font-size: 13px;
  font-weight: 700;
}

.status-unused {
  background: #eef8f2;
  color: #0f6a3a;
}

.status-in_use {
  background: #fff5d6;
  color: #8a5a00;
}

.status-used {
  background: #eef3f6;
  color: #586675;
}

.row-actions {
  display: flex;
  gap: 8px;
  align-items: center;
  flex-wrap: wrap;
}

.row-actions select {
  width: auto;
  min-width: 96px;
  padding: 7px 8px;
}

.row-actions a {
  white-space: nowrap;
}

.import-progress {
  display: grid;
  gap: 10px;
  margin-top: 16px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fbfcfd;
  padding: 12px 14px;
}

.progress-head {
  display: flex;
  gap: 12px;
  align-items: baseline;
  justify-content: space-between;
}

.progress-actions {
  display: flex;
  gap: 10px;
  align-items: center;
  flex-wrap: wrap;
  justify-content: flex-end;
}

.progress-head span,
.progress-stats {
  color: var(--muted);
  font-size: 14px;
}

.import-progress progress {
  width: 100%;
  height: 12px;
  accent-color: var(--accent);
}

.import-results {
  margin-top: 16px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fbfcfd;
  padding: 12px 14px;
}

.import-results ul {
  display: grid;
  gap: 8px;
  margin: 0;
  padding-left: 20px;
}

.result-success {
  color: #0f6a3a;
}

.result-warning {
  color: #8a5a00;
}

.result-pending {
  color: var(--accent);
}

.result-skipped {
  color: var(--muted);
}

.result-error {
  color: var(--error);
}

.section-title {
  display: flex;
  gap: 12px;
  align-items: baseline;
  justify-content: space-between;
  margin-bottom: 14px;
}

.section-title span {
  color: var(--muted);
  font-size: 14px;
}

.message-list {
  display: grid;
  border-top: 1px solid var(--line);
}

.message-row {
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(180px, 280px);
  gap: 18px;
  align-items: center;
  border-bottom: 1px solid var(--line);
  padding: 14px 0;
  text-decoration: none;
}

.message-row:hover strong {
  color: var(--accent);
}

.message-main,
.message-meta {
  display: grid;
  gap: 4px;
  min-width: 0;
}

.message-main strong,
.message-main span,
.message-meta span {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.message-main span,
.message-meta {
  color: var(--muted);
  font-size: 14px;
}

.message-meta {
  justify-items: end;
}

.empty {
  border: 1px dashed var(--line);
  border-radius: 8px;
  color: var(--muted);
  padding: 18px;
  text-align: center;
}

.empty.compact {
  padding: 12px;
  text-align: left;
}

.detail {
  display: grid;
  gap: 24px;
}

.meta-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 14px;
  margin: 0;
}

.meta-grid div {
  min-width: 0;
}

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

.meta-grid dd {
  margin: 4px 0 0;
  overflow-wrap: anywhere;
}

.body-block {
  display: grid;
  gap: 10px;
}

pre {
  overflow-x: auto;
  max-height: 620px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fbfcfd;
  padding: 16px;
  white-space: pre-wrap;
  word-wrap: break-word;
}

.html-preview {
  width: 100%;
  min-height: 520px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
}

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

.attachments li {
  display: flex;
  gap: 10px;
  align-items: center;
  justify-content: space-between;
  border: 1px solid var(--line);
  border-radius: 6px;
  padding: 10px 12px;
}

.attachments span {
  overflow-wrap: anywhere;
}

.error-panel {
  max-width: 680px;
  margin: 10vh auto 0;
  border-color: rgba(179, 38, 30, 0.3);
}

.error-panel h1 {
  color: var(--error);
}

@media (max-width: 720px) {
  .shell {
    width: min(100% - 20px, 1120px);
    padding: 16px 0;
  }

  .panel {
    padding: 18px;
  }

  .topbar,
  .section-title,
  .attachments li {
    align-items: stretch;
    flex-direction: column;
  }

  .message-row,
  .meta-grid {
    grid-template-columns: 1fr;
  }

  .message-meta {
    justify-items: start;
  }

  .public-login .button {
    width: 100%;
  }
}
