:root {
  --bg: #f4f5f7; --panel: #fff; --line: #e3e5e9; --text: #1f2328; --muted: #6b7280;
  --accent: #2f6feb; --accent-weak: #e8f0fe; --user: #fff; --admin: #d9f2e3;
  --pending: #d97706; --replied: #2563eb; --resolved: #16a34a; --danger: #dc2626;
  --topbar: 48px;
}
* { box-sizing: border-box; }
[hidden] { display: none !important; }
html, body { margin: 0; height: 100%; }
body { font: 14px/1.5 -apple-system, BlinkMacSystemFont, "PingFang SC", "Microsoft YaHei", "Segoe UI", sans-serif;
  color: var(--text); background: var(--bg); }
button, input, select, textarea { font: inherit; color: inherit; }
button { cursor: pointer; border: 1px solid var(--line); background: #fff; border-radius: 6px; padding: 6px 12px; }
button:hover { border-color: #c4c8cf; }
button.primary { background: var(--accent); border-color: var(--accent); color: #fff; }
button.primary:hover { filter: brightness(1.05); }
button.danger { color: var(--danger); border-color: #f3c4c4; }
button.small { padding: 3px 9px; font-size: 13px; }
button.link { border: 0; background: none; color: var(--accent); padding: 0; }
button:disabled { opacity: .55; cursor: default; }
input, select, textarea { border: 1px solid var(--line); border-radius: 6px; padding: 6px 9px; background: #fff; }
input:focus, select:focus, textarea:focus { outline: 2px solid var(--accent-weak); border-color: var(--accent); }
code { font: 13px ui-monospace, SFMono-Regular, Menlo, monospace; background: #f0f1f3; padding: 1px 5px; border-radius: 4px; }
.muted { color: var(--muted); }
.small { font-size: 12px; }
.pad { padding: 16px; }
.alert { background: #fdecec; color: #9b1c1c; padding: 8px 12px; border-radius: 6px; }
.notice { background: #e7f6ec; color: #166534; padding: 8px 12px; border-radius: 6px; }
.chk { display: inline-flex; align-items: center; gap: 4px; white-space: nowrap; }

/* 顶栏 */
.topbar { height: var(--topbar); display: flex; align-items: center; gap: 24px; padding: 0 16px;
  background: #fff; border-bottom: 1px solid var(--line); }
.brand { font-weight: 600; }
.topbar nav { display: flex; gap: 4px; flex: 1; }
.topbar nav a { padding: 6px 12px; border-radius: 6px; color: var(--text); text-decoration: none; }
.topbar nav a.on { background: var(--accent-weak); color: var(--accent); }
.logout { display: flex; gap: 10px; align-items: center; }
.who { color: var(--muted); }

/* 登录 */
.login-page { display: grid; place-items: center; }
.login-card { width: min(360px, 92vw); background: #fff; border: 1px solid var(--line); border-radius: 12px; padding: 28px; }
.login-card h1 { font-size: 20px; margin: 0 0 18px; }
.login-card form, .stack-form { display: grid; gap: 12px; }
.login-card label, .stack-form label { display: grid; gap: 4px; color: var(--muted); }
.login-card button { margin-top: 6px; padding: 9px; }

/* 普通页面 */
.page { max-width: 980px; margin: 0 auto; padding: 24px 16px 48px; }
.page h1 { font-size: 20px; }
.page h2 { font-size: 16px; margin-top: 32px; }
.stack-form { max-width: 420px; }
table.apps { width: 100%; border-collapse: collapse; background: #fff; border: 1px solid var(--line); border-radius: 8px; }
table.apps th, table.apps td { padding: 8px 10px; border-bottom: 1px solid var(--line); text-align: left; vertical-align: middle; }
table.apps th { font-weight: 500; color: var(--muted); font-size: 13px; }
.inline-form { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; }
.inline-form input[name=name] { width: 140px; }
.inline-form input[name=icon_url] { flex: 1; min-width: 180px; }
.app-icon { width: 28px; height: 28px; border-radius: 7px; object-fit: cover; display: inline-grid; place-items: center; }
.app-icon.ph { background: var(--accent-weak); color: var(--accent); font-weight: 600; }

/* 收件箱三栏 */
.inbox { display: grid; grid-template-columns: 340px 1fr auto; height: calc(100vh - var(--topbar)); height: calc(100dvh - var(--topbar)); }
.list-pane { display: flex; flex-direction: column; border-right: 1px solid var(--line); background: #fff; min-height: 0; }
.filters { padding: 10px; display: grid; gap: 8px; border-bottom: 1px solid var(--line); }
.filters .row { display: flex; gap: 6px; align-items: center; }
.filters select { flex: 1; min-width: 0; }
.counts { font-size: 12px; color: var(--muted); }
.conv-list { list-style: none; margin: 0; padding: 0; overflow-y: auto; flex: 1; }
.conv { padding: 10px 12px; border-bottom: 1px solid #f0f1f3; cursor: pointer; }
.conv:hover { background: #f8f9fb; }
.conv.on { background: var(--accent-weak); }
.conv .line1 { display: flex; gap: 6px; align-items: center; font-size: 12px; }
.conv .time { margin-left: auto; color: var(--muted); }
.conv .cid { color: var(--muted); }
.app-tag { background: #eef0f3; border-radius: 4px; padding: 0 6px; }
.status { border-radius: 4px; padding: 0 6px; font-size: 12px; }
.s-pending { color: var(--pending); background: #fef3e2; }
.s-replied { color: var(--replied); background: #e8effd; }
.s-resolved { color: var(--resolved); background: #e7f6ec; }
.conv .line2 { display: flex; align-items: center; gap: 6px; margin-top: 3px; }
.conv .preview { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; color: #3d434c; }
.conv.unread .preview { font-weight: 600; color: var(--text); }
.dot { flex: none; width: 8px; height: 8px; border-radius: 50%; background: var(--danger); }
.conv .line3 { font-size: 12px; margin-top: 2px; }
.more { margin: 8px auto; display: block; }

.chat-pane { min-width: 0; min-height: 0; display: flex; flex-direction: column; }
.empty { margin: auto; color: var(--muted); }
.chat { display: flex; flex-direction: column; height: 100%; min-height: 0; }
.chat[hidden] { display: none; }
.chat-head { display: flex; align-items: center; gap: 10px; padding: 8px 14px; background: #fff; border-bottom: 1px solid var(--line); }
.chat-head .title { flex: 1; min-width: 0; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.chat-head .actions { display: flex; gap: 6px; align-items: center; }
.chat-head .back { display: none; }
.messages { flex: 1; overflow-y: auto; padding: 16px 18px; display: flex; flex-direction: column; gap: 12px; }
.msg { display: flex; flex-direction: column; max-width: 72%; }
.msg.user { align-self: flex-start; }
.msg.admin { align-self: flex-end; align-items: flex-end; }
.bubble { padding: 8px 12px; border-radius: 12px; background: var(--user); border: 1px solid var(--line); }
.msg.admin .bubble { background: var(--admin); border-color: #c3e6d1; }
.bubble .text { white-space: pre-wrap; word-break: break-word; }
.imgs { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 6px; }
.bubble .text + .imgs { margin-top: 8px; }
.imgs:first-child { margin-top: 0; }
.imgs img { max-width: 160px; max-height: 200px; height: auto; border-radius: 8px; cursor: zoom-in; border: 1px solid var(--line); background: #f3f4f6; }
.meta { font-size: 11px; color: var(--muted); margin-top: 3px; padding: 0 4px; }

.composer { border-top: 1px solid var(--line); background: #fff; padding: 10px 14px; display: grid; gap: 8px; }
.composer textarea { width: 100%; resize: vertical; min-height: 64px; }
.composer-bar { display: flex; align-items: center; gap: 10px; }
.composer-bar #send { margin-left: auto; }
.file-btn { border: 1px solid var(--line); border-radius: 6px; padding: 5px 12px; cursor: pointer; }
.file-btn input { display: none; }
.previews { display: flex; gap: 8px; flex-wrap: wrap; }
.previews:empty { display: none; }
.pv { position: relative; }
.pv img { width: 64px; height: 64px; object-fit: cover; border-radius: 6px; border: 1px solid var(--line); }
.pv button { position: absolute; top: -6px; right: -6px; width: 20px; height: 20px; padding: 0; border-radius: 50%; line-height: 1; }

.info-pane { width: 280px; border-left: 1px solid var(--line); background: #fff; padding: 14px 16px; overflow-y: auto; }
.info-pane[hidden] { display: none; }
.info-pane h3 { margin: 0 0 10px; font-size: 15px; }
.info-pane dl { display: grid; grid-template-columns: auto 1fr; gap: 6px 10px; margin: 0 0 20px; font-size: 13px; }
.info-pane dt { color: var(--muted); }
.info-pane dd { margin: 0; word-break: break-all; }

.lightbox { position: fixed; inset: 0; background: rgba(0,0,0,.82); display: grid; place-items: center; z-index: 50; cursor: zoom-out; }
.lightbox[hidden] { display: none; }
.lightbox img { max-width: 94vw; max-height: 94vh; border-radius: 4px; }

/* 窄屏：列表和聊天二选一 */
@media (max-width: 820px) {
  .topbar { gap: 10px; padding: 0 10px; }
  .who { display: none; }
  .inbox { grid-template-columns: 1fr; }
  .chat-pane { display: none; }
  body.show-chat .list-pane { display: none; }
  body.show-chat .chat-pane { display: flex; }
  .chat-head .back { display: inline-block; }
  .chat-head .actions select { display: none; }
  .msg { max-width: 88%; }
  .info-pane { position: fixed; right: 0; top: var(--topbar); bottom: 0; width: min(320px, 90vw); box-shadow: -4px 0 16px rgba(0,0,0,.12); z-index: 20; }
}
.stack-form label.chk { display: flex; color: var(--text); }
.stack-form button { justify-self: start; padding: 7px 22px; }
