/**
 * RoadScript Mobile Styles
 * Mobile-first responsive design with touch-optimized UI
 */

/* ========== CSS VARIABLES FOR MOBILE ========== */
:root {
    /* Safe area insets for notched devices */
    --sat: env(safe-area-inset-top, 0px);
    --sar: env(safe-area-inset-right, 0px);
    --sab: env(safe-area-inset-bottom, 0px);
    --sal: env(safe-area-inset-left, 0px);

    /* Mobile touch target sizes */
    --touch-target-min: 44px;
    --touch-target-comfortable: 48px;
    --touch-spacing-min: 8px;

    /* Mobile z-index layers */
    --z-mobile-drawer: 1000;
    --z-mobile-fab: 1001;
    --z-mobile-modal: 1002;
    --z-mobile-overlay: 999;

    /* Mobile animation durations */
    --mobile-anim-fast: 150ms;
    --mobile-anim-normal: 250ms;
    --mobile-anim-slow: 350ms;
}

/* ========== RESPONSIVE VISIBILITY UTILITIES ========== */
.mobile-only {
    display: none;
}

.tablet-only {
    display: none;
}

.desktop-only {
    display: block;
}

/* Mobile (0-767px) */
@media (max-width: 767px) {
    .mobile-only {
        display: block;
    }

    .tablet-only {
        display: none;
    }

    .desktop-only {
        display: none !important;
    }

    .mobile-hide {
        display: none !important;
    }
}

/* Tablet (768-1023px) */
@media (min-width: 768px) and (max-width: 1023px) {
    .mobile-only {
        display: none !important;
    }

    .tablet-only {
        display: block;
    }

    .desktop-only {
        display: none !important;
    }

    .tablet-hide {
        display: none !important;
    }
}

/* Desktop (1024px+) */
@media (min-width: 1024px) {
    .mobile-only {
        display: none !important;
    }

    .tablet-only {
        display: none !important;
    }

    .desktop-hide {
        display: none !important;
    }
}

/* ========== MOBILE LAYOUT (0-767px) ========== */
@media (max-width: 767px) {
    /* Safe area padding for notched devices */
    body {
        padding-top: var(--sat);
        padding-right: var(--sar);
        padding-bottom: var(--sab);
        padding-left: var(--sal);
    }

    /* Prevent iOS bounce scroll */
    html, body {
        overscroll-behavior: none;
        -webkit-overflow-scrolling: touch;
    }

    /* Main container - full screen mobile */
    .container-fluid {
        flex-direction: column;
        height: 100vh;
        height: 100dvh; /* Dynamic viewport height for mobile browsers */
    }

    /* Roadmap container - remove min-width constraint on mobile */
    .roadmap-container {
        min-width: 100% !important;
        max-width: 100vw !important;
        padding: 12px !important;
        aspect-ratio: auto !important; /* Remove 16:9 constraint */
        overflow-x: auto !important;
        overflow-y: visible !important;
        -webkit-overflow-scrolling: touch;
    }

    /* Roadmap wrapper - full width mobile */
    .roadmap {
        width: 100% !important;
        min-width: 100% !important;
    }

    /* Preview pane - full screen on mobile */
    .preview-pane {
        flex: 1;
        width: 100% !important;
        padding: 8px !important;
        overflow: auto;
        -webkit-overflow-scrolling: touch;
    }

    /* Title container - minimal padding on mobile */
    .roadmap-title-container {
        padding: 8px 12px !important;
    }

    /* Hide footer button labels on mobile to prevent overflow */
    .footer-button-label {
        display: none !important;
    }

    .footer-button {
        padding: 6px 8px !important;
    }

    /* Title - smaller on mobile */
    .roadmap h1 {
        font-size: 24px !important;
        line-height: 1.2 !important;
        letter-spacing: -0.3px !important;
    }

    /* Subtitle - smaller on mobile */
    .roadmap-title-container p {
        font-size: 13px !important;
        line-height: 1.4 !important;
    }

    /* Column labels - smaller on mobile */
    .roadmap > div > div:last-child > div:first-child > div span:first-child {
        font-size: 14px !important;
        line-height: 1.3 !important;
    }

    /* Column subs - smaller on mobile */
    .roadmap > div > div:last-child > div:first-child > div span:last-child {
        font-size: 10px !important;
        line-height: 1.3 !important;
    }

    /* Lane titles - smaller on mobile */
    .roadmap > div > div:first-child span {
        font-size: 12px !important;
        line-height: 1.2 !important;
    }

    /* Item titles - smaller on mobile */
    .roadmap h4 {
        font-size: 16px !important;
        margin-bottom: 6px !important;
        line-height: 1.3 !important;
    }

    /* Item detail text - smaller on mobile */
    .roadmap ul li > div {
        font-size: 14px !important;
        line-height: 1.4 !important;
        padding-left: 12px !important;
    }

    /* Sub-bullets - smaller on mobile */
    .roadmap ul li ul li {
        font-size: 12px !important;
        line-height: 1.4 !important;
        padding-left: 16px !important;
    }

    /* Milestone labels - smaller on mobile */
    .roadmap > div > div:last-child > div:nth-child(2) span {
        font-size: 11px !important;
        line-height: 1.2 !important;
        padding: 2px 6px !important;
    }

    /* Lane label area - narrower on mobile */
    .roadmap > div > div:first-child {
        width: 80px !important;
        padding-right: 8px !important;
        padding-top: 36px !important;
    }

    /* Column header height - smaller on mobile */
    .roadmap > div > div:last-child > div:first-child {
        height: 36px !important;
    }

    /* Milestone row height - smaller on mobile */
    .roadmap > div > div:last-child > div:nth-child(2) {
        height: 30px !important;
    }

    /* Item card padding - tighter on mobile */
    .roadmap > div > div:last-child > div:last-child > div > div {
        padding: 8px 12px !important;
    }

    /* Touch-friendly tap targets */
    .clickable-element {
        min-height: var(--touch-target-min);
        min-width: var(--touch-target-min);
        padding: 8px;
        cursor: pointer;
        -webkit-tap-highlight-color: rgba(0, 0, 0, 0.1);
    }

    /* Quick action buttons - touch-friendly */
    .quick-action-icon {
        width: var(--touch-target-comfortable) !important;
        height: var(--touch-target-comfortable) !important;
    }

    /* Button labels - slightly larger on mobile for readability */
    .button-label {
        font-size: 10px !important;
    }
}

/* ========== MOBILE FAB (Floating Action Button) ========== */
.mobile-fab {
    position: fixed;
    bottom: calc(20px + var(--sab));
    right: calc(20px + var(--sar));
    z-index: var(--z-mobile-fab);
    display: flex;
    flex-direction: column-reverse;
    align-items: flex-end;
    gap: 12px;
}

.mobile-fab-main {
    width: 56px;
    height: 56px;
    border-radius: 50%;
    background: #667eea;
    color: white;
    border: none;
    box-shadow: 0 4px 12px rgba(102, 126, 234, 0.4),
                0 2px 8px rgba(0, 0, 0, 0.2);
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    transition: all var(--mobile-anim-fast) ease;
    -webkit-tap-highlight-color: transparent;
}

.mobile-fab-main:active {
    transform: scale(0.95);
    box-shadow: 0 2px 8px rgba(102, 126, 234, 0.3);
}

.mobile-fab-menu {
    display: flex;
    flex-direction: column-reverse;
    gap: 12px;
    opacity: 0;
    transform: translateY(10px);
    pointer-events: none;
    transition: all var(--mobile-anim-normal) ease;
}

.mobile-fab.expanded .mobile-fab-menu {
    opacity: 1;
    transform: translateY(0);
    pointer-events: all;
}

.mobile-fab-action {
    width: 48px;
    height: 48px;
    border-radius: 50%;
    background: #4a5568;
    color: white;
    border: none;
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.2);
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    transition: all var(--mobile-anim-fast) ease;
    -webkit-tap-highlight-color: transparent;
}

.mobile-fab-action:active {
    transform: scale(0.95);
}

/* ========== MOBILE DRAWERS ========== */

/* Bottom Drawer */
.mobile-bottom-drawer {
    position: fixed;
    bottom: 0;
    left: 0;
    right: 0;
    background: #1e1e2f;
    border-top-left-radius: 16px;
    border-top-right-radius: 16px;
    box-shadow: 0 -4px 24px rgba(0, 0, 0, 0.4);
    z-index: var(--z-mobile-drawer);
    transform: translateY(100%);
    transition: transform var(--mobile-anim-normal) ease;
    max-height: 90vh;
    display: flex;
    flex-direction: column;
    padding-bottom: var(--sab);
}

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

.mobile-drawer-handle {
    width: 40px;
    height: 4px;
    background: #4a5568;
    border-radius: 2px;
    margin: 12px auto 8px;
    cursor: grab;
    -webkit-tap-highlight-color: transparent;
}

.mobile-drawer-handle:active {
    cursor: grabbing;
}

.mobile-drawer-header {
    padding: 12px 20px;
    border-bottom: 1px solid #3a3a4e;
    display: flex;
    align-items: center;
    justify-content: space-between;
}

.mobile-drawer-title {
    font-size: 16px;
    font-weight: 600;
    color: #e0e7ff;
}

.mobile-drawer-close {
    width: 32px;
    height: 32px;
    border: none;
    background: transparent;
    color: #9ca3af;
    font-size: 24px;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: 4px;
    -webkit-tap-highlight-color: transparent;
}

.mobile-drawer-close:active {
    background: rgba(255, 255, 255, 0.1);
}

.mobile-drawer-content {
    flex: 1;
    overflow-y: auto;
    padding: 16px 20px;
    -webkit-overflow-scrolling: touch;
}

/* Side Drawer */
.mobile-side-drawer {
    position: fixed;
    top: 0;
    left: 0;
    bottom: 0;
    width: 85%;
    max-width: 320px;
    background: #1e1e2f;
    box-shadow: 4px 0 24px rgba(0, 0, 0, 0.4);
    z-index: var(--z-mobile-drawer);
    transform: translateX(-100%);
    transition: transform var(--mobile-anim-normal) ease;
    display: flex;
    flex-direction: column;
    padding-top: var(--sat);
    padding-bottom: var(--sab);
    padding-left: var(--sal);
}

.mobile-side-drawer.open {
    transform: translateX(0);
}

/* Drawer backdrop */
.mobile-drawer-backdrop {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(0, 0, 0, 0.5);
    z-index: calc(var(--z-mobile-drawer) - 1);
    opacity: 0;
    pointer-events: none;
    transition: opacity var(--mobile-anim-normal) ease;
}

.mobile-drawer-backdrop.visible {
    opacity: 1;
    pointer-events: all;
}

/* ========== MOBILE NAVIGATION ========== */

/* Column Navigator */
.mobile-column-navigator {
    position: fixed;
    bottom: calc(90px + var(--sab));
    left: 0;
    right: 0;
    height: 60px;
    background: rgba(30, 30, 47, 0.95);
    backdrop-filter: blur(10px);
    border-top: 1px solid #3a3a4e;
    z-index: calc(var(--z-mobile-drawer) - 1);
    display: flex;
    align-items: center;
    padding: 0 12px;
    gap: 8px;
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
    transform: translateY(100%);
    transition: transform var(--mobile-anim-normal) ease;
}

.mobile-column-navigator.visible {
    transform: translateY(0);
}

.mobile-column-item {
    flex-shrink: 0;
    min-width: 60px;
    height: 44px;
    border-radius: 8px;
    background: #2a2a3e;
    border: 2px solid transparent;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 12px;
    color: #9ca3af;
    cursor: pointer;
    transition: all var(--mobile-anim-fast) ease;
    -webkit-tap-highlight-color: transparent;
}

.mobile-column-item.active {
    background: #667eea;
    border-color: #667eea;
    color: white;
}

.mobile-column-item:active {
    transform: scale(0.95);
}

/* Lane Navigator */
.mobile-lane-navigator {
    position: fixed;
    top: calc(50% - 150px);
    right: calc(8px + var(--sar));
    display: flex;
    flex-direction: column;
    gap: 8px;
    z-index: calc(var(--z-mobile-drawer) - 1);
}

.mobile-lane-item {
    width: 44px;
    height: 44px;
    border-radius: 8px;
    background: rgba(30, 30, 47, 0.9);
    backdrop-filter: blur(10px);
    border: 2px solid transparent;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 11px;
    color: #9ca3af;
    cursor: pointer;
    transition: all var(--mobile-anim-fast) ease;
    -webkit-tap-highlight-color: transparent;
}

.mobile-lane-item.active {
    background: #667eea;
    border-color: #667eea;
    color: white;
}

.mobile-lane-item:active {
    transform: scale(0.95);
}

/* ========== MOBILE MODALS ========== */
.mobile-modal {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    z-index: var(--z-mobile-modal);
    display: flex;
    flex-direction: column;
    background: #1e1e2f;
    transform: translateY(100%);
    transition: transform var(--mobile-anim-normal) ease;
    padding-top: var(--sat);
    padding-bottom: var(--sab);
}

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

.mobile-modal-header {
    padding: 16px 20px;
    border-bottom: 1px solid #3a3a4e;
    display: flex;
    align-items: center;
    justify-content: space-between;
}

.mobile-modal-body {
    flex: 1;
    overflow-y: auto;
    padding: 20px;
    -webkit-overflow-scrolling: touch;
}

/* ========== MOBILE CONTEXT MENU ========== */
.mobile-context-menu {
    position: fixed;
    background: #2a2a3e;
    border-radius: 12px;
    box-shadow: 0 8px 24px rgba(0, 0, 0, 0.4);
    z-index: var(--z-mobile-modal);
    min-width: 180px;
    opacity: 0;
    transform: scale(0.9);
    pointer-events: none;
    transition: all var(--mobile-anim-fast) ease;
}

.mobile-context-menu.visible {
    opacity: 1;
    transform: scale(1);
    pointer-events: all;
}

.mobile-context-menu-item {
    padding: 14px 16px;
    color: #e0e7ff;
    font-size: 15px;
    cursor: pointer;
    display: flex;
    align-items: center;
    gap: 12px;
    border-bottom: 1px solid #3a3a4e;
    -webkit-tap-highlight-color: transparent;
}

.mobile-context-menu-item:last-child {
    border-bottom: none;
}

.mobile-context-menu-item:active {
    background: rgba(255, 255, 255, 0.1);
}

.mobile-context-menu-item.danger {
    color: #ef4444;
}

/* ========== TOUCH FEEDBACK ========== */
.touch-ripple {
    position: relative;
    overflow: hidden;
}

.touch-ripple::after {
    content: '';
    position: absolute;
    top: 50%;
    left: 50%;
    width: 0;
    height: 0;
    border-radius: 50%;
    background: rgba(255, 255, 255, 0.3);
    transform: translate(-50%, -50%);
    opacity: 0;
}

.touch-ripple:active::after {
    width: 200px;
    height: 200px;
    opacity: 1;
    transition: width var(--mobile-anim-fast) ease,
                height var(--mobile-anim-fast) ease,
                opacity var(--mobile-anim-normal) ease;
}

/* ========== MOBILE SCROLLBAR ========== */
@media (max-width: 767px) {
    /* Hide scrollbars on mobile but keep functionality */
    ::-webkit-scrollbar {
        width: 2px;
        height: 2px;
    }

    ::-webkit-scrollbar-track {
        background: transparent;
    }

    ::-webkit-scrollbar-thumb {
        background: rgba(102, 126, 234, 0.3);
        border-radius: 1px;
    }
}

/* ========== MOBILE LANDSCAPE ORIENTATION ========== */
@media (max-width: 767px) and (orientation: landscape) {
    .roadmap h1 {
        font-size: 20px !important;
    }

    .mobile-fab {
        bottom: calc(12px + var(--sab));
        right: calc(12px + var(--sar));
    }

    .mobile-fab-main {
        width: 48px;
        height: 48px;
    }

    .mobile-column-navigator {
        height: 50px;
    }
}

/* ========== PREVENT TEXT SELECTION ON MOBILE ========== */
@media (max-width: 767px) {
    .roadmap * {
        -webkit-user-select: none;
        user-select: none;
    }

    /* Allow selection in editable areas */
    input, textarea, [contenteditable] {
        -webkit-user-select: text;
        user-select: text;
    }
}
