:root {
  --bg: #f4f6f8;
  --panel: #ffffff;
  --panel-soft: #f8fafc;
  --line: #d9e0e8;
  --line-soft: #edf1f5;
  --text: #16202c;
  --muted: #697586;
  --primary: #2563eb;
  --primary-hover: #1d4ed8;
  --primary-soft: #eff6ff;
  --danger: #dc2626;
  --danger-hover: #b91c1c;
  --success-soft: #e8f7ef;
  --success: #087443;
  --warning-soft: #fff7ed;
  --warning: #9a3412;
  --shadow: 0 8px 24px rgba(15, 23, 42, 0.08);
}

* { box-sizing: border-box; }

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

body {
  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, h3, p { margin: 0; }

button, input, select, textarea {
  font: inherit;
}

button {
  cursor: pointer;
}

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

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

.glass-panel {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 8px;
  box-shadow: none;
}

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

.topbar h1 {
  font-size: 20px;
  font-weight: 700;
  letter-spacing: 0;
}

.hero-copy {
  min-width: 260px;
}

.subtitle,
.business-desc,
.support-note,
.muted {
  color: var(--muted);
}

.subtitle {
  margin-top: 3px;
  font-size: 12px;
}

.business-card {
  flex: 1;
  max-width: 720px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  padding: 12px 14px;
  border: 1px solid #bfdbfe;
  border-radius: 8px;
  background: linear-gradient(180deg, #f8fbff 0%, #eff6ff 100%);
}

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

.business-desc,
.support-note {
  margin-top: 3px;
  font-size: 12px;
}

.wechat-box {
  min-width: 210px;
  display: grid;
  grid-template-columns: auto 1fr auto;
  align-items: center;
  gap: 8px;
  padding: 8px 10px;
  border: 1px solid #dbeafe;
  border-radius: 8px;
  background: #fff;
}

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

.wechat-box strong {
  color: #0f172a;
  font-size: 14px;
  font-weight: 800;
  letter-spacing: 0;
}

.wechat-box .btn {
  min-height: 30px;
  padding: 5px 9px;
  font-size: 12px;
}

.toolbar,
.actions,
.table-panel {
  padding: 12px;
  margin-bottom: 12px;
}

.toolbar-grid {
  display: grid;
  grid-template-columns: minmax(320px, 1fr) 160px 84px repeat(3, auto);
  gap: 10px;
  align-items: end;
}

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

.field.wide { min-width: 280px; }
.field.small { width: 84px; }

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

select {
  padding-right: 28px;
}

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

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

.btn {
  min-height: 34px;
  border: 1px solid var(--line);
  border-radius: 6px;
  padding: 7px 11px;
  color: #263445;
  background: #fff;
  white-space: nowrap;
  font-weight: 500;
}

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

.btn.full { width: 100%; }

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

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

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

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

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

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

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

.btn-danger-soft {
  color: var(--danger);
  border-color: #fecaca;
  background: #fff1f2;
}

.btn-danger-soft:hover {
  color: #fff;
  border-color: var(--danger);
  background: var(--danger);
}

.btn-ghost {
  color: var(--primary);
  background: transparent;
}

.topbar-actions,
.action-group,
.mail-actions,
.modal-actions {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
}

.actions {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  background: transparent;
  border-color: transparent;
  padding: 0;
}

#batchGroupSelect {
  width: 160px;
}

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

.panel-header h2 {
  font-size: 15px;
  font-weight: 700;
}

#totalInfo {
  margin-top: 2px;
  color: var(--muted);
  font-size: 12px;
}

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

.selection-info {
  min-width: 74px;
  color: var(--muted);
  font-size: 12px;
  text-align: right;
}

.table-wrap {
  overflow-x: auto;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: #fff;
}

.mailbox-table {
  width: 100%;
  min-width: 1180px;
  border-collapse: separate;
  border-spacing: 0;
}

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

.mailbox-table th {
  position: sticky;
  top: 0;
  z-index: 1;
  height: 36px;
  color: #536174;
  font-size: 12px;
  font-weight: 700;
  background: #f8fafc;
}

.mailbox-table tbody tr:hover {
  background: #f9fbff;
}

.mailbox-table tbody tr.is-selected {
  background: #eff6ff;
}

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

.check-col { width: 40px; text-align: center; }
.idx-col { width: 54px; color: var(--muted); }
.op-col { width: 132px; }

.account-cell {
  display: grid;
  min-width: 250px;
}

.account-main {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  font-weight: 600;
}

.remark-input {
  width: 220px;
  max-width: 100%;
  min-height: 28px;
  height: 28px;
  padding: 4px 8px;
  border-radius: 5px;
  border-color: transparent;
  background: #f8fafc;
  color: #64748b;
  font-size: 12px;
}

.remark-input:hover,
.remark-input:focus {
  border-color: var(--line);
  background: #fff;
}

.password-cell {
  display: block;
  max-width: 180px;
  overflow: hidden;
  color: #475569;
  text-overflow: ellipsis;
  white-space: nowrap;
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, "Liberation Mono", monospace;
  font-size: 12px;
}

.row-group-select {
  min-width: 128px;
  min-height: 28px;
  height: 28px;
  padding-top: 4px;
  padding-bottom: 4px;
  font-size: 12px;
}

.permission-badge,
.token-badge {
  display: inline-flex;
  align-items: center;
  min-height: 22px;
  padding: 2px 7px;
  border-radius: 999px;
  font-size: 12px;
  font-weight: 700;
}

.badge-graph { color: #1d4ed8; background: #dbeafe; }
.badge-imap { color: var(--success); background: var(--success-soft); }
.badge-failed { color: #64748b; background: #eef2f7; }
.badge-unknown { color: #64748b; background: #eef2f7; }

.token-normal { color: var(--success); background: var(--success-soft); }
.token-invalid { color: var(--warning); background: var(--warning-soft); }
.token-failed { color: #b91c1c; background: #fee2e2; }
.token-unknown { color: #64748b; background: #eef2f7; }

.row-actions {
  display: flex;
  gap: 6px;
}

.row-actions .btn {
  min-height: 28px;
  padding: 4px 8px;
  font-size: 12px;
}

.empty-state {
  padding: 34px 26px;
  color: var(--muted);
  text-align: center;
  background: #fff;
}

.pager {
  display: flex;
  justify-content: flex-end;
  align-items: center;
  gap: 8px;
  margin-top: 10px;
  color: var(--muted);
  font-size: 12px;
}

.icon-button {
  width: 30px;
  height: 30px;
  border: 1px solid var(--line);
  border-radius: 6px;
  color: #475569;
  background: #fff;
  font-size: 18px;
  line-height: 1;
}

#pageInfo {
  min-width: 92px;
  text-align: center;
}

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

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

.modal-mask[hidden] {
  display: none;
}

.modal {
  width: min(720px, 100%);
  max-height: calc(100vh - 36px);
  overflow: auto;
  padding: 16px;
  background: #fff;
  border: 1px solid var(--line);
  border-radius: 8px;
  box-shadow: 0 24px 60px rgba(15, 23, 42, 0.18);
}

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

.modal-header h2 {
  font-size: 15px;
  font-weight: 700;
}

.import-modal textarea {
  margin-top: 10px;
}

.groups-modal {
  width: min(600px, 100%);
}

.group-create {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 8px;
  margin-bottom: 12px;
}

.groups-list {
  display: grid;
  gap: 8px;
}

.group-row {
  display: grid;
  grid-template-columns: 1fr auto auto;
  gap: 8px;
}

.mail-modal {
  width: min(1220px, calc(100vw - 28px));
  height: min(780px, calc(100vh - 28px));
  display: flex;
  flex-direction: column;
  padding: 14px;
}

.mail-header {
  align-items: flex-start;
  margin-bottom: 10px;
}

.mail-header h2 {
  max-width: 620px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.mail-tabs {
  display: flex;
  gap: 6px;
  margin-bottom: 10px;
}

.mail-tab {
  min-height: 30px;
  border: 1px solid var(--line);
  border-radius: 6px;
  padding: 5px 12px;
  color: #475569;
  background: #fff;
  font-weight: 500;
}

.mail-tab.active {
  color: var(--primary);
  border-color: #c7d7fe;
  background: var(--primary-soft);
}

.mail-layout {
  min-height: 0;
  flex: 1;
  display: grid;
  grid-template-columns: 330px 1fr;
  overflow: hidden;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: #fff;
}

.message-list {
  overflow: auto;
  border-right: 1px solid var(--line);
  background: #f8fafc;
}

.message-card {
  padding: 10px 12px;
  border-bottom: 1px solid var(--line-soft);
  cursor: pointer;
}

.message-card:hover {
  background: #f1f5f9;
}

.message-card.active {
  background: #fff;
  box-shadow: inset 3px 0 0 var(--primary);
}

.message-card.error {
  color: var(--danger);
}

.message-sender {
  font-weight: 700;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.message-subject {
  margin-top: 4px;
  color: #263445;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.message-preview {
  margin-top: 4px;
  color: var(--muted);
  font-size: 12px;
  line-height: 1.4;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
}

.message-time {
  margin-top: 6px;
  color: #94a3b8;
  font-size: 11px;
}

.message-detail {
  min-width: 0;
  overflow: auto;
  padding: 16px;
  background: #fff;
}

.message-detail h3 {
  margin-bottom: 10px;
  font-size: 17px;
  font-weight: 700;
  line-height: 1.35;
}

.detail-meta {
  display: grid;
  gap: 4px;
  margin-bottom: 12px;
  padding: 10px 12px;
  color: #536174;
  font-size: 12px;
  background: #f8fafc;
  border: 1px solid var(--line-soft);
  border-radius: 6px;
}

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

.placeholder {
  min-height: 160px;
  display: grid;
  place-items: center;
  color: var(--muted);
  text-align: center;
}

.toast {
  position: fixed;
  left: 50%;
  bottom: 22px;
  transform: translate(-50%, 16px);
  z-index: 60;
  opacity: 0;
  pointer-events: none;
  padding: 9px 13px;
  border-radius: 999px;
  color: #fff;
  background: rgba(15, 23, 42, 0.92);
  box-shadow: 0 18px 40px rgba(15, 23, 42, 0.2);
  transition: 0.16s ease;
}

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

.global-loading {
  position: fixed;
  top: 14px;
  left: 50%;
  z-index: 70;
  transform: translateX(-50%);
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 8px 12px;
  border-radius: 999px;
  color: #334155;
  background: #fff;
  border: 1px solid var(--line);
  box-shadow: var(--shadow);
}

.global-loading[hidden] {
  display: none;
}

.spinner {
  width: 14px;
  height: 14px;
  border: 2px solid #dbeafe;
  border-top-color: var(--primary);
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
}

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

@media (max-width: 980px) {
  .app-shell {
    width: min(100% - 20px, 1440px);
    padding-top: 12px;
  }

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

  .business-card {
    width: 100%;
    max-width: none;
    align-items: stretch;
  }

  .toolbar-grid {
    grid-template-columns: 1fr 1fr;
  }

  .toolbar-grid .wide {
    grid-column: 1 / -1;
  }

  .actions {
    align-items: stretch;
    flex-direction: column;
  }

  .action-group {
    align-items: stretch;
  }

  .action-group .btn,
  #batchGroupSelect {
    flex: 1;
    width: auto;
  }

  .mail-layout {
    grid-template-columns: 1fr;
  }

  .message-list {
    max-height: 250px;
    border-right: 0;
    border-bottom: 1px solid var(--line);
  }
}

@media (max-width: 640px) {
  body {
    font-size: 12px;
  }

  .toolbar-grid {
    grid-template-columns: 1fr;
  }

  .field.small {
    width: 100%;
  }

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

  .group-create,
  .group-row {
    grid-template-columns: 1fr;
  }

  .mail-modal {
    height: calc(100vh - 20px);
    width: calc(100vw - 20px);
  }

  .mail-actions {
    width: 100%;
  }

  .mail-actions .btn {
    flex: 1;
  }

  .business-card,
  .wechat-box {
    grid-template-columns: 1fr;
  }

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

  .account-cell {
    min-width: 240px;
  }

  .panel-actions {
    width: 100%;
    justify-content: space-between;
  }

  .selection-info {
    text-align: left;
  }
}
