/* 根目錄變數設定: 高質感 B2B SaaS 配色 */
:root {
    --primary-color: #4F46E5;
    --primary-hover: #4338CA;
    --bg-color: #F9FAFB;
    --surface-color: #FFFFFF;
    --text-main: #111827;
    --text-muted: #6B7280;
    --border-color: #E5E7EB;
    --error-color: #EF4444;
    --success-color: #10B981;
    --sidebar-bg: #111827;
    --sidebar-text: #D1D5DB;
    --sidebar-hover: #374151;
    --sidebar-active: #4F46E5;
}

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

body {
    font-family: 'Inter', sans-serif;
    background-color: var(--bg-color);
    color: var(--text-main);
    display: flex;
    height: 100vh;
    overflow: hidden;
}

/* 按鈕共用樣式 */
button {
    cursor: pointer;
    font-family: inherit;
    border: none;
    outline: none;
    border-radius: 6px;
    transition: all 0.2s ease;
}

.btn-primary {
    background-color: var(--primary-color);
    color: white;
    padding: 0.5rem 1rem;
    font-size: 0.875rem;
    font-weight: 500;
}

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

.btn-primary:disabled {
    opacity: 0.6;
    cursor: not-allowed;
}

.btn-secondary {
    background-color: white;
    color: var(--text-main);
    border: 1px solid var(--border-color);
    padding: 0.5rem 1rem;
    font-size: 0.875rem;
}

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

.btn-icon {
    background: none;
    color: var(--text-muted);
    font-size: 1.1rem;
    padding: 0.4rem;
}
.btn-icon:hover {
    color: var(--primary-color);
}

.btn-close {
    background: none;
    color: var(--text-muted);
    font-size: 1.25rem;
}
.btn-close:hover {
    color: var(--error-color);
}

/* 輸入框 */
input, select {
    width: 100%;
    padding: 0.625rem;
    border: 1px solid var(--border-color);
    border-radius: 6px;
    font-family: inherit;
    font-size: 0.875rem;
    transition: border-color 0.2s;
}

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

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

.input-group label {
    display: block;
    margin-bottom: 0.5rem;
    font-size: 0.875rem;
    font-weight: 500;
    color: var(--text-main);
}

/* 登入與浮動模態框 (Modal) */
.modal-overlay {
    position: fixed;
    top: 0; left: 0; right: 0; bottom: 0;
    background: rgba(17, 24, 39, 0.6);
    backdrop-filter: blur(4px);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 1000;
}

.login-card, .modal-card {
    background: var(--surface-color);
    padding: 2.5rem;
    border-radius: 12px;
    box-shadow: 0 20px 25px -5px rgba(0, 0, 0, 0.1), 0 10px 10px -5px rgba(0, 0, 0, 0.04);
    width: 100%;
    max-width: 400px;
}

.login-card h1 {
    font-size: 1.5rem;
    font-weight: 600;
    margin-bottom: 0.5rem;
    text-align: center;
}

.login-card .subtitle {
    text-align: center;
    color: var(--text-muted);
    margin-bottom: 1.5rem;
    font-size: 0.875rem;
}

.error-msg {
    color: var(--error-color);
    font-size: 0.875rem;
    margin-bottom: 1rem;
    text-align: center;
    min-height: 1.2rem;
}

.hidden {
    display: none !important;
}

/* Modal 樣式 */
.modal-card {
    max-width: 500px;
    padding: 1.5rem;
}

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

.modal-actions {
    display: flex;
    justify-content: flex-end;
    gap: 0.75rem;
    margin-top: 1.5rem;
}

/* 主應用容器 */
#app-container {
    display: flex;
    width: 100%;
    height: 100%;
}

/* 左側邊欄 */
.sidebar {
    width: 260px;
    background-color: var(--sidebar-bg);
    color: var(--sidebar-text);
    display: flex;
    flex-direction: column;
    flex-shrink: 0;
}

.sidebar-header {
    padding: 1.5rem;
    border-bottom: 1px solid rgba(255, 255, 255, 0.1);
}

.logo {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    font-size: 1.25rem;
    font-weight: 600;
    color: white;
    margin-bottom: 1.25rem;
}

.user-info {
    display: flex;
    align-items: center;
    justify-content: space-between;
    font-size: 0.875rem;
    background: rgba(255, 255, 255, 0.05);
    padding: 0.5rem 0.75rem;
    border-radius: 6px;
}

.sidebar-nav {
    flex: 1;
    padding: 1rem 0;
    overflow-y: auto;
}

.nav-item {
    padding: 0.75rem 1.5rem;
    display: flex;
    align-items: center;
    gap: 0.75rem;
    cursor: pointer;
    font-weight: 500;
    transition: background 0.2s, color 0.2s;
    font-size: 0.95rem;
}

.nav-item i {
    width: 20px;
    text-align: center;
}

.nav-item:hover {
    background-color: var(--sidebar-hover);
    color: white;
}

.nav-item.active {
    background-color: var(--sidebar-active);
    color: white;
    border-right: 3px solid white;
}

/* 右側主內容區 */
.main-content {
    flex: 1;
    background-color: var(--bg-color);
    position: relative;
    overflow: hidden;
}

.view-section {
    height: 100%;
    display: flex;
    flex-direction: column;
}

/* 智慧問答介面 */
.chat-header {
    padding: 1.5rem 2rem;
    background: var(--surface-color);
    border-bottom: 1px solid var(--border-color);
    box-shadow: 0 1px 2px rgba(0,0,0,0.05);
}

.chat-header h2 {
    font-size: 1.25rem;
    margin-bottom: 0.25rem;
}

.chat-header p {
    color: var(--text-muted);
    font-size: 0.875rem;
}

.chat-window {
    flex: 1;
    padding: 2rem;
    overflow-y: auto;
    display: flex;
    flex-direction: column;
    gap: 1.5rem;
}

.message {
    display: flex;
    gap: 1rem;
    max-width: 80%;
}

.message.user {
    align-self: flex-end;
    flex-direction: row-reverse;
}

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

.message.ai .avatar {
    background-color: var(--primary-color);
    color: white;
}

.message.user .avatar {
    background-color: var(--text-muted);
    color: white;
}

.bubble {
    background: var(--surface-color);
    padding: 1rem 1.25rem;
    border-radius: 8px;
    box-shadow: 0 1px 2px rgba(0,0,0,0.05);
    line-height: 1.5;
    font-size: 0.95rem;
    border: 1px solid var(--border-color);
}

.message.user .bubble {
    background: var(--primary-color);
    color: white;
    border: none;
}

.citation {
    display: inline-block;
    background-color: #E0E7FF;
    color: var(--primary-color);
    font-size: 0.75rem;
    padding: 0.1rem 0.4rem;
    border-radius: 4px;
    margin-left: 0.5rem;
    cursor: pointer;
    text-decoration: none;
    font-weight: 500;
}

.chat-input-area {
    padding: 1.5rem 2rem;
    background: var(--surface-color);
    border-top: 1px solid var(--border-color);
}

#chat-form {
    display: flex;
    gap: 0.75rem;
    position: relative;
    max-width: 1200px;
    width: 100%;
    margin: 0 auto;
}

#chat-form input {
    width: 100%;
    border-radius: 24px;
    padding: 1rem 1.5rem;
    padding-right: 4rem; /* 給按鈕空間 */
    box-shadow: 0 4px 6px rgba(0,0,0,0.05);
    font-size: 1.1rem;
    border: 2px solid var(--border-color);
}

#chat-form input:focus {
    border-color: var(--primary-color);
    box-shadow: 0 0 0 4px rgba(79, 70, 229, 0.1);
}

#btn-send {
    position: absolute;
    right: 0.5rem;
    top: 50%;
    transform: translateY(-50%);
    border-radius: 50%;
    width: 44px;
    height: 44px;
    padding: 0;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 1.2rem;
}

/* 其他視圖共用 */
.view-header {
    padding: 1.5rem 2rem;
    display: flex;
    justify-content: space-between;
    align-items: center;
    background: var(--surface-color);
    border-bottom: 1px solid var(--border-color);
}

.view-header h2 {
    font-size: 1.25rem;
    display: flex;
    align-items: center;
    gap: 0.5rem;
}

/* Data Table */
.table-container {
    padding: 2rem;
    flex: 1;
    overflow-y: auto;
}

.data-table {
    width: 100%;
    border-collapse: collapse;
    background: var(--surface-color);
    border-radius: 8px;
    overflow: hidden;
    box-shadow: 0 1px 3px rgba(0,0,0,0.1);
}

.data-table th, .data-table td {
    padding: 1rem;
    text-align: left;
    border-bottom: 1px solid var(--border-color);
    font-size: 0.875rem;
}

.data-table th {
    background-color: #F3F4F6;
    font-weight: 600;
    color: var(--text-muted);
}

.data-table tr:hover {
    background-color: #F9FAFB;
}

.text-center {
    text-align: center;
}

.action-btns {
    display: flex;
    gap: 0.5rem;
}

.btn-sm {
    padding: 0.25rem 0.5rem;
    font-size: 0.75rem;
}

/* Ingestion View */
.ingestion-card {
    padding: 2rem;
    display: flex;
    flex-direction: column;
    gap: 1.5rem;
    max-width: 800px;
}

.btn-large {
    padding: 1rem 2rem;
    font-size: 1.1rem;
    align-self: flex-start;
}

.terminal-log {
    background: #111827;
    color: #10B981;
    padding: 1.5rem;
    border-radius: 8px;
    font-family: 'Courier New', Courier, monospace;
    font-size: 0.875rem;
    min-height: 300px;
    max-height: 500px;
    overflow-y: auto;
    white-space: pre-wrap;
    box-shadow: inset 0 2px 4px rgba(0,0,0,0.5);
}
