:root {
    --editor-font-size: 16px;
    --editor-line-height: 1.6;
    --table-white-space: pre-wrap;
    --main-font: twhei-s, TWHEI, "台灣黑體", tauhu-oo, PingFangTC-Regular, "Microsoft JhengHei", sans-serif; 
    --ui-font: twhei-s, TWHEI, "台灣黑體", "Microsoft JhengHei", ui-sans-serif, system-ui, sans-serif;
	--row-num-valign: middle;
}

input, textarea, select, button {
    font-family: inherit;
}


body {
    font-family: var(--ui-font);
    background-color: #f3f4f6;
    margin: 0;
    height: 100vh; 
    height: 100dvh; 
    display: flex;
    flex-direction: column;
    overflow: hidden;
}

#mainContainer { 
    transition: max-width 0.3s ease, opacity 0.4s ease; 
    opacity: 0; 
}

.editor-wrapper {
    display: flex; flex: 1; background: #ffffff;
    border: 1px solid #d1d5db; border-radius: 0.5rem;
    overflow: hidden; box-shadow: 0 4px 6px -1px rgba(0, 0, 0, 0.1);
    position: relative;
}

input.code-text,
textarea.code-text,
select.code-text,
#batchTableBody td {
    font-family: var(--main-font) !important;
    font-size: var(--editor-font-size) !important;
    line-height: var(--editor-line-height) !important;
}

textarea#editor,
.line-numbers,
table#data-table td,
.td-inner {
    font-family: var(--main-font) !important;
    font-size: var(--editor-font-size);
    line-height: var(--editor-line-height);
}

table#data-table th {
    font-family: var(--ui-font) !important;
}


#textModeContainer { display: flex; flex: 1; width: 100%; height: 100%; overflow: hidden; }

#tableModeContainer { 
    display: none; flex: 1; width: 100%; height: 100%; 
    overflow: auto; background-color: #f8fafc; position: relative; 
    overscroll-behavior-x: contain; /* 新增這行：防止手機橫向滑動觸發上一頁 */
}

.line-numbers {
    width: 3rem; background-color: #f9fafb; color: #9ca3af; text-align: right;
    padding-right: 0.5rem; padding-top: 1rem; padding-bottom: 1rem;
    user-select: none; overflow: hidden; border-right: 1px solid #e5e7eb;
}
.line-number-item { display: flex; align-items: flex-start; justify-content: flex-end; }

textarea#editor {
    flex: 1; width: 100%; height: 100%; padding: 1rem; border: none; outline: none; resize: none;
    white-space: var(--table-white-space); word-break: break-all; overflow: auto;
}

/* ================= 表格進階樣式 ================= */
table#data-table { 
    border-collapse: separate; border-spacing: 0; 
    width: max-content; background-color: #ffffff; 
    table-layout: fixed; 
}

/* TD 左右各保留 12px 的透明空間作為防護選取區 */
table#data-table td { 
    border-right: 1px solid #cbd5e1; border-bottom: 1px solid #cbd5e1; 
    padding: 0 12px; /* 左右各 12px 透明空間 */
    vertical-align: top; 
    transition: none; /* 移除背景色漸變，讓選取反應零延遲 */
    overflow: hidden; 
}
table#data-table th { 
    border-right: 1px solid #cbd5e1; 
    border-bottom: 1px solid #cbd5e1;
    background-color: #f8fafc; /* 將背景稍微調淡一點，更接近純淨的灰色 */
    color: #475569; /* 字體顏色也稍微調淡，避免喧賓奪主 */
    font-weight: normal; /* �取消加粗，回歸正常粗細 */
    font-size: 14px; /* �縮小字體，標準試算表通常介於 12px~13px */
    text-align: center; 
    padding: 0.25rem 0.5rem;
    user-select: none; 
    position: relative; 
    white-space: nowrap; 
    cursor: pointer; 
    transition: none;
    min-width: 100px;
}

table#data-table th:hover { 
    background-color: #f1f5f9; /* 懸浮時的顏色稍微加深一點點 */
    color: #334155; /* 懸浮時字體稍微變深，增加互動感 */
}

table#data-table th.sticky-top { position: sticky; top: 0; z-index: 20; border-top: 1px solid #cbd5e1; }
table#data-table th.sticky-left { 
    position: sticky; 
    left: 0; 
    z-index: 20; 
    border-left: 1px solid #cbd5e1; 
    width: 4.5rem !important; 
    min-width: 4.5rem !important; 
    max-width: 4.5rem !important; 
    vertical-align: var(--row-num-valign) !important;
}
table#data-table th.sticky-corner { position: sticky; top: 0; left: 0; z-index: 30; border-top: 1px solid #cbd5e1; border-left: 1px solid #cbd5e1; width: 4.5rem !important; min-width: 4.5rem !important; max-width: 4.5rem !important; cursor: default; background-color: #f8fafc;}

/* 儲存格內部容器：隔離結構與文字 */
.td-inner {
    padding: 0.5rem 0; /* 左右 padding 交由 td 處理 */
    min-height: calc(var(--editor-line-height) * 1em + 1rem); 
    outline: none;
    white-space: var(--table-white-space);
    word-break: break-all;
    width: 100%;
    box-sizing: border-box;
}

/* 不換行模式 (No Wrap Mode) 強制單行與精準裁切 */
.table-nowrap .td-inner {
    display: -webkit-box !important; 
    -webkit-line-clamp: 1 !important; 
    -webkit-box-orient: vertical !important;
    white-space: pre-wrap !important; /* 保留換行，配合 line-clamp 自動隱藏多餘行數 */
    overflow: hidden !important;
    word-break: break-all !important;
    max-height: calc(var(--editor-line-height) * 1em + 1rem) !important; 
    max-width: none !important; 
    cursor: text;
}
/* 支援自訂帶空白的縮略符號 (Firefox 支援) */
@supports (text-overflow: " ...") {
    .table-nowrap .td-inner {
        text-overflow: " ..." !important;
    }
}

/* 單一選取 (Focus) 樣式備用清除 (現由 JS 全權接管外圍框線) */
table#data-table td:focus { outline: none; }

/* 選取底色樣式 (單選無底色，多選淺底色) */
.sel-bg { background-color: #f4f9ff !important; }
table#data-table td:focus-within {
    background-color: #ffffff !important;
}
.selected-header { background-color: #bfdbfe !important; color: #1e3a8a !important; }

/* 拖曳高亮效果 */
.drag-over-col { background-color: #bae6fd !important; border-left: 4px solid #2563eb !important; }
.drag-over-row > th, .drag-over-row > td { background-color: #bae6fd !important; border-top: 4px solid #2563eb !important; }

.resize-handle { position: absolute; top: 0; right: -3px; bottom: 0; width: 6px; cursor: col-resize; background-color: transparent; z-index: 25; }
.resize-handle:hover, .resize-handle.active { background-color: #3b82f6; }

/* 懸浮工具與選單 */
#floating-tool {
    position: absolute; display: none; background-color: #3b82f6; color: white; padding: 0.5rem 1rem; border-radius: 0.375rem;
    font-size: 0.875rem; cursor: pointer; box-shadow: 0 4px 6px -1px rgba(0, 0, 0, 0.2); z-index: 50; transition: background-color 0.2s;
}
#floating-tool:hover { background-color: #2563eb; }

.context-menu {
    position: fixed; display: none; background-color: white; box-shadow: 0 10px 15px -3px rgba(0,0,0,0.1), 0 4px 6px -2px rgba(0,0,0,0.05);
    border: 1px solid #e5e7eb; border-radius: 0.5rem; width: 180px; z-index: 9999; padding: 0.25rem 0; font-size: 0.875rem;
}
.context-menu.show { display: block; }
.context-menu-item { display: flex; align-items: center; gap: 0.5rem; width: 100%; text-align: left; padding: 0.5rem 1rem; color: #4b5563; transition: background-color 0.1s; }
.context-menu-item:hover { background-color: #f3f4f6; color: #111827; }
.context-menu-item.danger { color: #dc2626; }
.context-menu-item.danger:hover { background-color: #fef2f2; color: #b91c1c; }

::-webkit-scrollbar { width: 12px; height: 12px; }
::-webkit-scrollbar-track { background: #f1f1f1; }
::-webkit-scrollbar-thumb { background: #c1c1c1; border-radius: 6px; }
::-webkit-scrollbar-thumb:hover { background: #a8a8a8; }

/* 工具列按鈕與下拉 (仿 Google Sheets 風格) */
.icon-btn { 
    display: inline-flex; 
    align-items: center; 
    justify-content: center; 
    width: 34px; 
    height: 34px; /* 稍微縮小按鈕 */
    border-radius: 4px; /* 微微的圓角 */
    color: #444746; /* Google 系統的深灰色 */
    background-color: transparent; /* 預設透明底 */
    transition: background-color 0.15s, color 0.15s; 
}
.icon-btn .material-symbols-outlined {
    font-size: 20px; /* 縮小圖示尺寸，看起來更精緻 */
    font-weight: 300; /* 讓圖示線條柔和一點 */
}
.icon-btn:hover { 
    background-color: #e1e5ea; /* 懸浮時的淺灰底色 */
    color: #1f1f1f; 
}
.icon-btn.active { 
    background-color: #d3e3fd; /* 啟用時的淺藍底色 */
    color: #0b57d0; 
}
.dropdown-menu, .action-menu { display: none; }
.dropdown-menu.show, .action-menu.show { display: block; }
.check-icon { opacity: 0; }
.check-icon.active { opacity: 1; }

/* 垂直分隔線 */
.toolbar-separator {
    width: 1px;
    height: 20px;
    background-color: #c7c7c7;
    margin: 0 4px;
}
/* ==========================================
   自動填入視窗專屬細節樣式
   ========================================== */
#autoFillModal input {
    /* 強制要求繼承 var(--main-font)，解決 Firefox 不繼承的問題 */
    font-family: var(--main-font) !important;
}

/* 針對 number 類型的輸入框，微調左右 padding 避免跟上下箭頭打架 */
#autoFillModal input[type="number"] {
    padding-right: 0.5rem;
}

/* ==========================================
   手機版槽狀選單 (子選單) 最佳化
   ========================================== */
@media (max-width: 768px) {
    /* 攔截原本向右飛出的設定，改為向下展開 */
    .group\/submenu > div:last-child {
        position: static !important; 
        width: 100% !important;      
        box-shadow: inset 0 2px 4px 0 rgba(0, 0, 0, 0.05) !important; 
        border: none !important;
        border-left: 3px solid #3b82f6 !important; 
        border-radius: 0 !important;
        margin-top: 0 !important;
        background-color: #f8fafc !important; 
        max-height: 320px !important; 
        overflow-y: auto !important; 
        display: none !important; 
    }
    
    /* 當 JS 加上 .mobile-open 類別時，才顯示子選單 */
    .group\/submenu.mobile-open > div:last-child {
        display: block !important;
    }
}



/* ================= 浮動翻譯工具列樣式 ================= */
.draggable-translator {
    position: fixed;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    z-index: 9999;
    display: flex;
    align-items: center;
    gap: 0.5rem;
    padding: 0.4rem 0.5rem 0.4rem 0.2rem;
    background-color: #ffffff;
    border: 1px solid #cbd5e1;
    border-radius: 0.5rem;
    box-shadow: 0 10px 15px -3px rgba(0,0,0,0.1), 0 4px 6px -2px rgba(0,0,0,0.05);
    user-select: none;
}

.drag-handle {
    cursor: grab;
    padding: 0 0.4rem;
    color: #94a3b8;
    font-size: 1.2rem;
    display: flex;
    align-items: center;
}
.drag-handle:active { cursor: grabbing; }

.min-select {
    padding: 0.25rem 0.6rem;
    border: 1px solid #e2e8f0;
    border-radius: 0.375rem;
    
	background-color: #ffffff;
    outline: none;
    cursor: pointer;
    font-size: 0.875rem;
    color: #334155;
}

/* 中介語言特殊設計：隱藏 select，只秀圖示 */
.pivot-wrapper {
    position: relative;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    min-width: 32px;
    height: 30px;
    
	background-color: #ffffff;
    border-radius: 0.375rem;
    border: 1px solid #e2e8f0;
    padding: 0 0.3rem;
    transition: all 0.2s;
}

.pivot-wrapper:hover { background-color: #f1f5f9; }
.pivot-select {
    position: absolute;
    top: 0; left: 0; width: 100%; height: 100%;
    opacity: 0; 
    cursor: pointer;
    z-index: 10;
}
.pivot-display {
    display: flex;
    align-items: center;
    gap: 2px;
    pointer-events: none; /* 讓點擊穿透到隱藏的 select */
}
.pivot-icon {
    font-size: 1.2rem; /* 配合 material symbols 調整大小 */
    color: #475569;
}
.pivot-label {
    font-size: 0.8rem;
    color: #0f172a;
    font-weight: normal; 
    white-space: nowrap;
}

.trans-btn-primary {
    background-color: #3b82f6; color: white;
    border: none; border-radius: 0.375rem;
    padding: 0.3rem 0.8rem; cursor: pointer; font-size: 0.875rem;
}
.trans-btn-primary:hover { background-color: #2563eb; }
.trans-btn-primary:disabled { background-color: #94a3b8; cursor: not-allowed; }

.trans-close { color: #94a3b8; width: 26px; height: 26px; font-size: 0.8rem;}
.trans-close:hover { color: #ef4444; background-color: #fee2e2; }
/* ================= 自訂展開選單樣式 ================= */
.custom-dropdown {
    position: relative;
}

.dropdown-list {
    position: absolute;
    bottom: calc(100% + 5px); /* 向上展開 */
    left: 0;
    min-width: 100px;
    max-height: 250px; /* 限制最大高度，避免超出螢幕 */
    overflow-y: auto;
    background-color: #ffffff;
    border: 1px solid #cbd5e1;
    border-radius: 0.5rem;
    box-shadow: 0 10px 15px -3px rgba(0,0,0,0.1);
    display: none;
    z-index: 10000;
}

.dropdown-list.show {
    display: block;
    animation: fadeIn 0.1s ease-in;
}

.dropdown-item {
    padding: 0.5rem 1rem;
    font-size: 0.875rem;
    color: #334155;
    cursor: pointer;
    white-space: nowrap;
}

.dropdown-item:hover {
    background-color: #f1f5f9;
    color: #2563eb;
}

/* 修正按鈕外觀 */
.pivot-toggle {
    background: transparent;
    border: none;
    cursor: pointer;
    padding: 0;
    width: 100%;
    height: 100%;
}

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

/* ================= 複合膠囊按鈕樣式 ================= */
#trans-btn-group button:disabled {
    background-color: #f1f5f9;
    color: #94a3b8;
    border-color: #e2e8f0;
    cursor: not-allowed;
}

#trans-options-menu .menu-action-btn {
    width: 100%;
    text-align: left;
    padding: 0.4rem 0.75rem;
    font-size: 0.875rem;
    color: #334155;
    border-radius: 0.5rem;
    display: flex;
    align-items: center;
    gap: 0.5rem;
    transition: background-color 0.2s;
    border: none;
    background: transparent;
    cursor: pointer;
}

#trans-options-menu .menu-action-btn:hover {
    background-color: #f8fafc;
    color: #2563eb;
}

/* ================= 浮動翻譯工具列 (防邊緣擠壓與手機版優化) ================= */

/* 1. 工具列主體設定 */
.draggable-translator {
    width: max-content; 
    max-width: 95vw; 
    flex-wrap: nowrap;
    justify-content: center; 
}

/* 2. 針對所有按鈕與群組：防止文字被擠壓成直排 */
.min-select, 
.pivot-wrapper, 
#trans-btn-group, 
#btn-execute-translate, 
.trans-close {
    flex-shrink: 0 !important;
    white-space: nowrap !important;
}

/* 3. 手機版微調：當螢幕較窄時，才啟用自動換行與優化間距 */
@media (max-width: 480px) {
    .draggable-translator {
        flex-wrap: wrap;
        gap: 0.35rem;        
        padding: 0.4rem;
    }
    .min-select {
        padding: 0.25rem 0.6rem;
    }
    #trans-btn-group {
        margin-left: 0;
    }
}

/* ================= 文字模式顯示行號開關 ================= */
.hide-text-line-numbers #lineNumbers {
    display: none !important;
}

/* ================= 多工作表頁籤列樣式 ================= */
.sheet-tab {
    padding: 5px 16px;
    font-size: 13px;
    color: #4b5563;
    background-color: #f3f4f6;
    border-right: 1px solid #d1d5db;
    border-bottom: 3px solid transparent; 
    cursor: pointer;
    white-space: nowrap;
    user-select: none;
    transition: background-color 0.2s;
    display: flex;
    align-items: center;
    gap: 6px;
}
.sheet-tab:hover:not(.active) {
    background-color: #e5e7eb;
}
.sheet-tab.active {
    background-color: #ffffff;
    color: #10b981; /* 綠色，類似試算表風格 */
    font-weight: bold;
    border-bottom: 3px solid #10b981;
}
/* 雙擊重新命名時的輸入框 */
.sheet-rename-input {
    font-size: 13px;
    padding: 0 4px;
    border: 1px solid #10b981;
    border-radius: 2px;
    outline: none;
    font-family: inherit;
    width: 80px;
}


/* ================= 100% 寬度全螢幕無邊距模式 ================= */
body.full-width-mode {
    padding: 0 !important; /* 消除 body 外圍的 Tailwind padding (p-2 md:p-6) */
}

/* 讓工具列貼齊邊緣，並取消圓角 */
body.full-width-mode > #mainContainer > div:first-child {
    margin-bottom: 0 !important;
    border-radius: 0 !important;
    padding-left: 1rem !important; /* 滿版時，左右留一點呼吸空間 */
    padding-right: 1rem !important;
}

/* 讓編輯器與表格完全填滿畫面 */
body.full-width-mode .editor-wrapper {
    border-radius: 0 !important;
    border-left: none !important;
    border-right: none !important;
    border-bottom: none !important;
    border-top: 1px solid #d1d5db !important; /* 工具列與編輯區的細分隔線 */
    box-shadow: none !important;
}




/* ================= 對話模式樣式 ================= */
#chatModeContainer .dropdown-list {
    bottom: auto;
    top: calc(100% + 5px);
}

.chat-message-wrapper {
    transition: all 0.2s;
}

/* 氣泡本體樣式 */
.chat-bubble {
    width: fit-content;
    padding: 0.6rem 0.85rem;
    border-radius: 1.25rem;
    word-break: break-word;
    box-shadow: 0 1px 2px rgba(0,0,0,0.1);
    font-size: var(--editor-font-size);
    line-height: var(--editor-line-height);
}

.chat-bubble-user {
    background-color: #e0f2fe; 
    color: #0369a1;
    border-bottom-right-radius: 0.25rem; /* 右下角尖角 */
}

.chat-bubble-system {
    background-color: #ffffff;
    color: #334155;
    border: 1px solid #e2e8f0;
    border-top-left-radius: 0.25rem;
}

/* 當不顯示 Emoji 時，隱藏系統頭像區塊 */
#chatModeContainer:not(.show-emojis) .chat-avatar-area {
    display: none !important;
}

/* 當不顯示編號時，隱藏對話編號 */
#chatModeContainer:not(.show-numbers) .chat-number {
    display: none !important;
}
/* 當不顯示編號時，隱藏對話編號 */
#chatModeContainer:not(.show-numbers) .chat-number {
    display: none !important;
}

/* 當不顯示刪除按鈕時，隱藏對話氣泡旁的刪除按鈕 */
#chatModeContainer:not(.show-delete) .chat-btn-delete {
    display: none !important;
}


/* ================= 極致滿版 (Zen Mode) ================= */
body.maximized-mode {
    padding: 0 !important;
}
/* 隱藏上方工具列 */
body.maximized-mode > #mainContainer > div:first-child {
    display: none !important; 
}
/* 隱藏下方頁籤列 */
body.maximized-mode #sheetTabBar {
    display: none !important; 
}
/* 關鍵：強制主容器「垂直」滿版，但「水平」寬度會依照原本設定 (如 800px) */
body.maximized-mode #mainContainer {
    /* 註銷掉下面這行，讓它使用原本的 maxWidth 設定 */
    /* max-width: 100% !important; */ 
    height: 100vh !important;
    height: 100dvh !important;
}
/* 只有在同時處於 100% 寬度模式時，才去除邊框圓角 */
body.maximized-mode.full-width-mode .editor-wrapper {
    border: none !important;
    border-radius: 0 !important;
    box-shadow: none !important;
}