.pgae-component {
    --pgae-blue: #005bff;
    --pgae-text: #172b4d;
    --pgae-muted: #65758b;
    --pgae-border: #dde6f1;
    --pgae-soft: #f4f8ff;
    width: 100%;
    max-width: 100%;
    color: var(--pgae-text);
}

.pgae-component,
.pgae-component * {
    box-sizing: border-box;
}

.pgae-heading {
    margin: 0 0 8px;
    color: var(--pgae-text);
    font-size: 14px;
    font-weight: 700;
    line-height: 1.3;
}

.pgae-grid {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 8px;
}

.pgae-addon-card {
    position: relative;
    min-width: 0;
    overflow: hidden;
    border: 1px solid var(--pgae-border);
    border-radius: 9px;
    background: #fff;
    box-shadow: 0 2px 7px rgba(23, 43, 77, 0.035);
    transition: border-color 0.18s ease, background-color 0.18s ease, box-shadow 0.18s ease;
}

.pgae-addon-card:hover {
    border-color: #c9d8ea;
    box-shadow: 0 5px 14px rgba(23, 43, 77, 0.07);
}

.pgae-addon-card.is-selected {
    border-color: #a9c6fb;
    background: var(--pgae-soft);
}

.pgae-card-main {
    display: grid;
    grid-template-columns: minmax(0, 1fr) auto auto;
    align-items: center;
    gap: 7px;
    min-height: 44px;
    padding: 7px 9px;
}

.pgae-addon-check {
    position: absolute !important;
    width: 1px !important;
    height: 1px !important;
    margin: -1px !important;
    padding: 0 !important;
    overflow: hidden !important;
    clip: rect(0 0 0 0) !important;
    white-space: nowrap !important;
    border: 0 !important;
}

.pgae-select-area {
    display: flex;
    align-items: center;
    min-width: 0;
    gap: 9px;
    margin: 0;
    color: var(--pgae-text) !important;
    cursor: pointer;
}

.pgae-checkmark {
    position: relative;
    flex: 0 0 18px;
    width: 18px;
    height: 18px;
    border: 1px solid #c8d4e3;
    border-radius: 5px;
    background: #f7f9fc;
    transition: border-color 0.18s ease, background-color 0.18s ease;
}

.pgae-checkmark::after {
    content: "✓";
    position: absolute;
    left: 50%;
    top: 50%;
    transform: translate(-50%, -54%);
    color: #fff;
    font-size: 11px;
    font-weight: 800;
    opacity: 0;
}

.pgae-addon-check:focus-visible + .pgae-select-area .pgae-checkmark {
    outline: 2px solid rgba(0, 91, 255, 0.3);
    outline-offset: 2px;
}

.pgae-addon-check:checked + .pgae-select-area .pgae-checkmark {
    border-color: var(--pgae-blue);
    background: var(--pgae-blue);
}

.pgae-addon-check:checked + .pgae-select-area .pgae-checkmark::after {
    opacity: 1;
}

.pgae-addon-name {
    min-width: 0;
    overflow-wrap: anywhere;
    color: var(--pgae-text) !important;
    font-size: 12.5px;
    font-weight: 600;
    line-height: 1.25;
}

.pgae-photo-button {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    flex: 0 0 30px;
    width: 30px;
    height: 30px;
    padding: 0;
    border: 1px solid #d7e3f2;
    border-radius: 7px;
    background: #fff;
    color: var(--pgae-blue);
    cursor: pointer;
    transition: background-color 0.18s ease, border-color 0.18s ease, box-shadow 0.18s ease;
}

.pgae-photo-button:hover,
.pgae-photo-button:focus-visible {
    border-color: #a9c6fb;
    background: #eaf2ff;
    box-shadow: 0 4px 10px rgba(0, 91, 255, 0.1);
    outline: none;
}

.pgae-photo-button svg {
    width: 16px;
    height: 16px;
}

.pgae-addon-price {
    display: inline-flex;
    align-items: center;
    min-height: 26px;
    padding: 4px 7px;
    border-radius: 6px;
    background: #f2f5f9;
    color: #52627a !important;
    font-size: 11.5px;
    font-weight: 700;
    line-height: 1.15;
    white-space: nowrap;
}

.pgae-addon-card.is-selected .pgae-addon-price {
    background: #eaf2ff;
    color: #35506f !important;
}

/* Обе карточки в двухколоночной сетке имеют абсолютно одинаковую внутреннюю геометрию.
 * Ширины панели количества не зависят ни от левой/правой колонки, ни от длины числа. */
.pgae-grid > .pgae-addon-card {
    align-self: start;
}

.pgae-quantity-panel {
    display: grid;
    grid-template-columns: minmax(128px, 1fr) 92px;
    grid-template-areas:
        "quantity-label line-total"
        "quantity-control line-total";
    align-items: center;
    column-gap: 10px;
    row-gap: 5px;
    min-width: 0;
    padding: 9px 10px 10px;
    border-top: 1px solid #dce8f8;
    background: rgba(255, 255, 255, 0.72);
}

.pgae-quantity-panel[hidden] {
    display: none !important;
}

.pgae-quantity-label,
.pgae-line-total-wrap span {
    color: var(--pgae-muted);
    font-size: 11.5px;
    font-weight: 600;
}

.pgae-quantity-label {
    grid-area: quantity-label;
    min-width: 0;
}

.pgae-quantity-control {
    grid-area: quantity-control;
    display: grid;
    grid-template-columns: 30px 60px 30px;
    justify-content: start;
    align-items: center;
    gap: 4px;
    width: 128px;
    min-width: 128px;
    max-width: 128px;
}

.pgae-quantity-button {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 30px;
    height: 30px;
    padding: 0;
    border: 1px solid #cfdcec;
    border-radius: 6px;
    background: #fff;
    color: var(--pgae-blue);
    font-size: 18px;
    font-weight: 700;
    line-height: 1;
    cursor: pointer;
}

.pgae-quantity-button:hover,
.pgae-quantity-button:focus-visible {
    border-color: #9ebeff;
    background: #edf4ff;
    outline: none;
}

.pgae-quantity-input {
    width: 60px !important;
    min-width: 60px !important;
    max-width: 60px !important;
    height: 30px !important;
    margin: 0 !important;
    padding: 3px 5px !important;
    border: 1px solid #cfdcec !important;
    border-radius: 6px !important;
    background: #fff !important;
    color: var(--pgae-text) !important;
    font-size: 12px !important;
    font-weight: 700;
    font-variant-numeric: tabular-nums;
    text-align: center;
    box-shadow: none !important;
    appearance: textfield !important;
    -moz-appearance: textfield !important;
}

.pgae-quantity-input::-webkit-outer-spin-button,
.pgae-quantity-input::-webkit-inner-spin-button {
    margin: 0;
    -webkit-appearance: none;
    appearance: none;
}

.pgae-line-total-wrap {
    grid-area: line-total;
    display: flex;
    flex-direction: column;
    align-items: flex-end;
    justify-content: center;
    justify-self: end;
    gap: 2px;
    width: 92px;
    min-width: 92px;
    max-width: 92px;
    text-align: right;
}

.pgae-line-total {
    color: var(--pgae-text);
    font-size: 12px;
    white-space: nowrap;
}

.pgae-line-total-wrap > span,
.pgae-line-total-wrap > .pgae-line-total {
    display: block;
    width: 100%;
    text-align: right;
}


.pgae-component-status {
    min-height: 0;
    margin-top: 5px;
    color: var(--pgae-muted);
    font-size: 11px;
}

.pgae-component-status:empty {
    display: none;
}

.pgae-component-status.is-error {
    color: #b42318;
}

.pgae-selection-json,
.pgae-selection-text {
    display: none !important;
}


/* Компактный просмотр фото на ПК. Мобильный modal ниже остаётся без изменений. */
.pgae-photo-popover {
    display: none;
}

@media (min-width: 641px) {
    .pgae-photo-popover {
        --pgae-photo-arrow-left: 50%;
        position: fixed;
        z-index: 1000000;
        width: 280px;
        max-width: calc(100vw - 24px);
        padding: 10px;
        border: 1px solid #dce5f0;
        border-radius: 11px;
        background: #fff;
        box-shadow: 0 12px 32px rgba(23, 43, 77, 0.18);
        opacity: 0;
        transform: translateY(4px);
        pointer-events: none;
        transition: opacity 0.16s ease, transform 0.16s ease;
    }

    .pgae-photo-popover.is-open {
        display: block;
        opacity: 1;
        transform: translateY(0);
        pointer-events: auto;
    }

    .pgae-photo-popover-arrow {
        position: absolute;
        left: var(--pgae-photo-arrow-left);
        top: -6px;
        width: 11px;
        height: 11px;
        border-left: 1px solid #dce5f0;
        border-top: 1px solid #dce5f0;
        background: #fff;
        transform: translateX(-50%) rotate(45deg);
    }

    .pgae-photo-popover[data-placement="top"] .pgae-photo-popover-arrow {
        top: auto;
        bottom: -6px;
        border: 0;
        border-right: 1px solid #dce5f0;
        border-bottom: 1px solid #dce5f0;
    }

    .pgae-photo-popover-title {
        margin: 0 0 8px;
        padding: 0 2px;
        color: #172b4d;
        font-size: 13px;
        font-weight: 700;
        line-height: 1.3;
    }

    .pgae-photo-popover-image-wrap {
        display: flex;
        align-items: center;
        justify-content: center;
        width: 100%;
        min-height: 120px;
        max-height: 230px;
        overflow: hidden;
        border-radius: 8px;
        background: #f5f7fa;
    }

    .pgae-photo-popover-image {
        display: block;
        width: 100%;
        max-width: 100%;
        max-height: 230px;
        object-fit: contain;
    }
}

body.pgae-modal-open {
    overflow: hidden;
}

.pgae-modal {
    position: fixed;
    inset: 0;
    z-index: 999999;
    display: none;
    align-items: center;
    justify-content: center;
    padding: 24px;
}

.pgae-modal.is-open {
    display: flex;
}

.pgae-modal-backdrop {
    position: absolute;
    inset: 0;
    background: rgba(10, 22, 40, 0.72);
    backdrop-filter: blur(2px);
}

.pgae-modal-dialog {
    position: relative;
    z-index: 1;
    width: min(880px, 100%);
    max-height: calc(100vh - 48px);
    overflow: auto;
    padding: 18px;
    border: 1px solid rgba(255, 255, 255, 0.72);
    border-radius: 16px;
    background: #fff;
    box-shadow: 0 26px 80px rgba(0, 0, 0, 0.28);
}

.pgae-modal-close {
    position: absolute;
    top: 12px;
    right: 12px;
    z-index: 2;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 38px;
    height: 38px;
    padding: 0;
    border: 1px solid #dce5f0;
    border-radius: 10px;
    background: #fff;
    color: #172b4d;
    font-size: 27px;
    font-weight: 400;
    line-height: 1;
    cursor: pointer;
}

.pgae-modal-close:hover,
.pgae-modal-close:focus-visible {
    border-color: #a9c6fb;
    background: #edf4ff;
    color: var(--pgae-blue, #005bff);
    outline: none;
}

.pgae-modal-title {
    margin: 2px 48px 14px 2px;
    color: #172b4d;
    font-size: 18px;
    line-height: 1.3;
}

.pgae-modal-image-wrap {
    display: flex;
    align-items: center;
    justify-content: center;
    min-height: 280px;
    overflow: hidden;
    border-radius: 12px;
    background: #f5f7fa;
}

.pgae-modal-image {
    display: block;
    width: 100%;
    max-width: 100%;
    max-height: calc(100vh - 190px);
    object-fit: contain;
}


@media (max-width: 640px) {
    .pgae-grid {
        grid-template-columns: minmax(0, 1fr);
    }

    .pgae-card-main {
        grid-template-columns: minmax(0, 1fr) auto auto;
    }

   .pgae-quantity-panel {
        grid-template-columns: minmax(0, 1fr) auto;
        grid-template-areas:
            "quantity-label quantity-label"
            "quantity-control line-total";
        column-gap: 10px;
        row-gap: 6px;
    }

    .pgae-quantity-control {
        grid-template-columns: 32px minmax(54px, 76px) 32px;
        gap: 5px;
        width: auto;
        min-width: 0;
        max-width: none;
    }

    .pgae-quantity-button {
        width: 32px;
    }

    .pgae-quantity-input {
        width: 100% !important;
        min-width: 54px !important;
        max-width: 76px !important;
    }

    .pgae-line-total-wrap {
        width: auto;
        min-width: 0;
        max-width: none;
        align-items: flex-end;
    }

    .pgae-modal {
        padding: 10px;
    }

    .pgae-modal-dialog {
        max-height: calc(100vh - 20px);
        padding: 14px;
        border-radius: 13px;
    }

    .pgae-modal-title {
        margin-right: 44px;
        font-size: 16px;
    }

    .pgae-modal-image-wrap {
        min-height: 220px;
    }

    .pgae-modal-image {
        max-height: calc(100vh - 150px);
    }
}

@media (max-width: 390px) {
    .pgae-card-main {
        grid-template-columns: minmax(0, 1fr) auto;
    }

    .pgae-photo-button {
        grid-column: 2;
        grid-row: 1;
    }

    .pgae-addon-price {
        grid-column: 1 / -1;
        justify-self: end;
    }
}
