:root {
  --bg: #f5f7fa;
  --panel: #ffffff;
  --panel-soft: #f8fafc;
  --line: #d9e2ec;
  --line-soft: #eef2f6;
  --text: #17212f;
  --muted: #657386;
  --primary: #2563eb;
  --primary-hover: #1d4ed8;
  --blue-soft: #eff6ff;
  --warning: #a16207;
  --warning-soft: #fffbeb;
  --shadow: 0 10px 28px rgba(15, 23, 42, 0.08);
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }

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

h1,
h2,
p { margin: 0; }

h1 {
  font-size: 22px;
  line-height: 1.2;
  letter-spacing: 0;
}

h2 {
  font-size: 16px;
  line-height: 1.3;
}

button,
input,
textarea {
  font: inherit;
}

button { cursor: pointer; }
button:disabled { cursor: not-allowed; opacity: 0.55; }

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

.topbar,
.panel {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 8px;
}

.topbar {
  display: flex;
  align-items: stretch;
  justify-content: space-between;
  gap: 16px;
  padding: 16px 18px;
  margin-bottom: 12px;
  box-shadow: var(--shadow);
}

.topbar-side {
  flex: 1;
  max-width: 820px;
  display: grid;
  grid-template-columns: 150px minmax(420px, 1fr);
  gap: 12px;
  align-items: stretch;
}

.sync-card {
  display: grid;
  align-content: center;
  gap: 3px;
  padding: 10px 14px;
  border: 1px solid #bfdbfe;
  border-radius: 8px;
  background: var(--blue-soft);
}

.sync-card span,
.sync-card small {
  color: var(--muted);
  font-size: 12px;
  font-weight: 700;
}

.sync-card strong {
  color: #1d4ed8;
  font-size: 26px;
  line-height: 1;
}

.business-card {
  display: flex;
  align-items: stretch;
  justify-content: space-between;
  gap: 14px;
  padding: 12px 14px;
  border: 1px solid #bfdbfe;
  border-radius: 8px;
  background: linear-gradient(135deg, #eff6ff 0%, #ffffff 58%, #eef2ff 100%);
}

.business-title {
  color: #1e3a8a;
  font-size: 14px;
  font-weight: 800;
}

.business-desc {
  margin-top: 4px;
  color: #334155;
  font-weight: 600;
}

.support-note {
  margin-top: 4px;
  color: var(--muted);
  font-size: 12px;
}

.wechat-box {
  min-width: 172px;
  display: grid;
  align-content: center;
  gap: 4px;
  padding-left: 14px;
  border-left: 1px solid #c7d2fe;
}

.wechat-box span {
  color: var(--muted);
  font-size: 12px;
  font-weight: 700;
}

.wechat-box strong {
  color: #1d4ed8;
  font-size: 15px;
  line-height: 1.2;
}

.panel {
  padding: 14px;
  margin-bottom: 12px;
}

.panel-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 12px;
}

.muted {
  color: var(--muted);
  margin-top: 4px;
}

.field {
  display: grid;
  gap: 5px;
  color: var(--muted);
  font-size: 12px;
  font-weight: 600;
}

.inline-field.grow {
  flex: 1;
  min-width: 260px;
}

input,
textarea {
  width: 100%;
  min-height: 36px;
  border: 1px solid var(--line);
  border-radius: 6px;
  padding: 8px 10px;
  color: var(--text);
  background: #fff;
  outline: none;
}

textarea {
  resize: vertical;
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, "Liberation Mono", monospace;
  font-size: 12px;
  line-height: 1.55;
}

input:focus,
textarea:focus {
  border-color: #93b4ff;
  box-shadow: 0 0 0 3px rgba(37, 99, 235, 0.12);
}

.compact-area { min-height: 130px; }

.btn {
  min-height: 36px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  border: 1px solid var(--line);
  border-radius: 6px;
  padding: 8px 12px;
  color: #263445;
  background: #fff;
  white-space: nowrap;
  font-weight: 600;
}

.btn:hover { background: var(--panel-soft); }

.btn-primary {
  color: #fff;
  border-color: var(--primary);
  background: var(--primary);
}

.btn-primary:hover { background: var(--primary-hover); }

.btn-blue {
  color: var(--primary);
  border-color: #bcd0ff;
  background: var(--blue-soft);
}

.btn-blue:hover { background: #dbeafe; }

.btn-blue-soft {
  color: var(--primary);
  border-color: #bcd0ff;
  background: var(--blue-soft);
}

.btn-blue-soft:hover { background: #dbeafe; }

.btn-white {
  color: #334155;
  background: #fff;
}

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

.toolbar {
  display: flex;
  align-items: end;
  gap: 10px;
  flex-wrap: wrap;
  margin-bottom: 12px;
}

.table-wrap {
  overflow: auto;
  border: 1px solid var(--line);
  border-radius: 8px;
}

table {
  width: 100%;
  border-collapse: collapse;
}

.email-table { min-width: 620px; }
.message-table { min-width: 860px; }

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

th {
  position: sticky;
  top: 0;
  z-index: 1;
  color: #475569;
  background: #f8fafc;
  font-size: 12px;
  font-weight: 800;
}

td {
  color: #263445;
  word-break: break-word;
}

tr:last-child td { border-bottom: 0; }

.subject-cell { max-width: 430px; }
.muted-cell { color: var(--muted); margin-top: 3px; }

.badge {
  display: inline-flex;
  align-items: center;
  min-height: 24px;
  padding: 2px 8px;
  border-radius: 999px;
  font-size: 12px;
  font-weight: 800;
}

.badge.info {
  color: #1d4ed8;
  background: var(--blue-soft);
}

.badge.warning {
  color: var(--warning);
  background: var(--warning-soft);
}

.pager {
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: 10px;
  margin-top: 12px;
}

.modal-mask {
  position: fixed;
  inset: 0;
  z-index: 50;
  display: grid;
  place-items: center;
  padding: 18px;
  background: rgba(15, 23, 42, 0.45);
}

.modal {
  width: min(1040px, 100%);
  max-height: calc(100vh - 40px);
  overflow: auto;
  padding: 16px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
  box-shadow: var(--shadow);
}

.mail-list-modal {
  width: min(1180px, 100%);
}

.detail-grid {
  display: grid;
  grid-template-columns: 90px minmax(0, 1fr);
  gap: 8px 12px;
  margin-bottom: 12px;
  padding: 12px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel-soft);
}

.detail-grid span {
  color: var(--muted);
  font-weight: 700;
}

.detail-grid strong {
  min-width: 0;
  word-break: break-word;
}

.message-frame {
  width: 100%;
  height: min(64vh, 720px);
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
}

.toast {
  position: fixed;
  left: 50%;
  bottom: 22px;
  transform: translateX(-50%) translateY(20px);
  z-index: 60;
  max-width: min(520px, calc(100% - 32px));
  padding: 10px 14px;
  color: #fff;
  background: rgba(15, 23, 42, 0.92);
  border-radius: 8px;
  box-shadow: var(--shadow);
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.18s ease, transform 0.18s ease;
}

.toast.show {
  opacity: 1;
  transform: translateX(-50%) translateY(0);
}

@media (max-width: 900px) {
  .topbar {
    align-items: flex-start;
    flex-direction: column;
  }

  .panel-header {
    align-items: flex-start;
    flex-direction: column;
  }

  .topbar-side {
    width: 100%;
    max-width: none;
    grid-template-columns: 1fr;
  }

  .business-card {
    flex-direction: column;
  }

  .wechat-box {
    min-width: 0;
    padding-left: 0;
    padding-top: 10px;
    border-left: 0;
    border-top: 1px solid #c7d2fe;
  }

  .button-row,
  .toolbar {
    width: 100%;
  }
}

@media (max-width: 560px) {
  .app-shell {
    width: calc(100% - 18px);
    padding-top: 12px;
  }

  .inline-field.grow {
    width: 100%;
    min-width: 0;
  }
}
