/* ==========================================================================
   Textbook Knowledge & Page Search Modal (课本考点与页码速查雷达)
   ========================================================================== */

/* 搜索触发按钮（置于各页面顶部或工具栏）- 极简纯图标圆形设计，与主题、设置按钮完全对齐 */
.top-textbook-search-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 40px;
  height: 40px;
  min-width: 40px;
  padding: 0;
  border-radius: 50%;
  background: var(--panel-bg, #ffffff);
  border: 1px solid var(--border-color, #E2EBE2);
  color: var(--text-muted, #5F745E);
  cursor: pointer;
  transition: all 0.2s cubic-bezier(0.16, 1, 0.3, 1);
  box-shadow: 0 1px 3px rgba(0, 0, 0, 0.04);
}

.top-textbook-search-btn:hover {
  background: var(--primary-light, #E1ECE2);
  color: var(--primary-color, #2D5A27);
  border-color: var(--accent-color, #4F8549);
  transform: translateY(-1px);
}

.top-textbook-search-btn svg,
.top-textbook-search-btn i {
  width: 18px;
  height: 18px;
  stroke-width: 2.2;
}

/* 隐藏冗余文字与快捷键标签，平板与手机绝对不挤压主模式栏 */
.top-textbook-search-btn span,
.top-textbook-search-btn kbd {
  display: none !important;
}

@media (max-width: 768px) {
  .top-textbook-search-btn {
    width: 36px;
    height: 36px;
    min-width: 36px;
  }
  .top-textbook-search-btn svg,
  .top-textbook-search-btn i {
    width: 16px;
    height: 16px;
  }
}

/* 模态框遮罩层 - 顶层置顶（靠顶居中展示，顶着上面防遮挡） */
.tb-search-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(15, 23, 14, 0.45);
  backdrop-filter: blur(8px);
  -webkit-backdrop-filter: blur(8px);
  z-index: 2147483645 !important;
  display: flex;
  align-items: flex-start;
  justify-content: center;
  padding-top: max(16px, 2.5vh);
  padding-bottom: 20px;
  padding-left: 16px;
  padding-right: 16px;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.25s ease;
}

.tb-search-backdrop.is-open {
  opacity: 1;
  pointer-events: auto;
}

/* 模态框主体卡片 (Spotlight Dialog - 顶格对齐，考点快速速查) */
.tb-search-dialog {
  width: 100%;
  max-width: 720px;
  height: calc(100vh - max(36px, 6vh));
  max-height: calc(100vh - max(36px, 6vh));
  background: var(--panel-bg, #ffffff);
  border: 1px solid var(--border-color, #E2EBE2);
  border-radius: 16px;
  box-shadow: 0 16px 48px rgba(15, 23, 14, 0.22), 0 2px 8px rgba(15, 23, 14, 0.08);
  display: flex;
  flex-direction: column;
  overflow: hidden;
  transform: translateY(-12px) scale(0.99);
  transition: transform 0.25s cubic-bezier(0.16, 1, 0.3, 1);
}

.tb-search-backdrop.is-open .tb-search-dialog {
  transform: translateY(0) scale(1);
}

/* 顶部搜索输入条 */
.tb-search-header {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 14px 18px;
  border-bottom: 1px solid var(--border-color, #E2EBE2);
  position: relative;
}

.tb-search-icon {
  color: var(--primary-color, #2D5A27);
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
}

.tb-search-icon svg {
  width: 22px;
  height: 22px;
}

.tb-search-input {
  flex: 1;
  border: none;
  background: transparent;
  color: var(--text-main, #233322);
  font-size: 1.05rem;
  font-family: inherit;
  font-weight: 500;
  outline: none;
  padding: 0;
}

.tb-search-input::placeholder {
  color: var(--text-muted, #5F745E);
  opacity: 0.7;
}

.tb-search-close-btn {
  background: transparent;
  border: none;
  color: var(--text-muted, #5F745E);
  cursor: pointer;
  padding: 4px 8px;
  border-radius: 6px;
  font-size: 0.8rem;
  display: flex;
  align-items: center;
  gap: 4px;
  transition: all 0.15s ease;
}

.tb-search-close-btn:hover {
  background: var(--danger-light, #FCECE8);
  color: var(--danger-color, #A34E36);
}

/* 过滤筛选标签栏 */
.tb-search-filters {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 8px 18px;
  background: rgba(0, 0, 0, 0.015);
  border-bottom: 1px solid var(--border-color, #E2EBE2);
  overflow-x: auto;
  scrollbar-width: none;
}

.tb-search-filters::-webkit-scrollbar {
  display: none;
}

.tb-filter-chip {
  padding: 4px 12px;
  border-radius: 14px;
  border: 1px solid transparent;
  background: transparent;
  color: var(--text-muted, #5F745E);
  font-size: 0.8rem;
  font-weight: 500;
  cursor: pointer;
  white-space: nowrap;
  transition: all 0.15s ease;
}

.tb-filter-chip:hover {
  color: var(--text-main, #233322);
  background: var(--primary-light, #E1ECE2);
}

.tb-filter-chip.is-active {
  background: var(--primary-color, #2D5A27);
  color: #ffffff;
  font-weight: 600;
}

/* 考研政治二级科目筛选条 */
.tb-search-subfilters {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 6px 18px 8px;
  background: rgba(220, 38, 38, 0.04);
  border-bottom: 1px dashed var(--border-color, #E2EBE2);
  overflow-x: auto;
  scrollbar-width: none;
}

.tb-search-subfilters::-webkit-scrollbar {
  display: none;
}

.tb-subfilter-chip {
  padding: 2px 10px;
  border-radius: 12px;
  border: 1px solid rgba(220, 38, 38, 0.2);
  background: transparent;
  color: #991B1B;
  font-size: 0.74rem;
  font-weight: 500;
  cursor: pointer;
  white-space: nowrap;
  transition: all 0.15s ease;
}

body.dark-theme .tb-subfilter-chip {
  color: #FCA5A5;
  border-color: rgba(239, 68, 68, 0.35);
  background: rgba(239, 68, 68, 0.05);
}

.tb-subfilter-chip:hover {
  background: rgba(239, 68, 68, 0.12);
}

.tb-subfilter-chip.is-active {
  background: #DC2626;
  border-color: #DC2626;
  color: #ffffff;
  font-weight: 600;
}

/* 搜索结果列表容器 */
.tb-search-body {
  flex: 1;
  overflow-y: auto;
  padding: 12px 18px;
  overscroll-behavior: contain;
  min-height: 200px;
}

.tb-search-meta {
  font-size: 0.76rem;
  color: var(--text-muted, #5F745E);
  margin-bottom: 10px;
  display: flex;
  justify-content: space-between;
  align-items: center;
}

/* 单条结果卡片 */
.tb-search-card {
  background: var(--bg-color, #F7F9F6);
  border: 1px solid var(--border-color, #E2EBE2);
  border-radius: 12px;
  padding: 14px 16px;
  margin-bottom: 10px;
  transition: all 0.2s cubic-bezier(0.16, 1, 0.3, 1);
  display: flex;
  flex-direction: column;
  gap: 8px;
  position: relative;
  cursor: pointer;
}

.tb-search-card:hover {
  border-color: var(--accent-color, #4F8549);
  background: var(--panel-bg, #ffffff);
  box-shadow: 0 4px 14px rgba(45, 90, 39, 0.08);
  transform: translateY(-1px);
}

.tb-search-card.is-selected {
  border-color: var(--primary-color, #2D5A27);
  box-shadow: 0 0 0 2px var(--primary-light, #E1ECE2);
}

/* 卡片顶栏：学科、书名、章节、页码 Badge */
.tb-card-top {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  flex-wrap: wrap;
}

.tb-card-book-info {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  font-size: 0.8rem;
  color: var(--text-muted, #5F745E);
}

.tb-subject-badge {
  padding: 2px 7px;
  border-radius: 6px;
  font-size: 0.72rem;
  font-weight: 600;
  line-height: 1.2;
}

.tb-subject-badge.pharmacology {
  background: #E0E7FF;
  color: #3730A3;
}

.tb-subject-badge.industrial_pharmacy {
  background: #FEF3C7;
  color: #92400E;
}

.tb-subject-badge.pharmacy_administration {
  background: #DCFCE7;
  color: #166534;
}

.tb-subject-badge.international_pharmaceutical_regulations {
  background: #F3E8FF;
  color: #6B21A8;
}

.tb-subject-badge.politics,
.tb-subject-badge.politics_mayuan,
.tb-subject-badge.politics_maozhongte,
.tb-subject-badge.politics_xinsixiang,
.tb-subject-badge.politics_shigang,
.tb-subject-badge.politics_sixiu {
  background: #FEE2E2;
  color: #991B1B;
}

body.dark-theme .tb-subject-badge.politics,
body.dark-theme .tb-subject-badge.politics_mayuan,
body.dark-theme .tb-subject-badge.politics_maozhongte,
body.dark-theme .tb-subject-badge.politics_xinsixiang,
body.dark-theme .tb-subject-badge.politics_shigang,
body.dark-theme .tb-subject-badge.politics_sixiu {
  background: rgba(239, 68, 68, 0.22);
  color: #FCA5A5;
}

/* 核心页码突出显示 Badge */
.tb-card-page-badge {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  background: #FFF7ED;
  color: #C2410C;
  border: 1px solid #FFEDD5;
  padding: 3px 9px;
  border-radius: 8px;
  font-size: 0.82rem;
  font-weight: 700;
  font-family: var(--font-mono, monospace);
  flex-shrink: 0;
  box-shadow: 0 1px 2px rgba(194, 65, 12, 0.08);
}

body.dark-theme .tb-card-page-badge {
  background: rgba(234, 88, 12, 0.18);
  color: #FB923C;
  border-color: rgba(234, 88, 12, 0.3);
}

/* 卡片标题与考点 */
.tb-card-title {
  font-size: 1rem;
  font-weight: 600;
  color: var(--text-main, #233322);
  line-height: 1.35;
}

.tb-card-path {
  font-size: 0.76rem;
  color: var(--text-muted, #5F745E);
  line-height: 1.3;
}

/* 教材要点摘录 - 课本层级化版面 */
.tb-card-snippet {
  font-size: 0.85rem;
  line-height: 1.6;
  color: var(--text-main, #233322);
  background: rgba(0, 0, 0, 0.015);
  padding: 10px 12px;
  border-radius: 8px;
  border-left: 3.5px solid var(--accent-color, #4F8549);
  display: flex;
  flex-direction: column;
  gap: 8px;
}

body.dark-theme .tb-card-snippet {
  background: rgba(255, 255, 255, 0.025);
  border-left-color: #68A661;
}

/* 结构化板块：【药理作用】、【临床应用】、【不良反应】等 */
.tb-snippet-section {
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.tb-snippet-section + .tb-snippet-section {
  padding-top: 6px;
  border-top: 1px dashed rgba(0, 0, 0, 0.06);
}

body.dark-theme .tb-snippet-section + .tb-snippet-section {
  border-top-color: rgba(255, 255, 255, 0.07);
}

.tb-snippet-tag {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  align-self: flex-start;
  font-size: 0.74rem;
  font-weight: 700;
  padding: 2px 7px;
  border-radius: 4px;
  margin-bottom: 2px;
  letter-spacing: 0.2px;
}

/* 各板块专属色系 */
.tb-snippet-tag.tag-pharma { background: #E8F5E9; color: #1B5E20; border: 1px solid #C8E6C9; }
.tb-snippet-tag.tag-clinical { background: #E0F2FE; color: #0369A1; border: 1px solid #BAE6FD; }
.tb-snippet-tag.tag-adverse { background: #FEF2F2; color: #B91C1C; border: 1px solid #FECACA; }
.tb-snippet-tag.tag-kinetics { background: #F0FDFA; color: #0F766E; border: 1px solid #CCFBF1; }
.tb-snippet-tag.tag-interaction { background: #FAF5FF; color: #7E22CE; border: 1px solid #F3E8FF; }
.tb-snippet-tag.tag-excipient { background: #FFFBEB; color: #B45309; border: 1px solid #FDE68A; }
.tb-snippet-tag.tag-law { background: #F1F5F9; color: #334155; border: 1px solid #E2E8F0; }
.tb-snippet-tag.tag-default { background: #F3F4F6; color: #374151; border: 1px solid #E5E7EB; }

body.dark-theme .tb-snippet-tag.tag-pharma { background: rgba(27, 94, 32, 0.25); color: #81C784; border-color: rgba(129, 199, 132, 0.3); }
body.dark-theme .tb-snippet-tag.tag-clinical { background: rgba(3, 105, 161, 0.25); color: #7DD3FC; border-color: rgba(125, 211, 252, 0.3); }
body.dark-theme .tb-snippet-tag.tag-adverse { background: rgba(185, 28, 28, 0.25); color: #FCA5A5; border-color: rgba(252, 165, 165, 0.3); }
body.dark-theme .tb-snippet-tag.tag-kinetics { background: rgba(15, 118, 110, 0.25); color: #5EEAD4; border-color: rgba(94, 234, 212, 0.3); }
body.dark-theme .tb-snippet-tag.tag-interaction { background: rgba(126, 34, 206, 0.25); color: #D8B4FE; border-color: rgba(216, 180, 254, 0.3); }
body.dark-theme .tb-snippet-tag.tag-excipient { background: rgba(180, 83, 9, 0.25); color: #FCD34D; border-color: rgba(252, 211, 77, 0.3); }
body.dark-theme .tb-snippet-tag.tag-law { background: rgba(51, 65, 85, 0.35); color: #CBD5E1; border-color: rgba(203, 213, 225, 0.3); }

/* 子要点/分类小标题 (如 1. 胃肠道反应、① 与双香豆素合用) */
.tb-subtopic-head {
  display: flex;
  align-items: center;
  gap: 7px;
  margin-top: 8px;
  margin-bottom: 3px;
  padding: 2px 0 1px 2px;
}

.tb-subtopic-head:first-child {
  margin-top: 2px;
}

.tb-subtopic-dot {
  width: 5px;
  height: 5px;
  border-radius: 50%;
  background: var(--accent-color, #4F8549);
  flex-shrink: 0;
  opacity: 0.85;
}

.tb-subtopic-title {
  font-size: 0.84rem;
  font-weight: 700;
  color: var(--text-main, #1F2937);
  letter-spacing: 0.2px;
  line-height: 1.4;
}

body.dark-theme .tb-subtopic-title {
  color: #F3F4F6;
}

body.dark-theme .tb-subtopic-dot {
  background: #81C784;
}

/* 单行知识点列表 */
.tb-snippet-item {
  display: flex;
  align-items: flex-start;
  gap: 6px;
  font-size: 0.82rem;
  line-height: 1.55;
  padding-left: 2px;
}

.tb-snippet-item.tb-item-kv {
  margin: 1px 0;
}

.tb-snippet-item.tb-item-kv .tb-snippet-key {
  color: var(--accent-color, #2D5A27);
  margin-right: 2px;
}

body.dark-theme .tb-snippet-item.tb-item-kv .tb-snippet-key {
  color: #A3D89D;
}

.tb-snippet-bullet {
  color: var(--accent-color, #4F8549);
  font-size: 0.95rem;
  line-height: 1.35;
  user-select: none;
  flex-shrink: 0;
}

.tb-snippet-key {
  font-weight: 700;
  color: var(--text-main, #233322);
}

.tb-snippet-val {
  color: var(--text-muted, #4A5D49);
}

body.dark-theme .tb-snippet-key {
  color: #E2ECE1;
}

body.dark-theme .tb-snippet-val {
  color: #B2C2B1;
}

/* 联想与错字纠正提示横条 */
.tb-suggest-banner {
  padding: 6px 12px;
  background: rgba(45, 90, 39, 0.08);
  border-radius: 6px;
  font-size: 0.78rem;
  color: var(--primary-color, #2D5A27);
  display: flex;
  align-items: center;
  gap: 6px;
  margin-bottom: 8px;
}

body.dark-theme .tb-suggest-banner {
  background: rgba(104, 166, 97, 0.15);
  color: #A3D89D;
}

/* 高亮关键词 */
.tb-search-highlight {
  background: #FEF08A;
  color: #854D0E;
  padding: 0 2px;
  border-radius: 3px;
  font-weight: 600;
}

body.dark-theme .tb-search-highlight {
  background: #854D0E;
  color: #FEF08A;
}

/* 卡片操作底栏 */
.tb-card-actions {
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: 8px;
  margin-top: 4px;
}

.tb-action-btn {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  background: transparent;
  border: 1px solid var(--border-color, #E2EBE2);
  color: var(--text-main, #233322);
  font-size: 0.78rem;
  font-weight: 500;
  padding: 4px 10px;
  border-radius: 6px;
  cursor: pointer;
  transition: all 0.15s ease;
  text-decoration: none;
}

.tb-action-btn:hover {
  background: var(--primary-light, #E1ECE2);
  border-color: var(--accent-color, #4F8549);
  color: var(--primary-color, #2D5A27);
}

.tb-action-btn.primary {
  background: var(--primary-color, #2D5A27);
  color: #ffffff;
  border-color: var(--primary-color, #2D5A27);
}

.tb-action-btn.primary:hover {
  background: var(--primary-hover, #1E3F19);
}

/* 空状态与加载状态 */
.tb-search-empty {
  text-align: center;
  padding: 36px 16px;
  color: var(--text-muted, #5F745E);
  font-size: 0.9rem;
}

.tb-search-empty-icon {
  font-size: 2.2rem;
  margin-bottom: 8px;
}

.tb-search-footer {
  padding: 10px 18px;
  background: rgba(0, 0, 0, 0.02);
  border-top: 1px solid var(--border-color, #E2EBE2);
  display: flex;
  align-items: center;
  justify-content: space-between;
  font-size: 0.75rem;
  color: var(--text-muted, #5F745E);
}

.tb-kbd-hints {
  display: flex;
  gap: 12px;
}

.tb-kbd-hints span kbd {
  background: rgba(0, 0, 0, 0.05);
  border: 1px solid rgba(0, 0, 0, 0.08);
  border-radius: 4px;
  padding: 1px 4px;
  font-size: 0.7rem;
}

body.dark-theme .tb-kbd-hints span kbd {
  background: rgba(255, 255, 255, 0.08);
  border-color: rgba(255, 255, 255, 0.12);
}

/* 移动端与平板适配 - 顶格对齐防遮挡，紧贴顶部安全区 */
@media (max-width: 768px) {
  .tb-search-backdrop {
    align-items: flex-start !important;
    padding-top: max(8px, env(safe-area-inset-top, 8px)) !important;
    padding-bottom: max(12px, env(safe-area-inset-bottom, 12px)) !important;
    padding-left: 8px !important;
    padding-right: 8px !important;
  }
  .tb-search-dialog {
    width: 100%;
    height: calc(100dvh - max(16px, env(safe-area-inset-top, 16px)) - max(12px, env(safe-area-inset-bottom, 12px)));
    max-height: calc(100dvh - max(16px, env(safe-area-inset-top, 16px)) - max(12px, env(safe-area-inset-bottom, 12px)));
    border-radius: 14px;
    border: 1px solid var(--border-color, #E2EBE2);
  }
  .tb-search-header {
    padding: 12px 14px;
  }
  .tb-search-input {
    font-size: 0.96rem;
  }
  .tb-search-body {
    padding: 10px 12px max(16px, env(safe-area-inset-bottom, 16px));
  }
  .tb-search-footer {
    display: none;
  }
}
