/* 全局样式 */
* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

body {
    font-family: 'Segoe UI', 'Microsoft YaHei', sans-serif;
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    height: 100vh;
    display: flex;
    justify-content: center;
    align-items: center;
}

/* 页面容器 */
.page {
    width: 100%;
    height: 100%;
    display: none;
    flex-direction: column;
}

.page.active {
    display: flex;
}

/* 登录页面样式 */
.login-container {
    background: white;
    padding: 40px 35px;
    border-radius: 20px;
    box-shadow: 0 15px 35px rgba(0, 0, 0, 0.2);
    width: 90%;
    max-width: 400px;
    text-align: center;
}

.logo {
    display: flex;
    flex-direction: column;
    align-items: center;
    margin-bottom: 15px;
}

.logo i {
    font-size: 48px;
    color: #ff6b8b;
    margin-bottom: 15px;
}

.logo h1 {
    color: #333;
    font-size: 28px;
    font-weight: 600;
}

.subtitle {
    color: #666;
    font-size: 14px;
    margin-bottom: 30px;
}

#login-form {
    display: flex;
    flex-direction: column;
    gap: 20px;
}

.input-group {
    position: relative;
    display: flex;
    align-items: center;
}

.input-group i {
    position: absolute;
    left: 15px;
    color: #999;
    font-size: 18px;
}

#login-form input {
    width: 100%;
    padding: 15px 15px 15px 45px;
    border: 2px solid #e1e5e9;
    border-radius: 12px;
    font-size: 16px;
    transition: all 0.3s;
    background: #f8f9fa;
}

#login-form input:focus {
    border-color: #667eea;
    background: white;
    outline: none;
    box-shadow: 0 0 0 3px rgba(102, 126, 234, 0.1);
}

.login-btn {
    background: linear-gradient(to right, #667eea, #764ba2);
    color: white;
    border: none;
    padding: 16px;
    border-radius: 12px;
    font-size: 16px;
    font-weight: 600;
    cursor: pointer;
    transition: transform 0.2s, box-shadow 0.2s;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 10px;
}

.login-btn:hover {
    transform: translateY(-2px);
    box-shadow: 0 7px 14px rgba(102, 126, 234, 0.2);
}

.login-btn:active {
    transform: translateY(0);
}

.hint {
    margin-top: 25px;
    color: #888;
    font-size: 13px;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
}

/* 聊天页面样式 */
.chat-header {
    background: white;
    padding: 15px 20px;
    display: flex;
    justify-content: space-between;
    align-items: center;
    box-shadow: 0 2px 10px rgba(0, 0, 0, 0.08);
    border-bottom: 1px solid #f0f0f0;
}

.user-info {
    display: flex;
    align-items: center;
    gap: 15px;
}

.avatar {
    width: 45px;
    height: 45px;
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 24px;
    color: white;
    font-weight: bold;
}

.user-info h3 {
    color: #333;
    font-size: 18px;
    font-weight: 600;
}

.status {
    font-size: 12px;
    padding: 3px 8px;
    border-radius: 10px;
}

.status.online {
    background: #e8f5e9;
    color: #4caf50;
}

/* 头部操作按钮 */
.header-actions {
    display: flex;
    gap: 10px;
}

.settings-btn {
    background: #f0f0f0;
    border: none;
    width: 40px;
    height: 40px;
    border-radius: 50%;
    color: #667eea;
    font-size: 18px;
    cursor: pointer;
    transition: background 0.3s;
}

.settings-btn:hover {
    background: #e0e0e0;
}

.logout-btn {
    background: #fff5f5;
    border: none;
    width: 40px;
    height: 40px;
    border-radius: 50%;
    color: #ff6b6b;
    font-size: 18px;
    cursor: pointer;
    transition: background 0.3s;
}

.logout-btn:hover {
    background: #ffeaea;
}

/* 消息区域 */
.chat-main {
    flex: 1;
    overflow: hidden;
    background: #f8f9fa;
    position: relative;
}

.messages-container {
    height: 100%;
    overflow-y: auto;
    padding: 20px;
    display: flex;
    flex-direction: column;
    gap: 15px;
}

/* 消息气泡 */
.message {
    max-width: 75%;
    padding: 12px 16px;
    border-radius: 18px;
    position: relative;
    animation: fadeIn 0.3s ease;
    word-wrap: break-word;
    line-height: 1.5;
}

@keyframes fadeIn {
    from {
        opacity: 0;
        transform: translateY(10px);
    }
    to {
        opacity: 1;
        transform: translateY(0);
    }
}

.message.sent {
    align-self: flex-end;
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    color: white;
    border-bottom-right-radius: 4px;
}

.message.received {
    align-self: flex-start;
    background: white;
    color: #333;
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.06);
    border-bottom-left-radius: 4px;
}

.message.system {
    align-self: center;
    background: #f0f0f0;
    color: #666;
    font-size: 13px;
    max-width: 90%;
    text-align: center;
    border-radius: 12px;
    padding: 8px 16px;
}

.message .sender {
    font-size: 12px;
    font-weight: 600;
    margin-bottom: 5px;
    opacity: 0.9;
}

.message .time {
    font-size: 11px;
    margin-top: 8px;
    opacity: 0.7;
    text-align: right;
}

/* 输入区域 */
.chat-footer {
    background: white;
    padding: 15px 20px;
    border-top: 1px solid #f0f0f0;
}

.input-container {
    display: flex;
    gap: 12px;
    margin-bottom: 8px;
}

#message-input {
    flex: 1;
    padding: 14px 18px;
    border: 2px solid #e1e5e9;
    border-radius: 25px;
    font-size: 16px;
    transition: border-color 0.3s;
    background: #f8f9fa;
}

#message-input:focus {
    border-color: #667eea;
    background: white;
    outline: none;
}

#send-btn {
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    color: white;
    border: none;
    width: 50px;
    height: 50px;
    border-radius: 50%;
    font-size: 18px;
    cursor: pointer;
    transition: transform 0.2s;
}

#send-btn:hover {
    transform: scale(1.05);
}

.footer-hint {
    text-align: center;
    color: #888;
    font-size: 12px;
}

/* 设置弹窗样式 */
.modal {
    display: none;
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0, 0, 0, 0.5);
    z-index: 1000;
    justify-content: center;
    align-items: center;
}

.modal.active {
    display: flex;
}

.modal-content {
    background: white;
    border-radius: 15px;
    width: 90%;
    max-width: 400px;
    max-height: 80vh;
    overflow-y: auto;
    box-shadow: 0 10px 30px rgba(0, 0, 0, 0.2);
    animation: modalSlideIn 0.3s ease;
}

@keyframes modalSlideIn {
    from {
        opacity: 0;
        transform: translateY(-20px);
    }
    to {
        opacity: 1;
        transform: translateY(0);
    }
}

.modal-header {
    padding: 20px;
    border-bottom: 1px solid #eee;
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.modal-header h3 {
    margin: 0;
    color: #333;
    display: flex;
    align-items: center;
    gap: 10px;
}

.close-modal {
    background: none;
    border: none;
    font-size: 24px;
    cursor: pointer;
    color: #999;
    width: 30px;
    height: 30px;
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: 50%;
}

.close-modal:hover {
    background: #f5f5f5;
    color: #333;
}

.modal-body {
    padding: 20px;
}

.setting-item {
    margin-bottom: 25px;
}

.setting-item label {
    display: block;
    margin-bottom: 8px;
    font-weight: 600;
    color: #333;
    display: flex;
    align-items: center;
    gap: 8px;
}

#nickname-input {
    width: 100%;
    padding: 12px 15px;
    border: 2px solid #e1e5e9;
    border-radius: 10px;
    font-size: 16px;
    transition: border-color 0.3s;
}

#nickname-input:focus {
    border-color: #667eea;
    outline: none;
    box-shadow: 0 0 0 3px rgba(102, 126, 234, 0.1);
}

.setting-hint {
    margin-top: 5px;
    color: #888;
    font-size: 13px;
}

.emoji-selector {
    display: flex;
    gap: 8px;
    flex-wrap: wrap;
    margin-top: 10px;
}

.emoji-option {
    font-size: 28px;
    padding: 10px;
    border-radius: 10px;
    cursor: pointer;
    transition: all 0.2s;
    border: 2px solid transparent;
    background: #f8f9fa;
    display: flex;
    align-items: center;
    justify-content: center;
    width: 50px;
    height: 50px;
}

.emoji-option:hover {
    background: #f0f0f0;
    transform: scale(1.1);
}

.emoji-option.active {
    border-color: #667eea;
    background: #f0f4ff;
    transform: scale(1.1);
}

.save-btn {
    width: 100%;
    padding: 14px;
    background: linear-gradient(to right, #667eea, #764ba2);
    color: white;
    border: none;
    border-radius: 10px;
    font-size: 16px;
    font-weight: 600;
    cursor: pointer;
    margin-top: 20px;
    transition: transform 0.2s, opacity 0.2s;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 10px;
}

.save-btn:hover {
    opacity: 0.9;
    transform: translateY(-2px);
}

.save-btn:active {
    transform: translateY(0);
}

/* 滚动条美化 */
.messages-container::-webkit-scrollbar,
.modal-content::-webkit-scrollbar {
    width: 6px;
}

.messages-container::-webkit-scrollbar-track,
.modal-content::-webkit-scrollbar-track {
    background: #f1f1f1;
    border-radius: 3px;
}

.messages-container::-webkit-scrollbar-thumb,
.modal-content::-webkit-scrollbar-thumb {
    background: #c1c1c1;
    border-radius: 3px;
}

.messages-container::-webkit-scrollbar-thumb:hover,
.modal-content::-webkit-scrollbar-thumb:hover {
    background: #a8a8a8;
}

/* 响应式设计 */
@media (max-width: 480px) {
    .login-container {
        padding: 30px 20px;
        margin: 15px;
    }
    
    .message {
        max-width: 85%;
    }
    
    .chat-header,
    .chat-footer {
        padding: 12px 15px;
    }
    
    .emoji-option {
        font-size: 24px;
        width: 45px;
        height: 45px;
    }
}
/* ================= PWA专用样式 ================= */

/* 离线状态指示器 */
#offline-indicator {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    background: linear-gradient(to right, #ff6b6b, #ff8e53);
    color: white;
    text-align: center;
    padding: 12px;
    font-size: 14px;
    z-index: 9999;
    transform: translateY(-100%);
    transition: transform 0.3s ease;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 10px;
    font-weight: 500;
}

#offline-indicator.active {
    transform: translateY(0);
}

/* PWA安装按钮 */
#install-btn {
    position: fixed;
    bottom: 20px;
    right: 20px;
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    color: white;
    border: none;
    padding: 12px 20px;
    border-radius: 25px;
    font-size: 14px;
    font-weight: 600;
    cursor: pointer;
    box-shadow: 0 4px 15px rgba(102, 126, 234, 0.4);
    display: flex;
    align-items: center;
    gap: 8px;
    z-index: 999;
    transition: all 0.3s ease;
    display: none; /* 默认隐藏 */
}

#install-btn:hover {
    transform: translateY(-2px);
    box-shadow: 0 6px 20px rgba(102, 126, 234, 0.5);
}

#install-btn:active {
    transform: translateY(0);
}

/* PWA全屏模式优化 */
body.standalone {
    padding-top: env(safe-area-inset-top);
    padding-bottom: env(safe-area-inset-bottom);
    background: #f8f9fa;
}

/* 防止iOS缩放 */
input, textarea {
    font-size: 16px !important;
}

/* PWA安全区域适配 */
.chat-header {
    padding-top: max(15px, env(safe-area-inset-top));
}

.chat-footer {
    padding-bottom: max(15px, env(safe-area-inset-bottom));
}

/* 安装按钮动画 */
@keyframes pulse {
    0% {
        box-shadow: 0 0 0 0 rgba(102, 126, 234, 0.7);
    }
    70% {
        box-shadow: 0 0 0 10px rgba(102, 126, 234, 0);
    }
    100% {
        box-shadow: 0 0 0 0 rgba(102, 126, 234, 0);
    }
}

/* 网络恢复提示 */
#network-restored {
    position: fixed;
    top: 60px;
    left: 50%;
    transform: translateX(-50%);
    background: #4CAF50;
    color: white;
    padding: 10px 20px;
    border-radius: 20px;
    animation: slideInDown 0.3s ease, fadeOutUp 0.3s ease 2s forwards;
    z-index: 999;
    display: flex;
    align-items: center;
    gap: 8px;
}

@keyframes slideInDown {
    from {
        transform: translateX(-50%) translateY(-20px);
        opacity: 0;
    }
    to {
        transform: translateX(-50%) translateY(0);
        opacity: 1;
    }
}

@keyframes fadeOutUp {
    to {
        transform: translateX(-50%) translateY(-20px);
        opacity: 0;
    }
}

/* PWA启动画面样式 */
@media (display-mode: standalone) {
    .chat-header {
        height: calc(50px + env(safe-area-inset-top));
    }
    
    .login-container {
        margin-top: env(safe-area-inset-top);
    }
}

/* 触摸优化 */
@media (hover: none) {
    .login-btn:hover,
    .send-btn:hover,
    .settings-btn:hover,
    .logout-btn:hover,
    .save-btn:hover,
    .emoji-option:hover {
        transform: none !important;
    }
    
    .login-btn:active,
    .send-btn:active,
    .settings-btn:active,
    .logout-btn:active,
    .save-btn:active,
    .emoji-option:active {
        opacity: 0.8;
    }
}

/* 深色模式适配 */
@media (prefers-color-scheme: dark) {
    .page:not(#login-page) {
        background: #1a1a1a;
    }
    
    .chat-main {
        background: #1a1a1a;
    }
    
    .message.received {
        background: #2d2d2d;
        color: #e0e0e0;
    }
    
    #message-input {
        background: #2d2d2d;
        border-color: #404040;
        color: #e0e0e0;
    }
}