/*
 * Talabatey design overlay
 * Implements DESIGN.md tokens on top of the compiled Tailwind app.css.
 * Load order matters: this file must come AFTER /css/app.css in root.blade.php.
 *
 * Why an overlay? The Vue SPA is compiled into public/js/app.js; the build chain
 * (Laravel Mix 6 / Webpack 5 / vue-loader 15 from 2021) does not run on modern
 * Node and would take a multi-week dep upgrade to rehab. This stylesheet
 * modernizes the rendered output via CSS specificity + cascade order, without
 * touching the source .vue files.
 */

/* ---------- Fonts ---------- */
@import url('https://fonts.googleapis.com/css2?family=Tajawal:wght@400;500;700;800&family=Inter:wght@400;500;600;700;800&display=swap');

/* ---------- Tokens (from DESIGN.md) ---------- */
:root {
    --color-primary:        #f43545;
    --color-primary-dark:   #c41e2e;
    --color-primary-soft:   #fef2f3;
    --color-ink:            #0f172a;
    --color-ink-muted:      #64748b;
    --color-surface:        #ffffff;
    --color-bg:             #fafafa;
    --color-border:         #eef0f4;
    --color-border-strong:  #e2e8f0;
    --color-success:        #16a34a;
    --color-danger:         #dc2626;

    --font-display: 'Tajawal', 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;

    --radius-sm: 8px;
    --radius-md: 14px;
    --radius-lg: 20px;
    --radius-xl: 28px;

    --shadow-sm: 0 1px 2px rgba(15, 23, 42, .05);
    --shadow-md: 0 4px 16px rgba(15, 23, 42, .06), 0 1px 2px rgba(15, 23, 42, .04);
    --shadow-lg: 0 12px 32px rgba(15, 23, 42, .10), 0 2px 6px rgba(15, 23, 42, .04);
    --shadow-cta:       0 10px 24px rgba(244, 53, 69, .32);
    --shadow-cta-hover: 0 14px 32px rgba(244, 53, 69, .42);

    --space-md: 16px;
    --space-lg: 24px;
    --space-xl: 32px;
    --space-2xl: 48px;
    --space-3xl: 72px;
}

/* ---------- Base ---------- */
html, body {
    font-family: var(--font-display) !important;
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
    text-rendering: optimizeLegibility;
    color: var(--color-ink);
}

body.bg-gray-100 {
    background: var(--color-bg) !important;
}

/* ---------- Scroll performance ----------
 * The home page combined position:fixed background + backdrop-filter navbar +
 * many ScrollTrigger pins, which on mobile Safari triggers full-screen
 * repaints on every scroll frame. Fixes:
 *  - Soften + GPU-promote the bg image; drop fixed positioning on mobile
 *    (fixed bgs are the single worst scroll perf killer on iOS).
 *  - Drop scroll-behavior: smooth — it fights iOS momentum and causes
 *    visible "stuttering" mid-scroll.
 *  - will-change on the elements that actually animate during scroll.
 */
.background-image {
    opacity: 0.45;
    filter: saturate(0.85) contrast(0.95);
    transform: translateZ(0);          /* promote to GPU layer */
    will-change: transform;
}

@media (max-width: 1024px) {
    /* On phones/tablets, fixed bg = jank. Convert to a static gradient bg. */
    .background-image.fixed,
    .background-image-rtl.fixed {
        position: absolute !important;
        background-attachment: scroll !important;
    }
}

/* ---------- Navbar ---------- */
nav.bg-primary {
    background: rgba(255, 255, 255, 0.92) !important;
    backdrop-filter: saturate(180%) blur(14px);
    -webkit-backdrop-filter: saturate(180%) blur(14px);
    height: 64px !important;
    box-shadow: var(--shadow-sm);
    border-bottom: 1px solid var(--color-border);
    transform: translateZ(0);
    will-change: transform;
}

/* backdrop-filter is expensive on mobile Safari — drop it on small screens
   in favor of a slightly more opaque background. Same look, no scroll jank. */
@media (max-width: 768px) {
    nav.bg-primary {
        background: rgba(255, 255, 255, 0.98) !important;
        backdrop-filter: none;
        -webkit-backdrop-filter: none;
    }
}

nav.bg-primary .text-white {
    color: var(--color-ink) !important;
    font-weight: 500;
    font-size: 0.9375rem;
    transition: color 0.15s ease;
}

nav.bg-primary .text-white:hover,
nav.bg-primary .text-white.font-bold,
nav.bg-primary .scrollactive-item.is-active {
    color: var(--color-primary) !important;
}

nav.bg-primary svg.fill-current.text-white {
    color: var(--color-ink) !important;
    transition: color 0.15s ease;
}
nav.bg-primary svg.fill-current.text-white:hover {
    color: var(--color-primary) !important;
}

nav.bg-primary img[src*="logo-white"] {
    /* Original logo is white-on-red; invert hue to red-on-white for the new navbar */
    filter: brightness(0) saturate(100%) invert(31%) sepia(96%) saturate(2837%) hue-rotate(338deg) brightness(98%) contrast(99%);
}

/* Mobile hamburger icon */
nav.bg-primary svg.text-white {
    color: var(--color-ink) !important;
}

/* Mobile dropdown drawer — was the same red as the bar */
nav.bg-primary > div .bg-primary {
    background: var(--color-surface) !important;
    border-bottom: 1px solid var(--color-border);
    box-shadow: var(--shadow-md);
    border-radius: 0 0 var(--radius-md) var(--radius-md);
    padding: var(--space-md) 0;
}

/* ---------- Hero ---------- */
.font-black.text-gray-400 {
    color: var(--color-ink) !important;
    font-weight: 800 !important;
    letter-spacing: -0.02em;
    line-height: 1.05;
    font-size: clamp(2.5rem, 6vw, 4.5rem) !important;
}

/* Make hero headline `<div v-html="headerHTML">` legible whatever HTML it contains */
.font-black.text-gray-400 h1,
.font-black.text-gray-400 h2,
.font-black.text-gray-400 p {
    color: inherit;
    font-weight: inherit;
    line-height: inherit;
    letter-spacing: inherit;
    font-size: inherit;
    margin: 0;
}

/* Headlines on Posts/News sections */
h3.text-primary.font-black {
    font-size: clamp(1.75rem, 3vw, 2.25rem) !important;
    font-weight: 800 !important;
    letter-spacing: -0.015em;
    margin-bottom: var(--space-md);
}

/* ---------- Hero store-badges row (Get the app) ---------- */
.flex.mt-20.justify-center {
    margin-top: var(--space-2xl) !important;
    gap: 14px;
    flex-wrap: wrap;
    padding: 8px;
}

/* Each badge: a premium "card" with the brand SVG centered and the download
   count tucked beneath as a soft pill chip. */
.flex.mt-20.justify-center > a {
    display: inline-flex !important;
    flex-direction: column !important;
    align-items: center !important;
    gap: 10px;
    padding: 18px 22px 14px;
    background: linear-gradient(180deg, #ffffff 0%, #fbfbfd 100%);
    border: 1px solid var(--color-border);
    border-radius: var(--radius-lg);
    box-shadow: var(--shadow-sm);
    transition: transform 0.18s ease, box-shadow 0.22s ease, border-color 0.18s ease;
    min-width: 132px;
    text-decoration: none !important;
}

.flex.mt-20.justify-center > a:hover {
    border-color: var(--color-primary);
    transform: translateY(-4px);
    box-shadow: 0 18px 36px rgba(244, 53, 69, 0.14), 0 4px 10px rgba(15, 23, 42, 0.04);
}

/* Make the brand SVG noticeably bigger and crisper than h-10 (40px) */
.flex.mt-20.justify-center > a img {
    height: 38px !important;
    width: auto !important;
    margin: 0 !important;
    transition: transform 0.2s ease;
}
.flex.mt-20.justify-center > a:hover img {
    transform: scale(1.05);
}

/* Download count → soft red-tinted chip */
.flex.mt-20.justify-center > a span {
    color: var(--color-primary) !important;
    background: var(--color-primary-soft);
    font-weight: 700;
    font-size: 0.6875rem !important;
    letter-spacing: 0.03em;
    padding: 3px 10px;
    border-radius: 9999px;
    margin: 0 !important;
    line-height: 1.4;
}

@media (max-width: 768px) {
    .flex.mt-20.justify-center {
        gap: 10px;
        padding: 4px;
    }
    .flex.mt-20.justify-center > a {
        min-width: 0;
        flex: 1 1 0;
        padding: 14px 12px 12px;
        gap: 8px;
    }
    .flex.mt-20.justify-center > a img {
        height: 30px !important;
    }
}

/* ---------- Post cards ---------- */
.post {
    border-radius: var(--radius-lg) !important;
    box-shadow: var(--shadow-md) !important;
    overflow: hidden;
    transition: transform 0.18s ease, box-shadow 0.2s ease;
    background: var(--color-surface) !important;
}
.post:hover {
    transform: translateY(-3px);
    box-shadow: var(--shadow-lg) !important;
}
/* The Post component forces every card to bg-primary; tone it down */
.post.bg-primary {
    background: var(--color-surface) !important;
}
.post.bg-primary .text-white {
    color: var(--color-ink) !important;
}
.post.bg-primary .text-gray-200 {
    color: var(--color-ink-muted) !important;
}
.post .image {
    transition: transform 0.4s ease;
}
.post:hover .image {
    transform: scale(1.04);
}
.post .p-4 {
    padding: var(--space-lg) !important;
}
.post .text-xl.font-bold {
    font-size: 1.125rem !important;
    font-weight: 700;
    line-height: 1.35;
    letter-spacing: -0.005em;
    color: var(--color-ink);
    /* Truncate to 2 lines */
    display: -webkit-box;
    -webkit-line-clamp: 2;
    -webkit-box-orient: vertical;
    overflow: hidden;
}
.post .font-medium {
    color: var(--color-ink-muted) !important;
    font-size: 0.9375rem;
    line-height: 1.55;
    display: -webkit-box;
    -webkit-line-clamp: 3;
    -webkit-box-orient: vertical;
    overflow: hidden;
}

/* "View all posts" / "View all news" CTA card */
.dim {
    background: var(--color-primary-soft);
    border: 1px dashed var(--color-primary);
    border-radius: var(--radius-lg);
    padding: var(--space-lg);
    height: 100%;
    justify-content: center;
}

/* ---------- Forms ---------- */
.form-input,
.form-select,
input[type="text"]:not(.no-design),
input[type="email"]:not(.no-design),
input[type="tel"]:not(.no-design),
input[type="number"]:not(.no-design),
textarea {
    background: var(--color-surface) !important;
    border: 1px solid var(--color-border-strong) !important;
    border-radius: var(--radius-md) !important;
    padding: 12px 16px !important;
    font-size: 0.9375rem !important;
    color: var(--color-ink) !important;
    transition: border-color 0.15s ease, background 0.15s ease, box-shadow 0.15s ease !important;
    min-height: 48px;
    box-shadow: none !important;
}
textarea.form-select,
textarea {
    min-height: 120px;
    line-height: 1.5;
}
.form-input:focus,
.form-select:focus,
textarea:focus,
input:focus {
    border-color: var(--color-primary) !important;
    background: var(--color-primary-soft) !important;
    box-shadow: 0 0 0 3px rgba(244, 53, 69, 0.12) !important;
    outline: none !important;
}
label > span.text-gray-700 {
    color: var(--color-ink) !important;
    font-weight: 600;
    font-size: 0.875rem;
    display: inline-block;
    margin-bottom: 6px;
}

/* Form-card containers (Contact / Join pages) */
.bg-white.rounded-lg.shadow-md.p-10 {
    border-radius: var(--radius-xl) !important;
    box-shadow: var(--shadow-lg) !important;
    border: 1px solid var(--color-border);
    padding: clamp(24px, 4vw, 40px) !important;
}

/* ---------- Buttons ---------- */
button.bg-primary,
.bg-primary[role="button"] {
    background: var(--color-primary) !important;
    border-radius: var(--radius-md) !important;
    box-shadow: var(--shadow-cta) !important;
    border: none !important;
    font-weight: 600 !important;
    padding: 14px 28px !important;
    height: auto !important;
    min-height: 48px;
    transition: background 0.15s ease, transform 0.15s ease, box-shadow 0.2s ease !important;
}
button.bg-primary:hover,
.bg-primary[role="button"]:hover {
    background: var(--color-primary-dark) !important;
    transform: translateY(-2px);
    box-shadow: var(--shadow-cta-hover) !important;
}
button.bg-primary:active {
    transform: translateY(0);
    box-shadow: var(--shadow-cta) !important;
}

/* ---------- "Read more" / inline primary links ---------- */
.text-primary {
    color: var(--color-primary);
}

/* ---------- About / Contact decorative image ---------- */
.container.mx-auto.-mb-31 img,
.container.mx-auto.-mb-6 img {
    border-radius: var(--radius-xl);
}

/* ---------- Join section ---------- */
/* The big floating "Join Us" pill that overlaps the section above */
span.bg-primary.rounded-full.text-2xl {
    background: var(--color-primary) !important;
    color: #fff !important;
    font-weight: 700 !important;
    font-size: 1.125rem !important;
    padding: 16px 40px !important;
    border-radius: 9999px !important;
    box-shadow: var(--shadow-cta);
    letter-spacing: -0.005em;
}

/* The Join column was gray-200 — neutralize it and tighten the padding */
.min-h-screen.grid .col-span-1.bg-gray-200 {
    background: var(--color-surface) !important;
    padding: clamp(32px, 5vw, 64px) !important;
    gap: 8px;
    justify-content: center;
}
.min-h-screen.grid .col-span-1.bg-gray-200 > .flex.my-4 {
    margin: 8px 0 4px !important;
    color: var(--color-ink);
    font-size: 1rem;
    line-height: 1.6;
    max-width: 540px;
}
.min-h-screen.grid .col-span-1.bg-gray-200 > .flex.my-4 p {
    color: var(--color-ink);
}

/* Join CTA buttons — were outlined ghost buttons; promote to filled primary */
.min-h-screen.grid button.text-primary.border-primary,
.min-h-screen.grid button.border-2.border-primary {
    background: var(--color-primary) !important;
    color: #fff !important;
    border: none !important;
    border-radius: var(--radius-md) !important;
    padding: 12px 28px !important;
    font-weight: 600 !important;
    font-size: 0.9375rem !important;
    box-shadow: var(--shadow-cta) !important;
    transition: background 0.15s ease, transform 0.15s ease, box-shadow 0.2s ease !important;
    margin-bottom: 24px;
}
.min-h-screen.grid button.text-primary.border-primary:hover,
.min-h-screen.grid button.border-2.border-primary:hover {
    background: var(--color-primary-dark) !important;
    transform: translateY(-2px);
    box-shadow: var(--shadow-cta-hover) !important;
}

/* ---------- Footer ---------- */
/* Outer grid */
.grid.grid-cols-1.md\:grid-cols-3.bg-gray-200,
[class*="grid-cols-3"][class*="bg-gray-200"] {
    background: var(--color-ink) !important;
    color: rgba(255, 255, 255, 0.85);
    padding: var(--space-3xl) clamp(20px, 5vw, 64px) var(--space-xl) !important;
    gap: var(--space-xl);
    align-items: center;
    margin-top: var(--space-2xl);
    border-top: 4px solid var(--color-primary);
}
.grid.grid-cols-1.md\:grid-cols-3.bg-gray-200 > div {
    align-items: center;
}

/* Copyright line */
.grid.grid-cols-1.md\:grid-cols-3.bg-gray-200 .flex.justify-center.text-primary {
    color: rgba(255, 255, 255, 0.7) !important;
    font-size: 0.875rem;
    font-weight: 500;
}

/* Social icon row */
.grid.grid-cols-1.md\:grid-cols-3.bg-gray-200 .flex.justify-center a.mx-1 {
    width: 84px;
    height: 84px;
    margin: 0 12px !important;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    background: rgba(255, 255, 255, 0.10);
    border-radius: 20px;
    color: #ffffff;
    transition: background 0.15s ease, transform 0.15s ease, color 0.15s ease, box-shadow 0.2s ease;
}
.grid.grid-cols-1.md\:grid-cols-3.bg-gray-200 .flex.justify-center a.mx-1:hover {
    background: var(--color-primary);
    color: #ffffff;
    transform: translateY(-3px);
    box-shadow: var(--shadow-cta);
}
.grid.grid-cols-1.md\:grid-cols-3.bg-gray-200 .flex.justify-center a.mx-1 i {
    font-size: 2.75rem !important;   /* 44px — fills the 84px pill properly */
    color: inherit;
    line-height: 1;
}

@media (max-width: 768px) {
    .grid.grid-cols-1.md\:grid-cols-3.bg-gray-200 .flex.justify-center a.mx-1 {
        width: 64px;
        height: 64px;
        margin: 0 8px !important;
        border-radius: 16px;
    }
    .grid.grid-cols-1.md\:grid-cols-3.bg-gray-200 .flex.justify-center a.mx-1 i {
        font-size: 2rem !important;  /* 32px */
    }
}

/*
 * Swap FontAwesome's "square-*" brand glyphs for the clean unsquared
 * versions. The Vue template hard-codes fa-square-{youtube,instagram,facebook},
 * but the squared variants render as heavy/cluttered blocks. Overriding the
 * ::before content keeps the same DOM but renders the brand-mark only.
 */
.fa-brands.fa-square-youtube::before   { content: "\f167"; }   /* fa-youtube   */
.fa-brands.fa-square-instagram::before { content: "\f16d"; }   /* fa-instagram */
.fa-brands.fa-square-facebook::before  { content: "\f09a"; }   /* fa-facebook  */

@media (max-width: 768px) {
    .grid.grid-cols-1.md\:grid-cols-3.bg-gray-200 {
        padding: var(--space-2xl) var(--space-lg) var(--space-lg) !important;
        gap: var(--space-lg);
        text-align: center;
    }
    .grid.grid-cols-1.md\:grid-cols-3.bg-gray-200 .flex.justify-center.text-primary {
        order: 2;
        font-size: 0.8125rem;
    }
    .grid.grid-cols-1.md\:grid-cols-3.bg-gray-200 .flex.justify-center:nth-child(2) {
        order: 1;
    }
    /* Join section: stack image above content on mobile */
    .min-h-screen.grid.grid-cols-1.md\:grid-cols-2 {
        min-height: auto !important;
    }
    .min-h-screen.grid .col-span-1 img[src*="join.png"] {
        max-height: 240px;
        object-position: center;
    }
    .min-h-screen.grid .col-span-1.bg-gray-200 {
        padding: var(--space-xl) var(--space-lg) !important;
        align-items: center !important;
        text-align: center;
    }
    .min-h-screen.grid .col-span-1.bg-gray-200 > .flex.my-4 {
        justify-content: center;
        margin-left: auto !important;
        margin-right: auto !important;
    }
    .min-h-screen.grid .col-span-1.bg-gray-200 > .flex:not(.my-4) {
        justify-content: center;
    }
    span.bg-primary.rounded-full.text-2xl {
        font-size: 1rem !important;
        padding: 12px 28px !important;
    }
}

/* ---------- Floating FAB (Open App) ---------- */
.open-app-fab {
    position: fixed;
    bottom: 24px;
    inset-inline-end: 24px;
    z-index: 50;
    display: inline-flex;
    align-items: center;
    gap: 10px;
    padding: 14px 22px;
    background: var(--color-primary);
    color: #fff !important;
    font-family: var(--font-display);
    font-weight: 600;
    font-size: 0.9375rem;
    text-decoration: none !important;
    border-radius: 9999px;
    box-shadow: var(--shadow-cta);
    transition: transform 0.15s ease, box-shadow 0.2s ease, background 0.15s ease;
}
.open-app-fab:hover {
    background: var(--color-primary-dark);
    transform: translateY(-2px);
    box-shadow: var(--shadow-cta-hover);
}
.open-app-fab svg {
    width: 18px;
    height: 18px;
}

/* ---------- Responsive tuning ---------- */
@media (max-width: 768px) {
    nav.bg-primary {
        height: 60px !important;
    }
    nav.bg-primary > div .bg-primary {
        margin-top: 60px !important;
        padding: var(--space-md);
    }
    /* Hero image hidden behind text on tiny screens — keep it hidden, more breathing room */
    .container.mx-auto.flex.items-center.justify-center.h-screen {
        height: auto !important;
        min-height: calc(100vh - 60px);
        padding: var(--space-2xl) 0;
    }
    .grid.grid-cols-12.mx-5 {
        gap: var(--space-lg);
    }
    .col-span-9 {
        grid-column: span 12 / span 12 !important;
        text-align: center;
    }
    .flex.mt-20.justify-center {
        margin-top: var(--space-xl) !important;
        gap: 8px;
    }
    .flex.mt-20.justify-center > a img {
        height: 28px;
    }
    h3.text-primary.font-black {
        text-align: center;
    }
    .post .p-4 { padding: var(--space-md) !important; }
    .open-app-fab {
        bottom: 16px;
        inset-inline-end: 16px;
        padding: 12px 18px;
        font-size: 0.875rem;
    }
}

/* Mobile-menu items: keep them tappable */
@media (max-width: 768px) {
    nav.bg-primary > div .bg-primary a,
    nav.bg-primary > div .bg-primary .router-link-exact-active {
        padding: 12px 8px;
        font-size: 1rem;
        font-weight: 500;
    }
}

/*
 * NOTE: scroll-behavior: smooth is intentionally NOT set.
 * On iOS Safari it fights momentum scrolling and causes visible stutter
 * mid-scroll. The site uses scrollactive (vue-scrollactive) for anchor
 * jumps, which animates programmatically without the CSS rule.
 */
html, body {
    -webkit-overflow-scrolling: touch;   /* native momentum on iOS */
    overscroll-behavior-y: none;          /* no rubber-band glitch on macOS Safari */
}

/* Keep the FAB on the GPU so it doesn't trigger repaints on scroll */
.open-app-fab {
    transform: translateZ(0);
    will-change: transform;
}

/* Touch-only: a pure-CSS pulse on the FAB. Transform-only animation, lives
   on the compositor, costs nothing per scroll frame. Replaces the JS Motion
   animation that was causing mobile scroll jank by animating box-shadow. */
@media (hover: none) and (pointer: coarse) {
    .open-app-fab {
        animation: fab-pulse 2.6s ease-in-out infinite;
    }
    @keyframes fab-pulse {
        0%, 100% { transform: translateZ(0) translateY(0) scale(1); }
        50%      { transform: translateZ(0) translateY(-2px) scale(1.03); }
    }
}

/* ---------- iOS URL-bar resize jitter ----------
 * Tailwind's h-screen / min-h-screen use 100vh. On iOS Safari, 100vh
 * INCLUDES the URL bar height — when the bar hides during scroll, the
 * viewport grows, the element resizes, and every paint downstream re-runs.
 * Use 100svh (small viewport height) on mobile — it stays stable.
 * Fall back to 100vh on browsers without svh support.
 */
@media (max-width: 1024px) {
    .h-screen { height: 100svh !important; }
    .min-h-screen { min-height: 100svh !important; }
    /* Hero container had h-screen forcing a tall area on phones */
    .container.mx-auto.flex.items-center.justify-center.h-screen {
        min-height: auto !important;
        height: auto !important;
        padding: var(--space-2xl) 0;
    }
}

/* Reduce paint scope on long scroll sections — the browser doesn't need to
   re-paint the whole page when one section's content changes. */
.container.min-h-50vh,
.min-h-screen.grid.grid-cols-1.md\:grid-cols-2,
.grid.grid-cols-1.md\:grid-cols-3.bg-gray-200 {
    contain: layout style paint;
}

/* Post cards on scroll: drop the hover-only shadow on touch, keep a static
   one. Hover animations on a non-hover device just churn the compositor. */
@media (hover: none) and (pointer: coarse) {
    .post {
        transition: none !important;
    }
    .post:hover {
        transform: none !important;
    }
    .post:hover .image {
        transform: none !important;
    }
    /* The store-badge hover lift is also useless on touch — turn it off */
    .flex.mt-20.justify-center > a {
        transition: none !important;
    }
}

/* Focus-visible accessibility */
a:focus-visible,
button:focus-visible,
input:focus-visible,
textarea:focus-visible {
    outline: 2px solid var(--color-primary);
    outline-offset: 2px;
}
