/**
 * REUSABLE MOBILE COMPONENTS
 *
 * This file contains mobile-specific UI patterns that can be reused across
 * different mobile interfaces: bottom sheets, toolbars, full-screen containers, etc.
 *
 * Use these classes to build consistent mobile UX throughout the application.
 */

/* ========================================
   MOBILE NAV HEIGHT VARIABLES
   Use these for consistent spacing calculations
   ======================================== */

:root {
    --mobile-nav-height: 60px;
    --mobile-toolbar-height: 68px;
}

/* ========================================
   MOBILE TOP HEADER (Sticky)
   ======================================== */

.mobile-top-header {
    position: sticky;
    top: 0;
    left: 0;
    right: 0;
    background: var(--surface);
    backdrop-filter: blur(10px);
    -webkit-backdrop-filter: blur(10px);
    border-bottom: 1px solid var(--border);
    padding: 8px 0;
    z-index: 1000;
    box-shadow: 0 1px 8px rgba(0, 0, 0, 0.08);
}

.mobile-top-header-container {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0 16px;
}

.mobile-header-logo {
    font-size: 1.25rem;
    font-weight: bold;
    color: var(--text);
    text-decoration: none;
    display: flex;
    align-items: center;
    gap: 4px;
}

.mobile-header-logo:hover {
    color: var(--text);
    opacity: 0.8;
}

.mobile-header-actions {
    display: flex;
    align-items: center;
    gap: 8px;
}

/* ========================================
   MODAL CENTERING (Mobile)
   ======================================== */

/* Ensure Bootstrap modals are properly centered on mobile */
.modal-dialog {
    display: flex;
    align-items: center;
    min-height: calc(100% - 1rem);
}

@media (min-width: 576px) {
    .modal-dialog {
        min-height: calc(100% - 3.5rem);
    }
}

/* ========================================
   SEGMENTED CONTROLS (iOS/Android style)
   ======================================== */

.mobile-segmented-control {
    background: var(--surface-secondary);
    padding: 4px;
    border-radius: 10px;
}

.mobile-segmented-control .btn {
    border-radius: 8px;
    font-weight: 500;
    border: none !important;
    background: transparent !important;
    color: var(--text-secondary) !important;
    transition: all 0.2s ease;
}

.mobile-segmented-control .btn:hover {
    background: transparent !important;
    color: var(--text) !important;
}

.mobile-segmented-control .btn.active {
    background-color: var(--primary) !important;
    color: var(--primary-dark) !important;
    box-shadow: 0 2px 4px var(--text-10);
}

/* Content panel switching for segmented controls */
.content-panel {
    display: none;
}

.content-panel.active {
    display: block;
}

/* Empty state icon (large faded icons for empty states) */
.empty-state-icon {
    font-size: 4rem;
    opacity: 0.3;
}

/* ========================================
   FULL-SCREEN MOBILE CONTAINERS
   ======================================== */

.mobile-fullscreen-container {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    display: flex;
    flex-direction: column;
    background: var(--bg-color);
    overflow: hidden;
    z-index: 1000;
}

/* ========================================
   STICKY TOP BARS
   ======================================== */

.mobile-sticky-top-bar {
    position: sticky;
    top: 0;
    left: 0;
    right: 0;
    background: var(--surface);
    border-bottom: 1px solid var(--border);
    box-shadow: 0 2px 8px var(--text-5);
    z-index: 100;
    padding: 12px 16px;
}

/* Global mobile header (not page builder) - fixed position */
.mobile-global-header {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    background: var(--surface);
    backdrop-filter: blur(10px);
    -webkit-backdrop-filter: blur(10px);
    box-shadow: 0 2px 8px var(--text-5);
    z-index: 1020;
    padding: 12px 16px;
    padding-top: calc(12px + env(safe-area-inset-top, 0px));
    border-bottom: 1px solid var(--border);
}

/* When tabs are present, remove bottom padding but keep the border */
.mobile-global-header.has-tabs {
    padding-bottom: 0;
}

/* Add top padding to body when mobile header is present (below lg breakpoint) */
@media (max-width: 991.98px) {
    body {
        padding-top: calc(68px + env(safe-area-inset-top, 0px)); /* Height of mobile header + safe area */
    }

    /* When tabs are present, add extra padding for tab height */
    body.has-mobile-tabs {
        padding-top: calc(120px + env(safe-area-inset-top, 0px)); /* Header + tabs height + safe area */
    }
}

/* ========================================
   CONTEXTUAL TABS (iOS style)
   ======================================== */

.mobile-contextual-tabs {
    background: var(--surface);
    position: relative;
}

/* Fade gradient on right edge to indicate more tabs */
.mobile-contextual-tabs::after {
    content: '';
    position: absolute;
    top: 0;
    right: 0;
    bottom: 0;
    width: 40px;
    background: linear-gradient(to right, transparent, var(--surface));
    pointer-events: none;
    z-index: 1;
}

.mobile-contextual-tabs-scroll {
    display: flex;
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
    scrollbar-width: none;
    gap: 0;
}

.mobile-contextual-tabs-scroll::-webkit-scrollbar {
    display: none;
}

.mobile-contextual-tab {
    flex-shrink: 0;
    padding: 12px 20px;
    color: var(--text-secondary);
    text-decoration: none;
    font-size: 15px;
    font-weight: 500;
    border-bottom: 3px solid transparent;
    transition: all 0.2s ease;
    white-space: nowrap;
}

.mobile-contextual-tab:hover {
    color: var(--text);
    text-decoration: none;
}

.mobile-contextual-tab.active {
    color: var(--primary);
    border-bottom-color: var(--primary);
}

.mobile-top-bar-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    min-height: 44px; /* iOS minimum tap target */
}

.mobile-top-bar-header .logo-image {
    height: 54px;
    display: block;
    margin: 0;
    min-height: 44px; /* iOS minimum tap target */
}

.mobile-top-bar-back {
    display: flex;
    align-items: center;
    color: var(--primary);
    text-decoration: none;
    font-size: 16px;
    padding: 8px 12px;
    margin-left: -12px;
}

.mobile-top-bar-back:hover {
    color: var(--primary-hover);
}

.mobile-top-bar-title {
    font-size: 16px;
    font-weight: 600;
    color: var(--text);
}

.mobile-top-bar-action {
    padding: 8px 12px;
    margin-right: -12px;
    color: var(--text);
    background: none;
    border: none;
    font-size: 20px;
    cursor: pointer;
}

/* ========================================
   HORIZONTAL SCROLLING STRIPS
   ======================================== */

.mobile-horizontal-scroll {
    display: flex;
    gap: 8px;
    overflow-x: auto;
    overflow-y: hidden;
    padding: 12px 16px;
    -webkit-overflow-scrolling: touch;
    scrollbar-width: none; /* Firefox */
}

.mobile-horizontal-scroll::-webkit-scrollbar {
    display: none; /* Chrome, Safari, Edge */
}

.mobile-scroll-item {
    flex-shrink: 0;
    scroll-snap-align: center;
}

/* ========================================
   FIXED BOTTOM TOOLBARS
   ======================================== */

.mobile-toolbar {
    position: fixed;
    bottom: 0;
    left: 0;
    right: 0;
    display: flex;
    align-items: center;
    justify-content: space-around;
    background: var(--surface);
    backdrop-filter: blur(10px);
    -webkit-backdrop-filter: blur(10px);
    border-top: 1px solid var(--border);
    padding: 8px 0 env(safe-area-inset-bottom); /* iOS safe area */
    z-index: 200;
    box-shadow: 0 -1px 8px rgba(0, 0, 0, 0.08);
}

.mobile-toolbar-item {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 4px;
    flex: 1;
    min-height: 60px;
    color: var(--text-muted);
    text-decoration: none;
    background: none;
    border: none;
    cursor: pointer;
    transition: all 0.2s ease;
    padding: 8px;
}

.mobile-toolbar-item:hover,
.mobile-toolbar-item:active {
    color: var(--text);
    background: var(--hover-bg);
}

.mobile-toolbar-item:disabled,
.mobile-toolbar-item.disabled {
    opacity: 0.4;
    cursor: not-allowed;
    pointer-events: none;
}

.mobile-toolbar-item:disabled:hover,
.mobile-toolbar-item.disabled:hover {
    color: var(--text-muted);
    background: none;
}

.mobile-toolbar-item.active {
    color: var(--accent-color);
}

.mobile-toolbar-item.primary {
    color: var(--accent-color);
}

.mobile-toolbar-item.primary:hover {
    color: var(--accent-color);
    filter: brightness(1.2);
}

/* CTA highlight - guide user to next incomplete step */
.mobile-toolbar-item.cta-highlight {
    color: var(--primary);
    position: relative;
}

.mobile-toolbar-item.cta-highlight .mobile-toolbar-icon {
    animation: pulse-cta 2s ease-in-out infinite;
}

.mobile-toolbar-item.cta-highlight:hover {
    color: var(--primary-hover);
}

/* Pulsing animation to draw attention */
@keyframes pulse-cta {
    0%, 100% {
        transform: scale(1);
        opacity: 1;
    }
    50% {
        transform: scale(1.1);
        opacity: 0.8;
    }
}

.mobile-toolbar-icon {
    font-size: 24px;
    line-height: 1;
}

.mobile-toolbar-label {
    font-size: 11px;
    font-weight: 500;
    text-transform: uppercase;
    letter-spacing: 0.5px;
}

/* ========================================
   BOTTOM SHEETS
   ======================================== */

.mobile-bottom-sheet {
    position: fixed;
    left: 0;
    right: 0;
    bottom: 0;
    background: var(--surface);
    border-top-left-radius: 20px;
    border-top-right-radius: 20px;
    box-shadow: 0 -4px 32px var(--text-10);
    transform: translateY(100%);
    transition: transform 0.3s cubic-bezier(0.4, 0, 0.2, 1);
    z-index: 1040;
    max-height: 80vh;
    display: flex;
    flex-direction: column;
}

.mobile-bottom-sheet.open {
    transform: translateY(0);
}

.mobile-bottom-sheet.small {
    max-height: 40vh;
}

.mobile-bottom-sheet.medium {
    max-height: 60vh;
}

.mobile-bottom-sheet.large {
    max-height: 80vh;
}

.mobile-bottom-sheet.xlarge {
    max-height: 90vh;
}

.mobile-sheet-handle {
    width: 40px;
    height: 5px;
    background: var(--border);
    border-radius: 3px;
    margin: 12px auto;
    flex-shrink: 0;
}

.mobile-sheet-header {
    padding: 0 20px 16px;
    border-bottom: 1px solid var(--border);
    flex-shrink: 0;
}

.mobile-sheet-title {
    font-size: 20px;
    font-weight: 600;
    color: var(--text);
    margin: 0;
}

.mobile-sheet-body {
    padding: 20px;
    overflow-y: auto;
    flex: 1;
}

.mobile-sheet-footer {
    padding: 16px 20px calc(16px + env(safe-area-inset-bottom));
    border-top: 1px solid var(--border);
    flex-shrink: 0;
}

/* ========================================
   BACKDROP OVERLAY
   ======================================== */

.mobile-backdrop {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(0, 0, 0, 0.5);
    opacity: 0;
    visibility: hidden;
    transition: opacity 0.3s ease, visibility 0.3s ease;
    z-index: var(--modal-backdrop-z-index);
}

.mobile-backdrop.show {
    opacity: 1;
    visibility: visible;
}

/* ========================================
   TOUCH-FRIENDLY BUTTONS
   ======================================== */

/* Mobile button modifier - adds touch-friendly specs to any Bootstrap button */
.mobile-btn {
    min-height: 44px !important; /* iOS minimum tap target */
    padding: 12px 20px !important;
    font-size: 16px !important;
    font-weight: 600 !important;
    border-radius: 12px !important; /* More rounded for mobile friendly feel */
}

.mobile-btn-block {
    width: 100%;
}

/* ========================================
   LOADING STATES
   ======================================== */

.mobile-spinner-overlay {
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(0, 0, 0, 0.5);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 50;
}

.mobile-spinner {
    width: 48px;
    height: 48px;
    border: 4px solid rgba(255, 255, 255, 0.3);
    border-top-color: white;
    border-radius: 50%;
    animation: mobile-spin 0.8s linear infinite;
}

@keyframes mobile-spin {
    to {
        transform: rotate(360deg);
    }
}

/* ========================================
   FORM ELEMENTS
   ======================================== */

.mobile-input {
    width: 100%;
    min-height: 44px;
    padding: 12px 16px;
    font-size: 16px; /* Prevents zoom on iOS */
    border: 1px solid var(--border);
    border-radius: 8px;
    background: var(--surface);
    color: var(--text);
}

.mobile-input:focus {
    outline: none;
    border-color: var(--primary);
    box-shadow: 0 0 0 3px var(--primary-10);
}

.mobile-textarea {
    min-height: 120px;
    resize: vertical;
    font-family: inherit;
}

/* ========================================
   UTILITY CLASSES
   ======================================== */

.mobile-divider {
    height: 1px;
    background: var(--border-color);
    margin: 16px 0;
}

.mobile-spacer-sm {
    height: 8px;
}

.mobile-spacer-md {
    height: 16px;
}

.mobile-spacer-lg {
    height: 24px;
}

/* ========================================
   RESPONSIVE HELPERS
   ======================================== */

/* Only show on mobile (< 768px) */
.mobile-only {
    display: block;
}

@media (min-width: 768px) {
    .mobile-only {
        display: none !important;
    }
}

/* Hide on mobile (< 768px) */
.mobile-hide {
    display: none;
}

@media (min-width: 768px) {
    .mobile-hide {
        display: block;
    }
}

/* ========================================
   SAFE AREA UTILITIES
   For iOS home indicator / notch handling
   ======================================== */

/* Universal safe area bottom padding - use on any fixed/sticky bottom element */
.safe-area-bottom {
    padding-bottom: env(safe-area-inset-bottom, 0px) !important;
}

/* For elements that need base padding + safe area */
.safe-area-bottom-sm {
    padding-bottom: calc(8px + env(safe-area-inset-bottom, 0px)) !important;
}

.safe-area-bottom-md {
    padding-bottom: calc(16px + env(safe-area-inset-bottom, 0px)) !important;
}

.safe-area-bottom-lg {
    padding-bottom: calc(24px + env(safe-area-inset-bottom, 0px)) !important;
}

/* ========================================
   MOBILE TOAST NOTIFICATIONS
   Override desktop toast position for mobile
   Use body class instead of media query for force_mobile compatibility
   ======================================== */

body.page-builder-mobile .toast-notification {
    /* Override desktop bottom-right position */
    bottom: auto;
    right: auto;
    top: 80px;
    left: 50%;
    transform: translateX(-50%) translateY(-100px);
    max-width: 90%;
    text-align: center;
    transition: transform 0.3s ease, opacity 0.3s ease;
}

body.page-builder-mobile .toast-notification.show {
    opacity: 1;
    transform: translateX(-50%) translateY(0);
}

/* ========================================
   WIZARD MOBILE LAYOUT
   ======================================== */

/* Wizard mobile content spacing - accounts for fixed top bar and bottom toolbar */
@media (max-width: 991.98px) {
    /* Override sticky positioning to fixed for wizard top bar */
    .wizard-mobile-layout .mobile-sticky-top-bar {
        position: fixed;
        top: 0;
        left: 0;
        right: 0;
        z-index: 1020; /* Above content, same as global mobile header */
    }

    /* Apply padding for mobile wizard nav (only on base_wizard.html pages) */
    .wizard-mobile-layout .wizard-content {
        /* No top padding needed - mobile top bar is in mobile_header block above content */
        padding-bottom: calc(var(--mobile-toolbar-height, 68px) + 12px); /* Space for mobile bottom toolbar */
    }

    /* Reduce excessive spacing in wizard containers on mobile */
    .wizard-layout .wizard-content .container {
        padding-left: 12px;
        padding-right: 12px;
    }

    /* Reduce large top margins on mobile */
    .wizard-layout .wizard-content .mt-5 {
        margin-top: 1rem !important;
    }

    .wizard-layout .wizard-content .mb-5,
    .wizard-layout .wizard-content .mb-md-5 {
        margin-bottom: 1.5rem !important;
    }

    /* Wizard mobile navigation toolbar - 2 buttons (Back and Next) */
    .wizard-mobile-nav.mobile-toolbar {
        justify-content: space-between;
        padding-left: 12px;
        padding-right: 12px;
    }

    .wizard-mobile-nav .mobile-toolbar-item {
        flex: 0 1 auto;
        min-width: 100px;
        max-width: 140px;
    }
}
