/* Раздел «YouTube каналы» в библиотеке знаний. Отдельный файл, как у книг и
   презентаций: styles.css большой и тяжело переживает слияния веток. */

.kb-yt-section {
  /* Секция библиотеки — грид с авто-колонкой: без minmax(0) полоса Shorts распирала
     бы её на ширину всех карточек. */
  grid-template-columns: minmax(0, 1fr);
}
.kb-yt-section > * { min-width: 0; }

/* ——— Меню слева ——— */
.kb-yt-tree-row .kb-yt-tree-name {
  display: flex;
  align-items: center;
  gap: 8px;
  min-width: 0;
}
.kb-yt-tree-row .kb-yt-tree-name > span:last-child {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.kb-yt-new-dot {
  display: inline-block;
  padding: 0 6px;
  border-radius: 999px;
  background: #ff3b30;
  color: #fff;
  font-size: 11px;
  font-weight: 700;
  line-height: 18px;
}

/* ——— Аватары ——— */
.kb-yt-avatar {
  display: inline-grid;
  place-items: center;
  flex: none;
  border-radius: 50%;
  overflow: hidden;
  background: var(--color-bg-secondary, #f1f5f9);
  color: var(--color-text-secondary, #475569);
  font-weight: 700;
}
.kb-yt-avatar img { width: 100%; height: 100%; object-fit: cover; }
.kb-yt-avatar-xs { width: 20px; height: 20px; font-size: 10px; }
.kb-yt-avatar-md { width: 36px; height: 36px; font-size: 14px; }
.kb-yt-avatar-lg { width: 64px; height: 64px; font-size: 18px; border-radius: 18px; }
.kb-yt-avatar-xl { width: 88px; height: 88px; font-size: 28px; }
.kb-yt-avatar-all { background: var(--color-primary-soft-bg, rgba(109, 40, 217, .1)); color: var(--color-primary, #6d28d9); font-size: 15px; }
.kb-yt-avatar-add {
  background: transparent;
  border: 1.5px dashed var(--color-border, #e2e8f0);
  color: var(--color-text-muted, #64748b);
  font-size: 28px;
  font-weight: 400;
}

/* ——— Полоса каналов ——— */
.kb-yt-strip {
  display: flex;
  gap: 14px;
  overflow-x: auto;
  padding: 4px 2px 12px;
  scrollbar-width: thin;
}
.kb-yt-strip-item {
  position: relative;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 6px;
  width: 78px;
  flex: none;
  border: 0;
  background: transparent;
  color: var(--color-text-secondary, #475569);
  font: inherit;
  cursor: pointer;
  padding: 0;
}
.kb-yt-strip-item .kb-yt-avatar { transition: box-shadow .15s, transform .15s; }
.kb-yt-strip-item:hover .kb-yt-avatar { transform: translateY(-1px); }
.kb-yt-strip-item.active .kb-yt-avatar { box-shadow: 0 0 0 2px var(--color-bg-card, #fff), 0 0 0 4px var(--color-primary, #6d28d9); }
.kb-yt-strip-item.active .kb-yt-strip-name { color: var(--color-text-primary, #0f172a); font-weight: 600; }
.kb-yt-strip-name {
  max-width: 100%;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  font-size: 12px;
}
.kb-yt-strip-badge {
  position: absolute;
  top: -4px;
  right: 2px;
  min-width: 20px;
  padding: 0 5px;
  border-radius: 999px;
  background: #ff3b30;
  color: #fff;
  font-size: 11px;
  font-weight: 700;
  line-height: 20px;
  box-shadow: 0 0 0 2px var(--color-bg-card, #fff);
}
.kb-yt-strip-spin {
  position: absolute;
  top: 0;
  left: 50%;
  margin-left: -32px;
  width: 64px;
  height: 64px;
  border-radius: 18px;
  border: 2px solid transparent;
  border-top-color: var(--color-primary, #6d28d9);
  animation: kb-yt-spin 1s linear infinite;
  pointer-events: none;
}
@keyframes kb-yt-spin { to { transform: rotate(360deg); } }

/* ——— Добавление канала ——— */
.kb-yt-add {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  align-items: center;
  margin: 4px 0 16px;
}
.kb-yt-add input {
  flex: 1 1 320px;
  min-width: 0;
  padding: 9px 12px;
  border-radius: 10px;
  border: 1px solid var(--color-border, #e2e8f0);
  background: var(--color-bg-input, var(--color-bg-card, #fff));
  color: var(--color-text-primary, #0f172a);
  font: inherit;
}
.kb-yt-add input:focus { outline: none; border-color: var(--color-primary, #6d28d9); }
.kb-yt-add-hint {
  flex-basis: 100%;
  margin: 0;
  font-size: 12px;
  color: var(--color-text-muted, #64748b);
}
.kb-yt-intro { line-height: 1.55; }

/* ——— Шапка канала ——— */
.kb-yt-channel-head {
  display: flex;
  gap: 16px;
  align-items: flex-start;
  padding: 14px 0 16px;
  border-bottom: 1px solid var(--color-border, #e2e8f0);
  margin-bottom: 14px;
}
.kb-yt-channel-info { flex: 1; min-width: 0; }
.kb-yt-channel-info h3 { margin: 0 0 4px; font-size: 20px; }
.kb-yt-channel-sub { font-size: 13px; color: var(--color-text-muted, #64748b); }
.kb-yt-channel-stats {
  display: flex;
  flex-wrap: wrap;
  gap: 4px 14px;
  margin-top: 8px;
  font-size: 13px;
  color: var(--color-text-secondary, #475569);
}
.kb-yt-channel-stats b { color: var(--color-text-primary, #0f172a); }
.kb-yt-channel-sync { margin-top: 6px; font-size: 12px; color: var(--color-text-muted, #64748b); }
.kb-yt-channel-sync.is-error { color: #dc2626; }
.kb-yt-channel-actions {
  display: flex;
  flex-wrap: wrap;
  justify-content: flex-end;
  gap: 6px;
  max-width: 360px;
}
.kb-yt-channel-actions a { text-decoration: none; }
.kb-yt-danger:hover { color: #dc2626; border-color: #dc2626; }

/* ——— Фильтры ——— */
.kb-yt-filters { display: flex; flex-direction: column; gap: 10px; margin-bottom: 16px; }
.kb-yt-chips { display: flex; flex-wrap: wrap; gap: 6px; }
.kb-yt-chip {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 7px 14px;
  border-radius: 999px;
  border: 0;
  background: var(--color-bg-secondary, #f1f5f9);
  color: var(--color-text-primary, #0f172a);
  font: inherit;
  font-size: 14px;
  cursor: pointer;
}
.kb-yt-chip small { font-size: 11px; color: var(--color-text-muted, #64748b); }
.kb-yt-chip.active { background: var(--color-text-primary, #0f172a); color: var(--color-bg-card, #fff); }
.kb-yt-chip.active small { color: inherit; opacity: .7; }
.kb-yt-chip-soft { padding: 4px 11px; font-size: 13px; background: transparent; border: 1px solid var(--color-border, #e2e8f0); }
.kb-yt-chip-soft.active { border-color: transparent; }
.kb-yt-toolbar { display: flex; flex-wrap: wrap; align-items: center; gap: 8px; }
.kb-yt-toolbar .knowledge-library-list-filter { flex: 1 1 220px; width: auto; max-width: 360px; margin: 0; }
.kb-yt-toolbar select {
  width: auto;
  margin: 0;
  padding: 7px 10px;
  border-radius: 8px;
  border: 1px solid var(--color-border, #e2e8f0);
  background: var(--color-bg-card, #fff);
  color: var(--color-text-primary, #0f172a);
  font: inherit;
  font-size: 13px;
}
.kb-yt-link-btn {
  border: 0;
  background: transparent;
  color: #3b82f6;
  font: inherit;
  font-weight: 600;
  cursor: pointer;
  padding: 4px 2px;
}
.kb-yt-link-btn:hover { text-decoration: underline; }
.kb-yt-bulk {
  position: sticky;
  top: 0;
  z-index: 5;
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 8px;
  padding: 10px 12px;
  margin: -6px 0 14px;
  border-radius: 12px;
  background: var(--color-bg-solid, var(--color-bg-card, #fff));
  border: 1px solid var(--color-border, #e2e8f0);
  box-shadow: 0 6px 20px rgba(15, 23, 42, .12);
}

/* ——— Карточки ——— */
.kb-yt-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(260px, 1fr));
  gap: 22px 16px;
}
.kb-yt-grid.is-shorts { grid-template-columns: repeat(auto-fill, minmax(160px, 1fr)); }
.kb-yt-card { position: relative; display: flex; flex-direction: column; gap: 8px; min-width: 0; }
.kb-yt-card.is-gone { opacity: .55; }
.kb-yt-thumb {
  position: relative;
  display: block;
  width: 100%;
  aspect-ratio: 16 / 9;
  padding: 0;
  border: 0;
  border-radius: 12px;
  overflow: hidden;
  background: var(--color-bg-secondary, #1e1e1e);
  cursor: pointer;
}
.kb-yt-card.is-short .kb-yt-thumb { aspect-ratio: 9 / 16; }
.kb-yt-thumb img { width: 100%; height: 100%; object-fit: cover; display: block; transition: transform .25s; }
.kb-yt-thumb:hover img { transform: scale(1.03); }
.kb-yt-card.is-selected .kb-yt-thumb { outline: 3px solid var(--color-primary, #6d28d9); outline-offset: -3px; }
.kb-yt-duration,
.kb-yt-kind {
  position: absolute;
  bottom: 8px;
  right: 8px;
  padding: 1px 6px;
  border-radius: 6px;
  background: rgba(0, 0, 0, .78);
  color: #fff;
  font-size: 12px;
  font-weight: 600;
  line-height: 20px;
}
.kb-yt-kind { right: auto; left: 8px; background: #dc2626; text-transform: uppercase; font-size: 10px; letter-spacing: .04em; }
.kb-yt-short-title {
  position: absolute;
  left: 0;
  right: 0;
  bottom: 0;
  padding: 28px 10px 10px;
  background: linear-gradient(transparent, rgba(0, 0, 0, .8));
  color: #fff;
  font-size: 13px;
  font-weight: 600;
  line-height: 1.3;
  text-align: left;
  display: -webkit-box;
  -webkit-line-clamp: 3;
  -webkit-box-orient: vertical;
  overflow: hidden;
}
.kb-yt-badge {
  position: absolute;
  top: 8px;
  left: 8px;
  padding: 2px 8px;
  border-radius: 999px;
  font-size: 11px;
  font-weight: 700;
  line-height: 18px;
  color: #fff;
  background: rgba(0, 0, 0, .7);
  white-space: nowrap;
}
.kb-yt-row .kb-yt-badge,
.kb-yt-preview-body .kb-yt-badge { position: static; display: inline-block; }
.kb-yt-badge.is-new { background: #ff3b30; }
.kb-yt-badge.is-busy { background: #2563eb; }
.kb-yt-badge.is-downloaded { background: #0f766e; }
.kb-yt-badge.is-progress { background: #d97706; }
.kb-yt-badge.is-studied { background: #16a34a; }
.kb-yt-badge.is-failed { background: #b91c1c; }
.kb-yt-check {
  position: absolute;
  top: 8px;
  right: 8px;
  display: grid;
  place-items: center;
  width: 24px;
  height: 24px;
  border-radius: 50%;
  border: 2px solid #fff;
  background: rgba(0, 0, 0, .35);
  color: #fff;
  font-size: 13px;
  font-weight: 700;
}
.kb-yt-check.checked { background: var(--color-primary, #6d28d9); border-color: var(--color-primary, #6d28d9); }
.kb-yt-card-body { display: flex; align-items: flex-start; gap: 4px; min-width: 0; }
.kb-yt-card-text { flex: 1; min-width: 0; }
.kb-yt-title {
  font-size: 15px;
  font-weight: 500;
  line-height: 1.35;
  color: var(--color-text-primary, #0f172a);
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
}
.kb-yt-meta { margin-top: 3px; font-size: 13px; color: var(--color-text-muted, #64748b); }
.kb-yt-more {
  flex: none;
  width: 28px;
  height: 28px;
  border: 0;
  border-radius: 50%;
  background: transparent;
  color: var(--color-text-secondary, #475569);
  font-size: 18px;
  line-height: 1;
  cursor: pointer;
}
.kb-yt-more:hover { background: var(--color-bg-hover, #f1f5f9); }
.kb-yt-menu {
  position: absolute;
  z-index: 20;
  right: 0;
  top: calc(100% + 2px);
  display: flex;
  flex-direction: column;
  min-width: 230px;
  padding: 6px;
  border-radius: 14px;
  background: var(--color-bg-solid, var(--color-bg-card, #fff));
  border: 1px solid var(--color-border, #e2e8f0);
  box-shadow: 0 14px 40px rgba(15, 23, 42, .22);
}
.kb-yt-menu button,
.kb-yt-menu a {
  display: block;
  padding: 9px 12px;
  border: 0;
  border-radius: 9px;
  background: transparent;
  color: var(--color-text-primary, #0f172a);
  font: inherit;
  font-size: 14px;
  text-align: left;
  text-decoration: none;
  cursor: pointer;
}
.kb-yt-menu button:hover,
.kb-yt-menu a:hover { background: var(--color-bg-hover, #f1f5f9); }

/* ——— Полоса Shorts ——— */
.kb-yt-shorts { margin-bottom: 24px; }
.kb-yt-shorts h4 {
  display: flex;
  align-items: center;
  gap: 8px;
  margin: 0 0 10px;
  font-size: 18px;
}
.kb-yt-shorts h4 small { font-size: 13px; font-weight: 400; color: var(--color-text-muted, #64748b); }
.kb-yt-shorts h4 .kb-yt-link-btn { margin-left: auto; font-size: 13px; }
.kb-yt-shorts-ic {
  display: inline-grid;
  place-items: center;
  width: 22px;
  height: 22px;
  border-radius: 7px;
  background: #ff3b30;
  color: #fff;
  font-size: 10px;
}
.kb-yt-shorts-rail {
  display: grid;
  grid-auto-flow: column;
  grid-auto-columns: 168px;
  gap: 12px;
  overflow-x: auto;
  padding-bottom: 8px;
  scroll-snap-type: x proximity;
  scrollbar-width: thin;
}
.kb-yt-shorts-rail .kb-yt-card { scroll-snap-align: start; }
/* Меню у карточки в полосе прокрутки обрезалось бы — открываем его поверх, вверх. */
.kb-yt-shorts-rail .kb-yt-menu { top: auto; bottom: 30px; }

/* ——— Список ——— */
.kb-yt-list { display: flex; flex-direction: column; gap: 4px; }
.kb-yt-row {
  position: relative;
  display: flex;
  align-items: center;
  gap: 14px;
  padding: 8px;
  border-radius: 12px;
}
.kb-yt-row:hover { background: var(--color-bg-hover, #f8fafc); }
.kb-yt-row.is-selected { background: var(--color-primary-soft-bg, rgba(109, 40, 217, .08)); }
.kb-yt-row.is-gone { opacity: .55; }
.kb-yt-row-thumb {
  position: relative;
  flex: none;
  width: 168px;
  aspect-ratio: 16 / 9;
  padding: 0;
  border: 0;
  border-radius: 10px;
  overflow: hidden;
  background: var(--color-bg-secondary, #1e1e1e);
  cursor: pointer;
}
.kb-yt-row-thumb.is-short img { object-position: center 30%; }
.kb-yt-row-thumb img { width: 100%; height: 100%; object-fit: cover; display: block; }
.kb-yt-row-thumb .kb-yt-duration { bottom: 5px; right: 5px; font-size: 11px; line-height: 17px; }
.kb-yt-row-thumb .kb-yt-check { top: 5px; right: 5px; }
.kb-yt-row-body { flex: 1; min-width: 0; }
.kb-yt-row .kb-yt-menu { top: calc(100% - 6px); right: 8px; }
.kb-yt-kind-inline {
  display: inline-block;
  margin-right: 6px;
  padding: 0 6px;
  border-radius: 5px;
  background: #ff3b30;
  color: #fff;
  font-size: 10px;
  font-weight: 700;
  line-height: 16px;
  vertical-align: 2px;
  text-transform: uppercase;
}

.kb-yt-more-btn { display: block; margin: 20px auto 4px; }

/* ——— Окно просмотра ——— */
.kb-yt-preview-backdrop {
  position: fixed;
  inset: 0;
  /* Выше нижней панели приложения на телефоне — иначе она закрывает кнопки окна. */
  z-index: 10050;
  display: grid;
  place-items: center;
  padding: 24px;
  background: rgba(2, 6, 23, .72);
  backdrop-filter: blur(4px);
  -webkit-backdrop-filter: blur(4px);
}
.kb-yt-preview {
  position: relative;
  width: min(960px, 100%);
  max-height: calc(100vh - 48px);
  overflow: auto;
  border-radius: 18px;
  background: var(--color-bg-solid, var(--color-bg-card, #fff));
  box-shadow: 0 30px 80px rgba(0, 0, 0, .45);
}
.kb-yt-preview.is-short { width: min(420px, 100%); }
.kb-yt-preview-player { aspect-ratio: 16 / 9; background: #000; }
.kb-yt-preview.is-short .kb-yt-preview-player { aspect-ratio: 9 / 16; max-height: 70vh; margin: 0 auto; }
.kb-yt-preview-player iframe { width: 100%; height: 100%; border: 0; display: block; }
.kb-yt-preview-body { display: flex; flex-direction: column; gap: 8px; padding: 16px 18px 18px; }
.kb-yt-preview-body h3 { margin: 0; font-size: 18px; line-height: 1.35; }
.kb-yt-preview-actions { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 4px; }
.kb-yt-preview-actions a { text-decoration: none; }
.kb-yt-preview-x {
  position: absolute;
  top: 10px;
  right: 10px;
  z-index: 2;
  width: 34px;
  height: 34px;
  border: 0;
  border-radius: 50%;
  background: rgba(0, 0, 0, .6);
  color: #fff;
  font-size: 22px;
  line-height: 1;
  cursor: pointer;
}

@media (max-width: 720px) {
  .kb-yt-channel-head { flex-wrap: wrap; }
  .kb-yt-avatar-xl { width: 64px; height: 64px; font-size: 22px; }
  .kb-yt-channel-actions { max-width: none; justify-content: flex-start; }
  .kb-yt-grid { grid-template-columns: 1fr; }
  .kb-yt-chips { flex-wrap: nowrap; overflow-x: auto; scrollbar-width: none; }
  .kb-yt-chip { flex: none; }
  .kb-yt-grid.is-shorts { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .kb-yt-row-thumb { width: 120px; }
  .kb-yt-preview-backdrop { padding: 0; align-items: end; }
  .kb-yt-preview { border-radius: 18px 18px 0 0; max-height: 100vh; }
}

/* ——— Отдельные видео (ролики по ссылке без подписки) ——— */
.kb-yt-avatar.kb-yt-avatar-singles { background: #ff3b30; color: #fff; }
.kb-yt-avatar-xs.kb-yt-avatar-singles { font-size: 9px; }
.kb-yt-avatar-lg.kb-yt-avatar-singles { font-size: 24px; }
.kb-yt-avatar-xl.kb-yt-avatar-singles { font-size: 34px; }
.kb-yt-add-mode { display: contents; }

/* ——— Окно «Скачать»: формат, качество, звуковая дорожка ——— */
.kb-yt-dl {
  position: relative;
  width: min(480px, 100%);
  max-height: calc(100vh - 48px);
  overflow: auto;
  display: flex;
  flex-direction: column;
  gap: 10px;
  padding: 20px 20px 18px;
  border-radius: 18px;
  background: var(--color-bg-solid, var(--color-bg-card, #fff));
  box-shadow: 0 30px 80px rgba(0, 0, 0, .45);
}
.kb-yt-dl h3 { margin: 0 36px 0 0; font-size: 17px; line-height: 1.35; }
.kb-yt-dl .kb-yt-preview-x { background: var(--color-bg-hover, rgba(0, 0, 0, .08)); color: var(--color-text-primary, #0f172a); }
.kb-yt-dl-note { font-size: 13px; color: var(--color-text-muted, #64748b); line-height: 1.45; }
.kb-yt-dl-spin {
  display: inline-block;
  width: 12px;
  height: 12px;
  margin-right: 4px;
  vertical-align: -1px;
  border-radius: 50%;
  border: 2px solid var(--color-border, #e2e8f0);
  border-top-color: var(--color-primary, #6d28d9);
  animation: kb-yt-spin .9s linear infinite;
}
.kb-yt-dl-field { display: flex; flex-direction: column; gap: 6px; font-size: 13px; font-weight: 600; color: var(--color-text-secondary, #475569); margin-top: 4px; }
.kb-yt-dl-field small { font-weight: 400; color: var(--color-text-muted, #64748b); }
.kb-yt-dl-field select {
  padding: 9px 10px;
  border-radius: 10px;
  border: 1px solid var(--color-border, #e2e8f0);
  background: var(--color-bg-card, #fff);
  color: var(--color-text-primary, #0f172a);
  font: inherit;
  font-weight: 400;
}
.kb-yt-dl-options { display: flex; flex-direction: column; gap: 4px; }
.kb-yt-dl-option {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 9px 12px;
  border-radius: 10px;
  border: 1px solid var(--color-border, #e2e8f0);
  cursor: pointer;
  font-size: 14px;
}
.kb-yt-dl-option.active { border-color: var(--color-primary, #6d28d9); background: var(--color-primary-soft-bg, rgba(109, 40, 217, .08)); }
.kb-yt-dl-option input { margin: 0; accent-color: var(--color-primary, #6d28d9); }
.kb-yt-dl-option-label { flex: 1; }
.kb-yt-dl-option-label small { font-size: 11px; color: var(--color-text-muted, #64748b); }
.kb-yt-dl-option-size { font-size: 12px; color: var(--color-text-muted, #64748b); white-space: nowrap; }
.kb-yt-dl-check { display: flex; gap: 8px; align-items: flex-start; font-size: 13px; line-height: 1.4; cursor: pointer; }
.kb-yt-dl-check input { margin-top: 2px; accent-color: var(--color-primary, #6d28d9); }
.kb-yt-dl-actions { display: flex; flex-wrap: wrap; justify-content: flex-end; gap: 8px; margin-top: 4px; }
@media (max-width: 720px) {
  .kb-yt-dl { border-radius: 18px 18px 0 0; max-height: 92vh; }
}
