/* ==========================================================================
   Ahamoment Dark Mode (html[data-theme="dark"]) Quality Adaptations
   Resolves high-pressure button contrast, illegible light-on-white text,
   and unadapted light containers across profile, content, materials,
   assets, copy library, review, and settings.
   ========================================================================== */

html[data-theme="dark"] .primary-btn,
html[data-theme="dark"] .btn.primary-btn {
  /* HAZ-178 R1 patch：dark mode 主按钮跟 palette 走，不再被 14 层硬陶土强按回来。 */
  background: var(--primary-accent) !important;
  border-color: var(--primary-accent) !important;
  color: #ffffff !important;
}

html[data-theme="dark"] .primary-btn:hover,
html[data-theme="dark"] .btn.primary-btn:hover {
  background: var(--primary-accent-hover) !important;
  border-color: var(--primary-accent-hover) !important;
  color: #ffffff !important;
}

html[data-theme="dark"] .primary-btn:disabled,
html[data-theme="dark"] .primary-btn[disabled],
html[data-theme="dark"] .btn.primary-btn:disabled,
html[data-theme="dark"] .btn.primary-btn[disabled] {
  background: #33322f !important;
  border-color: #44423c !important;
  color: #6e6b63 !important;
  opacity: 0.6 !important;
  cursor: not-allowed !important;
}

/* Active status chips, filter selectors, active pagination page buttons */
html[data-theme="dark"] .material-chip.active,
html[data-theme="dark"] .filter-chip.active,
html[data-theme="dark"] .copylibrary-status-chip.active,
html[data-theme="dark"] .page-btn.active,
html[data-theme="dark"] .page-btn.is-active,
html[data-theme="dark"] .workbench-pagination .page-btn.active,
html[data-theme="dark"] .workbench-pagination .page-btn.is-active,
html[data-theme="dark"] .review-import-choice .aha-choice-menu .active {
  /* HAZ-178 R1 patch：dark active chip/page-btn 跟 palette 走。 */
  background: var(--primary-accent) !important;
  color: #ffffff !important;
  border-color: var(--primary-accent) !important;
}

/* Inspiration page final polish: brand icons should read as icons, not colored pills. */
body.inspiration-page .platform-brand-icon,
body.inspiration-page .platform-filter-brand.platform-brand-icon,
body.inspiration-page .platform-filter-dot.platform-brand-icon,
html[data-theme="dark"] body.inspiration-page .platform-brand-icon,
html[data-theme="dark"] body.inspiration-page .platform-filter-brand.platform-brand-icon,
html[data-theme="dark"] body.inspiration-page .platform-filter-dot.platform-brand-icon {
  background: transparent !important;
  border-color: transparent !important;
  box-shadow: none !important;
}

body.inspiration-page .platform-filter-brand.platform-brand-icon {
  width: 22px !important;
  min-width: 22px !important;
  height: 22px !important;
  padding: 0 !important;
}

body.inspiration-page .card-meta-line .platform-filter-brand.platform-brand-icon,
body.inspiration-page .card-meta-line .platform-filter-dot.platform-brand-icon {
  width: 16px !important;
  min-width: 16px !important;
  height: 16px !important;
  flex-basis: 16px !important;
}

body.inspiration-page .platform-brand-svg {
  width: 16px !important;
  height: 16px !important;
}

body.inspiration-page .card-meta-line .platform-brand-svg {
  width: 13px !important;
  height: 13px !important;
}

body.inspiration-page .platform-filter-xhs.platform-brand-icon { color: #ff2442 !important; }
body.inspiration-page .platform-filter-douyin.platform-brand-icon,
body.inspiration-page .platform-filter-tiktok.platform-brand-icon { color: #1f1e1d !important; }
html[data-theme="dark"] body.inspiration-page .platform-filter-douyin.platform-brand-icon,
html[data-theme="dark"] body.inspiration-page .platform-filter-tiktok.platform-brand-icon { color: #faf9f5 !important; }
body.inspiration-page .platform-filter-bili.platform-brand-icon { color: #00a1d6 !important; }
body.inspiration-page .platform-filter-wechat.platform-brand-icon { color: #07c160 !important; }
body.inspiration-page .platform-filter-channels.platform-brand-icon { color: #f97316 !important; }

body.inspiration-page .inspiration-data-overview {
  gap: 12px !important;
}

body.inspiration-page .overview-stat {
  gap: 8px !important;
}

body.inspiration-page .overview-stat .stat-icon {
  width: 22px !important;
  height: 22px !important;
  flex-basis: 22px !important;
  border-radius: 7px !important;
  background: transparent !important;
  border-color: currentColor !important;
  box-shadow: none !important;
  opacity: 1 !important;
}

body.inspiration-page .overview-stat .stat-icon svg {
  width: 13px !important;
  height: 13px !important;
  stroke-width: 2.2 !important;
}

body.inspiration-page .overview-stat.stat-total .stat-icon { color: #b05730 !important; }
body.inspiration-page .overview-stat.stat-unprocessed .stat-icon { color: #d97706 !important; }
body.inspiration-page .overview-stat.stat-favorited .stat-icon { color: #e11d48 !important; }
body.inspiration-page .overview-stat.stat-library .stat-icon { color: #16a34a !important; }
body.inspiration-page .overview-stat.stat-pending .stat-icon { color: #9c5f8f !important; }

body.inspiration-page .inspiration-detail-panel {
  overflow: hidden !important;
  scrollbar-gutter: auto !important;
}

body.inspiration-page .right-panel-content {
  overflow-y: auto !important;
  overflow-x: hidden !important;
  padding-right: 6px !important;
  scrollbar-width: thin;
  scrollbar-color: color-mix(in srgb, var(--text-muted) 28%, transparent) transparent;
}

body.inspiration-page .right-panel-content p {
  max-height: none !important;
  overflow: visible !important;
}

body.inspiration-page .right-panel-content::-webkit-scrollbar {
  width: 6px;
}

body.inspiration-page .right-panel-content::-webkit-scrollbar-track {
  background: transparent;
}

body.inspiration-page .right-panel-content::-webkit-scrollbar-thumb {
  border-radius: 999px;
  background: color-mix(in srgb, var(--text-muted) 24%, transparent);
}

body.inspiration-page .right-panel-content::-webkit-scrollbar-thumb:hover {
  background: color-mix(in srgb, var(--text-muted) 38%, transparent);
}

html[data-theme="dark"] body.inspiration-page .inspiration-tabs {
  gap: 4px !important;
  padding: 4px !important;
  border-color: #393733 !important;
  background: #191816 !important;
  box-shadow: none !important;
}

html[data-theme="dark"] body.inspiration-page .inspiration-tabs .tab-btn {
  min-height: 32px !important;
  border: 0 !important;
  border-radius: 6px !important;
  background: transparent !important;
  box-shadow: none !important;
  color: #adaaa3 !important;
}

html[data-theme="dark"] body.inspiration-page .inspiration-tabs .tab-btn:hover {
  background: rgba(168, 165, 156, 0.12) !important;
  color: #f2e1da !important;
}

html[data-theme="dark"] body.inspiration-page .inspiration-tabs .tab-btn.active {
  /* HAZ-178 R1 patch：dark 灵感页 tab active 跟 palette 走。 */
  background: var(--primary-accent) !important;
  border-color: var(--primary-accent) !important;
  box-shadow: 0 8px 18px color-mix(in srgb, var(--primary-accent) 28%, transparent) !important;
  color: #ffffff !important;
}

/* Material Library classification status selection chips */
html[data-theme="dark"] .material-chip.active .chip-count {
  background: rgba(255, 255, 255, 0.2) !important;
  color: #ffffff !important;
}

/* Copy library middle column list item selected active state */
html[data-theme="dark"] .copy-list-card-item.active {
  background: #33322f !important;
  /* HAZ-178 R1 patch：dark 文案库选中项左侧色条跟 palette 走。 */
  box-shadow: inset 4px 0 0 var(--primary-accent) !important;
  border-color: #44423c !important;
}

html[data-theme="dark"] .copy-list-card-item.active .copy-list-card-item-title-row strong {
  color: #ffffff !important;
}

/* Asset library reader usage actions wrapper background dark adaptions */
html[data-theme="dark"] .asset-reader-actions {
  background: var(--surface-muted) !important;
  border-color: var(--color-border) !important;
  box-shadow: none !important;
}

/* Personal profiles "AI help build profile" starter elements */
html[data-theme="dark"] .profile-ai-starter {
  background: #33322f !important;
  /* HAZ-178 R1 patch：profile starter 强调色跟 palette 走。 */
  color: var(--primary-accent) !important;
  border: 1px solid #44423c !important;
}

html[data-theme="dark"] .profile-ai-starter:hover {
  background: var(--primary-accent) !important;
  color: #ffffff !important;
  border-color: var(--primary-accent) !important;
}

/* Character metrics & words counting badges */
html[data-theme="dark"] .content-output-chars,
html[data-theme="dark"] [data-markdown-char-count],
html[data-theme="dark"] .copy-detail-wordcount-badge {
  background: var(--surface-muted) !important;
  color: var(--text-main) !important;
  border: 1px solid var(--color-border) !important;
}

html[data-theme="dark"] body.content-page .content-lite-panel-head {
  margin: -4px -4px 10px !important;
  padding: 10px 12px !important;
  /* HAZ-178 R1 patch：panel-head 暗色边走 palette 软描边。 */
  border: 1px solid color-mix(in srgb, var(--primary-accent) 26%, transparent) !important;
  border-radius: 8px !important;
  background: rgba(33, 32, 30, 0.72) !important;
  box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.04) !important;
}

html[data-theme="dark"] body.content-page .content-lite-panel-head > div {
  gap: 10px !important;
}

html[data-theme="dark"] body.content-page .content-lite-panel-head h3 {
  color: #faf9f5 !important;
  font-size: 1rem !important;
  font-weight: 750 !important;
}

html[data-theme="dark"] body.content-page .content-panel-label {
  display: inline-flex !important;
  align-items: center !important;
  min-height: 22px !important;
  padding: 3px 8px !important;
  border: 1px solid rgba(224, 139, 109, 0.5) !important;
  border-radius: 6px !important;
  background: rgba(201, 100, 66, 0.22) !important;
  color: #ecb09a !important;
  font-size: 0.7rem !important;
  letter-spacing: 0.08em !important;
}

html[data-theme="dark"] body.content-page .content-lite-output .content-panel-label {
  border-color: rgba(217, 119, 87, 0.52) !important;
  background: rgba(215, 121, 84, 0.24) !important;
  color: #f1cfc1 !important;
}

html[data-theme="dark"] body.content-page .content-output-chars {
  background: rgba(33, 32, 30, 0.9) !important;
  border-color: rgba(168, 165, 156, 0.36) !important;
  color: #ffffff !important;
  font-weight: 800 !important;
}

/* Detail panel widgets & floating popovers */
html[data-theme="dark"] .copy-detail-version-dropdown {
  background: #1f1e1d !important;
  border-color: #44423c !important;
  box-shadow: 0 10px 15px -3px rgba(0, 0, 0, 0.5), 0 4px 6px -2px rgba(0, 0, 0, 0.5) !important;
}

html[data-theme="dark"] .copy-detail-version-option:hover {
  background: #33322f !important;
}

html[data-theme="dark"] .copy-detail-version-trigger {
  background: var(--surface-muted) !important;
  border-color: var(--color-border) !important;
  color: var(--text-main) !important;
}

/* Icon action triggers & circular close bookmark triggers */
html[data-theme="dark"] .icon-btn,
html[data-theme="dark"] .asset-detail-top .icon-btn {
  background: rgba(255, 255, 255, 0.06) !important;
  border: 1px solid rgba(255, 255, 255, 0.1) !important;
  color: var(--text-main) !important;
}

html[data-theme="dark"] .icon-btn:hover,
html[data-theme="dark"] .asset-detail-top .icon-btn:hover {
  background: rgba(255, 255, 255, 0.12) !important;
  color: #ffffff !important;
}

html[data-theme="dark"] .icon-btn svg,
html[data-theme="dark"] .asset-detail-top .icon-btn svg {
  stroke: var(--text-main) !important;
}

/* Three dots more options triggers */
html[data-theme="dark"] .btn.secondary-btn.ghost {
  background: transparent !important;
  color: var(--text-muted) !important;
  border-color: transparent !important;
}

html[data-theme="dark"] .btn.secondary-btn.ghost:hover {
  background: rgba(255, 255, 255, 0.08) !important;
  color: var(--text-main) !important;
}

html[data-theme="dark"] body.content-page .btn.secondary-btn.ghost.content-clear-btn {
  border-color: rgba(168, 165, 156, 0.42) !important;
  background: rgba(47, 45, 42, 0.88) !important;
  color: #f6e3d7 !important;
  box-shadow:
    inset 0 1px 0 rgba(255, 255, 255, 0.06),
    0 0 0 1px rgba(33, 32, 30, 0.18);
}

html[data-theme="dark"] body.content-page .btn.secondary-btn.ghost.content-clear-btn:hover,
html[data-theme="dark"] body.content-page .btn.secondary-btn.ghost.content-clear-btn:focus-visible {
  border-color: rgba(234, 185, 166, 0.7) !important;
  background: rgba(201, 100, 66, 0.16) !important;
  color: #faf0ea !important;
}

body.sidebar-collapsed .sidebar {
  width: 64px !important;
  flex: 0 0 64px !important;
  flex-basis: 64px !important;
}

.app-container {
  max-width: 100vw;
  overflow-x: clip;
}

.sidebar-nav {
  scrollbar-width: none;
  scrollbar-gutter: auto;
}

.sidebar-nav::-webkit-scrollbar {
  width: 0;
  height: 0;
}

.sidebar-shell-toggle {
  position: absolute !important;
  top: 42px !important;
  right: -15px !important;
  left: auto !important;
  transform: translateY(-50%) !important;
  z-index: 80;
}

.sidebar-shell-toggle:hover,
.sidebar-shell-toggle:focus-visible {
  transform: translateY(-50%) scale(1.04) !important;
}

.sidebar-shell-toggle:active {
  transform: translateY(-50%) scale(0.96) !important;
}

@media (max-width: 900px) {
  html,
  body,
  .app-container {
    width: 100%;
    max-width: 100%;
    overflow-x: hidden !important;
  }

  body.sidebar-collapsed .sidebar {
    width: 100% !important;
    flex: 0 0 auto !important;
    flex-basis: auto !important;
  }

  .sidebar-shell-toggle,
  body.sidebar-collapsed .sidebar-shell-toggle {
    top: 32px !important;
    right: 12px !important;
    transform: none !important;
  }

  .sidebar-shell-toggle:hover,
  .sidebar-shell-toggle:focus-visible {
    transform: scale(1.04) !important;
  }

  .sidebar-shell-toggle:active {
    transform: scale(0.96) !important;
  }
}

/* Dashed add tag buttons in copy library */
html[data-theme="dark"] button.copylibrary-tag {
  border-color: var(--primary-accent) !important;
  color: var(--primary-accent) !important;
  background: transparent !important;
}

html[data-theme="dark"] button.copylibrary-tag:hover {
  background: #33322f !important;
  color: #ffffff !important;
}

/* ==========================================================================
   Ahamoment Dark Mode (html[data-theme="dark"]) Supplementary Adaptations
   - Fixes segmented control button whitening in trend analytics.
   - Fixes iOS-style settings switch checked status contrast and row sizing.
   - Fixes copy reader paper dark colors and grid item min-width text clipping.
   ========================================================================== */

/* 1. Trend chart metrics tabs selection in Analytics Review */
html[data-theme="dark"] .review-metric-segment .tab-btn.active {
  background: #c96442 !important;
  border-color: #c96442 !important;
  color: #ffffff !important;
}

/* 2. iOS-style checkbox switch checked colors and layout stability */
html[data-theme="dark"] .settings-switch-input:checked + .settings-switch-track {
  background: #c96442 !important;
}

.settings-switch-row {
  width: 100% !important;
  max-width: 100% !important;
  box-sizing: border-box !important;
}

/* 3. Copy detail reader paper dark mode theme */
html[data-theme="dark"] .copy-detail-reader-paper {
  background: #21201e !important;
  border-color: var(--color-border) !important;
  color: var(--text-main) !important;
  box-shadow: 0 4px 6px -1px rgba(0, 0, 0, 0.3) !important;
}

html[data-theme="dark"] .copy-detail-reader-paper h1,
html[data-theme="dark"] .copy-detail-reader-paper h2,
html[data-theme="dark"] .copy-detail-reader-paper h3,
html[data-theme="dark"] .copy-detail-reader-paper strong {
  color: #ffffff !important;
}

html[data-theme="dark"] .copy-detail-reader-paper h1 {
  border-bottom-color: var(--color-border) !important;
}

/* 4. Grid container text overflow clipping for content sources metadata */
.copy-detail-meta-flat-item {
  min-width: 0 !important;
}

.copy-detail-meta-flat-item strong {
  display: block !important;
  width: 100% !important;
  overflow: hidden !important;
  text-overflow: ellipsis !important;
  white-space: nowrap !important;
}

/* Ensure metadata card background is 100% opaque and stacked above scroll layers */
html[data-theme="dark"] .copy-detail-meta-flat-card {
  background: #1f1e1d !important;
  border-color: var(--color-border) !important;
  position: relative !important;
  z-index: 5 !important;
  box-shadow: 0 -4px 6px -1px rgba(0, 0, 0, 0.2) !important;
}

/* Give enough bottom margin inside copy details to prevent scroll clipping */
.copy-detail-pane-scroll-container {
  padding-bottom: 24px !important;
}

.copy-detail-meta-flat-card {
  margin-top: 8px !important;
}

/* Layout protection: Prevent flexbox from shrinking detail card components to avoid text bleeding and overlap */
.copy-detail-header-card,
.copy-detail-reader-paper,
.copy-detail-meta-flat-card {
  flex-shrink: 0 !important;
}

/* Preview modal controls: keep top-right tooltips inside the dialog and make +/- visibly zoom media. */
.preview-window-actions [data-tooltip]::after {
  top: calc(100% + 8px);
  bottom: auto;
  transform: translateX(-50%) translateY(0) scale(0.96);
}

.preview-window-actions [data-tooltip]::before {
  top: calc(100% + 4px);
  bottom: auto;
  border-width: 0 4px 4px 4px;
  border-color: transparent transparent rgba(33, 32, 30, 0.92) transparent;
  transform: translateX(-50%) translateY(0) scale(0.96);
}

.preview-window-actions [data-tooltip]:hover::after,
.preview-window-actions [data-tooltip]:focus-visible::after {
  transform: translateX(-50%) translateY(0) scale(1);
}

.preview-window-actions [data-tooltip]:hover::before,
.preview-window-actions [data-tooltip]:focus-visible::before {
  transform: translateX(-50%) translateY(0) scale(1);
}

.preview-stage,
.preview-media {
  overflow: auto;
}

.preview-media > img,
.preview-media > video,
.preview-media > iframe,
.preview-media > .embedded-video,
.preview-media > .video-play-frame,
.preview-media > .xiaohongshu-scroll {
  transform: scale(var(--preview-media-scale, 1));
  transform-origin: center center;
  transition: transform 0.16s var(--ease-out);
}

/* ── 全局 tooltip 深色模式修正 ──
   .aha-tooltip 用 --text-main 作底色；暗模式下 --text-main 是近白色，导致白色方块。
   翻回深底色+亮字（color-mix 取 --text-main 的 12% + --color-bg 的 88% ≈ 极深灰）。 */
html[data-theme="dark"] .aha-tooltip {
  background: color-mix(in srgb, var(--text-main) 12%, var(--color-bg));
  color: var(--text-main);
  border: 1px solid rgba(255, 255, 255, 0.10);
}
