/* === 基本設定 === */
:root {
    --primary-color: #4f46e5;
    --primary-hover: #4338ca;
    --bg-color: #f9fafb;
    --sidebar-bg: #ffffff;
    --card-bg: #ffffff;
    --text-color: #1f2937;
    --text-secondary: #6b7280;
    --border-color: #e5e7eb;
    --success-color: #10b981;
    --warning-color: #f59e0b;
    --error-color: #ef4444;
    --thought-bg: #fef3c7;
    --action-bg: #dbeafe;
    --observation-bg: #dcfce7;
    --answer-bg: #f0fdf4;
}

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

body {
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
    background-color: var(--bg-color);
    color: var(--text-color);
    line-height: 1.6;
}

/* === 主容器 === */
.container {
    display: flex;
    height: 100vh;
    overflow: hidden;
}

/* === 側邊欄 === */
.sidebar {
    width: 320px;
    background: var(--sidebar-bg);
    border-right: 1px solid var(--border-color);
    display: flex;
    flex-direction: column;
    transition: transform 0.3s ease, width 0.3s ease;
    overflow: hidden;
}

.sidebar.collapsed {
    width: 0;
    transform: translateX(-320px);
}

.sidebar-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 1rem;
    border-bottom: 1px solid var(--border-color);
}

.sidebar-header h2 {
    font-size: 1.1rem;
    font-weight: 600;
}

.toggle-sidebar {
    background: none;
    border: none;
    cursor: pointer;
    font-size: 1rem;
    color: var(--text-secondary);
    padding: 0.25rem;
}

.tools-list {
    flex: 1;
    overflow-y: auto;
    padding: 1rem;
}

.tool-card {
    background: var(--card-bg);
    border: 1px solid var(--border-color);
    border-radius: 8px;
    padding: 1rem;
    margin-bottom: 1rem;
    transition: box-shadow 0.2s ease;
}

.tool-card:hover {
    box-shadow: 0 4px 6px -1px rgba(0, 0, 0, 0.1);
}

.tool-header {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    margin-bottom: 0.5rem;
}

.tool-icon {
    font-size: 1.25rem;
}

.tool-name {
    font-weight: 600;
    font-size: 0.95rem;
}

.tool-description {
    font-size: 0.85rem;
    color: var(--text-secondary);
    margin-bottom: 0.75rem;
}

.suggestions-title {
    font-size: 0.75rem;
    color: var(--text-secondary);
    margin-bottom: 0.5rem;
}

.suggestion-btn {
    display: block;
    width: 100%;
    text-align: left;
    background: var(--bg-color);
    border: 1px solid var(--border-color);
    border-radius: 6px;
    padding: 0.5rem 0.75rem;
    margin-bottom: 0.5rem;
    font-size: 0.85rem;
    color: var(--text-color);
    cursor: pointer;
    transition: all 0.2s ease;
}

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

/* === 主內容區 === */
.main-content {
    flex: 1;
    display: flex;
    flex-direction: column;
    overflow: hidden;
}

/* === 標題列 === */
.header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 1rem 1.5rem;
    background: var(--card-bg);
    border-bottom: 1px solid var(--border-color);
}

.header-left {
    display: flex;
    align-items: center;
    gap: 1rem;
}

.menu-btn {
    display: block;
    background: none;
    border: none;
    font-size: 1.5rem;
    cursor: pointer;
    color: var(--text-color);
    padding: 0.25rem;
    border-radius: 4px;
    transition: background 0.2s ease;
}

.menu-btn:hover {
    background: var(--bg-color);
}

.header h1 {
    font-size: 1.25rem;
    font-weight: 600;
}

.header-center {
    display: flex;
    align-items: center;
}

.token-display {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    background: var(--bg-color);
    padding: 0.4rem 0.75rem;
    border-radius: 8px;
    font-size: 0.75rem;
    border: 1px solid var(--border-color);
}

.token-group {
    display: flex;
    align-items: center;
    gap: 0.5rem;
}

.token-group-label {
    font-weight: 600;
    color: var(--text-secondary);
    font-size: 0.7rem;
    padding: 0.1rem 0.3rem;
    background: var(--border-color);
    border-radius: 4px;
}

.token-group-cumulative .token-group-label {
    background: var(--primary-color);
    color: white;
}

.token-separator {
    width: 1px;
    height: 20px;
    background: var(--border-color);
    margin: 0 0.25rem;
}

.token-item {
    display: flex;
    align-items: center;
    gap: 0.2rem;
}

.token-label {
    color: var(--text-secondary);
}

.token-value {
    font-weight: 600;
    font-family: monospace;
    min-width: 2ch;
}

.token-total .token-value {
    color: var(--primary-color);
}

.header-right {
    display: flex;
    gap: 0.75rem;
}

.settings-btn, .clear-btn {
    background: var(--bg-color);
    border: 1px solid var(--border-color);
    border-radius: 6px;
    padding: 0.5rem 1rem;
    font-size: 0.875rem;
    cursor: pointer;
    transition: all 0.2s ease;
}

.settings-btn:hover, .clear-btn:hover {
    background: var(--border-color);
}

/* === 對話區域 === */
.chat-container {
    flex: 1;
    overflow-y: auto;
    padding: 1.5rem;
}

.welcome-message {
    max-width: 600px;
    margin: 2rem auto;
    text-align: center;
}

.welcome-message h2 {
    font-size: 1.5rem;
    margin-bottom: 1rem;
}

.welcome-message p {
    color: var(--text-secondary);
    margin-bottom: 0.5rem;
}

.quick-suggestions {
    margin-top: 2rem;
}

.quick-suggestions h3 {
    font-size: 1rem;
    color: var(--text-secondary);
    margin-bottom: 1rem;
}

.quick-btns {
    display: flex;
    flex-wrap: wrap;
    gap: 0.75rem;
    justify-content: center;
}

.quick-btn {
    background: var(--card-bg);
    border: 1px solid var(--border-color);
    border-radius: 20px;
    padding: 0.5rem 1rem;
    font-size: 0.875rem;
    cursor: pointer;
    transition: all 0.2s ease;
}

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

/* === 訊息樣式 === */
.messages {
    max-width: 800px;
    margin: 0 auto;
}

.message {
    margin-bottom: 1.5rem;
    animation: fadeIn 0.3s ease;
}

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

.message-user {
    display: flex;
    justify-content: flex-end;
}

.message-user .message-content {
    background: var(--primary-color);
    color: white;
    border-radius: 18px 18px 4px 18px;
    padding: 0.75rem 1rem;
    max-width: 70%;
}

.message-agent {
    display: flex;
    flex-direction: column;
    gap: 0.75rem;
}

.agent-step {
    background: var(--card-bg);
    border: 1px solid var(--border-color);
    border-radius: 12px;
    padding: 1rem;
    border-left: 4px solid var(--border-color);
}

.agent-step.thought {
    border-left-color: var(--warning-color);
    background: var(--thought-bg);
}

.agent-step.action {
    border-left-color: var(--primary-color);
    background: var(--action-bg);
}

.agent-step.observation {
    border-left-color: var(--success-color);
    background: var(--observation-bg);
}

.agent-step.final-answer {
    border-left-color: var(--success-color);
    background: var(--answer-bg);
    border-left-width: 6px;
}

.agent-step.error {
    border-left-color: var(--error-color);
    background: #fef2f2;
}

.step-header {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    font-weight: 600;
    font-size: 0.875rem;
    margin-bottom: 0.5rem;
    color: var(--text-secondary);
}

.step-content {
    font-size: 0.95rem;
    white-space: pre-wrap;
    word-break: break-word;
}

.step-content.observation-content {
    max-height: 300px;
    overflow-y: auto;
    font-size: 0.85rem;
    background: rgba(255, 255, 255, 0.5);
    padding: 0.75rem;
    border-radius: 6px;
}

/* === 載入指示器 === */
.loading {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    padding: 1rem;
    color: var(--text-secondary);
}

.loading-spinner {
    width: 20px;
    height: 20px;
    border: 2px solid var(--border-color);
    border-top-color: var(--primary-color);
    border-radius: 50%;
    animation: spin 1s linear infinite;
}

@keyframes spin {
    to { transform: rotate(360deg); }
}

/* === 輸入區域 === */
.input-container {
    padding: 1rem 1.5rem;
    background: var(--card-bg);
    border-top: 1px solid var(--border-color);
}

.input-wrapper {
    display: flex;
    gap: 0.75rem;
    max-width: 800px;
    margin: 0 auto;
}

#messageInput {
    flex: 1;
    border: 1px solid var(--border-color);
    border-radius: 12px;
    padding: 0.75rem 1rem;
    font-size: 1rem;
    resize: none;
    min-height: 44px;
    max-height: 200px;
    font-family: inherit;
}

#messageInput:focus {
    outline: none;
    border-color: var(--primary-color);
    box-shadow: 0 0 0 3px rgba(79, 70, 229, 0.1);
}

.send-btn {
    background: var(--primary-color);
    color: white;
    border: none;
    border-radius: 12px;
    padding: 0.75rem 1.5rem;
    font-size: 1rem;
    font-weight: 500;
    cursor: pointer;
    transition: background 0.2s ease;
}

.send-btn:hover {
    background: var(--primary-hover);
}

.send-btn:disabled {
    background: var(--border-color);
    cursor: not-allowed;
}

.input-hint {
    text-align: center;
    font-size: 0.75rem;
    color: var(--text-secondary);
    margin-top: 0.5rem;
}

/* === Modal 對話框 === */
.modal {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(0, 0, 0, 0.5);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 1000;
}

.modal-content {
    background: var(--card-bg);
    border-radius: 12px;
    width: 90%;
    max-width: 500px;
    max-height: 90vh;
    overflow-y: auto;
    box-shadow: 0 20px 25px -5px rgba(0, 0, 0, 0.1);
}

.modal-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 1rem 1.5rem;
    border-bottom: 1px solid var(--border-color);
}

.modal-header h2 {
    font-size: 1.1rem;
}

.modal-close {
    background: none;
    border: none;
    font-size: 1.5rem;
    cursor: pointer;
    color: var(--text-secondary);
}

.modal-body {
    padding: 1.5rem;
}

.modal-footer {
    display: flex;
    justify-content: flex-end;
    gap: 0.75rem;
    padding: 1rem 1.5rem;
    border-top: 1px solid var(--border-color);
}

.form-group {
    margin-bottom: 1rem;
}

.form-group label {
    display: block;
    font-weight: 500;
    margin-bottom: 0.5rem;
    font-size: 0.875rem;
}

.form-group select,
.form-group input,
.form-group textarea,
.modal-body textarea {
    width: 100%;
    border: 1px solid var(--border-color);
    border-radius: 8px;
    padding: 0.75rem;
    font-size: 0.95rem;
    font-family: inherit;
}

.form-group select:focus,
.form-group input:focus,
.form-group textarea:focus,
.modal-body textarea:focus {
    outline: none;
    border-color: var(--primary-color);
    box-shadow: 0 0 0 3px rgba(79, 70, 229, 0.1);
}

/* 用戶輸入對話框的 textarea */
#userInputText {
    min-height: 80px;
    resize: vertical;
    margin-top: 1rem;
}

.model-suggestions {
    display: flex;
    flex-wrap: wrap;
    gap: 0.5rem;
    margin-top: 0.5rem;
}

.model-suggestion {
    background: var(--bg-color);
    border: 1px solid var(--border-color);
    border-radius: 4px;
    padding: 0.25rem 0.5rem;
    font-size: 0.75rem;
    cursor: pointer;
}

.model-suggestion:hover {
    background: var(--primary-color);
    color: white;
    border-color: var(--primary-color);
}

.btn {
    padding: 0.5rem 1rem;
    border-radius: 8px;
    font-size: 0.875rem;
    font-weight: 500;
    cursor: pointer;
    transition: all 0.2s ease;
}

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

.btn-primary:hover {
    background: var(--primary-hover);
}

.btn-secondary {
    background: var(--bg-color);
    color: var(--text-color);
    border: 1px solid var(--border-color);
}

.btn-secondary:hover {
    background: var(--border-color);
}

/* === 響應式設計 === */
@media (max-width: 768px) {
    .sidebar {
        position: fixed;
        left: 0;
        top: 0;
        bottom: 0;
        z-index: 100;
        width: 280px;
        transform: translateX(-100%);
    }

    /* 手機版：沒有 collapsed 時顯示 */
    .sidebar:not(.collapsed) {
        transform: translateX(0);
    }

    .sidebar.collapsed {
        transform: translateX(-100%);
    }

    .toggle-sidebar {
        display: none;
    }

    .message-user .message-content {
        max-width: 85%;
    }

    .quick-btns {
        flex-direction: column;
    }

    .quick-btn {
        width: 100%;
    }
}

/* === 狀態訊息 === */
.status-message {
    text-align: center;
    color: var(--text-secondary);
    font-size: 0.85rem;
    padding: 0.5rem;
}

/* === 側邊欄標籤頁 === */
.sidebar-tabs {
    display: flex;
    border-bottom: 1px solid var(--border-color);
}

.sidebar-tab {
    flex: 1;
    padding: 0.875rem 1rem;
    background: none;
    border: none;
    font-size: 0.9rem;
    font-weight: 500;
    color: var(--text-secondary);
    cursor: pointer;
    transition: all 0.2s ease;
    border-bottom: 2px solid transparent;
}

.sidebar-tab:hover {
    background: var(--bg-color);
}

.sidebar-tab.active {
    color: var(--primary-color);
    border-bottom-color: var(--primary-color);
}

/* === 側邊欄面板 === */
.sidebar-panel {
    flex: 1;
    display: flex;
    flex-direction: column;
    overflow: hidden;
}

.sidebar-panel.hidden {
    display: none;
}

/* === 對話記錄面板 === */
.conversations-header {
    padding: 1rem;
    border-bottom: 1px solid var(--border-color);
}

.new-conversation-btn {
    width: 100%;
    padding: 0.75rem 1rem;
    background: var(--primary-color);
    color: white;
    border: none;
    border-radius: 8px;
    font-size: 0.9rem;
    font-weight: 500;
    cursor: pointer;
    transition: background 0.2s ease;
}

.new-conversation-btn:hover {
    background: var(--primary-hover);
}

.conversations-list {
    flex: 1;
    overflow-y: auto;
    padding: 0.5rem;
}

.no-conversations {
    text-align: center;
    padding: 2rem 1rem;
    color: var(--text-secondary);
}

.no-conversations p {
    margin-bottom: 0.5rem;
}

.no-conversations .hint {
    font-size: 0.85rem;
}

/* === 對話項目 === */
.conversation-item {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    padding: 0.75rem;
    margin-bottom: 0.25rem;
    border-radius: 8px;
    cursor: pointer;
    transition: background 0.2s ease;
}

.conversation-item:hover {
    background: var(--bg-color);
}

.conversation-item.active {
    background: var(--action-bg);
    border-left: 3px solid var(--primary-color);
}

.conversation-info {
    flex: 1;
    min-width: 0;
}

.conversation-title {
    font-size: 0.9rem;
    font-weight: 500;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    margin-bottom: 0.25rem;
}

.conversation-meta {
    display: flex;
    gap: 0.75rem;
    font-size: 0.75rem;
    color: var(--text-secondary);
}

.conversation-delete {
    background: none;
    border: none;
    padding: 0.25rem;
    cursor: pointer;
    opacity: 0;
    transition: opacity 0.2s ease;
    font-size: 0.875rem;
}

.conversation-item:hover .conversation-delete {
    opacity: 1;
}

.conversation-delete:hover {
    transform: scale(1.1);
}
