:root {
  --fill-general: #ffffff;
  --fill-upper: #ffffff;
  --fill-block: #f7f8fa;
  --button-fill: rgba(0,0,0,0.9);
  --button-text: #ffffff;
  --text-title: #232833;
  --text-body: #4e5666;
  --text-support: #818999;
  --text-disable: #bcc1cc;
  --line: rgba(35,40,51,0.1);
  --ux-hover: rgba(35,40,51,0.06);
  --ux-active: rgba(35,40,51,0.12);
  --ux-primary-select: rgba(0,196,255,0.08);
  --ux-primary-hover: rgba(0,196,255,0.16);
  --ux-primary-active: rgba(0,196,255,0.24);
  --brand: #00c4ff;
  --brand-lighter: #c2f1ff;
  --brand-dark: #0e404f;
  --gray: #727c8f;
  --shadow-1: rgba(0,0,0,0.07);
  --shadow-2: rgba(0,0,0,0.1);
}

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

body {
  font-family: 'Inter', -apple-system, BlinkMacSystemFont, sans-serif;
  background: var(--fill-general);
  display: flex;
  height: 100vh;
  overflow: hidden;
}

/* ===== Page Layout ===== */
.page-body {
  display: flex;
  width: 100%;
  height: 100vh;
  position: relative;
}

/* ===== Sidebar ===== */
.sidebar {
  width: 240px;
  min-width: 240px;
  background: var(--fill-general);
  border-right: 1px solid var(--line);
  display: flex;
  flex-direction: column;
  height: 100%;
}

.sidebar-top {
  display: flex;
  flex-direction: column;
  gap: 12px;
  padding: 12px 8px 0;
  flex: 1;
}

.sidebar-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  height: 48px;
  padding: 0 8px;
}

.sidebar-logo {
  display: flex;
  align-items: center;
  gap: 4px;
}

.logo-icon {
  width: 28px;
  height: 28px;
  flex-shrink: 0;
}

.logo-icon img {
  width: 28px;
  height: 28px;
  object-fit: contain;
}

.logo-text {
  font-size: 17px;
  font-weight: 700;
  color: var(--text-title);
  letter-spacing: -0.3px;
}

.nav-toggle-btn {
  width: 24px;
  height: 24px;
  display: flex;
  align-items: center;
  justify-content: center;
  border: none;
  background: transparent;
  border-radius: 4px;
  cursor: pointer;
  flex-shrink: 0;
}

.nav-toggle-btn svg {
  width: 16px;
  height: 16px;
  color: var(--text-support);
  display: block;
}

.create-btn {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  width: 100%;
  height: 36px;
  background: var(--button-fill);
  color: var(--button-text);
  border: none;
  border-radius: 100px;
  font-size: 14px;
  font-weight: 600;
  cursor: pointer;
  font-family: inherit;
}

.create-btn svg {
  display: block;
  flex-shrink: 0;
}

/* ===== Nav Items ===== */
.nav-section {
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.nav-section-title {
  font-size: 12px;
  font-weight: 500;
  color: var(--text-disable);
  padding: 12px 12px 4px;
}

.nav-item {
  display: flex;
  align-items: center;
  gap: 8px;
  height: 32px;
  padding: 4px 12px;
  border-radius: 8px;
  cursor: pointer;
  font-size: 14px;
  font-weight: 500;
  color: var(--text-body);
  text-decoration: none;
}

.nav-item:hover { background: var(--ux-hover); }

.nav-item.active {
  background: var(--ux-primary-select);
  color: var(--brand-dark);
  font-weight: 600;
}

.nav-icon {
  width: 20px;
  height: 20px;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
}

.nav-icon svg {
  width: 18px;
  height: 18px;
}

.nav-trailing {
  margin-left: auto;
  width: 20px;
  height: 20px;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: 100px;
  cursor: pointer;
}

.nav-trailing:hover { background: var(--ux-hover); }

.nav-trailing svg {
  width: 14px;
  height: 14px;
  color: var(--text-support);
}

/* ===== Sidebar Bottom ===== */
.sidebar-bottom {
  padding: 0 8px 20px;
  display: flex;
  flex-direction: column;
  gap: 8px;
  border-top: 1px solid var(--line);
  padding-top: 12px;
}

.video-ready-bar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 4px 12px;
  font-size: 12px;
}

.video-ready-bar span:first-child {
  color: var(--text-body);
  font-weight: 500;
}

.video-ready-bar a {
  color: var(--brand-dark);
  font-weight: 600;
  text-decoration: none;
  font-size: 12px;
}

.notification-bar {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 6px 12px;
  font-size: 14px;
  font-weight: 500;
  color: var(--text-body);
  cursor: pointer;
  border-radius: 8px;
}

.notification-bar:hover { background: var(--ux-hover); }

.notif-icon-wrap {
  width: 20px;
  height: 20px;
  display: flex;
  align-items: center;
  justify-content: center;
  position: relative;
}

.notif-icon-wrap svg {
  width: 18px;
  height: 18px;
}

.notif-ring {
  margin-left: auto;
  width: 20px;
  height: 20px;
  position: relative;
}

.notif-ring svg {
  width: 20px;
  height: 20px;
  animation: notif-spin 1.5s linear infinite;
}

@keyframes notif-spin {
  from { transform: rotate(0deg); }
  to { transform: rotate(360deg); }
}

.share-card {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 12px;
  border-radius: 8px;
  cursor: pointer;
  background: linear-gradient(143deg, rgba(233,233,232,0.4) 5.71%, rgba(223,248,255,0.4) 65.27%, rgba(250,177,66,0.16) 119.09%);
}

.share-icon {
  width: 24px;
  height: 24px;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  font-size: 16px;
}

.share-info {
  display: flex;
  flex-direction: column;
}

.share-title {
  font-size: 12px;
  font-weight: 600;
  color: var(--text-title);
  line-height: 16px;
}

.share-desc {
  font-size: 10px;
  color: var(--text-support);
  line-height: 14px;
}

.user-profile {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 8px 12px;
  border-radius: 8px;
  cursor: pointer;
}

.user-profile:hover { background: var(--ux-hover); }

.user-avatar {
  width: 32px;
  height: 32px;
  border-radius: 8px;
  overflow: hidden;
  flex-shrink: 0;
}

.user-avatar img {
  width: 100%;
  height: 100%;
  object-fit: cover;
}

.user-info { display: flex; flex-direction: column; flex: 1; }

.user-name {
  font-size: 14px;
  font-weight: 600;
  color: var(--text-title);
  line-height: 20px;
}

.user-plan {
  font-size: 12px;
  color: var(--text-support);
  line-height: 16px;
}

.user-arrow {
  margin-left: auto;
  color: var(--text-support);
  display: flex;
}

/* ===== Scrollbar ===== */
::-webkit-scrollbar { width: 6px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: var(--text-disable); border-radius: 3px; }
::-webkit-scrollbar-thumb:hover { background: var(--text-support); }

/* ================================================================
   Project Header & Selector
   ================================================================ */

.project-selector {
  display: flex;
  align-items: center;
  gap: 8px;
}
.project-selector-name {
  font-size: 22px;
  font-weight: 700;
  color: var(--text-title);
  padding: 2px 6px 2px 0;
  border-radius: 6px;
  cursor: text;
  transition: background 0.15s;
}
.project-selector-name:hover { background: var(--ux-hover); }
.project-selector-chevron {
  width: 24px;
  height: 24px;
  border-radius: 50%;
  border: 1.5px solid var(--line);
  background: transparent;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  cursor: pointer;
  transition: background 0.15s;
}
.project-selector-chevron:hover { background: var(--ux-hover); }
.project-selector-chevron svg { width: 12px; height: 12px; color: var(--text-support); }


/* ================================================================
   Modal Overlay
   ================================================================ */

.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.4);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 1000;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.15s;
}
.modal-overlay.visible { opacity: 1; pointer-events: auto; }

.modal-close-btn {
  width: 28px;
  height: 28px;
  border: none;
  background: transparent;
  cursor: pointer;
  color: var(--text-support);
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: 6px;
}
.modal-close-btn:hover { background: var(--ux-hover); }
.modal-close-btn svg { width: 16px; height: 16px; }

/* Project Picker Modal */
.project-modal-box {
  background: var(--fill-general);
  border-radius: 16px;
  width: 480px;
  max-height: 70vh;
  padding: 24px;
  transform: translateY(10px);
  transition: transform 0.2s;
  display: flex;
  flex-direction: column;
}
.modal-overlay.visible .project-modal-box { transform: translateY(0); }
.project-modal-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 16px;
}
.project-modal-header h3 {
  font-size: 18px;
  font-weight: 600;
  color: var(--text-title);
  margin: 0;
}
.project-list {
  flex: 1;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  gap: 4px;
}
.project-list-item {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 10px 12px;
  border: none;
  background: transparent;
  border-radius: 10px;
  cursor: pointer;
  font-family: inherit;
  text-align: left;
  width: 100%;
  transition: background 0.12s;
}
.project-list-item:hover { background: var(--ux-hover); }
.project-list-item.active { background: var(--fill-block); }
.project-list-icon {
  width: 36px;
  height: 36px;
  border-radius: 8px;
  background: var(--fill-block);
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
}
.project-list-item.active .project-list-icon { background: var(--brand); }
.project-list-icon svg { width: 18px; height: 18px; color: var(--text-support); }
.project-list-item.active .project-list-icon svg { color: #fff; }
.project-list-info {
  flex: 1;
  min-width: 0;
}
.project-list-name {
  font-size: 14px;
  font-weight: 500;
  color: var(--text-title);
  display: block;
}
.project-list-meta {
  font-size: 12px;
  color: var(--text-support);
  margin-top: 2px;
  display: block;
}
.project-list-check {
  width: 22px;
  height: 22px;
  border-radius: 50%;
  background: var(--brand);
  color: #fff;
  flex-shrink: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  opacity: 0;
}
.project-list-check svg { width: 12px; height: 12px; }
.project-list-item.active .project-list-check { opacity: 1; }

/* Per-item more button & menu */
.project-list-item {
  position: relative;
}
.project-item-more {
  width: 28px;
  height: 28px;
  border: none;
  background: transparent;
  border-radius: 6px;
  cursor: pointer;
  color: var(--text-support);
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  opacity: 0;
  transition: opacity 0.12s, background 0.12s;
}
.project-list-item:hover .project-item-more { opacity: 1; }
.project-item-more:hover { background: var(--ux-hover); }
.project-item-more svg { width: 16px; height: 16px; }

.project-item-menu {
  position: absolute;
  right: 12px;
  top: 100%;
  margin-top: 2px;
  background: var(--fill-general);
  border-radius: 10px;
  box-shadow: 0 4px 16px var(--shadow-2), 0 0 0 1px var(--line);
  padding: 4px;
  z-index: 110;
  min-width: 140px;
  display: none;
}
.project-item-menu.visible { display: flex; flex-direction: column; }

.project-item-menu-btn {
  display: flex;
  align-items: center;
  gap: 8px;
  width: 100%;
  padding: 7px 10px;
  border: none;
  background: transparent;
  border-radius: 6px;
  font-size: 13px;
  font-weight: 500;
  color: var(--text-body);
  cursor: pointer;
  font-family: inherit;
  text-align: left;
}
.project-item-menu-btn:hover { background: var(--ux-hover); }
.project-item-menu-btn svg { width: 14px; height: 14px; color: var(--text-support); flex-shrink: 0; }
.project-item-menu-btn.danger { color: #dc2626; }
.project-item-menu-btn.danger svg { color: #dc2626; }
.project-item-menu-btn.danger:hover { background: #fef2f2; }

.project-rename-input {
  font-size: 14px;
  font-weight: 500;
  color: var(--text-title);
  border: none;
  outline: none;
  background: transparent;
  padding: 0;
  font-family: inherit;
  width: 100%;
  box-shadow: 0 0 0 2px var(--brand);
  border-radius: 4px;
  padding: 2px 6px;
}
.project-modal-divider {
  height: 1px;
  background: var(--line);
  margin: 8px 0;
}
.project-create-btn {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 12px;
  border: none;
  background: transparent;
  border-radius: 10px;
  cursor: pointer;
  font-family: inherit;
  font-size: 14px;
  color: var(--brand);
  font-weight: 500;
  width: 100%;
  text-align: left;
  transition: background 0.12s;
}
.project-create-btn:hover { background: var(--ux-hover); }
.project-create-btn svg { width: 18px; height: 18px; flex-shrink: 0; }

/* Delete Confirm Modal */
.delete-confirm-box {
  background: var(--fill-general);
  border-radius: 16px;
  width: 380px;
  max-width: 90vw;
  padding: 32px;
  transform: translateY(10px);
  transition: transform 0.2s;
  display: flex;
  flex-direction: column;
  align-items: center;
  text-align: center;
}
.modal-overlay.visible .delete-confirm-box { transform: translateY(0); }
.delete-confirm-icon {
  width: 52px;
  height: 52px;
  border-radius: 50%;
  background: #fef2f2;
  display: flex;
  align-items: center;
  justify-content: center;
  margin-bottom: 16px;
}
.delete-confirm-icon svg { width: 24px; height: 24px; color: #dc2626; }
.delete-confirm-title {
  font-size: 17px;
  font-weight: 600;
  color: var(--text-title);
  margin-bottom: 8px;
}
.delete-confirm-desc {
  font-size: 13px;
  color: var(--text-support);
  line-height: 1.5;
  margin-bottom: 24px;
}
.delete-confirm-actions {
  display: flex;
  gap: 10px;
  width: 100%;
}
.delete-confirm-cancel,
.delete-confirm-delete {
  flex: 1;
  height: 40px;
  border-radius: 10px;
  border: none;
  font-size: 14px;
  font-weight: 500;
  font-family: inherit;
  cursor: pointer;
  transition: opacity 0.15s;
}
.delete-confirm-cancel {
  background: var(--fill-block);
  color: var(--text-body);
}
.delete-confirm-cancel:hover { background: var(--ux-hover); }
.delete-confirm-delete {
  background: #dc2626;
  color: #fff;
}
.delete-confirm-delete:hover { opacity: 0.85; }

/* Loading Overlay */
.loading-overlay {
  position: absolute;
  inset: 0;
  background: rgba(255,255,255,0.85);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 50;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.2s ease;
}
.loading-overlay.visible {
  opacity: 1;
  pointer-events: auto;
}
.loading-spinner {
  width: 32px;
  height: 32px;
  border: 3px solid var(--line);
  border-top-color: var(--brand);
  border-radius: 50%;
  animation: spin 0.7s linear infinite;
}
@keyframes spin {
  to { transform: rotate(360deg); }
}

/* ================================================================
   Knowledge Base — Page Styles
   ================================================================ */

.kb-main {
  flex: 1;
  overflow: hidden;
  padding: 40px 48px 0;
  background: var(--fill-general);
  position: relative;
  display: flex;
  flex-direction: column;
}

.kb-header {
  margin-bottom: 32px;
}

/* --- Top Row: Add Data | OR | Generate Video --- */
.kb-top-row {
  display: flex;
  align-items: stretch;
  gap: 0;
  margin-bottom: 32px;
  flex-shrink: 0;
}

.kb-top-row h2 {
  font-size: 17px;
  font-weight: 700;
  color: var(--text-title);
  margin-bottom: 4px;
}

.kb-top-row p {
  font-size: 13px;
  color: var(--text-support);
  margin-bottom: 16px;
}

/* --- Add Data Section (left) --- */
.kb-add-data {
  flex: 1;
  min-width: 0;
}

.kb-cards {
  display: flex;
  gap: 10px;
}

.kb-card {
  flex: 1;
  min-width: 0;
  height: 112px;
  border-radius: 12px;
  border: 1px solid var(--line);
  background: var(--fill-general);
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 8px;
  cursor: pointer;
  transition: box-shadow 0.2s, transform 0.2s, border-color 0.15s, background 0.15s;
  box-shadow: 0 0 4px rgba(0,0,0,0.03), 0 2px 8px rgba(0,0,0,0.05);
  font-family: inherit;
  padding: 12px 8px;
}

.kb-card:hover {
  box-shadow: 0 4px 16px rgba(0,0,0,0.08), 0 6px 20px rgba(0,0,0,0.06);
  transform: translateY(-1px);
}

.kb-card-icon {
  width: 36px;
  height: 36px;
  border-radius: 10px;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
}

.kb-card-icon svg {
  width: 18px;
  height: 18px;
}

.kb-card-icon.upload { background: linear-gradient(135deg, #00c4ff 0%, #0098d4 100%); color: #fff; }
.kb-card-icon.text { background: linear-gradient(135deg, #7c5cfc 0%, #5a3de6 100%); color: #fff; }
.kb-card-icon.link { background: linear-gradient(135deg, #ff7eb3 0%, #ff4081 100%); color: #fff; }
.kb-card-icon.explainer { background: #eef2ff; color: #4f46e5; }
.kb-card-icon.motion { background: #fff7ed; color: #ea580c; }
.kb-card-icon.training { background: #ecfdf5; color: #059669; }
.kb-card-icon.agent { background: #fef2f2; color: #dc2626; }

.kb-card-title {
  font-size: 12px;
  font-weight: 500;
  color: var(--text-title);
  line-height: 1.3;
}

.kb-card-subtitle {
  font-size: 10px;
  color: var(--text-support);
  background: var(--fill-block);
  border-radius: 6px;
  padding: 2px 7px;
  line-height: 1.4;
}

.kb-card-ghost {
  visibility: hidden;
  pointer-events: none;
  border: none;
  box-shadow: none;
}

/* --- OR Divider --- */
.kb-or-divider {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 56px;
  flex-shrink: 0;
  position: relative;
}
.kb-or-divider::before {
  content: '';
  position: absolute;
  top: 16px;
  bottom: 16px;
  left: 50%;
  width: 1px;
  background: var(--line);
}
.kb-or-divider span {
  position: relative;
  z-index: 1;
  font-size: 11px;
  font-weight: 600;
  color: var(--text-disable);
  text-transform: uppercase;
  letter-spacing: 0.5px;
  background: var(--fill-general);
  padding: 8px 0;
}

/* --- Generate Video Section (right) --- */
.kb-gen-section {
  flex: 1;
  min-width: 0;
}

/* --- Sources Section --- */
.kb-sources {
  margin-top: 8px;
  flex: 1;
  min-height: 0;
  display: flex;
  flex-direction: column;
  padding-bottom: 24px;
}

.kb-sources-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 16px;
}

.kb-sources-header-left {
  display: flex;
  align-items: center;
  gap: 16px;
}

/* --- Tabs --- */
.kb-tabs {
  display: flex;
  gap: 0;
  position: relative;
}
.kb-tab {
  padding: 0 2px;
  display: flex;
  align-items: center;
  gap: 6px;
  border: none;
  background: transparent;
  font-size: 18px;
  font-weight: 600;
  color: var(--text-support);
  cursor: pointer;
  font-family: inherit;
  margin-right: 16px;
  position: relative;
  transition: color 0.15s;
}
.kb-tab:hover { color: var(--text-body); }
.kb-tab.active {
  color: var(--text-title);
  font-weight: 700;
}
.kb-tabs-indicator {
  position: absolute;
  bottom: -13px;
  height: 2px;
  border-radius: 1px;
  background: var(--brand);
  transition: left 0.25s ease, width 0.25s ease;
}
.kb-tab-badge {
  font-size: 11px;
  font-weight: 600;
  color: var(--button-text);
  background: var(--brand);
  padding: 1px 6px;
  border-radius: 100px;
  line-height: 16px;
}

/* --- Tab Panels wrapper --- */
.kb-tab-panels {
  position: relative;
  flex: 1;
  min-height: 0;
}

/* --- Tab Content --- */
.kb-tab-content {
  position: absolute;
  inset: 0;
  display: flex;
  flex-direction: column;
  visibility: hidden;
  pointer-events: none;
}
.kb-tab-content.active {
  visibility: visible;
  pointer-events: auto;
}

/* --- Videos List --- */
.kb-videos-list {
  flex: 1;
  overflow-y: auto;
  min-height: 0;
  display: flex;
  flex-direction: column;
  gap: 8px;
}
.kb-videos-list .kb-empty {
  flex: 1;
  display: flex;
  align-items: center;
  justify-content: center;
}

.kb-search {
  position: relative;
  width: 360px;
}

.kb-search-icon {
  position: absolute;
  left: 14px;
  top: 50%;
  transform: translateY(-50%);
  width: 16px;
  height: 16px;
  color: var(--text-support);
  pointer-events: none;
  display: flex;
  align-items: center;
  justify-content: center;
}

.kb-search-icon svg {
  width: 16px;
  height: 16px;
}

.kb-search input {
  width: 100%;
  height: 36px;
  border: 1px solid var(--line);
  border-radius: 100px;
  padding: 0 16px 0 38px;
  font-size: 14px;
  font-family: inherit;
  color: var(--text-title);
  background: var(--fill-general);
  outline: none;
  transition: border-color 0.15s;
}

.kb-search input::placeholder {
  color: var(--text-disable);
}

.kb-search input:focus {
  border-color: var(--brand);
}

/* --- Checkbox --- */
.kb-checkbox {
  -webkit-appearance: none;
  appearance: none;
  width: 18px;
  height: 18px;
  border: none;
  border-radius: 4px;
  cursor: pointer;
  flex-shrink: 0;
  position: relative;
  background: #fff;
  box-shadow: inset 0 0 0 1.5px rgba(35,40,51,0.2);
  transition: background 0.15s, box-shadow 0.15s;
}
.kb-checkbox:checked {
  background: var(--brand);
  box-shadow: none;
}
.kb-checkbox:checked::after {
  content: '';
  position: absolute;
  inset: 0;
  background: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='10' height='8' fill='none'%3E%3Cpath d='M1 4l3 3 5-6' stroke='%23fff' stroke-width='1.8' stroke-linecap='round' stroke-linejoin='round'/%3E%3C/svg%3E") center/10px 8px no-repeat;
}
.kb-checkbox::before {
  content: '';
  position: absolute;
  top: -8px;
  left: -8px;
  right: -8px;
  bottom: -8px;
}

/* --- Select All --- */
.kb-select-all {
  display: flex;
  align-items: center;
  gap: 8px;
  cursor: pointer;
  border-radius: 6px;
  padding: 4px 8px;
}
.kb-select-all:hover {
  background: var(--ux-hover);
}
.kb-select-all span {
  font-size: 13px;
  font-weight: 500;
  color: var(--text-body);
  user-select: none;
}

/* --- Source List --- */
.kb-sources-list {
  display: flex;
  flex-direction: column;
  gap: 8px;
  flex: 1;
  overflow-y: auto;
  min-height: 0;
}

.kb-source-item {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 10px 12px;
  border: 1px solid var(--line);
  border-radius: 8px;
  cursor: pointer;
  transition: border-color 0.15s;
  position: relative;
}

.kb-source-item:hover {
  border-color: var(--brand);
}

.kb-source-item.selected {
  border-color: var(--brand);
  background: var(--ux-primary-select);
}

.kb-source-icon {
  width: 28px;
  height: 28px;
  border-radius: 6px;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  font-size: 11px;
  font-weight: 700;
  color: #fff;
  text-transform: uppercase;
}

.kb-source-icon.url { background: #00c4ff; }
.kb-source-icon.pdf { background: #e74c3c; }
.kb-source-icon.pptx { background: #f39c12; }
.kb-source-icon.xlsx { background: #27ae60; }

.kb-source-name {
  flex: 1;
  font-size: 14px;
  color: var(--text-title);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  line-height: 1.4;
}

.kb-source-more {
  width: 32px;
  height: 32px;
  border-radius: 50%;
  border: none;
  background: transparent;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--text-support);
  font-size: 18px;
  flex-shrink: 0;
  transition: background 0.15s;
  font-family: inherit;
}

.kb-source-more:hover {
  background: var(--ux-hover);
}

/* --- Context Menu --- */
.kb-context-menu {
  position: absolute;
  right: 12px;
  top: 100%;
  margin-top: 4px;
  background: var(--fill-general);
  border: 1px solid var(--line);
  border-radius: 10px;
  box-shadow: 0 4px 16px rgba(0,0,0,0.12);
  padding: 4px;
  z-index: 100;
  min-width: 140px;
  display: none;
}

.kb-context-menu.visible {
  display: block;
}

.kb-context-menu-item {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 8px 12px;
  border-radius: 6px;
  font-size: 14px;
  color: var(--text-body);
  cursor: pointer;
  border: none;
  background: none;
  width: 100%;
  text-align: left;
  font-family: inherit;
}

.kb-context-menu-item:hover {
  background: var(--ux-hover);
}

.kb-context-menu-item.danger {
  color: #e74c3c;
}

.kb-context-menu-item svg {
  width: 16px;
  height: 16px;
  flex-shrink: 0;
}

/* --- Empty State --- */
.kb-empty {
  text-align: center;
  padding: 40px 20px;
  color: var(--text-support);
  font-size: 14px;
}

/* ================================================================
   Generate Video — Grid + Detail views
   ================================================================ */

/* Card grid for video types */
.kb-gen-views {
  min-height: 132px;
}
.kb-gen-grid {
  display: flex;
  gap: 10px;
  flex-wrap: nowrap;
}

/* Detail view (hidden by default) */
.kb-gen-detail {
  display: none;
}
.kb-gen-detail.visible {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

/* Back button */
.kb-gen-back {
  display: flex;
  align-items: center;
  gap: 6px;
  border: none;
  background: none;
  cursor: pointer;
  font-family: inherit;
  font-size: 14px;
  font-weight: 600;
  color: var(--text-title);
  padding: 0;
  margin-bottom: 2px;
}
.kb-gen-back:hover { color: var(--brand); }
.kb-gen-back svg {
  width: 16px;
  height: 16px;
  color: var(--text-support);
}
.kb-gen-back:hover svg { color: var(--brand); }

/* Config Row */
.kb-config-row {
  display: flex;
  gap: 8px;
  align-items: center;
}

/* Avatar / Style Button */
.kb-avatar-btn {
  display: flex;
  align-items: center;
  gap: 8px;
  height: 34px;
  padding: 0 10px;
  border-radius: 8px;
  border: 1px solid var(--line);
  background: var(--fill-general);
  cursor: pointer;
  font-family: inherit;
  transition: background 0.15s;
  flex: 1;
}
.kb-avatar-btn:hover { background: var(--ux-hover); }
.kb-avatar-btn-thumb {
  width: 22px;
  height: 22px;
  border-radius: 50%;
  background: var(--fill-block);
  display: flex;
  align-items: center;
  justify-content: center;
  overflow: hidden;
  flex-shrink: 0;
}
.kb-avatar-btn-thumb svg { width: 12px; height: 12px; color: var(--text-support); }
.kb-avatar-btn-name {
  font-size: 12px;
  font-weight: 500;
  color: var(--text-title);
  flex: 1;
  text-align: left;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.kb-avatar-btn-arrow {
  width: 10px;
  height: 10px;
  color: var(--text-support);
  flex-shrink: 0;
}

/* Orientation toggle */
.kb-orientation-toggle {
  display: flex;
  align-items: center;
  height: 34px;
  background: var(--fill-block);
  border-radius: 17px;
  padding: 3px;
  position: relative;
  gap: 0;
}
.kb-orientation-slider {
  position: absolute;
  top: 3px;
  left: 3px;
  width: calc(50% - 3px);
  height: calc(100% - 6px);
  background: var(--fill-general);
  border-radius: 14px;
  box-shadow: 0 1px 3px rgba(0,0,0,0.1);
  transition: left 0.25s ease;
}
.kb-orientation-toggle.landscape .kb-orientation-slider {
  left: 50%;
}
.kb-orientation-opt {
  flex: 1;
  height: 100%;
  display: flex;
  align-items: center;
  justify-content: center;
  border: none;
  background: none;
  cursor: pointer;
  position: relative;
  z-index: 1;
  color: var(--text-support);
  transition: color 0.2s;
  padding: 0 6px;
}
.kb-orientation-opt svg { width: 16px; height: 16px; }
.kb-orientation-opt.active { color: var(--text-title); }

/* Generation Footer */
.kb-gen-footer {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding-top: 12px;
  border-top: 1px solid var(--line);
}
.kb-summary-text {
  font-size: 12px;
  font-weight: 500;
  color: var(--text-support);
}
.kb-generate-btn {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  height: 34px;
  padding: 0 18px;
  background: var(--button-fill);
  color: var(--button-text);
  border: none;
  border-radius: 100px;
  font-size: 13px;
  font-weight: 600;
  cursor: pointer;
  font-family: inherit;
  transition: opacity 0.15s;
}
.kb-generate-btn:hover:not(:disabled) {
  opacity: 0.85;
}
.kb-generate-btn:disabled {
  background: var(--text-disable);
  cursor: not-allowed;
}
.kb-generate-btn svg {
  width: 14px;
  height: 14px;
}

/* ================================================================
   Modals — URL, Text, Avatar Picker, Style Picker
   ================================================================ */
.kb-modal-box {
  background: var(--fill-general);
  border-radius: 16px;
  width: 440px;
  max-width: 90vw;
  padding: 24px;
  transform: translateY(10px);
  transition: transform 0.2s;
  display: flex;
  flex-direction: column;
}
.modal-overlay.visible .kb-modal-box { transform: translateY(0); }

.kb-modal-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 16px;
}
.kb-modal-title {
  font-size: 17px;
  font-weight: 600;
  color: var(--text-title);
}
.kb-modal-body { margin-bottom: 20px; }

.kb-modal-input {
  width: 100%;
  height: 40px;
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 0 14px;
  font-size: 14px;
  font-family: inherit;
  color: var(--text-title);
  outline: none;
  transition: border-color 0.15s;
}
.kb-modal-input:focus { border-color: var(--brand); }
.kb-modal-input::placeholder { color: var(--text-disable); }

.kb-modal-textarea {
  width: 100%;
  height: 160px;
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 12px 14px;
  font-size: 14px;
  font-family: inherit;
  color: var(--text-title);
  outline: none;
  resize: vertical;
  transition: border-color 0.15s;
}
.kb-modal-textarea:focus { border-color: var(--brand); }
.kb-modal-textarea::placeholder { color: var(--text-disable); }

.kb-modal-footer {
  display: flex;
  justify-content: flex-end;
  gap: 8px;
}
.kb-modal-btn {
  height: 36px;
  padding: 0 18px;
  border-radius: 10px;
  border: none;
  font-size: 14px;
  font-weight: 500;
  font-family: inherit;
  cursor: pointer;
  transition: opacity 0.15s;
}
.kb-modal-btn.secondary {
  background: var(--fill-block);
  color: var(--text-body);
}
.kb-modal-btn.secondary:hover { background: var(--ux-hover); }
.kb-modal-btn.primary {
  background: var(--button-fill);
  color: var(--button-text);
}
.kb-modal-btn.primary:hover:not(:disabled) { opacity: 0.85; }
.kb-modal-btn.primary:disabled {
  background: var(--text-disable);
  cursor: not-allowed;
}

/* --- Avatar Picker Modal (mirrors Video Notes) --- */
.kb-avatar-modal-box {
  background: var(--fill-general);
  border-radius: 16px;
  width: 580px;
  max-height: 80vh;
  padding: 24px;
  transform: translateY(10px);
  transition: transform 0.2s;
  display: flex;
  flex-direction: column;
}
.modal-overlay.visible .kb-avatar-modal-box { transform: translateY(0); }

.kb-avatar-modal-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 16px;
}
.kb-avatar-modal-header h3 {
  font-size: 18px;
  font-weight: 600;
  color: var(--text-title);
  margin: 0;
}
.kb-avatar-modal-close {
  width: 28px;
  height: 28px;
  border: none;
  background: transparent;
  cursor: pointer;
  color: var(--text-support);
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: 6px;
}
.kb-avatar-modal-close:hover { background: var(--ux-hover); }
.kb-avatar-modal-close svg { width: 16px; height: 16px; }

/* Tabs */
.kb-avatar-modal-tabs {
  display: flex;
  gap: 16px;
  border-bottom: 1px solid var(--line);
  margin-bottom: 16px;
}
.kb-avatar-modal-tab {
  font-size: 13px;
  color: var(--text-support);
  padding-bottom: 8px;
  border: none;
  background: none;
  cursor: pointer;
  font-family: inherit;
  position: relative;
}
.kb-avatar-modal-tab.active {
  color: var(--text-title);
  font-weight: 600;
}
.kb-avatar-modal-tab.active::after {
  content: '';
  position: absolute;
  bottom: -1px;
  left: 0;
  right: 0;
  height: 2px;
  background: var(--text-title);
  border-radius: 1px;
}

/* Search */
.kb-avatar-search {
  display: flex;
  align-items: center;
  gap: 8px;
  height: 38px;
  padding: 0 12px;
  border-radius: 8px;
  border: 1px solid var(--line);
  background: var(--fill-general);
  margin-bottom: 12px;
}
.kb-avatar-search svg { width: 16px; height: 16px; color: var(--text-support); flex-shrink: 0; }
.kb-avatar-search input {
  border: none;
  outline: none;
  background: transparent;
  font-size: 13px;
  font-family: inherit;
  color: var(--text-body);
  flex: 1;
}
.kb-avatar-search input::placeholder { color: var(--text-disable); }

/* Tags */
.kb-avatar-tags {
  display: flex;
  gap: 8px;
  margin-bottom: 16px;
  flex-wrap: wrap;
}
.kb-avatar-tag {
  font-size: 12px;
  padding: 4px 12px;
  border-radius: 20px;
  border: 1px solid var(--line);
  background: transparent;
  color: var(--text-body);
  cursor: pointer;
  font-family: inherit;
}
.kb-avatar-tag.active {
  background: var(--brand);
  color: #fff;
  border-color: var(--brand);
}
.kb-avatar-tag:hover:not(.active) { background: var(--ux-hover); }

/* Grid */
.kb-avatar-grid {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 12px;
  overflow-y: auto;
  flex: 1;
}
.kb-avatar-grid-item {
  border-radius: 12px;
  overflow: hidden;
  cursor: pointer;
  position: relative;
  aspect-ratio: 1;
  background: var(--fill-block);
  display: flex;
  align-items: center;
  justify-content: center;
  border: 2px solid transparent;
  transition: border-color 0.15s;
}
.kb-avatar-grid-item:hover { border-color: var(--brand); }
.kb-avatar-grid-item.selected { border-color: var(--brand); }
.kb-avatar-grid-name {
  position: absolute;
  bottom: 0;
  left: 0;
  right: 0;
  padding: 20px 8px 6px;
  font-size: 11px;
  font-weight: 500;
  color: #fff;
  background: linear-gradient(transparent, rgba(0,0,0,0.5));
  text-align: center;
}

/* --- Avatar/Style button clear icon --- */
.kb-avatar-btn-clear {
  width: 16px;
  height: 16px;
  border-radius: 50%;
  display: none;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  color: var(--text-support);
}
.kb-avatar-btn-clear svg { width: 10px; height: 10px; }
.kb-avatar-btn-clear:hover { color: var(--text-title); }
.kb-avatar-btn-clear.active { display: flex; }

/* --- Style Picker Modal (mirrors Video Notes) --- */
.kb-style-modal-box {
  background: var(--fill-general);
  border-radius: 16px;
  width: 620px;
  max-height: 80vh;
  padding: 24px;
  transform: translateY(10px);
  transition: transform 0.2s;
  display: flex;
  flex-direction: column;
}
.modal-overlay.visible .kb-style-modal-box { transform: translateY(0); }

.kb-style-grid {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 14px;
  overflow-y: auto;
  flex: 1;
}
.kb-style-grid-item {
  cursor: pointer;
  border-radius: 10px;
  overflow: hidden;
  border: 2px solid transparent;
  transition: border-color 0.15s;
  display: flex;
  flex-direction: column;
  background: var(--fill-block);
}
.kb-style-grid-item:hover { border-color: var(--brand); }
.kb-style-grid-item.selected { border-color: var(--brand); }

.kb-style-thumb {
  aspect-ratio: 9/16;
  position: relative;
  overflow: hidden;
}
.kb-style-thumb-img {
  width: 100%;
  height: 100%;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 20px;
  font-weight: 700;
  transform: scale(1);
  transition: transform 4s ease-out;
}
.kb-style-grid-item:hover .kb-style-thumb-img {
  transform: scale(1.15);
  animation: kbStyleLetterSpin 2s linear infinite;
}
@keyframes kbStyleLetterSpin {
  0% { transform: scale(1.15) rotateY(0deg); }
  100% { transform: scale(1.15) rotateY(360deg); }
}
.kb-style-thumb-label {
  position: absolute;
  bottom: 0;
  left: 0;
  right: 0;
  padding: 16px 6px 5px;
  font-size: 10px;
  font-weight: 600;
  color: #fff;
  background: linear-gradient(transparent, rgba(0,0,0,0.55));
  text-align: center;
  text-transform: uppercase;
  letter-spacing: 0.5px;
}
.kb-style-thumb-progress {
  position: absolute;
  bottom: 0;
  left: 0;
  height: 3px;
  background: var(--brand);
  width: 0%;
  transition: none;
  z-index: 2;
}
.kb-style-item-name {
  padding: 8px 6px;
  font-size: 12px;
  font-weight: 500;
  color: var(--text-title);
  text-align: center;
  line-height: 16px;
}

/* --- Video result card --- */
.kb-video-card {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 10px 12px;
  border: 1px solid var(--line);
  border-radius: 8px;
  cursor: pointer;
  transition: border-color 0.15s;
}
.kb-video-card:hover { border-color: var(--brand); }
.kb-video-card.loading { opacity: 0.7; pointer-events: none; }

.kb-video-thumb {
  width: 64px;
  height: 40px;
  border-radius: 6px;
  background: var(--fill-block);
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  position: relative;
  overflow: hidden;
}
.kb-video-thumb svg {
  width: 16px;
  height: 16px;
  color: var(--text-support);
}
.kb-video-progress {
  position: absolute;
  bottom: 0;
  left: 0;
  height: 3px;
  background: var(--brand);
  border-radius: 0 0 6px 6px;
  transition: width 0.4s ease;
}

.kb-video-info {
  flex: 1;
  min-width: 0;
  display: flex;
  flex-direction: column;
}
.kb-video-title {
  font-size: 14px;
  font-weight: 500;
  color: var(--text-title);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.kb-video-meta {
  font-size: 12px;
  color: var(--text-support);
  margin-top: 2px;
}

.kb-video-actions {
  display: flex;
  gap: 4px;
  flex-shrink: 0;
}
.kb-video-action-btn {
  width: 28px;
  height: 28px;
  border: none;
  background: transparent;
  border-radius: 6px;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--text-support);
}
.kb-video-action-btn:hover { background: var(--ux-hover); }
.kb-video-action-btn svg { width: 14px; height: 14px; }

/* --- Source inline rename --- */
.kb-rename-input {
  flex: 1;
  min-width: 0;
  height: 28px;
  font-size: 14px;
  font-weight: 500;
  color: var(--text-title);
  border: none;
  outline: none;
  background: transparent;
  padding: 2px 6px;
  font-family: inherit;
  box-shadow: 0 0 0 2px var(--brand);
  border-radius: 4px;
}
