/* ================= 全局重置 ================= */
* { box-sizing: border-box; margin: 0; padding: 0; -webkit-tap-highlight-color: transparent; outline: none; }
body, html {
    height: 100%; width: 100%;
    background-color: #f2f2f7; /* iOS 默认背景灰 */
    font-family: -apple-system, BlinkMacSystemFont, "SF Pro Text", "Helvetica Neue", Helvetica, Arial, sans-serif;
    overflow: hidden;
    color: #333;
}

/* ================= 容器布局 ================= */
.chat-container {
    height: 100%;
    display: flex;
    flex-direction: column;
    max-width: 600px;
    margin: 0 auto;
    background-color: #f2f2f7;
    position: relative;
    box-shadow: 0 0 20px rgba(0,0,0,0.05);
}

/* ================= 顶部导航 ================= */
.chat-header {
    height: 54px;
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 0 16px;
    background: rgba(255, 255, 255, 0.95);
    backdrop-filter: blur(10px);
    border-bottom: 1px solid rgba(0,0,0,0.05);
    flex-shrink: 0;
    z-index: 100;
}

.header-left { display: flex; flex-direction: column; justify-content: center; }
.header-left h3 { font-size: 17px; font-weight: 600; color: #000; margin-bottom: 2px; letter-spacing: -0.5px; }

.status-badge { display: flex; align-items: center; gap: 6px; font-size: 11px; font-weight: 400; opacity: 0.8; }
.status-badge.connecting { color: #faad14; }
.status-badge.online { color: #34c759; }
.status-dot {
    width: 8px; height: 8px; border-radius: 50%;
    background-color: currentColor;
    box-shadow: 0 0 0 1px rgba(255,255,255,0.5);
}
.status-badge.online .status-dot { animation: pulse 2s infinite; }
@keyframes pulse {
    0% { transform: scale(0.95); opacity: 0.7; }
    50% { transform: scale(1.1); opacity: 1; box-shadow: 0 0 4px currentColor; }
    100% { transform: scale(0.95); opacity: 0.7; }
}

.close-btn {
    background: rgba(0,0,0,0.05);
    color: #333;
    border: none;
    padding: 6px 14px;
    border-radius: 16px;
    font-size: 13px;
    font-weight: 500;
    transition: all 0.2s;
}
.close-btn:active { background: rgba(0,0,0,0.1); transform: scale(0.96); }

/* ================= 消息列表 ================= */
.chat-messages {
    flex: 1;
    overflow-y: auto;
    padding: 20px 16px;
    display: flex;
    flex-direction: column;
    gap: 20px;
    -webkit-overflow-scrolling: touch;
}

.message-item { width: 100%; display: flex; margin-bottom: 0; }
.right-align { justify-content: flex-end; }
.left-align { justify-content: flex-start; }

.avatar {
    width: 36px; height: 36px; border-radius: 8px;
    display: flex; align-items: center; justify-content: center;
    font-size: 12px; color: #fff; flex-shrink: 0;
    font-weight: bold;
}
.user-avatar { background: linear-gradient(135deg, #007aff, #005ecb); margin-left: 10px; box-shadow: 0 2px 6px rgba(0,122,255,0.2); }
.agent-avatar {
    width: 40px;
    height: 40px;
    border-radius: 5px;
    margin-right: 10px;
    flex-shrink: 0;
    overflow: hidden;
    border: none;
    background: none;
}


.agent-avatar img { width: 100%; height: 100%; border-radius: 8px; }

.message-body { max-width: 78%; display: flex; flex-direction: column; }
.right-align .message-body { align-items: flex-end; }
.left-align .message-body { align-items: flex-start; }

.bubble {
    padding: 10px 14px;
    border-radius: 12px;
    font-size: 16px;
    line-height: 1.5;
    word-break: break-all;
    position: relative;
    box-shadow: 0 1px 2px rgba(0,0,0,0.02);
    user-select: text; -webkit-user-select: text;
}

.user-bubble {
    background: #007aff;
    color: #fff;
    border-bottom-right-radius: 4px;
    box-shadow: 0 4px 10px rgba(0,122,255,0.15);
}
.user-bubble a { color: #fff; text-decoration: underline; }

.agent-bubble {
    background: #fff;
    color: #333;
    border-bottom-left-radius: 4px;
    box-shadow: 0 2px 8px rgba(0,0,0,0.04);
}

.rich-text { white-space: pre-wrap; font-size: 15px; }
.rich-text p { margin: 0; padding: 0; }
.rich-text img { max-width: 100%; border-radius: 6px; display: block; margin: 5px 0; cursor: pointer; }

.bubble.is-image { padding: 0; background: transparent; box-shadow: none; }
.bubble.is-image img {
    border-radius: 12px;
    border: 1px solid rgba(0,0,0,0.05);
    max-width: 100%;
    display: block;
    min-width: 60px; min-height: 60px;
    background: #e5e5e5;
    transition: transform 0.2s;
}
.bubble.is-image img:active { transform: scale(0.98); opacity: 0.9; }

.meta-row { display: flex; align-items: center; gap: 6px; margin-top: 4px; padding: 0 2px; opacity: 0.8; }
.time-text { font-size: 10px; color: #999; }
.status-text { font-size: 10px; font-weight: 500; }
.status-text.unread { color: #007aff; }
.status-text.read { color: #b0b0b0; }
.status-text.error { color: #ff3b30; }

.system-msg { width: 100%; text-align: center; margin: 15px 0; }
.system-msg span {
    background: rgba(0,0,0,0.04);
    color: #8e8e93;
    font-size: 12px;
    padding: 4px 12px;
    border-radius: 4px;
}
.notice-bar {
    text-align: center; font-size: 13px; padding: 8px 16px;
    background: #fff; color: #8e8e93;
    border-radius: 20px; align-self: center; margin: 10px 0;
    box-shadow: 0 2px 8px rgba(0,0,0,0.03);
    width: fit-content;
}
.notice-bar.warning { background: #fff4f2; color: #ff3b30; }

/* ================= 底部输入区 ================= */
.chat-footer {
    background: #f9f9f9;
    border-top: 1px solid rgba(0,0,0,0.08);
    /* 1. 保底高度：针对不支持 env 的普通老安卓机 */
    padding: 10px 12px 45px;
    /* 2. 针对旧版 iOS (iOS 11.0-11.2) */
    padding-bottom: calc(45px + constant(safe-area-inset-bottom));
    /* 3. 针对现代全面屏 (iOS 11.2+, Android 10+) */
    padding-bottom: calc(45px + env(safe-area-inset-bottom));
    flex-shrink: 0;
    backdrop-filter: blur(20px);
}

.toolbar { display: flex; gap: 20px; margin-bottom: 10px; padding-left: 8px; }
.tool-btn {
    width: 28px; height: 28px; cursor: pointer;
    transition: opacity 0.2s;
}
.tool-btn:active { opacity: 0.5; }
.tool-btn svg path { fill: #5c5c5c; }

.input-row { display: flex; align-items: flex-end; gap: 10px; }
textarea {
    flex: 1;
    background: #fff;
    border: 1px solid rgba(0,0,0,0.05);
    border-radius: 18px;
    padding: 10px 14px;
    font-size: 16px;
    resize: none;
    max-height: 120px;
    line-height: 1.4;
    box-shadow: 0 1px 3px rgba(0,0,0,0.02);
    -webkit-appearance: none;
    /* 【核心修复】隐藏滚动条 */
    scrollbar-width: none; /* Firefox */
}
/* 【核心修复】隐藏滚动条 Webkit */
textarea::-webkit-scrollbar { display: none; }
textarea:focus { border-color: #007aff; }

.send-btn {
    background: #007aff;
    color: #fff;
    border: none;
    border-radius: 18px;
    padding: 0 16px;
    height: 38px;
    font-size: 15px;
    font-weight: 600;
    transition: all 0.2s;
    box-shadow: 0 2px 6px rgba(0,122,255,0.3);
}
.send-btn:disabled { opacity: 0.5; box-shadow: none; background: #b0b0b0; }
.send-btn:not(:disabled):active { transform: scale(0.96); }

.safe-area-bottom {
    /* 即使系统返回 0，也至少保持 10px 的高度 */
    height: max(10px, env(safe-area-inset-bottom));
    width: 100%;
    background: #f9f9f9;
}

/* ================= 弹窗美化 ================= */
.layui-m-layerchild {
    border-radius: 16px !important;
    background-color: rgba(255,255,255,0.95) !important;
    backdrop-filter: blur(10px) !important;
    box-shadow: 0 10px 40px rgba(0,0,0,0.2) !important;
}
.layui-m-layercont {
    padding: 25px 20px !important;
    font-size: 16px !important;
    color: #333 !important;
    line-height: 1.5 !important;
    font-weight: 500 !important;
}
.layui-m-layerbtn {
    border-top: 1px solid rgba(0,0,0,0.1) !important;
    height: 50px !important; line-height: 50px !important;
    background: transparent !important;
}
.layui-m-layerbtn span {
    font-size: 17px !important;
    font-family: -apple-system, sans-serif !important;
}
.layui-m-layerbtn span[no] {
    color: #007aff !important;
    border-right: 1px solid rgba(0,0,0,0.1) !important;
    font-weight: 400 !important;
}
.layui-m-layerbtn span[yes] {
    color: #ff3b30 !important;
    font-weight: 600 !important;
}

.preset-list {
    max-height: 60vh;
    overflow-y: auto;
    background: #fff;
    border-radius: 20px 20px 0 0;
}
.preset-item {
    padding: 16px 20px;
    border-bottom: 1px solid #f5f5f5;
    color: #333;
    font-size: 15px;
    display: flex;
    justify-content: space-between;
    align-items: center;
    transition: background 0.2s;
}
.preset-item span:first-child { font-weight: 500; }
.preset-item:active { background: #f2f2f7; }

/* 【新增】图片预览关闭按钮样式 */
.img-preview-close {
    position: fixed;
    top: 30px;
    right: 20px;
    width: 40px;
    height: 40px;
    background: rgba(0,0,0,0.5);
    border-radius: 50%;
    color: white;
    font-size: 24px;
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 99999999;
    cursor: pointer;
    border: 1px solid rgba(255,255,255,0.3);
}

/* 强制开启气泡内的文本选择复制 */
.chat-messages, .bubble, .rich-text {
    -webkit-user-select: text !important;
    -moz-user-select: text !important;
    -ms-user-select: text !important;
    user-select: text !important;
    -webkit-touch-callout: default !important;
    cursor: text;
}