/* 重置默认样式 */
* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

:root {
    /* 安全区域变量 */
    --sat: env(safe-area-inset-top);
    --sab: env(safe-area-inset-bottom);
    --sal: env(safe-area-inset-left);
    --sar: env(safe-area-inset-right);
}

html, body {
    height: 100%;
    width: 100%;
    overflow: hidden;
    margin: 0;
    padding: 0;
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
    /* 防止移动端滚动 */
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    /* iOS Safari 地址栏适配 */
    padding-top: env(safe-area-inset-top);
    padding-bottom: env(safe-area-inset-bottom);
}

/* 确保根元素占满整个视口 */
#root, .chat-container {
    height: 100vh;
    width: 100vw;
    max-width: 100vw;
    max-height: 100vh;
}

.chat-container {
    max-width: 100vw;
    width: 100vw;
    margin: 0 auto;
    border: 1px solid #ddd;
    border-radius: 8px;
    box-shadow: 0 2px 8px #eee;
    display: flex;
    flex-direction: column;
    background: #fff;
    overflow: hidden;
    /* 确保容器不会超出视口 */
    position: relative;
    box-sizing: border-box;
    /* 高度由JavaScript动态设置 */
}
.chat-header {
    background: #007bff;
    color: #fff;
    padding: 8px 12px;
    text-align: center;
    font-size: 16px;
    border-radius: 8px 8px 0 0;
    min-height: auto;
    position: relative;
    display: flex;
    align-items: center;
    justify-content: center;
}

.back-btn {
    position: absolute;
    left: 12px;
    background: rgba(255, 255, 255, 0.2);
    border: 2px solid #fff;
    color: #fff;
    font-size: 18px;
    font-weight: bold;
    cursor: pointer;
    padding: 6px 10px;
    border-radius: 6px;
    transition: all 0.2s;
    z-index: 1000;
    min-width: 32px;
    min-height: 32px;
    display: flex;
    align-items: center;
    justify-content: center;
}

.back-btn:hover {
    background-color: rgba(255, 255, 255, 0.2);
}

.back-btn:active {
    background-color: rgba(255, 255, 255, 0.3);
}
.chat-header h2 {
    margin: 0;
    font-size: 16px;
    font-weight: 600;
}
.chat-messages {
    flex: 1;
    padding: 10px;
    overflow-y: auto;
    background: #f9f9f9;
    min-height: 0; /* 允许flex收缩 */
    border: 1px solid #ddd;
    /* 确保消息区域不会占用过多空间 */
    max-height: calc(100vh - 120px); /* 减去头部和输入框的高度 */
    /* iOS触摸滚动优化 */
    -webkit-overflow-scrolling: touch;
    /* 确保滚动条可见 */
    scrollbar-width: thin;
    scrollbar-color: #ccc #f0f0f0;
}

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

.chat-messages::-webkit-scrollbar-track {
    background: #f0f0f0;
    border-radius: 3px;
}

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

.chat-messages::-webkit-scrollbar-thumb:hover {
    background: #999;
}

.message {
    margin-bottom: 10px;
    display: flex;
    flex-direction: column;
}
.message.user {
    align-items: flex-end;
}
.message.admin {
    align-items: flex-start;
}
.message.system {
    align-items: center;
    margin: 10px 0;
}
.message-content {
    background: #e6f0ff;
    padding: 8px 12px;
    border-radius: 16px;
    max-width: 70%;
    word-break: break-all;
}
.message.user .message-content {
    background: #d1ffd6;
}
.message img {
    max-width: 120px;
    border-radius: 8px;
    margin-top: 4px;
}
.file-attachment {
    background: #fff;
    border: 1px solid #007bff;
    border-radius: 8px;
    padding: 8px 12px;
    margin-top: 4px;
    font-size: 14px;
    color: #007bff;
    cursor: pointer;
    display: inline-flex;
    align-items: center;
    gap: 6px;
}
.file-attachment:hover {
    background: #f8f9ff;
}
#chat-form {
    border-top: 1px solid #eee;
    background: #fafafa;
    padding: 10px;
    /* 确保输入框始终在底部可见 */
    position: sticky;
    bottom: 0;
    z-index: 1000;
    /* 防止输入框被压缩 */
    flex-shrink: 0;
}
.input-row {
    display: flex;
    margin-bottom: 8px;
    align-items: center;
    gap: 8px;
}
#message-input {
    flex: 1;
    padding: 8px;
    border: 1px solid #ccc;
    border-radius: 4px;
    margin-right: 0;
}
#file-btn {
    background: #6c757d;
    color: #fff;
    border: none;
    border-radius: 4px;
    padding: 8px 10px;
    cursor: pointer;
    font-size: 16px;
    white-space: nowrap;
    min-width: 40px;
    display: flex;
    align-items: center;
    justify-content: center;
}
#file-btn:hover {
    background: #5a6268;
}

button[type="submit"] {
    background: #007bff;
    color: #fff;
    border: none;
    border-radius: 4px;
    padding: 8px 16px;
    cursor: pointer;
    white-space: nowrap;
}
.file-row {
    display: flex;
    align-items: center;
    font-size: 12px;
    color: #666;
    padding: 4px 0;
    gap: 8px;
}
#file-status {
    flex: 1;
}
/* 移动端优化 */
@media (max-width: 500px) {
    .chat-container {
        width: 100vw;
        max-width: 100vw;
        margin: 0;
        border-radius: 0;
        border: none;
        /* 确保在虚拟键盘弹出时仍然可见 */
        position: fixed;
        top: env(safe-area-inset-top);
        left: 0;
        right: 0;
        bottom: env(safe-area-inset-bottom);
        /* 高度由JavaScript动态设置 */
    }
    .chat-header {
        border-radius: 0;
        /* 固定头部高度 */
        height: 44px;
        min-height: 44px;
        display: flex;
        align-items: center;
        justify-content: center;
    }
    .chat-messages {
        border: none;
        /* 确保消息区域有足够空间 */
        flex: 1;
        min-height: 0;
        /* 限制最大高度，确保输入框可见 */
        max-height: calc(100vh - 120px) !important;
        overflow-y: auto;
        /* iOS触摸滚动优化 */
        -webkit-overflow-scrolling: touch;
    }
    #chat-form {
        /* 固定底部输入区域 */
        position: sticky;
        bottom: 0;
        background: #fafafa;
        padding: 8px;
        border-top: 1px solid #eee;
        /* 确保输入框始终可见 */
        z-index: 1000;
        flex-shrink: 0;
        /* 强制显示 */
        display: block !important;
        visibility: visible !important;
    }
    .input-row {
        gap: 6px;
        /* 确保输入框在虚拟键盘上方 */
        position: relative;
        z-index: 1000;
    }
    #message-input {
        /* 增加输入框高度，更容易点击 */
        min-height: 44px;
        font-size: 16px; /* 防止iOS缩放 */
    }
    #file-btn {
        padding: 8px 10px;
        font-size: 12px;
        min-height: 44px;
    }
    button[type="submit"] {
        min-height: 44px;
        font-size: 16px;
    }

}

/* 桌面端优化 */
@media (min-width: 501px) {
    .chat-container {
        margin: 20px auto;
        width: 400px;
        max-width: 400px;
        height: calc(100vh - 40px);
        max-height: 600px;
    }
}

/* iOS Safari 特殊修复 */
@supports (-webkit-touch-callout: none) {
    .chat-container {
        width: 100vw !important;
        max-width: 100vw !important;
        /* 防止iOS Safari的弹性滚动 */
        position: fixed !important;
        top: env(safe-area-inset-top) !important;
        left: 0 !important;
        right: 0 !important;
        bottom: env(safe-area-inset-bottom) !important;
        /* 高度由JavaScript动态设置 */
    }
    
    .chat-messages {
        /* 确保在iOS上正确显示 */
        max-height: calc(100vh - 140px) !important;
        -webkit-overflow-scrolling: touch !important;
        /* 强制启用触摸滚动 */
        overflow-y: scroll !important;
        /* 确保滚动区域足够大 */
        min-height: 200px !important;
    }
    
    #chat-form {
        /* 确保输入框在iOS上始终可见 */
        position: sticky !important;
        bottom: 0 !important;
        background: #fafafa !important;
        z-index: 9999 !important;
    }
    
    /* iOS触摸滚动优化 */
    body {
        -webkit-overflow-scrolling: touch;
    }
}

/* 超小屏幕优化 */
@media (max-width: 360px) {
    .chat-container {
        height: 100vh;
    }
    .input-row {
        gap: 4px;
    }
    #message-input {
        padding: 8px;
        font-size: 16px; /* 保持16px防止iOS缩放 */
        min-height: 44px;
    }
    button[type="submit"] {
        padding: 8px 12px;
        font-size: 16px;
        min-height: 44px;
    }
    #file-btn {
        min-height: 44px;
        font-size: 14px;
    }
} 