/* ==================== Reset & Base ==================== */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }
html, body { height: 100%; font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, 'Helvetica Neue', Arial, sans-serif; font-size: 14px; line-height: 1.5; color: #333; background: #f0f2f5; -webkit-text-size-adjust: 100%; }
input, textarea, button { font-family: inherit; font-size: inherit; }
.hidden { display: none !important; }
.hidden-input { position: absolute; width: 0; height: 0; opacity: 0; overflow: hidden; }

/* ==================== Layout ==================== */
.main-container { width: 100%; height: 100%; max-width: 720px; margin: 0 auto; position: relative; background: #fff; box-shadow: 0 0 24px 0 rgba(15,66,76,.25); display: flex; flex-direction: column; }

/* ==================== Loading ==================== */
.loading-overlay { position: absolute; top: 0; left: 0; right: 0; bottom: 0; background: rgba(255,255,255,.9); display: flex; align-items: center; justify-content: center; z-index: 100; }
.spinner { width: 36px; height: 36px; border: 3px solid #e0e0e0; border-top-color: #409eff; border-radius: 50%; animation: spin .8s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }

/* ==================== Error Pages ==================== */
.page { flex: 1; overflow: hidden; }
.error-page { display: flex; flex-direction: column; align-items: center; padding: 120px 20px; }
.error-code { font-size: 3rem; margin-bottom: 20px; font-weight: bold; color: #333; }
.error-title { margin-bottom: 15px; font-weight: bold; font-size: 16px; }
.error-desc { color: rgba(0,0,0,.5); }

/* ==================== Captcha ==================== */
.captcha-container { display: flex; justify-content: center; align-items: center; min-height: 100%; padding: 20px; }
.captcha-box { width: 100%; max-width: 400px; }
.captcha-input-group { display: flex; border: 1px solid #dcdfe6; border-radius: 4px; overflow: hidden; margin-bottom: 16px; }
.captcha-input-group input { flex: 1; padding: 10px 12px; border: none; outline: none; font-size: 14px; }
.captcha-image { width: 120px; height: 40px; cursor: pointer; border-left: 1px solid #dcdfe6; object-fit: cover; }
.btn-primary { background: #409eff; color: #fff; border: none; padding: 10px 20px; border-radius: 4px; cursor: pointer; font-size: 14px; transition: background .2s; }
.btn-primary:hover { background: #66b1ff; }
.btn-primary:active { background: #3a8ee6; }
.btn-full { width: 100%; }
.btn-default { background: #fff; color: #606266; border: 1px solid #dcdfe6; padding: 10px 20px; border-radius: 4px; cursor: pointer; font-size: 14px; }
.btn-default:hover { color: #409eff; border-color: #c6e2ff; }

/* ==================== Chat Layout ==================== */
#page-chat { display: flex; flex-direction: column; height: 100%; }
.chat-header { display: flex; justify-content: space-between; align-items: center; padding: 5px 10px; line-height: 40px; background: #409eff; color: #fff; flex-shrink: 0; }
.header-left { display: flex; align-items: center; }
.header-right { display: flex; align-items: center; }
.avatar { width: 30px; height: 30px; border-radius: 50%; overflow: hidden; margin-right: 8px; flex-shrink: 0; background: rgba(255,255,255,.2); display: flex; align-items: center; justify-content: center; }
.avatar img { width: 100%; height: 100%; object-fit: cover; border-radius: 50%; }
.service-name { color: #fff; font-size: 14px; white-space: nowrap; }
.typing-indicator { color: #fff; font-size: 12px; }

/* Language Dropdown */
.lang-dropdown { position: relative; cursor: pointer; color: #fff; display: flex; align-items: center; gap: 4px; padding: 4px 8px; }
.lang-menu { position: absolute; top: 100%; right: 0; background: #fff; border-radius: 4px; box-shadow: 0 2px 12px rgba(0,0,0,.12); min-width: 120px; z-index: 50; overflow: hidden; }
.lang-menu-item { padding: 8px 16px; color: #606266; cursor: pointer; white-space: nowrap; }
.lang-menu-item:hover { background: #ecf5ff; color: #409eff; }

/* Announcement */
.announcement-bar { padding: 10px 16px; text-align: center; flex-shrink: 0; box-shadow: 0 2px 8px rgba(102,126,234,.1); }
.announcement-bar span { color: #f70202; font-size: 14px; font-weight: 500; }

/* Messages Container */
.messages-container { flex: 1; overflow-y: auto; overflow-x: hidden; padding: 8px 12px 8px 4px; background: #fff; -webkit-overflow-scrolling: touch; box-sizing: border-box; }
.messages-inner { min-height: 100%; padding-bottom: 8px; }

/* ==================== Chat Bottom ==================== */
.chat-bottom { flex-shrink: 0; background: #fff; padding: 8px; border-top: none; }
.faq-bar { margin-bottom: 8px; overflow-x: auto; -webkit-overflow-scrolling: touch; }
.faq-tags { display: flex; gap: 8px; white-space: nowrap; }
.faq-tag { display: inline-block; padding: 4px 12px; border: 1px solid #dcdfe6; border-radius: 4px; color: #606266; cursor: pointer; font-size: 12px; flex-shrink: 0; transition: all .2s; }
.faq-tag:hover { color: #409eff; border-color: #409eff; }
.toolbar { display: flex; align-items: center; gap: 12px; margin-bottom: 8px; }
.tool-btn { cursor: pointer; display: flex; align-items: center; opacity: .65; transition: opacity .2s; }
.tool-btn:hover { opacity: 1; }
.input-area { display: flex; align-items: flex-end; gap: 8px; }
.input-area textarea { flex: 1; border: 1px solid #dcdfe6; border-radius: 4px; padding: 8px 12px; resize: none; outline: none; font-size: 14px; line-height: 1.5; transition: border-color .2s; }
.input-area textarea:focus { border-color: #409eff; }
.btn-send { background: #67c23a; color: #fff; border: none; padding: 0 20px; height: 52px; border-radius: 4px; cursor: pointer; font-size: 14px; white-space: nowrap; transition: background .2s; }
.btn-send:hover { background: #85ce61; }
.btn-send:active { background: #5daf34; }

/* ==================== Emoji Picker ==================== */
.emoji-picker { position: fixed; background: #fff; border: 1px solid #e4e7ed; border-radius: 4px; box-shadow: 0 2px 12px rgba(0,0,0,.12); padding: 8px; width: 305px; max-height: 200px; overflow-y: auto; z-index: 60; }
.emoji-picker span { cursor: pointer; font-size: 18px; display: inline-block; width: 28px; height: 28px; text-align: center; line-height: 28px; border-radius: 4px; }
.emoji-picker span:hover { background: #f5f7fa; }

/* ==================== Message Styles ==================== */
.msg-group { margin-bottom: 16px; }
.msg-meta { font-size: 12px; color: #b4bbc4; margin-bottom: 4px; }
.msg-meta.right { text-align: right; }
.msg-meta.left { text-align: left; }
.msg-meta .sender-name { color: #000; margin-right: 8px; }
.msg-row { display: flex; width: 100%; margin-bottom: 6px; overflow: hidden; }
.msg-row.reverse { flex-direction: row-reverse; }
.msg-content-wrapper { max-width: 85%; position: relative; }
.msg-bubble { padding: 8px; word-break: break-all; border-radius: 8px; font-size: 14px; line-height: 20px; }
.msg-bubble.customer { background: #035ad833; }
.msg-bubble.service { background: #f5f5f5; }
.msg-bubble img { max-width: 100%; vertical-align: bottom; cursor: pointer; }
.msg-bubble p { margin: 0; }
.msg-bubble a { color: #409eff; text-decoration: underline; }
.msg-bubble a:hover { opacity: 0.8; }

/* Message status indicators */
.msg-status { position: absolute; bottom: 10px; left: -25px; width: 20px; height: 20px; }
.msg-status.reverse { left: auto; right: auto; left: -25px; }
.msg-spinner { width: 16px; height: 16px; border: 2px solid #e0e0e0; border-top-color: #409eff; border-radius: 50%; animation: spin .8s linear infinite; }
.msg-error-icon { cursor: pointer; color: red; font-size: 16px; line-height: 1; }

/* Image messages */
.msg-image { border-radius: 8px; cursor: pointer; min-width: 80px; max-width: 260px; position: relative; }
.msg-image img { border-radius: 8px; max-width: 260px; min-width: 80px; display: block; }
.msg-uploading { position: relative; }
.msg-uploading::after { content: ''; position: absolute; top: 0; left: 0; right: 0; bottom: 0; background: rgba(255,255,255,0.2); border-radius: 8px; }
.msg-image-spinner { position: absolute; top: 50%; left: 50%; transform: translate(-50%,-50%); width: 24px; height: 24px; z-index: 1; }
.msg-upload-error { position: absolute; top: 50%; left: 50%; transform: translate(-50%,-50%); cursor: pointer; font-size: 32px; color: red; z-index: 1; }

/* File messages */
.msg-file { display: flex; align-items: center; padding: 12px; border-radius: 8px; cursor: pointer; gap: 8px; }
.msg-file.customer { background: #035ad833; }
.msg-file.service { background: #f5f5f5; }
.msg-file-icon { flex-shrink: 0; }
.msg-file-info { overflow: hidden; }
.msg-file-name { font-weight: bold; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; max-width: 100px; }
.msg-file-size { color: #606266; font-size: 12px; }

/* Card messages */
.msg-card img { width: 200px; height: 100px; border-radius: 8px; cursor: pointer; object-fit: cover; }

/* Question messages */
.msg-question-list { margin-top: 8px; }
.msg-question-list p { margin-bottom: 4px; color: #606266; }
.msg-question-item { color: #409eff; cursor: pointer; padding: 2px 0; display: block; }
.msg-question-item:hover { text-decoration: underline; }

/* Form messages */
.msg-form { max-width: 100%; }
.msg-form .form-group { margin-bottom: 12px; }
.msg-form label { display: block; margin-bottom: 4px; font-weight: 500; font-size: 13px; }
.msg-form input[type="text"], .msg-form input[type="number"], .msg-form input[type="datetime-local"], .msg-form select, .msg-form textarea { width: 100%; padding: 6px 8px; border: 1px solid #dcdfe6; border-radius: 4px; outline: none; font-size: 13px; }
.msg-form input:focus, .msg-form select:focus, .msg-form textarea:focus { border-color: #409eff; }
.msg-form .radio-group, .msg-form .checkbox-group { display: flex; flex-wrap: wrap; gap: 8px; }
.msg-form .radio-group label, .msg-form .checkbox-group label { font-weight: normal; display: flex; align-items: center; gap: 4px; cursor: pointer; }

/* No more history */
.no-more-history { text-align: center; font-size: 12px; color: #b4bbc4; margin-bottom: 8px; }

/* Submitted form (type 37) */
.msg-submitted-form { background: #fff; padding: 8px 12px; border-radius: 8px; width: 45%; margin: 0 auto 10px; box-shadow: 0 1px 4px rgba(0,0,0,.08); }
.msg-submitted-form .form-header { display: flex; align-items: flex-start; gap: 8px; }
.msg-submitted-form .form-check { color: #67c23a; font-size: 16px; }
.msg-submitted-form .form-detail { flex: 1; font-size: 13px; }

/* ==================== Overlays & Dialogs ==================== */
.overlay { position: fixed; top: 0; left: 0; right: 0; bottom: 0; background: rgba(0,0,0,.5); display: flex; align-items: center; justify-content: center; z-index: 200; }
.dialog { background: #fff; border-radius: 8px; max-width: 500px; width: 90%; max-height: 80vh; overflow-y: auto; }
.dialog-header { display: flex; justify-content: space-between; align-items: center; padding: 16px 20px; border-bottom: 1px solid #e4e7ed; font-size: 16px; font-weight: 600; }
.dialog-close { cursor: pointer; font-size: 24px; color: #909399; line-height: 1; }
.dialog-close:hover { color: #606266; }
.dialog-body { padding: 20px; }

/* Evaluation Dialog */
.eval-title { margin-bottom: 16px; word-break: break-all; }
.eval-item { display: flex; align-items: center; margin-bottom: 12px; }
.eval-item-label { width: 100px; flex-shrink: 0; font-size: 14px; }
.eval-stars { display: flex; gap: 4px; }
.eval-star { cursor: pointer; font-size: 20px; color: #c0c4cc; transition: color .2s; }
.eval-star.active { color: #f7ba2a; }
.eval-star-text { margin-left: 8px; font-size: 12px; color: #909399; }
.form-group { margin-bottom: 16px; }
.form-group label { display: block; margin-bottom: 4px; font-size: 14px; }
.form-group textarea { width: 100%; padding: 8px; border: 1px solid #dcdfe6; border-radius: 4px; outline: none; resize: none; }
.form-group textarea:focus { border-color: #409eff; }
.form-actions { display: flex; gap: 12px; margin-top: 16px; }

/* Image Preview */
.preview-image { max-width: 90vw; max-height: 90vh; object-fit: contain; border-radius: 4px; }

/* Card Drawer */
.card-drawer { position: fixed; bottom: 0; left: 0; right: 0; top: 0; background: #fff; z-index: 210; display: flex; flex-direction: column; }
.drawer-header { display: flex; justify-content: space-between; align-items: center; padding: 10px 20px; border-bottom: 1px solid #e4e7ed; }
.drawer-back { cursor: pointer; font-size: 20px; width: 33%; }
.drawer-header > span:nth-child(2) { width: 33%; text-align: center; font-weight: 600; }
.drawer-help { width: 33%; text-align: right; cursor: pointer; color: #409eff; }
.drawer-content { flex: 1; overflow-y: auto; padding: 8px; }
.card-payment { margin: 8px; border-radius: 8px; background: #fff; overflow: hidden; }
.card-payment-title { padding: 6px 0; font-size: 16px; font-weight: 600; text-align: center; border-bottom: 1px solid #e6e6e6; }
.card-payment-intro { margin-top: 12px; font-size: 14px; text-align: center; }
.card-info-row { display: flex; justify-content: space-between; padding: 13px; }
.card-info-label { width: 90px; font-size: 16px; flex-shrink: 0; }
.card-info-value { font-size: 14px; flex: 1; text-align: right; word-break: break-all; }
.card-info-value .copy-btn { color: #409eff; cursor: pointer; margin-left: 4px; }
.card-qr-section { padding: 10px; text-align: center; border-bottom: 1px solid #e6e6e6; }
.card-qr-section img { width: 150px; height: 150px; margin: 0 auto; display: block; }
.card-qr-section .save-hint { margin-top: 10px; color: #409eff; }
.card-qr-section .save-hint a { text-decoration: none; color: #409eff; }
.card-rich-section { padding: 10px; }
.card-rich-title { font-size: 16px; padding: 0 0 6px 0; font-weight: 600; text-align: center; border-bottom: 1px solid #e6e6e6; }
.card-rich-content { margin-top: 15px; font-size: 14px; line-height: 2; }

/* ==================== Star Rating ==================== */
.star-rating { display: inline-flex; gap: 4px; align-items: center; }
.star { cursor: pointer; font-size: 20px; color: #dcdfe6; transition: color .15s; user-select: none; }
.star.active { color: #f7ba2a; }
.star-text { margin-left: 8px; font-size: 12px; color: #909399; min-width: 30px; }

/* ==================== Toast ==================== */
.toast { position: fixed; top: 20px; left: 50%; transform: translateX(-50%); background: #303133; color: #fff; padding: 10px 20px; border-radius: 4px; font-size: 14px; z-index: 9999; opacity: 0; transition: opacity .3s; pointer-events: none; }
.toast.show { opacity: 1; }
.toast.success { background: #67c23a; }
.toast.warning { background: #e6a23c; }
.toast.error { background: #f56c6c; }
.toast.info { background: #909399; }

/* ==================== Responsive ==================== */
@media (max-width: 720px) {
  .main-container { max-width: 100%; box-shadow: none; }
}
@media (max-width: 640px) {
  .announcement-bar { padding: 8px 12px; }
  .announcement-bar span { font-size: 13px; }
  .msg-submitted-form { width: 80%; }
}
