/*
 * TPO Frontend Styles
 */

/* .tpo-product-options {
    margin: 20px 0;
    padding: 20px;
    border: 1px solid #e5e5e5;
    border-radius: 4px;
} */

/* 去除外边框样式 */
.tpo-product-options.tpo-no-border {
    border: none !important;
    padding: 0 !important;
    margin: 0 !important;
    background: transparent !important;
    box-shadow: none !important;
}

.tpo-product-options h3 {
    margin: 0 0 15px;
    font-size: 18px;
    color: #333;
}

.tpo-option-set {
    margin-bottom: 20px;
}

.tpo-option-set-title {
    font-size: 16px;
    margin: 0 0 10px;
    color: #555;
}

.tpo-option-set-description {
    font-size: 14px;
    color: #666;
    margin: 0 0 15px;
}

.tpo-fields {
    display: flex;
    flex-wrap: wrap;
}

.tpo-field {
    margin-bottom: 15px;
    position: relative;
}

.tpo-field label {
    display: block;
    font-weight: 500;
    color: #333;
}

/* Label 包装器 - 用于包含 label 文本和 tooltip */
.tpo-field label.tpo-field-label-wrapper,
.tpo-field legend.tpo-field-label-wrapper {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: 4px;
}

.tpo-field label.tpo-field-label-wrapper .tpo-label-text,
.tpo-field legend.tpo-field-label-wrapper .tpo-label-text {
    display: inline;
}

.tpo-field label.tpo-field-label-wrapper .tpo-help-tooltip,
.tpo-field legend.tpo-field-label-wrapper .tpo-help-tooltip {
    display: inline-flex;
    vertical-align: middle;
    margin-left: 2px;
}

.tpo-field .required {
    color: #e2401c;
    margin-left: 3px;
}

.tpo-field-price {
    font-size: 12px;
    color: #2da764;
    font-weight: 500;
    margin-left: 6px;
}

.tpo-field-description {
    font-size: 13px;
    color: #666;
    margin: 0;
}

.tpo-field input[type="text"],
.tpo-field input[type="number"],
.tpo-field textarea,
.tpo-field select {
    padding: 10px;
    border: 1px solid #ddd;
    border-radius: 3px;
    font-size: 14px;
    width: 100%;
    box-sizing: border-box;
}

.tpo-field input[type="text"]:focus,
.tpo-field input[type="number"]:focus,
.tpo-field textarea:focus,
.tpo-field select:focus {
    outline: none;
    border-color: #96588a;
    box-shadow: 0 0 0 1px #96588a;
}

.tpo-field textarea {
    resize: vertical;
    min-height: 80px;
}



.tpo-radio-label input[type="radio"],
.tpo-checkbox-label input[type="checkbox"] {
    margin: 0;
}

.tpo-radio-label .price-adjustment,
.tpo-checkbox-label .price-adjustment {
    color: #96588a;
    font-size: 12px;
}

.tpo-switch-wrapper {
    display: flex;
    align-items: center;
    gap: 10px;
}

.tpo-switch {
    position: relative;
    display: inline-block;
    width: 50px;
    height: 24px;
}

.tpo-switch input {
    opacity: 0;
    width: 0;
    height: 0;
}

.tpo-switch-slider {
    position: absolute;
    cursor: pointer;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background-color: #ccc;
    transition: 0.4s;
    border-radius: 24px;
}

.tpo-switch-slider:before {
    position: absolute;
    content: "";
    height: 18px;
    width: 18px;
    left: 3px;
    bottom: 3px;
    background-color: white;
    transition: 0.4s;
    border-radius: 50%;
}

.tpo-switch input:checked + .tpo-switch-slider {
    background-color: #96588a;
}

.tpo-switch input:checked + .tpo-switch-slider:before {
    transform: translateX(26px);
}

.tpo-switch-label {
    font-size: 14px;
    color: #333;
}

.tpo-field-error {
    color: #e2401c;
    font-size: 12px;
    margin-top: 3px;
    display: block;
}

.tpo-field.has-error input,
.tpo-field.has-error textarea,
.tpo-field.has-error select {
    border-color: #e2401c;
}

/* Fieldset 和 Legend 样式 - 减小单选/复选区域的间距 */
.tpo-fieldset {
    border: 1px solid #e5e5e5;
    border-radius: 4px;
    padding: 12px 15px;
    margin: 0;
    min-width: 0;
    background: #fff;
}

.tpo-fieldset legend {
    font-weight: 500;
    color: #333;
    margin-bottom: 8px;
    padding: 0;
    display: block;
    width: 100%;
}

.tpo-radio-group,
.tpo-checkbox-group {
    display: flex;
    flex-direction: column;
    gap: 4px;
}

.tpo-radio-group.tpo-layout-horizontal,
.tpo-checkbox-group.tpo-layout-horizontal {
    flex-direction: row;
    flex-wrap: wrap;
    gap: 10px;
}

.tpo-radio-label,
.tpo-checkbox-label {
    display: flex;
    align-items: center;
    gap: 6px;
    cursor: pointer;
}

@media (max-width: 768px) {
    .tpo-product-options {
        padding: 15px;
    }

    .tpo-radio-group.tpo-layout-horizontal,
    .tpo-checkbox-group.tpo-layout-horizontal {
        flex-direction: column;
    }
}

/* Tooltip 帮助提示样式 */
.tpo-help-tooltip {
    position: relative;
    display: inline-flex;
    align-items: center;
    margin-left: 6px;
    cursor: help;
    color: #007cba;
    vertical-align: middle;
}

.tpo-help-tooltip svg {
    width: 16px;
    height: 16px;
}

/* 自定义 Tooltip 样式 - 由 JavaScript 控制 */
.tpo-custom-tooltip {
    position: fixed;
    padding: 8px 12px;
    background: #333;
    color: #fff;
    font-size: 13px;
    font-weight: normal;
    line-height: 1.4;
    border-radius: 4px;
    z-index: 9999;
    display: none;
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.15);
    pointer-events: auto;
    max-width: 250px;
    white-space: normal;
    word-wrap: break-word;
}

.tpo-custom-tooltip.show {
    display: block;
}

/* Tooltip 箭头 - 上方显示时 */
.tpo-custom-tooltip::after {
    content: '';
    position: absolute;
    top: 100%;
    left: 50%;
    transform: translateX(-50%);
    border: 6px solid transparent;
    border-top-color: #333;
}

/* Tooltip 箭头 - 下方显示时 */
.tpo-custom-tooltip.tooltip-below::after {
    top: auto;
    bottom: 100%;
    border-top-color: transparent;
    border-bottom-color: #333;
}

/* 移动端适配 tooltip */
@media (max-width: 768px) {
    .tpo-custom-tooltip {
        max-width: 200px;
        text-align: center;
    }
}

/* ==================== 从属规则过渡动画 ==================== */

/* 字段基础过渡效果 */
.tpo-field {
    transition: opacity 0.3s ease, transform 0.3s ease, max-height 0.3s ease, margin 0.3s ease, padding 0.3s ease;
    overflow: hidden;
}

/* 下拉类组件字段需要 overflow: visible，否则绝对定位的下拉菜单会被裁剪 */
.tpo-field-select,
.tpo-field-image_select {
    overflow: visible;
    /* transition 中的 transform 会创建新的 stacking context，导致下拉菜单被兄弟元素遮挡。
       对下拉类字段去掉 transform，改用 z-index 控制层叠顺序。 */
    transition: opacity 0.3s ease, max-height 0.3s ease, margin 0.3s ease, padding 0.3s ease;
    z-index: 1;
}

/* 下拉菜单打开时，将该字段提升到最顶层，覆盖所有兄弟字段 */
.tpo-field-select:has(.tpo-custom-dropdown.open),
.tpo-field-image_select:has(.tpo-image-select-custom-dropdown.open),
.tpo-field-select.tpo-dropdown-open,
.tpo-field-image_select.tpo-dropdown-open {
    z-index: 100;
}

/* 隐藏状态 */
.tpo-field-hidden {
    opacity: 0;
    transform: translateY(-10px);
    max-height: 0;
    margin-top: 0 !important;
    margin-bottom: 0 !important;
    padding-top: 0 !important;
    padding-bottom: 0 !important;
    pointer-events: none;
}

/* 显示状态 */
.tpo-field-visible {
    opacity: 1;
    transform: translateY(0);
    max-height: 500px;
}

/* 从属字段标记样式（可选，用于视觉提示） */
.tpo-field[data-dependent] {
    position: relative;
}

/* 确保隐藏的字段不会影响布局 */
.tpo-fields {
    align-items: flex-start;
}

/* 隐藏字段的边框和背景也渐变消失 */
.tpo-field-hidden .tpo-fieldset,
.tpo-field-hidden input,
.tpo-field-hidden textarea,
.tpo-field-hidden select {
    border-color: transparent;
    background: transparent;
}

/* 平滑显示动画 */
@keyframes tpo-field-show {
    from {
        opacity: 0;
        transform: translateY(-10px);
        max-height: 0;
    }
    to {
        opacity: 1;
        transform: translateY(0);
        max-height: 500px;
    }
}

/* 平滑隐藏动画 */
@keyframes tpo-field-hide {
    from {
        opacity: 1;
        transform: translateY(0);
        max-height: 500px;
    }
    to {
        opacity: 0;
        transform: translateY(-10px);
        max-height: 0;
    }
}

/* 应用动画类 */
.tpo-field-animating-show {
    animation: tpo-field-show 0.3s ease forwards;
}

.tpo-field-animating-hide {
    animation: tpo-field-hide 0.3s ease forwards;
}
