/* ============================================
   کپچای ایرانی - Frontend Styles v7.2.1
   ============================================ */

/* ==================== Base Variables ==================== */
.iranian-captcha-container {
    --ic-primary: #667eea;
    --ic-bg: #f9fafb;
    --ic-surface: #ffffff;
    --ic-text: #1e1e1e;
    --ic-text-muted: #6b7280;
    --ic-border: #e5e7eb;
    --ic-border-width: 1px;
    --ic-radius: 8px;
    --ic-padding: 12px;
    --ic-gap: 10px;
    --ic-font-size: 14px;
    --ic-shadow: 0 2px 8px rgba(0, 0, 0, 0.06);
    --ic-transition: 0.2s ease;
    --ic-child-radius: calc(var(--ic-radius) / 2);

    display: flex;
    flex-direction: column;
    gap: var(--ic-gap);
    margin: 12px 0;
    padding: var(--ic-padding);
    background: var(--ic-surface);
    border: var(--ic-border-width) solid var(--ic-border);
    border-radius: var(--ic-radius);
    box-sizing: border-box;
    width: 100%;
    max-width: 100%;
    font-size: var(--ic-font-size);
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Tahoma, "Vazirmatn", sans-serif;
    color: var(--ic-text);
    direction: rtl;
    text-align: right;
    transition: box-shadow var(--ic-transition), border-color var(--ic-transition);
}

.iranian-captcha-container *,
.iranian-captcha-container *::before,
.iranian-captcha-container *::after {
    box-sizing: border-box;
}

/* ✅ IMPROVEMENT: reset استایل‌های قالب‌های مهاجم */
.iranian-captcha-container button,
.iranian-captcha-container input {
    font-family: inherit;
    line-height: normal;
}

/* ==================== Theme Modes ==================== */
.iranian-captcha-container.ic-theme-light {
    --ic-bg: #f9fafb;
    --ic-surface: #ffffff;
    --ic-text: #1e1e1e;
    --ic-text-muted: #6b7280;
    --ic-border: #e5e7eb;
}

.iranian-captcha-container.ic-theme-dark {
    --ic-bg: #1a1a1a;
    --ic-surface: #2a2a2a;
    --ic-text: #f0f0f0;
    --ic-text-muted: #a0a0a0;
    --ic-border: #404040;
    --ic-shadow: 0 2px 8px rgba(0, 0, 0, 0.4);
}

.iranian-captcha-container.ic-theme-dark .captcha-image {
    background: #1e1e1e;
    border-color: #555;
}

.iranian-captcha-container.ic-theme-dark input[name="iranian_captcha_input"] {
    background: #1e1e1e;
    border-color: #555;
    color: #f0f0f0;
}

.iranian-captcha-container.ic-theme-dark input[name="iranian_captcha_input"]::placeholder {
    color: #888;
}

/* Auto Theme */
.iranian-captcha-container.ic-theme-auto {
    --ic-bg: #f9fafb;
    --ic-surface: #ffffff;
    --ic-text: #1e1e1e;
    --ic-text-muted: #6b7280;
    --ic-border: #e5e7eb;
}

@media (prefers-color-scheme: dark) {
    .iranian-captcha-container.ic-theme-auto {
        --ic-bg: #1a1a1a;
        --ic-surface: #2a2a2a;
        --ic-text: #f0f0f0;
        --ic-text-muted: #a0a0a0;
        --ic-border: #404040;
        --ic-shadow: 0 2px 8px rgba(0, 0, 0, 0.4);
    }
    .iranian-captcha-container.ic-theme-auto .captcha-image {
        background: #1e1e1e;
        border-color: #555;
    }
    .iranian-captcha-container.ic-theme-auto input[name="iranian_captcha_input"] {
        background: #1e1e1e;
        border-color: #555;
        color: #f0f0f0;
    }
}

/* ==================== Shadows ==================== */
.iranian-captcha-container.ic-shadow-none   { box-shadow: none; }
.iranian-captcha-container.ic-shadow-soft   { box-shadow: 0 2px 8px rgba(0, 0, 0, 0.06); }
.iranian-captcha-container.ic-shadow-medium { box-shadow: 0 4px 14px rgba(0, 0, 0, 0.10); }
.iranian-captcha-container.ic-shadow-strong { box-shadow: 0 8px 24px rgba(0, 0, 0, 0.16); }

.iranian-captcha-container.ic-theme-dark.ic-shadow-soft   { box-shadow: 0 2px 8px rgba(0, 0, 0, 0.4); }
.iranian-captcha-container.ic-theme-dark.ic-shadow-medium { box-shadow: 0 4px 14px rgba(0, 0, 0, 0.5); }
.iranian-captcha-container.ic-theme-dark.ic-shadow-strong { box-shadow: 0 8px 24px rgba(0, 0, 0, 0.6); }

/* ==================== Dotted Background ==================== */
.iranian-captcha-container.ic-dotted-bg {
    background-image: radial-gradient(circle, rgba(0, 0, 0, 0.05) 1px, transparent 1px);
    background-size: 12px 12px;
}

.iranian-captcha-container.ic-theme-dark.ic-dotted-bg {
    background-image: radial-gradient(circle, rgba(255, 255, 255, 0.06) 1px, transparent 1px);
}

/* ==================== Label ==================== */
.iranian-captcha-container > label {
    display: block;
    margin: 0;
    font-size: 13px;
    font-weight: 500;
    color: var(--ic-text-muted);
    line-height: 1.4;
}

/* ==================== Captcha Wrapper ==================== */
.iranian-captcha-container .captcha-wrapper {
    display: flex;
    align-items: center;
    justify-content: flex-start;
    gap: var(--ic-gap);
    width: 100%;
    flex-wrap: wrap;
}

.iranian-captcha-container.ic-layout-horizontal .captcha-wrapper {
    flex-direction: row;
}

.iranian-captcha-container.ic-layout-vertical .captcha-wrapper {
    flex-direction: column;
    align-items: stretch;
}

.iranian-captcha-container.ic-layout-vertical .captcha-image {
    width: 100%;
    max-width: 100%;
    height: auto;
}

.iranian-captcha-container.ic-layout-vertical .captcha-refresh {
    align-self: flex-start;
}

/* ==================== Captcha Image ==================== */
.iranian-captcha-container .captcha-image {
    border: 1px solid var(--ic-border);
    border-radius: var(--ic-child-radius);
    background: var(--ic-bg);
    height: auto;
    width: auto;
    max-width: 100%;
    object-fit: contain;
    display: block;
    flex: 0 1 auto;
    transition: opacity var(--ic-transition);
    user-select: none;
    -webkit-user-drag: none;
}

/* ✅ IMPROVEMENT: افکت لودینگ روی تصویر */
.iranian-captcha-container .captcha-image[data-loading="1"] {
    opacity: 0.4;
    filter: blur(1px);
}

.iranian-captcha-container.ic-animations-on .captcha-image[src*="data:image"] {
    opacity: 0.4;
}

/* ==================== Input Field ==================== */
.iranian-captcha-container input[name="iranian_captcha_input"] {
    width: 100%;
    padding: 10px 12px;
    border: 1px solid var(--ic-border);
    border-radius: var(--ic-child-radius);
    font-size: 16px;
    letter-spacing: 3px;
    text-align: center;
    margin: 0;
    background: var(--ic-surface);
    color: var(--ic-text);
    transition: border-color var(--ic-transition), box-shadow var(--ic-transition), background var(--ic-transition);
    outline: none;
    -webkit-appearance: none;
    appearance: none;
}

.iranian-captcha-container input[name="iranian_captcha_input"]::placeholder {
    color: var(--ic-text-muted);
    letter-spacing: normal;
    font-size: 13px;
}

.iranian-captcha-container input[name="iranian_captcha_input"]:focus {
    border-color: var(--ic-primary);
    box-shadow: 0 0 0 3px rgba(102, 126, 234, 0.15);
}

.iranian-captcha-container input[name="iranian_captcha_input"]:invalid:not(:placeholder-shown) {
    border-color: #ef4444;
}

/* ✅ IMPROVEMENT: حالت disabled */
.iranian-captcha-container input[name="iranian_captcha_input"]:disabled {
    opacity: 0.6;
    cursor: not-allowed;
    background: var(--ic-bg);
}

/* ==================== Refresh Button ==================== */
.iranian-captcha-container .captcha-refresh {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 6px;
    padding: 8px 14px;
    border: 1px solid transparent;
    border-radius: var(--ic-child-radius);
    cursor: pointer;
    font-size: 13px;
    font-weight: 500;
    line-height: 1;
    min-height: 38px;
    min-width: 38px;
    transition: all var(--ic-transition);
    white-space: nowrap;
    background: var(--ic-primary);
    color: #ffffff;
    flex: 0 0 auto;
    -webkit-appearance: none;
    appearance: none;
    text-decoration: none;
}

.iranian-captcha-container .captcha-refresh:hover:not(:disabled) {
    transform: translateY(-1px);
    filter: brightness(1.08);
    box-shadow: 0 4px 10px rgba(102, 126, 234, 0.3);
}

.iranian-captcha-container .captcha-refresh:active:not(:disabled) {
    transform: translateY(0);
}

.iranian-captcha-container .captcha-refresh:disabled {
    opacity: 0.55;
    cursor: not-allowed;
    transform: none;
    filter: none;
}

.iranian-captcha-container .captcha-refresh .ic-refresh-icon {
    font-size: 16px;
    line-height: 1;
    display: inline-block;
    transition: transform 0.4s ease;
}

.iranian-captcha-container .captcha-refresh:hover:not(:disabled) .ic-refresh-icon {
    transform: rotate(180deg);
}

.iranian-captcha-container .captcha-refresh.ic-btn-loading .ic-refresh-icon {
    animation: ic-spin 0.9s linear infinite;
}

@keyframes ic-spin {
    from { transform: rotate(0deg); }
    to   { transform: rotate(360deg); }
}

.iranian-captcha-container .captcha-refresh .ic-refresh-text {
    font-size: 13px;
}

/* ==================== Refresh Button Variants ==================== */
.iranian-captcha-container .captcha-refresh.ic-btn-primary {
    background: var(--ic-primary);
    color: #fff;
    border-color: var(--ic-primary);
}

.iranian-captcha-container .captcha-refresh.ic-btn-secondary {
    background: var(--ic-text-muted);
    color: #fff;
    border-color: var(--ic-text-muted);
}

.iranian-captcha-container .captcha-refresh.ic-btn-ghost {
    background: transparent;
    color: var(--ic-text);
    border-color: transparent;
}

.iranian-captcha-container .captcha-refresh.ic-btn-ghost:hover:not(:disabled) {
    background: rgba(102, 126, 234, 0.08);
    color: var(--ic-primary);
    box-shadow: none;
}

.iranian-captcha-container .captcha-refresh.ic-btn-outline {
    background: transparent;
    color: var(--ic-primary);
    border-color: var(--ic-primary);
}

.iranian-captcha-container .captcha-refresh.ic-btn-outline:hover:not(:disabled) {
    background: var(--ic-primary);
    color: #fff;
}

/* ✅ IMPROVEMENT: رنگ outline در دارک مود روشن‌تر */
.iranian-captcha-container.ic-theme-dark .captcha-refresh.ic-btn-outline {
    color: #93b4ff;
    border-color: #93b4ff;
}

.iranian-captcha-container.ic-theme-dark .captcha-refresh.ic-btn-outline:hover:not(:disabled) {
    background: #93b4ff;
    color: #1a1a1a;
}

/* ==================== Expiry Hint ==================== */
.iranian-captcha-container .ic-expiry-hint {
    display: inline-flex;
    align-items: center;
    gap: 4px;
    font-size: 12px;
    color: var(--ic-text-muted);
    margin: 0;
}

.iranian-captcha-container .ic-expiry-hint .dashicons {
    font-size: 14px;
    width: 14px;
    height: 14px;
    line-height: 1;
}

/* ==================== Animations ==================== */
.iranian-captcha-container.ic-animations-on:hover {
    border-color: var(--ic-primary);
}

/* ✅ IMPROVEMENT: انیمیشن ورود */
.iranian-captcha-container.ic-animations-on {
    animation: ic-fade-in 0.3s ease-out;
}

@keyframes ic-fade-in {
    from { opacity: 0; transform: translateY(4px); }
    to   { opacity: 1; transform: translateY(0); }
}

/* ==================== Error Message ==================== */
.iranian-captcha-error {
    padding: 10px 14px;
    background: #fef2f2;
    border: 1px solid #fecaca;
    border-radius: 6px;
    color: #b91c1c;
    font-size: 13px;
    margin: 8px 0;
    direction: rtl;
    text-align: right;
}

@media (prefers-color-scheme: dark) {
    .iranian-captcha-error {
        background: #451a1a;
        border-color: #7f1d1d;
        color: #fca5a5;
    }
}

/* ==================== Preview Image (برای ادمین) ==================== */
.ic-preview-img {
    max-width: 100%;
    height: auto;
    display: block;
    border-radius: 6px;
    border: 1px solid var(--ic-border, #e5e7eb);
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.08);
}

/* ==================== Context-Specific Overrides ==================== */
.login form .iranian-captcha-container {
    margin: 10px 0 14px;
    padding: 10px;
    --ic-font-size: 13px;
    --ic-padding: 10px;
}

.login form .iranian-captcha-container .captcha-image { max-height: 40px; }
.login form .iranian-captcha-container input[name="iranian_captcha_input"] { padding: 8px 10px; font-size: 15px; }
.login form .iranian-captcha-container .captcha-refresh { min-height: 34px; min-width: 34px; padding: 6px 10px; }

/* WooCommerce */
.woocommerce-form-login .iranian-captcha-container,
.woocommerce-form-register .iranian-captcha-container,
.woocommerce-ResetPassword .iranian-captcha-container { margin: 14px 0; }

form.checkout .iranian-captcha-container,
.ic-checkout-captcha-wrapper .iranian-captcha-container { margin: 15px 0; --ic-padding: 14px; }

.ic-checkout-captcha-wrapper { width: 100%; margin: 15px 0; order: 99; }
.ic-block-captcha-wrapper { width: 100%; margin: 15px 0; order: 99; }

/* Comments */
.comment-form .iranian-captcha-container { margin: 12px 0; }

/* wpDiscuz */
.ic-wpdiscuz-wrapper,
.ic-wpdiscuz-injected { width: 100%; margin: 12px 0; clear: both; }

#wpdcom .ic-wpdiscuz-injected .iranian-captcha-container { margin: 10px 0; }

/* Elementor */
.elementor-form .ic-elementor-wrapper { width: 100% !important; flex-basis: 100% !important; margin-top: 15px; }
.elementor-field-group .iranian-captcha-container { width: 100%; }

/* CF7 */
.wpcf7 .iranian-captcha-container { margin: 12px 0; }
.wpcf7-not-valid-tip { color: #ef4444; font-size: 12px; margin-top: 4px; display: block; }

/* Divi */
.et_pb_contact_form .iranian-captcha-container { margin: 15px 0; }

/* Bricks */
.brxe-form .iranian-captcha-container,
.bricks-form .iranian-captcha-container { margin: 15px 0; width: 100%; }

/* BuddyPress */
#register-page .iranian-captcha-container,
#signup-form .iranian-captcha-container { margin: 15px 0; }

/* bbPress */
#bbpress-forums .iranian-captcha-container { margin: 15px 0; }

/* EDD */
#edd_checkout_form_wrap .iranian-captcha-container { margin: 15px 0; }

/* ==================== RTL/LTR ==================== */
[dir="ltr"] .iranian-captcha-container { direction: ltr; text-align: left; }
[dir="ltr"] .iranian-captcha-container .captcha-wrapper { justify-content: flex-start; }

/* ==================== Responsive ==================== */
@media (max-width: 480px) {
    .iranian-captcha-container { --ic-padding: 10px; --ic-gap: 8px; }
    .iranian-captcha-container .captcha-wrapper { flex-wrap: wrap; }
    .iranian-captcha-container.ic-layout-horizontal .captcha-image { flex: 1 1 100%; width: 100%; margin-bottom: 6px; }
    .iranian-captcha-container .captcha-refresh { flex: 1 1 auto; width: auto; justify-content: center; }
    .iranian-captcha-container input[name="iranian_captcha_input"] { font-size: 15px; letter-spacing: 2px; }
}

/* ==================== Accessibility ==================== */
.iranian-captcha-container button:focus-visible,
.iranian-captcha-container input:focus-visible {
    outline: 2px solid var(--ic-primary);
    outline-offset: 2px;
}

/* ✅ IMPROVEMENT: کاهش حرکت */
@media (prefers-reduced-motion: reduce) {
    .iranian-captcha-container,
    .iranian-captcha-container * {
        transition: none !important;
        animation: none !important;
    }
}

@media print {
    .iranian-captcha-container { display: none; }
}