/* ==========================================================================
   Digital Seva Portal - Comprehensive Mobile-First Responsive Engine
   Breakpoints: 1200px (Desktop), 992px (Tablet), 768px (Mobile), 480px (Small Mobile)
   ========================================================================== */

/* --------------------------------------------------------------------------
   1. GLOBAL MOBILE RESETS & VIEWPORT OVERFLOW SAFEGUARDS
   -------------------------------------------------------------------------- */
html, body {
  overflow-x: hidden;
  width: 100%;
  max-width: 100vw;
  -webkit-text-size-adjust: 100%;
  -webkit-tap-highlight-color: transparent;
}

*, *::before, *::after {
  box-sizing: border-box;
}

img, svg, video, canvas, iframe {
  max-width: 100%;
  height: auto;
}

a, button, input, select, textarea, .btn {
  touch-action: manipulation;
}

/* --------------------------------------------------------------------------
   2. PUBLIC HEADER, TOP ANNOUNCEMENT & MOBILE NAVBAR
   -------------------------------------------------------------------------- */
.mobile-nav-toggle {
  display: none;
  background: #FFFFFF;
  border: 1px solid var(--border-color);
  border-radius: 8px;
  width: 42px;
  height: 42px;
  color: var(--dark-navy);
  cursor: pointer;
  padding: 0;
  align-items: center;
  justify-content: center;
  box-shadow: 0 1px 3px rgba(0,0,0,0.06);
  transition: all 0.2s ease;
}

.mobile-nav-toggle:active {
  transform: scale(0.95);
  background: #F1F5F9;
}

.mobile-nav-actions {
  display: none;
}

@keyframes slideDownNav {
  from {
    opacity: 0;
    transform: translateY(-8px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

/* --------------------------------------------------------------------------
   3. TABLET & MOBILE BREAKPOINTS (max-width: 992px)
   -------------------------------------------------------------------------- */
@media (max-width: 992px) {
  /* Dashboard Two-Column Layout Collapse */
  .dashboard-sidebar {
    position: fixed;
    top: 0;
    bottom: 0;
    left: 0;
    width: 280px;
    max-width: 86vw;
    z-index: 1000;
    transform: translateX(-100%);
    transition: transform 0.28s cubic-bezier(0.16, 1, 0.3, 1);
    box-shadow: none;
  }

  .dashboard-sidebar.show,
  .dashboard-sidebar.open {
    transform: translateX(0);
    box-shadow: 0 20px 45px rgba(0, 0, 0, 0.45);
  }

  .sidebar-close-btn {
    display: inline-flex !important;
    align-items: center;
    justify-content: center;
  }

  /* Backdrop Overlay for Mobile Sidebar */
  .sidebar-backdrop {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(15, 23, 42, 0.65);
    backdrop-filter: blur(3px);
    -webkit-backdrop-filter: blur(3px);
    z-index: 998;
    opacity: 0;
    visibility: hidden;
    transition: all 0.25s ease;
  }

  .sidebar-backdrop.active {
    opacity: 1;
    visibility: visible;
  }

  body.sidebar-open {
    overflow: hidden;
  }

  .dashboard-main {
    margin-left: 0 !important;
    width: 100%;
    max-width: 100vw;
  }

  .dashboard-topbar {
    height: auto;
    min-height: 58px;
    padding: 0.65rem 1.15rem;
    flex-wrap: wrap;
    gap: 0.5rem;
  }

  .dashboard-body {
    padding: 1.25rem 1rem !important;
  }

  .footer-grid {
    grid-template-columns: 1fr 1fr;
    gap: 2rem;
  }
}

/* --------------------------------------------------------------------------
   4. SMARTPHONE BREAKPOINTS (max-width: 820px)
   -------------------------------------------------------------------------- */
@media (max-width: 820px) {
  /* Public Header Navigation */
  .site-header {
    position: sticky;
    top: 0;
    z-index: 100;
  }

  .top-announcement-inner {
    flex-direction: column;
    text-align: center;
    gap: 0.25rem;
    font-size: 0.72rem;
  }

  .top-links {
    display: none;
  }

  .navbar {
    position: relative;
    padding: 0.5rem 0;
    min-height: 60px;
  }

  .mobile-nav-toggle {
    display: inline-flex;
  }

  .nav-actions {
    display: none !important;
  }

  .nav-menu {
    display: none;
    position: absolute;
    top: 100%;
    left: 0;
    right: 0;
    background-color: #FFFFFF;
    border-radius: 0 0 14px 14px;
    flex-direction: column;
    align-items: stretch;
    padding: 1rem 1.25rem 1.5rem;
    box-shadow: 0 16px 30px rgba(0, 0, 0, 0.12);
    border-bottom: 2px solid var(--primary-blue);
    border-top: 1px solid var(--border-color);
    z-index: 999;
    gap: 0.25rem;
  }

  .nav-menu.show {
    display: flex;
    animation: slideDownNav 0.22s cubic-bezier(0.16, 1, 0.3, 1);
  }

  .nav-link {
    display: block;
    padding: 0.75rem 0.5rem;
    font-size: 1rem;
    font-weight: 600;
    border-bottom: 1px solid #F1F5F9;
    color: var(--text-main);
  }

  .nav-link:hover, .nav-link.active {
    color: var(--primary-blue);
    padding-left: 0.85rem;
  }

  .mobile-nav-actions {
    display: flex;
    flex-direction: column;
    gap: 0.65rem;
    margin-top: 1rem;
    padding-top: 0.85rem;
    border-top: 1px dashed #CBD5E1;
  }

  .mobile-nav-actions .btn {
    width: 100%;
    padding: 0.75rem 1rem;
    font-size: 0.95rem;
  }

  /* Form Column Overrides: Collapse all 2-col inline styles on mobile */
  [style*="grid-template-columns:1fr 1fr"],
  [style*="grid-template-columns: 1fr 1fr"],
  [style*="grid-template-columns:1.15fr 0.85fr"],
  [style*="grid-template-columns: 1.15fr 0.85fr"],
  [style*="grid-template-columns:1fr 1fr 1fr"],
  [style*="grid-template-columns: 1fr 1fr 1fr"] {
    grid-template-columns: 1fr !important;
    gap: 0.85rem !important;
  }

  /* Hero Section */
  .hero-grid {
    grid-template-columns: 1fr !important;
    gap: 2rem !important;
  }

  .hero-grid h1 {
    font-size: 1.95rem !important;
    line-height: 1.25 !important;
  }

  .hero-grid p {
    font-size: 0.95rem !important;
  }

  /* Stats Counter under Hero */
  .hero-stats-row,
  [style*="border-top:1px solid var(--border-color); padding-top:1.5rem;"] {
    display: grid !important;
    grid-template-columns: repeat(3, 1fr) !important;
    gap: 0.75rem !important;
    text-align: center;
  }

  /* Forms & Inputs Zoom Guard for iOS */
  input, select, textarea, .form-control {
    font-size: 16px !important;
    width: 100% !important;
  }

  /* Cards Mobile Padding Override */
  .card, div.card {
    padding: 1.25rem 1rem !important;
  }

  /* Topbar Mobile Layout & Controls */
  #sidebar-toggle,
  .sidebar-toggle-btn {
    width: 38px !important;
    height: 38px !important;
    min-width: 38px !important;
    min-height: 38px !important;
    display: inline-flex !important;
    align-items: center !important;
    justify-content: center !important;
    padding: 0 !important;
    flex-shrink: 0 !important;
  }
  #sidebar-toggle svg,
  #sidebar-toggle i,
  .sidebar-toggle-btn svg,
  .sidebar-toggle-btn i {
    width: 20px !important;
    height: 20px !important;
    stroke-width: 2.2 !important;
  }

  .dashboard-topbar {
    padding: 0.5rem 0.85rem !important;
    height: auto !important;
    min-height: 56px !important;
    display: flex !important;
    align-items: center !important;
    justify-content: space-between !important;
    flex-wrap: nowrap !important;
    gap: 0.45rem !important;
  }

  .topbar-left {
    min-width: 0;
    flex: 1 1 auto;
    display: flex;
    align-items: center;
    gap: 0.45rem;
    overflow: hidden;
  }

  .topbar-prefix {
    display: none !important; /* Hides 'Storefront Desk:' so shop name fits cleanly on 1 line */
  }

  .topbar-name {
    font-size: 0.92rem !important;
    font-weight: 800 !important;
    max-width: 130px;
    white-space: nowrap !important;
    overflow: hidden !important;
    text-overflow: ellipsis !important;
    display: inline-block;
  }

  .topbar-id-badge {
    display: none !important;
  }

  .topbar-right {
    display: flex !important;
    align-items: center !important;
    gap: 0.35rem !important;
    flex-shrink: 0 !important;
    white-space: nowrap !important;
  }

  .topbar-icon-btn {
    width: 36px !important;
    height: 36px !important;
    min-width: 36px !important;
    min-height: 36px !important;
    flex-shrink: 0 !important;
    padding: 0 !important;
  }

  .wallet-badge-pill {
    padding: 0.35rem 0.65rem !important;
    font-size: 0.82rem !important;
    white-space: nowrap !important;
    flex-shrink: 0 !important;
    border-radius: 9999px !important;
  }

  .wallet-pill-label {
    display: none !important; /* On mobile screens, hide 'Balance:' so it shows: [WalletIcon] ₹ 1,950.50 */
  }

  .wallet-pill-amount {
    font-weight: 800 !important;
    font-size: 0.82rem !important;
  }

  .topbar-topup-btn {
    padding: 0.38rem 0.65rem !important;
    font-size: 0.78rem !important;
    white-space: nowrap !important;
    flex-shrink: 0 !important;
    border-radius: 8px !important;
  }

  /* Compact 2x2 KPI Metric Grid on Mobile */
  .kpi-grid {
    display: grid !important;
    grid-template-columns: repeat(2, 1fr) !important;
    gap: 0.65rem !important;
    margin-bottom: 1.25rem !important;
  }

  .kpi-card {
    padding: 0.85rem 0.75rem !important;
    border-radius: 12px !important;
    display: flex !important;
    flex-direction: row !important;
    justify-content: space-between !important;
    align-items: center !important;
    min-height: 74px !important;
    box-shadow: 0 1px 3px rgba(0,0,0,0.05) !important;
  }

  .kpi-title {
    font-size: 0.68rem !important;
    font-weight: 700 !important;
    letter-spacing: 0.02em !important;
    margin-bottom: 0.2rem !important;
    line-height: 1.2 !important;
  }

  .kpi-value {
    font-size: 1.18rem !important;
    font-weight: 800 !important;
    line-height: 1.15 !important;
  }

  /* Hide auxiliary description in KPI cards on mobile to keep them compact */
  .kpi-card > div:first-child > div:last-child {
    display: none !important;
  }

  .kpi-icon-wrap {
    width: 36px !important;
    height: 36px !important;
    min-width: 36px !important;
    border-radius: 8px !important;
  }

  .kpi-icon-wrap svg,
  .kpi-icon-wrap i {
    width: 18px !important;
    height: 18px !important;
  }

  /* Card Header on Mobile (Prevents 'All Applications' from breaking onto 2 lines) */
  .card-header {
    display: flex !important;
    justify-content: space-between !important;
    align-items: center !important;
    flex-wrap: wrap !important;
    gap: 0.5rem !important;
    margin-bottom: 1rem !important;
  }

  .card-header .btn {
    white-space: nowrap !important;
    flex-shrink: 0 !important;
  }

  /* Footers */
  .footer-grid {
    grid-template-columns: 1fr !important;
    gap: 1.75rem !important;
  }

  .footer-bottom {
    flex-direction: column;
    text-align: center;
    gap: 0.75rem;
  }
}

/* --------------------------------------------------------------------------
   5. SMALL MOBILE & NARROW SCREENS (max-width: 480px)
   -------------------------------------------------------------------------- */
@media (max-width: 480px) {
  .container {
    padding: 0 0.85rem !important;
  }

  .dashboard-body {
    padding: 0.85rem 0.65rem !important;
  }

  .hero-grid h1 {
    font-size: 1.65rem !important;
  }

  /* Full Width CTA Buttons on Small Mobile */
  .hero-grid .btn,
  .auth-card .btn,
  .pricing-card .btn {
    width: 100%;
    margin-bottom: 0.35rem;
  }

  .topbar-name {
    max-width: 105px !important;
    font-size: 0.88rem !important;
  }

  /* Stats row becomes 2x2 or compact */
  .hero-stats-row,
  [style*="border-top:1px solid var(--border-color); padding-top:1.5rem;"] {
    grid-template-columns: 1fr 1fr !important;
  }

  /* Modals */
  .modal-dialog {
    width: calc(100% - 1rem) !important;
    margin: 0.5rem auto !important;
    padding: 1rem !important;
    max-height: 90vh !important;
  }

  /* Tables Scroll Container */
  .table th, .table td {
    padding: 0.65rem 0.75rem !important;
    font-size: 0.8rem !important;
  }
}

/* --------------------------------------------------------------------------
   6. UNIVERSAL RESPONSIVE DATA TABLE ENGINE
   -------------------------------------------------------------------------- */
.table-responsive,
.data-table-wrap,
.table-wrap,
div[style*="overflow-x: auto"],
div[style*="overflow-x:auto"] {
  width: 100%;
  max-width: 100%;
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
  margin-bottom: 1rem;
}

.table-responsive table,
.data-table-wrap table,
.table-wrap table,
div[style*="overflow-x: auto"] table,
div[style*="overflow-x:auto"] table {
  min-width: 600px;
}

/* Modals backdrop helper */
.modal-backdrop.active {
  padding: 0.5rem;
}
