/* Agents Email 控制台 — Gmail 式三栏布局
   自带变量，不依赖既有 public/css/*，避免与旧临时邮箱样式互相干扰。 */

:root {
  --bg: #ffffff;
  --bg-sunk: #f6f8fc;
  --bg-hover: #f1f3f4;
  --bg-sel: #e8f0fe;
  --border: #e0e3e7;
  --text: #202124;
  --text-dim: #5f6368;
  --accent: #1a73e8;
  --accent-soft: #d3e3fd;
  --danger: #d93025;
  --ok: #188038;
  --radius: 8px;
  --row-h: 44px;
  --shadow: 0 1px 3px rgba(60,64,67,.15), 0 4px 8px rgba(60,64,67,.08);
}
[data-theme="dark"] {
  --bg: #1f1f1f;
  --bg-sunk: #171717;
  --bg-hover: #2a2a2a;
  --bg-sel: #29405e;
  --border: #3c4043;
  --text: #e8eaed;
  --text-dim: #9aa0a6;
  --accent: #8ab4f8;
  --accent-soft: #29405e;
  --danger: #f28b82;
  --ok: #81c995;
  --shadow: 0 1px 3px rgba(0,0,0,.4), 0 4px 8px rgba(0,0,0,.3);
}

* { box-sizing: border-box; }

/* 必须放在所有组件规则之前并加 !important：
   浏览器对 [hidden] 的 display:none 来自 UA 样式表，优先级低于任何类选择器。
   `.modal { display: grid }` 这类规则会直接把 hidden 覆盖掉，导致写信弹窗
   和空态永远显示。这个坑很隐蔽——元素有 hidden 属性但照样可见。 */
[hidden] { display: none !important; }

html, body { height: 100%; margin: 0; }
body {
  font: 14px/1.5 -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto,
        "Helvetica Neue", "PingFang SC", "Microsoft YaHei", sans-serif;
  color: var(--text);
  background: var(--bg-sunk);
}
button, input, select, textarea { font: inherit; color: inherit; }

.app { display: flex; flex-direction: column; height: 100%; }

/* ── 顶栏 ── */
.topbar {
  display: flex; align-items: center; gap: 12px;
  height: 56px; padding: 0 12px; flex: 0 0 auto;
  background: var(--bg-sunk); border-bottom: 1px solid var(--border);
}
.brand { display: flex; align-items: center; gap: 8px; min-width: 150px; }
.brand-mark {
  width: 28px; height: 28px; border-radius: 6px; background: var(--accent);
  color: #fff; display: grid; place-items: center; font-size: 15px;
}
.brand-text { font-size: 17px; font-weight: 500; letter-spacing: .1px; }
.search { flex: 1; max-width: 680px; }
.search input {
  width: 100%; height: 40px; padding: 0 14px;
  background: var(--bg-hover); border: 1px solid transparent;
  border-radius: 999px; outline: none;
}
.search input:focus { background: var(--bg); border-color: var(--accent); box-shadow: var(--shadow); }
.topbar-right { display: flex; align-items: center; gap: 4px; margin-left: auto; }
.whoami { color: var(--text-dim); font-size: 12px; margin-right: 4px; }
.icon-btn {
  width: 34px; height: 34px; display: grid; place-items: center;
  background: none; border: none; border-radius: 50%;
  cursor: pointer; color: var(--text-dim);
}
.icon-btn:hover { background: var(--bg-hover); color: var(--text); }

/* ── 主体三栏 ── */
.body { display: flex; flex: 1; min-height: 0; }

.sidebar {
  width: 232px; flex: 0 0 232px; padding: 8px 8px 24px;
  overflow-y: auto; background: var(--bg-sunk);
}
.compose {
  display: flex; align-items: center; gap: 8px;
  height: 44px; padding: 0 22px; margin: 4px 4px 14px;
  background: var(--accent-soft); color: var(--text);
  border: none; border-radius: 999px; cursor: pointer;
  font-size: 14px; font-weight: 500; box-shadow: var(--shadow);
}
.compose:hover { filter: brightness(.97); }
.nav-section { margin-bottom: 10px; }
.nav-item {
  display: flex; align-items: center; gap: 12px;
  height: 34px; padding: 0 12px 0 14px; margin-right: 8px;
  border-radius: 0 999px 999px 0; cursor: pointer;
  color: var(--text); text-decoration: none; font-size: 13px;
}
.nav-item:hover { background: var(--bg-hover); }
.nav-item.active { background: var(--accent-soft); font-weight: 600; }
.nav-ico { width: 16px; text-align: center; color: var(--text-dim); }
.nav-item.active .nav-ico { color: var(--accent); }
.nav-count { margin-left: auto; font-size: 11px; color: var(--text-dim); }
.nav-label {
  padding: 12px 14px 6px; font-size: 11px; font-weight: 600;
  color: var(--text-dim); text-transform: uppercase; letter-spacing: .5px;
  display: flex; gap: 6px;
}
.agent-list { display: flex; flex-direction: column; }
.agent-item {
  display: flex; align-items: center; gap: 10px;
  height: 34px; padding: 0 12px 0 14px; margin-right: 8px;
  border-radius: 0 999px 999px 0; cursor: pointer; font-size: 13px;
}
.agent-item:hover { background: var(--bg-hover); }
.agent-item.active { background: var(--accent-soft); font-weight: 600; }
.avatar {
  width: 22px; height: 22px; flex: 0 0 22px; border-radius: 50%;
  display: grid; place-items: center; color: #fff;
  font-size: 11px; font-weight: 600; text-transform: uppercase;
}
.agent-slug { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.dot-paused { width: 6px; height: 6px; border-radius: 50%; background: var(--text-dim); }
.ttl-hint { padding: 10px 14px; font-size: 11px; color: var(--text-dim); line-height: 1.6; }

/* ── 列表栏 ── */
.list-pane {
  width: 420px; flex: 0 0 420px; display: flex; flex-direction: column;
  min-height: 0; background: var(--bg);
  border-left: 1px solid var(--border); border-right: 1px solid var(--border);
}
.list-toolbar {
  display: flex; align-items: center; gap: 6px;
  height: 48px; padding: 0 8px 0 16px; flex: 0 0 auto;
  border-bottom: 1px solid var(--border);
}
.list-title { font-size: 14px; font-weight: 600; }
.grow { flex: 1; }
.muted { color: var(--text-dim); }
.small { font-size: 12px; }
.list { flex: 1; overflow-y: auto; }

.row {
  display: flex; align-items: flex-start; gap: 10px;
  padding: 10px 14px; border-bottom: 1px solid var(--border);
  cursor: pointer; position: relative;
}
.row:hover { background: var(--bg-hover); box-shadow: inset 3px 0 0 var(--accent); }
.row.active { background: var(--bg-sel); box-shadow: inset 3px 0 0 var(--accent); }
.row-main { min-width: 0; flex: 1; }
.row-top { display: flex; align-items: baseline; gap: 8px; }
.row-from { font-weight: 600; font-size: 13px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.row-time { margin-left: auto; font-size: 11px; color: var(--text-dim); flex: 0 0 auto; }
.row-subject { font-size: 13px; margin-top: 2px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.row-snippet { font-size: 12px; color: var(--text-dim); margin-top: 2px;
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.tag {
  font-size: 10px; padding: 1px 6px; border-radius: 4px;
  border: 1px solid var(--border); color: var(--text-dim); flex: 0 0 auto;
}
.tag.in { color: var(--ok); border-color: currentColor; }
.tag.out { color: var(--accent); border-color: currentColor; }
.tag.agent { background: var(--bg-hover); }

/* ── 阅读栏 ── */
.read-pane { flex: 1; min-width: 0; overflow-y: auto; background: var(--bg); }
.read-empty {
  height: 100%; display: flex; flex-direction: column;
  align-items: center; justify-content: center; color: var(--text-dim); gap: 12px;
}
.read-empty-mark { font-size: 48px; opacity: .35; }
.read-body { padding: 22px 28px 60px; max-width: 900px; }
.read-subject { font-size: 21px; font-weight: 400; margin: 0 0 4px; }
.read-meta { color: var(--text-dim); font-size: 12px; margin-bottom: 18px; }
.msg { border-top: 1px solid var(--border); padding: 16px 0; }
.msg:first-of-type { border-top: none; }
.msg-head { display: flex; align-items: center; gap: 10px; margin-bottom: 8px; }
.msg-who { font-weight: 600; font-size: 13px; }
.msg-time { margin-left: auto; font-size: 11px; color: var(--text-dim); }
.msg-body { white-space: pre-wrap; word-break: break-word; font-size: 14px; }
.msg-actions { margin-top: 12px; display: flex; gap: 8px; }

.btn {
  height: 34px; padding: 0 16px; border-radius: 999px;
  border: 1px solid var(--border); background: var(--bg);
  cursor: pointer; font-size: 13px;
}
.btn:hover { background: var(--bg-hover); }
.btn.primary { background: var(--accent); border-color: var(--accent); color: #fff; }
.btn.primary:hover { filter: brightness(1.08); }
.btn.danger { color: var(--danger); }

/* 管理面板内的表格 */
.panel-title { font-size: 18px; font-weight: 500; margin: 0 0 14px; }
table.tbl { width: 100%; border-collapse: collapse; font-size: 13px; }
table.tbl th, table.tbl td { text-align: left; padding: 9px 10px; border-bottom: 1px solid var(--border); }
table.tbl th { color: var(--text-dim); font-weight: 600; font-size: 11px; text-transform: uppercase; }
code.mono {
  font-family: ui-monospace, SFMono-Regular, Menlo, monospace; font-size: 12px;
  background: var(--bg-hover); padding: 2px 6px; border-radius: 4px;
}
.stat-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(120px, 1fr)); gap: 10px; margin-bottom: 22px; }
.stat { background: var(--bg-sunk); border: 1px solid var(--border); border-radius: var(--radius); padding: 12px 14px; }
.stat-n { font-size: 22px; font-weight: 500; }
.stat-l { font-size: 11px; color: var(--text-dim); margin-top: 2px; }

/* ── 写信弹窗 ── */
.modal { position: fixed; inset: 0; background: rgba(0,0,0,.45); display: grid; place-items: center; z-index: 50; }
.modal-card {
  width: min(680px, calc(100vw - 32px)); max-height: calc(100vh - 64px);
  display: flex; flex-direction: column;
  background: var(--bg); border-radius: 12px; box-shadow: var(--shadow); overflow: hidden;
}
.modal-head {
  display: flex; align-items: center; height: 48px; padding: 0 8px 0 18px;
  background: var(--bg-sunk); border-bottom: 1px solid var(--border); font-weight: 600;
}
.modal-head .icon-btn { margin-left: auto; }
.modal-body { padding: 16px 18px; overflow-y: auto; }
.modal-foot {
  display: flex; align-items: center; gap: 8px;
  padding: 12px 18px; border-top: 1px solid var(--border);
}
.field { display: block; margin-bottom: 12px; }
.field > span { display: block; font-size: 11px; color: var(--text-dim); margin-bottom: 4px; text-transform: uppercase; }
.field input, .field select, .field textarea {
  width: 100%; padding: 9px 11px; background: var(--bg);
  border: 1px solid var(--border); border-radius: 6px; outline: none;
}
.field input:focus, .field textarea:focus, .field select:focus { border-color: var(--accent); }
.field textarea { resize: vertical; }
.hint { font-size: 11px; color: var(--text-dim); margin: -6px 0 12px; }
.compose-msg { font-size: 12px; white-space: pre-wrap; }
.compose-msg.err { color: var(--danger); }
.compose-msg.ok { color: var(--ok); }

.toast {
  position: fixed; left: 50%; bottom: 26px; transform: translateX(-50%);
  background: #202124; color: #fff; padding: 11px 18px;
  border-radius: 6px; font-size: 13px; z-index: 100; box-shadow: var(--shadow);
}

.empty { padding: 40px 20px; text-align: center; color: var(--text-dim); font-size: 13px; }
.spin { padding: 30px; text-align: center; color: var(--text-dim); font-size: 13px; }

/* ── 窄屏：折叠为单栏 ── */
@media (max-width: 1100px) {
  .list-pane { width: 340px; flex-basis: 340px; }
}
@media (max-width: 860px) {
  .sidebar {
    position: fixed; top: 56px; bottom: 0; left: 0; z-index: 30;
    transform: translateX(-100%); transition: transform .2s;
    border-right: 1px solid var(--border);
  }
  .sidebar.open { transform: none; }
  .list-pane { width: 100%; flex-basis: auto; }
  .read-pane { display: none; }
  .app.reading .list-pane { display: none; }
  .app.reading .read-pane { display: block; }
  .search { max-width: none; }
  .whoami { display: none; }
}

/* ── 已读 / 未读 ──
   控制台只显示状态、不修改；标记权只在 agent 侧（POST /api/agent/messages/read）。
   未读用三重冗余编码（字重 + 圆点 + 徽标），不单靠颜色，避免色觉障碍下不可辨。 */

.row .dot {
  width: 8px; height: 8px; flex: 0 0 8px; margin-top: 7px;
  border-radius: 50%; background: transparent;
  border: 1px solid var(--border);
}
.row.unread .dot { background: var(--accent); border-color: var(--accent); }
.row.unread .row-from,
.row.unread .row-subject { font-weight: 700; }
.row.unread .row-snippet { color: var(--text); }

/* 侧栏未读徽标 */
.badge {
  margin-left: auto; min-width: 18px; padding: 0 5px;
  font-size: 10px; font-weight: 700; line-height: 16px; text-align: center;
  color: #fff; background: var(--accent); border-radius: 999px;
}
.agent-item .badge + .nav-count { margin-left: 6px; }

/* 阅读栏 */
.pill-unread {
  padding: 1px 7px; border-radius: 999px; font-size: 11px;
  color: #fff; background: var(--accent);
}
.tag.unread-tag { color: var(--accent); border-color: currentColor; font-weight: 600; }

/* 只读提示：让「不能改」看起来是设计，而不是功能缺失 */
.readonly-note {
  margin: 0 0 18px; padding: 9px 12px;
  font-size: 12px; line-height: 1.6; color: var(--text-dim);
  background: var(--bg-sunk); border: 1px solid var(--border);
  border-left: 3px solid var(--accent); border-radius: 4px;
}
.readonly-note strong { color: var(--text); }
