/**
 * 消防指挥调度聊天系统 - 样式文件
 * 手机端优先设计
 */

* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

:root {
    --primary-color: #d32f2f;
    --primary-dark: #b71c1c;
    --primary-light: #ef5350;
    --secondary-color: #1976d2;
    --background-color: #f5f5f5;
    --chat-bg: #e8eaf6;
    --user-bubble: #1976d2;
    --bot-bubble: #ffffff;
    --text-primary: #212121;
    --text-secondary: #757575;
    --border-color: #e0e0e0;
    --shadow: 0 2px 10px rgba(0, 0, 0, 0.1);
}

html {
    height: 100%;
}

body {
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "Roboto", "Oxygen",
        "Ubuntu", "Cantarell", "Fira Sans", "Droid Sans", "Helvetica Neue",
        "Microsoft YaHei", sans-serif;
    background: var(--background-color);
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
    height: 100%;
    width: 100%;
    margin: 0;
    padding: 0;
    /* 防止下拉刷新 */
    overscroll-behavior: none;
    /* iOS 平滑滚动 */
    -webkit-overflow-scrolling: touch;
    /* 防止整个页面滚动 */
    overflow: hidden;
    position: fixed;
}

/* 聊天容器 */
.chat-container {
    display: flex;
    flex-direction: column;
    height: 100vh;
    height: 100dvh; /* 动态视口高度，避免地址栏遮挡 */
    max-width: 100vw;
    width: 100%;
    background: var(--chat-bg);
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    overflow: hidden;
}

/* 头部 */
.chat-header {
    background: linear-gradient(135deg, var(--primary-color) 0%, var(--primary-dark) 100%);
    color: white;
    padding: 30px 20px 18px;
    display: flex;
    align-items: center;
    gap: 12px;
    box-shadow: var(--shadow);
    position: relative;
    z-index: 10;
    min-height: 90px;
    flex-shrink: 0;
}

.header-icon {
    font-size: 40px;
    line-height: 1;
}

.header-info {
    flex: 1;
}

.header-title {
    font-size: 19px;
    font-weight: bold;
    margin-bottom: 5px;
    line-height: 1.3;
}

.header-subtitle {
    font-size: 13px;
    opacity: 0.9;
    line-height: 1.3;
}

.status-indicator {
    width: 12px;
    height: 12px;
    border-radius: 50%;
    background: #4caf50;
    position: relative;
}

.status-indicator.online::before {
    content: '';
    position: absolute;
    top: -3px;
    left: -3px;
    right: -3px;
    bottom: -3px;
    border: 2px solid #4caf50;
    border-radius: 50%;
    animation: pulse 2s infinite;
}

@keyframes pulse {
    0%, 100% {
        opacity: 1;
        transform: scale(1);
    }
    50% {
        opacity: 0;
        transform: scale(1.5);
    }
}

/* 消息区域 */
.chat-messages {
    flex: 1;
    min-height: 0;
    overflow-y: auto;
    overflow-x: hidden;
    padding: 20px 15px;
    display: flex;
    flex-direction: column;
    gap: 15px;
    /* iOS 平滑滚动 - 关键！ */
    -webkit-overflow-scrolling: touch;
    /* 防止过度滚动 */
    overscroll-behavior-y: contain;
    /* 确保触摸滚动正常工作 */
    touch-action: pan-y;
    /* 强制创建独立滚动容器 */
    position: relative;
    will-change: scroll-position;
}

.chat-messages::-webkit-scrollbar {
    width: 6px;
}

.chat-messages::-webkit-scrollbar-track {
    background: transparent;
}

.chat-messages::-webkit-scrollbar-thumb {
    background: rgba(0, 0, 0, 0.2);
    border-radius: 3px;
}

/* 消息 */
.message {
    display: flex;
    gap: 10px;
    animation: slideIn 0.3s ease-out;
}

@keyframes slideIn {
    from {
        opacity: 0;
        transform: translateY(20px);
    }
    to {
        opacity: 1;
        transform: translateY(0);
    }
}

.message-avatar {
    width: 40px;
    height: 40px;
    border-radius: 50%;
    background: white;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 24px;
    flex-shrink: 0;
    box-shadow: 0 2px 5px rgba(0, 0, 0, 0.1);
    overflow: hidden;
}

.message-avatar img {
    width: 100%;
    height: 100%;
    object-fit: cover;
}

.message-content {
    display: flex;
    flex-direction: column;
    gap: 5px;
    max-width: calc(100% - 60px);
}

.message-bubble {
    padding: 12px 16px;
    border-radius: 18px;
    word-wrap: break-word;
    line-height: 1.5;
    font-size: 15px;
}

.message-bubble p {
    margin: 8px 0;
}

.message-bubble p:first-child {
    margin-top: 0;
}

.message-bubble p:last-child {
    margin-bottom: 0;
}

.message-bubble ul {
    margin: 10px 0;
    padding-left: 20px;
}

.message-bubble li {
    margin: 6px 0;
}

.message-time {
    font-size: 11px;
    color: var(--text-secondary);
    padding: 0 8px;
}

/* 快速提问按钮 */
.quick-questions {
    display: grid;
    grid-template-columns: repeat(2, 1fr);
    gap: 8px;
    margin: 12px 0;
}

.quick-question-btn {
    background: linear-gradient(135deg, var(--primary-light) 0%, var(--primary-color) 100%);
    color: white;
    border: none;
    padding: 8px 14px;
    border-radius: 20px;
    font-size: 13px;
    cursor: pointer;
    transition: all 0.3s;
    box-shadow: 0 2px 5px rgba(211, 47, 47, 0.2);
    font-family: inherit;
    -webkit-tap-highlight-color: transparent;
    width: 100%;
    text-align: center;
}

.quick-question-btn:active {
    transform: scale(0.95);
    box-shadow: 0 1px 3px rgba(211, 47, 47, 0.3);
}

.quick-question-btn:hover {
    box-shadow: 0 3px 8px rgba(211, 47, 47, 0.3);
}

.tip-text {
    font-size: 13px;
    color: var(--text-secondary);
    font-style: italic;
    margin-top: 8px !important;
}

/* 用户消息 */
.user-message {
    flex-direction: row-reverse;
}

.user-message .message-content {
    align-items: flex-end;
}

.user-message .message-bubble {
    background: var(--user-bubble);
    color: white;
    border-bottom-right-radius: 4px;
}

.user-message .message-avatar {
    background: linear-gradient(135deg, var(--secondary-color) 0%, #1565c0 100%);
    color: white;
    font-size: 20px;
}

/* 机器人消息 */
.bot-message .message-bubble {
    background: var(--bot-bubble);
    color: var(--text-primary);
    border-bottom-left-radius: 4px;
    box-shadow: 0 2px 5px rgba(0, 0, 0, 0.05);
}

/* 思考动画 */
.message-bubble.thinking {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 12px 20px;
}

.typing-indicator {
    display: flex;
    gap: 4px;
}

.typing-indicator span {
    width: 8px;
    height: 8px;
    border-radius: 50%;
    background: var(--primary-color);
    animation: typing 1.4s infinite;
}

.typing-indicator span:nth-child(2) {
    animation-delay: 0.2s;
}

.typing-indicator span:nth-child(3) {
    animation-delay: 0.4s;
}

@keyframes typing {
    0%, 60%, 100% {
        transform: translateY(0);
        opacity: 0.5;
    }
    30% {
        transform: translateY(-10px);
        opacity: 1;
    }
}

.thinking-text {
    color: var(--text-secondary);
    font-size: 14px;
}

/* 输入区域 */
.chat-input-container {
    background: white;
    padding: 12px 15px;
    border-top: 1px solid var(--border-color);
    box-shadow: 0 -2px 10px rgba(0, 0, 0, 0.05);
    flex-shrink: 0;
}

.input-wrapper {
    display: flex;
    gap: 10px;
    align-items: flex-end;
}

.chat-input {
    flex: 1;
    border: 2px solid var(--border-color);
    border-radius: 20px;
    padding: 10px 16px;
    font-size: 15px;
    font-family: inherit;
    resize: none;
    outline: none;
    max-height: 120px;
    overflow-y: auto;
    transition: border-color 0.3s;
}

.chat-input:focus {
    border-color: var(--primary-color);
}

.chat-input::-webkit-scrollbar {
    width: 4px;
}

.chat-input::-webkit-scrollbar-thumb {
    background: rgba(0, 0, 0, 0.2);
    border-radius: 2px;
}

.send-button {
    width: 44px;
    height: 44px;
    border-radius: 50%;
    border: none;
    background: linear-gradient(135deg, var(--primary-color) 0%, var(--primary-dark) 100%);
    color: white;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all 0.3s;
    flex-shrink: 0;
}

.send-button:active {
    transform: scale(0.95);
}

.send-button:disabled {
    background: #ccc;
    cursor: not-allowed;
}

.send-button svg {
    transform: translateX(2px);
}

/* 响应式设计 */
@media (min-width: 768px) {
    .chat-container {
        max-width: 500px;
        margin: 0 auto;
        box-shadow: 0 0 20px rgba(0, 0, 0, 0.1);
    }
}

/* 安全区域适配 (iPhone X等) */
@supports (padding: max(0px)) {
    .chat-header {
        padding-top: max(30px, calc(env(safe-area-inset-top) + 10px));
        padding-bottom: 18px;
    }

    .chat-input-container {
        padding-bottom: max(12px, env(safe-area-inset-bottom));
    }
}

/* 防止文本选择和长按菜单 */
.chat-header,
.message-avatar,
.send-button {
    -webkit-user-select: none;
    user-select: none;
    -webkit-touch-callout: none;
}

/* 滚动条优化 */
@media (max-width: 767px) {
    .chat-messages::-webkit-scrollbar {
        display: none;
    }

    /* 确保移动端可以滚动 - 关键配置 */
    .chat-messages {
        -webkit-overflow-scrolling: touch;
        overflow-y: scroll !important;
        /* 明确指定触摸动作 */
        touch-action: pan-y !important;
    }
}

/* 修复：移除可能阻止滚动的 touch-action */
.chat-container {
    touch-action: none;
}

/* 允许消息区域触摸滚动 */
.chat-messages {
    touch-action: pan-y !important;
}
