/*
 * mobile.css — Responsividade 100% iOS Safari & Android
 * Dr. Wheber Zampirollo | Psiquiatra Canoas RS
 *
 * Princípios aplicados:
 *  - Apple HIG: touch targets ≥ 44px, safe-area-inset, font-size ≥ 16px
 *  - Android Material: tap targets ≥ 48px, 8dp grid system
 *  - iOS Safari: -webkit-overflow-scrolling, viewport-fit=cover, bounce fix
 *  - Core Web Vitals: layout shift prevention, lazy loading, minimal repaints
 */

/* ═══════════════════════════════════════════════════════════════════════════
   0. BASE iOS / ANDROID FIXES — Apply everywhere
   ═══════════════════════════════════════════════════════════════════════════ */

/* Prevent text resize after orientation change on iOS */
html {
    -webkit-text-size-adjust: 100%;
    text-size-adjust: 100%;
}

/* Smooth scrolling without momentum bounce fighting */
html, body {
    scroll-behavior: smooth;
    -webkit-overflow-scrolling: touch;
    overscroll-behavior-y: none;
}

/* Prevent double-tap zoom on buttons/links (iOS) */
a, button, input, select, textarea {
    touch-action: manipulation;
}

/* Remove tap highlight flash on Android/iOS */
* {
    -webkit-tap-highlight-color: transparent;
}

/* Fix for iOS Safari 100vh bug (includes browser chrome) */
.hero-premium,
.internal-header {
    min-height: -webkit-fill-available;
}

/* Safe area support for iPhone notch / Dynamic Island / home indicator */
.premium-nav {
    padding-left: max(24px, env(safe-area-inset-left));
    padding-right: max(24px, env(safe-area-inset-right));
    padding-top: max(16px, env(safe-area-inset-top));
}

.premium-footer {
    padding-bottom: max(40px, calc(40px + env(safe-area-inset-bottom)));
}

/* ═══════════════════════════════════════════════════════════════════════════
   1. BREAKPOINTS
   - Mobile first: 0–767px (phones)
   - Tablet: 768–991px (iPad portrait, large phones landscape)
   - Desktop: 992px+ (iPad landscape, Mac)
   ═══════════════════════════════════════════════════════════════════════════ */

/* ─── PHONE (≤767px) ─────────────────────────────────────────────────────── */
@media (max-width: 767px) {

    /* Container */
    .container-premium {
        padding: 0 20px;
    }

    /* Section spacing — HIG: comfortable breathing room */
    .section-padding {
        padding: 64px 0;
    }

    /* ── NAVIGATION ─────────────────────────────────────────────── */
    .premium-nav {
        padding: 16px 20px;
        background: rgba(4, 47, 46, 0.97);
    }

    /* Scrolled state: force solid white bg so logo/links are always visible */
    .premium-nav.scrolled {
        background: rgba(4, 47, 46, 0.97) !important;
        -webkit-backdrop-filter: blur(20px) saturate(180%);
        backdrop-filter: blur(20px) saturate(180%);
        box-shadow: 0 2px 20px rgba(0,0,0,0.2);
    }

    .nav-logo {
        height: 48px !important;
        filter: brightness(0) invert(1); /* Always white on mobile before scroll */
    }

    .scrolled .nav-logo {
        height: 40px !important;
        filter: brightness(0) invert(1) !important;
    }

    /* ═══ MOBILE FULLSCREEN MENU ═══════════════════════════════════ */

    /* Full-screen nav panel */
    .nav-links {
        position: fixed;
        top: 0;
        left: 0;
        width: 100%;
        height: 100%;
        height: 100dvh;
        background: var(--secondary, #042f2e);
        flex-direction: column !important;
        align-items: stretch !important;
        padding: max(90px, calc(70px + env(safe-area-inset-top))) 28px;
        padding-bottom: max(28px, calc(28px + env(safe-area-inset-bottom)));
        z-index: 1050;
        display: flex !important;
        overflow-y: auto;
        -webkit-overflow-scrolling: touch;
        gap: 0 !important;
        opacity: 0;
        visibility: hidden;
        transform: scale(0.98);
        transition: opacity 0.35s ease, visibility 0.35s ease, transform 0.35s ease;
    }

    .nav-links.active {
        opacity: 1;
        visibility: visible;
        transform: scale(1);
    }

    /* ── Nav links styling ─────────────────────────────────────── */
    .nav-links > a,
    .nav-links .nav-item-dropdown > .nav-link-tratamentos {
        color: rgba(255,255,255,0.9) !important;
        font-size: 1.15rem;
        font-weight: 600;
        width: 100%;
        min-height: 52px;
        display: flex;
        align-items: center;
        padding: 14px 0;
        border-bottom: 1px solid rgba(255,255,255,0.07);
        text-decoration: none;
        letter-spacing: 0.01em;
    }

    .nav-links > a:active,
    .nav-links .nav-item-dropdown > .nav-link-tratamentos:active {
        color: var(--primary-light, #10B981) !important;
    }

    /* "Agendar" CTA button inside menu */
    .nav-links .btn-premium {
        width: 100%;
        text-align: center;
        margin-top: 20px;
        min-height: 56px;
        display: flex;
        align-items: center;
        justify-content: center;
        font-size: 1.1rem;
        border-radius: 14px;
        font-weight: 700;
        color: white !important;
        background: var(--primary-light, #10B981) !important;
        border: none !important;
        box-shadow: 0 8px 24px rgba(16, 185, 129, 0.3);
    }

    /* Instagram icon */
    .nav-social {
        color: rgba(255,255,255,0.6) !important;
        border-bottom: none !important;
        min-height: 44px !important;
        padding: 8px 0 !important;
        justify-content: center !important;
    }

    /* ── Dropdown (Tratamentos) — Accordion ───────────────────── */
    .nav-item-dropdown {
        width: 100%;
    }

    /* Arrow indicator on "Tratamentos" */
    .nav-item-dropdown > a.nav-link-tratamentos::after {
        content: '▾';
        margin-left: auto;
        font-size: 1.2rem;
        transition: transform 0.3s ease;
        display: inline-block;
        color: rgba(255,255,255,0.4);
    }
    .nav-item-dropdown.active > a.nav-link-tratamentos::after {
        transform: rotate(180deg);
        color: var(--primary-light, #10B981);
    }

    /* Section label for "Tratamentos" when expanded */
    .nav-item-dropdown.active > a.nav-link-tratamentos {
        color: var(--primary-light, #10B981) !important;
        border-bottom-color: transparent !important;
    }

    /* Dropdown items: Vertical Accordion List */
    .dropdown-menu {
        position: static !important;
        transform: none !important;
        opacity: 1 !important;
        visibility: visible !important;
        box-shadow: none !important;
        background: transparent !important;
        border-radius: 0 !important;
        padding: 0 0 16px 16px !important;
        display: none;
        flex-direction: column !important;
        gap: 0 !important;
        width: 100%;
        margin: 0;
        border-left: 2px solid rgba(16, 185, 129, 0.3) !important;
        max-height: none;
        overflow-y: visible;
    }

    .nav-item-dropdown.active .dropdown-menu {
        display: flex !important;
        animation: accordionSlideDown 0.3s ease forwards;
    }

    @keyframes accordionSlideDown {
        from { opacity: 0; transform: translateY(-10px); }
        to { opacity: 1; transform: translateY(0); }
    }

    .dropdown-menu a {
        font-size: 1.05rem !important;
        font-weight: 500 !important;
        min-height: 48px !important;
        display: flex;
        align-items: center;
        justify-content: flex-start;
        text-align: left;
        border-radius: 8px !important;
        padding: 10px 16px !important;
        color: rgba(255,255,255,0.75) !important;
        background: transparent;
        transition: background 0.2s ease, color 0.2s ease, padding-left 0.2s ease;
        border-bottom: 1px solid rgba(255,255,255,0.03) !important;
        width: 100%;
        box-sizing: border-box;
    }

    .dropdown-menu a:last-child {
        border-bottom: none !important;
    }

    .dropdown-menu a:active {
        background: rgba(16, 185, 129, 0.1) !important;
        color: white !important;
        padding-left: 24px !important;
    }

    /* ── Mobile hamburger — HIG 44px ──────────────────────────── */
    .mobile-menu-toggle {
        display: flex;
        align-items: center;
        justify-content: center;
        min-width: 48px;
        min-height: 48px;
        font-size: 1.6rem;
        border-radius: 10px;
        background: rgba(255,255,255,0.25);
        color: white !important;
        border: 1.5px solid rgba(255,255,255,0.4);
        -webkit-backdrop-filter: blur(8px);
        backdrop-filter: blur(8px);
        z-index: 1100;
        position: relative;
        box-shadow: 0 2px 12px rgba(0,0,0,0.3);
    }

    .scrolled .mobile-menu-toggle {
        background: rgba(255,255,255,0.2) !important;
        color: white !important;
        border: 1.5px solid rgba(255,255,255,0.35) !important;
    }

    /* When menu is open, hamburger (X) is always white */
    .mobile-menu-toggle[aria-expanded="true"] {
        color: white !important;
        background: rgba(255,255,255,0.1) !important;
        position: fixed;
        top: max(16px, env(safe-area-inset-top));
        right: 20px;
    }

    /* Overlay — hidden since menu is fullscreen */
    .nav-overlay {
        display: none;
    }

    /* ── HERO ───────────────────────────────────────────────────── */
    .hero-premium {
        height: auto !important;
        min-height: 100svh; /* svh = small viewport height, safe on iOS */
        margin-top: 0 !important;
        padding-top: calc(100px + env(safe-area-inset-top)) !important;
        padding-bottom: 60px;
        align-items: flex-end;
    }

    .hero-content {
        padding-top: 0 !important;
        padding-bottom: 24px;
    }

    .hero-content h1 {
        font-size: clamp(1.6rem, 6vw, 2.2rem) !important;
        line-height: 1.2 !important;
        letter-spacing: -0.5px;
    }

    .hero-content p {
        font-size: 1rem !important;
        margin: 16px 0 28px !important;
        max-width: 100% !important;
    }

    .hero-actions {
        flex-direction: column !important;
        gap: 12px !important;
        width: 100%;
    }

    .hero-actions .btn-premium {
        width: 100%;
        text-align: center;
        min-height: 52px;
        font-size: 1rem !important;
        padding: 14px 24px !important;
        display: flex;
        align-items: center;
        justify-content: center;
    }

    /* ── INTERNAL HEADER (patologia pages) ─────────────────────── */
    .internal-header {
        padding: max(120px, calc(100px + env(safe-area-inset-top))) 0 64px;
    }

    .internal-header h1 {
        font-size: clamp(1.8rem, 7vw, 2.8rem) !important;
    }

    .internal-header p {
        font-size: 1rem !important;
    }

    .header-badge {
        font-size: 0.7rem;
        padding: 6px 14px;
    }

    /* ── GRID SYSTEM ────────────────────────────────────────────── */
    .grid-asymmetric {
        grid-template-columns: 1fr !important;
        gap: 24px !important;
    }

    .span-8, .span-7, .span-6, .span-5, .span-4 {
        grid-column: span 1 !important;
    }

    /* Sidebar appears below content on mobile */
    .span-4 {
        order: 2;
    }
    .span-8 {
        order: 1;
    }

    /* Sidebar sticky off on mobile */
    .span-4 > div[style*="sticky"] {
        position: relative !important;
        top: auto !important;
    }

    /* ── CONTENT ────────────────────────────────────────────────── */
    .content-rich-text {
        font-size: 1rem !important;
        line-height: 1.75;
    }

    .content-rich-text h2 {
        font-size: 1.4rem !important;
    }

    .content-rich-text h3 {
        font-size: 1.25rem !important;
    }

    .content-rich-text img {
        border-radius: 16px !important;
    }

    .premium-lead {
        font-size: 1rem !important;
    }

    /* ── TYPOGRAPHY ─────────────────────────────────────────────── */
    /* HIG: minimum readable font size = 16px */
    p, li, td, th {
        font-size: max(1rem, 16px);
    }

    .section-title {
        font-size: clamp(1.5rem, 5vw, 2rem) !important;
    }

    /* ── CARDS ──────────────────────────────────────────────────── */
    .premium-card {
        padding: 24px !important;
    }

    /* Cards grid: single column on phone */
    [style*="display: grid"],
    [style*="display:grid"] {
        grid-template-columns: 1fr !important;
        display: grid !important;
    }
    [style*="display: grid"] > *,
    [style*="display:grid"] > * {
        margin-bottom: 0 !important;
    }

    /* ── BUTTONS ────────────────────────────────────────────────── */
    /* HIG: min touch target 44pt = 44px */
    .btn-premium {
        min-height: 48px;
        padding: 14px 28px !important;
        font-size: 0.95rem !important;
        -webkit-appearance: none;
        appearance: none;
    }

    /* ── MAP ────────────────────────────────────────────────────── */
    .premium-map-section {
        height: 300px !important;
    }

    /* ── FOOTER ─────────────────────────────────────────────────── */
    .premium-footer {
        padding: 48px 0 max(32px, calc(24px + env(safe-area-inset-bottom)));
    }

    /* Footer columns: stack vertically */
    .premium-footer > .container-premium > div {
        flex-direction: column !important;
        gap: 32px !important;
    }

    .footer-bottom {
        flex-direction: column;
        gap: 12px;
        text-align: center;
    }

    /* ── FORM ───────────────────────────────────────────────────── */
    .premium-form-container {
        padding: 24px 20px !important;
    }

    /* iOS: prevent form zoom (input font-size must be ≥ 16px) */
    .premium-input,
    select.premium-input,
    textarea.premium-input,
    .form-control,
    select.form-control,
    textarea.form-control {
        font-size: 16px !important;
        -webkit-appearance: none;
        appearance: none;
        border-radius: 12px;
    }

    /* contact-form-container: reduce padding on small screens */
    .contact-form-container {
        padding: 24px 20px !important;
    }

    /* Inline grid with 2 columns inside contact form → 1 column */
    .contact-form-container .grid-asymmetric,
    .contact-form-container [style*="grid-template-columns: 1fr 1fr"],
    .contact-form-container [style*="grid-template-columns:1fr 1fr"] {
        grid-template-columns: 1fr !important;
        gap: 0 !important;
    }

    /* ── SECTION TITLE MARGINS ──────────────────────────────────── */
    .section-padding h2:first-child {
        margin-top: 0;
    }

    /* ── HERO CONTENT: fix extra top padding on mobile ───────────── */
    /* hero-premium already has padding-top for the nav; hero-content
       does NOT need its own extra top padding on phone */
    section.hero-premium .hero-content {
        padding-top: 0 !important;
    }

    /* ── HIDE DECORATIVE ELEMENTS ───────────────────────────────── */
    .floating-accent {
        display: none;
    }

    /* ── INLINE STYLE OVERRIDES for flex layouts ─────────────────── */
    /* Footer flex row → column */
    .premium-footer [style*="display: flex"][style*="justify-content: space-between"] {
        flex-direction: column !important;
        gap: 32px !important;
    }

    /* ── INDEX PAGE: Patologias grid ──────────────────────────────── */
    /* 3-col grid → 1-col on phone */
    .grid-3 {
        grid-template-columns: 1fr !important;
    }
}

/* ─── TABLET (768px–991px) ───────────────────────────────────────────────── */
@media (min-width: 768px) and (max-width: 991px) {

    .container-premium {
        padding: 0 32px;
    }

    .section-padding {
        padding: 80px 0;
    }

    .hero-content h1 {
        font-size: clamp(2rem, 5vw, 3rem) !important;
    }

    .hero-actions {
        gap: 16px !important;
    }

    /* 2-column grid on tablet */
    .grid-asymmetric {
        grid-template-columns: 1fr 1fr !important;
        gap: 24px !important;
    }

    .span-8 { grid-column: span 2 !important; }
    .span-7 { grid-column: span 2 !important; }
    .span-6 { grid-column: span 1 !important; }
    .span-5 { grid-column: span 1 !important; }
    .span-4 { grid-column: span 2 !important; }

    /* Sidebar in tablet: full width below article */
    .span-4 {
        order: 2;
    }
    .span-8 {
        order: 1;
        grid-column: span 2 !important;
    }

    /* Internal header */
    .internal-header {
        padding: 160px 0 80px;
    }

    /* Map */
    .premium-map-section {
        height: 380px;
    }

    /* Form */
    .premium-input,
    select.premium-input,
    textarea.premium-input {
        font-size: 16px !important;
    }
}

/* ─── LANDSCAPE PHONES (max-height: 500px, landscape orientation) ─────────── */
@media (max-height: 500px) and (orientation: landscape) {

    .hero-premium {
        min-height: 100svh;
        height: auto !important;
        align-items: center;
    }

    .hero-content {
        padding-top: 80px !important;
        padding-bottom: 24px;
    }

    .hero-content h1 {
        font-size: 1.5rem !important;
        margin-bottom: 12px;
    }

    .hero-content p {
        display: none; /* Hide subtitle in landscape to save space */
    }

    .hero-actions {
        flex-direction: row !important;
        flex-wrap: wrap;
        gap: 12px !important;
    }

    .internal-header {
        padding: 100px 0 48px;
    }
}

/* ═══════════════════════════════════════════════════════════════════════════
   2. iOS SAFARI SPECIFIC FIXES
   ═══════════════════════════════════════════════════════════════════════════ */

/* Fix position: sticky inside overflow: hidden on iOS */
@supports (-webkit-touch-callout: none) {
    .premium-nav {
        position: -webkit-sticky;
        position: sticky;
    }

    /* iOS Safari: fix 100vh including browser chrome */
    .hero-premium {
        min-height: -webkit-fill-available;
    }

    /* Fix backdrop-filter on older iOS */
    .premium-nav {
        -webkit-backdrop-filter: blur(20px) saturate(180%);
        backdrop-filter: blur(20px) saturate(180%);
    }

    /* Fix for Safari overflow scroll performance */
    .nav-links {
        -webkit-overflow-scrolling: touch;
    }

    /* Fix for Safari flexbox gap support < iOS 14 */
    .hero-actions > * + * {
        margin-left: 24px;
    }

    @media (max-width: 767px) {
        .hero-actions > * + * {
            margin-left: 0;
            margin-top: 12px;
        }
    }
}

/* ═══════════════════════════════════════════════════════════════════════════
   3. ANDROID CHROME SPECIFIC FIXES
   ═══════════════════════════════════════════════════════════════════════════ */

/* Android: fix for overscroll color (address bar color) */
@media (max-width: 767px) {
    html {
        background-color: var(--secondary);
    }
}

/* ═══════════════════════════════════════════════════════════════════════════
   4. ACCESSIBILITY & INTERACTION IMPROVEMENTS
   ═══════════════════════════════════════════════════════════════════════════ */

/* Focus ring for keyboard navigation (also visible on Android with keyboard) */
:focus-visible {
    outline: 3px solid var(--primary-light);
    outline-offset: 3px;
    border-radius: 4px;
}

/* Remove hover-only effects on touch devices to prevent sticky hover on iOS */
@media (hover: none) {
    .premium-card:hover {
        transform: none;
        box-shadow: 0 10px 30px rgba(0,0,0,0.03);
        border-color: rgba(0,0,0,0.05);
    }

    .btn-premium-primary:hover {
        transform: none;
        box-shadow: none;
        background: var(--primary);
    }

    .premium-card-cta:hover {
        transform: none;
        background: rgba(255, 255, 255, 0.05);
    }

    /* Active state for touch instead */
    .btn-premium:active {
        transform: scale(0.97);
        opacity: 0.9;
    }

    .premium-card:active {
        transform: scale(0.99);
    }
}

/* ═══════════════════════════════════════════════════════════════════════════
   5. PRINT (bonus — clean print layout)
   ═══════════════════════════════════════════════════════════════════════════ */

@media print {
    .premium-nav,
    .mobile-menu-toggle,
    .hero-premium,
    .premium-map-section,
    .premium-footer,
    .hero-actions,
    .btn-premium {
        display: none !important;
    }

    body {
        font-size: 12pt;
        color: black;
    }

    .internal-header {
        padding: 24pt 0;
        background: none;
        border-bottom: 2pt solid black;
    }

    .internal-header h1,
    .internal-header p {
        color: black !important;
    }

    .content-rich-text {
        max-width: 100%;
    }
}

/* ── HERO INDEX: imagem + texto empilhados no mobile ───────────────────── */
@media (max-width: 767px) {
    .hero-content {
        flex-direction: column !important;
        align-items: center !important;
        gap: 24px !important;
        margin-top: 0 !important;
        text-align: center !important;
        padding: 0 16px !important;
    }
    .hero-content > div:first-child {
        width: 100% !important;
        max-width: 100% !important;
        flex: 0 0 auto !important;
        display: flex !important;
        justify-content: center !important;
        align-items: center !important;
    }
    .hero-content > div:first-child > div {
        width: 260px !important;
        max-width: 80vw !important;
        margin: 0 auto !important;
    }
    .hero-content > div:first-child img {
        width: 100% !important;
        height: auto !important;
        max-height: 300px !important;
        object-fit: cover !important;
        object-position: top center !important;
    }
    .hero-content > div:last-child {
        width: 100% !important;
        flex: 1 1 auto !important;
    }
    .hero-badge {
        align-self: center !important;
        margin-left: auto !important;
        margin-right: auto !important;
    }
}

/* ═══════════════════════════════════════════════════════════════════════════
   6. TABLET SUPPLEMENTAL FIXES (iPad / iPad Pro)
   ═══════════════════════════════════════════════════════════════════════════ */

/* iPad: fix dropdown "sticky hover" when using Apple Pencil or Magic Keyboard.
   On touch devices that also report hover:hover (iPads with pointer), the
   dropdown can get stuck open. We use :focus-within as a safer trigger. */
@media (min-width: 768px) and (max-width: 1199px) {

    /* Ensure dropdown still works on touch via :focus-within */
    .nav-item-dropdown:focus-within .dropdown-menu {
        opacity: 1;
        visibility: visible;
        transform: translateX(-50%) translateY(0);
    }

    /* WhatsApp: slightly smaller on tablet, stays clear of content */
    .whatsapp-float {
        width: 56px;
        height: 56px;
        right: 20px;
    }

    .whatsapp-float svg {
        width: 28px;
        height: 28px;
    }
}

/* ═══════════════════════════════════════════════════════════════════════════
   7. COOKIE BANNER + WHATSAPP FLOAT COORDINATION
   ═══════════════════════════════════════════════════════════════════════════ */

/* When the cookie banner is visible, shift WhatsApp button up
   so it doesn't cover the "Aceitar" / "Recusar" buttons */
@media (max-width: 767px) {
    /* Class added by JS when banner is shown — see enhancement note */
    body.cookie-banner-visible .whatsapp-float {
        bottom: max(100px, calc(90px + env(safe-area-inset-bottom)));
        transition: bottom 0.3s ease;
    }
}