/**
 * Q21 Advanced Form Builder - Frontend Styles
 */

/* Form Container */
.q21-afb-form {
    max-width: 600px;
    margin: 0 auto;
    padding: 20px;
    background: #fff;
    border: 1px solid #ddd;
    border-radius: 8px;
    box-shadow: 0 2px 10px rgba(0, 0, 0, 0.1);
}

/* Field Container */
.q21-afb-field-container {
    margin-bottom: 20px;
}

/* Labels */
.q21-afb-label {
    display: block;
    margin-bottom: 5px;
    font-weight: 600;
    color: #333;
    font-size: 14px;
}

.q21-afb-required {
    color: #e74c3c;
    margin-left: 2px;
}

/* Input Fields */
.q21-afb-input,
.q21-afb-select,
.q21-afb-textarea {
    width: 100%;
    padding: 12px;
    border: 2px solid #e1e5e9;
    border-radius: 4px;
    font-size: 16px;
    line-height: 1.4;
    transition: border-color 0.3s ease, box-shadow 0.3s ease;
    box-sizing: border-box;
}

.q21-afb-input:focus,
.q21-afb-select:focus,
.q21-afb-textarea:focus {
    outline: none;
    border-color: #3498db;
    box-shadow: 0 0 0 3px rgba(52, 152, 219, 0.1);
}

/* Error State */
.q21-afb-field-error .q21-afb-input,
.q21-afb-field-error .q21-afb-select,
.q21-afb-field-error .q21-afb-textarea {
    border-color: #e74c3c;
}

.q21-afb-field-error .q21-afb-input:focus,
.q21-afb-field-error .q21-afb-select:focus,
.q21-afb-field-error .q21-afb-textarea:focus {
    box-shadow: 0 0 0 3px rgba(231, 76, 60, 0.1);
}

/* Error Messages */
.q21-afb-error-message {
    margin-top: 5px;
    color: #e74c3c;
    font-size: 14px;
    line-height: 1.4;
}

/* Select Fields */
.q21-afb-select {
    background-image: url("data:image/svg+xml,%3csvg xmlns='http://www.w3.org/2000/svg' fill='none' viewBox='0 0 20 20'%3e%3cpath stroke='%236b7280' stroke-linecap='round' stroke-linejoin='round' stroke-width='1.5' d='m6 8 4 4 4-4'/%3e%3c/svg%3e");
    background-position: right 12px center;
    background-repeat: no-repeat;
    background-size: 16px;
    padding-right: 40px;
    appearance: none;
}

/* Textarea */
.q21-afb-textarea {
    resize: vertical;
    min-height: 100px;
}

/* Submit Button */
.q21-afb-submit-container {
    margin-top: 30px;
    text-align: center;
}

.q21-afb-submit {
    background: #3498db;
    color: white;
    border: none;
    padding: 15px 30px;
    font-size: 16px;
    font-weight: 600;
    border-radius: 4px;
    cursor: pointer;
    transition: background-color 0.3s ease, transform 0.1s ease;
    min-width: 150px;
}

.q21-afb-submit:hover {
    background: #2980b9;
    transform: translateY(-1px);
}

.q21-afb-submit:active {
    transform: translateY(0);
}

.q21-afb-submit:disabled,
.q21-afb-submit.q21-afb-submitting {
    background: #95a5a6;
    cursor: not-allowed;
    transform: none;
}

/* hCaptcha Container */
.q21-afb-hcaptcha-container {
    margin: 20px 0;
    text-align: center;
    transition: all 0.3s ease;
}

/* hCaptcha Error State */
.q21-afb-hcaptcha-container.q21-afb-hcaptcha-error {
    padding: 10px;
    border: 2px solid #e74c3c;
    border-radius: 4px;
    background-color: #fdf2f2;
    animation: q21-afb-shake 0.5s ease-in-out;
}

.q21-afb-hcaptcha-container.q21-afb-hcaptcha-error::after {
    content: "Please complete the captcha verification";
    display: block;
    margin-top: 10px;
    color: #e74c3c;
    font-size: 14px;
    font-weight: 600;
}

/* Shake animation for hCaptcha error */
@keyframes q21-afb-shake {
    0%, 100% { transform: translateX(0); }
    25% { transform: translateX(-5px); }
    75% { transform: translateX(5px); }
}

/* Form Messages */
.q21-afb-form-messages {
    margin-top: 20px;
}

.q21-afb-success-message {
    padding: 15px;
    background: #d4edda;
    color: #155724;
    border: 1px solid #c3e6cb;
    border-radius: 4px;
    font-size: 14px;
}

.q21-afb-error-message {
    padding: 15px;
    background: #f8d7da;
    color: #721c24;
    border: 1px solid #f5c6cb;
    border-radius: 4px;
    font-size: 14px;
}

/* Repeatable Groups */
.q21-afb-repeat {
    margin-bottom: 25px;
    border: 1px solid #e1e5e9;
    border-radius: 6px;
    padding: 15px;
    background: #fafbfc;
}

.q21-afb-repeat-items {
    margin-bottom: 15px;
}

.q21-afb-repeat-item {
    padding: 15px;
    margin-bottom: 15px;
    background: #fff;
    border: 1px solid #e1e5e9;
    border-radius: 4px;
    position: relative;
}

.q21-afb-repeat-item:last-child {
    margin-bottom: 0;
}

.q21-afb-repeat-item::before {
    content: "Item " counter(item-counter);
    counter-increment: item-counter;
    position: absolute;
    top: -8px;
    left: 10px;
    background: #3498db;
    color: white;
    padding: 2px 8px;
    font-size: 12px;
    border-radius: 3px;
    font-weight: 600;
}

.q21-afb-repeat {
    counter-reset: item-counter;
}

.q21-afb-repeat-controls {
    text-align: right;
    padding-top: 10px;
    border-top: 1px solid #e1e5e9;
}

.q21-afb-repeat-controls button {
    background: #3498db;
    color: white;
    border: none;
    padding: 8px 16px;
    margin-left: 8px;
    border-radius: 4px;
    cursor: pointer;
    font-size: 14px;
    font-weight: 600;
    transition: background-color 0.3s ease, transform 0.1s ease;
}

.q21-afb-repeat-controls button:hover:not(:disabled) {
    background: #2980b9;
    transform: translateY(-1px);
}

.q21-afb-repeat-controls button:disabled {
    background: #95a5a6;
    cursor: not-allowed;
    transform: none;
}

.q21-afb-repeat-add {
    background: #27ae60;
}

.q21-afb-repeat-add:hover:not(:disabled) {
    background: #229954;
}

.q21-afb-repeat-remove {
    background: #e74c3c;
}

.q21-afb-repeat-remove:hover:not(:disabled) {
    background: #c0392b;
}

/* Template Script (hidden) */
script[type="text/x-q21-afb-repeat-template"] {
    display: none;
}

/* Responsive Design */
@media (max-width: 768px) {
    .q21-afb-form {
        margin: 0 15px;
        padding: 15px;
    }
    
    .q21-afb-input,
    .q21-afb-select,
    .q21-afb-textarea {
        font-size: 16px; /* Prevents zoom on iOS */
    }
    
    .q21-afb-submit {
        width: 100%;
    }
    
    .q21-afb-repeat {
        padding: 10px;
    }
    
    .q21-afb-repeat-item {
        padding: 10px;
    }
    
    .q21-afb-repeat-controls {
        text-align: center;
    }
    
    .q21-afb-repeat-controls button {
        margin: 5px;
    }
}

/* Accessibility */
@media (prefers-reduced-motion: reduce) {
    .q21-afb-input,
    .q21-afb-select,
    .q21-afb-textarea,
    .q21-afb-submit,
    .q21-afb-repeat-controls button {
        transition: none;
    }
    
    .q21-afb-hcaptcha-container {
        transition: none;
    }
    
    .q21-afb-hcaptcha-container.q21-afb-hcaptcha-error {
        animation: none;
    }
}

/* High Contrast Mode */
@media (prefers-contrast: high) {
    .q21-afb-form {
        border: 2px solid;
    }
    
    .q21-afb-input,
    .q21-afb-select,
    .q21-afb-textarea {
        border: 2px solid;
    }
    
    .q21-afb-repeat {
        border: 2px solid;
    }
    
    .q21-afb-repeat-item {
        border: 2px solid;
    }
}

/* Loading State */
.q21-afb-submitting::after {
    content: '';
    display: inline-block;
    width: 16px;
    height: 16px;
    margin-left: 8px;
    border: 2px solid transparent;
    border-top: 2px solid currentColor;
    border-radius: 50%;
    animation: q21-afb-spin 1s linear infinite;
}

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

/* Error State for General Forms */
.q21-afb-error {
    color: #e74c3c;
    font-style: italic;
    font-size: 14px;
    margin: 10px 0;
    padding: 10px;
    background: #fdf2f2;
    border-left: 4px solid #e74c3c;
}

/* Settings Page Styles */
.q21-afb-settings-grid {
    display: grid;
    grid-template-columns: 2fr 1fr;
    gap: 30px;
    margin-top: 20px;
}

.q21-afb-help-box {
    background: #f9f9f9;
    border: 1px solid #ddd;
    border-radius: 4px;
    padding: 20px;
}

.q21-afb-help-box h3 {
    margin-top: 0;
    color: #333;
}

.q21-afb-help-box h4 {
    margin-bottom: 10px;
    color: #666;
}

.q21-afb-help-box code {
    display: block;
    background: #f4f4f4;
    padding: 15px;
    border-radius: 4px;
    margin-bottom: 20px;
    font-family: 'Courier New', monospace;
    font-size: 13px;
    line-height: 1.4;
    overflow-x: auto;
}

@media (max-width: 768px) {
    .q21-afb-settings-grid {
        grid-template-columns: 1fr;
        gap: 20px;
    }
}
