/* ==========================================================================
   首页增强样式：顶栏快捷入口 / 三主题切换 / 自动超链接 / 卡片搜索
   与 docs/技术栈全览.html 内联样式共用同一套设计令牌，不覆盖原布局
   ========================================================================== */

/* ---------------------------------------------------------------- 顶栏操作区 */
.header-actions {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-shrink: 0;
}

.header-action-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  height: 36px;
  padding: 0 12px;
  border-radius: var(--radius-full);
  border: 1px solid var(--border-light);
  background: var(--bg-surface);
  color: var(--text-secondary);
  font-size: 12.5px;
  font-weight: 500;
  white-space: nowrap;
  transition: background-color 0.18s ease, color 0.18s ease, border-color 0.18s ease,
    transform 0.18s ease;
  text-decoration: none;
}

.header-action-btn:hover {
  background: var(--bg-subtle);
  color: var(--text-primary);
  border-color: var(--border-strong);
}

.header-action-btn:active {
  transform: translateY(1px);
}

.header-action-btn.primary {
  background: var(--accent-indigo);
  border-color: var(--accent-indigo);
  color: var(--text-inverse);
}

.header-action-btn.primary:hover {
  background: var(--accent-indigo-hover);
  border-color: var(--accent-indigo-hover);
  color: var(--text-inverse);
}

.hab-kbd {
  font-family: var(--font-mono);
  font-size: 11px;
  line-height: 1;
  padding: 3px 5px;
  border-radius: 5px;
  background: var(--bg-subtle);
  border: 1px solid var(--border-light);
  color: var(--text-muted);
}

/* ---------------------------------------------------------------- 三主题切换 */
.theme-switch {
  position: relative;
  flex-shrink: 0;
}

.theme-toggle {
  height: 36px;
  gap: 7px;
}

.theme-swatch {
  width: 15px;
  height: 15px;
  border-radius: 5px;
  border: 1px solid var(--border-strong);
  background: #ffffff;
  flex-shrink: 0;
  transition: background-color 0.2s ease, border-color 0.2s ease;
}

.swatch-white {
  background: #ffffff;
  border-color: #cbd5e1;
}

.swatch-green {
  background: #e9f3ec;
  border-color: #a9cfb9;
}

.swatch-dark {
  background: #111827;
  border-color: #334155;
}

.theme-menu {
  position: absolute;
  top: calc(100% + 10px);
  right: 0;
  min-width: 208px;
  padding: 6px;
  border-radius: var(--radius-md);
  background: var(--bg-surface);
  border: 1px solid var(--border-light);
  box-shadow: var(--shadow-lg);
  display: none;
  z-index: 200;
}

.theme-menu.open {
  display: block;
  animation: tswMenuIn 0.16s ease both;
}

@keyframes tswMenuIn {
  from {
    opacity: 0;
    transform: translateY(-6px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

.theme-option {
  display: flex;
  align-items: center;
  gap: 9px;
  width: 100%;
  padding: 9px 10px;
  border: 0;
  border-radius: var(--radius-sm);
  background: transparent;
  color: var(--text-secondary);
  font-size: 13px;
  font-weight: 500;
  text-align: left;
  transition: background-color 0.15s ease, color 0.15s ease;
}

.theme-option em {
  margin-left: auto;
  font-style: normal;
  font-size: 11.5px;
  color: var(--text-muted);
}

.theme-option:hover {
  background: var(--bg-subtle);
  color: var(--text-primary);
}

.theme-option.is-active {
  background: var(--accent-indigo-soft);
  color: var(--accent-indigo);
}

.theme-option.is-active em {
  color: var(--accent-indigo);
  opacity: 0.75;
}

/* ---------------------------------------------------------------- 自动超链接 */
.tech-link {
  color: var(--accent-indigo);
  font-weight: 600;
  text-decoration: underline dotted var(--accent-indigo-border);
  text-decoration-thickness: 1.5px;
  text-underline-offset: 3px;
  border-radius: 3px;
  padding: 0 1px;
  transition: background-color 0.15s ease, color 0.15s ease, text-decoration-color 0.15s ease;
  word-break: break-word;
}

.tech-link:hover {
  color: var(--accent-indigo-hover);
  background: var(--accent-indigo-soft);
  text-decoration-color: var(--accent-indigo);
  text-decoration-style: solid;
}

.tech-link:focus-visible {
  outline: 2px solid var(--accent-indigo);
  outline-offset: 2px;
}

.tech-link::after {
  content: '';
}

/* 已读过的技术：换一种字体颜色做区分（与阅读次数无关） */
.tech-link.is-read {
  color: #B45309;
  text-decoration-color: rgba(180, 83, 9, 0.45);
}

.tech-link.is-read:hover {
  color: #92400E;
  background: rgba(251, 191, 36, 0.18);
}

[data-theme='green'] .tech-link.is-read {
  color: #8A5A12;
}

[data-theme='dark'] .tech-link.is-read {
  color: #FBBF24;
}

[data-theme='dark'] .tech-link.is-read:hover {
  color: #FCD34D;
  background: rgba(251, 191, 36, 0.16);
}

/* 重点技术：荧光笔式整块黄底（跨行时逐行包裹，不与已读的字色冲突） */
.tech-link.is-key {
  background-color: #FFF723;
  background-image: none;
  border-radius: 3px;
  padding: 1px 3px;
  margin: 0 -3px;
  box-decoration-break: clone;
  -webkit-box-decoration-break: clone;
}

.tech-link.is-key:hover {
  color: var(--accent-indigo-hover);
  background-color: #FFEC00;
}

[data-theme='green'] .tech-link.is-key {
  background-color: #FBF12A;
}

[data-theme='dark'] .tech-link.is-key {
  color: #3F3200;
  background-color: #FDEE2E;
}

[data-theme='dark'] .tech-link.is-key:hover {
  color: #2A2100;
  background-color: #FFE800;
}

/* 表格内的链接保持紧凑，不撑高行高 */
.table-wrap .tech-link,
table .tech-link {
  text-underline-offset: 2px;
  font-weight: 600;
}

@media (max-width: 900px) {
  /* 快捷跳转条隐藏后，操作区仍需要靠右 */
  .header-actions {
    margin-left: auto;
  }

  .hab-text,
  .hab-kbd {
    display: none;
  }

  .header-action-btn {
    width: 36px;
    padding: 0;
  }

  #themeLabel {
    display: none;
  }

  .theme-toggle {
    padding: 0 10px;
  }
}

@media (max-width: 560px) {
  .header-actions {
    gap: 6px;
  }

  .header-left {
    min-width: 0;
    flex-shrink: 1;
  }

  .brand,
  .brand > div {
    min-width: 0;
  }

  .brand > div {
    overflow: hidden;
  }

  .brand-title {
    font-size: 13px;
    line-height: 1.3;
    max-width: 100%;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
  }

  .brand-sub {
    display: none;
  }
}

/* ---------------------------------------------------------------- 卡片搜索浮层 */
.search-overlay {
  position: fixed;
  inset: 0;
  z-index: 300;
  display: flex;
  align-items: flex-start;
  justify-content: center;
  padding: 10vh 16px 24px;
  background: rgba(15, 23, 42, 0.44);
  backdrop-filter: blur(4px);
  -webkit-backdrop-filter: blur(4px);
  opacity: 0;
  visibility: hidden;
  transition: opacity 0.18s ease, visibility 0.18s ease;
}

.search-overlay.open {
  opacity: 1;
  visibility: visible;
}

.search-panel {
  width: min(660px, 100%);
  max-height: 76vh;
  display: flex;
  flex-direction: column;
  background: var(--bg-surface);
  border: 1px solid var(--border-light);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-lg);
  overflow: hidden;
  transform: translateY(-10px) scale(0.99);
  transition: transform 0.2s ease;
}

.search-overlay.open .search-panel {
  transform: translateY(0) scale(1);
}

.search-input-row {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 14px 16px;
  border-bottom: 1px solid var(--border-light);
  color: var(--text-muted);
}

.search-input-row input {
  flex: 1;
  min-width: 0;
  border: 0;
  outline: none;
  background: transparent;
  color: var(--text-primary);
  font-family: inherit;
  font-size: 15px;
  line-height: 1.5;
}

.search-input-row input::placeholder {
  color: var(--text-muted);
}

.search-input-row kbd {
  font-family: var(--font-mono);
  font-size: 11px;
  padding: 3px 6px;
  border-radius: 5px;
  border: 1px solid var(--border-light);
  background: var(--bg-subtle);
  color: var(--text-muted);
}

.search-meta {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 8px 18px;
  font-size: 11.5px;
  color: var(--text-muted);
  border-bottom: 1px solid var(--border-light);
  background: var(--bg-page);
}

.search-results {
  list-style: none;
  margin: 0;
  padding: 6px;
  overflow-y: auto;
  flex: 1;
}

.search-result {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 12px;
  border-radius: var(--radius-sm);
  cursor: pointer;
  color: var(--text-secondary);
  text-decoration: none;
  transition: background-color 0.12s ease;
}

.search-result:hover,
.search-result.active {
  background: var(--accent-indigo-soft);
}

.search-result-main {
  min-width: 0;
  flex: 1;
}

.search-result-name {
  font-size: 13.5px;
  font-weight: 600;
  color: var(--text-primary);
  display: flex;
  align-items: center;
  gap: 8px;
}

.search-result-name.is-read {
  color: #B45309;
}

[data-theme='dark'] .search-result-name.is-read {
  color: #FBBF24;
}

.search-result-name.is-key {
  background-color: #FFF723;
  border-radius: 3px;
  padding: 1px 4px;
}

[data-theme='dark'] .search-result-name.is-key {
  color: #3F3200;
  background-color: #FDEE2E;
}

.search-result-summary {
  font-size: 12px;
  color: var(--text-muted);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  margin-top: 2px;
}

.search-layer-badge {
  font-size: 10.5px;
  font-weight: 600;
  padding: 2px 7px;
  border-radius: var(--radius-full);
  background: var(--bg-subtle);
  border: 1px solid var(--border-light);
  color: var(--text-muted);
  white-space: nowrap;
  flex-shrink: 0;
}

.search-status {
  width: 7px;
  height: 7px;
  border-radius: 50%;
  flex-shrink: 0;
  background: var(--border-strong);
}

.search-status.published {
  background: var(--accent-emerald);
  box-shadow: 0 0 0 3px var(--accent-emerald-soft);
}

.search-result mark {
  background: var(--accent-amber-soft);
  color: inherit;
  border-radius: 3px;
  padding: 0 2px;
}

.search-empty {
  padding: 34px 16px;
  text-align: center;
  color: var(--text-muted);
  font-size: 13px;
}

.search-foot {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 10px 16px;
  border-top: 1px solid var(--border-light);
  background: var(--bg-page);
  font-size: 12px;
  color: var(--text-muted);
}

.search-foot a {
  font-weight: 600;
}

.search-foot b {
  color: var(--text-primary);
}

@media (max-width: 560px) {
  .search-overlay {
    padding: 4vh 10px 10px;
  }

  .search-panel {
    max-height: 88vh;
  }

  .search-meta {
    font-size: 11px;
  }

  .search-foot span {
    display: none;
  }
}
