/* Migo Contact – Light form styles (forms.css)
 *
 * This file styles only the reusable form components:
 *  - .m-form, .m-row, .m-label, .m-input, .m-textarea
 *  - .m-dropzone + file preview (.m-file-preview, .m-file-item, etc.)
 *  - .m-consent checkbox
 *  - .m-btn primary / .m-btn-secondary buttons
 *  - .m-alert global result box
 *
 * It is safe to include on any site – styles are scoped to .m-* classes.
 */

/* --------------------------------------------------
   Example page wrapper (used in /examples)
-------------------------------------------------- */

.m-form-page {
    max-width: 760px;
    margin: 40px auto 48px;
    padding: 0 16px;
    font-family: system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
    color: #111827;
}

/* Wrapper for H1 + description, aligned with .m-form padding */
.m-form-page-header {
    margin-bottom: 1.5rem;
    padding: 0 1.75rem; /* aligns with .m-form padding */
}

.m-form-page-header h1 {
    margin: 0 0 0.5rem;
    font-size: 2rem;
    line-height: 1.25;
    letter-spacing: -0.02em;
}

.m-form-page-header p {
    margin: 0;
    font-size: 0.95rem;
    line-height: 1.6;
    color: #4b5563;
    max-width: 40rem;
}

@media (max-width: 640px) {
    .m-form-page {
        margin: 24px auto 32px;
        padding: 0 12px;
    }

    .m-form-page-header {
        padding: 0 1.25rem;
    }

    .m-form-page-header h1 {
        font-size: 1.6rem;
    }
}

/* --------------------------------------------------
   Core form shell
-------------------------------------------------- */

.m-form {
    --m-color-bg: #ffffff;
    --m-color-border: #e5e7eb;
    --m-color-border-strong: #d1d5db;
    --m-color-text: #111827;
    --m-color-muted: #6b7280;
    --m-color-soft-muted: #9ca3af;
    --m-color-accent: #2563eb;
    --m-color-accent-soft: rgba(37, 99, 235, 0.08);
    --m-color-danger: #e11d48;
    --m-radius-lg: 1rem;
    --m-radius-md: 0.625rem;
    --m-radius-sm: 0.5rem;

    font-family: inherit;
    background-color: var(--m-color-bg);
    border-radius: var(--m-radius-lg);
    border: 1px solid var(--m-color-border);
    padding: 1.5rem 1.75rem;
    color: var(--m-color-text);
    box-shadow:
        0 18px 40px rgba(15, 23, 42, 0.06),
        0 0 0 1px rgba(15, 23, 42, 0.02);
}

.m-form * {
    box-sizing: border-box;
}

/* Generic layout helpers */

.m-row {
    margin-bottom: 1rem;
}

.m-row-group {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 1rem;
    margin-bottom: 1rem;
}

@media (max-width: 640px) {
    .m-row-group {
        grid-template-columns: 1fr;
    }

    .m-form {
        padding: 1.25rem 1.25rem 1.5rem;
        border-radius: 0.875rem;
    }
}

/* Labels & required mark */

.m-label {
    display: block;
    margin-bottom: 0.35rem;
    font-size: 0.875rem;
    font-weight: 500;
    color: var(--m-color-text);
}

.m-required {
    color: var(--m-color-danger);
    font-weight: 600;
}

/* Inputs / textarea / select */

.m-input,
.m-textarea,
.m-form select {
    width: 100%;
    border-radius: var(--m-radius-md);
    border: 1px solid var(--m-color-border-strong);
    background-color: #f9fafb;
    padding: 0.55rem 0.7rem;
    font-size: 0.9rem;
    line-height: 1.5;
    color: var(--m-color-text);
    outline: none;
    transition:
        border-color 0.15s ease,
        box-shadow 0.15s ease,
        background-color 0.15s ease,
        transform 0.08s ease;
}

.m-textarea {
    resize: vertical;
    min-height: 120px;
}

.m-input::placeholder,
.m-textarea::placeholder {
    color: var(--m-color-soft-muted);
}

.m-input:focus,
.m-textarea:focus,
.m-form select:focus {
    background-color: #ffffff;
    border-color: var(--m-color-accent);
    box-shadow:
        0 0 0 1px var(--m-color-accent-soft),
        0 0 0 3px rgba(37, 99, 235, 0.07);
    transform: translateY(-0.5px);
}

/* Number input: remove spinners in most browsers */

.m-input[type="number"]::-webkit-outer-spin-button,
.m-input[type="number"]::-webkit-inner-spin-button {
    -webkit-appearance: none;
    margin: 0;
}

.m-input[type="number"] {
    -moz-appearance: textfield;
}

/* Honeypot – keep invisible */

.m-hp {
    position: absolute;
    left: -9999px;
    top: auto;
    width: 1px;
    height: 1px;
    opacity: 0;
    pointer-events: none;
}

/* Small hints / helper text */

.m-hint {
    margin-top: 0.25rem;
    font-size: 0.8rem;
    color: var(--m-color-muted);
}

/* --------------------------------------------------
   Dropzone + file input
-------------------------------------------------- */

.m-dropzone {
    position: relative;
    border-radius: var(--m-radius-md);
    border: 1px dashed var(--m-color-border-strong);
    background: #f9fafb;
    padding: 0.9rem 0.9rem;
    display: flex;
    align-items: center;
    gap: 0.75rem;
    cursor: pointer;
    transition:
        border-color 0.15s ease,
        background-color 0.15s ease,
        box-shadow 0.15s ease,
        transform 0.08s ease;
}

.m-dropzone:hover {
    border-color: var(--m-color-accent);
    background: #f3f4ff;
    box-shadow: 0 12px 24px rgba(15, 23, 42, 0.06);
    transform: translateY(-1px);
}

.m-dropzone-icon {
    flex-shrink: 0;
    width: 2.4rem;
    height: 2.4rem;
    border-radius: 0.9rem;
    background: linear-gradient(135deg, #e0f2fe, #fef3c7);
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 1.2rem;
}

.m-dropzone-text {
    flex: 1 1 auto;
    min-width: 0;
    font-size: 0.85rem;
    line-height: 1.5;
    color: var(--m-color-muted);
}

.m-dropzone-text strong {
    display: inline-block;
    font-size: 0.88rem;
    color: var(--m-color-text);
}

.m-dropzone-text span {
    display: block;
    margin-top: 0.1rem;
    font-size: 0.82rem;
    color: var(--m-color-muted);
    overflow-wrap: anywhere;
    word-break: break-word;
}

/* Actual file input – hidden, handled by JS */

.m-file {
    position: absolute;
    inset: 0;
    opacity: 0;
    cursor: pointer;
}

/* Mobile adjustments for dropzone */

@media (max-width: 480px) {
    .m-dropzone {
        flex-direction: column;
        align-items: center;
        text-align: center;
        padding: 0.85rem 0.85rem;
    }

    .m-dropzone-text {
        text-align: center;
    }
}

/* --------------------------------------------------
   File preview list (data-m-preview)
-------------------------------------------------- */

.m-file-preview {
    margin-top: 0.75rem;
    display: flex;
    flex-direction: column;
    gap: 0.45rem;
}

/* Optional placeholder: "no files yet" */
.m-file-preview-empty {
    font-size: 0.8rem;
    color: var(--m-color-muted);
    font-style: italic;
}

/* Single file row */
.m-file-item {
    display: flex;
    align-items: center;
    gap: 0.6rem;
    font-size: 0.8rem;
    padding: 0.45rem 0.6rem;
    border-radius: 0.75rem;
    border: 1px solid var(--m-color-border);
    background: #f9fafb;
    color: var(--m-color-text);
    box-shadow: 0 4px 10px rgba(15, 23, 42, 0.03);
}

/* Main wrapper for icon + text */
.m-file-item-main {
    display: flex;
    align-items: center;
    gap: 0.6rem;
    min-width: 0;
    flex: 1 1 auto;
}

/* Icon / thumbnail square (40x40) */
.m-file-item-icon {
    flex: 0 0 40px;
    width: 40px;
    height: 40px;
    border-radius: 0.75rem;
    background-color: #e5e7eb;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 0.7rem;
    font-weight: 600;
    text-transform: uppercase;
    overflow: hidden;
}

/* Thumbnail image */
.m-file-item-thumb {
    width: 100%;
    height: 100%;
    display: block;
    object-fit: cover;
    border-radius: inherit;
}

/* Text wrapper (name + size) */
.m-file-item-text {
    flex: 1 1 auto;
    min-width: 0;
}

.m-file-item-name {
    font-size: 0.85rem;
    font-weight: 500;
    color: var(--m-color-text);
    display: block;
    white-space: nowrap;
    text-overflow: ellipsis;
    overflow: hidden;
    max-width: 100%;
}

.m-file-item-meta {
    font-size: 0.78rem;
    color: var(--m-color-muted);
}

/* Remove (X) button – text only, no background */
.m-file-item-remove,
.m-file-remove {
    margin-left: auto;
    flex: 0 0 auto;
    border: none;
    background: transparent;
    color: var(--m-color-soft-muted);
    cursor: pointer;
    padding: 0;
    font-size: 0.85rem;
    line-height: 1;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    transition:
        color 0.15s ease,
        transform 0.08s ease;
}

.m-file-item-remove:hover,
.m-file-remove:hover {
    color: #b91c1c;
    transform: translateY(-0.5px);
}

.m-file-item-remove:active,
.m-file-remove:active {
    transform: translateY(0);
}

/* Error state for invalid file (extension / size) */

.m-file-item--error {
    border-color: #fecaca;
    background-color: #fef2f2;
}

.m-file-item--error .m-file-item-name,
.m-file-item--error .m-file-item-meta {
    color: #b91c1c;
}

/* --------------------------------------------------
   Consent checkbox
-------------------------------------------------- */

.m-consent {
    display: inline-flex;
    align-items: flex-start;
    gap: 0.55rem;
    font-size: 0.86rem;
    color: var(--m-color-muted);
    cursor: pointer;
}

.m-consent-input {
    margin-top: 0.12rem;
    flex-shrink: 0;
    width: 1.05rem;
    height: 1.05rem;
    accent-color: var(--m-color-accent);
}

.m-consent-text {
    line-height: 1.4;
}

/* --------------------------------------------------
   Buttons
-------------------------------------------------- */

.m-btn,
.m-btn-secondary {
    position: relative;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 0.35rem;
    padding: 0.55rem 1.1rem;
    border-radius: 999px;
    font-size: 0.9rem;
    font-weight: 600;
    cursor: pointer;
    border: 1px solid transparent;
    text-decoration: none;
    white-space: nowrap;
    transition:
        background-color 0.15s ease,
        border-color 0.15s ease,
        color 0.15s ease,
        box-shadow 0.15s ease,
        transform 0.08s ease;
}

/* Primary button – dark neutral with arrow */

.m-btn {
    background: linear-gradient(135deg, #111827, #0f172a);
    color: #f9fafb;
    border-color: #020617;
    box-shadow:
        0 16px 30px rgba(15, 23, 42, 0.18),
        0 0 0 1px rgba(248, 250, 252, 0.02);
}

.m-btn::after {
    content: "↗";
    font-size: 0.9em;
    margin-left: 0.35rem;
    opacity: 0.9;
    transform: translateX(0);
    transition:
        transform 0.15s ease,
        opacity 0.15s ease;
}

.m-btn:hover {
    background: linear-gradient(135deg, #020617, #111827);
    box-shadow:
        0 18px 34px rgba(15, 23, 42, 0.22),
        0 0 0 1px rgba(15, 23, 42, 0.4);
    transform: translateY(-1px);
}

.m-btn:hover::after {
    transform: translateX(3px);
    opacity: 1;
}

.m-btn:active {
    transform: translateY(0);
    box-shadow:
        0 10px 20px rgba(15, 23, 42, 0.18),
        0 0 0 1px rgba(15, 23, 42, 0.55);
}

/* Secondary (ghost) button */

.m-btn-secondary {
    background: transparent;
    color: var(--m-color-text);
    border-color: var(--m-color-border-strong);
}

.m-btn-secondary:hover {
    background: #f9fafb;
    border-color: var(--m-color-accent);
    color: #111827;
    box-shadow: 0 10px 22px rgba(15, 23, 42, 0.08);
    transform: translateY(-1px);
}

.m-btn-secondary:active {
    transform: translateY(0);
    box-shadow: 0 6px 12px rgba(15, 23, 42, 0.06);
}

/* Disabled state */

.m-btn[disabled],
.m-btn-secondary[disabled] {
    cursor: default;
    opacity: 0.65;
    box-shadow: none;
    transform: none;
}

/* Footer area for forms that place button + note together */

.m-form-footer {
    margin-top: 0.9rem;
    display: flex;
    align-items: center;
    gap: 0.75rem;
}

/* --------------------------------------------------
   Global result alert (data-m-result)
-------------------------------------------------- */

.m-alert {
    margin-top: 0.9rem;
    border-radius: 0.85rem;
    border: 1px solid var(--m-color-border);
    background: #f9fafb;
    padding: 0.6rem 0.9rem;
    font-size: 0.86rem;
    color: var(--m-color-muted);
    display: none; /* forms.js toggles visibility */
    align-items: center;
    gap: 0.45rem;
    word-break: break-word;
    overflow-wrap: anywhere;
}

/* Animated status dot inside alert */
.m-alert::before {
    content: "";
    flex-shrink: 0;
    width: 6px;
    height: 6px;
    border-radius: 999px;
    background: currentColor;
    box-shadow: 0 0 0 3px rgba(148, 163, 184, 0.25);
    transform: scale(1);
    opacity: 0.8;
}

/* Visible state */
.m-alert.is-visible {
    display: inline-flex;
    width: 100%;
}

/* Success / error – supports both BEM (.m-alert--success) and .is-success */

.m-alert--success,
.m-alert.is-success {
    background: #ecfdf5;
    border-color: #bbf7d0;
    color: #166534;
}

.m-alert--error,
.m-alert.is-error {
    background: #fef2f2;
    border-color: #fecaca;
    color: #b91c1c;
}

/* Success dot animation */
.m-alert--success::before,
.m-alert.is-success::before {
    background: #22c55e;
    box-shadow: 0 0 0 3px rgba(34, 197, 94, 0.25);
    animation: m-alert-pulse-success 1.8s ease-out infinite;
}

/* Error dot animation */
.m-alert--error::before,
.m-alert.is-error::before {
    background: #ef4444;
    box-shadow: 0 0 0 3px rgba(248, 113, 113, 0.28);
    animation: m-alert-pulse-error 1.8s ease-out infinite;
}

/* If JS only sets .is-visible, treat it as an error */
.m-alert.is-visible:not(.m-alert--success):not(.m-alert--error):not(.is-success) {
    background: #fef2f2;
    border-color: #fecaca;
    color: #b91c1c;
}

/* Alert pulse animations */

@keyframes m-alert-pulse-success {
    0% {
        opacity: 0.9;
        transform: scale(1);
        box-shadow: 0 0 0 2px rgba(34, 197, 94, 0.3);
    }
    60% {
        opacity: 0;
        transform: scale(1.6);
        box-shadow: 0 0 0 8px rgba(34, 197, 94, 0);
    }
    100% {
        opacity: 0;
        transform: scale(1.6);
        box-shadow: 0 0 0 8px rgba(34, 197, 94, 0);
    }
}

@keyframes m-alert-pulse-error {
    0% {
        opacity: 0.9;
        transform: scale(1);
        box-shadow: 0 0 0 2px rgba(248, 113, 113, 0.35);
    }
    60% {
        opacity: 0;
        transform: scale(1.6);
        box-shadow: 0 0 0 8px rgba(248, 113, 113, 0);
    }
    100% {
        opacity: 0;
        transform: scale(1.6);
        box-shadow: 0 0 0 8px rgba(248, 113, 113, 0);
    }
}

/* --------------------------------------------------
   Field-level validation errors
-------------------------------------------------- */

.m-has-error .m-input,
.m-has-error .m-textarea,
.m-has-error select.m-input,
.m-input[aria-invalid="true"],
.m-textarea[aria-invalid="true"],
.m-form select[aria-invalid="true"] {
    border-color: var(--m-color-danger);
    box-shadow:
        0 0 0 1px rgba(225, 29, 72, 0.14),
        0 0 0 3px rgba(248, 113, 113, 0.16);
}

/* Small note next to / under error messages */

.m-error-text,
.m-field-error,
[data-m-error] {
    margin-top: 0.25rem;
    font-size: 0.78rem;
    color: var(--m-color-danger);
}
