:root {
  --bg: #f4f6f9;
  --panel: #ffffff;
  --sidebar: #0f172a;
  --sidebar-2: #16213a;
  --text: #172033;
  --muted: #64748b;
  --line: #e2e8f0;
  --primary: #2563eb;
  --primary-soft: #dbeafe;
  --danger: #dc2626;
  --ok: #059669;
  --warn: #b45309;
  --radius: 10px;
  --mono: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
}

* { box-sizing: border-box; }
html, body { height: 100%; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 14px/1.55 system-ui, -apple-system, "Segoe UI", "Microsoft YaHei", sans-serif;
}
a { color: var(--primary); }
button, input, select, textarea { font: inherit; }
h1, h2, h3, p { margin: 0; }
h1 { font-size: 22px; }
h2 { font-size: 17px; }
h3 { font-size: 15px; }
.muted { color: var(--muted); }
.mono { font-family: var(--mono); }
.hidden { display: none !important; }

/* ---------- login ---------- */
.login-view {
  min-height: 100%;
  display: grid;
  place-items: center;
  padding: 24px;
  background: radial-gradient(1200px 500px at 50% -10%, #dbeafe, transparent), var(--bg);
}
.login-card {
  width: min(420px, 100%);
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 16px;
  padding: 28px;
  box-shadow: 0 20px 50px rgb(15 23 42 / 10%);
}
.login-brand { display: flex; align-items: center; gap: 10px; font-weight: 700; font-size: 20px; }
.login-brand .dot {
  width: 30px; height: 30px; border-radius: 9px;
  background: linear-gradient(135deg, #6ca6ff, #1d4ed8);
}
.login-card h2 { margin-top: 22px; }
.login-card .sub { color: var(--muted); margin: 6px 0 20px; }
.login-card label { display: block; margin-bottom: 12px; }
.login-card label span { display: block; font-size: 12px; color: var(--muted); margin-bottom: 5px; }
.input, .select, .textarea {
  width: 100%;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
  color: var(--text);
  padding: 9px 11px;
  outline: none;
}
.input:focus, .select:focus, .textarea:focus { border-color: var(--primary); box-shadow: 0 0 0 3px var(--primary-soft); }
.textarea { min-height: 120px; resize: vertical; }
.btn {
  border: 1px solid var(--line);
  background: #fff;
  color: var(--text);
  border-radius: 8px;
  padding: 8px 14px;
  cursor: pointer;
  white-space: nowrap;
}
.btn:hover { border-color: #cbd5e1; background: #f8fafc; }
.btn:disabled { opacity: .55; cursor: not-allowed; }
.btn-primary { background: var(--primary); border-color: var(--primary); color: #fff; }
.btn-primary:hover { background: #1d4ed8; border-color: #1d4ed8; }
.btn-ghost { background: transparent; }
.btn-danger { color: var(--danger); border-color: #fecaca; }
.btn-danger:hover { background: #fef2f2; }
.btn-small { padding: 5px 9px; font-size: 12px; }
.btn-block { width: 100%; }
.error {
  background: #fef2f2; border: 1px solid #fecaca; color: #991b1b;
  border-radius: 8px; padding: 9px 11px; margin-bottom: 12px; font-size: 13px;
}
.note { background: #eff6ff; border: 1px solid #bfdbfe; color: #1e40af; border-radius: 8px; padding: 10px 12px; font-size: 12.5px; }

/* ---------- app shell ---------- */
.app { display: flex; height: 100vh; overflow: hidden; }
.sidebar {
  width: 240px;
  flex: 0 0 240px;
  background: var(--sidebar);
  color: #cbd5e1;
  display: flex;
  flex-direction: column;
  min-height: 0;
}
.sidebar-head { padding: 18px 18px 12px; border-bottom: 1px solid rgb(255 255 255 / 8%); }
.sidebar-brand { display: flex; align-items: center; gap: 9px; color: #fff; font-weight: 700; font-size: 18px; text-decoration: none; }
.sidebar-brand .dot { width: 26px; height: 26px; border-radius: 8px; background: linear-gradient(135deg, #6ca6ff, #1d4ed8); }
.sidebar-env { margin-top: 8px; font-size: 11px; color: #93a4c3; }
.env-tag {
  display: inline-block; padding: 1px 7px; border-radius: 999px;
  background: #1e3a8a; color: #dbeafe; font-size: 11px; margin-left: 4px;
}
.menu { flex: 1; overflow: auto; padding: 12px 10px; }
.menu-group { margin-bottom: 16px; }
.menu-group-title {
  padding: 6px 10px; font-size: 11px; letter-spacing: .08em;
  text-transform: uppercase; color: #7f8ea8;
}
.menu-item {
  width: 100%; display: flex; align-items: center; gap: 8px;
  border: 0; background: transparent; color: #d7e0f0;
  text-align: left; padding: 9px 10px; border-radius: 8px; cursor: pointer;
  font-size: 14px;
}
.menu-item:hover { background: var(--sidebar-2); color: #fff; }
.menu-item.active { background: #1d4ed8; color: #fff; }
.menu-item .label { flex: 1; }
.menu-badge {
  min-width: 18px; height: 18px; padding: 0 5px; border-radius: 999px;
  background: #ef4444; color: #fff; font-size: 11px; line-height: 18px;
  text-align: center; font-weight: 600;
}
.menu-badge.zero { display: none; }
.sidebar-foot { border-top: 1px solid rgb(255 255 255 / 8%); padding: 12px; font-size: 12px; }
.sidebar-foot .who { color: #e2e8f0; margin-bottom: 8px; word-break: break-all; }
.sidebar-foot .btn { width: 100%; background: transparent; color: #cbd5e1; border-color: rgb(255 255 255 / 16%); }
.sidebar-foot .btn:hover { background: var(--sidebar-2); color: #fff; }

.main { flex: 1; min-width: 0; display: flex; flex-direction: column; }
.topbar {
  height: 58px; flex: 0 0 58px; display: flex; align-items: center; gap: 12px;
  padding: 0 18px; background: var(--panel); border-bottom: 1px solid var(--line);
}
.topbar h1 { font-size: 16px; }
.topbar .crumb { color: var(--muted); font-size: 12px; }
.topbar .right { margin-left: auto; display: flex; align-items: center; gap: 10px; color: var(--muted); font-size: 12px; }
.frame-wrap { flex: 1; min-height: 0; background: var(--bg); }
iframe.content-frame { width: 100%; height: 100%; border: 0; display: block; background: var(--bg); }

/* ---------- page content (iframe pages) ---------- */
.page { padding: 22px; max-width: 1280px; margin: 0 auto; }
.page-head { display: flex; align-items: flex-start; gap: 14px; margin-bottom: 16px; }
.page-head h1 { font-size: 20px; }
.page-head p { color: var(--muted); font-size: 12.5px; margin-top: 3px; }
.page-head .actions { margin-left: auto; display: flex; gap: 8px; flex-wrap: wrap; flex: 0 0 auto; }
.card {
  background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius);
  padding: 16px; margin-bottom: 14px;
}
.card-head { display: flex; align-items: center; gap: 10px; margin-bottom: 10px; }
.card-head h2 { font-size: 15px; }
.card-head .right { margin-left: auto; color: var(--muted); font-size: 12px; }
.grid { display: grid; gap: 12px; grid-template-columns: repeat(auto-fit, minmax(180px, 1fr)); }
.stat { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); padding: 14px; }
.stat .k { font-size: 12px; color: var(--muted); }
.stat .v { font-size: 22px; font-weight: 700; margin-top: 4px; }
.stat .v.small { font-size: 15px; }
.row { display: flex; gap: 10px; align-items: center; flex-wrap: wrap; }
.row.end { justify-content: flex-end; }
.toolbar { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; margin-bottom: 12px; }
.toolbar .select { width: auto; min-width: 140px; }
.toolbar .input { width: auto; min-width: 180px; }
.toolbar .grow { flex: 1; min-width: 180px; }
.field { display: block; margin-bottom: 12px; }
.field span { display: block; font-size: 12px; color: var(--muted); margin-bottom: 5px; }
.table-wrap { overflow: auto; border: 1px solid var(--line); border-radius: var(--radius); background: #fff; }
table.table { width: 100%; border-collapse: collapse; font-size: 13px; }
.table th, .table td { padding: 9px 10px; border-bottom: 1px solid var(--line); text-align: left; vertical-align: top; }
.table th { background: #f8fafc; color: var(--muted); font-weight: 600; white-space: nowrap; }
.table tr:last-child td { border-bottom: 0; }
.table tr.clickable { cursor: pointer; }
.table tr.clickable:hover td { background: #f8fafc; }
.table tr.selected td { background: #eff6ff; }
.badge { display: inline-block; padding: 1px 7px; border-radius: 999px; font-size: 11px; background: #f1f5f9; color: #475569; }
.badge.unread { background: #fef3c7; color: #92400e; }
.badge.sent { background: #d1fae5; color: #065f46; }
.badge.failed { background: #fee2e2; color: #991b1b; }
.badge.other { background: #e0e7ff; color: #3730a3; }
.empty { padding: 26px; text-align: center; color: var(--muted); }
.hint { font-size: 12px; color: var(--muted); }
.message {
  border: 1px solid var(--line); border-radius: 10px; padding: 14px; background: #fff;
  margin-bottom: 12px;
}
.message .meta { color: var(--muted); font-size: 12px; display: flex; gap: 12px; flex-wrap: wrap; margin-bottom: 8px; }
.message pre { white-space: pre-wrap; word-break: break-word; margin: 0; font-family: inherit; }
.message iframe { width: 100%; min-height: 260px; border: 1px solid var(--line); border-radius: 8px; background: #fff; }
.split-2 { display: grid; grid-template-columns: minmax(300px, 1fr) minmax(360px, 1.2fr); gap: 14px; align-items: start; }
@media (max-width: 960px) {
  .split-2 { grid-template-columns: 1fr; }
  .sidebar { width: 200px; flex-basis: 200px; }
}
@media (max-width: 720px) {
  .sidebar { display: none; }
  .page { padding: 14px; }
}

/* ---------- toast ---------- */
.toast-host { position: fixed; right: 16px; bottom: 16px; z-index: 9999; display: flex; flex-direction: column; gap: 8px; }
.toast {
  background: #0f172a; color: #fff; border-radius: 8px; padding: 9px 12px;
  font-size: 13px; box-shadow: 0 8px 22px rgb(15 23 42 / 25%);
}
.toast.ok { background: #065f46; }
.toast.error { background: #991b1b; }

.page.wide { max-width: 1440px; }
.check { display: flex; align-items: center; gap: 8px; margin: 0 0 12px; cursor: pointer; }
.check input { width: 16px; height: 16px; accent-color: var(--primary); }
.filters { display: inline-flex; border: 1px solid var(--line); border-radius: 8px; overflow: hidden; }
.filters button {
  border: 0; border-right: 1px solid var(--line); background: #fff; color: var(--text);
  padding: 6px 12px; cursor: pointer;
}
.filters button:last-child { border-right: 0; }
.filters button.is-on { background: var(--primary); color: #fff; }
.table .input { width: 100%; min-width: 96px; padding: 5px 8px; }
.table .check { margin: 0; }
.table tr.is-dirty td { background: #fffbeb; }
.nowrap { white-space: nowrap; }
.help summary { cursor: pointer; font-weight: 600; }
.help dl { margin: 8px 0 0; }
.help dt { margin-top: 8px; font-weight: 600; }
.help dd { margin: 2px 0 0; color: var(--muted); }
.help code { font-family: var(--mono); font-size: 12px; }
