/* =========================================
   1. 全局重置 (Bootstrap 风格)
   ========================================= */
/* html, body { 样式已由 base.html 处理 } */

/* =========================================
   2. 主容器 (.d-flex .flex-column .vh-100)
   ========================================= */
.chat-container {
    display: flex;
    flex-direction: column;
    height: 100%;
    width: 100%;
    max-width: none;
    margin: 0;
    background-color: #fff;
    position: relative;
    overflow: hidden;
}

/* =========================================
   3. 头部 (.flex-shrink-0)
   ========================================= */
.chat-header-sub {
    flex: 0 0 auto;
    background-color: #fff;
    border-bottom: 1px solid #dee2e6;
    z-index: 10;
}

/* =========================================
   4. 任务视图区 (模拟 .d-flex .flex-column .flex-grow-1)
   这是修复的核心！
   ========================================= */
#taskOverview,
.task-overview {
    /* 强制 Flex 布局，覆盖 JS 的 display: block */
    display: flex !important;
    flex-direction: column !important;

    /* 自动占据剩余空间 */
    flex: 1 1 auto !important;

    /* 关键：允许容器被压缩，防止被内容撑爆 */
    min-height: 0 !important;

    /* 禁止外层滚动 */
    overflow: hidden !important;

    width: 100%;
    background-color: #f8f9fa;
    /* Bootstrap bg-light */
    position: relative;
}

/* 4.1 内容滚动区 (模拟 .flex-grow-1 .overflow-auto) */
.task-content {
    /* 占据按钮上方的所有空间 */
    flex: 1 1 auto !important;

    /* 开启内部滚动 */
    overflow-y: auto !important;

    /* 移动端顺滑滚动 */
    -webkit-overflow-scrolling: touch;
}

/* 4.2 底部按钮区 (模拟 .flex-shrink-0 .fixed-bottom-ish) */
.task-actions {
    /* 禁止压缩，根据内容决定高度 */
    flex: 0 0 auto !important;

    background-color: #fff;
    border-top: 1px solid #dee2e6;
    /* Bootstrap border-color */
    padding: 1rem;
    z-index: 1020;
}

/* =========================================
   5. 聊天视图区 (同样的逻辑)
   ========================================= */
.chat-view-container {
    /* 默认隐藏 */
    display: none;

    /* 激活时变成 flex column */
    flex-direction: column;

    /* 占满剩余空间 */
    flex: 1 1 auto;
    min-height: 0;
    overflow: hidden;

    background-color: #f8f9fa;
    position: relative;
    width: 100%;
}

.chat-view-container.active {
    display: flex !important;
}

/* 消息列表 (.flex-grow-1 .overflow-auto) */
.chat-messages {
    flex: 1 1 auto;
    overflow-y: auto;
    padding: 1rem;
    display: flex;
    flex-direction: column;
}

/* 输入框区域 (.flex-shrink-0) */
.chat-input-container {
    flex: 0 0 auto;
    background-color: #fff;
    border-top: 1px solid #dee2e6;
    padding: 1rem;
    z-index: 1020;
}

/* =========================================
   6. 组件样式 (保持原有设计，适配 Bootstrap)
   ========================================= */
/* 隐藏类 */
/* 隐藏类 (Removed duplicate .d-none to allow Bootstrap utilities to work) */

/* 头部元素 */
.header-info {
    display: flex;
    align-items: center;
    gap: 0.5rem;
}

.avatar {
    width: 36px;
    height: 36px;
    background: rgba(255, 255, 255, 0.2);
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
}

.header-text h3 {
    font-size: 1rem;
    font-weight: 600;
    margin: 0;
}

.status {
    font-size: 0.75rem;
    opacity: 0.9;
}

/* 按钮 */
.btn-start-chat {
    width: 100%;
    /* w-100 */
    background: linear-gradient(135deg, #1e3c72 0%, #2a5298 100%);
    color: white;
    border: none;
    padding: 0.75rem 1rem;
    border-radius: 30px;
    font-size: 1rem;
    font-weight: 600;
    box-shadow: 0 4px 6px rgba(0, 0, 0, 0.1);
}

.btn-start-chat:disabled {
    background: #ccc;
    box-shadow: none;
}

/* 输入框 */
.input-wrapper {
    display: flex;
    align-items: flex-end;
    gap: 0.5rem;
    background: #f1f3f5;
    border-radius: 1.5rem;
    padding: 0.5rem 1rem;
    margin-bottom: 0.5rem;
}

.input-field {
    flex: 1;
    display: flex;
}

#messageInput {
    width: 100%;
    background: transparent;
    border: none;
    resize: none;
    outline: none;
    padding: 0;
    margin: 0;
    max-height: 100px;
    color: #212529;
}

.btn-send {
    width: 40px;
    height: 40px;
    border: none;
    border-radius: 50%;
    background: linear-gradient(135deg, #1e3c72 0%, #2a5298 100%);
    color: white;
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
    transition: all 0.2s cubic-bezier(0.175, 0.885, 0.32, 1.275);
    cursor: pointer;
}

.btn-send:hover {
    transform: scale(1.1) rotate(-10deg);
    background: linear-gradient(135deg, #2a5298 0%, #3b82f6 100%);
}

.btn-send:active {
    transform: scale(0.9);
}

.btn-send:disabled {
    background: #e5e7eb;
    color: #9ca3af;
    transform: none;
    cursor: not-allowed;
}

.input-footer {
    display: flex;
    justify-content: center;
    align-items: center;
    min-height: 56px;
    position: relative;
    padding: 0.5rem 0;
}

.input-footer #hintBtn {
    position: absolute;
    left: 0;
}

/* 音量指示器样式 (已迁移至 theme.css .volume-module-v2) */
/* #volume-indicator, .volume-bar 样式已废弃并移除，避免覆盖全局样式 */

.input-footer .char-count {
    position: absolute;
    right: 0;
    font-size: 0.75rem;
    color: #9ca3af;
}

/* #voiceBtn 样式已迁移至 theme.css .mic-unified-btn，此处删除以避免 ID 优先级冲突 */

/* 消息气泡 */
.message {
    display: flex;
    margin-bottom: 1rem;
    animation: fadeInUp 0.3s ease;
}

.message-avatar {
    width: 34px;
    height: 34px;
    border-radius: 50%;
    margin-right: 0.5rem;
    flex-shrink: 0;
    display: flex;
    align-items: center;
    justify-content: center;
}

.bot-message .message-avatar {
    background: #1e3c72;
    color: white;
}

.user-message {
    flex-direction: row-reverse;
}

.user-message .message-avatar {
    background: #198754;
    color: white;
    margin-right: 0;
    margin-left: 0.5rem;
}

.message-content {
    max-width: 80%;
    display: flex;
    flex-direction: column;
}

.message-text {
    padding: 0.75rem 1rem;
    background: white;
    border-radius: 1rem;
    box-shadow: 0 1px 2px rgba(0, 0, 0, 0.05);
}

.bot-message .message-text {
    border-top-left-radius: 0.2rem;
}

.user-message .message-text {
    background: #1e3c72;
    color: white;
    border-top-right-radius: 0.2rem;
}

.message-time {
    font-size: 0.7rem;
    color: #6c757d;
    margin-top: 0.25rem;
    text-align: right;
}

/* 滚动条美化 */
::-webkit-scrollbar {
    width: 5px;
}

::-webkit-scrollbar-thumb {
    background: rgba(0, 0, 0, 0.2);
    border-radius: 10px;
}

::-webkit-scrollbar-track {
    background: transparent;
}

/* 动画 */
@keyframes fadeInUp {
    from {
        opacity: 0;
        transform: translateY(10px);
    }

    to {
        opacity: 1;
        transform: translateY(0);
    }
}

/* Loading & Modal */
.loading {
    display: none;
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0, 0, 0, 0.8);
    z-index: 2000;
    justify-content: center;
    align-items: center;
    color: white;
    flex-direction: column;
}

.loading.show {
    display: flex;
}

.loading-spinner {
    width: 2rem;
    height: 2rem;
    border: 0.25em solid currentColor;
    border-right-color: transparent;
    border-radius: 50%;
    animation: spinner-border .75s linear infinite;
    margin-bottom: 1rem;
}

@keyframes spinner-border {
    to {
        transform: rotate(360deg);
    }
}

.overlay-container {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0, 0, 0, 0.5);
    z-index: 3000;
    display: flex;
    justify-content: center;
    align-items: center;
    backdrop-filter: blur(2px);
}

.modal-card {
    background: white;
    width: 90%;
    max-width: 350px;
    border-radius: 1rem;
    padding: 1.5rem;
    text-align: center;
    box-shadow: 0 0.5rem 1rem rgba(0, 0, 0, 0.15);
    position: relative;
}

.modal-close-btn {
    position: absolute;
    top: 10px;
    right: 10px;
    background: none;
    border: none;
    font-size: 1.25rem;
    color: #6c757d;
}

.modal-icon-wrapper {
    width: 60px;
    height: 60px;
    background: #1e3c72;
    border-radius: 50%;
    margin: 0 auto 1rem;
    display: flex;
    align-items: center;
    justify-content: center;
    color: white;
    font-size: 1.5rem;
}

.btn-modal-primary {
    width: 100%;
    background: #1e3c72;
    color: white;
    border: none;
    padding: 0.5rem;
    border-radius: 2rem;
    margin-top: 1rem;
    font-weight: 600;
}

/* =========================================
   🚑 紧急修复：隐藏状态必须拥有最高优先级
   ========================================= */

/* 1. 确保带有 hidden 类的元素绝对隐藏，覆盖掉上面的 flex !important */
/* 1. 确保带有 hidden 类的元素绝对隐藏 */
.hidden {
    display: none !important;
}

/* 2. 特别针对 Task View 的隐藏修复 */
#taskOverview.hidden,
#taskOverview.d-none {
    display: none !important;
    visibility: hidden !important;
    opacity: 0 !important;
    height: 0 !important;
    width: 0 !important;
    position: absolute !important;
    z-index: -9999 !important;
}

/* 3. 特别针对 Chat View 的隐藏修复 */
.chat-view-container.hidden,
.chat-view-container[style*="display: none"] {
    display: none !important;
}

/* =========================================
   7. 补回丢失的组件样式 (播放器、折叠框等)
   ========================================= */

/* --- 自定义音频播放器 --- */
.custom-audio-player {
    background: white;
    border-radius: 30px;
    padding: 8px 12px;
    display: flex;
    align-items: center;
    gap: 10px;
    width: 260px;
    /* 固定宽度确保美观 */
    margin-bottom: 8px;
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.08);
    border: 1px solid #f0f0f0;
}

.audio-play-btn {
    width: 32px;
    height: 32px;
    border-radius: 50%;
    background: #1e3c72;
    /* 主题深蓝色 */
    color: white;
    border: none;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
    transition: transform 0.2s;
}

.audio-play-btn:hover {
    transform: scale(1.05);
    background: #2a5298;
}

.audio-progress-container {
    flex: 1;
    display: flex;
    flex-direction: column;
    justify-content: center;
    gap: 4px;
}

.audio-progress-bar {
    width: 100%;
    height: 4px;
    background: #e9ecef;
    border-radius: 2px;
    position: relative;
    overflow: hidden;
    cursor: pointer;
}

.audio-progress-fill {
    height: 100%;
    background: #1e3c72;
    /* 进度条颜色 */
    width: 0%;
    border-radius: 2px;
    transition: width 0.1s linear;
}

.audio-time {
    font-size: 10px;
    color: #999;
    text-align: right;
    font-family: monospace;
    line-height: 1;
}

.replay-btn {
    width: 32px;
    height: 32px;
    border-radius: 50%;
    background: #f1f3f5;
    color: #1e3c72;
    border: none;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
    font-size: 14px;
}

.replay-btn:hover {
    background: #e9ecef;
}

/* --- 消息折叠框 (查看文本) --- */
.message-collapse-container {
    background: white;
    border-radius: 12px;
    overflow: hidden;
    margin-top: 8px;
    box-shadow: 0 2px 5px rgba(0, 0, 0, 0.05);
    border: 1px solid #f0f0f0;
    width: 100%;
    /* 确保占满宽度 */
    max-width: 100%;
}

.message-collapse-header {
    padding: 10px 15px;
    background: #f8f9fa;
    cursor: pointer;
    font-size: 13px;
    font-weight: 600;
    color: #555;
    display: flex;
    align-items: center;
    transition: background 0.2s;
}

.message-collapse-header:hover {
    background: #e9ecef;
}

.collapse-icon {
    margin-right: 8px;
    font-size: 10px;
    transition: transform 0.2s;
}

.streaming-text,
.message-text-content {
    padding: 15px;
    font-size: 14px;
    line-height: 1.6;
    color: #333;
    background: white;
}

/* --- Loading 状态 --- */
.audio-loading {
    display: flex;
    align-items: center;
    gap: 8px;
    color: #666;
    font-size: 13px;
    padding: 5px 0;
}

/* --- Microphone Test Modal Styles --- */
#test-volume-indicator {
    height: 32px;
}

.test-volume-bar {
    width: 6px;
    height: 6px;
    background-color: #dee2e6;
    border-radius: 3px;
    transition: all 0.1s ease;
    align-self: center;
}

.test-volume-bar.active {
    background-color: #198754;
    /* Green for success */
    height: 100%;
}

.test-volume-bar.active.medium {
    background-color: #ffc107;
    /* Yellow */
}

.test-volume-bar.active.high {
    background-color: #dc3545;
    /* Red */
}

#mic-troubleshoot-area ul li {
    position: relative;
    padding-left: 5px;
}

#mic-troubleshoot-area i {
    width: 16px;
}


#mic-troubleshoot-area i {
    width: 16px;
}