/* amazon 站渲染修补：补上快照页缺失的两组关键规则。
   1) .a-offscreen —— 读屏专用文本，官方用 clip 藏起来；快照页缺这条规则，
      导致完整标题/价格/section 标题重复显示并叠在页面上。
   2) 列表页网格 —— 快照里 puisg 列宽由 Amazon 的 JS 运行时写入，静态页算成 0 宽，
      卡片被挤成细长条；这里改回「图在上、信息在下」的网格视图，并隐藏
      只由 JS 驱动的附加组件（对比按钮、捆绑优惠等）。 */

/* ---------- 1. 读屏文本不占视觉 ---------- */
.a-offscreen,
.a-offscreen:active,
.a-offscreen:focus {
  clip: rect(1px, 1px, 1px, 1px) !important;
  position: absolute !important;
  height: 1px !important;
  width: 1px !important;
  overflow: hidden !important;
  white-space: nowrap !important;
  border: 0 !important;
  padding: 0 !important;
  margin: 0 !important;
}

/* ---------- 2. 列表页网格视图 ---------- */
.s-main-slot [data-component-type="s-search-result"] .puisg-row {
  display: block !important;
}
.s-main-slot [data-component-type="s-search-result"] .puisg-col,
.s-main-slot [data-component-type="s-search-result"] .puisg-col-inner {
  width: 100% !important;
  max-width: 100% !important;
  flex: 0 0 auto !important;
  overflow: visible !important;
}

/* 图片盒统一 200px，等比缩放居中，和官网网格卡一致 */
.s-main-slot [data-component-type="s-search-result"] .s-product-image-container {
  height: 200px !important;
  margin-bottom: 4px;
}
.s-main-slot [data-component-type="s-search-result"] img.s-image {
  max-height: 200px !important;
  max-width: 100% !important;
  object-fit: contain !important;
}

/* 标题两行截断 */
.s-main-slot [data-component-type="s-search-result"] h2 {
  display: -webkit-box !important;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
}

/* 只由 JS 生成的附加组件：对比按钮、捆绑优惠、悬浮视频 */
[data-cy="secondary-offer-recipe"],
.copilot-compare-image-button-container,
.cp-comparison-button,
.cp-text-inside-button-animated-hidden,
.cui-video__link--hidden,
[class*="_hidden_"] {
  display: none !important;
}

/* 轮播容器必须裁剪，否则横向溢出把整页撑出滚动条 */
.a-carousel-container,
.a-carousel-viewport,
.fb-collections-carousel-container,
[class*="carousel-container"] {
  overflow: hidden !important;
  max-width: 100% !important;
}
/* 仅桌面宽度裁剪溢出；小屏交给下面 html 的横向滚动 */
@media (min-width: 1000px) {
  #a-page,
  #search {
    overflow-x: clip;
  }
}

/* 兜底：个别轮播把整页撑宽；clip 不产生滚动容器，不影响吸顶导航 */
html {
  overflow-x: hidden;
}

/* 卡片等高：同排卡片拉伸到行高，底部按钮对齐 */
.s-main-slot > [data-component-type="s-search-result"] {
  display: flex;
  flex-direction: column;
  align-self: stretch !important;
  height: auto !important;
}
.s-main-slot > [data-component-type="s-search-result"] .sg-col-inner,
.s-main-slot > [data-component-type="s-search-result"] .s-widget-container,
.s-main-slot > [data-component-type="s-search-result"] .rush-component,
.s-main-slot > [data-component-type="s-search-result"] .a-section[data-cy="asin-faceout-container"] {
  display: flex !important;
  flex-direction: column !important;
  flex: 1 1 auto !important;
  height: 100% !important;
}
.s-main-slot [data-component-type="s-search-result"] [data-cy="delivery-block"],
.s-main-slot [data-component-type="s-search-result"] .a-row:has(button[name="submit.addToCart"]) {
  margin-top: auto !important;
}
/* 搜索结果页（16 列槽位）：卡片跨 4 列 = 每行 4 个，和官网网格一致 */
body[data-amz-grid="4"] .s-main-slot > [data-component-type="s-search-result"] {
  grid-column: span 4 !important;
}

/* 标签的「默认态 / 悬停态」两份同时可见会导致 Sponsored 等文字重复 */
.puis-label-popover-hover { display: none !important; }
.puis-label-popover:hover .puis-label-popover-hover,
.puis-label-popover:focus .puis-label-popover-hover { display: inline !important; }
.puis-label-popover:hover .puis-label-popover-default,
.puis-label-popover:focus .puis-label-popover-default { display: none !important; }

/* 窄屏跟随官网收缩列数，避免固定 283px 卡片被裁切 */
@media (max-width: 1279px) {
  .s-main-slot > [data-component-type="s-search-result"] { grid-column: span 8 !important; }
  body[data-amz-grid="4"] .s-main-slot > [data-component-type="s-search-result"] { grid-column: span 5 !important; }
}
@media (max-width: 900px) {
  .s-main-slot > [data-component-type="s-search-result"] { grid-column: span 12 !important; }
  body[data-amz-grid="4"] .s-main-slot > [data-component-type="s-search-result"] { grid-column: span 8 !important; }
}

/* 快照页是桌面版结构，容器宽度固定；小屏不裁切，改为允许横向滚动，保证内容可及 */
@media (max-width: 999px) {
  html { overflow-x: auto; }
}

/* 商品小图容器在静态页里高度算成 0，图就"消失"了；撑满父级并等比缩放 */
[class*="_asin-image-wrapper"],
[class*="_asin-image-container"],
[class*="_asin-image-wrapper"] > a,
[class*="_asin-image-container"] > a { height: 100% !important; min-height: 100% !important; }
[class*="_asin-image-wrapper"] img,
[class*="_asin-image-container"] img { height: 100% !important; width: 100% !important; object-fit: contain !important; }

/* 首屏"四宫格"促销卡：内部行高被固定成 66px，图和折扣标签挤在一起；按实测高度铺满 */
/* 轮播卡片自带 20px 上边距，导致顶部留白、底部被裁 */
#gwm-window .a-cardui { margin-top: 0 !important; }
#gwm-window [class*="card-body"] { height: auto !important; }
#gwm-window [class*="tile-container"] { grid-template-rows: repeat(2, 148px) !important; height: auto !important; }
#gwm-window [class*="tile-wrapper"] { height: 148px !important; }
#gwm-window [class*="flex-height"] { height: 100% !important; }
#gwm-window [class*="asin-container"] { height: 100% !important; }

/* 主题色卡片（如 "Amazon Device deals"）：卡片自身白底盖住了主题色，导致白色标题看不见、也没有外框。
   让卡片继承外层主题色、内容区保持白底，标题就落在主题色上了。 */
[class*="theming-card-background"] { border-radius: 16px; overflow: hidden; }
[class*="theming-card-background"] > .a-cardui { background: inherit !important; }
[class*="theming-card-background"] > .a-cardui > [class*="card-body"] { background: #fff !important; border-radius: 0 0 16px 16px; }
/* 主题卡标题原来贴边，按官网补内边距 */
[class*="theming-card-background"] [class*="user-surface-head"],
[class*="theming-card-background"] [class*="user-surface-header"] { padding: 12px 16px 8px !important; }
[class*="theming-card-background"] [class*="wd-editorial-header-container"] { display: block !important; padding: 12px 16px 8px !important; }


/* 导航 logo 精灵图（原图缺失，补用与官网同一张） */
.nav-sprite,
.nav-logo-base,
.nav-logo-tagline,
#nav-logo .nav-sprite {
  background-image: url("/amazon/amazon-assets/m.media_amazon.com/nav-sprite-global.png") !important;
  background-repeat: no-repeat;
}


/* 卡片内部滚动条会显示成右侧一条灰杠，隐藏掉 */
#gwm-window, #gwm-window *, .a-cardui, .a-cardui * {
  scrollbar-width: none !important;
  -ms-overflow-style: none !important;
}
#gwm-window *::-webkit-scrollbar, .a-cardui *::-webkit-scrollbar {
  width: 0 !important;
  height: 0 !important;
  display: none !important;
  background: transparent !important;
}


/* 「Amazon Device deals」卡重排：2×2 网格 */
.amz-deal-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 10px;
  padding: 10px;
}
.amz-deal-tile {
  display: flex;
  flex-direction: column;
  gap: 6px;
  min-width: 0;
  text-decoration: none;
  color: #0f1111;
}
.amz-deal-img {
  display: grid;
  place-items: center;
  height: 116px;
  overflow: hidden;
}
.amz-deal-img img {
  max-width: 100%;
  max-height: 116px;
  object-fit: contain;
  mix-blend-mode: multiply;
}
.amz-deal-name {
  font: 12px/1.35 Arial, "Amazon Ember", sans-serif;
  color: #0f1111;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
}
.amz-deal-tile:hover .amz-deal-name { color: #c7511f; text-decoration: underline; }


/* 生成页缺 Amazon 的 body 类，默认 8px 外边距会让顶栏比首页窄 16px、整体右下偏移 */
body[data-preview-site="amazon"],
body[data-live-amazon] {
  margin: 0 !important;
}


/* 窄屏顶栏收缩：避免横向溢出把购物车挤出屏幕（也就不会出现聚焦后整页横向滚动） */
#nav-belt { overflow: hidden; }

@media (max-width: 1180px) {
  /* Amazon 桌面端给 #navbar 写死 1000px 底宽，窄窗口会横向溢出 */
  #navbar, #nav-belt, #nav-belt-search { min-width: 0 !important; }
  #glow-ingress-block { display: none !important; }
  #nav-search { min-width: 0; flex: 1 1 auto; }
}

@media (max-width: 1180px) {
  #a-page, #search { overflow-x: clip; }
}

@media (max-width: 1000px) {
  #nav-orders, #nav-link-accountList .nav-arrow { display: none !important; }
  #nav-tools { gap: 6px; }
  #nav-cart { margin-left: 6px; }
}

@media (max-width: 820px) {
  #nav-link-accountList .nav-line-2 { display: none !important; }
  #nav-link-accountList { min-width: 0 !important; }
  #nav-search { min-width: 0; }
}


/* 搜索按钮图标：精灵图切片与本地雪碧图不匹配（会画出购物车），改成自绘放大镜 */
.nav-search-submit {
  background-image: none !important;      /* 保留洋红底色，去掉错位的精灵图 */
  position: relative !important;
  top: 0 !important;                      /* Amazon 写了 top:5px，相对定位后会整体下移 */
}
#nav-search-submit-text { background-image: none !important; }
#nav-search-submit-button { background: transparent !important; border: 0; }
.nav-search-submit::after {
  content: "";
  position: absolute;
  left: 50%;
  top: 50%;
  width: 21px;
  height: 21px;
  transform: translate(-50%, -52%);
  background: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='%23fff' stroke-width='2.4' stroke-linecap='round'%3E%3Ccircle cx='10.5' cy='10.5' r='6.8'/%3E%3Cpath d='M15.6 15.6 21 21'/%3E%3C/svg%3E") center / 21px 21px no-repeat;
  pointer-events: none;
  z-index: 3;
}


/* 顶栏悬停：Amazon 用负 margin + border 画悬停框，缺父级 padding 时会整体位移，
   这里改成不占布局的 inset 阴影 */
#nav-link-accountList a,
#nav-link-accountList a:hover,
#nav-link-accountList a:focus,
#nav-orders,
#nav-orders:hover,
#nav-cart,
#nav-cart:hover {
  margin: 0 !important;
  border: 0 !important;
}
#nav-link-accountList a:hover,
#nav-link-accountList a:focus,
#nav-orders:hover,
#nav-cart:hover {
  box-shadow: inset 0 0 0 1px #fff;
  background: rgba(255, 255, 255, .12);
  border-radius: 2px;
}


/* 顶栏悬停会把 padding/top 改小导致整体位移，这里锁定静止态尺寸 */
#nav-cart:hover { padding: 0 9px 11px !important; top: 1px !important; }
#nav-orders:hover { padding: 0 9px 10px !important; top: 1px !important; }
#nav-link-accountList a:hover,
#nav-link-accountList a:focus { padding: 0 4px 8px 9px !important; top: 1px !important; }
