* { box-sizing: border-box; margin: 0; padding: 0; -webkit-tap-highlight-color: transparent; }
html, body {
    width: 100%;
    height: 100%;
    -webkit-text-size-adjust: 100%;
    -ms-text-size-adjust: 100%;
}
body {
    background: #ededed;
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, 'Helvetica Neue', Arial, sans-serif;
    overflow: hidden;
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
}

/* iOS Safari 安全区域适配 */
@supports (padding-bottom: env(safe-area-inset-bottom)) {
    .chat-app {
        padding-bottom: env(safe-area-inset-bottom);
    }
}

.chat-app {
    max-width: 480px;
    margin: 0 auto;
    height: 100%;
    display: flex;
    flex-direction: column;
    background: #f5f5f5;
    position: relative;
}

.chat-header {
    height: 50px;
    min-height: 50px;
    background: #ffffff;
    border-bottom: 1px solid #ddd;
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 0 12px;
    flex-shrink: 0;
}

.chat-body {
    flex: 1;
    min-height: 0;
    overflow-y: auto;
    overflow-x: hidden;
    padding: 12px;
    background: #ededed;
}

.chat-footer {
    background: #f7f7f7;
    border-top: 1px solid #ddd;
    padding: 8px;
    flex-shrink: 0;
    position: relative;
    z-index: 100;
}

/* 移动端输入框固定底部 - vivo 兼容方案 */
@media (max-width: 768px) {
    .chat-app {
        padding-bottom: 56px;
    }
    
    .chat-footer {
        position: fixed;
        bottom: 0;
        left: 0;
        right: 0;
        max-width: 480px;
        margin: 0 auto;
        min-height: 56px;
        padding: 8px;
    }
}

/* iPhone 安全区域 */
@supports (padding-bottom: env(safe-area-inset-bottom)) {
    @media (max-width: 768px) {
        .chat-app {
            padding-bottom: calc(56px + env(safe-area-inset-bottom));
        }
        
        .chat-footer {
            padding-bottom: calc(8px + env(safe-area-inset-bottom));
        }
    }
}

.composer-area {
    width: 100%;
    display: flex;
    flex-direction: column;
    gap: 8px;
}

.composer-row {
    display: flex;
    gap: 8px;
    align-items: center;
}

.composer-row input[type="text"] {
    flex: 1;
    min-width: 0;
    height: 40px;
    border: 1px solid #ccc;
    border-radius: 6px;
    padding: 0 10px;
    background: #fff;
    /* 核心修复：强制 16px 防止 iOS 自动放大 */
    font-size: 16px;
}

.composer-row button {
    min-width: 64px;
    height: 40px;
    border: none;
    border-radius: 6px;
    background: #07c160;
    color: #fff;
    cursor: pointer;
    flex-shrink: 0;
    -webkit-appearance: none;
    appearance: none;
    touch-action: manipulation;
    user-select: none;
    -webkit-user-select: none;
}

.composer-row button:disabled {
    opacity: 0.6;
    cursor: not-allowed;
}

.composer-row .secondary-btn {
    background: #909399;
    font-size: 18px;
    min-width: 44px;
    padding: 0;
}

/* 待发送预览 */
.pending-preview {
    width: 100%;
    border: 1px solid #e5e7eb;
    border-radius: 12px;
    background: #ffffff;
    padding: 10px;
    box-shadow: 0 1px 4px rgba(0,0,0,.04);
}

.pending-preview-head {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 8px;
    font-size: 13px;
    color: #333;
    gap: 10px;
}

.pending-preview-head span {
    font-weight: 600;
    color: #444;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.pending-remove-btn {
    min-width: auto !important;
    height: 28px !important;
    padding: 0 10px;
    border-radius: 6px !important;
    background: #fa5151 !important;
    color: #fff !important;
    border: none;
    cursor: pointer;
    font-size: 12px;
    flex-shrink: 0;
}

.pending-preview-body {
    display: flex;
    align-items: center;
    justify-content: flex-start;
    width: 100%;
    max-width: 100%;
}

/* 多图预览横向布局 */
.pending-multi {
    display: flex;
    flex-wrap: nowrap;
    gap: 8px;
    overflow-x: auto;
    padding-bottom: 4px;
    scrollbar-width: thin;
    width: 100%;
    max-width: 100%;
}

.pending-multi::-webkit-scrollbar {
    height: 4px;
}

.pending-multi::-webkit-scrollbar-thumb {
    background: #ccc;
    border-radius: 2px;
}

.pending-item {
    position: relative;
    display: inline-block;
    flex-shrink: 0;
    width: auto;
    max-width: min(100%, 120px);
}

.pending-item-remove {
    position: absolute;
    top: -6px;
    right: -6px;
    width: 20px;
    height: 20px;
    border-radius: 50%;
    background: #fa5151;
    color: #fff;
    border: none;
    cursor: pointer;
    font-size: 14px;
    line-height: 1;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 0;
    z-index: 10;
}

.pending-item-remove:hover {
    background: #e04040;
}

/* 上传进度条 */
.upload-progress-wrap {
    width: min(420px, 100%);
    display: flex;
    align-items: center;
    gap: 8px;
    margin-top: 10px;
}

.upload-progress-bar {
    flex: 1;
    height: 8px;
    background: #e5e7eb;
    border-radius: 999px;
    overflow: hidden;
}

.upload-progress-inner {
    width: 0%;
    height: 100%;
    background: #07c160;
    transition: width .2s ease;
}

.upload-progress-text {
    width: 42px;
    font-size: 12px;
    color: #666;
    text-align: right;
}

/* 待发送预览媒体 */
.pending-image,
.pending-video {
    display: block;
    width: auto;
    max-width: min(100%, 220px);
    max-height: 150px;
    border-radius: 10px;
    background: #000;
    box-shadow: 0 1px 4px rgba(0,0,0,.08);
}

/* 聊天气泡 */
.msg-item {
    margin-bottom: 8px;
}

.msg-time {
    text-align: center;
    color: #999;
    font-size: 12px;
    margin: 10px 0 6px;
}

.msg-row {
    display: flex;
    margin-bottom: 4px;
    width: 100%;
}

.msg-row.left {
    justify-content: flex-start;
}

.msg-row.right {
    justify-content: flex-end;
}

.bubble {
    border-radius: 10px;
    line-height: 1.5;
    overflow: hidden;
}

.text-bubble {
    max-width: 72%;
    padding: 10px 12px;
    background: #fff;
    word-break: break-word;
    overflow-wrap: break-word;
}

.msg-row.right .text-bubble {
    background: #95ec69;
}

.media-bubble {
    max-width: 78%;
    padding: 6px;
    background: #fff;
}

.msg-row.right .media-bubble {
    background: #95ec69;
}

.media-wrap {
    width: 100%;
    max-width: 100%;
}

.text-wrap {
    white-space: normal;
}

.chat-image,
.chat-video {
    display: block;
    width: 100%;
    max-width: 100%;
    height: auto;
    max-height: 46vh;
    object-fit: contain;
    border-radius: 8px;
    background: #000;
}

/* 平板以下 */
@media (max-width: 768px) {
    .chat-app {
        max-width: 100%;
    }

    .chat-header {
        height: 48px;
        min-height: 48px;
        padding: 0 10px;
    }

    .chat-body {
        padding: 10px;
    }

    .chat-footer {
        padding: 8px 10px;
    }

    .composer-row {
        gap: 6px;
    }

    .composer-row button {
        min-width: 60px;
        height: 40px;
    }

    .text-bubble {
        max-width: 78%;
        padding: 10px 12px;
        /* 提升移动端阅读性 */
        font-size: 16px;
    }

    .media-bubble {
        max-width: 86%;
        padding: 5px;
    }

    .chat-image,
    .chat-video {
        max-height: 38vh;
        border-radius: 8px;
    }

    .pending-image,
    .pending-video {
        max-width: min(100%, 190px);
        max-height: 130px;
        border-radius: 10px;
    }
}

/* 手机端重点优化 */
@media (max-width: 480px) {
    .chat-footer {
        padding: 8px;
    }

    .composer-area {
        gap: 6px;
    }

    .pending-preview {
        padding: 8px;
        border-radius: 10px;
    }

    .pending-preview-head {
        margin-bottom: 6px;
        font-size: 12px;
    }

    .pending-remove-btn {
        height: 26px !important;
        padding: 0 8px;
        font-size: 12px;
    }

    .pending-image,
    .pending-video {
        max-width: 160px;
        max-height: 110px;
        border-radius: 8px;
    }

    .text-bubble {
        max-width: 82%;
    }

    .media-bubble {
        max-width: 90%;
    }

    .chat-image,
    .chat-video {
        max-height: 34vh;
    }

    .composer-row input[type="text"] {
        height: 38px;
        font-size: 16px;
    }

    .composer-row button {
        height: 38px;
        min-width: 56px;
    }
}

/* 超小屏手机 */
@media (max-width: 360px) {
    .composer-row .secondary-btn {
        min-width: 40px;
        height: 36px;
        font-size: 16px;
    }

    .composer-row input[type="text"] {
        height: 36px;
        font-size: 16px;
    }

    .composer-row button {
        height: 36px;
        min-width: 52px;
        font-size: 13px;
    }

    .chat-header {
        height: 44px;
        min-height: 44px;
    }

    .text-bubble {
        max-width: 84%;
        padding: 8px 10px;
        font-size: 14px;
    }

    .media-bubble {
        max-width: 92%;
    }
}

/* 横屏模式优化 */
@media (max-height: 500px) and (orientation: landscape) {
    .chat-header {
        height: 40px;
        min-height: 40px;
    }

    .chat-image,
    .chat-video {
        max-height: 50vh;
    }

    .pending-image,
    .pending-video {
        max-height: 80px;
    }
}