<!DOCTYPE html>
<html lang="en">

<head>
    <!-- Google Tag Manager -->
    <script>(function (w, d, s, l, i) {
            w[l] = w[l] || []; w[l].push({
                'gtm.start':
                    new Date().getTime(), event: 'gtm.js'
            }); var f = d.getElementsByTagName(s)[0],
                j = d.createElement(s), dl = l != 'dataLayer' ? '&l=' + l : ''; j.async = true; j.src =
                    'https://www.googletagmanager.com/gtm.js?id=' + i + dl; f.parentNode.insertBefore(j, f);
        })(window, document, 'script', 'dataLayer', 'GTM-KVH6V6ZH');</script>
    <!-- End Google Tag Manager -->
    <!-- ⚡ Instant theme (prevents flash of wrong theme) -->
    <script>
        (function(){
            var t=localStorage.getItem('sachin-theme')||(window.matchMedia('(prefers-color-scheme: dark)').matches?'dark':'light');
            document.documentElement.setAttribute('data-theme',t);
        })();
    </script>
    <!-- Shared splash / loading screen (matches Flutter customer splash) -->
    <script src="loading.js"></script>
    <meta charset="UTF-8" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=5.0, viewport-fit=cover, user-scalable=yes" />

    <title>Sachin Deep Cleaning - Professional Cleaning Services</title>
    <meta name="description"
        content="Professional home and office cleaning services. Book online with transparent pricing, eco-friendly products, and quality guarantee." />
    <meta name="keywords"
        content="cleaning services, home cleaning, office cleaning, deep cleaning, professional cleaners" />
    <link rel="canonical" href="https://sachincleaning.online" />
    <meta name="facebook-domain-verification" content="59rja34sxhykuwl8r5o9kv1ret5dvy" />
    <link rel="manifest" href="manifest.json">
    <link rel="apple-touch-icon" href="icons/icon-192.png">
    <link rel="icon" type="image/png" href="icons/icon-192.png">
    <link rel="shortcut icon" href="icons/icon-192.png">
    <meta name="theme-color" content="#10B981">
    <meta name="mobile-web-app-capable" content="yes">
    <meta name="apple-mobile-web-app-capable" content="yes">
    <meta name="apple-mobile-web-app-status-bar-style" content="default">

    <!-- iOS App Icons (Different sizes) -->
    <link rel="apple-touch-icon" sizes="180x180" href="icons/ios/180.png">
    <link rel="apple-touch-icon" sizes="167x167" href="icons/ios/167.png">
    <link rel="apple-touch-icon" sizes="152x152" href="icons/ios/152.png">
    <link rel="apple-touch-icon" sizes="144x144" href="icons/ios/144.png">
    <link rel="apple-touch-icon" sizes="120x120" href="icons/ios/120.png">
    <link rel="apple-touch-icon" sizes="114x114" href="icons/ios/114.png">
    <link rel="apple-touch-icon" sizes="100x100" href="icons/ios/100.png">
    <link rel="apple-touch-icon" sizes="76x76" href="icons/ios/76.png">
    <link rel="apple-touch-icon" sizes="72x72" href="icons/ios/72.png">
    <link rel="apple-touch-icon" sizes="60x60" href="icons/ios/60.png">
    <link rel="apple-touch-icon" sizes="57x57" href="icons/ios/57.png">
    <link rel="apple-touch-icon" sizes="50x50" href="icons/ios/50.png">
    <link rel="apple-touch-icon" sizes="40x40" href="icons/ios/40.png">
    <link rel="apple-touch-icon" sizes="32x32" href="icons/ios/32.png">
    <link rel="apple-touch-icon" sizes="29x29" href="icons/ios/29.png">
    <link rel="apple-touch-icon" sizes="20x20" href="icons/ios/20.png">
    <link rel="apple-touch-icon" sizes="16x16" href="icons/ios/16.png">
    <link rel="apple-touch-icon" href="icons/ios/1024.png">
    <link rel="apple-touch-icon" sizes="256x256" href="icons/ios/256.png">
    <link rel="apple-touch-icon" sizes="192x192" href="icons/ios/192.png">
    <link rel="apple-touch-icon" sizes="128x128" href="icons/ios/128.png">
    <link rel="apple-touch-icon" sizes="64x64" href="icons/ios/64.png">
    <link rel="apple-touch-icon" sizes="58x58" href="icons/ios/58.png">

    <!-- Windows Tiles -->
    <meta name="msapplication-TileImage" content="icons/windows11/Square150x150Logo.scale-100.png">
    <meta name="msapplication-TileColor" content="#10B981">
    <meta name="msapplication-config" content="icons/windows11/browserconfig.xml">

    <!-- PWA META TAGS -->
    <meta name="mobile-web-app-title" content="Sachin Deep Cleaning" />
    <meta name="apple-mobile-web-app-title" content="Sachin Deep Cleaning" />

    <!-- ⭐ Google Review Schema for Rich Snippet -->
    <script type="application/ld+json">
  {
    "@context": "https://schema.org",
    "@type": "HomeAndConstructionBusiness",
    "name": "Sachin Deep Cleaning Services",
    "url": "https://sachincleaning.online",
    "telephone": "+919267905943",
    "address": {
      "@type": "PostalAddress",
      "addressLocality": "Gurgaon",
      "addressRegion": "Haryana",
      "addressCountry": "IN"
    },
    "aggregateRating": {
      "@type": "AggregateRating",
      "ratingValue": "4.9",
      "reviewCount": "1200"
    }
  }
  </script>
  <!-- Google Fonts: Sora (display) + Inter (UI) — unified with the mobile apps -->
  <link rel="preconnect" href="https://fonts.googleapis.com">
  <link rel="preconnect" href="https://fonts.gstatic.com" crossorigin>
  <link
      href="https://fonts.googleapis.com/css2?family=Inter:wght@300;400;500;600;700;800;900&family=Sora:wght@400;500;600;700;800&display=swap"
      rel="stylesheet">

  <link rel="stylesheet" href="dist/tailwind.css" />

<style>
    /* ══════════════════════════════════════════════════════════════
       PREMIUM DESIGN SYSTEM v3.0 — World-Class Production UI
       Project: Sachin Deep Cleaning | Firebase PWA
       Inspired by: Airbnb, Apple, Urban Company, Stripe
       ══════════════════════════════════════════════════════════════ */
    :root {
        /* ─── SURFACE COLORS (LIGHT THEME) ─── */
        --bg: #F8FAFB;
        --bg-card: #FFFFFF;
        --bg-surf: #F1F5F9;
        --bg-hover: #E8EDF2;
        --bg-elevated: #FFFFFF;

        /* ─── PRIMARY BRAND: Rich Emerald ─── */
        --sage: #10B981;
        --sage-lt: #34D399;
        --sage-dk: #059669;
        --sage-dim: rgba(16, 185, 129, 0.08);
        --sage-glow: rgba(16, 185, 129, 0.18);
        --sage-subtle: rgba(16, 185, 129, 0.10);

        /* ─── SECONDARY: Warm Gold ─── */
        --gold: #F59E0B;
        --gold-lt: #FBBF24;
        --gold-glow: rgba(245, 158, 11, 0.15);

        /* ─── TEXT HIERARCHY (LIGHT THEME) ─── */
        --text-primary: #1E293B;
        --text-secondary: #64748B;
        --text-tertiary: #94A3B8;
        --text-muted: #CBD5E1;
        --cream: #1E293B;
        --ink: #334155;
        --muted: #94A3B8;

        /* ─── BORDERS & DIVIDERS (LIGHT THEME) ─── */
        --border: rgba(0, 0, 0, 0.08);
        --border-md: rgba(0, 0, 0, 0.12);
        --border-strong: rgba(0, 0, 0, 0.18);

        /* ─── RADIUS SYSTEM ─── */
        --r-xs: 6px;
        --r-sm: 10px;
        --r-md: 16px;
        --r-lg: 24px;
        --r-xl: 32px;
        --r-full: 9999px;

        /* ─── SPACING ─── */
        --sidebar: 260px;
        --hh: 64px;

        /* ─── SAFE AREA INSETS (notches, home indicator) ─── */
        --safe-top: env(safe-area-inset-top, 0);
        --safe-bottom: env(safe-area-inset-bottom, 0);
        --safe-left: env(safe-area-inset-left, 0);
        --safe-right: env(safe-area-inset-right, 0);

        /* ─── HEADER HEIGHT (includes safe area top) ─── */
        --header-h: calc(72px + var(--safe-top));
        --header-h-mobile: calc(64px + var(--safe-top));

        /* ─── BOTTOM NAV HEIGHT (includes safe area bottom) ─── */
        --bottom-nav-h: calc(56px + var(--safe-bottom));

        /* ─── TOUCH TARGETS (iOS HIG minimum 44×44) ─── */
        --touch-target: 44px;
        --touch-target-sm: 40px;

        /* ─── SHADOWS (Lighter for light theme) ─── */
        --sh-xs: 0 1px 2px rgba(0, 0, 0, 0.05);
        --sh-sm: 0 2px 8px rgba(0, 0, 0, 0.06), 0 1px 3px rgba(0, 0, 0, 0.04);
        --sh: 0 8px 32px rgba(0, 0, 0, 0.08), 0 2px 8px rgba(0, 0, 0, 0.04);
        --sh-lg: 0 20px 60px rgba(0, 0, 0, 0.1), 0 8px 24px rgba(0, 0, 0, 0.06);
        --sh-xl: 0 32px 80px rgba(0, 0, 0, 0.12), 0 12px 40px rgba(0, 0, 0, 0.06);
        --sh-glow-emerald: 0 0 40px rgba(16, 185, 129, 0.1), 0 0 80px rgba(16, 185, 129, 0.04);
        --sh-glow-gold: 0 0 40px rgba(245, 158, 11, 0.08);

        /* ─── TIMING FUNCTIONS ─── */
        --ease-spring: cubic-bezier(0.34, 1.56, 0.64, 1);
        --ease-smooth: cubic-bezier(0.25, 0.1, 0.25, 1);
        --ease-out-expo: cubic-bezier(0.19, 1, 0.22, 1);
    }

    /* ══════════════════════════════════════════════════════════════
       DARK THEME — Full Override
       ══════════════════════════════════════════════════════════════ */
    [data-theme="dark"] {
        --bg: #0B1120;
        --bg-card: #131C2E;
        --bg-surf: #1A2540;
        --bg-hover: #1E2D4A;
        --bg-elevated: #1A2540;

        --text-primary: #E2E8F0;
        --text-secondary: #94A3B8;
        --text-tertiary: #64748B;
        --text-muted: #475569;
        --cream: #E2E8F0;
        --ink: #CBD5E1;
        --muted: #64748B;

        --border: rgba(255, 255, 255, 0.07);
        --border-md: rgba(255, 255, 255, 0.11);
        --border-strong: rgba(255, 255, 255, 0.16);

        --sh-xs: 0 1px 2px rgba(0, 0, 0, 0.4);
        --sh-sm: 0 2px 8px rgba(0, 0, 0, 0.35), 0 1px 3px rgba(0, 0, 0, 0.3);
        --sh: 0 8px 32px rgba(0, 0, 0, 0.4), 0 2px 8px rgba(0, 0, 0, 0.3);
        --sh-lg: 0 20px 60px rgba(0, 0, 0, 0.5), 0 8px 24px rgba(0, 0, 0, 0.35);
        --sh-xl: 0 32px 80px rgba(0, 0, 0, 0.6), 0 12px 40px rgba(0, 0, 0, 0.4);
    }

    /* ═══ UNIFIED TOKENS: spacing, status, icon system ═══ */
    :root {
        --space-1: 4px;  --space-2: 8px;  --space-3: 12px; --space-4: 16px;
        --space-5: 20px; --space-6: 24px; --space-8: 32px; --space-10: 40px;
        --space-12: 48px; --space-16: 64px;
        --c-pending: #3B82F6; --c-progress: #F59E0B; --c-completed: #10B981;
        --c-cancelled: #EF4444; --c-info: #3B82F6;
    }
    [data-theme="dark"] {
        --c-pending: #60A5FA; --c-progress: #FBBF24; --c-completed: #34D399;
        --c-cancelled: #FB7185; --c-info: #60A5FA;
    }

    /* ─── Icon system (inline SVG via <use href="#i-...">) ─── */
    .icon {
        width: 1.25em; height: 1.25em; display: inline-block;
        vertical-align: -0.14em; flex-shrink: 0;
        fill: none; stroke: currentColor; stroke-width: 2;
        stroke-linecap: round; stroke-linejoin: round;
    }
    .icon--fill { fill: currentColor; stroke: none; }
    .icon--sm { width: 1em; height: 1em; }
    .icon--lg { width: 1.75em; height: 1.75em; }
    .brand-mark { width: 22px; height: 22px; }
    .brand-logo-ic { color: #fff; }
    .splash-logo .icon { width: 44px; height: 44px; color: var(--sage); }
    .hero-emoji .icon { width: 56px; height: 56px; stroke-width: 1.6; color: var(--sage); }

    /* ── Dark body & background ── */
    [data-theme="dark"] body {
        background: var(--bg) !important;
        color: var(--ink) !important;
    }
    [data-theme="dark"] body::before {
        background: radial-gradient(circle, rgba(16, 185, 129, 0.06) 0%, transparent 70%);
    }
    [data-theme="dark"] body::after {
        background: radial-gradient(circle, rgba(99, 102, 241, 0.05) 0%, transparent 70%);
    }

    /* ── Dark Tailwind overrides ── */
    [data-theme="dark"] .bg-white,
    [data-theme="dark"] .bg-white\/95,
    [data-theme="dark"] .bg-white\/90 { background: var(--bg-card) !important; }

    [data-theme="dark"] .bg-gray-50 { background: var(--bg) !important; }
    [data-theme="dark"] .bg-gray-100,
    [data-theme="dark"] .bg-gray-100\/80 { background: var(--bg-surf) !important; }
    [data-theme="dark"] .bg-gray-200 { background: var(--bg-hover) !important; }
    [data-theme="dark"] .bg-gray-800 { background: #0D1625 !important; }
    [data-theme="dark"] .bg-gray-900 { background: #070E1A !important; }

    [data-theme="dark"] .text-gray-900 { color: var(--text-primary) !important; }
    [data-theme="dark"] .text-gray-800 { color: #D1D9E6 !important; }
    [data-theme="dark"] .text-gray-700 { color: #A8B4C8 !important; }
    [data-theme="dark"] .text-gray-600 { color: var(--text-secondary) !important; }
    [data-theme="dark"] .text-gray-500 { color: var(--text-tertiary) !important; }
    [data-theme="dark"] .text-gray-400 { color: var(--text-muted) !important; }

    [data-theme="dark"] .border-gray-100 { border-color: rgba(255,255,255,0.06) !important; }
    [data-theme="dark"] .border-gray-200 { border-color: rgba(255,255,255,0.08) !important; }
    [data-theme="dark"] .border-gray-300 { border-color: rgba(255,255,255,0.1) !important; }
    [data-theme="dark"] .border-gray-400 { border-color: rgba(255,255,255,0.15) !important; }

    [data-theme="dark"] .divide-gray-100 > * + * { border-color: rgba(255,255,255,0.06) !important; }
    [data-theme="dark"] .divide-gray-200 > * + * { border-color: rgba(255,255,255,0.08) !important; }

    [data-theme="dark"] .shadow-lg,
    [data-theme="dark"] .shadow-xl,
    [data-theme="dark"] .shadow-2xl { box-shadow: var(--sh-lg) !important; }

    /* ── Dark glassmorphism ── */
    [data-theme="dark"] .glass-card {
        background: rgba(19, 28, 46, 0.95) !important;
        border-color: rgba(255,255,255,0.08) !important;
    }
    [data-theme="dark"] .glass-card:hover {
        background: rgba(26, 37, 64, 1) !important;
        border-color: rgba(255,255,255,0.12) !important;
    }
    [data-theme="dark"] .glass-input {
        background: var(--bg-surf) !important;
        border-color: rgba(255,255,255,0.1) !important;
        color: var(--text-primary) !important;
    }
    [data-theme="dark"] .glass-input:focus {
        background: var(--bg-hover) !important;
        border-color: var(--sage) !important;
    }

    /* ── Dark Header ── */
    [data-theme="dark"] header {
        background: rgba(11, 17, 32, 0.95) !important;
        border-bottom-color: rgba(255,255,255,0.07) !important;
        backdrop-filter: blur(20px) !important;
    }

    /* ── Dark Sidebar ── */
    [data-theme="dark"] aside {
        background: var(--bg-card) !important;
        border-right-color: rgba(255,255,255,0.07) !important;
    }

    /* ── Dark Bottom Nav ── */
    [data-theme="dark"] nav > div.flex {
        background: rgba(11, 17, 32, 0.97) !important;
        border-top: 1px solid rgba(255,255,255,0.07) !important;
        backdrop-filter: blur(20px) !important;
    }

    /* ── Dark Mobile Menu Dropdown ── */
    [data-theme="dark"] .absolute.left-0.right-0.top-full.bg-white {
        background: var(--bg-card) !important;
        border-color: rgba(255,255,255,0.08) !important;
    }

    /* ── Dark Forms ── */
    [data-theme="dark"] input,
    [data-theme="dark"] textarea,
    [data-theme="dark"] select {
        background: var(--bg-surf) !important;
        border-color: rgba(255,255,255,0.1) !important;
        color: var(--text-primary) !important;
    }
    [data-theme="dark"] input::placeholder,
    [data-theme="dark"] textarea::placeholder { color: var(--text-tertiary) !important; }
    [data-theme="dark"] input:-webkit-autofill,
    [data-theme="dark"] input:-webkit-autofill:focus {
        -webkit-box-shadow: 0 0 0 30px var(--bg-surf) inset !important;
        -webkit-text-fill-color: var(--text-primary) !important;
    }
    [data-theme="dark"] input:disabled { background: var(--bg-hover) !important; }

    /* ── Dark Cards / Panels ── */
    [data-theme="dark"] .rounded-2xl,
    [data-theme="dark"] .rounded-xl {
        border-color: rgba(255,255,255,0.07);
    }
    [data-theme="dark"] .bg-blue-50 { background: rgba(59, 130, 246, 0.1) !important; }
    [data-theme="dark"] .bg-red-50 { background: rgba(239, 68, 68, 0.1) !important; }
    [data-theme="dark"] .bg-yellow-50 { background: rgba(245, 158, 11, 0.1) !important; }
    [data-theme="dark"] .bg-green-50 { background: rgba(16, 185, 129, 0.1) !important; }
    [data-theme="dark"] .hover\:bg-gray-100:hover { background: var(--bg-surf) !important; }
    [data-theme="dark"] .hover\:bg-red-50:hover { background: rgba(239, 68, 68, 0.15) !important; }

    /* ── Dark skeleton loader ── */
    [data-theme="dark"] .skeleton {
        background: linear-gradient(90deg, var(--bg-surf) 25%, var(--bg-hover) 50%, var(--bg-surf) 75%);
        background-size: 1000px 100%;
    }

    /* ── Dark Splash Screen ── */
    [data-theme="dark"] .splash-screen { background: #0B1120 !important; }

    /* ── Dark scrollbar ── */
    [data-theme="dark"] ::-webkit-scrollbar-thumb { background: rgba(255,255,255,0.1); }
    [data-theme="dark"] ::-webkit-scrollbar-thumb:hover { background: rgba(255,255,255,0.18); }

    /* ── Dark Login Card ── */
    [data-theme="dark"] .bg-gray-100.rounded-lg { background: var(--bg-surf) !important; }

    /* ── Dark step indicators ── */
    [data-theme="dark"] .bg-gray-200.text-gray-500 { background: var(--bg-surf) !important; }

    /* ══════════════════════════════════════════════════════════════
       THEME TOGGLE BUTTON STYLES
       ══════════════════════════════════════════════════════════════ */
    .theme-toggle-wrap {
        display: flex;
        align-items: center;
        gap: 6px;
        padding: 4px 6px 4px 4px;
        border-radius: 999px;
        border: 1.5px solid var(--border-md);
        background: var(--bg-surf);
        cursor: pointer;
        transition: all 0.3s var(--ease-smooth);
        user-select: none;
        flex-shrink: 0;
    }
    .theme-toggle-wrap:hover {
        border-color: var(--sage);
        box-shadow: 0 0 0 3px var(--sage-dim);
    }
    .theme-toggle-track {
        position: relative;
        width: 36px;
        height: 20px;
        background: #CBD5E1;
        border-radius: 999px;
        transition: background 0.35s ease;
        flex-shrink: 0;
    }
    [data-theme="dark"] .theme-toggle-track { background: var(--sage-dk); }
    .theme-toggle-thumb {
        position: absolute;
        top: 2px;
        left: 2px;
        width: 16px;
        height: 16px;
        border-radius: 50%;
        background: #fff;
        box-shadow: 0 1px 4px rgba(0,0,0,0.2);
        transition: transform 0.35s var(--ease-spring);
    }
    [data-theme="dark"] .theme-toggle-thumb { transform: translateX(16px); }
    .theme-toggle-icon {
        font-size: 14px;
        line-height: 1;
        transition: all 0.3s ease;
    }
    .theme-toggle-label {
        font-size: 11px;
        font-weight: 600;
        letter-spacing: 0.02em;
        color: var(--text-secondary);
        transition: color 0.3s ease;
        white-space: nowrap;
        font-family: 'Inter', sans-serif;
    }

    /* ── Dark Login / Signup Card (inline style override) ── */
    [data-theme="dark"] .max-w-md .relative.rounded-2xl.shadow-2xl.border {
        background: var(--bg-card) !important;
        border-color: rgba(255,255,255,0.1) !important;
    }
    /* OR divider white span */
    [data-theme="dark"] span.bg-white {
        background: var(--bg-card) !important;
        color: var(--text-secondary) !important;
    }
    /* Details/summary panels inside login */
    [data-theme="dark"] details summary {
        background: var(--bg-surf) !important;
        color: var(--text-secondary) !important;
    }
    [data-theme="dark"] details > div {
        background: var(--bg-surf) !important;
    }
    /* Tip banner in login */
    [data-theme="dark"] .bg-blue-50.border.border-blue-200.rounded-lg {
        background: rgba(59,130,246,0.08) !important;
        border-color: rgba(59,130,246,0.2) !important;
    }
    [data-theme="dark"] .bg-blue-50.border.border-blue-200.rounded-lg p {
        color: #93C5FD !important;
    }
    /* Google sign-in button */
    [data-theme="dark"] .bg-white.hover\:bg-slate-100 {
        background: var(--bg-surf) !important;
        color: var(--text-primary) !important;
        border: 1px solid rgba(255,255,255,0.1) !important;
    }
    [data-theme="dark"] .bg-white.hover\:bg-slate-100:hover {
        background: var(--bg-hover) !important;
    }
    /* Step progress connector lines */
    [data-theme="dark"] .h-0\.5.w-6.bg-gray-100 {
        background: rgba(255,255,255,0.08) !important;
    }
    /* Login card top border stays emerald */
    [data-theme="dark"] .max-w-md .relative.rounded-2xl.shadow-2xl.border {
        border-top: 2px solid var(--sage) !important;
    }
    /* "Continue as Guest" section text */
    [data-theme="dark"] .text-center.mt-6 > p.text-gray-500 {
        color: var(--text-secondary) !important;
    }

    /* ─── GLOBAL RESET & BASE ─── */
    *,
    *::before,
    *::after {
        box-sizing: border-box;
    }

    body {
        margin: 0;
        padding: 0;
        background: var(--bg);
        color: var(--ink);
        font-family: 'Inter', -apple-system, BlinkMacSystemFont, system-ui, sans-serif;
        font-size: 15px;
        line-height: 1.6;
        -webkit-font-smoothing: antialiased;
        -moz-osx-font-smoothing: grayscale;
        text-rendering: optimizeLegibility;
        font-feature-settings: 'cv11', 'ss01';
        overflow-x: hidden;
    }

    /* Ambient background effects — subtle for light theme */
    body::before {
        content: '';
        position: fixed;
        top: -40%;
        right: -20%;
        width: 600px;
        height: 600px;
        background: radial-gradient(circle, rgba(16, 185, 129, 0.03) 0%, transparent 70%);
        pointer-events: none;
        z-index: 0;
        animation: ambientFloat 25s ease-in-out infinite;
    }

    body::after {
        content: '';
        position: fixed;
        bottom: -30%;
        left: -15%;
        width: 500px;
        height: 500px;
        background: radial-gradient(circle, rgba(245, 158, 11, 0.02) 0%, transparent 70%);
        pointer-events: none;
        z-index: 0;
        animation: ambientFloat 30s ease-in-out infinite reverse;
    }

    @keyframes ambientFloat {

        0%,
        100% {
            transform: translate(0, 0) scale(1);
        }

        33% {
            transform: translate(30px, -20px) scale(1.05);
        }

        66% {
            transform: translate(-20px, 15px) scale(0.95);
        }
    }

    header h1,
    header p {
        margin: 0;
    }

    /* ─── TYPOGRAPHY ─── */
    h1,
    h2,
    h3,
    h4 {
        font-family: 'Sora', 'Inter', system-ui, sans-serif;
        font-weight: 600;
        line-height: 1.15;
        color: var(--text-primary);
        letter-spacing: -0.02em;
    }

    /* ─── SCROLLBAR STYLING ─── */
    ::-webkit-scrollbar {
        width: 6px;
        height: 6px;
    }

    ::-webkit-scrollbar-track {
        background: transparent;
    }

    ::-webkit-scrollbar-thumb {
        background: rgba(0, 0, 0, 0.12);
        border-radius: 100px;
    }

    ::-webkit-scrollbar-thumb:hover {
        background: rgba(0, 0, 0, 0.2);
    }

    .scrollbar-hide::-webkit-scrollbar {
        display: none;
    }

    .scrollbar-hide {
        -ms-overflow-style: none;
        scrollbar-width: none;
    }

    /* ════════════════════════════════════════
       SPLASH SCREEN
       ════════════════════════════════════════ */
    @keyframes spin-smooth {
        0% {
            transform: rotate(0deg);
        }

        100% {
            transform: rotate(360deg);
        }
    }

    @keyframes fade-out {
        0% {
            opacity: 1;
        }

        100% {
            opacity: 0;
        }
    }

    @keyframes bounce-logo {

        0%,
        100% {
            transform: translateY(0px) scale(1);
        }

        50% {
            transform: translateY(-16px) scale(1.03);
        }
    }

    @keyframes glow-pulse {

        0%,
        100% {
            box-shadow: 0 0 30px var(--sage-glow), 0 0 60px rgba(16, 185, 129, 0.08);
        }

        50% {
            box-shadow: 0 0 50px var(--sage-glow), 0 0 100px rgba(16, 185, 129, 0.12);
        }
    }

    .splash-screen {
        position: fixed;
        top: 0;
        left: 0;
        width: 100%;
        height: 100%;
        background: #FFFFFF;
        display: flex;
        flex-direction: column;
        align-items: center;
        justify-content: center;
        z-index: 9999;
        gap: 32px;
    }

    .splash-screen::before {
        content: '';
        position: absolute;
        width: 300px;
        height: 300px;
        background: radial-gradient(circle, rgba(16, 185, 129, 0.10) 0%, transparent 70%);
        border-radius: 50%;
        filter: blur(60px);
        animation: glow-pulse 3s ease-in-out infinite;
    }

    .splash-logo-container {
        position: relative;
        width: 110px;
        height: 110px;
        display: flex;
        align-items: center;
        justify-content: center;
    }

    .splash-logo {
        width: 100%;
        height: 100%;
        background: linear-gradient(135deg, var(--sage-dk), var(--sage), var(--sage-lt));
        border-radius: var(--r-lg);
        display: flex;
        align-items: center;
        justify-content: center;
        font-size: 52px;
        animation: bounce-logo 2.5s ease-in-out infinite;
        box-shadow: var(--sh-glow-emerald);
    }

    .splash-spinner {
        position: absolute;
        width: 130px;
        height: 130px;
        border: 3px solid rgba(16, 185, 129, 0.15);
        border-top: 3px solid var(--sage);
        border-radius: 50%;
        animation: spin-smooth 1.5s linear infinite;
    }

    .splash-text {
        color: var(--text-secondary);
        font-family: 'Inter', sans-serif;
        font-size: 13px;
        font-weight: 600;
        letter-spacing: 2.5px;
        text-transform: uppercase;
        animation: pulse-gentle 2s ease-in-out infinite;
    }

    .splash-loading-bar {
        width: 180px;
        height: 3px;
        background: rgba(16, 185, 129, 0.15);
        border-radius: 100px;
        overflow: hidden;
    }

    .splash-loading-bar-fill {
        height: 100%;
        background: linear-gradient(90deg, var(--sage-dk), var(--sage), var(--sage-lt));
        border-radius: 100px;
        animation: loadingProgress 2s ease-in-out infinite;
    }

    @keyframes loadingProgress {
        0% {
            width: 0%;
        }

        50% {
            width: 70%;
        }

        100% {
            width: 100%;
        }
    }

    .splash-fade-out {
        animation: fade-out 0.5s ease-out forwards;
    }

    /* ════════════════════════════════════════
       GLOBAL ELEMENTS
       ════════════════════════════════════════ */
    img {
        max-width: 100%;
        height: auto;
        display: block;
    }

    .modal-content {
        max-height: calc(100vh - 4rem);
        overflow-y: auto;
    }

    .truncate-multiline {
        display: -webkit-box;
        -webkit-line-clamp: 3;
        line-clamp: 3;
        -webkit-box-orient: vertical;
        overflow: hidden;
    }

    @keyframes pulse-gentle {

        0%,
        100% {
            opacity: 1;
        }

        50% {
            opacity: 0.6;
        }
    }

    .animate-pulse-gentle {
        animation: pulse-gentle 2s cubic-bezier(0.4, 0, 0.6, 1) infinite;
    }

    /* ════════════════════════════════════════
       ANIMATIONS
       ════════════════════════════════════════ */
    @keyframes slideIn {
        from {
            opacity: 0;
            transform: translateY(12px);
        }

        to {
            opacity: 1;
            transform: translateY(0);
        }
    }

    @keyframes fadeInScale {
        from {
            opacity: 0;
            transform: scale(0.96);
        }

        to {
            opacity: 1;
            transform: scale(1);
        }
    }

    @keyframes shimmer {
        0% {
            background-position: -1000px 0;
        }

        100% {
            background-position: 1000px 0;
        }
    }

    @keyframes slideInRight {
        from {
            opacity: 0;
            transform: translateX(20px);
        }

        to {
            opacity: 1;
            transform: translateX(0);
        }
    }

    @keyframes scaleUp {
        from {
            opacity: 0;
            transform: scale(0.92);
        }

        to {
            opacity: 1;
            transform: scale(1);
        }
    }

    @keyframes float-gentle {

        0%,
        100% {
            transform: translateY(0px);
        }

        50% {
            transform: translateY(-6px);
        }
    }

    .animate-slideIn {
        animation: slideIn 0.4s var(--ease-out-expo);
    }

    .animate-fadeInScale {
        animation: fadeInScale 0.3s var(--ease-out-expo);
    }

    .animate-float {
        animation: float-gentle 5s ease-in-out infinite;
    }

    .skeleton {
        background: linear-gradient(90deg, #E2E8F0 25%, #F1F5F9 50%, #E2E8F0 75%);
        background-size: 1000px 100%;
        animation: shimmer 2s infinite;
        border-radius: var(--r-sm);
    }

    /* ════════════════════════════════════════
       GLASSMORPHISM SYSTEM
       ════════════════════════════════════════ */
    .glass-card {
        background: rgba(255, 255, 255, 0.95) !important;
        backdrop-filter: blur(20px) saturate(1.2);
        -webkit-backdrop-filter: blur(20px) saturate(1.2);
        border: 1px solid var(--border);
        box-shadow: var(--sh-sm);
        transition: all 0.4s var(--ease-out-expo);
    }

    .glass-card:hover {
        background: rgba(255, 255, 255, 1) !important;
        border-color: var(--border-md);
        box-shadow: var(--sh);
        transform: translateY(-2px);
    }

    .glass-input {
        background: #F8FAFC !important;
        backdrop-filter: blur(10px);
        -webkit-backdrop-filter: blur(10px);
        border: 1.5px solid #E2E8F0 !important;
        color: var(--text-primary);
        border-radius: var(--r-sm) !important;
        transition: all 0.3s var(--ease-smooth);
    }

    .glass-input:focus {
        background: #FFFFFF !important;
        border-color: var(--sage) !important;
        box-shadow: 0 0 0 3px var(--sage-dim), 0 0 20px rgba(16, 185, 129, 0.06);
        transform: none;
    }

    /* ════════════════════════════════════════
       BUTTON SYSTEM
       ════════════════════════════════════════ */
    .btn-gradient-primary {
        background: linear-gradient(135deg, var(--sage-dk), var(--sage)) !important;
        box-shadow: 0 4px 14px var(--sage-glow), inset 0 1px 0 rgba(255, 255, 255, 0.1);
        color: white;
        font-weight: 600;
        letter-spacing: 0.01em;
        border-radius: var(--r-sm);
        transition: all 0.3s var(--ease-smooth);
    }

    .btn-gradient-primary:hover {
        background: linear-gradient(135deg, var(--sage), var(--sage-lt)) !important;
        box-shadow: 0 6px 20px var(--sage-glow), inset 0 1px 0 rgba(255, 255, 255, 0.15);
        transform: translateY(-1px);
    }

    .btn-gradient-accent {
        background: linear-gradient(135deg, #D97706, var(--gold)) !important;
        box-shadow: 0 4px 14px var(--gold-glow), inset 0 1px 0 rgba(255, 255, 255, 0.1);
        color: white;
        font-weight: 600;
        border-radius: var(--r-sm);
    }

    .btn-gradient-accent:hover {
        background: linear-gradient(135deg, var(--gold), var(--gold-lt)) !important;
        box-shadow: 0 6px 20px var(--gold-glow);
        transform: translateY(-1px);
    }

    /* Button ripple effect */
    button {
        transition: all 0.3s var(--ease-smooth);
        position: relative;
        overflow: hidden;
        cursor: pointer;
    }

    button::after {
        content: '';
        position: absolute;
        top: 50%;
        left: 50%;
        width: 0;
        height: 0;
        border-radius: 50%;
        background: rgba(255, 255, 255, 0.15);
        transform: translate(-50%, -50%);
        transition: width 0.5s var(--ease-out-expo), height 0.5s var(--ease-out-expo);
    }

    button:hover::after {
        width: 300px;
        height: 300px;
    }

    /* Reset ripple when not hovered */
    button:not(:hover)::after {
        width: 0 !important;
        height: 0 !important;
        transition: width 0.2s ease, height 0.2s ease;
    }

    /* Disable ripple effect for theme toggle */
    .theme-toggle-wrap::after {
        display: none !important;
    }

    button:active:not(:disabled) {
        transform: scale(0.97);
    }

    button:disabled {
        cursor: not-allowed;
        opacity: 0.5;
    }

    /* ════════════════════════════════════════
       INPUT SYSTEM
       ════════════════════════════════════════ */
    input,
    textarea,
    select {
        transition: all 0.3s var(--ease-smooth);
        font-family: 'Inter', sans-serif;
    }

    input:focus,
    textarea:focus,
    select:focus {
        box-shadow: 0 0 0 3px var(--sage-dim), 0 0 20px rgba(16, 185, 129, 0.04);
        transform: none;
        outline: none;
    }

    /* Autofill styling */
    input:-webkit-autofill,
    input:-webkit-autofill:hover,
    input:-webkit-autofill:focus,
    input:-webkit-autofill:active {
        -webkit-box-shadow: 0 0 0 30px #F8FAFC inset !important;
        -webkit-text-fill-color: var(--text-primary) !important;
        caret-color: var(--text-primary) !important;
        font-family: 'Inter', sans-serif !important;
    }

    /* ════════════════════════════════════════
       CARD HOVER EFFECTS
       ════════════════════════════════════════ */
    .card-hover {
        transition: all 0.4s var(--ease-out-expo);
        position: relative;
        overflow: hidden;
    }

    .card-hover:hover {
        transform: translateY(-4px);
        box-shadow: var(--sh-lg), var(--sh-glow-emerald);
    }

    .card-hover::before {
        content: '';
        position: absolute;
        top: 0;
        left: 0;
        right: 0;
        bottom: 0;
        background: linear-gradient(135deg, rgba(16, 185, 129, 0.04) 0%, transparent 50%);
        opacity: 0;
        transition: opacity 0.4s ease;
        pointer-events: none;
        border-radius: inherit;
    }

    .card-hover:hover::before {
        opacity: 1;
    }

    /* ════════════════════════════════════════
       GRADIENT & VISUAL EFFECTS
       ════════════════════════════════════════ */
    .gradient-bg-premium {
        background: linear-gradient(135deg, var(--sage-dim) 0%, rgba(16, 185, 129, 0.02) 100%);
    }

    .border-gradient {
        border: 1.5px solid transparent;
        background-image: linear-gradient(var(--bg-card), var(--bg-card)), linear-gradient(135deg, var(--sage), var(--gold));
        background-origin: border-box;
        background-clip: padding-box, border-box;
    }

    .text-gradient {
        background: linear-gradient(135deg, var(--sage-lt) 0%, var(--gold-lt) 100%);
        -webkit-background-clip: text;
        -webkit-text-fill-color: transparent;
        background-clip: text;
    }

    .text-glow {
        color: var(--sage);
        text-shadow: 0 0 20px var(--sage-glow), 0 0 40px rgba(16, 185, 129, 0.1);
    }

    /* ════════════════════════════════════════
       HEADER
       ════════════════════════════════════════ */
    header {
        background: rgba(255, 255, 255, 0.92) !important;
        backdrop-filter: blur(24px) saturate(1.5);
        -webkit-backdrop-filter: blur(24px) saturate(1.5);
        border-bottom: 1px solid var(--border);
        box-shadow: 0 1px 10px rgba(0, 0, 0, 0.06);
    }

    /* ── Safe Area & Touch Target Tokens ─────────────────────────────────────
       Safe area insets for notches/dynamic islands. Touch targets per iOS HIG (44px min). */
    :root {
        --safe-top: env(safe-area-inset-top, 0);
        --safe-bottom: env(safe-area-inset-bottom, 0);
        --safe-left: env(safe-area-inset-left, 0);
        --safe-right: env(safe-area-inset-right, 0);
        --header-h: calc(72px + var(--safe-top));
        --header-h-mobile: calc(64px + var(--safe-top));
        --bottom-nav-h: calc(56px + var(--safe-bottom));
        --touch-target: 44px;
        --touch-target-sm: 40px;
    }

    @media (max-width: 767px) {
        :root {
            --header-h: var(--header-h-mobile);
        }
    }

    /* ── Header height token ───────────────────────────────────────────────
       The glass header is position:fixed;top:0, so page content needs ONE
       top offset equal to the header height. We set it here (once) instead of
       padding every page section, which previously double-padded content and
       left a large empty gap between the header and the page. */
    main {
        padding-top: var(--header-h) !important;
        padding-bottom: var(--bottom-nav-h) !important;
    }

    @media (min-width: 768px) {
        main {
            padding-bottom: 0 !important;
        }
    }

    /* Minimum touch targets */
    .touch-target { min-height: var(--touch-target); min-width: var(--touch-target); }
    .touch-target-sm { min-height: var(--touch-target-sm); min-width: var(--touch-target-sm); }

    /* Prevent iOS input zoom - font-size >= 16px */
    input, textarea, select { font-size: 16px !important; }

    /* Smooth touch scrolling */
    .scroll-touch { -webkit-overflow-scrolling: touch; overflow-scrolling: touch; }

    /* Safe area utilities */
    .safe-top { padding-top: var(--safe-top); }
    .safe-bottom { padding-bottom: var(--safe-bottom); }
    .safe-left { padding-left: var(--safe-left); }
    .safe-right { padding-right: var(--safe-right); }
    .safe-all { padding: var(--safe-top) var(--safe-right) var(--safe-bottom) var(--safe-left); }

    /* ════════════════════════════════════════
       MODAL
       ════════════════════════════════════════ */
    .modal-content {
        background: #FFFFFF;
        backdrop-filter: blur(30px) saturate(1.3);
        -webkit-backdrop-filter: blur(30px) saturate(1.3);
        border: 1px solid var(--border);
        box-shadow: var(--sh-xl);
    }

    /* ════════════════════════════════════════
       SMOOTH EXPERIENCE 
       ════════════════════════════════════════ */
    [x-cloak] {
        display: none !important;
    }

    html,
    body {
        scroll-behavior: smooth;
    }

    @media (prefers-reduced-motion: reduce) {

        *,
        *::before,
        *::after {
            animation-duration: 0.01ms !important;
            animation-iteration-count: 1 !important;
            transition-duration: 0.01ms !important;
        }
    }

    @media (min-width: 1024px) {
        header .mx-auto {
            max-width: 1280px;
        }
    }

    /* ════════════════════════════════════════
       PRODUCT CARDS — Fluid Responsive
       ════════════════════════════════════════ */
    .products-grid {
        display: grid;
        grid-template-columns: repeat(auto-fill, minmax(min(100%, 160px), 1fr));
        gap: var(--space-3);
    }

    @media (min-width: 640px) {
        .products-grid {
            grid-template-columns: repeat(auto-fill, minmax(min(100%, 180px), 1fr));
        }
    }

    @media (min-width: 1024px) {
        .products-grid {
            grid-template-columns: repeat(auto-fill, minmax(min(100%, 200px), 1fr));
        }
    }

    .product-card {
        width: 100%;
        max-width: none;
        min-width: 0;
        border-radius: var(--r-md) !important;
        border: 1px solid #E2E8F0 !important;
        background: #FFFFFF !important;
        transition: all 0.35s var(--ease-out-expo) !important;
        overflow: hidden !important;
        display: flex;
        flex-direction: column;
    }

    .product-card:hover {
        border-color: #CBD5E1 !important;
        box-shadow: var(--sh), 0 0 40px rgba(16, 185, 129, 0.04) !important;
        transform: translateY(-3px) !important;
    }

    .product-card>div.overflow-hidden {
        aspect-ratio: 1;
        max-height: none;
        min-height: 0;
    }

    @media (min-width: 768px) {
        .product-card>div.overflow-hidden {
            aspect-ratio: 4/3;
        }
    }

    .product-card img {
        width: 100%;
        height: 100%;
        object-fit: cover;
        transition: transform 0.5s var(--ease-out-expo);
    }

    .product-card:hover img {
        transform: scale(1.08);
    }

    /* ════════════════════════════════════════
       BOTTOM NAVIGATION — Premium
       ════════════════════════════════════════ */
    nav.fixed.bottom-0 {
        background: rgba(255, 255, 255, 0.95) !important;
        backdrop-filter: blur(24px) saturate(1.5) !important;
        -webkit-backdrop-filter: blur(24px) saturate(1.5) !important;
        border-top: 1px solid rgba(0,0,0,0.08) !important;
        box-shadow: 0 -4px 20px rgba(0, 0, 0, 0.06) !important;
    }

    /* ════════════════════════════════════════
       SIDEBAR — Premium Desktop
       ════════════════════════════════════════ */
    aside {
        background: rgba(255, 255, 255, 0.95) !important;
        backdrop-filter: blur(20px) !important;
        border-right: 1px solid rgba(0,0,0,0.08) !important;
    }

    /* ════════════════════════════════════════
       ACTIVE NAV INDICATOR
       ════════════════════════════════════════ */
    .bg-emerald-500,
    .bg-emerald-600 {
        background: linear-gradient(135deg, var(--sage-dk), var(--sage)) !important;
        color: white !important;
    }

    /* Fix for all emerald-* color utilities used in the codebase */
    .text-emerald-400,
    .text-emerald-300,
    .text-emerald-500 {
        color: var(--sage) !important;
    }

    .hover\:text-emerald-400:hover,
    .hover\:text-emerald-300:hover {
        color: var(--sage-lt) !important;
    }

    .bg-emerald-500\/20 {
        background: var(--sage-dim) !important;
    }

    .bg-emerald-500\/10 {
        background: rgba(16, 185, 129, 0.06) !important;
    }

    .border-emerald-500,
    .border-emerald-500\/30 {
        border-color: rgba(16, 185, 129, 0.25) !important;
    }

    .ring-emerald-500,
    .focus\:ring-emerald-500:focus {
        --tw-ring-color: var(--sage) !important;
    }

    .bg-emerald-900\/20,
    .hover\:bg-emerald-900\/20:hover {
        background: rgba(16, 185, 129, 0.08) !important;
    }

    .hover\:bg-emerald-600:hover,
    .hover\:bg-emerald-700:hover {
        background: var(--sage-dk) !important;
    }

    .from-emerald-500,
    .from-emerald-600 {
        --tw-gradient-from: var(--sage) !important;
    }

    .to-emerald-600,
    .to-emerald-700 {
        --tw-gradient-to: var(--sage-dk) !important;
    }

    .hover\:from-emerald-600:hover {
        --tw-gradient-from: var(--sage-dk) !important;
    }

    .hover\:to-emerald-700:hover {
        --tw-gradient-to: #047857 !important;
    }

    .border-t-emerald-500,
    .border-emerald-400 {
        border-color: rgba(16, 185, 129, 0.2) !important;
    }

    /* ════════════════════════════════════════
       CUSTOM FOCUS VISIBLE
       ════════════════════════════════════════ */
    *:focus-visible {
        outline: 2px solid var(--sage);
        outline-offset: 2px;
    }

    /* ════════════════════════════════════════
       SELECTION COLOR
       ════════════════════════════════════════ */
    ::selection {
        background: rgba(16, 185, 129, 0.20);
        color: #1E293B;
    }

    /* ════════════════════════════════════════
       LOADING OVERLAY PREMIUM
       ════════════════════════════════════════ */
    .animate-spin {
        animation: spin-smooth 0.8s linear infinite;
    }

    /* ════════════════════════════════════════
       RESPONSIVE CONTENT WIDTH
       ════════════════════════════════════════ */
    @media (min-width: 1280px) {
        main .w-full.px-6 {
            max-width: 1200px;
            margin-left: auto;
            margin-right: auto;
        }
    }

    /* ══════════════════════════════════════════════════════════════
       PHONE SCREEN OPTIMIZATION (Phases 1-fix, 6, 7, 8)
       ══════════════════════════════════════════════════════════════ */

    /* Phase 1 fix: global tap targets + prevent double-tap zoom */
    * { -webkit-tap-highlight-color: transparent; }
    html, body { touch-action: manipulation; }
    button, [type="button"], [role="button"], .btn,
    input, select, textarea,
    a.btn, a.inline-flex, a.flex {
        min-height: var(--touch-target, 44px);
    }
    button, [type="button"], [role="button"], .btn, a.btn {
        min-width: var(--touch-target-sm, 40px);
    }

    /* Phase 8: fluid typography scale */
    :root {
        --text-xs: clamp(0.7rem, 0.65rem + 0.25vw, 0.78rem);
        --text-sm: clamp(0.8rem, 0.75rem + 0.25vw, 0.9rem);
        --text-base: clamp(0.95rem, 0.9rem + 0.25vw, 1rem);
        --text-lg: clamp(1.05rem, 1rem + 0.25vw, 1.15rem);
        --text-xl: clamp(1.2rem, 1.1rem + 0.5vw, 1.4rem);
    }
    body { font-size: var(--text-base); line-height: 1.5; }

    /* Phase 6: safe-area-aware modal height + bottom sheet on mobile */
    .modal-content {
        max-height: calc(100vh - var(--header-h) - var(--bottom-nav-h) - var(--safe-top) - var(--safe-bottom) - 2rem) !important;
        max-width: calc(100vw - 2rem) !important;
        border-radius: var(--r-lg) var(--r-lg) 0 0;
    }
    @media (max-width: 639px) {
        .modal-content {
            margin: 0 !important;
            border-radius: var(--r-xl) var(--r-xl) 0 0 !important;
        }
    }
    /* fixed overlays get notch/footer safe-area padding */
    .fixed.inset-0, [x-show].fixed.inset-0 {
        padding-top: var(--safe-top);
        padding-bottom: var(--safe-bottom);
    }
    /* toast repositioned just below the header */
    .toast-phone { top: calc(var(--header-h) + 12px) !important; }

    /* Phase 7: landscape handling for short viewports */
    @media (max-height: 500px) and (orientation: landscape) {
        :root {
            --header-h: calc(56px + var(--safe-top));
            --bottom-nav-h: calc(48px + var(--safe-bottom));
        }
        header { min-height: var(--header-h); }
        nav.fixed.bottom-0 { height: var(--bottom-nav-h); }
        .hero-slide { height: 60vh; min-height: 280px; }
        main { padding-top: var(--header-h); padding-bottom: var(--bottom-nav-h); }
        .modal-content { max-height: calc(100vh - var(--header-h) - var(--bottom-nav-h) - 1rem) !important; }
    }
</style>


<!-- Firebase SDKs (COMPAT - Latest version) -->
<script src="https://www.gstatic.com/firebasejs/10.7.2/firebase-app-compat.js"></script>
<script src="https://www.gstatic.com/firebasejs/10.7.2/firebase-auth-compat.js"></script>
<script src="https://www.gstatic.com/firebasejs/10.7.2/firebase-database-compat.js"></script>
<script src="https://www.gstatic.com/firebasejs/10.7.2/firebase-firestore-compat.js"></script>
<script src="https://www.gstatic.com/firebasejs/10.7.2/firebase-messaging-compat.js"></script>
<script src="https://www.gstatic.com/firebasejs/10.7.2/firebase-storage-compat.js"></script>
<script src="https://www.gstatic.com/firebasejs/10.7.2/firebase-app-check-compat.js"></script>

<!-- APK-Specific Utilities (must load BEFORE config.js) -->
<script src="apk-fixes.js"></script>

<!-- SECURITY (C1): Firebase Hosting auto-config injects the project config at
     runtime, so no hardcoded apiKey ships in production. Dev falls back to the
     literal in config.js when init.js is unavailable. -->
<script src="/__/firebase/init.js"></script>

<!-- Firebase Configuration (MUST load BEFORE script.js) -->
<script src="config.js"></script>

<!-- FIX: Polyfill for AppCheckDebugProvider -->
<script>
    if (typeof firebase !== 'undefined' && firebase.appCheck && !firebase.appCheck.AppCheckDebugProvider) {
        firebase.appCheck.AppCheckDebugProvider = class {
            constructor() { console.log('Mock AppCheckDebugProvider initialized'); }
            activate() { return Promise.resolve(); }
            getToken() { return Promise.resolve({ token: 'debug-token', expireTimeMillis: Date.now() + 3600000 }); }
        };
    }
</script>

<!-- Application Script (IMPORTANT: NO defer for proper initialization order in APK) -->
<script src="script.js"></script>
<!-- HIDE HOOK (loading.js): safety net — hide the shared splash once the
     window has fully loaded. The primary hide runs in script.js when auth +
     first data are ready; loading.js also auto-hides at 2400ms max. -->
<script>
    window.addEventListener('load', function () {
        if (window.SachinLoading) window.SachinLoading.hide();
    });
</script>

<!-- FIX: Patch ecommerceApp for Alpine - only add missing fields, never replace the full return object -->
<script>
    if (typeof window.ecommerceApp !== 'undefined' && typeof window.ecommerceApp === 'function') {
        const _originalApp = window.ecommerceApp;
        window.ecommerceApp = function () {
            // Get the full data object from script.js (all properties intact)
            const data = _originalApp.apply(this, arguments);
            // Only fill in any fields that are genuinely missing - never overwrite existing ones
            if (!data.authMethod) data.authMethod = 'email-password';
            if (data.loading === undefined) data.loading = { auth: false, orders: false, placeOrder: false, contactForm: false, location: false };
            return data;
        };
    }
</script>

<!-- Alpine.js (defer, after app script) -->
<script defer src="https://cdn.jsdelivr.net/npm/alpinejs@3.x.x/dist/cdn.min.js"></script>

<!-- Clarity Analytics -->
<script type="text/javascript">
    (function (c, l, a, r, i, t, y) {
        c[a] = c[a] || function () { (c[a].q = c[a].q || []).push(arguments) };
        t = l.createElement(r); t.async = 1; t.src = "https://www.clarity.ms/tag/" + i;
        y = l.getElementsByTagName(r)[0]; y.parentNode.insertBefore(t, y);
    })(window, document, "clarity", "script", "usguqk68v2");
</script>

<!-- Google tag (gtag.js) -->
<script async src="https://www.googletagmanager.com/gtag/js?id=G-BQBB8LFYEY"></script>
<script>
    window.dataLayer = window.dataLayer || [];
    function gtag() { dataLayer.push(arguments); }
    gtag('js', new Date());

    gtag('config', 'G-BQBB8LFYEY');
</script>

<script>
    // App Check enabled with reCAPTCHA v3
    window.FIREBASE_APPCHECK_SITE_KEY = "6LfANTosAAAAABt6IEo8DTYCnAQ-oy_e66Q2NlsL";
    // Set this to true to enable protection
    window.ENABLE_APP_CHECK = true;
</script>

</head>

<body class="bg-gray-50 min-h-screen text-gray-900" x-data="ecommerceApp" x-init="init()">
    <!-- ═══ ICON SPRITE (inline SVG symbols; reference via <svg class="icon"><use href="#i-..."/></svg>) ═══ -->
    <svg xmlns="http://www.w3.org/2000/svg" style="display:none" aria-hidden="true">
      <symbol id="i-sparkle" viewBox="0 0 24 24"><path d="M12 2c.4 3.8 2.2 5.6 6 6-3.8.4-5.6 2.2-6 6-.4-3.8-2.2-5.6-6-6 3.8-.4 5.6-2.2 6-6z"/></symbol>
      <symbol id="i-home" viewBox="0 0 24 24"><path d="m3 9 9-7 9 7v11a2 2 0 0 1-2 2H5a2 2 0 0 1-2-2z"/><path d="M9 22V12h6v10"/></symbol>
      <symbol id="i-kitchen" viewBox="0 0 24 24"><path d="M3 2v7c0 1.1.9 2 2 2a2 2 0 0 0 2-2V2"/><path d="M5 2v20"/><path d="M17 2v20"/><path d="M17 2c-1.66 0-3 1.34-3 3v7c0 1.66 1.34 3 3 3h0a3 3 0 0 0 3-3V5c0-1.66-1.34-3-3-3z"/></symbol>
      <symbol id="i-sofa" viewBox="0 0 24 24"><path d="M5 11V6a2 2 0 0 1 2-2h10a2 2 0 0 1 2 2v5"/><path d="M3 11h18a2 2 0 0 1 2 2v3a2 2 0 0 1-2 2H3a2 2 0 0 1-2-2v-3a2 2 0 0 1 2-2z"/><path d="M4 18v2"/><path d="M20 18v2"/></symbol>
      <symbol id="i-cart" viewBox="0 0 24 24"><circle cx="8" cy="21" r="1"/><circle cx="19" cy="21" r="1"/><path d="M2.05 2.05h2l2.66 12.42a2 2 0 0 0 2 1.58h9.78a2 2 0 0 0 1.95-1.57l1.65-7.43H5.12"/></symbol>
      <symbol id="i-clipboard" viewBox="0 0 24 24"><rect x="8" y="2" width="8" height="4" rx="1"/><path d="M16 4h2a2 2 0 0 1 2 2v14a2 2 0 0 1-2 2H6a2 2 0 0 1-2-2V6a2 2 0 0 1 2-2h2"/><path d="M9 12h6"/><path d="M9 16h6"/></symbol>
      <symbol id="i-doc" viewBox="0 0 24 24"><path d="M14 2H6a2 2 0 0 0-2 2v16a2 2 0 0 0 2 2h12a2 2 0 0 0 2-2V8z"/><path d="M14 2v6h6"/><path d="M16 13H8"/><path d="M16 17H8"/><path d="M10 9H8"/></symbol>
      <symbol id="i-location" viewBox="0 0 24 24"><path d="M20 10c0 6-8 12-8 12s-8-6-8-12a8 8 0 0 1 16 0z"/><circle cx="12" cy="10" r="3"/></symbol>
      <symbol id="i-phone" viewBox="0 0 24 24"><path d="M22 16.92v3a2 2 0 0 1-2.18 2 19.79 19.79 0 0 1-8.63-3.07 19.5 19.5 0 0 1-6-6 19.79 19.79 0 0 1-3.07-8.67A2 2 0 0 1 4.11 2h3a2 2 0 0 1 2 1.72c.13.96.36 1.9.7 2.81a2 2 0 0 1-.45 2.11L8.09 9.91a16 16 0 0 0 6 6l1.27-1.27a2 2 0 0 1 2.11-.45c.91.34 1.85.57 2.81.7A2 2 0 0 1 22 16.92z"/></symbol>
      <symbol id="i-mail" viewBox="0 0 24 24"><rect x="2" y="4" width="20" height="16" rx="2"/><path d="m22 7-10 5L2 7"/></symbol>
      <symbol id="i-lock" viewBox="0 0 24 24"><rect x="3" y="11" width="18" height="11" rx="2"/><path d="M7 11V7a5 5 0 0 1 10 0v4"/></symbol>
      <symbol id="i-target" viewBox="0 0 24 24"><circle cx="12" cy="12" r="10"/><circle cx="12" cy="12" r="6"/><circle cx="12" cy="12" r="2"/></symbol>
      <symbol id="i-user" viewBox="0 0 24 24"><path d="M19 21v-2a4 4 0 0 0-4-4H9a4 4 0 0 0-4 4v2"/><circle cx="12" cy="7" r="4"/></symbol>
      <symbol id="i-calendar" viewBox="0 0 24 24"><rect x="3" y="4" width="18" height="18" rx="2"/><path d="M16 2v4"/><path d="M8 2v4"/><path d="M3 10h18"/></symbol>
      <symbol id="i-check" viewBox="0 0 24 24"><path d="M20 6 9 17l-5-5"/></symbol>
      <symbol id="i-check-circle" viewBox="0 0 24 24"><circle cx="12" cy="12" r="10"/><path d="m9 12 2 2 4-4"/></symbol>
      <symbol id="i-warning" viewBox="0 0 24 24"><path d="M10.29 3.86 1.82 18a2 2 0 0 0 1.71 3h16.94a2 2 0 0 0 1.71-3L13.71 3.86a2 2 0 0 0-3.42 0z"/><path d="M12 9v4"/><path d="M12 17h.01"/></symbol>
      <symbol id="i-chat" viewBox="0 0 24 24"><path d="M7.9 20A9 9 0 1 0 4 16.1L2 22z"/></symbol>
      <symbol id="i-x" viewBox="0 0 24 24"><path d="M18 6 6 18"/><path d="M6 6l12 12"/></symbol>
      <symbol id="i-inbox" viewBox="0 0 24 24"><path d="M22 12h-6l-2 3h-4l-2-3H2"/><path d="M5.45 5.11 2 12v6a2 2 0 0 0 2 2h16a2 2 0 0 0 2-2v-6l-3.45-6.89A2 2 0 0 0 16.76 4H7.24a2 2 0 0 0-1.79 1.11z"/></symbol>
      <symbol id="i-search" viewBox="0 0 24 24"><circle cx="11" cy="11" r="8"/><path d="m21 21-4.3-4.3"/></symbol>
      <symbol id="i-star" viewBox="0 0 24 24"><polygon points="12 2 15.09 8.26 22 9.27 17 14.14 18.18 21.02 12 17.77 5.82 21.02 7 14.14 2 9.27 8.91 8.26 12 2"/></symbol>
      <symbol id="i-arrow" viewBox="0 0 24 24"><path d="M5 12h14"/><path d="m13 5 7 7-7 7"/></symbol>
      <symbol id="i-bolt" viewBox="0 0 24 24"><polygon points="13 2 3 14 12 14 11 22 21 10 12 10 13 2"/></symbol>
      <symbol id="i-bucket" viewBox="0 0 24 24"><path d="M5 4h14l-1.5 15a2 2 0 0 1-2 1.8H8.5a2 2 0 0 1-2-1.8z"/><path d="M3 4h18"/></symbol>
      <symbol id="i-fire" viewBox="0 0 24 24"><path d="M8.5 14.5A2.5 2.5 0 0 0 11 12c0-1.38-.5-2-1-3-1.07-2.14-.22-4.05 2-6 .5 2.5 2 4.9 4 6.5 2 1.6 3 3.5 3 5.5a7 7 0 1 1-14 0c0-1.15.43-2.29 1-3a2.5 2.5 0 0 0 2.5 2.5z"/></symbol>
      <symbol id="i-snow" viewBox="0 0 24 24"><path d="M12 2v20M2 12h20M5 5l14 14M19 5 5 19"/></symbol>
      <symbol id="i-pencil" viewBox="0 0 24 24"><path d="M12 20h9"/><path d="M16.5 3.5a2.12 2.12 0 0 1 3 3L7 19l-4 1 1-4z"/></symbol>
      <symbol id="i-trash" viewBox="0 0 24 24"><path d="M3 6h18"/><path d="M19 6v14a2 2 0 0 1-2 2H7a2 2 0 0 1-2-2V6m3 0V4a2 2 0 0 1 2-2h4a2 2 0 0 1 2 2v2"/><path d="M10 11v6"/><path d="M14 11v6"/></symbol>
      <symbol id="i-refresh" viewBox="0 0 24 24"><path d="M3 12a9 9 0 0 1 15-6.7L21 8"/><path d="M21 3v5h-5"/><path d="M21 12a9 9 0 0 1-15 6.7L3 16"/><path d="M3 21v-5h5"/></symbol>
      <symbol id="i-package" viewBox="0 0 24 24"><path d="M16.5 9.4 7.5 4.2"/><path d="M21 16V8a2 2 0 0 0-1-1.73l-7-4a2 2 0 0 0-2 0l-7 4A2 2 0 0 0 3 8v8a2 2 0 0 0 1 1.73l7 4a2 2 0 0 0 2 0l7-4A2 2 0 0 0 21 16z"/><path d="m3.3 7 8.7 5 8.7-5"/><path d="M12 22V12"/></symbol>
      <symbol id="i-key" viewBox="0 0 24 24"><path d="M21 2 14 9"/><path d="M16 7a4 4 0 1 0-5 5l-7 7"/><path d="M7 17v3M4 20h3"/></symbol>
    </svg>
    <!-- Splash Screen / Logo Loading: replaced by the shared SachinLoading
         overlay (www/loading.js) which is now the single loading screen used
         across the customer, partner, and admin web apps. -->
    <!-- Google Tag Manager (noscript) -->
    <noscript><iframe src="https://www.googletagmanager.com/ns.html?id=GTM-KVH6V6ZH" height="0" width="0"
            style="display:none;visibility:hidden"></iframe></noscript>
    <!-- End Google Tag Manager (noscript) -->
    <!-- Header - Modern Glassmorphism Design -->
    <header class="fixed top-0 left-0 right-0 z-50 w-full safe-top" style="overflow: visible; background: var(--bg-surf); border-bottom: 1px solid var(--border); box-shadow: 0 1px 2px rgba(0,0,0,0.06);">
        <div class="w-full mx-auto px-3 sm:px-4 md:px-5 py-2.5" style="position: relative; min-height: var(--header-h);">
            <div class="flex items-center justify-between" style="position: relative; z-index: 51;">
                <!-- Logo -->
                <div class="flex items-center space-x-3 flex-1 min-w-0">
                    <!-- Brand Icon -->
                    <div class="flex-shrink-0 w-10 h-10 rounded-xl flex items-center justify-center text-lg"
                        style="background: linear-gradient(135deg, var(--sage-dk), var(--sage)); box-shadow: 0 2px 10px var(--sage-glow);">
                        <svg class="icon icon--fill brand-mark brand-logo-ic"><use href="#i-sparkle"/></svg></div>
                    <!-- Brand name: visible on all sizes, truncated on mobile to save space -->
                    <div class="truncate">
                        <h1 class="text-base md:text-lg font-bold text-gray-900 truncate"
                            style="font-family: 'Inter', sans-serif; letter-spacing: -0.02em;">Sachin Deep Cleaning</h1>
                        <p class="text-xs hidden md:block" style="color: var(--text-tertiary); font-size: 11px;">
                            Professional Deep Cleaning Services</p>
                    </div>
                </div>

                <!-- Mobile actions - Only show when not on login page -->
                <div x-show="isNotLogin()" class="flex items-center space-x-1.5">

                    <!-- ☀️ / 🌙 Theme Toggle (always visible on header) -->
                    <button onclick="toggleTheme()" title="Toggle light/dark theme"
                        class="relative h-10 w-10 flex items-center justify-center rounded-xl transition-all hover:opacity-80"
                        style="background: var(--bg-surf); border: 1px solid var(--border);">
                        <span id="theme-icon" class="text-lg leading-none">☀️</span>
                    </button>

                    <!-- Download/Install PWA button (Android) - always visible (revealed by JS when installable) -->
                    <button id="header-install-btn" @click="if(pwaPrompt) { pwaPrompt.prompt(); }"
                        style="display: none;" class="relative h-10 w-10 flex items-center justify-center rounded-xl transition-all"
                        title="Download App on Android">
                        <svg class="w-5 h-5" fill="none" stroke="currentColor" viewBox="0 0 24 24"
                            style="color: var(--sage);">
                            <path stroke-linecap="round" stroke-linejoin="round" stroke-width="2"
                                d="M4 16v1a3 3 0 003 3h10a3 3 0 003-3v-1m-4-4l-4 4m0 0l-4-4m4 4V4"></path>
                        </svg>
                    </button>

                    <!-- Notifications bell with unread badge - always visible -->
                    <button @click="showNotifModal = true" class="relative h-10 w-10 flex items-center justify-center rounded-xl transition-all"
                        style="background: var(--bg-surf); border: 1px solid var(--border);">
                        <svg class="w-5 h-5 text-gray-600" fill="none" stroke="currentColor" viewBox="0 0 24 24">
                            <path stroke-linecap="round" stroke-linejoin="round" stroke-width="1.8"
                                d="M15 17h5l-1.4-1.4A2 2 0 0118 14.2V11a6 6 0 10-12 0v3.2a2 2 0 01-.6 1.4L4 17h5m6 0v1a3 3 0 11-6 0v-1m6 0H9"></path>
                        </svg>
                        <span x-show="unreadNotifications > 0" x-text="unreadNotifications > 9 ? '9+' : unreadNotifications"
                            class="absolute -top-1 -right-1 text-white text-xs rounded-full w-5 h-5 flex items-center justify-center font-bold"
                            style="background: #ef4444; font-size: 10px;"></span>
                    </button>

                    <!-- Secondary actions: hidden on mobile to declutter the navbar -->
                    <div class="hidden md:flex items-center space-x-1.5">

                        <!-- Wallet & Rewards -->
                        <button @click="openRewards()" class="relative h-10 w-10 flex items-center justify-center rounded-xl transition-all"
                            style="background: var(--bg-surf); border: 1px solid var(--border);">
                            <svg class="w-5 h-5 text-gray-600" fill="none" stroke="currentColor" viewBox="0 0 24 24">
                                <path stroke-linecap="round" stroke-linejoin="round" stroke-width="1.8"
                                    d="M3 7h18v10H3V7zm0 3h18M16 13h2"></path>
                            </svg>
                        </button>

                        <!-- Support / Help -->
                        <button @click="openSupport()" class="relative h-10 w-10 flex items-center justify-center rounded-xl transition-all"
                            style="background: var(--bg-surf); border: 1px solid var(--border);" aria-label="Support">
                            <svg class="w-5 h-5 text-gray-600" fill="none" stroke="currentColor" viewBox="0 0 24 24">
                                <path stroke-linecap="round" stroke-linejoin="round" stroke-width="1.8"
                                    d="M18 18h-2.2a2 2 0 01-1.7-1 4 4 0 00-6.2 0 2 2 0 01-1.7 1H4a1 1 0 01-1-1v-3.5A8 8 0 0120 13.5V17a1 1 0 01-1 1h-1zM12 3a7 7 0 017 7"></path>
                            </svg>
                        </button>
                    </div>


                    <!-- Menu button (always visible, 40px) -->
                    <button @click="mobileMenuOpen = !mobileMenuOpen" class="relative h-10 w-10 flex items-center justify-center rounded-xl transition-all md:hidden"
                        style="background: var(--bg-surf); border: 1px solid var(--border);" aria-label="Toggle menu">
                        <svg x-show="!mobileMenuOpen" class="w-5 h-5 text-gray-600" fill="none" stroke="currentColor"
                            viewBox="0 0 24 24">
                            <path stroke-linecap="round" stroke-linejoin="round" stroke-width="1.8"
                                d="M4 6h16M4 12h16M4 18h16"></path>
                        </svg>
                        <svg x-show="mobileMenuOpen" class="w-5 h-5 text-gray-600" fill="none" stroke="currentColor"
                            viewBox="0 0 24 24">
                            <path stroke-linecap="round" stroke-linejoin="round" stroke-width="1.8"
                                d="M6 18L18 6M6 6l12 12"></path>
                        </svg>
                    </button>
                </div>
            </div>
        </div>

        <!-- Mobile menu - Simplified -->
        <div x-show="mobileMenuOpen" @click.away="mobileMenuOpen = false"
            x-transition:enter="transition ease-out duration-200" x-transition:enter-start="opacity-0 scale-y-0"
            x-transition:enter-end="opacity-100 scale-y-100" x-transition:leave="transition ease-in duration-150"
            x-transition:leave-start="opacity-100 scale-y-100" x-transition:leave-end="opacity-0 scale-y-0"
            style="transform-origin: top;"
            class="absolute left-0 right-0 top-full bg-white shadow-lg rounded-b-2xl z-40 border-b border-gray-200 w-full overflow-hidden">
            <div class="px-3 pt-3 pb-4 space-y-1 w-full">
                <!-- Show user menu only when authenticated -->
                <template x-if="user.uid">
                    <div class="pt-4 pb-3 border-t border-gray-300">
                        <div class="flex items-center px-3">
                            <div class="flex-shrink-0">
                                <div class="h-10 w-10 rounded-full bg-gray-100 flex items-center justify-center">
                                    <span x-text="user.name ? user.name[0].toUpperCase() : 'U'"
                                        class="text-gray-600 font-medium"></span>
                                </div>
                            </div>
                            <div class="ml-3">
                                <div class="text-base font-medium text-gray-800" x-text="user.name || 'User'"></div>
                                <div class="text-sm font-medium text-gray-500" x-text="user.email || user.phoneNumber">
                                </div>
                            </div>
                        </div>
                        <div class="mt-3 space-y-1">
                            <a href="#" @click.prevent="navigateTo('profile'); mobileMenuOpen = false"
                                class="block px-3 py-2 rounded-md text-base font-medium text-gray-600 hover:text-gray-900 hover:bg-gray-100 transition-colors">
                                Profile
                            </a>
                            <a href="#" @click.prevent="navigateTo('orders'); mobileMenuOpen = false"
                                class="block px-3 py-2 rounded-md text-base font-medium text-gray-600 hover:text-gray-900 hover:bg-gray-100 transition-colors">
                                My Orders
                            </a>
                            <a href="#" @click.prevent="navigateTo('subscriptions'); mobileMenuOpen = false"
                                class="block px-3 py-2 rounded-md text-base font-medium text-gray-600 hover:text-gray-900 hover:bg-gray-100 transition-colors">
                                My Subscriptions
                            </a>
                            <a href="#" @click.prevent="openSupport(); mobileMenuOpen = false"
                                class="block px-3 py-2 rounded-md text-base font-medium text-gray-600 hover:text-gray-900 hover:bg-gray-100 transition-colors">
                                Support
                            </a>
                            <a href="#" @click.prevent="navigateTo('wallet'); mobileMenuOpen = false"
                                class="block px-3 py-2 rounded-md text-base font-medium text-gray-600 hover:text-gray-900 hover:bg-gray-100 transition-colors">
                                Wallet
                            </a>
                            <a href="#" @click.prevent="navigateTo('membership'); mobileMenuOpen = false"
                                class="block px-3 py-2 rounded-md text-base font-medium text-gray-600 hover:text-gray-900 hover:bg-gray-100 transition-colors">
                                Membership
                            </a>
                            <a href="#" @click.prevent="navigateTo('rewards'); mobileMenuOpen = false"
                                class="block px-3 py-2 rounded-md text-base font-medium text-gray-600 hover:text-gray-900 hover:bg-gray-100 transition-colors">
                                Rewards
                            </a>
                            <a href="#" @click.prevent="navigateTo('about'); mobileMenuOpen = false"
                                class="block px-3 py-2 rounded-md text-base font-medium text-gray-600 hover:text-gray-900 hover:bg-gray-100 transition-colors">
                                About
                            </a>
                            <a href="#" @click.prevent="logout(); mobileMenuOpen = false"
                                class="block px-3 py-2 rounded-md text-base font-medium text-gray-700 hover:text-gray-900 hover:bg-gray-100 transition-colors">
                                Sign Out
                            </a>
                        </div>
                    </div>
                </template>

                <!-- Show guest auth options when NOT authenticated -->
                <template x-if="!user.uid">
                    <div class="pt-4 pb-3 border-t border-gray-300">
                        <p class="px-3 text-xs text-gray-500 font-medium mb-2">GUEST MODE</p>
                        <div class="space-y-1">
                            <a href="#" @click.prevent="navigateTo('login'); isSignUp = false; mobileMenuOpen = false"
                                class="block px-3 py-2 rounded-md text-base font-medium text-white bg-emerald-500 hover:bg-emerald-600 transition-colors">
                                Sign In
                            </a>
                            <a href="#" @click.prevent="navigateTo('login'); isSignUp = true; mobileMenuOpen = false"
                                class="block px-3 py-2 rounded-md text-base font-medium text-gray-600 hover:text-gray-900 hover:bg-gray-100 transition-colors border border-gray-300">
                                Create Account
                            </a>
                            <a href="#" @click.prevent="navigateTo('about'); mobileMenuOpen = false"
                                class="block px-3 py-2 rounded-md text-base font-medium text-gray-600 hover:text-gray-900 hover:bg-gray-100 transition-colors">
                                About
                            </a>
                        </div>
                    </div>
                </template>
            </div>
        </div>
    </header>

    <!-- Enhanced Message Notification System - Modern Glassmorphism -->
    <div x-show="messageBox.show" x-transition:enter="transition ease-out duration-300"
        x-transition:enter-start="opacity-0 transform -translate-y-full scale-95"
        x-transition:enter-end="opacity-100 transform translate-y-0 scale-100"
        x-transition:leave="transition ease-in duration-200"
        x-transition:leave-start="opacity-100 transform translate-y-0 scale-100"
        x-transition:leave-end="opacity-0 transform -translate-y-full scale-95" :class="{
             'bg-emerald-500 border-emerald-600 shadow-lg shadow-emerald-500/40 text-white': messageBox.type === 'success',
             'bg-red-500 border-red-600 shadow-lg shadow-red-500/40 text-white': messageBox.type === 'error',
             'bg-blue-500 border-blue-600 shadow-lg shadow-blue-500/40 text-white': messageBox.type === 'info',
             'bg-amber-500 border-amber-600 shadow-lg shadow-amber-500/40 text-white': messageBox.type === 'warning'
         }"
        class="fixed toast-phone left-2 right-2 sm:left-auto sm:right-4 sm:max-w-sm rounded-2xl shadow-2xl p-4 z-50 border backdrop-blur-xl bg-opacity-95 animate-slideIn">
        <div class="flex items-start justify-between gap-3">
            <div class="flex items-start gap-3 flex-1">
                <!-- Icon based on type -->
                <div class="flex-shrink-0 mt-0.5">
                    <svg x-show="messageBox.type === 'success'" class="w-5 h-5 text-white" fill="currentColor"
                        viewBox="0 0 20 20">
                        <path fill-rule="evenodd"
                            d="M10 18a8 8 0 100-16 8 8 0 000 16zm3.707-9.293a1 1 0 00-1.414-1.414L9 10.586 7.707 9.293a1 1 0 00-1.414 1.414l2 2a1 1 0 001.414 0l4-4z"
                            clip-rule="evenodd"></path>
                    </svg>
                    <svg x-show="messageBox.type === 'error'" class="w-5 h-5 text-white" fill="currentColor"
                        viewBox="0 0 20 20">
                        <path fill-rule="evenodd"
                            d="M10 18a8 8 0 100-16 8 8 0 000 16zM8.707 7.293a1 1 0 00-1.414 1.414L8.586 10l-1.293 1.293a1 1 0 101.414 1.414L10 11.414l1.293 1.293a1 1 0 001.414-1.414L11.414 10l1.293-1.293a1 1 0 00-1.414-1.414L10 8.586 8.707 7.293z"
                            clip-rule="evenodd"></path>
                    </svg>
                    <svg x-show="messageBox.type === 'info'" class="w-5 h-5 text-white" fill="currentColor"
                        viewBox="0 0 20 20">
                        <path fill-rule="evenodd"
                            d="M18 10a8 8 0 11-16 0 8 8 0 0116 0zm-7-4a1 1 0 11-2 0 1 1 0 012 0zM9 9a1 1 0 000 2v3a1 1 0 001 1h1a1 1 0 100-2v-3a1 1 0 00-1-1H9z"
                            clip-rule="evenodd"></path>
                    </svg>
                    <svg x-show="messageBox.type === 'warning'" class="w-5 h-5 text-white" fill="currentColor"
                        viewBox="0 0 20 20">
                        <path fill-rule="evenodd"
                            d="M8.257 3.099c.765-1.36 2.722-1.36 3.486 0l5.58 9.92c.75 1.334-.213 2.98-1.742 2.98H4.42c-1.53 0-2.493-1.646-1.743-2.98l5.58-9.92zM11 13a1 1 0 11-2 0 1 1 0 012 0zm-1-8a1 1 0 00-1 1v3a1 1 0 002 0V6a1 1 0 00-1-1z"
                            clip-rule="evenodd"></path>
                    </svg>
                </div>

                <!-- Message Text -->
                <div class="flex-1 pt-0.5">
                    <p class="font-semibold text-sm sm:text-base leading-snug" x-text="messageBox.text"></p>
                </div>
            </div>

            <!-- Close Button -->
            <button @click="messageBox.show = false"
                class="flex-shrink-0 text-white/80 hover:text-white hover:bg-white/20 rounded-lg p-1 transition-all duration-200">
                <svg class="w-5 h-5" fill="none" stroke="currentColor" viewBox="0 0 24 24">
                    <path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M6 18L18 6M6 6l12 12">
                    </path>
                </svg>
            </button>
        </div>
    </div>

    <main class="pb-16 md:pb-8 md:ml-64 min-h-screen safe-left safe-right" style="padding-top: var(--header-h); padding-bottom: var(--bottom-nav-h);">
        <!-- Page Container with proper max-width and padding -->
        <div class="w-full px-3 sm:px-4 md:px-6 lg:px-6">
            <!-- Login / Sign-Up Page -->
            <div x-show="isLogin()" class="min-h-full pt-0 pb-12 w-full">
                <!-- Step Progress Indicator -->
                <div class="max-w-md mx-auto mb-6">
                    <div class="flex items-center justify-center gap-2 mb-4">
                        <div class="flex items-center gap-1">
                            <span
                                class="flex items-center justify-center w-8 h-8 rounded-full bg-emerald-500 text-gray-900 font-bold text-sm">1</span>
                            <span class="text-xs text-gray-600 font-medium">Sign In/Up</span>
                        </div>
                        <div class="h-0.5 w-6 bg-gray-100"></div>
                        <div class="flex items-center gap-1">
                            <span
                                class="flex items-center justify-center w-8 h-8 rounded-full bg-gray-200 text-gray-500 font-bold text-sm">2</span>
                            <span class="text-xs text-gray-500 font-medium">Browse</span>
                        </div>
                        <div class="h-0.5 w-6 bg-gray-100"></div>
                        <div class="flex items-center gap-1">
                            <span
                                class="flex items-center justify-center w-8 h-8 rounded-full bg-gray-200 text-gray-500 font-bold text-sm">3</span>
                            <span class="text-xs text-gray-500 font-medium">Cart</span>
                        </div>
                        <div class="h-0.5 w-6 bg-gray-100"></div>
                        <div class="flex items-center gap-1">
                            <span
                                class="flex items-center justify-center w-8 h-8 rounded-full bg-gray-200 text-gray-500 font-bold text-sm">4</span>
                            <span class="text-xs text-gray-500 font-medium">Order</span>
                        </div>
                    </div>
                </div>

                <div class="max-w-md mx-auto relative">
                    <!-- Decorative glow behind card -->
                    <div class="absolute -top-20 left-1/2 -translate-x-1/2 w-64 h-64 rounded-full opacity-30 pointer-events-none"
                        style="background: radial-gradient(circle, var(--sage-glow) 0%, transparent 70%); filter: blur(40px);">
                    </div>
                    <!-- Card Container -->
                    <div class="relative rounded-2xl shadow-2xl p-8 border"
                        style="background: rgba(255, 255, 255, 0.95); backdrop-filter: blur(24px); border-color: var(--border-md); border-top: 2px solid var(--sage);">
                        <!-- Header with Instructions -->
                        <div class="text-center mb-8">
                            <div
                                class="inline-block bg-emerald-500/20 text-emerald-400 text-xs font-semibold px-3 py-1 rounded-full mb-3">
                                STEP 1 OF 4</div>
                            <h1 class="text-2xl font-bold text-gray-900 mb-2"
                                x-text="isSignUp ? 'Create Your Account' : 'Sign In to Your Account'"></h1>
                            <p class="text-gray-500 text-sm"
                                x-text="isSignUp ? 'Fast, secure, and easy. Takes just 30 seconds!' : 'Welcome back! Let\'s get your cleaning booked.'">
                            </p>
                            <p class="text-xs text-gray-400 mt-3">
                                <span x-show="!isSignUp"><svg class="icon icon--sm"><use href="#i-lock"/></svg> Your data is encrypted and secure</span>
                                <span x-show="isSignUp"><svg class="icon icon--sm"><use href="#i-sparkle"/></svg> You can order anytime after signup</span>
                            </p>
                        </div>

                        <!-- Error Message -->
                        <div x-show="messageBox.show && (currentPage === 'login' || messageBox.type === 'error')"
                            class="bg-red-50 border border-red-200 rounded-lg p-3 mb-4">
                            <p class="text-red-600 text-sm" x-text="messageBox.text"></p>
                        </div>

                        <!-- Tabs / Toggle -->
                        <div class="flex gap-2 mb-6 bg-gray-100 rounded-lg p-1">
                            <button @click="isSignUp = false"
                                :class="!isSignUp ? 'bg-emerald-500 text-white' : 'text-gray-500'"
                                class="flex-1 py-2 px-4 rounded font-medium transition-all text-sm">Sign In</button>
                            <button @click="isSignUp = true"
                                :class="isSignUp ? 'bg-emerald-500 text-white' : 'text-gray-500'"
                                class="flex-1 py-2 px-4 rounded font-medium transition-all text-sm">Sign Up</button>
                        </div>

                        <!-- ====== LOGIN FORM ====== -->
                        <form x-show="!isSignUp" @submit.prevent="handleLogin()" class="space-y-4 mb-6">
                            <!-- Email Field (Login) -->
                            <div>
                                <label for="login-email" class="block text-sm font-medium text-gray-600 mb-2"><svg class="icon icon--sm"><use href="#i-mail"/></svg> Email
                                    Address</label>
                                <input id="login-email" type="email" name="email" autocomplete="email"
                                    x-model="loginForm.email" placeholder="yourname@example.com"
                                    class="w-full px-4 py-2.5 rounded-lg glass-input text-gray-900 placeholder-gray-400 focus:outline-none focus:ring-2 focus:ring-emerald-500 transition-all"
                                    required>
                                <p class="text-xs text-gray-500 mt-1"><svg class="icon icon--sm"><use href="#i-sparkle"/></svg>Use the email you registered with</p>
                            </div>

                            <!-- Password Field (Login) -->
                            <div>
                                <label for="login-password" class="block text-sm font-medium text-gray-600 mb-2"><svg class="icon icon--sm"><use href="#i-lock"/></svg>
                                    Password</label>
                                <input id="login-password" type="password" name="password"
                                    autocomplete="current-password" x-model="loginForm.password"
                                    placeholder="Enter your password"
                                    class="w-full px-4 py-2.5 rounded-lg glass-input text-gray-900 placeholder-gray-400 focus:outline-none focus:ring-2 focus:ring-emerald-500 transition-all"
                                    required>
                                <p class="text-xs text-gray-500 mt-1"><svg class="icon icon--sm"><use href="#i-sparkle"/></svg>At least 8 characters required</p>
                            </div>

                            <!-- Submit Button (Login) -->
                            <button type="submit" :disabled="loading.auth"
                                class="w-full btn-gradient-primary text-white font-bold py-3 px-4 rounded-lg transition-all transform hover:scale-105 disabled:opacity-50 disabled:cursor-not-allowed text-sm sm:text-base">
                                <span x-show="!loading.auth">Sign In</span>
                                <span x-show="loading.auth" class="flex items-center justify-center gap-2">
                                    <div class="animate-spin rounded-full h-4 w-4 border-b-2 border-white"></div>
                                    <span>Signing in...</span>
                                </span>
                            </button>
                        </form>

                        <!-- ====== SIGNUP FORM ====== -->
                        <form x-show="isSignUp" @submit.prevent="handleSignup()" class="space-y-4 mb-6">
                            <!-- Step 1: Signup Form -->
                            <template x-if="emailOtpStep === 'email'">
                                <div>
                                    <!-- Name Field -->
                                    <div>
                                        <label for="signup-name" class="block text-sm font-medium text-gray-600 mb-2"><svg class="icon icon--sm"><use href="#i-user"/></svg> Full Name</label>
                                        <input id="signup-name" type="text" name="signup-name" autocomplete="name"
                                            x-model="signupForm.name" placeholder="e.g., Rajesh Kumar"
                                            class="w-full px-4 py-2.5 rounded-lg glass-input text-gray-900 placeholder-gray-400 focus:outline-none focus:ring-2 focus:ring-emerald-500 transition-all"
                                            required>
                                        <p class="text-xs text-gray-500 mt-1"><svg class="icon icon--sm"><use href="#i-sparkle"/></svg>We'll use this name for communication</p>
                                    </div>
                                    <!-- Email Field -->
                                    <div>
                                        <label for="signup-email" class="block text-sm font-medium text-gray-600 mb-2"><svg class="icon icon--sm"><use href="#i-mail"/></svg> Email Address</label>
                                        <input id="signup-email" type="email" name="email" autocomplete="email"
                                            x-model="signupForm.email" placeholder="yourname@example.com"
                                            class="w-full px-4 py-2.5 rounded-lg glass-input text-gray-900 placeholder-gray-400 focus:outline-none focus:ring-2 focus:ring-emerald-500 transition-all"
                                            required>
                                        <p class="text-xs text-gray-500 mt-1"><svg class="icon icon--sm"><use href="#i-sparkle"/></svg>Used for order confirmations and updates</p>
                                    </div>
                                    <!-- Password Field -->
                                    <div>
                                        <label for="signup-password" class="block text-sm font-medium text-gray-600 mb-2"><svg class="icon icon--sm"><use href="#i-lock"/></svg> Password</label>
                                        <input id="signup-password" type="password" name="password" autocomplete="new-password"
                                            x-model="signupForm.password" placeholder="Min 8 characters recommended"
                                            class="w-full px-4 py-2.5 rounded-lg glass-input text-gray-900 placeholder-gray-400 focus:outline-none focus:ring-2 focus:ring-emerald-500 transition-all"
                                            required>
                                        <p class="text-xs text-gray-500 mt-1"><svg class="icon icon--sm"><use href="#i-sparkle"/></svg>At least 8 characters, mix of letters & numbers</p>
                                    </div>
                                    <!-- Confirm Password -->
                                    <div>
                                        <label for="signup-confirm-password" class="block text-sm font-medium text-gray-600 mb-2">✓ Confirm Password</label>
                                        <input id="signup-confirm-password" type="password" name="confirm-password"
                                            autocomplete="new-password" x-model="signupForm.confirmPassword"
                                            placeholder="Re-enter your password"
                                            class="w-full px-4 py-2.5 rounded-lg glass-input text-gray-900 placeholder-gray-400 focus:outline-none focus:ring-2 focus:ring-emerald-500 transition-all"
                                            required>
                                        <p x-show="signupForm.password && signupForm.confirmPassword && signupForm.password !== signupForm.confirmPassword"
                                            class="text-red-400 text-xs mt-1"><svg class="icon icon--sm"><use href="#i-x"/></svg> Passwords do not match</p>
                                        <p x-show="!signupForm.password || !signupForm.confirmPassword || signupForm.password === signupForm.confirmPassword"
                                            class="text-xs text-gray-500 mt-1"><svg class="icon icon--sm"><use href="#i-sparkle"/></svg>Make sure passwords match</p>
                                    </div>
                                    <!-- Send Verification Code Button -->
                                    <button type="submit" :disabled="loading.auth"
                                        class="w-full btn-gradient-primary text-white font-bold py-3 px-4 rounded-lg transition-all transform hover:scale-105 disabled:opacity-50 disabled:cursor-not-allowed text-sm sm:text-base">
                                        <span x-show="!loading.auth">Send Verification Code</span>
                                        <span x-show="loading.auth" class="flex items-center justify-center gap-2">
                                            <div class="animate-spin rounded-full h-4 w-4 border-b-2 border-white"></div>
                                            <span>Sending...</span>
                                        </span>
                                    </button>
                                </div>
                            </template>
                            <!-- Step 2: OTP Verification -->
                            <template x-if="emailOtpStep === 'otp'">
                                <div>
                                    <div class="mb-4">
                                        <label for="signup-otp" class="block text-sm font-medium text-gray-600 mb-2"><svg class="icon icon--sm"><use href="#i-key"/></svg> Enter 6-digit Code</label>
                                        <input id="signup-otp" type="text" maxlength="6" inputmode="numeric" pattern="[0-9]{6}"
                                            x-model="signupForm.otp" placeholder="Enter code from your email"
                                            class="w-full px-4 py-2.5 rounded-lg glass-input text-gray-900 placeholder-gray-400 focus:outline-none focus:ring-2 focus:ring-emerald-500 transition-all"
                                            required>
                                        <p class="text-xs text-gray-500 mt-1"><svg class="icon icon--sm"><use href="#i-sparkle"/></svg>Check your inbox for the code. Not received? <button type="button" @click="emailOtpStep = 'email'" class="text-blue-600 underline">Resend</button></p>
                                    </div>
                                    <button type="submit" :disabled="loading.auth"
                                        class="w-full btn-gradient-primary text-white font-bold py-3 px-4 rounded-lg transition-all transform hover:scale-105 disabled:opacity-50 disabled:cursor-not-allowed text-sm sm:text-base">
                                        <span x-show="!loading.auth">Verify & Create Account</span>
                                        <span x-show="loading.auth" class="flex items-center justify-center gap-2">
                                            <div class="animate-spin rounded-full h-4 w-4 border-b-2 border-white"></div>
                                            <span>Verifying...</span>
                                        </span>
                                    </button>
                                </div>
                            </template>
                        </form>

                        <!-- OR Divider (hide during OTP step) -->
                        <div class="relative mb-6" x-show="!isSignUp || emailOtpStep === 'email'">
                            <div class="absolute inset-0 flex items-center">
                                <div class="w-full border-t border-gray-300"></div>
                            </div>
                            <div class="relative flex justify-center text-sm">
                                <span class="px-2 bg-white text-gray-500">OR</span>
                            </div>
                        </div>

                        <!-- Tip Banner -->
                        <div class="bg-blue-50 border border-blue-200 rounded-lg p-3 mb-6">
                            <p class="text-xs text-blue-700"><svg class="icon icon--sm"><use href="#i-sparkle"/></svg> <strong>Pro Tip:</strong> Use a password you haven't used
                                before and keep it safe. You'll only need to sign in once per device.</p>
                        </div>

                        <!-- ====== GOOGLE SIGN-IN ====== -->
                        <button @click="signInWithGoogle()" :disabled="loading.auth"
                            class="w-full bg-white hover:bg-slate-100 text-gray-900 font-bold py-2.5 px-4 rounded-lg transition-all disabled:opacity-50 disabled:cursor-not-allowed flex items-center justify-center gap-2 mb-4"
                            x-show="!isSignUp || emailOtpStep === 'email'">
                            <svg class="w-5 h-5" viewBox="0 0 24 24" fill="currentColor">
                                <path d="M22.56 12.25c0-.78-.07-1.53-.2-2.25H12v4.26h5.92c-.26 1.37-1.04 2.53-2.21 3.31v2.77h3.57c2.08-1.92 3.28-4.74 3.28-8.09z" />
                                <path d="M12 23c2.97 0 5.46-.98 7.28-2.66l-3.57-2.77c-.98.66-2.23 1.06-3.71 1.06-2.86 0-5.29-1.93-6.16-4.53H2.18v2.84C3.99 20.53 7.7 23 12 23z" />
                                <path d="M5.84 14.09c-.22-.66-.35-1.36-.35-2.09s.13-1.43.35-2.09V7.07H2.18C1.43 8.55 1 10.22 1 12s.43 3.45 1.18 4.93l2.85-2.22.81-.62z" />
                                <path d="M12 5.38c1.62 0 3.06.56 4.21 1.64l3.15-3.15C17.45 2.09 14.97 1 12 1 7.7 1 3.99 3.47 2.18 7.07l3.66 2.84c.87-2.6 3.3-4.53 6.16-4.53z" />
                            </svg>
                            <span x-text="loading.auth ? 'Signing in...' : 'Continue with Google'"></span>
                        </button>

                        <!-- ====== MAGIC LINK (PASSWORDLESS EMAIL) ====== -->
                        <details class="mb-4">
                            <summary
                                class="cursor-pointer text-gray-600 hover:text-gray-900 text-sm font-medium py-2 px-3 bg-gray-100 rounded-lg text-center">
                                <svg class="icon icon--sm"><use href="#i-mail"/></svg> Sign in with Magic Link</summary>
                            <div class="mt-3 p-3 bg-gray-100/80 rounded-lg space-y-2">
                                <input type="email" x-model="emailOtpData.email" placeholder="Enter your email"
                                    class="w-full px-3 py-2 rounded-lg bg-gray-100 border border-gray-300 text-gray-900 placeholder-gray-400 focus:outline-none focus:ring-2 focus:ring-emerald-500 text-sm"
                                    autocomplete="email">
                                <button @click="sendMagicLink()" :disabled="loading.auth"
                                    class="w-full bg-blue-600 hover:bg-blue-700 text-white py-2 px-3 rounded-lg font-semibold disabled:opacity-50 disabled:cursor-not-allowed text-sm">
                                    <span x-text="loading.auth ? 'Sending...' : 'Send Magic Link'"></span>
                                </button>
                                <p class="text-gray-500 text-xs">Click the link in your email to sign in instantly (no
                                    password needed)</p>
                            </div>
                        </details>

                        <!-- ====== SMS OTP ====== -->
                        <details class="mb-4">
                            <summary
                                class="cursor-pointer text-gray-600 hover:text-gray-900 text-sm font-medium py-2 px-3 bg-gray-100 rounded-lg text-center">
                                <svg class="icon icon--sm"><use href="#i-phone"/></svg> Sign in with Phone OTP</summary>
                            <div class="mt-3 p-3 bg-gray-100/80 rounded-lg space-y-2">
                                <!-- Phone Input -->
                                <div x-show="!showOtpInput || true">
                                    <input type="tel" x-model="phoneNumber" placeholder="Enter 10-digit mobile number"
                                        inputmode="numeric"
                                        class="w-full px-3 py-2 rounded-lg bg-gray-100 border border-gray-300 text-gray-900 placeholder-gray-400 focus:outline-none focus:ring-2 focus:ring-emerald-500 text-sm"
                                        autocomplete="tel">
                                    <button @click="sendOtp()" :disabled="loading.auth || !phoneNumber"
                                        class="w-full bg-green-600 hover:bg-green-700 text-white py-2 px-3 rounded-lg font-semibold disabled:opacity-50 disabled:cursor-not-allowed text-sm mt-2">
                                        <span x-text="loading.auth ? 'Sending OTP...' : 'Send OTP'"></span>
                                    </button>
                                </div>

                                <!-- OTP Input (Shows after sending) -->
                                <div x-show="showOtpInput">
                                    <input type="text" x-model="otpCode" placeholder="Enter 6-digit OTP" maxlength="6"
                                        inputmode="numeric"
                                        class="w-full px-3 py-2 rounded-lg bg-gray-100 border border-gray-300 text-gray-900 placeholder-gray-400 focus:outline-none focus:ring-2 focus:ring-emerald-500 text-center text-lg font-bold tracking-widest">
                                    <button @click="verifyOtp()" :disabled="loading.auth || otpCode.length !== 6"
                                        class="w-full bg-green-600 hover:bg-green-700 text-white py-2 px-3 rounded-lg font-semibold disabled:opacity-50 disabled:cursor-not-allowed text-sm mt-2">
                                        <span x-text="loading.auth ? 'Verifying...' : 'Verify OTP'"></span>
                                    </button>
                                </div>

                                <!-- Error Message -->
                                <p x-show="phoneError" class="text-red-400 text-xs" x-text="phoneError"></p>
                                <p class="text-gray-500 text-xs">We'll send a one-time code to your phone</p>
                            </div>
                        </details>

                        <!-- ====== EMAIL OTP (6-digit code) ====== -->
                        <details class="mb-4">
                            <summary
                                class="cursor-pointer text-gray-600 hover:text-gray-900 text-sm font-medium py-2 px-3 bg-gray-100 rounded-lg text-center">
                                <svg class="icon icon--sm"><use href="#i-mail"/></svg> Sign in with Email OTP</summary>
                            <div class="mt-3 p-3 bg-gray-100/80 rounded-lg space-y-2">

                                <!-- Step 1: Enter Email -->
                                <div x-show="emailOtpStep === 'email'">
                                    <p class="text-xs text-gray-600 mb-2">We'll send a 6-digit code to your email</p>
                                    <input type="email" x-model="emailOtpData.email" placeholder="Enter your email"
                                        class="w-full px-3 py-2 rounded-lg bg-gray-100 border border-gray-300 text-gray-900 placeholder-gray-400 focus:outline-none focus:ring-2 focus:ring-emerald-500 text-sm"
                                        autocomplete="email">
                                    <input type="text" x-model="emailOtpData.name" placeholder="Your name (optional)"
                                        class="w-full px-3 py-2 mt-2 rounded-lg bg-gray-100 border border-gray-300 text-gray-900 placeholder-gray-400 focus:outline-none focus:ring-2 focus:ring-emerald-500 text-sm"
                                        autocomplete="name">
                                    <button @click="sendEmailOTP()" :disabled="loading.auth || !emailOtpData.email"
                                        class="w-full bg-gradient-to-r from-emerald-600 to-emerald-500 hover:from-emerald-500 hover:to-emerald-400 text-white py-2 px-3 rounded-lg font-semibold disabled:opacity-50 disabled:cursor-not-allowed text-sm mt-2 transition-all">
                                        <span x-show="!loading.auth">Send OTP Code</span>
                                        <span x-show="loading.auth" class="flex items-center justify-center gap-2">
                                            <div class="animate-spin rounded-full h-3.5 w-3.5 border-b-2 border-white">
                                            </div>
                                            <span>Sending...</span>
                                        </span>
                                    </button>
                                </div>

                                <!-- Step 2: Enter OTP Code -->
                                <div x-show="emailOtpStep === 'otp'">
                                    <p class="text-xs text-emerald-300 mb-2"><svg class="icon icon--sm"><use href="#i-check-circle"/></svg> OTP sent! Check your email inbox</p>
                                    <input type="text" x-model="otpCode" placeholder="Enter 6-digit OTP" maxlength="6"
                                        inputmode="numeric"
                                        class="w-full px-3 py-2.5 rounded-lg bg-gray-100 border border-gray-300 text-gray-900 placeholder-gray-400 focus:outline-none focus:ring-2 focus:ring-emerald-500 text-center text-lg font-bold tracking-widest">
                                    <button @click="verifyEmailOTP()" :disabled="loading.auth || otpCode.length !== 6"
                                        class="w-full bg-gradient-to-r from-emerald-600 to-emerald-500 hover:from-emerald-500 hover:to-emerald-400 text-white py-2 px-3 rounded-lg font-semibold disabled:opacity-50 disabled:cursor-not-allowed text-sm mt-2 transition-all">
                                        <span x-show="!loading.auth">Verify & Sign In</span>
                                        <span x-show="loading.auth" class="flex items-center justify-center gap-2">
                                            <div class="animate-spin rounded-full h-3.5 w-3.5 border-b-2 border-white">
                                            </div>
                                            <span>Verifying...</span>
                                        </span>
                                    </button>
                                    <div class="flex items-center justify-between mt-2">
                                        <button @click="emailOtpStep = 'email'; otpCode = ''"
                                            class="text-gray-500 hover:text-gray-800 text-xs underline">← Change
                                            email</button>
                                        <button @click="sendEmailOTP()" :disabled="loading.auth"
                                            class="text-emerald-400 hover:text-emerald-300 text-xs underline">Resend
                                            OTP</button>
                                    </div>
                                </div>

                                <p class="text-gray-500 text-xs mt-2"><svg class="icon icon--sm"><use href="#i-lock"/></svg> No password needed. Quick & secure.</p>
                            </div>
                        </details>

                        <!-- Footer -->
                        <div class="text-center mt-6 pt-6 border-t border-gray-200">
                            <p class="text-gray-500 text-sm">
                                <span x-show="!isSignUp"><svg class="icon icon--sm"><use href="#i-target"/></svg> New to Sachin Deep Cleaning?</span>
                                <span x-show="isSignUp">✓ Already registered?</span>
                                <button @click="isSignUp = !isSignUp" type="button"
                                    class="text-emerald-500 hover:text-emerald-400 font-semibold ml-1">
                                    <span x-text="isSignUp ? 'Click Here to Sign In' : 'Create Account Here'"></span>
                                </button>
                            </p>
                        </div>
                    </div>

                    <!-- Guest Browse Option -->
                    <div class="text-center mt-6">
                        <p class="text-gray-500 text-sm mb-3">Or just browse as a guest</p>
                        <button @click="navigateTo('products')"
                            class="text-emerald-500 hover:text-emerald-400 font-semibold text-sm hover:underline">
                            Continue as Guest →
                        </button>
                    </div>
                </div>
            </div>

            <!-- P1-2: promo offers banner on home / catalog -->
            <div x-show="isProducts()" class="pb-0 pt-0 px-3 sm:px-4 w-full">
                <div x-show="offers.length > 0" class="space-y-2 max-w-6xl mx-auto">
                    <template x-for="o in offers" :key="o.id">
                        <div class="p-4 rounded-xl bg-gradient-to-r from-emerald-500 to-emerald-600 text-white shadow-sm">
                            <div class="flex items-center gap-2">
                                <svg class="w-5 h-5" fill="none" stroke="currentColor" viewBox="0 0 24 24">
                                    <path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M7 7h10v10H7z"></path>
                                </svg>
                                <p class="font-semibold" x-text="o.title || 'Special Offer'"></p>
                            </div>
                            <p x-show="o.description" class="text-sm opacity-90 mt-1" x-text="o.description"></p>
                            <p x-show="o.code" class="text-xs mt-1 opacity-90">Use code: <span class="font-bold" x-text="o.code"></span></p>
                        </div>
                    </template>
                </div>
            </div>

            <!-- Products Page - DESKTOP OPTIMIZED -->
            <div x-show="isProducts() && isDesktop" class="min-h-full pb-6 pt-0 w-full">
                <!-- HERO SECTION - Desktop Fade Carousel -->
                <div class="w-full mb-8 px-6">
                    <div class="relative h-96 rounded-xl overflow-hidden shadow-2xl" style="background:#059669;">

                        <style>
                            .hero-slide {
                                position: absolute;
                                inset: 0;
                                display: flex;
                                align-items: center;
                                justify-content: center;
                                opacity: 0;
                                animation: heroFade 15s infinite;
                            }
                            .hero-slide:nth-child(1) { animation-delay: 0s; }
                            .hero-slide:nth-child(2) { animation-delay: 5s; }
                            .hero-slide:nth-child(3) { animation-delay: 10s; }

                            @keyframes heroFade {
                                0%   { opacity: 0; }
                                5%   { opacity: 1; }
                                30%  { opacity: 1; }
                                35%  { opacity: 0; }
                                100% { opacity: 0; }
                            }

                            .hero-slide-content {
                                text-align: center;
                                color: white;
                                padding: 2rem;
                                z-index: 2;
                                position: relative;
                            }
                            .hero-slide-content .hero-emoji {
                                font-size: 4rem;
                                margin-bottom: 1rem;
                                display: block;
                            }
                            .hero-slide-content h2 {
                                font-size: 2rem;
                                font-weight: 800;
                                margin-bottom: 0.5rem;
                                font-family: 'Sora', 'Inter', sans-serif;
                                color: white;
                            }
                            .hero-slide-content p {
                                font-size: 1.1rem;
                                opacity: 0.9;
                                margin: 0;
                            }
                        </style>

                        <!-- Slide 1 -->
                        <div class="hero-slide" style="background: linear-gradient(135deg, #059669 0%, #10b981 50%, #34d399 100%);">
                            <div class="hero-slide-content">
                                <span class="hero-emoji"><svg class="icon"><use href="#i-home"/></svg></span>
                                <h2>Home Deep Cleaning</h2>
                                <p>Professional cleaning for every corner of your home</p>
                            </div>
                        </div>

                        <!-- Slide 2 -->
                        <div class="hero-slide" style="background: linear-gradient(135deg, #0f766e 0%, #0d9488 50%, #2dd4bf 100%);">
                            <div class="hero-slide-content">
                                <span class="hero-emoji"><svg class="icon"><use href="#i-kitchen"/></svg></span>
                                <h2>Kitchen Deep Cleaning</h2>
                                <p>Grease-free, hygienic kitchens guaranteed</p>
                            </div>
                        </div>

                        <!-- Slide 3 -->
                        <div class="hero-slide" style="background: linear-gradient(135deg, #047857 0%, #059669 50%, #6ee7b7 100%);">
                            <div class="hero-slide-content">
                                <span class="hero-emoji"><svg class="icon"><use href="#i-sofa"/></svg></span>
                                <h2>Sofa & Carpet Cleaning</h2>
                                <p>Steam clean & shampoo for a fresh feel</p>
                            </div>
                        </div>

                        <!-- Dot indicators -->
                        <div style="position:absolute; bottom:16px; left:50%; transform:translateX(-50%); display:flex; gap:8px; z-index:10;">
                            <div style="width:10px; height:10px; border-radius:50%; background:rgba(255,255,255,0.9);"></div>
                            <div style="width:10px; height:10px; border-radius:50%; background:rgba(255,255,255,0.4);"></div>
                            <div style="width:10px; height:10px; border-radius:50%; background:rgba(255,255,255,0.4);"></div>
                        </div>
                    </div>
                </div>

                <!-- Products Content - Show to all users (guest or logged in) -->
                <div class="w-full px-6">
                    <!-- Desktop Header -->
                    <div class="mb-6">
                        <h1 class="text-2xl font-bold text-gray-900 mb-4">Cleaning Services</h1>
                        <div class="flex gap-4">
                            <div class="relative flex-1 max-w-md">
                                <label for="search-services-desktop" class="sr-only">Search services</label>
                                <input id="search-services-desktop" type="text" x-model="searchQuery"
                                    placeholder="Search services..." autocomplete="off" inputmode="search"
                                    class="w-full px-5 py-3 pl-12 bg-white border-2 border-gray-300 rounded-lg focus:outline-none focus:ring-2 focus:ring-emerald-500 text-gray-900 placeholder-gray-400">
                                <svg class="absolute left-4 top-1/2 transform -translate-y-1/2 w-5 h-5 text-gray-500 pointer-events-none"
                                    fill="none" stroke="currentColor" viewBox="0 0 24 24">
                                    <path stroke-linecap="round" stroke-linejoin="round" stroke-width="2"
                                        d="M21 21l-6-6m2-5a7 7 0 11-14 0 7 7 0 0114 0z"></path>
                                </svg>
                            </div>
                        </div>
                    </div>

                    <!-- P1-5: Recommended for you (personalized from order history) -->
                    <div class="mb-8" x-show="recommendedProducts().length > 0">
                        <h2 class="text-lg font-semibold text-gray-900 mb-3"
                            x-text="(orders && orders.length) ? 'Recommended for you' : 'Popular right now'"></h2>
                        <div class="flex flex-wrap gap-3">
                            <template x-for="p in recommendedProducts()" :key="p.id">
                                <div @click="openProductDetail(p)"
                                    class="w-40 bg-white rounded-xl border border-gray-200 p-3 cursor-pointer hover:shadow-md transition-shadow">
                                    <div class="h-28 rounded-lg bg-gray-100 mb-2 flex items-center justify-center overflow-hidden">
                                        <img x-show="p.img" :src="p.img" class="w-full h-full object-cover" alt="" />
                                        <span x-show="!p.img" class="text-3xl" x-text="p.icon || '🧹'"></span>
                                    </div>
                                    <p class="font-medium text-gray-900 text-sm truncate" x-text="p.name"></p>
                                    <p class="text-emerald-600 font-semibold text-sm mt-1">₹<span x-text="(p.price || 0).toFixed(0)"></span></p>
                                </div>
                            </template>
                        </div>
                    </div>

                    <!-- Desktop Category Filters -->
                    <div class="flex flex-wrap gap-3 mb-6">
                        <button @click="filterByCategory('all')"
                            :class="{'bg-emerald-500 text-white': selectedCategory === 'all', 'bg-gray-100 text-gray-600 hover:bg-gray-200': selectedCategory !== 'all'}"
                            class="px-5 py-2.5 rounded-full text-sm font-medium transition-all">All</button>
                        <button @click="filterByCategory('Non-Furnished')"
                            :class="{'bg-emerald-500 text-white': selectedCategory === 'Non-Furnished', 'bg-gray-100 text-gray-600 hover:bg-gray-200': selectedCategory !== 'Non-Furnished'}"
                            class="px-5 py-2.5 rounded-full text-sm font-medium transition-all">Non-Furnished</button>
                        <button @click="filterByCategory('Furnished')"
                            :class="{'bg-emerald-500 text-white': selectedCategory === 'Furnished', 'bg-gray-100 text-gray-600 hover:bg-gray-200': selectedCategory !== 'Furnished'}"
                            class="px-5 py-2.5 rounded-full text-sm font-medium transition-all">Furnished</button>
                    </div>

                    <!-- Step Progress Indicator (Desktop) -->
                    <div class="flex items-center justify-start gap-2 mb-8">
                        <div class="flex items-center gap-1">
                            <span
                                class="flex items-center justify-center w-8 h-8 rounded-full bg-gray-200 text-gray-500 font-bold text-sm">1</span>
                            <span class="text-xs text-gray-500 font-medium">Sign In</span>
                        </div>
                        <div class="h-0.5 w-6 bg-gray-100"></div>
                        <div class="flex items-center gap-1">
                            <span
                                class="flex items-center justify-center w-8 h-8 rounded-full bg-emerald-500 text-gray-900 font-bold text-sm">2</span>
                            <span class="text-xs text-gray-600 font-medium">Browse</span>
                        </div>
                        <div class="h-0.5 w-6 bg-gray-100"></div>
                        <div class="flex items-center gap-1">
                            <span
                                class="flex items-center justify-center w-8 h-8 rounded-full bg-gray-200 text-gray-500 font-bold text-sm">3</span>
                            <span class="text-xs text-gray-500 font-medium">Cart</span>
                        </div>
                    </div>

                    <!-- Desktop Horizontal Scroll Sections -->
                    <div class="space-y-12">

                        <!-- Desktop Skeleton: visible while Firestore loads -->
                        <template x-if="!firestoreDataReady">
                            <div class="space-y-12">
                                <template x-for="s in [1,2]" :key="s">
                                    <div>
                                        <div class="flex items-center justify-between mb-6">
                                            <div class="skeleton h-8 w-40"></div>
                                            <div class="skeleton h-4 w-16"></div>
                                        </div>
                                        <div class="flex gap-4 overflow-hidden">
                                            <template x-for="c in [1,2,3,4]" :key="c">
                                                <div class="flex-shrink-0 w-48 rounded-xl bg-white border border-gray-200 shadow-sm overflow-hidden">
                                                    <div class="skeleton h-36 rounded-none"></div>
                                                    <div class="p-3 space-y-2">
                                                        <div class="skeleton h-4 w-3/4"></div>
                                                        <div class="skeleton h-3 w-1/2"></div>
                                                        <div class="skeleton h-8 w-full rounded-lg mt-2"></div>
                                                    </div>
                                                </div>
                                            </template>
                                        </div>
                                    </div>
                                </template>
                            </div>
                        </template>

                        <template x-for="[category, services] in Object.entries(filteredServices())"
                            :key="category + '-' + firestoreDataReady">
                            <div>
                                <div class="flex items-center justify-between mb-6">
                                    <h2 class="text-3xl font-bold text-gray-900"
                                        x-text="category.charAt(0).toUpperCase() + category.slice(1)"></h2>
                                    <span class="text-sm text-gray-500 font-medium"
                                        x-text="services.length + ' items'"></span>
                                </div>

                                <!-- Vertical Product Grid Container -->
                                <div class="relative">
                                    <!-- Vertical grid: scrolls top-to-bottom, no horizontal swipe -->
                                    <div class="grid grid-cols-2 sm:grid-cols-2 lg:grid-cols-4 gap-3">
                                        <template x-for="service in services" :key="service.id">
                                            <div
                                                class="bg-white rounded-xl shadow-lg border border-gray-200 flex flex-col overflow-hidden cursor-pointer group/card transition-all duration-300 hover:shadow-2xl hover:border-gray-300">
                                                <!-- Image Container -->
                                                <div class="h-32 overflow-hidden bg-gray-100 relative">
                                                    <img :src="service.img" :data-src="service.img" :alt="service.name"
                                                        loading="lazy"
                                                        class="w-full h-full object-cover hover:scale-110 transition-transform duration-300 lazy-image"
                                                        decoding="async">
                                                    <div
                                                        class="absolute inset-0 bg-black/0 group-hover/card:bg-black/20 transition-colors duration-300">
                                                    </div>
                                                </div>

                                                <!-- Content Container -->
                                                <div class="p-3 flex flex-col flex-1">
                                                    <h3 class="font-bold text-sm text-gray-900 line-clamp-2 mb-2"
                                                        x-text="service.name"></h3>

                                                    <!-- Rating -->
                                                    <div class="flex items-center gap-1 mb-3">
                                                        <div class="flex gap-0.5">
                                                            <template
                                                                x-for="(filled, idx) in [service.rating >= 1, service.rating >= 2, service.rating >= 3, service.rating >= 4, service.rating >= 5]"
                                                                :key="idx">
                                                                <svg :class="filled ? 'text-yellow-400' : 'text-gray-400'"
                                                                    class="w-4 h-4" fill="currentColor"
                                                                    viewBox="0 0 20 20">
                                                                    <path
                                                                        d="M9.049 2.927c.3-.921 1.603-.921 1.902 0l1.07 3.292a1 1 0 00.95.69h3.462c.969 0 1.371 1.24.588 1.81l-2.8 2.034a1 1 0 00-.364 1.118l1.07 3.292c.3.921-.755 1.688-1.54 1.118l-2.8-2.034a1 1 0 00-1.175 0l-2.8 2.034c-.786.57-1.833-.197-1.54-1.118l1.07-3.292a1 1 0 00-.364-1.118L2.096 9.389c-.784-.57-.381-1.81.588-1.81h3.462a1 1 0 00.95-.69l1.07-3.292z">
                                                                    </path>
                                                                </svg>
                                                            </template>
                                                        </div>
                                                        <span class="text-sm font-bold text-yellow-400"
                                                            x-text="service.rating"></span>
                                                    </div>

                                                    <!-- Price -->
                                                    <div class="text-lg font-bold text-gray-900 mb-3">₹<span
                                                            x-text="service.price"></span>
                                                    </div>

                                                    <!-- Buttons -->
                                                    <div class="mt-auto space-y-2">
                                                        <button @click.stop="openServiceDetail(service)"
                                                            class="w-full bg-emerald-500 hover:bg-emerald-600 text-white py-2 px-3 rounded-lg text-sm font-semibold transition-colors">
                                                            View Details
                                                        </button>
                                                        <button
                                                            @click.stop="addServiceToCart(service); showMessage('Added to cart!', 'success')"
                                                            class="w-full bg-white hover:bg-blue-50 text-gray-800 py-2 px-3 rounded-lg text-sm font-semibold transition-colors">
                                                            Add to Cart
                                                        </button>
                                                    </div>
                                                </div>
                                            </div>
                                        </template>
                                    </div>
                                </div>
                            </div>
                        </template>
                    </div>
                </div>
            </div>

            <!-- Products Page - MOBILE OPTIMIZED -->
            <div x-show="isProducts() && !isDesktop" class="min-h-full pb-4 pt-0 w-full">
                <!-- HERO SECTION (MOBILE) -->
                <div class="w-full mb-4 px-3">
                    <div class="relative w-full rounded-lg overflow-hidden shadow-lg bg-emerald-600" style="aspect-ratio: 2 / 1; max-height: 140px;">
                        <!-- Hero Background Image -->
                        <img src="assets/images/5bhk-non-furnished.webp"
                             alt="Professional Cleaning Services"
                             class="w-full h-full object-cover"
                             onerror="this.src='assets/images/cleaning-banner.jpg'">
                    </div>
                </div>

                <!-- Products Content - Show to all users (guest or logged in) -->
                <div class="w-full px-3">
                    <!-- Mobile Header -->
                    <div class="mb-4">
                        <h1 class="text-2xl font-bold text-gray-900 mb-3 mt-1">Cleaning Services</h1>
                        <div class="relative">
                            <label for="search-services-mobile" class="sr-only">Search services</label>
                            <input id="search-services-mobile" type="text" x-model="searchQuery" placeholder="Search..."
                                autocomplete="off" inputmode="search"
                                class="w-full px-4 py-2.5 pl-10 bg-white border-2 border-gray-300 rounded-lg focus:outline-none focus:ring-2 focus:ring-emerald-500 text-sm text-gray-900 placeholder-gray-400">
                            <svg class="absolute left-3 top-1/2 transform -translate-y-1/2 w-4 h-4 text-gray-500 pointer-events-none"
                                fill="none" stroke="currentColor" viewBox="0 0 24 24">
                                <path stroke-linecap="round" stroke-linejoin="round" stroke-width="2"
                                    d="M21 21l-6-6m2-5a7 7 0 11-14 0 7 7 0 0114 0z"></path>
                            </svg>
                        </div>
                    </div>

                    <!-- Mobile Category Filters - Scrollable -->
                    <div class="flex gap-1 overflow-x-auto mb-3 pb-2 scrollbar-hide">
                        <button @click="filterByCategory('all')"
                            :class="{'bg-emerald-500 text-white': selectedCategory === 'all', 'bg-gray-100 text-gray-600': selectedCategory !== 'all'}"
                            class="px-3 py-1.5 rounded-full text-xs font-medium whitespace-nowrap transition-all flex-shrink-0">All</button>
                        <button @click="filterByCategory('Non-Furnished')"
                            :class="{'bg-emerald-500 text-white': selectedCategory === 'Non-Furnished', 'bg-gray-100 text-gray-600': selectedCategory !== 'Non-Furnished'}"
                            class="px-3 py-1.5 rounded-full text-xs font-medium whitespace-nowrap transition-all flex-shrink-0">Non-Furnished</button>
                        <button @click="filterByCategory('Furnished')"
                            :class="{'bg-emerald-500 text-white': selectedCategory === 'Furnished', 'bg-gray-100 text-gray-600': selectedCategory !== 'Furnished'}"
                            class="px-3 py-1.5 rounded-full text-xs font-medium whitespace-nowrap transition-all flex-shrink-0">Furnished</button>
                    </div>

                    <!-- Mobile Products - Horizontal Scroll Layout -->
                    <div class="space-y-6">

                        <!-- Mobile Skeleton: visible while Firestore loads -->
                        <template x-if="!firestoreDataReady">
                            <div class="space-y-6">
                                <template x-for="s in [1,2]" :key="s">
                                    <div>
                                        <div class="flex items-center justify-between mb-3">
                                            <div class="skeleton h-5 w-32"></div>
                                            <div class="skeleton h-3 w-12"></div>
                                        </div>
                                        <div class="grid grid-cols-2 gap-3">
                                            <template x-for="c in [1,2,3,4]" :key="c">
                                                <div class="rounded-xl bg-white border border-gray-200 shadow-sm overflow-hidden">
                                                    <div class="skeleton h-24 rounded-none"></div>
                                                    <div class="p-2 space-y-2">
                                                        <div class="skeleton h-3 w-3/4"></div>
                                                        <div class="skeleton h-3 w-1/2"></div>
                                                        <div class="skeleton h-7 w-full rounded-lg mt-1"></div>
                                                    </div>
                                                </div>
                                            </template>
                                        </div>
                                    </div>
                                </template>
                            </div>
                        </template>

                        <!-- Vertical Grid Layout (2 columns, smaller cards) - Shows 4-5 products per screen -->
                        <template x-for="[category, services] in Object.entries(filteredServices())"
                            :key="category + '-' + firestoreDataReady">
                            <div>
                                <div class="flex items-center justify-between mb-3">
                                    <h2 class="text-base font-bold text-gray-900"
                                        x-text="category.charAt(0).toUpperCase() + category.slice(1)"></h2>
                                    <span class="text-xs text-gray-500" x-text="services.length + ' items'"></span>
                                </div>

                                <!-- Vertical Scrollable Product List (2 columns, page scrolls top-to-bottom) -->
                                <div class="relative">
                                    <!-- 2-up grid: no horizontal swipe, continuous vertical scroll, 2 products per row -->
                                    <div class="grid grid-cols-2 gap-3">
                                        <template x-for="(service, idx) in services" :key="service.id">
                                            <div class="product-card bg-white rounded-lg shadow-md border border-gray-200 flex flex-col overflow-hidden cursor-pointer group/mcard transition-all duration-300 hover:shadow-lg hover:border-gray-300 w-full"
                                                @click="openServiceDetail(service)">
                                                <div class="overflow-hidden bg-gray-100 h-40 relative">
                                                    <img :src="service.img" :data-src="service.img" :alt="service.name"
                                                        class="w-full h-full object-cover hover:scale-110 transition-transform duration-300 lazy-image"
                                                        loading="lazy">
                                                    <div
                                                        class="absolute inset-0 bg-black/0 group-hover/mcard:bg-black/10 transition-colors duration-300">
                                                    </div>
                                                    <!-- Badge for first item on mobile -->
                                                    <div x-show="idx === 0 && isViewportSmall()"
                                                        class="absolute top-1 left-1 bg-gradient-to-r from-blue-500 to-cyan-500 text-white text-[10px] font-bold px-1.5 py-0.5 rounded-full">
                                                        New</div>
                                                </div>
                                                <div class="p-3 flex flex-col flex-1 justify-between gap-1">
                                                    <div>
                                                        <h3 class="product-title font-semibold text-xs md:text-xs text-gray-900 line-clamp-2 md:line-clamp-2 leading-tight"
                                                            x-text="service.name"></h3>
                                                        <div class="flex items-center gap-0.5 mt-1">
                                                            <div class="flex gap-0.5">
                                                                <template
                                                                    x-for="(filled, idx) in [service.rating >= 1, service.rating >= 2, service.rating >= 3, service.rating >= 4, service.rating >= 5]"
                                                                    :key="idx">
                                                                    <svg :class="filled ? 'text-yellow-400' : 'text-gray-400'"
                                                                        class="w-2.5 h-2.5 md:w-3.5 md:h-3.5"
                                                                        fill="currentColor" viewBox="0 0 20 20">
                                                                        <path
                                                                            d="M9.049 2.927c.3-.921 1.603-.921 1.902 0l1.07 3.292a1 1 0 00.95.69h3.462c.969 0 1.371 1.24.588 1.81l-2.8 2.034a1 1 0 00-.364 1.118l1.07 3.292c.3.921-.755 1.688-1.54 1.118l-2.8-2.034a1 1 0 00-1.175 0l-2.8 2.034c-.786.57-1.833-.197-1.54-1.118l1.07-3.292a1 1 0 00-.364-1.118L2.096 9.389c-.784-.57-.381-1.81.588-1.81h3.462a1 1 0 00.95-.69l1.07-3.292z">
                                                                        </path>
                                                                    </svg>
                                                                </template>
                                                            </div>
                                                            <span class="text-xs md:text-xs font-bold text-yellow-400"
                                                                x-text="service.rating"></span>
                                                        </div>
                                                    </div>
                                                    <div
                                                        class="product-price text-xs md:text-xs font-bold text-gray-900 mt-0.5">
                                                        ₹<span
                                                            x-text="service.price"></span>
                                                    </div>
                                                    <button
                                                        @click.stop="addServiceToCart(service); showMessage('Added to cart!', 'success')"
                                                        class="w-full bg-white hover:bg-gray-200 text-gray-800 py-1 px-1.5 rounded font-semibold text-xs md:py-2 md:px-3 transition-colors">Add</button>
                                                </div>
                                            </div>
                                        </template>
                                    </div>
                                </div>
                            </div>
                        </template>
                    </div>
                </div>
            </div>
        </div>

        <!-- REVIEWS MODAL - REMOVED -->

        <!-- SERVICE DETAIL MODAL (Urban Company Style) -->
        <div x-show="showServiceDetail" class="fixed inset-0 bg-black bg-opacity-50 z-50 overflow-y-auto"
            x-transition:enter="transition ease-out duration-300" x-transition:enter-start="opacity-0"
            x-transition:enter-end="opacity-100" @click.outside="closeServiceDetail()">
            <div class="min-h-screen flex items-end md:items-center justify-center py-4">
                <!-- Modal Container - Modern Glassmorphism -->
                <div class="w-full md:max-w-2xl rounded-t-2xl md:rounded-2xl shadow-2xl max-h-[85vh] md:max-h-[90vh] overflow-y-auto glass-card"
                    @click.stop x-show="showServiceDetail" x-transition:enter="transition ease-out duration-300"
                    x-transition:enter-start="transform translate-y-full md:scale-95 md:opacity-0"
                    x-transition:enter-end="transform translate-y-0 md:scale-100 md:opacity-100">

                    <!-- Modal Header with Close Button -->
                    <div
                        class="sticky top-0 glass-card border-b border-gray-200 p-4 flex items-center justify-between z-10">
                        <h2 class="text-xl font-bold text-gray-900 flex-1" x-text="serviceDetailData?.name"></h2>
                        <button @click="closeServiceDetail()"
                            class="p-2 hover:bg-gray-100 rounded-full transition-colors">
                            <svg class="w-6 h-6 text-gray-500" fill="none" stroke="currentColor" viewBox="0 0 24 24">
                                <path stroke-linecap="round" stroke-linejoin="round" stroke-width="2"
                                    d="M6 18L18 6M6 6l12 12"></path>
                            </svg>
                        </button>
                    </div>

                    <!-- Modal Body -->
                    <div class="p-4 md:p-6 space-y-6">

                        <!-- Service Image -->
                        <div
                            class="relative overflow-hidden rounded-xl glass-card h-64 flex items-center justify-center">
                            <img :src="serviceDetailData?.img" :data-src="serviceDetailData?.img"
                                :alt="serviceDetailData?.name" class="w-full h-full object-cover lazy-image"
                                loading="lazy" decoding="async">
                        </div>

                        <!-- Rating & Reviews -->
                        <div
                            class="flex items-center justify-between glass-card rounded-lg p-4 border border-gray-200">
                            <div class="flex items-center space-x-3">
                                <div
                                    class="flex items-center btn-gradient-primary text-white px-3 py-1.5 rounded-full font-semibold text-sm">
                                    <svg class="w-4 h-4 mr-1" fill="currentColor" viewBox="0 0 20 20">
                                        <path
                                            d="M9.049 2.927c.3-.921 1.603-.921 1.902 0l1.07 3.292a1 1 0 00.95.69h3.462c.969 0 1.371 1.24.588 1.81l-2.8 2.034a1 1 0 00-.364 1.118l1.07 3.292c.3.921-.755 1.688-1.54 1.118l-2.8-2.034a1 1 0 00-1.175 0l-2.8 2.034c-.786.57-1.833-.197-1.54-1.118l1.07-3.292a1 1 0 00-.364-1.118L2.096 9.389c-.784-.57-.381-1.81.588-1.81h3.462a1 1 0 00.95-.69l1.07-3.292z">
                                        </path>
                                    </svg>
                                    <span x-text="serviceDetailData?.rating"></span>
                                </div>
                                <div>
                                    <p class="text-gray-600 font-semibold"
                                        x-text="`${serviceDetailData?.reviews} reviews`"></p>
                                    <p class="text-gray-500 text-sm">Based on customer feedback</p>
                                </div>
                            </div>
                        </div>

                        <!-- Description -->
                        <div>
                            <h3 class="text-lg font-semibold text-gray-900 mb-2">About This Service</h3>
                            <p class="text-gray-500 text-sm leading-relaxed" x-text="serviceDetailData?.description">
                            </p>
                        </div>

                        <!-- Variant Selector - Simplified -->
                        <div x-show="serviceDetailData?.variants && serviceDetailData.variants.length > 1">
                            <h3 class="text-sm sm:text-base font-semibold text-gray-900 mb-2">Select Package:</h3>
                            <div class="flex flex-wrap gap-2">
                                <template x-for="variant in serviceDetailData?.variants" :key="variant.id">
                                    <button @click="selectedVariantId = variant.id"
                                        :class="{'bg-emerald-600 border-emerald-500 text-white': selectedVariantId === variant.id, 'bg-gray-100 border-gray-300 text-gray-600 hover:border-gray-400': selectedVariantId !== variant.id}"
                                        class="px-3 py-2 border rounded-lg transition-all text-xs sm:text-sm font-medium">
                                        <span x-text="variant.name"></span> - ₹<span x-text="variant.price"></span>
                                    </button>
                                </template>
                            </div>
                        </div>

                        <!-- Equipment Used -->
                        <div x-show="serviceDetailData?.equipment && serviceDetailData.equipment.length > 0">
                            <h3 class="text-lg font-semibold text-gray-900 mb-3">Equipment & Tools Used</h3>
                            <div class="grid grid-cols-2 md:grid-cols-3 gap-2">
                                <template x-for="item in serviceDetailData?.equipment" :key="item">
                                    <div class="bg-white rounded-lg p-3 border border-gray-200 text-center">
                                        <p class="text-gray-600 text-sm" x-text="item"></p>
                                    </div>
                                </template>
                            </div>
                        </div>

                        <!-- Customer Requirements -->
                        <div
                            x-show="serviceDetailData?.customerRequirements && serviceDetailData.customerRequirements.length > 0">
                            <h3 class="text-lg font-semibold text-gray-900 mb-3">What You Need to Do</h3>
                            <ul class="space-y-2">
                                <template x-for="req in serviceDetailData?.customerRequirements" :key="req">
                                    <li class="flex items-start space-x-2">
                                        <div
                                            class="mt-1 flex-shrink-0 w-5 h-5 rounded-full bg-emerald-500 flex items-center justify-center">
                                            <svg class="w-3 h-3 text-white" fill="none" stroke="currentColor"
                                                viewBox="0 0 24 24">
                                                <path stroke-linecap="round" stroke-linejoin="round" stroke-width="2"
                                                    d="M5 13l4 4L19 7"></path>
                                            </svg>
                                        </div>
                                        <span class="text-gray-600 text-sm" x-text="req"></span>
                                    </li>
                                </template>
                            </ul>
                        </div>

                        <!-- Trust Badges -->
                        <div x-show="serviceDetailData?.trustBadges && serviceDetailData.trustBadges.length > 0">
                            <h3 class="text-lg font-semibold text-gray-900 mb-3">Trust & Credentials</h3>
                            <div class="grid grid-cols-2 gap-2">
                                <template x-for="badge in serviceDetailData?.trustBadges" :key="badge.label">
                                    <div :style="`border-left: 4px solid ${badge.color === 'green' ? '#10b981' : badge.color === 'blue' ? '#3b82f6' : '#f59e0b'}`"
                                        class="bg-white rounded-lg p-3 border border-gray-200">
                                        <p class="text-2xl mb-1" x-text="badge.icon"></p>
                                        <p class="text-gray-600 font-semibold text-sm" x-text="badge.label"></p>
                                    </div>
                                </template>
                            </div>
                        </div>

                        <!-- Ratings Breakdown -->
                        <div class="bg-white rounded-lg p-4 border border-gray-200">
                            <h3 class="text-lg font-semibold text-gray-900 mb-3">Ratings Breakdown</h3>
                            <template x-if="serviceDetailData?.ratingBreakdown">
                                <div class="space-y-2">
                                    <template x-for="star in [5,4,3,2,1]" :key="star">
                                        <div class="flex items-center justify-between">
                                            <div class="flex items-center space-x-3">
                                                <span class="font-semibold text-gray-900" x-text="`${star}★`"></span>
                                                <div class="w-40 bg-gray-100 rounded-full h-2 overflow-hidden">
                                                    <div class="bg-yellow-400 h-2"
                                                        :style="`width: ${(serviceDetailData?.ratingBreakdown?.[star] || 0)}%`">
                                                    </div>
                                                </div>
                                            </div>
                                            <div class="text-gray-500 text-sm"
                                                x-text="`${(serviceDetailData?.ratingBreakdown?.[star] || 0)}%`"></div>
                                        </div>
                                    </template>
                                </div>
                            </template>
                            <template x-if="!serviceDetailData?.ratingBreakdown">
                                <p class="text-center text-gray-500">Loading ratings...</p>
                            </template>
                        </div>

                        <!-- Top Reviews -->
                        <div x-show="serviceDetailData?.topReviews && serviceDetailData.topReviews.length > 0">
                            <div class="flex items-center justify-between mb-3">
                                <h3 class="text-lg font-semibold text-gray-900">Top Reviews</h3>
                                <button @click="openReviewForm(serviceDetailData)"
                                    class="text-sm text-emerald-600 font-medium hover:underline">Write a review</button>
                            </div>
                            <div class="space-y-3">
                                <template x-for="review in getFilteredReviews()" :key="review.author">
                                    <div class="bg-white rounded-lg p-4 border border-gray-200">
                                        <div class="flex items-start justify-between mb-2">
                                            <p class="font-semibold text-gray-900" x-text="review.author"></p>
                                            <div class="flex space-x-0.5">
                                                <template x-for="(filled, index) in getStars(review.rating)"
                                                    :key="index">
                                                    <svg :class="filled ? 'text-yellow-400' : 'text-gray-600'"
                                                        class="w-4 h-4" fill="currentColor" viewBox="0 0 20 20">
                                                        <path
                                                            d="M9.049 2.927c.3-.921 1.603-.921 1.902 0l1.07 3.292a1 1 0 00.95.69h3.462c.969 0 1.371 1.24.588 1.81l-2.8 2.034a1 1 0 00-.364 1.118l1.07 3.292c.3.921-.755 1.688-1.54 1.118l-2.8-2.034a1 1 0 00-1.175 0l-2.8 2.034c-.786.57-1.833-.197-1.54-1.118l1.07-3.292a1 1 0 00-.364-1.118L2.096 9.389c-.784-.57-.381-1.81.588-1.81h3.462a1 1 0 00.95-.69l1.07-3.292z">
                                                        </path>
                                                    </svg>
                                                </template>
                                            </div>
                                        </div>
                                        <p class="text-gray-600 text-sm" x-text="review.text"></p>
                                    </div>
                                </template>
                            </div>
                        </div>

                        <!-- Add to Cart Button (Sticky at Bottom on Mobile) -->
                        <div class="space-y-2 md:sticky md:bottom-0 md:bg-gray-50 md:pt-4 md:pb-0">
                            <button @click="addServiceToCart(serviceDetailData)"
                                class="w-full bg-gradient-to-r from-emerald-500 to-emerald-600 hover:from-emerald-600 hover:to-emerald-700 text-white font-semibold py-3 px-4 rounded-lg transition-all transform hover:scale-105 flex items-center justify-center space-x-2">
                                <svg class="w-5 h-5" fill="none" stroke="currentColor" viewBox="0 0 24 24">
                                    <path stroke-linecap="round" stroke-linejoin="round" stroke-width="2"
                                        d="M3 3h2l.4 2M7 13h10l4-8H5.4m1.6 8L6 21h12M9 19a2 2 0 100 4 2 2 0 000-4zM20 19a2 2 0 100 4 2 2 0 000-4z">
                                    </path>
                                </svg>
                                <span>Add to Cart - ₹<span x-text="getCurrentPrice()"></span></span>
                            </button>
                            <button @click="closeServiceDetail()"
                                class="w-full bg-white hover:bg-gray-100 text-gray-800 font-semibold py-3 px-4 rounded-lg transition-colors border border-gray-200">
                                Continue Shopping
                            </button>
                        </div>
                    </div>
                </div>
            </div>
        </div>
        </template>

        <!-- Product Detail Page -->
        <div x-show="currentPage === 'product-detail'" class="min-h-full pb-20 md:pb-0 pt-0"
            x-transition:enter="transition ease-out duration-300" x-transition:enter-start="opacity-0"
            x-transition:enter-end="opacity-100">
            <div class="w-full space-y-3" x-show="selectedProduct">
                <div class="bg-white rounded-2xl shadow-xl p-3 md:p-4 border border-gray-200">
                    <div class="grid grid-cols-1 gap-4">
                        <div class="text-center">
                            <div class="text-5xl md:text-6xl mb-2" x-text="selectedProduct?.icon"></div>
                            <div class="flex items-center justify-center space-x-2">
                                <svg class="w-5 h-5 text-emerald-500" fill="currentColor" viewBox="0 0 20 20">
                                    <path
                                        d="M9.049 2.927c.3-.921 1.603-.921 1.902 0l1.07 3.292a1 1 0 00.95.69h3.462c.969 0 1.371 1.24.588 1.81l-2.8 2.034a1 1 0 00-.364 1.118l1.07 3.292c.3.921-.755 1.688-1.54 1.118l-2.8-2.034a1 1 0 00-1.175 0l-2.8 2.034c-.786.57-1.833-.197-1.54-1.118l1.07-3.292a1 1 0 00-.364-1.118L2.098 9.389c-.784-.57-.382-1.81.588-1.81h4.167a1 1 0 00.95-.691l1.07-3.292z">
                                    </path>
                                </svg>
                                <span class="text-lg font-semibold text-emerald-400"
                                    x-text="selectedProduct?.rating"></span>
                                <span class="text-yellow-400">(<span x-text="selectedProduct?.reviews"></span>
                                    reviews)</span>
                            </div>
                        </div>
                        <div>
                            <h1 class="text-xl sm:text-2xl font-bold text-gray-900 mb-2 sm:mb-3"
                                x-text="selectedProduct?.name"></h1>
                            <p class="text-gray-500 mb-3 sm:mb-4 text-xs sm:text-sm"
                                x-text="selectedProduct?.description"></p>

                            <div class="mb-6 sm:mb-8">
                                <div class="flex items-baseline space-x-2">
                                    <span x-show="selectedProduct?.originalPrice > 0"
                                        class="text-lg sm:text-xl text-gray-400 line-through">₹<span
                                            x-text="selectedProduct?.originalPrice"></span></span>
                                    <span class="text-xl sm:text-2xl font-bold text-white">₹<span
                                            x-text="selectedProduct?.customPrice ? selectedProduct?.calculatedPrice : selectedProduct?.price"></span></span>
                                </div>
                            </div>

                            <div class="space-y-3 sm:space-y-4 mb-6 sm:mb-8">
                                <h3 class="text-base sm:text-lg font-semibold text-gray-900">Service Includes:</h3>
                                <ul
                                    class="list-disc list-inside text-gray-500 space-y-1 sm:space-y-2 text-xs sm:text-sm">
                                    <li>Professional cleaning equipment</li>
                                    <li>Eco-friendly cleaning products</li>
                                    <li>Trained and experienced staff</li>
                                    <li>Quality assurance guarantee</li>
                                </ul>
                            </div>

                            <div x-show="selectedProduct?.hasQuantity || selectedProduct?.customPrice"
                                class="mb-4 sm:mb-6">
                                <label for="custom-quantity"
                                    class="block text-xs sm:text-sm font-medium text-gray-600">Enter <span
                                        x-text="selectedProduct?.quantityLabel || selectedProduct?.customLabel"></span>:</label>
                                <input type="number" id="custom-quantity" x-model.number="customQuantity"
                                    @input="updateCustomPrice()" min="1"
                                    class="mt-1 block w-full rounded-md bg-gray-100 border-gray-300 text-gray-900 shadow-sm focus:border-emerald-500 focus:ring focus:ring-emerald-500 focus:ring-opacity-50 text-sm">
                                <p class="text-gray-500 mt-2 text-xs sm:text-sm" x-show="customQuantity > 0">Calculated
                                    Price: ₹<span x-text="selectedProduct?.calculatedPrice"></span></p>
                            </div>

                            <!-- Quick OTP Verification in Product Detail -->
                            <div x-show="!hasAuth()"
                                class="mb-4 sm:mb-6 bg-gray-100/80 rounded-lg p-3 border border-gray-300">
                                <h4 class="text-xs sm:text-sm font-semibold text-gray-900 mb-2">Quick Verification
                                    (Optional)</h4>
                                <p class="text-xs text-gray-600 mb-3">Verify your email quickly before checkout</p>

                                <div class="space-y-2">
                                    <input type="email" name="email" autocomplete="email" x-model="emailOtpData.email"
                                        placeholder="Enter your email"
                                        class="w-full p-2 rounded-md bg-gray-100 border border-gray-300 text-gray-900 placeholder-gray-400 focus:outline-none focus:ring-2 focus:ring-emerald-500 text-xs sm:text-sm">
                                    <button @click="sendEmailOTP()" :disabled="loading.auth || !emailOtpData.email"
                                        class="w-full bg-emerald-500 text-white px-3 py-2 rounded-md font-semibold hover:bg-emerald-600 transition-colors disabled:opacity-50 disabled:cursor-not-allowed text-xs sm:text-sm">
                                        <span x-show="!showOtpInput">Send OTP</span>
                                        <span x-show="showOtpInput">Resend OTP</span>
                                    </button>
                                </div>

                                <div x-show="showOtpInput" class="mt-3 space-y-2">
                                    <input type="text" x-model="otpCode" placeholder="Enter 6-digit OTP" maxlength="6"
                                        class="w-full p-2 rounded-md bg-gray-100 border border-gray-300 text-gray-900 placeholder-gray-400 focus:outline-none focus:ring-2 focus:ring-emerald-500 text-center text-sm font-bold tracking-widest">
                                    <button @click="verifyEmailOTP()" :disabled="loading.auth || otpCode.length !== 6"
                                        class="w-full bg-green-600 text-white px-3 py-2 rounded-md font-semibold hover:bg-green-700 transition-colors disabled:opacity-50 disabled:cursor-not-allowed text-xs sm:text-sm">
                                        Verify OTP
                                    </button>
                                </div>
                            </div>

                            <div class="space-y-3">
                                <button @click="addToCart(selectedProduct)"
                                    class="w-full bg-white text-gray-800 px-4 sm:px-6 py-2 sm:py-3 rounded-lg font-semibold hover:bg-slate-100 transform hover:scale-105 transition-all text-sm sm:text-base">
                                    Add to Cart
                                </button>
                                <button @click="navigateTo('products')"
                                    class="w-full bg-gray-100 text-gray-800 px-4 sm:px-6 py-2 sm:py-3 rounded-lg font-semibold hover:bg-gray-200 transition-colors text-sm sm:text-base">
                                    Back to Services
                                </button>
                            </div>
                        </div>
                    </div>
                </div>
            </div>
        </div>
        </div>

        <div x-show="currentPage === 'cart'" class="min-h-full pb-20 md:pb-0 pt-0 px-3 sm:px-4">
            <div class="w-full space-y-3">
                <!-- Step Progress Indicator -->
                <div class="flex items-center justify-start gap-2 mb-6">
                    <div class="flex items-center gap-1">
                        <span
                            class="flex items-center justify-center w-8 h-8 rounded-full bg-gray-200 text-gray-500 font-bold text-sm">✓</span>
                        <span class="text-xs text-gray-500 font-medium">Sign In</span>
                    </div>
                    <div class="h-0.5 w-6 bg-gray-100"></div>
                    <div class="flex items-center gap-1">
                        <span
                            class="flex items-center justify-center w-8 h-8 rounded-full bg-gray-200 text-gray-500 font-bold text-sm">✓</span>
                        <span class="text-xs text-gray-500 font-medium">Browse</span>
                    </div>
                    <div class="h-0.5 w-6 bg-gray-100"></div>
                    <div class="flex items-center gap-1">
                        <span
                            class="flex items-center justify-center w-8 h-8 rounded-full bg-emerald-500 text-gray-900 font-bold text-sm">3</span>
                        <span class="text-xs text-gray-600 font-medium">Cart</span>
                    </div>
                    <div class="h-0.5 w-6 bg-gray-100"></div>
                    <div class="flex items-center gap-1">
                        <span
                            class="flex items-center justify-center w-8 h-8 rounded-full bg-gray-200 text-gray-500 font-bold text-sm">4</span>
                        <span class="text-xs text-gray-500 font-medium">Order</span>
                    </div>
                </div>

                <h1 class="text-lg md:text-xl font-bold text-gray-900 mb-6 flex items-center gap-2"><svg class="icon"><use href="#i-cart"/></svg> Review Your Cart</h1>

                <div x-show="Object.keys(cart).length === 0" class="text-center py-16">
                    <div class="text-6xl mb-4">&#128717;</div>
                    <h2 class="text-2xl font-semibold text-gray-500 mb-4">Your cart is empty</h2>
                    <button @click="navigateTo('products')"
                        class="btn-gradient-primary text-white px-8 py-3 rounded-lg font-semibold hover:shadow-lg transition-all">
                        Continue Shopping
                    </button>
                </div>

                <div x-show="Object.keys(cart).length > 0" class="space-y-4">
                    <!-- Cart Tips -->
                    <div class="bg-green-50 border border-green-200 rounded-lg p-3">
                        <p class="text-xs text-green-700"><svg class="icon icon--sm"><use href="#i-sparkle"/></svg><strong>Next Step:</strong> Review your items and click
                            "Proceed to Checkout" to enter your delivery address and schedule the service.</p>
                    </div>

                    <div>
                        <div class="glass-card rounded-xl shadow-lg border border-gray-200 divide-y divide-gray-200">
                            <template x-for="(item, id) in cart" :key="id">
                                <div
                                    class="flex items-start justify-between p-3 md:p-4 space-x-3 hover:bg-gray-100/60 transition-colors">
                                    <div class="flex items-start space-x-3 md:space-x-4 flex-1 min-w-0">
                                        <div class="text-2xl md:text-3xl flex-shrink-0 mt-1" x-text="item.icon"></div>
                                        <div class="min-w-0 flex-1">
                                            <h3 class="font-semibold text-sm md:text-base text-gray-900 line-clamp-2"
                                                x-text="item.name"></h3>
                                            <p class="text-xs text-gray-500 hidden sm:block mt-0.5"
                                                x-text="item.description"></p>
                                            <p class="text-sm md:text-base font-bold text-emerald-400 mt-1.5">₹<span
                                                    x-text="item.price"></span> <span
                                                    class="text-xs text-gray-600 font-normal"
                                                    x-text="'per ' + (item.unit || 'unit')"></span> × <span
                                                    x-text="item.quantity"></span></p>
                                        </div>
                                    </div>
                                    <div class="flex items-center space-x-2 flex-shrink-0">
                                        <button @click="updateQuantity(id, item.quantity - 1)"
                                            class="bg-gray-200 text-gray-800 w-7 h-7 rounded flex items-center justify-center hover:bg-gray-300 text-sm font-semibold transition-all"
                                            :aria-label="'Decrease ' + item.name + ' quantity'">−</button>
                                        <span class="font-semibold w-7 text-center text-gray-900 text-sm"
                                            x-text="item.quantity" aria-live="polite"></span>
                                        <button @click="updateQuantity(id, item.quantity + 1)"
                                            class="btn-gradient-primary text-white w-7 h-7 rounded flex items-center justify-center text-sm font-semibold transition-all"
                                            :aria-label="'Increase ' + item.name + ' quantity'">+</button>
                                        <button @click="removeFromCart(id)"
                                            class="text-emerald-400 hover:text-emerald-300 flex-shrink-0 ml-1 transition-colors"
                                            :aria-label="'Remove ' + item.name + ' from cart'">
                                            <svg class="w-5 h-5" fill="none" stroke="currentColor" viewBox="0 0 24 24">
                                                <path stroke-linecap="round" stroke-linejoin="round" stroke-width="2"
                                                    d="M19 7l-.867 12.142A2 2 0 0116.138 21H7.862a2 2 0 01-1.995-1.858L5 7m5 4v6m4-6v6m1-10V4a1 1 0 00-1-1h-4a1 1 0 00-1 1v3M4 7h16">
                                                </path>
                                            </svg>
                                        </button>
                                    </div>
                                </div>
                            </template>
                        </div>
                    </div>

                    <!-- Recommended Add-ons Section - COMPACT -->
                    <div class="glass-card rounded-lg border border-gray-200 p-4">
                        <div class="mb-4">
                            <h3 class="text-base font-bold text-gray-900">Quick Add-ons</h3>
                            <p class="text-xs text-gray-500 mt-1">Enhance your cleaning package</p>
                        </div>

                        <div class="space-y-3">
                            <!-- Carpet Shampoo -->
                            <div
                                class="bg-white rounded border border-gray-300 p-2.5 hover:border-gray-400 transition-colors flex items-start justify-between gap-2">
                                <div class="flex items-start gap-2 flex-1 min-w-0">
                                    <div class="text-lg flex-shrink-0">🧼</div>
                                    <div class="min-w-0 flex-1">
                                        <h4 class="text-xs font-semibold text-gray-900">Carpet Shampoo</h4>
                                        <p class="text-xs text-gray-600 font-bold mt-0.5">₹600 per carpet</p>
                                    </div>
                                </div>
                                <button
                                    @click="quickAddToCart({id: 'carpet-shampoo', name: 'Carpet Shampoo', description: 'Professional deep cleaning per carpet', price: 600, icon: '🧼', unit: 'carpet', quantity: 1})"
                                    class="bg-gray-100 hover:bg-gray-200 text-gray-900 text-xs px-2 py-1 rounded flex-shrink-0 transition-colors">
                                    Add
                                </button>
                            </div>

                            <!-- Sofa Shampoo -->
                            <div
                                class="bg-white rounded border border-gray-300 p-2.5 hover:border-gray-400 transition-colors flex items-start justify-between gap-2">
                                <div class="flex items-start gap-2 flex-1 min-w-0">
                                    <div class="text-lg flex-shrink-0"><svg class="icon"><use href="#i-sofa"/></svg></div>
                                    <div class="min-w-0 flex-1">
                                        <h4 class="text-xs font-semibold text-gray-900">Sofa Shampoo</h4>
                                        <p class="text-xs text-gray-600 font-bold mt-0.5">₹150 per seat</p>
                                    </div>
                                </div>
                                <button
                                    @click="quickAddToCart({id: 'sofa-shampoo', name: 'Sofa Shampoo', description: 'Professional cleaning per seat', price: 150, icon: '🛋️', unit: 'seat', quantity: 1})"
                                    class="bg-gray-100 hover:bg-gray-200 text-gray-900 text-xs px-2 py-1 rounded flex-shrink-0 transition-colors">
                                    Add
                                </button>
                            </div>

                            <!-- Fridge Cleaning -->
                            <div
                                class="bg-white rounded border border-gray-300 p-2.5 hover:border-gray-400 transition-colors flex items-start justify-between gap-2">
                                <div class="flex items-start gap-2 flex-1 min-w-0">
                                    <div class="text-lg flex-shrink-0"><svg class="icon"><use href="#i-snow"/></svg></div>
                                    <div class="min-w-0 flex-1">
                                        <h4 class="text-xs font-semibold text-gray-900">Fridge Cleaning</h4>
                                        <p class="text-xs text-gray-600 font-bold mt-0.5">₹400 per fridge</p>
                                    </div>
                                </div>
                                <button
                                    @click="quickAddToCart({id: 'fridge-cleaning', name: 'Fridge Cleaning', description: 'Thorough interior and exterior cleaning', price: 400, icon: '❄️', unit: 'fridge', quantity: 1})"
                                    class="bg-gray-100 hover:bg-gray-200 text-gray-900 text-xs px-2 py-1 rounded flex-shrink-0 transition-colors">
                                    Add
                                </button>
                            </div>

                            <!-- Microwave Cleaning -->
                            <div
                                class="bg-white rounded border border-gray-300 p-2.5 hover:border-gray-400 transition-colors flex items-start justify-between gap-2">
                                <div class="flex items-start gap-2 flex-1 min-w-0">
                                    <div class="text-lg flex-shrink-0"><svg class="icon"><use href="#i-fire"/></svg></div>
                                    <div class="min-w-0 flex-1">
                                        <h4 class="text-xs font-semibold text-gray-900">Microwave Cleaning</h4>
                                        <p class="text-xs text-gray-600 font-bold mt-0.5">₹200 per microwave</p>
                                    </div>
                                </div>
                                <button
                                    @click="quickAddToCart({id: 'microwave-cleaning', name: 'Microwave Cleaning', description: 'Interior, exterior, and turntable cleaning', price: 200, icon: '🔥', unit: 'microwave', quantity: 1})"
                                    class="bg-gray-100 hover:bg-gray-200 text-gray-900 text-xs px-2 py-1 rounded flex-shrink-0 transition-colors">
                                    Add
                                </button>
                            </div>
                        </div>
                    </div>

                    <div>
                        <div class="glass-card rounded-xl shadow-lg p-4 border border-gray-200">
                            <h2 class="text-lg font-bold mb-4 text-gray-900">Order Summary</h2>
                            <div class="space-y-3 mb-4 text-gray-600">
                                <div class="flex justify-between">
                                    <span>Subtotal</span>
                                    <span>₹<span x-text="formatPrice(getSubtotal())"></span></span>
                                </div>
                                <div class="flex justify-between">
                                    <span>Service Fee</span>
                                    <span>₹<span x-text="formatPrice(getServiceFee())"></span></span>
                                </div>
                                <div class="flex justify-between">
                                    <span>GST (18%)</span>
                                    <span>₹<span x-text="formatPrice(getTax())"></span></span>
                                </div>
                                <div
                                    class="border-t border-gray-300 pt-3 flex justify-between font-bold text-base text-gray-900">
                                    <span>Total</span>
                                    <span>₹<span x-text="formatPrice(getTotal())"></span></span>
                                </div>
                            </div>
                            <button @click="navigateTo('checkout')"
                                class="w-full btn-gradient-primary text-white py-3 rounded-lg font-semibold hover:shadow-lg transform hover:scale-105 transition-all">
                                Proceed to Checkout
                            </button>
                        </div>
                    </div>
                </div>
            </div>
        </div>

        <div x-show="currentPage === 'checkout'" class="min-h-full pb-20 md:pb-0 pt-0 px-3 sm:px-4">
            <div class="w-full space-y-3">
                <!-- Step Progress Indicator -->
                <div class="flex items-center justify-center gap-2 mb-6 flex-wrap">
                    <div class="flex items-center gap-1">
                        <span
                            class="flex items-center justify-center w-7 h-7 rounded-full bg-gray-200 text-gray-500 font-bold text-sm">✓</span>
                        <span class="text-xs text-gray-500 font-medium hidden sm:inline">Sign In</span>
                    </div>
                    <div class="h-0.5 w-4 bg-gray-100 hidden sm:inline"></div>
                    <div class="flex items-center gap-1">
                        <span
                            class="flex items-center justify-center w-7 h-7 rounded-full bg-gray-200 text-gray-500 font-bold text-sm">✓</span>
                        <span class="text-xs text-gray-500 font-medium hidden sm:inline">Browse</span>
                    </div>
                    <div class="h-0.5 w-4 bg-gray-100 hidden sm:inline"></div>
                    <div class="flex items-center gap-1">
                        <span
                            class="flex items-center justify-center w-7 h-7 rounded-full bg-gray-200 text-gray-500 font-bold text-sm">✓</span>
                        <span class="text-xs text-gray-500 font-medium hidden sm:inline">Cart</span>
                    </div>
                    <div class="h-0.5 w-4 bg-gray-100 hidden sm:inline"></div>
                    <div class="flex items-center gap-1">
                        <span
                            class="flex items-center justify-center w-7 h-7 rounded-full bg-emerald-500 text-gray-900 font-bold text-sm">4</span>
                        <span class="text-xs text-gray-600 font-medium hidden sm:inline">Order</span>
                    </div>
                </div>

                <h1 class="text-lg md:text-xl font-bold text-center text-gray-900 mb-4 flex items-center justify-center gap-2"><svg class="icon"><use href="#i-clipboard"/></svg> Complete Your Order</h1>

                <!-- Main Instructions Banner -->
                <div
                    class="bg-emerald-50 border border-emerald-300 rounded-lg p-3 mb-4">
                    <h3 class="text-emerald-900 font-bold text-xs md:text-sm mb-2 flex items-center gap-1"><svg class="icon icon--sm"><use href="#i-doc"/></svg> How to complete:</h3>
                    <ol class="text-xs text-emerald-800 space-y-0.5 list-decimal list-inside">
                        <li><strong>Address:</strong> Enter your delivery location</li>
                        <li><strong>Contact:</strong> Phone & email for confirmation</li>
                        <li><strong>Schedule:</strong> Pick your preferred date & time</li>
                        <li><strong>Verify:</strong> Review order & click place order</li>
                    </ol>
                </div>

                <div class="lg:flex lg:space-x-8">
                    <div class="lg:w-2/3">
                        <div class="bg-white rounded-xl shadow-lg p-3 md:p-4 border border-gray-200">
                            <h3 class="text-base md:text-lg font-bold text-gray-900 mb-4 flex items-center gap-2">
                                <span
                                    class="bg-emerald-500/20 text-emerald-600 w-7 h-7 flex items-center justify-center rounded-full text-sm font-bold">1</span>
                                Delivery Details
                            </h3>

                            <!-- Address Selection Section - HIDDEN BY DEFAULT -->
                            <div x-show="checkoutAddresses && checkoutAddresses.length > 0"
                                class="bg-white rounded-xl shadow-lg p-4 border border-gray-200 mb-6">
                                <!-- Button to toggle saved addresses dropdown -->
                                <button @click="toggleSavedAddresses()"
                                    class="w-full flex items-center justify-between px-4 py-3 bg-emerald-50 hover:bg-emerald-100 border border-emerald-300 rounded-lg transition-all text-left">
                                    <div class="flex items-center gap-3">
                                        <svg class="w-5 h-5 text-emerald-600" fill="none" stroke="currentColor"
                                            viewBox="0 0 24 24">
                                            <path stroke-linecap="round" stroke-linejoin="round" stroke-width="2"
                                                d="M17.657 16.657L13.414 20.9a1.998 1.998 0 01-2.827 0l-4.244-4.243a8 8 0 1111.314 0zM10 11a2 2 0 100-4 2 2 0 000 4z" />
                                        </svg>
                                        <span class="font-semibold text-gray-900">Use Saved Address</span>
                                    </div>
                                    <svg :class="showSavedAddresses ? 'rotate-180' : ''"
                                        class="w-5 h-5 text-emerald-600 transition-transform" fill="none"
                                        stroke="currentColor" viewBox="0 0 24 24">
                                        <path stroke-linecap="round" stroke-linejoin="round" stroke-width="2"
                                            d="M19 14l-7 7m0 0l-7-7m7 7V3"></path>
                                    </svg>
                                </button>

                                <!-- Address Options - Shown when toggled -->
                                <div x-show="showSavedAddresses" x-transition class="mt-4 space-y-2">
<div class="bg-gray-50 rounded-lg p-3 mb-3">
                                    <p class="text-xs text-gray-700 font-medium">SELECT A SAVED ADDRESS</p>
                                    </div>

                                    <!-- Clean list of addresses -->
                                    <template x-for="(addr, index) in checkoutAddresses" :key="index">
                                        <button @click="applyCheckoutAddress(index)"
                                            class="w-full text-left p-3 bg-white hover:bg-emerald-50 border-2 border-gray-200 hover:border-emerald-400 rounded-lg transition-all group">
                                            <div class="flex items-start justify-between">
                                                <div class="flex-1">
                                                    <p class="font-semibold text-gray-900 group-hover:text-emerald-600"
                                                        x-text="(addr.city ? addr.city + ', ' : '') + (addr.state || '')">
                                                    </p>
                                                    <p class="text-xs text-gray-600 mt-1"
                                                        x-text="addr.houseNumber ? addr.houseNumber : 'No house number'">
                                                    </p>
                                                    <p class="text-xs text-gray-500 mt-0.5 line-clamp-1"
                                                        x-text="addr.address.substring(0, 50) + (addr.address.length > 50 ? '...' : '')">
                                                    </p>
                                                </div>
                                                <svg class="w-5 h-5 text-emerald-600 opacity-0 group-hover:opacity-100 flex-shrink-0 ml-2"
                                                    fill="currentColor" viewBox="0 0 20 20">
                                                    <path fill-rule="evenodd"
                                                        d="M16.707 5.293a1 1 0 010 1.414l-8 8a1 1 0 01-1.414 0l-4-4a1 1 0 011.414-1.414L8 12.586l7.293-7.293a1 1 0 011.414 0z"
                                                        clip-rule="evenodd" />
                                                </svg>
                                            </div>
                                        </button>
                                    </template>

                                    <!-- Add New Address option inside dropdown -->
                                    <button @click="clearCheckoutAddress()"
                                        class="w-full text-left p-3 bg-white hover:bg-emerald-50 border-2 border-dashed border-gray-300 hover:border-emerald-300 rounded-lg transition-all text-gray-700 hover:text-emerald-700">
                                        <div class="flex items-center gap-2">
                                            <svg class="w-5 h-5" fill="none" stroke="currentColor" viewBox="0 0 24 24">
                                                <path stroke-linecap="round" stroke-linejoin="round" stroke-width="2"
                                                    d="M12 4v16m8-8H4"></path>
                                            </svg>
                                            <span class="font-medium">Add New Address</span>
                                        </div>
                                    </button>
                                </div>
                            </div>

                            <!-- ADDITIVE: save the completed address to the user's profile -->
                            <button type="button" @click="saveCheckoutAddressToProfile()"
                                class="mb-5 w-full flex items-center justify-center gap-2 px-4 py-2.5 bg-amber-50 hover:bg-amber-100 border border-amber-300 rounded-lg text-amber-800 text-sm font-semibold transition-colors">
                                <svg class="w-4 h-4" fill="none" stroke="currentColor" viewBox="0 0 24 24"><path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M5 5a2 2 0 012-2h10a2 2 0 012 2v16l-7-3.5L5 21V5z"/></svg>
                                Save this address to my profile
                            </button>

                            <div class="grid grid-cols-1 md:grid-cols-2 gap-2">
                                <div>
                                    <input id="checkout-name" type="text" name="name" autocomplete="name"
                                        x-model="checkoutForm.name" placeholder="Name (Optional)"
                                        class="w-full p-2 rounded-lg bg-white border border-gray-300 text-gray-900 placeholder-gray-500 text-sm focus:outline-none focus:ring-2 focus:ring-emerald-500"
                                        aria-label="Name (optional)">
                                </div>
                                <div>
                                    <label class="text-xs text-gray-700 font-semibold">Email <span
                                            class="text-red-500">*</span></label>
                                    <input id="checkout-email" type="email" name="email" autocomplete="email"
                                        x-model="checkoutForm.email" placeholder="Email (Required)" required
                                        :class="{'border-red-500 border-2': showCheckoutValidationErrors && isCheckoutFieldEmpty('email')}"
                                        class="w-full p-2 rounded-lg bg-white border border-gray-300 text-gray-900 placeholder-gray-500 text-sm focus:outline-none focus:ring-2 focus:ring-emerald-500"
                                        aria-label="Email (required)" aria-required="true">
                                </div>
                                <div class="md:col-span-2">
                                    <label class="text-xs text-gray-700 font-semibold">Phone
                                        <span class="text-gray-500 text-xs">(Optional)</span>
                                    </label>
                                    <input id="checkout-phone" type="tel" name="tel" autocomplete="tel"
                                        inputmode="numeric" x-model="checkoutForm.phone" placeholder="Phone (Optional)"
                                        class="w-full p-2 rounded-lg bg-white border border-gray-300 text-gray-900 placeholder-gray-500 focus:outline-none focus:ring-2 focus:ring-emerald-500"
                                        aria-label="Phone number (optional)" aria-required="false">
                                </div>
                                <div>
                                    <label class="text-xs text-gray-700 font-semibold">House No. / Building No. <span
                                            class="text-red-500">*</span></label>
                                    <input id="checkout-houseno" type="text" name="address-line1"
                                        autocomplete="address-line1" x-model="checkoutForm.houseNumber"
                                        placeholder="House No. / Building No. (Required)" required
                                        :class="{'border-red-500 border-2': showCheckoutValidationErrors && isCheckoutFieldEmpty('houseNumber')}"
                                        class="w-full p-2 rounded-lg bg-white border border-gray-300 text-gray-900 placeholder-gray-500 text-sm focus:outline-none focus:ring-2 focus:ring-emerald-500"
                                        aria-label="House or building number (required)" aria-required="true">
                                </div>
                            </div>
                            <button @click="detectLocation()"
                                class="w-full mt-2 mb-2 py-2 px-3 bg-emerald-600 text-white rounded-lg font-semibold hover:bg-emerald-700 transition-colors flex items-center justify-center space-x-2 disabled:opacity-50 disabled:cursor-not-allowed text-sm">
                                <svg xmlns="http://www.w3.org/2000/svg" class="h-5 w-5" viewBox="0 0 20 20"
                                    fill="currentColor">
                                    <path fill-rule="evenodd"
                                        d="M5.05 4.05a7 7 0 119.9 9.9L10 18.9l-4.95-4.95a7 7 0 010-9.9zM10 11a2 2 0 100-4 2 2 0 000 4z"
                                        clip-rule="evenodd" />
                                </svg>
                                <span
                                    x-text="loading.location ? 'Detecting Location...' : 'Auto-Fill Current Location'"></span>
                            </button>

                            <div class="space-y-4">
                                <label class="block" for="checkout-address">
                                    <span class="text-gray-700 font-semibold">Address (Area / Locality)</span>
                                    <input id="checkout-address" type="text" name="address-line2"
                                        autocomplete="address-line2" x-model="checkoutForm.address"
                                        class="w-full p-3 rounded-lg bg-white border border-gray-300 text-gray-900 placeholder-gray-500 focus:outline-none focus:ring-2 focus:ring-emerald-500 focus:border-transparent">
                                </label>

                                <div class="grid grid-cols-2 gap-4">
                                    <label class="block" for="checkout-city">
                                        <span class="text-gray-700 font-semibold">City</span>
                                        <input id="checkout-city" type="text" name="address-level2"
                                            autocomplete="address-level2" x-model="checkoutForm.city"
                                            class="w-full p-3 rounded-lg bg-white border border-gray-300 text-gray-900 placeholder-gray-500 focus:outline-none focus:ring-2 focus:ring-emerald-500">
                                    </label>

                                    <label class="block" for="checkout-state">
                                        <span class="text-gray-700 font-semibold">State</span>
                                        <input id="checkout-state" type="text" name="address-level1"
                                            autocomplete="address-level1" x-model="checkoutForm.state"
                                            class="w-full p-3 rounded-lg bg-white border border-gray-300 text-gray-900 placeholder-gray-500 focus:outline-none focus:ring-2 focus:ring-emerald-500">
                                    </label>
                                </div>

                                <label class="block" for="checkout-pincode">
                                    <span class="text-gray-700 font-semibold">Pincode</span>
                                    <input id="checkout-pincode" type="text" name="postal-code"
                                        autocomplete="postal-code" inputmode="numeric" x-model="checkoutForm.pincode" @change="fetchAvailableSlots()" @blur="fetchAvailableSlots()"
                                        class="w-full p-3 rounded-lg bg-white border border-gray-300 text-gray-900 placeholder-gray-500 focus:outline-none focus:ring-2 focus:ring-emerald-500">
                                </label>
                            </div>
                        </div>

                        <!-- Guest Email OTP Verification (only shown to non-logged-in users) -->
                        <div x-show="!user.uid" class="bg-white rounded-xl shadow-lg p-4 mb-4 border border-emerald-300">
                            <h3 class="text-base font-bold text-gray-900 mb-1 flex items-center gap-2">
                                <span class="bg-emerald-500/20 text-emerald-600 w-7 h-7 flex items-center justify-center rounded-full text-sm font-bold"><svg class="icon icon--sm"><use href="#i-mail"/></svg></span>
                                Verify Your Email to Book
                            </h3>
                            <p class="text-xs text-gray-500 mb-3">As a guest, verify your email with a one-time code before placing your order.</p>

                            <!-- Verified -->
                            <div x-show="guestEmailOtp.verified" class="flex items-center gap-2 bg-emerald-50 border border-emerald-300 rounded-lg p-3">
                                <svg class="w-5 h-5 text-emerald-600 flex-shrink-0" fill="none" stroke="currentColor" viewBox="0 0 24 24">
                                    <path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M9 12l2 2 4-4m6 2a9 9 0 11-18 0 9 9 0 0118 0z"/>
                                </svg>
                                <span class="text-sm text-emerald-800 font-semibold"><svg class="icon icon--sm"><use href="#i-check-circle"/></svg> Email verified — you're good to book!</span>
                            </div>

                            <!-- Step 1: Send OTP -->
                            <div x-show="!guestEmailOtp.verified && !guestEmailOtp.sent" class="space-y-2">
                                <p class="text-xs text-gray-600">We'll send a one-time code to: <strong x-text="checkoutForm.email || '—'"></strong></p>
                                <p x-show="!checkoutForm.email" class="text-xs text-amber-600 font-medium"><svg class="icon icon--sm"><use href="#i-warning"/></svg> Enter your email above first</p>
                                <button @click="guestEmailOtp.email = checkoutForm.email; sendGuestEmailOtp()"
                                    :disabled="guestEmailOtp.loading || !checkoutForm.email"
                                    class="w-full py-2.5 px-4 bg-emerald-600 hover:bg-emerald-700 text-white rounded-lg text-sm font-bold disabled:opacity-50 disabled:cursor-not-allowed transition-colors">
                                    <span x-text="guestEmailOtp.loading ? 'Sending…' : 'Send OTP to My Email'"></span>
                                </button>
                            </div>

                            <!-- Step 2: Enter code -->
                            <div x-show="!guestEmailOtp.verified && guestEmailOtp.sent" class="space-y-2">
                                <p class="text-xs text-gray-600">Enter the 6-digit code sent to <strong x-text="guestEmailOtp.email"></strong></p>
                                <div class="flex gap-2">
                                    <input type="text" inputmode="numeric" maxlength="6"
                                        x-model="guestEmailOtp.code"
                                        placeholder="6-digit code"
                                        class="flex-1 p-2.5 rounded-lg border border-gray-300 bg-white text-gray-900 placeholder-gray-400 text-sm tracking-widest text-center font-bold focus:outline-none focus:ring-2 focus:ring-emerald-500"
                                        @keydown.enter.prevent="verifyGuestEmailOtp()">
                                    <button @click="verifyGuestEmailOtp()"
                                        :disabled="guestEmailOtp.loading"
                                        class="px-4 py-2 bg-emerald-600 hover:bg-emerald-700 text-white rounded-lg text-sm font-bold disabled:opacity-50 disabled:cursor-not-allowed whitespace-nowrap transition-colors">
                                        <span x-text="guestEmailOtp.loading ? 'Verifying…' : 'Verify Code'"></span>
                                    </button>
                                </div>
                                <button @click="guestEmailOtp.sent = false; guestEmailOtp.code = ''"
                                    class="text-xs text-emerald-600 hover:underline">← Resend / change email</button>
                            </div>
                        </div>

                        <!-- Verification via email magic link only - no OTP UI -->

                        <!-- A3/A4: optional preferred-partner selection at booking -->
                        <div class="bg-white rounded-xl shadow-lg p-4 md:p-5 border border-gray-200 mb-6">
                            <div class="flex items-center justify-between mb-3">
                                <h3 class="text-base md:text-lg font-bold text-gray-900 flex items-center gap-2">
                                    <span class="bg-emerald-500/20 text-emerald-600 w-7 h-7 flex items-center justify-center rounded-full text-sm font-bold">2</span>
                                    Choose your preferred professional
                                </h3>
                                <span class="text-xs text-gray-400 font-medium">Optional</span>
                            </div>
                            <p class="text-xs text-gray-500 mb-3">Pick a professional you'd like, or leave it blank and we'll auto-assign the best available pro.</p>

                            <p x-show="loadingPartners" class="text-sm text-gray-400 py-2">Loading professionals…</p>
                            <p x-show="!loadingPartners && availablePartners.length === 0" class="text-sm text-gray-400 py-2">No specific professionals listed for your area — we'll auto-assign the best match.</p>

                            <div class="grid grid-cols-1 sm:grid-cols-2 gap-3" x-show="availablePartners.length > 0">
                                <template x-for="p in availablePartners" :key="p.id">
                                    <button type="button" @click="selectPreferredPartner(p.id)"
                                        :class="selectedPartnerId === p.id ? 'border-emerald-500 bg-emerald-50 ring-1 ring-emerald-300' : 'border-gray-200 hover:border-emerald-300'"
                                        class="flex items-center gap-3 text-left p-3 rounded-xl border transition-all">
                                        <img :src="p.photoUrl || 'https://ui-avatars.com/api/?name=' + encodeURIComponent(p.displayName || p.name || 'Pro') + '&background=10b981&color=fff'"
                                            alt="Pro" class="w-11 h-11 rounded-full object-cover bg-emerald-100 shrink-0" />
                                        <div class="min-w-0 flex-1">
                                            <p class="font-semibold text-gray-900 text-sm truncate" x-text="p.displayName || p.name || 'Professional'"></p>
                                            <div class="flex items-center gap-1 text-xs text-amber-500">
                                                <span x-text="(p.avgRating ? '★ ' + (p.avgRating.toFixed ? p.avgRating.toFixed(1) : p.avgRating) : 'New')"></span>
                                                <span class="text-gray-400" x-show="p.ratingCount" x-text="'(' + p.ratingCount + ')'"></span>
                                                <span x-show="p.online" class="ml-1 inline-flex items-center gap-1 text-emerald-600"><span class="w-1.5 h-1.5 rounded-full bg-emerald-500"></span>Online</span>
                                            </div>
                                        </div>
                                        <span x-show="selectedPartnerId === p.id" class="text-emerald-600 shrink-0">
                                            <svg class="w-5 h-5" fill="currentColor" viewBox="0 0 20 20"><path fill-rule="evenodd" d="M16.707 5.293a1 1 0 010 1.414l-8 8a1 1 0 01-1.414 0l-4-4a1 1 0 011.414-1.414L8 12.586l7.293-7.293a1 1 0 011.414 0z" clip-rule="evenodd" /></svg>
                                        </span>
                                    </button>
                                </template>
                            </div>

                            <button type="button" x-show="selectedPartnerId" @click="selectPreferredPartner(selectedPartnerId)"
                                class="mt-3 text-xs text-gray-500 hover:text-gray-700 underline">Clear selection</button>
                        </div>

                        <div class="bg-white rounded-xl shadow-lg p-6 mb-8 border border-gray-200">
                            <h3 class="text-xl font-bold text-gray-900 mb-4">Service Schedule</h3>
                            <div>
                                <label for="checkout-date" class="block text-sm font-medium text-gray-700 mb-2">Service
                                    Date <span class="text-red-500">*</span> (Tomorrow onwards)</label>
                                <input id="checkout-date" type="date" x-model="checkoutForm.date" :min="getMinDate()" @change="fetchAvailableSlots()"
                                    :class="{'border-red-500 border-2': showCheckoutValidationErrors && isCheckoutFieldEmpty('date')}"
                                    class="w-full p-3 rounded-lg bg-white border border-gray-300 text-gray-900 focus:outline-none focus:ring-2 focus:ring-emerald-500"
                                    required aria-required="true">
                                <p class="text-gray-600 text-xs mt-2">Select any date from tomorrow onwards (next month
                                    dates visible in calendar)</p>
                            </div>

                        </div>
                    </div>
                    <div>
                        <div class="bg-white rounded-xl shadow-lg p-6 border border-gray-200">
                            <h3 class="text-xl font-bold text-gray-900 mb-4">Order Summary</h3>

                            <!-- ADDITIVE: Price-lock reassurance badge (pure UI) -->
                            <div class="flex items-center gap-2 mb-4 px-3 py-2 rounded-lg bg-emerald-50 border border-emerald-200">
                                <svg class="w-5 h-5 text-emerald-600 flex-shrink-0" fill="none" stroke="currentColor" viewBox="0 0 24 24"><path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M12 15v2m-6 4h12a2 2 0 002-2v-6a2 2 0 00-2-2H6a2 2 0 00-2 2v6a2 2 0 002 2zm10-10V7a4 4 0 00-8 0v4h8z"/></svg>
                                <div class="leading-tight">
                                    <p class="text-sm font-semibold text-emerald-800" x-text="priceLockInfo().title">Price locked — no hidden fees</p>
                                    <p class="text-xs text-emerald-700" x-text="priceLockInfo().sub">The total shown is exactly what you pay.</p>
                                </div>
                            </div>

                            <template x-for="[id, item] in Object.entries(cart)" :key="id">
                                <div class="mb-2">
                                    <p class="text-gray-600" x-text="item.name + ' x ' + item.quantity"></p>
                                    <p class="font-semibold text-gray-900">&#8377;<span
                                            x-text="item.price * item.quantity"></span></p>
                                </div>
                            </template>

                            <div class="space-y-2 mb-4 border-t border-gray-300 mt-4 pt-4">
                                <div class="flex justify-between items-center">
                                    <span class="text-gray-500">Subtotal</span>
                                    <span class="text-gray-900">₹<span
                                            x-text="formatPrice(getSubtotal())"></span></span>
                                </div>

                                <div class="flex justify-between items-center">
                                    <span class="text-gray-500">Service Fee (5%)</span>
                                    <span class="text-gray-900">₹<span
                                            x-text="formatPrice(getServiceFee())"></span></span>
                                </div>

                                <div class="flex justify-between items-center">
                                    <span class="text-gray-500">GST (18%)</span>
                                    <span class="text-gray-900">₹<span x-text="formatPrice(getTax())"></span></span>
                                </div>
                            </div>

                            <!-- P1-6: coupon -->
                            <div class="mt-4 p-3 rounded-lg border border-emerald-200 bg-emerald-50">
                                <div class="flex flex-col sm:flex-row items-stretch sm:items-center gap-2">
                                    <input type="text" x-model="couponCode" placeholder="Have a coupon?"
                                        :disabled="appliedCoupon"
                                        class="flex-1 px-3 py-2 rounded-md border border-gray-300 text-sm focus:ring-2 focus:ring-emerald-400 outline-none bg-white" />
                                    <button x-show="!appliedCoupon" @click="applyCoupon()"
                                        :disabled="couponLoading"
                                        class="w-full sm:w-auto px-4 py-2 rounded-md bg-emerald-600 text-white text-sm font-semibold hover:bg-emerald-700 disabled:opacity-50">Apply</button>
                                    <button x-show="appliedCoupon" @click="removeCoupon()"
                                        class="w-full sm:w-auto px-4 py-2 rounded-md text-red-600 text-sm font-semibold">Remove</button>
                                </div>
                                <p x-show="couponError" class="text-xs text-red-500 mt-1" x-text="couponError"></p>
                                <p x-show="appliedCoupon" class="text-xs text-emerald-700 mt-1">
                                    Coupon <span x-text="appliedCoupon"></span> applied — you save ₹<span x-text="couponDiscount"></span>
                                </p>
                            </div>

                            <div
                                class="border-t border-gray-300 pt-4 flex justify-between items-center font-bold text-lg">
                                <span class="text-gray-900">Total</span>
                                <span class="text-emerald-400">₹<span x-text="formatPrice(getTotal())"></span></span>
                            </div>
                            <div x-show="appliedCoupon"
                                class="flex justify-between items-center text-emerald-700 font-semibold mt-1">
                                <span>Payable</span>
                                <span>₹<span x-text="formatPrice(getPayableTotal())"></span></span>
                            </div>

                            <!-- P1-6: offers banner -->
                            <div x-show="offers.length > 0" class="mt-4 space-y-2">
                                <template x-for="o in offers" :key="o.id">
                                    <div class="p-3 rounded-lg bg-gradient-to-r from-emerald-500 to-emerald-600 text-white text-sm">
                                        <p class="font-semibold" x-text="o.title || 'Special Offer'"></p>
                                        <p x-show="o.description" x-text="o.description"></p>
                                    </div>
                                </template>
                            </div>

                            <!-- Payment method (Razorpay-style selector, key-gated) -->
                            <div class="mt-6 border-t border-gray-300 pt-4">
                                <h4 class="font-semibold text-gray-900 mb-3">Payment Method</h4>
                                <template x-for="m in getPaymentMethods()" :key="m.id">
                                    <label class="flex items-center gap-3 p-3 mb-2 rounded-lg border cursor-pointer transition-colors"
                                           :class="checkoutForm.paymentMethod === m.id ? 'border-emerald-500 bg-emerald-50' : 'border-gray-200'">
                                        <input type="radio" class="accent-emerald-600 shrink-0" :value="m.id"
                                               x-model="checkoutForm.paymentMethod" />
                                        <svg class="icon w-5 h-5 shrink-0 text-emerald-600" aria-hidden="true"><use :href="m.icon"/></svg>
                                        <span class="flex-1 min-w-0">
                                            <span class="block text-sm font-semibold text-gray-800" x-text="m.label"></span>
                                            <span class="block text-xs text-gray-500" x-text="m.desc"></span>
                                        </span>
                                        <span x-show="m.badge" class="shrink-0 text-[10px] font-bold uppercase tracking-wide text-gray-500 bg-gray-100 rounded px-2 py-0.5" x-text="m.badge"></span>
                                    </label>
                                </template>
                                <p x-show="!window.RAZORPAY_KEY" class="flex items-start gap-1.5 text-xs text-gray-500 mt-1">
                                    Online payments activate once Razorpay is enabled. Until then, orders are Cash After Service.
                                </p>
                            </div>

                            <!-- Phase 3 C9: Recurring booking creation -->
                            <div class="mt-6 border-t border-gray-300 pt-4">
                                <label class="flex items-start gap-3 cursor-pointer">
                                    <input type="checkbox" class="accent-emerald-600 mt-1 shrink-0" x-model="recurringEnabled" />
                                    <span class="min-w-0">
                                        <span class="block text-sm font-semibold text-gray-800">Make this a recurring booking</span>
                                        <span class="block text-xs text-gray-500">Automatically schedule this service on a repeating plan (Cash After Service).</span>
                                    </span>
                                </label>
                                <div x-show="recurringEnabled" class="mt-3" x-cloak>
                                    <label class="block text-sm font-medium text-gray-700 mb-2">Frequency</label>
                                    <div class="grid grid-cols-3 gap-2">
                                        <button type="button" @click="recurringFrequency = 'weekly'"
                                            :class="recurringFrequency === 'weekly' ? 'border-emerald-500 bg-emerald-50 text-emerald-700' : 'border-gray-300 text-gray-700'"
                                            class="text-xs font-medium p-2.5 rounded-lg border transition-colors">Weekly</button>
                                        <button type="button" @click="recurringFrequency = 'biweekly'"
                                            :class="recurringFrequency === 'biweekly' ? 'border-emerald-500 bg-emerald-50 text-emerald-700' : 'border-gray-300 text-gray-700'"
                                            class="text-xs font-medium p-2.5 rounded-lg border transition-colors">Every 2 weeks</button>
                                        <button type="button" @click="recurringFrequency = 'monthly'"
                                            :class="recurringFrequency === 'monthly' ? 'border-emerald-500 bg-emerald-50 text-emerald-700' : 'border-gray-300 text-gray-700'"
                                            class="text-xs font-medium p-2.5 rounded-lg border transition-colors">Monthly</button>
                                    </div>
                                    <p x-show="!recurringFrequency" class="text-xs text-amber-600 mt-2 font-medium">Choose a frequency to enable the recurring plan.</p>
                                    <p x-show="!user.uid" class="text-xs text-amber-600 mt-2 font-medium">Sign in to create a recurring plan (guests can't set one up).</p>
                                </div>
                            </div>

                            <button @click="placeOrder" :disabled="loading.placeOrder || (!user.uid && !guestEmailOtp.verified)"
                                class="w-full mt-6 bg-emerald-600 text-white py-3 rounded-lg font-bold hover:bg-emerald-700 transition-colors disabled:opacity-50 disabled:cursor-not-allowed">
                                <span x-show="loading.placeOrder">Placing Order...</span>
                                <span x-show="!loading.placeOrder && (user.uid || guestEmailOtp.verified)">Place Order</span>
                                <span x-show="!loading.placeOrder && !user.uid && !guestEmailOtp.verified">Verify Email to Place Order</span>
                            </button>
                        </div>
                    </div>
                </div>
            </div>
        </div>


        <div x-show="currentPage === 'profile'" class="min-h-full py-16 pb-20 md:pb-0 md:py-10 pt-0 px-3 sm:px-4">
            <div class="w-full max-w-2xl mx-auto">
                <h1 class="text-2xl md:text-3xl font-bold text-gray-900 mb-6">My Profile</h1>

                <!-- Guest Mode Message -->
                <div x-show="!hasAuth()" class="bg-blue-50 border border-blue-600 rounded-2xl shadow-lg p-8 mb-6">
                    <div class="text-center">
                        <div class="text-5xl mb-4"><svg class="icon"><use href="#i-user"/></svg></div>
                        <h2 class="text-2xl font-bold text-gray-900 mb-3">Sign In to Save Your Profile</h2>
                        <p class="text-gray-600 mb-6">Create an account to save your details, addresses, and order
                            history in one place.</p>
                        <button @click="navigateTo('login')"
                            class="bg-gradient-to-r from-emerald-500 to-emerald-600 hover:from-emerald-600 hover:to-emerald-700 text-white font-bold py-3 px-8 rounded-lg transition-all transform hover:scale-105">
                            Sign In / Create Account
                        </button>
                    </div>
                </div>

                <!-- Profile Tabs (show only if logged in) -->
                <div x-show="hasAuth()" class="mb-6 flex gap-2 border-b border-gray-300">
                    <button @click="profileTab = 'overview'"
                        :class="profileTab === 'overview' ? 'text-emerald-600 border-b-2 border-emerald-600' : 'text-gray-600 hover:text-gray-900'"
                        class="px-4 py-3 font-semibold transition-colors">
                        Profile Overview
                    </button>
                    <button @click="profileTab = 'addresses'"
                        :class="profileTab === 'addresses' ? 'text-emerald-600 border-b-2 border-emerald-600' : 'text-gray-600 hover:text-gray-900'"
                        class="px-4 py-3 font-semibold transition-colors">
                        <svg class="icon icon--sm"><use href="#i-location"/></svg> My Addresses
                    </button>
                </div>

                <!-- Loading State -->
                <div x-show="loading.orders && hasAuth()" class="text-center py-8">
                    <div
                        class="animate-spin rounded-full h-12 w-12 border-4 border-gray-300 border-t-emerald-500 mx-auto mb-4">
                    </div>
                    <p class="text-gray-600">Loading your profile...</p>
                </div>

                <!-- ===== PROFILE OVERVIEW TAB ===== -->
                <div x-show="profileTab === 'overview' && hasAuth()">
                    <!-- Profile Card (Only show if logged in) -->
                    <div x-show="hasAuth() && !loading.orders"
                        class="bg-white/95 backdrop-blur-md rounded-2xl shadow-xl p-8 space-y-8 border border-gray-300/20">
                        <div
                            class="h-16 w-16 bg-gradient-to-br from-emerald-500 to-emerald-600 rounded-full flex items-center justify-center">
                            <span class="text-2xl font-bold text-white" x-text="getUserInitial()"></span>
                        </div>
                        <div>
                            <h2 class="text-2xl font-bold text-gray-900" x-text="savedProfile.name || user.name || 'User'">
                            </h2>
                            <p class="text-gray-500 text-sm" x-text="'Member since ' + (new Date().getFullYear())"></p>
                        </div>
                    </div>

                    <div class="space-y-4">
                        <!-- Name -->
                        <div>
                            <label for="profile-name" class="block text-sm font-medium text-gray-600 mb-2">Full
                                Name</label>
                            <input id="profile-name" type="text" name="profile-name" autocomplete="name"
                                x-model="savedProfile.name" placeholder="Enter your full name"
                                class="w-full px-4 py-2.5 rounded-lg bg-gray-100 border border-gray-300 text-gray-900 placeholder-gray-400 focus:outline-none focus:ring-2 focus:ring-emerald-500 focus:border-transparent">
                        </div>

                        <!-- Email (Read-only) -->
                        <div>
                            <label for="profile-email" class="block text-sm font-medium text-gray-600 mb-2">Email
                                Address</label>
                            <input id="profile-email" type="email" :value="savedProfile.email || user.email"
                                placeholder="Email"
                                class="w-full px-4 py-2.5 rounded-lg bg-gray-200 border border-gray-300 text-gray-600 cursor-not-allowed"
                                disabled>
                            <p class="text-xs text-gray-500 mt-1">✓ Fetched from your orders</p>
                        </div>

                        <!-- Phone -->
                        <div>
                            <label for="profile-phone" class="block text-sm font-medium text-gray-600 mb-2">Phone
                                Number</label>
                            <input id="profile-phone" type="tel" name="tel" autocomplete="tel" inputmode="numeric"
                                x-model="savedProfile.phone" placeholder="Enter phone number"
                                class="w-full px-4 py-2.5 rounded-lg bg-gray-100 border border-gray-300 text-gray-900 placeholder-gray-400 focus:outline-none focus:ring-2 focus:ring-emerald-500 focus:border-transparent">
                        </div>
                    </div>

                    <!-- Address Selection (if multiple addresses) -->
                    <div>
                        <!-- Show header only if have addresses -->
                        <h2 class="text-2xl font-bold text-gray-900 mb-4" x-show="userAddresses && userAddresses.length > 0"><svg class="icon icon--sm"><use href="#i-location"/></svg>
                            Your Addresses</h2>

                        <!-- Address Count Badge (only for multiple addresses) -->
                        <div x-show="userAddresses && userAddresses.length > 1"
                            class="mb-4 bg-emerald-500/20 border border-emerald-500/30 rounded-lg p-3">
                            <p class="text-emerald-300 text-sm font-medium">You have <span x-text="userAddresses.length"></span>
                                saved addresses. Select or edit:</p>
                        </div>

                        <!-- Address Selector (only show if multiple) -->
                        <div x-show="userAddresses && userAddresses.length > 1" class="mb-6">
                            <label for="address-selector" class="block text-sm font-medium text-gray-600 mb-2">Select
                                Address</label>
                            <select id="address-selector" x-model.number="selectedAddressIndex" @change="loadSelectedAddress()"
                                class="w-full px-4 py-2.5 rounded-lg bg-gray-100 border border-gray-300 text-gray-900 focus:outline-none focus:ring-2 focus:ring-emerald-500">
                                <template x-for="(addr, index) in userAddresses" :key="index">
                                    <option :value="index"
                                        x-text="`${addr.city}, ${addr.state} (${addr.houseNumber || 'No House #'})`"></option>
                                </template>
                            </select>
                        </div>

                        <!-- Single Address Info (when only 1 address) -->
                        <div x-show="userAddresses && userAddresses.length === 1"
                            class="mb-4 bg-emerald-500/10 border border-emerald-500/30 rounded-lg p-3">
                            <p class="text-emerald-300 text-sm font-medium"><svg class="icon icon--sm"><use href="#i-location"/></svg> <span x-text="userAddresses[0]?.city"></span>,
                                <span x-text="userAddresses[0]?.state"></span>
                            </p>
                            <p class="text-gray-500 text-xs mt-1">Saved from your order history</p>
                        </div>

                        <!-- Current Address Details -->
                        <div class="bg-gray-100/80 rounded-lg p-6 border border-gray-300 space-y-4 mb-6">
                            <!-- House Number -->
                            <div>
                                <label for="profile-house-no" class="block text-sm font-medium text-gray-600 mb-2">House Number
                                    / Building Name</label>
                                <input id="profile-house-no" type="text" name="house-number" x-model="savedProfile.houseNumber"
                                    placeholder="e.g., 123, Apt 4B, Villa Heights"
                                    class="w-full px-4 py-2.5 rounded-lg bg-gray-100 border border-gray-300 text-gray-900 placeholder-gray-400 focus:outline-none focus:ring-2 focus:ring-emerald-500 focus:border-transparent">
                            </div>

                            <!-- Street Address -->
                            <div>
                                <label for="profile-address" class="block text-sm font-medium text-gray-600 mb-2">Street
                                    Address / Area</label>
                                <textarea id="profile-address" name="address-line2" x-model="savedProfile.address" rows="2"
                                    placeholder="e.g., 456 Main Street, Sector 5"
                                    class="w-full px-4 py-2.5 rounded-lg bg-gray-100 border border-gray-300 text-gray-900 placeholder-gray-400 focus:outline-none focus:ring-2 focus:ring-emerald-500 focus:border-transparent"></textarea>
                            </div>

                            <!-- City, State, Pincode -->
                            <div class="grid grid-cols-1 md:grid-cols-3 gap-4">
                                <div>
                                    <label for="profile-city" class="block text-sm font-medium text-gray-600 mb-2">City</label>
                                    <input id="profile-city" type="text" name="address-level2" x-model="savedProfile.city"
                                        placeholder="e.g., New Delhi"
                                        class="w-full px-4 py-2.5 rounded-lg bg-gray-100 border border-gray-300 text-gray-900 placeholder-gray-400 focus:outline-none focus:ring-2 focus:ring-emerald-500 focus:border-transparent">
                                </div>
                                <div>
                                    <label for="profile-state"
                                        class="block text-sm font-medium text-gray-600 mb-2">State</label>
                                    <input id="profile-state" type="text" name="address-level1" x-model="savedProfile.state"
                                        placeholder="e.g., Delhi"
                                        class="w-full px-4 py-2.5 rounded-lg bg-gray-100 border border-gray-300 text-gray-900 placeholder-gray-400 focus:outline-none focus:ring-2 focus:ring-emerald-500 focus:border-transparent">
                                </div>
                                <div>
                                    <label for="profile-pincode"
                                        class="block text-sm font-medium text-gray-600 mb-2">Pincode</label>
                                    <input id="profile-pincode" type="text" name="postal-code" inputmode="numeric"
                                        x-model="savedProfile.pincode" placeholder="e.g., 110001"
                                        class="w-full px-4 py-2.5 rounded-lg bg-gray-100 border border-gray-300 text-gray-900 placeholder-gray-400 focus:outline-none focus:ring-2 focus:ring-emerald-500 focus:border-transparent">
                                </div>
                            </div>
                        </div>
                    </div>

                    <!-- No Addresses Yet -->
                    <div x-show="!userAddresses || userAddresses.length === 0"
                        class="bg-gray-100/60 border border-dashed border-gray-300 rounded-lg p-6 text-center">
                        <p class="text-gray-500 mb-3 flex items-center gap-1"><svg class="icon icon--sm"><use href="#i-inbox"/></svg> No addresses saved yet</p>
                        <p class="text-gray-400 text-sm">Complete an order to save addresses, or fill in your address below:
                        </p>
                    </div>

                    <!-- Save Button -->
                    <div class="flex gap-3 pt-6 border-t border-gray-200">
                        <button @click="updateUserProfile()"
                            class="flex-1 bg-gradient-to-r from-emerald-500 to-emerald-600 hover:from-emerald-600 hover:to-emerald-700 text-white font-semibold py-3 px-4 rounded-lg transition-all transform hover:scale-105 flex items-center justify-center gap-2">
                            <svg class="w-5 h-5" fill="none" stroke="currentColor" viewBox="0 0 24 24">
                                <path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M5 13l4 4L19 7"></path>
                            </svg>
                            Save Profile
                        </button>
                        <button @click="navigateTo('products')"
                            class="flex-1 bg-gray-100 hover:bg-gray-200 text-gray-800 font-semibold py-3 px-4 rounded-lg transition-colors">
                            Back to Services
                        </button>
                    </div>
                </div>

                <!-- ===== MY ADDRESSES TAB ===== -->
                <div x-show="profileTab === 'addresses' && hasAuth()">
                    <div class="space-y-6">
                        <!-- No Addresses Message -->
                        <div x-show="savedAddresses.length === 0 && !showAddressForm"
                            class="bg-gray-50 border-2 border-dashed border-gray-300 rounded-lg p-8 text-center">
                            <p class="text-6xl mb-4"><svg class="icon"><use href="#i-inbox"/></svg></p>
                            <h3 class="text-xl font-semibold text-gray-700 mb-2">No Saved Addresses</h3>
                            <p class="text-gray-600 mb-6">Add your first address to make checkout faster and easier.</p>
                            <button @click="showAddressForm = true"
                                class="bg-emerald-500 hover:bg-emerald-600 text-white font-semibold py-2 px-6 rounded-lg transition-colors inline-flex items-center gap-2">
                                <svg class="w-5 h-5" fill="none" stroke="currentColor" viewBox="0 0 24 24">
                                    <path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M12 4v16m8-8H4"></path>
                                </svg>
                                Add Address
                            </button>
                        </div>

                        <!-- Saved Addresses List -->
                        <div x-show="savedAddresses.length > 0" class="space-y-4">
                            <div class="flex justify-between items-center mb-4">
                                <h3 class="text-xl font-bold text-gray-900">Saved Addresses (<span x-text="savedAddresses.length"></span>)</h3>
                                <button @click="showAddressForm = !showAddressForm"
                                    class="bg-emerald-500 hover:bg-emerald-600 text-white font-semibold py-2 px-4 rounded-lg transition-colors inline-flex items-center gap-2 text-sm">
                                    <svg class="w-4 h-4" fill="none" stroke="currentColor" viewBox="0 0 24 24">
                                        <path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M12 4v16m8-8H4"></path>
                                    </svg>
                                    Add New Address
                                </button>
                            </div>

                            <!-- Address Cards -->
                            <template x-for="address in savedAddresses" :key="address.id">
                                <div class="bg-white border border-gray-300 rounded-lg p-5 hover:shadow-lg transition-shadow">
                                    <div class="flex justify-between items-start mb-3">
                                        <div>
                                            <h4 class="font-semibold text-gray-900 text-lg">
                                                <span x-text="address.label || 'Home'"></span>
                                            </h4>
                                            <p class="text-sm text-gray-500 mt-1">
                                                <span x-text="address.houseNumber"></span> • 
                                                <span x-text="address.city + ', ' + address.state"></span>
                                            </p>
                                        </div>
                                        <span class="bg-emerald-100 text-emerald-700 text-xs font-semibold px-2.5 py-1 rounded-full">
                                            <svg class="icon icon--sm"><use href="#i-location"/></svg> Saved
                                        </span>
                                    </div>

                                    <p class="text-gray-600 text-sm mb-3">
                                        <span x-text="address.address"></span><br/>
                                        <span x-text="address.pincode"></span>
                                    </p>

                                    <div class="flex gap-3 pt-3 border-t border-gray-200">
                                        <button @click="startEditAddress(address)"
                                            class="flex-1 bg-blue-50 hover:bg-blue-100 text-blue-700 font-semibold py-2 rounded-lg transition-colors text-sm">
                                            <svg class="icon icon--sm"><use href="#i-pencil"/></svg> Edit
                                        </button>
                                        <button @click="deleteAddress(address.id)"
                                            class="flex-1 bg-red-50 hover:bg-red-100 text-red-700 font-semibold py-2 rounded-lg transition-colors text-sm">
                                            <svg class="icon icon--sm"><use href="#i-trash"/></svg> Delete
                                        </button>
                                    </div>
                                </div>
                            </template>
                        </div>

                        <!-- Add/Edit Address Form -->
                        <div x-show="showAddressForm" class="bg-gray-50 border border-gray-300 rounded-lg p-6">
                            <h3 class="text-xl font-bold text-gray-900 mb-4">
                                <span x-show="!editingAddressId" x-text="'➕ Add New Address'"></span>
                                <span x-show="editingAddressId" x-text="'Edit Address'"></span>
                            </h3>

                            <div class="space-y-4">
                                <!-- Label -->
                                <div>
                                    <label for="addr-label" class="block text-sm font-medium text-gray-600 mb-2">
                                        Address Label (e.g., Home, Work)
                                    </label>
                                    <input id="addr-label" type="text" x-model="newAddressForm.label" placeholder="Home"
                                        class="w-full px-4 py-2.5 rounded-lg bg-white border border-gray-300 text-gray-900 placeholder-gray-400 focus:outline-none focus:ring-2 focus:ring-emerald-500">
                                </div>

                                <!-- House Number -->
                                <div>
                                    <label for="addr-house" class="block text-sm font-medium text-gray-600 mb-2">
                                        House Number / Building Name <span class="text-red-500">*</span>
                                    </label>
                                    <input id="addr-house" type="text" x-model="newAddressForm.houseNumber" placeholder="e.g., 123, Apt 4B"
                                        class="w-full px-4 py-2.5 rounded-lg bg-white border border-gray-300 text-gray-900 placeholder-gray-400 focus:outline-none focus:ring-2 focus:ring-emerald-500">
                                </div>

                                <!-- Street Address -->
                                <div>
                                    <label for="addr-street" class="block text-sm font-medium text-gray-600 mb-2">
                                        Street Address / Area <span class="text-red-500">*</span>
                                    </label>
                                    <input id="addr-street" type="text" x-model="newAddressForm.address" placeholder="e.g., Main Street, Sector 5"
                                        class="w-full px-4 py-2.5 rounded-lg bg-white border border-gray-300 text-gray-900 placeholder-gray-400 focus:outline-none focus:ring-2 focus:ring-emerald-500">
                                </div>

                                <!-- City, State, Pincode -->
                                <div class="grid grid-cols-1 md:grid-cols-3 gap-4">
                                    <div>
                                        <label for="addr-city" class="block text-sm font-medium text-gray-600 mb-2">
                                            City <span class="text-red-500">*</span>
                                        </label>
                                        <input id="addr-city" type="text" x-model="newAddressForm.city" placeholder="e.g., New Delhi"
                                            class="w-full px-4 py-2.5 rounded-lg bg-white border border-gray-300 text-gray-900 placeholder-gray-400 focus:outline-none focus:ring-2 focus:ring-emerald-500">
                                    </div>
                                    <div>
                                        <label for="addr-state" class="block text-sm font-medium text-gray-600 mb-2">
                                            State <span class="text-red-500">*</span>
                                        </label>
                                        <input id="addr-state" type="text" x-model="newAddressForm.state" placeholder="e.g., Delhi"
                                            class="w-full px-4 py-2.5 rounded-lg bg-white border border-gray-300 text-gray-900 placeholder-gray-400 focus:outline-none focus:ring-2 focus:ring-emerald-500">
                                    </div>
                                    <div>
                                        <label for="addr-pincode" class="block text-sm font-medium text-gray-600 mb-2">
                                            Pincode <span class="text-red-500">*</span>
                                        </label>
                                        <input id="addr-pincode" type="text" x-model="newAddressForm.pincode" placeholder="e.g., 110001"
                                            class="w-full px-4 py-2.5 rounded-lg bg-white border border-gray-300 text-gray-900 placeholder-gray-400 focus:outline-none focus:ring-2 focus:ring-emerald-500">
                                    </div>
                                </div>

                                <!-- Action Buttons -->
                                <div class="flex gap-3 pt-6 border-t border-gray-300">
                                    <button @click="submitAddressForm()"
                                        class="flex-1 bg-emerald-500 hover:bg-emerald-600 text-white font-semibold py-3 rounded-lg transition-colors">
                                        <span x-show="!editingAddressId" x-text="'Add Address'"></span>
                                        <span x-show="editingAddressId" x-text="'Update Address'"></span>
                                    </button>
                                    <button @click="cancelEditAddress()"
                                        class="flex-1 bg-gray-300 hover:bg-gray-400 text-gray-900 font-semibold py-3 rounded-lg transition-colors">
                                        <svg class="icon icon--sm"><use href="#i-x"/></svg> Cancel
                                    </button>
                                </div>
                            </div>
                        </div>
                    </div>
                </div>
        </div>
        </div>

        <div x-show="currentPage === 'orders'"
            class="min-h-screen bg-gray-50 pb-20 md:pb-0 pt-0 px-3 sm:px-4">
            <div class="w-full space-y-3">
                <!-- Header -->
                <div>
                    <h1 class="text-lg md:text-xl font-bold text-gray-900">My Orders</h1>
                    <p class="text-xs md:text-sm text-gray-500 mt-1">View and manage your service orders</p>
                </div>
                <!-- Skeleton Loading Cards -->
                <div x-show="loading.orders" class="space-y-3 sm:space-y-4">
                    <template x-for="i in [1,2,3]" :key="i">
                        <div class="border border-gray-200 rounded-lg p-6 bg-white">
                            <div class="flex justify-between items-center mb-4">
                                <div class="space-y-2">
                                    <div class="skeleton h-4 w-36"></div>
                                    <div class="skeleton h-3 w-24"></div>
                                </div>
                                <div class="skeleton h-6 w-20 rounded-full"></div>
                            </div>
                            <div class="space-y-2 mb-4">
                                <div class="skeleton h-3 w-48"></div>
                                <div class="skeleton h-3 w-36"></div>
                            </div>
                            <div class="flex justify-between items-center pt-3 border-t border-gray-100">
                                <div class="skeleton h-3 w-28"></div>
                                <div class="skeleton h-5 w-16"></div>
                            </div>
                        </div>
                    </template>
                </div>
                <div x-show="!loading.orders && _authStateChecked && (!orders || orders.length === 0)"
                    class="text-center py-12 sm:py-16 md:py-20">
                    <div class="text-6xl mb-4">&#128196;</div>
                    <h2 class="text-xl sm:text-2xl md:text-3xl font-semibold text-gray-500 mb-3 sm:mb-4 md:mb-6">You
                        have no past orders</h2>
                    <p class="text-sm sm:text-base text-gray-400 mb-6 sm:mb-8">Start booking cleaning services now!</p>
                    <button @click="navigateTo('products')"
                        class="bg-emerald-600 hover:bg-emerald-700 text-white px-5 sm:px-6 md:px-8 py-2.5 sm:py-3 md:py-3 rounded-lg font-semibold transition-all duration-200 text-sm sm:text-base md:text-lg shadow-lg hover:shadow-xl">
                        Start a New Order
                    </button>
                </div>
                <!-- Orders List -->
                <div x-show="orders && orders.length > 0" class="space-y-3 sm:space-y-4">
                    <!-- Summary Line -->
                    <div class="bg-emerald-50 border border-emerald-200 rounded-lg p-3 text-emerald-800 text-sm">
                        <span x-text="'Showing ' + getOrdersLoadedCount() + ' of ' + getTotalOrdersCount() + ' orders'"></span>
                    </div>

                    <div class="space-y-3 sm:space-y-4 md:space-y-5 lg:space-y-6">
                        <template x-for="order in getPaginatedOrders()" :key="order.id">
                            <div class="border border-gray-300 rounded-lg p-4 md:p-6 bg-white cursor-pointer hover:border-emerald-400 hover:shadow-lg transition-all"
                                @click="openOrderDetails(order)">
                                <div class="flex justify-between items-start mb-4">
                                    <div>
                                        <h2 class="text-lg font-semibold text-gray-900">Order #<span
                                                x-text="order.id.substring(0, 8)"></span></h2>
                                        <p class="text-sm text-gray-500" x-text="order.date"></p>
                                    </div>
                                    <span :class="getOrderStatusClass(order.status)"
                                        class="px-3 py-1 rounded-full text-xs font-semibold whitespace-nowrap" x-text="order.status"></span>
                                </div>

                                <!-- Inline Items Preview (limit to 3 for space) -->
                                <div class="mb-4">
                                    <h3 class="text-xs font-semibold text-gray-500 mb-2 uppercase">Items Ordered</h3>
                                    <ul class="space-y-1.5">
                                        <template x-for="(item, idx) in order.items.slice(0, 3)" :key="item.id">
                                            <li class="flex items-center justify-between text-sm">
                                                <div class="flex items-center space-x-2">
                                                    <span class="text-lg" x-text="item.icon"></span>
                                                    <span class="text-gray-700" x-text="item.name"></span>
                                                    <span class="text-gray-500 text-xs" x-text="'(x' + item.quantity + ')'"></span>
                                                </div>
                                                <span class="font-semibold text-gray-900">₹<span
                                                        x-text="formatPrice(item.price * item.quantity)"></span></span>
                                            </li>
                                        </template>
                                        <template x-if="order.items.length > 3">
                                            <li class="text-xs text-gray-500 italic">
                                                + <span x-text="order.items.length - 3"></span> more items...
                                            </li>
                                        </template>
                                    </ul>
                                </div>

                                <div class="border-t border-gray-200 pt-4 flex flex-col gap-3 sm:flex-row sm:justify-between sm:items-center sm:gap-2">
                                    <div>
                                        <span class="text-xs text-gray-500">Total Amount:</span>
                                        <p class="text-xl font-bold text-emerald-600">₹<span
                                                x-text="formatPrice(order.total)"></span></p>
                                    </div>
                                    <div class="flex flex-wrap gap-2 w-full sm:w-auto sm:flex-nowrap">
                                        <button @click.stop="bookAgain(order); showMessage('Added to cart!', 'success')"
                                            class="flex-1 sm:flex-none bg-emerald-500 hover:bg-emerald-600 text-white px-3 py-2 sm:px-4 sm:py-2.5 rounded-lg text-sm font-semibold transition-colors">
                                            <svg class="icon icon--sm"><use href="#i-package"/></svg> Book Again
                                        </button>
                                        <button @click.stop="openOrderDetails(order)"
                                            class="flex-1 sm:flex-none bg-gray-200 hover:bg-gray-300 text-gray-800 px-3 py-2 sm:px-4 sm:py-2.5 rounded-lg text-sm font-semibold transition-colors">
                                            Details →
                                        </button>
                                    </div>
                                </div>
                            </div>
                        </template>

                    <!-- Show More Button -->
                    <div x-show="hasMoreOrders()" class="flex justify-center pt-4 md:pt-6">
                        <button @click="loadMoreOrders()" :disabled="isLoadingMoreOrders()"
                            class="bg-emerald-600 hover:bg-emerald-700 disabled:opacity-50 disabled:cursor-not-allowed text-white px-6 md:px-8 py-3 md:py-3 rounded-lg font-semibold transition-all duration-200 text-sm md:text-base shadow-lg hover:shadow-xl">
                            <span x-show="!isLoadingMoreOrders()" x-text="'Load More Orders (' + getOrdersLoadedCount() + ' of ' + getTotalOrdersCount() + ')'"></span>
                            <span x-show="isLoadingMoreOrders()" class="flex items-center justify-center">
                                <svg class="animate-spin -ml-1 mr-2 h-4 w-4 text-white"
                                    xmlns="http://www.w3.org/2000/svg" fill="none" viewBox="0 0 24 24">
                                    <circle class="opacity-25" cx="12" cy="12" r="10" stroke="currentColor"
                                        stroke-width="4"></circle>
                                    <path class="opacity-75" fill="currentColor"
                                        d="M4 12a8 8 0 018-8V0C5.373 0 0 5.373 0 12h4zm2 5.291A7.962 7.962 0 014 12H0c0 3.042 1.135 5.824 3 7.938l3-2.647z">
                                    </path>
                                </svg>
                                Loading...
                            </span>
                        </button>
                    </div>
                </div>
            </div>
        </div>
        </div>

        <!-- ============ SUBSCRIPTIONS VIEW (P1-4) ============ -->
        <div x-show="currentPage === 'subscriptions'"
            class="min-h-full pb-20 md:pb-0 pt-0 px-3 sm:px-4">
            <div class="w-full space-y-3 max-w-3xl mx-auto">
                <!-- Header -->
                <div>
                    <h1 class="text-lg md:text-xl font-bold text-gray-900">My Subscriptions</h1>
                    <p class="text-xs md:text-sm text-gray-500 mt-1">Manage your recurring cleaning plans &amp; memberships</p>
                </div>

                <!-- Skeleton -->
                <div x-show="loading.subscriptions" class="space-y-3 sm:space-y-4">
                    <template x-for="i in [1,2]" :key="i">
                        <div class="border border-gray-200 rounded-2xl p-5 bg-white">
                            <div class="flex justify-between items-center mb-4">
                                <div class="skeleton h-4 w-40"></div>
                                <div class="skeleton h-6 w-20 rounded-full"></div>
                            </div>
                            <div class="space-y-2">
                                <div class="skeleton h-3 w-48"></div>
                                <div class="skeleton h-3 w-32"></div>
                            </div>
                        </div>
                    </template>
                </div>

                <!-- Signed-out state -->
                <div x-show="!loading.subscriptions && !hasAuth()" class="text-center py-16">
                    <div class="text-6xl mb-4">&#128274;</div>
                    <h2 class="text-xl md:text-2xl font-semibold text-gray-600 mb-2">Sign in to view subscriptions</h2>
                    <p class="text-sm text-gray-400 mb-6">Your recurring cleaning plans are tied to your account.</p>
                    <button @click="navigateTo('login')"
                        class="bg-emerald-600 hover:bg-emerald-700 text-white px-6 py-3 rounded-lg font-semibold transition-all duration-200 shadow-lg hover:shadow-xl">
                        Sign In
                    </button>
                </div>

                <!-- Empty state -->
                <div x-show="!loading.subscriptions && hasAuth() && subscriptions.length === 0"
                    class="text-center py-16">
                    <div class="text-6xl mb-4">&#128260;</div>
                    <h2 class="text-xl md:text-2xl font-semibold text-gray-600 mb-2">No subscriptions yet</h2>
                    <p class="text-sm text-gray-400 mb-6">Recurring plans and memberships you subscribe to will appear here.</p>
                    <button @click="navigateTo('membership')"
                        class="bg-emerald-600 hover:bg-emerald-700 text-white px-6 py-3 rounded-lg font-semibold transition-all duration-200 shadow-lg hover:shadow-xl">
                        Explore Plans
                    </button>
                </div>

                <!-- Subscriptions List -->
                <div x-show="!loading.subscriptions && subscriptions.length > 0" class="space-y-3 sm:space-y-4">
                    <template x-for="sub in subscriptions" :key="sub.firebaseKey">
                        <div class="border border-gray-300 rounded-2xl p-5 bg-white shadow-sm">
                            <div class="flex justify-between items-start gap-3 mb-4">
                                <h2 class="text-lg font-semibold text-gray-900" x-text="subTitle(sub)"></h2>
                                <span
                                    :class="(sub.status === 'active') ? 'bg-emerald-100 text-emerald-700' : (sub.status === 'cancelled' ? 'bg-red-100 text-red-700' : 'bg-amber-100 text-amber-700')"
                                    class="px-3 py-1 rounded-full text-xs font-semibold uppercase whitespace-nowrap"
                                    x-text="sub.status || 'active'"></span>
                            </div>
                            <div class="space-y-2 text-sm">
                                <div class="flex justify-between">
                                    <span class="text-gray-500">Frequency</span>
                                    <span class="font-medium text-gray-800" x-text="subFrequencyLabel(sub)"></span>
                                </div>
                                <div class="flex justify-between" x-show="subNextDate(sub)">
                                    <span class="text-gray-500"
                                        x-text="(sub.status === 'active') ? 'Next booking' : 'Was scheduled'"></span>
                                    <span class="font-medium text-gray-800" x-text="subNextDate(sub)"></span>
                                </div>
                                <div class="flex justify-between" x-show="subAmount(sub) > 0">
                                    <span class="text-gray-500">Amount</span>
                                    <span class="font-medium text-gray-800">&#8377;<span x-text="subAmount(sub)"></span></span>
                                </div>
                            </div>
                            <div class="mt-4" x-show="sub.status === 'active'">
                                <button
                                    @click="cancelSubTarget = sub; showCancelSubModal = true"
                                    :disabled="cancellingSubId === sub.firebaseKey"
                                    class="w-full border border-red-500 text-red-600 hover:bg-red-50 disabled:opacity-50 disabled:cursor-not-allowed px-4 py-2.5 rounded-lg text-sm font-semibold transition-colors">
                                    <span x-show="cancellingSubId !== sub.firebaseKey">Cancel subscription</span>
                                    <span x-show="cancellingSubId === sub.firebaseKey">Cancelling…</span>
                                </button>
                            </div>
                        </div>
                    </template>
                </div>
            </div>
        </div>

        <!-- Phase 3 C10: In-app Support / Help -->
        <div x-show="currentPage === 'support'" class="min-h-full pb-20 md:pb-0 pt-0 px-3 sm:px-4">
            <div class="w-full space-y-4 max-w-3xl mx-auto">
                <!-- Header -->
                <div class="flex items-center justify-between">
                    <div>
                        <h1 class="text-lg md:text-xl font-bold text-gray-900">Support</h1>
                        <p class="text-xs md:text-sm text-gray-500 mt-1">Chat with our team about your bookings &amp; account</p>
                    </div>
                    <button x-show="!selectedTicket && supportView !== 'new'" @click="supportView = 'new'"
                        class="bg-emerald-600 hover:bg-emerald-700 text-white px-4 py-2.5 rounded-lg text-sm font-semibold transition-all shadow">
                        + New ticket
                    </button>
                    <button x-show="selectedTicket || supportView === 'new'" @click="selectedTicket = null; supportView = 'list'"
                        class="text-sm font-medium text-emerald-600 hover:underline">← Back to tickets</button>
                </div>

                <!-- Signed-out state -->
                <div x-show="!hasAuth() && !selectedTicket && supportView !== 'new'" class="text-center py-16">
                    <div class="text-6xl mb-4">&#128172;</div>
                    <h2 class="text-xl md:text-2xl font-semibold text-gray-600 mb-2">Sign in to view support</h2>
                    <p class="text-sm text-gray-400 mb-6">Your tickets are tied to your account.</p>
                    <button @click="navigateTo('login')"
                        class="bg-emerald-600 hover:bg-emerald-700 text-white px-6 py-3 rounded-lg font-semibold transition-all shadow-lg">
                        Sign In
                    </button>
                </div>

                <!-- New ticket form -->
                <div x-show="supportView === 'new' && !selectedTicket"
                    class="bg-white rounded-2xl shadow-lg border border-gray-200 p-5 space-y-4">
                    <h2 class="text-base font-bold text-gray-900">New support ticket</h2>
                    <div>
                        <label class="block text-sm font-medium text-gray-700 mb-1">Subject <span class="text-red-500">*</span></label>
                        <input type="text" x-model="ticketForm.subject" placeholder="e.g. Issue with my last booking"
                            class="w-full p-3 rounded-lg border border-gray-300 bg-white text-gray-900 focus:outline-none focus:ring-2 focus:ring-emerald-500">
                    </div>
                    <div>
                        <label class="block text-sm font-medium text-gray-700 mb-1">Order ID <span class="text-gray-400">(optional)</span></label>
                        <input type="text" x-model="ticketForm.orderId" placeholder="e.g. CP1234567890"
                            class="w-full p-3 rounded-lg border border-gray-300 bg-white text-gray-900 focus:outline-none focus:ring-2 focus:ring-emerald-500">
                    </div>
                    <div>
                        <label class="block text-sm font-medium text-gray-700 mb-1">Message <span class="text-red-500">*</span></label>
                        <textarea x-model="ticketForm.message" rows="4" placeholder="Describe your issue…"
                            class="w-full p-3 rounded-lg border border-gray-300 bg-white text-gray-900 focus:outline-none focus:ring-2 focus:ring-emerald-500"></textarea>
                    </div>
                    <div class="flex gap-3">
                        <button @click="createSupportTicket()" :disabled="supportLoading"
                            class="bg-emerald-600 hover:bg-emerald-700 text-white px-6 py-2.5 rounded-lg text-sm font-semibold disabled:opacity-50 transition-colors">
                            <span x-show="!supportLoading">Submit ticket</span>
                            <span x-show="supportLoading">Submitting…</span>
                        </button>
                        <button @click="supportView = 'list'" :disabled="supportLoading"
                            class="px-4 py-2.5 rounded-lg text-sm font-medium text-gray-600 hover:bg-gray-100 transition-colors">Cancel</button>
                    </div>
                </div>

                <!-- Ticket list -->
                <div x-show="!selectedTicket && supportView === 'list' && hasAuth()"
                    class="space-y-3">
                    <p x-show="supportLoading" class="text-center text-gray-400 text-sm py-8">Loading your tickets…</p>
                    <template x-for="t in tickets" :key="t.firebaseKey">
                        <div @click="openTicketDetail(t)"
                            class="bg-white rounded-2xl shadow-sm border border-gray-200 p-4 cursor-pointer hover:border-emerald-300 transition-colors">
                            <div class="flex justify-between items-start gap-3">
                                <div class="min-w-0">
                                    <p class="font-semibold text-gray-900 truncate" x-text="t.subject || 'Support ticket'"></p>
                                    <p class="text-xs text-gray-400 mt-0.5"
                                        x-text="t.createdAt && t.createdAt.toDate ? t.createdAt.toDate().toLocaleDateString('en-IN') : ''"></p>
                                </div>
                                <span class="px-2.5 py-1 rounded-full text-xs font-semibold uppercase whitespace-nowrap"
                                    :class="(t.status === 'open' || t.status === 'replied') ? 'bg-amber-100 text-amber-700' : (t.status === 'closed' ? 'bg-gray-100 text-gray-600' : 'bg-emerald-100 text-emerald-700')"
                                    x-text="t.status || 'open'"></span>
                            </div>
                            <p class="text-sm text-gray-500 mt-2 line-clamp-2"
                                x-text="(t.messages && t.messages.length) ? (t.messages[t.messages.length-1].text) : ''"></p>
                        </div>
                    </template>
                    <div x-show="!supportLoading && tickets.length === 0" class="text-center py-16">
                        <div class="text-6xl mb-4">&#128587;</div>
                        <h2 class="text-xl md:text-2xl font-semibold text-gray-600 mb-2">No tickets yet</h2>
                        <p class="text-sm text-gray-400 mb-6">Need help? Open a ticket and we'll get back to you.</p>
                        <button @click="supportView = 'new'"
                            class="bg-emerald-600 hover:bg-emerald-700 text-white px-6 py-3 rounded-lg font-semibold transition-all shadow-lg">
                            New ticket
                        </button>
                    </div>
                </div>

                <!-- Ticket detail / thread -->
                <div x-show="selectedTicket" x-cloak
                    class="bg-white rounded-2xl shadow-lg border border-gray-200 p-5 space-y-4">
                    <div class="border-b border-gray-100 pb-3">
                        <h2 class="text-base font-bold text-gray-900" x-text="(selectedTicket && selectedTicket.subject) || 'Support ticket'"></h2>
                        <span class="text-xs text-gray-400"
                            x-text="selectedTicket && selectedTicket.createdAt && selectedTicket.createdAt.toDate ? selectedTicket.createdAt.toDate().toLocaleString('en-IN') : ''"></span>
                    </div>

                    <div class="space-y-3 max-h-80 overflow-y-auto">
                        <p x-show="ticketDetailLoading" class="text-center text-gray-400 text-sm py-4">Loading…</p>
                        <template x-for="(m, idx) in (selectedTicket && selectedTicket.messages || [])" :key="idx">
                            <div class="flex" :class="m.from === 'customer' ? 'justify-end' : 'justify-start'">
                                <div class="max-w-[80%] px-3 py-2 rounded-2xl text-sm"
                                    :class="m.from === 'customer' ? 'bg-emerald-600 text-white' : 'bg-gray-100 text-gray-800'"
                                    x-text="m.text"></div>
                            </div>
                        </template>
                        <p x-show="!ticketDetailLoading && (!selectedTicket || !selectedTicket.messages || selectedTicket.messages.length === 0)"
                            class="text-center text-gray-400 text-sm py-4">No messages yet.</p>
                    </div>

                    <div x-show="selectedTicket && selectedTicket.status !== 'closed'" class="flex gap-2 items-end border-t border-gray-100 pt-3">
                        <textarea x-model="ticketReply" rows="2" placeholder="Type a reply…"
                            class="flex-1 p-3 rounded-lg border border-gray-300 bg-white text-gray-900 focus:outline-none focus:ring-2 focus:ring-emerald-500"></textarea>
                        <button @click="replyToTicket()" :disabled="ticketDetailLoading"
                            class="bg-emerald-600 hover:bg-emerald-700 text-white px-5 py-3 rounded-lg text-sm font-semibold disabled:opacity-50 transition-colors">
                            <span x-show="!ticketDetailLoading">Send</span>
                            <span x-show="ticketDetailLoading">…</span>
                        </button>
                    </div>
                    <p x-show="selectedTicket && selectedTicket.status === 'closed'" class="text-sm text-gray-400 text-center border-t border-gray-100 pt-3">
                        This ticket is closed. Open a new ticket if you need more help.
                    </p>
                </div>
            </div>
        </div>

        <!-- Cancel Subscription Confirmation Modal (P1-4) -->
        <div x-show="showCancelSubModal" x-transition:enter="transition ease-out duration-200"
            x-transition:enter-start="opacity-0" x-transition:enter-end="opacity-100"
            x-transition:leave="transition ease-in duration-150" x-transition:leave-start="opacity-100"
            x-transition:leave-end="opacity-0" x-cloak
            class="fixed inset-0 bg-black/50 backdrop-blur-sm flex items-center justify-center z-50 p-4"
            @click.away="showCancelSubModal = false">
            <div class="bg-white rounded-2xl shadow-2xl border border-gray-200 w-full max-w-md p-6 max-h-[90vh] overflow-y-auto">
                <h2 class="text-xl font-bold text-gray-900 mb-2">Cancel subscription?</h2>
                <p class="text-sm text-gray-500 mb-6">This stops future recurring bookings for this plan. You can subscribe again anytime.</p>
                <div class="flex gap-3 justify-end">
                    <button @click="showCancelSubModal = false"
                        class="bg-gray-200 hover:bg-gray-300 text-gray-800 px-4 py-2.5 rounded-lg text-sm font-semibold transition-colors">
                        Keep plan
                    </button>
                    <button @click="cancelSubscription(cancelSubTarget)"
                        class="bg-red-600 hover:bg-red-700 text-white px-4 py-2.5 rounded-lg text-sm font-semibold transition-colors">
                        Cancel plan
                    </button>
                </div>
            </div>
        </div>


        <!-- Order Details Modal -->
        <div x-show="showOrderDetails" x-transition:enter="transition ease-out duration-200"
            x-transition:enter-start="opacity-0" x-transition:enter-end="opacity-100"
            x-transition:leave="transition ease-in duration-150" x-transition:leave-start="opacity-100"
            x-transition:leave-end="opacity-0"
            class="fixed inset-0 bg-black/50 backdrop-blur-sm flex items-end md:items-center justify-center z-50 p-0 md:p-4"
            @click.away="closeOrderDetails()">
            <div x-show="showOrderDetails" x-transition:enter="transition ease-out duration-300"
                x-transition:enter-start="opacity-0 translate-y-full md:scale-95"
                x-transition:enter-end="opacity-100 translate-y-0 md:scale-100"
                x-transition:leave="transition ease-in duration-200"
                x-transition:leave-start="opacity-100 translate-y-0 md:scale-100"
                x-transition:leave-end="opacity-0 translate-y-full md:scale-95"
                class="modal-content bg-white rounded-t-2xl md:rounded-xl shadow-2xl border border-gray-200 w-full md:w-full md:max-w-2xl md:max-h-96 overflow-y-auto md:p-8 p-4 pb-6 md:pb-8">

                <div
                    class="flex justify-between items-center mb-4 md:mb-6 sticky top-0 bg-white -m-4 md:m-0 md:mb-6 p-4 md:p-0 md:bg-transparent z-10">
                    <h2 class="text-xl md:text-2xl font-bold text-gray-900">Order Details</h2>
                    <button @click="closeOrderDetails()"
                        class="text-gray-500 hover:text-gray-800 p-1 hover:bg-gray-100 rounded-lg md:hover:bg-transparent transition-colors">
                        <svg class="w-5 h-5 md:w-6 md:h-6" fill="none" stroke="currentColor" viewBox="0 0 24 24">
                            <path stroke-linecap="round" stroke-linejoin="round" stroke-width="2"
                                d="M6 18L18 6M6 6l12 12"></path>
                        </svg>
                    </button>
                    <button @click="openChat(selectedOrder)"
                        class="inline-flex items-center gap-1.5 text-sm font-medium text-emerald-600 hover:underline mr-2">
                        <svg class="w-5 h-5" fill="none" stroke="currentColor" viewBox="0 0 24 24">
                            <path stroke-linecap="round" stroke-linejoin="round" stroke-width="1.8"
                                d="M8 12h.01M12 12h.01M16 12h.01M21 12c0 4.418-4.03 8-9 8a9.8 9.8 0 01-4-1l-4 1 1-3.5A7.5 7.5 0 013 12c0-4.418 4.03-8 9-8s9 3.582 9 8z"></path>
                        </svg>
                        Chat
                    </button>
                    <button @click="downloadInvoice(selectedOrder)"
                        class="inline-flex items-center gap-1.5 text-sm font-medium text-emerald-600 hover:underline mr-2">
                        <svg class="w-5 h-5" fill="none" stroke="currentColor" viewBox="0 0 24 24">
                            <path stroke-linecap="round" stroke-linejoin="round" stroke-width="1.8"
                                d="M12 10v6m0 0l-3-3m3 3l3-3M7 3h10a2 2 0 012 2v14a2 2 0 01-2 2H7a2 2 0 01-2-2V5a2 2 0 012-2z"></path>
                        </svg>
                        Invoice
                    </button>
                    <button @click="printInvoice(selectedOrder)"
                        class="inline-flex items-center gap-1.5 text-sm font-medium text-emerald-600 hover:underline mr-2">
                        <svg class="w-5 h-5" fill="none" stroke="currentColor" viewBox="0 0 24 24">
                            <path stroke-linecap="round" stroke-linejoin="round" stroke-width="1.8"
                                d="M17 17h2a2 2 0 002-2v-4a2 2 0 00-2-2H5a2 2 0 00-2 2v4a2 2 0 002 2h2m2 4h6a1 1 0 001-1v-4a1 1 0 00-1-1H9a1 1 0 00-1 1v4a1 1 0 001 1zm8-12V5a2 2 0 00-2-2H7a2 2 0 00-2 2v4h14z"></path>
                        </svg>
                        Print
                    </button>
                </div>

                <template x-if="selectedOrder">
                    <div class="space-y-4 md:space-y-6">
                        <!-- Order Header Info -->
                        <div class="bg-gray-100 rounded-lg p-3 md:p-4 space-y-2 md:space-y-3">
                            <div class="flex justify-between items-start gap-2">
                                <div>
                                    <p class="text-xs md:text-sm text-gray-500">Order ID</p>
                                    <p class="text-base md:text-lg font-semibold text-gray-900"
                                        x-text="selectedOrder.id"></p>
                                </div>
                                <span :class="getOrderStatusClass(selectedOrder.status)"
                                    class="px-2 md:px-3 py-1 rounded-full text-xs font-semibold whitespace-nowrap"
                                    x-text="selectedOrder.status"></span>
                            </div>

                            <!-- Completion OTP (NEW MODEL): shown to the CUSTOMER once the
                                 professional STARTS the job. The customer reads this code
                                 to the professional, who enters it in their app to complete
                                 the job. The customer no longer taps "confirm" themselves. -->
                            <template x-if="selectedOrder && selectedOrder.awaitingCompletionConfirm && (selectedOrder.status === 'In Progress' || selectedOrder.startedAt) && selectedOrder.completionOtp && isOrderOwner()">
                                <div class="mt-4 rounded-xl border border-emerald-200 bg-emerald-50 p-4">
                                    <p class="text-sm font-semibold text-emerald-800">Your completion OTP</p>
                                    <p class="mt-1 text-sm text-emerald-700">
                                        Share this code with your professional when the work is
                                        finished. They enter it to mark the job complete.
                                    </p>
                                    <div class="mt-3 flex items-center justify-center">
                                        <span class="font-mono text-3xl font-extrabold tracking-[0.4em] text-emerald-900"
                                            x-text="selectedOrder.completionOtp"></span>
                                    </div>
                                    <p class="mt-2 text-center text-xs text-emerald-600">
                                        Do not share this code until the job is done to your satisfaction.
                                    </p>
                                </div>
                            </template>

                            <!-- Booking Date & Time -->
                            <div>
                                <p class="text-xs md:text-sm text-gray-500">Booked On</p>
                                <p class="text-sm md:text-base text-gray-800"
                                    x-text="formatBookedDateTime(selectedOrder.date || selectedOrder.createdAt)"></p>
                            </div>

                            <!-- Service Date -->
                            <div>
                                <p class="text-xs md:text-sm text-gray-500">Service Date</p>
                                <p class="text-sm md:text-base text-gray-800 font-medium"
                                    x-text="selectedOrder.serviceDate ? formatServiceDate(selectedOrder.serviceDate) : 'To be scheduled'">
                                </p>
                            </div>
                        </div>

                        <!-- Phase 1: assigned professional profile card -->
                        <div x-show="selectedOrder.assignedPartner && selectedOrderPartner"
                            class="bg-white border border-gray-200 rounded-lg p-3 md:p-4 flex items-center gap-3">
                            <template x-if="selectedOrderPartner && selectedOrderPartner.photoUrl">
                                <img :src="selectedOrderPartner.photoUrl" alt="Professional"
                                    class="w-14 h-14 rounded-full object-cover flex-shrink-0 border border-gray-200">
                            </template>
                            <template x-if="!(selectedOrderPartner && selectedOrderPartner.photoUrl)">
                                <div class="w-14 h-14 rounded-full bg-emerald-100 text-emerald-700 flex items-center justify-center text-xl font-bold flex-shrink-0"
                                    x-text="(selectedOrderPartner && selectedOrderPartner.name ? selectedOrderPartner.name : (selectedOrder.partnerName || 'P')).charAt(0).toUpperCase()"></div>
                            </template>
                            <div class="min-w-0 flex-1">
                                <p class="text-xs text-gray-500">Your Professional</p>
                                <p class="font-semibold text-gray-900 truncate"
                                    x-text="(selectedOrderPartner && selectedOrderPartner.name) || selectedOrder.partnerName || 'Assigned Professional'"></p>
                                <div class="flex items-center gap-2 text-sm text-gray-600 mt-0.5">
                                    <span x-show="selectedOrderPartner && selectedOrderPartner.avgRating > 0">
                                        ⭐ <span x-text="(selectedOrderPartner.avgRating || 0).toFixed(1)"></span>
                                        <span class="text-gray-400" x-show="selectedOrderPartner.ratingCount">(<span x-text="selectedOrderPartner.ratingCount"></span>)</span>
                                    </span>
                                    <span x-show="selectedOrderPartner && selectedOrderPartner.kycVerified"
                                        class="inline-flex items-center gap-1 text-emerald-600 text-xs font-medium">✓ Verified</span>
                                </div>
                            </div>
                        </div>

                        <!-- P1-1 / P2-2: live order tracking -->
                        <div x-show="isEnRoute(selectedOrder) || selectedOrder.professionalLocation"
                            class="bg-emerald-50 border border-emerald-200 rounded-lg p-3 md:p-4 space-y-3">
                            <div class="flex items-center gap-2">
                                <svg class="w-5 h-5 text-emerald-600" fill="none" stroke="currentColor" viewBox="0 0 24 24">
                                    <path stroke-linecap="round" stroke-linejoin="round" stroke-width="2"
                                        d="M17.657 16.657L13.414 20.9a1.998 1.998 0 01-2.827 0l-4.244-4.243a8 8 0 1111.314 0z"></path>
                                    <path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M15 11a3 3 0 11-6 0 3 3 0 016 0z"></path>
                                </svg>
                                <h3 class="font-semibold text-emerald-800">Live Tracking</h3>
                                <span x-show="isEnRoute(selectedOrder)"
                                    class="ml-auto text-xs font-bold text-white bg-emerald-600 px-2 py-0.5 rounded-full">EN ROUTE</span>
                            </div>

                            <!-- En Route banner -->
                            <template x-if="isEnRoute(selectedOrder)">
                                <div class="flex items-center gap-2 bg-emerald-600 text-white text-sm font-medium rounded-lg px-3 py-2">
                                    <svg class="w-4 h-4 animate-pulse" fill="none" stroke="currentColor" viewBox="0 0 24 24">
                                        <path stroke-linecap="round" stroke-linejoin="round" stroke-width="2"
                                            d="M13 16h-1v-4h-1m1-4h.01M21 12a9 9 0 11-18 0 9 9 0 0118 0z"></path>
                                    </svg>
                                    <span>Your professional is on the way to your location.</span>
                                </div>
                            </template>

                            <p class="text-sm text-gray-700" x-show="selectedOrder.professionalEta"
                                x-text="'Estimated arrival: ' + formatOrderEta(selectedOrder.professionalEta)"></p>

                            <template x-if="hasValidLocation()">
                                <div class="space-y-3">
                                    <!-- Tracking card: coordinates + computed distance/ETA -->
                                    <div class="grid grid-cols-1 sm:grid-cols-3 gap-2">
                                        <div class="bg-white border border-emerald-200 rounded-lg p-2">
                                            <p class="text-xs text-emerald-700 font-medium">Coordinates</p>
                                            <p class="text-sm font-semibold text-gray-900"
                                                x-text="selectedOrder.professionalLocation.latitude.toFixed(4) + ', ' + selectedOrder.professionalLocation.longitude.toFixed(4)"></p>
                                        </div>
                                        <div class="bg-white border border-emerald-200 rounded-lg p-2" x-show="trackingDistanceKm() != null">
                                            <p class="text-xs text-emerald-700 font-medium">Distance</p>
                                            <p class="text-sm font-semibold text-gray-900"
                                                x-text="trackingDistanceKm().toFixed(1) + ' km'"></p>
                                        </div>
                                        <div class="bg-white border border-emerald-200 rounded-lg p-2" x-show="trackingEtaMin() != null">
                                            <p class="text-xs text-emerald-700 font-medium">ETA</p>
                                            <p class="text-sm font-semibold text-gray-900"
                                                x-text="trackingEtaMin() + ' min (~' + (window.TRACKING_SPEED_KMH || 30) + ' km/h)'"></p>
                                        </div>
                                    </div>

                                    <!-- P2-2: embedded live map. Keyless Google Maps embed — always
                                         works WITHOUT an API key (CSP frame-src allows google.com);
                                         if window.GOOGLE_MAPS_API_KEY is set, the same embed is used. -->
                                    <div class="rounded-xl overflow-hidden border-2 border-emerald-300 shadow-sm">
                                        <iframe
                                            title="Partner live location"
                                            class="w-full"
                                            style="height: 220px; border: 0; display: block;"
                                            loading="lazy"
                                            referrerpolicy="no-referrer-when-downgrade"
                                            :src="'https://www.google.com/maps?q=' + selectedOrder.professionalLocation.latitude + ',' + selectedOrder.professionalLocation.longitude + '&z=15&output=embed'"></iframe>
                                    </div>

                                    <div class="flex flex-wrap gap-2">
                                        <a :href="'https://maps.google.com/?q=' + selectedOrder.professionalLocation.latitude + ',' + selectedOrder.professionalLocation.longitude"
                                            target="_blank" rel="noopener"
                                            class="inline-flex items-center gap-1 text-sm text-white bg-emerald-600 font-medium px-3 py-1.5 rounded-lg hover:bg-emerald-700">
                                            <svg class="w-4 h-4" fill="none" stroke="currentColor" viewBox="0 0 24 24">
                                                <path stroke-linecap="round" stroke-linejoin="round" stroke-width="2"
                                                    d="M17.657 16.657L13.414 20.9a1.998 1.998 0 01-2.827 0l-4.244-4.243a8 8 0 1111.314 0z"></path>
                                                <path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M15 11a3 3 0 11-6 0 3 3 0 016 0z"></path>
                                            </svg>
                                            Open in Google Maps
                                        </a>
                                    </div>
                                </div>
                            </template>
                            <p class="text-sm text-gray-500" x-show="!selectedOrder.professionalLocation && !isEnRoute(selectedOrder)">
                                Your professional will share live location once en route.
                            </p>
                        </div>

                        <!-- Services Booked -->
                        <div>
                            <h3 class="text-base md:text-lg font-semibold text-gray-900 mb-2 md:mb-3">Services Booked
                            </h3>
                            <div class="space-y-2">
                                <template x-for="item in selectedOrder.items" :key="item.id">
                                    <div
                                        class="flex items-center justify-between bg-gray-100 p-2 md:p-3 rounded-lg gap-2">
                                        <div class="flex items-center space-x-2 min-w-0">
                                            <span class="text-lg md:text-2xl flex-shrink-0" x-text="item.icon"></span>
                                            <div class="min-w-0">
                                                <p class="font-medium text-gray-900 text-sm md:text-base truncate"
                                                    x-text="item.name"></p>
                                                <p class="text-xs text-gray-500" x-show="item.quantity > 1">Qty: <span
                                                        x-text="item.quantity"></span></p>
                                            </div>
                                        </div>
                                        <p
                                            class="font-semibold text-gray-900 text-sm md:text-base whitespace-nowrap flex-shrink-0">
                                            ₹<span x-text="formatPrice(item.price * item.quantity)"></span></p>
                                    </div>
                                </template>
                            </div>
                        </div>

                        <!-- Delivery Address (if available) -->
                        <template x-if="selectedOrder?.customerInfo?.address">
                            <div>
                                <h3 class="text-base md:text-lg font-semibold text-gray-900 mb-2 md:mb-3">Delivery
                                    Address</h3>
                                <div
                                    class="bg-gray-100 rounded-lg p-3 md:p-4 text-gray-800 text-sm md:text-base space-y-1">
                                    <p class="font-medium" x-text="selectedOrder?.customerInfo?.name"></p>
                                    <p x-show="selectedOrder?.customerInfo?.houseNumber"
                                        x-text="selectedOrder?.customerInfo?.houseNumber"></p>
                                    <p x-text="selectedOrder?.customerInfo?.address"></p>
                                    <p
                                        x-text="(selectedOrder?.customerInfo?.city || '') + ', ' + (selectedOrder?.customerInfo?.state || '') + ' ' + (selectedOrder?.customerInfo?.pincode || '')">
                                    </p>
                                    <p class="mt-2 text-gray-500 flex items-center gap-1"><svg class="icon icon--sm"><use href="#i-phone"/></svg> <span
                                            x-text="selectedOrder?.customerInfo?.phone" class="break-all"></span></p>
                                    <p class="mt-2 text-gray-500 flex items-center gap-1"><svg class="icon icon--sm"><use href="#i-mail"/></svg> <span
                                            x-text="selectedOrder?.customerInfo?.email" class="break-all"></span></p>
                                </div>
                            </div>
                        </template>

                        <!-- Price Breakdown -->
                        <div class="bg-gray-100 rounded-lg p-3 md:p-4 space-y-1 md:space-y-2">
                            <div class="flex justify-between text-gray-600 text-sm md:text-base">
                                <span>Subtotal</span>
                                <span>₹<span x-text="formatPrice(selectedOrder.subtotal)"></span></span>
                            </div>
                            <div class="flex justify-between text-gray-600 text-sm md:text-base">
                                <span>Service Fee</span>
                                <span>₹<span x-text="formatPrice(selectedOrder.serviceFee)"></span></span>
                            </div>
                            <div class="flex justify-between text-gray-600 text-sm md:text-base">
                                <span>GST (18%)</span>
                                <span>₹<span x-text="formatPrice(selectedOrder.tax)"></span></span>
                            </div>
                            <div
                                class="border-t border-gray-300 pt-2 mt-2 flex justify-between font-bold text-gray-900 text-base md:text-lg">
                                <span>Total</span>
                                <span>₹<span x-text="formatPrice(selectedOrder.total)"></span></span>
                            </div>
                        </div>
                    </div>
                </template>

                <!-- Fallback when selectedOrder is null -->
                <template x-if="!selectedOrder">
                    <div class="text-center py-12 text-gray-500">
                        <div
                            class="animate-spin rounded-full h-10 w-10 border-4 border-gray-300 border-t-emerald-500 mx-auto mb-4">
                        </div>
                        <p>Loading order details...</p>
                    </div>
                </template>
            </div>
        </div>
        </div>


        <div x-show="currentPage === 'contact'" class="min-h-full pb-20 md:pb-0 pt-0 px-3 sm:px-4">
            <div class="w-full space-y-3">
                <h1 class="text-lg md:text-xl font-bold text-center text-gray-900">Contact Us</h1>

                <div class="grid grid-cols-1 lg:grid-cols-2 gap-2.5 md:gap-3">
                    <!-- Contact Form -->
                    <div class="bg-white rounded-2xl shadow-xl p-3 md:p-3.5 border border-gray-200">
                        <h2 class="text-base md:text-lg font-bold text-gray-900 mb-2">Send us a Message</h2>
                        <form @submit.prevent="submitContactForm()" class="space-y-2">
                            <div>
                                <input type="text" name="name" autocomplete="name" id="contact-name"
                                    x-model="contactForm.name" placeholder="Full Name *"
                                    class="w-full p-2 rounded-lg border border-gray-300 bg-gray-100 text-gray-900 placeholder-gray-400 focus:outline-none focus:ring-2 focus:ring-emerald-500 focus:border-emerald-500 text-sm"
                                    required>
                            </div>

                            <div>
                                <input type="tel" name="tel" autocomplete="tel" inputmode="numeric" id="contact-phone"
                                    x-model="contactForm.phone" placeholder="Phone Number *"
                                    class="w-full p-2 rounded-lg border border-gray-300 bg-gray-100 text-gray-900 placeholder-gray-400 focus:outline-none focus:ring-2 focus:ring-emerald-500 focus:border-emerald-500 text-sm"
                                    required>
                            </div>

                            <div>
                                <button type="submit" :disabled="loading.contactForm"
                                    class="w-full bg-emerald-500 hover:bg-emerald-600 text-white font-bold py-3 px-6 rounded-lg transition duration-200 flex items-center justify-center space-x-2 disabled:opacity-50 disabled:cursor-not-allowed">
                                    <div x-show="loading.contactForm"
                                        class="animate-spin rounded-full h-5 w-5 border-b-2 border-white"></div>
                                    <span x-show="!loading.contactForm">Send Message</span>
                                    <span x-show="loading.contactForm">Sending...</span>
                                </button>
                            </div>
                        </form>
                    </div>

                    <!-- Contact Information -->
                    <div class="bg-white rounded-2xl shadow-xl p-8 border border-gray-200">
                        <h2 class="text-2xl font-bold mb-6 text-gray-900">Get in Touch</h2>

                        <div class="space-y-6">
                            <div class="flex items-start space-x-4">
                                <div class="bg-gray-100 p-3 rounded-lg">
                                    <svg class="w-6 h-6 text-gray-600" fill="none" stroke="currentColor"
                                        viewBox="0 0 24 24">
                                        <path fill-rule="evenodd"
                                            d="M17.657 16.657L13.414 20.9a1.998 1.998 0 01-2.827 0l-4.244-4.243a8 8 0 1111.314 0zM10 11a2 2 0 100-4 2 2 0 000 4z"
                                            clip-rule="evenodd" />
                                    </svg>
                                </div>
                                <div>
                                    <h3 class="font-semibold mb-1 text-gray-900">Address</h3>
                                    <p class="text-gray-600">B747b, Block B, Sushant Lok 1, Near Vipul Square, Sector 43, Ashok Road, Sushant Lok, Gurgaon-122009, Haryana, India</p>
                                </div>
                            </div>

                            <div class="flex items-start space-x-4">
                                <div class="bg-gray-100 p-3 rounded-lg">
                                    <svg class="w-6 h-6 text-gray-600" fill="none" stroke="currentColor"
                                        viewBox="0 0 24 24">
                                        <path stroke-linecap="round" stroke-linejoin="round" stroke-width="2"
                                            d="M3 5a2 2 0 012-2h3.28a1 1 0 01.948.684l1.498 4.493a1 1 0 01-.502 1.21l-2.257 1.13a11.042 11.042 0 005.516 5.516l1.13-2.257a1 1 0 011.21-.502l4.493 1.498a1 1 0 01.684.949V19a2 2 0 01-2 2h-1C9.716 21 3 14.284 3 6V5z">
                                        </path>
                                    </svg>
                                </div>
                                <div>
                                    <h3 class="font-semibold mb-1 text-gray-900">Phone</h3>
                                    <p class="text-gray-600">+91 9267905943</p>
                                </div>
                            </div>

                            <div class="flex items-start space-x-4">
                                <div class="bg-gray-100 p-3 rounded-lg">
                                    <svg class="w-6 h-6 text-gray-600" fill="none" stroke="currentColor"
                                        viewBox="0 0 24 24">
                                        <path stroke-linecap="round" stroke-linejoin="round" stroke-width="2"
                                            d="M3 8l7.89 5.26a2 2 0 002.22 0L21 8M5 19h14a2 2 0 002-2V7a2 2 0 00-2-2H5a2 2 0 00-2 2v10a2 2 0 002 2z">
                                        </path>
                                    </svg>
                                </div>
                                <div>
                                    <h3 class="font-semibold mb-1 text-gray-900">Email</h3>
                                    <p class="text-gray-600"><a href="mailto:sachindeepcleaning@gmail.com" class="hover:underline">sachindeepcleaning@gmail.com</a></p>
                                </div>
                            </div>

                            <div class="flex items-start space-x-4">
                                <div class="bg-gray-100 p-3 rounded-lg">
                                    <svg class="w-6 h-6 text-gray-600" fill="none" stroke="currentColor"
                                        viewBox="0 0 24 24">
                                        <path stroke-linecap="round" stroke-linejoin="round" stroke-width="2"
                                            d="M12 8v4l3 3m6-3a9 9 0 11-18 0 9 9 0 0118 0z"></path>
                                    </svg>
                                </div>
                                <div>
                                    <h3 class="font-semibold mb-1 text-gray-900">Business Hours</h3>
                                    <p class="text-gray-600">Open 24 hours, 7 days a week</p>
                                </div>
                            </div>
                        </div>

                        <div class="mt-8 pt-6 border-t border-emerald-400">
                            <h3 class="font-semibold mb-3">Quick Contact</h3>
                            <p class="text-gray-500 mb-4">Reach us directly via WhatsApp or phone</p>

                            <div class="flex gap-3 mb-6">
                                <button @click="navigateTo('products')"
                                    class="flex-1 bg-gradient-to-r from-emerald-500 to-emerald-600 hover:from-emerald-600 hover:to-emerald-700 text-white font-semibold py-3 px-4 rounded-lg transition-all flex items-center justify-center gap-2">
                                    <svg class="w-5 h-5" fill="none" stroke="currentColor" viewBox="0 0 24 24">
                                        <path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M3 3h2l.4 2M7 13h10l4-8H5.4m1.6 8L6 21h12M9 19a2 2 0 100 4 2 2 0 000-4zM20 19a2 2 0 100 4 2 2 0 000-4z" />
                                    </svg>
                                    Book a Service
                                </button>
                                <a href="tel:+919267905943"
                                    class="flex-1 bg-gradient-to-r from-blue-500 to-blue-600 hover:from-blue-600 hover:to-blue-700 text-white font-semibold py-3 px-4 rounded-lg transition-all flex items-center justify-center gap-2">
                                    <svg class="w-5 h-5" fill="none" stroke="currentColor" viewBox="0 0 24 24">
                                        <path stroke-linecap="round" stroke-linejoin="round" stroke-width="2"
                                            d="M3 5a2 2 0 012-2h3.28a1 1 0 01.948.684l1.498 4.493a1 1 0 01-.502 1.21l-2.257 1.13a11.042 11.042 0 005.516 5.516l1.13-2.257a1 1 0 011.21-.502l4.493 1.498a1 1 0 01.684.949V19a2 2 0 01-2 2h-1C9.716 21 3 14.284 3 6V5z">
                                        </path>
                                    </svg>
                                    Call
                                </a>
                            </div>

                            <div class="mt-6 pt-6 border-t border-gray-200">
                                <p class="text-gray-500 text-sm mb-3">Important Links:</p>
                                <div class="flex flex-wrap text-sm" style="column-gap: 2.5rem; row-gap: 1.25rem;">
                                    <a href="/about.html"
                                        class="text-emerald-400 hover:text-emerald-300 hover:underline">About Us</a>
                                    <a href="/contact.html"
                                        class="text-emerald-400 hover:text-emerald-300 hover:underline">Contact</a>
                                    <a href="/privacy-policy.html"
                                        class="text-emerald-400 hover:text-emerald-300 hover:underline">Privacy Policy</a>
                                    <a href="/terms-of-service.html"
                                        class="text-emerald-400 hover:text-emerald-300 hover:underline">Terms &amp; Conditions</a>
                                    <a href="/refund-policy.html"
                                        class="text-emerald-400 hover:text-emerald-300 hover:underline">Refund Policy</a>
                                    <a href="/disclaimer.html"
                                        class="text-emerald-400 hover:text-emerald-300 hover:underline">Disclaimer</a>
                                    <a href="/account-deletion.html"
                                        class="text-emerald-400 hover:text-emerald-300 hover:underline">Account Deletion</a>
                                </div>
                            </div>

                            <div class="mt-6 pt-6 border-t border-gray-200">
                                <p class="text-gray-500 text-sm mb-3">Follow Us:</p>
                                <div class="flex flex-wrap gap-4 text-sm">
                                    <a href="https://www.facebook.com/profile.php?id=61577737535478" target="_blank" rel="noopener"
                                        class="text-emerald-400 hover:text-emerald-300 hover:underline">Facebook</a>
                                    <a href="https://www.instagram.com/cleaning_service_in_gurgaon" target="_blank" rel="noopener"
                                        class="text-emerald-400 hover:text-emerald-300 hover:underline">Instagram</a>
                                    <a href="https://x.com/sachindeepclean" target="_blank" rel="noopener"
                                        class="text-emerald-400 hover:text-emerald-300 hover:underline">Twitter / X</a>
                                    <a href="https://wa.me/919267905943" target="_blank" rel="noopener"
                                        class="text-emerald-400 hover:text-emerald-300 hover:underline">WhatsApp</a>
                                </div>
                            </div>

                            <div class="mt-6 pt-6 border-t border-gray-200 text-center">
                                <p class="text-gray-500 text-xs">&copy; 2020–2026 Sachin Deep Cleaning. All rights reserved.</p>
                            </div>
                        </div>
                    </div>
                </div>
            </div>
        </div>

        <!-- ============ ABOUT (P1.4) ============ -->
        <div x-show="currentPage === 'about'" class="min-h-full pb-20 md:pb-0 pt-0 px-3 sm:px-4">
            <div class="w-full max-w-3xl mx-auto space-y-4">

                <!-- Hero -->
                <div class="bg-white rounded-2xl shadow-xl p-6 md:p-8 border border-gray-200 text-center">
                    <div class="mx-auto mb-4 w-14 h-14 rounded-2xl flex items-center justify-center"
                        style="background: linear-gradient(135deg, var(--sage-dk), var(--sage)); box-shadow: 0 6px 20px var(--sage-glow);">
                        <svg class="w-7 h-7 text-white" fill="none" stroke="currentColor" viewBox="0 0 24 24">
                            <path stroke-linecap="round" stroke-linejoin="round" stroke-width="1.8"
                                d="M12 2c.4 3.8 2.2 5.6 6 6-3.8.4-5.6 2.2-6 6-.4-3.8-2.2-5.6-6-6 3.8-.4 5.6-2.2 6-6z"></path>
                        </svg>
                    </div>
                    <h1 class="text-2xl md:text-3xl font-bold text-gray-900">About Sachin Deep Cleaning</h1>
                    <p class="text-gray-600 mt-2">Trusted home & office deep-cleaning services — trained professionals,
                        transparent pricing, and a satisfaction promise in every visit.</p>
                </div>

                <!-- Our Story -->
                <div class="bg-white rounded-2xl shadow-xl p-6 md:p-8 border border-gray-200">
                    <h2 class="text-lg md:text-xl font-bold text-gray-900 mb-2 flex items-center gap-2">
                        <svg class="w-5 h-5 text-emerald-600" fill="none" stroke="currentColor" viewBox="0 0 24 24">
                            <path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M13 16h-1v-4h-1m1-4h.01M21 12a9 9 0 11-18 0 9 9 0 0118 0z"></path>
                        </svg>
                        Our Story
                    </h2>
                    <p class="text-gray-600 leading-relaxed">Sachin Deep Cleaning was started to make professional-grade
                        cleaning simple, reliable, and affordable. From sofa and kitchen deep-cleans to full home
                        makeovers, our vetted team brings eco-friendly products and a checklist-driven process to every
                        job — so your space feels genuinely fresh, not just superficially tidy.</p>
                </div>

                <!-- Why choose us -->
                <div class="bg-white rounded-2xl shadow-xl p-6 md:p-8 border border-gray-200">
                    <h2 class="text-lg md:text-xl font-bold text-gray-900 mb-4">Why Customers Choose Us</h2>
                    <div class="grid grid-cols-1 sm:grid-cols-2 gap-3">
                        <div class="flex items-start gap-3 rounded-xl bg-emerald-50 border border-emerald-200 p-3">
                            <svg class="w-6 h-6 text-emerald-600 flex-shrink-0" fill="none" stroke="currentColor" viewBox="0 0 24 24">
                                <path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M9 12l2 2 4-4m6 2a9 9 0 11-18 0 9 9 0 0118 0z"></path>
                            </svg>
                            <div><p class="font-semibold text-gray-900">Trained Professionals</p>
                                <p class="text-sm text-gray-600">Background-checked & regularly trained staff.</p></div>
                        </div>
                        <div class="flex items-start gap-3 rounded-xl bg-emerald-50 border border-emerald-200 p-3">
                            <svg class="w-6 h-6 text-emerald-600 flex-shrink-0" fill="none" stroke="currentColor" viewBox="0 0 24 24">
                                <path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M12 8c-1.657 0-3 .895-3 2s1.343 2 3 2 3 .895 3 2-1.343 2-3 2m0-8c1.11 0 2.08.402 2.599 1M12 8V7m0 1v8m0 0c-1.11 0-2.08-.402-2.599-1"></path>
                            </svg>
                            <div><p class="font-semibold text-gray-900">Transparent Pricing</p>
                                <p class="text-sm text-gray-600">Upfront quotes, no hidden charges.</p></div>
                        </div>
                        <div class="flex items-start gap-3 rounded-xl bg-emerald-50 border border-emerald-200 p-3">
                            <svg class="w-6 h-6 text-emerald-600 flex-shrink-0" fill="none" stroke="currentColor" viewBox="0 0 24 24">
                                <path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M5 13l4 4L19 7"></path>
                            </svg>
                            <div><p class="font-semibold text-gray-900">Satisfaction Promise</p>
                                <p class="text-sm text-gray-600">We re-clean if you're not happy.</p></div>
                        </div>
                        <div class="flex items-start gap-3 rounded-xl bg-emerald-50 border border-emerald-200 p-3">
                            <svg class="w-6 h-6 text-emerald-600 flex-shrink-0" fill="none" stroke="currentColor" viewBox="0 0 24 24">
                                <path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M12 8v4l3 3m6-3a9 9 0 11-18 0 9 9 0 0118 0z"></path>
                            </svg>
                            <div><p class="font-semibold text-gray-900">Live Tracking</p>
                                <p class="text-sm text-gray-600">Follow your pro in real time on the app.</p></div>
                        </div>
                    </div>
                </div>

                <!-- Coverage + CTA -->
                <div class="bg-white rounded-2xl shadow-xl p-6 md:p-8 border border-gray-200 text-center">
                    <h2 class="text-lg md:text-xl font-bold text-gray-900 mb-1">Service Area</h2>
                    <p class="text-gray-600 mb-4">Currently serving Delhi NCR, India. New cities coming soon.</p>
                    <div class="flex flex-col sm:flex-row gap-3 justify-center">
                        <button @click="navigateTo('products')"
                            class="flex-1 bg-gradient-to-r from-emerald-500 to-emerald-600 hover:from-emerald-600 hover:to-emerald-700 text-white font-semibold py-3 px-4 rounded-lg transition-all">
                            Book a Service
                        </button>
                        <button @click="navigateTo('contact')"
                            class="flex-1 border border-emerald-500 text-emerald-700 hover:bg-emerald-50 font-semibold py-3 px-4 rounded-lg transition-all">
                            Contact Us
                        </button>
                    </div>
                </div>
            </div>
        </div>

        <!-- P1-2: WALLET VIEW -->
        <div x-show="currentPage === 'wallet'" class="min-h-full pb-20 md:pb-0 pt-0 px-3 sm:px-4">
            <div class="max-w-3xl mx-auto space-y-6">
                <h2 class="text-2xl font-bold text-gray-900">My Wallet</h2>

                <!-- Balance -->
                <div class="rounded-2xl p-6 text-white shadow-lg" style="background: linear-gradient(135deg, var(--sage-dk, #047857), var(--sage, #10b981));">
                    <p class="text-sm opacity-80">Available Balance</p>
                    <p class="text-3xl font-bold mt-1">₹<span x-text="(walletBalance || 0).toFixed(2)"></span></p>
                    <p class="text-xs mt-2 opacity-90"><span x-text="loyaltyPoints || 0"></span> loyalty points earned</p>
                </div>

                <!-- Add money -->
                <div class="bg-white rounded-2xl p-5 shadow-sm border border-gray-100">
                    <h3 class="font-semibold text-gray-900 mb-3">Add Money</h3>
                    <div class="flex flex-col sm:flex-row gap-2">
                        <input type="number" min="1" x-model="walletAmount" placeholder="Enter amount ₹"
                            class="flex-1 rounded-lg border border-gray-300 px-3 py-2.5 text-sm focus:ring-2 focus:ring-emerald-400 outline-none" />
                        <button @click="addWalletCredit(walletAmount)" :disabled="walletLoading || !window.RAZORPAY_KEY"
                            class="px-5 py-2.5 rounded-lg bg-emerald-600 text-white text-sm font-semibold hover:bg-emerald-700 disabled:opacity-50">
                            <span x-show="!walletLoading">Add via Razorpay</span>
                            <span x-show="walletLoading">Processing…</span>
                        </button>
                    </div>
                    <p class="text-xs text-gray-400 mt-2" x-show="!window.RAZORPAY_KEY">
                        Top-up opens once online payments are enabled (currently Cash on Delivery only).
                    </p>
                </div>

                <!-- Spend -->
                <div class="bg-white rounded-2xl p-5 shadow-sm border border-gray-100">
                    <h3 class="font-semibold text-gray-900 mb-3">Spend from Wallet</h3>
                    <div class="flex flex-col sm:flex-row gap-2">
                        <input type="number" min="1" x-model="spendAmount" placeholder="Amount to spend ₹"
                            class="flex-1 rounded-lg border border-gray-300 px-3 py-2.5 text-sm focus:ring-2 focus:ring-emerald-400 outline-none" />
                        <button @click="spendFromWallet(spendAmount)" :disabled="walletLoading"
                            class="px-5 py-2.5 rounded-lg bg-emerald-600 text-white text-sm font-semibold hover:bg-emerald-700 disabled:opacity-50">
                            <span x-show="!walletLoading">Spend</span>
                            <span x-show="walletLoading">Processing…</span>
                        </button>
                    </div>
                    <p class="text-xs text-gray-400 mt-2">Payments are processed securely via the wallet service.</p>
                </div>

                <!-- Transaction history -->
                <div class="bg-white rounded-2xl p-5 shadow-sm border border-gray-100">
                    <h3 class="font-semibold text-gray-900 mb-3">Transaction History</h3>
                    <div x-show="walletTransactions.length === 0" class="text-sm text-gray-400">No transactions yet.</div>
                    <ul class="divide-y divide-gray-100">
                        <template x-for="tx in walletTransactions" :key="tx.at + '-' + tx.type + '-' + tx.amount">
                            <li class="flex items-center justify-between py-3">
                                <div>
                                    <p class="text-sm font-medium text-gray-800 capitalize" x-text="(tx.type || 'txn') + ' • ' + (tx.method || '')"></p>
                                    <p class="text-xs text-gray-400" x-text="new Date(tx.at || Date.now()).toLocaleString('en-IN')"></p>
                                </div>
                                <p class="font-semibold"
                                    :class="tx.type === 'credit' ? 'text-emerald-600' : 'text-red-500'"
                                    x-text="(tx.type === 'credit' ? '+₹' : '−₹') + (tx.amount || 0)"></p>
                            </li>
                        </template>
                    </ul>
                </div>
            </div>
        </div>

        <!-- P1-2: MEMBERSHIP VIEW -->
        <div x-show="currentPage === 'membership'" class="min-h-full pb-20 md:pb-0 pt-0 px-3 sm:px-4">
            <div class="max-w-4xl mx-auto space-y-6">
                <h2 class="text-2xl font-bold text-gray-900">Membership</h2>

                <!-- Current membership -->
                <div x-show="currentMembership" class="rounded-2xl p-5 text-white shadow-lg"
                    style="background: linear-gradient(135deg, var(--sage-dk, #047857), var(--sage, #10b981));">
                    <div class="flex items-center justify-between">
                        <p class="text-sm opacity-80">Current Plan</p>
                        <span class="text-[10px] font-bold uppercase tracking-wide bg-white/20 rounded-full px-2 py-0.5">★ Prime Member</span>
                    </div>
                    <p class="text-xl font-bold mt-1" x-text="currentMembership?.planName || 'Active Membership'"></p>
                    <p class="text-xs mt-1 opacity-90" x-text="'Status: ' + (currentMembership?.status || 'active')"></p>
                </div>
                <div x-show="!currentMembership" class="rounded-2xl p-5 bg-gray-50 border border-gray-100 text-sm text-gray-500">
                    You have no active membership. Pick a plan below to unlock benefits.
                </div>

                <!-- Plans -->
                <div class="grid gap-4 sm:grid-cols-2 lg:grid-cols-3">
                    <template x-for="plan in membershipPlans" :key="plan.id">
                        <div class="bg-white rounded-2xl p-5 shadow-sm border border-gray-100 flex flex-col">
                            <h3 class="font-semibold text-gray-900 text-lg" x-text="plan.name || 'Plan'"></h3>
                            <p class="text-2xl font-bold text-emerald-600 mt-1">₹<span x-text="plan.price || 0"></span><span class="text-sm text-gray-400 font-normal">/mo</span></p>
                            <p class="text-xs text-gray-500 mt-2 flex-1" x-text="plan.description || ''"></p>
                            <button @click="purchaseMembershipPlan(plan)" :disabled="walletLoading || !window.RAZORPAY_KEY"
                                class="mt-4 w-full py-2.5 rounded-lg bg-emerald-600 text-white text-sm font-semibold hover:bg-emerald-700 disabled:opacity-50">
                                <span x-show="!walletLoading && window.RAZORPAY_KEY">Activate</span>
                                <span x-show="!walletLoading && !window.RAZORPAY_KEY">Coming soon</span>
                                <span x-show="walletLoading">Processing…</span>
                            </button>
                        </div>
                    </template>
                    <p x-show="membershipPlans.length === 0" class="text-sm text-gray-400 col-span-full">No plans available yet.</p>
                </div>
                <p x-show="!window.RAZORPAY_KEY" class="text-xs text-amber-600 font-medium">
                    Payments activate soon — membership will be enabled when we go live.
                </p>
                <p class="text-xs text-gray-400">Membership is activated securely via a verified payment — your plan is managed by our servers.</p>
            </div>
        </div>

        <!-- P1-2: REWARDS (Loyalty + Referral) VIEW -->
        <div x-show="currentPage === 'rewards'" class="min-h-full pb-20 md:pb-0 pt-0 px-3 sm:px-4">
            <div class="max-w-3xl mx-auto space-y-6">
                <h2 class="text-2xl font-bold text-gray-900">Rewards</h2>

                <!-- Loyalty points -->
                <div class="rounded-2xl p-6 text-white shadow-lg" style="background: linear-gradient(135deg, var(--sage-dk, #047857), var(--sage, #10b981));">
                    <p class="text-sm opacity-80">Loyalty Points</p>
                    <p class="text-3xl font-bold mt-1" x-text="loyaltyPoints || 0"></p>
                </div>

                <div class="bg-white rounded-2xl p-5 shadow-sm border border-gray-100">
                    <h3 class="font-semibold text-gray-900 mb-3">Redeem Points</h3>
                    <div class="flex flex-col sm:flex-row gap-2">
                        <input type="number" min="1" x-model="loyaltyRedeemPoints" placeholder="Points to redeem"
                            class="flex-1 rounded-lg border border-gray-300 px-3 py-2.5 text-sm focus:ring-2 focus:ring-emerald-400 outline-none" />
                        <button @click="redeemLoyalty()" :disabled="walletLoading"
                            class="px-5 py-2.5 rounded-lg bg-emerald-600 text-white text-sm font-semibold hover:bg-emerald-700 disabled:opacity-50">
                            <span x-show="!walletLoading">Redeem</span>
                            <span x-show="walletLoading">Processing…</span>
                        </button>
                    </div>
                    <p class="text-xs mt-2" :class="loyaltyRedeemError ? 'text-red-500' : 'text-emerald-600'" x-show="loyaltyRedeemMsg" x-text="loyaltyRedeemMsg"></p>
                </div>

                <!-- Referral -->
                <div class="bg-white rounded-2xl p-5 shadow-sm border border-gray-100 space-y-4">
                    <div>
                        <h3 class="font-semibold text-gray-900 mb-2">Your Referral Code</h3>
                        <button @click="generateReferralCode()" :disabled="walletLoading"
                            class="w-full py-2.5 rounded-lg bg-emerald-600 text-white text-sm font-semibold hover:bg-emerald-700 disabled:opacity-50">
                            <span x-show="!walletLoading && !referralCreated">Generate & Share</span>
                            <span x-show="walletLoading">Generating…</span>
                            <span x-show="!walletLoading && referralCreated">Regenerate</span>
                        </button>
                        <div x-show="referralCode" class="mt-3 p-3 rounded-lg bg-emerald-50 border border-emerald-200">
                            <p class="text-sm font-mono font-bold text-emerald-700" x-text="referralCode"></p>
                            <p class="text-xs text-gray-500 mt-1 break-all" x-text="referralLink"></p>
                        </div>
                    </div>

                    <div class="border-t border-gray-100 pt-4">
                        <h3 class="font-semibold text-gray-900 mb-2">Have a friend's code?</h3>
                        <div class="flex flex-col sm:flex-row gap-2">
                            <input type="text" x-model="referralApplyInput" placeholder="Enter referral code"
                                class="flex-1 rounded-lg border border-gray-300 px-3 py-2.5 text-sm uppercase focus:ring-2 focus:ring-emerald-400 outline-none" />
                            <button @click="applyReferral()" :disabled="walletLoading"
                                class="px-5 py-2.5 rounded-lg bg-emerald-600 text-white text-sm font-semibold hover:bg-emerald-700 disabled:opacity-50">
                                <span x-show="!walletLoading">Apply</span>
                                <span x-show="walletLoading">Applying…</span>
                            </button>
                        </div>
                        <p class="text-xs mt-2" :class="referralApplyError ? 'text-red-500' : 'text-emerald-600'" x-show="referralApplyMsg" x-text="referralApplyMsg"></p>
                    </div>
                </div>
            </div>
        </div>

        <div x-show="currentPage === 'error'"
            class="min-h-full pt-0 pb-20 md:pb-0 md:pt-0 text-center flex items-center justify-center">
            <div class="max-w-lg mx-auto p-8 md:p-10 rounded-2xl"
                style="background: var(--bg-card); border: 1px solid var(--border-md); box-shadow: var(--sh-lg);">
                <div class="text-4xl md:text-5xl mb-4"><svg class="icon"><use href="#i-warning"/></svg></div>
                <h1 class="text-lg md:text-xl font-bold mb-2"
                    style="color: var(--text-primary); font-family: 'Inter', sans-serif;">Something Went Wrong</h1>
                <p class="text-sm md:text-base mb-6" style="color: var(--text-secondary);">We're sorry, an unexpected
                    error occurred. Please try again later.</p>
                <button @click="navigateTo('products')"
                    class="btn-gradient-primary text-white px-8 py-3 rounded-lg font-semibold transition-all">
                    Go to Services
                </button>
            </div>
        </div>

        </div> <!-- This closes the page container -->


        </div>
    </main>


    <!-- Loading Overlay -->
    <div x-show="loading.auth || loading.orders || loading.placeOrder"
        x-transition:enter="transition ease-out duration-200" x-transition:enter-start="opacity-0"
        x-transition:enter-end="opacity-100" x-transition:leave="transition ease-in duration-150"
        class="fixed inset-0 flex items-center justify-center z-50"
        style="background: rgba(255,255,255,0.7); backdrop-filter: blur(12px);">
        <div class="rounded-2xl p-8 flex flex-col items-center space-y-4"
            style="background: rgba(255,255,255,0.95); border: 1px solid var(--border-md); box-shadow: var(--sh-xl);">
            <div class="w-12 h-12 border-3 rounded-full animate-spin"
                style="border-color: var(--border); border-top-color: var(--sage);"></div>
            <p class="font-medium"
                style="color: var(--text-secondary); font-family: 'Inter', sans-serif; font-size: 14px;">Please wait...
            </p>
        </div>
    </div>

    <!-- Desktop Sidebar Navigation -->
    <aside x-show="currentPage !== 'login'"
        class="hidden md:fixed md:left-0 md:top-14 md:w-64 md:h-[calc(100vh-3.5rem)] md:bg-white md:border-r md:border-gray-200 md:flex md:flex-col md:pt-4 md:z-40 overflow-y-auto">
        <nav class="flex-1 space-y-2 px-3">
            <!-- Services -->
            <button @click="navigateTo('products')"
                :class="currentPage === 'products' ? 'bg-emerald-600 text-white' : 'text-gray-600 hover:text-gray-900 hover:bg-gray-100'"
                class="w-full flex items-center space-x-3 px-4 py-3 rounded-lg transition-all duration-200">
                <svg class="w-6 h-6 flex-shrink-0" fill="none" stroke="currentColor" viewBox="0 0 24 24">
                    <path stroke-linecap="round" stroke-linejoin="round" stroke-width="2"
                        d="M19 21V5a2 2 0 00-2-2H7a2 2 0 00-2 2v16m14 0h2m-2 0h-5m-9 0H3m2 0h5M9 7h1m-1 4h1m4-4h1m-1 4h1m-5 10v-5a1 1 0 011-1h2a1 1 0 011 1v5m-4 0h4">
                    </path>
                </svg>
                <span class="font-medium">Services</span>
            </button>

            <!-- Cart -->
            <button @click="navigateTo('cart')"
                :class="currentPage === 'cart' ? 'bg-emerald-600 text-white' : 'text-gray-600 hover:text-gray-900 hover:bg-gray-100'"
                class="w-full flex items-center space-x-3 px-4 py-3 rounded-lg transition-all duration-200 relative">
                <svg class="w-6 h-6 flex-shrink-0" fill="none" stroke="currentColor" viewBox="0 0 24 24">
                    <path stroke-linecap="round" stroke-linejoin="round" stroke-width="2"
                        d="M3 3h2l.4 2M7 13h10l4-8H5.4m0 0L7 13m0 0l-2.5 5M7 13l2.5 5m6-5v6a2 2 0 01-2 2H9a2 2 0 01-2-2v-6m8 0V9a2 2 0 00-2-2H9a2 2 0 00-2 2v4.01">
                    </path>
                </svg>
                <div class="flex-1 text-left">
                    <span class="font-medium">Cart</span>
                    <span x-show="getCartItemCount() > 0" class="ml-2 text-sm text-emerald-300">₹<span
                            x-text="formatPrice(getTotal())"></span></span>
                </div>
                <span x-show="getCartItemCount() > 0" x-text="getCartItemCount()"
                    class="bg-emerald-500 text-white text-xs rounded-full h-6 w-6 flex items-center justify-center font-bold"></span>
            </button>

            <!-- Orders -->
            <button @click="navigateTo('orders')"
                :class="currentPage === 'orders' ? 'bg-emerald-600 text-white' : 'text-gray-600 hover:text-gray-900 hover:bg-gray-100'"
                class="w-full flex items-center space-x-3 px-4 py-3 rounded-lg transition-all duration-200">
                <svg class="w-6 h-6 flex-shrink-0" fill="none" stroke="currentColor" viewBox="0 0 24 24">
                    <path stroke-linecap="round" stroke-linejoin="round" stroke-width="2"
                        d="M9 5H7a2 2 0 00-2 2v10a2 2 0 002 2h8a2 2 0 002-2V7a2 2 0 00-2-2h-2M9 5a2 2 0 002 2h2a2 2 0 002-2M9 5a2 2 0 012-2h2a2 2 0 012 2">
                    </path>
                </svg>
                <span class="font-medium">Orders</span>
            </button>

            <!-- Subscriptions (P1-4) -->
            <button @click="navigateTo('subscriptions')"
                :class="currentPage === 'subscriptions' ? 'bg-emerald-600 text-white' : 'text-gray-600 hover:text-gray-900 hover:bg-gray-100'"
                class="w-full flex items-center space-x-3 px-4 py-3 rounded-lg transition-all duration-200">
                <svg class="w-6 h-6 flex-shrink-0" fill="none" stroke="currentColor" viewBox="0 0 24 24">
                    <path stroke-linecap="round" stroke-linejoin="round" stroke-width="2"
                        d="M4 4v5h.582m15.356 2A8.001 8.001 0 004.582 9m0 0H9m11 11v-5h-.581m0 0a8.003 8.003 0 01-15.357-2m15.357 2H15">
                    </path>
                </svg>
                <span class="font-medium">Subscriptions</span>
            </button>

            <!-- Wallet (P1-2) -->
            <button @click="navigateTo('wallet')"
                :class="currentPage === 'wallet' ? 'bg-emerald-600 text-white' : 'text-gray-600 hover:text-gray-900 hover:bg-gray-100'"
                class="w-full flex items-center space-x-3 px-4 py-3 rounded-lg transition-all duration-200">
                <svg class="w-6 h-6 flex-shrink-0" fill="none" stroke="currentColor" viewBox="0 0 24 24">
                    <path stroke-linecap="round" stroke-linejoin="round" stroke-width="2"
                        d="M21 12a2 2 0 0 0-2-2h-1V6a2 2 0 0 0-2-2H5a2 2 0 0 0-2 2v12a2 2 0 0 0 2 2h12a2 2 0 0 0 2-2v-2m0 0V10m0 2h.01">
                    </path>
                </svg>
                <span class="font-medium">Wallet</span>
            </button>

            <!-- Membership (P1-2) -->
            <button @click="navigateTo('membership')"
                :class="currentPage === 'membership' ? 'bg-emerald-600 text-white' : 'text-gray-600 hover:text-gray-900 hover:bg-gray-100'"
                class="w-full flex items-center space-x-3 px-4 py-3 rounded-lg transition-all duration-200">
                <svg class="w-6 h-6 flex-shrink-0" fill="none" stroke="currentColor" viewBox="0 0 24 24">
                    <path stroke-linecap="round" stroke-linejoin="round" stroke-width="2"
                        d="M2 18h20l-2-9-5 4-3-7-3 7-5-4z"></path>
                </svg>
                <span class="font-medium">Membership</span>
            </button>

            <!-- Rewards (P1-2) -->
            <button @click="navigateTo('rewards')"
                :class="currentPage === 'rewards' ? 'bg-emerald-600 text-white' : 'text-gray-600 hover:text-gray-900 hover:bg-gray-100'"
                class="w-full flex items-center space-x-3 px-4 py-3 rounded-lg transition-all duration-200">
                <svg class="w-6 h-6 flex-shrink-0" fill="none" stroke="currentColor" viewBox="0 0 24 24">
                    <path stroke-linecap="round" stroke-linejoin="round" stroke-width="2"
                        d="M20 12v8H4v-8M2 7h20v5H2zM12 7v13M12 7H7a3 3 0 0 1 0-6h5m0 0h5a3 3 0 0 1 0 6h-5">
                    </path>
                </svg>
                <span class="font-medium">Rewards</span>
            </button>

            <!-- Contact -->
            <button @click="navigateTo('contact')"
                :class="currentPage === 'contact' ? 'bg-emerald-600 text-white' : 'text-gray-600 hover:text-gray-900 hover:bg-gray-100'"
                class="w-full flex items-center space-x-3 px-4 py-3 rounded-lg transition-all duration-200">
                <svg class="w-6 h-6 flex-shrink-0" fill="none" stroke="currentColor" viewBox="0 0 24 24">
                    <path stroke-linecap="round" stroke-linejoin="round" stroke-width="2"
                        d="M8 12h.01M12 12h.01M16 12h.01M21 12c0 4.418-4.03 8-9 8a9.863 9.863 0 01-4.255-.949L3 20l1.395-3.72C3.512 15.042 3 13.574 3 12c0-4.418 4.03-8 9-8s9 3.582 9 8z">
                    </path>
                </svg>
                <span class="font-medium">Contact</span>
            </button>

            <!-- About -->
            <button @click="navigateTo('about')"
                :class="currentPage === 'about' ? 'bg-emerald-600 text-white' : 'text-gray-600 hover:text-gray-900 hover:bg-gray-100'"
                class="w-full flex items-center space-x-3 px-4 py-3 rounded-lg transition-all duration-200">
                <svg class="w-6 h-6 flex-shrink-0" fill="none" stroke="currentColor" viewBox="0 0 24 24">
                    <path stroke-linecap="round" stroke-linejoin="round" stroke-width="2"
                        d="M13 16h-1v-4h-1m1-4h.01M21 12a9 9 0 11-18 0 9 9 0 0118 0z"></path>
                </svg>
                <span class="font-medium">About</span>
            </button>
        </nav>

        <!-- Profile/Logout Section -->
        <div class="border-t border-gray-200 p-3 space-y-2">
            <template x-if="user.uid">
                <button @click="navigateTo('profile')"
                    :class="currentPage === 'profile' ? 'bg-emerald-600 text-white' : 'text-gray-600 hover:text-gray-900 hover:bg-gray-100'"
                    class="w-full flex items-center space-x-3 px-4 py-3 rounded-lg transition-all duration-200">
                    <svg class="w-6 h-6 flex-shrink-0" fill="none" stroke="currentColor" viewBox="0 0 24 24">
                        <path stroke-linecap="round" stroke-linejoin="round" stroke-width="2"
                            d="M16 7a4 4 0 11-8 0 4 4 0 018 0zM12 14a7 7 0 00-7 7h14a7 7 0 00-7-7z"></path>
                    </svg>
                    <span class="font-medium">Profile</span>
                </button>
            </template>
            <button @click="logout()"
                class="w-full flex items-center space-x-3 px-4 py-3 rounded-lg text-red-500 hover:text-red-600 hover:bg-red-50 transition-all duration-200">
                <svg class="w-6 h-6 flex-shrink-0" fill="none" stroke="currentColor" viewBox="0 0 24 24">
                    <path stroke-linecap="round" stroke-linejoin="round" stroke-width="2"
                        d="M17 16l4-4m0 0l-4-4m4 4H7m6 4v1a3 3 0 01-3 3H6a3 3 0 01-3-3V7a3 3 0 013-3h4a3 3 0 013 3v1">
                    </path>
                </svg>
                <span class="font-medium">Logout</span>
            </button>
        </div>
    </aside>

<nav x-show="currentPage !== 'login'" class="md:hidden fixed bottom-0 left-0 right-0 z-40 safe-bottom" style="height: var(--bottom-nav-h);">
        <div class="flex h-full overflow-hidden">
            <!-- Services -->
            <button @click="navigateTo('products')"
                class="flex-1 flex flex-col items-center justify-center space-y-0.5 transition-all duration-200">
                <svg class="w-5 h-5 transition-colors" :class="currentPage === 'products' ? '' : ''"
                    :style="currentPage === 'products' ? 'color: var(--sage)' : 'color: var(--text-tertiary)'"
                    fill="none" stroke="currentColor" viewBox="0 0 24 24">
                    <path stroke-linecap="round" stroke-linejoin="round" stroke-width="1.8"
                        d="M19 21V5a2 2 0 00-2-2H7a2 2 0 00-2 2v16m14 0h2m-2 0h-5m-9 0H3m2 0h5M9 7h1m-1 4h1m4-4h1m-1 4h1m-5 10v-5a1 1 0 011-1h2a1 1 0 011 1v5m-4 0h4">
                    </path>
                </svg>
                <span class="text-xs font-medium transition-colors"
                    :style="currentPage === 'products' ? 'color: var(--sage)' : 'color: var(--text-tertiary)'"
                    style="font-family: 'Inter', sans-serif; font-size: 10px;">Services</span>
                <div class="w-1 h-1 rounded-full transition-all"
                    :style="currentPage === 'products' ? 'background: var(--sage); box-shadow: 0 0 6px var(--sage-glow);' : 'background: transparent;'">
                </div>
            </button>

            <!-- Cart with Total -->
            <button @click="navigateTo('cart')"
                class="flex-1 flex flex-col items-center justify-center space-y-0.5 transition-all duration-200 relative">
                <svg class="w-5 h-5 transition-colors"
                    :style="currentPage === 'cart' ? 'color: var(--sage)' : 'color: var(--text-tertiary)'" fill="none"
                    stroke="currentColor" viewBox="0 0 24 24">
                    <path stroke-linecap="round" stroke-linejoin="round" stroke-width="1.8"
                        d="M9 5H7a2 2 0 0 0-2 2v12a2 2 0 0 0 2 2h10a2 2 0 0 0 2-2V7a2 2 0 0 0-2-2h-2M9 5a2 2 0 0 0 2 2h2a2 2 0 0 0 2-2M9 5a2 2 0 0 1 2-2h2a2 2 0 0 1 2 2"></path>
                </svg>
                <span class="text-xs font-medium transition-colors"
                    :style="currentPage === 'cart' ? 'color: var(--sage)' : 'color: var(--text-tertiary)'"
                    style="font-family: 'Inter', sans-serif; font-size: 10px;">Cart</span>
                <div class="w-1 h-1 rounded-full transition-all"
                    :style="currentPage === 'cart' ? 'background: var(--sage); box-shadow: 0 0 6px var(--sage-glow);' : 'background: transparent;'">
                </div>
                <span x-show="getCartItemCount() > 0" x-text="getCartItemCount()"
                    class="absolute top-1 right-4 text-white text-xs rounded-full w-4 h-4 flex items-center justify-center font-bold"
                    style="background: var(--sage); font-size: 9px; box-shadow: 0 2px 6px var(--sage-glow);"></span>
            </button>

            <!-- Checkout -->
            <button @click="navigateTo('checkout')"
                class="flex-1 flex flex-col items-center justify-center space-y-0.5 transition-all duration-200">
                <svg class="w-5 h-5 transition-colors"
                    :style="currentPage === 'checkout' ? 'color: var(--sage)' : 'color: var(--text-tertiary)'" fill="none"
                    stroke="currentColor" viewBox="0 0 24 24">
                    <path stroke-linecap="round" stroke-linejoin="round" stroke-width="1.8"
                        d="M6 2 3 6v14a2 2 0 0 0 2 2h14a2 2 0 0 0 2-2V6l-3-4zM3 6h18M16 10a4 4 0 0 1-8 0"></path>
                </svg>
                <span class="text-xs font-medium transition-colors"
                    :style="currentPage === 'checkout' ? 'color: var(--sage)' : 'color: var(--text-tertiary)'"
                    style="font-family: 'Inter', sans-serif; font-size: 10px;">Checkout</span>
                <div class="w-1 h-1 rounded-full transition-all"
                    :style="currentPage === 'checkout' ? 'background: var(--sage); box-shadow: 0 0 6px var(--sage-glow);' : 'background: transparent;'">
                </div>
            </button>

            <!-- Orders -->
            <button @click="navigateTo('orders')"
                class="flex-1 flex flex-col items-center justify-center space-y-0.5 transition-all duration-200">
                <svg class="w-5 h-5 transition-colors"
                    :style="currentPage === 'orders' ? 'color: var(--sage)' : 'color: var(--text-tertiary)'" fill="none"
                    stroke="currentColor" viewBox="0 0 24 24">
                    <path stroke-linecap="round" stroke-linejoin="round" stroke-width="1.8"
                        d="M9 5H7a2 2 0 00-2 2v10a2 2 0 002 2h8a2 2 0 002-2V7a2 2 0 00-2-2h-2M9 5a2 2 0 002 2h2a2 2 0 002-2M9 5a2 2 0 012-2h2a2 2 0 012 2">
                    </path>
                </svg>
                <span class="text-xs font-medium transition-colors"
                    :style="currentPage === 'orders' ? 'color: var(--sage)' : 'color: var(--text-tertiary)'"
                    style="font-family: 'Inter', sans-serif; font-size: 10px;">Orders</span>
                <div class="w-1 h-1 rounded-full transition-all"
                    :style="currentPage === 'orders' ? 'background: var(--sage); box-shadow: 0 0 6px var(--sage-glow);' : 'background: transparent;'">
                </div>
            </button>

            <!-- Contact -->
            <button @click="navigateTo('contact')"
                class="flex-1 flex flex-col items-center justify-center space-y-0.5 transition-all duration-200">
                <svg class="w-5 h-5 transition-colors"
                    :style="currentPage === 'contact' ? 'color: var(--sage)' : 'color: var(--text-tertiary)'"
                    fill="none" stroke="currentColor" viewBox="0 0 24 24">
                    <path stroke-linecap="round" stroke-linejoin="round" stroke-width="1.8"
                        d="M8 12h.01M12 12h.01M16 12h.01M21 12c0 4.418-4.03 8-9 8a9.863 9.863 0 01-4.255-.949L3 20l1.395-3.72C3.512 15.042 3 13.574 3 12c0-4.418 4.03-8 9-8s9 3.582 9 8z">
                    </path>
                </svg>
                <span class="text-xs font-medium transition-colors"
                    :style="currentPage === 'contact' ? 'color: var(--sage)' : 'color: var(--text-tertiary)'"
                    style="font-family: 'Inter', sans-serif; font-size: 10px;">Contact</span>
                <div class="w-1 h-1 rounded-full transition-all"
                    :style="currentPage === 'contact' ? 'background: var(--sage); box-shadow: 0 0 6px var(--sage-glow);' : 'background: transparent;'">
                </div>
            </button>
        </div>
    </nav>

<!-- PWA Install Banner -->
    <style>
        #pwa-install-banner {
            position: fixed;
            bottom: 64px;
            left: 0;
            right: 0;
            background: linear-gradient(135deg, var(--sage), var(--sage-lt));
            color: white;
            padding: 16px 20px;
            z-index: 50;
            box-shadow: 0 -2px 10px rgba(0, 0, 0, 0.2);
            margin: 0 auto;
            max-width: 100vw;
        }

        #pwa-install-banner.hidden {
            display: none;
        }

        #pwa-install-btn {
            background: white;
            color: var(--sage);
            border: none;
            padding: 8px 16px;
            border-radius: 20px;
            font-weight: bold;
            cursor: pointer;
            transition: all 0.3s;
            white-space: nowrap;
        }

        #pwa-install-btn:hover {
            background: var(--cream);
        }
    </style>
    <div id="pwa-install-banner" class="hidden">
        <div style="display: flex; align-items: center; justify-content: space-between; gap: 16px; width: 100%;">
            <div style="flex: 1; min-width: 0;">
                <div style="font-weight: bold; font-size: 16px; margin-bottom: 4px;">Install Sachin Deep Cleaning App</div>
                <div style="font-size: 13px; opacity: 0.9;">Get one-click access & offline support</div>
            </div>
            <div style="display: flex; gap: 8px; flex-shrink: 0;">
                <button id="pwa-install-btn">Install</button>
                <button id="pwa-dismiss-btn"
                    style="background: transparent; color: white; border: none; cursor: pointer; font-size: 24px; padding: 0 8px; width: auto; height: 32px; display: flex; align-items: center; justify-content: center;"><svg class="icon icon--sm"><use href="#i-x"/></svg></button>
    </div>
    </div>
    </div>

    <!-- ══════════════════════════════════════
         THEME TOGGLE SCRIPT
         ══════════════════════════════════════ -->
    <script>
        (function () {
            var STORAGE_KEY = 'sachin-theme';

            function applyTheme(theme) {
                document.documentElement.setAttribute('data-theme', theme);
                var icon = document.getElementById('theme-icon');
                var label = document.getElementById('theme-label');
                if (icon) icon.textContent = theme === 'dark' ? '🌙' : '☀️';
                if (label) label.textContent = theme === 'dark' ? 'Dark' : 'Light';
            }

            window.toggleTheme = function () {
                var current = document.documentElement.getAttribute('data-theme') || 'light';
                var next = current === 'dark' ? 'light' : 'dark';
                localStorage.setItem(STORAGE_KEY, next);
                applyTheme(next);
                // Clear button focus and hover state
                document.activeElement.blur();
            };

            // Apply saved or system preference on load
            var saved = localStorage.getItem(STORAGE_KEY);
            var preferred = saved || (window.matchMedia('(prefers-color-scheme: dark)').matches ? 'dark' : 'light');
            applyTheme(preferred);

            // Keep icon/label in sync after Alpine re-renders
            document.addEventListener('DOMContentLoaded', function () {
                applyTheme(document.documentElement.getAttribute('data-theme') || preferred);
            });
        })();
    </script>

    <!-- P0-W2: Write-a-review modal -->
    <div x-show="showReviewForm" x-cloak
        class="fixed inset-0 z-50 flex items-center justify-center bg-black/50 px-4"
        @click.self="showReviewForm = false">
        <div class="bg-white rounded-2xl shadow-2xl w-full max-w-md p-6 max-h-[90vh] overflow-y-auto">
            <div class="flex items-center justify-between mb-4">
                <h3 class="text-lg font-bold text-gray-900">Write a review</h3>
                <button @click="showReviewForm = false" class="text-gray-400 hover:text-gray-600">
                    <svg class="w-5 h-5" fill="none" stroke="currentColor" viewBox="0 0 24 24">
                        <path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M6 18L18 6M6 6l12 12" />
                    </svg>
                </button>
            </div>

            <p class="text-sm text-gray-500 mb-3" x-text="'Reviewing: ' + (reviewForm.productName || '')"></p>

            <!-- Star rating -->
            <div class="flex items-center gap-1 mb-4" x-data="{ hover: 0 }">
                <template x-for="i in 5" :key="i">
                    <button type="button" @click="reviewForm.rating = i"
                        @mouseenter="hover = i" @mouseleave="hover = 0">
                        <svg :class="(hover || reviewForm.rating) >= i ? 'text-yellow-400' : 'text-gray-300'"
                            class="w-8 h-8 cursor-pointer" fill="currentColor" viewBox="0 0 20 20">
                            <path d="M9.049 2.927c.3-.921 1.603-.921 1.902 0l1.07 3.292a1 1 0 00.95.69h3.462c.969 0 1.371 1.24.588 1.81l-2.8 2.034a1 1 0 00-.364 1.118l1.07 3.292c.3.921-.755 1.688-1.54 1.118l-2.8-2.034a1 1 0 00-1.175 0l-2.8 2.034c-.786.57-1.833-.197-1.54-1.118l1.07-3.292a1 1 0 00-.364-1.118L2.096 9.389c-.784-.57-.381-1.81.588-1.81h3.462a1 1 0 00.95-.69l1.07-3.292z" />
                        </svg>
                    </button>
                </template>
            </div>

            <textarea x-model="reviewForm.comment" rows="4" placeholder="Share your experience…"
                class="w-full rounded-lg border border-gray-300 p-3 text-sm focus:ring-2 focus:ring-emerald-400 focus:border-emerald-400 outline-none"></textarea>

            <div class="mt-3 flex items-center gap-3">
                <label class="cursor-pointer inline-flex items-center gap-2 text-sm text-emerald-600 font-medium">
                    <svg class="w-5 h-5" fill="none" stroke="currentColor" viewBox="0 0 24 24">
                        <path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M3 9a2 2 0 012-2h.93a2 2 0 001.664-.89l.812-1.22A2 2 0 0110.07 4h3.86a2 2 0 011.664.89l.812 1.22A2 2 0 0018.07 7H19a2 2 0 012 2v9a2 2 0 01-2 2H5a2 2 0 01-2-2V9z" />
                        <path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M15 13a3 3 0 11-6 0 3 3 0 016 0z" />
                    </svg>
                    <span x-text="(reviewForm.photos && reviewForm.photos.length) ? (reviewForm.photos.length + ' photo(s) attached') : 'Add photos'"></span>
                    <input type="file" accept="image/*" multiple class="hidden" @change="onReviewPhotos($event)" />
                </label>
            </div>
            <template x-if="reviewForm.photos && reviewForm.photos.length">
                <div class="mt-2 flex flex-wrap gap-2">
                    <template x-for="(ph, phi) in reviewForm.photos" :key="phi">
                        <div class="relative">
                            <img :src="ph.url" alt="Attached photo"
                                class="w-16 h-16 object-cover rounded-lg border border-gray-200" />
                            <button type="button" @click="removeReviewPhoto(phi)"
                                class="absolute -top-1.5 -right-1.5 w-5 h-5 rounded-full bg-red-500 text-white text-xs flex items-center justify-center leading-none">×</button>
                        </div>
                    </template>
                </div>
            </template>

            <div class="mt-5 flex gap-3">
                <button @click="showReviewForm = false"
                    class="flex-1 py-2.5 rounded-lg border border-gray-300 text-gray-700 font-medium hover:bg-gray-50">Cancel</button>
                <button @click="submitReview" :disabled="reviewSubmitting"
                    class="flex-1 py-2.5 rounded-lg bg-emerald-600 text-white font-semibold hover:bg-emerald-700 disabled:opacity-50">
                    <span x-show="!reviewSubmitting">Submit Review</span>
                    <span x-show="reviewSubmitting">Submitting…</span>
                </button>
            </div>
        </div>
    </div>
    <!-- P1-3: Notification inbox modal -->
    <div x-show="showNotifModal" x-cloak
        class="fixed inset-0 z-50 flex items-center justify-center bg-black/50 px-4"
        @click.self="showNotifModal = false">
        <div class="bg-white rounded-2xl shadow-2xl w-full max-w-md p-6 max-h-[80vh] flex flex-col">
            <div class="flex items-center justify-between mb-4">
                <h3 class="text-lg font-bold text-gray-900">Notifications</h3>
                <div class="flex items-center gap-3">
                    <button x-show="unreadNotifications > 0" @click="markAllNotificationsRead()"
                        class="text-sm text-emerald-600 font-medium hover:underline">Mark all read</button>
                    <button @click="showNotifModal = false" class="text-gray-400 hover:text-gray-600">
                        <svg class="w-5 h-5" fill="none" stroke="currentColor" viewBox="0 0 24 24">
                            <path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M6 18L18 6M6 6l12 12" />
                        </svg>
                    </button>
                </div>
            </div>
            <div class="overflow-y-auto flex-1 space-y-2">
                <template x-for="n in notifications" :key="n.id">
                    <div class="p-3 rounded-lg border"
                        :class="n.read ? 'border-gray-200 bg-gray-50' : 'border-emerald-300 bg-emerald-50'"
                        @click="onNotificationClick(n)">
                        <p class="font-semibold text-gray-900 text-sm" x-text="n.title"></p>
                        <p class="text-gray-600 text-sm mt-0.5" x-text="n.body"></p>
                        <p class="text-xs text-gray-400 mt-1"
                            x-text="n.createdAt && n.createdAt.toDate ? n.createdAt.toDate().toLocaleString('en-IN') : ''"></p>
                    </div>
                </template>
                <p x-show="notifications.length === 0" class="text-center text-gray-400 py-8">No notifications yet</p>
            </div>
        </div>
    </div>

    <!-- D2: Reviews read modal (lists all reviews for a product) -->
    <div x-show="showReviewsModal" x-cloak
        class="fixed inset-0 z-50 flex items-center justify-center bg-black/50 px-4"
        @click.self="closeReviewsModal()">
        <div class="bg-white rounded-2xl shadow-2xl w-full max-w-md max-h-[85vh] flex flex-col overflow-hidden">
            <div class="flex items-center justify-between px-5 py-4 border-b border-gray-200">
                <div>
                    <h3 class="text-base font-bold text-gray-900">Reviews</h3>
                    <p class="text-xs text-gray-500" x-text="selectedProductName || ''"></p>
                </div>
                <button @click="closeReviewsModal()" class="text-gray-400 hover:text-gray-600">
                    <svg class="w-5 h-5" fill="none" stroke="currentColor" viewBox="0 0 24 24">
                        <path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M6 18L18 6M6 6l12 12" />
                    </svg>
                </button>
            </div>
            <div class="flex-1 overflow-y-auto px-4 py-3 space-y-3 bg-gray-50">
                <p x-show="reviewsLoading" class="text-center text-gray-400 text-sm py-4">Loading…</p>
                <template x-for="(r, idx) in selectedProductReviews" :key="idx">
                    <div class="bg-white rounded-xl border border-gray-200 p-4">
                        <div class="flex items-center justify-between mb-1">
                            <div class="flex items-center gap-1" aria-label="rating">
                                <template x-for="star in 5" :key="star">
                                    <svg class="w-4 h-4"
                                        :class="star <= (r.rating || 5) ? 'text-amber-400' : 'text-gray-300'"
                                        fill="currentColor" viewBox="0 0 20 20">
                                        <path d="M9.049 2.927c.3-.921 1.603-.921 1.902 0l1.286 3.957a1 1 0 00.95.69h4.162c.969 0 1.371 1.24.588 1.81l-3.368 2.447a1 1 0 00-.364 1.118l1.287 3.957c.3.921-.755 1.688-1.54 1.118l-3.367-2.448a1 1 0 00-1.176 0l-3.367 2.448c-.784.57-1.838-.197-1.539-1.118l1.286-3.957a1 1 0 00-.364-1.118L2.354 9.384c-.783-.57-.38-1.81.588-1.81h4.163a1 1 0 00.95-.69l1.287-3.957z"></path>
                                    </svg>
                                </template>
                            </div>
                            <span x-show="r.verified" class="text-xs text-emerald-600 font-medium">✓ Verified</span>
                        </div>
                        <p class="text-sm text-gray-800 mt-1" x-text="r.text || r.comment || ''"></p>
                        <template x-if="r.photos && r.photos.length">
                            <div class="flex flex-wrap gap-2 mt-2">
                                <template x-for="(p, pi) in r.photos" :key="pi">
                                    <img :src="p" alt="Review photo"
                                        class="w-20 h-20 object-cover rounded-lg border border-gray-200" loading="lazy" />
                                </template>
                            </div>
                        </template>
                        <div class="flex items-center justify-between mt-2">
                            <span class="text-xs font-medium text-gray-600"
                                x-text="r.userName || r.customerName || r.author || 'Anonymous'"></span>
                            <div class="flex items-center gap-3">
                                <span class="text-xs text-gray-400" x-text="r.date || (r.createdAt ? (r.createdAt.toDate ? r.createdAt.toDate().toLocaleDateString('en-IN') : '') : '')"></span>
                                <button @click="voteReviewHelpful(r)"
                                    :class="r.userVotedHelpful ? 'text-emerald-600 bg-emerald-50 border-emerald-200' : 'text-gray-500 border-gray-200 hover:bg-gray-50'"
                                    class="text-xs font-medium border rounded-full px-2.5 py-1 flex items-center gap-1 transition-colors">
                                    <svg class="w-3.5 h-3.5" fill="none" stroke="currentColor" viewBox="0 0 24 24">
                                        <path stroke-linecap="round" stroke-linejoin="round" stroke-width="2"
                                            d="M14 10h4.764a2 2 0 011.789 2.894l-3.5 7A2 2 0 0115.263 21h-4.017c-.163 0-.326-.02-.485-.06L7 20m7-10V5a2 2 0 00-2-2h-.095c-.5 0-.905.405-.905.905a3.61 3.61 0 01-.608 2.006L9 9m7-10V5a2 2 0 00-2-2h-.095c-.5 0-.905.405-.905.905a3.61 3.61 0 01-.608 2.006L9 9m7-10h-3M8 21l-1.5-4.5M8 21l1.5-4.5" />
                                    </svg>
                                    <span x-text="'Helpful (' + (r.helpfulCount || 0) + ')'"></span>
                                </button>
                            </div>
                        </div>
                        <div x-show="r.partnerResponse" class="mt-2 ml-3 pl-3 border-l-2 border-emerald-200 text-xs text-gray-500"
                            x-text="'Pro: ' + r.partnerResponse"></div>
                    </div>
                </template>
                <p x-show="!reviewsLoading && selectedProductReviews.length === 0" class="text-center text-gray-400 text-sm py-6">
                    No reviews yet.
                </p>
            </div>
        </div>
    </div>

    <!-- P1-2: Customer ↔ Professional chat modal -->
    <div x-show="showChatModal" x-cloak
        class="fixed inset-0 z-50 flex items-center justify-center bg-black/50 px-4"
        @click.self="closeChat()">
        <div class="bg-white rounded-2xl shadow-2xl w-full max-w-md h-[80vh] flex flex-col overflow-hidden">
            <div class="flex items-center justify-between px-5 py-4 border-b border-gray-200">
                <div>
                    <h3 class="text-base font-bold text-gray-900">Chat</h3>
                    <p class="text-xs text-gray-500" x-text="chatPartnerName"></p>
                </div>
                <button @click="closeChat()" class="text-gray-400 hover:text-gray-600">
                    <svg class="w-5 h-5" fill="none" stroke="currentColor" viewBox="0 0 24 24">
                        <path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M6 18L18 6M6 6l12 12" />
                    </svg>
                </button>
            </div>
            <div class="flex-1 overflow-y-auto px-4 py-3 space-y-2 bg-gray-50">
                <p x-show="chatLoading" class="text-center text-gray-400 text-sm py-4">Loading…</p>
                <template x-for="m in chatMessages" :key="m.id">
                    <div class="flex" :class="m.senderRole === 'customer' ? 'justify-end' : 'justify-start'">
                        <div class="max-w-[75%] px-3 py-2 rounded-2xl text-sm"
                            :class="m.senderRole === 'customer' ? 'bg-emerald-600 text-white' : 'bg-white text-gray-800 border border-gray-200'"
                            x-text="m.text">
                        </div>
                    </div>
                </template>
                <p x-show="!chatLoading && chatMessages.length === 0" class="text-center text-gray-400 text-sm py-4">
                    Say hi to your professional
                </p>
            </div>
            <form class="flex items-center gap-2 p-3 border-t border-gray-200" @submit.prevent="sendChatMessage()">
                <input x-model="chatInput" type="text" placeholder="Type a message…"
                    class="flex-1 rounded-full border border-gray-300 px-4 py-2 text-sm focus:ring-2 focus:ring-emerald-400 focus:border-emerald-400 outline-none" />
                <button type="submit"
                    class="w-10 h-10 rounded-full bg-emerald-600 text-white flex items-center justify-center hover:bg-emerald-700 disabled:opacity-50"
                    :disabled="!chatInput.trim()">
                    <svg class="w-5 h-5" fill="none" stroke="currentColor" viewBox="0 0 24 24">
                        <path stroke-linecap="round" stroke-linejoin="round" stroke-width="2"
                            d="M5 12h14M12 5l7 7-7 7"></path>
                    </svg>
                </button>
            </form>
        </div>
    </div>

    <!-- P1-4: Wallet & Rewards modal -->
    <div x-show="showRewardsModal" x-cloak
        class="fixed inset-0 z-50 flex items-center justify-center bg-black/50 px-4"
        @click.self="closeRewards()">
        <div class="bg-white rounded-2xl shadow-2xl w-full max-w-md max-h-[85vh] overflow-y-auto p-6">
            <div class="flex items-center justify-between mb-4">
                <h3 class="text-lg font-bold text-gray-900">Wallet & Rewards</h3>
                <button @click="closeRewards()" class="text-gray-400 hover:text-gray-600">
                    <svg class="w-5 h-5" fill="none" stroke="currentColor" viewBox="0 0 24 24">
                        <path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M6 18L18 6M6 6l12 12" />
                    </svg>
                </button>
            </div>

            <!-- Balance -->
            <div class="rounded-xl p-4 mb-4 text-white" style="background: var(--sage, #10b981);">
                <p class="text-sm opacity-80">Wallet Balance</p>
                <p class="text-2xl font-bold">₹<span x-text="(walletBalance || 0).toFixed(2)"></span></p>
                <p class="text-xs mt-1"><span x-text="loyaltyPoints || 0"></span> loyalty points</p>
            </div>

            <!-- Add money -->
            <div class="flex gap-2 mb-2">
                <input type="number" min="1" x-model="walletAmount" placeholder="Add ₹"
                    class="flex-1 rounded-lg border border-gray-300 px-3 py-2 text-sm focus:ring-2 focus:ring-emerald-400 outline-none" />
                <button @click="addWalletCredit(walletAmount)" :disabled="walletLoading || !window.RAZORPAY_KEY"
                    class="px-4 py-2 rounded-lg bg-emerald-600 text-white text-sm font-semibold hover:bg-emerald-700 disabled:opacity-50">Add</button>
            </div>
            <p class="text-xs text-gray-400 mb-4" x-show="!window.RAZORPAY_KEY">
                Wallet top-up opens once online payments are enabled (currently Cash on Delivery only).
            </p>

            <!-- Memberships -->
            <h4 class="font-semibold text-gray-900 mb-2">Membership Plans</h4>
            <div class="space-y-2 mb-4">
                <template x-for="plan in membershipPlans" :key="plan.id">
                    <div class="border border-gray-200 rounded-lg p-3">
                        <div class="flex justify-between items-center">
                            <div>
                                <p class="font-medium text-gray-900" x-text="plan.name || 'Plan'"></p>
                                <p class="text-xs text-gray-500" x-text="plan.description || ''"></p>
                            </div>
                            <button @click="subscribePlan(plan)"
                                class="text-sm text-emerald-600 font-medium hover:underline">Subscribe</button>
                        </div>
                    </div>
                </template>
                <p x-show="membershipPlans.length === 0" class="text-xs text-gray-400">No plans available yet.</p>
            </div>

            <!-- Referral -->
            <h4 class="font-semibold text-gray-900 mb-2">Refer & Earn</h4>
            <p class="text-xs text-gray-500 mb-2" x-text="referralLink"></p>
            <button @click="createReferral()" x-show="!referralCreated"
                class="w-full py-2.5 rounded-lg bg-emerald-600 text-white text-sm font-semibold hover:bg-emerald-700">Activate & Share</button>
            <p x-show="referralCreated" class="text-sm text-emerald-600 font-medium">Referral link ready — share it with friends!</p>
        </div>
    </div>

    <!-- PHONE OPT: form augmentation (Phase 5) + enhancements (Phase 10) -->
    <script>
    (function () {
        'use strict';

        /* ---- Phase 5: mobile-friendly input attributes ---- */
        function augmentForms(root) {
            root = root || document;
            root.querySelectorAll('input, select, textarea').forEach(function (el) {
                if (el.dataset.phoneAug) return;
                el.dataset.phoneAug = '1';
                var t = (el.type || el.tagName).toLowerCase();
                var name = (el.name || el.id || '').toLowerCase();

                var mode = el.getAttribute('inputmode');
                if (!mode) {
                    if (t === 'email' || /email/.test(name)) mode = 'email';
                    else if (t === 'tel' || /phone|mobile/.test(name)) mode = 'tel';
                    else if (t === 'search') mode = 'search';
                    else if (t === 'number' || /amount|otp|count|qty|quantity|zip|pincode|age/.test(name)) mode = 'numeric';
                    if (mode) el.setAttribute('inputmode', mode);
                }

                var ac = el.getAttribute('autocomplete');
                if (!ac) {
                    if (t === 'email' || /email/.test(name)) ac = 'email';
                    else if (t === 'tel' || /phone|mobile/.test(name)) ac = 'tel';
                    else if (/address|street/.test(name)) ac = 'street-address';
                    else if (/name/.test(name)) ac = 'name';
                    else if (t === 'password') ac = (/new|confirm/.test(name) ? 'new-password' : 'current-password');
                    if (ac) el.setAttribute('autocomplete', ac);
                }

                var ek = el.getAttribute('enterkeyhint');
                if (!ek && (t === 'search' || /search/.test(name))) el.setAttribute('enterkeyhint', 'search');
            });
        }
        augmentForms();
        document.addEventListener('DOMContentLoaded', function () { augmentForms(); });
        document.addEventListener('alpine:initialized', function () { augmentForms(); });
        if (window.MutationObserver) {
            new MutationObserver(function () { augmentForms(); })
                .observe(document.body, { childList: true, subtree: true });
        }

        /* ---- Phase 10: visualViewport -> --vh (keyboard / safe area) ---- */
        function setVH() {
            var h = (window.visualViewport && window.visualViewport.height) || window.innerHeight;
            document.documentElement.style.setProperty('--vh', (h * 0.01) + 'px');
        }
        if (window.visualViewport) window.visualViewport.addEventListener('resize', setVH);
        setVH();

        /* ---- Phase 10: PWA install prompt ---- */
        var deferredPrompt = null;
        window.addEventListener('beforeinstallprompt', function (e) {
            e.preventDefault();
            deferredPrompt = e;
            showInstallBanner();
        });
        function showInstallBanner() {
            if (document.getElementById('pwa-install-banner')) return;
            var b = document.createElement('div');
            b.id = 'pwa-install-banner';
            b.style.cssText = 'position:fixed;left:8px;right:8px;bottom:calc(var(--bottom-nav-h,56px) + 8px);z-index:60;background:#047857;color:#fff;border-radius:12px;padding:12px 14px;display:flex;align-items:center;gap:10px;box-shadow:0 8px 24px rgba(0,0,0,.25);font-size:14px;';
            b.innerHTML = '<span style="flex:1">Add Sachin Deep Cleaning to your home screen for a faster experience.</span>' +
                '<button id="pwa-install-yes" style="background:#fff;color:#047857;border:0;border-radius:8px;padding:8px 12px;font-weight:600;min-height:40px">Install</button>' +
                '<button id="pwa-install-no" style="background:transparent;color:#fff;border:0;min-height:40px;font-size:18px;line-height:1">&times;</button>';
            document.body.appendChild(b);
            document.getElementById('pwa-install-yes').addEventListener('click', function () {
                if (deferredPrompt) deferredPrompt.prompt();
                hideBanner();
            });
            document.getElementById('pwa-install-no').addEventListener('click', hideBanner);
        }
        function hideBanner() { var b = document.getElementById('pwa-install-banner'); if (b) b.remove(); }
        window.addEventListener('appinstalled', hideBanner);
    })();
    </script>
</body>
</html>