/* Simple Mobile Leads CSS - Fixed Scrolling Version */

@media (max-width: 768px) {
    /* Force scrolling on everything that might block it */
    * {
        -webkit-overflow-scrolling: touch !important;
        touch-action: auto !important;
    }
    
    /* Ensure body and html can scroll */
    html, body {
        overflow-x: hidden !important;
        overflow-y: auto !important;
        height: auto !important;
        min-height: 100vh !important;
        max-height: none !important;
        position: static !important;
        touch-action: auto !important;
        -webkit-overflow-scrolling: touch !important;
    }
    
    /* Remove any scroll blocking classes */
    html.no-scroll, body.no-scroll {
        overflow: auto !important;
        height: auto !important;
        position: static !important;
    }
    
    /* Fix main page wrapper to allow scrolling */
    #page-content {
        overflow: visible !important;
        height: auto !important;
        min-height: auto !important;
        max-height: none !important;
        position: static !important;
        touch-action: auto !important;
    }
    
    .page-wrapper {
        overflow: visible !important;
        height: auto !important;
        min-height: auto !important;
        max-height: none !important;
        position: static !important;
        touch-action: auto !important;
    }
    
    /* Fix any containers that might block scrolling */
    .container, .container-fluid, .row, .col, [class*="col-"] {
        overflow: visible !important;
        height: auto !important;
        min-height: auto !important;
        max-height: none !important;
        position: static !important;
    }
    
    /* Hide desktop table on mobile */
    .leads-view .table-responsive {
        display: none !important;
    }
    
    /* Show mobile container with proper scrolling */
    .mobile-leads-container {
        display: block !important;
        padding: 15px;
        background: #f8f9fa;
        overflow: visible !important;
        height: auto !important;
        min-height: auto !important;
        position: relative !important;
        width: 100% !important;
        max-width: 100% !important;
    }
    
    /* Simple mobile lead card */
    .mobile-lead-card {
        background: white;
        border-radius: 15px;
        margin-bottom: 15px;
        padding: 0;
        box-shadow: 0 2px 15px rgba(0,0,0,0.1);
        border: 1px solid #e9ecef;
        width: 100%;
        box-sizing: border-box;
        overflow: hidden;
        position: relative;
    }
    
    .mobile-lead-header {
        display: flex;
        justify-content: space-between;
        align-items: center;
        padding: 15px 20px 10px 20px;
        background: linear-gradient(135deg, #f8f9fa, #ffffff);
        border-bottom: 1px solid #f1f3f4;
        margin-bottom: 10px;
    }
    
    .mobile-lead-company {
        font-size: 16px;
        font-weight: 700;
        color: #2c3e50;
        margin: 0;
        flex: 1;
    }
    
    .mobile-lead-actions-top {
        display: flex;
        gap: 8px;
        align-items: center;
    }
    
    .mobile-action-icon {
        width: 36px;
        height: 36px;
        border-radius: 50%;
        display: flex;
        align-items: center;
        justify-content: center;
        text-decoration: none;
        transition: all 0.3s ease;
        position: relative;
        border: 2px solid transparent;
        background: transparent;
    }
    
    .mobile-action-icon svg {
        width: 18px;
        height: 18px;
        stroke-width: 2;
    }
    
    .mobile-action-view {
        color: #17a2b8;
        border-color: rgba(23,162,184,0.2);
    }
    
    .mobile-action-view:hover {
        color: #17a2b8;
        background: rgba(23,162,184,0.1);
        border-color: #17a2b8;
        transform: scale(1.1);
        text-decoration: none;
    }
    
    .mobile-action-edit {
        color: #28a745;
        border-color: rgba(40,167,69,0.2);
    }
    
    .mobile-action-edit:hover {
        color: #28a745;
        background: rgba(40,167,69,0.1);
        border-color: #28a745;
        transform: scale(1.1);
        text-decoration: none;
    }
    
    .mobile-action-delete {
        color: #dc3545;
        border-color: rgba(220,53,69,0.2);
    }
    
    .mobile-action-delete:hover {
        color: #dc3545;
        background: rgba(220,53,69,0.1);
        border-color: #dc3545;
        transform: scale(1.1);
        text-decoration: none;
    }
    
    .mobile-action-icon:active {
        transform: scale(1.05);
    }
    
    /* Adjust card content padding */
    .mobile-lead-card > div:not(.mobile-lead-header):not(.mobile-lead-actions) {
        padding: 0 20px;
        margin: 8px 0;
    }
    
    .mobile-lead-actions {
        padding: 15px 20px;
        margin: 0;
    }
    
    .mobile-lead-phone {
        color: #666;
        margin-bottom: 10px;
        font-size: 14px;
        word-wrap: break-word;
    }
    
    /* Simple action buttons */
    .mobile-lead-actions {
        display: flex;
        gap: 10px;
        margin-top: 15px;
        flex-wrap: wrap;
    }
    
    .mobile-action-btn {
        flex: 1;
        padding: 12px;
        text-align: center;
        text-decoration: none;
        color: white;
        border-radius: 8px;
        font-size: 14px;
        font-weight: bold;
        min-width: 80px;
        white-space: nowrap;
        overflow: hidden;
        text-overflow: ellipsis;
    }
    
    .mobile-action-call {
        background: #28a745;
    }
    
    .mobile-action-whatsapp {
        background: #25d366;
    }
    
    .mobile-action-email {
        background: #007bff;
    }
    
    .mobile-action-location {
        background: linear-gradient(135deg, #fd7e14, #e65100);
        position: relative;
        overflow: hidden;
    }
    
    .mobile-action-location:hover {
        background: linear-gradient(135deg, #e65100, #d84315);
        transform: translateY(-2px);
        box-shadow: 0 4px 15px rgba(253,126,20,0.3);
    }
    
    .mobile-action-location:active {
        transform: translateY(0px);
    }
    
    .mobile-action-btn:hover {
        color: white;
        text-decoration: none;
        opacity: 0.9;
    }
    
    .mobile-action-btn.disabled {
        background: #6c757d;
        cursor: not-allowed;
    }
    
    /* Loading and empty states */
    .mobile-leads-loading, .mobile-leads-empty {
        text-align: center;
        padding: 40px 20px;
        color: #6c757d;
    }
    
    /* Fix any fixed positioning that might interfere */
    .navbar, .nav-tabs, .header {
        position: relative !important;
    }
    
    /* Ensure mobile list container has proper scrolling */
    #mobile-leads-list {
        overflow: visible !important;
        height: auto !important;
        width: 100% !important;
        position: relative !important;
    }
    
    /* Pagination styles */
    #mobile-pagination {
        padding: 20px;
        text-align: center;
        background: rgba(248, 249, 250, 0.5);
        border-radius: 15px;
        margin: 15px;
    }
    
    /* Mobile Filter Styles */
    #mobile-filter-section {
        background: white;
        border-radius: 15px;
        margin: 15px;
        box-shadow: 0 2px 10px rgba(0,0,0,0.1);
        overflow: hidden;
    }
    
    .mobile-filter-header {
        display: flex;
        justify-content: space-between;
        align-items: center;
        padding: 15px 20px;
        background: linear-gradient(135deg, #f8f9fa, #e9ecef);
        border-bottom: 1px solid #dee2e6;
        cursor: pointer;
    }
    
    .mobile-filter-header h5 {
        margin: 0 !important;
        color: #495057 !important;
        font-weight: 600 !important;
        font-size: 16px !important;
    }
    
    #mobile-filter-toggle {
        border: none !important;
        background: transparent !important;
        color: #007bff !important;
        padding: 5px 10px !important;
        border-radius: 20px !important;
        transition: all 0.3s ease !important;
    }
    
    #mobile-filter-toggle:hover {
        background: rgba(0,123,255,0.1) !important;
    }
    
    #mobile-filter-content {
        padding: 20px;
    }
    
    .mobile-filter-item {
        margin-bottom: 20px;
    }
    
    .mobile-filter-label {
        display: block;
        font-weight: 600;
        color: #495057;
        margin-bottom: 8px;
        font-size: 14px;
    }
    
    .mobile-filter-input,
    .mobile-filter-select {
        width: 100% !important;
        padding: 12px 15px !important;
        border: 2px solid #e9ecef !important;
        border-radius: 10px !important;
        font-size: 16px !important;
        background: white !important;
        color: #495057 !important;
        transition: all 0.3s ease !important;
        -webkit-appearance: none !important;
        appearance: none !important;
    }
    
    .mobile-filter-select {
        background-image: url("data:image/svg+xml;charset=utf-8,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 16 16'%3E%3Cpath fill='none' stroke='%23343a40' stroke-linecap='round' stroke-linejoin='round' stroke-width='2' d='m2 5 6 6 6-6'/%3E%3C/svg%3E") !important;
        background-repeat: no-repeat !important;
        background-position: right 12px center !important;
        background-size: 16px 12px !important;
        padding-right: 40px !important;
    }
    
    .mobile-filter-input:focus,
    .mobile-filter-select:focus {
        border-color: #007bff !important;
        box-shadow: 0 0 0 3px rgba(0,123,255,0.1) !important;
        outline: none !important;
    }
    
    .mobile-filter-actions {
        display: flex;
        gap: 10px;
        margin-top: 25px;
        padding-top: 20px;
        border-top: 1px solid #e9ecef;
    }
    
    .mobile-filter-actions .btn {
        flex: 1;
        padding: 12px !important;
        font-weight: 600 !important;
        border-radius: 10px !important;
        font-size: 14px !important;
        border: none !important;
        transition: all 0.3s ease !important;
    }
    
    .mobile-filter-actions .btn-primary {
        background: linear-gradient(135deg, #007bff, #0056b3) !important;
        color: white !important;
    }
    
    .mobile-filter-actions .btn-secondary {
        background: #6c757d !important;
        color: white !important;
    }
    
    .mobile-filter-actions .btn:active {
        transform: translateY(1px) !important;
    }
    
    #load-more-btn {
        background: linear-gradient(135deg, #007bff, #0056b3) !important;
        border: none !important;
        border-radius: 25px !important;
        padding: 15px 30px !important;
        color: white !important;
        font-weight: 600 !important;
        font-size: 16px !important;
        box-shadow: 0 4px 20px rgba(0,123,255,0.3) !important;
        transition: all 0.3s ease !important;
        min-height: 50px !important;
        min-width: 200px !important;
        touch-action: manipulation !important;
    }
    
    #load-more-btn:hover, #load-more-btn:active {
        background: linear-gradient(135deg, #0056b3, #004085) !important;
        transform: translateY(-2px) !important;
        box-shadow: 0 6px 25px rgba(0,123,255,0.4) !important;
    }
    
    #load-more-btn:disabled {
        background: #6c757d !important;
        cursor: not-allowed !important;
        transform: none !important;
        box-shadow: none !important;
    }
    
    #loading-more {
        color: #6c757d;
        font-size: 14px;
        padding: 10px;
    }
    
    .spinner-border-sm {
        width: 1rem;
        height: 1rem;
        border-width: 0.1rem;
    }
    
    /* Fix viewport meta if needed */
    @viewport {
        width: device-width;
        zoom: 1.0;
    }
}

/* Hide mobile container on desktop */
@media (min-width: 769px) {
    .mobile-leads-container {
        display: none !important;
    }
}

/* Mobile Modal Styles */
@media (max-width: 768px) {
    #leadEditModal .modal-dialog {
        margin: 10px;
        max-width: calc(100% - 20px);
        max-height: calc(100vh - 20px);
        display: flex;
        flex-direction: column;
    }
    
    #leadEditModal .modal-content {
        border-radius: 10px;
        height: 100%;
        max-height: calc(100vh - 20px);
        display: flex;
        flex-direction: column;
        position: relative;
    }
    
    #leadEditModal .modal-header {
        flex-shrink: 0;
        padding: 15px 60px 15px 15px; /* Add right padding for close button */
        border-bottom: 1px solid #dee2e6;
        position: relative;
    }
    
    #leadEditModal .modal-body {
        flex: 1;
        padding: 15px;
        overflow-y: auto;
        -webkit-overflow-scrolling: touch;
        overscroll-behavior: contain;
    }
    
    /* Ensure modal appears above everything */
    #leadEditModal {
        z-index: 1055;
    }
    
    #leadEditModal.modal {
        padding-left: 0 !important;
        padding-right: 0 !important;
    }
    
    /* Close button styling - positioned in top right corner */
    #leadEditModal .close,
    #leadEditModal .btn-close {
        position: absolute !important;
        top: 15px;
        right: 15px;
        background: rgba(0,0,0,0.1);
        border: none;
        font-size: 1.2rem;
        font-weight: 700;
        line-height: 1;
        color: #000;
        text-shadow: none;
        opacity: .8;
        cursor: pointer;
        padding: 0;
        margin: 0;
        width: 35px;
        height: 35px;
        display: flex;
        align-items: center;
        justify-content: center;
        border-radius: 50%;
        z-index: 10;
        transition: all 0.2s ease;
    }
    
    #leadEditModal .close:hover,
    #leadEditModal .btn-close:hover {
        opacity: 1;
        background-color: rgba(220, 53, 69, 0.1);
        color: #dc3545;
        transform: scale(1.1);
    }
    
    #leadEditModal .close:active,
    #leadEditModal .btn-close:active {
        transform: scale(0.95);
    }
    
    /* Modal title adjustment */
    #leadEditModal .modal-title {
        margin: 0;
        padding-right: 40px; /* Ensure title doesn't overlap close button */
        font-size: 18px;
        font-weight: 600;
    }
    
    /* Fix form elements in modal */
    #leadEditModal .form-control,
    #leadEditModal .form-select,
    #leadEditModal select,
    #leadEditModal input,
    #leadEditModal textarea {
        font-size: 16px; /* Prevents zoom on iOS */
        max-width: 100%;
    }
    
    /* Fix select2 dropdowns in modal */
    .select2-container {
        z-index: 1060 !important;
    }
    
    .select2-dropdown {
        z-index: 1060 !important;
    }
}

/* Desktop modal improvements */
@media (min-width: 769px) {
    #leadEditModal .modal-dialog {
        max-height: 90vh;
    }
    
    #leadEditModal .modal-body {
        max-height: 70vh;
        overflow-y: auto;
    }
    
    /* Desktop close button positioning */
    #leadEditModal .close,
    #leadEditModal .btn-close {
        position: absolute !important;
        top: 20px;
        right: 20px;
        background: rgba(0,0,0,0.05);
        border: none;
        font-size: 1.5rem;
        font-weight: 700;
        line-height: 1;
        color: #6c757d;
        text-shadow: none;
        opacity: .8;
        cursor: pointer;
        padding: 0;
        margin: 0;
        width: 40px;
        height: 40px;
        display: flex;
        align-items: center;
        justify-content: center;
        border-radius: 50%;
        z-index: 10;
        transition: all 0.2s ease;
    }
    
    #leadEditModal .close:hover,
    #leadEditModal .btn-close:hover {
        opacity: 1;
        background-color: rgba(220, 53, 69, 0.1);
        color: #dc3545;
    }
    
    #leadEditModal .modal-header {
        padding: 20px 70px 20px 20px; /* Add right padding for close button */
        border-bottom: 1px solid #dee2e6;
        position: relative;
    }
}

/* Loading animation */
.rotating {
    animation: rotate 1s linear infinite;
}

@keyframes rotate {
    from {
        transform: rotate(0deg);
    }
    to {
        transform: rotate(360deg);
    }
}

/* Prevent body scroll when modal is open */
body.modal-open {
    overflow: hidden;
    position: fixed;
    width: 100%;
}

/* Modal backdrop fixes */
.modal-backdrop {
    z-index: 1050;
}

/* Ensure modal scrolling works properly */
.modal-dialog-scrollable {
    height: calc(100% - 1rem);
}

.modal-dialog-scrollable .modal-content {
    max-height: 100%;
    overflow: hidden;
}

.modal-dialog-scrollable .modal-body {
    overflow-y: auto;
}

/* Additional close button improvements */
#leadEditModal .close span,
#leadEditModal .btn-close span {
    font-size: inherit;
    line-height: inherit;
}

/* Ensure close button works on touch devices */
#leadEditModal .close,
#leadEditModal .btn-close {
    touch-action: manipulation;
    -webkit-tap-highlight-color: transparent;
}

/* Mobile Lead Actions Button Styling */
.mobile-lead-actions {
    display: flex;
    gap: 8px;
    margin-top: 10px;
    flex-wrap: wrap;
}

.mobile-action-btn {
    flex: 1;
    min-width: calc(25% - 6px);
    padding: 8px 4px;
    text-align: center;
    border-radius: 6px;
    font-size: 12px;
    font-weight: 500;
    text-decoration: none;
    transition: all 0.2s ease;
    border: 1px solid transparent;
}

.mobile-action-whatsapp {
    background: linear-gradient(135deg, #25D366, #128C7E);
    color: white;
    border-color: #25D366;
}

.mobile-action-whatsapp:hover {
    background: linear-gradient(135deg, #128C7E, #075E54);
    color: white;
    text-decoration: none;
    transform: translateY(-1px);
}

.mobile-action-btn.disabled {
    background: #f8f9fa;
    color: #6c757d;
    border-color: #dee2e6;
    cursor: not-allowed;
}

.mobile-action-location {
    background: linear-gradient(135deg, #007bff, #0056b3);
    color: white;
    border-color: #007bff;
}

.mobile-action-location:hover {
    background: linear-gradient(135deg, #0056b3, #004085);
    color: white;
    text-decoration: none;
    transform: translateY(-1px);
}

.mobile-action-call {
    background: linear-gradient(135deg, #28a745, #1e7e34);
    color: white;
    border-color: #28a745;
}

.mobile-action-call:hover {
    background: linear-gradient(135deg, #1e7e34, #155724);
    color: white;
    text-decoration: none;
    transform: translateY(-1px);
}

@media (max-width: 480px) {
    .mobile-action-btn {
        font-size: 11px;
        padding: 6px 3px;
    }
}
.mobile-lead-info-actions {
    display: flex;
    gap: 6px;
    margin: 10px 0 8px 0;
    flex-wrap: nowrap;
}

.mobile-info-btn {
    flex: 1;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    padding: 8px 4px;
    background: linear-gradient(135deg, #f8f9fa, #e9ecef);
    border: 1px solid #dee2e6;
    border-radius: 8px;
    font-size: 11px;
    font-weight: 500;
    color: #495057;
    text-decoration: none;
    transition: all 0.2s ease;
    cursor: pointer;
    min-height: 55px;
}

.mobile-info-btn:hover,
.mobile-info-btn:focus {
    background: linear-gradient(135deg, #e9ecef, #dee2e6);
    border-color: #adb5bd;
    color: #212529;
    transform: translateY(-1px);
    box-shadow: 0 2px 8px rgba(0,0,0,0.1);
}

.mobile-info-btn:active {
    transform: translateY(0);
    box-shadow: 0 1px 4px rgba(0,0,0,0.1);
}

.mobile-info-btn i {
    margin-bottom: 4px;
    opacity: 0.8;
}

.mobile-info-btn span {
    font-size: 10px;
    line-height: 1.2;
    text-align: center;
}

/* Specific styling for different info buttons */
.mobile-info-source:hover {
    background: linear-gradient(135deg, #d4edda, #c3e6cb);
    border-color: #28a745;
    color: #155724;
}

.mobile-info-labels:hover {
    background: linear-gradient(135deg, #fff3cd, #ffeaa7);
    border-color: #ffc107;
    color: #856404;
}

.mobile-info-status:hover {
    background: linear-gradient(135deg, #d1ecf1, #bee5eb);
    border-color: #17a2b8;
    color: #0c5460;
}

.mobile-info-messages:hover {
    background: linear-gradient(135deg, #f8d7da, #f5c6cb);
    border-color: #dc3545;
    color: #721c24;
}

/* Responsive adjustments */
@media (max-width: 480px) {
    .mobile-info-btn {
        padding: 6px 3px;
        min-height: 50px;
    }
    
    .mobile-info-btn span {
        font-size: 9px;
    }
}
/* Comments Modal Styles */
#commentsModal .modal-body {
    padding: 0;
}

#commentsModal .comments-section {
    max-height: 400px;
    overflow-y: auto;
    padding: 15px;
}

#commentsModal .comment-item {
    border-bottom: 1px solid #e9ecef;
    padding: 15px 0;
    margin-bottom: 15px;
}

#commentsModal .comment-item:last-child {
    border-bottom: none;
    margin-bottom: 0;
}

#commentsModal .comment-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 8px;
}

#commentsModal .comment-author {
    font-weight: 600;
    color: #495057;
    font-size: 14px;
}

#commentsModal .comment-date {
    font-size: 12px;
    color: #6c757d;
}

#commentsModal .comment-content {
    color: #495057;
    line-height: 1.5;
    font-size: 14px;
    margin-bottom: 10px;
}

#commentsModal .comment-form {
    border-top: 1px solid #e9ecef;
    padding: 20px;
    background: #f8f9fa;
}

#commentsModal .comment-textarea {
    min-height: 80px;
    resize: vertical;
}

#commentsModal .no-comments {
    text-align: center;
    color: #6c757d;
    padding: 40px 20px;
    font-style: italic;
}

/* Mobile specific adjustments for comments modal */
@media (max-width: 768px) {
    #commentsModal .modal-dialog {
        margin: 10px;
        max-width: calc(100% - 20px);
        max-height: calc(100vh - 20px);
    }
    
    #commentsModal .modal-content {
        height: 100%;
        max-height: calc(100vh - 20px);
        display: flex;
        flex-direction: column;
    }
    
    #commentsModal .modal-header {
        flex-shrink: 0;
        padding: 15px 60px 15px 15px;
        position: relative;
    }
    
    #commentsModal .modal-body {
        flex: 1;
        overflow: hidden;
        display: flex;
        flex-direction: column;
    }
    
    #commentsModal .comments-section {
        flex: 1;
        overflow-y: auto;
        -webkit-overflow-scrolling: touch;
    }
    
    #commentsModal .comment-form {
        flex-shrink: 0;
    }
    
    /* Close button positioning for comments modal */
    #commentsModal .close,
    #commentsModal .btn-close {
        position: absolute !important;
        top: 15px;
        right: 15px;
        background: rgba(0,0,0,0.1);
        border: none;
        font-size: 1.2rem;
        font-weight: 700;
        line-height: 1;
        color: #000;
        text-shadow: none;
        opacity: .8;
        cursor: pointer;
        padding: 0;
        margin: 0;
        width: 35px;
        height: 35px;
        display: flex;
        align-items: center;
        justify-content: center;
        border-radius: 50%;
        z-index: 10;
        transition: all 0.2s ease;
    }
    
    #commentsModal .close:hover,
    #commentsModal .btn-close:hover {
        opacity: 1;
        background-color: rgba(220, 53, 69, 0.1);
        color: #dc3545;
        transform: scale(1.1);
    }
}

/* Loading animation for rotating icon */
.rotating {
    animation: rotate 1s linear infinite;
}

@keyframes rotate {
    from {
        transform: rotate(0deg);
    }
    to {
        transform: rotate(360deg);
    }
}