/* Mobile-first responsive CSS for FrameShare */

/* =================================================================
   Breakpoint System
   Mobile: ≤767px | Tablet: 768-1023px | Desktop: ≥1024px
   ================================================================= */

/* Base mobile styles (default) */
:root {
    --mobile-header-height: 56px;
    --mobile-nav-height: 60px;
    --mobile-safe-area-bottom: env(safe-area-inset-bottom, 0);
    --mobile-safe-area-top: env(safe-area-inset-top, 0);
}

/* =================================================================
   Layout Adjustments
   ================================================================= */

/* Hide desktop navigation on mobile and tablets */
@media (max-width: 1023px) {
    /* Hide desktop header navigation tabs */
    header nav > div.flex.space-x-8 {
        display: none !important;
    }
    
    /* Alternative selector for navigation links */
    header .py-4.px-1.border-b-2 {
        display: none !important;
    }
    
    /* Hide desktop navigation links */
    header nav a[href*="/dashboard/"],
    header nav a[href*="/cases/"],
    header nav a[href*="/sessions/"],
    header nav a[href*="/instant/"],
    header nav a[href*="/clients/"] {
        display: none !important;
    }
    
    /* Simplify header */
    header {
        height: var(--mobile-header-height);
        padding: 0 1rem;
    }
    
    header nav {
        padding: 0;
    }
    
    header .py-3 {
        padding: 0.75rem 0;
    }
    
    /* Adjust main content for mobile navigation */
    body > .min-h-full {
        padding-bottom: calc(var(--mobile-nav-height) + var(--mobile-safe-area-bottom));
    }
}

/* Ensure body padding on all mobile/tablet devices */
@media (max-width: 1023px) {
    body {
        padding-bottom: 60px !important;
        padding-bottom: calc(60px + env(safe-area-inset-bottom, 0)) !important;
    }
    
    /* Ensure content doesn't go under navbar */
    .min-h-screen,
    .min-h-full {
        min-height: calc(100vh - 60px) !important;
        min-height: calc(100vh - 60px - env(safe-area-inset-bottom, 0)) !important;
    }
}

/* =================================================================
   Mobile Navigation (Bottom Tab Bar)
   ================================================================= */

/* Hide mobile nav on desktop by default */
.mobile-nav {
    display: none !important;
}

/* Show mobile nav on mobile devices (including landscape) */
@media (max-width: 1023px) {
    /* Mobile bottom navigation */
    .mobile-nav {
        position: fixed !important;
        bottom: 0 !important;
        left: 0 !important;
        right: 0 !important;
        width: 100% !important;
        height: 60px !important;
        background: white !important;
        border-top: 1px solid #e5e7eb !important;
        z-index: 999 !important;
        padding: 0 !important;
        padding-bottom: env(safe-area-inset-bottom, 0) !important;
        display: flex !important;
        justify-content: space-evenly !important;
        align-items: center !important;
        box-shadow: 0 -2px 4px rgba(0, 0, 0, 0.1) !important;
    }
    
    /* Force display on mobile */
    nav.mobile-nav {
        display: flex !important;
        visibility: visible !important;
        opacity: 1 !important;
    }
    
    /* Mobile nav items */
    .mobile-nav-item {
        flex: 1;
        display: flex;
        flex-direction: column;
        align-items: center;
        justify-content: center;
        height: 60px;
        color: #6b7280;
        text-decoration: none;
        transition: color 0.2s;
        position: relative;
        padding: 8px;
    }
    
    .mobile-nav-item svg {
        width: 24px;
        height: 24px;
    }
    
    .mobile-nav-item.active {
        color: #3b82f6;
    }
    
    .mobile-nav-item.active::after {
        content: '';
        position: absolute;
        top: 0;
        left: 50%;
        transform: translateX(-50%);
        width: 32px;
        height: 3px;
        background-color: #3b82f6;
        border-radius: 0 0 2px 2px;
    }
}

/* Landscape-specific adjustments */
@media (max-width: 1023px) and (orientation: landscape) {
    /* Reduce navbar height in landscape */
    .mobile-nav {
        height: 50px !important;
    }
    
    /* Adjust body padding for landscape */
    body {
        padding-bottom: 50px !important;
    }
    
    /* Make header more compact in landscape */
    header {
        height: 48px !important;
    }
    
    /* Smaller nav items in landscape */
    .mobile-nav-item {
        padding: 4px 2px !important;
    }
    
    .mobile-nav-item svg {
        width: 22px !important;
        height: 22px !important;
    }
    
    .mobile-nav-item {
        flex: 1;
        display: flex;
        flex-direction: column;
        align-items: center;
        justify-content: center;
        height: 60px;
        color: #6b7280;
        text-decoration: none;
        font-size: 0.75rem;
        transition: color 0.2s;
        position: relative;
        padding: 8px 4px;
    }
    
    .mobile-nav-item.active {
        color: #2563eb;
    }
    
    .mobile-nav-item.active::after {
        content: '';
        position: absolute;
        top: 0;
        left: 50%;
        transform: translateX(-50%);
        width: 32px;
        height: 3px;
        background-color: #2563eb;
        border-radius: 0 0 2px 2px;
    }
    
    .mobile-nav-item svg {
        width: 24px !important;
        height: 24px !important;
        min-width: 24px !important;
        min-height: 24px !important;
        max-width: 24px !important;
        max-height: 24px !important;
        flex-shrink: 0;
    }
    
    /* Hide any span text that might still be showing */
    .mobile-nav-item span {
        display: none !important;
    }
    
    /* Ensure nav doesn't overflow */
    .mobile-nav * {
        box-sizing: border-box;
    }
}

/* =================================================================
   Dashboard Mobile Styles
   ================================================================= */

@media (max-width: 767px) {
    /* Fix calendar grid on mobile */
    .grid.grid-cols-3 {
        display: block !important;
    }
    
    /* Make calendar months stack vertically on mobile */
    .grid.grid-cols-3 > div {
        margin-bottom: 1rem;
    }
    
    /* Ensure calendar table displays properly */
    .grid.grid-cols-3 table {
        width: 100% !important;
        table-layout: fixed !important;
    }
    
    /* Calendar day cells */
    .grid.grid-cols-3 td {
        width: 14.28% !important; /* 1/7 for 7 days */
        padding: 2px !important;
    }
    /* Convert swimlanes to stacked cards */
    .dashboard-swimlanes {
        flex-direction: column !important;
        gap: 1rem;
        padding: 1rem;
    }
    
    .swimlane {
        width: 100% !important;
        margin: 0 !important;
    }
    
    /* Adjust case cards for mobile */
    .case-card {
        padding: 1rem;
        margin-bottom: 0.75rem;
    }
    
    /* Stack client info vertically */
    .case-card .flex.items-center {
        flex-direction: column;
        align-items: flex-start;
    }
    
    /* Adjust buttons in cards */
    .case-card .flex.space-x-2 {
        width: 100%;
        margin-top: 0.75rem;
    }
    
    .case-card .btn-primary,
    .case-card .btn-secondary {
        flex: 1;
        padding: 0.5rem;
        font-size: 0.875rem;
    }
}

/* =================================================================
   Cases List Swimlanes Mobile Styles
   ================================================================= */

@media (max-width: 767px) {
    /* Convert grid to single column on mobile */
    .grid.sm\:grid-cols-2.lg\:grid-cols-4 {
        display: block !important;
    }
    
    /* Make swimlanes full width and stack them */
    .swim-lane {
        min-height: auto !important;
        margin-bottom: 1rem;
    }
    
    /* Add collapsible behavior to swimlanes */
    .bg-blue-50,
    .bg-green-50,
    .bg-orange-50,
    .bg-gray-50 {
        margin-bottom: 1rem;
    }
    
    /* Disable drag and drop on mobile */
    .room-card {
        cursor: pointer !important;
    }
    
    /* Compact room cards on mobile */
    .room-card {
        padding: 0.75rem !important;
    }
    
    /* Hide drag hint on mobile */
    .text-xs.text-gray-400.mt-2 {
        display: none;
    }
    
    /* Make filter controls stack on mobile */
    .flex.gap-3 {
        flex-direction: column;
        gap: 0.75rem;
    }
    
    /* Full width search input */
    .relative.flex-1.max-w-xs {
        max-width: none !important;
    }
    
    /* Stack quick filter buttons */
    .flex.flex-wrap.gap-2 {
        overflow-x: auto;
        -webkit-overflow-scrolling: touch;
        white-space: nowrap;
        padding-bottom: 0.5rem;
    }
    
    /* Hide case stats widget on mobile or make it compact */
    .min-w-\\[280px\\] {
        min-width: auto !important;
        margin-top: 1rem;
    }
    
    /* Compact grid stats */
    .grid.grid-cols-2.gap-3 {
        gap: 0.5rem !important;
    }
    
    .grid.grid-cols-2.gap-3 > div {
        padding: 0.5rem !important;
    }
}

/* =================================================================
   Form Mobile Optimizations
   ================================================================= */

@media (max-width: 767px) {
    /* Full-width forms */
    form {
        padding: 1rem;
    }
    
    /* Larger touch targets for inputs */
    input[type="text"],
    input[type="email"],
    input[type="password"],
    input[type="tel"],
    input[type="number"],
    input[type="date"],
    input[type="time"],
    select,
    textarea {
        min-height: 44px;
        font-size: 16px; /* Prevents zoom on iOS */
        padding: 0.75rem;
    }
    
    /* Stack form groups */
    .form-group {
        margin-bottom: 1.25rem;
    }
    
    /* Full-width buttons */
    .form-actions {
        flex-direction: column;
        gap: 0.75rem;
    }
    
    .form-actions button,
    .form-actions a {
        width: 100%;
        justify-content: center;
    }
}

/* =================================================================
   Modal Adjustments
   ================================================================= */

@media (max-width: 767px) {
    /* Full-screen modals on mobile */
    .modal-content {
        width: 100%;
        height: 100%;
        max-width: none;
        max-height: none;
        margin: 0;
        border-radius: 0;
    }
    
    /* Adjust modal padding */
    .modal-body {
        padding: 1rem;
    }
    
    /* Fixed modal header */
    .modal-header {
        position: sticky;
        top: 0;
        background: white;
        z-index: 10;
        padding: 1rem;
        border-bottom: 1px solid #e5e7eb;
    }
}

/* =================================================================
   Table Responsiveness
   ================================================================= */

@media (max-width: 767px) {
    /* Convert tables to cards */
    table {
        display: block;
    }
    
    thead {
        display: none;
    }
    
    tbody {
        display: block;
    }
    
    tr {
        display: block;
        margin-bottom: 1rem;
        border: 1px solid #e5e7eb;
        border-radius: 0.5rem;
        padding: 1rem;
        background: white;
    }
    
    td {
        display: flex;
        justify-content: space-between;
        padding: 0.5rem 0;
        border: none;
    }
    
    td::before {
        content: attr(data-label);
        font-weight: 600;
        color: #6b7280;
    }
}

/* =================================================================
   Touch Gesture Support
   ================================================================= */

@media (max-width: 767px) {
    /* Smooth scrolling for touch */
    .scrollable {
        -webkit-overflow-scrolling: touch;
        overflow-scrolling: touch;
    }
    
    /* Disable hover effects on touch devices */
    @media (hover: none) {
        .btn-primary:hover,
        .btn-secondary:hover,
        .btn-danger:hover,
        .btn-outline:hover {
            background-color: inherit;
        }
    }
    
    /* Larger tap targets */
    a, button {
        min-height: 44px;
        min-width: 44px;
        display: inline-flex;
        align-items: center;
        justify-content: center;
    }
    
    /* Prevent text selection on interactive elements */
    button, a, .draggable {
        -webkit-user-select: none;
        -moz-user-select: none;
        -ms-user-select: none;
        user-select: none;
    }
    
    /* Add touch feedback */
    button:active,
    a:active,
    .touchable:active {
        opacity: 0.8;
        transform: scale(0.98);
    }
    
    /* Swipeable lists */
    .swipeable-list {
        overflow-x: auto;
        -webkit-overflow-scrolling: touch;
        scroll-snap-type: x mandatory;
    }
    
    .swipeable-item {
        scroll-snap-align: start;
    }
    
    /* Prevent accidental zooming */
    input[type="text"],
    input[type="email"],
    input[type="password"],
    input[type="tel"],
    input[type="number"],
    input[type="date"],
    input[type="time"],
    select,
    textarea {
        touch-action: manipulation;
    }
}

/* =================================================================
   Typography Adjustments
   ================================================================= */

@media (max-width: 767px) {
    /* Responsive font sizes */
    h1 {
        font-size: 1.75rem;
    }
    
    h2 {
        font-size: 1.5rem;
    }
    
    h3 {
        font-size: 1.25rem;
    }
    
    /* Adjust paragraph spacing */
    p {
        margin-bottom: 1rem;
    }
}

/* =================================================================
   Mobile Cases & Sessions List
   ================================================================= */

@media (max-width: 767px) {
    /* Rotate chevron when expanded */
    .rotate-90 {
        transform: rotate(90deg);
        transition: transform 0.2s ease-out;
    }
    
    /* Session cards */
    .mobile-case-list .bg-gray-50 {
        background-color: #f9fafb;
    }
    
    /* Active touch state */
    .mobile-case-list .hover\\:bg-gray-50:active {
        background-color: #f3f4f6;
    }
}

/* =================================================================
   Utility Classes
   ================================================================= */

/* Desktop/Mobile visibility */
.mobile-only {
    display: none !important;
}

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

@media screen and (max-width: 1023px) {
    .mobile-only {
        display: block !important;
        visibility: visible !important;
    }
    
    .desktop-only {
        display: none !important;
        visibility: hidden !important;
    }
    
    /* Hide on mobile */
    .mobile-hidden {
        display: none !important;
    }
    
    /* Stack horizontally aligned items */
    .mobile-stack {
        flex-direction: column !important;
    }
    
    /* Full width on mobile */
    .mobile-full-width {
        width: 100% !important;
        max-width: none !important;
    }
    
    /* Reduce padding on mobile */
    .mobile-compact {
        padding: 0.5rem !important;
    }
}

/* =================================================================
   Tablet Styles (768px - 1023px)
   ================================================================= */

@media (min-width: 768px) and (max-width: 1023px) {
    /* Tablet-specific adjustments */
    .dashboard-swimlanes {
        flex-wrap: wrap;
        justify-content: space-between;
    }
    
    .swimlane {
        width: calc(50% - 0.5rem);
        margin-bottom: 1rem;
    }
    
    /* Two-column forms on tablet */
    .form-grid {
        display: grid;
        grid-template-columns: 1fr 1fr;
        gap: 1rem;
    }
}

/* =================================================================
   Performance Optimizations
   ================================================================= */

/* Reduce animations on mobile for better performance */
@media (max-width: 767px) and (prefers-reduced-motion: no-preference) {
    * {
        animation-duration: 0.2s !important;
        transition-duration: 0.2s !important;
    }
}

/* Optimize image loading on mobile */
@media (max-width: 767px) {
    /* Use smaller images on mobile */
    img {
        image-rendering: -webkit-optimize-contrast;
        image-rendering: crisp-edges;
        max-width: 100%;
        height: auto;
    }
    
    /* Constrain logo sizes */
    img[src*="logo"] {
        max-width: 120px !important;
        max-height: 40px !important;
    }
    
    /* Prevent any images from becoming too large */
    img {
        max-width: 100% !important;
        height: auto !important;
        object-fit: contain;
    }
    
    /* Specific fix for any footer images */
    footer img,
    .footer img,
    body > img:last-child {
        max-height: 60px !important;
    }
    
    /* Lazy load images below the fold */
    img[loading="lazy"] {
        background: #f3f4f6;
    }
    
    /* Reduce shadow complexity on mobile */
    .shadow-lg {
        box-shadow: 0 4px 6px -1px rgba(0, 0, 0, 0.1) !important;
    }
    
    .shadow-xl {
        box-shadow: 0 10px 15px -3px rgba(0, 0, 0, 0.1) !important;
    }
    
    /* Simplify gradients on mobile */
    .bg-gradient-to-r {
        background-image: none !important;
        background-color: var(--gradient-from, #fbbf24) !important;
    }
    
    /* Reduce blur effects on mobile */
    .backdrop-blur,
    .backdrop-blur-sm,
    .backdrop-blur-md {
        backdrop-filter: none !important;
        background-color: rgba(255, 255, 255, 0.95) !important;
    }
    
    /* Use GPU acceleration for transforms */
    .mobile-nav,
    .modal,
    .dropdown {
        will-change: transform;
        transform: translateZ(0);
    }
    
    /* Optimize scrolling performance */
    .overflow-y-auto,
    .overflow-x-auto {
        -webkit-overflow-scrolling: touch;
        will-change: scroll-position;
    }
    
    /* Reduce repaints for fixed elements */
    .fixed {
        transform: translateZ(0);
        backface-visibility: hidden;
    }
}

/* =================================================================
   Firefox Mobile Specific Fixes
   ================================================================= */

@-moz-document url-prefix() {
    @media (max-width: 1023px) {
        /* Firefox mobile navbar fixes */
        .mobile-nav,
        nav.mobile-nav {
            position: fixed !important;
            bottom: 0 !important;
            left: 0 !important;
            right: 0 !important;
            width: 100% !important;
            display: -moz-box !important;
            display: flex !important;
            -moz-box-sizing: border-box !important;
            box-sizing: border-box !important;
            visibility: visible !important;
            opacity: 1 !important;
            transform: none !important;
            -moz-transform: none !important;
        }
        
        /* Firefox-specific navbar item fixes */
        .mobile-nav-item {
            display: -moz-box !important;
            display: flex !important;
            -moz-box-orient: vertical !important;
            -moz-box-direction: normal !important;
            flex-direction: column !important;
        }
        
        /* Ensure SVGs render properly in Firefox */
        .mobile-nav-item svg {
            display: block !important;
            width: 24px !important;
            height: 24px !important;
            min-width: 24px !important;
            min-height: 24px !important;
        }
        
        /* Firefox calendar grid fix */
        .grid.grid-cols-3 {
            display: block !important;
        }
        
        .grid.grid-cols-3 table {
            display: table !important;
            width: 100% !important;
        }
        
        .grid.grid-cols-3 tr {
            display: table-row !important;
        }
        
        .grid.grid-cols-3 th,
        .grid.grid-cols-3 td {
            display: table-cell !important;
        }
    }
}

/* =================================================================
   Dark Mode Support (future enhancement)
   ================================================================= */

@media (prefers-color-scheme: dark) {
    /* Dark mode styles will go here */
}

/* =================================================================
   Mobile Overflow Prevention
   ================================================================= */

@media (max-width: 1023px) {
    /* Prevent horizontal overflow on mobile devices */
    html, body {
        overflow-x: hidden !important;
        width: 100% !important;
        max-width: 100% !important;
    }
    
    /* Ensure all containers respect viewport width */
    .container, .content, main, section, article, div {
        max-width: 100% !important;
        overflow-x: hidden !important;
    }
    
    /* Prevent images from overflowing */
    img {
        max-width: 100% !important;
        height: auto !important;
        display: block !important;
    }
    
    /* Ensure tables are responsive */
    table {
        max-width: 100% !important;
        overflow-x: auto !important;
        display: block !important;
    }
    
    /* Prevent pre/code blocks from overflowing */
    pre, code {
        max-width: 100% !important;
        overflow-x: auto !important;
        word-wrap: break-word !important;
        white-space: pre-wrap !important;
    }
    
    /* Ensure forms don't overflow */
    form, input, textarea, select {
        max-width: 100% !important;
    }
    
    /* Prevent long text from overflowing */
    p, h1, h2, h3, h4, h5, h6, li, td, th {
        word-break: break-word !important;
        overflow-wrap: break-word !important;
    }
    
    /* Specific fix for any content that might be injected */
    .prose, .content-items, [class*="content"] {
        max-width: 100% !important;
        overflow-x: hidden !important;
    }
    
    /* Fix for absolute positioned elements */
    [style*="position: absolute"], [style*="position:absolute"] {
        max-width: 100% !important;
    }
    
    /* Ensure mobile nav doesn't cause overflow */
    .mobile-nav {
        width: 100% !important;
        max-width: 100% !important;
        left: 0 !important;
        right: 0 !important;
    }
}