/* Reset CSS */
* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

body {
    background:
        radial-gradient(circle at 50% 38%, rgba(232, 239, 250, 0.78) 0%, rgba(255, 255, 255, 0.96) 32%, #ffffff 72%),
        linear-gradient(180deg, #ffffff 0%, #fcfdff 100%);
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Helvetica, Arial, sans-serif;
    font-size: 15px;
    line-height: 1.6;
    color: #0d0d0d;
    height: 100vh;
    display: flex;
    flex-direction: column;
}

/* Center watermark */
.qa-watermark {
    position: fixed;
    top: 43%;
    left: 50%;
    transform: translate(-50%, -50%);
    z-index: 1;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 40px;
    opacity: 0.115;
    pointer-events: none;
    user-select: none;
    white-space: nowrap;
    width: max-content;
    max-width: 90vw;
}

.header-logo {
    width: 228px;
    height: 228px;
    margin-right: 0;
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
}

.header-logo img {
    width: 100%;
    height: 100%;
    object-fit: contain;
}

.brand-mark {
    display: flex;
    flex-direction: column;
    align-items: flex-start;
    justify-content: center;
    line-height: 0.88;
}

.main-title {
    text-align: left;
    font-family: Georgia, 'Times New Roman', serif;
    font-size: 132px;
    font-weight: 500;
    color: #56729b;
    margin: 0;
    letter-spacing: -4px;
}

.brand-subtitle {
    margin-top: 8px;
    font-family: Georgia, 'Times New Roman', serif;
    font-size: 74px;
    font-weight: 400;
    color: #6f86aa;
    letter-spacing: -1px;
}

/* Container Layout */
.container {
    display: flex;
    height: 100vh;
    margin-top: 0;
    padding: 0;
    position: relative;
    justify-content: center;
    width: 100%;
    overflow: hidden;
    z-index: 2;
}

/* 獨立 Scrollbar 容器 */
.scrollbar-track {
    position: fixed;
    right: 0;
    top: 0;
    bottom: 0;
    width: 8px;
    background: transparent;
    z-index: 98;
    cursor: grab;
}

.scrollbar-thumb {
    position: absolute;
    right: 0;
    width: 8px;
    background-color: #ccc;
    border-radius: 4px;
    cursor: grab;
    opacity: 0.7;
    transition: opacity 0.3s;
}

.scrollbar-thumb:hover {
    opacity: 1;
    background-color: #999;
}

.scrollbar-thumb:active {
    cursor: grabbing;
}

/* Chat Area Styles */
.chat-area {
    flex: 1;
    display: flex;
    flex-direction: column;
    position: relative;
    height: 100%;
    background-color: transparent;
    border-radius: 0;
    box-shadow: none;
    margin-right: 0;
    width: 100%;
    overflow: hidden;
    z-index: 2;
}

.chat-history {
    flex-grow: 1;
    overflow-y: scroll;
    overflow-x: hidden;
    padding: 24px 0 0;
    margin-bottom: 100px;
    max-width: 900px;
    width: 100%;
    margin-left: auto;
    margin-right: auto;
    scrollbar-width: none;
    /* 對話少的時候，訊息貼齊輸入框底部，空白留在最上面而不是卡在訊息和輸入框中間 */
    display: flex;
    flex-direction: column;
    justify-content: flex-end;
    position: relative;
    z-index: 2;
}

@media (max-width: 900px) {
    .qa-watermark {
        top: 36%;
        gap: 18px;
        opacity: 0.08;
        max-width: 94vw;
    }

    .header-logo {
        width: 120px;
        height: 120px;
    }

    .main-title {
        font-size: 68px;
        letter-spacing: -2px;
    }

    .brand-subtitle {
        font-size: 36px;
    }
}

/* 隱藏 scrollbar，由頁面右邊的獨立 scrollbar 顯示 */
.chat-history::-webkit-scrollbar {
    display: none;
}

/* Message Styles */
.message {
    margin: 6px 0;
    max-width: 100%;
    padding: 0 16px;
    display: flex;
    justify-content: center;
}

.user {
    text-align: right;
    margin-left: auto;
    justify-content: flex-end;
    width: 100%;
}

.user p {
    background-color: #f0f0f0;
    padding: 8px 12px;
    border-radius: 12px;
    font-size: 15px;
    line-height: 1.5;
    color: #0d0d0d;
    display: inline-block;
    text-align: left;
    white-space: pre-wrap;
    word-wrap: break-word;
    max-width: 70%;
}

.assistant {
    display: flex;
    flex-direction: row;
    align-items: flex-start;
    gap: 10px;
    justify-content: flex-start;
    width: 100%;
}

.assistant .msg-wrapper {
    background-color: #ffffff;
    padding: 12px 15px;
    border-radius: 4px 16px 16px 16px;
    border: 1px solid #ececf1;
    font-size: 15px;
    line-height: 1.6;
    color: #0d0d0d;
    margin: 0;
    display: block;
    white-space: pre-wrap;
    word-wrap: break-word;
    flex: 1;
    max-width: 700px;
}

.assistant p {
    margin: 0;
    padding: 0;
    white-space: pre-wrap;
    word-wrap: break-word;
}

/* 助手訊息前方的頭像徽章（原本是裸露的 icon，改成小圓角色塊） */
.message.assistant > i {
    width: 30px;
    height: 30px;
    min-width: 30px;
    border-radius: 9px;
    background: linear-gradient(155deg, #2196F3, #1c3d99);
    color: #ffffff;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 13px;
    margin-top: 2px;
}

/* 使用者訊息不需要頭像，泡泡已靠右對齊即可辨識 */
.message.user > i {
    display: none;
}

/* Chat Form Styles */
#chat-form {
    position: fixed;
    bottom: 18px;
    left: 50%;
    transform: translateX(-50%);
    width: 760px;
    max-width: calc(100% - 56px);
    padding: 10px 10px 10px 20px;
    background-color: rgba(255, 255, 255, 0.88);
    border: 1px solid rgba(210, 220, 235, 0.95);
    border-radius: 22px;
    box-shadow: 0 10px 28px rgba(32, 52, 84, 0.10);
    backdrop-filter: blur(10px);
    display: flex;
    align-items: flex-end;
    gap: 8px;
    z-index: 99;
}

.request-status {
    position: fixed;
    left: 50%;
    bottom: 86px;
    transform: translateX(-50%);
    width: 900px;
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 10px 14px;
    border: 1px solid #d5d5d5;
    border-radius: 10px;
    background: rgba(255, 255, 255, 0.96);
    color: #444;
    box-shadow: 0 6px 20px rgba(0, 0, 0, 0.06);
    z-index: 98;
}

.request-status[hidden] {
    display: none !important;
}

.request-status-spinner {
    width: 16px;
    height: 16px;
    border: 2px solid #d9d9d9;
    border-top-color: #0d0d0d;
    border-radius: 50%;
    animation: request-status-spin 0.8s linear infinite;
    flex-shrink: 0;
}

.request-status-text {
    font-size: 14px;
    line-height: 1.4;
}

@keyframes request-status-spin {
    from {
        transform: rotate(0deg);
    }
    to {
        transform: rotate(360deg);
    }
}

.user-input {
    flex-grow: 1;
    padding: 12px 10px;
    border: none;
    border-radius: 22px;
    font-size: 15px;
    outline: none;
    background-color: transparent;
    font-family: inherit;
    resize: none;
    max-height: 150px;
}

.user-input:focus {
    box-shadow: none;
}

.send-button, #recordingBtn {
    width: 40px;
    height: 40px;
    border-radius: 50%;
    border: none;
    background-color: transparent;
    color: #6b7280;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all 0.2s;
    flex-shrink: 0;
    font-size: 17px;
}

.send-button:hover, #recordingBtn:hover {
    background-color: #f0f2f7;
}

.send-button:active, #recordingBtn:active {
    background-color: #e5e8f0;
}

#sendBtn {
    background: linear-gradient(180deg, #4a8ef7 0%, #2d6fe0 100%);
    color: #ffffff;
}

#sendBtn:hover {
    background: linear-gradient(180deg, #3f84ef 0%, #2467da 100%);
    transform: scale(1.05);
}

#recordingBtn.recording {
    background-color: #e0453f;
    color: #ffffff;
    animation: mic-recording-pulse 1.1s infinite;
}

@keyframes mic-recording-pulse {
    0% { box-shadow: 0 0 0 0 rgba(224, 69, 63, 0.45); }
    70% { box-shadow: 0 0 0 8px rgba(224, 69, 63, 0); }
    100% { box-shadow: 0 0 0 0 rgba(224, 69, 63, 0); }
}

/* AI Disclaimer Styles */
.ai-disclaimer {
    position: fixed;
    bottom: -10px;
    left: 50%;
    transform: translateX(-50%);
    width: 760px;
    max-width: calc(100% - 56px);
    padding: 6px 16px;
    font-size: 12px;
    color: #7c8592;
    text-align: center;
    background-color: transparent;
    border-top: none;
    z-index: 100;
    height: auto;
    display: flex;
    align-items: center;
    justify-content: center;
}

/* Sidebar Styles */
.sidebar {
    display: none !important;
    width: 0;
    position: relative;
    background: #ffffff;
    border-radius: 10px;
    box-shadow: 0 2px 10px rgba(0, 0, 0, 0.1);
    overflow: hidden;
    transition: width 0.3s ease;
    height: 100%;
    margin-right: 30px;
    overflow-y: auto; 
}

.sidebar.expanded {
    display: none !important;
    width: 0;
}

.sidebar h3 {
    padding: 20px;
    margin: 0;
    border-bottom: 1px solid #eee;
    color: #333;
}

#search-results {
    padding: 20px;
    height: calc(100% - 60px);
    overflow-y: auto;
}



/* 搜尋結果樣式 */
.search-result {
    background: #F8F9FA;
    padding: 15px;
    margin-bottom: 15px;
    border-radius: 8px;
    border: 1px solid #E3F2FD;
    transition: all 0.3s ease;
    position: relative;
}

.search-result:hover {
    transform: translateY(-2px);
    box-shadow: 0 4px 12px rgba(0,0,0,0.1);
    border-color: #2196F3;
}

.search-result .content {
    font-size: 14px;
    line-height: 1.6;
    color: #333;
    margin: 10px 0;
    height: 10em;  /* 設置為5行高度 */
    overflow-y: auto;  /* 添加垂直滾動條 */
    padding-right: 10px;  /* 為滾動條預留空間 */
    white-space: pre-wrap;
    word-break: break-word;
}

/* 自定義滾動條樣式 */
.search-result .content::-webkit-scrollbar {
    width: 6px;
}

.search-result .content::-webkit-scrollbar-track {
    background: #f1f1f1;
    border-radius: 3px;
}

.search-result .content::-webkit-scrollbar-thumb {
    background: #2196F3;
    border-radius: 3px;
}

.search-result .content::-webkit-scrollbar-thumb:hover {
    background: #1976D2;
}

.search-result .similarity {
    color: #2196F3;
    font-weight: bold;
    font-size: 14px;
    margin-bottom: 8px;
}

.search-result .source-container {
    margin-top: 10px;
    padding-top: 8px;
    border-top: 1px solid #eee;
}
/* 圖片顯示*/
.response-image {
  max-width: 100%;
  width: 600px;     
  height: auto;
  border-radius: 8px;
  margin-top: 0.5rem;
  cursor: pointer;
  box-shadow: 0 2px 4px rgba(0, 0, 0, 0.1);
}
.search-result .source-link {
    display: inline-block;
    color: #2196F3;
    text-decoration: none;
    font-size: 14px;
    margin-bottom: 5px;
    padding: 4px 8px;
    background: #E3F2FD;
    border-radius: 4px;
    transition: all 0.2s ease;
    border: none;
    outline: none;
}
/* loading顯示*/
.loading-indicator {
  display: flex;
  justify-content: flex-start;
  align-items: center;
  padding: 12px 0;
  margin: 0;
}

.loading-dots {
  display: flex;
  align-items: center;
  gap: 4px;
  margin-left: 10px;
}

.dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background-color: #d1d5db;
  animation: pulse 1.4s infinite;
}

.dot:nth-child(2) {
  animation-delay: 0.2s;
}

.dot:nth-child(3) {
  animation-delay: 0.4s;
}

@keyframes pulse {
  0%, 100% {
    opacity: 0.4;
    transform: scale(0.8);
  }
  50% {
    opacity: 1;
    transform: scale(1);
  }
}

.search-result .source-link:hover {
    background: #2196F3;
    color: white;
}

.search-result .source-path {
    display: block;
    font-size: 12px;
    color: #666;
    word-break: break-all;
    margin-top: 5px;
    padding: 4px 8px;
    background: #f5f5f5;
    border-radius: 4px;
    font-family: monospace;
    border: none;
    outline: none;
}

/* 關鍵字標籤樣式 */
.search-result .keywords {
    margin-top: 8px;
    font-size: 12px;
    display: flex;
    flex-wrap: wrap;
    gap: 5px;
}

.search-result .keyword-tag {
    background: #E3F2FD;
    color: #2196F3;
    padding: 2px 8px;
    border-radius: 12px;
    display: inline-block;
}

.search-result .keyword-tag.related {
    background: #FFF3CD;
    color: #856404;
}

/* 高亮樣式 */
.highlight {
    background-color: #FFF3CD;
    padding: 2px 4px;
    border-radius: 3px;
    color: #856404;
    font-weight: 500;
}

/* 無結果樣式 */
.no-results {
    padding: 20px;
    background: #f8f9fa;
    border-radius: 8px;
    text-align: center;
    color: #666;
}

.no-results p {
    margin: 0 0 10px 0;
}

.no-results .suggestion {
    color: #2196F3;
    font-weight: bold;
}

.no-results ul {
    text-align: left;
    margin: 10px 0;
    padding-left: 20px;
}

.no-results li {
    margin: 5px 0;
}

/* 保留回應效果 */
.response-image {
    max-width: 100%;
    height: auto;
    border: 1px solid #ccc;
    margin-top: 10px;
    cursor: pointer;
    transition: transform 0.2s ease;
}

.image-container {
    margin-top: 10px;
    display: flex;
    flex-direction: column;
    align-items: flex-start;
}

.message.assistant {
    display: flex;
    flex-direction: column;
    align-items: flex-start;
}

.source-info {
    font-size: 0.9rem;
    color: #555;
    margin: 8px 0 16px 32px;
}

/* 動畫效果 */
@keyframes fadeIn {
    from {
        opacity: 0;
        transform: translateY(10px);
    }
    to {
        opacity: 1;
        transform: translateY(0);
    }
}

.message {
    animation: fadeIn 0.3s ease-out;
}

/* Image Modal Styles */
#imageModal {
    display: none;
    position: fixed;
    z-index: 9999;
    left: 0;
    top: 0;
    width: 100%;
    height: 100%;
    background-color: rgba(0, 0, 0, 0.9);
}

#imageModal img {
    max-width: 90%;
    max-height: 90vh;
    margin: auto;
    display: block;
    position: relative;
    top: 50%;
    transform: translateY(-50%);
}

#imageModal .close {
    position: absolute;
    top: 20px;
    right: 30px;
    color: #fff;
    font-size: 30px;
    cursor: pointer;
    transition: color 0.3s;
}

#imageModal .close:hover {
    color: #ccc;
}

/* Responsive Design */
@media (max-width: 768px) {
    #chat-form {
        bottom: 10px;
        max-width: calc(100% - 24px);
    }

    .ai-disclaimer {
        bottom: -10px;
        max-width: calc(100% - 24px);
        padding: 4px 10px;
    }

    .container {
        flex-direction: column;
        padding: 10px;
    }

    .chat-area {
        margin-right: 0;
        margin-bottom: 20px;
    }

    .sidebar {
        height: 300px;
    }
}

@media (max-width: 480px) {
    .main-title {
        font-size: 20px;
    }

    .chat-history {
        padding: 10px;
    }

    .message {
        max-width: 90%;
    }

    #chat-form {
        padding: 10px;
    }
}
.modal {
  position: fixed;
  z-index: 1000;
  left: 0; top: 0;
  width: 100%; height: 100%;
  overflow: auto;
  background-color: rgba(0,0,0,0.6);
}

/* 預覽模態框層級更高 */
#previewModal {
  z-index: 1001 !important;
}

#previewModal .modal-content {
  z-index: 1001 !important;
}

.modal-content {
  background-color: #fefefe;
  margin: 5% auto;
  padding: 15px;
  border: 1px solid #888;
  width: 80%;
  max-width: 900px;
  border-radius: 10px;
}

.modal-content .close {
  float: right;
  font-size: 24px;
  font-weight: bold;
  cursor: pointer;
}

/* 資料來源模態框特殊樣式 */
.source-modal-content {
  max-width: 1000px;
}

.modal-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  border-bottom: 2px solid #2196F3;
  padding-bottom: 15px;
  margin-bottom: 20px;
}

.modal-header h2 {
  margin: 0;
  color: #333;
  font-size: 20px;
}

.close-btn {
  font-size: 28px;
  font-weight: bold;
  color: #aaa;
  cursor: pointer;
  transition: color 0.3s;
}

.close-btn:hover {
  color: #000;
}

.modal-body {
  max-height: 600px;
  overflow-y: auto;
  padding: 10px 0;
}

/* 資料來源模態框內的檔案列表 */
.source-file-list {
  display: flex;
  flex-direction: column;
  gap: 12px;
  padding: 10px 0;
}

.source-file-card {
  background: #fff;
  border: 1px solid #e0e0e0;
  border-radius: 8px;
  padding: 12px 15px;
  display: flex;
  flex-direction: row;
  align-items: center;
  gap: 12px;
  transition: all 0.3s ease;
  box-shadow: 0 2px 4px rgba(0,0,0,0.05);
}

.source-file-card:hover {
  background: #f9fafb;
  box-shadow: 0 4px 8px rgba(0,0,0,0.1);
  border-color: #2196F3;
}

.source-file-thumb {
  width: 60px;
  height: 60px;
  min-width: 60px;
  object-fit: contain;
  border-radius: 6px;
  background: #f5f5f5;
}

.source-file-icon {
  font-size: 40px;
  color: #999;
  width: 60px;
  min-width: 60px;
  text-align: center;
}

.source-file-name {
  font-size: 14px;
  font-weight: 500;
  margin: 0;
  color: #333;
  flex: 1;
  word-break: break-word;
  line-height: 1.4;
}

.source-file-actions {
  display: flex;
  gap: 8px;
  margin: 0;
  flex-shrink: 0;
}

.source-file-btn {
  padding: 6px 12px;
  border: none;
  border-radius: 6px;
  font-size: 12px;
  cursor: pointer;
  transition: all 0.2s;
  white-space: nowrap;
}

.source-file-preview {
  background: #E3F2FD;
  color: #2196F3;
}

.source-file-preview:hover {
  background: #2196F3;
  color: white;
}

.source-file-download {
  background: #2196F3;
  color: white;
}

.source-file-download:hover {
  background: #1976D2;
}

/* ============ 分享模態框樣式 ============ */
#shareModal .modal-content {
  max-width: 400px;
}

.share-options {
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.share-option-btn {
  display: flex;
  align-items: center;
  gap: 15px;
  background: #f9fafb;
  border: 1px solid #e0e0e0;
  border-radius: 8px;
  padding: 15px;
  cursor: pointer;
  transition: all 0.3s ease;
  text-align: left;
}

.share-option-btn:hover {
  background: #f0f4f8;
  border-color: #2196F3;
  box-shadow: 0 2px 8px rgba(33, 150, 243, 0.15);
}

.share-option-btn:active {
  transform: scale(0.98);
}

.icon-box {
  font-size: 32px;
  color: #2196F3;
  min-width: 50px;
  display: flex;
  align-items: center;
  justify-content: center;
}

.text-box {
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.text-box .title {
  font-size: 14px;
  font-weight: 600;
  color: #333;
  display: block;
}

.text-box .desc {
  font-size: 12px;
  color: #999;
  display: block;
}

/* 回應訊息中的資料來源按鈕：改成淺色膠囊，跟內文分開 */
.source-button {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  margin-top: 10px;
  padding: 5px 12px;
  background: #E3F2FD;
  color: #1c3d99;
  border: 1px solid rgba(33, 150, 243, 0.35);
  border-radius: 999px;
  font-size: 12.5px;
  cursor: pointer;
  transition: all 0.15s ease;
  font-weight: 600;
}

.source-button:hover {
  background: #2196F3;
  color: #ffffff;
  transform: translateY(-1px);
  box-shadow: 0 4px 10px rgba(33, 150, 243, 0.25);
}

.source-button i {
  font-size: 13px;
}
/* 右欄檔案卡片樣式 
.file-item{
  display:flex;
  align-items:center;
  gap:10px;
  padding:8px 12px;
  border-bottom:1px solid #eee;
  cursor:pointer;
  transition:background .15s, transform .15s;
}
.file-item:hover{
  background:#f0f8ff;
  transform:scale(1.02);
}*/
.file-thumb {
  width: 96px;
  height: 96px;
  object-fit: contain;        /* ✅ 不再裁切 */
  background: #f8fafc;
  border: 1px solid #eef2ff;
  border-radius: 6px;
}
.file-icon {
  font-size: 48px;            /* ✅ icon 放大 */
  color: #6b7280;
}
.file-info{display:flex;flex-direction:column;flex:1;}
/*.file-name{font-size:.9rem;white-space:nowrap;overflow:hidden;text-overflow:ellipsis;}*/
.file-download{font-size:.8rem;color:#0d6efd;text-decoration:none;}
.file-download:hover{text-decoration:underline;}

/*.file-item {
  width: 220px;
  background: #fff;
  border: 1px solid #e6e8f0;
  border-radius: 10px;
  padding: 12px;
  margin: 12px;
  display: inline-flex;
  flex-direction: column;
  align-items: center;
  gap: 8px;
  box-shadow: 0 2px 6px rgba(0,0,0,.06);
  transition: box-shadow .2s ease;
  cursor: pointer;
  text-align: center;
}*/
.file-item:hover { box-shadow: 0 6px 18px rgba(0,0,0,.12); }
.file-name {
  font-size: 14px;
  font-weight: 500;
  margin: 6px 0 2px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  width: 100%;
}
.file-download {
  font-size: 12px;
  color: #0d6efd;
  text-decoration: none;
}
.file-download:hover { text-decoration: underline; }
/* =========================================
   修復後的 Markdown 樣式 (仿 ChatGPT/Gemini)
   ========================================= */

/* 1. 基礎容器設定：改回 normal 讓 HTML 標籤決定排版 */
.assistant .msg-wrapper {
    white-space: normal; /* 重要：因為 marked.js 已經轉成 HTML，不需要 pre-wrap */
    word-wrap: break-word;
    font-size: 15px;
    line-height: 1.7; /* 增加行距，閱讀更舒適 */
    color: #1f2937;   /* 深灰色，比純黑柔和 */
}

/* 2. 列表縮排修復 (關鍵) */
.assistant .msg-wrapper ul,
.assistant .msg-wrapper ol {
    margin: 0.8em 0;          /* 上下留白 */
    padding-left: 24px;       /* 左側內縮，讓圓點顯示出來 */
    list-style-position: outside; /* 圓點在文字外 */
}

.assistant .msg-wrapper li {
    margin-bottom: 0.4em;     /* 列表項目之間的距離 */
}

.assistant .msg-wrapper li > ul,
.assistant .msg-wrapper li > ol {
    margin: 0.4em 0;          /* 多層級列表的間距 */
}

/* 3. 段落與標題 */
.assistant .msg-wrapper p {
    margin-bottom: 1em;       /* 段落間距 */
}
/* 移除最後一個段落的 margin，避免對話框下方留白太多 */
.assistant .msg-wrapper p:last-child {
    margin-bottom: 0;
}

.assistant .msg-wrapper h1,
.assistant .msg-wrapper h2,
.assistant .msg-wrapper h3,
.assistant .msg-wrapper h4 {
    color: #111;
    font-weight: 600;
    margin-top: 1.5em;
    margin-bottom: 0.8em;
    line-height: 1.3;
}

/* 4. 程式碼區塊 (Code Block) */
.assistant .msg-wrapper pre {
    background-color: #f6f8fa; /* 淺灰背景 */
    border: 1px solid #e1e4e8;
    border-radius: 6px;
    padding: 16px;
    margin: 1em 0;
    overflow-x: auto;          /* 橫向捲動 */
    font-family: ui-monospace, SFMono-Regular, SF Mono, Menlo, Consolas, monospace;
    font-size: 13px;
    line-height: 1.5;
}

.assistant .msg-wrapper code {
    font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
    background-color: rgba(175, 184, 193, 0.2); /* 行內程式碼的淺灰底色 */
    padding: 0.2em 0.4em;
    border-radius: 6px;
    font-size: 85%;
    color: #24292f;
}

/* 避免 pre 裡面的 code 重複背景色 */
.assistant .msg-wrapper pre code {
    background-color: transparent;
    padding: 0;
    border-radius: 0;
    color: inherit;
    white-space: pre; /* 程式碼區塊保留格式 */
}

/* 5. 引用 (Blockquote) */
.assistant .msg-wrapper blockquote {
    border-left: 4px solid #dfe2e5;
    color: #6a737d;
    padding-left: 1em;
    margin: 1em 0;
}

/* 6. 表格樣式 */
.assistant .msg-wrapper table {
    border-collapse: collapse;
    width: 100%;
    margin: 1em 0;
    font-size: 14px;
}

.assistant .msg-wrapper th,
.assistant .msg-wrapper td {
    border: 1px solid #dfe2e5;
    padding: 6px 13px;
    line-height: 1.5;
}

.assistant .msg-wrapper th {
    background-color: #f6f8fa;
    font-weight: 600;
    text-align: left;
}

.assistant .msg-wrapper tr:nth-child(2n) {
    background-color: #fcfcfc;
}
/* 統一訊息內容容器（文字或表格都放這） */
.message .msg-content{
  display: inline-block;
  max-width: 100%;
  border-radius: 14px;
  padding: 12px 14px;
  background: #f6f8fb;               /* 助手泡泡底色 */
  overflow-x: auto;                   /* 表格太寬時水平捲動 */
}

/* 表格樣式（只影響聊天訊息中的表格） */
.message .msg-content table{
  width: 100%;
  border-collapse: collapse;
  table-layout: auto;
}
.message .msg-content th,
.message .msg-content td{
  border: 1px solid #e5e7eb;
  padding: 8px 10px;
  vertical-align: top;
}
.message .msg-content th{
  background: #eef2ff;
  font-weight: 600;
}
.message .msg-content td{
  word-break: break-word;             /* 長字分行，避免撐寬 */
}

.sidebar .file-item{
  display:flex;
  gap:12px;
  align-items:center;
  padding:10px 8px;
  border-radius:10px;
  transition: background .2s ease;
}
.sidebar .file-item:hover{ background:#f5f7fb; }

/* 縮圖大小與陰影 */
.sidebar .file-thumb{
  flex: 0 0 64px;
  width:64px;
  height:90px;
  object-fit:cover;
  border-radius:8px;
  box-shadow:0 2px 8px rgba(0,0,0,.08);
}

/* 檔名區域要能收縮，並做單行省略 */
.sidebar .file-info{
  flex: 1;
  min-width: 0;          /* 讓文字在 flex 內可縮，避免把縮圖擠掉 */
  display: flex;
  flex-direction: column;
  gap: 6px;
}
.sidebar .file-name{
  margin: 0 0 6px 0;
  line-height: 1.3;
  white-space: normal;           /* 允許換行 */
  overflow-wrap: anywhere;       /* 超長單字也可斷行 */
  word-break: break-word;        /* 備援 */
  display: -webkit-box;          /* 2–3 行截斷（含省略） */
  -webkit-box-orient: vertical;
  -webkit-line-clamp: 3;         /* 顯示 3 行 */
  line-clamp: 3;                 /* 新增標準屬性 line-clamp */
  overflow: hidden;
  max-height: calc(1.3em * 3);   /* Safari 備援，對齊 line-clamp 行高 */
}
/* 美化下載按鈕 */
/* 固定大小的下載按鈕 */
.sidebar .file-download{
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  width: 110px;          /* 固定寬度：依喜好可改 96/110/120px */
  height: 34px;          /* 固定高度 */
  padding: 0 12px;       /* 保留可點擊區，不影響高度 */
  border-radius: 999px;
  text-decoration: none;
  color: #fff;
  background: linear-gradient(180deg, #3b82f6, #2563eb);
  box-shadow: 0 6px 16px rgba(37,99,235,.35);
  transition: transform .12s ease, box-shadow .12s ease;
  flex: 0 0 auto;        /* 不要被擠壓 */
}
.sidebar .file-download:hover{
  transform: translateY(-1px);
  box-shadow: 0 10px 20px rgba(37,99,235,.45);
}
.sidebar .file-download i{ font-size:14px; }
.sidebar .file-download span{ line-height: 1; }

/* =========================================
   訊息操作按鈕與功能列
   ========================================= */

/* 1. 訊息內容與按鈕的垂直容器 */
.message-content-group {
    display: flex;
    flex-direction: column;
    max-width: 700px;
    width: 100%;
}

/* 2. 按鈕列容器：收成一顆置中膠囊，手機也容易點 */
.message-actions {
    display: flex;
    justify-content: center;
    align-items: center;
    gap: 2px;
    margin: 10px auto 0;
    padding: 3px;
    width: fit-content;
    max-width: 100%;
    background: #ffffff;
    border: 1px solid #ececf1;
    border-radius: 999px;
    flex-wrap: nowrap;
}

.message-actions .actions-divider {
    width: 1px;
    height: 16px;
    background: #ececf1;
    margin: 0 4px;
    flex-shrink: 0;
}

/* 滑鼠懸停時顯示按鈕 */

/* 手機版/觸控裝置總是顯示 */
@media (hover: none), (max-width: 768px) {
    .message-actions { opacity: 1; }
}

/* 3. 個別按鈕通用樣式：圓形小按鈕 */
.action-btn {
    background: transparent;
    border: none;
    color: #8e8ea0;
    cursor: pointer;
    width: 30px;
    height: 30px;
    padding: 0;
    font-size: 13px;
    border-radius: 50%;
    transition: all 0.2s;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    position: relative;
    flex-shrink: 0;
}

.action-btn:hover {
    background-color: #eaf0ff;
    color: #1c3d99;
}

/* 4. 朗讀中的特效 (紅色呼吸燈) */
.action-btn.speaking {
    color: #ef4444;
    background-color: #fee2e2;
    animation: speakingPulse 1.5s infinite;
}

@keyframes speakingPulse {
    0% { transform: scale(1); box-shadow: 0 0 0 0 rgba(239, 68, 68, 0.4); }
    70% { transform: scale(1); box-shadow: 0 0 0 6px rgba(239, 68, 68, 0); }
    100% { transform: scale(1); box-shadow: 0 0 0 0 rgba(239, 68, 68, 0); }
}

/* 5. 評價按鈕激活狀態 (藍色) */
.action-btn.active {
    color: #2196F3;
}

/* 6. 複製成功提示 (綠色) */
.copy-success {
    color: #10a37f !important;
}

/* 7. 停止生成按鈕 (紅色懸停) */
#stopBtn:hover {
    background-color: #fee2e2;
    color: #ef4444;
    border-color: #ef4444;
}

/* =========================================
   三點選單 (Action Menu)
   ========================================= */
.action-menu-container {
    position: relative;
    display: inline-block;
}

.action-menu {
    position: absolute;
    bottom: 100%;
    left: 0;
    background: #fff;
    border: 1px solid #ececf1;
    border-radius: 6px;
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.12);
    min-width: 140px;
    z-index: 1000;
    display: none;
    animation: slideUp 0.15s ease-out;
    margin-bottom: 5px;
}

.action-menu.show { display: block; }

.action-menu-item {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 8px 12px;
    background: transparent;
    border: none;
    color: #333;
    cursor: pointer;
    font-size: 13px;
    width: 100%;
    text-align: left;
    transition: all 0.15s;
    white-space: nowrap;
}

.action-menu-item:hover { background-color: #f5f5f5; }
.action-menu-item:first-child { border-radius: 6px 6px 0 0; }
.action-menu-item:last-child { border-radius: 0 0 6px 6px; }

@keyframes slideUp {
    from { opacity: 0; transform: translateY(4px); }
    to { opacity: 1; transform: translateY(0); }
}

/* =========================================
   分享選單 (Share Modal)
   ========================================= */
.share-options {
    display: flex;
    flex-direction: column;
    gap: 12px;
    padding: 10px 0;
}

.share-option-btn {
    display: flex;
    align-items: center;
    width: 100%;
    padding: 12px 16px;
    background-color: #fff;
    border: 1px solid #ececf1;
    border-radius: 8px;
    cursor: pointer;
    text-align: left;
    transition: all 0.2s ease;
}

.share-option-btn:hover {
    background-color: #f5f5f5;
    border-color: #2196F3;
    transform: translateY(-1px);
    box-shadow: 0 4px 6px rgba(0,0,0,0.05);
}

.share-option-btn .icon-box {
    width: 40px;
    height: 40px;
    border-radius: 50%;
    background-color: #E3F2FD;
    color: #2196F3;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 18px;
    margin-right: 15px;
    flex-shrink: 0;
}

.share-option-btn .text-box {
    display: flex;
    flex-direction: column;
}

.share-option-btn .title {
    font-size: 15px;
    font-weight: 600;
    color: #333;
    margin-bottom: 2px;
}

.share-option-btn .desc {
    font-size: 12px;
    color: #666;
}

/* =========================================
   版本切換控制器 (Version Control)
   ========================================= */
.version-controls {
    display: flex;
    align-items: center;
    gap: 8px;
    font-size: 13px;
    color: #555;
    margin-top: 8px;
    padding-left: 2px;
    font-family: monospace;
    user-select: none;
}

.version-btn {
    background: transparent;
    border: none;
    cursor: pointer;
    color: #555;
    padding: 2px 6px;
    border-radius: 4px;
    font-size: 14px;
    display: flex;
    align-items: center;
    justify-content: center;
}

.version-btn:hover {
    background-color: #e0e0e0;
    color: #000;
}

.version-btn:disabled {
    color: #ccc;
    cursor: not-allowed;
    background-color: transparent;
}

/* 隱藏時 */
.version-controls.hidden {
    display: none;
}
