/**
 * Shrichakra Theme - Ultra-Stable Responsive Breakpoints & Mobile Enhancements
 */

/* ==========================================================================
   Header & Navigation
   ========================================================================== */
.site-header {
  position: sticky;
  top: 0;
  background: var(--color-surface);
  border-bottom: 1px solid var(--color-border);
  z-index: var(--z-header);
  transition: all var(--transition-fast);
}

.top-utility-bar {
  background: var(--color-primary-dark);
  color: var(--color-text-inverse);
  font-size: 12px;
  padding: 6px 0;
  border-bottom: 1px solid rgba(212, 175, 55, 0.4);
}
.utility-flex {
  display: flex;
  justify-content: space-between;
  align-items: center;
  flex-wrap: wrap;
  gap: var(--space-2);
}
.utility-left, .utility-right {
  display: flex;
  align-items: center;
  gap: var(--space-4);
}

/* Left-hand identity line */
.utility-brand {
  display: flex;
  align-items: center;
  gap: var(--space-2);
  font-weight: 500;
  min-width: 0;
}
.utility-brand-alt {
  opacity: 0.9;
}
.utility-sep {
  opacity: 0.5;
}

/* Right-hand cluster: languages, then the social/search icons */
.utility-right {
  gap: 14px;
}
.utility-social {
  display: flex;
  align-items: center;
  gap: 10px;
  font-size: 13px;
  line-height: 1;
}
.utility-icon {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  color: #fff;
  background: none;
  border: none;
  padding: 2px;
  opacity: 0.85;
  cursor: pointer;
  transition: opacity var(--transition-fast), transform var(--transition-fast);
}
.utility-icon:hover {
  opacity: 1;
  transform: translateY(-1px);
}
.utility-icon-wa {
  color: #25D366;
}
.lang-flag {
  margin-right: 4px;
}

/* Language Switcher UI */
.lang-switcher {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  background: rgba(255, 255, 255, 0.12);
  padding: 3px 10px;
  border-radius: var(--radius-full);
}
.lang-btn {
  display: inline-flex;
  align-items: center;
  background: none;
  border: none;
  color: rgba(255, 255, 255, 0.85);
  white-space: nowrap;
  font-size: 11px;
  font-weight: 600;
  cursor: pointer;
  padding: 2px 6px;
  border-radius: 4px;
  transition: all var(--transition-fast);
}
.lang-btn:hover {
  color: #fff;
}
.lang-btn.active {
  background: var(--color-secondary);
  color: #fff;
  font-weight: 700;
}

.main-nav-wrap {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--space-4);
  min-height: var(--header-height);
}

.site-logo {
  display: flex;
  align-items: center;
  gap: var(--space-3);
  font-family: var(--font-heading);
  font-size: var(--text-xl);
  font-weight: 700;
  color: var(--color-primary);
  flex: 0 1 auto;
  min-width: 0;
}
.site-logo img {
  height: 48px;
  width: 48px;
  border-radius: 50%;
  object-fit: cover;
  flex-shrink: 0;
}
/* The logo may shrink, but never hyphenate or break its own name. Wrapping
   "Shrichakra" to "SHRICHA / KRA" was the visible symptom of allowing that. */
.site-logo > span,
.site-logo > div,
.site-logo > div > div {
  min-width: 0;
  overflow-wrap: normal;
  word-break: keep-all;
}
.site-logo > span {
  white-space: nowrap;
}

.desktop-nav {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: var(--space-5);
  flex-wrap: nowrap;
  /* No shrinking: a squeezed nav overlaps .nav-actions instead of overflowing,
     which reads as broken rather than as "too narrow". */
  flex: 0 0 auto;
}
.desktop-nav a {
  font-size: var(--text-sm);
  font-weight: 600;
  color: var(--color-text-main);
  padding: var(--space-2) 0;
  position: relative;
  white-space: nowrap;
}
.desktop-nav a:hover, .desktop-nav a.active {
  color: var(--color-primary);
}
.desktop-nav a.active::after {
  content: '';
  position: absolute;
  bottom: 0;
  left: 0;
  right: 0;
  height: 2px;
  background: var(--color-secondary);
}

.nav-actions {
  display: flex;
  align-items: center;
  gap: var(--space-3);
  flex-shrink: 0;
}
/* There is exactly one language switcher per breakpoint: the utility bar above
   768px, the drawer below it. A third copy used to sit in .nav-actions and
   rendered alongside the utility-bar one on every desktop width. */

.hamburger-btn {
  display: none;
  flex-direction: column;
  justify-content: center;
  gap: 5px;
  width: 40px;
  height: 40px;
  padding: 8px;
  border-radius: var(--radius-sm);
  border: 1px solid var(--color-border);
  background: var(--color-surface);
  cursor: pointer;
}
.hamburger-btn span {
  display: block;
  width: 100%;
  height: 2px;
  background-color: var(--color-primary);
  border-radius: 2px;
  transition: all var(--transition-fast);
}

/* Mobile Drawer */
.mobile-nav-drawer {
  position: fixed;
  top: 0;
  right: -100%;
  width: 86%;
  max-width: 340px;
  height: 100vh;
  height: 100dvh;
  background: var(--color-surface);
  z-index: var(--z-drawer);
  box-shadow: -8px 0 24px rgba(0, 0, 0, 0.2);
  display: flex;
  flex-direction: column;
  transition: right 0.3s cubic-bezier(0.4, 0, 0.2, 1);
  padding: var(--space-5) var(--space-4) var(--space-4);
  overflow-y: auto;
  overscroll-behavior: contain;
}
.mobile-nav-drawer.open {
  right: 0;
}

.drawer-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.6);
  z-index: calc(var(--z-drawer) - 1);
  opacity: 0;
  visibility: hidden;
  transition: all var(--transition-fast);
}
.drawer-backdrop.open {
  opacity: 1;
  visibility: visible;
}

@media (min-width: 992px) {
  .mobile-nav-drawer,
  .drawer-backdrop,
  .hamburger-btn {
    display: none !important;
  }
}

.mobile-nav-links {
  display: flex;
  flex-direction: column;
  gap: 2px;
  margin: var(--space-4) 0;
}
.mobile-nav-links a {
  font-size: var(--text-base);
  font-weight: 600;
  color: var(--color-text-main);
  padding: 11px 2px;
  border-bottom: 1px solid var(--color-border);
  display: block;
}
.mobile-nav-links a:last-child {
  border-bottom: none;
}
.mobile-nav-links a:hover, .mobile-nav-links a.active {
  color: var(--color-primary);
}

/* Sticky Mobile Action Bar */
.sticky-mobile-action-bar {
  display: none;
  position: fixed;
  bottom: 0;
  left: 0;
  right: 0;
  background: var(--color-surface);
  border-top: 1px solid var(--color-border-gold);
  box-shadow: 0 -4px 16px rgba(0, 0, 0, 0.1);
  z-index: var(--z-header);
  padding: 8px 16px calc(8px + env(safe-area-inset-bottom));
  justify-content: space-around;
  align-items: center;
}
.mobile-action-item {
  display: flex;
  flex-direction: column;
  align-items: center;
  font-size: 11px;
  font-weight: 700;
  color: var(--color-primary);
  gap: 2px;
}
.mobile-action-item span.icon {
  font-size: 1.3rem;
}

/* Mobile drawer header, brand & footer actions */
.drawer-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--space-3);
  padding-bottom: var(--space-3);
  border-bottom: 1px solid var(--color-border);
}
.drawer-brand {
  display: flex;
  align-items: center;
  gap: var(--space-2);
  min-width: 0;
  font-family: var(--font-heading);
  font-weight: 700;
  font-size: var(--text-base);
  color: var(--color-primary);
}
.drawer-brand img {
  width: 36px;
  height: 36px;
  border-radius: 50%;
  flex-shrink: 0;
}
.drawer-close-btn {
  flex-shrink: 0;
  width: 40px;
  height: 40px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 1.8rem;
  line-height: 1;
  color: var(--color-primary);
  border-radius: var(--radius-sm);
}
.drawer-close-btn:hover {
  background: var(--color-bg-alt);
}
.drawer-actions {
  margin-top: auto;
  padding-top: var(--space-4);
  display: flex;
  flex-direction: column;
  gap: var(--space-2);
}
.drawer-actions .btn {
  width: 100%;
}

/* Mobile drawer language switcher */
.drawer-lang-switcher {
  display: flex;
  align-items: center;
  gap: var(--space-2);
  margin: var(--space-4) 0 var(--space-2);
  padding-top: var(--space-3);
  border-top: 1px solid var(--color-border);
}
.drawer-lang-switcher .lang-btn {
  flex: 1 1 0;
  background: var(--color-bg-alt);
  border: 1px solid var(--color-border);
  color: var(--color-text-muted);
  font-size: var(--text-sm);
  padding: 8px 4px;
  border-radius: var(--radius-sm);
  min-height: 40px;
}
.drawer-lang-switcher .lang-btn.active {
  background: var(--color-primary);
  border-color: var(--color-primary);
  color: #fff;
}

/* ==========================================================================
   Global Overflow Guards
   Long words, unbroken URLs and fixed-width media must never widen the page.
   ========================================================================== */
/* `overflow-x: clip` (NOT `hidden`). The off-canvas drawer is position:fixed, so
   the body's `overflow-x: hidden` never clipped it and the page could be dragged
   sideways. `clip` contains it without establishing a scroll container - using
   `hidden` here instead turns `body` into its own 100vh scroller and breaks
   vertical scrolling entirely. `body { overflow-x: hidden }` in reset.css stays
   as the fallback for browsers without `clip`. */
html {
  overflow-x: clip;
}
h1, h2, h3, h4, h5, h6, p, li, td, th, a, span, strong, em {
  overflow-wrap: break-word;
}
iframe, video, embed, object {
  max-width: 100%;
}
pre, code {
  overflow-x: auto;
  max-width: 100%;
}

/* Buttons keep one line on wide screens but must never overflow their column */
.btn {
  max-width: 100%;
}

/* Tables scroll horizontally instead of stretching the page */
.table-scroll,
.timing-table-wrap {
  width: 100%;
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
}

/* ==========================================================================
   Responsive Breakpoints & Stability Improvements
   ========================================================================== */

/* --- Laptops: the full 12-link nav plus both CTAs no longer fits --- */
@media (max-width: 1400px) {
  .nav-actions .btn-outline-gold {
    display: none;
  }
}

@media (max-width: 1280px) {
  .desktop-nav {
    gap: var(--space-3);
  }
  .desktop-nav a {
    font-size: 0.82rem;
  }
  .nav-actions {
    gap: var(--space-2);
  }
}

@media (max-width: 1150px) {
  .desktop-nav {
    display: none;
  }
  .hamburger-btn {
    display: flex;
  }
  .temple-intro-grid,
  .visit-guide-grid,
  .guruji-hero-grid {
    grid-template-columns: minmax(0, 1fr);
    gap: var(--space-6);
  }
  .grid-cols-4 {
    grid-template-columns: repeat(3, minmax(0, 1fr));
  }
  .grid-cols-3 {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }
  .footer-grid {
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: var(--space-6);
  }
}

/* --- Tablets --- */
@media (max-width: 900px) {
  .portal-main-grid,
  .prefooter-grid {
    grid-template-columns: minmax(0, 1fr);
  }
  .grid-cols-4 {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }
  .quick-nav-strip {
    margin-top: var(--space-4);
  }
  :root {
    --pad-card-lg: var(--space-5);
  }
  /* 80px section gutters are far too airy once the viewport is this narrow */
  .section {
    padding-top: var(--space-8);
    padding-bottom: var(--space-8);
  }
  .section-lg {
    padding-top: var(--space-10);
    padding-bottom: var(--space-10);
  }
}

/* --- Large phones / small tablets: keep cards two-up instead of stretching
       one card across the whole screen --- */
@media (max-width: 700px) {
  .grid-cols-2 {
    grid-template-columns: minmax(0, 1fr);
  }
}

@media (max-width: 768px) {
  :root {
    --header-height: 64px;
  }
  .top-utility-bar {
    display: none;
  }
  .main-nav-wrap {
    padding-top: var(--space-2);
    padding-bottom: var(--space-2);
  }
  .site-footer {
    padding-top: var(--space-8);
  }
  .hero-section {
    min-height: 65vh;
    padding: var(--space-8) 0;
  }
  .sticky-mobile-action-bar {
    display: flex;
  }
  /* Only pages that actually render the bar need room for it */
  body:has(.sticky-mobile-action-bar) {
    padding-bottom: 72px;
  }
  .floating-whatsapp-btn {
    bottom: 76px;
    right: 16px;
    width: 52px;
    height: 52px;
    font-size: 26px;
  }
  .whatsapp-chat-box {
    bottom: 136px;
    right: 16px;
    left: 16px;
    width: auto;
    max-width: none;
  }
  .astrology-selector-wrap .grid-cols-4 {
    grid-template-columns: repeat(3, minmax(0, 1fr));
  }
  .card-footer {
    flex-wrap: wrap;
    gap: var(--space-2);
  }
  .stotram-content-panel {
    padding: var(--space-5) var(--space-4);
    font-size: var(--text-base);
  }
  /* Three script names do not fit one row on a phone. Wrapping keeps every
     option visible instead of hiding them behind a horizontal scroll. */
  .script-tabs {
    flex-wrap: wrap;
    justify-content: center;
    gap: var(--space-1) var(--space-2) !important;
  }
  .script-tab {
    padding: var(--space-2) var(--space-3) !important;
    white-space: nowrap;
    font-size: var(--text-sm);
  }
  .progress-card,
  .parayana-form-wrap {
    padding: var(--space-5);
  }
  .timeline {
    padding-left: var(--space-6);
  }
  .timeline-dot {
    left: -28px;
    width: 20px;
    height: 20px;
  }
  .gallery-grid {
    grid-template-columns: repeat(auto-fill, minmax(150px, 1fr));
    gap: var(--space-3);
  }
  /* Touch devices have no hover, so gallery captions must always show */
  .gallery-caption-overlay {
    opacity: 1;
  }
  .p-8 {
    padding: var(--space-5);
  }
  /* The Mahayaga digit counter is 10 fixed boxes wide */
  .counter-display,
  .progress-counter-display {
    flex-wrap: wrap;
    gap: var(--space-2);
  }
  .digit-box {
    font-size: 2rem !important;
    padding: 8px 12px !important;
  }
  .faq-question {
    font-size: var(--text-base);
    padding: var(--space-4);
  }
  .faq-answer,
  .faq-item.active .faq-answer {
    padding-left: var(--space-4);
    padding-right: var(--space-4);
  }
}

/* --- Phones: one column, tighter rhythm --- */
@media (max-width: 560px) {
  :root {
    --pad-card-lg: var(--space-4);
  }
  .grid-cols-2,
  .grid-cols-3,
  .grid-cols-4 {
    grid-template-columns: minmax(0, 1fr);
  }
  .footer-grid {
    grid-template-columns: minmax(0, 1fr);
    gap: var(--space-6);
    text-align: left;
  }
  .section {
    padding-top: var(--space-6);
    padding-bottom: var(--space-6);
  }
  .section-lg {
    padding-top: var(--space-8);
    padding-bottom: var(--space-8);
  }
}

/* --- Phones --- */
@media (max-width: 640px) {
  /* Long CTA labels wrap instead of pushing the layout sideways */
  .btn {
    white-space: normal;
    text-align: center;
  }
  .btn-lg {
    padding: 0.85rem 1.5rem;
    font-size: var(--text-base);
  }
  .section-header {
    margin-bottom: var(--space-6);
  }
}

@media (max-width: 480px) {
  .section {
    padding-top: var(--space-6);
    padding-bottom: var(--space-6);
  }
  .section-title {
    font-size: 1.65rem;
  }
  .hero-actions {
    flex-direction: column;
    width: 100%;
  }
  .hero-actions .btn {
    width: 100%;
  }
  .astrology-selector-wrap .grid-cols-4 {
    grid-template-columns: repeat(3, minmax(0, 1fr));
  }
  .rashi-card {
    padding: var(--space-3) var(--space-2);
  }
  .rashi-icon {
    font-size: 1.6rem;
  }
  .rashi-sanskrit {
    font-size: var(--text-base);
  }
  .parayana-form-wrap {
    padding: var(--space-4);
  }
  .form-step-indicators {
    gap: var(--space-2);
  }
  .step-bubble {
    width: 30px;
    height: 30px;
    font-size: 12px;
  }
  .form-step-indicators::before {
    left: 15px;
    right: 15px;
  }
  .card-body,
  .p-8,
  .p-6 {
    padding: var(--space-4);
  }
  .nav-actions .btn {
    display: none;
  }
  .site-logo {
    font-size: var(--text-base);
  }
  .site-logo img {
    width: 40px;
    height: 40px;
  }

  .counter-display,
  .progress-counter-display {
    flex-wrap: wrap;
  }
  .digit-box {
    font-size: 1.6rem !important;
    padding: 8px 10px !important;
  }
  .gallery-filters {
    justify-content: flex-start;
    flex-wrap: nowrap;
    overflow-x: auto;
    scrollbar-width: none;
    padding-bottom: var(--space-1);
  }
  .gallery-filters::-webkit-scrollbar {
    display: none;
  }
  .gallery-filter-btn {
    white-space: nowrap;
    flex-shrink: 0;
  }
  .mobile-action-item {
    font-size: 10.5px;
    min-width: 52px;
  }
}

/* Fallback for browsers without :has() — reserve the space unconditionally */
@supports not selector(:has(*)) {
  @media (max-width: 768px) {
    body {
      padding-bottom: 72px;
    }
  }
}

/* Respect users who ask for less motion */
@media (prefers-reduced-motion: reduce) {
  html {
    scroll-behavior: auto;
  }
  *, *::before, *::after {
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.01ms !important;
  }
  .card:hover,
  .btn:hover,
  .quick-nav-item:hover,
  .rashi-card:hover {
    transform: none;
  }
}

/* ==========================================================================
   Touch Ergonomics (pointer: coarse and small screens)
   ========================================================================== */
@media (max-width: 768px) {
  /* Footer link lists are the densest tap targets on the site */
  .site-footer ul a,
  .site-footer .footer-bottom a {
    display: inline-block;
    padding: 5px 0;
  }
  .audio-progress-slider {
    height: 24px;
  }
  .mobile-action-item {
    min-width: 60px;
    min-height: 44px;
    justify-content: center;
  }
  .gallery-filter-btn,
  .script-tab,
  .chat-option-btn {
    min-height: 40px;
  }
}

/* --- Very narrow phones (320px: iPhone SE 1, folded devices) --- */
@media (max-width: 400px) {
  /* Nudge the type scale down so long Sanskrit compounds in card headings
     ("Trailokyamohana", "Panchadashakshari") stop breaking mid-word */
  :root {
    --text-2xl: 1.3rem;
    --text-xl: 1.1rem;
    --text-lg: 1.02rem;
  }
  .hero-title {
    font-size: 1.32rem;
  }
  .audio-player-card {
    padding: var(--space-4);
  }
  .btn-play-pause {
    width: 42px;
    height: 42px;
    font-size: 1.05rem;
  }
  .audio-time {
    min-width: 32px;
    font-size: 10px;
  }
  .quick-nav-label,
  .quick-label-ref {
    font-size: 10px;
  }
}


/* ==========================================================================
   Temple Updates popup on small screens
   ========================================================================== */
@media (max-width: 768px) {
  .site-notifications {
    left: 12px;
    right: 12px;
    /* Clear of the sticky mobile action bar */
    bottom: 80px;
  }
  .notif-panel {
    width: auto;
    right: 0;
    max-width: none;
  }
  .notif-body {
    max-height: 46vh;
  }
  .notif-launcher {
    width: 42px;
    height: 42px;
    font-size: 18px;
  }
  /* The panel goes edge to edge here, straight under the WhatsApp bubble */
  .notif-open .floating-whatsapp-btn {
    opacity: 0;
    visibility: hidden;
  }
}

/* No sticky action bar here, so the popup can sit lower */
@media (max-width: 768px) {
  body:not(:has(.sticky-mobile-action-bar)) .site-notifications {
    bottom: 16px;
  }
}

/* ==========================================================================
   Homepage Grids & Components - Ultra-Stable Responsive Layout
   ========================================================================== */
.quick-card-ref {
    background: #FFF9F2;
    border: 1px solid #EADCC7;
    border-radius: var(--radius-md);
    padding: 14px 6px;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    text-align: center;
    gap: 6px;
    text-decoration: none;
    box-shadow: 0 2px 8px rgba(103, 14, 40, 0.04);
    transition: all var(--transition-fast);
    min-height: 86px;
}
.quick-card-ref:hover {
    background: #FFF;
    transform: translateY(-3px);
    border-color: var(--color-secondary);
    box-shadow: 0 6px 16px rgba(103, 14, 40, 0.12);
}
.quick-icon-ref {
    font-size: 1.45rem;
    line-height: 1;
}
.quick-label-ref {
    font-size: 11.5px;
    font-weight: 700;
    color: var(--color-text-main);
    line-height: 1.2;
}

.quick-nav-grid-resp {
    display: grid;
    grid-template-columns: repeat(8, minmax(0, 1fr));
    gap: 12px;
}

.portal-grid-resp {
    display: grid;
    grid-template-columns: minmax(0, 1.6fr) minmax(0, 1fr);
    gap: 28px;
}

.about-card-split-resp {
    display: grid;
    grid-template-columns: minmax(0, 1.25fr) minmax(0, 1fr);
    gap: 20px;
    align-items: center;
}

.media-grid-resp {
    display: grid;
    grid-template-columns: repeat(3, minmax(0, 1fr));
    gap: 16px;
}

.prefooter-grid-resp {
    display: grid;
    grid-template-columns: minmax(0, 1.2fr) minmax(0, 1fr) minmax(0, 1.2fr);
    gap: 32px;
}

@media (max-width: 1024px) {
    .quick-nav-grid-resp {
        grid-template-columns: repeat(4, minmax(0, 1fr));
        gap: 10px;
    }
    .portal-grid-resp {
        grid-template-columns: minmax(0, 1fr);
        gap: 24px;
    }
    .prefooter-grid-resp {
        grid-template-columns: minmax(0, 1fr);
        gap: 24px;
    }
}

@media (max-width: 768px) {
    .about-card-split-resp {
        grid-template-columns: minmax(0, 1fr);
        gap: 16px;
    }
    .about-card-split-resp img {
        height: 200px !important;
    }
}

@media (max-width: 600px) {
    .media-grid-resp {
        grid-template-columns: minmax(0, 1fr);
        gap: 14px;
    }
    .quick-nav-grid-resp {
        grid-template-columns: repeat(4, minmax(0, 1fr));
        gap: 6px;
    }
    .quick-card-ref {
        padding: 10px 4px;
        min-height: 74px;
    }
    .quick-icon-ref {
        font-size: 1.25rem;
    }
    .quick-label-ref {
        font-size: 10.5px;
    }
}

@media (max-width: 400px) {
    .quick-nav-grid-resp {
        grid-template-columns: repeat(2, minmax(0, 1fr));
        gap: 8px;
    }
    .quick-card-ref {
        padding: 12px 6px;
        min-height: 70px;
    }
    .quick-label-ref {
        font-size: 11px;
    }
}

