/* css/style.css */

/* --- 通用樣式 --- */
body, html {
    margin: 0;
    padding: 0;
    height: 100%;
    font-family: Arial, sans-serif;
    display: flex;
    flex-direction: column;
}

.page {
    flex: 1;
    padding: 15px; /* 可以稍微減少頁面 padding */
    box-sizing: border-box;
    display: flex;
    flex-direction: column;
    /* overflow-y: auto;  <-- 移除 page 級的 overflow-y，讓子元素控制 */
    height: 100%; /* 確保 .page 也佔滿父容器高度 */
}

label {
    display: block;
    margin-top: 10px;
    margin-bottom: 5px;
}

input[type="text"], select, button, textarea {
    margin-top: 5px;
    padding: 8px;
    width: 100%;
    border-radius: 5px;
    border: 1px solid #ccc;
    box-sizing: border-box;
    font-size: 1rem;
}

button {
    cursor: pointer;
    border: none;
    margin-top: 10px; /* 統一按鈕頂部間距 */
}

/* --- 聊天頁面 (index.html) 特定樣式 --- */
.chat-page {
    background: linear-gradient(to right, #7BC6CC, #BE93C5);
    color: white;
}
.top-controls-area {
    flex-shrink: 0; /* 防止此區域被壓縮 */
    padding-bottom: 10px; /* 與對話列表的間距 */
}
.chat-page h1 {
    font-size: 1.5em; /* 縮小標題字體 */
    margin-top: 5px;  /* 減少頂部 margin */
    margin-bottom: 8px; /* 減少底部 margin */
}
.chat-page label, .chat-page h1 { /* 確保聊天頁的標籤和標題也是白色 */
    color: white;
}
.chat-page .hint {
    font-size: 0.8em; /* 縮小提示字體 */
    margin-top: 3px;
    color: #f0f0f0; /* 讓提示更柔和 */
}
.chat-page .nav-to-settings a {
    color: white;
    text-decoration: none;
    padding: 5px 10px;
    background-color: rgba(0,0,0,0.2);
    border-radius: 5px;
}
.chat-page .nav-to-settings {
    text-align: right;
    margin-bottom: 10px;
}
.chat-page label[for="configSelect"] {
    font-size: 0.9em; /* 縮小標籤字體 */
    margin-top: 5px;  /* 減少頂部 margin */
    margin-bottom: 3px; /* 減少底部 margin */
}
.chat-page select#configSelect,
.chat-page input[type="text"], /* 如果頂部有 input */
.chat-page textarea#userInput {
    margin-top: 3px;
    padding: 6px; /* 稍微減少 padding */
}
.conversation-list-container {
    flex-grow: 1; /* 這是關鍵，使其填充剩餘空間 */
    overflow-y: auto; /* 內容超出時滾動 */
    margin-bottom: 10px; /* 與輸入區域的間距 */
    border-radius: 5px;
    background-color: rgba(255, 255, 255, 0.85);
    color: black;
    padding: 10px;
    min-height: 100px; /* 設定一個最小高度，防止在內容很少時過於扁平 */
    position: relative; /* <--- 新增：為了絕對定位子元素 */
    padding-top: 40px; /* <--- 新增/調整：為右上角的按鈕留出空間 */
}

.conversation-item {
    margin-bottom: 10px;
    padding: 10px;
    border: 1px solid #ddd; /* 邊框顏色調整 */
    border-radius: 5px;
    position: relative;
    background-color: rgba(255, 255, 255, 0.7); /* 基礎背景 */
}

.conversation-item:nth-child(even) {
    background-color: rgba(240, 240, 240, 0.7); /* 偶數項背景 */
}

.conversation-item button.delete-button,
.conversation-item button.copy-button {
    background: none;
    border: none;
    cursor: pointer;
    font-size: 18px;
    position: absolute;
    bottom: 5px;
    width: 20px;
    height: 20px;
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: 50%;
    z-index: 1;
}
.conversation-item button.delete-button {
    color: red;
    right: 5px;
}
.conversation-item button.copy-button {
    color: #007bff;
    right: 30px;
}

.input-area {
    flex-shrink: 0; /* 防止此區域被壓縮 */
    display: flex;
    align-items: flex-end; /* 按鈕和輸入框底部對齊 */
    gap: 8px; /* 調整間隙 */
    margin-top: auto; /* 已有，保持 */
    padding-top: 8px; /* 減少與對話列表的間距 */
}
.input-area > div:first-child { /* 包裹 textarea 和 hint 的 div */
    flex-grow: 1; /* 讓它佔據更多空間 */
}
textarea#userInput {
    flex: 1; /* 已有 */
    height: 60px;    /* 縮小初始高度 */
    min-height: 40px; /* 縮小最小高度 */
    max-height: 120px;/* 縮小最大高度 */
    padding: 8px;    /* 調整 padding */
}

.action-buttons {
    display: flex;
    flex-direction: column;
    gap: 8px;
}

.action-buttons button {
    padding: 6px 8px; /* 縮小按鈕 padding */
    font-size: 0.9em; /* 縮小按鈕字體 */
    margin-top: 0;    /* 移除按鈕自身的 margin-top，由 gap 控制 */
    min-width: 100px; /* 調整最小寬度 */
}

.action-buttons .send-button {
    background-color: #dc3545; /* 更鮮明的紅色 */
    color: white;
}
.action-buttons .action-button {
    background-color: #28a745; /* 更鮮明的綠色 */
    color: white;
}

.delete-all-conversations {
    /* 移除之前的佈局樣式，因為它現在是絕對定位的 */
    /* text-align: right; (不再需要) */
    /* margin-bottom: 5px; (不再需要) */
    /* margin-top: -28px; (不再需要) */
    /* padding-right: 5px; (不再需要) */

    position: absolute;   /* <--- 新增：絕對定位 */
    top: 8px;             /* <--- 新增：距離頂部距離 (可調整) */
    right: 8px;           /* <--- 新增：距離右側距離 (可調整) */
    z-index: 10;          /* <--- 新增：確保在其他內容之上 */

}
.delete-all-conversations button {
    background: rgba(255, 0, 0, 0.1); /* 給按鈕一點背景，使其在對話背景上更明顯 */
    border: 1px solid rgba(255, 0, 0, 0.3);
    color: #ff0000ba;
    cursor: pointer;
    font-size: 16px; /* 可以根據需要調整大小 */
    width: 28px;     /* 調整按鈕大小 */
    height: 28px;    /* 調整按鈕大小 */
    display: inline-flex;
    align-items: center;
    justify-content: center;
    border-radius: 50%;
    padding: 0;
    line-height: 1; /* 確保 "X" 垂直居中 */
}
.delete-all-conversations button:hover {
    background: rgba(255, 0, 0, 0.2);
    color: #ff0000;
}


code {
    background-color: #282c34; /* 暗色背景 */
    color: #abb2bf;    /* 淺色文字 */
    font-family: 'SFMono-Regular', Consolas, 'Liberation Mono', Menlo, Courier, monospace;
    padding: 10px 15px; /* 調整 padding */
    border-radius: 5px;
    display: block;
    white-space: pre-wrap;
    overflow-x: auto;
    position: relative;
    font-size: 0.9em; /* 調整程式碼字體大小 */
    border: 1px solid #3c4048;
}
/* 確保 pre 標籤也有良好樣式 */
pre {
    margin: 1em 0;
    background-color: #282c34;
    padding: 0; /* pre 的 padding 設為0，由 code 控制 */
    border-radius: 5px;
    position: relative; /* For copy button */
}
pre > code { /* 如果 code 在 pre 裡面，調整樣式 */
    padding: 1em; /* 讓 pre 內的 code 有 padding */
    border: none;
    background-color: transparent; /* 繼承 pre 的背景 */
}

button.copy-code-button { /* 程式碼複製按鈕 */
    background: rgba(255,255,255,0.1);
    border: 1px solid rgba(255,255,255,0.2);
    color: #fff;
    cursor: pointer;
    font-size: 16px; /* 調整大小 */
    position: absolute;
    top: 8px;
    right: 8px;
    width: 28px; /* 調整大小 */
    height: 28px; /* 調整大小 */
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: 4px; /* 圓角調整 */
    z-index: 1;
    opacity: 0.7;
    transition: opacity 0.2s;
}
pre:hover button.copy-code-button {
    opacity: 1;
}


/* --- 設定頁面 (settings.html) 特定樣式 --- */
.settings-page {
    background-color: #f8f9fa; /* 更亮的背景色 */
    color: #212529; /* 深色文字 */
}

.settings-page input[type="text"], .settings-page select {
    max-width: 400px; /* 增加設定頁輸入框最大寬度 */
}
.settings-page button {
    background-color: #007bff;
    color: white;
    max-width: 200px; /* 設定按鈕最大寬度 */
}
.settings-page button:hover {
    background-color: #0056b3;
}

.config-list-container {
    margin-top: 30px;
}

.config-item {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 8px;
    border: 1px solid #ced4da; /* 邊框顏色調整 */
    border-radius: 5px;
    padding: 12px; /* 增加 padding */
    background-color: #fff;
    box-shadow: 0 1px 3px rgba(0,0,0,0.05); /* 細微陰影 */
}
.config-item-details {
    flex-grow: 1;
    cursor: pointer;
    color: #495057;
}
.config-item button.delete-config-btn {
    background: none;
    border: none;
    color: #dc3545;
    cursor: pointer;
    font-size: 1.2em;
    padding: 5px;
    margin: 0 0 0 10px;
}
.config-item button.delete-config-btn:hover {
    color: #c82333;
}


.nav-to-chat a {
    color: #007bff;
    text-decoration: none;
    padding: 8px 12px;
    background-color: #e9ecef;
    border-radius: 5px;
    border: 1px solid #ced4da;
    display: inline-block; /* 讓 padding 生效 */
}
.nav-to-chat a:hover {
    background-color: #dee2e6;
    text-decoration: none;
}
.settings-page .nav-to-chat { /*特定於設定頁的導航樣式 */
    margin-bottom: 25px;
}


/* --- 載入指示器樣式 (通用) --- */
.loading-indicator {
    display: none;
    position: fixed;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    background-color: rgba(0, 0, 0, 0.75);
    color: white;
    padding: 25px;
    border-radius: 10px;
    z-index: 10000;
    text-align: center;
    box-shadow: 0 5px 15px rgba(0,0,0,0.3);
}
.loading-indicator.show {
    display: block;
}
.talking-head {
    font-size: 48px; /* 放大 */
    margin-bottom: 15px;
}
.loading-indicator div:last-child { /* Loading text */
    font-size: 1.1em;
}
.dots::after {
    content: '';
    animation: dots 1.5s steps(4, end) infinite;
}
@keyframes dots {
    0%, 20% { content: ''; }
    40% { content: '.'; }
    60% { content: '..'; }
    80% { content: '...'; }
}
.loading { /* 禁用狀態的元素 */
    opacity: 0.5; /* 更明顯的禁用效果 */
    cursor: not-allowed !important;
}

/* --- Agent 工具授權與執行紀錄 --- */
.conversation-item.tool-approval {
    border: 1px solid #ffcc00;
    background-color: rgba(255, 204, 0, 0.12);
    border-radius: 5px;
}

.tool-approval-body {
    padding: 10px;
    font-size: 0.92em;
    line-height: 1.5;
    word-break: break-word;
}

.tool-approval-body code {
    display: inline;
    padding: 2px 4px;
    font-size: 0.95em;
    white-space: pre-wrap;
    word-break: break-all;
}

.tool-approval-note {
    padding: 0 10px 8px 10px;
    font-size: 0.85em;
    color: #b36b00;
}

.tool-approval-buttons {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
    padding: 0 10px 10px 10px;
}

.tool-approval-buttons button {
    margin: 0;
    padding: 6px 12px;
    border: none;
    border-radius: 4px;
    color: white;
    cursor: pointer;
    font-size: 0.9em;
}

.tool-approval-buttons button:disabled {
    cursor: default;
    opacity: 0.7;
}

.tool-approval-buttons .tool-approve { background-color: #4CAF50; }
.tool-approval-buttons .tool-always  { background-color: #2196F3; }
.tool-approval-buttons .tool-stop    { background-color: #ff9800; }
.tool-approval-buttons .tool-deny    { background-color: #f44336; }

/* 工具執行紀錄：與思考區塊區隔，用灰藍色系表示這是系統動作而非模型發言 */
.conversation-item.agent-step {
    border-left: 3px solid #607d8b;
    background-color: rgba(96, 125, 139, 0.08);
}

.conversation-item.agent-step summary {
    cursor: pointer;
    font-size: 0.9em;
    opacity: 0.85;
}

/* --- 「所以呢？」對話式知識內化 --- */
.sowhat-thread {
    position: relative;
    padding-top: 18px;
}

.sowhat-thread > button.sowhat-thread-delete {
    background: none;
    border: none;
    color: red;
    cursor: pointer;
    font-size: 18px;
    position: absolute;
    top: 0;
    right: 6px;
    width: 20px;
    height: 20px;
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: 50%;
    padding: 0;
    margin: 0;
    z-index: 2;
}

.sowhat-thread-details {
    border: 1px solid #ccc;
    border-radius: 5px;
    background-color: rgba(255, 255, 255, 0.6);
    padding: 8px 10px;
    margin-bottom: 10px;
}

.sowhat-thread-details > summary {
    cursor: pointer;
    font-weight: bold;
    color: #6a4c93;
    word-break: break-word;
}

/* 摺疊後裡面的訊息框不用再各自畫框，省得層層疊框 */
.sowhat-thread-details .conversation-item {
    border: none;
    padding: 6px 0;
    margin-bottom: 0;
    background: none;
}

.sowhat-thread-details[open] > summary {
    margin-bottom: 6px;
    border-bottom: 1px solid #eee;
    padding-bottom: 6px;
}

.conversation-item.sowhat-item {
    padding-bottom: 16px;
    margin-bottom: 16px;
}

.sowhat-source {
    margin: 0 0 6px 0;
    padding-left: 8px;
    border-left: 3px solid #bbb;
    color: #555;
    font-size: 0.92em;
    white-space: pre-wrap;
    word-break: break-word;
}

.sowhat-source-meta {
    color: #888;
    font-size: 0.85em;
}

/* 選項鈕要蓋過 .delete-button（絕對定位、z-index:1），
   否則會被上一則訊息突出來的刪除鈕壓住 */
.sowhat-options {
    display: flex;
    flex-wrap: wrap;
    align-items: flex-start;
    gap: 6px;
    margin-top: 8px;
    position: relative;
    z-index: 2;
}

.sowhat-options.answered { opacity: 0.5; }

button.sowhat-option {
    /* margin 必須歸零：全域的 `select, input, button` 規則會塞 5px 進來，
       和 flex gap 疊加後整組選項會被撐高 */
    margin: 0;
    padding: 6px 10px;
    font-size: 0.9em;
    border: 1px solid #007bff;
    background-color: #fff;
    color: #007bff;
    border-radius: 14px;
    cursor: pointer;
    width: auto;
    max-width: 100%;
    white-space: normal;
    text-align: left;
    line-height: 1.3;
}

button.sowhat-option:hover:not(:disabled) {
    background-color: #007bff;
    color: #fff;
}

button.sowhat-option-exit {
    border-color: #888;
    color: #666;
}

button.sowhat-option-exit:hover:not(:disabled) {
    background-color: #888;
    color: #fff;
}

.sowhat-freetext {
    display: flex;
    gap: 6px;
    width: 100%;
    margin-top: 4px;
}

.sowhat-freetext input {
    flex: 1;
    min-width: 0;
    width: auto;
    margin: 0;
    padding: 6px 8px;
    border: 1px solid #ccc;
    border-radius: 14px;
}

.sowhat-title {
    font-weight: bold;
    margin-bottom: 6px;
}

.sowhat-takeaway { margin-bottom: 8px; }

.sowhat-note {
    color: #a06000;
    font-size: 0.85em;
    margin: 4px 0;
    word-break: break-word;
}

.sowhat-tags {
    color: #007bff;
    font-size: 0.85em;
    margin-top: 6px;
}

.sowhat-open-questions {
    margin: 6px 0 0 0;
    padding-left: 20px;
    font-size: 0.9em;
}

.sowhat-raw-text {
    white-space: pre-wrap;
    word-break: break-word;
    font-size: 0.85em;
    background: rgba(0, 0, 0, 0.05);
    padding: 6px;
    border-radius: 4px;
}

.sowhat-edit-input {
    width: 100%;
    min-height: 80px;
    box-sizing: border-box;
    margin-bottom: 6px;
}

/* --- 卡片資料表覆蓋層 --- */
.sowhat-overlay {
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.45);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 1000;
    padding: 16px;
    box-sizing: border-box;
}

.sowhat-card-panel {
    background: #fff;
    color: #000;
    border-radius: 8px;
    width: 100%;
    max-width: 640px;
    max-height: 80vh;
    display: flex;
    flex-direction: column;
    padding: 12px;
    box-sizing: border-box;
    box-shadow: 0 4px 16px rgba(0, 0, 0, 0.3);
}

.sowhat-card-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 8px;
    margin-bottom: 8px;
}

.sowhat-card-list {
    flex: 1;
    overflow-y: auto;
    min-height: 0;
}

.sowhat-card-row {
    display: flex;
    align-items: flex-start;
    gap: 8px;
    padding: 8px 4px;
    border-bottom: 1px solid #eee;
    cursor: pointer;
}

.sowhat-card-row input.sowhat-card-check {
    width: auto;
    margin: 2px 0 0 0;
    flex: none;
}

.sowhat-card-body { min-width: 0; }

.sowhat-card-title {
    font-weight: bold;
    word-break: break-word;
}

.sowhat-card-meta {
    color: #888;
    font-size: 0.85em;
    word-break: break-word;
}

.sowhat-card-actions {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
    margin-top: 10px;
}

/* --- Web Share Target 的接收提示 --- */
.share-banner {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    justify-content: space-between;
    gap: 8px;
    margin-bottom: 8px;
    padding: 8px 10px;
    border: 1px solid #7BC6CC;
    border-radius: 5px;
    background-color: rgba(123, 198, 204, 0.18);
    font-size: 0.9em;
}

.share-banner-info {
    min-width: 0;
    flex: 1;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.share-banner-actions {
    display: flex;
    gap: 6px;
    flex: none;
}

.share-banner-actions button {
    margin: 0;
    padding: 5px 10px;
    border: none;
    border-radius: 4px;
    background-color: #6a4c93;
    color: white;
    cursor: pointer;
    font-size: 0.9em;
    width: auto;
}

.share-banner-actions button.share-banner-dismiss {
    background-color: #888;
}
