/* 浏览历史（design/components.md 第 12 节）：页头面板与 /user-history/ 页面。
   页面只有一层带边框的容器，行间用分隔线；页头面板是无遮罩的 raised 浮层（同 .zb-search-popover）。 */

/* —— 行：面板与页面共用 —— */
.zbui .zb-history-item {
  position: relative;
  display: flex;
  align-items: center;
  gap: var(--zb-space-2xs);
  margin: 0;
  padding: 0 var(--zb-space-sm) 0 0;
  list-style: none;
  transition: background-color var(--zb-duration-fast) var(--zb-ease);
}
.zbui .zb-history-item__link {
  display: flex;
  flex: 1 1 auto;
  min-width: 0;
  align-items: center;
  gap: var(--zb-space-md);
  padding: var(--zb-space-sm) 0 var(--zb-space-sm) var(--zb-space-lg);
  color: var(--zb-text);
  text-decoration: none;
}
.zbui .zb-history-item__link:focus-visible {
  outline: 2px solid var(--zb-accent);
  outline-offset: -2px;
}
.zbui .zb-history-item__media {
  position: relative;
  display: grid;
  flex: 0 0 auto;
  width: 112px;
  aspect-ratio: 16 / 10;
  place-items: center;
  overflow: hidden;
  border-radius: var(--zb-radius-xs);
  background: var(--zb-muted);
  color: var(--zb-text-muted);
}
/* 没有缩略图或图片加载失败时的占位图标；装饰性，强制色模式下可以消失。 */
.zbui .zb-history-item__media::before {
  width: var(--zb-icon-xl);
  height: var(--zb-icon-xl);
  background: currentColor;
  content: "";
  -webkit-mask: url("../img/lucide/file-text.svg") center / contain no-repeat;
  mask: url("../img/lucide/file-text.svg") center / contain no-repeat;
}
.zbui .zb-history-item__media img {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  object-fit: cover;
}
.zbui .zb-history-item__body {
  display: flex;
  min-width: 0;
  flex-direction: column;
  gap: var(--zb-space-2xs);
}
.zbui .zb-history-item__title {
  display: -webkit-box;
  overflow: hidden;
  color: var(--zb-text);
  font-size: var(--zb-text-md);
  font-weight: var(--zb-weight-medium);
  line-height: var(--zb-leading-snug);
  overflow-wrap: anywhere;
  -webkit-box-orient: vertical;
  -webkit-line-clamp: 2;
  line-clamp: 2;
}
.zbui .zb-history-item__meta {
  color: var(--zb-text-muted);
  font-size: var(--zb-text-xs);
  font-variant-numeric: tabular-nums;
  line-height: var(--zb-leading-snug);
}
.zbui .zb-history-item__remove {
  display: inline-grid;
  flex: 0 0 auto;
  width: 32px;
  height: 32px;
  place-items: center;
  border: 0;
  border-radius: var(--zb-radius-sm);
  background: transparent;
  color: var(--zb-text-muted);
  cursor: pointer;
  padding: 0;
  transition: background-color var(--zb-duration-fast) var(--zb-ease), color var(--zb-duration-fast) var(--zb-ease),
    opacity var(--zb-duration-fast) var(--zb-ease);
}
.zbui .zb-history-item__remove:hover {
  background: var(--zb-danger-soft);
  color: var(--zb-danger);
}
.zbui .zb-history-item__remove:focus-visible {
  outline: 2px solid var(--zb-accent);
  outline-offset: 2px;
}
.zbui .zb-history-item__remove-icon {
  width: var(--zb-icon-lg);
  height: var(--zb-icon-lg);
}

/* 页面行：悬停用页面的弱化底，行与行之间分隔线。 */
.zb-history .zb-history-item:hover {
  background: var(--zb-muted);
}
.zb-history .zb-history-item + .zb-history-item {
  border-top: 1px solid var(--zb-border);
}
.zb-history-item__link:hover .zb-history-item__title {
  color: var(--zb-link);
}

/* —— 页头面板 —— */
.zbui.zb-history-popover {
  position: fixed;
  z-index: var(--zb-z-dropdown);
  top: 0;
  left: 0;
  display: flex;
  width: 360px;
  max-width: calc(100vw - var(--zb-space-lg));
  flex-direction: column;
  border: 1px solid var(--zb-border);
  border-radius: var(--zb-radius-md);
  background: var(--zb-surface-raised);
  box-shadow: var(--zb-shadow-overlay), var(--zb-inset-highlight);
  opacity: 0;
  padding: 0 0 var(--zb-space-2xs);
  transform: translateY(-4px);
  transition: opacity var(--zb-duration-fast) var(--zb-ease-out), transform var(--zb-duration-fast) var(--zb-ease-out);
}
.zbui.zb-history-popover.is-open {
  opacity: 1;
  transform: none;
}
.zbui.zb-history-popover[hidden] {
  display: none !important;
}
/* 组件工作台：在页面流里展示打开状态的面板。 */
.zbui.zb-history-popover--inline {
  position: relative;
  z-index: auto;
  margin-inline: auto;
}
.zbui .zb-history-popover__head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--zb-space-sm);
  padding: var(--zb-space-sm) var(--zb-space-sm) var(--zb-space-xs) var(--zb-space-md);
}
.zbui .zb-history-popover__title {
  color: var(--zb-text);
  font-size: var(--zb-text-base);
  font-weight: var(--zb-weight-semibold);
  line-height: var(--zb-leading-snug);
}
.zbui .zb-history-popover__all {
  display: inline-flex;
  min-height: var(--zb-control-h-xs);
  align-items: center;
  gap: var(--zb-space-2xs);
  border-radius: var(--zb-radius-sm);
  color: var(--zb-link);
  font-size: var(--zb-text-sm);
  font-weight: var(--zb-weight-medium);
  line-height: var(--zb-leading-snug);
  padding: 0 var(--zb-space-2xs) 0 var(--zb-space-xs);
  text-decoration: none;
}
.zbui .zb-history-popover__all:hover {
  background: var(--zb-surface-overlay-muted);
}
.zbui .zb-history-popover__all:focus-visible {
  outline: 2px solid var(--zb-accent);
  outline-offset: 0;
}
.zbui .zb-history-popover__all-icon {
  width: var(--zb-icon-md);
  height: var(--zb-icon-md);
}
.zbui .zb-history-popover__list {
  max-height: min(408px, 64vh);
  overflow-y: auto;
  overscroll-behavior: contain;
  list-style: none;
  margin: 0;
  padding: 0;
}
.zb-history-popover .zb-history-item:hover,
.zb-history-popover .zb-history-item:focus-within {
  background: var(--zb-surface-overlay-muted);
}
.zbui .zb-history-item--compact {
  padding-right: var(--zb-space-xs);
}
.zb-history-item--compact .zb-history-item__link {
  gap: var(--zb-space-sm);
  padding: var(--zb-space-xs) 0 var(--zb-space-xs) var(--zb-space-md);
}
.zb-history-item--compact .zb-history-item__media {
  width: 64px;
  background: var(--zb-surface-sunken);
}
.zb-history-item--compact .zb-history-item__media::before {
  width: var(--zb-icon-lg);
  height: var(--zb-icon-lg);
}
.zb-history-item--compact .zb-history-item__title {
  font-size: var(--zb-text-base);
  -webkit-line-clamp: 1;
  line-clamp: 1;
}
.zb-history-item--compact .zb-history-item__remove {
  width: 28px;
  height: 28px;
}
.zbui .zb-history-popover__empty {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: var(--zb-space-2xs);
  padding: var(--zb-space-lg) var(--zb-space-lg) var(--zb-space-xl);
  text-align: center;
}
.zbui .zb-history-popover__empty-icon {
  display: grid;
  width: 44px;
  height: 44px;
  place-items: center;
  margin-bottom: var(--zb-space-2xs);
  border-radius: var(--zb-radius-circle);
  background: var(--zb-surface-overlay-muted);
  color: var(--zb-text-muted);
}
.zbui .zb-history-popover__empty-icon svg {
  width: var(--zb-icon-xl);
  height: var(--zb-icon-xl);
}
.zbui .zb-history-popover__empty-title {
  margin: 0;
  color: var(--zb-text);
  font-size: var(--zb-text-base);
  font-weight: var(--zb-weight-medium);
  line-height: var(--zb-leading-snug);
}
.zbui .zb-history-popover__empty-text {
  max-width: 22em;
  margin: 0;
  color: var(--zb-text-muted);
  font-size: var(--zb-text-sm);
  line-height: var(--zb-leading-normal);
  text-wrap: balance;
}

/* —— 页面 —— */
.zbui.zb-history {
  max-width: 960px;
  margin: 0 auto;
  background: transparent;
  padding: var(--zb-space-xl) 0 var(--zb-space-2xl);
}
.zbui .zb-history__panel {
  overflow: hidden;
  border: 1px solid var(--zb-border);
  border-radius: var(--zb-radius-md);
  background: var(--zb-surface-card);
  box-shadow: var(--zb-shadow-card);
}
.zbui .zb-history__head {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: var(--zb-space-md);
  border-bottom: 1px solid var(--zb-border);
  padding: var(--zb-space-lg);
}
.zbui .zb-history__heading {
  display: flex;
  min-width: 0;
  align-items: center;
  gap: var(--zb-space-sm);
}
.zbui .zb-history__icon {
  display: inline-grid;
  flex: 0 0 auto;
  width: 40px;
  height: 40px;
  place-items: center;
  border-radius: var(--zb-radius-md);
  background: var(--zb-primary-soft);
  color: var(--zb-primary-soft-text);
}
.zbui .zb-history__icon svg {
  width: var(--zb-icon-xl);
  height: var(--zb-icon-xl);
}
.zbui .zb-history__heading-copy {
  min-width: 0;
}
.zbui .zb-history__title {
  margin: 0;
  color: var(--zb-text);
  font-size: var(--zb-text-xl);
  font-weight: var(--zb-weight-semibold);
  line-height: var(--zb-leading-tight);
}
.zbui .zb-history__summary {
  margin: var(--zb-space-2xs) 0 0;
  color: var(--zb-text-muted);
  font-size: var(--zb-text-sm);
  line-height: var(--zb-leading-snug);
}
.zbui .zb-history__tools {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: var(--zb-space-sm);
}
.zbui .zb-history__search {
  position: relative;
  display: flex;
  width: 240px;
  align-items: center;
  margin: 0;
}
.zbui .zb-history__search-icon {
  position: absolute;
  left: var(--zb-space-sm);
  width: var(--zb-icon-md);
  height: var(--zb-icon-md);
  color: var(--zb-text-muted);
  pointer-events: none;
}
.zbui .zb-history__search-input {
  width: 100%;
  min-height: var(--zb-control-h-sm);
  border: 1px solid var(--zb-field-border);
  border-radius: var(--zb-radius-sm);
  background: var(--zb-field);
  color: var(--zb-text);
  font-size: var(--zb-text-base);
  line-height: var(--zb-leading-normal);
  padding: 0 var(--zb-space-sm) 0 calc(var(--zb-space-sm) + var(--zb-icon-md) + var(--zb-space-xs));
  transition: border-color var(--zb-duration-fast) var(--zb-ease), box-shadow var(--zb-duration-fast) var(--zb-ease);
}
.zbui .zb-history__search-input::placeholder {
  color: var(--zb-text-subtle);
}
.zbui .zb-history__search-input:focus {
  border-color: var(--zb-accent);
  box-shadow: var(--zb-ring-soft);
  outline: 0;
}
.zbui .zb-history__search-input:disabled {
  cursor: not-allowed;
}
.zbui .zb-history__actions {
  display: flex;
  align-items: center;
  gap: var(--zb-space-xs);
}
.zbui .zb-history__switch {
  display: inline-flex;
  min-height: var(--zb-control-h-sm);
  align-items: center;
  gap: var(--zb-space-xs);
  border: 0;
  border-radius: var(--zb-radius-sm);
  background: transparent;
  color: var(--zb-text-soft);
  cursor: pointer;
  font-size: var(--zb-text-sm);
  font-weight: var(--zb-weight-medium);
  line-height: var(--zb-leading-snug);
  padding: 0 var(--zb-space-xs);
}
.zbui .zb-history__switch:hover {
  color: var(--zb-text);
}
.zbui .zb-history__switch:focus-visible {
  outline: 2px solid var(--zb-accent);
  outline-offset: 2px;
}
/* 关：内凹轨道加表单边界，圆钮小而偏左；开：主色轨道、白色圆钮靠右。位置与大小都是非颜色线索。 */
.zbui .zb-history__switch-track {
  position: relative;
  display: inline-block;
  flex: 0 0 auto;
  width: 36px;
  height: 20px;
  border-radius: var(--zb-radius-pill);
  background: var(--zb-surface-inset);
  box-shadow: inset 0 0 0 1px var(--zb-field-border);
  transition: background-color var(--zb-duration-fast) var(--zb-ease);
}
.zbui .zb-history__switch-knob {
  position: absolute;
  top: 5px;
  left: 5px;
  width: 10px;
  height: 10px;
  border-radius: var(--zb-radius-circle);
  background: var(--zb-text-muted);
  transition: transform var(--zb-duration-fast) var(--zb-ease-out), width var(--zb-duration-fast) var(--zb-ease-out),
    height var(--zb-duration-fast) var(--zb-ease-out), top var(--zb-duration-fast) var(--zb-ease-out),
    left var(--zb-duration-fast) var(--zb-ease-out);
}
.zb-history__switch[aria-checked="true"] .zb-history__switch-track {
  background: var(--zb-primary);
  box-shadow: none;
}
.zb-history__switch[aria-checked="true"] .zb-history__switch-knob {
  top: 3px;
  left: 3px;
  width: 14px;
  height: 14px;
  background: var(--zb-on-primary);
  transform: translateX(16px);
}
.zbui .zb-history__clear,
.zbui .zb-history__resume,
.zbui .zb-history__empty-action,
.zbui .zb-history__more-button {
  display: inline-flex;
  min-height: var(--zb-control-h-sm);
  align-items: center;
  justify-content: center;
  gap: var(--zb-space-2xs);
  border: 1px solid var(--zb-chip-border);
  border-radius: var(--zb-radius-sm);
  background: transparent;
  color: var(--zb-text-soft);
  cursor: pointer;
  font-size: var(--zb-text-sm);
  font-weight: var(--zb-weight-medium);
  line-height: var(--zb-leading-snug);
  padding: 0 var(--zb-space-sm);
  text-decoration: none;
  transition: background-color var(--zb-duration-fast) var(--zb-ease), border-color var(--zb-duration-fast) var(--zb-ease),
    color var(--zb-duration-fast) var(--zb-ease);
}
.zbui .zb-history__resume:hover,
.zbui .zb-history__empty-action:hover,
.zbui .zb-history__more-button:hover {
  background: var(--zb-muted);
  color: var(--zb-text);
}
.zb-history__clear:hover:not(:disabled) {
  border-color: var(--zb-danger-soft-border);
  background: var(--zb-danger-soft);
  color: var(--zb-danger-soft-text);
}
.zbui .zb-history__clear:disabled {
  cursor: not-allowed;
  opacity: 0.5;
}
.zbui .zb-history__clear:focus-visible,
.zbui .zb-history__resume:focus-visible,
.zbui .zb-history__empty-action:focus-visible,
.zbui .zb-history__more-button:focus-visible {
  outline: 2px solid var(--zb-accent);
  outline-offset: 2px;
}
.zbui .zb-history__clear-icon {
  width: var(--zb-icon-md);
  height: var(--zb-icon-md);
}
.zbui .zb-history__paused {
  display: flex;
  align-items: center;
  gap: var(--zb-space-sm);
  margin: var(--zb-space-md) var(--zb-space-lg) 0;
  border: 1px solid var(--zb-info-soft-border);
  border-radius: var(--zb-radius-sm);
  background: var(--zb-info-soft);
  color: var(--zb-info-soft-text);
  font-size: var(--zb-text-sm);
  line-height: var(--zb-leading-normal);
  padding: var(--zb-space-xs) var(--zb-space-xs) var(--zb-space-xs) var(--zb-space-sm);
}
.zbui .zb-history__paused-icon {
  flex: 0 0 auto;
  width: var(--zb-icon-lg);
  height: var(--zb-icon-lg);
}
.zbui .zb-history__paused-text {
  flex: 1 1 auto;
  margin: 0;
}
.zbui .zb-history__resume {
  flex: 0 0 auto;
  border-color: var(--zb-info-soft-border);
  color: var(--zb-info-soft-text);
}
.zbui .zb-history__groups:empty {
  display: none;
}
.zbui .zb-history__group + .zb-history__group {
  border-top: 1px solid var(--zb-border);
}
.zbui .zb-history__group-label {
  margin: 0;
  color: var(--zb-text-muted);
  font-size: var(--zb-text-xs);
  font-weight: var(--zb-weight-semibold);
  line-height: var(--zb-leading-snug);
  padding: var(--zb-space-md) var(--zb-space-lg) var(--zb-space-2xs);
}
.zbui .zb-history__list {
  list-style: none;
  margin: 0;
  padding: 0;
}
.zbui .zb-history__empty {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: var(--zb-space-xs);
  padding: var(--zb-space-2xl) var(--zb-space-lg);
  text-align: center;
}
.zbui .zb-history__empty-icon {
  display: grid;
  width: 56px;
  height: 56px;
  place-items: center;
  margin-bottom: var(--zb-space-2xs);
  border-radius: var(--zb-radius-circle);
  background: var(--zb-muted);
  color: var(--zb-text-muted);
}
.zbui .zb-history__empty-icon svg {
  width: var(--zb-icon-2xl);
  height: var(--zb-icon-2xl);
}
.zbui .zb-history__empty-title {
  max-width: 22em;
  margin: 0;
  color: var(--zb-text);
  font-size: var(--zb-text-md);
  font-weight: var(--zb-weight-semibold);
  line-height: var(--zb-leading-snug);
  text-wrap: balance;
}
.zbui .zb-history__empty-text {
  max-width: 22em;
  margin: 0;
  color: var(--zb-text-muted);
  font-size: var(--zb-text-sm);
  line-height: var(--zb-leading-normal);
  text-wrap: balance;
}
.zbui .zb-history__empty-action {
  margin-top: var(--zb-space-sm);
}
.zbui .zb-history__more {
  display: flex;
  justify-content: center;
  border-top: 1px solid var(--zb-border);
  padding: var(--zb-space-md) var(--zb-space-lg);
}
.zbui .zb-history__more-button {
  min-width: 200px;
}
.zbui .zb-history__noscript {
  margin: 0;
  color: var(--zb-text-soft);
  font-size: var(--zb-text-sm);
  padding: var(--zb-space-xl) var(--zb-space-lg);
  text-align: center;
}
.zbui .zb-history__sr {
  position: absolute;
  overflow: hidden;
  width: 1px;
  height: 1px;
  margin: 0;
  clip: rect(0 0 0 0);
  padding: 0;
  white-space: nowrap;
}

/* —— 清空确认：原生 <dialog>.showModal()，模态浮层配方 —— */
.zbui .zb-history-dialog {
  width: min(400px, calc(100vw - 2 * var(--zb-space-lg)));
  margin: auto;
  border: 1px solid var(--zb-border-overlay);
  border-radius: var(--zb-radius-xl);
  background: var(--zb-surface-overlay);
  box-shadow: var(--zb-shadow-overlay), var(--zb-inset-highlight);
  color: var(--zb-text);
  padding: var(--zb-space-xl);
}
.zbui .zb-history-dialog::backdrop {
  background: var(--zb-overlay);
}
.zbui .zb-history-dialog__title {
  margin: 0;
  color: var(--zb-text);
  font-size: var(--zb-text-lg);
  font-weight: var(--zb-weight-semibold);
  line-height: var(--zb-leading-tight);
}
.zbui .zb-history-dialog__body {
  margin: var(--zb-space-xs) 0 0;
  color: var(--zb-text-soft);
  font-size: var(--zb-text-base);
  line-height: var(--zb-leading-normal);
}
.zbui .zb-history-dialog__actions {
  display: flex;
  justify-content: flex-end;
  gap: var(--zb-space-sm);
  margin-top: var(--zb-space-xl);
}
.zbui .zb-history-dialog__cancel,
.zbui .zb-history-dialog__confirm {
  display: inline-flex;
  min-height: var(--zb-control-h-sm);
  min-width: 88px;
  align-items: center;
  justify-content: center;
  border-radius: var(--zb-radius-sm);
  cursor: pointer;
  font-size: var(--zb-text-base);
  font-weight: var(--zb-weight-medium);
  line-height: var(--zb-leading-snug);
  padding: 0 var(--zb-space-lg);
  transition: background-color var(--zb-duration-fast) var(--zb-ease);
}
.zbui .zb-history-dialog__cancel {
  border: 1px solid var(--zb-border-overlay);
  background: transparent;
  color: var(--zb-text);
}
.zbui .zb-history-dialog__cancel:hover {
  background: var(--zb-surface-overlay-muted);
}
.zbui .zb-history-dialog__confirm {
  border: 0;
  background: var(--zb-danger);
  color: var(--zb-danger-on-solid);
}
.zbui .zb-history-dialog__confirm:hover {
  background: var(--zb-danger-hover);
}
.zbui .zb-history-dialog__cancel:focus-visible,
.zbui .zb-history-dialog__confirm:focus-visible {
  outline: 2px solid var(--zb-accent);
  outline-offset: 2px;
}

/* —— 手机：标题区换行，搜索占满一行 —— */
@media (max-width: 575.98px) {
  .zbui.zb-history {
    padding-top: var(--zb-space-md);
  }
  .zbui .zb-history__head {
    padding: var(--zb-space-md);
  }
  .zbui .zb-history__tools,
  .zbui .zb-history__search {
    width: 100%;
  }
  .zbui .zb-history__search-input {
    font-size: var(--zb-text-lg);
  }
  .zbui .zb-history__actions {
    width: 100%;
    justify-content: space-between;
  }
  .zbui .zb-history__paused {
    margin-inline: var(--zb-space-md);
  }
  .zbui .zb-history__group-label {
    padding-inline: var(--zb-space-md);
  }
  .zbui .zb-history-item__link {
    gap: var(--zb-space-sm);
    padding-left: var(--zb-space-md);
  }
  .zbui .zb-history-item__media {
    width: 88px;
  }
  .zbui .zb-history-item__title {
    font-size: var(--zb-text-base);
  }
}

/* —— 能悬停的设备：行内删除按钮在行悬停或聚焦时出现（同 YouTube 历史记录），触屏始终显示 —— */
@media (hover: hover) {
  .zbui .zb-history-item__remove {
    opacity: 0;
  }
  .zb-history-item:hover .zb-history-item__remove,
  .zb-history-item:focus-within .zb-history-item__remove {
    opacity: 1;
  }
}

/* —— 触屏：按钮的触控区 44px —— */
@media (any-pointer: coarse) {
  .zbui .zb-history__search-input,
  .zbui .zb-history__switch,
  .zbui .zb-history__clear,
  .zbui .zb-history__resume,
  .zbui .zb-history__empty-action,
  .zbui .zb-history__more-button,
  .zbui .zb-history-dialog__cancel,
  .zbui .zb-history-dialog__confirm {
    min-height: var(--zb-control-h);
  }
  .zbui .zb-history-item__remove {
    width: var(--zb-control-h);
    height: var(--zb-control-h);
  }
  .zbui .zb-history-item__remove {
    opacity: 1;
  }
}

@media (prefers-reduced-motion: reduce) {
  .zbui.zb-history-popover,
  .zbui .zb-history-item,
  .zbui .zb-history-item__remove,
  .zbui .zb-history__switch-track,
  .zbui .zb-history__switch-knob {
    transition: none !important;
  }
  .zbui.zb-history-popover {
    transform: none !important;
  }
}

@media (forced-colors: active) {
  .zbui.zb-history-popover,
  .zbui .zb-history__panel,
  .zbui .zb-history-dialog {
    border: 1px solid CanvasText;
  }
  .zbui .zb-history__switch-track {
    border: 1px solid CanvasText;
  }
  .zb-history__switch[aria-checked="true"] .zb-history__switch-knob {
    background: Highlight;
    forced-color-adjust: none;
  }
}
