/*
 * Professional Service Request Manager – frontend styles.
 *
 * Bootstrap 5 is loaded as a dependency. This file integrates the custom
 * open/close behaviour (driven by `is-open` / JS classes) with Bootstrap's
 * component styles (modal-content, form-control, btn, etc.) and applies the
 * site's IranSans font and custom design tokens throughout.
 */

:root {
    --psrm-color-primary:       #2563eb;
    --psrm-color-primary-hover: #1d4ed8;
    --psrm-color-danger:        #dc2626;
    --psrm-color-success:       #16a34a;
    --psrm-color-bg:            #ffffff;
    --psrm-color-surface:       #f8fafc;
    --psrm-color-border:        #e2e8f0;
    --psrm-color-text:          #0f172a;
    --psrm-color-text-muted:    #64748b;
    --psrm-radius:              12px;
    --psrm-radius-sm:           6px;
    --psrm-shadow:              0 20px 60px -10px rgba(15, 23, 42, 0.35);
    --psrm-font:                "IranSans", sans-serif;
    --psrm-transition:          260ms ease;
}

@media (prefers-color-scheme: dark) {
    :root {
        --psrm-color-bg:         #111827;
        --psrm-color-surface:    #1f2937;
        --psrm-color-border:     #374151;
        --psrm-color-text:       #f1f5f9;
        --psrm-color-text-muted: #94a3b8;
        --psrm-shadow:           0 20px 60px -10px rgba(0, 0, 0, 0.6);
    }
}

/* ── Scroll lock ──────────────────────────────────────────────────────────── */

body.psrm-scroll-locked {
    overflow: hidden;
}

/* ── Modal backdrop overlay ───────────────────────────────────────────────── */

.psrm-modal {
    position: fixed;
    inset: 0;
    z-index: 100000;
    display: none;
    overflow-x: hidden;
    overflow-y: auto;
    font-family: var(--psrm-font);
    color: var(--psrm-color-text);
}

.psrm-modal.is-open {
    display: block;
}

.psrm-modal__overlay {
    position: fixed;
    inset: 0;
    z-index: 0;
    background: rgba(15, 23, 42, 0.55);
    opacity: 0;
    transition: opacity var(--psrm-transition);
}

.psrm-modal.is-open .psrm-modal__overlay {
    opacity: 1;
}

/* ── Dialog wrapper – animation shell only ────────────────────────────────── */

/*
 * Bootstrap's .modal-dialog-centered applies display:flex which interferes
 * with margin-auto horizontal centering. We reset to block here so the
 * custom width + margin: auto centering works reliably.
 * pointer-events: auto overrides Bootstrap's .modal-dialog { pointer-events: none }.
 */
.psrm-modal__dialog {
    position: relative;
    z-index: 1;
    display: block !important;
    width: min(92vw, 560px);
    margin: 5vh auto 3rem;
    pointer-events: auto;
    /* entrance animation */
    opacity: 0;
    transform: translateY(24px) scale(0.97);
    transition: transform var(--psrm-transition), opacity var(--psrm-transition);
}

.psrm-modal.is-open .psrm-modal__dialog {
    opacity: 1;
    transform: translateY(0) scale(1);
}

/* ── Visual card (Bootstrap modal-content) ────────────────────────────────── */

.psrm-modal .modal-content {
    font-family: var(--psrm-font);
    background-color: var(--psrm-color-bg);
    color: var(--psrm-color-text);
    border: 1px solid var(--psrm-color-border);
    border-radius: var(--psrm-radius);
    box-shadow: var(--psrm-shadow);
    overflow: hidden;
}

/* ── Modal header ─────────────────────────────────────────────────────────── */

.psrm-modal .modal-header {
    padding: 1.25rem 1.5rem;
    border-bottom: 1px solid var(--psrm-color-border);
    background-color: var(--psrm-color-surface);
}

.psrm-modal .modal-title {
    font-family: var(--psrm-font);
    font-size: 1.2rem;
    font-weight: 700;
    color: var(--psrm-color-text);
}

.psrm-modal .btn-close {
    opacity: 0.55;
    transition: opacity var(--psrm-transition);
}

.psrm-modal .btn-close:hover {
    opacity: 1;
}

/* ── Modal body ───────────────────────────────────────────────────────────── */

.psrm-modal .modal-body {
    padding: 1.5rem;
}

.psrm-modal__intro {
    margin: 0 0 1.25rem;
    font-family: var(--psrm-font);
    font-size: 0.9rem;
    color: var(--psrm-color-text-muted);
}

/* ── Form labels ──────────────────────────────────────────────────────────── */

.psrm-modal .form-label {
    font-family: var(--psrm-font);
    font-weight: 600;
    font-size: 0.875rem;
    color: var(--psrm-color-text);
    margin-bottom: 0.4rem;
}

.psrm-form__required {
    color: var(--psrm-color-danger);
    margin-right: 2px;
}

/* ── Form controls ────────────────────────────────────────────────────────── */

.psrm-modal .form-control,
.psrm-modal .form-select {
    font-family: var(--psrm-font);
    font-size: 0.9rem;
    color: var(--psrm-color-text);
    background-color: var(--psrm-color-bg);
    border: 1px solid var(--psrm-color-border);
    border-radius: var(--psrm-radius-sm);
    transition: border-color var(--psrm-transition), box-shadow var(--psrm-transition);
}

.psrm-modal .form-control:focus,
.psrm-modal .form-select:focus {
    color: var(--psrm-color-text);
    background-color: var(--psrm-color-bg);
    border-color: var(--psrm-color-primary);
    box-shadow: 0 0 0 3px rgba(37, 99, 235, 0.18);
    outline: none;
}

.psrm-modal textarea.form-control {
    resize: vertical;
    min-height: 7rem;
}

.psrm-modal .form-text {
    font-family: var(--psrm-font);
    font-size: 0.78rem;
    color: var(--psrm-color-text-muted);
}

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

.psrm-form__error {
    display: block;
    margin-top: 0.3rem;
    font-family: var(--psrm-font);
    font-size: 0.8rem;
    color: var(--psrm-color-danger);
    min-height: 1em;
}

.psrm-form__row.has-error .form-control,
.psrm-form__row.has-error .form-select {
    border-color: var(--psrm-color-danger);
}

/* ── Feedback banner (success / error) ────────────────────────────────────── */

.psrm-form__feedback {
    display: none;
    margin-bottom: 1rem;
    padding: 0.75em 1em;
    border-radius: var(--psrm-radius-sm);
    font-family: var(--psrm-font);
    font-size: 0.88rem;
}

.psrm-form__feedback.is-success {
    display: block;
    background: rgba(22, 163, 74, 0.1);
    color: var(--psrm-color-success);
    animation: psrm-fade-in var(--psrm-transition);
}

.psrm-form__feedback.is-error {
    display: block;
    background: rgba(220, 38, 38, 0.1);
    color: var(--psrm-color-danger);
    animation: psrm-shake 320ms ease;
}

/* ── Modal footer / form actions ──────────────────────────────────────────── */

.psrm-modal .modal-footer {
    padding: 1rem 1.5rem;
    border-top: 1px solid var(--psrm-color-border);
    background-color: var(--psrm-color-surface);
    gap: 0.75rem;
}

/* ── Buttons ──────────────────────────────────────────────────────────────── */

.psrm-modal .btn {
    font-family: var(--psrm-font);
    font-weight: 600;
    display: inline-flex;
    align-items: center;
    gap: 0.45em;
}

.psrm-modal .btn-primary {
    background-color: var(--psrm-color-primary);
    border-color: var(--psrm-color-primary);
    color: #fff;
}

.psrm-modal .btn-primary:hover,
.psrm-modal .btn-primary:focus-visible {
    background-color: var(--psrm-color-primary-hover);
    border-color: var(--psrm-color-primary-hover);
    color: #fff;
}

.psrm-modal .btn-primary:disabled {
    background-color: var(--psrm-color-primary);
    border-color: var(--psrm-color-primary);
    opacity: 0.65;
}

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

.psrm-modal .btn-secondary:hover,
.psrm-modal .btn-secondary:focus-visible {
    background-color: var(--psrm-color-surface);
    border-color: var(--psrm-color-border);
    color: var(--psrm-color-text);
}

/* ── Submit-button loading state (spinner) ────────────────────────────────── */

/* The spinner uses Bootstrap's .spinner-border class for the animation;
   we only need to control its visibility. */
.psrm-btn__spinner {
    display: none;
    width: 1em;
    height: 1em;
}

.psrm-btn.is-loading .psrm-btn__spinner {
    display: inline-block;
}

.psrm-btn.is-loading .psrm-btn__label {
    opacity: 0.85;
}

/* ── Result card (post-submission summary) ────────────────────────────────── */

.psrm-result__list dt,
.psrm-result__list dd {
    font-family: var(--psrm-font);
    color: var(--psrm-color-text);
}

/* ── Honeypot (hidden from real users) ───────────────────────────────────── */

.psrm-form__honeypot {
    position: absolute !important;
    width: 1px;
    height: 1px;
    overflow: hidden;
    opacity: 0;
    pointer-events: none;
    left: -9999px;
}

/* ── Post-success state: hide the form ────────────────────────────────────── */

.psrm-form.is-submitted-success .psrm-form__control,
.psrm-form.is-submitted-success .modal-footer {
    display: none;
}

/* ── Keyframe animations ──────────────────────────────────────────────────── */

@keyframes psrm-fade-in {
    from { opacity: 0; transform: translateY(-4px); }
    to   { opacity: 1; transform: translateY(0); }
}

@keyframes psrm-shake {
    10%, 90% { transform: translateX(-1px); }
    20%, 80% { transform: translateX(2px); }
    30%, 50%, 70% { transform: translateX(-4px); }
    40%, 60% { transform: translateX(4px); }
}

/* ── RTL support ──────────────────────────────────────────────────────────── */

[dir="rtl"] .psrm-modal .modal-footer {
    justify-content: flex-start;
}

[dir="rtl"] .psrm-modal .btn-close {
    margin-left: 0;
    margin-right: auto;
}

[dir="rtl"] .psrm-form__required {
    margin-right: 0;
    margin-left: 2px;
}
