/* layout container */
.main-container {
    margin-top: 80px;
}

/* flex row helpers */
.flex-row {
    display: flex;
    flex-wrap: wrap;
    margin-left: -12px;
    margin-right: -12px;
    box-sizing: border-box;
}

.justify-center {
    justify-content: center;
}

/* column base */
.col {
    padding-left: 12px;
    padding-right: 12px;
    box-sizing: border-box;
    flex: 0 0 100%;
    max-width: 100%;
}

/* responsive columns */
@media (min-width: 768px) {
    .col-md-8 {
        flex: 0 0 66.666666%;
        max-width: 66.666666%;
    }

    .col-md-4 {
        flex: 0 0 33.333333%;
        max-width: 33.333333%;
    }
}

/* spacing utilities */
.mt-3 {
    margin-top: 1rem;
}

.mb-3 {
    margin-bottom: 1rem;
}

.mt-12 {
    margin-top: 12px;
}

.mt-8 {
    margin-top: 8px;
}

/* card */
.card {
    background: #fff;
    border: 1px solid #e6e6e6;
    border-radius: 8px;
    overflow: hidden;
    box-shadow: 0 6px 20px rgba(21, 30, 38, 0.04);
}

.card-row {
    display: flex;
    flex-wrap: wrap;
    gap: 0;
}

.no-gutters {
    margin: 0;
}

.card-body {
    padding: 16px;
}

.card-header {
    padding: 12px 16px;
    border-bottom: 1px solid #f0f0f0;
    background: #fafafa;
}

.info-wrap {
    display: flex;
    flex-direction: column;
    width: 100%;
}

/* image area */
.img-wrap {
    width: 100%;
    height: 100%;
    grid-area: img;
    position: relative;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 12px;
    box-sizing: border-box;
}

.img-inner {
    position: relative;
    width: 100%;
    display: block;
}

.card-img-top {
    width: 100%;
    height: auto;
    max-width: 100%;
    object-fit: contain;
    display: block;
    border-radius: 6px;
    padding: 8px;
    box-sizing: border-box;
}

.badge {
    position: absolute;
    top: 12px;
    left: 12px;
    padding: 4px 8px;
    font-size: 12px;
    border-radius: 4px;
    color: #fff;
    z-index: 2;
}

.badge-success {
    background: #28a745;
}

.card-title {
    margin: 0 0 8px 0;
    font-size: 20px;
    line-height: 1.2;
    display: -webkit-box;
    -webkit-line-clamp: 3;
    -webkit-box-orient: vertical;
    overflow: hidden;
}

.muted {
    color: #6c757d;
    font-size: 14px;
    margin: 6px 0;
}

.price {
    margin: 0;
    color: #222;
    font-weight: 600;
}

/* form layout */
.form-block {
    width: 100%;
}

.form-row {
    display: flex;
    flex-wrap: wrap;
    gap: 12px;
}

.full {
    flex: 0 0 100%;
    max-width: 100%;
    min-width: 0;
}

.half {
    flex: 0 0 50%;
    max-width: 50%;
    min-width: 0;
}

.third {
    flex: 0 0 33.3333%;
    max-width: 33.3333%;
    min-width: 0;
}

/* labels & inputs */
.label {
    display: block;
    margin-bottom: 6px;
    font-size: 14px;
    color: #333;
}

.input {
    width: 100%;
    padding: 8px 10px;
    border-radius: 6px;
    border: 1px solid #e0e0e0;
    box-sizing: border-box;
    font-size: 14px;
}

.input-sm {
    height: 36px;
}

/* input group (quantity) */
.input-group {
    display: flex;
    align-items: center;
    border: 1px solid #ddd;
    border-radius: 6px;
    overflow: hidden;
    box-sizing: border-box;
}

.qty-input {
    flex: 1;
    border: 0;
    min-width: 0;
    outline: none;
    font-size: 14px;
    padding: 8px 6px;
    text-align: center;
    background: transparent;
}

.textarea {
    display: inline-block;
    width: 100%;
    padding: 8px 10px;
    border: 1px solid #e5e7eb;
    border-radius: 6px;
    outline: none;
    font-size: 14px;
}

.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    padding: 8px 12px;
    border-radius: 6px;
    border: 0;
    cursor: pointer;
    background: #f0f0f0;
    color: #333;
    font-weight: 600;
    min-width: 44px;
    box-sizing: border-box;
}

.btn-decrement, .btn-increment {
    width: 44px;
    height: 36px;
    padding: 0;
}

.btn-decrement:hover, .btn-increment:hover {
    background: #e6e6e6;
}

/* primary button */
.btn-primary {
    background: linear-gradient(180deg, #0b74ff, #0066d4);
    color: #fff;
    border-radius: 6px;
    padding: 10px 18px;
    border: 0;
}

.btn-primary:hover {
    filter: brightness(.95);
}

fieldset.pay-methods {
    border: none;
    padding: 0;
}

.pay-option {
    display: flex;
    align-items: center;
    padding: 8px 12px;
    margin-bottom: 6px;
    border: 2px solid #ccc;
    border-radius: 6px;
    cursor: pointer;
    transition: border-color 0.2s, background-color 0.2s;
    user-select: none;
}

/* 隐藏原生单选框 */
.pay-option input[type="radio"] {
    display: none;
}

/* 选中时改变整个 label 边框颜色和背景 */
.pay-option:has(input[type="radio"]:checked) {
    border-color: #FCD535;
    background-color: #fff8e1;
}

/* 禁用样式 */
.pay-option.disabled {
    opacity: 0.5;
    cursor: not-allowed;
}

.pay-option.disabled span {
    color: #999;
}

/* small helpers */
.mt-2 {
    margin-top: 8px;
}

.product-summary .summary-body,
.product-details .details-body {
    padding: 0; /* 已在外层 card-body 加 padding，如需可调整 */
}

/* 使用 CSS Grid 实现可重排布局 */
.product-grid {
    display: grid;
    grid-template-columns: 1fr 2fr; /* 左列图片约 33%，右列信息约 67%（桌面） */
    grid-template-rows: auto auto; /* summary 在上，details 在下（右侧） */
    grid-template-areas: "img summary" "img details";
    gap: 16px;
    width: calc(100% - 20px);
    align-items: start;
    box-sizing: border-box;
    margin: 10px;
}

.product-summary {
    grid-area: summary;
}

.product-details {
    grid-area: details;
}

/* summary / details basic */
.summary-body, .details-body {
    padding: 8px 12px;
    box-sizing: border-box;
}

/* responsive behavior: mobile (<768px) */
@media (max-width: 767.98px) {
    .main-container {
        margin-top: 60px;
    }

    .product-grid {
        grid-template-columns: 40% 60%;
        grid-template-areas: "img summary" "details details";
        gap: 12px;
        width: calc(100% - 24px);
        align-items: stretch;
        box-sizing: border-box;
        grid-auto-rows: auto;
    }

    .img-wrap {
        grid-area: img;
        position: relative;
        overflow: hidden;
        width: 100%;
        min-width: 0;
        box-sizing: border-box;
        padding: 0; /* 移除额外内边距，确保宽度可用 */
        border-radius: 6px;
        align-self: stretch; /* stretch 以占满行高度 */
        /* 优先使用现代浏览器的 aspect-ratio 来保持比例 */
        aspect-ratio: 1 / 1; /* 可改为 1/1 或 3/4 */
        min-height: 120px; /* 最小高度保护 */
        background: #f5f5f5;
    }

    /* 图片本身：填满容器并裁剪（cover） */
    .img-wrap .card-img-top {
        width: 100%;
        height: 100%;
        object-fit: cover; /* 填满容器 */
        display: block;
        max-width: none; /* 防止被 max-width:100% 误缩放 */
    }

    /* badge 浮在图片上，但不会改变布局高度 */
    .img-wrap .badge {
        position: absolute;
        top: 8px;
        left: 8px;
        z-index: 6;
        padding: 4px 6px;
        font-size: 12px;
    }

    /* ---------- summary：占满右侧全部宽度并撑满高度 ---------- */
    .product-summary {
        grid-area: summary;
        align-self: stretch; /* 拉伸到单元高度 */
        justify-self: stretch; /* 横向拉伸到单元宽度 */
        box-sizing: border-box;
        flex-direction: column;
        padding: 0 10px 0 0;
        margin: 0; /* 确保没有额外外边距导致超出 */
        min-width: 0; /* 关键：允许其在窄列中收缩换行，而不撑开容器 */
        max-width: 100%; /* 额外保险：不要超过所在单元 */
        background: transparent;
    }

    /* 若 summary 内部标题/文本存在长单词，允许换行避免撑开 */
    .product-summary .card-title,
    .product-summary .muted,
    .product-summary .price {
        word-break: break-word;
        overflow-wrap: anywhere;
    }

    /* 缩小标题字号以适配右侧宽度（可调） */
    .product-summary .card-title {
        font-size: 16px;
        line-height: 1.2;
        margin: 0 0 6px;
        display: -webkit-box;
        -webkit-line-clamp: 3;
        -webkit-box-orient: vertical;
        overflow: hidden;
        text-overflow: ellipsis;
    }

    /* ---------- details：放在下一行，占满宽度 ---------- */
    .product-details {
        grid-area: details;
        box-sizing: border-box;
        padding: 0 10px 0 0;
        min-width: 0;
        max-width: 100%;
    }

    /* 表单内部列在小屏占满一行 */
    .product-details .half,
    .product-details .third {
        flex: 0 0 100%;
        max-width: 100%;
        min-width: 0;
    }

    /* 细节：确保 quantity 不溢出 */
    .input-group {
        max-width: 180px;
    }

    .qty-input {
        min-width: 40px;
    }
}

/* 保证桌面上右侧 summary 和 details 是纵向堆叠（不并列） */
@media (min-width: 768px) {
    .product-summary, .product-details {
        /* 右侧宽度由 grid 控制（summary 在上，details 在下） */
    }
}