/* ============================================
   MENTALITY v4 — Mobile Responsive
   Breakpoints: 768px (tablet), 480px (phone)
   ============================================ */

/* ── TABLET & MOBILE (max-width: 768px) ── */
@media (max-width: 768px) {

  /* Container */
  .container { padding: 0 16px !important; }

  /* Typography scaling */
  .h-display { letter-spacing: -0.01em; }

  /* Buttons — touch-friendly */
  .btn { min-height: 44px; }
  .btn--lg { height: 52px; padding: 0 24px; font-size: 15px; }

  /* Section padding reduction */
  section[style*="padding: 100px"],
  section[style*="padding: 120px"],
  section[style*="padding: 80px"] {
    padding-top: 48px !important;
    padding-bottom: 48px !important;
  }

  /* ── Grid overrides (inline styles need !important) ── */

  /* 2-column grids → 1 column */
  [style*="grid-template-columns: 1fr 1."],
  [style*="grid-template-columns: 1."],
  [style*="grid-template-columns: 1fr 2"],
  [style*="grid-template-columns: 2"],
  [style*="grid-template-columns: 240px"] {
    grid-template-columns: 1fr !important;
    gap: 24px !important;
  }

  /* 3-column grids → 2 columns */
  [style*="grid-template-columns: repeat(3"] {
    grid-template-columns: repeat(2, 1fr) !important;
  }

  /* 4-column grids → 2 columns */
  [style*="grid-template-columns: repeat(4"] {
    grid-template-columns: repeat(2, 1fr) !important;
  }

  /* Flex wrapping */
  [style*="display: flex"][style*="gap: 64px"],
  [style*="display: flex"][style*="gap: 48px"] {
    flex-wrap: wrap !important;
    gap: 24px !important;
  }

  /* ── Navigation ── */
  .nav-links { display: none !important; }
  .mobile-menu-toggle { display: flex !important; }

  .mobile-menu {
    padding: 100px 20px 40px;
    padding-bottom: calc(40px + env(safe-area-inset-bottom));
  }
  .mobile-menu .btn {
    width: 100%;
    justify-content: center;
  }
  body.menu-open {
    overflow: hidden;
    position: fixed;
    width: 100%;
  }

  /* ── Footer ── */
  .footer-grid {
    grid-template-columns: 1fr !important;
    gap: 32px !important;
  }
  .footer-bottom {
    flex-direction: column !important;
    gap: 8px !important;
    text-align: center !important;
  }

  /* ── Homepage ── */
  .hero-stats {
    flex-wrap: wrap;
    gap: 16px !important;
  }
  .hero-stat-number {
    font-size: 32px !important;
  }
  .team-grid {
    grid-template-columns: repeat(2, 1fr) !important;
  }

  /* ── Specialists page ── */
  .specialist-grid {
    grid-template-columns: repeat(2, 1fr) !important;
  }

  /* ── Single specialist — hero card ── */
  .specialist-hero-avatar {
    width: 100% !important;
    max-width: 280px !important;
    margin: 0 auto !important;
  }

  /* ── Booking ── */
  #services-grid {
    grid-template-columns: 1fr !important;
  }
  #time-slots {
    grid-template-columns: repeat(3, 1fr) !important;
  }
  .booking-step {
    padding: 24px !important;
  }

  /* ── Account ── */
  .acc-nav {
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
    scrollbar-width: none;
    flex-wrap: nowrap !important;
    gap: 4px !important;
  }
  .acc-nav::-webkit-scrollbar { display: none; }
  .acc-nav__item {
    white-space: nowrap;
    flex-shrink: 0;
    font-size: 12px !important;
    padding: 8px 12px !important;
  }

  /* ── Welcome quiz ── */
  .quiz-options {
    grid-template-columns: 1fr !important;
  }

  /* ── Tests ── */
  .tests-grid {
    grid-template-columns: repeat(2, 1fr) !important;
  }

  /* ── FAQ ── */
  .faq-grid {
    grid-template-columns: 1fr !important;
  }

  /* ── Blog ── */
  .blog-grid {
    grid-template-columns: 1fr !important;
  }

  /* ── Legal pages (privacy, terms, cookie-policy) ── */
  .legal-toc {
    position: static !important;
    max-height: none !important;
  }

  /* ── CTA sections ── */
  .cta-final,
  .cta-band,
  [style*="border-radius: 40px"] {
    border-radius: 24px !important;
    padding: 32px 20px !important;
  }

  /* Aura performance — reduce on mobile */
  .aura {
    opacity: 0.3 !important;
    filter: blur(40px) !important;
  }

  /* Fixed widths that break on mobile */
  [style*="max-width: 920px"],
  [style*="max-width: 1120px"] {
    max-width: 100% !important;
  }

  /* Images */
  img {
    max-width: 100%;
    height: auto;
  }

  /* Aspect ratio cards — reduce height */
  [style*="aspect-ratio: 3/4"][style*="350px"] {
    width: 200px !important;
    height: auto !important;
  }
}


/* ── PHONE ONLY (max-width: 480px) ── */
@media (max-width: 480px) {

  /* All multi-col grids → single column */
  [style*="grid-template-columns: repeat(2"],
  [style*="grid-template-columns: repeat(3"],
  [style*="grid-template-columns: repeat(4"] {
    grid-template-columns: 1fr !important;
  }

  /* Button groups → stack vertically */
  [style*="display: flex"][style*="gap: 12px"]:has(.btn),
  [style*="display: flex"][style*="gap: 16px"]:has(.btn),
  .hero-buttons,
  .cta-buttons {
    flex-direction: column !important;
    width: 100% !important;
  }
  .hero-buttons .btn,
  .cta-buttons .btn {
    width: 100% !important;
    justify-content: center !important;
  }

  /* Stats → stack */
  .hero-stats,
  [style*="display: flex"][style*="justify-content: center"][style*="gap"] {
    flex-direction: column !important;
    align-items: center !important;
  }

  /* Team grid → 1 column */
  .team-grid,
  .specialist-grid,
  .tests-grid {
    grid-template-columns: 1fr !important;
  }

  /* Time slots → 2 columns on phone */
  #time-slots {
    grid-template-columns: repeat(2, 1fr) !important;
  }

  /* Specialist cards — full width */
  .specialist-card,
  .service-card,
  .test-card {
    min-height: auto !important;
  }

  /* Nav logo */
  .site-logo span {
    font-size: 14px !important;
  }
  .nav-wrapper {
    padding: 8px 12px !important;
  }

  /* FAQ — hide numbers on phone */
  .faq-number {
    display: none !important;
  }

  /* Section padding — tighter */
  section {
    padding-top: 36px !important;
    padding-bottom: 36px !important;
  }

  /* Hero title sizes */
  .h-display {
    font-size: clamp(28px, 7vw, 48px) !important;
  }

  /* Cards padding */
  [style*="padding: 40px"],
  [style*="padding: 48px"] {
    padding: 20px !important;
  }

  /* Contact postcard stack — simplify */
  [style*="transform: rotate"] {
    transform: none !important;
    position: relative !important;
    top: auto !important;
    left: auto !important;
    right: auto !important;
  }
}


/* ── Touch device improvements ��─ */
@media (hover: none) and (pointer: coarse) {
  .btn:hover {
    transform: none;
  }
  .btn:active {
    transform: scale(0.97);
  }

  /* Larger touch targets for interactive elements */
  .faq-question {
    min-height: 48px;
  }
  .acc-nav__item {
    min-height: 44px;
  }
}


/* ── Safe areas (notched phones) ── */
@supports (padding: env(safe-area-inset-bottom)) {
  .site-footer {
    padding-bottom: calc(24px + env(safe-area-inset-bottom));
  }
  .mobile-menu {
    padding-bottom: calc(40px + env(safe-area-inset-bottom));
  }
}


/* ============================================
   PHASE 2 — Page-specific & Component fixes
   ============================================ */

@media (max-width: 768px) {

  /* ── MODALS (all) ── */
  [style*="position: fixed"][style*="z-index: 9999"],
  [style*="position: fixed"][style*="z-index: 10000"],
  #payment-success-modal,
  #booking-success-modal {
    padding: 16px !important;
  }
  [style*="position: fixed"] > [style*="max-width: 560px"],
  [style*="position: fixed"] > [style*="max-width: 480px"],
  #payment-success-modal > div,
  #booking-success-modal > div {
    max-width: 100% !important;
    padding: 24px 20px !important;
    border-radius: 24px !important;
    margin: auto !important;
  }

  /* ── QUIZ MODAL (single-test.php) ── */
  .quiz-modal {
    padding: 12px !important;
  }
  .quiz-modal__container {
    max-width: 100% !important;
    max-height: 96vh !important;
    border-radius: 22px !important;
  }
  .quiz-modal__header {
    padding: 16px 20px !important;
  }
  .quiz-modal__body {
    padding: 20px !important;
  }
  .quiz-modal__footer {
    padding: 16px 20px !important;
  }
  .quiz-option {
    padding: 14px 16px !important;
  }

  /* ── BOOKING WIZARD ── */
  #booking-container {
    padding: 20px !important;
  }
  #booking-container .container {
    max-width: 100% !important;
    padding: 0 !important;
  }
  /* Booking success modal */
  #booking-success-modal [style*="padding: 40px"] {
    padding: 24px 16px !important;
  }
  /* Specialist buttons in booking */
  .booking-specialist-btn {
    padding: 12px !important;
  }
  /* Date selector horizontal scroll */
  #date-selector {
    gap: 8px !important;
  }
  .booking-date-btn {
    min-width: 64px !important;
    padding: 8px 4px !important;
    font-size: 12px !important;
  }
  /* Step indicators */
  [style*="display: flex"][style*="gap: 32px"] > [style*="opacity"] {
    font-size: 13px !important;
  }
  /* Contact form in booking */
  [style*="max-width: 420px"] {
    max-width: 100% !important;
  }

  /* ── WELCOME QUIZ ── */
  .result-specialist {
    flex-direction: column !important;
    text-align: center !important;
  }
  .result-specialist > [style*="aspect-ratio"] {
    width: 120px !important;
    height: 160px !important;
    margin: 0 auto !important;
  }
  .result-buttons {
    flex-direction: column !important;
    width: 100% !important;
  }
  .result-buttons .btn {
    width: 100% !important;
    justify-content: center !important;
  }
  .result-other-card {
    flex-direction: row !important;
  }

  /* ── ACCOUNT PAGE ── */
  /* Sidebar layout → stack */
  .acc-layout {
    grid-template-columns: 1fr !important;
  }
  /* Appointment cards */
  .acc-appointment-card {
    flex-direction: column !important;
    gap: 12px !important;
  }
  .acc-appointment-card__actions {
    flex-direction: row !important;
    width: 100% !important;
  }
  .acc-appointment-card__actions .btn {
    flex: 1 !important;
  }
  /* Specialist cards */
  .acc-specialist-card {
    flex-direction: column !important;
    text-align: center !important;
    gap: 12px !important;
  }
  .acc-specialist-hero {
    flex-direction: column !important;
    text-align: center !important;
    gap: 16px !important;
  }
  .acc-specialist-hero__info {
    align-items: center !important;
  }
  /* Chat panel */
  .chat-container {
    flex-direction: column !important;
    height: auto !important;
    min-height: 500px !important;
  }
  .chat-sidebar {
    width: 100% !important;
    max-height: 200px !important;
    border-right: none !important;
    border-bottom: 1px solid var(--line) !important;
  }
  .chat-main {
    width: 100% !important;
    min-height: 350px !important;
  }
  .chat-input-area {
    padding: 12px !important;
  }
  /* Mood tracker */
  .mood-chart-container {
    overflow-x: auto !important;
    -webkit-overflow-scrolling: touch;
  }
  .mood-week-grid {
    min-width: 320px !important;
  }
  /* Documents/payments tables */
  .acc-table {
    display: block !important;
    overflow-x: auto !important;
    -webkit-overflow-scrolling: touch;
    font-size: 13px !important;
  }
  /* Settings form */
  .acc-settings-form input,
  .acc-settings-form select {
    font-size: 16px !important; /* prevents iOS zoom */
  }
  /* Empty state icons */
  .acc-empty-icon {
    font-size: 48px !important;
  }
  /* Tab content padding */
  .acc-tab-content {
    padding: 20px 0 !important;
  }

  /* ── FRONT PAGE ── */
  /* Payment success modal content */
  #payment-success-modal [style*="display: flex"][style*="gap: 12px"] {
    flex-direction: column !important;
  }
  /* Hero section buttons */
  .hero-buttons {
    flex-direction: column !important;
    gap: 10px !important;
  }
  .hero-buttons .btn {
    width: 100% !important;
    justify-content: center !important;
  }
  /* Team cards — reduce portrait height */
  .team-card-portrait {
    height: 160px !important;
  }
  /* Stats row */
  .hero-stats {
    flex-direction: column !important;
    gap: 12px !important;
  }
  /* CTA band */
  .cta-band [style*="font-size: clamp(40px"] {
    font-size: clamp(28px, 6vw, 40px) !important;
  }

  /* ── SINGLE SPECIALIST ── */
  /* Avatar card */
  [style*="aspect-ratio: 3/4"][style*="border-radius: 28px"] {
    max-width: 220px !important;
    margin: 0 auto !important;
  }
  /* Works-with tags */
  [style*="display: flex"][style*="flex-wrap: wrap"][style*="gap: 10px"] {
    gap: 6px !important;
  }

  /* ── SERVICES PAGE ── */
  .service-card {
    min-height: 200px !important;
    padding: 20px !important;
  }

  /* ── CONTACT PAGE ── */
  /* Postcard stack — flatten */
  [style*="position: absolute"][style*="transform: rotate"] {
    position: relative !important;
    transform: none !important;
    top: auto !important;
    left: auto !important;
    right: auto !important;
    margin-bottom: 12px !important;
  }

  /* ── BLOG ── */
  .blog-card-image {
    height: 180px !important;
  }

  /* ── TEST PAGES ── */
  .test-card {
    min-height: auto !important;
  }
  .test-hero-stat {
    font-size: 28px !important;
  }

  /* ── COOKIE/PRIVACY/TERMS — TOC + content ── */
  [style*="grid-template-columns: 240px"] {
    display: block !important;
  }
  .legal-toc {
    margin-bottom: 24px !important;
  }
  .legal-toc nav {
    display: flex !important;
    flex-wrap: wrap !important;
    gap: 4px !important;
  }
  .toc-link {
    font-size: 12px !important;
    padding: 6px 10px !important;
    background: var(--isabelline-warm) !important;
    border-radius: 8px !important;
  }
  /* Tables in legal pages */
  table {
    display: block;
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
    font-size: 13px;
  }

  /* ── HEADER ── */
  .nav-wrapper {
    padding: 8px 12px !important;
  }
  .site-logo img {
    height: 28px !important;
  }
}


/* ── PHONE ONLY extras (max-width: 480px) ── */
@media (max-width: 480px) {

  /* Quiz modal — full screen on phone */
  .quiz-modal {
    padding: 0 !important;
  }
  .quiz-modal__container {
    border-radius: 0 !important;
    max-height: 100vh !important;
    height: 100% !important;
  }

  /* Booking — specialist list stacked */
  .booking-specialist-btn {
    flex-direction: column !important;
    text-align: center !important;
    gap: 8px !important;
    padding: 16px 12px !important;
  }

  /* Account nav — smaller */
  .acc-nav__item {
    font-size: 11px !important;
    padding: 6px 10px !important;
  }

  /* Chat — full height */
  .chat-container {
    min-height: 70vh !important;
  }
  .chat-sidebar {
    max-height: 150px !important;
  }

  /* Welcome result — compact */
  .result-specialist > [style*="aspect-ratio"] {
    width: 100px !important;
    height: 133px !important;
  }

  /* Booking date buttons */
  .booking-date-btn {
    min-width: 56px !important;
    font-size: 11px !important;
  }

  /* Modal buttons stack */
  [style*="position: fixed"] [style*="display: flex"][style*="gap: 12px"]:has(.btn) {
    flex-direction: column !important;
  }
  [style*="position: fixed"] .btn {
    width: 100% !important;
    justify-content: center !important;
  }
}
