:root {
  --brand: #16a34a; --brand-soft: #dcfce7; --bg: #f3f4f6; --panel: #fff; --line: #e5e7eb;
  --text: #111827; --muted: #6b7280; --danger: #dc2626; --warn: #f59e0b;
}
* { box-sizing: border-box; }
[hidden] { display: none !important; }
html, body { margin: 0; height: 100%; font: 14px/1.5 system-ui, -apple-system, "Segoe UI", "Microsoft YaHei", sans-serif; color: var(--text); background: var(--bg); }
button { font: inherit; cursor: pointer; border: none; border-radius: 6px; padding: 6px 12px; background: var(--brand); color: #fff; }
button:disabled { opacity: .5; cursor: default; }
button.ghost { background: transparent; color: var(--text); border: 1px solid var(--line); }
button.ghost:hover { background: var(--bg); }
button.danger { background: #fff; color: var(--danger); border: 1px solid #fecaca; }
.err { color: var(--danger); font-size: 12px; }
.flex { flex: 1; }

/* 登录 */
.login { height: 100%; display: flex; align-items: center; justify-content: center; padding: 16px; }
.login-card { background: var(--panel); padding: 28px; border-radius: 12px; width: 100%; max-width: 340px; box-shadow: 0 10px 30px rgba(0,0,0,.08); display: flex; flex-direction: column; gap: 14px; }
.login-card h1 { margin: 0 0 6px; font-size: 20px; }
.login-card label { display: flex; flex-direction: column; gap: 4px; font-size: 13px; color: var(--muted); }
.login-card input { padding: 9px 10px; border: 1px solid var(--line); border-radius: 6px; font: inherit; color: var(--text); }
.login-card button { padding: 10px; }

/* 布局 */
.main { display: flex; height: 100%; }
.side { width: 320px; flex: none; background: var(--panel); border-right: 1px solid var(--line); display: flex; flex-direction: column; min-height: 0; }
.chat { flex: 1; min-width: 0; display: flex; flex-direction: column; }
.info { width: 280px; flex: none; background: var(--panel); border-left: 1px solid var(--line); padding: 14px; overflow-y: auto; }

.me { display: flex; align-items: center; justify-content: space-between; padding: 12px 14px; border-bottom: 1px solid var(--line); }
.me-name { font-weight: 600; }
.me-online { font-size: 12px; color: var(--muted); }
.me-actions { display: flex; gap: 6px; }
.me-actions button { padding: 4px 8px; }
.tabs { display: flex; flex-wrap: wrap; gap: 4px; padding: 8px 10px 0; }
.tabs button { background: transparent; color: var(--muted); padding: 4px 8px; font-size: 13px; }
.tabs button.active { background: var(--brand-soft); color: #166534; font-weight: 600; }
.tabs b { background: var(--danger); color: #fff; border-radius: 9px; padding: 0 6px; font-size: 11px; }
.tabs b:empty { display: none; }
.search { margin: 8px 10px; padding: 7px 10px; border: 1px solid var(--line); border-radius: 6px; font: inherit; }
.conv-list { flex: 1; overflow-y: auto; }
.conv { padding: 10px 14px; border-bottom: 1px solid #f3f4f6; cursor: pointer; display: flex; gap: 10px; }
.conv:hover { background: #f9fafb; }
.conv.active { background: var(--brand-soft); }
.conv-main { flex: 1; min-width: 0; }
.conv-top { display: flex; justify-content: space-between; gap: 6px; }
.conv-name { font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.conv-time { font-size: 11px; color: var(--muted); flex: none; }
.conv-last { font-size: 12px; color: var(--muted); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.conv-tags { display: flex; gap: 4px; margin-top: 3px; flex-wrap: wrap; }
.tag { font-size: 11px; padding: 0 6px; border-radius: 4px; background: var(--bg); color: var(--muted); }
.tag.waiting { background: #fef3c7; color: #92400e; }
.tag.open { background: var(--brand-soft); color: #166534; }
.tag.ok { background: #dbeafe; color: #1e40af; }
.unread { align-self: center; background: var(--danger); color: #fff; border-radius: 10px; min-width: 20px; text-align: center; font-size: 11px; padding: 0 6px; }
.list-empty { padding: 30px; text-align: center; color: var(--muted); }

/* 聊天 */
.empty { margin: auto; color: var(--muted); }
.chat-inner { display: flex; flex-direction: column; height: 100%; }
.chat-head { display: flex; align-items: center; gap: 8px; padding: 10px 14px; background: var(--panel); border-bottom: 1px solid var(--line); }
.chat-head .who { flex: 1; min-width: 0; }
.who-name { font-weight: 600; }
.who-sub { font-size: 12px; color: var(--muted); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.back { display: none; font-size: 18px; padding: 2px 10px; }
.msgs { flex: 1; overflow-y: auto; padding: 16px; display: flex; flex-direction: column; gap: 8px; }
.row { display: flex; flex-direction: column; max-width: 70%; }
.row.member { align-self: flex-start; align-items: flex-start; }
.row.agent { align-self: flex-end; align-items: flex-end; }
.row.system { align-self: center; max-width: 90%; }
.meta { font-size: 11px; color: var(--muted); margin: 0 4px 2px; }
.bubble { padding: 8px 12px; border-radius: 12px; white-space: pre-wrap; word-break: break-word; background: var(--panel); box-shadow: 0 1px 2px rgba(0,0,0,.05); }
.agent .bubble { background: var(--brand); color: #fff; }
.system .bubble { background: transparent; box-shadow: none; color: var(--muted); font-size: 12px; text-align: center; }
.bubble img { display: block; max-width: 260px; max-height: 300px; border-radius: 6px; cursor: zoom-in; }
.bubble.img { padding: 4px; background: var(--panel); }
.composer { background: var(--panel); border-top: 1px solid var(--line); padding: 8px 12px; position: relative; }
.composer textarea { width: 100%; height: 76px; resize: vertical; border: 1px solid var(--line); border-radius: 6px; padding: 8px 10px; font: inherit; outline: none; }
.composer textarea:focus { border-color: var(--brand); }
.composer-bar { display: flex; align-items: center; gap: 8px; margin-top: 6px; }
.quick { position: absolute; bottom: 100%; left: 12px; right: 12px; max-height: 260px; overflow-y: auto; background: var(--panel); border: 1px solid var(--line); border-radius: 8px; box-shadow: 0 -6px 20px rgba(0,0,0,.08); }
.quick div { padding: 8px 12px; cursor: pointer; border-bottom: 1px solid #f3f4f6; }
.quick div:hover { background: var(--brand-soft); }

/* 资料 */
.info h3 { font-size: 13px; margin: 4px 0 8px; color: var(--muted); }
.info dl { margin: 0 0 16px; display: grid; grid-template-columns: 70px 1fr; gap: 6px 8px; font-size: 13px; }
.info dt { color: var(--muted); }
.info dd { margin: 0; word-break: break-all; }
.info textarea { width: 100%; height: 100px; border: 1px solid var(--line); border-radius: 6px; padding: 8px; font: inherit; }

.viewer { position: fixed; inset: 0; background: rgba(0,0,0,.85); display: none; align-items: center; justify-content: center; z-index: 10; cursor: zoom-out; }
.viewer img { max-width: 95%; max-height: 95%; }

/* 手机 / 窄屏 */
@media (max-width: 900px) {
  .info { position: fixed; right: 0; top: 0; bottom: 0; z-index: 5; box-shadow: -6px 0 20px rgba(0,0,0,.1); }
}
@media (max-width: 700px) {
  .side { width: 100%; }
  .main.in-chat .side { display: none; }
  .main:not(.in-chat) .chat { display: none; }
  .back { display: inline-block; }
  .row { max-width: 85%; }
  .chat-head { flex-wrap: wrap; }
}

/* 没选会话时不显示资料栏 */
.main:not(.in-chat) .info { display: none; }

/* 平台资料 */
.info-head { display: flex; align-items: center; justify-content: space-between; }
.info-head h3 { display: flex; align-items: center; gap: 6px; }
button.small { padding: 3px 10px; font-size: 12px; }
.lookup { display: flex; gap: 6px; margin-bottom: 10px; }
.lookup input { flex: 1; min-width: 0; padding: 5px 8px; border: 1px solid var(--line); border-radius: 6px; font: inherit; font-size: 13px; }
.pf-state { font-size: 12px; color: var(--muted); margin-bottom: 8px; }
.pf-state.warn { color: #92400e; background: #fef3c7; padding: 6px 8px; border-radius: 6px; }
.pf-state.bad { color: var(--danger); }
#pfList dd.hl { font-weight: 600; color: #166534; }
#pfList dd.note { color: #b45309; font-weight: 600; }

/* 在后台查看 */
.admin-btn { width: 100%; margin-bottom: 6px; padding: 8px; font-weight: 600; }
.admin-tip { font-size: 12px; color: #166534; margin-bottom: 8px; }
.admin-tip:empty { display: none; }
