/* Opt-in Forms - Universal Styling
 * These styles apply to opt-in forms across all contexts:
 * - Public pages (HTML and Quill)
 * - Admin previews
 * - Form builder previews
 */

/* Form Container */
.optin-form-container {
    margin: 1.5rem 0;
}

/* Form Wrapper */
form.optin-form {
    max-width: 600px;
    margin: 0 auto;
}

/* Form Header */
.optin-form-header {
    margin-bottom: 1.5rem;
}

.optin-form-header h3 {
    margin-bottom: 0.5rem;
    color: var(--md-sys-color-on-surface, #212529);
    font-size: 1.5rem;
    font-weight: 500;
    line-height: 1.3;
}

.optin-form-header p {
    margin-bottom: 0;
    color: var(--md-sys-color-on-surface-variant, #6c757d);
}

/* Form Fields Container */
.optin-form-fields {
    margin-bottom: 1.5rem;
}

/* Individual Field */
.form-field {
    margin-bottom: 1.25rem;
}

.form-field:last-child {
    margin-bottom: 0;
}

.form-field label {
    display: block;
    margin-bottom: 0.375rem;
    color: var(--md-sys-color-on-surface, #212529);
}

/* Required field indicator */
.form-field label.required:after,
.form-field label[required]:after {
    content: " *";
    color: var(--md-sys-color-error, #dc3545);
}

/* Form Inputs */
.form-field input,
.form-field textarea,
.form-field select {
    display: block;
    width: 100%;
    padding: 0.625rem 0.875rem;
    font-size: 1rem;
    font-weight: 400;
    line-height: 1.5;
    color: var(--md-sys-color-on-surface, #212529);
    background-color: var(--md-sys-color-surface, #fff);
    background-clip: padding-box;
    border: 1px solid var(--md-sys-color-outline, #ced4da);
    border-radius: 0.375rem;
    transition: border-color 0.15s ease-in-out, box-shadow 0.15s ease-in-out;
    -webkit-appearance: none;
    -moz-appearance: none;
    appearance: none;
}

/* Focus State */
.form-field input:focus,
.form-field textarea:focus,
.form-field select:focus {
    color: var(--md-sys-color-on-surface, #212529);
    background-color: var(--md-sys-color-surface, #fff);
    border-color: var(--md-sys-color-primary, #86b7fe);
    outline: 0;
    box-shadow: 0 0 0 0.2rem rgba(var(--md-sys-color-primary-rgb, 13, 110, 253), 0.25);
}

/* Placeholder styling */
.form-field input::placeholder,
.form-field textarea::placeholder {
    color: var(--md-sys-color-on-surface-variant, #6c757d);
    opacity: 0.7;
}

/* Submit Button */
.optin-form button[type="submit"],
form[data-form-id] button[type="submit"],
button.optin-submit-btn {
    display: block;
    width: 100%;
    font-weight: 500;
    text-align: center;
    vertical-align: middle;
    user-select: none;
    padding: 0.875rem 1.5rem;
    border-radius: 0.375rem;
    transition: all 0.15s ease-in-out;
    cursor: pointer;
    border: 1px solid transparent;
    text-transform: none;
    font-size: 1.5rem;
    line-height: 1.5;
    letter-spacing: normal;

    /* Primary button styling */
    color: var(--md-sys-color-on-primary, #fff) !important;
    background-color: var(--md-sys-color-primary, #0d6efd) !important;
    border-color: var(--md-sys-color-primary, #0d6efd) !important;
}

/* Button hover state */
.optin-form button[type="submit"]:hover,
form[data-form-id] button[type="submit"]:hover,
button.optin-submit-btn:hover {
    background-color: var(--md-sys-color-primary-container, #0b5ed7) !important;
    border-color: var(--md-sys-color-primary-container, #0a58ca) !important;
}

/* Button focus state */
.optin-form button[type="submit"]:focus,
form[data-form-id] button[type="submit"]:focus,
button.optin-submit-btn:focus {
    outline: 0;
    box-shadow: 0 0 0 0.2rem rgba(var(--md-sys-color-primary-rgb, 13, 110, 253), 0.5);
}

/* Button disabled state */
.optin-form button[type="submit"]:disabled,
form[data-form-id] button[type="submit"]:disabled,
button.optin-submit-btn:disabled {
    opacity: 0.65;
    cursor: not-allowed;
}

/* Success/Error Messages */
.optin-form-success,
.optin-form-error,
.optin-form-unavailable {
    padding: 1rem;
    margin: 1rem 0;
    border-radius: 0.375rem;
    text-align: center;
}

.optin-form-success {
    color: var(--md-sys-color-on-success, #155724);
    background-color: var(--md-sys-color-success-container, #d4edda);
    border: 1px solid var(--md-sys-color-success, #c3e6cb);
}

.optin-form-error,
.optin-form-unavailable {
    color: var(--md-sys-color-on-error, #721c24);
    background-color: var(--md-sys-color-error-container, #f8d7da);
    border: 1px solid var(--md-sys-color-error, #f5c6cb);
}

/* Responsive Design */
@media (max-width: 768px) {
    form.optin-form {
        padding: 0 1rem;
    }

    .form-field input,
    .form-field textarea,
    .form-field select {
        font-size: 16px; /* Prevents zoom on iOS */
    }
}

/* Two-column layout for first/last name fields */
.form-field-row {
    display: flex;
    gap: 1rem;
    margin-bottom: 1.25rem;
}

.form-field-row .form-field {
    flex: 1;
    margin-bottom: 0;
}

@media (max-width: 576px) {
    .form-field-row {
        flex-direction: column;
        gap: 0;
    }

    .form-field-row .form-field {
        margin-bottom: 1.25rem;
    }

    .form-field-row .form-field:last-child {
        margin-bottom: 0;
    }
}

/* Preview-specific styling (for admin context) */
.preview-notice,
.form-preview-container .alert-info {
    margin-bottom: 1.5rem;
    padding: 0.75rem 1rem;
    color: var(--md-sys-color-on-info, #0c5460);
    background-color: var(--md-sys-color-info-container, #d1ecf1);
    border: 1px solid var(--md-sys-color-info, #bee5eb);
    border-radius: 0.375rem;
}

/* Validation States */
.form-field input.is-valid,
.form-field textarea.is-valid,
.form-field select.is-valid {
    border-color: var(--md-sys-color-success, #198754);
    padding-right: calc(1.5em + 0.75rem);
    background-image: url("data:image/svg+xml,%3csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 8 8'%3e%3cpath fill='%23198754' d='M2.3 6.73L.6 4.53c-.4-1.04.46-1.4 1.1-.8l1.1 1.4 3.4-3.8c.6-.63 1.6-.27 1.2.7l-4 4.6c-.43.5-.8.4-1.1.1z'/%3e%3c/svg%3e");
    background-repeat: no-repeat;
    background-position: right calc(0.375em + 0.1875rem) center;
    background-size: calc(0.75em + 0.375rem) calc(0.75em + 0.375rem);
}

.form-field input.is-invalid,
.form-field textarea.is-invalid,
.form-field select.is-invalid {
    border-color: var(--md-sys-color-error, #dc3545);
    padding-right: calc(1.5em + 0.75rem);
    background-image: url("data:image/svg+xml,%3csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 12 12' width='12' height='12' fill='none' stroke='%23dc3545'%3e%3ccircle cx='6' cy='6' r='4.5'/%3e%3cpath stroke-linejoin='round' d='M5.8 3.6h.4L6 6.5z'/%3e%3ccircle cx='6' cy='8.2' r='.6' fill='%23dc3545' stroke='none'/%3e%3c/svg%3e");
    background-repeat: no-repeat;
    background-position: right calc(0.375em + 0.1875rem) center;
    background-size: calc(0.75em + 0.375rem) calc(0.75em + 0.375rem);
}

.valid-feedback,
.invalid-feedback {
    display: block;
    margin-top: 0.25rem;
    font-size: 0.875rem;
}

.valid-feedback {
    color: var(--md-sys-color-success, #198754);
}

.invalid-feedback {
    color: var(--md-sys-color-error, #dc3545);
}