.ai-image-generator-wrapper {
    display: flex;
    flex-direction: column;
    gap: 20px;
    border: 1px solid #ddd;
    padding: 20px;
    border-radius: 8px;
    background-color: #fff;
    box-sizing: border-box;
}

.ai-image-generator-form {
    display: flex;
    flex-wrap: wrap;
    gap: 20px;
}

.ai-image-form-left {
    flex: 1 1 300px;
    min-width: 0;
}

.ai-image-form-right {
    flex: 1 1 300px;
    min-height: 200px;
    max-height: 80vh;
    overflow: hidden;
    border-left: 1px solid #eee;
    padding-left: 20px;
    display: flex;
    flex-direction: column;
    gap: 10px;
    align-items: center;
    justify-content: center;
    text-align: center;
}

.ai-field {
    margin-bottom: 10px;
}

.ai-prompt-counter {
    margin-top: 4px;
    font-size: 12px;
    color: #666;
}

.ai-prompt-counter.ai-prompt-counter-over {
    color: #dc3232;
    font-weight: 600;
}

.ai-captcha {
    margin: 15px 0;
    padding: 10px;
    border: 1px solid #e0e0e0;
    border-radius: 4px;
    background: #fafafa;
}

.ai-captcha-title {
    font-size: 13px;
    margin-bottom: 8px;
}

.ai-captcha-image-wrapper {
    position: relative;
    height: 60px;
    margin-bottom: 8px;
    background: 
        repeating-linear-gradient(
            45deg,
            #667eea,
            #667eea 10px,
            #764ba2 10px,
            #764ba2 20px
        );
    border-radius: 4px;
    overflow: hidden;
}

.ai-captcha-image {
    position: relative;
    width: 100%;
    height: 100%;
    background: 
        repeating-linear-gradient(
            45deg,
            #667eea,
            #667eea 10px,
            #764ba2 10px,
            #764ba2 20px
        );
}

/* Вырез в фоне - цель для пазла (более заметный) */
.ai-captcha-image::after {
    content: '';
    position: absolute;
    top: 8px;
    left: var(--captcha-target, 50%);
    width: 60px;
    height: 44px;
    background: rgba(255, 255, 255, 0.3);
    border: 3px dashed #fff;
    border-radius: 4px;
    transform: translateX(-50%);
    pointer-events: none;
    box-shadow: 0 0 0 2px rgba(255, 255, 255, 0.5) inset;
    animation: ai-captcha-pulse 2s ease-in-out infinite;
}

@keyframes ai-captcha-pulse {
    0%, 100% {
        opacity: 0.8;
        border-color: #fff;
    }
    50% {
        opacity: 1;
        border-color: #ffeb3b;
    }
}

.ai-captcha-piece {
    position: absolute;
    top: 8px;
    left: 0;
    width: 60px;
    height: 44px;
    background: 
        repeating-linear-gradient(
            45deg,
            #667eea,
            #667eea 10px,
            #764ba2 10px,
            #764ba2 20px
        );
    border-radius: 4px;
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.4);
    transition: left 0.1s linear;
    border: 2px solid rgba(255, 255, 255, 0.9);
    z-index: 2;
    cursor: grab;
    user-select: none;
    touch-action: none;
}

.ai-captcha-piece:active {
    cursor: grabbing;
}

.ai-captcha-piece.ai-captcha-piece-dragging {
    transition: none;
}

.ai-captcha-slider input[type="range"] {
    width: 100%;
}

.ai-captcha-message {
    margin-top: 4px;
    font-size: 12px;
    color: #666;
}

.ai-captcha.ai-captcha-success .ai-captcha-message {
    color: #2e7d32;
}

.ai-captcha.ai-captcha-error .ai-captcha-message {
    color: #c62828;
}

.ai-field-row {
    display: flex;
    gap: 10px;
}

.ai-field-row > div {
    flex: 1 1 0;
    min-width: 0;
    overflow: hidden;
}

.ai-field-row > div input[type="number"],
.ai-field-row > div input[type="text"].ai-size-input {
    width: 100%;
    min-width: 0;
    max-width: 100%;
    box-sizing: border-box;
}

.ai-size-field label {
    display: inline;
}

.ai-size-error {
    color: #c62828;
    font-size: 12px;
    font-weight: 600;
    margin-left: 0.25em;
}

.ai-field-row .ai-size-invalid {
    border-color: #c62828 !important;
    box-shadow: 0 0 0 1px #c62828;
}

.ai-submit-btn {
    margin-top: 10px;
    padding: 8px 16px;
    background-color: #2271b1;
    border: none;
    color: #fff;
    border-radius: 4px;
    cursor: pointer;
}

.ai-submit-btn:hover {
    background-color: #135e96;
}

.ai-submit-row {
    display: flex;
    align-items: center;
    flex-wrap: wrap;
    gap: 12px;
    margin-top: 10px;
}

.ai-cost-preview-label {
    font-size: 14px;
    color: #555;
}

.ai-total-row {
    display: flex;
    align-items: center;
    flex-wrap: wrap;
    gap: 12px;
    margin-top: 15px;
    padding-top: 12px;
    border-top: 1px solid #eee;
}

.ai-total-label {
    font-size: 16px;
    font-weight: 600;
    color: #333;
}

.ai-pay-download-btn {
    padding: 8px 16px;
    background-color: #2271b1;
    border: none;
    color: #fff;
    border-radius: 4px;
    cursor: pointer;
    font-size: 14px;
}

.ai-pay-download-btn:hover {
    background-color: #135e96;
}

/* Стили для неактивной кнопки генерации */
.ai-image-generator-form button[type="submit"]:disabled {
    opacity: 0.6;
    cursor: not-allowed;
    pointer-events: none;
}

.ai-result-placeholder {
    color: #666;
    font-size: 14px;
    line-height: 1.6;
    text-align: center;
    padding: 10px;
}

.ai-result-placeholder:empty {
    display: none;
}

.ai-loader {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 8px;
}

.ai-spinner {
    width: 40px;
    height: 40px;
    border: 4px solid #ddd;
    border-top-color: #2271b1;
    border-radius: 50%;
    animation: ai-spin 1s linear infinite;
}

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

/* Блок результата: когда пустой — не занимает место, лоадер и статус остаются по центру */
.ai-result-image {
    min-width: 0;
    width: 100%;
    display: flex;
    align-items: center;
    justify-content: center;
    overflow: hidden;
}
.ai-result-image:not(:has(img)) {
    flex: 0 0 auto;
}
.ai-result-image:has(img) {
    flex: 1 1 0;
    min-height: 0;
}

.ai-result-image img {
    max-width: 100%;
    max-height: 100%;
    width: auto;
    height: auto;
    object-fit: contain;
    object-position: center;
    display: block;
    border-radius: 4px;
}

.ai-status-text {
    margin-top: 4px;
    font-size: 14px;
    color: #666;
}

.ai-status-text.ai-status-error {
    color: #dc3232;
    font-weight: 600;
}

.ai-image-history {
    border-top: 1px solid #eee;
    padding-top: 10px;
}

.ai-image-history {
    display: flex;
    flex-wrap: wrap;
    gap: 10px;
}

.ai-thumb {
    width: 120px;
    cursor: pointer;
    text-align: center;
}

.ai-thumb-image-wrap {
    width: 100%;
    aspect-ratio: 4 / 3;
    overflow: hidden;
    border-radius: 4px;
    border: 1px solid #ddd;
    background: #f7f7f7;
}

.ai-thumb-image-wrap img {
    width: 100%;
    height: 100%;
    object-fit: cover;
    display: block;
}

.ai-thumb-label {
    margin-top: 4px;
    font-size: 12px;
}

.ai-log-wrapper {
    margin-top: 15px;
    padding-top: 10px;
    border-top: 1px dashed #ccc;
}

.ai-log-title {
    font-weight: 600;
    margin-bottom: 5px;
}

.ai-log-output {
    max-height: 250px;
    overflow: auto;
    background: #111;
    color: #e5e5e5;
    padding: 10px;
    border-radius: 4px;
    font-family: Menlo, Monaco, Consolas, "Courier New", monospace;
    font-size: 12px;
    white-space: pre-wrap;
}

.ai-gallery-overlay {
    position: fixed;
    inset: 0;
    z-index: 9999;
    display: flex;
    align-items: center;
    justify-content: center;
}

.ai-gallery-backdrop {
    position: absolute;
    inset: 0;
    background: rgba(0, 0, 0, 0.7);
}

.ai-gallery-content {
    position: relative;
    max-width: 90vw;
    max-height: 90vh;
    display: flex;
    align-items: center;
    justify-content: center;
}

.ai-gallery-image-wrap {
    max-width: 100%;
    max-height: 100%;
}

.ai-gallery-image-wrap img {
    max-width: 100%;
    max-height: 100%;
    border-radius: 4px;
    box-shadow: 0 0 20px rgba(0, 0, 0, 0.5);
}

.ai-gallery-close,
.ai-gallery-prev,
.ai-gallery-next {
    position: absolute;
    background: rgba(0, 0, 0, 0.6);
    color: #fff;
    border: none;
    padding: 6px 10px;
    cursor: pointer;
    font-size: 18px;
    border-radius: 3px;
}

.ai-gallery-close {
    top: 10px;
    right: 10px;
}

.ai-gallery-prev {
    left: -40px;
    top: 50%;
    transform: translateY(-50%);
}

.ai-gallery-next {
    right: -40px;
    top: 50%;
    transform: translateY(-50%);
}

/* Адаптивность */
@media (max-width: 768px) {
    .ai-image-generator-wrapper {
        padding: 15px;
    }

    .ai-image-generator-form {
        flex-direction: column;
    }

    .ai-image-form-right {
        border-left: none;
        border-top: 1px solid #eee;
        padding-left: 0;
        padding-top: 15px;
    }

    .ai-field-row {
        flex-direction: column;
    }

    .ai-field-row > div {
        flex: 0 0 auto;
        min-width: 100%;
    }

    .ai-thumb {
        width: 30%;
        min-width: 90px;
    }

    .ai-gallery-prev {
        left: 5px;
    }

    .ai-gallery-next {
        right: 5px;
    }
}

@media (max-width: 480px) {
    .ai-thumb {
        width: 45%;
    }
}

/* Кнопка очистки истории */
.ai-clear-history-wrapper {
    margin-top: 15px;
    padding-top: 15px;
    border-top: 1px solid #eee;
    text-align: center;
}

.ai-clear-history-btn {
    padding: 10px 20px;
    background-color: #dc3232;
    color: #fff;
    border: none;
    border-radius: 4px;
    cursor: pointer;
    font-size: 14px;
    transition: background-color 0.2s;
}

.ai-clear-history-btn:hover {
    background-color: #a00;
}

/* Попап подтверждения очистки */
.ai-clear-confirm-popup {
    position: fixed;
    inset: 0;
    z-index: 10000;
    display: flex;
    align-items: center;
    justify-content: center;
}

.ai-clear-confirm-backdrop {
    position: absolute;
    inset: 0;
    background: rgba(0, 0, 0, 0.7);
}

.ai-clear-confirm-content {
    position: relative;
    background: #fff;
    border-radius: 8px;
    padding: 25px;
    max-width: 400px;
    width: 90%;
    box-shadow: 0 4px 20px rgba(0, 0, 0, 0.3);
    z-index: 1;
}

.ai-clear-confirm-content h3 {
    margin: 0 0 15px 0;
    font-size: 20px;
    color: #333;
}

.ai-clear-confirm-content p {
    margin: 10px 0;
    font-size: 14px;
    color: #666;
    line-height: 1.5;
}

.ai-clear-warning {
    color: #dc3232 !important;
    font-weight: 600;
}

.ai-clear-confirm-buttons {
    margin-top: 20px;
    display: flex;
    gap: 10px;
    justify-content: flex-end;
}

.ai-clear-confirm-yes,
.ai-clear-confirm-no {
    padding: 10px 20px;
    border: none;
    border-radius: 4px;
    cursor: pointer;
    font-size: 14px;
    transition: opacity 0.2s;
}

.ai-clear-confirm-yes {
    background-color: #dc3232;
    color: #fff;
}

.ai-clear-confirm-yes:hover {
    background-color: #a00;
}

.ai-clear-confirm-no {
    background-color: #f0f0f0;
    color: #333;
}

.ai-clear-confirm-no:hover {
    background-color: #e0e0e0;
}

@media (max-width: 480px) {
    .ai-clear-confirm-content {
        padding: 20px;
    }

    .ai-clear-confirm-buttons {
        flex-direction: column;
    }

    .ai-clear-confirm-yes,
    .ai-clear-confirm-no {
        width: 100%;
    }
}

