:root {
  --bg: #e8e8ed;
  --window-bg: #ffffff;
  --panel-bg: #f7f7f9;
  --titlebar: #f0f0f2;
  --border: #d9d9de;
  --border-strong: #c6c6cc;
  --text: #1d1d1f;
  --muted: #86868b;
  --accent: #007aff;
  --accent-hover: #0a6cdf;
  --green: #28c840;
  --red: #ff3b30;
  --shadow: 0 18px 50px rgba(0, 0, 0, 0.22);
  --radius: 12px;
  --font: -apple-system, BlinkMacSystemFont, "SF Pro Text", "Helvetica Neue",
    "PingFang SC", "Microsoft YaHei", sans-serif;
}

* { box-sizing: border-box; }

/* hidden 属性必须始终生效（覆盖下方 .modal-overlay/.login-view 等的 display） */
[hidden] { display: none !important; }

html, body {
  margin: 0;
  height: 100%;
  font-family: var(--font);
  color: var(--text);
  -webkit-font-smoothing: antialiased;
  background:
    radial-gradient(1200px 800px at 20% 0%, #f3e9ff 0%, transparent 55%),
    radial-gradient(1000px 700px at 100% 100%, #d9eaff 0%, transparent 55%),
    var(--bg);
}

body {
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 28px;
  min-height: 100vh;
}

/* ===== 窗口 / 标题栏 ===== */
.window {
  background: var(--window-bg);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  border: 1px solid rgba(0, 0, 0, 0.06);
  overflow: hidden;
}
.titlebar {
  display: flex;
  align-items: center;
  height: 42px;
  padding: 0 14px;
  background: linear-gradient(180deg, #f7f7f9, #ededf0);
  border-bottom: 1px solid var(--border);
  user-select: none;
}
.lights { display: flex; gap: 8px; width: 70px; }
.light { width: 12px; height: 12px; border-radius: 50%; display: inline-block; }
.light.red { background: #ff5f57; }
.light.yellow { background: #febc2e; }
.light.green { background: #28c840; }
.titlebar-title { font-size: 13px; font-weight: 600; color: #4a4a4f; }
.titlebar-spacer { flex: 1; }
.titlebar-right { display: flex; align-items: center; gap: 10px; }
.user-chip { font-size: 12.5px; color: var(--muted); }

/* ===== 登录 ===== */
.login-view { width: 100%; display: flex; justify-content: center; }
.login-window { width: 380px; }
.login-body { padding: 34px 36px 40px; text-align: center; }
.login-logo { font-size: 42px; }
.login-title { font-size: 21px; margin: 12px 0 4px; }
.login-sub { color: var(--muted); font-size: 13.5px; margin: 0 0 26px; }
.login-form { display: flex; flex-direction: column; gap: 12px; text-align: left; }

/* ===== 输入控件 ===== */
.input {
  width: 100%;
  height: 38px;
  padding: 0 12px;
  font-size: 14px;
  font-family: var(--font);
  color: var(--text);
  background: #fff;
  border: 1px solid var(--border-strong);
  border-radius: 8px;
  outline: none;
  transition: border-color .15s, box-shadow .15s;
}
.input:focus { border-color: var(--accent); box-shadow: 0 0 0 3px rgba(0,122,255,.18); }
.input-sm { height: 32px; font-size: 13px; }
textarea.input { height: auto; padding: 8px 12px; }

/* ===== 按钮 ===== */
.btn {
  font-family: var(--font);
  font-size: 14px;
  border: 1px solid transparent;
  border-radius: 8px;
  padding: 8px 16px;
  cursor: pointer;
  transition: background .15s, opacity .15s, transform .05s;
  white-space: nowrap;
}
.btn:active { transform: translateY(0.5px); }
.btn:disabled { opacity: .5; cursor: not-allowed; }
.btn-primary { background: var(--accent); color: #fff; }
.btn-primary:hover:not(:disabled) { background: var(--accent-hover); }
.btn-secondary { background: #fff; color: var(--text); border-color: var(--border-strong); }
.btn-secondary:hover { background: #f3f3f5; }
.btn-ghost { background: transparent; color: var(--accent); padding: 6px 10px; }
.btn-ghost:hover { background: rgba(0,122,255,.08); }
.btn-block { width: 100%; }
.btn-sm { font-size: 12.5px; padding: 6px 12px; }
.btn-lg { font-size: 15px; padding: 11px 22px; }

.form-error {
  background: #fff0ef; color: var(--red); border: 1px solid #ffd4d1;
  padding: 8px 12px; border-radius: 8px; font-size: 13px;
}

/* ===== 主体两栏 ===== */
.app-window { width: min(1160px, 96vw); height: min(800px, 92vh); display: flex; flex-direction: column; }
.app-body { flex: 1; display: grid; grid-template-columns: 540px 1fr; min-height: 0; }
.panel { padding: 18px 20px; overflow-y: auto; }
.recipients-panel { border-right: 1px solid var(--border); background: var(--panel-bg); display: flex; flex-direction: column; }
.compose-panel { display: flex; flex-direction: column; gap: 4px; }
.panel-head { display: flex; align-items: center; justify-content: space-between; margin-bottom: 14px; }
.panel-head h2 { font-size: 16px; margin: 0; }

/* ===== 分段控件 ===== */
.segmented {
  display: inline-flex; background: #e4e4e9; border-radius: 9px; padding: 2px; gap: 2px; width: 100%;
}
.segmented-sub { width: auto; margin: 12px 0 10px; }
.seg {
  flex: 1; border: none; background: transparent; font-family: var(--font); font-size: 13px;
  color: #4a4a4f; padding: 6px 14px; border-radius: 7px; cursor: pointer; transition: all .15s;
}
.seg.active { background: #fff; color: var(--text); box-shadow: 0 1px 3px rgba(0,0,0,.12); font-weight: 600; }

/* ===== 收件人表 ===== */
.search-row { margin: 12px 0 8px; }

/* 字段筛选 */
.filter-toggle-row { display: flex; align-items: center; gap: 8px; margin: 4px 0; }
.filter-badge { font-size: 11px; color: var(--accent); background: rgba(0,122,255,.1); padding: 2px 8px; border-radius: 10px; }
.filter-panel { background: #fff; border: 1px solid var(--border); border-radius: 8px; padding: 10px 12px; margin-bottom: 8px; display: flex; flex-direction: column; gap: 8px; }
.filter-row { display: flex; align-items: center; gap: 8px; }
.filter-label { width: 52px; flex-shrink: 0; font-size: 12.5px; color: #6a6a6f; font-weight: 600; }
.filter-op { width: 72px; flex-shrink: 0; padding: 0 6px; }
.filter-val { flex: 1; min-width: 0; }
.filter-hint { font-size: 11.5px; margin: 2px 0 0; }
.filter-actions { display: flex; justify-content: flex-end; gap: 8px; margin-top: 2px; }

.users-meta { display: flex; justify-content: space-between; font-size: 12.5px; margin-bottom: 6px; }
.muted { color: var(--muted); }
.users-table-wrap { flex: 1; overflow: auto; border: 1px solid var(--border); border-radius: 8px; background: #fff; min-height: 120px; }
.users-table { width: 100%; table-layout: fixed; border-collapse: collapse; font-size: 13px; }
.users-table col.cg-check { width: 32px; }
.users-table col.cg-name { width: 84px; }
.users-table col.cg-email { width: 130px; }
.users-table col.cg-level { width: 52px; }
.users-table col.cg-num { width: 56px; }
.users-table col.cg-login { width: 82px; }
.users-table thead th {
  position: sticky; top: 0; background: #fafafc; text-align: left; padding: 7px 8px;
  border-bottom: 1px solid var(--border); font-weight: 600; color: #6a6a6f; font-size: 12px;
}
.users-table th, .users-table td { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.users-table td { padding: 6px 8px; border-bottom: 1px solid #f0f0f2; }
.users-table tbody tr:hover { background: #f5f9ff; }
.users-table .col-check { text-align: center; }
.users-table td.col-check { text-align: center; }
.users-table .email-cell { color: #515156; }
.users-table .col-num { text-align: right; }
.empty-hint { padding: 24px; text-align: center; color: var(--muted); font-size: 13px; }
.pager { display: flex; align-items: center; justify-content: space-between; padding-top: 10px; }

/* ===== 撰写区 ===== */
.field { margin: 8px 0; }
.field-label { display: block; font-size: 12.5px; color: #6a6a6f; margin-bottom: 6px; font-weight: 600; }
.from-display { font-size: 13.5px; padding: 8px 12px; background: #f2f2f4; border-radius: 8px; }

.toolbar { display: flex; flex-wrap: wrap; gap: 4px; padding: 6px; background: #f2f2f4; border: 1px solid var(--border); border-bottom: none; border-radius: 8px 8px 0 0; }
.toolbar button {
  border: none; background: transparent; padding: 4px 9px; border-radius: 6px; cursor: pointer;
  font-size: 13px; font-family: var(--font); color: var(--text); min-width: 30px;
}
.toolbar button:hover { background: #e2e2e6; }
.tb-sep { width: 1px; background: var(--border-strong); margin: 2px 4px; }

.rich-editor {
  min-height: 220px; max-height: 360px; overflow-y: auto; padding: 12px 14px; font-size: 14px; line-height: 1.6;
  border: 1px solid var(--border-strong); border-radius: 0 0 8px 8px; background: #fff; outline: none;
}
.rich-editor:focus { border-color: var(--accent); box-shadow: 0 0 0 3px rgba(0,122,255,.15); }
.rich-editor:empty::before { content: "在此撰写邮件正文…"; color: var(--muted); }

.code-area {
  width: 100%; min-height: 180px; padding: 12px; font-size: 13px; line-height: 1.5;
  font-family: "SF Mono", Menlo, Consolas, monospace; border: 1px solid var(--border-strong);
  border-radius: 8px; resize: vertical; outline: none; background: #fff;
}
.code-area:focus { border-color: var(--accent); box-shadow: 0 0 0 3px rgba(0,122,255,.15); }
.preview-label { font-size: 11.5px; margin: 10px 0 4px; }
.html-preview { width: 100%; height: 200px; border: 1px solid var(--border); border-radius: 8px; background: #fff; }

#tpl-vars { display: flex; flex-direction: column; gap: 8px; margin-bottom: 8px; }
.var-row { display: flex; gap: 8px; align-items: center; }
.var-row .input { flex: 1; }
.var-del { border: none; background: #f2f2f4; color: var(--red); width: 30px; height: 32px; border-radius: 7px; cursor: pointer; }
.hint { font-size: 12px; margin: 6px 0 0; }

.test-field { margin-top: 14px; padding-top: 14px; border-top: 1px dashed var(--border); }
.test-row { display: flex; gap: 8px; }
.test-row .input { flex: 1; }
.test-results { margin-top: 8px; display: flex; flex-direction: column; gap: 4px; }
.test-result { font-size: 12.5px; padding: 5px 10px; border-radius: 6px; }
.test-result.ok { background: #eafaef; color: #1d8c3e; }
.test-result.fail { background: #fff0ef; color: var(--red); }

.compose-actions { margin-top: 18px; display: flex; justify-content: flex-end; }

/* ===== 弹窗 ===== */
.modal-overlay {
  position: fixed; inset: 0; background: rgba(0,0,0,.28); backdrop-filter: blur(3px);
  display: flex; align-items: center; justify-content: center; z-index: 50;
}
.modal { background: #fff; border-radius: 14px; padding: 24px; width: 380px; box-shadow: var(--shadow); }
.modal-wide { width: 540px; }
.modal-title { margin: 0 0 10px; font-size: 17px; }
.modal-text { color: #4a4a4f; font-size: 14px; line-height: 1.5; margin: 0 0 20px; }
.modal-actions { display: flex; justify-content: flex-end; gap: 10px; margin-top: 16px; }

.progress-bar { height: 10px; background: #ececf0; border-radius: 6px; overflow: hidden; margin: 6px 0 12px; }
.progress-fill { height: 100%; width: 0; background: linear-gradient(90deg, #007aff, #34c759); transition: width .25s; }
.progress-stats { display: flex; gap: 18px; font-size: 13px; color: #4a4a4f; margin-bottom: 12px; }
.progress-stats b { color: var(--text); }
.stat-fail b { color: var(--red); }
.progress-log {
  height: 220px; overflow-y: auto; border: 1px solid var(--border); border-radius: 8px;
  padding: 8px 10px; font-size: 12px; font-family: "SF Mono", Menlo, monospace; background: #fafafc;
}
.log-line { padding: 2px 0; border-bottom: 1px solid #f2f2f4; }
.log-line.ok { color: #1d8c3e; }
.log-line.fail { color: var(--red); }

/* ===== Toast ===== */
.toast {
  position: fixed; bottom: 28px; left: 50%; transform: translateX(-50%);
  background: rgba(30,30,32,.92); color: #fff; padding: 10px 18px; border-radius: 10px;
  font-size: 13.5px; z-index: 60; box-shadow: 0 8px 24px rgba(0,0,0,.25);
}

@media (max-width: 820px) {
  .app-body { grid-template-columns: 1fr; }
  .recipients-panel { border-right: none; border-bottom: 1px solid var(--border); max-height: 40vh; }
}
