/**
 * DigiSoko Kenya — Modern mobile UX layer
 * Safe to load after styles.css. Desktop largely unchanged.
 */

:root {
  --km-mobile-nav-h: 64px;
  --km-mobile-ease: cubic-bezier(0.22, 1, 0.36, 1);
  --km-safe-bottom: env(safe-area-inset-bottom, 0px);
  --km-safe-top: env(safe-area-inset-top, 0px);
}

/* ---------- Base mobile polish ---------- */
@media (max-width: 767px) {
  html {
    -webkit-tap-highlight-color: transparent;
  }

  body {
    padding-bottom: calc(var(--km-mobile-nav-h) + var(--km-safe-bottom) + 8px);
    background: #f8fafc;
  }

  /* Sticky glass header */
  #mainHeader {
    position: sticky;
    top: 0;
    z-index: 50;
    transition: transform 0.28s var(--km-mobile-ease), box-shadow 0.28s ease;
    backdrop-filter: saturate(1.2) blur(12px);
    background: rgba(255, 255, 255, 0.92) !important;
  }

  #mainHeader.km-header-hidden {
    transform: translateY(-110%);
  }

  #mainHeader.km-header-compact .top-bar {
    display: none;
  }

  #mainHeader.km-header-compact .max-w-7xl {
    padding-top: 0.45rem !important;
    padding-bottom: 0.45rem !important;
  }

  #mainHeader .top-bar {
    font-size: 0.62rem;
    letter-spacing: 0.01em;
  }

  #mainHeader .top-bar .max-w-7xl {
    padding-top: 0.35rem;
    padding-bottom: 0.35rem;
    gap: 0.35rem;
  }

  #mainHeader .top-bar a {
    white-space: nowrap;
  }

  /* Logo row: tighter, always show name */
  #mainHeader > .max-w-7xl {
    flex-wrap: nowrap !important;
    gap: 0.5rem !important;
    padding-left: 0.75rem !important;
    padding-right: 0.75rem !important;
  }

  #mainHeader a[aria-label] span.hidden {
    display: flex !important;
  }

  #mainHeader a[aria-label] span.hidden span:last-child {
    display: none; /* hide tagline on very tight */
  }

  #mainHeader a[aria-label] img {
    width: 2.25rem;
    height: 2.25rem;
    border-radius: 0.65rem;
  }

  /* Auth links: icons only */
  #mainHeader .ml-auto {
    gap: 0.65rem !important;
  }

  #mainHeader .ml-auto a {
    min-width: 2.5rem;
    min-height: 2.5rem;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    border-radius: 999px;
    background: #f8fafc;
    border: 1px solid #e5e7eb;
  }

  #mainHeader .ml-auto a:active {
    transform: scale(0.94);
    background: #fff7ed;
    border-color: #fdba74;
  }

  /* Category chip nav — horizontal snap */
  #mainHeader nav > div {
    gap: 0.5rem !important;
    padding-top: 0.5rem !important;
    padding-bottom: 0.55rem !important;
    -webkit-overflow-scrolling: touch;
    scroll-snap-type: x mandatory;
    scrollbar-width: none;
  }

  #mainHeader nav > div::-webkit-scrollbar {
    display: none;
  }

  #mainHeader nav a {
    scroll-snap-align: start;
    padding: 0.4rem 0.85rem;
    border-radius: 999px;
    background: #f1f5f9;
    font-size: 0.75rem;
    font-weight: 600;
    color: #334155;
    border: 1px solid transparent;
  }

  #mainHeader nav a:active {
    background: #fff7ed;
    border-color: #fdba74;
    color: #c2410c;
  }

  /* Mobile search strip (injected) */
  .km-mobile-search {
    display: flex;
    padding: 0 0.75rem 0.65rem;
    background: rgba(255, 255, 255, 0.95);
    border-bottom: 1px solid #f1f5f9;
  }

  .km-mobile-search form {
    display: flex !important;
    flex: 1;
    width: 100%;
    background: #f1f5f9;
    border-radius: 999px;
    overflow: hidden;
    border: 1px solid #e2e8f0;
    transition: border-color 0.2s, box-shadow 0.2s;
  }

  .km-mobile-search form:focus-within {
    border-color: #fb923c;
    box-shadow: 0 0 0 3px rgba(249, 115, 22, 0.15);
    background: #fff;
  }

  .km-mobile-search input {
    flex: 1;
    border: 0;
    background: transparent;
    padding: 0.7rem 0.25rem 0.7rem 1rem;
    font-size: 0.9rem;
    outline: none;
    min-width: 0;
  }

  .km-mobile-search button {
    border: 0;
    background: linear-gradient(135deg, #f97316, #ea580c);
    color: #fff;
    padding: 0 1.1rem;
    font-size: 0.95rem;
  }

  /* Hero tighter */
  .km-hero h1,
  section h1.text-4xl,
  section h1 {
    font-size: 1.65rem !important;
    line-height: 1.2 !important;
  }

  section .py-14 {
    padding-top: 1.75rem !important;
    padding-bottom: 1.75rem !important;
  }

  /* Product grids — 2 columns, equal cards */
  .km-grid-products,
  main .grid.grid-cols-2,
  .grid.sm\:grid-cols-2,
  .grid.grid-cols-2.md\:grid-cols-3,
  .grid.grid-cols-2.lg\:grid-cols-4 {
    display: grid !important;
    grid-template-columns: repeat(2, minmax(0, 1fr)) !important;
    gap: 0.65rem !important;
  }

  .product-card,
  a.group.bg-white.border.rounded-2xl {
    border-radius: 1rem !important;
    box-shadow: 0 2px 10px rgba(15, 23, 42, 0.05);
    transition: transform 0.25s var(--km-mobile-ease), box-shadow 0.25s ease;
  }

  .product-card:active,
  a.group.bg-white.border.rounded-2xl:active {
    transform: scale(0.98);
  }

  /* Horizontal sliders */
  .km-best-slider {
    gap: 0.65rem;
    padding-left: 0.25rem;
    padding-right: 0.25rem;
    scroll-padding-left: 0.75rem;
  }

  .km-best-slider > a,
  .km-best-slider > * {
    min-width: 9.25rem !important;
    max-width: 10.5rem;
  }

  /* Section titles */
  main h2,
  .text-2xl.font-bold,
  .text-xl.font-bold {
    font-size: 1.1rem !important;
  }

  /* Footer spacing above bottom nav */
  footer {
    margin-bottom: 0.5rem;
    padding-bottom: calc(0.5rem + var(--km-safe-bottom));
  }

  footer .py-12 {
    padding-top: 2rem !important;
    padding-bottom: 1.5rem !important;
  }

  /* Forms & inputs touch size */
  input, select, textarea, button, .btn {
    font-size: 16px; /* prevents iOS zoom */
  }

  input.input,
  .input,
  select.input {
    min-height: 2.75rem;
    border-radius: 0.75rem;
  }

  .btn, button[type="submit"] {
    min-height: 2.85rem;
    border-radius: 0.85rem;
  }

  /* Category sidebar drawer full-bleed feel */
  .sidebar-mobile,
  .km-cat-drawer {
    border-radius: 1.25rem 1.25rem 0 0;
  }

  /* Cart / product detail: sticky CTA space */
  .km-sticky-cta {
    position: fixed;
    left: 0;
    right: 0;
    bottom: calc(var(--km-mobile-nav-h) + var(--km-safe-bottom));
    z-index: 40;
    padding: 0.65rem 0.85rem;
    background: rgba(255, 255, 255, 0.95);
    backdrop-filter: blur(10px);
    border-top: 1px solid #e5e7eb;
    box-shadow: 0 -8px 24px rgba(15, 23, 42, 0.06);
  }
}

/* ---------- Bottom navigation ---------- */
.km-bottom-nav {
  display: none;
}

@media (max-width: 767px) {
  .km-bottom-nav {
    display: flex;
    position: fixed;
    left: 0;
    right: 0;
    bottom: 0;
    z-index: 60;
    height: calc(var(--km-mobile-nav-h) + var(--km-safe-bottom));
    padding: 0.35rem 0.25rem var(--km-safe-bottom);
    background: rgba(255, 255, 255, 0.94);
    backdrop-filter: saturate(1.3) blur(16px);
    border-top: 1px solid rgba(226, 232, 240, 0.95);
    box-shadow: 0 -10px 30px rgba(15, 23, 42, 0.08);
    justify-content: space-around;
    align-items: flex-start;
  }

  .km-bottom-nav a {
    flex: 1;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 0.2rem;
    padding: 0.35rem 0.15rem;
    text-decoration: none;
    color: #64748b;
    font-size: 0.62rem;
    font-weight: 600;
    letter-spacing: 0.01em;
    border-radius: 0.85rem;
    transition: color 0.2s, transform 0.2s var(--km-mobile-ease);
    -webkit-user-select: none;
    user-select: none;
  }

  .km-bottom-nav a i {
    font-size: 1.2rem;
    line-height: 1;
    transition: transform 0.25s var(--km-mobile-ease);
  }

  .km-bottom-nav a.km-nav-active {
    color: #ea580c;
  }

  .km-bottom-nav a.km-nav-active i {
    transform: translateY(-1px) scale(1.08);
  }

  .km-bottom-nav a:active {
    transform: scale(0.94);
  }

  .km-bottom-nav .km-nav-center {
    position: relative;
    top: -0.55rem;
  }

  .km-bottom-nav .km-nav-center span.km-nav-fab {
    width: 3.1rem;
    height: 3.1rem;
    border-radius: 999px;
    background: linear-gradient(145deg, #fb923c, #ea580c 55%, #c2410c);
    color: #fff;
    display: flex;
    align-items: center;
    justify-content: center;
    box-shadow: 0 8px 20px rgba(234, 88, 12, 0.4);
    border: 3px solid #fff;
  }

  .km-bottom-nav .km-nav-center i {
    font-size: 1.15rem;
    color: #fff;
  }

  .km-bottom-nav .km-nav-center.km-nav-active {
    color: #c2410c;
  }
}

/* ---------- Scroll reveal animations ---------- */
@media (max-width: 767px) {
  .km-reveal {
    opacity: 0;
    transform: translateY(14px);
    transition: opacity 0.45s var(--km-mobile-ease), transform 0.45s var(--km-mobile-ease);
  }

  .km-reveal.km-reveal-in {
    opacity: 1;
    transform: translateY(0);
  }

  @media (prefers-reduced-motion: reduce) {
    .km-reveal {
      opacity: 1;
      transform: none;
      transition: none;
    }
    #mainHeader {
      transition: none;
    }
  }
}

/* ---------- Desktop: never show mobile-only chrome ---------- */
@media (min-width: 768px) {
  .km-mobile-search,
  .km-bottom-nav {
    display: none !important;
  }
}
