/* ==========================================================================
   CLEANCRED — RESPONSIVE ADAPTATIONS
   CleanCred UI Design System
   ========================================================================== */

/* Breakpoint: Laptop / Tablet (<= 1024px) */
@media (max-width: 1024px) {
  .desktop-dashboard-grid {
    grid-template-columns: 1fr;
  }

  .admin-sidebar {
    position: static;
  }

  .admin-metrics-row {
    grid-template-columns: repeat(2, 1fr);
  }
}

/* Breakpoint: Mobile Viewport (<= 768px) */
@media (max-width: 768px) {
  :root {
    --header-stack-height: calc(120px + env(safe-area-inset-top, 0px));
  }

  /* Prevent horizontal overflow globally */
  html,
  body {
    overflow-x: hidden;
    max-width: 100vw;
  }

  /* Safe container guttering */
  .app-container {
    padding-left: 16px;
    padding-right: 16px;
    max-width: 100%;
    box-sizing: border-box;
  }

  /* Top Municipal Navigation Bar */
  .app-topbar,
  .silicone-topbar {
    min-height: 64px;
    height: auto;
    padding-left: 16px;
    padding-right: 16px;
    padding-top: env(safe-area-inset-top, 0px);
    padding-bottom: 6px;
    box-sizing: border-box;
  }

  .topbar-content {
    overflow: hidden;
  }

  /* Hide center role switcher in topbar row (moved to .mobile-role-strip) */
  .topbar-content .role-switcher-nav {
    display: none;
  }

  .brand-badge {
    display: none; /* Hide SBM-U 2.0 pill on mobile */
  }

  .demo-reset-btn {
    display: none; /* Hide demo reset from topbar on mobile */
  }

  .topbar-profile-btn span {
    display: none; /* Icon-only profile button on mobile */
  }

  .topbar-profile-btn {
    padding: 0.4rem 0.6rem;
  }

  .points-pill-top {
    padding: 0.38rem 0.75rem;
    gap: 0.35rem;
  }

  .points-pill-top span {
    font-size: 0.82rem; /* Keep points clearly visible */
  }

  /* Mobile Role Switcher Strip: Situated directly beneath topbar inside header stack */
  .mobile-role-strip {
    display: flex;
    justify-content: center;
    position: relative;
    width: 100%;
    background: var(--bg-surface);
    padding: 6px 16px 8px 16px;
    box-shadow: 0 4px 10px rgba(0, 0, 0, 0.04);
    border-bottom: 1px solid var(--color-border);
    box-sizing: border-box;
  }

  /* Main Content Offset: Dynamically self-correcting below header stack */
  .main-content {
    margin-top: var(--header-stack-height, calc(120px + env(safe-area-inset-top, 0px)));
    padding-bottom: calc(90px + env(safe-area-inset-bottom, 0px));
  }

  /* Mobile Primary CTA Button */
  .mobile-primary-cta-container {
    display: block;
    margin: 1.25rem 0;
    width: 100%;
  }

  /* Tactile Hero Scan Component (AI Pre-Check) */
  .hero-scan-circle-container {
    margin: 1.5rem auto 1.75rem auto;
  }

  .btn-hero-scan-circular {
    width: 165px;
    height: 165px;
    padding: 0.75rem;
    border-width: 3.5px;
    box-shadow: 7px 7px 18px var(--shadow-dark), -6px -6px 14px var(--shadow-light);
  }

  .scan-icon-bubble {
    width: 48px;
    height: 48px;
    margin-bottom: 0.35rem;
  }

  .scan-icon-bubble svg {
    width: 22px;
    height: 22px;
  }

  .scan-btn-label {
    font-size: 0.85rem;
    letter-spacing: 0.06em;
  }

  .scan-btn-sublabel {
    font-size: 0.65rem;
  }

  .scan-supporting-note {
    font-size: 0.75rem;
    margin-top: 0.65rem;
    max-width: 290px;
  }

  .scan-supporting-note .desktop-note {
    display: none;
  }

  .scan-supporting-note .mobile-note {
    display: inline;
  }

  /* Credits Hero Card */
  .hero-points-card {
    padding: 1.25rem 1rem;
    border-radius: 16px;
    margin-bottom: 1.25rem;
  }

  .points-oversized-value {
    font-size: 2.6rem;
    margin: 0.25rem 0 0.5rem 0;
  }

  /* Active Pickup Card (Vertical Stacking) */
  .pickup-status-card {
    display: flex;
    flex-direction: column;
    align-items: stretch;
    gap: 0.85rem;
    padding: 1.15rem 1rem;
    margin-bottom: 1.25rem;
    border-radius: 16px;
  }

  .pickup-status-info {
    min-width: 0;
    width: 100%;
  }

  .pickup-status-actions {
    display: flex;
    flex-direction: column;
    align-items: stretch;
    width: 100%;
    gap: 0.65rem;
  }

  .pickup-status-actions .btn {
    width: 100%;
    justify-content: center;
  }

  .pickup-otp-pill {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0.5rem 1rem;
    width: 100%;
    box-sizing: border-box;
  }

  /* Dashboard Metrics Grid (2-Column Compact) */
  .dashboard-metrics-grid {
    grid-template-columns: repeat(2, 1fr);
    gap: 0.75rem;
    margin-bottom: 1.5rem;
  }

  .metric-card {
    padding: 0.85rem 0.75rem;
    border-radius: 14px;
  }

  .metric-card span {
    font-size: 0.72rem;
    margin-bottom: 0.2rem;
  }

  .metric-card strong {
    font-size: 1.45rem;
  }

  .metric-card em {
    font-size: 0.7rem;
  }

  /* Standardized Mobile Card Sizing & Padding */
  .neu-card,
  .neu-card-raised,
  .neu-card-flat {
    padding: 1.15rem 1rem;
    border-radius: 16px;
    box-shadow: var(--neu-raised-sm);
  }

  .neu-card .flex-between,
  .neu-card-raised .flex-between,
  .neu-card-flat .flex-between {
    flex-wrap: wrap;
    gap: 0.5rem;
  }

  /* Step 2 Demo Picker: Horizontal Scroll Row & Upload Button */
  .btn-upload-photo {
    width: 100%;
    max-width: 100%;
    justify-content: center;
  }

  .demo-picker-grid {
    display: flex;
    overflow-x: auto;
    scroll-snap-type: x mandatory;
    gap: 0.75rem;
    padding-bottom: 0.5rem;
    -webkit-overflow-scrolling: touch;
  }

  .demo-thumb-btn {
    min-width: 120px;
    flex-shrink: 0;
    scroll-snap-align: start;
  }

  /* Surreal Background Blobs Calming on Mobile (prevent horizontal stretch & jitter) */
  .surreal-blob {
    animation: none;
    filter: blur(40px);
    opacity: 0.16;
  }
  .surreal-blob-green {
    width: 180px;
    height: 180px;
    left: 0;
    top: 2%;
  }
  .surreal-blob-cyan {
    width: 180px;
    height: 180px;
    right: 0;
    top: 45%;
  }
  .surreal-blob-orange {
    width: 160px;
    height: 160px;
    bottom: 2%;
    left: 5%;
  }

  /* Modals: Guaranteed Viewport Fit */
  .modal-overlay,
  .modal-overlay-backdrop {
    padding: 12px;
  }

  .modal-content,
  .neu-modal,
  .celebration-reward-card {
    max-width: calc(100vw - 24px);
    max-height: calc(100vh - 24px);
    padding: 1.25rem 1rem;
    border-radius: var(--radius-lg);
    box-sizing: border-box;
    overflow-y: auto;
  }

  .scan-viewfinder-modal {
    width: calc(100vw - 32px);
    max-width: 360px;
    padding: 1.25rem 1rem;
  }

  .camera-preview-box {
    max-height: 200px;
  }

  /* Mobile Bottom Navigation Dock (Solid Matte Neumorphic) */
  .mobile-bottom-dock {
    display: flex;
    position: fixed;
    bottom: 0;
    left: 0;
    right: 0;
    width: 100%;
    height: calc(64px + env(safe-area-inset-bottom, 0px));
    padding-bottom: env(safe-area-inset-bottom, 0px);
    background: var(--bg-surface);
    border-top: 1px solid var(--color-border);
    box-shadow: 0 -4px 14px var(--shadow-dark), 0 -1px 0 var(--color-border-highlight);
    align-items: center;
    justify-content: space-between;
    padding-left: 8px;
    padding-right: 8px;
    z-index: 1000;
    box-sizing: border-box;
  }

  .dock-nav-group {
    display: flex;
    align-items: center;
    flex: 1;
    justify-content: space-around;
  }

  .dock-item-btn {
    flex: 1;
    min-height: 48px;
    padding: 0.4rem 0.2rem;
    gap: 0.25rem;
    font-size: 0.7rem;
    font-weight: 500;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    background: transparent;
    border: none;
    color: var(--text-muted);
    cursor: pointer;
    touch-action: manipulation;
  }

  .dock-item-btn.active {
    color: var(--color-primary);
  }

  .dock-item-btn svg {
    width: 20px;
    height: 20px;
  }

  .dock-center-slot {
    position: relative;
    width: 64px;
    height: 64px;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: flex-end;
    padding-bottom: 6px;
    flex-shrink: 0;
  }

  .dock-floating-fab {
    position: absolute;
    top: -22px;
    left: 50%;
    transform: translateX(-50%);
    width: 52px;
    height: 52px;
    border-radius: 50%;
    background: var(--color-primary);
    color: #FFFFFF;
    border: 3px solid var(--bg-surface);
    box-shadow: 0 6px 18px rgba(5, 150, 105, 0.45), 0 2px 6px rgba(0, 0, 0, 0.15);
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    touch-action: manipulation;
    z-index: 1005;
  }

  .dock-floating-fab:active {
    transform: translateX(-50%) scale(0.94);
  }

  .dock-floating-fab svg {
    width: 24px;
    height: 24px;
    stroke: #FFFFFF;
    stroke-width: 2.5;
  }

  .dock-fab-label {
    font-size: 0.65rem;
    font-weight: 600;
    color: var(--text-muted);
    letter-spacing: 0.02em;
    margin-top: auto;
  }

  /* Rewards Overview Grid (Mobile composition) */
  .rewards-overview-grid {
    grid-template-columns: 1fr 1fr;
    gap: 0.85rem;
  }

  .rewards-card-primary {
    grid-column: span 2;
    padding: 1.35rem 1.15rem;
  }

  .rewards-card-compact {
    padding: 1rem 0.85rem;
  }

  .rewards-card-amount {
    font-size: 2.2rem;
  }

  .rewards-card-actions {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 0.75rem;
    width: 100%;
  }

  .rewards-card-actions .btn {
    width: 100%;
    min-height: 44px;
    justify-content: center;
    box-sizing: border-box;
  }

  .rewards-catalog-grid {
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 0.85rem;
  }

  .rewards-avg-text {
    display: none;
  }

  .rewards-cat-desc-full {
    display: none;
  }

  .rewards-cat-desc-short {
    display: inline;
  }

  .rewards-tx-row {
    padding: 0.75rem 0.65rem;
    gap: 0.5rem;
  }

  .rewards-tx-info {
    flex: 1 1 100%;
  }

  .rewards-tx-amount {
    width: 100%;
    display: flex;
    justify-content: space-between;
    align-items: baseline;
    border-top: 1px dashed var(--color-border);
    padding-top: 0.4rem;
    margin-top: 0.2rem;
  }

  /* Impact Analytics (Mobile Layout) */
  .impact-header {
    margin-bottom: 1.5rem;
  }

  .impact-header-desc,
  .impact-lifecycle-desc {
    display: none;
  }

  .impact-title .title-full {
    display: none;
  }

  .impact-title .title-short {
    display: inline;
  }

  .impact-header-btn {
    width: 100%;
    min-height: 44px;
    justify-content: center;
  }

  .impact-header-btn .btn-text-full {
    display: none;
  }

  .impact-header-btn .btn-text-short {
    display: inline;
  }

  .impact-metric-label .label-full {
    display: none;
  }

  .impact-metric-label .label-short {
    display: inline;
  }

  .impact-metric-grid {
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 0.85rem;
    margin-bottom: 1.75rem;
  }

  .impact-metric-card {
    padding: 1.15rem 0.95rem;
  }

  .impact-breakdown-card {
    padding: 1.25rem 1rem;
    margin-bottom: 1.75rem;
  }

  .impact-breakdown-grid {
    grid-template-columns: 1fr;
    gap: 1rem;
  }

  .impact-lifecycle-item {
    padding: 1.15rem 1rem;
  }

  /* Institutions Portal (Mobile Layout) */
  .institution-title .title-full {
    display: none;
  }

  .institution-title .title-short {
    display: inline;
  }

  .institution-subtitle .desc-full {
    display: none;
  }

  .institution-subtitle .desc-short {
    display: inline;
  }

  .institution-header-btn .btn-text-full {
    display: none;
  }

  .institution-header-btn .btn-text-short {
    display: inline;
  }
  .institution-tab-grid {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 0.6rem;
    overflow-x: visible;
    padding-bottom: 0;
    margin-bottom: 1.5rem;
  }

  .institution-tab-grid .btn {
    width: 100%;
    min-height: 44px;
    white-space: normal;
    padding: 0.6rem 0.5rem;
    font-size: 0.82rem;
    justify-content: center;
    box-sizing: border-box;
  }

  .institution-tab-grid .btn:last-child {
    grid-column: span 2;
  }

  .institution-tab-grid .tab-label-full {
    display: none;
  }

  .institution-tab-grid .tab-label-short {
    display: inline;
  }

  .institution-showcase-card {
    padding: 1.25rem 1rem;
    margin-bottom: 1.5rem;
  }

  .institution-feature-grid {
    grid-template-columns: 1fr;
    gap: 0.85rem;
    margin-bottom: 1.5rem;
  }

  .institution-feature-item {
    padding: 1rem;
  }

  .institution-action-btn {
    width: 100%;
    min-height: 44px;
    justify-content: center;
  }

  .institution-modal-metrics {
    padding: 1rem 0.6rem;
    gap: 0.5rem;
  }

  /* Mobile Modals: Rewards */
  #recharge-modal .modal-content,
  #bills-modal .modal-content {
    width: calc(100vw - 24px) !important;
    max-width: 100% !important;
    max-height: calc(100vh - 24px) !important;
    overflow-y: auto !important;
    padding: 1.5rem 1.15rem !important;
    box-sizing: border-box !important;
  }

  /* Mobile Modals: Impact & Institutions Certificates */
  #impact-cert-modal .modal-content,
  #certificate-modal .modal-content {
    width: calc(100vw - 32px) !important;
    max-width: 100% !important;
    max-height: calc(100vh - 32px) !important;
    overflow-y: auto !important;
    padding: 1.5rem 1.15rem !important;
    box-sizing: border-box !important;
  }

  /* Mobile Gutters (16px) */
  .rewards-container,
  .impact-container,
  .institution-container {
    padding-left: 16px !important;
    padding-right: 16px !important;
    padding-top: 1.25rem !important;
    padding-bottom: 4rem !important;
  }

  /* Global Dual-State Utility Activation (Mobile) */
  .desc-short,
  .title-short,
  .label-short,
  .btn-text-short,
  .tab-label-short {
    display: inline;
  }

  .desc-full,
  .title-full,
  .label-full,
  .btn-text-full,
  .tab-label-full {
    display: none;
  }

  /* Municipal Command Center (Admin View) */
  .admin-sidebar {
    display: none;
  }

  .command-tools-section {
    display: block;
  }

  .admin-page-title {
    font-size: clamp(1.3rem, 5.5vw, 1.85rem);
    line-height: 1.2;
    letter-spacing: -0.02em;
  }

  .admin-page-subtitle {
    font-size: 0.82rem;
  }

  .admin-metrics-row {
    grid-template-columns: 1fr;
  }

  .view-section.active {
    width: 100%;
    max-width: 100%;
    min-width: 0;
    box-sizing: border-box;
  }

  .desktop-dashboard-grid {
    grid-template-columns: 1fr;
    min-width: 0;
    max-width: 100%;
  }

  .desktop-dashboard-grid > * {
    min-width: 0;
    max-width: 100%;
  }

  .hero-grid,
  .hero-grid-admin,
  .hero-grid-profile,
  .hero-grid-dumping,
  .hero-grid-landing,
  .hero-grid-leaderboard,
  .hero-grid-2col {
    grid-template-columns: 1fr;
    min-width: 0;
    max-width: 100%;
  }

  .grid-cols-2,
  .grid-cols-3,
  .grid-cols-4 {
    grid-template-columns: 1fr;
    min-width: 0;
    max-width: 100%;
  }

  .hero-grid > *,
  .hero-grid-admin > *,
  .hero-grid-profile > *,
  .hero-grid-dumping > *,
  .hero-grid-landing > *,
  .hero-grid-leaderboard > *,
  .hero-grid-2col > *,
  .grid-cols-2 > *,
  .grid-cols-3 > *,
  .grid-cols-4 > * {
    min-width: 0;
    max-width: 100%;
  }

  canvas {
    max-width: 100%;
  }

  .btn-block {
    display: flex;
    width: 100%;
  }
}

/* Breakpoint: Compact Mobile (<= 360px e.g. Galaxy S8, Xperia, etc.) */
@media (max-width: 360px) {
  .rewards-container,
  .impact-container,
  .institution-container {
    padding-left: 12px !important;
    padding-right: 12px !important;
    padding-top: 1rem !important;
    padding-bottom: 3.5rem !important;
  }
}

/* Breakpoint: Ultra-Compact Screen (<= 340px e.g. 320px iPhone SE 1st Gen) */
@media (max-width: 340px) {
  .rewards-overview-grid {
    grid-template-columns: 1fr;
  }

  .rewards-card-primary,
  .rewards-card-compact {
    grid-column: span 1;
  }

  .rewards-card-actions {
    grid-template-columns: 1fr;
  }

  .rewards-catalog-grid {
    grid-template-columns: 1fr;
  }

  .impact-metric-grid {
    grid-template-columns: 1fr;
  }

  .institution-tab-grid {
    grid-template-columns: 1fr;
  }

  .institution-tab-grid .btn:last-child {
    grid-column: span 1;
  }

  .institution-modal-metrics {
    flex-direction: column;
    gap: 0.75rem;
  }
}

/* Breakpoint: Small Mobile (<= 480px) */
@media (max-width: 480px) {
  .dashboard-heading {
    margin-bottom: 1rem;
  }

  .btn-hero-scan-circular {
    width: 155px;
    height: 155px;
  }

  .points-oversized-value {
    font-size: 2.35rem;
  }

  .waste-options-grid {
    grid-template-columns: 1fr;
  }
}

/* Breakpoint: Ultra-Compact Mobile (<= 360px e.g. iPhone SE 1st Gen) */
@media (max-width: 360px) {
  .app-container {
    padding-left: 12px;
    padding-right: 12px;
  }

  .btn-hero-scan-circular {
    width: 148px;
    height: 148px;
    padding: 0.5rem;
  }

  .scan-icon-bubble {
    width: 40px;
    height: 40px;
    margin-bottom: 0.25rem;
  }

  .scan-icon-bubble svg {
    width: 18px;
    height: 18px;
  }

  .scan-btn-label {
    font-size: 0.78rem;
  }

  .scan-btn-sublabel {
    font-size: 0.6rem;
  }

  .points-pill-top {
    padding: 0.35rem 0.55rem;
  }

  .points-pill-top span {
    font-size: 0.75rem;
  }

  .points-oversized-value {
    font-size: 2.1rem;
  }

  .dashboard-metrics-grid {
    grid-template-columns: 1fr;
  }
}
