/* 重置和基础样式 */
* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
    -webkit-tap-highlight-color: transparent;
}

body {
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, 'Helvetica Neue', Arial, sans-serif;
    background: #f5f5f5;
    color: #333;
    height: 100vh;
    overflow: hidden;
    position: fixed;
    width: 100%;
    touch-action: manipulation;
}

/* 顶部工具栏 */
.top-bar {
    background: linear-gradient(135deg, #6a11cb 0%, #2575fc 100%);
    color: white;
    padding: 12px 16px;
    display: flex;
    justify-content: space-between;
    align-items: center;
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    height: 60px;
    z-index: 1000;
    box-shadow: 0 2px 10px rgba(0, 0, 0, 0.1);
}

.top-bar-left {
    display: flex;
    align-items: center;
    gap: 12px;
}

.menu-btn {
    background: none;
    border: none;
    color: white;
    font-size: 20px;
    width: 40px;
    height: 40px;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    transition: background 0.2s;
}

.menu-btn:active {
    background: rgba(255, 255, 255, 0.1);
}

.app-title {
    display: flex;
    align-items: center;
    gap: 8px;
    font-size: 18px;
    font-weight: 600;
}

.top-bar-right {
    display: flex;
    align-items: center;
    gap: 10px;
}

.online-badge {
    background: rgba(255, 255, 255, 0.2);
    padding: 6px 12px;
    border-radius: 20px;
    display: flex;
    align-items: center;
    gap: 6px;
    font-size: 14px;
}

.icon-btn {
    background: none;
    border: none;
    color: white;
    font-size: 20px;
    width: 40px;
    height: 40px;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    transition: background 0.2s;
}

.icon-btn:active {
    background: rgba(255, 255, 255, 0.1);
}

/* 侧边菜单 */
.side-menu {
    position: fixed;
    top: 0;
    left: -100%;
    width: 85%;
    max-width: 300px;
    height: 100%;
    background: white;
    z-index: 2000;
    transition: left 0.3s ease;
    display: flex;
    flex-direction: column;
    box-shadow: 2px 0 15px rgba(0, 0, 0, 0.1);
}

.side-menu.active {
    left: 0;
}

.menu-header {
    background: linear-gradient(135deg, #6a11cb 0%, #2575fc 100%);
    color: white;
    padding: 20px 16px;
    position: relative;
}

.user-avatar {
    width: 70px;
    height: 70px;
    background: rgba(255, 255, 255, 0.2);
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 36px;
    margin: 0 auto 15px;
}

.user-info {
    text-align: center;
}

.username-input {
    width: 100%;
    padding: 12px;
    border: none;
    border-radius: 8px;
    font-size: 16px;
    text-align: center;
    margin-bottom: 8px;
    background: rgba(255, 255, 255, 0.9);
}

.user-id {
    font-size: 13px;
    opacity: 0.9;
    word-break: break-all;
    padding: 0 10px;
}

.close-menu {
    position: absolute;
    top: 10px;
    right: 10px;
    background: none;
    border: none;
    color: white;
    font-size: 20px;
    width: 40px;
    height: 40px;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
}

.menu-section {
    padding: 20px 16px;
    border-bottom: 1px solid #eee;
}

.menu-section h3 {
    display: flex;
    align-items: center;
    gap: 10px;
    margin-bottom: 15px;
    color: #555;
    font-size: 16px;
}

.upload-options {
    display: grid;
    grid-template-columns: repeat(2, 1fr);
    gap: 10px;
    margin-bottom: 15px;
}

.menu-option {
    background: #f8f9fa;
    border: 2px solid #e9ecef;
    border-radius: 10px;
    padding: 15px 10px;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 8px;
    cursor: pointer;
    transition: all 0.2s;
}

.menu-option:active {
    background: #e9ecef;
    transform: scale(0.98);
}

.menu-option i {
    font-size: 24px;
    color: #6a11cb;
}

.menu-option span {
    font-size: 13px;
    color: #555;
}

.upload-area {
    background: #f8f9fa;
    border: 2px dashed #dee2e6;
    border-radius: 10px;
    padding: 30px 20px;
    text-align: center;
    cursor: pointer;
    transition: border-color 0.2s;
}

.upload-area.active {
    border-color: #6a11cb;
    background: #f0f4ff;
}

.upload-area i {
    font-size: 32px;
    color: #6a11cb;
    margin-bottom: 10px;
}

.upload-area p {
    color: #666;
    margin: 5px 0;
}

.upload-area .small {
    font-size: 12px;
    color: #888;
}

.instructions {
    padding: 0 5px;
}

.instructions p {
    display: flex;
    align-items: center;
    gap: 10px;
    margin-bottom: 10px;
    font-size: 14px;
    color: #666;
}

.instructions i {
    color: #28a745;
}

.menu-footer {
    padding: 20px 16px;
    margin-top: auto;
}

.btn-clear {
    width: 100%;
    padding: 15px;
    background: #ff6b6b;
    color: white;
    border: none;
    border-radius: 10px;
    font-size: 16px;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 10px;
    cursor: pointer;
    transition: background 0.2s;
}

.btn-clear:active {
    background: #ff5252;
}

/* 消息容器 */
.messages-container {
    padding: 70px 16px 150px;
    height: 90vh;
    overflow-y: auto;
    -webkit-overflow-scrolling: touch;
    display: flex;
    flex-direction: column;
    gap: 12px;
}

/* 消息样式 */
.message {
    max-width: 85%;
    padding: 12px 16px;
    border-radius: 18px;
    position: relative;
    word-wrap: break-word;
    animation: messageAppear 0.3s ease;
    box-shadow: 0 1px 2px rgba(0, 0, 0, 0.1);
}

@keyframes messageAppear {
    from {
        opacity: 0;
        transform: translateY(10px);
    }
    to {
        opacity: 1;
        transform: translateY(0);
    }
}

.message.user {
    background: linear-gradient(135deg, #6a11cb 0%, #2575fc 100%);
    color: white;
    align-self: flex-end;
    border-bottom-right-radius: 5px;
}

.message.other {
    background: white;
    align-self: flex-start;
    border-bottom-left-radius: 5px;
}

.message.system {
    background: #fff3cd;
    color: #856404;
    align-self: center;
    text-align: center;
    max-width: 90%;
    font-size: 14px;
    padding: 8px 16px;
    border-radius: 10px;
}

.message.system.success {
    background: #d4edda;
    color: #155724;
}

.message.system.error {
    background: #f8d7da;
    color: #721c24;
}

.message.system.info {
    background: #d1ecf1;
    color: #0c5460;
}

.message-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 5px;
}

.message-sender {
    font-weight: 600;
    font-size: 14px;
}

.message-time {
    font-size: 12px;
    opacity: 0.8;
}

.message-content {
    line-height: 1.4;
    font-size: 16px;
}

.message-content a {
    color: inherit;
    text-decoration: underline;
}

/* 图片消息 */
.message-image {
    margin-top: 8px;
    border-radius: 10px;
    overflow: hidden;
    max-width: 250px;
}

.message-image img {
    width: 100%;
    height: auto;
    display: block;
    cursor: pointer;
    transition: transform 0.3s;
}

.message-image img:active {
    transform: scale(0.98);
}

/* 文件消息 */
.message-file {
    margin-top: 8px;
    background: rgba(255, 255, 255, 0.2);
    border-radius: 10px;
    padding: 12px;
    display: flex;
    align-items: center;
    gap: 12px;
    max-width: 250px;
}

.file-icon {
    font-size: 24px;
    color: inherit;
}

.file-info {
    flex: 1;
    min-width: 0;
}

.file-name {
    font-weight: 600;
    font-size: 14px;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.file-size {
    font-size: 12px;
    opacity: 0.8;
}

.file-download {
    color: inherit;
    text-decoration: none;
    font-size: 20px;
}

/* 底部输入栏 */
.input-container {
    position: fixed;
    bottom: 0;
    left: 0;
    right: 0;
    background: black;
    padding: 10px 16px;
    border-top: 1px solid #e9ecef;
    box-shadow: 0 -2px 10px rgba(0, 0, 0, 0.1);
    z-index: 1000;
}

.input-wrapper {
    display: flex;
    align-items: center;
    gap: 10px;
    margin-bottom: 10px;
}

.input-action-btn {
    width: 44px;
    height: 44px;
    border-radius: 50%;
    border: none;
    background: #f8f9fa;
    color: #666;
    font-size: 20px;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    flex-shrink: 0;
}

.input-action-btn:active {
    background: #e9ecef;
}

.voice-btn {
    background: linear-gradient(135deg, #6a11cb 0%, #2575fc 100%);
    color: white;
}

.message-input-wrapper {
    flex: 1;
}

.message-input {
    width: 100%;
    padding: 12px 16px;
    border: 2px solid #e9ecef;
    border-radius: 22px;
    font-size: 16px;
    background: #f8f9fa;
    transition: border-color 0.2s;
}

.message-input:focus {
    outline: none;
    border-color: #6a11cb;
    background: white;
}

.input-hint {
    font-size: 12px;
    color: #888;
    text-align: center;
    margin-top: 4px;
    display: none;
}

.send-btn {
    width: 44px;
    height: 44px;
    border-radius: 50%;
    border: none;
    background: linear-gradient(135deg, #6a11cb 0%, #2575fc 100%);
    color: white;
    font-size: 20px;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    flex-shrink: 0;
}

.send-btn:active {
    transform: scale(0.95);
}

.quick-actions {
    display: flex;
    gap: 8px;
    overflow-x: auto;
    padding-bottom: 5px;
    -webkit-overflow-scrolling: touch;
}

.quick-action-btn {
    padding: 8px 12px;
    border: 1px solid #e9ecef;
    border-radius: 20px;
    background: white;
    font-size: 18px;
    cursor: pointer;
    flex-shrink: 0;
    transition: all 0.2s;
}

.quick-action-btn:active {
    background: #f8f9fa;
    transform: scale(0.95);
}

/* 上传预览 */
.upload-preview {
    position: fixed;
    bottom: 80px;
    left: 0;
    right: 0;
    background: white;
    border-radius: 20px 20px 0 0;
    box-shadow: 0 -2px 20px rgba(0, 0, 0, 0.15);
    z-index: 1500;
    transform: translateY(100%);
    transition: transform 0.3s ease;
    max-height: 60vh;
    display: flex;
    flex-direction: column;
}

.upload-preview.active {
    transform: translateY(0);
}

.preview-header {
    padding: 16px;
    border-bottom: 1px solid #e9ecef;
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.preview-header h4 {
    font-size: 16px;
    color: #333;
}

.close-preview {
    background: none;
    border: none;
    color: #666;
    font-size: 20px;
    width: 40px;
    height: 40px;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
}

.preview-list {
    flex: 1;
    overflow-y: auto;
    padding: 16px;
    -webkit-overflow-scrolling: touch;
}

.preview-item {
    background: #f8f9fa;
    border-radius: 12px;
    padding: 12px;
    margin-bottom: 10px;
    display: flex;
    align-items: center;
    justify-content: space-between;
}

.preview-info {
    display: flex;
    align-items: center;
    gap: 12px;
    flex: 1;
    min-width: 0;
}

.preview-icon {
    font-size: 24px;
    color: #6a11cb;
    flex-shrink: 0;
}

.preview-text {
    min-width: 0;
}

.preview-name {
    font-weight: 600;
    font-size: 14px;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.preview-size {
    font-size: 12px;
    color: #666;
}

.preview-remove {
    background: none;
    border: none;
    color: #ff6b6b;
    font-size: 18px;
    width: 40px;
    height: 40px;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    flex-shrink: 0;
}

.preview-actions {
    padding: 16px;
    border-top: 1px solid #e9ecef;
    display: flex;
    gap: 10px;
}

.btn-cancel {
    flex: 1;
    padding: 14px;
    background: #f8f9fa;
    color: #666;
    border: 2px solid #e9ecef;
    border-radius: 12px;
    font-size: 16px;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    cursor: pointer;
    transition: all 0.2s;
}

.btn-cancel:active {
    background: #e9ecef;
}

.btn-send {
    flex: 1;
    padding: 14px;
    background: linear-gradient(135deg, #6a11cb 0%, #2575fc 100%);
    color: white;
    border: none;
    border-radius: 12px;
    font-size: 16px;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    cursor: pointer;
    transition: transform 0.2s;
}

.btn-send:active {
    transform: scale(0.98);
}

/* 图片模态框 */
.image-modal {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(0, 0, 0, 0.95);
    z-index: 3000;
    display: none;
    align-items: center;
    justify-content: center;
}

.image-modal.active {
    display: flex;
}

.modal-content {
    position: relative;
    width: 100%;
    height: 100%;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
}

.modal-close {
    position: absolute;
    top: 20px;
    right: 20px;
    background: rgba(255, 255, 255, 0.1);
    border: none;
    color: white;
    font-size: 24px;
    width: 50px;
    height: 50px;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    z-index: 1;
}

#modalImage {
    max-width: 100%;
    max-height: 70%;
    object-fit: contain;
}

.modal-actions {
    position: absolute;
    bottom: 40px;
    left: 20px;
    right: 20px;
    display: flex;
    gap: 10px;
}

.modal-action-btn {
    flex: 1;
    padding: 16px;
    background: rgba(255, 255, 255, 0.1);
    backdrop-filter: blur(10px);
    color: white;
    border: none;
    border-radius: 12px;
    font-size: 16px;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    cursor: pointer;
    transition: background 0.2s;
}

.modal-action-btn:active {
    background: rgba(255, 255, 255, 0.2);
}

/* 连接状态 */
.connection-status {
    position: fixed;
    top: 70px;
    left: 50%;
    transform: translateX(-50%);
    background: rgba(0, 0, 0, 0.8);
    color: white;
    padding: 10px 20px;
    border-radius: 25px;
    font-size: 14px;
    display: flex;
    align-items: center;
    gap: 8px;
    z-index: 1000;
    animation: slideDown 0.3s ease;
}

@keyframes slideDown {
    from {
        transform: translate(-50%, -20px);
        opacity: 0;
    }
    to {
        transform: translate(-50%, 0);
        opacity: 1;
    }
}

.status-content {
    display: flex;
    align-items: center;
    gap: 8px;
}

/* 通知 */
.notification {
    position: fixed;
    top: 70px;
    left: 50%;
    transform: translateX(-50%);
    background: white;
    color: #333;
    padding: 12px 20px;
    border-radius: 12px;
    font-size: 14px;
    box-shadow: 0 4px 15px rgba(0, 0, 0, 0.1);
    z-index: 1000;
    animation: slideDown 0.3s ease;
    display: none;
}

.notification-content {
    display: flex;
    align-items: center;
    gap: 10px;
}

.notification-content i {
    color: #6a11cb;
}

/* 触摸优化 */
@media (hover: none) and (pointer: coarse) {
    .menu-option:hover,
    .btn-clear:hover,
    .quick-action-btn:hover,
    .input-action-btn:hover,
    .send-btn:hover {
        background: initial;
    }
    
    .menu-option:active,
    .btn-clear:active,
    .quick-action-btn:active,
    .input-action-btn:active,
    .send-btn:active {
        background: #e9ecef;
        transform: scale(0.98);
    }
}

/* 适配不同屏幕尺寸 */
@media (max-width: 360px) {
    .app-title span {
        display: none;
    }
    
    .message {
        max-width: 90%;
    }
    
    .upload-options {
        grid-template-columns: 1fr;
    }
}

/* 适配全面屏手机 */
@supports (padding-top: env(safe-area-inset-top)) {
    .top-bar {
        padding-top: calc(12px + env(safe-area-inset-top));
        padding-bottom: 12px;
        height: calc(60px + env(safe-area-inset-top));
    }
    
    .messages-container {
        padding-top: calc(70px + env(safe-area-inset-top));
    }
    
    .input-container {
        padding-bottom: calc(10px + env(safe-area-inset-bottom));
    }
    
    .upload-preview {
        bottom: calc(80px + env(safe-area-inset-bottom));
    }
}

/* 滚动条优化 */
::-webkit-scrollbar {
    width: 6px;
    height: 6px;
}

::-webkit-scrollbar-track {
    background: #f1f1f1;
    border-radius: 3px;
}

::-webkit-scrollbar-thumb {
    background: #c1c1c1;
    border-radius: 3px;
}

::-webkit-scrollbar-thumb:hover {
    background: #a8a8a8;
}

/* 长按复制 */
.message:active {
    opacity: 0.9;
}