/* =============================================================================
   AQ Journey: shared UX components for the admin/partner journey
   - Top progress bar (page navigation feedback)
   - Toast notifications (success / error / warning / info)
   - Confirmation modal (destructive action gate)
   - Full-page loading overlay
   ============================================================================= */

:root {
    --aq-journey-primary: var(--Primary-500, #6A5D8B);
    --aq-journey-primary-dark: #5a4e7a;
    --aq-journey-success: #10B981;
    --aq-journey-success-bg: #ECFDF5;
    --aq-journey-error: #DB3A34;
    --aq-journey-error-bg: #FEF2F2;
    --aq-journey-warning: #F59E0B;
    --aq-journey-warning-bg: #FFFBEB;
    --aq-journey-info: #3B82F6;
    --aq-journey-info-bg: #EFF6FF;
    --aq-journey-z-progress: 9998;
    --aq-journey-z-toast: 9999;
    --aq-journey-z-overlay: 10000;
    --aq-journey-z-modal: 10001;
}

/* ─────────────────────────────────────────────────────────
   1) Top Progress Bar — slim coloured bar across page top
   ───────────────────────────────────────────────────────── */
.aq-progress-bar {
    position: fixed;
    top: 0;
    inset-inline-start: 0;
    width: 0;
    height: 3px;
    background: linear-gradient(90deg, var(--aq-journey-primary) 0%, #9A8BB7 50%, var(--aq-journey-primary) 100%);
    background-size: 200% 100%;
    z-index: var(--aq-journey-z-progress);
    pointer-events: none;
    transition: width 0.18s ease-out, opacity 0.3s ease;
    box-shadow: 0 0 8px rgba(106, 93, 139, 0.45);
    opacity: 0;
}

.aq-progress-bar.is-active {
    opacity: 1;
    animation: aq-progress-shimmer 1.4s linear infinite;
}

.aq-progress-bar.is-finishing {
    width: 100% !important;
    opacity: 0;
    transition: width 0.2s ease-out, opacity 0.4s ease 0.15s;
}

@keyframes aq-progress-shimmer {
    0%   { background-position: 100% 50%; }
    100% { background-position: -100% 50%; }
}

/* Make the progress bar a touch more visible (was 3px) so users notice navigation. */
.aq-progress-bar {
    height: 4px;
}

/* ─────────────────────────────────────────────────────────
   1.b) Side-menu navigation feedback — instant in-place spinner
   When a sidebar item is clicked, JS adds `.aq-nav-loading` so the
   user gets immediate visual confirmation that the click registered,
   even before the next page begins to render.
   ───────────────────────────────────────────────────────── */
.aq-nav-loading {
    position: relative;
    pointer-events: none;
}

.aq-nav-loading::after {
    content: "";
    position: absolute;
    inset-inline-end: 12px;
    top: 50%;
    width: 14px;
    height: 14px;
    margin-top: -7px;
    border: 2px solid rgba(106, 93, 139, 0.25);
    border-top-color: var(--aq-journey-primary);
    border-radius: 50%;
    animation: aq-nav-spin 0.7s linear infinite;
    z-index: 2;
}

/* While loading, give the tile the active visual (purple wash + bold accent) so the
   user sees their selection take effect immediately. */
.aq-nav-loading {
    background: var(--Primary-50, #F3F2F6) !important;
    border-inline-start: 3px solid var(--aq-journey-primary) !important;
    box-shadow: 0 1px 2px rgba(106, 93, 139, 0.08) !important;
}

@keyframes aq-nav-spin {
    to { transform: rotate(360deg); }
}

/* Simple full-page loader — same visual as header account switching. */
.aqr-switch-overlay {
    position: fixed;
    inset: 0;
    z-index: 999999;
    background: rgba(255, 255, 255, 0.7);
    display: flex;
    align-items: center;
    justify-content: center;
}

.aqr-switch-overlay__spinner {
    width: 44px;
    height: 44px;
    border: 4px solid #e0d9f0;
    border-top-color: #6A5D8B;
    border-radius: 50%;
    animation: aqr-switch-spin 0.7s linear infinite;
}

@keyframes aqr-switch-spin {
    to { transform: rotate(360deg); }
}

/* ─────────────────────────────────────────────────────────
   2) Toast Notifications — banner alerts (top-end stack)
   ───────────────────────────────────────────────────────── */
.aq-toast-container {
    position: fixed;
    /* Sit below the client fixed header when present; admin/partner fall back to 24px. */
    top: max(24px, calc(var(--client-fixed-header-offset, 24px) + 8px));
    inset-inline-end: 24px;
    /* Above #mainHeader (uses extreme z-index) and flash-toast fallback. */
    z-index: 2147483647;
    display: flex;
    flex-direction: column;
    gap: 12px;
    max-width: 420px;
    width: calc(100vw - 48px);
    pointer-events: none;
}

.aq-toast {
    pointer-events: auto;
    display: flex;
    align-items: center;
    gap: 14px;
    padding: 16px 18px;
    border-radius: 8px;
    border: 1px solid transparent;
    box-shadow: none;
    animation: aq-toast-in 0.3s cubic-bezier(0.16, 1, 0.3, 1);
    position: relative;
    overflow: hidden;
}

.aq-toast.is-leaving {
    animation: aq-toast-out 0.25s ease-in forwards;
}

[dir="rtl"] .aq-toast {
    animation-name: aq-toast-in-rtl;
}

[dir="rtl"] .aq-toast.is-leaving {
    animation-name: aq-toast-out-rtl;
}

@keyframes aq-toast-in {
    from { opacity: 0; transform: translateX(20px); }
    to   { opacity: 1; transform: translateX(0); }
}
@keyframes aq-toast-out {
    from { opacity: 1; transform: translateX(0); }
    to   { opacity: 0; transform: translateX(20px); }
}
@keyframes aq-toast-in-rtl {
    from { opacity: 0; transform: translateX(-20px); }
    to   { opacity: 1; transform: translateX(0); }
}
@keyframes aq-toast-out-rtl {
    from { opacity: 1; transform: translateX(0); }
    to   { opacity: 0; transform: translateX(-20px); }
}

/* Banner alert variants */
.aq-toast--info {
    background: #eff6ff;
    border-color: #3b82f6;
}

.aq-toast--success {
    background: #ecfdf5;
    border-color: #10b981;
}

.aq-toast--error {
    background: #fef2f2;
    border-color: #f87171;
    border-style: dashed;
}

.aq-toast--warning {
    background: #fffbeb;
    border-color: #fbbf24;
    border-style: dashed;
}

.aq-toast__icon {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 40px;
    height: 40px;
    border-radius: 8px;
    flex-shrink: 0;
}

.aq-toast--info .aq-toast__icon { background: rgba(59, 130, 246, 0.12); color: #2563eb; }
.aq-toast--success .aq-toast__icon { background: rgba(16, 185, 129, 0.12); color: #059669; }
.aq-toast--error .aq-toast__icon { background: rgba(248, 113, 113, 0.15); color: #dc2626; }
.aq-toast--warning .aq-toast__icon { background: rgba(251, 191, 36, 0.15); color: #d97706; }

.aq-toast__icon svg { width: 22px; height: 22px; }

.aq-toast__body {
    flex: 1 1 auto;
    min-width: 0;
}

.aq-toast__title {
    font-size: 14px;
    font-weight: 700;
    line-height: 1.35;
    margin: 0 0 4px 0;
}

.aq-toast--info .aq-toast__title { color: #1e3a8a; }
.aq-toast--success .aq-toast__title { color: #065f46; }
.aq-toast--error .aq-toast__title { color: #991b1b; }
.aq-toast--warning .aq-toast__title { color: #92400e; }

.aq-toast__message {
    font-size: 13px;
    line-height: 1.5;
    margin: 0;
    word-break: break-word;
}

.aq-toast__message--solo {
    font-size: 14px;
    font-weight: 700;
    line-height: 1.35;
}

.aq-toast--info .aq-toast__message--solo { color: #1e3a8a; }
.aq-toast--success .aq-toast__message--solo { color: #065f46; }
.aq-toast--error .aq-toast__message--solo { color: #991b1b; }
.aq-toast--warning .aq-toast__message--solo { color: #92400e; }

.aq-toast--info .aq-toast__message { color: #475569; }
.aq-toast--success .aq-toast__message { color: #047857; }
.aq-toast--error .aq-toast__message { color: #7f1d1d; }
.aq-toast--warning .aq-toast__message { color: #78350f; }

.aq-toast__close {
    flex-shrink: 0;
    width: 28px;
    height: 28px;
    background: transparent;
    border: none;
    cursor: pointer;
    border-radius: 6px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    padding: 0;
    align-self: flex-start;
    margin-top: 2px;
    transition: background 0.15s ease, color 0.15s ease;
}

.aq-toast--info .aq-toast__close { color: #3b82f6; }
.aq-toast--success .aq-toast__close { color: #10b981; }
.aq-toast--error .aq-toast__close { color: #ef4444; }
.aq-toast--warning .aq-toast__close { color: #f59e0b; }

.aq-toast__close:hover {
    background: rgba(0, 0, 0, 0.06);
}

.aq-toast__close svg { width: 16px; height: 16px; }

/* Auto-dismiss progress strip */
.aq-toast__progress {
    position: absolute;
    bottom: 0;
    inset-inline-start: 0;
    height: 2px;
    background: currentColor;
    opacity: 0.35;
    width: 100%;
    transform-origin: left;
    animation: aq-toast-progress linear forwards;
}

[dir="rtl"] .aq-toast__progress {
    transform-origin: right;
}

.aq-toast--success .aq-toast__progress { color: var(--aq-journey-success); }
.aq-toast--error   .aq-toast__progress { color: var(--aq-journey-error); }
.aq-toast--warning .aq-toast__progress { color: var(--aq-journey-warning); }
.aq-toast--info    .aq-toast__progress { color: var(--aq-journey-info); }

@keyframes aq-toast-progress {
    from { transform: scaleX(1); }
    to   { transform: scaleX(0); }
}

/* ─────────────────────────────────────────────────────────
   3) SweetAlert-style modal (alert + confirm)
   ───────────────────────────────────────────────────────── */
.aq-swal-backdrop,
.aq-modal-backdrop {
    position: fixed;
    inset: 0;
    background: rgba(55, 42, 88, 0.42);
    backdrop-filter: blur(4px);
    -webkit-backdrop-filter: blur(4px);
    z-index: var(--aq-journey-z-modal);
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 1.25rem;
    animation: aq-fade-in 0.22s ease-out;
}

/* The backdrop above is a native <dialog> (see aq-journey.js): the services composers are
   <dialog>s in the browser's TOP LAYER, and nothing outside that layer can paint above them at
   any z-index. These rules undo the UA's dialog box — fit-content sizing, auto margin, a solid
   border, a max-width — so it stretches back to the full-viewport overlay the rule above
   describes. Without `width/height: auto` the `inset: 0` above cannot stretch it, because the
   UA's `width: fit-content` wins the sizing. */
dialog.aq-swal-backdrop,
dialog.aq-modal-backdrop {
    width: auto;
    height: auto;
    max-width: none;
    max-height: none;
    margin: 0;
    border: 0;
    color: inherit;
    overflow: visible;
}

/* The dim and the blur live on the element itself, so the UA's own backdrop must not add a
   second darker layer on top of it. */
dialog.aq-swal-backdrop::backdrop,
dialog.aq-modal-backdrop::backdrop {
    background: transparent;
}

@keyframes aq-fade-in  { from { opacity: 0; } to { opacity: 1; } }
@keyframes aq-fade-out { from { opacity: 1; } to { opacity: 0; } }

.aq-swal-backdrop.is-leaving,
.aq-modal-backdrop.is-leaving {
    animation: aq-fade-out 0.18s ease-in forwards;
}

.aq-swal,
.aq-modal {
    --aq-swal-accent: #6a5d8b;
    --aq-swal-ink: #372a58;
    --aq-swal-muted: #5a5272;
    --aq-swal-border: #e0dae8;
    --aq-swal-danger: #d92d20;
    --aq-swal-danger-hover: #b42318;
    --aq-swal-danger-soft: #fef3f2;
    --aq-swal-warning: #dc6803;
    --aq-swal-warning-soft: #fffaeb;
    background: #fff;
    border: 1px solid var(--aq-swal-border);
    border-radius: 1.125rem;
    box-shadow:
        0 20px 40px rgba(55, 42, 88, 0.14),
        0 6px 14px rgba(55, 42, 88, 0.06);
    width: 100%;
    max-width: 34rem;
    padding: 2.5rem 2.25rem 2rem;
    text-align: center;
    animation: aq-swal-in 0.28s cubic-bezier(0.16, 1, 0.3, 1);
    box-sizing: border-box;
    font-family: "IBM Plex Sans Arabic", "Cairo", "Helvetica", sans-serif;
}

.aq-swal-backdrop.is-leaving .aq-swal,
.aq-modal-backdrop.is-leaving .aq-modal {
    animation: aq-swal-out 0.18s ease-in forwards;
}

@keyframes aq-swal-in {
    from { opacity: 0; transform: scale(0.94) translateY(8px); }
    to   { opacity: 1; transform: scale(1) translateY(0); }
}
@keyframes aq-swal-out {
    from { opacity: 1; transform: scale(1); }
    to   { opacity: 0; transform: scale(0.96); }
}

.aq-swal__icon-wrap {
    display: flex;
    justify-content: center;
    margin-bottom: 1.25rem;
}

.aq-swal__icon {
    width: 3.75rem;
    height: 3.75rem;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    box-sizing: border-box;
}

.aq-swal__icon--success {
    background: #ecfdf5;
    color: #059669;
}

.aq-swal__icon--error {
    background: var(--aq-swal-danger-soft);
    color: var(--aq-swal-danger);
}

.aq-swal__icon--warning {
    background: var(--aq-swal-warning-soft);
    color: var(--aq-swal-warning);
}

.aq-swal__icon--info,
.aq-swal__icon--question {
    background: rgba(106, 93, 139, 0.1);
    color: var(--aq-swal-accent);
}

.aq-swal__svg {
    width: 1.75rem;
    height: 1.75rem;
}

/* Content lang drives bidi — partner shell may invert layout dir while body is always rtl. */
.aq-swal[lang="en"],
.aq-modal[lang="en"] {
    direction: ltr !important;
    unicode-bidi: isolate;
}

.aq-swal[lang="ar"],
.aq-modal[lang="ar"] {
    direction: rtl !important;
    unicode-bidi: isolate;
}

.aq-swal__title {
    margin: 0 0 0.875rem;
    padding: 0 0.5rem;
    font-size: 1.25rem !important;
    font-weight: 500 !important;
    color: var(--aq-swal-ink);
    line-height: 1.45 !important;
    letter-spacing: 0 !important;
    text-align: center;
    unicode-bidi: isolate;
}

.aq-modal__title {
    font-size: 17px;
    font-weight: 700;
    color: #111827;
    margin: 0;
    line-height: 1.3;
    text-align: start;
    flex: 1 1 auto;
    min-width: 0;
}

.aq-swal__content {
    margin: 0 auto;
    padding: 0 0.5rem;
    max-width: 28rem;
    font-size: 1rem;
    font-weight: 400;
    color: var(--aq-swal-muted);
    line-height: 1.65;
    word-break: break-word;
    text-align: center;
    unicode-bidi: isolate;
}

.aq-swal__actions {
    display: flex;
    flex-wrap: wrap;
    align-items: stretch;
    justify-content: center;
    gap: 0.875rem;
    margin-top: 1.875rem;
}

.aq-swal__btn {
    border: 0;
    border-radius: 0.625rem;
    font-size: 0.9375rem;
    font-weight: 600;
    padding: 0.8125rem 1.25rem;
    min-height: 2.875rem;
    cursor: pointer;
    font-family: inherit;
    transition: background 0.15s ease, color 0.15s ease, border-color 0.15s ease, transform 0.1s ease, box-shadow 0.15s ease;
    min-width: 6.5rem;
    line-height: 1.25;
}

.aq-swal__btn--cancel {
    background: #faf9fc;
    color: var(--aq-swal-ink);
    border: 1px solid #cfc8dc;
    box-shadow: none;
}

.aq-swal__btn--cancel:hover {
    background: #f3f1f7;
    border-color: #b8afc8;
    color: var(--aq-swal-ink);
}

.aq-swal__btn--primary {
    background: var(--aq-swal-accent);
    color: #fff;
    box-shadow: 0 4px 12px rgba(106, 93, 139, 0.28);
}

.aq-swal__btn--primary:hover {
    background: #5c5080;
}

.aq-swal__btn--danger {
    background: var(--aq-swal-danger);
    color: #fff;
    box-shadow: 0 2px 8px rgba(217, 45, 32, 0.28);
}

.aq-swal__btn--danger:hover {
    background: var(--aq-swal-danger-hover);
    box-shadow: 0 4px 12px rgba(217, 45, 32, 0.32);
}

.aq-swal__btn:active {
    transform: scale(0.98);
}

.aq-swal__btn:focus-visible {
    outline: 2px solid rgba(106, 93, 139, 0.45);
    outline-offset: 2px;
}

.aq-swal__btn--danger:focus-visible {
    outline-color: rgba(220, 38, 38, 0.45);
}

.aq-swal--confirm .aq-swal__actions {
    flex-direction: row;
    justify-content: stretch;
}

.aq-swal--confirm .aq-swal__btn {
    flex: 1 1 0;
    min-width: 0;
}

/* Use the dialog's own dir — not the page/shell — so EN dialogs stay correct on RTL partner layout. */
.aq-swal[dir="rtl"].aq-swal--confirm .aq-swal__actions {
    flex-direction: row-reverse;
}

/* Legacy modal class hooks (still referenced by older markup) */
.aq-modal__header,
.aq-modal__body,
.aq-modal__footer,
.aq-modal__btn {
    /* superseded by .aq-swal — kept empty to avoid breaking cached CSS order */
}

/* ─────────────────────────────────────────────────────────
   4) Full-page Loading Overlay
   ───────────────────────────────────────────────────────── */
.aq-loading-overlay {
    position: fixed;
    inset: 0;
    background: rgba(255, 255, 255, 0.78);
    backdrop-filter: blur(1.5px);
    -webkit-backdrop-filter: blur(1.5px);
    z-index: var(--aq-journey-z-overlay);
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 16px;
    animation: aq-fade-in 0.18s ease-out;
}

.aq-loading-overlay.is-leaving {
    animation: aq-fade-out 0.18s ease-in forwards;
}

.aq-spinner {
    width: 44px;
    height: 44px;
    border: 4px solid #E5E7EB;
    border-top-color: var(--aq-journey-primary);
    border-radius: 50%;
    animation: aq-spin 0.8s linear infinite;
}

.aq-spinner--sm {
    width: 22px;
    height: 22px;
    border-width: 3px;
}

.aq-loading-overlay__text {
    font-size: 14px;
    color: #374151;
    font-weight: 500;
    letter-spacing: 0.2px;
}

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

/* ─────────────────────────────────────────────────────────
   5) Inline section skeletons (when content is loading inside a card)
   ───────────────────────────────────────────────────────── */
.aq-skeleton {
    display: block;
    background: linear-gradient(90deg, #F3F4F6 25%, #E5E7EB 50%, #F3F4F6 75%);
    background-size: 200% 100%;
    border-radius: 6px;
    animation: aq-skeleton-pulse 1.4s ease-in-out infinite;
}

.aq-skeleton--text  { height: 14px; width: 100%; margin: 4px 0; }
.aq-skeleton--title { height: 20px; width: 60%; }
.aq-skeleton--card  { height: 80px; width: 100%; }

@keyframes aq-skeleton-pulse {
    0%   { background-position: 200% 0; }
    100% { background-position: -200% 0; }
}

/* ─────────────────────────────────────────────────────────
   Responsive tweaks
   ───────────────────────────────────────────────────────── */
@media (max-width: 480px) {
    .aq-toast-container {
        top: max(12px, calc(var(--client-fixed-header-offset, 12px) + 6px));
        inset-inline-end: 12px;
        max-width: calc(100vw - 24px);
    }

    .aq-swal,
    .aq-modal {
        max-width: 100%;
        font-size: 0.95rem;
        padding: 2rem 1.5rem 1.5rem;
    }

    .aq-swal__title {
        font-size: 1.125rem !important;
        font-weight: 500 !important;
    }

    .aq-swal__content {
        font-size: 0.9375rem;
        max-width: none;
    }

    .aq-swal--confirm .aq-swal__actions {
        flex-direction: column;
        width: 100%;
    }

    .aq-swal--confirm .aq-swal__btn {
        width: 100%;
        flex: none;
    }
}
