@import url('https://fonts.googleapis.com/css2?family=Noto+Sans+TC:wght@400;500;700&display=swap');

:root {
    --bg-main: #1a1d2e;
    --bg-sidebar: #242842;
    --bg-content: #1e2139;
    --primary-color: #6a5acd;
    --secondary-color: #48d1cc;
    --text-primary: #e0e0e0;
    --text-secondary: #a0a0b8;
    --border-color: #3a3f63;
    --success-color: #4caf50;
    --error-color: #f44336;
    --selection-bg: rgba(106, 90, 205, 0.3);
    --font-family: 'Noto Sans TC', sans-serif;
}

* {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
}

body {
    font-family: var(--font-family);
    background-color: var(--bg-main);
    color: var(--text-primary);
    overflow: hidden;
}

#app-container {
    display: flex; 
    height: 100vh;
}

/* --- Sidebar --- */
#sidebar {
    width: 320px;      
    flex-shrink: 0;
    background-color: var(--bg-sidebar);
    display: flex;
    flex-direction: column;
    border-right: 1px solid var(--border-color);
}

.sidebar-header {
    padding: 1.5rem;
    border-bottom: 1px solid var(--border-color);
}

.logo {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    margin-bottom: 1rem;
}

.logo-icon { font-size: 1.5rem; }

.logo h1 {
    font-size: 1.2rem;
    font-weight: 700;
    background: linear-gradient(90deg, var(--primary-color), var(--secondary-color));
    -webkit-background-clip: text;
    background-clip: text; 
    -webkit-text-fill-color: transparent;
}

.status-indicator {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    font-size: 0.8rem;
    padding: 0.4rem 0.8rem;
    border-radius: 20px;
    transition: all 0.3s ease;
}
.status-indicator .dot { width: 8px; height: 8px; border-radius: 50%; transition: background-color 0.3s ease; }
.status-indicator.disconnected { background-color: rgba(244, 67, 54, 0.2); color: var(--error-color); }
.status-indicator.disconnected .dot { background-color: var(--error-color); }
.status-indicator.connected { background-color: rgba(76, 175, 80, 0.2); color: var(--success-color); }
.status-indicator.connected .dot { background-color: var(--success-color); }

.report-list-container {
    padding: 1rem;
    flex-grow: 1;
    overflow-y: auto;
}
.report-list-container h2 {
    font-size: 1rem;
    margin-bottom: 1rem;
    color: var(--text-secondary);
}
#report-list {
    list-style: none;
}

/* ✨ 修改：使用 flexbox 佈局，為下載圖示騰出空間 */
#report-list li {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 0.8rem 1rem;
    margin-bottom: 0.5rem;
    border-radius: 8px;
    cursor: pointer;
    transition: background-color 0.2s;
    font-size: 0.9rem;
    border: 1px solid transparent;
}
#report-list li:hover { background-color: var(--bg-content); }
#report-list li.active {
    background-color: var(--primary-color);
    color: white;
    font-weight: 500;
    border-color: var(--secondary-color);
}
/* ✨ 新增：報告名稱樣式，處理長檔名 */
.report-name {
    flex-grow: 1;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    margin-right: 0.5rem;
}
/* ✨ 新增：下載圖示樣式 */
.download-icon {
    flex-shrink: 0;
    color: var(--text-secondary);
    padding: 0.3rem;
    border-radius: 5px;
    display: flex;
    align-items: center;
    justify-content: center;
    text-decoration: none;
    transition: all 0.2s ease;
}
.download-icon:hover {
    color: var(--secondary-color);
    background-color: var(--bg-content);
}
#report-list li.active .download-icon { color: white; }
#report-list li.active .download-icon:hover { background-color: rgba(255, 255, 255, 0.2); }

.loader {
    width: 20px;
    height: 20px;
    border: 3px solid var(--border-color);
    border-top-color: var(--primary-color);
    border-radius: 50%;
    animation: spin 1s linear infinite;
    margin: 2rem auto;
}

@keyframes spin { to { transform: rotate(360deg); } }

/* --- Main Content --- */
#main-content {
    flex-grow: 1; 
    background-color: var(--bg-content);
    display: flex;
    flex-direction: column;
    overflow-y: auto; 
}

#welcome-screen {
    flex-grow: 1;
    display: flex;
    justify-content: center;
    align-items: center;
    text-align: center;
    color: var(--text-secondary);
}
.welcome-icon { font-size: 4rem; }
.welcome-content h2 { font-size: 1.5rem; margin: 1rem 0; color: var(--text-primary); }

#report-view {
    display: flex;
    flex-direction: column;
    height: 100%;
}
/* ✨ 修改：讓 header 內的元素對齊 */
.report-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 1.5rem 2rem;
    border-bottom: 1px solid var(--border-color);
    flex-shrink: 0;
}
.report-header h2 { font-size: 1.4rem; flex-grow: 1; }
/* ✨ 新增：動作按鈕及狀態訊息的容器 */
.actions {
    display: flex;
    align-items: center;
    gap: 1rem;
}
/* ✨ 新增：保存狀態訊息樣式 */
.save-status {
    font-size: 0.9rem;
    color: var(--text-secondary);
}
.save-status span { margin-right: 0.5rem; }
.save-status a {
    color: var(--secondary-color);
    text-decoration: none;
    font-weight: 500;
    margin: 0 0.25rem;
}
.save-status a:hover { text-decoration: underline; }

#report-display-container {
    flex-grow: 1;
    overflow-y: auto;
    padding: 2rem 4rem;
}
#report-display {
    max-width: 800px;
    margin: 0 auto;
    line-height: 1.8;
}
#report-display:focus { outline: none; }
#report-display p, #report-display h1, #report-display h2, #report-display h3 { margin-bottom: 1em; }
#report-display ::selection { background: var(--selection-bg); }


#report-list.is-loading {
    opacity: 0.5;
    cursor: wait;
    pointer-events: none; /* 徹底禁止點擊事件 */
}


#report-list li.pending {
    background-color: var(--bg-content);
    box-shadow: 0 0 0 2px var(--secondary-color) inset;
}

/* --- Refine Panel --- */
#refine-panel {
    width: 400px;      
    flex-shrink: 0;  
    background-color: var(--bg-sidebar);
    border-left: 1px solid var(--border-color);
    display: flex;
    flex-direction: column;
    transition: all 0.3s ease;
}
#refine-panel.hidden { display: none; }
.refine-header {
    padding: 1rem 1.5rem;
    border-bottom: 1px solid var(--border-color);
    flex-shrink: 0;
    font-size: 1.1rem;
    text-align: center;
}
#selection-info {
    padding: 1rem 1.5rem;
    border-bottom: 1px solid var(--border-color);
    flex-shrink: 0;
}
#selection-info h4 { font-size: 0.9rem; margin-bottom: 0.5rem; color: var(--text-secondary); }
.text-preview {
    background: var(--bg-content);
    border-radius: 8px;
    padding: 0.8rem;
    max-height: 100px;
    overflow-y: auto;
    font-size: 0.85rem;
    color: var(--text-secondary);
}
.text-preview.active { color: var(--text-primary); }

#chat-container {
    flex-grow: 1;
    display: flex;
    flex-direction: column;
    overflow: hidden;
}
#chat-history {
    flex-grow: 1;
    padding: 1.5rem;
    overflow-y: auto;
    display: flex;
    flex-direction: column;
    gap: 1.5rem;
}
.chat-bubble {
    padding: 0.8rem 1rem;
    border-radius: 12px;
    max-width: 85%;
    line-height: 1.6;
    font-size: 0.9rem;
}
.chat-bubble.user {
    background-color: var(--primary-color);
    color: white;
    border-bottom-right-radius: 2px;
    align-self: flex-end;
}
.chat-bubble.ai {
    background-color: var(--bg-content);
    border-bottom-left-radius: 2px;
    align-self: flex-start;
}
.chat-bubble .refined-content {
    background-color: rgba(0,0,0,0.2);
    padding: 0.8rem;
    border-radius: 8px;
    margin-top: 0.5rem;
    border: 1px solid var(--border-color);
}
.chat-bubble .apply-btn {
    margin-top: 0.8rem;
    background-color: var(--secondary-color);
    color: var(--bg-main);
}

#chat-input-area {
    padding: 1rem;
    border-top: 1px solid var(--border-color);
    display: flex;
    gap: 0.5rem;
    flex-shrink: 0;
}
#refine-instruction {
    flex-grow: 1;
    background-color: var(--bg-content);
    border: 1px solid var(--border-color);
    border-radius: 8px;
    padding: 0.8rem;
    color: var(--text-primary);
    resize: none;
    font-family: var(--font-family);
}
#refine-instruction:focus {
    outline: none;
    border-color: var(--primary-color);
}
#refine-instruction:disabled, #send-instruction-btn:disabled {
    opacity: 0.5;
    cursor: not-allowed;
}

/* --- General Components --- */
.btn {
    padding: 0.6rem 1.2rem;
    border: none;
    border-radius: 8px;
    font-size: 0.9rem;
    font-weight: 500;
    cursor: pointer;
    transition: all 0.2s ease;
    display: flex;
    align-items: center;
    gap: 0.5rem;
}
.btn .icon { font-size: 1.1rem; }
.btn-primary { background-color: var(--primary-color); color: white; }
.btn-primary:hover { background-color: #7b68ee; }
#send-instruction-btn {
    background-color: var(--secondary-color);
    color: var(--bg-main);
    padding: 0.8rem;
    flex-shrink: 0;
}
#send-instruction-btn:hover { background-color: #59e0d9; }
.hidden { display: none !important; }

#report-display {
    line-height: 1.8;
}

#report-display h1,
#report-display h2,
#report-display h3,
#report-display h4 {
    color: var(--text-primary);
    margin-top: 1.5em;
    margin-bottom: 0.8em;
    line-height: 1.4;
}

#report-display p {
    margin-bottom: 1.2em;
}

#report-display strong {
    font-weight: 700;
    color: var(--text-primary);
}

#report-display em {
    font-style: italic;
    color: var(--text-primary);
}

/* 列表樣式 */
#report-display ul,
#report-display ol {
    margin-bottom: 1.2em;
    padding-left: 2em; /* 標準縮排 */
}

#report-display li {
    margin-bottom: 0.5em;
}

/* 表格樣式 */
#report-display table {
    width: 100%;
    border-collapse: collapse;
    margin-bottom: 1.5em;
    font-size: 0.9rem;
}

#report-display th,
#report-display td {
    border: 1px solid var(--border-color);
    padding: 0.8em 1em;
    text-align: left;
}

#report-display th {
    background-color: var(--bg-sidebar);
    font-weight: 700;
    color: var(--text-primary);
}

#report-display tr:nth-child(even) {
    background-color: var(--bg-sidebar);
}

/* 圖片樣式 */
#report-display img {
    max-width: 100%; /* 確保圖片不會超出容器寬度 */
    height: auto;
    border-radius: 8px;
    margin: 1em 0;
    border: 1px solid var(--border-color);
    background-color: #fff; /* 如果圖片有透明背景，給一個白色底 */
}

/* --- Konami Code Easter Egg Styles --- */

/* ✨ 天崩地裂 - 螢幕震動特效 */
.screen-shake {
  animation: shake 0.8s cubic-bezier(.36,.07,.19,.97) both;
  transform: translate3d(0, 0, 0);
  backface-visibility: hidden;
  perspective: 1000px;
}

@keyframes shake {
  10%, 90% { transform: translate3d(-1px, 0, 0); }
  20%, 80% { transform: translate3d(2px, 0, 0); }
  30%, 50%, 70% { transform: translate3d(-4px, 0, 0); }
  40%, 60% { transform: translate3d(4px, 0, 0); }
}

/* ✨ Turbo 模式 UI 強化 (您提供的樣式) */
body.turbo, body.turbo * {
  transition: all .3s ease !important;
}
body.turbo {
  /* 增加一點濾鏡效果讓視覺更強烈 */
  filter: brightness(1.1) saturate(1.2);
}
body.turbo .btn-primary { 
    background: linear-gradient(90deg, #ff6ec4, #7873f5);
    box-shadow: 0 0 15px rgba(120, 115, 245, 0.7);
}
body.turbo #sidebar { 
    background: #202046;
    box-shadow: 5px 0 25px rgba(0,0,0,0.3);
}
body.turbo #refine-panel { 
    background: #1b1b35;
}
body.turbo #report-list li.active {
    background-color: #7873f5;
    border-color: #ff6ec4;
}

/* 讓 Turbo 按鈕在不同狀態下有不同樣式 */
#turbo-btn {
    background-color: var(--bg-content);
    color: var(--text-secondary);
}
#turbo-btn.btn-primary {
    color: white;
}

/* Custom Scrollbar */
::-webkit-scrollbar { width: 6px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: var(--border-color); border-radius: 3px; }
::-webkit-scrollbar-thumb:hover { background: var(--primary-color); }
