:root{--bg:#f5f7fb;--card:#fff;--text:#172033;--muted:#6b7280;--accent:#ff9500;--line:#e5e7eb}
*{box-sizing:border-box}html,body{height:100%;margin:0;overflow-x:hidden}
body{font-family:-apple-system,BlinkMacSystemFont,"PingFang SC","Hiragino Sans GB","Microsoft YaHei","Segoe UI",Roboto,"Helvetica Neue",Arial,sans-serif;background:linear-gradient(180deg,#fff7ef 0%,#f5f7fb 34%,#eef2ff 100%);color:var(--text);font-size:16px;line-height:1.5}
[hidden]{display:none!important}
.sticky-header{position:sticky;top:0;z-index:20;background:#fff;backdrop-filter:blur(12px);border-bottom:1px solid #e4e9ed;padding:6px}
.header-row{display:flex;align-items:center;gap:8px;height:44px}
.page-title{flex:1;text-align:center;font-size:20px;font-weight:600;white-space:nowrap;overflow:hidden;text-overflow:ellipsis}
.top-spacer{width:48px;flex:0 0 48px}
.conversation-drawer{position:fixed;inset:0;z-index:80;display:block}
.conversation-drawer[hidden]{display:none!important}
.drawer-mask{position:absolute;inset:0;background:rgba(15,23,42,.36)}
.drawer-panel{position:absolute;top:60px;right:12px;width:min(72vw,240px);max-height:min(48vh,360px);background:#fff;border-radius:16px;box-shadow:0 16px 40px rgba(15,23,42,.22);display:flex;flex-direction:column;overflow:hidden}
.drawer-main{flex:1;overflow:auto;padding:10px}
.btn-clear-chat,.btn-send,.preview-close,.preview-back{min-height:44px}
.btn-back{border:0;background:transparent;color:var(--accent);font-size:15px;padding:0;width:26px;min-width:26px;min-height:26px;display:inline-flex;align-items:center;justify-content:center}
.btn-back .nav-icon-img{width:22px;height:22px;display:block}
.btn-clear-chat{border:1px solid var(--line);background:#fff;border-radius:10px;padding:0 10px;color:#475569;font-size:14px}
#messageList,
#guestMessages{display:flex;flex-direction:column;justify-content:flex-start;gap:10px;overflow-anchor:none}
.chat-empty-state-message{display:grid;place-items:center;flex:1;min-height:42vh;padding:24px;color:var(--muted);font-size:15px;text-align:center}
.denied-box,.feedback{border-radius:14px;padding:12px 14px;margin-bottom:12px;font-size:12px;font-weight:500;word-break:break-word}
.denied-box{background:#fef2f2;border:1px solid #fecaca;color:#b91c1c}
.feedback.error{background:#fef2f2;border:1px solid #fecaca;color:#b91c1c}
.feedback.success{background:#f0fdf4;border:1px solid #bbf7d0;color:#15803d}
.chat-feedback{position:fixed;left:16px;right:16px;bottom:92px;z-index:50;margin:0;box-shadow:0 8px 24px rgba(15,23,42,.12)}
.loading,.empty-state{text-align:center;color:var(--muted);padding:28px 8px}
.conv-list{display:flex;flex-direction:column;gap:10px}
.drawer-conv-item{display:flex;align-items:center;gap:10px;padding:10px 12px;background:#fff;border:1px solid var(--line);border-radius:12px;cursor:pointer}
.drawer-conv-title{flex:1;min-width:0;overflow:hidden;text-overflow:ellipsis;white-space:nowrap;font-size:14px;font-weight:600;color:#172033}
.drawer-conv-close{display:none}
.conv-item,.message-bubble{background:var(--card);border:1px solid var(--line);border-radius:16px}
.conv-item{padding:12px 14px}
.conv-top,.conv-sub{display:flex;justify-content:space-between;gap:10px;align-items:center}
.conv-title{font-size:14px;font-weight:600;min-width:0;overflow:hidden;text-overflow:ellipsis;white-space:nowrap}
.conv-time,.chat-status{font-size:12px;font-weight:500;color:var(--muted)}
.conv-sub-text{min-width:0;overflow:hidden;text-overflow:ellipsis;white-space:nowrap;color:#475569;font-size:12px;font-weight:500}
.conv-badge{background:var(--accent);color:#fff;border-radius:999px;min-width:22px;height:22px;line-height:22px;text-align:center;font-size:12px;font-weight:500;padding:0 7px}
.message-row{display:flex;flex-direction:column;max-width:min(82%,560px);position:relative}
.message-row.me{align-self:flex-end;align-items:flex-end}
.message-row.other{align-self:flex-start;align-items:flex-start}
.message-time{width:100%;flex:0 0 auto;text-align:center;color:#7890aa;font-size:12px;font-weight:500;line-height:20px;padding:2px 0 4px}
.message-meta{font-size:12px;font-weight:500;color:#94a3b8;margin:0 6px 3px}.message-read-state{font-size:12px;font-weight:500;color:#7890aa;margin:2px 6px 0;line-height:18px}
.message-bubble{padding:6px 10px;line-height:20px;word-break:break-word;white-space:pre-wrap;min-height:32px}
.message-row.me .message-bubble{background:#e6edf6;color:#334155;border-bottom-right-radius:4px}
.message-row.other .message-bubble{background:#f8dfe7;color:#7f1d3b;border-bottom-left-radius:4px}
.message-row.recalled .message-bubble{background:#f3f4f6;color:#94a3b8}
.attach-card{display:flex;flex-direction:column;gap:8px}
.attach-thumb{width:200px;max-width:100%;display:block;color:inherit;text-decoration:none}
.attach-img,.product-context-card img{width:200px;height:auto;border-radius:10px;display:block}
.file-thumb{width:200px;min-height:96px;display:grid;place-items:center;background:#eef2f7;color:#475569;border-radius:10px}
.file-thumb-icon{font-weight:700;letter-spacing:.08em}
.product-context-card{display:flex;flex-direction:column;gap:8px;color:inherit;text-decoration:none}
.product-thumb-placeholder{width:200px;height:120px;border-radius:10px;display:grid;place-items:center;background:linear-gradient(135deg,#fff4d6,#ffd08a);color:#9a5b00;font-weight:700}
.chat-product-card{display:flex;align-items:flex-start;gap:8px;max-width:100%;padding:6px 10px;color:inherit;text-decoration:none}
#messageList .chat-product-card-thumb,
#guestMessages .chat-product-card-thumb,
.chat-product-card-thumb{width:120px !important;max-width:120px !important;height:auto !important;flex:0 0 120px !important;border-radius:10px;object-fit:cover;display:block}
.chat-product-card-meta{display:flex;flex:1;min-width:0;flex-direction:column;gap:4px}
.chat-product-card-title{font-size:14px;font-weight:600;line-height:1.35;overflow:hidden;text-overflow:ellipsis;display:-webkit-box;-webkit-box-orient:vertical;-webkit-line-clamp:2}
.chat-product-card-model{font-size:12px;color:var(--muted);line-height:1.3;overflow:hidden;text-overflow:ellipsis;white-space:nowrap}
.message-action-menu{position:absolute;z-index:1000;left:50%;bottom:calc(100% + 8px);transform:translateX(-50%);display:flex;gap:12px;align-items:center;padding:0;background:transparent;border:0;box-shadow:none;white-space:nowrap}
.message-action-menu.below-message{top:calc(100% + 8px);bottom:auto}
.message-action-menu button{border:0;border-radius:0;background:transparent;color:#2563eb;padding:0;font-size:14px;line-height:20px}
.message-action-menu button:hover{text-decoration:underline;background:transparent}
.attachment-preview{position:fixed;inset:0;z-index:1100;background:rgba(0,0,0,.88);display:grid;place-items:center;padding:64px 16px 20px}
.attachment-preview img,.attachment-preview video{max-width:100%;max-height:100%;object-fit:contain}
.preview-close,.preview-back{position:absolute;top:12px;border:0;border-radius:999px;background:rgba(255,255,255,.16);color:#fff}
.preview-close{right:12px;width:44px;height:44px;font-size:30px}
.preview-back{left:12px;padding:0 14px}
.product-prompt{display:flex;align-items:center;justify-content:space-between;gap:6px;padding:2px 0;margin:0 0 4px;border:0;background:transparent;color:#9a5b00;font-size:11px;font-weight:600;line-height:1.1}
.chat-product-prompt-text{min-width:0;overflow:hidden;text-overflow:ellipsis;white-space:nowrap;line-height:1.1}
.chat-product-prompt-send{border:0;border-radius:8px;background:#ff9500;color:#fff;padding:2px 8px;font-size:11px;font-weight:600;min-height:24px}
.btn-send{padding:0 16px;border:0;border-radius:12px;background:var(--accent);color:#fff;font-size:14px}
@media (max-width:390px){.chat-main{padding:12px}.top-spacer{width:40px}.btn-send{padding:0 14px}.attach-thumb,.product-context-card img,.file-thumb,.product-thumb-placeholder{width:200px;max-width:100%}}
.message-avatar,.message-avatar-wrap{display:flex!important;width:38px!important;height:38px!important;max-width:38px!important;min-width:38px!important;overflow:hidden;flex:0 0 38px}
.message-avatar{display:block!important;width:38px!important;height:38px!important;border-radius:50%;object-fit:cover;background:#eef2f7;border:1px solid #dbe3ea;padding:5px}
.message-attachments{display:flex;flex-wrap:wrap;gap:8px;align-items:flex-start}
.message-attachment-image{display:block;width:min(70vw,320px);max-width:min(70vw,320px);min-height:200px;height:auto;aspect-ratio:1 / 1;object-fit:contain;cursor:zoom-in;border-radius:8px;background:#f8fafc}
.message-attachment-video{display:block;width:min(70vw,320px);max-width:min(70vw,320px);min-height:180px;height:auto;aspect-ratio:16 / 9;object-fit:contain;border-radius:8px;background:#111}
.message-attachment-audio{width:220px;max-width:60vw}
.chat-product-card{display:flex;align-items:flex-start;gap:8px;min-width:0;max-width:100%;text-decoration:none;color:inherit}
.chat-product-card-thumb{width:110px;max-width:110px;height:82px;flex:0 0 110px;object-fit:cover;border-radius:10px;background:#eef2f7}
.chat-product-card-meta{min-width:0;display:flex;flex-direction:column;gap:4px}
.chat-product-card-title,.chat-product-card-model{min-width:0;overflow:hidden;text-overflow:ellipsis;white-space:nowrap;font-size:13px;line-height:1.35}
.chat-product-card-title{font-weight:600;color:#0f172a}
.chat-product-card-model{color:#64748b}
.chat-window-shell #messageList .chat-product-card-thumb{width:110px!important;max-width:110px!important;flex:0 0 110px!important;height:82px!important}
.chat-image-lightbox{position:fixed;inset:0;z-index:3000;display:flex;align-items:center;justify-content:center;padding:24px;background:rgba(0,0,0,.82);cursor:zoom-out}
.chat-image-lightbox img{max-width:96vw;max-height:92vh;width:auto;height:auto;object-fit:contain}
.chat-image-lightbox-image{max-width:96vw;max-height:92vh;width:auto;height:auto;object-fit:contain;transition:transform .12s ease;touch-action:none}
.chat-image-lightbox-close{position:absolute;top:14px;right:16px;width:36px;height:36px;border:0;border-radius:50%;background:#fff;color:#111827;font-size:26px;line-height:1;cursor:pointer}
.btn-voice.is-recording{background:#fee2e2!important;color:#dc2626!important}
.btn-voice.is-recording::after{content:'';display:block;width:8px;height:8px;border-radius:50%;background:#dc2626;margin:0 auto}
.attach-video-player{display:block;width:200px;max-width:100%;height:auto;max-height:none;aspect-ratio:auto;object-fit:contain;border-radius:8px;background:#111}.attach-video{display:block;overflow:hidden}.attachment-preview img,.attachment-preview video{width:auto;max-width:calc(100vw - 32px);height:auto;max-height:92vh;object-fit:contain}
.chat-menu-button{position:relative;display:inline-flex;align-items:center;justify-content:center;min-width:36px;min-height:36px}.chat-menu-button .nav-icon-img[hidden]{display:none}.inbox-unread-badge{position:static;display:inline-flex;align-items:center;justify-content:center;min-width:28px;height:28px;padding:0 6px;border-radius:14px;background:#ef4444;color:#fff;box-shadow:0 0 0 2px #fff;font-size:14px;font-weight:700;line-height:1;white-space:nowrap}.inbox-unread-badge[hidden]{display:none}.inbox-item{position:relative}.inbox-item-close{margin-left:auto;border:0;background:transparent;color:#94a3b8;font-size:20px;padding:4px 8px;cursor:pointer}.inbox-item-tag{display:inline-block!important;width:max-content;margin:3px 4px 0 0;padding:1px 6px;border-radius:8px;color:#fff;font-size:10px!important;line-height:16px!important;white-space:nowrap!important}
.chat-window-shell .thread-main,
.chat-window-shell #chatView{position:relative}
/* 表情栏必须相对聊天主区域定位，避免 PC 端 absolute 参考视口后横向铺满整页。 */
.emoji-panel{position:absolute;bottom:70px;left:8px;right:8px;width:auto;max-width:100%;z-index:20;display:flex;flex-direction:column;box-sizing:border-box;background:#fff;border:1px solid var(--line);border-radius:10px;padding:8px;box-shadow:0 8px 24px rgba(0,0,0,.16);max-height:min(260px,42%);overflow:hidden}.emoji-pack-tabs{display:flex;flex:0 0 auto;gap:6px;overflow-x:auto;margin-bottom:8px;padding-bottom:1px;scrollbar-width:none}.emoji-pack-tabs::-webkit-scrollbar{display:none}.emoji-pack-tab{flex:0 0 auto;border:0;background:#f1f5f9;border-radius:6px;padding:5px 8px;white-space:nowrap;cursor:pointer}.emoji-pack-tab.is-active{background:#2563eb;color:#fff}.emoji-grid{flex:1 1 auto;min-width:0;min-height:0;width:100%;display:grid;grid-template-columns:repeat(auto-fill,minmax(52px,1fr));gap:6px;justify-items:center;overflow-x:hidden;overflow-y:auto;overscroll-behavior:contain}.emoji-option{width:52px;max-width:100%;height:52px;object-fit:contain;cursor:pointer;border-radius:5px}.emoji-option:hover{background:#f1f5f9}

/* 桌面端采用 QQ 式独立聊天窗口，消息区滚动，标题栏和输入栏固定在窗口内。 */
@media (min-width: 769px) {
  html body.chat-window-shell.factory-workbench-page {
    height: 100vh;
    min-height: 0;
    padding: 0 24px 24px 204px !important;
    overflow: hidden;
    background: #e9edf3;
  }
  .chat-window-shell #chatView {
    width: min(720px, calc(75vh - 48px), 100%);
    height: auto;
    aspect-ratio: 3 / 4;
    min-height: 0;
    max-height: calc(100vh - 64px);
    margin-top: 40px;
    margin: 0 auto;
    display: flex;
    flex-direction: column;
    overflow: hidden;
    background: #f5f7fb;
    border: 1px solid #d7dde6;
    border-radius: 10px;
    box-shadow: 0 12px 32px rgba(15, 23, 42, .14);
  }
  .chat-window-shell #chatView .sticky-header {
    position: relative;
    top: auto;
    flex: 0 0 52px;
    box-shadow: 0 1px 0 rgba(15, 23, 42, .04);
  }
  .chat-window-shell #chatView .thread-main {
    height: auto;
    flex: 1 1 auto;
    min-height: 0;
    position: relative;
    overflow: hidden;
  }
  .chat-window-shell #chatView .chat-thread {
    padding: 14px 18px 10px;
  }
  .chat-window-shell #chatView .composer {
    flex: 0 0 68px;
    margin: 0 -14px;
    padding: 12px 18px;
    position: relative;
    z-index: 21;
  }
  /* PC QQ 式窗口：表情栏嵌入聊天框宽度，贴在输入栏上方，不溢出到工作台整页。 */
  .chat-window-shell #chatView .emoji-panel {
    left: 0;
    right: 0;
    bottom: 68px;
    width: auto;
    max-width: none;
    margin: 0;
    border-radius: 0;
    border-left: 0;
    border-right: 0;
    border-bottom: 0;
    box-shadow: 0 -6px 18px rgba(15, 23, 42, .08);
    max-height: min(280px, 46%);
  }
}
