/**
 * SecureGate Captcha Lite - Frontend Styles
 *
 * @package SecureGate_Captcha
 * @since 1.0.0
 */

/* ==========================================================================
   CAPTCHA Container Styles
   ========================================================================== */

/* ==========================================================================
   CAPTCHA Container Styles
   ========================================================================== */

.securegate-captcha-wrapper {
	margin: 20px 0;
	padding: 10px 0;
	background: transparent;
	border: none;
    /* Use max-width and auto margins to play nice with themes */
    width: 100%;
    max-width: 100%;
    box-sizing: border-box;
    /* Avoid aggressive clearing which can break some layouts */
    clear: none; 
}

/* Ensure content inside doesn't overflow */
.securegate-captcha-wrapper * {
    box-sizing: border-box;
}

.securegate-captcha-wrapper::after {
	content: "";
	display: table;
	clear: both;
}

/* ==========================================================================
   Comment Form Specific Fixes (High Specificity)
   ========================================================================== */
#respond .securegate-captcha-wrapper,
.comment-form .securegate-captcha-wrapper {
    width: 100% !important;
    max-width: 100% !important;
    clear: both !important; /* Force new line */
    float: none !important;
    margin: 15px 0 20px !important;
    display: block !important;
    flex-basis: 100%; /* Fix for flexbox forms */
}


/* ==========================================================================
   Fallback CAPTCHA Styles
   ========================================================================== */

.securegate-captcha-fallback {
	display: block;
    width: 100%;
}

.securegate-captcha-fallback label {
	display: block;
	margin-bottom: 8px;
	font-weight: 600;
	color: inherit; /* Inherit from theme */
	font-size: 14px;
}

.securegate-captcha-fallback label .required {
	color: #d63638;
	font-weight: bold;
}

.securegate-captcha-fallback input[type="text"] {
	width: 100%;
	max-width: 200px;
	padding: 8px 12px;
	border: 1px solid #ccc;
	border-radius: 4px;
	font-size: 14px;
	box-sizing: border-box;
    background-color: #fff;
    color: #333;
}

.securegate-captcha-fallback input[type="text"]:focus {
	border-color: #2271b1;
	outline: none;
	box-shadow: 0 0 0 1px #2271b1;
}

/* Math CAPTCHA */
.securegate-captcha-math label {
	font-size: 16px;
}

/* ==========================================================================
   External Provider Styles
   ========================================================================== */

/* Turnstile */
.securegate-captcha-turnstile {
	display: block;
}

.securegate-captcha-turnstile .cf-turnstile {
    /* Align left by default for forms, or inherit flex alignment */
	margin: 0; 
}

/* reCAPTCHA v2 */
.securegate-captcha-recaptcha-v2 {
	display: block;
}

.securegate-captcha-recaptcha-v2 .g-recaptcha {
	margin: 0;
}

/* reCAPTCHA v3 (Invisible) */
.securegate-captcha-recaptcha-v3 {
	display: none;
}

/* hCaptcha */
.securegate-captcha-hcaptcha {
	display: block;
}

.securegate-captcha-hcaptcha .h-captcha {
	margin: 0;
}

/* ==========================================================================
   Error Messages
   ========================================================================== */

.securegate-captcha-error {
	padding: 8px 0;
	background-color: transparent;
    border: none;
	color: #d63638 !important; /* Force WP error red */
	font-size: 13px;
	margin: 5px 0 10px;
    font-weight: 600;
    display: block;
    width: 100%;
}

/* ==========================================================================
   WordPress Login/Register Form Styles
   ========================================================================== */

/* WP Login Layout Fix: Widen the form container so fixed-width CAPTCHAs fit naturally */
#login {
    width: 350px !important;
}

#login form {
    overflow: visible !important;
}

#login .securegate-captcha-wrapper {
    margin: 5px 0 !important;
    padding: 0 !important;
    clear: both;
    width: 100%;
}

#login form .input, 
#login form input[type="text"], 
#login form input[type="password"],
#login form input[type="email"] {
    width: 100% !important;
    box-sizing: border-box;
}

#login .submit {
    padding-top: 5px;
    clear: both;
}

/* Ensure Remember Me and Log In button stay inside the box */
#login form .forgetmenot {
    float: none !important;
    display: inline-block;
    margin-top: 5px !important;
}

#login form p.submit {
    display: flex;
    justify-content: space-between;
    align-items: center;
    width: 100%;
    margin-top: 15px !important;
}

/* Tighten vertical spacing between form elements */
#loginform p {
    margin-bottom: 8px !important;
}

#login form .securegate-captcha-turnstile,
#login form .securegate-captcha-recaptcha-v2,
#login form .securegate-captcha-recaptcha-v3,
#login form .securegate-captcha-hcaptcha {
    margin-bottom: 0px;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    width: 100%;
}

/* Ensure inner widgets are centered and fill the space without scaling */
#login form .cf-turnstile,
#login form .g-recaptcha,
#login form .h-captcha {
    margin-left: auto;
    margin-right: auto;
    transform: none !important;
    max-width: 100% !important;
}

#login form .securegate-captcha-container {
    margin-bottom: 1.5em;
    display: flex;
    flex-direction: column;
    align-items: flex-start;
    justify-content: flex-start;
    width: 100%;
    text-align: left;
}

#login form .securegate-captcha-container .securegate-captcha-input-box {
    width: 100%;
    display: flex;
    flex-direction: column;
    align-items: flex-start;
}

#login form .securegate-captcha-container .securegate-captcha-input-box input[type='text'] {
    width: 100% !important;
    max-width: 100% !important;
    box-sizing: border-box;
}

#login form .securegate-captcha-container .securegate-captcha-math-question {
    margin-bottom: 5px;
    font-size: 24px;
    text-align: left;
    width: 100%;
}

#login form .securegate-captcha-container .securegate-captcha-img-box {
    margin-bottom: 5px;
    display: inline-block;
}

#login form .securegate-captcha-container .securegate-captcha-helper-text {
    text-align: left;
    width: 100%;
    margin-top: 0px !important;
}

#login .securegate-captcha-fallback input[type="text"] {
	width: 100%;
}
/* ==========================================================================
   Advanced Fallback CAPTCHA Styles (Visual Match: Scratched Style)
   ========================================================================== */

.securegate-captcha-label {
    display: block;
    font-weight: 700;
    color: #444; /* Dark grey for label */
    margin-bottom: 5px;
    font-size: 14px;
}

.securegate-captcha-label .required {
    color: #e2401c; /* Orange-red for asterisk */
}

/* Image Box Container - Warped Blue Style */
.securegate-captcha-img-box {
    position: relative;
    display: inline-block !important; /* Force inline-block */
    padding: 10px 20px;
    background-color: #fff;
    border: 1px solid #ccc;
    border-radius: 4px;
    margin-bottom: 8px;
    user-select: none;
    min-width: 160px;
    text-align: center;
    overflow: hidden; /* Contain the SVG lines */
    box-shadow: inset 0 0 4px rgba(0,0,0,0.05);
    
    /* Protective Styles against Theme Bleed */
    width: auto !important;
    max-width: none !important;
    line-height: 1.4 !important;
    box-sizing: border-box !important;
    vertical-align: middle;
}

/* Math Question Style */
.securegate-captcha-math-question {
    font-family: 'Segoe UI', 'Roboto', sans-serif;
    font-size: 22px;
    font-weight: 700;
    color: #2c3e50;
    margin-bottom: 12px;
}

/* Text Layer - Warped */
.securegate-captcha-text-layer {
    position: relative;
    z-index: 2;
    font-family: 'Georgia', 'Times New Roman', serif; /* Serif for Google-like look */
    white-space: nowrap !important; /* PREVENT WRAPPING */
    line-height: 40px !important; /* Fixed height for accumulation */
    display: block;
}

/* Individual Character Styling */
.securegate-char {
    display: inline-block !important;
    margin: 0 -3px !important;
    text-shadow: 1px 1px 0 rgba(0,0,0,0.1);
    transform-origin: center center;
    /* Reset any theme span styles */
    float: none !important;
    padding: 0 !important;
    border: none !important;
    background: transparent !important;
}

/* Helper Text (Bottom) */
.securegate-captcha-helper-text {
    margin: 6px 0 0;
    font-size: 12px;
    color: #777; 
    line-height: 1.4;
    font-weight: 500;
}

/* SVG Overlay */
.securegate-captcha-svg-overlay {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    pointer-events: none;
}

/* Input Styles - FORCE White Background with High Specificity */
body .securegate-captcha-input-box input[type="text"],
body .securegate-captcha-input-box input[type="number"],
#respond .securegate-captcha-input-box input[type="text"],
.woocommerce .securegate-captcha-input-box input[type="text"] {
    display: block;
    width: 100%;
    max-width: 250px;
    height: 40px;
    padding: 8px 12px;
    border: 1px solid #dcdcdc !important;
    border-radius: 5px;
    background-color: #ffffff !important; /* Force WHITE */
    color: #333333 !important; /* Force DARK text */
    font-size: 15px;
    box-shadow: 0 2px 4px rgba(0,0,0,0.03);
    transition: all 0.2s ease;
    opacity: 1 !important;
}

.securegate-captcha-input-box input[type="text"]::placeholder,
.securegate-captcha-input-box input[type="number"]::placeholder {
    color: #999;
    opacity: 1;
}

.securegate-captcha-input-box input[type="text"]:focus,
.securegate-captcha-input-box input[type="number"]:focus {
    border-color: #00539c !important; /* Google Blue focus */
    box-shadow: 0 0 0 1px #00539c !important;
    outline: none;
    background-color: #fff !important;
}

/* Error Messages - ALWAYS RED */
.securegate-captcha-error,
.woocommerce-error li,
.securegate-captcha-wrapper .error {
	padding: 8px 0;
	background-color: transparent;
    border: none;
	color: #d63638 !important; /* STRICTLY RED */
	font-size: 13px;
	margin: 5px 0 10px;
    font-weight: 600;
    display: block;
    width: 100%;
}


/* ==========================================================================
   Dark Mode Theme Overrides (.securegate-theme-dark)
   ========================================================================== */

.securegate-theme-dark .securegate-captcha-img-box {
    background-color: #2b2b2b;
    border-color: #444;
    box-shadow: inset 0 0 15px rgba(0,0,0,0.3);
}

/* Force light blue/cyan for text in dark mode (Overriding inline PHP styles) */
.securegate-theme-dark .securegate-char {
    color: #4db8ff !important; /* Light Sky Blue */
    text-shadow: 0 0 5px rgba(77, 184, 255, 0.3);
}

/* Update SVG lines stroke for dark mode */
.securegate-theme-dark .securegate-captcha-interference path {
    stroke: rgba(77, 184, 255, 0.4) !important;
}

.securegate-theme-dark .securegate-captcha-math-question {
    color: #f0f0f0;
}

.securegate-theme-dark .securegate-captcha-helper-text {
    color: #bbb;
}

/* Targeted Dark Mode Inputs */
body .securegate-theme-dark .securegate-captcha-input-box input[type="text"],
body .securegate-theme-dark .securegate-captcha-input-box input[type="number"] {
    background-color: #1e1e1e !important; /* Force dark bg ONLY here */
    border-color: #444 !important;
    color: #eee !important;
}

.securegate-theme-dark .securegate-captcha-input-box input[type="text"]::placeholder,
.securegate-theme-dark .securegate-captcha-input-box input[type="number"]::placeholder {
    color: #666;
}

.securegate-theme-dark .securegate-captcha-input-box input[type="text"]:focus,
.securegate-theme-dark .securegate-captcha-input-box input[type="number"]:focus {
    border-color: #4db8ff !important;
    box-shadow: 0 0 0 1px #4db8ff !important;
}

/* Mobile Responsiveness */
@media screen and (max-width: 480px) {
    .securegate-captcha-img-box {
        width: 100%;
        box-sizing: border-box;
    }
    
    .securegate-captcha-input-box input[type="text"],
    .securegate-captcha-input-box input[type="number"] {
        width: 100%;
        max-width: 100%;
    }
}

/* ==========================================================================
   WooCommerce Styles
   ========================================================================== */

/* WooCommerce Login/Register Forms */
.woocommerce-form .securegate-captcha-wrapper {
	margin: 1em 0;
}

.woocommerce-form-row--wide .securegate-captcha-wrapper {
	width: 100%;
}

/* WooCommerce Checkout */
.woocommerce-checkout .securegate-captcha-wrapper {
	margin: 20px 0;
}

.woocommerce-checkout-captcha {
	margin-top: 20px;
	padding-top: 20px;
	border-top: 1px solid #e0e0e0;
}

/* ==========================================================================
   Responsive Styles
   ========================================================================== */

@media screen and (max-width: 768px) {
	.securegate-captcha-wrapper {
		padding: 12px;
	}

	.securegate-captcha-code-display {
		font-size: 20px;
		letter-spacing: 6px;
		padding: 8px 15px;
	}

	.securegate-captcha-fallback input[type="text"] {
		max-width: 100%;
	}
}

@media screen and (max-width: 480px) {
	.securegate-captcha-code-display {
		font-size: 18px;
		letter-spacing: 4px;
		padding: 6px 12px;
	}
}

/* ==========================================================================
   Loading State
   ========================================================================== */

.securegate-captcha-loading {
	opacity: 0.6;
	pointer-events: none;
}

.securegate-captcha-loading::after {
	content: "";
	position: absolute;
	top: 50%;
	left: 50%;
	width: 20px;
	height: 20px;
	margin: -10px 0 0 -10px;
	border: 2px solid #f3f3f3;
	border-top: 2px solid #2271b1;
	border-radius: 50%;
	animation: securegate-spin 1s linear infinite;
}

@keyframes securegate-spin {
	0% {
		transform: rotate(0deg);
	}
	100% {
		transform: rotate(360deg);
	}
}

/* ==========================================================================
   Accessibility
   ========================================================================== */


.securegate-captcha-fallback input[type="text"]:invalid {
	border-color: #d63638;
}

.securegate-captcha-fallback input[type="text"]:invalid:focus {
	box-shadow: 0 0 0 1px #d63638;
}

/* Screen reader text */
.securegate-captcha-sr-only {
	position: absolute;
	width: 1px;
	height: 1px;
	padding: 0;
	margin: -1px;
	overflow: hidden;
	clip: rect(0, 0, 0, 0);
	white-space: nowrap;
	border-width: 0;
}

/* ==========================================================================
   Dark Mode Support
   ========================================================================== */

@media (prefers-color-scheme: dark) {
	.securegate-captcha-wrapper {
		border-color: #3c3c3c;
	}

	.securegate-captcha-fallback label {
		color: #e0e0e0;
	}

	.securegate-captcha-fallback input[type="text"] {
		background: #2a2a2a;
		border-color: #3c3c3c;
		color: #e0e0e0;
	}

	.securegate-captcha-code-display {
		background: #2a2a2a;
		border-color: #4a90e2;
		color: #e0e0e0;
	}
}

/* ==========================================================================
   Print Styles
   ========================================================================== */

@media print {
	.securegate-captcha-wrapper {
		display: none;
	}
}
