/* XSignsCartItemEditor — 购物车页 / 抽屉这一侧
 *
 * 链接的位置与外观刻意与 xsigns_cart_edit_item 的 "Edit Design" 保持一致：
 * 同一行上两种商品（设计器的 / 上传稿的）看起来必须是同一个东西。
 */

a.xsigns-ie-edit {
    cursor: pointer;
    text-decoration: underline;
}

a.xsigns-ie-edit:hover {
    opacity: 0.75;
}

/* ------------------------------------------------------------------
   /cart（Blocks 购物车）

   JS 把链接克隆进 .wc-block-cart-item__quantity，放在 Remove item 左边；
   原来 item_data 生成的那一条用 .xsigns-ie-source 藏掉。
   ------------------------------------------------------------------ */

.wc-block-components-product-details li.xsigns-ie-source {
    display: none !important;
}

/* 该容器原本是 column（数量选择器在上、Remove 在下），而数量选择器被 comun-woo
   全局隐藏了，所以改成 row 不会留空位。
   前缀 table.wc-block-cart-items .wc-block-cart-items__row 是必须的：
   WooCommerce 的 cart.css 就是在这个层级设的 flex-direction: column。 */
table.wc-block-cart-items .wc-block-cart-items__row .wc-block-cart-item__quantity.xsigns-ie-row {
    flex-direction: row;
    align-items: center;
    gap: 12px;
}

/* 与 Remove item 完全一致：12px/24px、下划线、无背景无边框无内距 */
a.xsigns-ie-edit.xsigns-ie-inline {
    display: block;
    margin: 0;
    padding: 0;
    border: 0;
    background: none;
    font-size: 12px;
    line-height: 24px;
    font-weight: 400;
    color: inherit;
    text-decoration: underline;
}

/* ------------------------------------------------------------------
   结算页的订单摘要里不要这个链接

   服务端已经在 is_checkout() 时不输出了（见 xsigns_ie_add_item_data），这一条
   是兜底：结算页上任何一次 Store API 往返（用优惠券、改地址、换配送方式）都会
   用返回的数据重渲染摘要，而那些请求直接打到 /wp-json，没有页面上下文，
   is_checkout() 在那里恒为 false，链接会被重新塞回来。

   只圈定结算区块：抽屉在结算页上照样能打开，那里的编辑入口应当保留。
   ------------------------------------------------------------------ */

.wp-block-woocommerce-checkout a.xsigns-ie-edit {
    display: none !important;
}

/* ------------------------------------------------------------------
   betheme 侧边抽屉
   ------------------------------------------------------------------ */

.mfn-chpf-right a.xsigns-ie-edit.xsigns-ie-sidecart {
    display: inline-block;
    margin: 0 16px 0 0;
    font-size: inherit;
    line-height: inherit;
    color: inherit;
    text-decoration: none;
}

/* 「图标 + 空格 + 文字」在窄屏上会从空格处断行，垃圾桶图标独占一行很难看 */
.mfn-chpf-right a.xsigns-ie-edit.xsigns-ie-sidecart {
    white-space: nowrap;
}

.mfn-chpf-right a.xsigns-ie-edit.xsigns-ie-sidecart:hover {
    opacity: 0.7;
}

/* ------------------------------------------------------------------
   支架行的标记

   服务端在抽屉里给这一行塞了一个空 span（见 includes/wirestands-lock.php），
   前端据此摘掉 Remove。它本身不该占位 —— 万一 JS 没跑，也不能在数量后面
   留一个空格子。

   ⚠ 名字不能再叫 xsigns-ie-locked：那个类是加在 <html> 上锁滚动条用的，
   两者撞名之后，这条 display:none !important 会在弹窗一打开就把【整页】
   隐藏掉 —— 购物车和弹窗一起消失，只剩白屏，而且 DOM 和网络请求全都正常，
   极难排查。类名各归各的用途，别再复用。
   ------------------------------------------------------------------ */

.xsigns-ie-accessory {
    display: none !important;
}

/* ------------------------------------------------------------------
   支架行：名称和图片不是链接

   背后的商品是 wirestands_internal —— 只为了跟着招牌一起计价而存在，
   前台没有可打开的商品页，链接点过去是打不开的。

   服务端已经把 permalink 过滤成空串（woocommerce_cart_item_permalink，
   见 includes/wirestands-lock.php），但 Blocks 照样会渲染成 <a href="">，
   图片那一格还另有一个自己的链接。所以这里补一刀：整行由 cartItemClass
   过滤器打上 .xsigns-ie-accessory-row，把两处都变回普通文字。
   ------------------------------------------------------------------ */

.wc-block-cart-items__row.xsigns-ie-accessory-row .wc-block-components-product-name,
.wc-block-cart-items__row.xsigns-ie-accessory-row .wc-block-cart-item__image a {
    pointer-events: none;
    cursor: default;
    color: inherit;
    text-decoration: none;
}

/* 抽屉里是另一种做法：那边由 JS 把 href 摘掉（不是把 <a> 拆掉 —— 主题用
   `.mfn-chp-image a img` 定图片尺寸，拆了 <a> 图片就变成原图大小），
   这里只把残留的手型光标和下划线收拾干净。 */
a.xsigns-ie-deadlink {
    cursor: default;
    text-decoration: none;
}

/* ------------------------------------------------------------------
   弹窗

   内容是 iframe，高度固定（min(92vh, 980px)），滚动条在 iframe 内部。
   不做「按内容自适应高度」的 postMessage 联动：那一页的高度会随
   算价/上传/第二面出现反复变化，跟着抖不如给一个稳定的框。
   ------------------------------------------------------------------ */

.xsigns-ie-modal {
    position: fixed;
    inset: 0;
    z-index: 100000;              /* betheme 的固定顶栏是 999 */
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 16px;
}

.xsigns-ie-modal.xsigns-ie-hidden {
    display: none;
}

.xsigns-ie-backdrop {
    position: absolute;
    inset: 0;
    background: rgba(15, 23, 42, 0.55);
}

.xsigns-ie-dialog {
    position: relative;
    width: min(1100px, 100%);
    height: min(92vh, 980px);
    background: #fff;
    border-radius: 12px;
    overflow: hidden;
    box-shadow: 0 24px 60px rgba(0, 0, 0, 0.35);
}

.xsigns-ie-iframe {
    display: block;
    width: 100%;
    height: 100%;
    border: 0;
    opacity: 0;
    transition: opacity 0.15s ease;
}

.xsigns-ie-modal.xsigns-ie-loaded .xsigns-ie-iframe {
    opacity: 1;
}

/* 首屏空白期的转圈。iframe 里那一页要跑主题样式 + 算价一次，
   没有这个反馈会像是没点动。 */
.xsigns-ie-spinner {
    position: absolute;
    left: 50%;
    top: 50%;
    width: 34px;
    height: 34px;
    margin: -17px 0 0 -17px;
    border: 3px solid #dbe2ee;
    border-top-color: #1e3a6e;
    border-radius: 50%;
    animation: xsigns-ie-spin 0.8s linear infinite;
}

.xsigns-ie-modal.xsigns-ie-loaded .xsigns-ie-spinner {
    display: none;
}

@keyframes xsigns-ie-spin {
    to { transform: rotate(360deg); }
}

/* ------------------------------------------------------------------
   打不开时的说明（见 JS 的 showFailure）

   盖在 iframe 上，而不是替换它 —— 失败原因可能只是一次超时，
   iframe 里那份（半截的）文档留着，"在新标签页打开" 也还指得到原 URL。
   ------------------------------------------------------------------ */

.xsigns-ie-failure {
    position: absolute;
    inset: 0;
    z-index: 2;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 6px;
    padding: 32px;
    text-align: center;
    background: #fff;
    font-family: Nunito, system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
}

.xsigns-ie-failure-title {
    margin: 0;
    font-size: 17px;
    font-weight: 800;
    color: #1e3a6e;
}

.xsigns-ie-failure-text {
    margin: 0;
    font-size: 14px;
    color: #6b7280;
}

.xsigns-ie-failure-actions {
    display: flex;
    align-items: center;
    gap: 12px;
    margin: 14px 0 0;
}

.xsigns-ie-failure-open,
.xsigns-ie-failure-close {
    border: 0 !important;
    border-radius: 8px !important;
    padding: 10px 20px !important;
    font-size: 14px;
    font-weight: 800;
    line-height: 1.2;
    cursor: pointer;
    text-decoration: none;
}

.xsigns-ie-failure-open {
    background-color: #1e3a6e !important;
    color: #fff !important;
}

.xsigns-ie-failure-close {
    background-color: #cfd8e5 !important;
    color: #1f2937 !important;
}

/* 失败时那个转圈没有意义了 */
.xsigns-ie-modal.xsigns-ie-failed .xsigns-ie-spinner {
    display: none;
}

/* 弹窗打开时锁住底层滚动 */
html.xsigns-ie-locked,
html.xsigns-ie-locked body {
    overflow: hidden;
}

@media (max-width: 600px) {
    .xsigns-ie-modal { padding: 0; }
    .xsigns-ie-dialog {
        width: 100%;
        height: 100%;
        border-radius: 0;
    }
}
