:root {
    --bg-gradient: linear-gradient(135deg, #0f172a 0%, #1e1b4b 100%);
    --glass-bg: rgba(255, 255, 255, 0.05);
    --glass-border: rgba(255, 255, 255, 0.1);
    --primary: #8b5cf6;
    --primary-hover: #7c3aed;
    --text-main: #f8fafc;
    --text-muted: #94a3b8;
    --user-msg-bg: linear-gradient(135deg, #8b5cf6 0%, #6d28d9 100%);
    --ai-msg-bg: rgba(255, 255, 255, 0.1);
}

* {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
}

body {
    font-family: 'Inter', system-ui, -apple-system, sans-serif;
    background: var(--bg-gradient);
    color: var(--text-main);
    height: 100vh;
    display: flex;
    justify-content: center;
    align-items: center;
    overflow: hidden;
}

/* 整個 APP 容器 */
.app-container {
    width: 100%;
    max-width: 900px;
    height: 95vh;
    display: flex;
    flex-direction: column;
    gap: 1rem;
    padding: 1rem;
}

/* 毛玻璃共用樣式 (Glassmorphism) */
.glass-header, .glass-panel {
    background: var(--glass-bg);
    backdrop-filter: blur(16px);
    -webkit-backdrop-filter: blur(16px);
    border: 1px solid var(--glass-border);
    border-radius: 20px;
    box-shadow: 0 8px 32px rgba(0, 0, 0, 0.3);
}

/* 頂部導航列 */
.glass-header {
    padding: 1rem 2rem;
    display: flex;
    justify-content: space-between;
    align-items: center;
    flex-shrink: 0;
}

.glass-header h1 {
    font-size: 1.25rem;
    font-weight: 600;
    letter-spacing: 0.5px;
    background: linear-gradient(to right, #a78bfa, #f472b6);
    -webkit-background-clip: text;
    background-clip: text;
    -webkit-text-fill-color: transparent;
}

.status {
    font-size: 0.875rem;
    color: #4ade80;
    font-weight: 500;
}

/* 聊天區塊 */
.chat-container {
    flex: 1;
    overflow-y: auto;
    padding: 1.5rem;
    display: flex;
    flex-direction: column;
    gap: 1.5rem;
    scrollbar-width: thin;
    scrollbar-color: var(--glass-border) transparent;
}

.chat-container::-webkit-scrollbar { width: 6px; }
.chat-container::-webkit-scrollbar-thumb { background-color: var(--glass-border); border-radius: 10px; }

/* 訊息通用樣式 */
.message {
    display: flex;
    gap: 1rem;
    max-width: 85%;
    animation: fadeIn 0.4s ease-out forwards;
}

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

.message .avatar {
    width: 36px;
    height: 36px;
    border-radius: 50%;
    display: flex;
    justify-content: center;
    align-items: center;
    font-weight: 600;
    font-size: 0.85rem;
    flex-shrink: 0;
}

.message .content {
    padding: 1rem 1.25rem;
    border-radius: 18px;
    line-height: 1.6;
    font-size: 0.95rem;
}

/* AI 訊息 */
.ai-message { align-self: flex-start; }
.ai-message .avatar { background: linear-gradient(135deg, #10b981, #059669); color: white; }
.ai-message .content { background: var(--ai-msg-bg); border-top-left-radius: 4px; }

/* 使用者訊息 */
.user-message {
    align-self: flex-end;
    flex-direction: row-reverse;
}
.user-message .avatar { background: linear-gradient(135deg, #3b82f6, #2563eb); color: white; }
.user-message .content { background: var(--user-msg-bg); border-top-right-radius: 4px; }

/* 底部輸入框 */
.input-area {
    padding: 1rem;
    display: flex;
    flex-direction: column;
    gap: 0.5rem;
    align-items: stretch;
    flex-shrink: 0;
}

.icon-btn {
    background: rgba(255, 255, 255, 0.1);
    color: var(--text-main);
    border: 1px solid var(--glass-border);
    border-radius: 50%;
    width: 44px;
    height: 44px;
    display: flex;
    justify-content: center;
    align-items: center;
    cursor: pointer;
    transition: all 0.2s ease;
    flex-shrink: 0;
}

.icon-btn:hover {
    background: rgba(255, 255, 255, 0.2);
    transform: scale(1.05);
}

.icon-btn svg {
    width: 20px;
    height: 20px;
}

.icon-btn-small {
    background: rgba(255, 255, 255, 0.1);
    color: var(--text-muted);
    border: 1px solid var(--glass-border);
    border-radius: 8px;
    width: 32px;
    height: 32px;
    display: flex;
    justify-content: center;
    align-items: center;
    cursor: pointer;
    transition: all 0.2s ease;
    font-size: 0.9rem;
}

.icon-btn-small:hover {
    background: rgba(239, 68, 68, 0.2);
    color: #f87171;
    border-color: rgba(239, 68, 68, 0.4);
}

.image-preview-container {
    padding: 0.5rem;
    background: rgba(0, 0, 0, 0.2);
    border-radius: 12px;
    position: relative;
    display: inline-block;
    align-self: flex-start;
    margin-bottom: 0.5rem;
}

.image-preview-container img {
    max-width: 120px;
    max-height: 120px;
    border-radius: 8px;
    display: block;
}

.remove-image-btn {
    position: absolute;
    top: -8px;
    right: -8px;
    background: #ef4444;
    color: white;
    border: none;
    border-radius: 50%;
    width: 20px;
    height: 20px;
    font-size: 14px;
    cursor: pointer;
    display: flex;
    justify-content: center;
    align-items: center;
    line-height: 1;
}

#message-input {
    flex: 1;
    background: transparent;
    border: none;
    color: var(--text-main);
    font-family: inherit;
    font-size: 1rem;
    padding: 0.5rem;
    resize: none;
    outline: none;
    max-height: 150px;
}
#message-input::placeholder { color: var(--text-muted); }

.send-btn {
    background: var(--primary);
    color: white;
    border: none;
    border-radius: 50%;
    width: 44px;
    height: 44px;
    display: flex;
    justify-content: center;
    align-items: center;
    cursor: pointer;
    transition: all 0.2s ease;
    flex-shrink: 0;
}
.send-btn:hover { background: var(--primary-hover); transform: scale(1.05); }
.send-btn:active { transform: scale(0.95); }
.send-btn svg { width: 20px; height: 20px; margin-left: 2px; }

/* AI 思考打字動畫 */
.typing-indicator { display: flex; gap: 4px; padding: 1rem 1.25rem; align-items: center; }
.dot {
    width: 6px; height: 6px;
    background: var(--text-muted);
    border-radius: 50%;
    animation: typing 1.4s infinite ease-in-out both;
}
.dot:nth-child(1) { animation-delay: -0.32s; }
.dot:nth-child(2) { animation-delay: -0.16s; }

@keyframes typing {
    0%, 80%, 100% { transform: scale(0); }
    40% { transform: scale(1); }
}

/* Markdown 細節樣式修正 */
.content pre {
    background: rgba(0, 0, 0, 0.4);
    padding: 1rem; border-radius: 8px;
    margin-top: 0.5rem; overflow-x: auto;
}
.content code {
    font-family: monospace;
    background: rgba(0, 0, 0, 0.3);
    padding: 0.1rem 0.3rem; border-radius: 4px;
}
.content p { margin-bottom: 0.5rem; }
.content p:last-child { margin-bottom: 0; }

/* 🛠️ 店長室專屬工具列樣式 */
.tools-bar {
    padding: 1rem;
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 1rem;
    flex-wrap: wrap;
    border: 1px solid var(--glass-border);
    margin-bottom: 1.5rem; /* 優化間隔 */
}

.file-selector {
    display: flex;
    align-items: center;
    gap: 0.5rem;
}

#file-select {
    background: rgba(255, 255, 255, 0.1);
    border: 1px solid var(--glass-border);
    color: var(--text-main);
    padding: 0.5rem 1rem;
    border-radius: 10px;
    outline: none;
    cursor: pointer;
    transition: all 0.3s ease;
}

#file-select:focus {
    border-color: var(--primary);
    background: rgba(255, 255, 255, 0.15);
}

#file-select option {
    background: #1e1b4b;
    color: white;
}

.action-buttons {
    display: flex;
    gap: 0.75rem;
}

.action-btn {
    padding: 0.6rem 1.2rem;
    border-radius: 10px;
    font-weight: 600;
    font-size: 0.9rem;
    cursor: pointer;
    transition: all 0.3s ease;
    display: flex;
    align-items: center;
    gap: 0.5rem;
    border: none;
}

#gen-report-btn {
    background: linear-gradient(135deg, #8b5cf6 0%, #6d28d9 100%);
    color: white;
    box-shadow: 0 4px 12px rgba(139, 92, 246, 0.3);
}

#gen-report-btn:hover {
    transform: translateY(-2px);
    box-shadow: 0 6px 16px rgba(139, 92, 246, 0.4);
}

#chat-mode-btn {
    background: rgba(255, 255, 255, 0.1);
    color: var(--text-main);
    border: 1px solid var(--glass-border);
}

#chat-mode-btn:hover {
    background: rgba(255, 255, 255, 0.2);
}

/* 📊 圖表容器樣式 */
.chart-wrapper {
    width: 100%;
    max-width: 500px;
    background: rgba(255, 255, 255, 0.05);
    border: 1px solid var(--glass-border);
    border-radius: 12px;
    padding: 1rem;
    margin-top: 1rem;
    animation: fadeIn 0.6s ease-out;
}

.chart-wrapper canvas {
    width: 100% !important;
    height: auto !important;
}

/* 下載按鈕樣式 */
.download-btn {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    margin-top: 10px;
    padding: 6px 12px;
    background: rgba(255, 255, 255, 0.1);
    border: 1px solid var(--glass-border);
    border-radius: 6px;
    color: var(--text-muted);
    font-size: 0.8rem;
    cursor: pointer;
    transition: all 0.2s;
}

.download-btn:hover {
    background: var(--primary);
    color: white;
    border-color: var(--primary);
}

/* 🧠 AI 筆記本 Modal 樣式 */
.memory-modal {
    position: fixed;
    top: 0; left: 0; width: 100%; height: 100%;
    background: rgba(0, 0, 0, 0.6);
    backdrop-filter: blur(5px);
    display: flex;
    justify-content: center;
    align-items: center;
    z-index: 1000;
}

.memory-modal-content {
    width: 90%;
    max-width: 600px;
    padding: 2rem;
    box-shadow: 0 10px 40px rgba(0,0,0,0.5);
}

.rules-list li {
    background: rgba(255, 255, 255, 0.05);
    border: 1px solid var(--glass-border);
    padding: 12px 15px;
    margin-bottom: 10px;
    border-radius: 8px;
    display: flex;
    justify-content: space-between;
    align-items: center;
    color: var(--text-main);
    font-size: 0.95rem;
}

.delete-rule-btn {
    background: rgba(239, 68, 68, 0.2);
    color: #fca5a5;
    border: 1px solid rgba(239, 68, 68, 0.3);
    border-radius: 6px;
    padding: 4px 8px;
    cursor: pointer;
    font-size: 0.8rem;
    transition: all 0.2s;
}

.delete-rule-btn:hover {
    background: #ef4444;
    color: white;
}

/* 📊 表格樣式 (Markdown rendered tables) */
.content table {
    display: block;
    width: 100%;
    max-height: 400px;
    overflow-x: auto;
    overflow-y: auto;
    border-collapse: collapse;
    margin: 15px 0;
    min-width: 100%;
    background: rgba(255, 255, 255, 0.05);
    border-radius: 8px;
    box-shadow: 0 4px 15px rgba(0, 0, 0, 0.1);
}

.content th, .content td {
    padding: 12px 15px;
    border: 1px solid rgba(255, 255, 255, 0.15); /* 新增明顯線條 */
    text-align: left;
    color: var(--text-main);
    font-size: 0.95rem;
}

.content th {
    background: rgba(139, 92, 246, 0.2);
    font-weight: 600;
    color: #e2e8f0;
    border-bottom: 2px solid rgba(139, 92, 246, 0.4);
}

.content tbody tr:nth-of-type(even) {
    background: rgba(255, 255, 255, 0.02);
}

.content tbody tr:hover {
    background: rgba(255, 255, 255, 0.08); /* 滑鼠游標經過變色 */
}

/* 下載表格獨立按鈕 */
.download-table-btn {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    margin-top: 5px;
    margin-bottom: 15px;
    padding: 4px 10px;
    background: rgba(16, 185, 129, 0.2);
    border: 1px solid rgba(16, 185, 129, 0.4);
    border-radius: 6px;
    color: #34d399;
    font-size: 0.8rem;
    cursor: pointer;
    transition: all 0.2s;
}

.download-table-btn:hover {
    background: #10b981;
    color: white;
}
