/**
 * Sell My Images - Modal Styles
 * 
 * Responsive modal styling that integrates with WordPress themes
 * 
 * @package SellMyImages
 * @since 1.0.0
 */

/* ==========================================================================
   Get Hi-Res Button Styles - Pinterest Style Hover Buttons
   ========================================================================== */

/* Ensure figure containers have relative positioning */
.wp-block-image,
figure.wp-block-image {
    position: relative !important;
}

.smi-get-button {
    background: rgba(0, 0, 0, 0.85);
    color: white;
    border: none;
    padding: 10px 14px;
    border-radius: 20px;
    cursor: pointer;
    font-size: 13px;
    font-weight: 600;
    text-decoration: none;
    display: inline-flex;
    align-items: center;
    gap: 6px;
    transition: all 0.3s ease;
    z-index: 100;
    
    /* Pinterest-style positioning */
    position: absolute;
    bottom: 12px;
    right: 12px;
    
    /* Hidden by default, show on hover */
    opacity: 0;
    transform: translateY(8px);
    pointer-events: none;
    
    /* Ensure it stays above other elements */
    box-shadow: 0 2px 12px rgba(0, 0, 0, 0.3);
}

/* Show button on image hover */
.wp-block-image:hover .smi-get-button,
figure.wp-block-image:hover .smi-get-button {
    opacity: 1;
    transform: translateY(0);
    pointer-events: auto;
}

/* Button hover state */
.smi-get-button:hover {
    background: rgba(0, 0, 0, 0.95);
    transform: translateY(-2px) scale(1.05);
    box-shadow: 0 4px 16px rgba(0, 0, 0, 0.4);
}

.smi-get-button:active {
    transform: translateY(0) scale(1.02);
}

.smi-get-button:focus {
    outline: 2px solid rgba(255, 255, 255, 0.8);
    outline-offset: 2px;
}

/* Button Icons */
.smi-button-icon {
    font-size: 12px;
    opacity: 0.9;
}

/* Mobile and touch device support */
@media (max-width: 768px) {
    /* Always show buttons on mobile (no hover) */
    .smi-get-button {
        opacity: 1;
        transform: translateY(0);
        pointer-events: auto;
        bottom: 8px;
        right: 8px;
        padding: 8px 12px;
        font-size: 12px;
    }
}

/* High DPI displays */
@media (-webkit-min-device-pixel-ratio: 2), (min-resolution: 192dpi) {
    .smi-get-button {
        box-shadow: 0 1px 6px rgba(0, 0, 0, 0.3);
    }
}

/* Button Position Variants */
.smi-overlay-button {
    position: absolute;
    top: 10px;
    right: 10px;
    z-index: 10;
    background: rgba(0, 0, 0, 0.8);
    backdrop-filter: blur(4px);
    color: white;
}

.smi-overlay-button:hover {
    background: rgba(0, 0, 0, 0.9);
}

.smi-after-button,
.smi-before-button {
    margin: 8px 0;
    display: inline-block;
}

/* Image Container for Overlay Positioning */
.smi-image-container {
    position: relative !important;
    display: inline-block !important;
}

.smi-image-container img {
    display: block;
    max-width: 100%;
    height: auto;
}

/* ==========================================================================
   Modal Base Styles
   ========================================================================== */

.smi-modal {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    z-index: 2147483647; /* Maximum z-index value to ensure it covers all ads */
    font-family: inherit;
    line-height: inherit;
}

.smi-modal-overlay {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0, 0, 0, 0.7);
    backdrop-filter: blur(2px);
}

.smi-modal-content {
    position: relative;
    width: 90%;
    max-width: 600px;
    max-height: 90vh;
    margin: 5vh auto;
    background: var(--wp--preset--color--background, white);
    border-radius: 8px;
    box-shadow: 0 10px 40px rgba(0, 0, 0, 0.3);
    overflow: hidden;
    display: flex;
    flex-direction: column;
}

/* ==========================================================================
   Modal Header
   ========================================================================== */

.smi-modal-header {
    padding: 20px 24px;
    border-bottom: 1px solid currentColor;
    border-bottom-color: rgba(0, 0, 0, 0.1);
    display: flex;
    justify-content: space-between;
    align-items: center;
    background: var(--wp--preset--color--tertiary, rgba(0, 0, 0, 0.03));
}

.smi-modal-title {
    margin: 0;
    font-size: 18px;
    font-weight: 600;
    color: #1d2327;
}

.smi-modal-close {
    background: none;
    border: none;
    font-size: 24px;
    cursor: pointer;
    color: #666;
    width: 32px;
    height: 32px;
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: 4px;
    transition: all 0.2s ease;
}

.smi-modal-close:hover {
    background: rgba(0, 0, 0, 0.1);
    color: #333;
}

/* ==========================================================================
   Modal Body
   ========================================================================== */

.smi-modal-body {
    padding: 24px;
    flex: 1;
    overflow-y: auto;
    max-height: calc(90vh - 140px); /* Account for header and footer */
}

/* Loading State */
.smi-loading {
    text-align: center;
    padding: 40px 20px;
}

.smi-spinner {
    width: 40px;
    height: 40px;
    border: 4px solid rgba(0, 0, 0, 0.1);
    border-top: 4px solid currentColor;
    border-radius: 50%;
    animation: smi-spin 1s linear infinite;
    margin: 0 auto 20px;
}

@keyframes smi-spin {
    0% { transform: rotate(0deg); }
    100% { transform: rotate(360deg); }
}

.smi-loading p {
    color: #666;
    margin: 0;
}

/* Main Content Layout */
.smi-modal-main {
    display: flex;
    flex-direction: column;
    gap: 24px;
}

/* ==========================================================================
   Image Preview
   ========================================================================== */

.smi-image-preview {
    text-align: center;
}

.smi-preview-image {
    max-width: 100%;
    max-height: 200px;
    border-radius: 6px;
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.1);
    margin-bottom: 12px;
}

.smi-image-info {
    font-size: 13px;
    color: #666;
}

.smi-image-info p {
    margin: 4px 0;
}

/* ==========================================================================
   Process Overview
   ========================================================================== */

.smi-process-overview {
    margin-bottom: 24px;
    padding: 16px;
    background: rgba(0, 123, 255, 0.05);
    border: 1px solid rgba(0, 123, 255, 0.15);
    border-radius: 6px;
}

.smi-process-intro h4 {
    margin: 0 0 8px 0;
    font-size: 16px;
    font-weight: 600;
    color: #0f4d73;
}

.smi-process-intro p {
    margin: 0;
    font-size: 14px;
    color: #1d2327;
    line-height: 1.5;
}

/* ==========================================================================
   Upscale Options
   ========================================================================== */

.smi-upscale-options h4 {
    margin: 0 0 16px 0;
    font-size: 16px;
    font-weight: 600;
    color: #1d2327;
}

.smi-resolution-options {
    display: flex;
    flex-direction: column;
    gap: 12px;
}

.smi-option {
    display: flex;
    align-items: center;
    padding: 16px;
    border: 2px solid currentColor;
    border-color: rgba(0, 0, 0, 0.15);
    border-radius: 6px;
    cursor: pointer;
    transition: all 0.2s ease;
    background: transparent;
}

.smi-option:hover {
    border-color: rgba(0, 0, 0, 0.3);
    background: rgba(0, 0, 0, 0.02);
}

.smi-option input[type="radio"] {
    margin: 0 12px 0 0;
    transform: scale(1.2);
}

.smi-option input[type="radio"]:checked + .smi-option-label {
    color: #1d2327;
    font-weight: 600;
}

.smi-option input[type="radio"]:checked {
    accent-color: var(--wp--preset--color--primary, #2271b1);
}

.smi-option-label {
    flex: 1;
    display: flex;
    flex-direction: column;
    gap: 4px;
}

.smi-option-label strong {
    font-size: 15px;
    color: #1d2327;
}

.smi-option-details {
    font-size: 13px;
    color: #666;
}

.smi-option-price {
    font-size: 16px;
    font-weight: 600;
    color: #1d2327;
    margin-left: auto;
}

/* Selected Option Styling */
.smi-option:has(input:checked) {
    border-color: var(--wp--preset--color--primary, #2271b1);
    border-width: 2px;
    background: rgba(0, 0, 0, 0.02);
}

/* Email Field */
.smi-email-field {
    margin-top: 20px;
    padding-top: 20px;
    border-top: 1px solid currentColor;
    border-top-color: rgba(0, 0, 0, 0.1);
}

.smi-email-field label {
    display: block;
    font-weight: 600;
    color: #1d2327;
    margin-bottom: 8px;
}

.smi-email-field input[type="email"] {
    width: 100%;
    padding: 12px;
    border: 2px solid rgba(0, 0, 0, 0.15);
    border-radius: 6px;
    font-size: 14px;
    transition: border-color 0.2s ease;
    background: white;
    color: #1d2327;
    font-family: inherit;
}

.smi-email-field input[type="email"]:focus {
    outline: none;
    border-color: var(--wp--preset--color--primary, #2271b1);
    box-shadow: 0 0 0 1px var(--wp--preset--color--primary, #2271b1);
}

.smi-email-field .description {
    font-size: 13px;
    color: #666;
    margin: 8px 0 0 0;
    font-style: italic;
}


/* ==========================================================================
   Error Messages
   ========================================================================== */

.smi-error-message {
    text-align: center;
    padding: 40px 20px;
}

.smi-error-text {
    color: var(--wp--preset--color--vivid-red, #d63638);
    font-size: 16px;
    margin: 0;
}

/* ==========================================================================
   Success Messages
   ========================================================================== */

.smi-success-message {
    text-align: center;
    padding: 40px 20px;
}

.smi-success-message h3 {
    color: var(--wp--preset--color--vivid-green-cyan, #00a32a);
    margin: 0 0 15px 0;
}

.smi-success-message p {
    color: #666;
    margin: 0 0 20px 0;
}

/* ==========================================================================
   Modal Footer
   ========================================================================== */

.smi-modal-footer {
    padding: 20px 24px;
    border-top: 1px solid currentColor;
    border-top-color: rgba(0, 0, 0, 0.1);
    background: var(--wp--preset--color--tertiary, rgba(0, 0, 0, 0.03));
    display: flex;
    justify-content: flex-end;
    align-items: center;
    gap: 12px;
}

.smi-btn {
    padding: 10px 20px;
    border: 1px solid transparent;
    border-radius: 4px;
    font-size: 14px;
    font-weight: 500;
    cursor: pointer;
    text-decoration: none;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    min-width: 100px;
    transition: all 0.2s ease;
    font-family: inherit;
}

.smi-btn:focus {
    outline: 2px solid currentColor;
    outline-offset: 2px;
}

.smi-btn-primary {
    background: #2271b1;
    color: white;
    border-color: #2271b1;
}

.smi-btn-primary:hover:not(:disabled) {
    background: #135e96;
    border-color: #135e96;
}

.smi-btn-primary:disabled {
    background: #ccc;
    border-color: #ccc;
    color: #666;
    cursor: not-allowed;
}

.smi-btn-secondary {
    background: white;
    color: #666;
    border-color: rgba(0, 0, 0, 0.2);
}

.smi-btn-secondary:hover {
    background: #f0f0f0;
    color: #333;
    border-color: rgba(0, 0, 0, 0.3);
}

/* ==========================================================================
   Responsive Design
   ========================================================================== */

@media (max-width: 767px) {
    .smi-modal {
        overflow-y: auto;
        -webkit-overflow-scrolling: touch;
    }

    .smi-modal-content {
        width: 95%;
        margin: 2vh auto 2vh auto;
        max-height: none;
        overflow-y: visible;
    }

    .smi-modal-header,
    .smi-modal-body,
    .smi-modal-footer {
        padding: 16px;
    }

    .smi-modal-body {
        flex: none;
        overflow-y: visible;
        max-height: none;
    }
    
    .smi-modal-title {
        font-size: 16px;
    }
    
    .smi-modal-main {
        gap: 16px;
    }

    .smi-modal-footer {
        flex-direction: column;
        align-items: stretch;
    }

    .smi-process-btn {
        width: 100%;
        justify-content: center;
    }
    
    /* Overlay buttons are smaller on mobile */
    .smi-overlay-button {
        padding: 6px 12px;
        font-size: 12px;
        top: 8px;
        right: 8px;
    }
    
    .smi-preview-image {
        max-height: 150px;
    }
}

@media (max-width: 480px) {
    .smi-resolution-options {
        gap: 8px;
    }
    
    .smi-option {
        padding: 12px;
    }
    
    .smi-option-label strong {
        font-size: 14px;
    }
    
    .smi-option-price {
        font-size: 14px;
    }
    
    .smi-total-price {
        font-size: 16px;
    }
}

/* ==========================================================================
   Accessibility Improvements
   ========================================================================== */

.smi-modal[aria-hidden="true"] {
    display: none;
}

.smi-modal[aria-hidden="false"] {
    display: block;
}

/* Focus management */
.smi-modal-content:focus {
    outline: none;
}

/* Screen reader text */
.smi-sr-only {
    position: absolute;
    width: 1px;
    height: 1px;
    padding: 0;
    margin: -1px;
    overflow: hidden;
    clip: rect(0, 0, 0, 0);
    white-space: nowrap;
    border: 0;
}

/* High contrast mode support */
@media (prefers-contrast: high) {
    .smi-get-button {
        border: 2px solid;
    }
    
    .smi-modal-content {
        border: 2px solid;
    }
    
    .smi-option {
        border-width: 2px;
    }
}

/* Reduced motion support */
@media (prefers-reduced-motion: reduce) {
    .smi-get-button,
    .smi-modal-close,
    .smi-option,
    .smi-btn {
        transition: none;
    }
    
    .smi-spinner {
        animation: none;
    }
    
    .smi-get-button:hover {
        transform: none;
    }
}

/* ==========================================================================
   Utility Classes
   ========================================================================== */

.smi-hidden {
    display: none !important;
}

/* Body scroll lock when modal is open */
body.smi-modal-open {
    overflow: hidden !important;
    position: fixed !important;
    width: 100% !important;
    height: 100% !important;
}

.smi-retry-container {
    text-align: center;
    margin-top: 15px;
}

/* Status and Message States */
.smi-error-pricing {
    color: #d63638;
    font-size: 12px;
}

.smi-status-container {
    text-align: center;
    padding: 20px;
}

.smi-status-container p {
    color: #1d2327;
    font-size: 14px;
    line-height: 1.5;
    margin: 10px 0;
}

.smi-status-icon {
    font-size: 24px;
    margin-bottom: 15px;
}

.smi-status-icon.success { color: #00a32a; }
.smi-status-icon.error { color: #d63638; }
.smi-status-icon.info { color: #0073aa; }
.smi-status-icon.warning { color: #f0b90b; }

.smi-status-title {
    margin-bottom: 15px;
    font-weight: 600;
    color: #1d2327;
}

.smi-status-title.success { color: #1d7331; }
.smi-status-title.error { color: #a82229; }
.smi-status-title.info { color: #0f4d73; }
.smi-status-title.warning { color: #986505; }

.smi-button-container {
    margin-top: 20px;
}

.smi-download-container {
    margin: 20px 0;
}

.smi-helper-text{
    font-size:.9rem;
}

/* ==========================================================================
   Theme Integration Helpers
   ========================================================================== */

/* Ensure modal works with common WordPress themes */
.smi-modal * {
    box-sizing: border-box;
}

/* Override common theme styles that might interfere */
.smi-modal button {
    font-family: inherit;
}

.smi-modal input[type="radio"] {
    appearance: auto;
    -webkit-appearance: radio;
}

.smi-modal img {
    max-width: 100%;
    height: auto;
}