/* ==========================================================================
   Azee ViralHub — Responsive & PWA Layer (Chapter 25)
   Loaded AFTER tokens/style/landing/dashboard/auth so it can safely refine
   breakpoints already defined there without fighting specificity.
   Mobile-first: base rules target phones; min-width queries scale up.
   ========================================================================== */

/* ---------- 1. Touch-friendly targets (WCAG 44x44 minimum) ---------- */
@media (max-width: 767px) {
  .btn, button, .icon-btn, a.btn { min-height: 44px; }
  .icon-btn { min-width: 44px; }
  .nav-links a, .mobile-nav-panel a { padding-top: 10px; padding-bottom: 10px; }
  input, select, textarea, .form-control { min-height: 44px; font-size: 16px; } /* 16px prevents iOS Safari auto-zoom */
}

/* ---------- 2. Adaptive Grid System ---------- */
.az-grid { display: grid; gap: var(--space-4); grid-template-columns: 1fr; }
@media (min-width: 576px) { .az-grid.cols-2 { grid-template-columns: repeat(2, 1fr); } }
@media (min-width: 768px) { .az-grid.cols-3 { grid-template-columns: repeat(3, 1fr); } .az-grid.cols-2 { grid-template-columns: repeat(2, 1fr); } }
@media (min-width: 992px) { .az-grid.cols-4 { grid-template-columns: repeat(4, 1fr); } .az-grid.cols-3 { grid-template-columns: repeat(3, 1fr); } }

/* Bootstrap card/stat grids used across the panel already use .row/.col-* —
   tighten gutters on small screens so 2-up stat cards stay comfortable. */
@media (max-width: 480px) {
  .row.g-3 > * { padding: 6px; }
  .row.g-4 > * { padding: 8px; }
  .container-az { padding-left: 14px; padding-right: 14px; }
}

/* ---------- 3. Responsive Tables ---------- */
/* Default: horizontal scroll wrapper so wide tables (orders, tickets, logs)
   never break the mobile layout. Wrap existing <table> markup with
   <div class="table-responsive-az">...</div> — Bootstrap's .table-responsive
   already does this too; this just adds a scroll hint + sticky first col. */
.table-responsive-az { overflow-x: auto; -webkit-overflow-scrolling: touch; border-radius: var(--radius-card); }
.table-responsive-az table { min-width: 640px; }

/* Card-list fallback: add data-label to <td> and .table-az-cards to the
   table for a true "table becomes cards" transform below 576px. */
@media (max-width: 576px) {
  table.table-az-cards, table.table-az-cards thead, table.table-az-cards tbody,
  table.table-az-cards th, table.table-az-cards td, table.table-az-cards tr { display: block; }
  table.table-az-cards thead { display: none; }
  table.table-az-cards tr {
    background: var(--bg-card); border-radius: var(--radius-card);
    box-shadow: var(--shadow-soft); margin-bottom: var(--space-3); padding: var(--space-3);
  }
  table.table-az-cards td {
    display: flex; justify-content: space-between; align-items: center;
    padding: 8px 4px; border: none; text-align: right;
  }
  table.table-az-cards td::before {
    content: attr(data-label); font-weight: 600; color: var(--text-secondary);
    text-align: left; margin-right: 12px; font-size: 13px;
  }
}

/* ---------- 4. Responsive Forms ---------- */
@media (max-width: 767px) {
  .row > [class*="col-"] { margin-bottom: var(--space-3); }
  .form-row-az, .d-flex.gap-3:has(input) { flex-direction: column; }
  .auth-card { width: 100%; margin: 0 var(--space-3); }
}

/* ---------- 5. Responsive Navigation / Bottom Nav (Mobile UI) ---------- */
.bottom-nav-az {
  display: none;
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 1040;
  background: var(--bg-card); border-top: 1px solid rgba(0,0,0,0.06);
  padding: 6px max(6px, env(safe-area-inset-left)) calc(6px + env(safe-area-inset-bottom));
  box-shadow: 0 -6px 20px rgba(31,41,55,0.08);
}
@media (max-width: 767px) {
  .bottom-nav-az.is-enabled { display: flex; justify-content: space-around; align-items: center; }
  body.has-bottom-nav { padding-bottom: 64px; }
}
.bottom-nav-az a {
  display: flex; flex-direction: column; align-items: center; gap: 2px;
  font-size: 11px; color: var(--text-muted); text-decoration: none; min-width: 56px; padding: 6px 0;
}
.bottom-nav-az a i { font-size: 20px; }
.bottom-nav-az a.active { color: var(--color-purple); }

/* ---------- 6. Optimized Cards (mobile) ---------- */
@media (max-width: 480px) {
  .card, .stat-card, .service-card { border-radius: var(--radius-sm); }
  .h-page { font-size: 24px; }
  .h-section { font-size: 22px; }
}

/* ---------- 6b. Dashboard / Admin Stat Cards — Chapter 52.6 fix (v2) ----------
   v1 only shrank the icon/font while keeping icon-beside-number (row)
   layout — on real narrow phones the text column left over next to the
   icon was so thin that even "PKR" itself had no room to sit on one
   line, and word-break:break-word chopped it mid-letter into "PK"/"R"/
   "1,2"/"50."/"00" fragments instead of overflowing OR wrapping cleanly.
   Fix: stack icon-above-value on mobile so the number gets the card's
   FULL width to wrap at natural word boundaries (worst case two clean
   lines, e.g. "PKR" / "1,250.00" — never mid-word). Also stretches both
   cards in a row to equal height so a 2-line card and a 1-line card
   still align instead of leaving a visible height gap. */
@media (max-width: 576px) {
  .card-az { padding: 14px; }
  .stat-card {
    display: flex; flex-direction: column; align-items: flex-start;
    gap: 6px; height: 100%;
  }
  .stat-card .stat-icon { width: 30px; height: 30px; font-size: 14px; border-radius: 9px; }
  .stat-card .stat-value {
    font-size: 16px; line-height: 1.25; font-weight: 700;
    word-break: normal; overflow-wrap: break-word; white-space: normal;
  }
  .stat-card .stat-label { font-size: 11.5px; line-height: 1.3; }
  .stat-card .small.text-muted-c { font-size: 10.5px; }
  /* Stretch each grid column so both cards in a row match height,
     regardless of whether one wraps to more lines than the other. */
  .row.g-3 > [class*="col-"]:has(> .stat-card),
  .row.g-4 > [class*="col-"]:has(> .stat-card) { display: flex; }
  .row.g-3 > [class*="col-"]:has(> .stat-card) > .stat-card,
  .row.g-4 > [class*="col-"]:has(> .stat-card) > .stat-card { width: 100%; min-height: 0; }
}
@media (max-width: 400px) {
  /* Narrowest phones (iPhone SE/Mini, small Androids at 320–400px). */
  .card-az { padding: 11px; }
  .stat-card { gap: 5px; }
  .stat-card .stat-icon { width: 26px; height: 26px; font-size: 13px; border-radius: 8px; }
  .stat-card .stat-value { font-size: 14.5px; }
  .stat-card .stat-label { font-size: 10.5px; }
}

/* ---------- 6c. App Header (Dashboard/Admin) — narrow mobile ----------
   Search is hidden below the sidebar breakpoint, leaving hamburger,
   currency, language, theme, notifications and the user chip in one row.
   Keep every item at a 44px hit area and prevent flex compression; only
   padding/gaps and the avatar glyph shrink on the narrowest phones. */
@media (max-width: 767px) {
  .app-header { min-width: 0; padding: 0 10px; gap: 6px; }
  .app-header > .hamburger-btn { flex: 0 0 44px; }
  .header-actions { min-width: 0; margin-left: auto; flex: 0 0 auto; gap: 6px; }
  .header-actions > * { min-width: 44px; flex: 0 0 44px; }
  .app-header .icon-btn { width: 44px; min-width: 44px; height: 44px; min-height: 44px; font-size: 16px; }
  .app-header #currencyToggleBtn { padding: 0 4px; font-size: 11px; }
  .header-actions .lang-switcher-btn {
    width: 44px; min-width: 44px; height: 44px; min-height: 44px;
    padding: 0 !important; gap: 1px; justify-content: center; font-size: 9px;
  }
  .header-actions .lang-switcher .lang-flag { font-size: 13px; }
  .header-actions .lang-switcher .lang-code { max-width: 24px; overflow: hidden; }
  .user-chip { width: 44px; min-width: 44px; min-height: 44px; justify-content: center; gap: 0; }
  .user-chip > div, .user-chip > i { display: none; }
  .user-chip .avatar { width: 36px; height: 36px; font-size: 13px; }
}
@media (max-width: 380px) {
  .app-header { padding: 0 6px; gap: 4px; }
  .header-actions { gap: 4px; }
  .user-chip .avatar { width: 34px; height: 34px; font-size: 12px; }
}

/* ---------- 7. Responsive Charts ---------- */
@media (max-width: 576px) {
  canvas { max-width: 100% !important; height: auto !important; }
  .chart-card { overflow-x: auto; }
}

/* ---------- 8. Loading Skeletons ---------- */
.skeleton {
  position: relative; overflow: hidden; background: var(--bg-secondary);
  border-radius: var(--radius-sm);
}
.skeleton::after {
  content: ""; position: absolute; inset: 0; transform: translateX(-100%);
  background: linear-gradient(90deg, transparent, rgba(255,255,255,0.55), transparent);
  animation: skeleton-shimmer 1.4s ease-in-out infinite;
}
[data-theme="dark"] .skeleton::after { background: linear-gradient(90deg, transparent, rgba(255,255,255,0.08), transparent); }
@keyframes skeleton-shimmer { 100% { transform: translateX(100%); } }
.skeleton-text { height: 14px; margin-bottom: 8px; width: 100%; }
.skeleton-text.short { width: 40%; }
.skeleton-card { height: 120px; width: 100%; }
.skeleton-avatar { width: 44px; height: 44px; border-radius: 50%; }

/* ---------- 9. Mobile Error Pages ---------- */
@media (max-width: 480px) {
  .error-page-az { padding: var(--space-6) var(--space-4); }
  .error-page-az .error-code { font-size: 56px; }
}

/* ---------- 10. PWA — Install Banner & Update Toast ---------- */
.pwa-install-banner {
  position: fixed; left: 12px; right: 12px; bottom: 12px; z-index: 1050;
  background: var(--bg-card); border-radius: var(--radius-card);
  box-shadow: var(--shadow-hover); padding: 14px 16px;
  display: flex; align-items: center; gap: 12px;
  transform: translateY(120%); transition: transform var(--duration-slow) var(--ease);
}
.pwa-install-banner.show { transform: translateY(0); }
.pwa-install-banner img { width: 40px; height: 40px; border-radius: 10px; flex-shrink: 0; }
.pwa-install-banner .pwa-copy { flex: 1; min-width: 0; }
.pwa-install-banner .pwa-copy strong { display: block; font-size: 14px; color: var(--text-primary); }
.pwa-install-banner .pwa-copy span { font-size: 12px; color: var(--text-secondary); }
.pwa-install-banner button { border: none; border-radius: var(--radius-btn); font-weight: 600; font-size: 13px; cursor: pointer; }
.pwa-install-banner .pwa-install-btn { background: var(--gradient-primary); color: #fff; height: 36px; padding: 0 14px; }
.pwa-install-banner .pwa-dismiss-btn { background: transparent; color: var(--text-muted); height: 36px; padding: 0 8px; }
@media (min-width: 576px) { .pwa-install-banner { left: auto; right: 20px; bottom: 20px; max-width: 340px; } }

.pwa-toast {
  position: fixed; top: 16px; left: 50%; transform: translateX(-50%) translateY(-120%);
  z-index: 1060; background: var(--text-primary); color: #fff; font-size: 13px;
  padding: 10px 18px; border-radius: 999px; box-shadow: var(--shadow-hover);
  transition: transform var(--duration-slow) var(--ease);
}
.pwa-toast.show { transform: translateX(-50%) translateY(0); }

/* ---------- 11. Dark Mode toggle floating button (public pages) ---------- */
.theme-toggle-fab {
  position: fixed; right: 16px; z-index: 1030;
  bottom: 16px;
  width: 44px; height: 44px; border-radius: 50%;
  background: var(--bg-card); box-shadow: var(--shadow-card);
  border: 1px solid rgba(0,0,0,0.06);
  display: flex; align-items: center; justify-content: center;
  color: var(--text-primary); cursor: pointer;
}
body.has-bottom-nav .theme-toggle-fab { bottom: 76px; }

/* Floating WhatsApp support replaces the public floating theme switch. */
.whatsapp-support-fab{position:fixed;right:18px;bottom:22px;z-index:1040;display:flex;align-items:center;gap:9px;padding:13px 17px;border-radius:999px;background:#20b95a;color:#fff!important;text-decoration:none!important;box-shadow:0 10px 28px rgba(20,155,75,.32);font-weight:700;transition:transform .2s,box-shadow .2s}
.whatsapp-support-fab:hover{transform:translateY(-2px);box-shadow:0 14px 32px rgba(20,155,75,.4)}
.whatsapp-support-fab i{font-size:22px;line-height:1}
body.has-bottom-nav .whatsapp-support-fab{bottom:82px}
.live-service-card,.digital-showcase-card{padding:18px;display:flex;flex-direction:column;gap:12px;border:1px solid rgba(var(--color-purple-rgb),.14)}
.live-service-heading{display:flex;align-items:center;gap:11px;min-width:0}
.live-service-heading img{width:44px;height:44px;object-fit:contain;border-radius:12px;flex:0 0 44px;background:#fff}
.live-service-heading h3,.digital-showcase-card h3{font-size:16px;line-height:1.3;margin:0;font-weight:750;color:var(--text-primary)}
.live-service-title{flex:1;min-width:0}.live-service-title h3{overflow-wrap:anywhere}.service-id-badge{display:inline-flex;align-items:center;justify-content:center;flex:0 0 auto;min-height:24px;padding:3px 8px;border-radius:999px;background:#f0edff;color:#5b43d6;font-size:10.5px;font-weight:800;white-space:nowrap}
.live-service-heading span,.live-service-meta span{display:block;font-size:12px;color:var(--text-secondary);margin-top:3px}
.live-service-card p,.digital-showcase-card p{font-size:13px;line-height:1.55;color:var(--text-secondary);margin:0;flex:1}
.live-service-meta{display:flex;align-items:baseline;gap:6px;border-top:1px solid rgba(var(--color-purple-rgb),.12);padding-top:10px}
.live-service-meta strong,.digital-showcase-card strong{font-size:17px;color:var(--color-purple)}
.digital-showcase-card>img{width:100%;aspect-ratio:4/3;object-fit:cover;border-radius:12px;background:var(--bg-secondary)}
.digital-showcase-card>div{display:flex;flex-direction:column;gap:8px;flex:1}
@media(max-width:575.98px){.whatsapp-support-fab{width:50px;height:50px;padding:0;justify-content:center;bottom:14px}.whatsapp-support-fab span{display:none}body.has-bottom-nav .whatsapp-support-fab{bottom:68px}.live-service-card,.digital-showcase-card{padding:12px;gap:9px}.live-service-heading{align-items:flex-start;gap:8px}.live-service-heading img{width:36px;height:36px;flex-basis:36px}.live-service-heading h3,.digital-showcase-card h3{font-size:14px}.live-service-card p,.digital-showcase-card p{font-size:12px}.live-service-meta strong,.digital-showcase-card strong{font-size:15px}.live-service-card .btn,.digital-showcase-card .btn{font-size:12px;padding-inline:8px}}
.digital-promo-art{position:relative;width:178px;height:112px;margin:18px 0 8px;display:grid;place-items:center}
.digital-promo-orbit{position:absolute;width:145px;height:80px;border:1px solid rgba(255,255,255,.36);border-radius:50%;transform:rotate(-18deg)}
.digital-promo-core,.digital-promo-tile{position:absolute;display:grid;place-items:center;color:#fff;box-shadow:0 12px 28px rgba(0,0,0,.22)}
.digital-promo-core{width:64px;height:64px;border-radius:20px;background:linear-gradient(135deg,#7c4dff,#d12add);font-size:28px;z-index:2}
.digital-promo-tile{width:39px;height:39px;border-radius:12px;background:linear-gradient(135deg,#ff9a28,#f03b8c);font-size:18px}
.digital-promo-tile.tile-one{left:12px;top:18px;transform:rotate(-12deg)}.digital-promo-tile.tile-two{right:11px;top:8px;transform:rotate(12deg);background:linear-gradient(135deg,#28b8d8,#6657f5)}.digital-promo-tile.tile-three{right:24px;bottom:3px;transform:rotate(9deg);background:linear-gradient(135deg,#9d44ee,#f145a2)}

/* ---------- 12. Reduced-data / performance-conscious image sizing ---------- */
img { max-width: 100%; height: auto; }

/* ---------- 13. Landscape Mode Support (phones/tablets) ---------- */
/* Short, wide viewports (rotated phones) need slimmer fixed chrome so
   fixed bottom nav / floating buttons don't eat too much of the limited
   vertical space. Targets landscape phones specifically (not tablets/desktop
   in landscape, which already have plenty of height). */
@media (max-width: 900px) and (orientation: landscape) {
  .bottom-nav-az { padding-top: 4px; padding-bottom: max(4px, env(safe-area-inset-bottom)); }
  .bottom-nav-az a { font-size: 10px; padding: 4px 0; }
  .bottom-nav-az a i { font-size: 17px; }
  body.has-bottom-nav { padding-bottom: 48px; }

  .theme-toggle-fab { width: 38px; height: 38px; bottom: 10px; }
  body.has-bottom-nav .theme-toggle-fab { bottom: 56px; }
  body.has-bottom-nav .whatsapp-support-fab { bottom: 60px; }

  .pwa-install-banner { padding: 10px 14px; }
  .pwa-install-banner img { width: 32px; height: 32px; }

  /* Modals/offcanvas panels should scroll within the viewport height rather
     than overflow off-screen when landscape height is short. */
  .modal-az, .offcanvas, .modal-dialog { max-height: 92vh; overflow-y: auto; }

  /* Auth cards (login/register/forgot-password) are tall by default —
     let them shrink and scroll instead of clipping on short landscape screens. */
  .auth-card { max-height: 92vh; overflow-y: auto; }
}

/* Landscape-specific safe-area padding for notched devices (iPhone) so
   content isn't obscured by the sensor housing / rounded corners when rotated. */
@media (orientation: landscape) {
  .container-az, .app-shell { padding-left: max(var(--space-3, 14px), env(safe-area-inset-left)); padding-right: max(var(--space-3, 14px), env(safe-area-inset-right)); }
}
