/**
 * Mobile Bottom Navigation Bar
 * ============================
 * Fixed bottom tab bar for mobile devices (<768px).
 * 
 * Items: О компании | Врачи | Записаться (CTA) | Услуги | Отзывы
 * Design: Unique organic style — cream background, green-tinted layered shadow,
 *         floating CTA with subtle gradient pulse, smooth scroll-hide.
 * 
 * Skills: emil-design-eng, make-interfaces-feel-better, accessibility-compliance
 * Breakpoint: SM (≤767.98px) only
 */

/* ============================================
   CSS Custom Properties (scoped)
   ============================================ */
:root {
    --bottom-nav-height: 64px;
    --bottom-nav-bg: var(--color-cream, #FEFADF);
    --bottom-nav-icon-size: 22px;
    --bottom-nav-label-size: 10px;
    --bottom-nav-cta-size: 54px;
    --bottom-nav-cta-color: var(--color-cta-orange, #FF6633);
    --bottom-nav-text-color: var(--color-primary-green, #195F40);
    --bottom-nav-active-color: var(--color-cta-orange, #FF6633);
    /* Strong ease-out for UI interactions (Emil) */
    --ease-out-ui: cubic-bezier(0.23, 1, 0.32, 1);
}

/* ============================================
   Container — hidden on desktop
   ============================================ */
.bottom-nav {
    display: none; /* Hidden on desktop — screen readers won't see it */
}

@media (max-width: 767.98px) {
    /* ============================================
       Main Container
       ============================================ */
    .bottom-nav {
        display: block;
        position: fixed;
        bottom: 0;
        left: 0;
        right: 0;
        z-index: 9998; /* Below mobile-menu overlay (9999) */
        background: var(--bottom-nav-bg);
        /* Thin top rule — always visible, even on same-color bg */
        border-top: 1px solid rgba(25, 95, 64, 0.12);
        /* Stronger layered shadows for contrast against cream sections */
        box-shadow:
            0 -2px 6px rgba(25, 95, 64, 0.10),
            0 -8px 24px rgba(25, 95, 64, 0.12),
            0 -16px 48px rgba(25, 95, 64, 0.07);
        /* Safe area for iPhone notch/home indicator */
        padding-bottom: env(safe-area-inset-bottom, 0px);
        /* Scroll hide/show transition */
        transform: translateY(0);
        transition: transform 0.35s var(--ease-out-ui);
        will-change: transform;
    }

    /* State: hidden on scroll down */
    .bottom-nav.is-hidden {
        transform: translateY(calc(100% + 10px));
    }

    /* State: hidden when menu or modal is open */
    body.menu-open .bottom-nav,
    body.modal-open .bottom-nav {
        transform: translateY(calc(100% + 10px));
        transition-duration: 0.2s;
    }

    /* ============================================
       CTA shield — cream background behind raised button
       Prevents content from showing through
       ============================================ */
    .bottom-nav__item--cta::before {
        content: '';
        position: absolute;
        top: -2px;
        left: 50%;
        transform: translateX(-50%);
        width: 70px;
        height: 36px;
        background: var(--bottom-nav-bg);
        border-radius: 20px 20px 0 0;
        z-index: -1;
        /* Subtle shadow so shield doesn't merge into same-color content */
        box-shadow:
            0 -2px 8px rgba(25, 95, 64, 0.10),
            -2px 0 6px rgba(25, 95, 64, 0.06),
            2px 0 6px rgba(25, 95, 64, 0.06);
    }

    /* ============================================
       Navigation List
       ============================================ */
    .bottom-nav__list {
        display: grid;
        grid-template-columns: repeat(5, minmax(0, 1fr));
        align-items: center;
        justify-items: center;
        list-style: none;
        margin: 0;
        padding: 5px 8px;
        height: var(--bottom-nav-height);
    }

    /* ============================================
       Navigation Item
       ============================================ */
    .bottom-nav__item {
        display: flex;
        flex-direction: column;
        align-items: center;
        justify-content: center;
        gap: 3px;
        min-width: 0;
        min-height: 48px; /* WCAG 2.5.8 touch target */
        position: relative;
        -webkit-tap-highlight-color: transparent;
    }

    /* ============================================
       Navigation Link
       ============================================ */
    .bottom-nav__link {
        display: flex;
        flex-direction: column;
        align-items: center;
        justify-content: center;
        gap: 3px;
        text-decoration: none;
        color: var(--bottom-nav-text-color);
        min-width: 56px;
        min-height: 48px; /* WCAG touch target */
        padding: 4px 2px;
        border-radius: 12px;
        position: relative;
    }

    /* Subtle active indicator — rounded pill behind icon (not just color change) */
    .bottom-nav__item.is-active .bottom-nav__link::before {
        content: '';
        position: absolute;
        top: 2px;
        left: 50%;
        transform: translateX(-50%);
        width: 36px;
        height: 28px;
        background: rgba(255, 102, 51, 0.1);
        border-radius: 14px;
        z-index: -1;
    }

    /* Focus visible (WCAG — keyboard nav) */
    .bottom-nav__link:focus-visible {
        outline: 2px solid var(--bottom-nav-active-color);
        outline-offset: 2px;
        border-radius: 12px;
    }

    /* Tap feedback — scale on icon only (Emil: scale(0.96) on press) */
    .bottom-nav__link:active .bottom-nav__icon {
        transform: scale(0.92);
    }

    .bottom-nav__icon {
        width: var(--bottom-nav-icon-size);
        height: var(--bottom-nav-icon-size);
        flex-shrink: 0;
        transition: transform 0.12s ease-out, color 0.2s ease;
    }

    /* ============================================
       Label
       ============================================ */
    .bottom-nav__label {
        font-family: 'Montserrat', sans-serif;
        font-size: var(--bottom-nav-label-size);
        font-weight: 600;
        letter-spacing: 0.3px;
        line-height: 1;
        text-transform: uppercase;
        color: var(--bottom-nav-text-color);
        transition: color 0.2s ease;
        white-space: nowrap;
    }

    /* Tighten labels on very narrow phones (≤359.98px) */
    @media (max-width: 359.98px) {
        .bottom-nav__label {
            font-size: 9px;
            letter-spacing: 0.2px;
        }
    }

    /* ============================================
       Active State — orange icon + label + pill bg
       ============================================ */
    .bottom-nav__item.is-active .bottom-nav__icon,
    .bottom-nav__item.is-active .bottom-nav__label {
        color: var(--bottom-nav-active-color);
    }

    /* ============================================
       CTA Button — «Записаться» (center item)
       Unique design: soft gradient, organic shadow,
       subtle floating animation, NOT a simple circle
       ============================================ */
    .bottom-nav__item--cta {
        position: relative;
        align-self: center;
        /* Remove default gap — CTA has its own spacing */
        gap: 0;
    }

    .bottom-nav__cta {
        display: flex;
        align-items: center;
        justify-content: center;
        width: var(--bottom-nav-cta-size);
        height: var(--bottom-nav-cta-size);
        border-radius: 18px; /* Rounded square — unique, NOT circle */
        /* Subtle gradient — NOT flat color */
        background: linear-gradient(145deg, #FF7A4D 0%, var(--bottom-nav-cta-color) 50%, #E8552B 100%);
        border: none;
        cursor: pointer;
        position: relative;
        /* Float above the bar */
        transform: translateY(-14px);
        /* Layered shadow — warm orange glow (Emil: layered transparent box-shadow) */
        box-shadow:
            0 2px 4px rgba(255, 102, 51, 0.2),
            0 6px 16px rgba(255, 102, 51, 0.25),
            0 12px 32px rgba(255, 102, 51, 0.15);
        transition:
            transform 0.2s var(--ease-out-ui),
            box-shadow 0.2s var(--ease-out-ui);
        -webkit-tap-highlight-color: transparent;
        /* Concentric radius: inner icon doesn't need radius matching here */
    }

    /* CTA press feedback (Emil: scale(0.96), never below 0.95) */
    .bottom-nav__cta:active {
        transform: translateY(-14px) scale(0.95);
        box-shadow:
            0 1px 2px rgba(255, 102, 51, 0.2),
            0 3px 8px rgba(255, 102, 51, 0.2);
    }

    /* Focus visible for keyboard users */
    .bottom-nav__cta:focus-visible {
        outline: 3px solid var(--bottom-nav-text-color);
        outline-offset: 3px;
    }

    /* CTA icon — white */
    .bottom-nav__cta-icon {
        width: 24px;
        height: 24px;
        color: #FFFFFF;
        flex-shrink: 0;
    }

    /* CTA label — below the button */
    .bottom-nav__label--cta {
        color: var(--bottom-nav-cta-color);
        font-weight: 700;
        margin-top: -8px;
    }

    /* ============================================
       Subtle pulse ring animation — draws attention
       on first load, then stops (not infinite — 
       infinite animations are distracting per Emil)
       ============================================ */
    .bottom-nav__cta::after {
        content: '';
        position: absolute;
        inset: -4px;
        border-radius: 22px; /* Concentric: 18px + 4px */
        border: 2px solid var(--bottom-nav-cta-color);
        opacity: 0;
        animation: bottomNavPulse 2s ease-out 1s 2; /* 2 pulses, after 1s delay */
    }

    @keyframes bottomNavPulse {
        0% {
            transform: scale(1);
            opacity: 0.5;
        }
        100% {
            transform: scale(1.25);
            opacity: 0;
        }
    }

    /* ============================================
       Body Padding — prevent content overlap
       ============================================ */
    body {
        padding-bottom: calc(var(--bottom-nav-height) + env(safe-area-inset-bottom, 0px));
    }

    /* Don't add padding on 404 and maintenance (standalone pages) */
    body.error404,
    body.maintenance-page {
        padding-bottom: 0;
    }
}

/* ============================================
   Accessibility: prefers-reduced-motion
   Keep color changes, remove movement (Emil)
   ============================================ */
@media (max-width: 767.98px) and (prefers-reduced-motion: reduce) {
    .bottom-nav {
        transition: none;
    }

    .bottom-nav.is-hidden {
        /* Instant hide instead of slide */
        opacity: 0;
        visibility: hidden;
        transform: none;
    }

    .bottom-nav__cta {
        transition: none;
    }

    .bottom-nav__cta::after {
        animation: none;
    }

    .bottom-nav__link:active .bottom-nav__icon {
        transform: none;
    }

    .bottom-nav__cta:active {
        transform: translateY(-18px); /* No scale */
    }
}
