/**
 * MB27 Forms - Frontend Styles
 *
 * Layout and spacing only - colors managed by theme
 *
 * @package MB27_Forms
 * @since   2.0.0
 */

/* ==========================================================================
   Form Wrapper
   ========================================================================== */

.mb27-form-wrapper {
    margin: 20px 0;
}

.mb27-form-title {
    font-size: 1.5em;
    font-weight: 600;
    margin: 0 0 10px 0;
}

.mb27-form-description {
    font-size: 0.95em;
    margin: 0 0 20px 0;
}

/* Alert messages */
.mb27-form-alert {
    padding: 15px 20px;
    margin-bottom: 20px;
    border-radius: 4px;
    border-left: 4px solid;
}

.mb27-form-alert--success {
    border-left-width: 4px;
}

.mb27-form-alert--error {
    border-left-width: 4px;
}

.mb27-form-error {
    font-weight: 500;
}

/* ==========================================================================
   Form Styles
   ========================================================================== */

.mb27-form {
    width: 100%;
}

.mb27-form__form {
    display: flex;
    flex-direction: column;
}

/* ==========================================================================
   Form Fields (BEM Methodology)
   ========================================================================== */

.mb27-form__field {
    margin-bottom: 20px;
    display: flex;
    flex-direction: column;
}

/* Labels */
.mb27-form__label {
    display: block;
    font-weight: 500;
    font-size: 0.95em;
    margin-bottom: 8px;
}

.mb27-form__label--checkbox {
    display: flex;
    align-items: flex-start;
    font-weight: 400;
    margin-bottom: 0;
}

.mb27-form__label--checkbox span {
    flex: 1;
    margin-left: 8px;
    line-height: 1.4;
}

.mb27-form__label--checkbox a {
    text-decoration: none;
}

.mb27-form__label--checkbox a:hover {
    text-decoration: underline;
}

/* Required field indicator */
.mb27-form__required {
    margin-left: 3px;
    font-weight: 600;
}

/* Input fields */
.mb27-form__input,
.mb27-form__textarea,
.mb27-form__select {
    padding: 12px 15px;
    border: 1px solid;
    border-radius: 4px;
    font-size: 1em;
    font-family: inherit;
    transition: border-color 0.3s ease, box-shadow 0.3s ease;
}

.mb27-form__input:focus,
.mb27-form__textarea:focus,
.mb27-form__select:focus {
    outline: none;
    border-width: 2px;
    box-shadow: 0 0 0 3px;
}

.mb27-form__input[aria-invalid="true"],
.mb27-form__textarea[aria-invalid="true"],
.mb27-form__select[aria-invalid="true"] {
    border-width: 2px;
}

.mb27-form__input:disabled,
.mb27-form__textarea:disabled,
.mb27-form__select:disabled {
    opacity: 0.6;
    cursor: not-allowed;
}

/* Select field styling with custom dropdown arrow */
.mb27-form__select {
    appearance: none;
    background-image: url("data:image/svg+xml;charset=UTF-8,%3csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='currentColor' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'%3e%3cpolyline points='6 9 12 15 18 9'%3e%3c/polyline%3e%3c/svg%3e");
    background-repeat: no-repeat;
    background-position: right 12px center;
    background-size: 18px;
    padding-right: 40px;
    cursor: pointer;
}

/* Textarea */
.mb27-form__textarea {
    resize: vertical;
    min-height: 120px;
    font-family: 'Courier New', monospace;
}

/* Placeholder styling */
.mb27-form__input::placeholder,
.mb27-form__textarea::placeholder {
    opacity: 0.6;
}

/* Checkbox and Radio */
.mb27-form__checkbox,
.mb27-form__radio {
    width: 18px;
    height: 18px;
    cursor: pointer;
    flex-shrink: 0;
    margin-top: 2px;
}

.mb27-form__checkbox:focus,
.mb27-form__radio:focus {
    outline: 2px solid;
    outline-offset: 2px;
}

/* Error messages */
.mb27-form__error {
    display: none;
    font-size: 0.85em;
    margin-top: 5px;
    font-weight: 600;
}

.mb27-form__error:not(:empty) {
    display: block;
}

.mb27-form__field--text .mb27-form__error:not(:empty),
.mb27-form__field--email .mb27-form__error:not(:empty),
.mb27-form__field--textarea .mb27-form__error:not(:empty) {
    margin-top: 5px;
}

/* Field error state */
.mb27-form__field--error .mb27-form__input,
.mb27-form__field--error .mb27-form__textarea,
.mb27-form__field--error .mb27-form__select {
    border-width: 2px;
    border-color: #dc2626;
}

.mb27-form__field--error .mb27-form__error {
    color: #dc2626;
    font-weight: 600;
}

/* Checkbox field error state */
.mb27-form__field--error .mb27-form__checkbox,
.mb27-form__field--error .mb27-form__radio {
    outline: 2px solid #dc2626;
    outline-offset: 2px;
}

/* ==========================================================================
   Submit Button
   ========================================================================== */

.mb27-form__submit-wrapper {
    margin-top: 30px;
    display: flex;
    gap: 10px;
}

.mb27-form__submit {
    padding: 12px 30px;
    border: none;
    border-radius: 4px;
    font-size: 1em;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.3s ease;
    display: flex;
    align-items: center;
    gap: 8px;
}

.mb27-form__submit:hover:not(:disabled) {
    transform: translateY(-2px);
    transition: all 0.3s ease;
}

.mb27-form__submit:focus {
    outline: 2px solid;
    outline-offset: 2px;
}

.mb27-form__submit:disabled {
    opacity: 0.6;
    cursor: not-allowed;
}

/* Submit loading state */
.mb27-form__submit--loading {
    display: none;
    align-items: center;
    gap: 6px;
}

.mb27-form__submit.is-loading .mb27-form__submit-text {
    display: none;
}

.mb27-form__submit.is-loading .mb27-form__submit-loading {
    display: flex;
}

/* Spinner */
.mb27-form__spinner {
    display: inline-block;
    width: 14px;
    height: 14px;
    border: 2px solid;
    border-radius: 50%;
    animation: mb27-spin 0.6s linear infinite;
}

@keyframes mb27-spin {
    to {
        transform: rotate(360deg);
    }
}

/* ==========================================================================
   Success and Error Messages
   ========================================================================== */

.mb27-form__message {
    padding: 15px 20px;
    border-radius: 4px;
    margin-top: 20px;
    font-weight: 500;
    border-left: 4px solid;
}

.mb27-form__message--success {
    border-left-width: 4px;
}

.mb27-form__message--error {
    border-left-width: 4px;
}

/* ==========================================================================
   Responsive Design
   ========================================================================== */

@media (max-width: 768px) {
    .mb27-form__field {
        margin-bottom: 18px;
    }

    .mb27-form__submit {
        padding: 10px 20px;
        font-size: 0.95em;
        width: 100%;
    }

    .mb27-form__label {
        font-size: 0.9em;
    }

    .mb27-form__input,
    .mb27-form__textarea,
    .mb27-form__select {
        padding: 10px 12px;
        font-size: 16px; /* Prevents zoom on iOS */
    }

    .mb27-form__textarea {
        min-height: 100px;
    }
}

@media (max-width: 480px) {
    .mb27-form-title {
        font-size: 1.25em;
    }

    .mb27-form__field {
        margin-bottom: 16px;
    }

    .mb27-form__submit {
        padding: 10px 16px;
        font-size: 0.9em;
        width: 100%;
    }

    .mb27-form__submit-wrapper {
        margin-top: 20px;
    }

    .mb27-form__message {
        font-size: 0.9em;
    }
}

/* ==========================================================================
   Accessibility
   ========================================================================== */

/* High contrast mode support */
@media (prefers-contrast: more) {
    .mb27-form__input,
    .mb27-form__textarea,
    .mb27-form__select {
        border-width: 2px;
    }

    .mb27-form__submit {
        border: 2px solid;
    }
}

/* Reduced motion support */
@media (prefers-reduced-motion: reduce) {
    .mb27-form__input:focus,
    .mb27-form__textarea:focus,
    .mb27-form__select:focus,
    .mb27-form__submit:hover {
        box-shadow: none;
    }

    .mb27-form__spinner {
        animation: none;
    }
}
