/* 帥府商店結帳動線（2026-10-17 商店前台整合 Task 5）。

   版型（設計規格 S4、Owner 指令 §四）：
   - 桌機：置中紙面面板 min(780px, 100% − 32px)、最高 94dvh，與商店對話框同一套米色紙面與圓角。
   - 手機（≤650px）：全螢幕全寬（100dvh、無圓角），頁面本體鎖捲；標題列與底部操作列 sticky。
   - 對話框本身是唯一的縱向捲動區（無巢狀捲軸）；底部操作列在內容流的最後（sticky），捲到底時不蓋住任何內容；
     scroll-padding 讓聚焦的欄位不會被標題列或操作列擋住（shop-checkout.js 另在鍵盤彈出後把欄位捲到中間）。
   - 色值一律引用 theme.css 既有色票（零硬編色）；字級全 rem；圓角走 --radius-*；觸控目標 ≥44px。
   - 頁面語義變數（--shop-paper 等）由 shop.css 的根選擇器同時掛在 .shop-checkout 上。 */

html:has(.shop-checkout[open]) {
    overflow: hidden;
}

.shop-checkout {
    width: min(780px, calc(100% - 32px));
    max-height: 94dvh;
    margin: auto;
    padding: 0;
    overflow: auto;
    overscroll-behavior: contain;
    scroll-padding-top: 160px;
    scroll-padding-bottom: 120px;
    border: 1px solid var(--shop-paper-line);
    border-radius: var(--radius-14);
    background: var(--shop-paper);
    color: var(--shop-paper-ink);
    box-shadow: 0 15px 70px color-mix(in srgb, var(--c-231815) 19%, transparent);
    line-height: 1.8;
}

.shop-checkout[open] {
    display: flex;
    flex-direction: column;
}

.shop-checkout::backdrop {
    background: color-mix(in srgb, var(--c-231815) 50%, transparent);
    backdrop-filter: blur(4px);
}

.shop-checkout [hidden] {
    display: none !important;
}

:where(.shop-checkout) :is(h2, h3, p, dl, dd, figure, fieldset) {
    margin: 0;
}

:where(.shop-checkout) :is(button, input, select) {
    font: inherit;
}

/* 標題／錯誤摘要的 tabindex="-1" 只是程式聚焦的落點（讓讀屏念到），不畫焦點框。 */
.shop-checkout :is(button, a, input, select, summary):focus-visible {
    outline: 3px solid var(--shop-focus);
    outline-offset: 3px;
}

.shop-checkout .shop-eyebrow {
    margin: 0;
    color: var(--shop-paper-gold);
}

/* ───────────── 標題列（sticky） ───────────── */
.shop-co__head {
    position: sticky;
    top: 0;
    z-index: 3;
    padding: 20px 32px 14px;
    border-bottom: 1px solid var(--shop-paper-rule);
    background: var(--shop-paper);
}

.shop-co__head-row {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
}

.shop-co__close {
    display: grid;
    place-items: center;
    flex: none;
    width: 44px;
    height: 44px;
    margin: -8px -12px -8px 0;
    padding: 0;
    border: 0;
    border-radius: var(--radius-full);
    background: transparent;
    color: var(--shop-paper-muted);
    font-size: 1.75rem;
    line-height: 1;
    cursor: pointer;
}

.shop-co__close:hover {
    background: var(--cream-warm);
}

.shop-co__close:disabled {
    opacity: 0.4;
    cursor: not-allowed;
}

.shop-co__title {
    margin: 2px 0 12px;
    font-family: var(--font-brand);
    font-size: 1.75rem;
    font-weight: 600;
    line-height: 1.4;
    letter-spacing: 0.06em;
    color: var(--shop-paper-ink);
}

.shop-co__title:focus {
    outline: none;
}

.shop-co__steps {
    display: flex;
    gap: 8px;
    margin: 0;
    padding: 0;
    list-style: none;
    counter-reset: none;
}

.shop-co__steps li {
    display: flex;
    flex: 1 1 0;
    align-items: center;
    gap: 8px;
    min-width: 0;
    font-size: 0.875rem;
    line-height: 1.4;
    color: var(--shop-paper-muted);
}

.shop-co__step-no {
    display: grid;
    place-items: center;
    flex: none;
    width: 28px;
    height: 28px;
    border: 1px solid var(--shop-paper-line);
    border-radius: var(--radius-full);
    background: var(--shop-paper);
    font-variant-numeric: tabular-nums;
}

.shop-co__steps li.is-done .shop-co__step-no {
    border-color: var(--c-b1813b);
    background: var(--c-f6e4bb);
    color: var(--c-714523);
}

.shop-co__steps li[aria-current="step"] {
    color: var(--shop-paper-ink);
    font-weight: 700;
}

.shop-co__steps li[aria-current="step"] .shop-co__step-no {
    border-color: var(--gold-deep);
    background: var(--gold-deep);
    color: var(--white-warm);
}

/* ───────────── 內容 ───────────── */
.shop-co__body {
    flex: 1 0 auto;
    padding: 22px 32px 28px;
}

.shop-co__section {
    display: grid;
    gap: 18px;
}

.shop-co__muted {
    font-size: 0.875rem;
    line-height: 1.7;
    color: var(--shop-paper-muted);
}

.shop-co__section > .shop-text-link {
    justify-self: start;
}

.shop-co__section p {
    text-wrap: pretty;
}

.shop-co__notice {
    margin: 0 0 16px;
    padding: 12px 16px;
    border: 1px solid var(--c-e1cba7);
    border-radius: var(--radius-8);
    background: var(--cream-warm);
    font-size: 0.875rem;
    line-height: 1.7;
}

.shop-co__alert {
    display: grid;
    gap: 10px;
    margin: 0 0 16px;
    padding: 14px 16px;
    border: 1px solid color-mix(in srgb, var(--shop-error) 45%, transparent);
    border-radius: var(--radius-8);
    background: var(--c-error-bg);
    color: var(--shop-error);
    font-size: 0.9rem;
    line-height: 1.7;
}

.shop-co__alert:focus {
    outline: none;
}

.shop-co__alert-actions {
    display: flex;
    flex-wrap: wrap;
    gap: 10px;
}

.shop-co__paused {
    padding: 12px 16px;
    border-radius: var(--radius-8);
    background: var(--cream-warm);
    color: var(--c-714523);
    font-size: 0.9rem;
}

/* LINE 登入 */
.shop-co__gate {
    justify-items: center;
    padding: 18px 0 8px;
    text-align: center;
}

.shop-co__gate .btn-line.shop-co__line {
    width: min(100%, 360px);
    min-height: 52px;
}

.shop-co__empty,
.shop-co__complete {
    justify-items: center;
    padding: 24px 0 8px;
    text-align: center;
}

.shop-co__done-mark {
    display: grid;
    place-items: center;
    width: 56px;
    height: 56px;
    border-radius: var(--radius-full);
    background: var(--c-f6e4bb);
    color: var(--gold-deep);
    font-size: 1.75rem;
}

/* ───────────── 商品明細（收據） ───────────── */
.shop-co-receipt {
    display: grid;
    grid-template-columns: minmax(0, 1fr) minmax(0, 1fr);
    gap: 4px 28px;
    padding: 18px 20px;
    border: 1px solid var(--shop-paper-line);
    border-radius: var(--radius-sm);
    background: var(--cream);
}

.shop-co__receipt-slot[aria-busy="true"] .shop-co-receipt {
    opacity: 0.6;
}

/* 明細還是舊的（另一個分頁改了數量、重算中或重算失敗）：明顯淡化，送出鈕同時停用，直到拿到新的試算。 */
.shop-co__receipt-slot.is-stale .shop-co-receipt {
    opacity: 0.4;
}

.shop-co-receipt__heading {
    grid-column: 1 / -1;
    font-size: 0.875rem;
    font-weight: 700;
    letter-spacing: 0.12em;
    color: var(--gold-deep);
}

.shop-co-receipt__lines {
    margin: 0;
    padding: 0;
    list-style: none;
}

.shop-co-receipt__line {
    display: flex;
    align-items: baseline;
    justify-content: space-between;
    gap: 14px;
    padding: 10px 0;
    border-bottom: 1px solid var(--shop-paper-rule);
}

.shop-co-receipt__line:last-child {
    border-bottom: 0;
}

.shop-co-receipt__name {
    min-width: 0;
}

.shop-co-receipt__name strong {
    display: block;
    font-weight: 600;
    line-height: 1.5;
}

.shop-co-receipt__name small {
    display: block;
    font-size: 0.875rem;
    color: var(--shop-paper-muted);
}

.shop-co-receipt__amount,
.shop-co-receipt__row dd {
    flex: none;
    white-space: nowrap;
    font-variant-numeric: tabular-nums;
}

.shop-co-receipt__totals {
    align-self: start;
    padding-left: 24px;
    border-left: 1px solid var(--shop-paper-rule);
}

.shop-co-receipt__row {
    display: flex;
    align-items: baseline;
    justify-content: space-between;
    gap: 14px;
    padding: 8px 0;
}

.shop-co-receipt__row dt small {
    display: block;
    font-size: 0.875rem;
    color: var(--shop-paper-muted);
}

.shop-co-receipt__row.is-discount dd {
    color: var(--note-ok-ink);
}

.shop-co-receipt__row.is-total {
    margin-top: 6px;
    padding-top: 12px;
    border-top: 1px solid var(--c-b08a4a);
    font-weight: 700;
}

/* 沒有折抵、沒有運費時合計是唯一一列：不再多畫一條分隔線（上方已有明細與合計的分界）。 */
.shop-co-receipt__row.is-total:first-child {
    margin-top: 0;
    padding-top: 8px;
    border-top: 0;
}

.shop-co-receipt__row.is-total dd {
    font-size: 1.25rem;
    color: var(--shop-paper-red);
}

.shop-co-receipt__foot {
    grid-column: 1 / -1;
    margin-top: 6px;
    font-size: 0.875rem;
    color: var(--shop-paper-muted);
}

/* 優惠券（只在請回自用；預設收合） */
.shop-co__coupon {
    padding: 0 16px;
    border: 1px solid var(--shop-paper-line);
    border-radius: var(--radius-sm);
    background: var(--shop-paper);
}

.shop-co__coupon summary {
    display: flex;
    align-items: center;
    min-height: 48px;
    font-weight: 600;
    color: var(--c-714523);
    cursor: pointer;
}

.shop-co__coupon[open] {
    padding-bottom: 14px;
}

.shop-co__coupon[open] > :not(summary) + :not(summary) {
    margin-top: 10px;
}

.shop-co__coupon-status {
    min-height: 1.5em;
    font-size: 0.9rem;
}

.shop-co__coupon-status.is-valid {
    color: var(--note-ok-ink);
    font-weight: 700;
}

.shop-co__coupon-status.is-invalid {
    color: var(--shop-error);
}

/* ───────────── 表單欄位 ───────────── */
.shop-co__label {
    display: block;
    margin-bottom: 6px;
    padding: 0;
    font-size: 0.9rem;
    font-weight: 700;
    color: var(--shop-paper-ink);
}

.shop-co__label-row {
    display: flex;
    align-items: baseline;
    justify-content: space-between;
    gap: 12px;
}

.shop-co__link {
    display: inline-flex;
    align-items: center;
    min-height: 44px;
    color: var(--c-88541f);
    font-size: 0.875rem;
}

.shop-co__optional {
    margin-left: 4px;
    font-weight: 400;
    color: var(--shop-paper-muted);
}

.shop-checkout :is(input[type="text"], input[type="tel"], input[type="email"], input[type="password"], select) {
    width: 100%;
    min-height: 48px;
    padding: 10px 14px;
    border: 1px solid var(--c-cbb48c);
    border-radius: var(--radius-8);
    background: var(--c-fffaf0);
    color: var(--shop-paper-ink);
    font-size: 1rem;
    line-height: 1.5;
}

.shop-checkout :is(input, select)[aria-invalid="true"] {
    border: 2px solid var(--shop-error);
    background: var(--c-error-bg);
}

.shop-co__error {
    margin-top: 6px;
    font-size: 0.875rem;
    line-height: 1.6;
    color: var(--shop-error);
}

.shop-co__summary {
    margin-bottom: 18px;
    padding: 12px 16px;
    border: 1px solid color-mix(in srgb, var(--shop-error) 45%, transparent);
    border-radius: var(--radius-8);
    background: var(--c-error-bg);
    color: var(--shop-error);
    font-size: 0.9rem;
}

.shop-co__summary:focus {
    outline: none;
}

.shop-co__field {
    min-width: 0;
}

.shop-co__grid {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 16px 18px;
}

.shop-co__field--wide {
    grid-column: 1 / -1;
}

#co-data-form {
    display: grid;
    gap: 18px;
}

#co-home-fields,
#co-donation-fields {
    display: grid;
    gap: 18px;
}

.shop-co__inline {
    display: flex;
    gap: 10px;
}

.shop-co__inline input {
    flex: 1 1 auto;
    min-width: 0;
}

.shop-co__inline .shop-secondary {
    flex: none;
    min-height: 48px;
}

.shop-co__store {
    margin-top: 8px;
    padding: 10px 14px;
    border-radius: var(--radius-8);
    background: var(--cream);
    font-size: 0.9rem;
    color: var(--shop-paper-muted);
}

.shop-co__store.is-verified {
    border: 1px solid var(--c-b1813b);
    background: var(--c-f6e4bb);
    color: var(--shop-paper-ink);
}

/* 取貨方式／付款方式（按鈕式選擇） */
.shop-co__ship,
.shop-co__methods,
.shop-co__birthday {
    min-width: 0;
    padding: 0;
    border: 0;
}

.shop-co__choices {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 12px;
}

.shop-co__choice {
    position: relative;
    display: grid;
    gap: 2px;
    min-height: 64px;
    margin: 0;
    padding: 14px 40px 14px 18px;
    border: 1px solid var(--shop-paper-line);
    border-radius: var(--radius-12);
    background: var(--c-fffaf0);
    color: var(--c-76502d);
    cursor: pointer;
}

.shop-co__choice strong {
    font-size: 1rem;
}

.shop-co__choice span {
    font-size: 0.875rem;
    line-height: 1.6;
}

.shop-co__choice input {
    position: absolute;
    width: 1px;
    height: 1px;
    margin: 0;
    padding: 0;
    border: 0;
    clip-path: inset(50%);
    overflow: hidden;
}

.shop-co__choice:has(input:checked) {
    border-color: var(--c-b1813b);
    background: var(--c-f6e4bb);
    box-shadow: inset 0 0 0 1px var(--c-b1813b);
}

.shop-co__choice:has(input:checked)::after {
    content: "✓";
    position: absolute;
    top: 12px;
    right: 16px;
    color: var(--c-815629);
}

.shop-co__choice:has(input:disabled) {
    opacity: 0.55;
    cursor: not-allowed;
}

.shop-co__choice:has(input:focus-visible) {
    outline: 3px solid var(--c-a66f2b);
    outline-offset: 3px;
}

.shop-co__choice:has(input[aria-invalid="true"]) {
    border-color: var(--shop-error);
}

.shop-co__method-note {
    margin-top: 8px;
    font-size: 0.875rem;
    color: var(--shop-paper-muted);
}

/* 農曆生日三格 */
.shop-co__birthday-parts {
    display: grid;
    grid-template-columns: repeat(3, minmax(0, 1fr));
    gap: 10px;
}

.shop-co__birthday-parts label {
    display: grid;
    gap: 4px;
    font-size: 0.875rem;
    color: var(--shop-paper-muted);
}

.shop-co__birthday .shop-co__muted {
    margin-top: 8px;
}

/* 核對頁：收件／護持資料 */
.shop-co__facts {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 12px 24px;
    padding: 16px 20px;
    border: 1px solid var(--shop-paper-line);
    border-radius: var(--radius-sm);
}

.shop-co__facts dt {
    font-size: 0.875rem;
    color: var(--shop-paper-muted);
}

.shop-co__facts dd {
    white-space: pre-line;
    overflow-wrap: anywhere;
}

/* 收單前必填後五碼（2026-10-25）：核對頁的匯款帳戶＋後五碼 */
.shop-co__transfer {
    display: grid;
    gap: 12px;
    margin-top: 16px;
}

.shop-co__transfer #co-transfer-account {
    font-size: 1.125rem;
    font-weight: 700;
    letter-spacing: 0.02em;
}

.shop-co__transfer #co-last5 {
    max-width: 12em;
    letter-spacing: 0.2em;
}

.shop-co__consent label {
    display: flex;
    align-items: flex-start;
    gap: 10px;
    font-size: 0.9rem;
    line-height: 1.7;
    cursor: pointer;
}

.shop-co__consent input {
    flex: none;
    width: 22px;
    height: 22px;
    margin-top: 3px;
    accent-color: var(--gold-deep);
}

.shop-co__consent small {
    display: block;
    margin-top: 4px;
    font-size: 0.875rem;
    color: var(--shop-paper-muted);
}

.shop-co__consent a,
.shop-checkout .privacy-notice a {
    color: var(--c-88541f);
}

.shop-checkout .privacy-notice {
    margin: 0;
}

/* ───────────── 底部操作列（sticky） ───────────── */
.shop-co__bar {
    position: sticky;
    bottom: 0;
    z-index: 3;
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 16px;
    padding: 14px 32px calc(14px + env(safe-area-inset-bottom, 0px));
    border-top: 1px solid var(--shop-paper-rule);
    background: var(--shop-paper);
    box-shadow: 0 -6px 18px color-mix(in srgb, var(--wood-mid) 6%, transparent);
}

.shop-co__bar-total {
    display: grid;
    line-height: 1.4;
}

.shop-co__bar-total span {
    font-size: 0.875rem;
    color: var(--shop-paper-muted);
}

.shop-co__bar-total strong {
    font-size: 1.25rem;
    color: var(--shop-paper-red);
    font-variant-numeric: tabular-nums;
}

.shop-co__bar-actions {
    display: flex;
    flex: 1 1 auto;
    align-items: center;
    justify-content: flex-end;
    gap: 18px;
}

.shop-co__back:disabled {
    opacity: 0.4;
    cursor: not-allowed;
}

.shop-co__next[aria-busy="true"] {
    cursor: progress;
}

/* ───────────── 手機：全螢幕結帳頁 ───────────── */
@media (max-width: 650px) {
    .shop-checkout {
        width: 100%;
        max-width: 100%;
        height: 100dvh;
        max-height: 100dvh;
        border: 0;
        border-radius: 0;
        box-shadow: none;
        scroll-padding-top: 140px;
        scroll-padding-bottom: 150px;
    }

    .shop-co__head {
        padding: 12px 16px 10px;
    }

    .shop-co__close {
        margin: -6px -8px -6px 0;
    }

    .shop-co__title {
        margin: 0 0 10px;
        font-size: 1.25rem;
    }

    .shop-co__steps li:not([aria-current="step"]) .shop-co__step-label {
        position: absolute;
        width: 1px;
        height: 1px;
        overflow: hidden;
        clip-path: inset(50%);
        white-space: nowrap;
    }

    .shop-co__steps {
        gap: 10px;
    }

    .shop-co__steps li {
        flex: 0 0 auto;
    }

    .shop-co__body {
        padding: 18px 16px 24px;
    }

    .shop-co-receipt {
        grid-template-columns: 1fr;
        padding: 16px;
    }

    .shop-co-receipt__totals {
        margin-top: 6px;
        padding: 6px 0 0;
        border-top: 1px solid var(--shop-paper-rule);
        border-left: 0;
    }

    .shop-co__grid,
    .shop-co__facts {
        grid-template-columns: 1fr;
    }

    .shop-co__choices {
        grid-template-columns: 1fr;
    }

    .shop-co__choice {
        padding: 12px 38px 12px 14px;
    }

    .shop-co__birthday-parts {
        grid-template-columns: 1fr;
    }

    .shop-co__bar {
        flex-direction: column;
        align-items: stretch;
        gap: 8px;
        padding: 10px 16px calc(10px + env(safe-area-inset-bottom, 0px));
    }

    .shop-co__bar-total {
        display: flex;
        align-items: baseline;
        justify-content: space-between;
        gap: 12px;
    }

    .shop-co__bar-actions {
        justify-content: space-between;
        gap: 12px;
    }

    .shop-co__next {
        flex: 1 1 auto;
        gap: 8px;
        padding: 12px 18px;
    }

    .shop-co__back {
        flex: none;
    }
}
