* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

body {
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
    background: #ededed;
    height: 100vh;
    height: 100dvh; /* 动态视口高度 */
    overflow: hidden;
    margin: 0;
    padding: 0;
}

/* 登录页面样式 */
.login-container {
    display: flex;
    justify-content: center;
    align-items: center;
    height: 100vh;
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
}

.login-box {
    background: white;
    padding: 40px;
    border-radius: 10px;
    box-shadow: 0 10px 40px rgba(0, 0, 0, 0.2);
    width: 100%;
    max-width: 400px;
}

.login-box h1 {
    text-align: center;
    color: #333;
    margin-bottom: 30px;
    font-size: 28px;
}

.form-group {
    margin-bottom: 20px;
}

.form-group input {
    width: 100%;
    padding: 12px;
    border: 1px solid #ddd;
    border-radius: 5px;
    font-size: 16px;
    transition: border-color 0.3s;
}

.form-group input:focus {
    outline: none;
    border-color: #667eea;
}

.login-btn {
    width: 100%;
    padding: 12px;
    background: #07c160;
    color: white;
    border: none;
    border-radius: 5px;
    font-size: 16px;
    cursor: pointer;
    transition: background 0.3s;
}

.login-btn:hover {
    background: #06ad56;
}

.error-message {
    color: #ff3b30;
    margin-top: 10px;
    text-align: center;
    font-size: 14px;
    min-height: 20px;
}

.login-hint {
    margin-top: 20px;
    padding: 15px;
    background: #f5f5f5;
    border-radius: 5px;
    font-size: 14px;
    color: #666;
    text-align: center;
}

.login-hint p {
    margin: 5px 0;
}

/* 聊天页面样式 */
.chat-container {
    display: flex;
    flex-direction: column;
    height: 100vh;
    height: 100dvh; /* 动态视口高度，考虑移动端浏览器UI */
    background: #ededed;
    position: relative;
    overflow: hidden;
}

.chat-header {
    background: #2e2e2e;
    color: white;
    padding: 15px 20px;
    padding-top: max(15px, env(safe-area-inset-top)); /* iOS安全区域 */
    display: flex;
    justify-content: space-between;
    align-items: center;
    box-shadow: 0 2px 5px rgba(0, 0, 0, 0.1);
    position: relative;
    z-index: 1000;
    flex-shrink: 0;
    min-height: 60px;
}

.chat-header h2 {
    font-size: 18px;
    font-weight: 500;
}

.user-info {
    display: flex;
    align-items: center;
    gap: 15px;
}

.username-link {
    color: #95ec69;
    text-decoration: underline;
    cursor: pointer;
    transition: opacity 0.2s;
}

.username-link:hover {
    opacity: 0.8;
}

.username-link:active {
    opacity: 0.6;
}

.logout-btn {
    padding: 6px 15px;
    background: #ff3b30;
    color: white;
    border: none;
    border-radius: 4px;
    cursor: pointer;
    font-size: 14px;
}

.logout-btn:hover {
    background: #ff2d20;
}

.chat-main {
    flex: 1;
    overflow-y: auto;
    padding: 20px;
}

.messages-container {
    max-width: 800px;
    margin: 0 auto;
}

.message {
    margin-bottom: 15px;
    display: flex;
    align-items: flex-start;
    animation: fadeIn 0.3s;
    transition: opacity 0.3s, transform 0.3s;
    cursor: pointer;
    user-select: none;
    -webkit-user-select: none;
}

.message.own {
    cursor: pointer;
}

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

.message.own {
    flex-direction: row-reverse;
}

.message-avatar {
    width: 40px;
    height: 40px;
    min-width: 40px;
    min-height: 40px;
    border-radius: 50%;
    background: #07c160;
    display: block;
    color: white;
    font-weight: bold;
    flex-shrink: 0;
    margin: 0 10px;
    cursor: pointer;
    transition: transform 0.2s, box-shadow 0.2s;
    border: 2px solid transparent;
    position: relative;
    background-size: 100% 100%;
    background-position: center center;
    background-repeat: no-repeat;
    overflow: hidden;
    text-align: center;
    line-height: 40px;
}

.message-avatar:hover {
    transform: scale(1.1);
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.2);
}

.message-avatar:active {
    transform: scale(0.95);
}

/* 头像预览模态框 */
.avatar-modal {
    display: none;
    position: fixed;
    z-index: 10000;
    left: 0;
    top: 0;
    width: 100%;
    height: 100%;
    background-color: rgba(0, 0, 0, 0.8);
    justify-content: center;
    align-items: center;
    animation: fadeIn 0.3s;
}

.avatar-modal-content {
    background-color: white;
    border-radius: 12px;
    padding: 20px;
    max-width: 90%;
    max-height: 90%;
    position: relative;
    display: flex;
    flex-direction: column;
    align-items: center;
    box-shadow: 0 4px 20px rgba(0, 0, 0, 0.3);
}

.avatar-modal-close {
    position: absolute;
    top: 10px;
    right: 15px;
    color: #999;
    font-size: 28px;
    font-weight: bold;
    cursor: pointer;
    line-height: 1;
    transition: color 0.2s;
}

.avatar-modal-close:hover {
    color: #333;
}

.avatar-modal-header {
    width: 100%;
    text-align: center;
    margin-bottom: 15px;
}

.avatar-modal-header h3 {
    margin: 0;
    font-size: 18px;
    color: #333;
}

.avatar-modal-body {
    width: 100%;
    display: flex;
    justify-content: center;
    align-items: center;
    margin-bottom: 15px;
}

.avatar-modal-body img {
    max-width: 300px;
    max-height: 300px;
    width: auto;
    height: auto;
    border-radius: 50%;
    object-fit: cover;
    box-shadow: 0 2px 10px rgba(0, 0, 0, 0.2);
}

.avatar-modal-footer {
    width: 100%;
    display: flex;
    justify-content: center;
}

/* 头像裁剪模态框样式 */
.avatar-crop-modal {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0, 0, 0, 0.8);
    z-index: 2000;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 20px;
    box-sizing: border-box;
}

.avatar-crop-content {
    background: white;
    border-radius: 10px;
    width: 100%;
    max-width: 500px;
    max-height: 90vh;
    display: flex;
    flex-direction: column;
    overflow: hidden;
}

.avatar-crop-header {
    padding: 20px;
    border-bottom: 1px solid #eee;
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.avatar-crop-header h3 {
    margin: 0;
    font-size: 18px;
    color: #333;
}

.avatar-crop-close {
    font-size: 28px;
    color: #999;
    cursor: pointer;
    line-height: 1;
    transition: color 0.3s;
}

.avatar-crop-close:hover {
    color: #333;
}

.avatar-crop-body {
    flex: 1;
    padding: 20px;
    overflow: hidden;
    display: flex;
    flex-direction: column;
}

.crop-container {
    flex: 1;
    position: relative;
    overflow: hidden;
    background: #f5f5f5;
    border-radius: 8px;
    min-height: 300px;
    display: flex;
    align-items: center;
    justify-content: center;
}

.crop-image-wrapper {
    position: relative;
    width: 100%;
    height: 100%;
    overflow: visible;
    touch-action: none;
    user-select: none;
    min-height: 300px;
}

#cropImage {
    display: block !important;
    max-width: none;
    max-height: none;
    position: absolute;
    cursor: move;
    user-select: none;
    -webkit-user-drag: none;
    pointer-events: auto;
    opacity: 1 !important;
    visibility: visible !important;
    z-index: 1;
}

.crop-overlay {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    pointer-events: none;
    z-index: 10;
}

.crop-circle {
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    width: 200px;
    height: 200px;
    border: 3px solid #07c160;
    border-radius: 50%;
    box-shadow: 0 0 0 9999px rgba(0, 0, 0, 0.5);
    pointer-events: none;
    box-sizing: border-box;
}

.crop-tips {
    margin-top: 15px;
    text-align: center;
}

.crop-tips p {
    margin: 0;
    font-size: 14px;
    color: #666;
}

.avatar-crop-footer {
    padding: 15px 20px;
    border-top: 1px solid #eee;
    display: flex;
    gap: 10px;
    justify-content: flex-end;
}

.crop-btn {
    padding: 10px 20px;
    border: none;
    border-radius: 5px;
    font-size: 16px;
    cursor: pointer;
    transition: all 0.3s;
}

.cancel-btn {
    background: #f5f5f5;
    color: #333;
}

.cancel-btn:hover {
    background: #e0e0e0;
}

.confirm-btn {
    background: #07c160;
    color: white;
}

.confirm-btn:hover {
    background: #06ad56;
}

@media (max-width: 600px) {
    .crop-circle {
        width: 180px;
        height: 180px;
    }
    
    .avatar-crop-content {
        max-width: 100%;
        max-height: 100vh;
        border-radius: 0;
    }
}

/* 调试面板样式 */
.debug-panel {
    position: fixed;
    bottom: 20px;
    right: 20px;
    width: 300px;
    max-height: 400px;
    background: white;
    border: 2px solid #07c160;
    border-radius: 8px;
    box-shadow: 0 4px 20px rgba(0, 0, 0, 0.3);
    z-index: 10001;
    display: flex;
    flex-direction: column;
}

.debug-header {
    padding: 10px;
    background: #07c160;
    color: white;
    display: flex;
    justify-content: space-between;
    align-items: center;
    border-radius: 6px 6px 0 0;
}

.debug-header h4 {
    margin: 0;
    font-size: 14px;
}

.debug-close-btn {
    background: none;
    border: none;
    color: white;
    font-size: 20px;
    cursor: pointer;
    padding: 0;
    width: 24px;
    height: 24px;
    display: flex;
    align-items: center;
    justify-content: center;
}

.debug-content {
    padding: 10px;
    overflow-y: auto;
    max-height: 350px;
    font-size: 12px;
    font-family: monospace;
    color: #333;
    line-height: 1.4;
}

.debug-content .debug-item {
    margin-bottom: 5px;
    padding: 3px 0;
    border-bottom: 1px solid #eee;
}

.debug-content .debug-item:last-child {
    border-bottom: none;
}

.debug-btn {
    background: #f5f5f5;
    border: 1px solid #ddd;
    border-radius: 4px;
    padding: 5px 10px;
    margin-right: 10px;
    cursor: pointer;
    font-size: 16px;
}

.debug-btn:hover {
    background: #e0e0e0;
}

@media (max-width: 600px) {
    .debug-panel {
        width: calc(100% - 40px);
        max-width: 300px;
        bottom: 10px;
        right: 10px;
    }
}

.avatar-upload-btn {
    padding: 10px 20px;
    background: #07c160;
    color: white;
    border: none;
    border-radius: 6px;
    cursor: pointer;
    font-size: 14px;
    transition: background 0.2s;
}

.avatar-upload-btn:hover {
    background: #06ad56;
}

.avatar-upload-btn:active {
    background: #05994c;
}

.message-content {
    max-width: 60%;
    background: white;
    padding: 10px 15px;
    border-radius: 8px;
    box-shadow: 0 1px 2px rgba(0, 0, 0, 0.1);
    word-wrap: break-word;
}

.message.own .message-content {
    background: #95ec69;
}

.message-username {
    font-size: 12px;
    color: #999;
    margin-bottom: 5px;
}

.message-text {
    font-size: 16px;
    line-height: 1.5;
    color: #333;
}

.message-time {
    font-size: 11px;
    color: #999;
    margin-top: 5px;
    text-align: right;
    opacity: 0.7;
}

.message-image {
    max-width: 100%;
    border-radius: 5px;
    cursor: pointer;
}

.message-voice {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 10px;
    background: #f0f0f0;
    border-radius: 5px;
    cursor: pointer;
    transition: background 0.2s;
    user-select: none;
    -webkit-user-select: none;
}

.message-voice:hover {
    background: #e0e0e0;
}

.message.own .message-voice {
    background: #e8f5e0;
}

.message.own .message-voice:hover {
    background: #d8e5d0;
}

.voice-play-btn {
    width: 30px;
    height: 30px;
    border-radius: 50%;
    background: #07c160;
    border: none;
    color: white;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    pointer-events: auto;
    z-index: 10;
    position: relative;
    flex-shrink: 0;
}

.voice-text {
    flex: 1;
    font-size: 14px;
    color: #666;
}

.voice-duration {
    font-size: 12px;
    color: #999;
}

.chat-input-area {
    background: white;
    border-top: 1px solid #ddd;
    padding: 10px;
}

.input-toolbar {
    display: flex;
    gap: 10px;
    margin-bottom: 10px;
}

.tool-btn {
    width: 40px;
    height: 40px;
    border: none;
    background: #f5f5f5;
    border-radius: 5px;
    cursor: pointer;
    font-size: 20px;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: background 0.3s;
}

.tool-btn:hover {
    background: #e0e0e0;
}

.voice-send-btn {
    padding: 10px 20px;
    border: none;
    background: #07c160;
    color: white;
    border-radius: 5px;
    cursor: pointer;
    font-size: 16px;
    white-space: nowrap;
    transition: all 0.3s;
    user-select: none;
    -webkit-user-select: none;
    -moz-user-select: none;
    -ms-user-select: none;
}

.voice-send-btn:hover {
    background: #06ad56;
}

.voice-send-btn:active,
.voice-send-btn.recording {
    background: #ff3b30;
    transform: scale(0.95);
}

.input-container {
    display: flex;
    gap: 10px;
    align-items: flex-end;
}

#messageInput {
    flex: 1;
    padding: 10px;
    border: 1px solid #ddd;
    border-radius: 5px;
    font-size: 16px;
    resize: none;
    max-height: 120px;
    font-family: inherit;
}

#messageInput:focus {
    outline: none;
    border-color: #07c160;
}

.send-btn {
    padding: 10px 20px;
    background: #07c160;
    color: white;
    border: none;
    border-radius: 5px;
    cursor: pointer;
    font-size: 16px;
    white-space: nowrap;
    transition: background 0.3s;
}

.send-btn:hover {
    background: #06ad56;
}

.voice-recording {
    text-align: center;
    padding: 20px;
    background: #fff3cd;
    border-radius: 5px;
    margin-top: 10px;
}

.voice-wave {
    display: flex;
    justify-content: center;
    gap: 5px;
    margin: 10px 0;
}

.voice-wave span {
    width: 4px;
    height: 20px;
    background: #07c160;
    border-radius: 2px;
    animation: wave 1s infinite;
}

.voice-wave span:nth-child(2) {
    animation-delay: 0.1s;
}

.voice-wave span:nth-child(3) {
    animation-delay: 0.2s;
}

.voice-wave span:nth-child(4) {
    animation-delay: 0.3s;
}

.voice-wave span:nth-child(5) {
    animation-delay: 0.4s;
}

@keyframes wave {
    0%, 100% {
        transform: scaleY(0.5);
    }
    50% {
        transform: scaleY(1.5);
    }
}

.stop-btn {
    margin-top: 10px;
    padding: 8px 20px;
    background: #ff3b30;
    color: white;
    border: none;
    border-radius: 5px;
    cursor: pointer;
}

.stop-btn:hover {
    background: #ff2d20;
}

.convert-btn {
    margin-top: 10px;
    margin-left: 10px;
    padding: 8px 20px;
    background: #07c160;
    color: white;
    border: none;
    border-radius: 5px;
    cursor: pointer;
}

.convert-btn:hover {
    background: #06ad56;
}

.voice-convert-btn {
    width: 30px;
    height: 30px;
    border-radius: 50%;
    background: #f5f5f5;
    border: none;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 14px;
    transition: background 0.3s;
}

.voice-convert-btn:hover {
    background: #e0e0e0;
}

.voice-tip {
    position: fixed;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    background: rgba(0, 0, 0, 0.8);
    color: white;
    padding: 15px 30px;
    border-radius: 8px;
    font-size: 16px;
    z-index: 10000;
    pointer-events: none;
    animation: fadeInOut 2s;
}

@keyframes fadeInOut {
    0% {
        opacity: 0;
        transform: translate(-50%, -50%) scale(0.8);
    }
    20% {
        opacity: 1;
        transform: translate(-50%, -50%) scale(1);
    }
    80% {
        opacity: 1;
        transform: translate(-50%, -50%) scale(1);
    }
    100% {
        opacity: 0;
        transform: translate(-50%, -50%) scale(0.8);
    }
}

/* 滚动条样式 */
.messages-container::-webkit-scrollbar {
    width: 6px;
}

.messages-container::-webkit-scrollbar-track {
    background: #f1f1f1;
}

.messages-container::-webkit-scrollbar-thumb {
    background: #888;
    border-radius: 3px;
}

.messages-container::-webkit-scrollbar-thumb:hover {
    background: #555;
}

