:root {
  --bg: #f6f7fb;
  --panel: #ffffff;
  --panel-2: #f1f4f9;
  --border: #dfe4ee;
  --text: #172033;
  --muted: #667085;
  --brand: #2563eb;
  --brand-2: #1d4ed8;
  --green: #12805c;
  --amber: #b45309;
  --red: #c0392b;
  --shadow: 0 8px 30px rgba(23, 32, 51, .08);
  --radius: 14px;
  --mono: ui-monospace, SFMono-Regular, Menlo, Consolas, "Liberation Mono", monospace;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0e1420;
    --panel: #151d2c;
    --panel-2: #1b2537;
    --border: #273349;
    --text: #e6ebf5;
    --muted: #9aa7bd;
    --brand: #5b8cff;
    --brand-2: #7aa2ff;
    --green: #3ddc97;
    --amber: #f5b74b;
    --red: #ff6b6b;
    --shadow: 0 8px 30px rgba(0, 0, 0, .35);
  }
}

* { box-sizing: border-box; }
html, body { height: 100%; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 14px/1.55 -apple-system, BlinkMacSystemFont, "Segoe UI", "PingFang SC", "Hiragino Sans GB", "Microsoft YaHei", sans-serif;
  -webkit-font-smoothing: antialiased;
}
a { color: var(--brand); text-decoration: none; }
a:hover { text-decoration: underline; }
button, input, select, textarea { font: inherit; color: inherit; }
button { cursor: pointer; }
.boot { display: grid; place-items: center; height: 100vh; color: var(--muted); }

/* ---------- auth ---------- */
.auth-wrap {
  min-height: 100vh;
  display: grid;
  place-items: center;
  padding: 24px;
  background:
    radial-gradient(900px 500px at 15% 0%, rgba(37, 99, 235, .13), transparent 60%),
    radial-gradient(700px 400px at 100% 100%, rgba(18, 128, 92, .10), transparent 60%);
}
.card {
  width: 100%;
  max-width: 440px;
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 18px;
  box-shadow: var(--shadow);
  padding: 28px;
}
.card.wide { max-width: 760px; }
.card h1 { font-size: 20px; margin: 0 0 6px; }
.card .sub { color: var(--muted); margin: 0 0 22px; font-size: 13px; }
.brand-mark {
  width: 42px; height: 42px; border-radius: 12px;
  display: grid; place-items: center;
  background: linear-gradient(135deg, var(--brand), #7c3aed);
  color: #fff; font-weight: 700; font-size: 18px; margin-bottom: 14px;
}
.field { display: grid; gap: 6px; margin-bottom: 14px; }
.field label { font-size: 12px; color: var(--muted); font-weight: 600; letter-spacing: .02em; }
.input, .select, .textarea {
  width: 100%;
  border: 1px solid var(--border);
  background: var(--panel-2);
  border-radius: 10px;
  padding: 10px 12px;
  outline: none;
  transition: border-color .15s, box-shadow .15s;
}
.input:focus, .select:focus, .textarea:focus {
  border-color: var(--brand);
  box-shadow: 0 0 0 3px rgba(37, 99, 235, .15);
}
.textarea { min-height: 96px; resize: vertical; font-family: var(--mono); font-size: 12.5px; }
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  border: 1px solid var(--border);
  background: var(--panel-2);
  color: var(--text);
  border-radius: 10px;
  padding: 9px 14px;
  font-weight: 600;
  white-space: nowrap;
  transition: transform .06s, background .15s, border-color .15s;
}
.btn:hover { border-color: var(--brand); }
.btn:active { transform: translateY(1px); }
.btn.primary { background: var(--brand); border-color: var(--brand); color: #fff; }
.btn.primary:hover { background: var(--brand-2); }
.btn.danger { color: #fff; background: var(--red); border-color: var(--red); }
.btn.ghost { background: transparent; }
.btn.small { padding: 5px 9px; font-size: 12px; border-radius: 8px; }
.btn.block { width: 100%; }
.btn:disabled { opacity: .55; cursor: not-allowed; }
.alert {
  border: 1px solid rgba(192, 57, 43, .35);
  background: rgba(192, 57, 43, .08);
  color: var(--red);
  border-radius: 10px;
  padding: 10px 12px;
  margin-bottom: 14px;
  font-size: 13px;
  white-space: pre-wrap;
}
.alert.info { border-color: rgba(37, 99, 235, .3); background: rgba(37, 99, 235, .08); color: var(--brand); }
.alert.ok { border-color: rgba(18, 128, 92, .3); background: rgba(18, 128, 92, .08); color: var(--green); }
.muted { color: var(--muted); }
.small { font-size: 12px; }
.mono { font-family: var(--mono); }
.center { text-align: center; }
.row { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; }
.spread { display: flex; align-items: center; justify-content: space-between; gap: 10px; }
.stack { display: grid; gap: 14px; }
.divider { height: 1px; background: var(--border); margin: 18px 0; }

/* ---------- app shell ---------- */
.app { min-height: 100vh; display: flex; flex-direction: column; }
.topbar {
  position: sticky; top: 0; z-index: 20;
  display: flex; align-items: center; gap: 18px;
  padding: 10px 18px;
  background: color-mix(in srgb, var(--panel) 88%, transparent);
  border-bottom: 1px solid var(--border);
  backdrop-filter: blur(10px);
}
.topbar .brand { display: flex; align-items: center; gap: 10px; font-weight: 700; letter-spacing: .01em; }
.topbar .brand .logo {
  width: 30px; height: 30px; border-radius: 9px;
  background: linear-gradient(135deg, var(--brand), #7c3aed);
  display: grid; place-items: center; color: #fff; font-size: 14px;
}
.nav { display: flex; gap: 4px; margin-left: 6px; overflow-x: auto; }
.nav button {
  border: 0; background: transparent; color: var(--muted);
  padding: 7px 11px; border-radius: 9px; font-weight: 600; white-space: nowrap;
}
.nav button.active { color: var(--brand); background: rgba(37, 99, 235, .1); }
.nav button:hover { color: var(--text); }
.topbar .spacer { flex: 1; }
.userbox { display: flex; align-items: center; gap: 10px; }
.avatar {
  width: 30px; height: 30px; border-radius: 50%;
  display: grid; place-items: center;
  background: var(--panel-2); border: 1px solid var(--border);
  font-weight: 700; color: var(--brand);
}
.userbox .who { line-height: 1.15; }
.userbox .who b { display: block; font-size: 12.5px; }
.userbox .who span { display: block; font-size: 11px; color: var(--muted); }

.layout { flex: 1; display: grid; grid-template-columns: 250px minmax(0, 1fr); min-height: 0; }
.sidebar {
  border-right: 1px solid var(--border);
  background: var(--panel);
  padding: 16px 12px;
  overflow-y: auto;
}
.sidebar h3 { font-size: 11px; text-transform: uppercase; letter-spacing: .08em; color: var(--muted); margin: 6px 8px 8px; }
.domain-list { display: grid; gap: 4px; }
.domain-item {
  display: flex; align-items: center; gap: 8px;
  padding: 8px 10px; border-radius: 9px;
  color: var(--text); border: 1px solid transparent; background: transparent;
  text-align: left; width: 100%;
}
.domain-item:hover { background: var(--panel-2); }
.domain-item.active { background: rgba(37, 99, 235, .1); border-color: rgba(37, 99, 235, .25); color: var(--brand); }
.domain-item .dot { width: 7px; height: 7px; border-radius: 50%; background: var(--muted); flex: 0 0 auto; }
.domain-item .dot.ready { background: var(--green); }
.domain-item .dot.misconfigured { background: var(--amber); }
.domain-item .dot.disabled { background: var(--red); }
.domain-item .name { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-weight: 600; font-size: 13px; }
.domain-item .count { font-size: 11px; color: var(--muted); background: var(--panel-2); border-radius: 20px; padding: 1px 7px; }

.main { min-width: 0; display: flex; flex-direction: column; }
.toolbar {
  display: flex; align-items: center; gap: 10px;
  padding: 12px 18px; border-bottom: 1px solid var(--border);
  background: var(--panel); flex-wrap: wrap;
}
.search { position: relative; flex: 1; min-width: 180px; max-width: 520px; }
.search .input { padding-left: 34px; }
.search svg { position: absolute; left: 11px; top: 50%; transform: translateY(-50%); opacity: .5; }
.toolbar .meta { color: var(--muted); font-size: 12px; }

.content { flex: 1; min-height: 0; display: grid; grid-template-columns: minmax(300px, 420px) minmax(0, 1fr); }
.msg-list { border-right: 1px solid var(--border); overflow-y: auto; background: var(--panel); }
.msg-row {
  display: block; width: 100%; text-align: left;
  border: 0; border-bottom: 1px solid var(--border);
  background: transparent; padding: 12px 16px; color: inherit;
}
.msg-row:hover { background: var(--panel-2); }
.msg-row.active { background: rgba(37, 99, 235, .08); box-shadow: inset 3px 0 0 var(--brand); }
.msg-row .line1 { display: flex; align-items: center; gap: 8px; }
.msg-row .rcpt { font-weight: 700; font-size: 12.5px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; flex: 1; }
.msg-row .time { font-size: 11px; color: var(--muted); white-space: nowrap; }
.msg-row .subject { color: var(--text); font-size: 13px; margin: 3px 0 2px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.msg-row .from { color: var(--muted); font-size: 11.5px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.badge {
  display: inline-flex; align-items: center; gap: 4px;
  font-size: 10.5px; font-weight: 700; letter-spacing: .02em;
  padding: 2px 7px; border-radius: 999px;
  background: var(--panel-2); border: 1px solid var(--border); color: var(--muted);
  white-space: nowrap;
}
.badge.ready, .badge.ok { color: var(--green); border-color: rgba(18, 128, 92, .3); background: rgba(18, 128, 92, .08); }
.badge.pending { color: var(--amber); border-color: rgba(180, 83, 9, .3); background: rgba(180, 83, 9, .08); }
.badge.misconfigured, .badge.bad { color: var(--red); border-color: rgba(192, 57, 43, .3); background: rgba(192, 57, 43, .08); }
.badge.disabled { color: var(--muted); }
.code-chip {
  font-family: var(--mono); font-size: 11.5px; font-weight: 700;
  color: var(--brand); background: rgba(37, 99, 235, .1);
  border: 1px solid rgba(37, 99, 235, .25);
  padding: 1px 6px; border-radius: 6px;
}

.detail { min-width: 0; overflow-y: auto; background: var(--bg); }
.detail-empty { height: 100%; display: grid; place-items: center; color: var(--muted); padding: 30px; text-align: center; }
.detail-inner { padding: 20px 24px 40px; max-width: 980px; }
.detail h2 { font-size: 19px; margin: 6px 0 10px; line-height: 1.35; word-break: break-word; }
.meta-grid { display: grid; grid-template-columns: 76px minmax(0, 1fr); gap: 4px 12px; font-size: 12.5px; color: var(--muted); }
.meta-grid b { color: var(--text); font-weight: 600; overflow: hidden; text-overflow: ellipsis; }
.code-box {
  display: flex; align-items: center; gap: 12px; flex-wrap: wrap;
  border: 1px dashed rgba(37, 99, 235, .45);
  background: rgba(37, 99, 235, .07);
  border-radius: 12px; padding: 14px 16px; margin: 18px 0;
}
.code-box .code { font-family: var(--mono); font-size: 24px; font-weight: 800; letter-spacing: .14em; color: var(--brand); }
.code-box .hint { color: var(--muted); font-size: 12px; }
.tabs { display: flex; gap: 4px; border-bottom: 1px solid var(--border); margin: 18px 0 12px; }
.tabs button { border: 0; background: transparent; padding: 8px 10px; color: var(--muted); font-weight: 600; border-bottom: 2px solid transparent; }
.tabs button.active { color: var(--brand); border-bottom-color: var(--brand); }
.body-text {
  white-space: pre-wrap; word-break: break-word;
  background: var(--panel); border: 1px solid var(--border); border-radius: 12px;
  padding: 16px; font-size: 13.5px; line-height: 1.65;
  max-height: 60vh; overflow: auto;
}
.frame { width: 100%; height: 60vh; border: 1px solid var(--border); border-radius: 12px; background: #fff; }
.links { display: grid; gap: 6px; margin-top: 10px; }
.link-row {
  display: flex; align-items: center; gap: 8px;
  background: var(--panel); border: 1px solid var(--border); border-radius: 10px; padding: 8px 10px;
  font-size: 12.5px;
}
.link-row a { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; flex: 1; }

/* ---------- admin ---------- */
.admin-wrap { padding: 22px; max-width: 1180px; width: 100%; margin: 0 auto; }
.admin-head { display: flex; align-items: center; justify-content: space-between; gap: 14px; margin-bottom: 16px; flex-wrap: wrap; }
.admin-head h1 { font-size: 20px; margin: 0; }
.panel {
  background: var(--panel); border: 1px solid var(--border); border-radius: var(--radius);
  box-shadow: var(--shadow); overflow: hidden;
}
.panel + .panel { margin-top: 16px; }
.panel-head { padding: 14px 16px; border-bottom: 1px solid var(--border); display: flex; align-items: center; justify-content: space-between; gap: 10px; flex-wrap: wrap; }
.panel-head h2 { font-size: 15px; margin: 0; }
.panel-body { padding: 16px; }
.table-wrap { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; font-size: 13px; }
th, td { text-align: left; padding: 10px 12px; border-bottom: 1px solid var(--border); vertical-align: top; }
th { color: var(--muted); font-size: 11px; text-transform: uppercase; letter-spacing: .06em; font-weight: 700; white-space: nowrap; }
tr:last-child td { border-bottom: 0; }
td .actions { display: flex; gap: 6px; flex-wrap: wrap; }
.form-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 12px; }
.form-grid .full { grid-column: 1 / -1; }
.checklist { display: grid; gap: 6px; max-height: 220px; overflow: auto; border: 1px solid var(--border); border-radius: 10px; padding: 10px; background: var(--panel-2); }
.checklist label { display: flex; align-items: center; gap: 8px; font-size: 13px; }
.checklist input { accent-color: var(--brand); }
.kv { display: grid; grid-template-columns: 150px minmax(0, 1fr); gap: 6px 12px; font-size: 13px; }
.kv b { color: var(--muted); font-weight: 600; }

/* ---------- modal / toast ---------- */
.modal-back {
  position: fixed; inset: 0; z-index: 50;
  background: rgba(10, 16, 28, .55);
  display: grid; place-items: center; padding: 20px;
}
.modal {
  width: 100%; max-width: 640px; max-height: 88vh; overflow: auto;
  background: var(--panel); border: 1px solid var(--border); border-radius: 16px;
  box-shadow: 0 20px 60px rgba(0,0,0,.35);
}
.modal-head { padding: 16px 18px; border-bottom: 1px solid var(--border); display: flex; align-items: center; justify-content: space-between; }
.modal-head h3 { margin: 0; font-size: 16px; }
.modal-body { padding: 18px; }
.modal-foot { padding: 14px 18px; border-top: 1px solid var(--border); display: flex; justify-content: flex-end; gap: 8px; }
.toast {
  position: fixed; left: 50%; bottom: 24px; transform: translateX(-50%);
  z-index: 60; background: #111827; color: #fff;
  padding: 10px 16px; border-radius: 10px; font-size: 13px;
  box-shadow: 0 10px 30px rgba(0,0,0,.3); max-width: 90vw;
}
.toast.err { background: var(--red); }

.empty { padding: 40px 20px; text-align: center; color: var(--muted); }
.spinner {
  width: 16px; height: 16px; border-radius: 50%;
  border: 2px solid rgba(255,255,255,.35); border-top-color: #fff;
  animation: spin .8s linear infinite; display: inline-block;
}
@keyframes spin { to { transform: rotate(360deg); } }

@media (max-width: 980px) {
  .layout { grid-template-columns: 1fr; }
  .sidebar { border-right: 0; border-bottom: 1px solid var(--border); max-height: 180px; }
  .content { grid-template-columns: 1fr; }
  .msg-list { border-right: 0; max-height: 45vh; }
  .detail { min-height: 40vh; }
}
@media (max-width: 640px) {
  .topbar { gap: 10px; padding: 9px 12px; }
  .topbar .brand span.full { display: none; }
  .nav { gap: 0; }
  .nav button { padding: 6px 8px; font-size: 12.5px; }
  .userbox .who { display: none; }
  .form-grid { grid-template-columns: 1fr; }
  .admin-wrap { padding: 14px; }
  .detail-inner { padding: 16px; }
  .kv { grid-template-columns: 110px minmax(0, 1fr); }
}
