/* =================================================================
   ORGAFUND — Responsive Enhancement Layer
   -----------------------------------------------------------------
   Loaded after area-specific stylesheets. Adds:
   - Safe-area-inset (notch) support
   - Fluid typography with clamp()
   - 13" laptop optimizations (sidebar narrowing, container breathability)
   - CMS-style mobile bottom navigation bar
   - Touch-friendly tap targets
   - Horizontal scroll containment for filter bars and tables

   Design rule: this layer MUST NOT change colors, fonts, shadows, or
   visual identity. It only adjusts SIZING, SPACING, LAYOUT, and adds
   MOBILE-ONLY UI. Each area's --primary token drives the bottom nav
   accent so the design language of every panel is preserved.
   ================================================================= */

/* ----------------------------------------------------------------- */
/* 1. ROOT VARIABLES — mobile design tokens (per CMS pattern)        */
/* ----------------------------------------------------------------- */
:root {
  --of-mobile-tab-h: 64px;
  --of-mobile-header-h: 60px;
  --of-safe-top: env(safe-area-inset-top, 0px);
  --of-safe-bottom: env(safe-area-inset-bottom, 0px);
  --of-safe-left: env(safe-area-inset-left, 0px);
  --of-safe-right: env(safe-area-inset-right, 0px);
  --of-easing: cubic-bezier(0.32, 0.72, 0, 1);
  --of-easing-spring: cubic-bezier(0.34, 1.56, 0.64, 1);

  /* Public-site tokens (default green) — overridden by area body classes */
  --of-accent: #198754;
  --of-accent-deep: #145a32;
  --of-accent-soft: rgba(25, 135, 84, 0.12);
  --of-accent-contrast: #ffffff;
  --of-nav-bg: #ffffff;
  --of-nav-border: rgba(0, 0, 0, 0.06);
  --of-nav-shadow: 0 -4px 18px rgba(0, 0, 0, 0.06);
  --of-tab-fg: #6b7280;
  --of-tab-fg-active: #1f2937;
}

/* Area-specific theming — keeps each portal's color identity */
body.orgafund-admin {
  --of-accent: #0D47A1;
  --of-accent-deep: #08306B;
  --of-accent-soft: rgba(13, 71, 161, 0.10);
  --of-accent-contrast: #ffffff;
  --of-tab-fg: #6b7280;
  --of-tab-fg-active: #1a1a2e;
}

body.orgafund-hospital {
  --of-accent: #0D47A1;
  --of-accent-deep: #08306B;
  --of-accent-soft: rgba(13, 71, 161, 0.10);
  --of-accent-contrast: #ffffff;
  --of-tab-fg: #6b7280;
  --of-tab-fg-active: #1a1a2e;
}

body.orgafund-csr {
  --of-accent: #198754;
  --of-accent-deep: #145a32;
  --of-accent-soft: rgba(25, 135, 84, 0.12);
  --of-accent-contrast: #ffffff;
  --of-tab-fg: #6b7280;
  --of-tab-fg-active: #1a1a2e;
}

/* ----------------------------------------------------------------- */
/* 2. HTML/BODY BASE — touch ergonomics, safe-area, no zoom jolt     */
/* ----------------------------------------------------------------- */
html {
  -webkit-text-size-adjust: 100%;
  text-size-adjust: 100%;
  scroll-behavior: smooth;
}

body {
  -webkit-tap-highlight-color: transparent;
  -webkit-touch-callout: none;
}

/* Respect device safe areas on notch / dynamic-island devices */
body {
  padding-left: var(--of-safe-left);
  padding-right: var(--of-safe-right);
}

/* Touch feedback — gentle scale on tap for interactive elements */
@media (max-width: 991.98px) {
  a, button, .btn, .nav-link, [role="button"],
  .stat-card, .stat-card-mini, .widget-card,
  .leaderboard-row, .impact-card, .campaign-card,
  .mobile-menu-btn, .header-icon-btn, .tbl-btn,
  .filter-select, .form-select, .form-control {
    transition: transform 0.18s var(--of-easing), background-color 0.2s var(--of-easing), color 0.2s var(--of-easing), border-color 0.2s var(--of-easing), box-shadow 0.2s var(--of-easing);
  }
  a:active, button:active, .btn:active, .nav-link:active,
  .stat-card:active, .stat-card-mini:active, .impact-card:active,
  .leaderboard-row:active, .campaign-card:active,
  .mobile-menu-btn:active, .header-icon-btn:active, .tbl-btn:active {
    transform: scale(0.97);
  }
}

/* ----------------------------------------------------------------- */
/* 3. FLUID TYPOGRAPHY — scales gracefully from mobile to 4K         */
/* ----------------------------------------------------------------- */
.display-1 { font-size: clamp(2.5rem, 6vw, 4.5rem); }
.display-2 { font-size: clamp(2.25rem, 5.5vw, 4rem); }
.display-3 { font-size: clamp(2rem, 5vw, 3.5rem); }
.display-4 { font-size: clamp(1.75rem, 4.5vw, 3rem); }
.display-5 { font-size: clamp(1.5rem, 4vw, 2.5rem); }
.display-6 { font-size: clamp(1.35rem, 3.5vw, 2rem); }

.lead { font-size: clamp(1.05rem, 2vw, 1.25rem); }

.section-title {
  font-size: clamp(1.5rem, 3vw, 2.25rem);
  line-height: 1.15;
}

/* ----------------------------------------------------------------- */
/* 4. LAPTOP (992px – 1279px) — give 13" screens breathing room      */
/* ----------------------------------------------------------------- */
@media (min-width: 992px) and (max-width: 1279px) {
  /* Narrow sidebar on small laptops so content has more room */
  body.orgafund-admin .sidebar,
  body.orgafund-hospital .sidebar,
  body.orgafund-csr .sidebar {
    width: 220px;
  }
  body.orgafund-admin .main-content,
  body.orgafund-hospital .main-content,
  body.orgafund-csr .main-content {
    margin-left: 220px;
  }

  /* Tighter dashboard padding on small laptops */
  .dashboard-content,
  .page-content {
    padding: 20px 22px 32px;
  }

  /* Header search bar slim down */
  .header-search input {
    max-width: 200px;
    width: 100% !important;
  }

  /* Hero search and CTA group: smaller touch targets OK on laptop */
  .hero-section {
    padding: 80px 0;
  }
}

/* ----------------------------------------------------------------- */
/* 5. TABLET (768px – 991px) — sidebar already collapsed here        */
/*    Add bottom-nav breathing room and improve two-column layouts   */
/* ----------------------------------------------------------------- */
@media (min-width: 768px) and (max-width: 991.98px) {
  /* Tables get cramped on portrait iPad — let them scroll horizontally cleanly */
  .table-responsive {
    -webkit-overflow-scrolling: touch;
  }

  /* Page content side padding reduce slightly */
  .dashboard-content,
  .page-content {
    padding: 20px 18px 32px;
  }

  /* Hero — slightly less aggressive on tablet */
  .hero-section {
    padding: 70px 0;
  }

  /* Admin/Hospital dashboard: 2-col stat grid on tablet */
  .row.g-2 > .col-6.col-md-3,
  .row.g-3 > .col-6.col-md-3,
  .row.g-2 > .col-12.col-md-3,
  .row.g-3 > .col-12.col-md-3 {
    flex: 0 0 50%;
    max-width: 50%;
  }
}

/* ----------------------------------------------------------------- */
/* 6. MOBILE (< 768px) — bottom nav, touch sizing, safe-area         */
/* ----------------------------------------------------------------- */
@media (max-width: 767.98px) {
  /* Reserve space at the bottom for the fixed mobile nav */
  body.orgafund-has-bottom-nav {
    padding-bottom: calc(var(--of-mobile-tab-h) + var(--of-safe-bottom));
  }

  /* Containers slimmer on mobile */
  .container,
  .container-sm,
  .container-md,
  .container-lg,
  .container-xl {
    padding-left: 16px;
    padding-right: 16px;
  }

  /* Section padding clamped for vertical rhythm */
  section.py-5,
  .py-5 {
    padding-top: 2.25rem !important;
    padding-bottom: 2.25rem !important;
  }

  /* Hero: smaller, full-width, stacked CTAs */
  .hero-section {
    padding: 56px 0;
    text-align: left;
  }
  .hero-section .display-4 {
    font-size: clamp(1.9rem, 7vw, 2.4rem);
    line-height: 1.1;
  }
  .hero-section .lead {
    font-size: 1rem;
    line-height: 1.55;
  }
  .hero-section .row > div {
    width: 100%;
  }

  /* Forms on mobile — larger tap targets */
  .form-control,
  .form-select,
  input.form-control,
  select.form-select,
  textarea.form-control {
    min-height: 44px;
    font-size: 15px;
  }

  /* Buttons — minimum tap target 44px */
  .btn {
    min-height: 44px;
    font-size: 14px;
    padding: 10px 18px;
  }
  .btn-sm {
    min-height: 36px;
    font-size: 13px;
    padding: 6px 14px;
  }
  .btn-lg {
    min-height: 50px;
    font-size: 15px;
    padding: 12px 22px;
  }

  /* Tabs — let them scroll horizontally if they overflow */
  .nav-tabs {
    flex-wrap: nowrap;
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
    scrollbar-width: none;
    padding-bottom: 1px;
  }
  .nav-tabs::-webkit-scrollbar { display: none; }
  .nav-tabs .nav-item { flex: 0 0 auto; }
  .nav-tabs .nav-link { white-space: nowrap; padding: 10px 14px; }

  /* Tables — always scrollable horizontally on mobile */
  .table-responsive {
    -webkit-overflow-scrolling: touch;
    border-radius: var(--radius-sm, 10px);
  }

  /* Filter bars wrap into stacked rows */
  .filter-bar {
    flex-direction: column;
    align-items: stretch;
    gap: 8px;
  }
  .filter-bar .search-group {
    margin-left: 0;
    width: 100%;
  }

  /* Modal dialog fills more of the screen on mobile */
  .modal-dialog {
    margin: 12px;
  }
  .modal-content {
    border-radius: 14px;
  }

  /* Sticky-top donation card on Campaign Detail: stop being sticky on mobile */
  .sticky-top {
    position: static !important;
    top: auto !important;
  }

  /* Header logo: cap width so it never overflows */
  .navbar-brand img {
    max-width: 160px !important;
    height: 40px !important;
  }

  /* Public footer: stack columns cleanly */
  footer .row > [class*="col-"] {
    margin-bottom: 1.5rem;
  }

  /* Admin/Hospital dashboard: 2-col stat grid (was 4-col even at small) */
  .row.g-2 > .col-6.col-md-3,
  .row.g-3 > .col-6.col-md-3,
  .row.g-2 > .col-12.col-md-3,
  .row.g-3 > .col-12.col-md-3 {
    flex: 0 0 50%;
    max-width: 50%;
  }

  /* Page titles stack with actions */
  .page-title-row {
    flex-direction: column;
    align-items: stretch;
  }
  .page-actions {
    width: 100%;
    flex-wrap: wrap;
  }
  .page-actions .btn-primary-green,
  .page-actions .btn-outline-dark,
  .page-actions .btn-search,
  .page-actions form {
    flex: 1 1 auto;
    min-width: 0;
  }
  .page-actions .form-select {
    width: 100% !important;
  }

  /* Header padding slimmer */
  .main-header {
    padding: 0 14px !important;
    height: 56px !important;
  }
  .header-search { display: none !important; }
  .user-info { display: none !important; }
  .mobile-menu-btn {
    width: 40px;
    height: 40px;
    font-size: 18px;
    display: inline-flex !important;
    align-items: center;
    justify-content: center;
  }
}

/* Very small phones (< 380px) */
@media (max-width: 379.98px) {
  .container,
  .container-sm,
  .container-md,
  .container-lg,
  .container-xl {
    padding-left: 14px;
    padding-right: 14px;
  }

  .hero-section .display-4 {
    font-size: 1.75rem;
  }

  /* Stack stat grid as single column on tiny phones if too cramped */
  .row.g-2 > .col-6,
  .row.g-3 > .col-6 {
    flex: 0 0 100%;
    max-width: 100%;
  }
}

/* ----------------------------------------------------------------- */
/* 7. CMS-STYLE MOBILE BOTTOM NAVIGATION                             */
/*    Fixed bar with up to 4 quick-access tabs.                      */
/*    Each portal's tabs are configured in the layout .cshtml        */
/*    and styled here consistently with portal accent color.         */
/* ----------------------------------------------------------------- */
.orgafund-mobile-nav {
  display: none;
  position: fixed;
  left: 0;
  right: 0;
  bottom: 0;
  z-index: 1080;
  height: calc(var(--of-mobile-tab-h) + var(--of-safe-bottom));
  padding: 6px 6px calc(6px + var(--of-safe-bottom));
  background: var(--of-nav-bg);
  border-top: 1px solid var(--of-nav-border);
  box-shadow: var(--of-nav-shadow);
  backdrop-filter: saturate(180%) blur(20px);
  -webkit-backdrop-filter: saturate(180%) blur(20px);
  grid-template-columns: repeat(auto-fit, minmax(0, 1fr));
  align-items: stretch;
  gap: 2px;
}

/* Only show on mobile */
@media (max-width: 991.98px) {
  body.orgafund-has-bottom-nav .orgafund-mobile-nav {
    display: grid;
  }
}

.orgafund-mobile-nav__tab {
  position: relative;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 3px;
  padding: 4px 4px;
  min-height: 52px;
  color: var(--of-tab-fg);
  font-size: 10.5px;
  font-weight: 500;
  line-height: 1.15;
  letter-spacing: 0.02em;
  text-align: center;
  text-decoration: none;
  border: 0;
  background: transparent;
  cursor: pointer;
  -webkit-appearance: none;
  appearance: none;
  border-radius: 12px;
  transition: color 0.2s var(--of-easing), background-color 0.2s var(--of-easing), transform 0.18s var(--of-easing);
}

.orgafund-mobile-nav__tab i,
.orgafund-mobile-nav__tab svg {
  font-size: 18px;
  width: 18px;
  height: 18px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  transition: transform 0.3s var(--of-easing-spring);
}

.orgafund-mobile-nav__tab:active {
  transform: scale(0.92);
  background: var(--of-accent-soft);
}

.orgafund-mobile-nav__tab.is-active {
  color: var(--of-accent);
  font-weight: 600;
}

.orgafund-mobile-nav__tab.is-active i,
.orgafund-mobile-nav__tab.is-active svg {
  color: var(--of-accent);
  transform: translateY(-1px) scale(1.08);
}

.orgafund-mobile-nav__tab.is-active::before {
  content: '';
  position: absolute;
  top: 4px;
  width: 32px;
  height: 24px;
  border-radius: 999px;
  background: var(--of-accent-soft);
  z-index: -1;
}

.orgafund-mobile-nav__tab.is-active::after {
  content: '';
  position: absolute;
  bottom: 2px;
  width: 4px;
  height: 4px;
  border-radius: 50%;
  background: var(--of-accent);
}

/* Special "Menu" tab — opens the slide-in sidebar (admin/hospital/csr) */
.orgafund-mobile-nav__tab--menu {
  position: relative;
}
.orgafund-mobile-nav__tab--menu i {
  font-size: 17px;
}

/* Hide the body scroll when sidebar is open via mobile menu tap */
body.orgafund-sidebar-open {
  overflow: hidden;
}

/* ----------------------------------------------------------------- */
/* 8. CAMPAIGN DETAIL — sticky donation card behavior                */
/*    On laptops the sticky right column must not overlap the tabs.  */
/* ----------------------------------------------------------------- */
@media (min-width: 992px) and (max-width: 1199.98px) {
  /* Two-column Campaign Detail: reduce sticky column to a comfortable width */
  .col-lg-8 + .col-lg-4 {
    flex: 0 0 38%;
    max-width: 38%;
  }
}

/* On mobile, the donation card should sit naturally in flow (no overlap with bottom nav) */
@media (max-width: 991.98px) {
  .col-lg-4 .sticky-top {
    position: static !important;
    top: auto !important;
  }
}

/* ----------------------------------------------------------------- */
/* 9. PRINT + REDUCED MOTION — accessibility hygiene                  */
/* ----------------------------------------------------------------- */
@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.01ms !important;
    scroll-behavior: auto !important;
  }
}

/* ----------------------------------------------------------------- */
/* 10. helpers for horizontal-scroll chips on mobile                  */
/* ----------------------------------------------------------------- */
.of-chip-row {
  display: flex;
  flex-wrap: nowrap;
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
  scrollbar-width: none;
  gap: 8px;
  padding: 4px 0 8px;
}
.of-chip-row::-webkit-scrollbar { display: none; }
.of-chip-row > * {
  flex: 0 0 auto;
  white-space: nowrap;
}

/* Campaign feed: ensure cards are full-width on mobile (overridable) */
@media (max-width: 767.98px) {
  #campaign-feed-container .card,
  #campaign-feed-container [class*="col-"] {
    max-width: 100%;
  }
}

/* ----------------------------------------------------------------- */
/* 11. HOSPITAL FORM-CARD defensive overrides                         */
/*     The existing form-card.css shrinks inputs to 10px font and     */
/*     6px padding at 576px — unreadable and below tap-target min.    */
/*     We restore readable sizes without changing colors or layout.   */
/* ----------------------------------------------------------------- */
@media (max-width: 575.98px) {
  .fc-input,
  .fc-input.form-control,
  .fc-input.form-select {
    font-size: 14px !important;
    padding: 10px 12px !important;
    min-height: 44px;
  }
  .fc-group.form-floating > label,
  .fc-label {
    font-size: 12px !important;
  }
  .fc-input::placeholder {
    font-size: 13px;
  }
  .fc-card-body {
    padding: 16px 14px 20px;
  }
  .fc-row {
    flex-direction: column;
    gap: 0;
  }
}

/* ----------------------------------------------------------------- */
/* 12. CAMPAIGN DETAIL — donation card touch-target fixes (mobile)    */
/* ----------------------------------------------------------------- */
@media (max-width: 767.98px) {
  /* The donation form on the campaign detail page: keep inputs usable */
  .col-lg-4 .form-control,
  .col-lg-4 .form-select {
    min-height: 44px;
    font-size: 15px;
  }
  /* Tab content padding slimmer on mobile */
  .card-body.p-4 {
    padding: 16px !important;
  }
}

/* ----------------------------------------------------------------- */
/* 13. TOUCH SCROLL for filter bars and horizontal chip rows          */
/*     Allows momentum scrolling on iOS                               */
/* ----------------------------------------------------------------- */
.table-responsive,
.campaign-steps,
.products-filters,
.faq-sidebar,
.of-chip-row {
  -webkit-overflow-scrolling: touch;
  overscroll-behavior-x: contain;
}

/* Hide scrollbars on horizontal scroll containers (CMS-style) */
.campaign-steps::-webkit-scrollbar,
.products-filters::-webkit-scrollbar,
.faq-sidebar::-webkit-scrollbar {
  display: none;
}
.campaign-steps,
.products-filters,
.faq-sidebar {
  scrollbar-width: none;
}
