/* =====================================================
   SahiHisab — Mobile UI Overrides
   Systematic fixes for 375px mobile screens
   All 6 issue categories addressed globally.
   ===================================================== */

/* ─────────────────────────────────────────────────────
   PWA INSTALL BUTTON
   Mobile: floating pill above bottom nav
   Desktop: floating pill bottom-right corner
   ───────────────────────────────────────────────────── */
body .pwa-install-btn {
  position: fixed;
  z-index: 998;
  border: none;
  cursor: pointer;
  display: flex;
  align-items: center;
  gap: 6px;
  font-family: 'DM Sans', sans-serif;
  font-weight: 600;
  transition: transform 0.2s ease, box-shadow 0.2s ease, opacity 0.3s ease;
  /* Mobile default: pill above bottom nav */
  bottom: calc(84px + env(safe-area-inset-bottom, 0px));
  left: 50%;
  transform: translateX(-50%);
  height: 42px;
  padding: 0 16px;
  border-radius: 21px;
  font-size: 0.8rem;
  background: var(--primary, #0ea5e9);
  color: #fff;
  box-shadow: 0 4px 14px rgba(14, 165, 233, 0.35), 0 1px 3px rgba(0,0,0,0.1);
}

body .pwa-install-btn .material-symbols-rounded {
  font-size: 1.2rem;
}

body .pwa-install-btn .pwa-install-label {
  font-size: 0.8rem;
  letter-spacing: 0.02em;
}

body .pwa-install-btn:active {
  transform: translateX(-50%) scale(0.94);
}

/* Gentle pulse animation to attract attention */
@keyframes pwa-pulse {
  0%, 100% { box-shadow: 0 4px 14px rgba(14, 165, 233, 0.35); }
  50% { box-shadow: 0 4px 20px rgba(14, 165, 233, 0.55), 0 0 0 6px rgba(14, 165, 233, 0.1); }
}

body .pwa-install-btn {
  animation: pwa-pulse 3s ease-in-out infinite;
}

body .pwa-install-btn:hover {
  animation: none;
  box-shadow: 0 6px 20px rgba(14, 165, 233, 0.45);
}

/* Desktop: bottom-right corner floating pill */
@media (min-width: 769px) {
  body .pwa-install-btn {
    bottom: 24px;
    left: auto;
    right: 24px;
    transform: none;
    height: 44px;
    padding: 0 20px;
    border-radius: 22px;
    font-size: 0.85rem;
  }

  body .pwa-install-btn:active {
    transform: scale(0.95);
  }

  body .pwa-install-btn:hover {
    transform: translateY(-2px);
  }
}

/* Hide in standalone mode (already installed) */
@media (display-mode: standalone) {
  body .pwa-install-btn {
    display: none;
  }
}

/* Dark mode */
@media (prefers-color-scheme: dark) {
  body .pwa-install-btn {
    background: #0284c7;
    box-shadow: 0 4px 14px rgba(2, 132, 199, 0.4), 0 1px 3px rgba(0,0,0,0.2);
  }
}

@media (prefers-reduced-motion: reduce) {
  body .pwa-install-btn {
    animation: none;
    transition: none;
  }
}

/* ─────────────────────────────────────────────────────
   ISSUE 1 — HEADER OVERFLOW
   Prevent header icons/buttons from overflowing the
   right edge of the viewport on 375px screens.
   ───────────────────────────────────────────────────── */

@media (max-width: 480px) {
  .app-header {
    overflow: hidden;
    padding: 0 12px;
  }

  .header-left {
    flex: 1;
    min-width: 0;
    overflow: hidden;
  }

  .header-left .page-title {
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    font-size: 1rem;
    max-width: 160px;
  }

  .header-right {
    flex-shrink: 0;
    gap: 2px;
    display: flex;
    align-items: center;
  }

  /* Keep icon buttons at minimum tap-safe size */
  .header-icon-btn {
    width: 38px;
    height: 38px;
    min-width: 38px;
    flex-shrink: 0;
  }

  .header-avatar {
    width: 34px;
    height: 34px;
    min-width: 34px;
    flex-shrink: 0;
    font-size: 0.78rem;
  }
}

@media (max-width: 375px) {
  .app-header {
    padding: 0 10px;
  }

  .header-left .page-title {
    max-width: 130px;
    font-size: 0.92rem;
  }

  .header-icon-btn {
    width: 36px;
    height: 36px;
    min-width: 36px;
  }

  .header-avatar {
    width: 32px;
    height: 32px;
    min-width: 32px;
  }
}


/* ─────────────────────────────────────────────────────
   ISSUE 2 — FILTER / TAB PILLS CUT OFF
   All filter rows across every page: scrollable,
   no line wrap, hidden scrollbar.
   ───────────────────────────────────────────────────── */

@media (max-width: 768px) {
  /* Global: any flex row used as filter bar */
  .filter-tabs,
  .filter-row,
  .filter-pills,
  .tab-pills,
  .status-filter-row,
  .page-filters,
  .rental-filters,

  /* Inline d-flex rows that hold filter buttons (rental.js, quotation.js etc.) */
  body .d-flex.gap-sm[style*="overflow-x"],
  body .d-flex.gap-xs[style*="overflow-x"],
  body .d-flex.gap-md[style*="overflow-x"] {
    overflow-x: auto;
    overflow-y: hidden;
    flex-wrap: nowrap;
    touch-action: pan-x pan-y;
    white-space: nowrap;
    scrollbar-width: none;
    -webkit-overflow-scrolling: touch;
    padding-bottom: 4px;
  }

  /* Hide webkit scrollbar on filter rows */
  .filter-tabs::-webkit-scrollbar,
  .filter-row::-webkit-scrollbar,
  .filter-pills::-webkit-scrollbar,
  .tab-pills::-webkit-scrollbar,
  .status-filter-row::-webkit-scrollbar,
  .page-filters::-webkit-scrollbar {
    display: none;
  }

  /* Prevent filter button text from wrapping inside scroll container */
  .filter-tabs .btn,
  .filter-row .btn,
  .filter-pills .btn,
  .tab-pills .btn,
  .page-filters .btn {
    flex-shrink: 0;
    white-space: nowrap;
  }

  /* WI filter tabs — already correct but reinforce */
  .wi-filter-tabs {
    overflow-x: auto;
    flex-wrap: nowrap;
    scrollbar-width: none;
    padding-bottom: 4px;
  }

  .wi-filter-tabs::-webkit-scrollbar {
    display: none;
  }

  .wi-filter-tabs .btn {
    flex-shrink: 0;
    white-space: nowrap;
  }
}


/* ─────────────────────────────────────────────────────
   ISSUE 2b — PAGE-LEVEL: No horizontal scroll bleed
   The page-content itself must never cause horizontal
   page scroll. Any inner container that scrolls must
   be clipped to its own width.
   ───────────────────────────────────────────────────── */

@media (max-width: 480px) {
  .page-content {
    overflow-x: hidden;
  }

  /* Page-header row (title + CTA button): prevent the button
     from escaping the right edge. */
  .d-flex.align-center.justify-between,
  .d-flex.justify-between {
    max-width: 100%;
    min-width: 0;
  }
}


/* ─────────────────────────────────────────────────────
   ISSUE 3 — ADD / CTA BUTTONS CUT OFF
   "Add Assistant", "New Rental", "Add Item" etc. must
   always be fully visible. The page-header row (filter
   row + button) stacks vertically on mobile so the
   button is always on its own line, never clipped.
   ───────────────────────────────────────────────────── */

@media (max-width: 480px) {

  /* Rows that contain a filter group + an action button:
     stack them vertically so the CTA is never hidden. */
  .d-flex.align-center.justify-between.mb-lg,
  .d-flex.align-center.justify-between.mb-xl,
  .d-flex.align-center.justify-between.mb-md {
    flex-wrap: wrap;
    gap: 10px;
  }

  /* Make the CTA buttons in page headers full-width on
     very small screens so they always fit. */
  .d-flex.align-center.justify-between>.btn.btn-primary.btn-sm,
  .d-flex.align-center.justify-between>.btn.btn-primary {
    flex-shrink: 0;
    white-space: nowrap;
  }
}

@media (max-width: 375px) {

  /* On 375px, the CTA button in page headers goes to full
     width so it always fits and is fully visible. */
  .d-flex.align-center.justify-between>.btn.btn-primary.btn-sm,
  .d-flex.align-center.justify-between>.btn.btn-primary {
    width: 100%;
    justify-content: center;
  }
}


/* ─────────────────────────────────────────────────────
   ISSUE 4 — SIDEBAR OVERLAY: FULL SCREEN
   Ensure sidebar covers the full viewport on mobile.
   The sidebar-backdrop must be position:fixed and cover
   100vw × 100vh with the correct z-index.
   ───────────────────────────────────────────────────── */

@media (max-width: 768px) {

  /* Sidebar: slides from left, smaller than 280px viewport */
  .sidebar {
    width: min(280px, 85vw);
    max-width: 85vw;
    height: 100dvh;
    top: 0;
    left: 0;
    position: fixed;
    z-index: 1050;
  }

  /* Backdrop: covers entire viewport */
  .sidebar-backdrop {
    position: fixed;
    top: 0;
    left: 0;
    width: 100vw;
    height: 100vh;
    height: 100dvh;
    background: rgba(0, 0, 0, 0.5);
    z-index: 998;
    pointer-events: none;
    opacity: 0;
    visibility: hidden;
    transition: opacity 0.25s ease, visibility 0.25s ease;
  }

  .sidebar-backdrop.visible {
    opacity: 1;
    pointer-events: auto;
    visibility: visible;
  }
}


/* ─────────────────────────────────────────────────────
   ISSUE 5 — DASHBOARD STAT CARDS TOO CRAMPED
   Force exactly 2-column grid on mobile with proper
   16px internal padding.
   ───────────────────────────────────────────────────── */

@media (max-width: 480px) {
  body .stats-grid {
    grid-template-columns: repeat(2, 1fr);
    gap: 10px;
  }

  body .stat-card {
    padding: 16px;
  }

  /* Aaj Ka Summary (dashboard hero stats) */
  body .aaj-ka-summary {
    grid-template-columns: repeat(2, 1fr);
    gap: 10px;
  }

  body .aaj-summary-item {
    padding: 16px 12px;
  }
}

@media (max-width: 375px) {
  body .stats-grid {
    grid-template-columns: repeat(2, 1fr);
    gap: 8px;
  }

  body .stat-card {
    padding: 12px;
  }

  body .stat-value {
    font-size: 1.1rem;
  }
}


/* ─────────────────────────────────────────────────────
   ISSUE 6 — QUICK ACTION BUTTONS WRAP BADLY
   Force quick actions to scroll horizontally in a
   single row — never wrap onto multiple rows.
   ───────────────────────────────────────────────────── */

@media (max-width: 480px) {
  body .quick-actions {
    display: flex;
    flex-direction: row;
    flex-wrap: nowrap;
    overflow-x: auto;
    overflow-y: hidden;
    scrollbar-width: none;
    -webkit-overflow-scrolling: touch;
    touch-action: pan-x pan-y;
    gap: 8px;
    padding-bottom: 6px;
    /* Fade-out hint on right edge */
    -webkit-mask-image: linear-gradient(to right, #000 85%, transparent);
    mask-image: linear-gradient(to right, #000 85%, transparent);
  }

  .quick-actions::-webkit-scrollbar {
    display: none;
  }

  body .quick-action-btn {
    flex-shrink: 0;
    min-width: 84px;
    min-height: 44px;
    white-space: nowrap;
    font-size: 0.75rem;
    padding: 8px 10px;
  }
}


/* ─────────────────────────────────────────────────────
   GLOBAL: PREVENT HORIZONTAL PAGE SCROLL
   No horizontal overflow on the page root itself.
   ───────────────────────────────────────────────────── */

@media (max-width: 768px) {

  html,
  body {
    overflow-x: clip;
    max-width: 100vw;
  }

  .main-content {
    overflow-x: clip;
    max-width: 100vw;
  }

  /* Cards and content blocks must not exceed viewport */
  .card,
  .card-padded,
  .card-body,
  .card-header {
    max-width: 100%;
    box-sizing: border-box;
  }

  /* Floating tabbar: ensure it never exceeds viewport width */
  .floating-tabbar {
    left: 10px;
    right: 10px;
    width: auto;
    max-width: calc(100vw - 20px);
  }
}


/* ─────────────────────────────────────────────────────
   MINIMUM TAP TARGETS (44 × 44px)
   All interactive elements must be at least 44px tall.
   ───────────────────────────────────────────────────── */

@media (max-width: 768px) {

  .btn,
  .btn-sm {
    min-height: 44px;
  }

  .nav-item,
  .bottom-nav-item,
  .floating-tabbar-item {
    min-height: 44px;
  }
}


/* ─────────────────────────────────────────────────────
   MODAL FOOTER: Stack on 375px
   Buttons in modal footer should be full-width on
   very small screens to avoid overflow/clipping.
   ───────────────────────────────────────────────────── */

@media (max-width: 375px) {
  .modal-footer {
    flex-direction: column;
  }

  .modal-footer .btn {
    width: 100%;
    justify-content: center;
  }
}