/* 全域樣式 */
* { box-sizing: border-box; margin: 0; padding: 0; }
body {
    font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
    background: linear-gradient(135deg, #f5f7fa 0%, #c3cfe2 100%);
    min-height: 100vh;
    padding: 20px;
    color: #333;
    scroll-behavior: smooth; /* 讓頁面捲動有滑順動畫 */
}
.container { max-width: 1000px; margin: 0 auto; position: relative; }
h1 {
    color: #2d3748; text-align: center; margin-bottom: 20px;
    font-size: 2.2em; text-shadow: 1px 1px 2px rgba(255,255,255,0.8);
}

/* API 與模型設定區 */
.api-compact-section {
    background: white; border-radius: 10px; padding: 15px 20px; margin-bottom: 25px;
    box-shadow: 0 4px 6px rgba(0,0,0,0.05); display: flex; flex-direction: column; gap: 10px;
}
.settings-row { display: flex; flex-wrap: wrap; gap: 15px; align-items: center; justify-content: space-between; }
.input-group { display: flex; gap: 10px; flex: 1; min-width: 300px; }
.input-group input { flex: 1; padding: 10px; border: 1px solid #cbd5e0; border-radius: 6px; }
.input-group button { 
    padding: 10px 20px; background: #4a5568; color: white; border: none; 
    border-radius: 6px; cursor: pointer; font-weight: bold; transition: 0.2s;
}
.input-group button:hover { background: #2d3748; }
.input-group button.btn-secondary { background: #cbd5e0; color: #4a5568; }
.input-group button.btn-secondary:hover { background: #a0aec0; }

/* 模型選擇下拉選單 */
.model-select-group { display: flex; align-items: center; font-weight: bold; color: #4a5568; }
.model-select-group select {
    padding: 9px 12px; border: 1px solid #cbd5e0; border-radius: 6px;
    background-color: #f7fafc; color: #2d3748; font-weight: bold; cursor: pointer; outline: none;
}
.model-select-group select:focus { border-color: #667eea; box-shadow: 0 0 0 2px rgba(102,126,234,0.2); }

.api-status { display: flex; align-items: center; gap: 8px; font-size: 13px; color: #718096; margin-top: 5px; }
.status-indicator { width: 10px; height: 10px; border-radius: 50%; background: #e53e3e; }
.status-indicator.valid { background: #38a169; }
.author-credits { margin-left: auto; font-weight: 600; color: #4a5568;}

/* 步驟導航列 (Stepper) */
.stepper-header {
    display: flex; justify-content: space-between; margin-bottom: 30px;
    background: white; border-radius: 12px; padding: 15px; box-shadow: 0 4px 15px rgba(0,0,0,0.05);
}
.step-indicator {
    flex: 1; text-align: center; position: relative; cursor: pointer;
    color: #a0aec0; font-weight: bold; transition: 0.3s;
}
.step-indicator:not(:last-child)::after {
    content: ''; position: absolute; top: 15px; right: -50%; width: 100%; height: 2px;
    background: #e2e8f0; z-index: 1;
}
.step-num {
    width: 32px; height: 32px; background: #e2e8f0; color: white;
    border-radius: 50%; line-height: 32px; margin: 0 auto 8px; position: relative; z-index: 2; transition: 0.3s;
}
.step-indicator.active { color: #667eea; }
.step-indicator.active .step-num { background: #667eea; box-shadow: 0 0 10px rgba(102, 126, 234, 0.4); }
.step-content { display: none; animation: fadeIn 0.4s ease; }
.step-content.active { display: block; }

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

/* 區塊與標題 */
.section { background: white; border-radius: 12px; padding: 25px; margin-bottom: 20px; box-shadow: 0 4px 15px rgba(0,0,0,0.05); }
.section-header { display: flex; justify-content: space-between; align-items: center; border-bottom: 2px solid #e2e8f0; padding-bottom: 10px; margin-bottom: 20px; }
h2 { color: #4a5568; font-size: 1.5em; border: none; padding: 0;}
.clear-btn { background: none; border: none; color: #e53e3e; cursor: pointer; font-weight: bold; padding: 5px 10px; border-radius: 5px;}
.clear-btn:hover { background: #fff5f5; }

/* 觀察重點 Checkbox */
.focus-options { background: #f7fafc; padding: 15px; border-radius: 8px; margin-bottom: 20px; border-left: 4px solid #667eea; }
.checkbox-group { display: flex; flex-wrap: wrap; gap: 15px; margin-top: 10px; }
.checkbox-group label { cursor: pointer; font-size: 14px; display: flex; align-items: center; gap: 5px; }

/* 輸入與模式切換 */
.mode-switch { display: flex; gap: 10px; margin-bottom: 15px; }
.mode-btn { flex: 1; padding: 10px; background: #edf2f7; border: none; border-radius: 6px; cursor: pointer; font-weight: bold; color: #718096; }
.mode-btn.active { background: #667eea; color: white; }
.input-label { font-weight: bold; display: block; margin-bottom: 8px; font-size: 14px; }
textarea { width: 100%; min-height: 120px; padding: 15px; border: 1px solid #cbd5e0; border-radius: 8px; font-size: 15px; resize: none; overflow-y: hidden; line-height: 1.5;}
textarea:focus { outline: none; border-color: #667eea; box-shadow: 0 0 0 3px rgba(102,126,234,0.2); }
.extra-notes-section { margin-top: 20px; }

/* 檔案上傳 */
.file-upload label { display: flex; justify-content: space-between; padding: 15px; background: #f7fafc; border: 2px dashed #cbd5e0; border-radius: 8px; cursor: pointer; }
.file-upload label:hover { border-color: #667eea; background: #ebf4ff; }
.file-upload input { display: none; }

/* 按鈕與輸出 */
.generate-btn { width: 100%; padding: 15px; background: linear-gradient(135deg, #667eea 0%, #764ba2 100%); color: white; border: none; border-radius: 8px; font-size: 16px; font-weight: bold; cursor: pointer; margin-bottom: 15px; box-shadow: 0 4px 6px rgba(102,126,234,0.3); transition: 0.2s;}
.generate-btn:hover { transform: translateY(-2px); box-shadow: 0 6px 12px rgba(102,126,234,0.4); }
.generate-btn:disabled { background: #cbd5e0; cursor: not-allowed; transform: none; box-shadow: none; }
.presentation-btn { background: linear-gradient(135deg, #ed8936 0%, #dd6b20 100%); box-shadow: 0 4px 6px rgba(237,137,54,0.3); }
.fb-btn { background: linear-gradient(135deg, #4299e1 0%, #3182ce 100%); box-shadow: 0 4px 6px rgba(66,153,225,0.3); }
.short-btn { background: linear-gradient(135deg, #38b2ac 0%, #319795 100%); box-shadow: 0 4px 6px rgba(56,178,172,0.3); }

.output { background: #f8fafc; padding: 25px; border-radius: 8px; min-height: 150px; border: 1px solid #e2e8f0; font-size: 15px; line-height: 1.7; overflow-y: auto; max-height: 500px; margin-bottom: 15px; }

/* Markdown 排版優化 */
.output h1, .output h2, .output h3 { color: #2d3748; margin-top: 1.2em; margin-bottom: 0.5em; border-bottom: 2px solid #edf2f7; padding-bottom: 5px; }
.output h2 { font-size: 1.3em; color: #4a5568;}
.output ul, .output ol { margin-left: 1.5em; margin-bottom: 1em; }
.output li { margin-bottom: 0.3em; }
.output p { margin-bottom: 1em; }
.output strong { color: #2c5282; }

/* 打字機游標 */
.streaming-cursor { display: inline-block; width: 6px; height: 16px; background: #667eea; margin-left: 4px; animation: blink 1s step-end infinite; vertical-align: middle; }
@keyframes blink { 50% { opacity: 0; } }

/* 動作按鈕群 (加入歷史按鈕) */
.action-buttons { display: flex; gap: 10px; }
.copy-btn, .export-btn, .history-btn { flex: 1; padding: 12px; border: none; border-radius: 6px; font-weight: bold; cursor: pointer; color: white; transition: 0.2s;}
.copy-btn { background: #48bb78; }
.copy-btn:hover:not(:disabled) { background: #38a169; }
.export-btn { background: #805ad5; }
.export-btn:hover:not(:disabled) { background: #6b46c1; }
/* 歷史紀錄按鈕：優雅的橘黃色 */
.history-btn { background: #d69e2e; }
.history-btn:hover:not(:disabled) { background: #b7791f; }
.copy-btn:disabled, .export-btn:disabled, .history-btn:disabled { background: #cbd5e0; cursor: not-allowed; }

/* 步驟底部切換 */
.step-footer { display: flex; justify-content: space-between; padding: 0 10px; }
.next-step-btn, .prev-step-btn { padding: 12px 25px; border: none; border-radius: 25px; font-weight: bold; cursor: pointer; transition: 0.2s; box-shadow: 0 4px 6px rgba(0,0,0,0.1); }
.next-step-btn { background: #2d3748; color: white; margin-left: auto; }
.next-step-btn:hover { background: #1a202c; transform: translateX(3px); }
.prev-step-btn { background: white; color: #4a5568; }
.prev-step-btn:hover { background: #edf2f7; transform: translateX(-3px); }

/* FB 選項與提示 */
.fb-options { display: flex; flex-direction: column; gap: 10px; margin-bottom: 15px; padding: 10px; background: #f7fafc; border-radius: 6px; }
.hint { font-size: 13px; color: #718096; margin-bottom: 15px; background: #ebf8ff; padding: 10px; border-left: 3px solid #4299e1; border-radius: 4px;}
.section-grid { display: grid; grid-template-columns: 1fr; gap: 20px; }

/* 浮動快速捲動按鈕 */
.floating-scroll-controls {
    position: fixed;
    bottom: 30px;
    right: 30px;
    display: flex;
    flex-direction: column;
    gap: 15px;
    z-index: 9999;
}
.floating-scroll-controls button {
    width: 45px;
    height: 45px;
    border-radius: 50%;
    background: rgba(45, 55, 72, 0.8);
    color: white;
    border: none;
    font-size: 20px;
    cursor: pointer;
    box-shadow: 0 4px 10px rgba(0,0,0,0.2);
    transition: all 0.3s ease;
    display: flex;
    align-items: center;
    justify-content: center;
}
.floating-scroll-controls button:hover {
    background: rgba(102, 126, 234, 1);
    transform: translateY(-2px);
    box-shadow: 0 6px 15px rgba(102,126,234,0.4);
}

/* 訊息框 */
.message-box {
    position: fixed; top: 50%; left: 50%; transform: translate(-50%, -50%);
    min-width: 300px; max-width: 500px; padding: 20px 30px; border-radius: 12px;
    box-shadow: 0 8px 32px rgba(0, 0, 0, 0.3); font-size: 16px; font-weight: 500;
    text-align: center; z-index: 10000; opacity: 0; visibility: hidden; transition: all 0.3s ease;
}
.message-box.hidden { opacity: 0; visibility: hidden; }
.message-box.show { opacity: 1; visibility: visible; animation: messageSlideIn 0.3s ease; }
.message-box.hide { opacity: 0; visibility: hidden; animation: messageSlideOut 0.3s ease; }
@keyframes messageSlideIn { from { transform: translate(-50%, -60%); opacity: 0; } to { transform: translate(-50%, -50%); opacity: 1; } }
@keyframes messageSlideOut { from { transform: translate(-50%, -50%); opacity: 1; } to { transform: translate(-50%, -40%); opacity: 0; } }

.message-box.success { background: linear-gradient(135deg, #667eea 0%, #764ba2 100%); color: white; border-left: 5px solid #4CAF50; }
.message-box.error { background: linear-gradient(135deg, #f093fb 0%, #f5576c 100%); color: white; border-left: 5px solid #f44336; }
.message-box.info { background: linear-gradient(135deg, #4facfe 0%, #00f2fe 100%); color: white; border-left: 5px solid #2196F3; }
.message-box.warning { background: linear-gradient(135deg, #fa709a 0%, #fee140 100%); color: #333; border-left: 5px solid #ff9800; }
.message-box::before { content: ''; display: inline-block; width: 24px; height: 24px; margin-right: 10px; vertical-align: middle; }
.message-box.success::before { content: '✓'; font-size: 24px; font-weight: bold; }
.message-box.error::before { content: '✕'; font-size: 24px; font-weight: bold; }
.message-box.info::before { content: 'ℹ'; font-size: 24px; font-weight: bold; }
.message-box.warning::before { content: '⚠'; font-size: 24px; font-weight: bold; }

/* 歷史紀錄彈出視窗 (Modal) */
.history-modal-overlay {
    position: fixed; top: 0; left: 0; width: 100%; height: 100%;
    background: rgba(0,0,0,0.5); z-index: 10001;
    opacity: 0; visibility: hidden; transition: 0.3s;
}
.history-modal-overlay.show { opacity: 1; visibility: visible; }

.history-modal {
    position: fixed; top: 50%; left: 50%; transform: translate(-50%, -50%) scale(0.9);
    width: 90%; max-width: 550px; background: white; border-radius: 12px;
    box-shadow: 0 10px 30px rgba(0,0,0,0.3); z-index: 10002;
    opacity: 0; visibility: hidden; transition: 0.3s;
    display: flex; flex-direction: column; max-height: 80vh;
}
.history-modal.show { opacity: 1; visibility: visible; transform: translate(-50%, -50%) scale(1); }

.history-modal-header {
    display: flex; justify-content: space-between; align-items: center;
    padding: 20px; border-bottom: 1px solid #e2e8f0; background: #f8fafc;
    border-radius: 12px 12px 0 0;
}
.history-modal-header h3 { color: #2d3748; margin: 0; font-size: 1.2em; border: none; padding: 0;}
.close-modal-btn {
    background: none; border: none; font-size: 20px; color: #a0aec0;
    cursor: pointer; transition: 0.2s; padding: 0 5px;
}
.close-modal-btn:hover { color: #e53e3e; }

.history-list { padding: 20px; overflow-y: auto; display: flex; flex-direction: column; gap: 15px; }
.history-item {
    padding: 15px; border: 2px solid #e2e8f0; border-radius: 8px;
    cursor: pointer; transition: 0.2s; background: white; text-align: left;
}
.history-item:hover { border-color: #d69e2e; background: #fffff0; transform: translateY(-2px); box-shadow: 0 4px 6px rgba(0,0,0,0.05);}
.history-time { font-size: 0.9em; color: #d69e2e; margin-bottom: 8px; font-weight: bold; }
.history-preview { font-size: 0.95em; color: #4a5568; line-height: 1.5;
    display: -webkit-box; -webkit-line-clamp: 3; -webkit-line-break: auto; -webkit-box-orient: vertical; overflow: hidden; }
.no-history-msg { text-align: center; color: #a0aec0; padding: 20px 0; font-weight: bold;}

@media (min-width: 768px) {
    .section-grid { grid-template-columns: 1fr 1fr; }
    .settings-row { flex-wrap: nowrap; }
}
@media (max-width: 768px) {
    .message-box { min-width: 280px; max-width: 90%; padding: 15px 20px; font-size: 14px; }
}