/* Mobile iOS-like UI Styling - Enhanced for iPhone */

/* iOS menu button - guaranteed access */
.ios-menu-button {
    position: fixed;
    top: 10px;
    left: 10px;
    width: 44px;
    height: 44px;
    border-radius: 22px;
    background-color: rgba(255, 255, 255, 0.9);
    border: none;
    color: #007aff;
    font-size: 20px;
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 1100;
    box-shadow: 0 2px 8px rgba(0,0,0,0.15);
    -webkit-tap-highlight-color: transparent;
}

.ios-menu-button:active {
    transform: scale(0.95);
    background-color: rgba(235, 235, 235, 0.9);
}

/* Mobile menu backdrop needs to be visible */
.mobile-menu-backdrop {
    display: none;
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background-color: rgba(0,0,0,0.5);
    z-index: 1040;
    opacity: 0;
    transition: opacity 0.3s ease;
}

.mobile-menu-backdrop.show {
    display: block !important;
    opacity: 1 !important;
}

@media (max-width: 767.98px) {
    /* Body styling */
    body {
        font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Helvetica, Arial, sans-serif;
        background-color: #f2f2f7;
        -webkit-font-smoothing: antialiased;
        -moz-osx-font-smoothing: grayscale;
        padding-bottom: env(safe-area-inset-bottom, 85px);
        padding-top: 60px;
        min-height: 100vh;
        width: 100%;
        overflow-x: hidden;
        position: relative;
    }

    /* iOS-style safe area handling */
    .safe-area-bottom {
        padding-bottom: env(safe-area-inset-bottom, 20px);
    }

    .safe-area-top {
        padding-top: env(safe-area-inset-top, 20px);
    }

    /* Fixed elements for mobile */
    .navbar-collapse {
        position: fixed;
        top: 60px;
        left: 0;
        right: 0;
        bottom: 0;
        background-color: white;
        z-index: 1000;
        overflow-y: auto;
        -webkit-overflow-scrolling: touch;
        padding: 20px;
        transition: transform 0.3s cubic-bezier(0.23, 1, 0.32, 1);
        will-change: transform;
        display: block;
        transform: translateX(100%);
        box-shadow: -5px 0 15px rgba(0,0,0,0.1);
        /* Added to ensure visibility */
        visibility: hidden;
        opacity: 0;
    }
    
    .navbar-collapse.show {
        transform: translateX(0);
        /* Added to ensure visibility */
        visibility: visible !important;
        opacity: 1 !important;
        display: block !important;
    }
    
    /* Enhanced iOS-style navbar */
    .navbar {
        background-color: rgba(255, 255, 255, 0.95) !important;
        backdrop-filter: blur(10px);
        -webkit-backdrop-filter: blur(10px);
        box-shadow: 0 1px 5px rgba(0,0,0,0.08);
        height: 60px;
        padding: 0 16px;
        position: fixed;
        top: 0;
        left: 0;
        right: 0;
        z-index: 1030;
        transition: transform 0.3s ease;
    }
    
    .navbar.navbar-hidden {
        transform: translateY(-100%);
    }

    .navbar-dark {
        background-color: rgba(58, 58, 60, 0.95) !important;
    }

    .navbar-brand {
        padding: 0;
        margin-right: 0.5rem;
        height: 45px;
        display: flex;
        align-items: center;
    }
    
    .navbar-brand img {
        height: 28px;
    }

    .navbar-toggler {
        border: none;
        color: #007aff !important;
        padding: 0.5rem;
        outline: none !important;
        box-shadow: none !important;
        transition: transform 0.15s ease;
        -webkit-tap-highlight-color: transparent;
        cursor: pointer;
        touch-action: manipulation;
        /* Increase touch target size for better iOS interaction */
        min-width: 44px;
        min-height: 44px;
        margin-right: -8px;
    }

    .navbar-toggler:focus, 
    .navbar-toggler:active,
    .navbar-toggler.touch-active {
        outline: none !important;
        box-shadow: none !important;
        transform: scale(0.95);
    }

    /* Container styling */
    .container-fluid {
        padding: 16px;
        margin-top: 0 !important;
        max-width: 100%;
        transition: transform 0.3s ease;
    }
    
    /* Card styling with refined iOS card look */
    .card {
        border-radius: 13px;
        box-shadow: 0 2px 15px rgba(0,0,0,0.06);
        border: none;
        margin-bottom: 20px;
        overflow: hidden;
        background-color: #ffffff;
        transition: transform 0.2s ease, box-shadow 0.2s ease;
    }
    
    .card:active {
        transform: scale(0.98);
        box-shadow: 0 1px 8px rgba(0,0,0,0.06);
    }

    .card-header {
        background-color: #ffffff;
        border-bottom: 1px solid rgba(0,0,0,0.05);
        font-weight: 600;
        font-size: 17px;
        padding: 16px;
        border-top-left-radius: 13px !important;
        border-top-right-radius: 13px !important;
    }

    .card-body {
        padding: 16px;
    }

    /* Button styling for iOS feel */
    .btn {
        border-radius: 10px;
        padding: 10px 16px;
        font-weight: 600;
        font-size: 16px;
        transition: all 0.2s ease;
        display: inline-flex;
        align-items: center;
        justify-content: center;
        line-height: 1.4;
        touch-action: manipulation;
    }
    
    .btn i {
        margin-right: 8px;
    }

    .btn:active {
        transform: scale(0.96);
        box-shadow: none !important;
    }

    .btn-primary {
        background-color: #007aff;
        border-color: #007aff;
    }

    .btn-primary:hover, .btn-primary:focus {
        background-color: #0062cc;
        border-color: #0062cc;
    }
    
    .btn-sm {
        padding: 6px 12px;
        font-size: 14px;
        border-radius: 8px;
    }

    /* Form controls with iOS style */
    .form-control {
        border-radius: 10px;
        border: 1px solid rgba(0,0,0,0.1);
        padding: 12px 16px;
        font-size: 16px;
        background-color: #f5f5f5;
        appearance: none;
        -webkit-appearance: none;
        transition: all 0.2s ease;
    }

    .form-control:focus {
        border-color: #007aff;
        background-color: #ffffff;
        box-shadow: 0 0 0 3px rgba(0, 122, 255, 0.15);
    }
    
    .form-group label {
        font-weight: 500;
        margin-bottom: 8px;
        display: block;
    }

    /* Footer styling */
    .footer {
        background-color: #f2f2f7 !important;
        border-top: none;
        padding: 16px;
        font-size: 13px;
        color: #8e8e93;
        margin-bottom: 80px;
    }

    /* Improved Tab Panel - iPhone Style */
    .nav-tabs {
        border-bottom: none;
        display: flex;
        background-color: #f2f2f7;
        border-radius: 9px;
        padding: 4px;
        margin-bottom: 16px;
    }
    
    .nav-tabs .nav-item {
        flex: 1;
        margin-bottom: 0;
        text-align: center;
    }
    
    .nav-tabs .nav-link {
        border: none;
        border-radius: 7px;
        font-size: 14px;
        font-weight: 500;
        padding: 8px 10px;
        color: #8e8e93;
        transition: all 0.2s ease;
    }
    
    .nav-tabs .nav-link.active {
        background-color: #ffffff;
        color: #000000;
        box-shadow: 0 1px 3px rgba(0,0,0,0.1);
    }
    
    /* Mobile Client View Enhancements */
    /* Improved client list items */
    .client-list-item {
        border-radius: 12px;
        margin-bottom: 10px;
        background-color: white;
        box-shadow: 0 1px 5px rgba(0,0,0,0.08);
        overflow: hidden;
        transition: transform 0.2s ease, box-shadow 0.2s ease;
    }
    
    .client-list-item a {
        padding: 12px;
        display: block;
    }

    .client-list-item:active {
        transform: scale(0.98);
        box-shadow: 0 1px 2px rgba(0,0,0,0.05);
    }
    
    /* Bottom Tab Navigation - iPhone Style */
    .mobile-nav-container {
        position: fixed;
        bottom: 0;
        left: 0;
        right: 0;
        background-color: rgba(255, 255, 255, 0.95);
        backdrop-filter: blur(10px);
        -webkit-backdrop-filter: blur(10px);
        display: flex;
        justify-content: space-around;
        padding: 10px 0 calc(10px + env(safe-area-inset-bottom, 10px));
        box-shadow: 0 -1px 10px rgba(0,0,0,0.08);
        z-index: 1020;
        transition: transform 0.3s ease;
    }
    
    .mobile-nav-container.nav-hidden {
        transform: translateY(100%);
    }

    .mobile-nav-item {
        display: flex;
        flex-direction: column;
        align-items: center;
        justify-content: center;
        color: #8e8e93;
        text-decoration: none;
        font-size: 10px;
        padding: 8px 0;
        width: 20%;
        transition: color 0.2s ease;
        -webkit-tap-highlight-color: transparent;
    }
    
    .mobile-nav-item:active {
        color: #007aff;
    }

    .mobile-nav-item.active {
        color: #007aff;
    }

    .mobile-nav-item i {
        font-size: 24px;
        margin-bottom: 5px;
    }
    
    .mobile-nav-item span {
        font-weight: 500;
        white-space: nowrap;
        overflow: hidden;
        text-overflow: ellipsis;
        max-width: 100%;
    }
    
    /* Enhanced fab button for adding clients/items */
    .mobile-fab {
        position: fixed;
        right: 20px;
        bottom: 90px;
        width: 56px;
        height: 56px;
        border-radius: 28px;
        background-color: #007aff;
        color: #ffffff;
        display: flex;
        align-items: center;
        justify-content: center;
        box-shadow: 0 4px 10px rgba(0, 122, 255, 0.3);
        transition: all 0.3s ease;
        z-index: 1010;
    }
    
    .mobile-fab i {
        font-size: 24px;
    }
    
    .mobile-fab:active {
        transform: scale(0.95);
        box-shadow: 0 2px 5px rgba(0, 122, 255, 0.3);
    }
    
    /* Grid layouts for client cards */
    .mobile-clients-grid {
        display: grid;
        grid-template-columns: repeat(2, 1fr);
        gap: 12px;
        padding: 0 5px;
    }
    
    .mobile-client-card {
        background-color: white;
        border-radius: 12px;
        box-shadow: 0 2px 10px rgba(0,0,0,0.05);
        overflow: hidden;
        display: flex;
        flex-direction: column;
        transition: transform 0.2s ease, box-shadow 0.2s ease;
        position: relative;
        height: 100%;
    }
    
    .mobile-client-card:active {
        transform: scale(0.97);
        box-shadow: 0 1px 5px rgba(0,0,0,0.05);
    }
    
    .mobile-client-card .card-img-container {
        height: 110px;
        overflow: hidden;
        position: relative;
    }
    
    .mobile-client-card .card-img-container img {
        width: 100%;
        height: 100%;
        object-fit: cover;
    }
    
    .mobile-client-card .avatar-circle {
        width: 100%;
        height: 100%;
        display: flex;
        align-items: center;
        justify-content: center;
        font-size: 36px;
        font-weight: bold;
    }
    
    .mobile-client-card .card-body {
        padding: 10px;
        display: flex;
        flex-direction: column;
        flex-grow: 1;
    }
    
    .mobile-client-card .client-name {
        font-size: 14px;
        font-weight: 600;
        margin-bottom: 3px;
        white-space: nowrap;
        overflow: hidden;
        text-overflow: ellipsis;
    }
    
    .mobile-client-card .client-details {
        font-size: 12px;
        color: #8e8e93;
        margin-bottom: 0;
        white-space: nowrap;
        overflow: hidden;
        text-overflow: ellipsis;
    }
    
    /* iOS-style search bar */
    .mobile-search {
        position: relative;
        margin-bottom: 15px;
    }
    
    .mobile-search-input {
        width: 100%;
        padding: 12px 16px 12px 40px;
        font-size: 16px;
        border-radius: 10px;
        border: none;
        background-color: rgba(142, 142, 147, 0.12);
        appearance: none;
        -webkit-appearance: none;
    }
    
    .mobile-search-input:focus {
        outline: none;
        background-color: rgba(142, 142, 147, 0.20);
    }
    
    .mobile-search-icon {
        position: absolute;
        left: 15px;
        top: 50%;
        transform: translateY(-50%);
        color: #8e8e93;
        font-size: 16px;
    }
    
    /* Client detail panes with tab navigation */
    #clientDetailTabs {
        display: flex;
        overflow-x: auto;
        -webkit-overflow-scrolling: touch;
        scrollbar-width: none;
        margin-bottom: 10px;
        padding-bottom: 5px;
        flex-wrap: nowrap;
    }
    
    #clientDetailTabs::-webkit-scrollbar {
        display: none;
    }
    
    #clientDetailTabs .nav-item {
        flex: 0 0 auto;
        margin-right: 5px;
    }
    
    #clientDetailTabs .nav-link {
        padding: 8px 12px;
        border-radius: 15px;
        font-size: 14px;
        border: none;
        background-color: rgba(0,0,0,0.05);
        color: #8E8E93;
        white-space: nowrap;
    }
    
    #clientDetailTabs .nav-link.active {
        background-color: #007aff;
        color: white;
    }
    
    /* Services and products in mobile client view */
    .client-services-cards .card,
    .client-products-cards .card {
        margin-bottom: 15px;
        box-shadow: 0 2px 8px rgba(0,0,0,0.05);
    }
    
    .client-services-cards .card-header,
    .client-products-cards .card-header {
        display: flex;
        justify-content: space-between;
        align-items: center;
        padding: 12px 15px;
    }
    
    /* Mobile pulls to refresh animation */
    .pull-to-refresh {
        height: 60px;
        display: flex;
        align-items: center;
        justify-content: center;
        margin-top: -60px;
        transition: margin-top 0.3s ease;
    }
    
    .pull-to-refresh.visible {
        margin-top: 0;
    }
    
    .pull-to-refresh-spinner {
        width: 24px;
        height: 24px;
        border: 2px solid rgba(0, 122, 255, 0.3);
        border-top-color: #007aff;
        border-radius: 50%;
        animation: spin 1s infinite linear;
    }
    
    @keyframes spin {
        from { transform: rotate(0deg); }
        to { transform: rotate(360deg); }
    }
    
    /* Bottom sheet for actions */
    .bottom-sheet {
        position: fixed;
        bottom: 0;
        left: 0;
        right: 0;
        background-color: #ffffff;
        border-top-left-radius: 16px;
        border-top-right-radius: 16px;
        box-shadow: 0 -4px 20px rgba(0,0,0,0.1);
        z-index: 1050;
        transform: translateY(100%);
        transition: transform 0.35s cubic-bezier(0.23, 1, 0.32, 1);
        will-change: transform;
    }
    
    .bottom-sheet.show {
        transform: translateY(0);
    }
    
    .bottom-sheet-header {
        display: flex;
        align-items: center;
        justify-content: space-between;
        padding: 16px;
        border-bottom: 1px solid rgba(0,0,0,0.1);
    }
    
    .bottom-sheet-content {
        padding: 16px;
        max-height: 70vh;
        overflow-y: auto;
        -webkit-overflow-scrolling: touch;
    }
    
    .bottom-sheet-footer {
        border-top: 1px solid rgba(0,0,0,0.1);
        padding: 16px;
        display: flex;
        justify-content: space-between;
    }
    
    /* Modal backdrop for iOS */
    .modal-backdrop-ios {
        position: fixed;
        top: 0;
        left: 0;
        right: 0;
        bottom: 0;
        background-color: rgba(0,0,0,0.4);
        z-index: 1040;
        opacity: 0;
        transition: opacity 0.3s ease;
        pointer-events: none;
    }
    
    .modal-backdrop-ios.show {
        opacity: 1;
        pointer-events: auto;
    }
    
    /* Document types and status badges */
    .document-type-badge {
        padding: 6px 10px;
        border-radius: 12px;
        font-size: 12px;
        font-weight: 500;
        display: inline-block;
        margin-right: 5px;
        margin-bottom: 5px;
    }
    
    /* Payment plan visualization */
    .payment-plan-timeline {
        position: relative;
        margin: 30px 0;
        padding-left: 20px;
    }
    
    .payment-plan-timeline::before {
        content: '';
        position: absolute;
        left: 0;
        top: 0;
        bottom: 0;
        width: 2px;
        background-color: #e6e6e6;
    }
    
    .payment-plan-item {
        position: relative;
        padding-bottom: 20px;
    }
    
    .payment-plan-item::before {
        content: '';
        position: absolute;
        left: -24px;
        top: 0;
        width: 12px;
        height: 12px;
        border-radius: 50%;
        background-color: #007aff;
        border: 2px solid #ffffff;
        box-shadow: 0 0 0 2px #007aff;
    }
    
    .payment-plan-item.completed::before {
        background-color: #34c759;
        box-shadow: 0 0 0 2px #34c759;
    }
    
    .payment-plan-item.upcoming::before {
        background-color: #ffffff;
        box-shadow: 0 0 0 2px #ff9500;
    }
    
    /* Touch optimized sliders for iOS */
    .touch-slider {
        padding: 0;
        overflow-x: auto;
        -webkit-overflow-scrolling: touch;
        display: flex;
        gap: 10px;
        margin: 0 -16px;
        padding: 0 16px;
        scroll-snap-type: x mandatory;
    }
    
    .touch-slider::-webkit-scrollbar {
        display: none;
    }
    
    .touch-slider-item {
        flex: 0 0 auto;
        width: 220px;
        scroll-snap-align: start;
    }
    
    /* Stack cards for lists in mobile */
    .stack-card {
        margin-bottom: 12px;
    }
    
    .stack-card-header {
        display: flex;
        justify-content: space-between;
        align-items: center;
        padding: 12px 15px;
        border-bottom: 1px solid rgba(0,0,0,0.05);
    }
    
    .stack-card-body {
        padding: 15px;
    }
    
    .stack-card-footer {
        border-top: 1px solid rgba(0,0,0,0.05);
        padding: 10px 15px;
        display: flex;
        justify-content: flex-end;
    }
    
    /* Segmented controls for iOS style filtering */
    .segmented-control {
        display: flex;
        background-color: #e0e0e6;
        border-radius: 9px;
        padding: 2px;
        margin-bottom: 15px;
    }
    
    .segmented-control-item {
        flex: 1;
        text-align: center;
        padding: 8px 0;
        font-size: 13px;
        font-weight: 500;
        color: #636366;
        border-radius: 7px;
        transition: all 0.2s ease;
    }
    
    .segmented-control-item.active {
        background-color: #fff;
        color: #000;
        box-shadow: 0 1px 3px rgba(0,0,0,0.1);
    }
    
    /* Context menu for long-press on items */
    .context-menu {
        position: absolute;
        background-color: rgba(255, 255, 255, 0.98);
        backdrop-filter: blur(10px);
        -webkit-backdrop-filter: blur(10px);
        border-radius: 13px;
        box-shadow: 0 5px 25px rgba(0,0,0,0.15);
        z-index: 1051;
        overflow: hidden;
        min-width: 200px;
        transform-origin: top center;
        animation: scaleIn 0.15s ease-out forwards;
    }
    
    @keyframes scaleIn {
        from { transform: scale(0.9); opacity: 0; }
        to { transform: scale(1); opacity: 1; }
    }
    
    .context-menu-item {
        padding: 12px 16px;
        display: flex;
        align-items: center;
        font-size: 16px;
        color: #000;
        border-bottom: 1px solid rgba(0,0,0,0.05);
    }
    
    .context-menu-item:last-child {
        border-bottom: none;
    }
    
    .context-menu-item.destructive {
        color: #ff3b30;
    }
    
    .context-menu-item i {
        margin-right: 10px;
        width: 20px;
        text-align: center;
    }
    
    /* Improved form layout */
    .form-row-ios {
        margin-bottom: 20px;
    }
    
    .form-row-ios label {
        display: block;
        margin-bottom: 8px;
        font-weight: 500;
        font-size: 14px;
    }
    
    .form-input-ios {
        width: 100%;
        border-radius: 10px;
        padding: 12px 15px;
        border: 1px solid rgba(0,0,0,0.1);
        background-color: #f5f5f5;
        font-size: 16px;
        transition: all 0.2s ease;
    }
    
    .form-input-ios:focus {
        background-color: #fff;
        border-color: #007aff;
        box-shadow: 0 0 0 3px rgba(0, 122, 255, 0.15);
    }
    
    /* Alert panels with icons */
    .alert-ios {
        border-radius: 12px;
        padding: 15px;
        margin-bottom: 20px;
        display: flex;
        align-items: flex-start;
        box-shadow: 0 2px 8px rgba(0,0,0,0.05);
    }
    
    .alert-ios-icon {
        margin-right: 12px;
        font-size: 20px;
    }
    
    .alert-ios-content {
        flex: 1;
    }
    
    .alert-ios-content h5 {
        margin-bottom: 5px;
        font-size: 16px;
        font-weight: 600;
    }
    
    .alert-ios-content p {
        margin-bottom: 0;
        font-size: 14px;
    }
    
    /* Empty states for iOS - when no content */
    .empty-state {
        display: flex;
        flex-direction: column;
        align-items: center;
        justify-content: center;
        padding: 40px 20px;
        text-align: center;
    }
    
    .empty-state-icon {
        font-size: 40px;
        color: #8e8e93;
        margin-bottom: 15px;
    }
    
    .empty-state h3 {
        font-size: 18px;
        font-weight: 600;
        margin-bottom: 10px;
    }
    
    .empty-state p {
        font-size: 15px;
        color: #8e8e93;
        max-width: 250px;
        margin: 0 auto 20px;
    }
    
    /* Dark mode support */
    @media (prefers-color-scheme: dark) {
        body {
            background-color: #000;
            color: #fff;
        }
        
        .card, .navbar, .mobile-nav-container {
            background-color: #1c1c1e !important;
        }
        
        .card-header, .card-body {
            background-color: #1c1c1e;
            color: #fff;
        }
        
        .form-control, .form-input-ios {
            background-color: #2c2c2e;
            border-color: rgba(255,255,255,0.1);
            color: #fff;
        }
        
        .form-control:focus, .form-input-ios:focus {
            background-color: #3a3a3c;
        }
        
        .table thead th {
            background-color: #2c2c2e;
            color: #8e8e93;
        }
        
        .table {
            background-color: #1c1c1e;
            color: #fff;
        }
        
        .table td {
            border-color: rgba(255,255,255,0.1);
        }
        
        .list-group-item, .mobile-client-card, .client-list-item {
            background-color: #1c1c1e;
            color: #fff;
        }
        
        .bottom-sheet, .context-menu {
            background-color: rgba(28, 28, 30, 0.98);
        }
        
        .nav-tabs {
            background-color: #2c2c2e;
        }
        
        .nav-tabs .nav-link.active {
            background-color: #3a3a3c;
            color: #fff;
        }
        
        .segmented-control {
            background-color: #2c2c2e;
        }
        
        .segmented-control-item.active {
            background-color: #3a3a3c;
            color: #fff;
        }
        
        .alert-ios {
            background-color: #1c1c1e;
        }
    }
    
    /* Fix for unwanted touch highlighting */
    * {
        -webkit-tap-highlight-color: transparent;
    }
}

/* Mobile table fixes for smaller screens */
@media (max-width: 575.98px) {
    .table.mobile-ready {
        display: block;
        width: 100%;
    }
    
    .table.mobile-ready thead {
        display: none;
    }
    
    .table.mobile-ready tbody, 
    .table.mobile-ready tr {
        display: block;
        width: 100%;
    }
    
    .table.mobile-ready tr {
        margin-bottom: 15px;
        border-radius: 10px;
        box-shadow: 0 1px 5px rgba(0,0,0,0.08);
        overflow: hidden;
        background-color: #fff;
    }
    
    .table.mobile-ready td {
        display: flex;
        justify-content: space-between;
        align-items: center;
        border-bottom: 1px solid rgba(0,0,0,0.05);
        border-top: none !important;
        padding: 12px 16px;
        text-align: right;
    }
    
    .table.mobile-ready td:last-child {
        border-bottom: none;
    }
    
    .table.mobile-ready td::before {
        content: attr(data-label);
        font-weight: 600;
        margin-right: 15px;
        text-align: left;
        color: #666;
        flex: 1;
    }
    
    @media (prefers-color-scheme: dark) {
        .table.mobile-ready tr {
            background-color: #1c1c1e;
        }
        
        .table.mobile-ready td::before {
            color: #8e8e93;
        }
    }
}