:root {
  --bg: #f4f6f8; --panel: #fff; --text: #1f2933; --muted: #6b7785; --line: #e3e8ee;
  --brand: #06c755; --brand-dark: #05a647; --blue: #2f6fed; --red: #e5484d; --amber: #e9a23b;
  --green: #12a150; --gray: #8b95a1; --radius: 10px; --shadow: 0 1px 3px rgba(16,24,40,.06), 0 1px 2px rgba(16,24,40,.04);
}
* { box-sizing: border-box; }
body { margin: 0; font-family: "Noto Sans TC", "Microsoft JhengHei", system-ui, sans-serif; background: var(--bg); color: var(--text); font-size: 14px; line-height: 1.55; }
a { color: var(--blue); text-decoration: none; }
a:hover { text-decoration: underline; }
h1 { font-size: 20px; margin: 0 0 16px; }
h2 { font-size: 16px; margin: 0 0 12px; }
h3 { font-size: 14px; margin: 0 0 8px; }
code, pre { font-family: Consolas, "Courier New", monospace; font-size: 12.5px; }
pre { background: #0f172a; color: #e2e8f0; padding: 12px; border-radius: 8px; overflow: auto; max-height: 480px; white-space: pre-wrap; word-break: break-all; }

.app { display: flex; min-height: 100vh; }
.sidebar { width: 220px; background: #111827; color: #cbd5e1; flex-shrink: 0; position: sticky; top: 0; height: 100vh; overflow-y: auto; }
.sidebar .logo { padding: 18px 20px; font-size: 18px; font-weight: 700; color: #fff; display: flex; align-items: center; gap: 8px; }
.sidebar .logo span { background: var(--brand); color: #fff; border-radius: 6px; padding: 2px 6px; font-size: 13px; }
.sidebar nav a { display: flex; justify-content: space-between; align-items: center; padding: 9px 20px; color: #cbd5e1; font-size: 14px; }
.sidebar nav a:hover { background: #1f2937; text-decoration: none; color: #fff; }
.sidebar nav a.active { background: #1f2937; color: #fff; border-left: 3px solid var(--brand); padding-left: 17px; }
.sidebar nav .group { padding: 14px 20px 4px; font-size: 11px; text-transform: uppercase; letter-spacing: .08em; color: #64748b; }
.sidebar .count { background: var(--red); color: #fff; border-radius: 10px; padding: 0 7px; font-size: 11px; }
.main { flex: 1; min-width: 0; }
.topbar { background: var(--panel); border-bottom: 1px solid var(--line); padding: 10px 24px; display: flex; justify-content: space-between; align-items: center; position: sticky; top: 0; z-index: 5; }
.topbar .env { font-size: 12px; padding: 2px 8px; border-radius: 6px; background: #fef3c7; color: #92400e; }
.topbar .env.production { background: #dcfce7; color: #166534; }
.content { padding: 24px; max-width: 1400px; }
.menu-toggle { display: none; }

.card { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); box-shadow: var(--shadow); padding: 18px; margin-bottom: 18px; }
.card.tight { padding: 0; overflow: hidden; }
.card-head { display: flex; justify-content: space-between; align-items: center; margin-bottom: 12px; gap: 10px; flex-wrap: wrap; }
.grid { display: grid; gap: 16px; }
.grid.cols-2 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
.grid.cols-3 { grid-template-columns: repeat(3, minmax(0, 1fr)); }
.grid.cols-4 { grid-template-columns: repeat(4, minmax(0, 1fr)); }
.stat { padding: 16px; }
.stat .num { font-size: 26px; font-weight: 700; }
.stat .label { color: var(--muted); font-size: 13px; }
.row { display: flex; gap: 10px; align-items: center; flex-wrap: wrap; }
.spacer { flex: 1; }
.muted { color: var(--muted); }
.small { font-size: 12px; }
.mt { margin-top: 12px; } .mb { margin-bottom: 12px; }
.nowrap { white-space: nowrap; }
.right { text-align: right; }

table { width: 100%; border-collapse: collapse; }
th, td { padding: 9px 12px; border-bottom: 1px solid var(--line); text-align: left; vertical-align: top; }
th { background: #f8fafc; font-weight: 600; font-size: 12.5px; color: #475467; white-space: nowrap; }
tr:last-child td { border-bottom: none; }
tbody tr:hover { background: #fafbfc; }
.table-wrap { overflow-x: auto; }

.badge { display: inline-block; padding: 1px 8px; border-radius: 999px; font-size: 12px; font-weight: 500; white-space: nowrap; }
.badge-green { background: #dcfce7; color: #166534; }
.badge-red { background: #fee2e2; color: #991b1b; }
.badge-amber { background: #fef3c7; color: #92400e; }
.badge-blue { background: #dbeafe; color: #1e40af; }
.badge-gray { background: #eef1f4; color: #475467; }

.btn { display: inline-flex; align-items: center; gap: 6px; padding: 7px 14px; border-radius: 8px; border: 1px solid var(--line); background: #fff; color: var(--text); cursor: pointer; font-size: 13.5px; font-family: inherit; line-height: 1.3; }
.btn:hover { background: #f5f7fa; text-decoration: none; }
.btn.primary { background: var(--brand); border-color: var(--brand); color: #fff; }
.btn.primary:hover { background: var(--brand-dark); }
.btn.blue { background: var(--blue); border-color: var(--blue); color: #fff; }
.btn.danger { background: #fff; border-color: #f4b4b6; color: var(--red); }
.btn.danger:hover { background: #fff5f5; }
.btn.stop { background: var(--red); border-color: var(--red); color: #fff; font-weight: 600; }
.btn.stop:hover { background: #c9363b; }
.btn.sm { padding: 4px 10px; font-size: 12.5px; }
form.inline { display: inline; }

label { display: block; font-weight: 600; margin-bottom: 4px; font-size: 13px; }
.field { margin-bottom: 14px; }
.field .hint { font-weight: normal; color: var(--muted); font-size: 12px; margin-top: 3px; }
input[type=text], input[type=password], input[type=number], input[type=email], input[type=time], input[type=url], select, textarea {
  width: 100%; padding: 8px 10px; border: 1px solid #cfd6de; border-radius: 8px; font-size: 14px; font-family: inherit; background: #fff;
}
textarea { min-height: 90px; resize: vertical; }
textarea.code { font-family: Consolas, monospace; font-size: 12.5px; min-height: 320px; }
input:focus, select:focus, textarea:focus { outline: 2px solid #b7e4c7; border-color: var(--brand); }
.check { display: flex; align-items: center; gap: 6px; font-weight: normal; }

.flash { padding: 10px 14px; border-radius: 8px; margin-bottom: 14px; }
.flash.success { background: #dcfce7; color: #166534; }
.flash.error { background: #fee2e2; color: #991b1b; }
.flash.info { background: #dbeafe; color: #1e40af; }
.alert { padding: 12px 14px; border-radius: 8px; background: #fffbeb; border: 1px solid #fde68a; color: #92400e; margin-bottom: 14px; }

/* 收件匣 */
.inbox { display: grid; grid-template-columns: 300px minmax(0, 1fr) 300px; gap: 16px; align-items: start; }
.chat-list a { display: block; padding: 10px 14px; border-bottom: 1px solid var(--line); color: var(--text); }
.chat-list a:hover { background: #f5f7fa; text-decoration: none; }
.chat-list a.active { background: #ecfdf3; }
.chat-list .name { font-weight: 600; display: flex; justify-content: space-between; gap: 6px; }
.chat-list .preview { color: var(--muted); font-size: 12.5px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.messages { background: #8cabd9; border-radius: var(--radius); padding: 16px; max-height: 64vh; overflow-y: auto; }
.msg { display: flex; margin-bottom: 10px; }
.msg .bubble { max-width: 72%; background: #fff; padding: 8px 12px; border-radius: 16px; white-space: pre-wrap; word-break: break-word; box-shadow: 0 1px 1px rgba(0,0,0,.08); }
.msg.out { justify-content: flex-end; }
.msg.out .bubble { background: #b7f398; }
.msg.system { justify-content: center; }
.msg.system .bubble { background: rgba(0,0,0,.25); color: #fff; font-size: 12px; }
.msg .meta { font-size: 11px; color: #f1f5f9; margin: 0 6px; align-self: flex-end; white-space: nowrap; }
.msg .sender { font-size: 11.5px; color: #eef2ff; margin-bottom: 2px; }
.msg .ai { margin-top: 6px; padding: 6px 8px; background: #f1f5f9; border-radius: 8px; font-size: 12.5px; color: #334155; }
.msg.recalled .bubble { opacity: .55; text-decoration: line-through; }
.msg img.att { max-width: 220px; max-height: 220px; border-radius: 8px; display: block; margin-top: 4px; }
.draft { border: 1px solid var(--line); border-radius: var(--radius); padding: 14px; margin-bottom: 12px; background: #fff; }
.draft.risk-high { border-color: #f4b4b6; background: #fff8f8; }
.draft.risk-medium { border-color: #fde68a; }
.draft .ctx { background: #f8fafc; border-radius: 8px; padding: 8px 10px; font-size: 12.5px; color: #475467; max-height: 160px; overflow: auto; white-space: pre-wrap; }

.shot { max-width: 100%; border: 1px solid var(--line); border-radius: 8px; }
.shots { display: grid; grid-template-columns: repeat(auto-fill, minmax(220px, 1fr)); gap: 12px; }
.shots figure { margin: 0; }
.shots figcaption { font-size: 12px; color: var(--muted); }
.kv { display: grid; grid-template-columns: 140px 1fr; gap: 6px 12px; }
.kv div:nth-child(odd) { color: var(--muted); }
.cmd { background: #0f172a; color: #a7f3d0; padding: 12px; border-radius: 8px; font-family: Consolas, monospace; font-size: 12.5px; word-break: break-all; position: relative; }
.empty { text-align: center; color: var(--muted); padding: 30px; }

.login-wrap { min-height: 100vh; display: flex; align-items: center; justify-content: center; padding: 16px; }
.login-card { width: 100%; max-width: 380px; }

@media (max-width: 1100px) {
  .inbox { grid-template-columns: 260px minmax(0, 1fr); }
  .inbox .side-info { grid-column: 1 / -1; }
  .grid.cols-4 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
}
@media (max-width: 800px) {
  .sidebar { position: fixed; left: -240px; z-index: 20; transition: left .2s; }
  .sidebar.open { left: 0; }
  .menu-toggle { display: inline-flex; }
  .content { padding: 16px; }
  .topbar { padding: 10px 16px; }
  .grid.cols-2, .grid.cols-3, .grid.cols-4, .inbox { grid-template-columns: minmax(0, 1fr); }
  .kv { grid-template-columns: 1fr; }
}
