:root {
    --safe-top: env(safe-area-inset-top);
    --safe-bottom: env(safe-area-inset-bottom);
    --pink: #ff9a9e;
    --pink-light: #fecfef;
    --text-primary: #1a1a1a;
    --text-secondary: #8e8e93;
    --bg-color: linear-gradient(180deg, #fef3f3 0%, #fef9f3 50%, #f3fef6 100%);
}

* { margin: 0; padding: 0; box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { height: 100%; overflow: hidden; overscroll-behavior: none; }
body {
    font-family: -apple-system, 'PingFang SC', 'Helvetica Neue', sans-serif;
    background: var(--bg-color);
    background-attachment: fixed;
    touch-action: manipulation;
}

#app {
    max-width: 500px;
    margin: 0 auto;
    height: 100vh;
    height: 100dvh;
    height: var(--app-height, 100dvh);
    display: flex;
    flex-direction: column;
    position: relative;
}

/* 头部 */
.header {
    padding: 12px 16px;
    padding-top: calc(12px + var(--safe-top));
    display: flex;
    align-items: center;
    gap: 12px;
    background: rgba(255,255,255,0.75);
    backdrop-filter: saturate(180%) blur(20px);
    -webkit-backdrop-filter: saturate(180%) blur(20px);
    border-bottom: 0.5px solid rgba(0,0,0,0.06);
    position: relative;
    z-index: 10;
}

.header .title {
    font-size: 16px;
    font-weight: 600;
    color: var(--text-primary);
    position: static;
    transform: none;
}

.header .status {
    font-size: 12px;
    color: #34c759;
    display: flex;
    align-items: center;
    gap: 4px;
}
.header .status::before {
    content: '';
    width: 6px;
    height: 6px;
    background: #34c759;
    border-radius: 50%;
}

/* 客服头像 */
.avatar {
    width: 42px;
    height: 42px;
    border-radius: 50%;
    object-fit: cover;
    flex-shrink: 0;
    background: linear-gradient(135deg, var(--pink) 0%, var(--pink-light) 100%);
}

/* 头部信息区 */
.header-info {
    flex: 1;
    min-width: 0;
}
.header-info .title {
    font-size: 16px;
    font-weight: 600;
    color: var(--text-primary);
}
.header-info .status {
    margin-top: 1px;
}

/* 消息列表 */
.message-list {
    flex: 1;
    overflow-y: auto;
    overflow-x: hidden;
    padding: 12px 16px;
    -webkit-overflow-scrolling: touch;
    overscroll-behavior: contain;
}

.message {
    display: flex;
    margin-bottom: 12px;
    max-width: 78%;
    flex-direction: column;
    align-items: flex-start;
}
.message.self {
    margin-left: auto;
    align-items: flex-end;
}
.message.other {
    align-items: flex-start;
}

/* 消息气泡 */
.message .bubble {
    padding: 10px 14px;
    font-size: 16px;
    line-height: 1.5;
    border-radius: 20px;
    word-break: break-word;
    max-width: 100%;
}

.message.other .bubble {
    background: #fff;
    color: var(--text-primary);
    border-bottom-left-radius: 6px;
}

.message.self .bubble {
    background: linear-gradient(135deg, var(--pink) 0%, var(--pink-light) 100%);
    color: #fff;
    border-bottom-right-radius: 6px;
}

/* 客服消息带头像 */
.message.other {
    flex-direction: row;
    align-items: flex-end;
    max-width: 85%;
}
.message.other .avatar {
    width: 36px;
    height: 36px;
    margin-right: 8px;
    flex-shrink: 0;
}
.message.other .bubble {
    max-width: calc(100% - 44px);
}

/* 图片消息 */
.msg-img {
    max-width: 200px;
    max-height: 200px;
    border-radius: 16px;
    cursor: pointer;
    display: block;
}

/* 链接消息 */
.link-msg {
    cursor: pointer;
    background: #fff !important;
    border: 1px solid rgba(0,0,0,0.06) !important;
}
.link-msg:active {
    background: #f9f9f9 !important;
}
.link-title {
    font-weight: 500;
    color: var(--text-primary);
    margin-bottom: 4px;
}
.link-desc {
    font-size: 13px;
    color: var(--text-secondary);
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    max-width: 200px;
}

/* 富文本链接 */
.msg-link {
    color: var(--pink);
    text-decoration: none;
    cursor: pointer;
    font-weight: 500;
}
.msg-link:active {
    text-decoration: underline;
}

/* 视频消息 */
.video-msg {
    position: relative;
    display: inline-block;
    cursor: pointer;
}
.video-msg .video-cover {
    width: 200px;
    height: 150px;
    object-fit: cover;
    border-radius: 16px;
}
.video-msg .video-cover-placeholder {
    width: 200px;
    height: 150px;
    background: #2D2A26;
    border-radius: 16px;
    position: relative;
}
.video-msg .video-cover-placeholder::after {
    content: '';
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-40%, -50%);
    width: 0;
    height: 0;
    border-left: 28px solid #fff;
    border-top: 18px solid transparent;
    border-bottom: 18px solid transparent;
}
.video-msg .play-icon {
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    font-size: 40px;
    color: #fff;
    text-shadow: 0 2px 8px rgba(0,0,0,0.5);
    pointer-events: none;
}

/* 快捷消息区域 */
.quick-msg {
    padding: 8px 16px;
    background: rgba(255,255,255,0.6);
    backdrop-filter: blur(10px);
    -webkit-backdrop-filter: blur(10px);
    display: flex;
    gap: 8px;
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
    scrollbar-width: none;
}
.quick-msg::-webkit-scrollbar { display: none; }
.quick-msg:empty { display: none; }

.quick-msg-btn {
    padding: 8px 14px;
    background: #fff;
    border: none;
    border-radius: 16px;
    font-size: 14px;
    color: var(--text-primary);
    white-space: nowrap;
    flex-shrink: 0;
    box-shadow: 0 1px 3px rgba(0,0,0,0.06);
    cursor: pointer;
}
.quick-msg-btn:active {
    background: #f5f5f5;
}

/* 输入区 */
.input-area {
    padding: 10px 12px;
    padding-bottom: calc(10px + var(--safe-bottom));
    background: rgba(255,255,255,0.88);
    backdrop-filter: saturate(180%) blur(20px);
    -webkit-backdrop-filter: saturate(180%) blur(20px);
    border-top: 0.5px solid rgba(0,0,0,0.06);
    display: flex;
    align-items: center;
    gap: 8px;
}

/* 上传图片按钮 */
.img-btn {
    width: 36px;
    height: 36px;
    border: none;
    border-radius: 50%;
    background: rgba(118,118,128,0.12);
    color: var(--text-secondary);
    font-size: 22px;
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
    cursor: pointer;
}
.img-btn:active {
    background: rgba(118,118,128,0.2);
}

/* 输入框容器 */
.input-wrap {
    flex: 1;
    display: flex;
    align-items: center;
    background: rgba(118,118,128,0.12);
    border-radius: 20px;
    padding: 4px;
}

#messageInput {
    flex: 1;
    min-width: 0;
    padding: 8px 12px;
    border: none;
    font-size: 16px;
    outline: none;
    background: transparent;
    color: var(--text-primary);
}
#messageInput::placeholder {
    color: var(--text-secondary);
}

/* 发送按钮 */
#sendBtn {
    width: 32px;
    height: 32px;
    border: none;
    border-radius: 50%;
    background: linear-gradient(135deg, var(--pink) 0%, var(--pink-light) 100%);
    color: #fff;
    font-size: 16px;
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
    cursor: pointer;
    margin: 0;
    padding: 0;
}
#sendBtn:active {
    opacity: 0.8;
}

/* 视频播放弹窗 */
.video-modal {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(0,0,0,0.95);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 1000;
}
.video-wrapper {
    position: relative;
    max-width: 90%;
    max-height: 90%;
}
.video-wrapper video {
    max-width: 100%;
    max-height: 80vh;
    border-radius: 12px;
}
.close-btn {
    position: absolute;
    top: -40px;
    right: 0;
    color: #fff;
    font-size: 32px;
    cursor: pointer;
    opacity: 0.8;
}
.close-btn:active { opacity: 1; }

/* 加载动画 */
.loading-spinner {
    width: 40px;
    height: 40px;
    border: 3px solid rgba(255,255,255,0.2);
    border-top-color: var(--pink);
    border-radius: 50%;
    animation: spin 1s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

.loading-content {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 16px;
}
.loading-progress {
    color: #fff;
    font-size: 18px;
    font-weight: 500;
}
.loading-cancel-btn {
    padding: 10px 30px;
    background: transparent;
    border: 2px solid rgba(255,255,255,0.6);
    border-radius: 25px;
    color: #fff;
    font-size: 16px;
    cursor: pointer;
}
.loading-cancel-btn:active {
    background: rgba(255,255,255,0.1);
    border-color: #fff;
}

/* 图片预览弹窗 */
.image-modal {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(0,0,0,0.95);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 1000;
}
.image-modal .image-wrapper {
    position: relative;
    max-width: 90%;
    max-height: 90%;
}
.image-modal img {
    max-width: 100%;
    max-height: 90vh;
    border-radius: 8px;
}

/* 小屏幕适配 */
@media (max-width: 375px) {
    .message .bubble { font-size: 15px; padding: 9px 12px; }
    .header .title { font-size: 15px; }
    .quick-msg-btn { font-size: 13px; padding: 6px 12px; }
    .message.other .avatar { width: 32px; height: 32px; }
}

/* 横屏适配 */
@media (orientation: landscape) and (max-height: 500px) {
    .header { padding: 8px 16px; padding-top: calc(8px + var(--safe-top)); }
    .header .avatar { width: 36px; height: 36px; }
    .message-list { padding: 8px 16px; }
    .message { margin-bottom: 8px; }
    .input-area { padding: 6px 12px; padding-bottom: calc(6px + var(--safe-bottom)); }
}
