/* =========================================================================
   Apps Launcher — floating apps panel (Premium SaaS, Arabic RTL)
   Paired with: Views/Shared/_AppsLauncher.cshtml + wwwroot/js/apps-launcher.js
   Keeps the platform identity: purple primary, white surface, soft shadows.
   ========================================================================= */

.apps-launcher-root {
    --al-primary: #7c3aed;          /* platform purple */
    --al-primary-soft: #f3edfe;
    --al-surface: #ffffff;
    --al-text: #1f2937;
    --al-muted: #6b7280;
    --al-border: #eef0f4;
    --al-radius: 20px;

    position: fixed;
    inset: 0;
    z-index: 1090;                  /* above content, below Bootstrap modals (1055+ toasts ok) */
    pointer-events: none;           /* let clicks pass through when closed */
    visibility: hidden;
}

    .apps-launcher-root.is-open {
        pointer-events: auto;
        visibility: visible;
    }

/* -------- Overlay -------- */
.apps-launcher-overlay {
    position: absolute;
    inset: 0;
    background: rgba(17, 24, 39, 0.16);
    -webkit-backdrop-filter: blur(1px);
    backdrop-filter: blur(1px);
    opacity: 0;
    transition: opacity 0.22s ease;
}

.apps-launcher-root.is-open .apps-launcher-overlay {
    opacity: 1;
}

/* -------- Panel (desktop: floating next to the aside rail) -------- */
.apps-launcher {
    position: absolute;
    top: 74px;
    inset-inline-end: 112px;      /* RTL: sits just inside the ~100px aside rail */
    width: clamp(360px, 30vw, 420px);
    max-height: min(78vh, 720px);
    display: flex;
    flex-direction: column;
    background: var(--al-surface);
    border: 1px solid var(--al-border);
    border-radius: var(--al-radius);
    box-shadow: 0 12px 40px rgba(17, 24, 39, 0.14), 0 4px 12px rgba(17, 24, 39, 0.06);
    overflow: hidden;
    opacity: 0;
    transform: translateY(-8px) scale(0.98);
    transform-origin: top center;
    transition: opacity 0.2s ease, transform 0.2s cubic-bezier(0.16, 1, 0.3, 1);
    font-family: inherit;
}

.apps-launcher-root.is-open .apps-launcher {
    opacity: 1;
    transform: translateY(0) scale(1);
}

/* -------- Header -------- */
.apps-launcher__header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 18px 20px 12px;
}

.apps-launcher__title {
    margin: 0;
    font-size: 1.15rem;
    font-weight: 700;
    color: var(--al-text);
}

.apps-launcher__close {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 34px;
    height: 34px;
    padding: 0;
    border: none;
    border-radius: 10px;
    background: #f4f5f7;
    color: var(--al-muted);
    font-size: 0.95rem;
    cursor: pointer;
    transition: background 0.15s ease, color 0.15s ease;
}

    .apps-launcher__close:hover {
        background: var(--al-primary-soft);
        color: var(--al-primary);
    }

    .apps-launcher__close:focus-visible {
        outline: 2px solid var(--al-primary);
        outline-offset: 2px;
    }

/* -------- Search -------- */
.apps-launcher__search {
    position: relative;
    padding: 0 20px 14px;
}

.apps-launcher__search-icon {
    position: absolute;
    inset-inline-start: 32px;       /* RTL-aware */
    top: 11px;
    color: var(--al-muted);
    font-size: 0.9rem;
    pointer-events: none;
}

.apps-launcher__search-input {
    width: 100%;
    height: 44px;
    padding-inline-start: 42px;
    padding-inline-end: 16px;
    border: 1px solid var(--al-border);
    border-radius: 12px;
    background: #fafafb;
    color: var(--al-text);
    font-size: 0.92rem;
    outline: none;
    transition: border-color 0.15s ease, box-shadow 0.15s ease, background 0.15s ease;
}

    .apps-launcher__search-input::placeholder {
        color: #9aa1ad;
    }

    .apps-launcher__search-input:focus {
        background: #fff;
        border-color: var(--al-primary);
        box-shadow: 0 0 0 4px rgba(124, 58, 237, 0.12);
    }

    /* hide native search clear button for a cleaner look */
    .apps-launcher__search-input::-webkit-search-cancel-button {
        -webkit-appearance: none;
        appearance: none;
    }

/* -------- Body / Grid -------- */
.apps-launcher__body {
    flex: 1 1 auto;
    overflow-y: auto;
    overflow-x: hidden;
    padding: 4px 16px 18px;
    scrollbar-width: thin;
    scrollbar-color: #d7d9e0 transparent;
}

    .apps-launcher__body::-webkit-scrollbar {
        width: 8px;
    }

    .apps-launcher__body::-webkit-scrollbar-thumb {
        background: #d7d9e0;
        border-radius: 8px;
    }

.apps-launcher__grid {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 8px;
}

/* -------- Tile -------- */
.apps-launcher-tile {
    /* default tint (overridden by app-tile--* modifiers) */
    --app-color: var(--al-primary);
    --app-soft: var(--al-primary-soft);

    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: flex-start;
    gap: 10px;
    padding: 16px 8px 14px;
    border-radius: 16px;
    text-decoration: none;
    background: transparent;
    transition: background 0.16s ease, transform 0.16s ease, box-shadow 0.16s ease;
}

    .apps-launcher-tile:hover,
    .apps-launcher-tile:focus-visible {
        background: #f7f7fa;
        transform: translateY(-3px);
        box-shadow: 0 8px 18px rgba(17, 24, 39, 0.08);
        outline: none;
    }

    .apps-launcher-tile:focus-visible {
        box-shadow: 0 0 0 2px var(--app-color);
    }

    .apps-launcher-tile.is-active {
        background: var(--al-primary-soft);
    }

.apps-launcher-tile__icon {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 56px;
    height: 56px;
    border-radius: 16px;
    background: var(--app-soft);
    color: var(--app-color);
    font-size: 1.6rem;
    transition: transform 0.16s ease;
}

.apps-launcher-tile:hover .apps-launcher-tile__icon {
    transform: scale(1.05);
}

/* image icons inside the tinted square (svg or raster like .jfif) */
.apps-launcher-tile__img {
    width: 60px;
    height: 60px;
    object-fit: contain;
    border-radius: 12px;
    display: block;
}

.apps-launcher-tile__label {
    font-size: 0.8rem;
    font-weight: 600;
    line-height: 1.3;
    text-align: center;
    color: var(--al-text);
    word-break: break-word;
}

.apps-launcher-tile.is-active .apps-launcher-tile__label {
    color: var(--al-primary);
}

/* -------- Empty state -------- */
.apps-launcher__empty {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 8px;
    padding: 32px 12px;
    color: var(--al-muted);
    font-size: 0.9rem;
}

    .apps-launcher__empty .bi {
        font-size: 1.6rem;
        opacity: 0.5;
    }

/* -------- Footer CTA (separate horizontal button, e.g. Marketplace) -------- */
.apps-launcher__footer {
    flex: 0 0 auto;
    padding: 12px 16px 16px;
    border-top: 1px solid var(--al-border);
}

.apps-launcher__cta {
    /* default tint (overridden by app-tile--* modifier on the element) */
    --app-color: var(--al-primary);
    --app-soft: var(--al-primary-soft);

    position: relative;
    overflow: hidden;
    isolation: isolate;
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 11px 14px;
    border-radius: 14px;
    border: 1px solid transparent;
    background: var(--app-soft);
    text-decoration: none;
    transition: transform 0.16s ease, box-shadow 0.16s ease, filter 0.16s ease,
        background 0.25s ease, border-color 0.25s ease, backdrop-filter 0.25s ease;
}

    /* continuous shine sweep ("لمعة" مستمرة) */
    .apps-launcher__cta::after {
        content: "";
        position: absolute;
        top: 0;
        left: -75%;
        width: 50%;
        height: 100%;
        background: linear-gradient(115deg,
            transparent 0%,
            rgba(255, 255, 255, 0.15) 40%,
            rgba(255, 255, 255, 0.6) 50%,
            rgba(255, 255, 255, 0.15) 60%,
            transparent 100%);
        transform: skewX(-18deg);
        pointer-events: none;
        z-index: 2;
        animation: appsCtaShine 3.4s ease-in-out infinite;
    }

@keyframes appsCtaShine {
    0% { left: -75%; }
    55%, 100% { left: 130%; }
}

    /* stronger one-shot shine triggered on hover */
    .apps-launcher__cta::before {
        content: "";
        position: absolute;
        top: 0;
        left: -75%;
        width: 60%;
        height: 100%;
        background: linear-gradient(115deg,
            transparent 0%,
            rgba(255, 255, 255, 0.85) 50%,
            transparent 100%);
        transform: skewX(-18deg);
        pointer-events: none;
        opacity: 0;
        z-index: 3;
    }

@keyframes appsCtaShineHover {
    0% { left: -75%; opacity: 0; }
    10% { opacity: 1; }
    100% { left: 130%; opacity: 0; }
}

    /* glassify on hover (frosted glass) */
    .apps-launcher__cta:hover,
    .apps-launcher__cta:focus-visible {
        transform: translateY(-2px);
        background: rgba(255, 255, 255, 0.22);
        backdrop-filter: blur(10px) saturate(160%);
        -webkit-backdrop-filter: blur(10px) saturate(160%);
        border-color: rgba(255, 255, 255, 0.55);
        box-shadow: 0 10px 24px rgba(17, 24, 39, 0.14), inset 0 1px 0 rgba(255, 255, 255, 0.6);
        outline: none;
    }

    /* shine speeds up while hovering */
    .apps-launcher__cta:hover::after {
        animation-duration: 1.5s;
    }

    /* extra bright shine that fires once on hover */
    .apps-launcher__cta:hover::before,
    .apps-launcher__cta:focus-visible::before {
        animation: appsCtaShineHover 0.9s ease-out;
    }

    @media (prefers-reduced-motion: reduce) {
        .apps-launcher__cta::after,
        .apps-launcher__cta::before {
            animation: none;
        }
    }

    .apps-launcher__cta:focus-visible {
        box-shadow: 0 0 0 2px var(--app-color);
    }

    .apps-launcher__cta.is-active {
        box-shadow: inset 0 0 0 1.5px var(--app-color);
    }

.apps-launcher__cta-icon {
    flex: 0 0 auto;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 42px;
    height: 42px;
    border-radius: 12px;
    background: #fff;
    box-shadow: 0 1px 3px rgba(17, 24, 39, 0.06);
}

    .apps-launcher__cta-icon img {
        width: 26px;
        height: 26px;
        object-fit: contain;
        display: block;
    }

.apps-launcher__cta-text {
    flex: 1 1 auto;
    display: flex;
    flex-direction: column;
    gap: 2px;
    min-width: 0;
}

.apps-launcher__cta-title {
    font-size: 0.92rem;
    font-weight: 700;
    color: var(--al-text);
    line-height: 1.25;
}

.apps-launcher__cta-sub {
    font-size: 0.74rem;
    color: var(--al-muted);
    line-height: 1.25;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.apps-launcher__cta-arrow {
    flex: 0 0 auto;
    color: var(--app-color);
    font-size: 0.85rem;
    transition: transform 0.16s ease;
}

.apps-launcher__cta:hover .apps-launcher__cta-arrow {
    transform: translateX(-3px);
}

/* =========================================================================
   Per-app color palette (colorful, distinct, tinted squares)
   ========================================================================= */
.app-tile--purple    { --app-color: #7c3aed; --app-soft: #f3edfe; }
.app-tile--blue      { --app-color: #2f6bff; --app-soft: #e9f0ff; }
.app-tile--green     { --app-color: #16a34a; --app-soft: #e7f7ee; }
.app-tile--orange    { --app-color: #f97316; --app-soft: #fff0e4; }
.app-tile--yellow    { --app-color: #eab308; --app-soft: #fef7dd; }
.app-tile--turquoise { --app-color: #14b8a6; --app-soft: #e3f8f5; }
.app-tile--pink      { --app-color: #ec4899; --app-soft: #fdeaf4; }
.app-tile--cyan      { --app-color: #06b6d4; --app-soft: #e2f7fb; }
.app-tile--whatsapp  { --app-color: #25d366; --app-soft: #e6f9ee; }

/* =========================================================================
   Mobile — bottom sheet (< 992px)
   ========================================================================= */
@media (max-width: 991.98px) {
    .apps-launcher {
        top: auto;
        inset-inline-start: 0;
        inset-inline-end: 0;
        bottom: 0;
        width: 100%;
        max-height: 82vh;
        border-radius: 22px 22px 0 0;
        border-inline: none;
        border-bottom: none;
        transform: translateY(16px);
        transform-origin: bottom center;
    }

    .apps-launcher-root.is-open .apps-launcher {
        transform: translateY(0);
    }

    .apps-launcher-overlay {
        background: rgba(17, 24, 39, 0.32);
    }

    .apps-launcher__grid {
        gap: 6px;
    }

    /* small drag-handle affordance on the bottom sheet */
    .apps-launcher__header::before {
        content: "";
        position: absolute;
        top: 8px;
        inset-inline-start: 50%;
        transform: translateX(-50%);
        width: 42px;
        height: 4px;
        border-radius: 4px;
        background: #e2e4ea;
    }

    .apps-launcher__header {
        position: relative;
        padding-top: 22px;
    }
}

/* =========================================================================
   Reduced motion
   ========================================================================= */
@media (prefers-reduced-motion: reduce) {
    .apps-launcher,
    .apps-launcher-overlay,
    .apps-launcher-tile,
    .apps-launcher-tile__icon {
        transition: none !important;
    }

    .apps-launcher {
        transform: none !important;
    }
}
