/**
 * Grace Community - Responsive Adaptations & Mobile Experience
 * Breakpoints: 1440px, 1024px, 768px, 480px, 320px
 */

/* ==========================================================================
   1. Large Desktop (1440px+)
   ========================================================================== */
@media (min-width: 1440px) {
  :root {
    --gc-container-max: 1360px;
  }
}

/* ==========================================================================
   2. Desktop & Tablet Transition (<= 1024px)
   ========================================================================== */
@media (max-width: 1024px) {
  .gc-container {
    width: min(100% - 48px, var(--gc-container-max));
  }

  .gc-content-grid {
    grid-template-columns: repeat(3, 1fr);
    gap: 20px;
  }

  .gc-footer-grid {
    grid-template-columns: 1.5fr 1fr 1fr;
    gap: 36px;
  }

  .gc-footer-col:last-child {
    grid-column: 1 / -1;
  }

  .gc-nav-list {
    gap: 22px;
  }
}

/* ==========================================================================
   3. Tablet & Mobile Transition (<= 768px)
   ========================================================================== */
@media (max-width: 768px) {
  .gc-container {
    width: min(100% - 32px, var(--gc-container-max));
  }

  .gc-site-header .gc-container {
    height: 100%;
    padding-top: 0;
  }

  /* Header mobile toggle */
  .gc-mobile-toggle {
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 1002;
  }

  /* Header action button adjustment */
  .gc-header-actions .gc-btn-telegram {
    display: none; /* Handled inside mobile drawer & sticky bottom CTA */
  }

  /* Desktop nav is hidden on mobile */
  .gc-nav-desktop {
    display: none !important;
  }

  /* Off-canvas mobile menu drawer */
  .gc-mobile-drawer {
    position: fixed;
    top: 0;
    right: -100%;
    width: min(340px, 85vw);
    height: 100vh;
    height: 100dvh;
    background: var(--gc-surface);
    color: var(--gc-text);
    border-left: 1px solid var(--gc-border);
    display: flex !important;
    flex-direction: column;
    justify-content: space-between;
    transition: right var(--gc-transition-smooth);
    z-index: 1002;
    box-shadow: -10px 0 30px rgba(0, 0, 0, 0.25);
    overflow: hidden;
  }

  /* Admin Bar adjustments for mobile drawer */
  body.admin-bar .gc-mobile-drawer {
    top: 32px;
    height: calc(100vh - 32px);
    height: calc(100dvh - 32px);
  }

  @media screen and (max-width: 782px) {
    body.admin-bar .gc-mobile-drawer {
      top: 46px;
      height: calc(100vh - 46px);
      height: calc(100dvh - 46px);
    }
  }

  .gc-mobile-drawer.is-open {
    right: 0;
  }

  .gc-mobile-drawer-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 20px 24px;
    border-bottom: 1px solid var(--gc-border-light);
    flex-shrink: 0;
  }

  .gc-mobile-drawer-body {
    display: flex;
    flex-direction: column;
    justify-content: space-between;
    flex: 1;
    padding: 20px 24px 28px;
    overflow-y: auto;
    -webkit-overflow-scrolling: touch;
  }

  .gc-mobile-nav-list {
    display: flex;
    flex-direction: column;
    align-items: flex-start;
    gap: 6px;
    width: 100%;
    list-style: none;
    padding: 0;
    margin: 0;
  }

  .gc-mobile-nav-list li {
    width: 100%;
    list-style: none;
  }

  /* Staggered slide-in animation for mobile drawer links */
  .gc-mobile-drawer.is-open .gc-mobile-nav-list li {
    animation: gcSlideInRight 0.35s cubic-bezier(0.16, 1, 0.3, 1) both;
  }
  .gc-mobile-drawer.is-open .gc-mobile-nav-list li:nth-child(1) { animation-delay: 0.04s; }
  .gc-mobile-drawer.is-open .gc-mobile-nav-list li:nth-child(2) { animation-delay: 0.08s; }
  .gc-mobile-drawer.is-open .gc-mobile-nav-list li:nth-child(3) { animation-delay: 0.12s; }
  .gc-mobile-drawer.is-open .gc-mobile-nav-list li:nth-child(4) { animation-delay: 0.16s; }
  .gc-mobile-drawer.is-open .gc-mobile-nav-list li:nth-child(5) { animation-delay: 0.20s; }

  @keyframes gcSlideInRight {
    from {
      opacity: 0;
      transform: translateX(20px);
    }
    to {
      opacity: 1;
      transform: translateX(0);
    }
  }

  .gc-mobile-nav-list li a {
    display: flex;
    align-items: center;
    min-height: 44px;
    font-size: 16px;
    font-weight: 600;
    padding-block: 8px;
    border-bottom: 1px solid var(--gc-border-light);
    color: var(--gc-text) !important;
    transition: color 0.2s ease, transform 0.2s ease;
  }

  .gc-mobile-nav-list li a:hover {
    color: var(--gc-telegram) !important;
    transform: translateX(4px);
  }

  .gc-mobile-drawer-actions {
    display: flex;
    flex-direction: column;
    gap: 12px;
    margin-top: 24px;
    width: 100%;
  }

  .gc-mobile-drawer-actions .gc-btn {
    width: 100%;
    min-height: 44px;
  }

  /* Drawer Backdrop */
  .gc-nav-backdrop {
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.65);
    backdrop-filter: blur(8px);
    -webkit-backdrop-filter: blur(8px);
    z-index: 1000;
    opacity: 0;
    visibility: hidden;
    transition: opacity var(--gc-transition-base), visibility var(--gc-transition-base);
  }

  .gc-nav-backdrop.is-visible {
    opacity: 1;
    visibility: visible;
  }

  /* Hero adjustments */
  .gc-hero-section {
    min-height: 560px;
    padding-bottom: 50px;
  }

  .gc-hero-cta-group {
    flex-direction: column;
    align-items: stretch;
  }

  .gc-hero-cta-group .gc-btn {
    width: 100%;
  }

  /* Telegram cards stack */
  .gc-telegram-cards-section {
    margin-top: 0;
  }

  .gc-tg-cards-grid {
    grid-template-columns: 1fr;
    gap: 18px;
  }

  .gc-tg-card-action .gc-btn {
    width: 100%;
  }

  /* Content Grid */
  .gc-content-grid {
    grid-template-columns: repeat(2, 1fr);
    gap: 16px;
  }

  /* In-feed banner */
  .gc-feed-banner {
    flex-direction: column;
    align-items: flex-start;
    gap: 20px;
    padding: 28px 24px;
  }

  .gc-feed-banner-action {
    width: 100%;
  }

  .gc-feed-banner-action .gc-btn {
    width: 100%;
  }

  /* Footer grid */
  .gc-footer-grid {
    grid-template-columns: 1fr;
    gap: 36px;
  }

  .gc-footer-bottom-row {
    flex-direction: column;
    align-items: flex-start;
  }

  /* Single post adjustments */
  .gc-single-header {
    margin-bottom: 24px;
  }

  .gc-single-tg-banner {
    flex-direction: column;
    align-items: flex-start;
    padding: 24px;
  }

  .gc-single-tg-banner .gc-btn {
    width: 100%;
  }

  .gc-share-section {
    flex-direction: column;
    align-items: flex-start;
  }

  /* Add bottom padding to body so the sticky bar does not overlap content */
  body.has-mobile-cta {
    padding-bottom: calc(76px + env(safe-area-inset-bottom, 0px));
  }
}

/* ==========================================================================
   4. Mobile Sticky Bottom CTA Bar (Mobile Only)
   ========================================================================== */
.gc-mobile-sticky-cta {
  position: fixed;
  bottom: 0;
  left: 0;
  width: 100%;
  height: calc(62px + env(safe-area-inset-bottom, 0px));
  padding-bottom: env(safe-area-inset-bottom, 0px);
  background-color: var(--gc-telegram);
  color: #FFFFFF;
  z-index: 999;
  display: flex;
  align-items: center;
  justify-content: center;
  padding-inline: 16px;
  box-shadow: 0 -4px 20px rgba(0, 0, 0, 0.35);
  border-top: 1px solid rgba(255, 255, 255, 0.2);
  transition: transform var(--gc-transition-base);
  animation: gcStickyGlow 5s infinite ease-in-out;
}

@keyframes gcStickyGlow {
  0%, 100% { box-shadow: 0 -4px 18px rgba(0, 0, 0, 0.35); }
  50% { box-shadow: 0 -6px 26px rgba(34, 158, 217, 0.5); }
}

.gc-mobile-sticky-cta a {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 10px;
  width: 100%;
  height: 100%;
  font-size: 15px;
  font-weight: 700;
  letter-spacing: 0.02em;
  color: #FFFFFF;
}

.gc-mobile-sticky-cta svg {
  flex-shrink: 0;
}

/* Hide mobile sticky CTA on desktop */
@media (min-width: 769px) {
  .gc-mobile-sticky-cta {
    display: none !important;
  }

  body.has-mobile-cta {
    padding-bottom: 0 !important;
  }
}

/* ==========================================================================
   5. Small Mobile (<= 480px)
   ========================================================================== */
@media (max-width: 480px) {
  .gc-container {
    width: min(100% - 24px, var(--gc-container-max));
  }

  .gc-content-grid {
    grid-template-columns: repeat(2, 1fr);
    gap: 12px;
  }

  .gc-card-body {
    padding: 12px 14px;
  }

  .gc-card-title {
    font-size: 15px;
  }

  .gc-card-meta {
    font-size: 11px;
  }

  .gc-badge {
    font-size: 10px;
    padding: 3px 8px;
  }

  .gc-card-badges {
    top: 10px;
    left: 10px;
  }

  .gc-section-header.has-action {
    flex-direction: column;
    align-items: flex-start;
  }

  .gc-footer-tg-card {
    padding: 36px 20px;
  }

  .gc-modal-box {
    padding: 28px 18px;
  }

  .gc-modal-actions {
    flex-direction: column;
  }

  .gc-modal-actions .gc-btn {
    width: 100%;
  }
}

/* ==========================================================================
   6. Micro Mobile (<= 360px)
   ========================================================================== */
@media (max-width: 360px) {
  .gc-content-grid {
    grid-template-columns: 1fr;
  }
}
