/* ═══════════════════════════════════════════════════════════════════
   RAG AI Customer Service — Bootstrap 5.3.8 Design System
   主題：紫色清新系 / 白色 Navbar / RWD
   ═══════════════════════════════════════════════════════════════════ */

/* ── Bootstrap CSS Variable Overrides ──────────────────────────────── */
:root {
  /* ─ 主色：紫色系 ─ */
  --bs-primary:                  #7c3aed;
  --bs-primary-rgb:              124, 58, 237;
  --bs-body-bg:                  #f5f6fa;
  --bs-body-color:               #1a1a2e;
  --bs-border-color:             #e5e7eb;
  --bs-border-color-translucent: rgba(0,0,0,.07);
  --bs-border-radius:            0.625rem;
  --bs-border-radius-sm:         0.4rem;
  --bs-border-radius-lg:         0.875rem;

  /* 中文優先字型堆疊，清晰適合各年齡閱讀 */
  --bs-font-sans-serif: 'PingFang TC', 'Noto Sans TC', -apple-system, BlinkMacSystemFont,
                        'Segoe UI', 'Microsoft JhengHei', '微軟正黑體', sans-serif;

  --bs-link-color:               #7c3aed;
  --bs-link-hover-color:         #6d28d9;
  --bs-link-color-rgb:           124, 58, 237;

  /* ─ App design tokens ─ */
  --app-primary:        #7c3aed;
  --app-primary-hover:  #6d28d9;
  --app-primary-light:  #ede9fe;
  --app-primary-mid:    #ddd6fe;
  --app-nav-bg:         #ffffff;
  --app-nav-border:     #e5e7eb;
  --app-nav-h:          60px;
  --app-sidebar-bg:     #f7f8fc;   /* 淡灰白，乾淨清爽 */
  --app-sidebar-border: #e5e7eb;
  --app-sidebar-w:      268px;
  --app-text:           #1a1a2e;
  --app-text-muted:     #6b7280;
  --app-border:         #e5e7eb;
  --app-surface:        #ffffff;
  --app-bg:             #f5f6fa;
}

/* ── Primary colour overrides ───────────────────────────────────────── */
.btn-primary {
  --bs-btn-bg:                 #7c3aed;
  --bs-btn-border-color:       #7c3aed;
  --bs-btn-hover-bg:           #6d28d9;
  --bs-btn-hover-border-color: #6d28d9;
  --bs-btn-active-bg:          #5b21b6;
  --bs-btn-active-border-color:#5b21b6;
  --bs-btn-focus-shadow-rgb:   124, 58, 237;
}
.btn-outline-primary {
  --bs-btn-color:              #7c3aed;
  --bs-btn-border-color:       #7c3aed;
  --bs-btn-hover-bg:           #7c3aed;
  --bs-btn-hover-border-color: #7c3aed;
  --bs-btn-focus-shadow-rgb:   124, 58, 237;
}

/* ── Typography & base ─────────────────────────────────────────────── */
html { font-size: 16px; }        /* 明確 base，確保 rem 計算正確 */
body {
  font-size: 1rem;               /* 16px — 適合各年齡閱讀 */
  line-height: 1.65;
  background: var(--app-bg);
  color: var(--app-text);
  font-family: var(--bs-font-sans-serif);
  -webkit-font-smoothing: antialiased;
}

h1, h2, h3, h4, h5, h6 { font-weight: 700; letter-spacing: -.01em; }

::-webkit-scrollbar       { width: 5px; height: 5px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: #d1d5db; border-radius: 99px; }
::-webkit-scrollbar-thumb:hover { background: #9ca3af; }

.form-control, .form-select {
  font-size: .9375rem;           /* 15px */
  padding: .5rem .75rem;
  border-color: var(--app-border);
}
.form-control:focus, .form-select:focus {
  border-color: #7c3aed;
  box-shadow: 0 0 0 .2rem rgba(124,58,237,.15);
}
.form-check-input:checked { background-color: #7c3aed; border-color: #7c3aed; }
.form-check-input:focus   { box-shadow: 0 0 0 .2rem rgba(124,58,237,.15); }

/* ═══════════════════════════════════════════════════════════════════
   NAVBAR — 白色清新
   ═══════════════════════════════════════════════════════════════════ */

.navbar-app {
  background: var(--app-nav-bg) !important;
  border-bottom: 1px solid var(--app-nav-border);
  box-shadow: 0 1px 6px rgba(0,0,0,.06);
  height: var(--app-nav-h); padding: 0 1.25rem; z-index: 1030;
}
.navbar-app .logo-icon {
  width: 36px; height: 36px;
  background: linear-gradient(135deg, #7c3aed, #a855f7);
  border-radius: 10px;
  display: flex; align-items: center; justify-content: center; flex-shrink: 0;
}
.navbar-app .logo-text { font-size: 1rem; font-weight: 800; color: #1a1a2e; letter-spacing: .01em; }
.navbar-app .logo-sub  { font-size: .7rem; color: #9ca3af; margin-top: -2px; }
.navbar-app .app-nav-link {
  color: #6b7280; font-size: .9rem; font-weight: 600;
  padding: .45rem .9rem; border-radius: 8px;
  display: inline-flex; align-items: center; gap: 6px;
  text-decoration: none; transition: color .15s, background .15s; white-space: nowrap;
  position: relative;
}
.navbar-app .app-nav-link:hover { color: #7c3aed; background: var(--app-primary-light); }
.navbar-app .app-nav-link.active { color: #7c3aed; background: var(--app-primary-light); }
/* 底線指示器 */
.navbar-app .app-nav-link.active::after {
  content: ''; position: absolute; bottom: -1px; left: .9rem; right: .9rem; height: 2px;
  background: #7c3aed; border-radius: 2px 2px 0 0;
}
.nav-divider { width: 1px; height: 20px; background: #e5e7eb; margin: 0 4px; }

/* 手機 hamburger */
.btn-sidebar-toggle {
  display: none;
  background: none; border: none; padding: 6px; border-radius: 8px;
  color: #374151; cursor: pointer; transition: background .15s;
}
.btn-sidebar-toggle:hover { background: var(--app-primary-light); color: #7c3aed; }

/* 手機版 Nav 連結文字隱藏 */
@media (max-width: 767.98px) {
  .btn-sidebar-toggle { display: flex; align-items: center; }
  .navbar-app .app-nav-link span { display: none; }      /* 只保留 icon */
  .navbar-app .app-nav-link { padding: .45rem .55rem; }
  .navbar-app { padding: 0 .75rem; }
}
@media (max-width: 575.98px) {
  .navbar-app .nav-divider { display: none; }
}

/* ═══════════════════════════════════════════════════════════════════
   CHAT PAGE LAYOUT
   ═══════════════════════════════════════════════════════════════════ */

.chat-sidebar {
  position: fixed; top: var(--app-nav-h); left: 0; bottom: 0;
  width: var(--app-sidebar-w); background: var(--app-sidebar-bg);
  border-right: 1px solid var(--app-sidebar-border);
  display: flex; flex-direction: column;
  /* 不設 overflow:hidden，讓按鈕陰影/邊框不被裁切 */
  z-index: 400; transition: transform .25s cubic-bezier(.4,0,.2,1);
}
.chat-main {
  margin-left: var(--app-sidebar-w); margin-top: var(--app-nav-h);
  height: calc(100vh - var(--app-nav-h));
  display: flex; flex-direction: column; background: #f8f9fb;
  transition: margin-left .25s cubic-bezier(.4,0,.2,1);
}

/* 手機版側邊欄（預設隱藏） */
@media (max-width: 767.98px) {
  .chat-sidebar {
    transform: translateX(-100%);
    z-index: 1200;
  }
  .chat-sidebar.open { transform: translateX(0); }
  .chat-main { margin-left: 0; }
  .sidebar-overlay {
    display: none; position: fixed; inset: 0;
    background: rgba(30,20,60,.45); z-index: 1100;
    backdrop-filter: blur(2px);
  }
  .sidebar-overlay.show { display: block; }
}

/* Sidebar elements */
/* sidebar 頂部 form — 高度與 chat-topbar 對齊 */
.chat-sidebar > form {
  height: 54px;
  display: flex; align-items: center;
  padding: 0 14px;
  border-bottom: 1px solid var(--app-sidebar-border);
  flex-shrink: 0;
}
.sidebar-new-btn {
  display: flex; align-items: center; justify-content: center; gap: 7px;
  width: 100%; margin: 0; padding: 8px 16px;
  background: #7c3aed; border: none;
  border-radius: 8px; color: #fff; font-size: .875rem; font-weight: 600;
  cursor: pointer; text-decoration: none;
  transition: background .15s, box-shadow .15s;
  box-shadow: 0 2px 6px rgba(124,58,237,.2);
}
.sidebar-new-btn:hover { background: #6d28d9; box-shadow: 0 3px 10px rgba(124,58,237,.32); color: #fff; }
.sidebar-label {
  font-size: .72rem; font-weight: 700; color: #9ca3af;
  letter-spacing: .08em; text-transform: uppercase; padding: 10px 14px 6px;
}
.conv-list { flex: 1; overflow-y: auto; overflow-x: hidden; padding: 0 8px 12px; }
.conv-item {
  display: flex; align-items: center; gap: 8px;
  padding: 8px 10px; border-radius: 8px; cursor: pointer;
  color: #374151; font-size: .9rem;
  transition: background .12s, color .12s; min-height: 40px; margin-bottom: 1px;
}
.conv-item:hover  { background: #ede9fe; color: #5b21b6; }
.conv-item.active { background: #ede9fe; color: #6d28d9; font-weight: 600; }
.conv-name { flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; min-width: 0; }
.conv-edit, .conv-del {
  width: 24px; height: 24px; border-radius: 5px;
  display: flex; align-items: center; justify-content: center;
  color: #9ca3af; opacity: 0; transition: opacity .12s, background .12s, color .12s;
  flex-shrink: 0; background: none; border: none; cursor: pointer; padding: 0;
}
.conv-item:hover .conv-edit, .conv-item:hover .conv-del { opacity: 1; }
.conv-edit:hover { background: #ddd6fe; color: #7c3aed; }
.conv-del:hover  { background: #fee2e2; color: #dc2626; }
.conv-name-input {
  background: #fff; border: 1px solid #ddd6fe;
  border-radius: 5px; color: #1a1a2e; font-size: .9rem;
  padding: 2px 7px; outline: none; min-width: 0; flex: 1; width: 100%;
}
.sidebar-empty { padding: 20px 14px; font-size: .84rem; color: #9ca3af; text-align: center; line-height: 1.7; }

/* Chat topbar */
.chat-topbar {
  background: #fff; border-bottom: 1px solid #ede9fe;
  padding: 0 20px; height: 54px;
  display: flex; align-items: center; justify-content: space-between; flex-shrink: 0;
}
.chat-topbar-title { font-size: .95rem; font-weight: 700; color: #1a1a2e; }
.chat-topbar-hint  { font-size: .8rem; color: #9ca3af; }

/* Messages area */
.messages-area {
  flex: 1; overflow-y: auto; padding: 24px 20px;
  display: flex; flex-direction: column; gap: 18px;
}
.msg-row { display: flex; gap: 10px; max-width: 880px; }
.msg-row.user { flex-direction: row-reverse; align-self: flex-end; }
.msg-row.ai   { align-self: flex-start; }
.msg-avatar {
  width: 36px; height: 36px; border-radius: 10px;
  display: flex; align-items: center; justify-content: center;
  font-size: .75rem; font-weight: 700; flex-shrink: 0;
}
.msg-row.user .msg-avatar { background: linear-gradient(135deg, #7c3aed, #a855f7); color: #fff; }
.msg-row.ai  .msg-avatar  { background: linear-gradient(135deg, #6d28d9, #7c3aed); color: #fff; }
.msg-col { display: flex; flex-direction: column; gap: 4px; max-width: 700px; }
.msg-row.user .msg-col { align-items: flex-end; }
.msg-bubble {
  padding: 12px 16px; border-radius: 14px;
  font-size: .9375rem; line-height: 1.65;
}
.msg-row.user .msg-bubble {
  background: linear-gradient(135deg, #7c3aed, #6d28d9); color: #fff;
  border-bottom-right-radius: 4px; white-space: pre-wrap;
}
.msg-row.ai .msg-bubble {
  background: #fff; color: #1a1a2e; border: 1px solid #ede9fe;
  border-bottom-left-radius: 4px; box-shadow: 0 2px 8px rgba(124,58,237,.08);
}
.msg-time { font-size: .74rem; color: #9ca3af; padding: 0 2px; }

/* 資料來源標籤（AI 回覆下方） */
.msg-sources {
  display: flex; flex-wrap: wrap; align-items: center; gap: 4px;
  margin-top: 5px; margin-bottom: 1px;
}
.sources-label {
  font-size: .72rem; color: #9ca3af; white-space: nowrap;
}
.source-tag {
  display: inline-block; font-size: .71rem; line-height: 1.3;
  padding: 1px 7px; border-radius: 10px;
  background: #f3f0ff; color: #7c3aed;
  border: 1px solid #ede9fe; white-space: nowrap;
  text-decoration: none; cursor: default;
}
a.source-tag:hover {
  background: #ede9fe; text-decoration: underline; cursor: pointer;
}

/* Typing indicator */
.typing-indicator {
  background: #fff; border: 1px solid #ede9fe;
  border-radius: 14px; border-bottom-left-radius: 4px;
  padding: 14px 18px; display: flex; gap: 5px; align-items: center;
  box-shadow: 0 2px 8px rgba(124,58,237,.08);
}
.typing-dot {
  width: 8px; height: 8px; background: #c4b5fd; border-radius: 50%;
  animation: typingBounce 1.2s infinite;
}
.typing-dot:nth-child(2) { animation-delay: .2s; }
.typing-dot:nth-child(3) { animation-delay: .4s; }
@keyframes typingBounce {
  0%, 60%, 100% { transform: translateY(0); }
  30%           { transform: translateY(-6px); }
}

/* Chat welcome */
.chat-welcome {
  flex: 1; display: flex; flex-direction: column;
  align-items: center; justify-content: center;
  gap: 14px; padding: 40px; text-align: center;
}
.chat-welcome .welcome-icon {
  width: 80px; height: 80px;
  background: linear-gradient(135deg, rgba(124,58,237,.1), rgba(168,85,247,.1));
  border-radius: 24px;
  display: flex; align-items: center; justify-content: center; margin-bottom: 8px;
}
.chat-welcome h2 { font-size: 1.4rem; font-weight: 800; color: #1a1a2e; margin: 0; }
.chat-welcome p  { font-size: .9375rem; color: #6b7280; margin: 0; line-height: 1.7; }

/* Input area */
.chat-input-area {
  background: #fff; border-top: 1px solid #ede9fe; padding: 14px 18px; flex-shrink: 0;
}
.chat-input-box {
  display: flex; gap: 8px; align-items: center;
  background: #faf9ff; border: 1.5px solid #ddd6fe;
  border-radius: 14px; padding: 10px 14px; transition: border-color .15s, box-shadow .15s;
}
.chat-input-box:focus-within {
  border-color: #7c3aed;
  box-shadow: 0 0 0 3px rgba(124,58,237,.12);
  background: #fff;
}
.chat-input-box textarea {
  flex: 1; border: none; background: none; resize: none; outline: none;
  font-size: .9375rem; font-family: inherit; color: #1a1a2e;
  line-height: 1.6; max-height: 140px; overflow-y: auto; padding: 0;
}
.chat-input-box textarea::placeholder { color: #9ca3af; }
.btn-send {
  width: 38px; height: 38px;
  background: linear-gradient(135deg, #7c3aed, #6d28d9);
  border: none; border-radius: 10px; color: #fff;
  display: flex; align-items: center; justify-content: center;
  flex-shrink: 0; cursor: pointer; transition: opacity .15s, transform .1s;
}
.btn-send:disabled { opacity: .35; cursor: not-allowed; }
.btn-send:not(:disabled):hover { opacity: .88; transform: scale(1.05); }
.input-hint { font-size: .74rem; color: #9ca3af; margin-top: 5px; text-align: center; }

/* Markdown content */
.markdown-content h1,.markdown-content h2,.markdown-content h3 {
  font-size: 1rem; font-weight: 700; margin: 10px 0 6px; color: #1a1a2e;
}
.markdown-content p       { margin: 0 0 8px; }
.markdown-content p:last-child { margin-bottom: 0; }
.markdown-content ul,.markdown-content ol { margin: 6px 0; padding-left: 20px; }
.markdown-content li      { margin-bottom: 4px; }
.markdown-content code    { background: #ede9fe; border-radius: 4px; padding: 1px 5px; font-size: .84em; color: #6d28d9; }
.markdown-content pre     { background: #1e1b4b; border-radius: 10px; padding: 14px 16px; overflow-x: auto; }
.markdown-content pre code { background: none; color: #e0d7ff; padding: 0; font-size: .84em; }
.markdown-content blockquote {
  border-left: 3px solid #7c3aed; margin: 8px 0;
  padding: 6px 12px; background: #faf5ff; border-radius: 0 8px 8px 0; color: #5b21b6;
}
.markdown-content table { width: 100%; border-collapse: collapse; font-size: .84em; margin: 8px 0; }
.markdown-content th { background: #f5f3ff; font-weight: 600; padding: 7px 10px; border: 1px solid #ede9fe; }
.markdown-content td { padding: 7px 10px; border: 1px solid #ede9fe; }
.markdown-content a  { color: #7c3aed; text-decoration: underline; }
.markdown-content strong { font-weight: 700; }
.markdown-content hr { border: none; border-top: 1px solid #ede9fe; margin: 10px 0; }

/* ═══════════════════════════════════════════════════════════════════
   ADMIN / SETTINGS / CANNED — page frame
   ═══════════════════════════════════════════════════════════════════ */

.page-frame {
  margin-top: var(--app-nav-h);
  min-height: calc(100vh - var(--app-nav-h));
  padding: 28px 28px 40px;
}
@media (max-width: 767.98px) { .page-frame { padding: 16px 14px 32px; } }
@media (max-width: 575.98px) { .page-frame { padding: 12px 10px 24px; } }

.page-hdr { margin-bottom: 28px; }
.page-hdr h1 { font-size: 1.5rem; font-weight: 800; color: #1a1a2e; margin: 0; }
.page-hdr p  { color: #6b7280; margin: 5px 0 0; font-size: .9375rem; }
@media (max-width: 575.98px) {
  .page-hdr h1 { font-size: 1.25rem; }
  .page-hdr p  { font-size: .875rem; }
}

/* ─ Stat cards ─ */
.stat-card {
  background: #fff; border: 1px solid #ede9fe; border-radius: 14px;
  padding: 20px 22px; box-shadow: 0 2px 10px rgba(124,58,237,.07);
  transition: box-shadow .2s;
}
.stat-card:hover { box-shadow: 0 4px 18px rgba(124,58,237,.13); }
.stat-card-value { font-size: 2.25rem; font-weight: 800; color: #1a1a2e; line-height: 1; }
.stat-card-label { font-size: .875rem; color: #6b7280; margin-top: 5px; }
.stat-card.enabled  .stat-card-value { color: #059669; }
.stat-card.disabled .stat-card-value { color: #dc2626; }

/* App Cards */
.app-card {
  background: #fff; border: 1px solid #ede9fe; border-radius: 14px;
  box-shadow: 0 2px 10px rgba(124,58,237,.07); margin-bottom: 22px; overflow: hidden;
}
.app-card-hdr {
  display: flex; align-items: center; gap: 12px;
  padding: 16px 22px; border-bottom: 1px solid #f5f3ff; background: #faf9ff;
}
.app-card-hdr h2, .app-card-hdr h3 { font-size: 1rem; font-weight: 700; color: #1a1a2e; margin: 0; }
.app-card-badge {
  font-size: .72rem; font-weight: 700; padding: 2px 9px;
  border-radius: 99px; background: #ede9fe; color: #5b21b6;
  border: 1px solid #ddd6fe; letter-spacing: .04em;
}
.app-card-icon {
  width: 34px; height: 34px;
  background: linear-gradient(135deg, #7c3aed, #a855f7);
  border-radius: 9px; display: flex; align-items: center; justify-content: center; flex-shrink: 0;
}
.app-card-body { padding: 22px; }
@media (max-width: 575.98px) { .app-card-body { padding: 14px; } }

/* ─ Tables ─ */
.table-app thead th {
  background: #faf9ff; color: #6b7280; font-size: .8rem; font-weight: 700;
  text-transform: uppercase; letter-spacing: .05em;
  border-bottom: 2px solid #ede9fe; white-space: nowrap; vertical-align: middle;
}
.table-app td { font-size: .9375rem; color: #1a1a2e; vertical-align: middle; }
.table-app tbody tr:hover { background: #faf9ff; }
.th-sortable { cursor: pointer; user-select: none; }
.th-sortable:hover { color: #1a1a2e; }
.sort-arrow { font-size: .72rem; color: #9ca3af; margin-left: 4px; }
.sort-arrow.active { color: #7c3aed; }
.td-check, .th-check { width: 44px; text-align: center; }
.td-actions { white-space: nowrap; }

/* 手機表格：水平捲動 */
.table-responsive { -webkit-overflow-scrolling: touch; }

/* Cell filename */
.cell-filename { display: flex; align-items: center; gap: 8px; }
.file-icon {
  font-size: .6rem; font-weight: 700; padding: 2px 6px; border-radius: 5px;
  flex-shrink: 0; text-transform: uppercase; background: #f3f4f6; color: #6b7280;
}
.file-icon.pdf   { background: #fee2e2; color: #dc2626; }
.file-icon.docx, .file-icon.doc  { background: #dbeafe; color: #1d4ed8; }
.file-icon.xlsx, .file-icon.xls  { background: #d1fae5; color: #059669; }
.file-icon.pptx, .file-icon.ppt  { background: #fef3c7; color: #d97706; }
.file-icon.txt,  .file-icon.md   { background: #f5f3ff; color: #7c3aed; }
.file-icon.jpg, .file-icon.jpeg, .file-icon.png,
.file-icon.bmp, .file-icon.gif,  .file-icon.tiff,
.file-icon.tif, .file-icon.webp  { background: #ecfdf5; color: #059669; }
.file-icon.url   { background: #ede9fe; color: #6d28d9; }

/* Status badges */
.status-badge {
  display: inline-flex; align-items: center; gap: 5px;
  font-size: .78rem; font-weight: 600; padding: 3px 9px;
  border-radius: 99px; white-space: nowrap;
}
.status-dot { width: 6px; height: 6px; border-radius: 50%; flex-shrink: 0; }
.status-badge.COMPLETED  { background: #d1fae5; color: #065f46; }
.status-badge.COMPLETED .status-dot  { background: #059669; }
.status-badge.PENDING    { background: #f3f4f6; color: #4b5563; }
.status-badge.PENDING .status-dot    { background: #9ca3af; }
.status-badge.PARSING    { background: #ede9fe; color: #4c1d95; }
.status-badge.PARSING .status-dot    { background: #7c3aed; animation: dotPulse 1.2s infinite; }
.status-badge.PROCESSING { background: #fef3c7; color: #92400e; }
.status-badge.PROCESSING .status-dot { background: #f59e0b; animation: dotPulse 1.2s infinite; }
.status-badge.FAILED     { background: #fee2e2; color: #991b1b; }
.status-badge.FAILED .status-dot     { background: #ef4444; }
@keyframes dotPulse { 0%, 100% { opacity: 1; } 50% { opacity: .35; } }

/* Provider badges */
.provider-badge {
  font-size: .68rem; font-weight: 700; padding: 1px 5px;
  border-radius: 4px; display: inline-block; flex-shrink: 0; white-space: nowrap;
}
.provider-badge.bedrock    { background: #fef3c7; color: #92400e; }
.provider-badge.openrouter { background: #dbeafe; color: #1e40af; }
.provider-badge.ollama     { background: #d1fae5; color: #065f46; }
.provider-badge.unknown    { background: #f3f4f6; color: #6b7280; }

/* Dataset chip */
.ds-chip { font-size: .82rem; font-weight: 600; color: #5b21b6; background: #ede9fe; padding: 2px 8px; border-radius: 5px; display: inline-block; }
.ds-chip.muted { color: #9ca3af; background: #f3f4f6; }

/* No-match row */
.no-match-cell { text-align: center; color: #9ca3af; font-size: .9375rem; padding: 28px !important; }

/* Bulk bar */
.bulk-bar {
  display: none; align-items: center; gap: 12px;
  background: #f5f3ff; border-top: 1px solid #ddd6fe; border-bottom: 1px solid #ddd6fe;
  padding: 9px 16px; font-size: .875rem;
}
.bulk-bar.show { display: flex; }

/* Search box */
.search-box { position: relative; display: flex; align-items: center; }
.search-box svg { position: absolute; left: 10px; color: #9ca3af; pointer-events: none; }
.search-box input {
  padding: 8px 12px 8px 36px; border: 1px solid #e5e7eb; border-radius: 9px;
  font-size: .9rem; background: #fff; transition: border-color .15s, box-shadow .15s;
  outline: none; min-width: 220px; font-family: inherit; color: #1a1a2e;
}
.search-box input:focus { border-color: #7c3aed; box-shadow: 0 0 0 2px rgba(124,58,237,.12); }
@media (max-width: 575.98px) { .search-box input { min-width: 0; width: 100%; } }

/* Docs toolbar */
.docs-toolbar {
  padding: 12px 16px; border-bottom: 1px solid #f5f3ff;
  display: flex; align-items: center; justify-content: space-between; gap: 12px;
  flex-wrap: wrap;
}

/* Pagination bar */
.pagination-bar {
  display: none; align-items: center; gap: 14px;
  padding: 11px 16px; border-top: 1px solid #f5f3ff;
  font-size: .875rem; color: #6b7280; flex-wrap: wrap;
}
.pagination-bar.visible { display: flex; }
.page-size-select { display: flex; align-items: center; gap: 6px; }
.page-size-select select {
  padding: 4px 8px; border: 1px solid #e5e7eb; border-radius: 7px;
  font-size: .875rem; font-family: inherit;
}
.page-nav { display: flex; gap: 6px; margin-left: auto; }
.page-nav button {
  padding: 5px 14px; border: 1px solid #e5e7eb; border-radius: 7px;
  background: #fff; font-size: .875rem; cursor: pointer; font-family: inherit;
  transition: background .12s, border-color .12s, color .12s;
}
.page-nav button:not(:disabled):hover { background: #f5f3ff; border-color: #7c3aed; color: #7c3aed; }
.page-nav button:disabled { opacity: .4; cursor: not-allowed; }

/* Empty state */
.empty-state {
  padding: 56px 24px; text-align: center;
  display: flex; flex-direction: column; align-items: center; gap: 14px; color: #9ca3af;
}
.empty-state svg { opacity: .3; }
.empty-state p   { font-size: .9375rem; margin: 0; line-height: 1.7; }

/* Drop zone */
.drop-zone {
  border: 2px dashed #ddd6fe; border-radius: 14px; padding: 32px 24px;
  text-align: center; cursor: pointer;
  transition: border-color .15s, background .15s; position: relative; background: #faf9ff;
}
.drop-zone:hover, .drop-zone.drag-over { border-color: #7c3aed; background: #f5f3ff; }
.drop-zone input[type="file"] { position: absolute; inset: 0; opacity: 0; cursor: pointer; width: 100%; }
.drop-icon  { margin-bottom: 12px; }
.drop-title { font-weight: 700; color: #1a1a2e; font-size: 1rem; margin-bottom: 5px; }
.drop-sub   { font-size: .84rem; color: #6b7280; margin-bottom: 12px; }
.drop-types { display: flex; flex-wrap: wrap; gap: 5px; justify-content: center; }
.type-badge { background: #f3f4f6; color: #6b7280; font-size: .72rem; font-weight: 700; padding: 2px 7px; border-radius: 5px; }

/* Upload progress */
.upload-progress { margin-top: 14px; display: none; }
.upload-progress.show { display: block; }
.progress-bar-wrap { background: #ede9fe; border-radius: 99px; height: 6px; overflow: hidden; }
.progress-bar-fill { background: linear-gradient(90deg, #7c3aed, #a855f7); height: 100%; border-radius: 99px; transition: width .3s; }
.progress-label { font-size: .8rem; color: #6b7280; margin-top: 5px; }

/* Parse progress inline */
.parse-progress-inline {
  display: inline-flex; align-items: center; gap: 6px;
  background: #f5f3ff; border-radius: 7px; padding: 3px 9px; min-width: 80px;
}
.parse-progress-fill { flex: 1; height: 4px; background: #7c3aed; border-radius: 99px; transition: width .3s; }
.parse-progress-pct  { font-size: .72rem; font-weight: 600; color: #5b21b6; min-width: 28px; text-align: right; }
.parse-progress-inline.hidden, .btn-play.hidden, .btn-download.hidden { display: none !important; }

/* Action buttons */
.btn-play, .btn-download, .btn-del, .btn-ds-edit, .btn-ds-del {
  width: 30px; height: 30px; border-radius: 7px; border: none;
  background: none; display: inline-flex; align-items: center; justify-content: center;
  cursor: pointer; transition: background .12s, color .12s; color: #9ca3af;
}
.btn-play:hover     { background: #ede9fe; color: #5b21b6; }
.btn-download:hover { background: #d1fae5; color: #059669; }
.btn-del:hover, .btn-ds-del:hover { background: #fee2e2; color: #dc2626; }
.btn-ds-edit:hover  { background: #ede9fe; color: #7c3aed; }

/* ─ 知識庫模式指示橫幅 ─ */
.kb-mode-banner {
  border-radius: 12px; padding: 12px 16px; margin-bottom: 18px;
  border: 1px solid #e5e7eb;
}
.kb-mode-banner.local   { background: linear-gradient(135deg, #f5f3ff 0%, #fafafa 100%); border-color: #ddd6fe; }
.kb-mode-banner.bedrock { background: linear-gradient(135deg, #fffbeb 0%, #fafafa 100%); border-color: #fde68a; }

.kb-mode-row {
  display: flex; align-items: center; justify-content: space-between;
  gap: 12px; flex-wrap: wrap;
}
.kb-mode-left  { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; }
.kb-mode-right { display: flex; align-items: center; gap: 8px; flex-shrink: 0; }

/* 模式 badge */
.kb-mode-badge {
  display: inline-flex; align-items: center; gap: 5px;
  padding: 4px 10px; border-radius: 20px; font-size: .78rem; font-weight: 700;
  white-space: nowrap;
}
.kb-mode-badge.local   { background: #ede9fe; color: #5b21b6; }
.kb-mode-badge.bedrock { background: #fde68a; color: #92400e; }

/* 說明文字 */
.kb-mode-desc { font-size: .82rem; color: #6b7280; }
.kb-mode-desc strong { color: #374151; }
.kb-mode-no-parser {
  display: inline-block; margin-left: 4px;
  font-size: .75rem; font-weight: 600; color: #d97706;
  background: #fef3c7; border-radius: 4px; padding: 1px 6px;
}

/* 解析器 badge + 切換按鈕（沿用原樣式移至此處） */
.parser-badge {
  display: inline-flex; align-items: center; gap: 6px;
  padding: 4px 10px; border-radius: 7px; font-size: .82rem; font-weight: 700;
  background: #f3f4f6; color: #6b7280;
}
.parser-badge.tika    { background: #d1fae5; color: #065f46; }
.parser-badge.deepdoc { background: #ede9fe; color: #5b21b6; }
.btn-switch-parser {
  display: inline-flex; align-items: center; gap: 5px;
  padding: 4px 12px; border-radius: 7px; font-size: .82rem; font-weight: 600;
  border: 1px solid #e5e7eb; background: #fff; cursor: pointer; font-family: inherit;
  transition: background .12s, border-color .12s, color .12s;
}
.btn-switch-parser:hover { background: #f5f3ff; border-color: #7c3aed; color: #5b21b6; }

/* 前往設定連結（Bedrock 模式右側） */
.kb-mode-settings-link {
  display: inline-flex; align-items: center; gap: 5px;
  font-size: .82rem; font-weight: 600; color: #d97706;
  text-decoration: none; padding: 4px 12px; border-radius: 7px;
  border: 1px solid #fde68a; background: #fffbeb;
  transition: background .12s, border-color .12s;
}
.kb-mode-settings-link:hover { background: #fef3c7; border-color: #f59e0b; color: #92400e; }

/* URL card */
.url-input-row { display: flex; gap: 8px; margin-top: 10px; flex-wrap: wrap; }
.url-input-row input { flex: 1; min-width: 200px; }
.url-name-row { margin-top: 12px; display: flex; align-items: center; gap: 8px; }
.url-label { font-size: .84rem; font-weight: 600; color: #6b7280; white-space: nowrap; min-width: 60px; }
.url-hint { font-size: .82rem; color: #9ca3af; margin-top: 8px; }
.btn-parse {
  display: inline-flex; align-items: center; gap: 6px;
  padding: 8px 18px; background: #7c3aed; color: #fff;
  border: none; border-radius: 9px; font-size: .9rem; font-weight: 600;
  cursor: pointer; transition: background .15s; white-space: nowrap; font-family: inherit;
}
.btn-parse:hover:not(:disabled) { background: #6d28d9; }
.btn-parse:disabled { background: #9ca3af; cursor: not-allowed; }

/* Dataset select row（預設：位於頂部，下方分隔線） */
.dataset-select-row {
  display: flex; align-items: center; gap: 8px; flex-wrap: wrap;
  margin-bottom: 14px; padding-bottom: 14px; border-bottom: 1px solid #f5f3ff;
}
/* 位於底部時（URL Card）：改為上方分隔線 */
.dataset-select-row.row-bottom {
  margin-bottom: 0; padding-bottom: 0; border-bottom: none;
  margin-top: 12px; padding-top: 12px; border-top: 1px solid #f5f3ff;
}
.dataset-select-row label {
  font-size: .84rem; font-weight: 600; color: #6b7280; white-space: nowrap;
  display: flex; align-items: center; gap: 4px; flex-shrink: 0;
}
.dataset-select-row select { font-size: .875rem; min-width: 160px; }

/* Dataset name link */
.ds-name-link { color: #7c3aed; font-weight: 600; text-decoration: none; }
.ds-name-link:hover { text-decoration: underline; }

/* Create dataset row */
.dataset-create-row { display: flex; gap: 10px; align-items: center; flex-wrap: wrap; }
.dataset-create-row input { flex: 1; min-width: 0; }

/* Toast container */
#toastContainer {
  position: fixed; bottom: 20px; right: 20px; z-index: 9999;
  display: flex; flex-direction: column; gap: 8px; min-width: 280px;
}
@media (max-width: 575.98px) {
  #toastContainer { right: 10px; left: 10px; min-width: 0; }
}

/* ─ Page tabs ─ */
.page-tab-nav {
  display: flex; gap: 2px; border-bottom: 2px solid #e5e7eb;
  margin-bottom: 22px; overflow-x: auto; scrollbar-width: none;
}
.page-tab-nav::-webkit-scrollbar { display: none; }
.page-tab-btn {
  display: flex; align-items: center; gap: 7px;
  padding: 10px 20px; font-size: .9rem; font-weight: 600; font-family: inherit;
  color: #6b7280; background: none; border: none;
  border-bottom: 2px solid transparent; margin-bottom: -2px;
  cursor: pointer; white-space: nowrap; transition: color .15s, border-color .15s;
}
.page-tab-btn:hover  { color: #1a1a2e; }
.page-tab-btn.active { color: #7c3aed; border-bottom-color: #7c3aed; }
.page-tab-panel        { display: none; }
.page-tab-panel.active { display: block; }

/* ─ Settings 兩欄分組佈局 ─ */
.tab-panel        { display: none; }
.tab-panel.active { display: block; }

/* 外層兩欄 */
.settings-layout {
  display: flex;
  gap: 24px;
  align-items: flex-start;
}

/* 左側垂直分組導覽 */
.settings-sidenav {
  width: 210px;
  flex-shrink: 0;
  background: #fff;
  border: 1px solid #e5e7eb;
  border-radius: 14px;
  padding: 10px 8px;
  position: sticky;
  top: calc(var(--app-nav-h) + 72px);
}

/* 群組 */
.settings-group { margin-bottom: 4px; }
.settings-group + .settings-group {
  border-top: 1px solid #e5e7eb;
  padding-top: 8px;
  margin-top: 6px;
}

/* 群組標題 */
.settings-group-label {
  display: flex; align-items: center; gap: 5px;
  font-size: .69rem; font-weight: 700; color: #9ca3af;
  text-transform: uppercase; letter-spacing: .06em;
  padding: 4px 10px 6px;
}

/* 群組說明文字 */
.settings-group-desc {
  font-size: .7rem; color: #b0b7c3;
  padding: 0 10px 6px; line-height: 1.45;
}

/* 子群組分隔線標籤 */
.settings-subgroup-label {
  font-size: .67rem; font-weight: 700; color: #c4b5fd;
  text-transform: uppercase; letter-spacing: .05em;
  padding: 8px 10px 2px;
}

/* 導覽按鈕 */
.settings-nav-item {
  display: flex; align-items: center; gap: 8px;
  width: 100%; padding: 7px 10px;
  border: none; border-radius: 8px; background: none;
  font-size: .84rem; font-weight: 500; color: #374151; font-family: inherit;
  cursor: pointer; text-align: left;
  transition: background .12s, color .12s;
  white-space: nowrap;
}
.settings-nav-item:hover { background: #f5f3ff; color: #7c3aed; }
.settings-nav-item.active { background: #ede9fe; color: #6d28d9; font-weight: 600; }
.settings-nav-item svg { flex-shrink: 0; opacity: .65; }
.settings-nav-item.active svg { opacity: 1; }

/* 供應商選擇群組 — 最上方獨立入口 */
.settings-group-provider {
  background: linear-gradient(135deg, #f5f3ff 0%, #fff 100%);
  border-radius: 10px;
  padding: 6px 4px;
  border: 1px solid #ddd6fe;
  margin-bottom: 4px;
}
.settings-group-provider .settings-group-label { color: #7c3aed; }

/* 本地模式群組 — 藍色標示本地/OpenRouter/Ollama */
.settings-group-local {
  background: linear-gradient(135deg, #eff6ff 0%, #f0f9ff 100%);
  border-radius: 10px;
  padding: 6px 4px;
  border: 1px solid #bfdbfe;
  margin-top: 4px;
}
.settings-group-local .settings-group-label { color: #1d4ed8; }
.settings-group-local .settings-group-desc  { color: #4b7bc4; }
.settings-group-local .settings-nav-item:hover  { background: #dbeafe; color: #1e40af; }
.settings-group-local .settings-nav-item.active { background: #bfdbfe; color: #1e3a8a; }

/* AWS Bedrock 群組 — 橘黃色標示獨立性 */
.settings-group-aws {
  background: linear-gradient(135deg, #fffbeb 0%, #fff7ed 100%);
  border-radius: 10px;
  padding: 6px 4px;
  border: 1px solid #fde68a;
  margin-top: 8px !important;
}
.settings-group-aws .settings-group-label { color: #d97706; }
.settings-group-aws .settings-group-desc  { color: #c4933a; }
.settings-group-aws .settings-nav-item:hover  { background: #fef3c7; color: #b45309; }
.settings-group-aws .settings-nav-item.active { background: #fde68a; color: #92400e; }

/* 右側內容區 */
.settings-content { flex: 1; min-width: 0; }

/* RWD — 手機版垂直排列 */
@media (max-width: 767.98px) {
  .settings-layout   { flex-direction: column; }
  .settings-sidenav  { width: 100%; position: static; border-radius: 10px; }
  .settings-nav-item { font-size: .875rem; }
}

/* ─ Settings field rows ─ */
.field-row {
  display: grid; grid-template-columns: 220px 1fr;
  align-items: start; gap: 14px; padding: 12px 0; border-bottom: 1px solid #f9f8ff;
}
.field-row:last-child { border-bottom: none; }
@media (max-width: 767.98px) {
  .field-row { grid-template-columns: 1fr; gap: 6px; }
}
.field-label { font-size: .9rem; font-weight: 600; color: #1a1a2e; padding-top: 8px; line-height: 1.4; }
.field-label small { display: block; font-size: .75rem; font-weight: 400; color: #9ca3af; margin-top: 3px; }
.field-input .hint { font-size: .75rem; color: #9ca3af; margin-top: 5px; }
.field-input input[type="number"] { max-width: 140px; }
.field-input textarea { width: 100%; resize: vertical; font-size: .9rem; font-family: inherit; }

/* Password wrap */
.password-wrap { position: relative; }
.password-wrap input { padding-right: 40px; }
.toggle-pw {
  position: absolute; right: 8px; top: 50%; transform: translateY(-50%);
  background: none; border: none; cursor: pointer; color: #9ca3af; padding: 2px;
}
.toggle-pw:hover { color: #7c3aed; }

/* Range */
.range-wrap { display: flex; align-items: center; gap: 10px; }
.range-wrap input[type="range"] { flex: 1; accent-color: #7c3aed; }
.range-val { min-width: 36px; text-align: right; font-size: .875rem; font-weight: 700; color: #7c3aed; }

/* Validate row */
.validate-row {
  display: flex; align-items: center; gap: 14px; flex-wrap: wrap;
  padding: 18px 0 4px; border-top: 1px solid #f5f3ff; margin-top: 4px;
}
.btn-validate {
  display: inline-flex; align-items: center; gap: 6px;
  padding: 8px 18px; border: 1px solid #7c3aed; border-radius: 9px;
  background: #fff; color: #7c3aed; font-size: .9rem; font-weight: 600;
  cursor: pointer; font-family: inherit; transition: background .15s;
}
.btn-validate:hover:not(:disabled) { background: #f5f3ff; }
.btn-validate:disabled { opacity: .5; cursor: not-allowed; }
.validate-status { font-size: .875rem; font-weight: 600; display: none; }
.validate-status.success { color: #059669; display: inline; }
.validate-status.error   { color: #dc2626; display: inline; }

/* Save bar */
.save-bar {
  position: sticky; top: var(--app-nav-h); z-index: 200;
  background: #fff; border-bottom: 1px solid #ede9fe;
  padding: 11px 24px; display: flex; align-items: center; gap: 14px; flex-wrap: wrap;
  box-shadow: 0 2px 10px rgba(124,58,237,.08);
}
@media (max-width: 575.98px) { .save-bar { padding: 9px 14px; } }
.save-status { font-size: .875rem; font-weight: 600; display: none; }
.save-status.success { color: #059669; display: inline; }
.save-status.error   { color: #dc2626; display: inline; }

/* Provider option cards */
.provider-options { display: flex; flex-direction: column; gap: 12px; }
.provider-option { cursor: pointer; }
.provider-option input[type="radio"] { position: absolute; opacity: 0; width: 0; height: 0; }
.provider-card {
  border: 2px solid #e5e7eb; border-radius: 12px; padding: 16px 18px;
  transition: border-color .15s, background .15s;
  display: flex; align-items: flex-start; gap: 14px;
}
.provider-option input:checked + .provider-card { border-color: #7c3aed; background: #faf9ff; }
.provider-card-icon {
  width: 38px; height: 38px; border-radius: 9px; background: #f3f4f6;
  display: flex; align-items: center; justify-content: center; flex-shrink: 0;
}
.provider-option input:checked + .provider-card .provider-card-icon { background: #7c3aed; }
.provider-option input:checked + .provider-card .provider-card-icon svg { stroke: #fff; }
.provider-card-info { flex: 1; }
.provider-card-name { font-size: .9375rem; font-weight: 700; color: #1a1a2e; }
.provider-card-desc { font-size: .78rem; color: #6b7280; margin-top: 3px; }
.provider-check {
  width: 18px; height: 18px; border: 2px solid #d1d5db; border-radius: 50%;
  display: flex; align-items: center; justify-content: center; flex-shrink: 0; margin-top: 2px;
}
.provider-option input:checked + .provider-card .provider-check { border-color: #7c3aed; background: #7c3aed; }
.provider-option input:checked + .provider-card .provider-check::after {
  content: ''; width: 6px; height: 6px; background: #fff; border-radius: 50%;
}

/* Checkbox wrap */
.checkbox-wrap { display: flex; align-items: flex-start; gap: 10px; cursor: pointer; }
.checkbox-wrap input[type="checkbox"] { margin-top: 4px; flex-shrink: 0; }
.cb-label { font-size: .9rem; color: #1a1a2e; line-height: 1.55; }
.cb-label small { display: block; font-size: .75rem; color: #9ca3af; margin-top: 3px; }

/* KB sync result */
.kb-sync-result {
  display: none; margin-top: 10px;
  background: #faf9ff; border: 1px solid #ddd6fe; border-radius: 10px;
  padding: 14px 16px; font-family: 'Menlo', 'Consolas', monospace;
  font-size: .82rem; line-height: 1.65; color: #1a1a2e;
  white-space: pre-wrap; max-height: 300px; overflow-y: auto;
}

/* ─ Toggle switch ─ */
.toggle-switch { position: relative; display: inline-block; width: 42px; height: 24px; }
.toggle-switch input { opacity: 0; width: 0; height: 0; }
.toggle-slider {
  position: absolute; inset: 0; background: #d1d5db; border-radius: 24px;
  cursor: pointer; transition: background .2s;
}
.toggle-slider::before {
  content: ''; position: absolute; width: 18px; height: 18px;
  left: 3px; top: 3px; background: #fff; border-radius: 50%;
  transition: transform .2s; box-shadow: 0 1px 3px rgba(0,0,0,.18);
}
.toggle-switch input:checked + .toggle-slider { background: #7c3aed; }
.toggle-switch input:checked + .toggle-slider::before { transform: translateX(18px); }

/* Keyword chips */
.keyword-chips { display: flex; flex-wrap: wrap; gap: 4px; }
.keyword-chip {
  display: inline-block; padding: 2px 8px; border-radius: 5px;
  background: #f5f3ff; color: #5b21b6; font-size: .75rem; font-weight: 600;
  border: 1px solid #ddd6fe; white-space: nowrap;
}
.answer-preview {
  display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical;
  overflow: hidden; font-size: .875rem; color: #6b7280; line-height: 1.55; max-width: 320px;
}

/* Back button */
.btn-back {
  display: inline-flex; align-items: center; gap: 5px;
  padding: 6px 14px; border: 1px solid #e5e7eb; border-radius: 8px;
  background: #fff; font-size: .875rem; color: #6b7280;
  text-decoration: none; transition: background .12s, border-color .12s, color .12s;
}
.btn-back:hover { background: #f5f3ff; border-color: #7c3aed; color: #7c3aed; }

/* ─ Breadcrumb ─ */
.breadcrumb { font-size: .875rem; }
.breadcrumb-item a { color: #7c3aed; text-decoration: none; }
.breadcrumb-item a:hover { text-decoration: underline; }

/* ─ RWD utility ─ */
@media (max-width: 575.98px) {
  .btn { font-size: .875rem; }
  .table-app td, .table-app th { font-size: .84rem; }
}
