/**
 * Wareed — site-wide responsive overrides (mobile-first)
 * Loaded after style.css. Does not change colors or fonts.
 */

/* —— Mobile nav drawer base —— */
.nav-backdrop {
  display: none;
  position: fixed;
  inset: 0;
  z-index: 1700;
  background: rgba(0, 0, 0, 0.6);
  border: none;
  padding: 0;
  cursor: pointer;
  opacity: 0;
  visibility: hidden;
  pointer-events: none;
  transition: opacity 0.3s ease, visibility 0.3s ease;
}
.nav-backdrop.open {
  opacity: 1;
  visibility: visible;
  pointer-events: auto;
}
.nav-drawer-header {
  display: none;
  align-items: center;
  justify-content: space-between;
  padding: 12px 4px 16px;
  border-bottom: 1px solid var(--border);
  margin-bottom: 8px;
}
.nav-drawer-title {
  font-weight: 800;
  font-size: var(--fs-lg);
  color: var(--wareed-dark);
}
.nav-drawer-close {
  width: 48px;
  height: 48px;
  min-width: 48px;
  min-height: 48px;
  border: none;
  border-radius: 12px;
  background: #f5f5f5;
  color: var(--wareed-dark);
  font-size: 1.4rem;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  justify-content: center;
}
.menu-toggle {
  display: none;
  align-items: center;
  justify-content: center;
  width: 48px;
  height: 48px;
  min-width: 48px;
  min-height: 48px;
  padding: 0;
  border-radius: 12px;
  background: #fff;
  border: 1px solid var(--border);
  font-size: 1.5rem;
  color: var(--wareed-dark);
  cursor: pointer;
  flex-shrink: 0;
  position: relative;
  z-index: 1200;
  -webkit-tap-highlight-color: transparent;
}

/* ========== Mobile (< 768px) ========== */
@media (max-width: 767px) {
  .menu-toggle { display: inline-flex; }

  .header-content {
    flex-wrap: nowrap;
    gap: var(--space-sm);
  }

  /* Hide tools in flow — they live inside the drawer nav */
  .header-content > .header-tools { display: none; }

  .nav-backdrop {
    display: block;
  }

  /* Physical right-edge drawer — fully off-screen when closed */
  #mainNav {
    position: fixed !important;
    top: 0 !important;
    right: 0 !important;
    left: auto !important;
    bottom: 0 !important;
    z-index: 1800 !important;
    width: min(85vw, 320px) !important;
    max-width: 320px !important;
    height: 100% !important;
    height: 100dvh !important;
    margin: 0 !important;
    padding: 16px 18px calc(24px + env(safe-area-inset-bottom, 0px)) !important;
    background: #fff !important;
    box-shadow: -8px 0 32px rgba(0, 0, 0, 0.18);
    display: flex !important;
    flex-direction: column !important;
    gap: 8px;
    overflow-y: auto;
    -webkit-overflow-scrolling: touch;
    transform: translateX(105%) !important;
    visibility: hidden !important;
    pointer-events: none !important;
    opacity: 1;
    transition: transform 0.3s ease, visibility 0.3s ease, opacity 0.25s ease !important;
    order: initial !important;
  }
  body.drawer-open #mainNav,
  #mainNav.open {
    transform: translateX(0) !important;
    visibility: visible !important;
    pointer-events: auto !important;
    opacity: 1;
  }
  #mainNav.drawer-animating {
    pointer-events: none !important;
  }
  #mainNav.drawer-condensing {
    /* JS sets opacity; keep at final position */
    transform: translateX(0) !important;
    visibility: visible !important;
  }
  #mainNav.drawer-scattering {
    transform: translateX(0) !important;
    visibility: visible !important;
  }

  .nav-drawer-header { display: flex; }

  #mainNav ul {
    display: flex;
    flex-direction: column;
    align-items: stretch;
    gap: 4px;
    width: 100%;
    padding: 8px 0;
    list-style: none;
  }
  #mainNav ul li { width: 100%; }
  #mainNav a {
    display: flex;
    align-items: center;
    min-height: 56px;
    padding: 12px 14px;
    font-size: 16px;
    border-radius: 12px;
    width: 100%;
  }
  #mainNav a::after { display: none; }
  #mainNav a:hover,
  #mainNav a.active { background: #fff5f5; }

  #mainNav .header-tools {
    display: flex !important;
    flex-direction: column;
    align-items: stretch;
    gap: 12px;
    margin-top: auto;
    padding-top: 16px;
    border-top: 1px solid var(--border);
    width: 100%;
  }
  #mainNav .lang-switch {
    width: 100%;
    justify-content: stretch;
  }
  #mainNav .lang-btn {
    flex: 1;
    min-height: 44px;
    font-size: 16px;
  }
  #mainNav .status-chip {
    text-align: center;
    width: 100%;
    box-sizing: border-box;
  }

  body.drawer-open { overflow: hidden; }

  /* Hero */
  .hero {
    padding: clamp(16px, 4vw, 40px) 0;
    min-height: auto;
  }
  .hero-layout {
    grid-template-columns: 1fr !important;
    gap: var(--space-lg);
    text-align: center;
  }
  .hero h1 {
    font-size: clamp(28px, 8vw, 42px) !important;
  }
  .hero p {
    font-size: clamp(16px, 4vw, 20px) !important;
    margin-inline: auto;
  }
  .hero-cta {
    flex-direction: column;
    align-items: stretch;
    gap: 12px;
    justify-content: center;
  }
  .hero-cta .btn {
    width: 100%;
    max-width: none;
  }
  .hero-visual img.hands {
    max-width: 100%;
    margin-inline: auto;
  }
  .hero-visual img.mark-float {
    width: 64px;
    height: 64px;
    inset-inline-start: 8px;
  }
  .brand-banner { margin-top: var(--space-md); }

  /* Sections */
  section { padding: var(--space-xl) 0; }
  .section-title { font-size: var(--fs-xl); margin-bottom: var(--space-lg); }

  /* Grids — single column */
  .grid,
  .counter-grid,
  .sponsors-grid,
  .team-grid,
  .library-grid,
  .research-project-grid,
  .research-survey-grid,
  .research-team-grid {
    grid-template-columns: 1fr !important;
    gap: clamp(12px, 3vw, 24px);
  }
  .card { padding: 20px; width: 100%; }
  .grid .card > div:first-child {
    font-size: clamp(40px, 10vw, 60px) !important;
  }

  /* Counter */
  .counter-section { padding: var(--space-xl) 0; }
  .counter-icon { font-size: 32px; }
  .counter-number { font-size: clamp(28px, 7vw, 40px) !important; }
  .counter-label { font-size: 14px; }

  /* Form */
  .form-container {
    max-width: 100%;
    padding: var(--space-md);
    border-radius: var(--radius-md);
  }
  .form-step-indicator { gap: 8px; margin-bottom: var(--space-md); }
  .step-dot {
    width: 28px;
    height: 28px;
    font-size: 13px;
  }
  .form-group input,
  .form-group select,
  .form-group textarea {
    font-size: 16px;
    min-height: 48px;
  }
  .form-section .btn,
  .qr-actions .btn {
    width: 100%;
    max-width: none;
  }
  .blood-type-option { flex: 1 1 calc(50% - 8px); min-width: 0; }
  .blood-type-option label { min-height: 48px; display: flex; align-items: center; justify-content: center; }

  /* Social 2x2 */
  .social-platforms-grid {
    grid-template-columns: repeat(2, minmax(0, 1fr)) !important;
    gap: 12px;
  }
  .social-platform-card { padding: 16px; }

  /* Footer */
  footer { padding: var(--space-xl) 0 var(--space-lg); text-align: center; }
  .footer-links {
    flex-direction: column;
    gap: 12px;
    align-items: center;
  }
  .footer-links a {
    min-height: 44px;
    display: inline-flex;
    align-items: center;
  }
  .footer-social-link {
    width: 48px !important;
    height: 48px !important;
  }

  /* Admin panel */
  #overlay-admin {
    padding: 12px 0;
  }
  #overlay-admin .container {
    width: 100%;
    max-width: 100%;
    padding: 0 var(--space-sm);
  }
  .admin-panel {
    max-width: 100%;
    padding: var(--space-md);
    border-radius: var(--radius-md);
  }
  .admin-tabs {
    display: flex;
    flex-wrap: nowrap;
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
    gap: 8px;
    padding-bottom: 8px;
    scrollbar-width: thin;
  }
  .admin-tab {
    flex: 0 0 auto;
    min-height: 44px;
    white-space: nowrap;
    font-size: 14px;
    padding: 10px 14px;
  }
  .admin-row {
    flex-direction: column;
    gap: 8px;
  }
  .admin-row input,
  .admin-row textarea,
  .admin-row select {
    width: 100%;
    min-height: 48px;
    font-size: 16px;
  }
  .admin-panel .btn {
    width: 100%;
  }
  .admin-mini-list,
  #adminSponsorsList,
  #adminTeamsList,
  #adminDonorsList,
  #libAdminList {
    display: flex;
    flex-direction: column;
    gap: 10px;
  }
  .admin-mini-list > *,
  #adminSponsorsList > *,
  #adminTeamsList > *,
  #adminDonorsList > *,
  #libAdminList > * {
    width: 100%;
    box-sizing: border-box;
  }

  /* Research */
  .research-hero {
    padding: clamp(40px, 8vw, 56px) 0 clamp(28px, 5vw, 40px);
  }
  .research-hero h1 {
    font-size: clamp(28px, 7vw, 40px) !important;
  }
  .research-stats-grid,
  .research-focus-grid {
    grid-template-columns: repeat(2, minmax(0, 1fr)) !important;
    gap: 12px;
  }
  .research-who-grid {
    grid-template-columns: 1fr !important;
  }
  .research-hero-actions {
    flex-direction: column;
    align-items: stretch;
  }
  .research-hero-actions .btn {
    width: 100%;
    max-width: none;
  }

  /* Library */
  .library-grid {
    grid-template-columns: 1fr !important;
  }
  .library-filters {
    flex-wrap: nowrap;
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
    gap: 8px;
    padding-bottom: 6px;
  }
  .library-filter {
    flex: 0 0 auto;
    min-height: 44px;
  }

  /* Floating buttons — clear admin toolbar */
  .floating-share {
    left: 16px;
    bottom: 16px;
  }
  .floating-share-toggle {
    width: 56px;
    height: 56px;
  }
  .research-fab {
    right: 16px;
    bottom: 16px;
    width: 56px;
    height: 56px;
  }
  body.wat-toolbar-visible .floating-share {
    bottom: calc(96px + env(safe-area-inset-bottom, 0px));
  }
  body.wat-toolbar-visible .research-fab {
    bottom: calc(96px + env(safe-area-inset-bottom, 0px));
  }

  /* Buttons general */
  .btn {
    min-height: 48px;
    font-size: 16px;
  }

  /* Prevent overflow from decorative blobs */
  .hero::before,
  .hero::after,
  .counter-section::before {
    max-width: 100vw;
  }
}

/* ========== Tablet (768px – 1023px) ========== */
@media (min-width: 768px) and (max-width: 1023px) {
  .menu-toggle { display: inline-flex; }

  .header-content {
    flex-wrap: wrap;
    gap: var(--space-sm);
  }

  #mainNav {
    display: flex !important;
    flex: 1 1 100%;
    order: 3;
    width: 100%;
    position: static;
    transform: none !important;
    height: auto;
    max-width: none;
    box-shadow: none;
    background: transparent;
    padding: 8px 0 0;
    overflow: visible;
  }
  .nav-drawer-header { display: none; }
  .nav-backdrop { display: none !important; }

  #mainNav ul {
    flex-direction: row;
    flex-wrap: wrap;
    justify-content: flex-start;
    gap: 10px 14px;
    width: 100%;
  }
  #mainNav a {
    min-height: 44px;
    display: inline-flex;
    align-items: center;
    font-size: var(--fs-sm);
  }

  body.drawer-open #mainNav {
    position: fixed !important;
    top: 0 !important;
    right: 0 !important;
    left: auto !important;
    bottom: 0 !important;
    z-index: 1800 !important;
    width: min(85vw, 320px) !important;
    max-width: 320px !important;
    background: #fff !important;
    padding: 16px 18px !important;
    box-shadow: -8px 0 32px rgba(0, 0, 0, 0.18);
    flex-direction: column !important;
    overflow-y: auto;
    order: initial !important;
    transform: translateX(0) !important;
    visibility: visible !important;
    pointer-events: auto !important;
  }
  body.drawer-open .nav-drawer-header { display: flex; }
  body.drawer-open .nav-backdrop,
  .nav-backdrop.open {
    display: block !important;
    opacity: 1;
    visibility: visible;
    pointer-events: auto;
  }
  body.drawer-open #mainNav ul {
    flex-direction: column;
  }
  body.drawer-open #mainNav a {
    min-height: 56px;
    width: 100%;
  }

  .hero-layout {
    grid-template-columns: 1fr !important;
    text-align: center;
  }
  .hero { padding: clamp(40px, 6vw, 64px) 0; }
  .hero-cta { justify-content: center; }

  .grid {
    grid-template-columns: repeat(2, 1fr) !important;
    gap: clamp(12px, 3vw, 24px);
  }
  .counter-grid {
    grid-template-columns: repeat(2, 1fr) !important;
  }
  .sponsors-grid {
    grid-template-columns: repeat(2, 1fr) !important;
  }
  .team-grid {
    grid-template-columns: repeat(2, 1fr) !important;
  }
  .social-platforms-grid {
    grid-template-columns: repeat(2, minmax(0, 1fr)) !important;
  }
  .research-stats-grid,
  .research-focus-grid {
    grid-template-columns: repeat(2, minmax(0, 1fr)) !important;
  }
  .research-who-grid {
    grid-template-columns: repeat(2, minmax(0, 1fr)) !important;
  }
  .form-container { max-width: 640px; }

  .admin-tabs {
    overflow-x: auto;
    flex-wrap: nowrap;
  }
}

/* ========== Laptop / Desktop (1024px+) ========== */
@media (min-width: 1024px) {
  .menu-toggle { display: none !important; }
  .nav-backdrop { display: none !important; }
  .nav-drawer-header { display: none !important; }

  #mainNav {
    display: flex !important;
    position: static;
    transform: none !important;
    width: auto;
    height: auto;
    max-width: none;
    flex: 1;
    align-items: center;
    justify-content: flex-end;
    gap: 16px;
    padding: 0;
    background: transparent;
    box-shadow: none;
    overflow: visible;
  }
  #mainNav ul {
    display: flex;
    flex-direction: row;
    flex-wrap: wrap;
    align-items: center;
    gap: 18px;
    justify-content: flex-end;
  }
  #mainNav a {
    min-height: auto;
    padding: 0;
    width: auto;
  }
  #mainNav .header-tools {
    display: flex;
    flex-direction: row;
    align-items: center;
    gap: 10px;
    margin-top: 0;
    padding-top: 0;
    border-top: none;
    width: auto;
  }

  .hero-layout {
    grid-template-columns: 1.15fr 0.85fr;
    text-align: start;
  }
  .hero {
    padding: clamp(40px, 6vw, 80px) 0;
  }
  .hero-cta {
    flex-direction: row;
    flex-wrap: wrap;
  }
  .hero-cta .btn {
    width: auto;
  }

  .grid {
    grid-template-columns: repeat(3, 1fr);
    gap: clamp(12px, 3vw, 24px);
  }
  .counter-grid {
    grid-template-columns: repeat(4, 1fr);
  }
  .sponsors-grid {
    grid-template-columns: repeat(4, 1fr);
  }
  .team-grid {
    grid-template-columns: repeat(3, 1fr);
  }
  .social-platforms-grid {
    grid-template-columns: repeat(4, minmax(0, 1fr));
  }
  .form-container {
    max-width: 600px;
    margin-inline: auto;
  }
  .research-stats-grid,
  .research-focus-grid {
    grid-template-columns: repeat(4, minmax(0, 1fr));
  }
  .research-who-grid {
    grid-template-columns: repeat(3, minmax(0, 1fr));
  }

  .floating-share {
    left: 24px;
    bottom: 24px;
  }
  .floating-share-toggle {
    width: 64px;
    height: 64px;
  }
  .research-fab {
    right: 24px;
    bottom: 24px;
    width: 64px;
    height: 64px;
  }
  body.wat-toolbar-visible .floating-share,
  body.wat-toolbar-visible .research-fab {
    bottom: calc(100px + env(safe-area-inset-bottom, 0px));
  }
}

/* ========== Ultra-wide ========== */
@media (min-width: 1920px) {
  .container { max-width: 1520px; }
}

/* Small phones tighten */
@media (max-width: 380px) {
  .brand-sub { display: none; }
  .logo-small-wrapper img { width: 36px; height: 36px; }
  .brand-title { font-size: 0.95rem; }
  .social-platforms-grid {
    grid-template-columns: 1fr 1fr !important;
  }
  .research-stats-grid,
  .research-focus-grid {
    grid-template-columns: 1fr 1fr !important;
  }
}

/* Overlay pages on mobile */
@media (max-width: 767px) {
  .overlay-page {
    padding: 16px 0;
  }
  .overlay-header {
    gap: 12px;
    margin-bottom: 16px;
  }
  .overlay-close {
    min-width: 44px;
    min-height: 44px;
  }
}

/* ========== Mobile overlap / modal / chat fixes ========== */
@media (max-width: 767px) {
  /* Overlays: full-screen solid modals */
  .overlay-page {
    position: fixed !important;
    inset: 0 !important;
    width: 100% !important;
    height: 100% !important;
    height: 100dvh !important;
    max-width: 100vw !important;
    z-index: 9999 !important;
    background: #fff !important;
    padding: calc(12px + env(safe-area-inset-top, 0px)) 12px calc(16px + env(safe-area-inset-bottom, 0px)) !important;
    overflow-y: auto !important;
    -webkit-overflow-scrolling: touch;
    overscroll-behavior: contain;
  }
  .overlay-page.active {
    display: block !important;
  }
  .overlay-header {
    position: sticky;
    top: 0;
    z-index: 2;
    background: #fff;
    padding: 8px 4px 12px;
    margin-bottom: 12px;
    align-items: center;
  }
  .overlay-close {
    width: 48px !important;
    height: 48px !important;
    min-width: 48px !important;
    min-height: 48px !important;
    flex-shrink: 0;
    border-radius: 12px;
    background: #f5f5f5;
    font-size: 1.35rem;
    display: inline-flex !important;
    align-items: center;
    justify-content: center;
  }
  .overlay-page .container {
    width: 100% !important;
    max-width: 100% !important;
    padding: 0 4px !important;
  }

  /* Share button: bottom-left */
  .floating-share,
  #floatingShare {
    position: fixed !important;
    bottom: calc(16px + env(safe-area-inset-bottom, 0px)) !important;
    left: 16px !important;
    right: auto !important;
    top: auto !important;
    width: auto !important;
    z-index: var(--z-floating-button, 900) !important;
  }
  .floating-share-toggle,
  #floatingShare .floating-share-toggle {
    width: 56px !important;
    height: 56px !important;
    min-width: 56px !important;
    min-height: 56px !important;
  }

  body.wat-toolbar-visible .floating-share {
    bottom: calc(96px + env(safe-area-inset-bottom, 0px)) !important;
  }

  body.modal-open .floating-share {
    visibility: hidden !important;
    pointer-events: none !important;
  }
  body.modal-open {
    overflow: hidden !important;
  }

  /* Touch targets */
  button, a.btn, input[type="submit"], .nav-btn, .admin-tab {
    min-height: 48px;
    padding: 12px 16px;
    font-size: 16px;
  }

  /* Drawer z-index */
  .nav-backdrop { z-index: 1700 !important; }
  #mainNav { z-index: 1800 !important; }

  /* Header: no overlap */
  .header-content {
    flex-wrap: nowrap !important;
    align-items: center;
    gap: 8px;
  }
  .logo-small-wrapper { min-width: 0; flex: 1 1 auto; }
  .menu-toggle { flex-shrink: 0; }

  /* Hero stack */
  .hero-layout {
    grid-template-columns: 1fr !important;
    gap: 20px;
  }
  .hero-visual { order: 2; }
  .hero-layout > div:first-child { order: 1; }

  /* Cards gap */
  .grid, .sponsors-grid, .team-grid, .counter-grid {
    gap: max(12px, var(--space-md, 12px)) !important;
  }

  /* Footer stack */
  footer .footer-links {
    flex-direction: column;
    gap: 12px;
  }
}

@supports (padding: env(safe-area-inset-bottom)) {
  @media (max-width: 767px) {
    .floating-share {
      bottom: calc(16px + env(safe-area-inset-bottom));
    }
    body.wat-toolbar-visible .floating-share {
      bottom: calc(96px + env(safe-area-inset-bottom));
    }
  }
}
