:root { color-scheme: light; --ink: #111827; --muted: #6b7280; --line: #e5e7eb; --bg: #f3f4f6; --card: #fff; --accent: #1e40af; --accent-l: #dbeafe; --danger: #b91c1c; --ok: #15803d; }
* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; background: var(--bg); color: var(--ink); font: 14px/1.45 system-ui, -apple-system, "Segoe UI", Roboto, "Noto Sans", "PingFang SC", "Microsoft YaHei", "Noto Sans Thai", sans-serif; }
#app { height: 100%; }
button, input, textarea, select { font: inherit; }
button { cursor: pointer; }
.ag-hidden { display: none; }
.ag-boot, .ag-empty { padding: 24px; text-align: center; color: var(--muted); }
.ag-muted { color: var(--muted); }
.ag-ok { color: var(--ok); } .ag-fail { color: var(--danger); }

/* 通用控件 */
.ag-primary { background: var(--accent); color: #fff; border: 0; border-radius: 8px; padding: 8px 14px; font-weight: 600; }
.ag-primary:disabled { opacity: .5; cursor: not-allowed; }
.ag-ghost { background: transparent; border: 1px solid var(--line); border-radius: 8px; padding: 6px 10px; color: var(--ink); }
.ag-link { background: transparent; border: 0; color: var(--accent); padding: 0 4px; text-decoration: underline; font-size: 12px; }
.ag-badge { display: inline-block; min-width: 18px; padding: 0 5px; border-radius: 9px; background: #ef4444; color: #fff; font-size: 11px; line-height: 18px; text-align: center; font-weight: 600; margin-left: 4px; }
input[type=text], input[type=password], input[type=search], textarea, select { width: 100%; padding: 8px 10px; border: 1px solid var(--line); border-radius: 8px; background: #fff; outline: none; }
input:focus, textarea:focus, select:focus { border-color: var(--accent); }
textarea { resize: vertical; }
.ag-row { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }

/* 登录 */
.ag-login { min-height: 100%; display: grid; place-items: center; padding: 16px; }
.ag-login-card { width: 100%; max-width: 360px; background: var(--card); padding: 24px; border-radius: 14px; box-shadow: 0 10px 30px rgba(0, 0, 0, .1); display: grid; gap: 14px; }
.ag-login-card h1 { margin: 0; font-size: 20px; }
.ag-login-card label { display: grid; gap: 4px; color: var(--muted); font-size: 12px; }
.ag-note { background: #fee2e2; color: #991b1b; padding: 8px 10px; border-radius: 8px; }

/* 外壳 */
.ag-shell { height: 100%; display: flex; flex-direction: column; }
.ag-top { display: flex; align-items: center; gap: 12px; padding: 8px 14px; background: #1e3a8a; color: #fff; }
.ag-top .ag-ghost { color: #fff; border-color: rgba(255, 255, 255, .35); }
.ag-brand { white-space: nowrap; }
.ag-tabs { flex: 1; display: flex; gap: 4px; overflow-x: auto; }
.ag-nav { background: transparent; border: 0; color: rgba(255, 255, 255, .8); padding: 6px 12px; border-radius: 8px; white-space: nowrap; }
.ag-nav.ag-active { background: rgba(255, 255, 255, .18); color: #fff; }
.ag-user { white-space: nowrap; opacity: .85; }
.ag-update { background: #fde68a; border: 0; padding: 6px; color: #78350f; cursor: pointer; }
.ag-banner { background: #fee2e2; color: #991b1b; padding: 6px 14px; cursor: pointer; }
.ag-main { flex: 1; min-height: 0; }

/* 会话 */
.ag-chats { height: 100%; display: grid; grid-template-columns: 320px 1fr; }
.ag-side { background: var(--card); border-right: 1px solid var(--line); display: flex; flex-direction: column; min-height: 0; }
.ag-seg { display: flex; border-bottom: 1px solid var(--line); }
.ag-seg button { flex: 1; padding: 10px; background: transparent; border: 0; border-bottom: 2px solid transparent; color: var(--muted); }
.ag-seg button.ag-active { color: var(--accent); border-bottom-color: var(--accent); font-weight: 600; }
.ag-count { color: var(--muted); font-size: 12px; }
.ag-rooms { list-style: none; margin: 0; padding: 0; overflow-y: auto; flex: 1; }
.ag-room-item { padding: 10px 12px; border-bottom: 1px solid var(--line); cursor: pointer; }
.ag-room-item:hover { background: #f9fafb; }
.ag-room-item.ag-sel { background: var(--accent-l); }
.ag-room-top, .ag-room-bot { display: flex; justify-content: space-between; gap: 8px; align-items: center; }
.ag-room-name { font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.ag-room-time { color: var(--muted); font-size: 12px; }
.ag-room-prev { color: var(--muted); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-size: 13px; }
.ag-room { min-width: 0; min-height: 0; background: var(--bg); }
.ag-roomview { height: 100%; display: flex; flex-direction: column; }
.ag-room-head { display: flex; align-items: center; gap: 10px; padding: 8px 12px; background: var(--card); border-bottom: 1px solid var(--line); }
.ag-room-title { flex: 1; min-width: 0; display: flex; flex-direction: column; }
.ag-page { color: var(--accent); font-size: 12px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.ag-back { display: none; background: transparent; border: 0; font-size: 28px; line-height: 1; }
.ag-msgs { flex: 1; overflow-y: auto; padding: 12px; display: flex; flex-direction: column; gap: 8px; overscroll-behavior: contain; }
.ag-more { align-self: center; }
.ag-msg { display: flex; }
.ag-msg.ag-me { justify-content: flex-end; }
.ag-bubble { max-width: min(70%, 640px); padding: 8px 10px; border-radius: 12px; background: var(--card); box-shadow: 0 1px 2px rgba(0, 0, 0, .08); overflow-wrap: anywhere; }
.ag-me .ag-bubble { background: #dbeafe; }
.ag-bubble.ag-pending { opacity: .65; }
.ag-sender { font-size: 11px; color: var(--muted); margin-bottom: 2px; }
.cb-text { white-space: pre-wrap; }
.ag-bubble a { color: var(--accent); }
.ag-img { display: block; max-width: 100%; max-height: 260px; border-radius: 8px; cursor: zoom-in; background: #e5e7eb; min-width: 60px; min-height: 40px; }
.ag-upload { width: 160px; height: 8px; background: #e5e7eb; border-radius: 4px; overflow: hidden; margin: 6px 0; }
.ag-upload-bar { height: 100%; background: var(--accent); }
.ag-meta { display: flex; gap: 8px; justify-content: flex-end; font-size: 11px; color: var(--muted); margin-top: 2px; align-items: center; }
.ag-trans { margin-top: 4px; padding-top: 4px; border-top: 1px dashed var(--line); color: #374151; white-space: pre-wrap; }
.ag-composer { display: flex; gap: 8px; align-items: flex-end; padding: 8px 12px; background: var(--card); border-top: 1px solid var(--line); padding-bottom: max(8px, env(safe-area-inset-bottom)); }
.ag-composer textarea { flex: 1; resize: none; }

/* 知识库 */
.ag-kb { height: 100%; display: grid; grid-template-columns: 320px 1fr; }
.ag-kb-list { background: var(--card); border-right: 1px solid var(--line); padding: 10px; overflow-y: auto; display: flex; flex-direction: column; gap: 8px; }
.ag-kb-newcat { display: flex; gap: 6px; }
.ag-kb-cat-head { display: flex; align-items: center; gap: 4px; margin-top: 8px; }
.ag-kb-cat-head strong { flex: 1; }
.ag-kb-entry { display: block; width: 100%; text-align: left; background: transparent; border: 0; padding: 6px 8px; border-radius: 6px; }
.ag-kb-entry:hover { background: #f3f4f6; }
.ag-kb-entry.ag-sel { background: var(--accent-l); }
.ag-kb-detail { padding: 16px; overflow-y: auto; }
.ag-kb-body { white-space: pre-wrap; background: var(--card); padding: 12px; border-radius: 8px; margin: 8px 0 12px; }
.ag-kb-edit { display: grid; gap: 10px; max-width: 760px; }
.ag-kb-edit label { display: grid; gap: 4px; color: var(--muted); font-size: 12px; }

/* 管理 / 设置 / 日志 */
.ag-page-box { padding: 16px; max-width: 980px; margin: 0 auto; height: 100%; overflow-y: auto; }
.ag-table { width: 100%; border-collapse: collapse; background: var(--card); border-radius: 8px; overflow: hidden; margin-bottom: 12px; }
.ag-table td { padding: 6px 10px; border-bottom: 1px solid var(--line); font-size: 13px; }
.ag-form { display: grid; gap: 8px; max-width: 480px; margin-bottom: 20px; }
.ag-form label { display: grid; gap: 4px; color: var(--muted); font-size: 12px; }
.ag-check { display: flex !important; flex-direction: row; align-items: center; gap: 6px; }

/* 图片预览 */
.cb-viewer { position: fixed; inset: 0; z-index: 50; background: rgba(0, 0, 0, .92); display: flex; align-items: center; justify-content: center; touch-action: none; overflow: hidden; }
.cb-viewer-img { max-width: 100%; max-height: 100%; user-select: none; -webkit-user-drag: none; }
.cb-viewer-close { position: absolute; top: 8px; right: 12px; border: 0; background: rgba(255, 255, 255, .15); color: #fff; width: 40px; height: 40px; border-radius: 20px; font-size: 26px; line-height: 1; }

@media (max-width: 760px) {
  .ag-chats { grid-template-columns: 1fr; }
  .ag-chats .ag-room { display: none; }
  .ag-chats.ag-has-room .ag-side { display: none; }
  .ag-chats.ag-has-room .ag-room { display: block; }
  .ag-back { display: block; }
  .ag-kb { grid-template-columns: 1fr; }
  .ag-user { display: none; }
  .ag-bubble { max-width: 88%; }
}
