﻿
/* ===== 頁面佈局 ===== */
body {
    /* header 固定時補上頂部空間（main-2.css 的 min-header 高度約 50px） */
    padding-top: 50px;
}

.header.scrolled {
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.15);
    transition: box-shadow 0.2s ease;
}

/* Banner */
.chat-banner {
    height: 72px;
    position: relative;
    display: flex;
    align-items: center;
    justify-content: center;
    overflow: hidden;
    background: #060e1f;
}
    /* 底層深色漸層 */
    .chat-banner::before {
        content: '';
        position: absolute;
        inset: 0;
        background: radial-gradient(ellipse 60% 120% at 20% 50%, rgba(0,80,200,0.55) 0%, transparent 70%), radial-gradient(ellipse 50% 100% at 80% 50%, rgba(0,40,120,0.45) 0%, transparent 70%), linear-gradient(135deg, #060e1f 0%, #0a1a3a 50%, #081428 100%);
    }
/* SVG 神經網路意境圖（data URI） */
.chat-banner-bg {
    position: absolute;
    inset: 0;
    width: 100%;
    height: 100%;
    opacity: 0.55;
}
/* 中央光暈 */
.chat-banner::after {
    content: '';
    position: absolute;
    left: 50%;
    top: 50%;
    transform: translate(-50%, -50%);
    width: 320px;
    height: 72px;
    background: radial-gradient(ellipse at center, rgba(64,140,255,0.18) 0%, transparent 70%);
    pointer-events: none;
}

.chat-banner-title {
    color: #fff;
    font-size: 18px;
    font-weight: 300;
    letter-spacing: 6px;
    position: relative;
    z-index: 1;
    text-shadow: 0 0 24px rgba(80,160,255,0.7), 0 0 2px rgba(255,255,255,0.4);
}

/* ===== 三欄容器：自然延伸高度，不鎖定 ===== */
.chat-layout {
    display: flex;
    align-items: stretch;
    min-height: calc(100vh - 50px - 72px);
    position: relative; /* 供 overlay 定位 */
}

/* ===== 左側邊欄 ===== */
.chat-sidebar-wrap {
    /* 包裹層：控制寬度 transition，不裁切內容（讓 toggle 按鈕可見） */
    position: relative;
    flex-shrink: 0;
}

.chat-sidebar {
    width: 200px;
    border-right: 1px solid #e5e7eb;
    background: #fff;
    padding-bottom: 24px;
    overflow: hidden; /* 收合時隱藏內容 */
    transition: width 0.25s ease;
    box-sizing: border-box;
}
/* 收合狀態：側欄縮至 0 寬，內容隱藏 */
.chat-sidebar-wrap.collapsed .chat-sidebar {
    width: 0;
    border-right: none;
}

.chat-new-btn {
    display: flex;
    align-items: center;
    gap: 8px;
    margin: 12px;
    padding: 10px 14px;
    border-radius: 6px;
    background: #f3f4f6;
    border: none;
    cursor: pointer;
    font-size: 14px;
    color: #374151;
    transition: background 0.2s;
    width: calc(100% - 24px);
    box-sizing: border-box;
    white-space: nowrap; /* 避免收合時文字換行 */
}

    .chat-new-btn:hover {
        background: #e5e7eb;
    }

.chat-new-btn-icon {
    font-size: 16px;
    font-weight: 300;
    color: #6b7280;
}

.chat-history-label {
    padding: 8px 16px 6px;
    font-size: 12px;
    color: #9ca3af;
    white-space: nowrap;
}

.chat-history-item {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 8px 12px;
    cursor: pointer;
    position: relative;
    transition: background 0.15s;
    white-space: nowrap;
}

    .chat-history-item:hover {
        background: #f3f4f6;
    }

        .chat-history-item:hover .chat-history-arrow {
            opacity: 1;
        }

.chat-history-icon {
    width: 16px;
    height: 16px;
    flex-shrink: 0;
    color: #6b7280;
}

    .chat-history-icon svg {
        width: 100%;
        height: 100%;
    }

.chat-history-text {
    flex: 1;
    font-size: 13px;
    color: #374151;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.chat-history-arrow {
    flex-shrink: 0;
    color: #9ca3af;
    font-size: 10px;
    opacity: 0;
    cursor: pointer;
    padding: 2px 4px;
}

.chat-history-dropdown {
    display: none;
    position: absolute;
    right: 0;
    top: calc(100% - 4px);
    background: #fff;
    border-radius: 8px;
    box-shadow: 0 4px 16px rgba(0,0,0,0.12);
    z-index: 100;
    min-width: 100px;
    padding: 6px 0;
}

    .chat-history-dropdown.active {
        display: block;
    }

.chat-history-dropdown-item {
    padding: 10px 18px;
    font-size: 14px;
    color: #374151;
    cursor: pointer;
}

    .chat-history-dropdown-item:hover {
        background: #f3f4f6;
    }

/* ===== 中間主聊天區 ===== */
.chat-main {
    flex: 1;
    min-width: 0;
    display: flex;
    flex-direction: column;
}

.chat-toolbar {
    display: flex;
    justify-content: flex-end;
    align-items: center;
    gap: 6px;
    padding: 12px 20px 4px;
}

.chat-toolbar-btn {
    width: 32px;
    height: 32px;
    border-radius: 50%;
    border: none;
    background: #1e3a6e;
    color: #fff;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: background 0.2s;
}

    .chat-toolbar-btn:hover {
        background: #15306a;
    }

    .chat-toolbar-btn svg {
        width: 16px;
        height: 16px;
    }
    /* 手機版專用按鈕：桌機隱藏（放在 .chat-toolbar-btn 之後，specificity 相同但 later wins） */
    .chat-toolbar-btn.mobile-history-btn {
        display: none;
        margin-right: auto;
    }

    .chat-toolbar-btn.mobile-sources-btn {
        display: none;
    }

.chat-layout.sources-collapsed .chat-toolbar-btn.mobile-sources-btn {
    opacity: 0.45;
}

/* 訊息區 */
.chat-messages {
    flex: 1;
    padding: 8px 24px 16px;
    display: flex;
    flex-direction: column;
}

/* Loading 特效 */
.chat-loading {
    margin-top: auto;
    padding: 20px 0 4px;
}

.chat-loading-status {
    font-size: 13px;
    color: #6b7280;
    margin-bottom: 10px;
    min-height: 20px;
}

.chat-loading-dots {
    font-size: 14px;
    color: #1e3a6e;
    font-weight: 500;
    display: none;
}

.dot {
    opacity: 0;
    animation: dotBlink 1.2s infinite;
}

.dot1 {
    animation-delay: 0s;
}

.dot2 {
    animation-delay: 0.3s;
}

.dot3 {
    animation-delay: 0.6s;
}

@keyframes dotBlink {
    0%,100% {
        opacity: 0;
    }

    50% {
        opacity: 1;
    }
}

/* 相關報告清單收合 */
.related-reports-tabs {
    align-items: center;
}

.related-reports-collapse-btn {
    margin-left: auto;
    padding: 8px 14px;
    cursor: pointer;
    color: #9ca3af;
    font-size: 13px;
    user-select: none;
    transition: transform 0.2s;
    flex-shrink: 0;
    line-height: 1;
}

    .related-reports-collapse-btn.collapsed {
        transform: rotate(180deg);
    }

.related-reports.collapsed .related-reports-panel {
    display: none !important;
}

.related-reports-footer {
    display: flex;
    justify-content: flex-end;
    border-top: 1px solid #e5e7eb;
}

.related-reports.collapsed .related-reports-footer {
    display: none;
}

/* 使用者訊息（右側綠色） */
.msg-user-row {
    display: flex;
    justify-content: flex-end;
    align-items: flex-start;
    gap: 10px;
    margin-bottom: 20px;
}

.msg-user-bubble {
    background: #3d8c45;
    color: #fff;
    border-radius: 20px;
    padding: 10px 20px;
    font-size: 15px;
    max-width: 60%;
}

.msg-user-avatar {
    width: 32px;
    height: 32px;
    border-radius: 50%;
    background: #e5e7eb;
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
    margin-top: 2px;
}

    .msg-user-avatar svg {
        width: 18px;
        height: 18px;
        color: #6b7280;
    }

/* AI 訊息（左側） */
.msg-ai-row {
    display: flex;
    align-items: flex-start;
    gap: 12px;
    margin-bottom: 16px;
}

.msg-ai-avatar {
    width: 32px;
    height: 32px;
    border-radius: 50%;
    background: #1e3a6e;
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
    margin-top: 2px;
}

    .msg-ai-avatar svg {
        width: 18px;
        height: 18px;
        color: #fff;
    }

.msg-ai-content {
    flex: 1;
    font-size: 16px;
    color: #1f2937;
    line-height: 1.8;
}

    .msg-ai-content p {
        margin: 0 0 12px;
    }

    .msg-ai-content ul {
        margin: 6px 0 14px;
        padding-left: 22px;
    }

    .msg-ai-content li {
        margin-bottom: 8px;
    }

.msg-section-title {
    font-weight: 600;
    color: #1f2937;
    margin: 16px 0 10px;
    font-size: 16px;
}

.msg-cite {
    color: #2563eb;
    font-size: 13px;
    text-decoration: none;
}

    .msg-cite:hover {
        text-decoration: underline;
    }

.msg-copy-btn {
    background: none;
    border: none;
    cursor: pointer;
    color: #9ca3af;
    display: flex;
    align-items: center;
    gap: 4px;
    font-size: 14px;
    padding: 4px 0;
    margin-top: 8px;
    transition: color 0.2s;
}

    .msg-copy-btn:hover {
        color: #374151;
    }

    .msg-copy-btn svg {
        width: 15px;
        height: 15px;
    }

/* 相關報告清單 */
.related-reports {
    margin-top: 24px;
    border: 1px solid #e5e7eb;
    border-radius: 4px;
    overflow: hidden;
}

.related-reports-header {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 12px 16px;
    border-bottom: 1px solid #e5e7eb;
    font-size: 16px;
    font-weight: 600;
    color: #1f2937;
}

    .related-reports-header svg {
        width: 18px;
        height: 18px;
        color: #6b7280;
        flex-shrink: 0;
    }
/* 頁籤列 */
.related-reports-tabs {
    display: flex;
    border-bottom: 1px solid #e5e7eb;
}

.related-reports-tab {
    padding: 10px 20px;
    font-size: 15px;
    font-weight: 400;
    color: #6b7280;
    cursor: pointer;
    border-bottom: 2px solid transparent;
    margin-bottom: -1px;
    transition: color 0.15s, border-color 0.15s;
    user-select: none;
}

    .related-reports-tab:hover {
        color: #1f2937;
    }

    .related-reports-tab.active {
        color: #1e3a6e;
        font-weight: 600;
        border-bottom-color: #1e3a6e;
    }
/* 頁籤內容 */
.related-reports-panel {
    display: none;
}

    .related-reports-panel.active {
        display: block;
    }

.related-reports-list {
    list-style: none;
    margin: 0;
    padding: 0;
}

    .related-reports-list li {
        border-bottom: 1px solid #f3f4f6;
    }

        .related-reports-list li:last-child {
            border-bottom: none;
        }

    .related-reports-list a {
        display: block;
        padding: 13px 16px;
        font-size: 15px;
        color: #1f2937;
        text-decoration: none;
        transition: background 0.15s, color 0.15s;
    }

        .related-reports-list a:hover {
            background: #f8faff;
            color: #1e3a6e;
        }

/* 輸入區 */
.chat-input-area {
    position: sticky;
    bottom: 0;
    padding: 8px 24px 16px;
    background: #fff;
    border-top: 1px solid #e5e7eb;
    z-index: 50;
}

.chat-mode-bar {
    display: flex;
    align-items: center;
    gap: 16px;
    margin-bottom: 8px;
    flex-wrap: wrap;
}

.chat-mode-badge {
    display: inline-block;
    background: #1e3a6e;
    color: #fff;
    font-size: 12px;
    padding: 4px 12px;
    border-radius: 4px;
    cursor: pointer;
    flex-shrink: 0;
}

.chat-mode-filters {
    display: flex;
    align-items: center;
    gap: 14px;
}

.mode-filter-check {
    display: flex;
    align-items: center;
    gap: 5px;
    cursor: pointer;
    font-size: 14px;
    color: #1e3a6e;
    font-weight: 500;
    user-select: none;
}

    .mode-filter-check input[type="checkbox"] {
        position: absolute;
        opacity: 0;
        width: 0;
        height: 0;
    }

    .mode-filter-check .check-box {
        width: 16px;
        height: 16px;
        border: 2px solid #1e3a6e;
        border-radius: 3px;
        background: #fff;
        flex-shrink: 0;
        display: flex;
        align-items: center;
        justify-content: center;
        box-sizing: border-box;
        transition: background 0.15s, border-color 0.15s;
    }

    .mode-filter-check input[type="checkbox"]:checked + .check-box {
        background: #1e3a6e;
        border-color: #1e3a6e;
    }

        .mode-filter-check input[type="checkbox"]:checked + .check-box::after {
            content: '';
            display: block;
            width: 4px;
            height: 7px;
            border-right: 2px solid #fff;
            border-bottom: 2px solid #fff;
            transform: rotate(45deg);
            margin-top: -2px;
        }

.chat-input-row {
    display: flex;
    align-items: stretch;
    border: 1px solid #d1d5db;
    border-radius: 6px;
    overflow: hidden;
    background: #f9fafb;
}

.chat-input-box {
    flex: 1;
    border: none;
    background: transparent;
    padding: 10px 12px;
    font-size: 14px;
    color: #374151;
    resize: none;
    outline: none;
    font-family: inherit;
    min-height: 42px;
    max-height: 120px;
    line-height: 1.5;
}

    .chat-input-box::placeholder {
        color: #9ca3af;
    }

.chat-send-btn {
    width: 44px;
    background: #1e3a6e;
    border: none;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    color: #fff;
    flex-shrink: 0;
    transition: background 0.2s;
}

    .chat-send-btn:hover {
        background: #15306a;
    }

    .chat-send-btn svg {
        width: 18px;
        height: 18px;
    }

.chat-action-row {
    display: flex;
    gap: 8px;
    margin-top: 8px;
}

.chat-action-btn {
    width: 32px;
    height: 32px;
    border-radius: 50%;
    border: 1.5px solid #374151;
    background: transparent;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    color: #374151;
    transition: background 0.2s, color 0.2s;
}

    .chat-action-btn:hover {
        background: #374151;
        color: #fff;
    }

    .chat-action-btn svg {
        width: 15px;
        height: 15px;
    }

/* ===== 問答群組（左右兩欄：主內容 + 資料來源） ===== */
.qa-group {
    display: flex;
    align-items: flex-start;
    padding-bottom: 28px;
    margin-bottom: 28px;
    border-bottom: 1.5px solid #e8eaed;
}

    .qa-group:last-child {
        border-bottom: none;
        margin-bottom: 0;
        padding-bottom: 0;
    }

.qa-group-main {
    flex: 1;
    min-width: 0;
}

.qa-group-sources {
    width: 260px;
    flex-shrink: 0;
    border-left: 1px solid #e5e7eb;
    margin-left: 16px;
    transition: width 0.25s ease, opacity 0.25s ease, margin-left 0.25s ease;
    overflow: hidden;
    position: sticky;
    top: 60px; /* 固定 header 50px + 10px 緩衝 */
    align-self: flex-start;
}

.qa-group-sources-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 12px 14px;
    font-size: 14px;
    font-weight: 600;
    color: #374151;
    border-bottom: 1px solid #e5e7eb;
    cursor: pointer;
    user-select: none;
}

.qa-group-sources-toggle {
    font-size: 12px;
    color: #9ca3af;
    transition: transform 0.2s;
}

    .qa-group-sources-toggle.collapsed {
        transform: rotate(180deg);
    }

.qa-group-sources-body.hidden {
    display: none;
}

.source-card {
    padding: 10px 14px;
    border-bottom: 1px solid #f3f4f6;
    transition: background 0.15s;
}

    .source-card:last-child {
        border-bottom: none;
    }

    .source-card:hover {
        background: #f8faff;
    }

.source-card-title {
    display: block;
    font-size: 13px;
    font-weight: 600;
    color: #1e3a6e;
    text-decoration: none;
    line-height: 1.5;
    margin-bottom: 5px;
}

    .source-card-title:hover {
        text-decoration: underline;
    }

.source-card-desc {
    font-size: 12px;
    color: #6b7280;
    line-height: 1.55;
    display: -webkit-box;
    -webkit-line-clamp: 3;
    -webkit-box-orient: vertical;
    overflow: hidden;
}

/* ===== 兩個 Panel Toggle（手機/平板用，固定浮動） ===== */
/* 桌機預設隱藏；< 1024px 才顯示 */
.sources-toggle-wrap {
    flex-shrink: 0;
    width: 0;
}
/* 共用浮動 pill 樣式（display 由 sidebar-toggle / sources-toggle 各自控制） */
.panel-toggle-btn {
    position: fixed;
    top: 50%;
    transform: translateY(-50%);
    width: 30px;
    height: 80px;
    cursor: pointer;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 6px;
    z-index: 300;
    background: rgba(255,255,255,0.55);
    backdrop-filter: blur(10px);
    -webkit-backdrop-filter: blur(10px);
    border: 1px solid rgba(209,213,219,0.5);
    transition: background 0.2s, box-shadow 0.2s;
}

.pill-icon {
    width: 14px;
    height: 14px;
    color: #1e3a6e;
    flex-shrink: 0;
    opacity: 0.85;
}

.pill-arrow {
    width: 13px;
    height: 13px;
    color: #1e3a6e;
    flex-shrink: 0;
    transition: transform 0.25s ease;
}
/* 桌機預設隱藏；手機/平板由 media query 設 display: flex */
.sidebar-toggle {
    display: none;
    left: 0;
    border-radius: 0 14px 14px 0;
    border-left: none;
    box-shadow: 3px 0 12px rgba(0,0,0,0.1);
}

    .sidebar-toggle:hover {
        background: rgba(240,244,255,0.9);
        box-shadow: 3px 0 16px rgba(30,58,110,0.15);
    }

.sources-toggle {
    display: none;
    right: 0;
    border-radius: 14px 0 0 14px;
    border-right: none;
    box-shadow: -3px 0 12px rgba(0,0,0,0.1);
}

    .sources-toggle:hover {
        background: rgba(240,244,255,0.9);
        box-shadow: -3px 0 16px rgba(30,58,110,0.15);
    }
/* 箭頭方向：aria-expanded="false" 時只旋轉箭頭（圖示不動） */
#sidebarToggle[aria-expanded="false"] .pill-arrow {
    transform: rotate(180deg);
}

#sourcesToggle[aria-expanded="false"] .pill-arrow {
    transform: rotate(180deg);
}
/* 收合右側資料來源：width 設為 0，opacity fade out */
.chat-layout.sources-collapsed .qa-group-sources {
    width: 0;
    opacity: 0;
    margin-left: 0;
    pointer-events: none;
}

/* ===== Modals ===== */
.chat-modal-overlay {
    display: none;
    position: fixed;
    inset: 0;
    background: rgba(0,0,0,0.35);
    z-index: 1000;
    align-items: flex-start;
    justify-content: center;
    padding-top: 80px;
}

    .chat-modal-overlay.active {
        display: flex;
    }

.chat-modal {
    background: #fff;
    border-radius: 8px;
    width: 90%;
    max-width: 680px;
    max-height: 75vh;
    overflow-y: auto;
    padding: 32px 36px;
    position: relative;
}

.chat-modal-close {
    position: absolute;
    top: 14px;
    right: 18px;
    font-size: 22px;
    color: #9ca3af;
    cursor: pointer;
    background: none;
    border: none;
}

    .chat-modal-close:hover {
        color: #374151;
    }

.chat-modal-title {
    font-size: 18px;
    font-weight: 600;
    color: #1f2937;
    text-align: center;
    margin-bottom: 24px;
}

.chat-modal-section-title {
    font-size: 16px;
    font-weight: 600;
    color: #1e3a6e;
    margin: 20px 0 10px;
}

.chat-modal-list {
    list-style: none;
    padding: 0;
    margin: 0;
}

    .chat-modal-list li {
        display: flex;
        gap: 10px;
        font-size: 14px;
        color: #374151;
        line-height: 1.7;
        margin-bottom: 8px;
    }

        .chat-modal-list li::before {
            content: '■';
            color: #1f2937;
            flex-shrink: 0;
            margin-top: 1px;
        }

        .chat-modal-list li > span {
            flex: 1;
            min-width: 0;
        }

.chat-modal-sublist {
    list-style: none;
    padding: 4px 0 2px 0;
    margin: 0;
}

    .chat-modal-sublist > li {
        display: flex;
        gap: 8px;
        font-size: 13px;
        color: #374151;
        line-height: 1.6;
        margin-bottom: 4px;
        padding-left: 8px;
    }

        .chat-modal-sublist > li::before {
            content: '•';
            color: #6b7280;
            flex-shrink: 0;
        }

.chat-modal-list li.no-bullet::before {
    content: none;
}

.feedback-modal {
    max-width: 560px;
}

.feedback-modal-title {
    font-size: 17px;
    font-weight: 600;
    color: #1f2937;
    text-align: center;
    margin-bottom: 20px;
}

.feedback-sub-title {
    font-size: 15px;
    font-weight: 600;
    color: #1e3a6e;
    margin-bottom: 12px;
}

.feedback-textarea {
    width: 100%;
    height: 160px;
    border: 1px solid #d1d5db;
    border-radius: 4px;
    padding: 10px 12px;
    font-size: 14px;
    font-family: inherit;
    resize: none;
    outline: none;
    box-sizing: border-box;
}

    .feedback-textarea:focus {
        border-color: #1e3a6e;
    }

.feedback-btn-row {
    display: flex;
    gap: 12px;
    justify-content: center;
    margin-top: 20px;
}

.feedback-btn {
    padding: 10px 36px;
    border-radius: 4px;
    border: none;
    cursor: pointer;
    font-size: 15px;
    font-weight: 500;
    transition: opacity 0.2s;
}

    .feedback-btn:hover {
        opacity: 0.85;
    }

.feedback-btn-confirm {
    background: #1e60c8;
    color: #fff;
}

.feedback-btn-cancel {
    background: #3b82f6;
    color: #fff;
}
/* ===== 手機版右側 Sources Drawer ===== */
.mobile-sources-drawer {
    display: none; /* 桌機隱藏，手機由 media query 開啟 */
    position: fixed;
    right: 0;
    top: 50px;
    width: min(88vw, 340px);
    height: calc(100vh - 50px);
    background: #fff;
    z-index: 220;
    transform: translateX(100%);
    transition: transform 0.25s ease;
    overflow-y: auto;
    box-shadow: -4px 0 20px rgba(0,0,0,0.15);
    border-left: 1px solid #e5e7eb;
}

    .mobile-sources-drawer.open {
        transform: translateX(0);
    }

.mobile-sources-drawer-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 14px 16px;
    border-bottom: 1px solid #e5e7eb;
    font-weight: 600;
    font-size: 15px;
    color: #1f2937;
    position: sticky;
    top: 0;
    background: #fff;
    z-index: 1;
}

.mobile-sources-drawer-close {
    border: none;
    background: none;
    cursor: pointer;
    color: #6b7280;
    padding: 4px;
    display: flex;
    align-items: center;
}

    .mobile-sources-drawer-close svg {
        width: 18px;
        height: 18px;
    }

@media (max-width: 767px) {
    .mobile-sources-drawer {
        display: block;
    }
    /* 手機版 inline sources 隱藏（改用 drawer 顯示） */
    .qa-group-sources {
        display: none !important;
    }
    /* Drawer 內的 clone 強制顯示 */
    #mobileSourcesBody .qa-group-sources {
        display: block !important;
    }
}

/* ===== 手機版 Overlay（抽屜式側欄背景遮罩） ===== */
.sidebar-overlay {
    display: none;
    position: fixed;
    inset: 0;
    background: rgba(0,0,0,0.4);
    z-index: 200;
}

    .sidebar-overlay.active {
        display: block;
    }

/* ===== RWD 斷點 ===== */

/* 手機：< 768px
           - 左側抽屜式 overlay（fixed 定位，展開後覆蓋主內容）
           - 右側資料來源收合
           - 主內容全寬
        */
@media (max-width: 767px) {
    /* 左側改為 fixed 抽屜式 */
    .chat-sidebar-wrap {
        position: fixed;
        top: 50px; /* header 高度 */
        left: 0;
        height: calc(100vh - 50px);
        z-index: 210;
        /* 初始收合：translate 到畫面左側外 */
        transform: translateX(-100%);
        transition: transform 0.25s ease;
    }

        .chat-sidebar-wrap.mobile-open {
            transform: translateX(0);
        }

    .chat-sidebar {
        width: 240px; /* 手機版抽屜稍寬 */
        height: 100%;
        overflow-y: auto;
        border-right: 1px solid #e5e7eb;
        box-shadow: 2px 0 12px rgba(0,0,0,0.15);
    }
    /* 手機版 sidebar 收合後 sidebar-wrap.collapsed 的 CSS 不適用，改用 translate */
    .chat-sidebar-wrap.collapsed .chat-sidebar {
        width: 240px; /* 覆蓋桌機收合樣式 */
        border-right: 1px solid #e5e7eb;
    }
    /* 手機版：顯示左右固定浮動按鈕 */
    .sidebar-toggle,
    .sources-toggle {
        display: flex;
    }
    /* 手機版：來源改為內嵌垂直排列（在 AI 回覆下方） */
    .qa-group {
        flex-direction: column;
    }

    .qa-group-sources {
        width: 100% !important;
        opacity: 1 !important;
        margin-left: 0 !important;
        pointer-events: auto !important;
        border-left: none;
        border-top: 1px solid #e5e7eb;
        margin-top: 12px;
        position: static; /* 覆蓋桌機 sticky */
    }
    /* 來源全局收合時，手機版也隱藏 */
    .chat-layout.sources-collapsed .qa-group-sources {
        display: none;
    }
    /* sources-toggle 已用 fixed，wrap 不需要佔位 */
    .sources-toggle-wrap {
        display: none;
    }
    /* toolbar 的 mobile-only 按鈕保持隱藏（已由固定浮動 pill 取代） */
    /* 手機版輸入區左右 padding 縮小 */
    .chat-input-area {
        padding: 8px 12px 16px;
    }

    .chat-messages {
        padding: 8px 12px 16px;
    }

    .chat-toolbar {
        padding-left: 12px;
    }
}

/* 平板（768-1023px）：顯示兩個固定浮動按鈕，右側面板預設收合 */
@media (min-width: 768px) and (max-width: 1023px) {
    .sidebar-toggle,
    .sources-toggle {
        display: flex;
    }

    .sources-toggle-wrap {
        display: none;
    }
    /* 收合時完全隱藏（width:0 不消高度，會在主內容下方留空白） */
    .chat-layout.sources-collapsed .qa-group-sources {
        display: none;
    }
}

/* 極小螢幕（< 480px）：輸入框 placeholder 文字縮短 */
@media (max-width: 479px) {
    .msg-user-bubble {
        max-width: 80%;
        font-size: 14px;
    }

    .chat-banner-title {
        font-size: 16px;
        letter-spacing: 4px;
    }
}


/* 排序方式控制項 */
.related-reports-sort {
    margin-left: auto;
    display: flex;
    align-items: center;
    gap: 10px;
    font-size: 13px;
    font-weight: 400;
}

    .related-reports-sort > svg {
        width: 15px;
        height: 15px;
        color: #6b7280;
        flex-shrink: 0;
    }

.rr-sort-opt {
    display: inline-flex;
    align-items: center;
    gap: 4px;
    color: #6b7280;
    cursor: pointer;
    padding-bottom: 2px;
    border-bottom: 2px solid transparent;
    user-select: none;
    transition: color 0.15s, border-color 0.15s;
}

    .rr-sort-opt svg {
        width: 14px;
        height: 14px;
        color: inherit;
        flex-shrink: 0;
    }

    .rr-sort-opt:hover {
        color: #1f2937;
    }

    .rr-sort-opt.active {
        color: #1e3a6e;
        font-weight: 600;
        border-bottom-color: #1e3a6e;
    }