/* Reset CSS */
* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

body {
    background-color: #F7F8FC;
    font-family: Arial, sans-serif;
    height: 100vh;
    display: flex;
    flex-direction: column;
}

/* Header Styles */
header {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 85px;
    background-color: #ffffff;
    z-index: 1000;
    box-shadow: 0px 2px 5px rgba(0, 0, 0, 0.1);
    display: flex;
    align-items: center;
    padding: 0 20px;
}

.header-logo {
    width: 60px;
    height: 60px;
    margin-right: 20px;
    display: flex;
    align-items: center;
    justify-content: center;
}

.header-text {
    flex-grow: 1;
    display: flex;
    flex-direction: column;
    align-items: flex-end;
}

.main-title {
    text-align: right;
    font-size: 24px;
    font-weight: bold;
    color: #333;
    margin: 0;
}

.sub-title {
    text-align: right;
    font-size: 16px;
    color: #666;
    margin: 5px 0 0 0;
}

/* Container Layout */
.container {
    display: flex;
    height: calc(100vh - 85px);
    margin-top: 85px;
    padding: 0 20px;
    position: relative;
}

/* Chat Area Styles */
.chat-area {
    flex: 1;
    display: flex;
    flex-direction: column;
    position: relative;
    height: 100%;
    background-color: #ffffff;
    border-radius: 10px;
    box-shadow: 0 2px 10px rgba(0, 0, 0, 0.1);
    margin-right: 20px;
}

.chat-history {
    flex-grow: 1;
    overflow-y: auto;
    padding: 20px;
    margin-bottom: 80px;
}

/* Message Styles */
.message {
    margin: 10px 0;
    max-width: 80%;
}

.user {
    text-align: right;
    margin-left: auto;
}

.user p {
    background-color: #E3F2FD;
    padding: 15px 20px;
    border-radius: 15px 15px 0 15px;
    font-size: 16px;
    line-height: 1.5;
    color: #333;
    display: inline-block;
    text-align: left;
    white-space: pre-wrap;
    word-wrap: break-word;
}

.assistant {
    display: flex;
    align-items: flex-start;
}

.assistant p {
    background-color: #F5F5F5;
    padding: 15px 20px;
    border-radius: 15px 15px 15px 0;
    font-size: 16px;
    line-height: 1.5;
    color: #333;
    margin-left: 10px;
    display: inline-block;
    white-space: pre-wrap;
    word-wrap: break-word;
}

/* Chat Form Styles */
#chat-form {
    position: absolute;
    bottom: 0;
    left: 0;
    right: 0;
    padding: 20px;
    background-color: #ffffff;
    border-top: 1px solid #eee;
    display: flex;
    align-items: center;
    gap: 10px;
}

.user-input {
    flex-grow: 1;
    padding: 12px 15px;
    border: 1px solid #E0E0E0;
    border-radius: 25px;
    font-size: 16px;
    outline: none;
    transition: border-color 0.3s;
}

.user-input:focus {
    border-color: #2196F3;
}

.send-button, #recordingBtn {
    width: 45px;
    height: 45px;
    border-radius: 50%;
    border: none;
    background-color: #2196F3;
    color: white;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: background-color 0.3s;
}

.send-button:hover, #recordingBtn:hover {
    background-color: #1976D2;
}

/* Sidebar Styles */
.sidebar {
    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 {
    width: 345px;
}

.sidebar h3 {
    padding: 20px;
    margin: 0;
    border-bottom: 1px solid #eee;
    color: #333;
}

#search-results {
    padding: 20px;
    height: calc(100% - 60px);
    overflow-y: auto;
}

/* 側邊欄切換按鈕 */
.sidebar-toggle {
    position: absolute;
    right: 0;
    top: 50%;
    transform: translateY(-50%);
    width: 30px;
    height: 60px;
    background: #2196F3;
    border: none;
    border-radius: 15px 0 0 15px;
    color: white;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    box-shadow: -2px 0 5px rgba(0, 0, 0, 0.1);
    z-index: 1000;
    transition: all 0.3s ease;
}

.sidebar-toggle:hover {
    background: #1976D2;
}

.sidebar-toggle i {
    font-size: 14px;
    transition: transform 0.3s ease;
}

.sidebar.expanded ~ .sidebar-toggle {
    right: 390px;
}

.sidebar.expanded ~ .sidebar-toggle i {
    transform: rotate(180deg);
}

/* 搜尋結果樣式 */
.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: center;
  align-items: center;
  padding: 8px;
}

.loading-gif {
  width: 360px;        /* 寬度可依比例調整，80px 通常適中 */
  height: auto;       /* 保持原始高寬比例 */
  display: block;
  
}

.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) {
    .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);
}

.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;
}
/* 右欄檔案卡片樣式 
.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 產生的表格 */
.message .md ul { margin: .25rem 0 .5rem 1.1rem; line-height: 1.6; }
.message .md li { margin: .1rem 0; }
.message .md table { border-collapse: collapse; margin: .25rem 0; max-width: 100%; }
.message .md th, .message .md td { border: 1px solid #e5e7eb; padding: .5rem .625rem; }
.message .md thead th { background: #f8fafc; font-weight: 600; }
pre.ascii-table { font-family: ui-monospace, SFMono-Regular, Menlo, monospace; background:#fafafa; padding:8px 10px; border-radius:8px; overflow:auto; }
/* 助手訊息內的 Markdown 樣式微調 */
.message .md h3 {
  margin: .6rem 0 .35rem;
  font-size: 1.05rem;
  line-height: 1.35;
}
.message .md p {
  margin: .25rem 0 .25rem;
}
.message .md ul, 
.message .md ol {
  margin: .25rem 0 .35rem 1.25rem;
}

/* ASCII 表格退場機制用等寬字體 */
.ascii-table { 
  white-space: pre-wrap;
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, "Liberation Mono", monospace;
  font-size: 0.95rem;
}
/* 統一訊息內容容器（文字或表格都放這） */
.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; }
