/* ========================================
   Mobile Experience Enhancements
   Bottom Nav, Focus Mode, Swipe, Tables
   ======================================== */

/* =========================================
   1. BOTTOM NAVIGATION BAR (Mobile Only)
   ========================================= */
.mobile-bottom-nav {
    display: none; /* Hidden on desktop */
    position: fixed;
    bottom: 0;
    left: 0;
    right: 0;
    z-index: 10000;
    background: rgba(15, 23, 42, 0.97);
    backdrop-filter: blur(20px);
    -webkit-backdrop-filter: blur(20px);
    border-top: 1px solid rgba(99, 102, 241, 0.15);
    padding: 0;
    padding-bottom: env(safe-area-inset-bottom, 0);
    font-family: 'Tajawal', sans-serif;
    direction: rtl;
    transition: transform 0.35s cubic-bezier(0.4, 0, 0.2, 1);
}

.mobile-bottom-nav.hidden {
    transform: translateY(100%);
}

.mobile-bottom-nav-inner {
    display: flex;
    align-items: stretch;
    justify-content: space-around;
    max-width: 480px;
    margin: 0 auto;
    height: 60px;
}

.mobile-bottom-nav-item {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    flex: 1;
    text-decoration: none;
    color: #64748b;
    font-size: 0.62rem;
    font-weight: 500;
    gap: 3px;
    position: relative;
    transition: all 0.2s ease;
    -webkit-tap-highlight-color: transparent;
    padding: 6px 2px;
}

.mobile-bottom-nav-item i {
    font-size: 1.15rem;
    transition: all 0.25s cubic-bezier(0.34, 1.56, 0.64, 1);
}

.mobile-bottom-nav-item span {
    transition: all 0.2s;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    max-width: 64px;
    text-align: center;
}

.mobile-bottom-nav-item.active {
    color: #6366f1;
}

.mobile-bottom-nav-item.active i {
    transform: scale(1.15) translateY(-2px);
    color: #818cf8;
}

.mobile-bottom-nav-item.active span {
    font-weight: 700;
    color: #6366f1;
}

/* Active indicator dot */
.mobile-bottom-nav-item.active::before {
    content: '';
    position: absolute;
    top: 2px;
    width: 20px;
    height: 3px;
    border-radius: 2px;
    background: linear-gradient(135deg, #6366f1, #06b6d4);
}

/* Ripple effect on tap */
.mobile-bottom-nav-item::after {
    content: '';
    position: absolute;
    inset: 4px 8px;
    border-radius: 12px;
    background: rgba(99, 102, 241, 0);
    transition: background 0.3s;
}

.mobile-bottom-nav-item:active::after {
    background: rgba(99, 102, 241, 0.1);
}

/* More menu button */
.mobile-bottom-nav-more {
    position: relative;
}

/* More menu popup */
.mobile-more-menu {
    position: absolute;
    bottom: calc(100% + 12px);
    left: 50%;
    transform: translateX(-50%) scale(0.9);
    width: 200px;
    background: rgba(15, 23, 42, 0.98);
    backdrop-filter: blur(20px);
    -webkit-backdrop-filter: blur(20px);
    border: 1px solid rgba(99, 102, 241, 0.2);
    border-radius: 16px;
    box-shadow: 0 -12px 40px rgba(0, 0, 0, 0.3);
    opacity: 0;
    pointer-events: none;
    transition: all 0.25s cubic-bezier(0.34, 1.56, 0.64, 1);
    z-index: 10001;
    padding: 8px;
    overflow: hidden;
}

.mobile-more-menu.open {
    opacity: 1;
    pointer-events: auto;
    transform: translateX(-50%) scale(1);
}

.mobile-more-menu-item {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 10px 14px;
    border-radius: 10px;
    text-decoration: none;
    color: #94a3b8;
    font-size: 0.82rem;
    font-weight: 500;
    transition: all 0.15s;
}

.mobile-more-menu-item:hover,
.mobile-more-menu-item:active {
    background: rgba(99, 102, 241, 0.1);
    color: #e2e8f0;
}

.mobile-more-menu-item i {
    width: 20px;
    text-align: center;
    font-size: 0.85rem;
    color: #818cf8;
}

.mobile-more-menu-item.active {
    color: #6366f1;
    font-weight: 700;
}

/* =========================================
   2. RESPONSIVE TABLES
   ========================================= */
.mobile-table-wrapper {
    position: relative;
    margin: 16px 0;
}

.mobile-table-wrapper table {
    min-width: 100%;
}

.mobile-table-scroll {
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
    scrollbar-width: thin;
    scrollbar-color: rgba(99, 102, 241, 0.3) transparent;
    border-radius: 12px;
}

.mobile-table-scroll::-webkit-scrollbar {
    height: 4px;
}

.mobile-table-scroll::-webkit-scrollbar-thumb {
    background: rgba(99, 102, 241, 0.3);
    border-radius: 2px;
}

/* Scroll indicator */
.mobile-table-hint {
    display: none;
    text-align: center;
    font-size: 0.72rem;
    color: rgba(255, 255, 255, 0.35);
    padding: 4px 0;
    gap: 6px;
    align-items: center;
    justify-content: center;
}

.mobile-table-hint i {
    animation: mobileTableSwipe 1.5s ease-in-out infinite;
}

@keyframes mobileTableSwipe {
    0%, 100% { transform: translateX(0); }
    50% { transform: translateX(-8px); }
}


/* =========================================
   3. FOCUS MODE
   ========================================= */
.focus-mode-btn {
    display: none; /* Only shown on mobile */
    position: fixed;
    top: 70px;
    left: 12px;
    z-index: 9997;
    width: 38px;
    height: 38px;
    border-radius: 50%;
    border: 1.5px solid rgba(99, 102, 241, 0.3);
    background: rgba(15, 23, 42, 0.85);
    backdrop-filter: blur(10px);
    -webkit-backdrop-filter: blur(10px);
    color: #818cf8;
    font-size: 0.85rem;
    cursor: pointer;
    transition: all 0.3s;
    align-items: center;
    justify-content: center;
}

.focus-mode-btn:hover {
    background: rgba(99, 102, 241, 0.2);
    border-color: #6366f1;
}

.focus-mode-btn.active {
    background: linear-gradient(135deg, #6366f1, #06b6d4);
    border-color: transparent;
    color: #fff;
}

/* Focus mode active - hide floating elements */
body.focus-mode .cx-next-action,
body.focus-mode .notes-fab,
body.focus-mode .notes-panel,
body.focus-mode .cx-search-trigger,
body.focus-mode .cx-toast-container,
body.focus-mode .mobile-bottom-nav {
    display: none !important;
}

body.focus-mode .focus-mode-btn {
    bottom: 16px;
    top: auto;
    background: linear-gradient(135deg, #6366f1, #06b6d4);
    border-color: transparent;
    color: #fff;
    box-shadow: 0 4px 16px rgba(99, 102, 241, 0.4);
}

/* Focus mode banner */
.focus-mode-banner {
    display: none;
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    z-index: 10002;
    background: linear-gradient(135deg, #6366f1, #06b6d4);
    color: #fff;
    text-align: center;
    padding: 6px 16px;
    font-size: 0.75rem;
    font-weight: 600;
    font-family: 'Tajawal', sans-serif;
    direction: rtl;
}

body.focus-mode .focus-mode-banner {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
}

body.focus-mode .site-nav {
    top: 28px;
}


/* =========================================
   4. SWIPE NAVIGATION (unit.html)
   ========================================= */
.swipe-nav-indicator {
    display: none; /* Only on mobile */
    position: fixed;
    top: 50%;
    transform: translateY(-50%);
    z-index: 9990;
    width: 32px;
    height: 64px;
    border-radius: 0 12px 12px 0;
    background: rgba(99, 102, 241, 0.15);
    backdrop-filter: blur(8px);
    -webkit-backdrop-filter: blur(8px);
    color: #818cf8;
    font-size: 0.85rem;
    align-items: center;
    justify-content: center;
    pointer-events: none;
    opacity: 0;
    transition: opacity 0.3s;
}

.swipe-nav-indicator.left {
    left: 0;
    border-radius: 0 12px 12px 0;
}

.swipe-nav-indicator.right {
    right: 0;
    border-radius: 12px 0 0 12px;
}

.swipe-nav-indicator.visible {
    opacity: 1;
}

/* Swipe progress bar */
.swipe-progress {
    display: none;
    position: fixed;
    bottom: 68px;
    left: 16px;
    right: 16px;
    height: 3px;
    background: rgba(255, 255, 255, 0.08);
    border-radius: 2px;
    z-index: 9995;
    overflow: hidden;
}

.swipe-progress-fill {
    height: 100%;
    background: linear-gradient(90deg, #6366f1, #06b6d4);
    border-radius: 2px;
    transition: width 0.3s ease;
}

/* Unit swipe hint toast */
.swipe-hint {
    position: fixed;
    bottom: 80px;
    left: 50%;
    transform: translateX(-50%) translateY(20px);
    z-index: 10001;
    background: rgba(15, 23, 42, 0.95);
    border: 1px solid rgba(99, 102, 241, 0.2);
    border-radius: 12px;
    padding: 10px 20px;
    display: flex;
    align-items: center;
    gap: 10px;
    color: #94a3b8;
    font-size: 0.78rem;
    font-family: 'Tajawal', sans-serif;
    direction: rtl;
    opacity: 0;
    pointer-events: none;
    transition: all 0.3s ease;
    white-space: nowrap;
}

.swipe-hint.visible {
    opacity: 1;
    transform: translateX(-50%) translateY(0);
}

.swipe-hint i {
    color: #818cf8;
    font-size: 1rem;
}


/* =========================================
   5. FLOATING BUTTONS REPOSITIONING
   ========================================= */

/* =========================================
   MOBILE ONLY RULES
   ========================================= */
@media (max-width: 768px) {
    /* Show bottom nav */
    .mobile-bottom-nav {
        display: block;
    }

    /* Show focus mode button */
    .focus-mode-btn {
        display: flex;
    }

    /* Show swipe elements on unit page */
    .swipe-nav-indicator {
        display: flex;
    }
    .swipe-progress {
        display: block;
    }

    /* Show table hint */
    .mobile-table-hint {
        display: flex;
    }

    /* ---- Reposition floating buttons above bottom nav ---- */
    /* Next Action widget */
    .cx-next-action {
        bottom: 74px !important;
        right: 12px !important;
    }
    .cx-na-toggle {
        width: 48px !important;
        height: 48px !important;
        font-size: 1rem !important;
    }
    .cx-na-panel {
        bottom: 60px !important;
        max-height: 60vh !important;
    }

    /* Search trigger */
    .cx-search-trigger {
        bottom: 140px !important;
        left: 12px !important;
        width: 38px !important;
        height: 38px !important;
        font-size: 0.85rem !important;
    }

    /* Notes FAB */
    .notes-fab {
        bottom: 74px !important;
        left: 62px !important;
        width: 42px !important;
        height: 42px !important;
        font-size: 0.95rem !important;
    }
    .notes-panel {
        bottom: 130px !important;
        max-height: 55vh !important;
    }

    /* Add bottom padding to body for bottom nav */
    body {
        padding-bottom: 68px !important;
    }

    /* Also offset the top nav body padding */
    body:has(.site-nav) .tool-page,
    body:has(.site-nav) .unit-page {
        padding-top: 80px;
    }

    /* Hide top nav on scroll down, show on scroll up (controlled by JS) */
    .site-nav.nav-hidden {
        transform: translateY(-100%);
        transition: transform 0.35s cubic-bezier(0.4, 0, 0.2, 1);
    }
    .site-nav {
        transition: transform 0.35s cubic-bezier(0.4, 0, 0.2, 1);
    }

    /* Focus mode adjustments */
    body.focus-mode {
        padding-bottom: 0 !important;
    }
}

/* Smaller phones */
@media (max-width: 480px) {
    .mobile-bottom-nav-inner {
        height: 56px;
    }

    .mobile-bottom-nav-item {
        font-size: 0.58rem;
    }

    .mobile-bottom-nav-item i {
        font-size: 1.05rem;
    }

    .mobile-more-menu {
        width: 180px;
    }

    /* Tables */
    .mobile-table-wrapper {
        margin: 8px -8px;
    }

    /* Floating buttons */
    .cx-next-action {
        bottom: 68px !important;
        right: 8px !important;
    }
    .cx-na-toggle {
        width: 44px !important;
        height: 44px !important;
    }

    .cx-search-trigger {
        bottom: 124px !important;
        left: 8px !important;
        width: 36px !important;
        height: 36px !important;
    }

    .notes-fab {
        bottom: 68px !important;
        left: 54px !important;
        width: 38px !important;
        height: 38px !important;
    }

    body {
        padding-bottom: 60px !important;
    }
}


/* =========================================
   6. JOURNEY MAP TOUCH IMPROVEMENTS
   ========================================= */
@media (max-width: 768px) {
    .dnd-pool, .dnd-target {
        min-height: 80px;
        padding: 12px;
    }

    .dnd-item {
        padding: 14px 18px;
        font-size: 0.88rem;
        touch-action: none;
        user-select: none;
        -webkit-user-select: none;
    }

    .dnd-item:active {
        transform: scale(1.05);
        box-shadow: 0 4px 20px rgba(99, 102, 241, 0.4);
        z-index: 10;
    }

    .jm-stages {
        grid-template-columns: 1fr 1fr !important;
        gap: 10px !important;
    }

    .jm-stage::after {
        display: none !important;
    }

    .jm-input {
        min-height: 48px;
        font-size: 0.85rem;
    }
}


/* =========================================
   LIGHT THEME OVERRIDES
   ========================================= */
body.light-theme .mobile-bottom-nav {
    background: rgba(255, 255, 255, 0.97);
    border-top-color: rgba(99, 102, 241, 0.1);
}

body.light-theme .mobile-bottom-nav-item {
    color: #94a3b8;
}

body.light-theme .mobile-bottom-nav-item.active {
    color: #6366f1;
}

body.light-theme .mobile-bottom-nav-item.active i {
    color: #6366f1;
}

body.light-theme .mobile-bottom-nav-item:active::after {
    background: rgba(99, 102, 241, 0.06);
}

body.light-theme .mobile-more-menu {
    background: rgba(255, 255, 255, 0.98);
    border-color: rgba(99, 102, 241, 0.12);
    box-shadow: 0 -12px 40px rgba(0, 0, 0, 0.1);
}

body.light-theme .mobile-more-menu-item {
    color: #64748b;
}

body.light-theme .mobile-more-menu-item:hover,
body.light-theme .mobile-more-menu-item:active {
    background: rgba(99, 102, 241, 0.06);
    color: #1e293b;
}

body.light-theme .focus-mode-btn {
    background: rgba(255, 255, 255, 0.9);
    border-color: rgba(99, 102, 241, 0.2);
    color: #6366f1;
}

body.light-theme .mobile-table-hint {
    color: rgba(0, 0, 0, 0.3);
}

body.light-theme .swipe-hint {
    background: rgba(255, 255, 255, 0.95);
    border-color: rgba(99, 102, 241, 0.12);
    color: #64748b;
}


/* =========================================
   PRINT: HIDE ALL MOBILE UI
   ========================================= */
@media print {
    .mobile-bottom-nav,
    .focus-mode-btn,
    .focus-mode-banner,
    .swipe-nav-indicator,
    .swipe-progress,
    .swipe-hint,
    .mobile-table-hint {
        display: none !important;
    }
}


/* =========================================
   REDUCED MOTION
   ========================================= */
@media (prefers-reduced-motion: reduce) {
    .mobile-bottom-nav,
    .mobile-bottom-nav-item i,
    .mobile-more-menu,
    .focus-mode-btn,
    .swipe-nav-indicator,
    .swipe-hint {
        transition-duration: 0.01ms !important;
    }

    @keyframes mobileTableSwipe {
        0%, 100% { transform: translateX(0); }
    }
}
