/* =============================================================
   DukaanWale Mobile App Styles - v1.0
   Activates only on screens ≤768px (mobile devices)
   Desktop layout remains untouched
   ============================================================= */

/* ====== MOBILE-ONLY BASE OVERRIDES ====== */
@media (max-width: 768px) {

  /* Body & HTML - prevent horizontal scroll globally */
  html, body {
    overflow-x: hidden !important;
    -webkit-text-size-adjust: 100%;
    max-width: 100vw;
  }

  body {
    padding-bottom: 70px !important; /* space for bottom nav */
    font-size: 15px !important;
  }

  /* Hide desktop side rail on mobile */
  .side-rail,
  .sidebar,
  .nav-side,
  .left-sidebar {
    display: none !important;
  }

  /* ====== TOPBAR - Mobile Style ====== */
  .topbar {
    position: sticky !important;
    top: 0 !important;
    z-index: 900 !important;
    padding: 10px 14px !important;
    box-shadow: 0 2px 8px rgba(0,0,0,0.15) !important;
    flex-wrap: nowrap !important;
  }

  .topbar h1 {
    font-size: 0.95rem !important;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    max-width: 60vw;
  }

  /* Hide non-essential topbar text on mobile */
  .topbar .desktop-only {
    display: none !important;
  }

  /* ====== CONTENT WRAPPER ====== */
  .content,
  .page-wrap,
  .main-layout,
  .container {
    padding: 12px !important;
    max-width: 100% !important;
    margin: 0 !important;
    grid-template-columns: 1fr !important;
  }

  /* ====== TABLES → CARDS ====== */
  /* Allow tables to scroll horizontally if too wide */
  .table-wrap,
  .table-scroll {
    overflow-x: auto !important;
    -webkit-overflow-scrolling: touch;
  }

  table {
    font-size: 0.82rem !important;
  }

  table th,
  table td {
    padding: 6px 8px !important;
    white-space: nowrap;
  }

  /* ====== BUTTONS - Touch Friendly ====== */
  button,
  .btn,
  .dwc-btn,
  input[type="button"],
  input[type="submit"] {
    min-height: 44px !important;
    padding: 10px 16px !important;
    font-size: 0.9rem !important;
    touch-action: manipulation;
  }

  /* Small inline buttons */
  .btn-small,
  .btn-icon,
  .table-action-btn {
    min-height: 36px !important;
    padding: 6px 10px !important;
  }

  /* ====== INPUTS - Mobile Sized ====== */
  input[type="text"],
  input[type="number"],
  input[type="email"],
  input[type="tel"],
  input[type="password"],
  input[type="date"],
  select,
  textarea,
  .inp {
    font-size: 16px !important; /* Prevents iOS zoom on focus */
    padding: 10px 12px !important;
    min-height: 44px !important;
    width: 100% !important;
    max-width: 100% !important;
    box-sizing: border-box !important;
  }

  /* ====== MODALS - Full Screen on Mobile ====== */
  .modal-overlay,
  .dwc-overlay,
  .dw-modal-overlay {
    padding: 0 !important;
    align-items: flex-end !important;
  }

  .modal-box,
  .dwc-modal,
  .dw-modal-box {
    max-width: 100% !important;
    width: 100% !important;
    max-height: 95vh !important;
    border-radius: 20px 20px 0 0 !important;
    margin: 0 !important;
    padding: 20px !important;
    animation: slideUp 0.25s ease-out;
  }

  @keyframes slideUp {
    from { transform: translateY(100%); }
    to { transform: translateY(0); }
  }

  /* ====== GRIDS - Single Column ====== */
  .stats-grid,
  .summary-grid,
  .cards-grid {
    grid-template-columns: repeat(2, 1fr) !important;
    gap: 10px !important;
  }

  /* Big single column for forms */
  .form-grid,
  .field-grid {
    grid-template-columns: 1fr !important;
    gap: 12px !important;
  }

  /* ====== CARDS ====== */
  .card,
  .stat-card,
  .info-card {
    padding: 14px !important;
    border-radius: 12px !important;
  }

  /* ====== HIDE FROM MOBILE ====== */
  .desktop-only,
  .hide-mobile {
    display: none !important;
  }

  .mobile-only {
    display: block !important;
  }

  /* ====== TABS - Mobile Friendly ====== */
  .dw-tab-btn,
  .tab-btn {
    padding: 10px 14px !important;
    font-size: 0.85rem !important;
    flex-shrink: 0;
  }

  .tabs-row,
  .tabs-wrap {
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
    white-space: nowrap;
    padding-bottom: 4px;
  }

  /* ====== HEADINGS ====== */
  h1 { font-size: 1.25rem !important; }
  h2 { font-size: 1.1rem !important; }
  h3 { font-size: 1rem !important; }

  /* ====== UTILITY ====== */
  .flex-mobile-col {
    flex-direction: column !important;
  }

  .text-mobile-center {
    text-align: center !important;
  }

  /* ====== PRINT BUTTONS - Hide on Mobile in some contexts ====== */
  .print-btn-row {
    flex-direction: column !important;
    gap: 8px !important;
  }
}

/* ====== EXTRA SMALL PHONES (≤400px) ====== */
@media (max-width: 400px) {
  body {
    font-size: 14px !important;
  }

  .topbar h1 {
    font-size: 0.88rem !important;
  }

  .stats-grid,
  .summary-grid {
    grid-template-columns: 1fr !important;
  }

  .stat-card {
    padding: 12px !important;
  }
}

/* =============================================================
   BOTTOM NAVIGATION BAR STYLES
   ============================================================= */
.dw-bottom-nav {
  display: none;
}

@media (max-width: 768px) {
  .dw-bottom-nav {
    display: flex !important;
    position: fixed !important;
    bottom: 0 !important;
    left: 0 !important;
    right: 0 !important;
    width: 100% !important;
    height: 62px !important;
    background: #ffffff !important;
    border-top: 1px solid rgba(15,23,42,0.08) !important;
    box-shadow: 0 -4px 16px rgba(0,0,0,0.08) !important;
    z-index: 9990 !important; /* Higher than any page content */
    padding: 0 4px !important;
    justify-content: space-around !important;
    align-items: stretch !important;
    /* Prevent disappearance on scroll */
    transform: translateZ(0) !important;
    -webkit-transform: translateZ(0) !important;
    will-change: transform !important;
    /* Ensure visible on all browsers */
    visibility: visible !important;
    opacity: 1 !important;
  }

  .dw-bottom-nav .nav-item {
    flex: 1;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 3px;
    background: none;
    border: none;
    color: #64748b;
    cursor: pointer;
    transition: all 0.2s;
    padding: 6px 4px;
    text-decoration: none;
    font-family: inherit;
    min-height: unset !important;
    border-radius: 12px;
    position: relative;
  }

  .dw-bottom-nav .nav-item:active {
    background: rgba(233,69,96,0.08);
    transform: scale(0.95);
  }

  .dw-bottom-nav .nav-icon {
    font-size: 22px;
    line-height: 1;
    transition: transform 0.2s;
  }

  .dw-bottom-nav .nav-label {
    font-size: 10.5px;
    font-weight: 600;
    letter-spacing: 0.2px;
  }

  .dw-bottom-nav .nav-item.active {
    color: #e94560;
  }

  .dw-bottom-nav .nav-item.active .nav-icon {
    transform: scale(1.15);
  }

  .dw-bottom-nav .nav-item.active::before {
    content: '';
    position: absolute;
    top: 4px;
    width: 30px;
    height: 3px;
    background: linear-gradient(90deg, #e94560, #f5a623);
    border-radius: 0 0 3px 3px;
  }

  /* Notification badge */
  .dw-bottom-nav .nav-badge {
    position: absolute;
    top: 4px;
    right: 50%;
    transform: translateX(14px);
    background: #ef4444;
    color: white;
    font-size: 9px;
    font-weight: 800;
    min-width: 16px;
    height: 16px;
    border-radius: 8px;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 0 4px;
    box-shadow: 0 2px 4px rgba(0,0,0,0.2);
  }

  /* FAB - Center Plus Button (optional) */
  .dw-bottom-nav .nav-fab {
    background: linear-gradient(135deg, #e94560, #f5a623);
    width: 52px;
    height: 52px;
    border-radius: 50%;
    margin-top: -22px;
    box-shadow: 0 6px 14px rgba(233,69,96,0.4);
    color: white;
    border: 3px solid white;
  }

  .dw-bottom-nav .nav-fab .nav-icon {
    color: white;
    font-size: 26px;
  }

  .dw-bottom-nav .nav-fab .nav-label {
    display: none;
  }
}

/* =============================================================
   "MORE" MENU OVERLAY
   ============================================================= */
.dw-more-overlay {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.5);
  z-index: 1100;
  backdrop-filter: blur(4px);
  -webkit-backdrop-filter: blur(4px);
}

.dw-more-overlay.show {
  display: flex;
  align-items: flex-end;
  animation: fadeIn 0.2s ease-out;
}

@keyframes fadeIn {
  from { opacity: 0; }
  to { opacity: 1; }
}

.dw-more-sheet {
  background: white;
  width: 100%;
  border-radius: 24px 24px 0 0;
  padding: 16px 16px 24px;
  max-height: 80vh;
  overflow-y: auto;
  animation: slideUp 0.25s ease-out;
}

.dw-more-sheet .sheet-handle {
  width: 40px;
  height: 4px;
  background: rgba(15,23,42,0.15);
  border-radius: 2px;
  margin: 0 auto 16px;
}

.dw-more-sheet .sheet-title {
  font-size: 1rem;
  font-weight: 800;
  color: #1e293b;
  margin-bottom: 14px;
  padding: 0 4px;
}

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

.dw-more-item {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 6px;
  padding: 14px 8px;
  background: rgba(15,23,42,0.03);
  border: 1px solid rgba(15,23,42,0.05);
  border-radius: 14px;
  text-decoration: none;
  color: #1e293b;
  transition: all 0.2s;
  cursor: pointer;
  font-family: inherit;
  font-size: inherit;
}

.dw-more-item:active {
  background: rgba(233,69,96,0.08);
  transform: scale(0.96);
}

.dw-more-item .more-icon {
  font-size: 26px;
  line-height: 1;
}

.dw-more-item .more-label {
  font-size: 10.5px;
  font-weight: 600;
  text-align: center;
  line-height: 1.2;
}

.dw-more-item .more-badge {
  position: absolute;
  background: #ef4444;
  color: white;
  font-size: 9px;
  font-weight: 800;
  min-width: 16px;
  height: 16px;
  border-radius: 8px;
  padding: 0 4px;
  margin-top: -10px;
  margin-left: 28px;
}

@media (min-width: 769px) {
  .dw-bottom-nav,
  .dw-more-overlay {
    display: none !important;
  }
}

/* =============================================================
   DASHBOARD MOBILE TWEAKS
   ============================================================= */
@media (max-width: 768px) {
  .stats-grid {
    grid-template-columns: repeat(2, 1fr) !important;
    gap: 10px !important;
  }

  .stat-card {
    padding: 14px 12px !important;
  }

  .stat-card .stat-value,
  .stat-card .amt {
    font-size: 1.3rem !important;
  }

  .stat-card .stat-label,
  .stat-card .desc {
    font-size: 0.72rem !important;
  }

  /* Charts horizontal scroll */
  .chart-wrap,
  .recharts-wrapper {
    overflow-x: auto;
  }
}

/* =============================================================
   BILLING PAGE MOBILE TWEAKS
   ============================================================= */
@media (max-width: 768px) {
  /* Item search bar prominent */
  .billing-search,
  .item-search-row {
    position: sticky;
    top: 56px;
    z-index: 50;
    background: white;
    padding: 10px 0;
    margin: -12px -12px 12px;
    padding: 12px;
  }

  /* Cart items - card style */
  .smart-table tbody tr {
    display: block;
    margin-bottom: 8px;
    background: white;
    border-radius: 10px;
    padding: 8px;
    box-shadow: 0 1px 3px rgba(0,0,0,0.05);
  }

  /* Sticky total bar */
  .billing-total-bar,
  .bill-footer {
    position: sticky;
    bottom: 70px; /* above bottom nav */
    background: white;
    padding: 12px;
    box-shadow: 0 -2px 8px rgba(0,0,0,0.1);
    border-radius: 14px 14px 0 0;
    margin: 16px -12px 0;
  }
}

/* =============================================================
   INVENTORY MOBILE - Card-based list
   ============================================================= */
@media (max-width: 768px) {
  .inventory-table tbody tr,
  .stock-table tbody tr {
    display: block;
    background: white;
    margin-bottom: 8px;
    padding: 12px;
    border-radius: 12px;
    box-shadow: 0 1px 4px rgba(0,0,0,0.06);
    border: 1px solid rgba(15,23,42,0.05);
  }

  .inventory-table tbody td,
  .stock-table tbody td {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 4px 0 !important;
    border: none !important;
    white-space: normal !important;
  }

  .inventory-table tbody td::before,
  .stock-table tbody td::before {
    content: attr(data-label);
    font-weight: 700;
    color: #64748b;
    font-size: 0.8rem;
    margin-right: 8px;
  }

  /* Hide table headers on mobile (we use data-label instead) */
  .inventory-table thead,
  .stock-table thead {
    display: none;
  }
}

/* =============================================================
   DAY END WIZARD MOBILE
   ============================================================= */
@media (max-width: 768px) {
  .dayend-wizard {
    padding: 12px !important;
  }

  .dayend-step {
    padding: 16px !important;
    border-radius: 14px !important;
  }

  .dayend-nav-row {
    flex-direction: column-reverse !important;
    gap: 10px !important;
  }

  .dayend-nav-row button {
    width: 100% !important;
  }
}

/* =============================================================
   FAB - Floating Action Button (Quick Add)
   ============================================================= */
.dw-fab {
  display: none;
}

@media (max-width: 768px) {
  .dw-fab {
    display: flex;
    position: fixed;
    bottom: 80px;
    right: 16px;
    width: 56px;
    height: 56px;
    border-radius: 50%;
    background: linear-gradient(135deg, #e94560, #f5a623);
    color: white;
    border: none;
    font-size: 28px;
    align-items: center;
    justify-content: center;
    box-shadow: 0 6px 18px rgba(233,69,96,0.4);
    z-index: 950;
    cursor: pointer;
    transition: transform 0.2s;
  }

  .dw-fab:active {
    transform: scale(0.92);
  }
}

/* =============================================================
   SAFE AREA INSETS (iPhone X+)
   ============================================================= */
@supports (padding: env(safe-area-inset-bottom)) {
  @media (max-width: 768px) {
    body {
      padding-bottom: calc(70px + env(safe-area-inset-bottom)) !important;
    }
    .dw-bottom-nav {
      height: calc(62px + env(safe-area-inset-bottom));
      padding-bottom: env(safe-area-inset-bottom);
    }
  }
}

/* =============================================================
   SMOOTH SCROLLING & TOUCH OPTIMIZATIONS
   ============================================================= */
@media (max-width: 768px) {
  * {
    -webkit-tap-highlight-color: transparent;
  }

  body {
    -webkit-overflow-scrolling: touch;
    scroll-behavior: smooth;
  }

  /* Prevent double-tap zoom on buttons */
  button, a {
    touch-action: manipulation;
  }
}
