/* CASA 工作群 - 移动端优先的浅色主题样式 */
:root {
  --orange: #f18805;
  --orange-dark: #d86e00;
  --bg: #ededed;
  --bg-light: #ffffff;
  --text: #1a1a1a;
  --text-muted: #888888;
  --border: #e5e5e5;
  --danger: #fa5151;
  --warn-bg: #fef0f0;
  --warn-text: #d32f2f;
  --safe-bottom: env(safe-area-inset-bottom, 0px);
  --safe-top: env(safe-area-inset-top, 0px);
}

* { box-sizing: border-box; margin: 0; padding: 0; -webkit-tap-highlight-color: transparent; }

html, body {
  height: 100%;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "PingFang SC", "Microsoft YaHei", sans-serif;
  background: var(--bg);
  color: var(--text);
  font-size: 16px;
}

.hidden { display: none !important; }

/* 把 file input 绝对定位到屏幕外而不是 hidden —— 修复 Android Chrome PWA 模式下
   hidden input + 编程式 .click() 偶发不响应的 bug */
.visually-hidden {
  position: absolute !important;
  width: 1px !important;
  height: 1px !important;
  padding: 0 !important;
  margin: -1px !important;
  overflow: hidden !important;
  clip: rect(0,0,0,0) !important;
  white-space: nowrap !important;
  border: 0 !important;
  opacity: 0 !important;
}

.screen { min-height: 100dvh; }

/* ---- 登录页 ---- */
#auth-screen {
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px;
  background: #ffffff;
}
.auth-card {
  width: 100%;
  max-width: 360px;
  background: #f0a51c;
  border: 1px solid rgba(0, 0, 0, 0.08);
  border-radius: 16px;
  padding: 36px 28px;
  text-align: center;
  box-shadow: 0 8px 30px rgba(0,0,0,0.12);
}
.logo-img {
  width: auto;
  max-width: 230px;
  height: auto;
  max-height: 133px;
  margin: 0 auto 16px;
  border-radius: 12px;
  object-fit: contain;
  display: block;
}
.subtitle { color: #5a5a5a; font-size: 13px; margin-bottom: 28px; letter-spacing: 0.5px; }
#login-form input {
  width: 100%; padding: 13px 14px; margin-bottom: 12px;
  border: 1px solid var(--border); border-radius: 10px; font-size: 16px;
  background: #fff; color: var(--text);
}
#login-form input:focus { outline: none; border-color: var(--orange); }
.btn-primary {
  width: 100%; padding: 13px; border: none; border-radius: 10px;
  background: var(--orange); color: #fff; font-size: 16px; font-weight: 600; cursor: pointer;
  transition: background 0.2s;
}
.btn-primary:hover { background: var(--orange-dark); }
.btn-primary:active { background: var(--orange-dark); }

/* 登录按钮：黑色，与黄色登录卡片搭配 */
#login-form .btn-primary { background: #1a1a1a; }
#login-form .btn-primary:hover { background: #333; }
#login-form .btn-primary:active { background: #000; }

.error { color: #7a1010; font-size: 13px; margin-top: 10px; min-height: 18px; }
.hint { color: #6b4a10; font-size: 12px; margin-top: 16px; }
.app-version { color: rgba(0,0,0,0.45); font-size: 11px; margin-top: 12px; letter-spacing: 1px; }

/* ---- 主界面 ---- */
#app-screen {
  display: flex;
  flex-direction: column;
  height: 100dvh;
}
.topbar {
  display: flex; align-items: center; justify-content: space-between;
  padding: calc(8px + var(--safe-top)) 8px 8px;
  background: var(--bg-light);
  border-bottom: 1px solid var(--border);
}
.topbar-title { font-size: 17px; font-weight: 600; flex: 1; text-align: center; }
.topbar-spacer { width: 40px; height: 40px; flex-shrink: 0; }
.icon-btn {
  width: 40px; height: 40px; border: none; background: transparent;
  font-size: 22px; cursor: pointer; color: var(--text);
  display: inline-flex; align-items: center; justify-content: center;
}

.group-tabs {
  display: flex; background: var(--bg-light);
  border-bottom: 1px solid var(--border);
}
.tab {
  flex: 1; padding: 10px 0; border: none; background: transparent;
  font-size: 15px; color: var(--text-muted); cursor: pointer;
  border-bottom: 2px solid transparent;
}
.tab.active { color: var(--orange); border-bottom-color: var(--orange); font-weight: 600; }

.message-list {
  flex: 1; overflow-y: auto; padding: 16px 12px;
  -webkit-overflow-scrolling: touch;
}
.sys-tip { padding: 32px 20px; text-align: center; color: var(--text-muted); font-size: 13px; line-height: 1.8; }
.day-divider { text-align: center; margin: 8px 0 16px; font-size: 12px; color: #999; }

.msg { display: flex; margin-bottom: 16px; }
.msg.mine { flex-direction: row-reverse; }
.avatar {
  width: 40px; height: 40px; border-radius: 8px; flex-shrink: 0;
  display: flex; align-items: center; justify-content: center;
  color: #fff; font-size: 16px; font-weight: 600;
}
.msg-body { max-width: 72%; margin: 0 10px; display: flex; flex-direction: column; }
.msg.mine .msg-body { align-items: flex-end; }
.sender { font-size: 12px; color: var(--text-muted); margin-bottom: 4px; }
.msg.mine .sender { text-align: right; }
.bubble {
  padding: 9px 12px; border-radius: 8px; background: #fff;
  font-size: 16px; line-height: 1.45; word-break: break-word; white-space: pre-wrap;
  box-shadow: 0 1px 2px rgba(0,0,0,0.04);
}
.msg.mine .bubble { background: #ffd8a6; }
.bubble img { display: block; max-width: 200px; border-radius: 6px; cursor: zoom-in; }
/* 图片气泡外框着色：OCR 读到"字母 + 7 位数字"格式的 INVOICE NO. → 绿框；否则 → 红框 */
.bubble img.img-ok { border: 3px solid #22a06b; }
.bubble img.img-bad { border: 3px solid #e5484d; }
/* 本地图片未做 OCR → 灰色虚线边（v39） */
.bubble img.img-pending { border: 3px dashed #b8b8b8; }

/* ---------- v39 离线消息状态 ---------- */
.msg.local .bubble { opacity: 0.78; }
.msg.msg-sending .bubble { opacity: 0.6; }
.msg.msg-failed .bubble { opacity: 0.95; border: 1px dashed #e5484d; background: #fff5f5 !important; }
.msg.msg-retryable { cursor: pointer; }
.msg-msg-retryable:hover .bubble { background: #ffe6e6 !important; }

/* v70：图片在线发送的三段状态（uploading=本地显示/COS PUT 中；finalizing=COS 完成/OCR done 中；done=已确认） */
.msg.msg-uploading .bubble { opacity: 0.85; outline: 1.5px dashed #f18805; outline-offset: 2px; }
.msg.msg-uploading .bubble::after { content: 'Uploading'; font-size: 10px; color: #f18805; margin-left: 6px; }
.msg.msg-finalizing .bubble { opacity: 0.85; outline: 1.5px dashed #07c160; outline-offset: 2px; }
.msg.msg-finalizing .bubble::after { content: 'Finalizing'; font-size: 10px; color: #07c160; margin-left: 6px; }
.msg.msg-done .bubble { opacity: 1; }

.msg-status {
  display: inline-block;
  margin-top: 2px;
  font-size: 11px;
  color: #888;
  text-align: right;
  width: 100%;
}
.msg-failed .msg-status { color: #e5484d; }

/* 顶栏离线横幅 */
.offline-bar {
  background: #fff8e1;
  color: #8b6f00;
  text-align: center;
  font-size: 13px;
  padding: 6px 12px;
  border-bottom: 1px solid #f0d97b;
}
/* v42：顶栏可点击 → 手动重试 */
.offline-bar:not(.offline) { cursor: pointer; user-select: none; }
.offline-bar:not(.offline):hover { background: #fff3c4; }
.offline-bar.offline {
  background: #fbe9e7;
  color: #c62828;
  border-bottom-color: #f5c6c1;
}

/* ---- Deduction Record 弹窗 ---- */
.deduction-form { display: flex; flex-wrap: wrap; gap: 8px; margin-bottom: 12px; }
.deduction-form > input,
.deduction-form > select { flex: 1 1 130px; min-width: 0; padding: 10px 12px; border: 1px solid var(--border); border-radius: 8px; font-size: 15px; background: #fff; color: var(--text); }
.deduction-form > select { appearance: auto; }
.deduction-form > button { flex: 0 0 auto; padding: 10px 18px; }
.deduction-toolbar { display: flex; justify-content: space-between; align-items: center; margin-bottom: 8px; }
.deduction-unit { color: var(--text-muted); font-size: 12px; }
.deduction-table-wrap { max-height: 60vh; overflow: auto; border: 1px solid var(--border); border-radius: 8px; }
.deduction-table { width: 100%; border-collapse: collapse; font-size: 14px; }
.deduction-table th, .deduction-table td { padding: 8px 10px; border-bottom: 1px solid var(--border); text-align: left; }
.deduction-table th { background: rgba(0,0,0,0.04); font-weight: 600; position: sticky; top: 0; }
.deduction-table tbody tr:last-child td { border-bottom: none; }
.deduction-table .num { text-align: right; font-variant-numeric: tabular-nums; white-space: nowrap; }
.deduction-table .actions { text-align: right; }
.deduction-table .del-btn { background: var(--danger); color: #fff; border: none; padding: 4px 10px; border-radius: 6px; cursor: pointer; font-size: 12px; }
.deduction-table .del-btn:hover { opacity: 0.9; }
.deduction-table .empty { text-align: center; color: var(--text-muted); padding: 24px; font-size: 13px; }
.msg-time { font-size: 11px; color: #bbb; margin-top: 4px; }

/* 机器人消息（WARNING 高亮） */
.msg.bot .bubble {
  background: var(--warn-bg); color: var(--warn-text); font-weight: 600;
  border: 1px solid #f3b4b4;
}

/* 图片加载态 */
.img-loading { width: 200px; height: 140px; background: #f0f0f0; border-radius: 6px; display:flex; align-items:center; justify-content:center; color:#aaa; font-size:13px; }

/* ---- 输入栏 ---- */
.composer {
  display: flex; align-items: center; gap: 6px;
  padding: 8px 8px calc(8px + var(--safe-bottom));
  background: var(--bg-light); border-top: 1px solid var(--border);
}
.composer input[type="text"] {
  flex: 1; padding: 10px 12px; border: 1px solid var(--border);
  border-radius: 20px; font-size: 16px;
}
.composer input[type="text"]:focus { outline: none; border-color: var(--orange); }
.send-btn {
  padding: 10px 16px; border: none; border-radius: 20px;
  background: var(--orange); color: #fff; font-size: 15px; font-weight: 600; cursor: pointer;
}
.send-btn:active { background: var(--green-dark); }

/* ---- 抽屉 & 弹窗 ---- */
.mask { position: fixed; inset: 0; background: rgba(0,0,0,0.4); z-index: 100; }

/* ---- 发图方式选择（底部动作面板） ---- */
.action-sheet {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 210;
  padding: 8px 10px calc(10px + env(safe-area-inset-bottom));
  display: flex; flex-direction: column; gap: 8px;
  animation: sheetUp .18s ease-out;
}
@keyframes sheetUp { from { transform: translateY(100%); } to { transform: translateY(0); } }
.sheet-item {
  width: 100%; padding: 16px; border: none; border-radius: 12px;
  background: var(--bg-light); color: var(--text);
  font-size: 16px; font-weight: 500; cursor: pointer;
  box-shadow: 0 2px 10px rgba(0,0,0,.15);
}
.sheet-item:active { background: var(--bg); }
.sheet-item.sheet-cancel { color: var(--text-muted); font-weight: 400; }

.drawer {
  position: fixed; top: 0; left: 0; bottom: 0; width: 280px; max-width: 82%;
  background: var(--bg-light); z-index: 101;
  display: flex; flex-direction: column;
  transform: translateX(0); transition: transform .2s ease;
}
.drawer-header {
  display: flex; align-items: center; gap: 12px; padding: 24px 16px 16px;
  background: #f7f7f7; border-bottom: 1px solid var(--border);
}
.drawer-header .avatar { background: var(--orange); }
.drawer-name { font-size: 16px; font-weight: 600; }
.drawer-role { font-size: 12px; color: var(--text-muted); }
.drawer-body { flex: 1; overflow-y: auto; padding: 12px; display: flex; flex-direction: column; }
.drawer-footer { margin-top: auto; padding-top: 12px; border-top: 1px solid var(--border); }
.section-title { font-size: 13px; color: var(--text-muted); margin: 16px 4px 8px; }
.menu-item {
  display: flex; align-items: center; gap: 8px; width: 100%;
  padding: 12px 8px; border: none; background: transparent;
  font-size: 15px; color: var(--text); cursor: pointer; text-align: left;
  border-radius: 8px;
}
.menu-item:active { background: #f0f0f0; }
.menu-item.danger { color: var(--danger); }
.my-group { display: flex; justify-content: space-between; padding: 10px 8px; font-size: 15px; border-bottom: 1px solid #f5f5f5; }
.badge { font-size: 12px; color: var(--orange); }

.modal {
  position: fixed; left: 50%; top: 50%; transform: translate(-50%, -50%);
  width: 92%; max-width: 480px; max-height: 84vh;
  background: var(--bg-light); border-radius: 16px; z-index: 101;
  display: flex; flex-direction: column; overflow: hidden;
}
.modal-header {
  display: flex; align-items: center; justify-content: space-between;
  padding: 16px; border-bottom: 1px solid var(--border);
}
.modal-header h2 { font-size: 17px; font-weight: 600; }
.list-group-name { font-size: 13px; font-weight: 400; color: var(--text-muted); }
.modal-body { flex: 1; overflow-y: auto; padding: 16px; }
.create-user { display: flex; flex-direction: column; gap: 8px; margin-bottom: 16px; }
.create-user input {
  padding: 11px 12px; border: 1px solid var(--border); border-radius: 8px; font-size: 15px;
}
.create-user input:focus { outline: none; border-color: var(--orange); }
.member-tabs { display: flex; margin-bottom: 12px; border-bottom: 1px solid var(--border); }
.mtab { flex: 1; padding: 8px 0; border: none; background: transparent; font-size: 14px; color: var(--text-muted); cursor: pointer; }
.mtab.active { color: var(--orange); font-weight: 600; border-bottom: 2px solid var(--orange); }
/* 黑名单弹窗内的群切换栏：4 个群更紧凑，防中文名换行 */
.list-group-tabs { margin: 0 0 10px; flex: none; }
.list-group-tabs .mtab { font-size: 13px; padding: 8px 2px; white-space: nowrap; }
.user-list { list-style: none; }
.user-item {
  display: flex; align-items: center; justify-content: space-between; gap: 8px;
  padding: 10px 4px; border-bottom: 1px solid #f5f5f5;
}
.user-info { flex: 1; min-width: 0; }
.user-name { font-size: 15px; font-weight: 500; }
.user-role { font-size: 12px; color: var(--text-muted); }
.user-actions { display: flex; gap: 6px; flex-shrink: 0; }
.mini-btn {
  padding: 5px 10px; border: 1px solid var(--border); border-radius: 6px;
  background: #fff; font-size: 13px; cursor: pointer; color: var(--text);
}
.mini-btn.in { background: var(--orange); border-color: var(--orange); color: #fff; }
.mini-btn.del { color: var(--danger); border-color: #f3c1c1; }

/* ---- Toast ---- */
.toast {
  position: fixed; left: 50%; top: 50%; transform: translate(-50%, -50%);
  background: rgba(0,0,0,0.75); color: #fff; padding: 12px 18px;
  border-radius: 10px; font-size: 14px; z-index: 200; max-width: 80%; text-align: center;
}

/* ---- WARNING LIST 管理弹窗 ---- */
.list-modal { max-height: calc(100dvh - 40px); display: flex; flex-direction: column; }
.list-modal .modal-header { flex: none; }
.list-modal-body {
  display: flex; flex-direction: column; min-height: 0; overflow: hidden; padding: 12px 14px;
}
.list-add-row { display: flex; gap: 8px; margin-bottom: 10px; }
.list-add-row input {
  flex: 1; min-width: 0; padding: 10px 12px;
  border: 1px solid var(--border); border-radius: 8px; font-size: 15px;
}
.list-add-row .btn-primary { width: auto; padding: 10px 18px; flex: none; }
.list-toolbar { display: flex; align-items: center; gap: 8px; margin-bottom: 8px; }
.list-toolbar input {
  flex: 1; min-width: 0; padding: 8px 12px;
  border: 1px solid var(--border); border-radius: 8px; font-size: 14px;
}
.list-count { color: var(--text-muted); font-size: 12px; white-space: nowrap; }
.list-items {
  list-style: none; flex: 1; min-height: 200px; max-height: 52dvh;
  overflow-y: auto; border: 1px solid var(--border); border-radius: 8px;
  background: #fafafa; -webkit-overflow-scrolling: touch;
}
.list-item {
  display: flex; align-items: center; justify-content: space-between;
  padding: 8px 10px; border-bottom: 1px solid var(--border); font-size: 14px;
}
.list-item .list-no { font-family: monospace; word-break: break-all; }
.list-item .mini-btn { padding: 3px 10px; font-size: 12px; flex: none; margin-left: 8px; }
.list-empty { padding: 18px; color: var(--text-muted); text-align: center; font-size: 13px; }
.list-footer { display: flex; align-items: center; gap: 10px; margin-top: 10px; }
.list-footer .btn-primary { width: auto; padding: 10px 20px; }
.list-dirty { color: var(--warn-text); font-size: 12px; background: var(--warn-bg); padding: 4px 10px; border-radius: 6px; }

/* ---- 白单/红单丢失列表 ---- */
.lost-items .list-item { flex-wrap: wrap; }
.lost-meta { flex-basis: 100%; font-size: 12px; color: var(--text-muted); margin-top: 3px; }
.lost-meta .lost-status-pending { color: var(--warn-text); }
.lost-meta .lost-status-done { color: #22a06b; }
.lost-tip { font-size: 12px; color: var(--text-muted); margin-top: 8px; text-align: center; }

/* ---- 导出 Excel 群选择弹窗 ---- */
.export-body { padding-top: 12px; }
.export-hint { font-size: 13px; color: var(--text-muted); margin-bottom: 12px; }
.export-group-list { list-style: none; }
.export-group-item {
  display: flex; align-items: center; justify-content: space-between;
  padding: 14px 12px; border-bottom: 1px solid var(--border); cursor: pointer;
}
.export-group-item:active { background: #f7f7f7; }
.export-group-name { font-size: 15px; font-weight: 500; }
.export-group-go { font-size: 13px; color: var(--orange); }

/* ---- 图片查看器 ---- */
.img-viewer {
  position: fixed; inset: 0; z-index: 300;
  background: rgba(0,0,0,0.92);
  display: flex; flex-direction: column; align-items: center; justify-content: center;
  padding: 16px;
  touch-action: none; /* 手势完全交给 JS（缩放/拖动/关闭） */
}
.img-viewer img {
  max-width: 100%; max-height: calc(100% - 60px);
  object-fit: contain; border-radius: 4px;
  /* 手势缩放/拖动相关 */
  touch-action: none;          /* 禁用浏览器默认手势，交给 JS */
  user-select: none; -webkit-user-select: none;
  -webkit-user-drag: none;
  transform-origin: center center;
  will-change: transform;
}
.img-viewer-tip {
  color: rgba(255,255,255,0.55); font-size: 12px; margin-top: 14px;
}

/* 聊天气泡图片：加载中占位高度，避免跳屏 */
.bubble img { min-height: 60px; }

/* 桌面端稍宽 */
@media (min-width: 640px) {
  #app-screen { max-width: 560px; margin: 0 auto; border-left: 1px solid var(--border); border-right: 1px solid var(--border); }
}
