:root {
    --navy:        #001B2A;
    --navy-2:      #0A2A3D;
    --deep:        #1E3A8A;
    --teal:        #0D9488;
    --teal-600:    #0B7F75;
    --teal-50:     #E6F4F2;
    --teal-100:    #CFE9E5;
    --wa:          #25D366;
    --wa-600:      #1FB855;
    --bg:          #F1F3F5;
    --surface:     #FFFFFF;
    --gray-50:     #F7F8FA;
    --gray-100:    #F1F3F5;
    --gray-200:    #E5E7EB;
    --gray-300:    #D1D5DB;
    --gray-400:    #9CA3AF;
    --gray-500:    #6B7280;
    --gray-700:    #374151;
    --line:        #ECEEF2;
    --line-2:      #E3E6EC;
    --ink:         #001B2A;
    --ink-2:       #1F2937;
    --ink-3:       #4B5563;
    --ink-4:       #9CA3AF;
    --amber:       #F59E0B;

    --shadow-sm:   0 1px 2px rgba(0,27,42,.04), 0 1px 3px rgba(0,27,42,.06);
    --shadow:      0 4px 12px rgba(0,27,42,.06), 0 2px 4px rgba(0,27,42,.04);
    --shadow-lg:   0 12px 32px rgba(0,27,42,.08), 0 4px 8px rgba(0,27,42,.04);

    /* responsive tokens */
    --sidebar-w:   260px;
    --topbar-h:    64px;
    --content-max: 1240px;
    --bnav-h:      60px;
}

* { box-sizing: border-box; margin: 0; padding: 0; -webkit-tap-highlight-color: transparent; }

/* Make the [hidden] attribute always win over inline display:flex/grid.
   Without this, <div hidden style="display:flex"> stays visible. */
[hidden] { display: none !important; }
html, body { font-family: 'Cairo', 'IBM Plex Sans Arabic', system-ui, sans-serif; color: var(--ink); }
a { text-decoration: none; color: inherit; }
button { font-family: inherit; cursor: pointer; }
input, textarea, select { font-family: inherit; }
img, svg { display: block; max-width: 100%; }

body.app {
    background: var(--gray-50);
    min-height: 100vh;
    min-height: 100dvh;
    overflow-x: hidden;
}
html { overflow-x: hidden; }

/* ═══ MOBILE-FIRST SHELL ════════════════════════════════════════════ */
.shell {
    display: flex;
    flex-direction: column;
    min-height: 100vh;
    min-height: 100dvh;
}

.sidebar { display: none; } /* Hidden on mobile; replaced by .bnav */
.topbar  { display: none; } /* Hidden on mobile */

.screen {
    width: 100%;
    flex: 1;
    background: var(--surface);
    display: flex;
    flex-direction: column;
    min-height: 0; /* let the shell's padding (for fixed bnav) win over a 100dvh min */
    padding-top: env(safe-area-inset-top);
    position: relative;
}
/* Landing & other no-chrome pages still want the screen to fill the viewport */
.shell.is-landing .screen { min-height: 100vh; min-height: 100dvh; }
.screen.bg-gray { background: var(--gray-100); }
.screen.bg-navy { background: var(--navy); color: white; }

/* iOS-style status bar — mobile preview only */
.statusbar { height: 28px; padding: 0 18px; display: flex; align-items: center; justify-content: space-between; font-size: 11px; font-weight: 700; flex-shrink: 0; }
.statusbar.dark { color: white; }

/* ── In-page header (still used as page chrome) ─────────────────── */
.app-head { padding: 8px 16px 12px; display: flex; align-items: center; gap: 10px; background: var(--surface); flex-shrink: 0; }
.app-head .back, .app-head .ico-btn {
    width: 36px; height: 36px; border-radius: 12px; background: var(--gray-100);
    display: grid; place-items: center; color: var(--ink); border: none;
}
.app-head .title { font-weight: 800; font-size: 15px; flex: 1; }

/* ── Scrollable region ──────────────────────────────────────────── */
.scroll { flex: 1; overflow-y: auto; -webkit-overflow-scrolling: touch; }
.scroll::-webkit-scrollbar { width: 0; height: 0; }

/* ── Cards ──────────────────────────────────────────────────────── */
.card { background: var(--surface); border-radius: 16px; border: 1px solid var(--line); box-shadow: var(--shadow-sm); }
.card-pad { padding: 12px; }

/* ── Buttons ────────────────────────────────────────────────────── */
.btn { display: inline-flex; align-items: center; justify-content: center; gap: 6px; padding: 10px 14px; border-radius: 12px; font-weight: 800; font-size: 13px; border: none; text-align: center; }
.btn-navy  { background: var(--navy); color: white; }
.btn-teal  { background: var(--teal); color: white; }
.btn-wa    { background: var(--wa); color: white; }
.btn-ghost { background: var(--gray-100); color: var(--ink); }
.btn-line  { background: white; color: var(--ink); border: 1px solid var(--line-2); }
.btn-full  { width: 100%; padding: 12px; font-size: 14px; }
.btn:disabled { opacity: .5; pointer-events: none; }
.btn:hover { filter: brightness(1.04); }

/* ── Chips ──────────────────────────────────────────────────────── */
.chip { display: inline-flex; align-items: center; gap: 5px; padding: 6px 11px; border-radius: 999px; background: var(--gray-100); color: var(--ink-2); font-size: 12px; font-weight: 700; white-space: nowrap; }
.chip.active   { background: var(--navy); color: white; }
.chip.teal     { background: var(--teal-50); color: var(--teal-600); }
.chip.wa-tint  { background: rgba(37,211,102,.12); color: var(--wa-600); }
.chip.open     { background: rgba(37,211,102,.12); color: #15803D; }
.chip.closed   { background: #FEE2E2; color: #B91C1C; }

/* ── Horizontal chip scroller with edge fade ────────────────────── */
.chip-scroll-wrap {
    position: relative;
    -webkit-mask-image: linear-gradient(to left, transparent 0, #000 24px, #000 calc(100% - 24px), transparent 100%);
            mask-image: linear-gradient(to left, transparent 0, #000 24px, #000 calc(100% - 24px), transparent 100%);
}
.chip-scroll {
    display: flex;
    gap: 6px;
    overflow-x: auto;
    flex-wrap: nowrap;
    scrollbar-width: none;
}
.chip-scroll::-webkit-scrollbar { display: none; }

/* ── Bottom nav (mobile) ────────────────────────────────────────── */
.bnav {
    background: var(--navy);
    border: 1px solid rgba(255, 255, 255, 0.06);
    box-shadow: 0 16px 36px -10px rgba(0, 27, 42, 0.45), 0 4px 12px -4px rgba(0, 27, 42, 0.25);
    border-radius: 999px;
    display: grid;
    grid-template-columns: repeat(5, 1fr);
    align-items: center;
    padding: 0 6px;
    height: 60px;
    position: fixed;
    left: 16px; right: 16px;
    /* Sit a tight 12px from the viewport bottom on every device.
       Safe-area is ignored on purpose so the pill looks identical
       across PWA / browser / Android / iPhone. The 60px-tall bar
       still keeps icons clear of the iOS home indicator gesture zone. */
    bottom: 12px;
    z-index: 40;
    transition: transform .25s ease;
    will-change: transform;
}
.bnav.is-hidden {
    /* disabled — bnav stays visible at all times */
    transform: none;
}

/* Push page content above the floating pill bnav so nothing hides behind it.
   60px pill height + 12px bottom offset + 12px breathing room = 84px. */
.shell:not(.is-landing) {
    padding-bottom: 84px;
}
/* Pages that explicitly opt out of a bnav (e.g. public business pages with sticky CTA) */
.shell.no-bnav { padding-bottom: 0; }
/* Modern browsers: drop the padding automatically when no .bnav is rendered */
@supports selector(:has(*)) {
    .shell:not(.is-landing):not(:has(.bnav)) { padding-bottom: 0; }
}

/* Hide page scrollbars globally — content still scrolls */
html, body { scrollbar-width: none; -ms-overflow-style: none; }
html::-webkit-scrollbar, body::-webkit-scrollbar { display: none; width: 0; height: 0; }
.screen, .scroll, .shell {
    scrollbar-width: none;
    -ms-overflow-style: none;
}
.screen::-webkit-scrollbar,
.scroll::-webkit-scrollbar,
.shell::-webkit-scrollbar { display: none; width: 0; height: 0; }

.bnav-item {
    position: relative;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    min-width: 0;
    height: 100%;
    color: rgba(255, 255, 255, 0.55);
    text-decoration: none;
    transition: color .18s ease;
    -webkit-tap-highlight-color: transparent;
}
.bnav-item:active { transform: scale(0.92); }
.bnav-item span { display: none; }

.bnav-item .ico-wrap {
    display: grid;
    place-items: center;
    width: 24px;
    height: 24px;
}
.bnav-item svg {
    width: 24px;
    height: 24px;
    flex-shrink: 0;
    display: block;
    transition: transform .18s ease;
    stroke: currentColor;
}

/* Active: white icon + a small teal dot underneath */
.bnav-item.active {
    color: white;
}
.bnav-item.active svg { transform: scale(1.06); }
.bnav-item.active::after {
    content: '';
    position: absolute;
    bottom: 8px;
    left: 50%;
    transform: translateX(-50%);
    width: 4px;
    height: 4px;
    border-radius: 50%;
    background: var(--teal);
}

/* ── Misc atoms ─────────────────────────────────────────────────── */
.muted { color: var(--ink-3); font-size: 12px; font-weight: 600; }
.tiny  { font-size: 10px; font-weight: 700; }
.row { display: flex; align-items: center; gap: 8px; }
.between { justify-content: space-between; }
.col { display: flex; flex-direction: column; gap: 8px; }
.sep { height: 1px; background: var(--line); }
.dot { width: 5px; height: 5px; border-radius: 50%; background: var(--gray-300); display: inline-block; }
.label-strong { font-weight: 800; font-size: 13px; color: var(--ink); }
.label-meta   { font-size: 11px; color: var(--ink-3); font-weight: 600; }
.stars { color: #F5BA12; font-size: 11px; font-weight: 800; display: inline-flex; align-items: center; gap: 3px; }
.stars svg { width: 11px; height: 11px; fill: #F5BA12; }

/* ── Photo placeholders ─────────────────────────────────────────── */
.ph { border-radius: 12px; background: linear-gradient(135deg, rgba(255,255,255,.4), rgba(255,255,255,0) 60%), linear-gradient(120deg, #D9E2EC, #B0BEC9); position: relative; overflow: hidden; display: grid; place-items: center; color: rgba(255,255,255,.85); font-weight: 800; }
.ph-restaurant { background: linear-gradient(135deg, rgba(255,255,255,.35), transparent 60%), linear-gradient(120deg, #E4B65B, #C1471B); }
.ph-shop       { background: linear-gradient(135deg, rgba(255,255,255,.35), transparent 60%), linear-gradient(120deg, #B9D49A, #6F9A4A); }
.ph-clinic     { background: linear-gradient(135deg, rgba(255,255,255,.35), transparent 60%), linear-gradient(120deg, #99C8E0, #4F89A8); }
.ph-salon      { background: linear-gradient(135deg, rgba(255,255,255,.35), transparent 60%), linear-gradient(120deg, #D7A6D6, #8B5A8A); }
.ph-education  { background: linear-gradient(135deg, rgba(255,255,255,.35), transparent 60%), linear-gradient(120deg, #95B0DD, #4063A6); }
.ph-service    { background: linear-gradient(135deg, rgba(255,255,255,.35), transparent 60%), linear-gradient(120deg, #C0C8D0, #6C7884); }

/* ── Map mock ───────────────────────────────────────────────────── */
.map-bg {
    position: absolute; inset: 0;
    background:
        radial-gradient(circle at 30% 40%, #DDEBE0 0 18%, transparent 19%),
        radial-gradient(circle at 70% 70%, #DDEBE0 0 14%, transparent 15%),
        radial-gradient(circle at 80% 30%, #DDEBE0 0 10%, transparent 11%),
        repeating-linear-gradient(45deg, #EEF1F4 0 18px, #E6EAEF 18px 19px),
        #EEF1F4;
}
.map-roads::before {
    content: ''; position: absolute; inset: 0; pointer-events: none;
    background:
        linear-gradient(90deg, transparent 0 5%, #FFFFFFCC 5% 5.6%, transparent 5.6% 100%),
        linear-gradient(180deg, transparent 0 25%, #FFFFFFCC 25% 25.5%, transparent 25.5% 60%, #FFFFFFCC 60% 60.5%, transparent 60.5%),
        linear-gradient(60deg, transparent 0 32%, #FFFFFFCC 32% 32.5%, transparent 32.5% 70%, #FFFFFFCC 70% 70.5%, transparent 70.5%);
}
.map-pin { position: absolute; transform: translate(50%, -100%); filter: drop-shadow(0 4px 6px rgba(0,27,42,.25)); }

/* ── Inputs ─────────────────────────────────────────────────────── */
.field-label { font-size: 10px; font-weight: 700; color: var(--ink-3); margin-bottom: 5px; display: block; }
.field { background: white; border: 1.5px solid var(--line-2); border-radius: 12px; padding: 11px 12px; display: flex; gap: 8px; align-items: center; }
.field.focused, .field:focus-within { border-color: var(--teal); box-shadow: 0 0 0 4px rgba(13,148,136,.08); }
.field input, .field textarea, .field select { flex: 1; border: none; outline: none; background: transparent; font-size: 13px; font-weight: 700; width: 100%; color: var(--ink); }
.field input::placeholder { color: var(--ink-4); font-weight: 600; }

/* Hide native number-input spinners — we use ± buttons instead */
input[type="number"]::-webkit-outer-spin-button,
input[type="number"]::-webkit-inner-spin-button { -webkit-appearance: none; margin: 0; }
input[type="number"] { -moz-appearance: textfield; appearance: textfield; }

.cta-bar { position: sticky; bottom: 0; padding: 10px 14px 14px; background: white; border-top: 1px solid var(--line); display: flex; gap: 8px; }
.cta-bar.dark { background: var(--navy); border-top: 0; }

.flash { padding: 10px 14px; background: rgba(37,211,102,.10); color: #15803D; font-size: 12px; font-weight: 700; text-align: center; }
.flash.err { background: #FEE2E2; color: #B91C1C; }

/* ── Sidebar atoms (used at lg+) ─────────────────────────────────── */
.brand { display: flex; align-items: center; gap: 12px; padding: 20px 18px 12px; }
.brand-mark { width: 40px; height: 40px; border-radius: 12px; background: var(--teal); display: grid; place-items: center; box-shadow: 0 4px 12px rgba(13,148,136,.3); flex-shrink: 0; }
.brand-text { display: flex; flex-direction: column; }
.brand-name { font-weight: 900; font-size: 18px; color: var(--navy); letter-spacing: -.3px; }
.brand-sub  { font-size: 10px; color: var(--ink-3); font-weight: 700; }

.sidebar-nav { padding: 8px 12px; display: flex; flex-direction: column; gap: 2px; }
.sidebar-section { font-size: 10px; font-weight: 800; color: var(--ink-4); text-transform: uppercase; letter-spacing: .5px; padding: 12px 10px 6px; }
.sidebar-item {
    display: flex; align-items: center; gap: 12px;
    padding: 10px 12px; border-radius: 10px;
    color: var(--ink-3); font-size: 13px; font-weight: 700;
    transition: background .12s, color .12s;
    text-align: right;
}
.sidebar-item:hover { background: var(--gray-100); color: var(--ink); }
.sidebar-item.is-active { background: var(--teal-50); color: var(--teal-600); }
.sidebar-item.is-active svg { stroke: var(--teal); }
.sidebar-item svg { flex-shrink: 0; }

.sidebar-foot { padding: 12px; border-top: 1px solid var(--line); margin-top: auto; }
.sidebar-cta {
    display: flex; align-items: center; justify-content: center; gap: 6px;
    background: var(--teal); color: white;
    border-radius: 12px; padding: 11px;
    font-weight: 800; font-size: 13px;
}

.topbar-title { font-weight: 900; font-size: 20px; color: var(--navy); letter-spacing: -.3px; }
.topbar-user {
    display: inline-flex; align-items: center; gap: 8px;
    padding: 6px 12px 6px 6px; background: white;
    border: 1px solid var(--line); border-radius: 999px;
    font-size: 12px; font-weight: 700;
}
.topbar-user--ghost { padding: 8px 14px; }
.topbar-avatar {
    width: 28px; height: 28px; border-radius: 50%;
    background: var(--navy); color: white;
    display: grid; place-items: center;
    font-size: 12px; font-weight: 800;
}

/* ── Responsive content helpers ──────────────────────────────────── */
.container-main { width: 100%; max-width: var(--content-max); margin: 0 auto; }
.section-pad { padding: 16px; }

.grid { display: grid; gap: 12px; }
.grid-2 { grid-template-columns: repeat(2, 1fr); }
.grid-3 { grid-template-columns: 1fr; }
.grid-4 { grid-template-columns: repeat(2, 1fr); }

/* ═══ TABLET (≥ 640px) ═══════════════════════════════════════════ */
@media (min-width: 640px) {
    .section-pad { padding: 24px; }
    .grid-3 { grid-template-columns: repeat(2, 1fr); }
    .grid-4 { grid-template-columns: repeat(2, 1fr); }
}

/* ── Responsive grids in views ──────────────────────────────────── */
.stat-grid { display: grid; grid-template-columns: repeat(2, 1fr); gap: 8px; }
.product-grid { display: grid; grid-template-columns: 1fr; gap: 10px; }
.type-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.result-grid { display: grid; grid-template-columns: 1fr; gap: 10px; }

/* ── Page container (centered content on wide screens) ───────────── */
.page-body { width: 100%; }

/* ── Landing page (no sidebar/topbar) ──────────────────────────────── */
.shell.is-landing .sidebar { display: none !important; }
.shell.is-landing .topbar  { display: none !important; }
.shell.is-landing .statusbar { display: none; }
.shell.is-landing .bnav { display: none; }
.shell.is-landing { flex-direction: column !important; }
.shell.is-landing .screen { background: var(--surface); min-height: 100vh; min-height: 100dvh; padding-top: 0; }

/* ═══ DESKTOP (≥ 1024px) — show sidebar + topbar, hide bottom nav ══ */
@media (min-width: 1024px) {
    body.app { background: var(--gray-50); }
    .shell {
        flex-direction: row-reverse; /* RTL: sidebar on right */
        min-height: 100vh;
        min-height: 100dvh;
    }

    .sidebar {
        display: flex;
        flex-direction: column;
        width: var(--sidebar-w);
        flex-shrink: 0;
        background: white;
        border-left: 1px solid var(--line);
        height: 100vh;
        height: 100dvh;
        position: sticky;
        top: 0;
        overflow-y: auto;
    }

    .screen {
        flex: 1;
        min-width: 0;
        min-height: 100vh;
        min-height: 100dvh;
        background: var(--gray-50);
        padding-top: 0;
    }

    /* Hide status bar (no need on desktop) */
    .statusbar { display: none; }

    /* Show desktop topbar */
    .topbar {
        display: flex;
        align-items: center;
        justify-content: space-between;
        height: var(--topbar-h);
        padding: 0 32px;
        background: white;
        border-bottom: 1px solid var(--line);
        position: sticky;
        top: 0;
        z-index: 5;
    }

    /* Hide the in-page app-head (it's mobile chrome) */
    .app-head { display: none; }

    /* Hide bottom nav on desktop + drop the mobile padding it required */
    .bnav { display: none; }
    .shell:not(.is-landing) { padding-bottom: 0; }

    /* Centered content shell */
    .scroll {
        display: block;
    }

    /* Cards & content get more padding */
    .grid-3 { grid-template-columns: repeat(3, 1fr); }
    .grid-4 { grid-template-columns: repeat(4, 1fr); }

    /* Buttons get hover state more prominent */
    .btn { transition: transform .1s, filter .12s; }
    .btn:active { transform: scale(.98); }

    /* Field inputs slightly larger */
    .field { padding: 13px 14px; }
    .field input { font-size: 14px; }

    /* Constrain content to readable max-width */
    .scroll { padding-left: max(32px, calc((100% - var(--content-max)) / 2)); padding-right: max(32px, calc((100% - var(--content-max)) / 2)); padding-top: 24px; padding-bottom: 32px; }

    /* Cards & sections breathe more */
    .card { border-radius: 18px; }
    .card-pad { padding: 16px; }
    .app-head .title { font-size: 20px; }

    /* Stats grids open up to full row */
    .stat-grid { grid-template-columns: repeat(4, 1fr); gap: 16px; }
    .product-grid { grid-template-columns: repeat(2, 1fr); gap: 16px; }
    .result-grid  { grid-template-columns: repeat(2, 1fr); gap: 16px; }
    .type-grid    { grid-template-columns: repeat(3, 1fr); gap: 14px; }

    /* Sticky cart on menu becomes side rail */
    .menu-cart-rail { position: sticky; bottom: 24px; }

    /* Auth / wizard / splash get a centered card */
    .center-card {
        max-width: 520px; margin: 32px auto;
        background: white; border-radius: 24px;
        padding: 40px;
        box-shadow: var(--shadow);
        border: 1px solid var(--line);
    }
}

/* ═══ XL DESKTOP (≥ 1440px) ════════════════════════════════════════ */
@media (min-width: 1440px) {
    .stat-grid { grid-template-columns: repeat(4, 1fr); gap: 20px; }
    .product-grid { grid-template-columns: repeat(3, 1fr); }
    .result-grid  { grid-template-columns: repeat(3, 1fr); }
}

/* ═══ LARGE DESKTOP (≥ 1440px) ════════════════════════════════════ */
@media (min-width: 1440px) {
    :root { --sidebar-w: 280px; }
}

/* ═══ TOUCH-OPTIMIZED helper ══════════════════════════════════════ */
@media (hover: none) {
    .btn:hover { filter: none; }
    .sidebar-item:hover { background: transparent; }
}
