/**
 * Mobile Table & List Responsiveness
 * 
 * Strategy:
 * - Desktop: Traditional HTML tables
 * - Mobile (<768px): Card-based layout with key information
 * - Swipe gestures: Left (delete), right (edit)
 * - Pull-to-refresh for list updates
 * - Infinite scroll or "Load More" button
 * 
 * Phase: 3.4 - Table/List Responsiveness
 * Date: December 30, 2025
 */

/* ========================================================================
   MOBILE TABLE RESPONSIVENESS (< 768px)
   ======================================================================== */

@media (max-width: 767px) {
    
    /* ====================================================================
       1. HIDE TABLES ON MOBILE - Show cards instead
       ==================================================================== */
    
    /* Hide traditional table structure on mobile */
    .table-responsive-mobile {
        display: none !important;
    }
    
    /* Show card layout on mobile */
    .card-layout-mobile {
        display: block !important;
    }
    
    /* For tables without card alternatives, enable horizontal scroll */
    .table-horizontal-scroll {
        overflow-x: auto;
        -webkit-overflow-scrolling: touch;
        margin-bottom: 20px;
    }
    
    .table-horizontal-scroll table {
        min-width: 600px;
        white-space: nowrap;
    }
    
    /* ====================================================================
       2. CARD-BASED LIST ITEMS
       ==================================================================== */
    
    /* Lead/Client card */
    .mobile-list-card {
        background: white;
        border-radius: 12px;
        padding: 16px;
        margin-bottom: 12px;
        box-shadow: 0 2px 8px rgba(0, 0, 0, 0.08);
        position: relative;
        transition: transform 0.2s ease, box-shadow 0.2s ease;
        cursor: pointer;
        -webkit-tap-highlight-color: transparent;
    }
    
    .mobile-list-card:active {
        transform: scale(0.98);
        box-shadow: 0 1px 4px rgba(0, 0, 0, 0.12);
    }
    
    /* Card header with title and status */
    .mobile-card-header {
        display: flex;
        justify-content: space-between;
        align-items: flex-start;
        margin-bottom: 12px;
    }
    
    .mobile-card-title {
        font-size: 17px;
        font-weight: 700;
        color: #1f2937;
        margin: 0;
        flex: 1;
        line-height: 1.4;
    }
    
    .mobile-card-status {
        flex-shrink: 0;
        margin-left: 12px;
    }
    
    /* Card body with key information */
    .mobile-card-body {
        margin-bottom: 12px;
    }
    
    .mobile-card-info-row {
        display: flex;
        align-items: center;
        margin-bottom: 8px;
        font-size: 14px;
        color: #6b7280;
    }
    
    .mobile-card-info-row i {
        width: 20px;
        margin-right: 8px;
        color: #9ca3af;
        font-size: 14px;
    }
    
    .mobile-card-info-label {
        font-weight: 600;
        margin-right: 6px;
        color: #4b5563;
    }
    
    .mobile-card-info-value {
        color: #1f2937;
    }
    
    /* Card footer with actions */
    .mobile-card-actions {
        display: flex;
        gap: 8px;
        padding-top: 12px;
        border-top: 1px solid #e5e7eb;
    }
    
    .mobile-card-actions .btn {
        flex: 1;
        min-height: 40px;
        font-size: 14px;
        padding: 8px 12px;
    }
    
    /* ====================================================================
       3. STATUS BADGES - Larger on mobile
       ==================================================================== */
    
    .mobile-card-status .badge {
        font-size: 12px;
        padding: 4px 10px;
        border-radius: 12px;
        font-weight: 600;
        text-transform: uppercase;
        letter-spacing: 0.3px;
    }
    
    /* Status colors */
    .badge-new { background: #dbeafe; color: #1e40af; }
    .badge-contacted { background: #fef3c7; color: #92400e; }
    .badge-qualified { background: #d1fae5; color: #065f46; }
    .badge-proposal { background: #e0e7ff; color: #3730a3; }
    .badge-negotiation { background: #fce7f3; color: #831843; }
    .badge-won { background: #d1fae5; color: #065f46; }
    .badge-lost { background: #fee2e2; color: #991b1b; }
    
    /* ====================================================================
       4. SWIPE GESTURES - Touch interactions
       ==================================================================== */
    
    /* Swipe container */
    .swipeable-card {
        position: relative;
        overflow: hidden;
    }
    
    /* Swipe actions background */
    .swipe-actions-left,
    .swipe-actions-right {
        position: absolute;
        top: 0;
        bottom: 0;
        width: 80px;
        display: flex;
        align-items: center;
        justify-content: center;
        z-index: -1;
    }
    
    .swipe-actions-left {
        left: 0;
        background: linear-gradient(90deg, #ef4444 0%, #dc2626 100%);
    }
    
    .swipe-actions-right {
        right: 0;
        background: linear-gradient(90deg, #3b82f6 0%, #2563eb 100%);
    }
    
    .swipe-action-icon {
        color: white;
        font-size: 24px;
    }
    
    /* Swipe indicator */
    .swipe-hint {
        position: absolute;
        bottom: 8px;
        right: 12px;
        font-size: 11px;
        color: #9ca3af;
        font-weight: 500;
        display: flex;
        align-items: center;
        gap: 4px;
    }
    
    /* ====================================================================
       5. PULL-TO-REFRESH
       ==================================================================== */
    
    .pull-to-refresh-container {
        position: relative;
        overflow: hidden;
    }
    
    .pull-to-refresh-indicator {
        position: absolute;
        top: -60px;
        left: 0;
        right: 0;
        height: 60px;
        display: flex;
        align-items: center;
        justify-content: center;
        background: linear-gradient(180deg, #f3f4f6 0%, white 100%);
        transition: transform 0.3s ease;
        z-index: 100;
    }
    
    .pull-to-refresh-indicator.pulling {
        transform: translateY(60px);
    }
    
    .pull-to-refresh-indicator i {
        font-size: 24px;
        color: #2563eb;
        animation: spin 1s linear infinite;
    }
    
    @keyframes spin {
        from { transform: rotate(0deg); }
        to { transform: rotate(360deg); }
    }
    
    /* ====================================================================
       6. LOAD MORE BUTTON - Better than pagination on mobile
       ==================================================================== */
    
    .mobile-load-more {
        width: 100%;
        min-height: 52px;
        margin: 20px 0;
        font-size: 16px;
        font-weight: 600;
        border: 2px solid #e5e7eb;
        background: white;
        color: #2563eb;
        border-radius: 10px;
        display: flex;
        align-items: center;
        justify-content: center;
        gap: 8px;
        cursor: pointer;
        transition: all 0.2s ease;
    }
    
    .mobile-load-more:active {
        background: #f9fafb;
        transform: scale(0.98);
    }
    
    .mobile-load-more i {
        font-size: 18px;
    }
    
    /* Loading state */
    .mobile-load-more.loading {
        opacity: 0.6;
        cursor: wait;
    }
    
    .mobile-load-more.loading i {
        animation: spin 1s linear infinite;
    }
    
    /* ====================================================================
       7. EMPTY STATES - Better visual feedback
       ==================================================================== */
    
    .mobile-empty-state {
        text-align: center;
        padding: 60px 20px;
    }
    
    .mobile-empty-state i {
        font-size: 64px;
        color: #d1d5db;
        margin-bottom: 20px;
    }
    
    .mobile-empty-state h3 {
        font-size: 20px;
        font-weight: 700;
        color: #1f2937;
        margin-bottom: 12px;
    }
    
    .mobile-empty-state p {
        font-size: 15px;
        color: #6b7280;
        margin-bottom: 24px;
        line-height: 1.6;
    }
    
    .mobile-empty-state .btn {
        min-height: 48px;
        padding: 12px 24px;
        font-size: 16px;
    }
    
    /* ====================================================================
       8. SEARCH & FILTER BAR - Sticky on mobile
       ==================================================================== */
    
    .mobile-search-bar {
        position: sticky;
        top: 0;
        z-index: 100;
        background: white;
        padding: 12px 16px;
        border-bottom: 1px solid #e5e7eb;
        margin-bottom: 16px;
    }
    
    .mobile-search-input {
        width: 100%;
        min-height: 44px;
        padding: 10px 16px 10px 44px;
        font-size: 16px;
        border: 1px solid #d1d5db;
        border-radius: 22px;
        background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='%236b7280' stroke-width='2'%3E%3Ccircle cx='11' cy='11' r='8'/%3E%3Cpath d='m21 21-4.35-4.35'/%3E%3C/svg%3E");
        background-repeat: no-repeat;
        background-position: 14px center;
        background-size: 20px 20px;
    }
    
    .mobile-search-input:focus {
        outline: none;
        border-color: #2563eb;
        box-shadow: 0 0 0 4px rgba(37, 99, 235, 0.1);
    }
    
    /* Filter button */
    .mobile-filter-button {
        min-width: 44px;
        min-height: 44px;
        margin-left: 8px;
        border-radius: 22px;
        border: 1px solid #d1d5db;
        background: white;
        display: flex;
        align-items: center;
        justify-content: center;
        cursor: pointer;
    }
    
    .mobile-filter-button.active {
        background: #2563eb;
        color: white;
        border-color: #2563eb;
    }
    
    .mobile-filter-button i {
        font-size: 18px;
    }
    
    /* ====================================================================
       9. SORTING DROPDOWN - Mobile-friendly
       ==================================================================== */
    
    .mobile-sort-bar {
        display: flex;
        align-items: center;
        padding: 12px 16px;
        background: #f9fafb;
        border-bottom: 1px solid #e5e7eb;
        margin-bottom: 16px;
    }
    
    .mobile-sort-label {
        font-size: 14px;
        font-weight: 600;
        color: #6b7280;
        margin-right: 12px;
    }
    
    .mobile-sort-select {
        flex: 1;
        min-height: 40px;
        padding: 8px 12px;
        font-size: 14px;
        border: 1px solid #d1d5db;
        border-radius: 8px;
        background: white;
        cursor: pointer;
    }
    
    /* ====================================================================
       10. LEAD LIST - Specific styles
       ==================================================================== */
    
    .mobile-lead-card {
        position: relative;
    }
    
    .mobile-lead-card .lead-name {
        font-size: 17px;
        font-weight: 700;
        color: #1f2937;
        margin-bottom: 4px;
    }
    
    .mobile-lead-card .lead-company {
        font-size: 14px;
        color: #6b7280;
        margin-bottom: 12px;
    }
    
    .mobile-lead-card .lead-meta {
        display: flex;
        flex-wrap: wrap;
        gap: 12px;
        font-size: 13px;
        color: #6b7280;
    }
    
    .mobile-lead-card .lead-meta-item {
        display: flex;
        align-items: center;
        gap: 6px;
    }
    
    .mobile-lead-card .lead-actions {
        display: flex;
        gap: 8px;
        margin-top: 12px;
        padding-top: 12px;
        border-top: 1px solid #e5e7eb;
    }
    
    .mobile-lead-card .lead-actions .btn {
        flex: 1;
        min-height: 40px;
        font-size: 13px;
    }
    
    /* ====================================================================
       11. CLIENT LIST - Specific styles
       ==================================================================== */
    
    .mobile-client-card {
        position: relative;
    }
    
    .mobile-client-card .client-name {
        font-size: 17px;
        font-weight: 700;
        color: #1f2937;
        margin-bottom: 8px;
    }
    
    .mobile-client-card .client-revenue {
        font-size: 20px;
        font-weight: 700;
        color: #059669;
        margin-bottom: 12px;
    }
    
    .mobile-client-card .client-info-grid {
        display: grid;
        grid-template-columns: 1fr 1fr;
        gap: 8px;
        margin-bottom: 12px;
    }
    
    .mobile-client-card .client-info-item {
        font-size: 13px;
    }
    
    .mobile-client-card .client-info-label {
        color: #6b7280;
        display: block;
        margin-bottom: 2px;
    }
    
    .mobile-client-card .client-info-value {
        color: #1f2937;
        font-weight: 600;
    }
    
    /* ====================================================================
       12. QUOTE LIST - Specific styles
       ==================================================================== */
    
    .mobile-quote-card {
        position: relative;
    }
    
    .mobile-quote-card .quote-number {
        font-size: 14px;
        font-weight: 600;
        color: #6b7280;
        margin-bottom: 4px;
    }
    
    .mobile-quote-card .quote-client {
        font-size: 17px;
        font-weight: 700;
        color: #1f2937;
        margin-bottom: 8px;
    }
    
    .mobile-quote-card .quote-amount {
        font-size: 24px;
        font-weight: 700;
        color: #2563eb;
        margin-bottom: 12px;
    }
    
    .mobile-quote-card .quote-meta {
        display: flex;
        justify-content: space-between;
        font-size: 13px;
        color: #6b7280;
        margin-bottom: 12px;
    }
    
    /* ====================================================================
       13. TASK LIST - Specific styles
       ==================================================================== */
    
    .mobile-task-card {
        display: flex;
        align-items: flex-start;
        gap: 12px;
        padding: 12px;
    }
    
    .mobile-task-checkbox {
        width: 28px;
        height: 28px;
        margin-top: 2px;
        flex-shrink: 0;
        cursor: pointer;
    }
    
    .mobile-task-content {
        flex: 1;
    }
    
    .mobile-task-title {
        font-size: 16px;
        font-weight: 600;
        color: #1f2937;
        margin-bottom: 6px;
        line-height: 1.4;
    }
    
    .mobile-task-card.completed .mobile-task-title {
        text-decoration: line-through;
        color: #9ca3af;
    }
    
    .mobile-task-meta {
        font-size: 13px;
        color: #6b7280;
        display: flex;
        flex-wrap: wrap;
        gap: 12px;
    }
    
    .mobile-task-priority {
        padding: 2px 8px;
        border-radius: 4px;
        font-size: 11px;
        font-weight: 600;
        text-transform: uppercase;
    }
    
    .mobile-task-priority.high {
        background: #fee2e2;
        color: #991b1b;
    }
    
    .mobile-task-priority.medium {
        background: #fef3c7;
        color: #92400e;
    }
    
    .mobile-task-priority.low {
        background: #dbeafe;
        color: #1e40af;
    }
    
    /* ====================================================================
       14. INVOICE LIST - Specific styles
       ==================================================================== */
    
    .mobile-invoice-card {
        position: relative;
    }
    
    .mobile-invoice-card .invoice-number {
        font-size: 14px;
        font-weight: 600;
        color: #6b7280;
        margin-bottom: 4px;
    }
    
    .mobile-invoice-card .invoice-client {
        font-size: 17px;
        font-weight: 700;
        color: #1f2937;
        margin-bottom: 8px;
    }
    
    .mobile-invoice-card .invoice-amount {
        font-size: 24px;
        font-weight: 700;
        color: #059669;
        margin-bottom: 12px;
    }
    
    .mobile-invoice-card .invoice-status-row {
        display: flex;
        justify-content: space-between;
        align-items: center;
        margin-bottom: 12px;
    }
    
    .mobile-invoice-card .invoice-due-date {
        font-size: 13px;
        color: #6b7280;
    }
    
    .mobile-invoice-card .invoice-due-date.overdue {
        color: #dc2626;
        font-weight: 600;
    }
    
    /* ====================================================================
       15. STICKY HEADERS - List sections
       ==================================================================== */
    
    .mobile-list-section-header {
        position: sticky;
        top: 0;
        z-index: 50;
        background: #f3f4f6;
        padding: 8px 16px;
        font-size: 13px;
        font-weight: 700;
        color: #6b7280;
        text-transform: uppercase;
        letter-spacing: 0.5px;
        border-top: 1px solid #e5e7eb;
        border-bottom: 1px solid #e5e7eb;
    }
    
    /* ====================================================================
       16. SKELETON LOADING - While fetching data
       ==================================================================== */
    
    .mobile-card-skeleton {
        background: white;
        border-radius: 12px;
        padding: 16px;
        margin-bottom: 12px;
        animation: pulse 1.5s ease-in-out infinite;
    }
    
    .skeleton-line {
        height: 16px;
        background: linear-gradient(90deg, #e5e7eb 25%, #f3f4f6 50%, #e5e7eb 75%);
        background-size: 200% 100%;
        animation: shimmer 1.5s ease-in-out infinite;
        border-radius: 4px;
        margin-bottom: 8px;
    }
    
    .skeleton-line.title {
        height: 20px;
        width: 70%;
        margin-bottom: 12px;
    }
    
    .skeleton-line.short {
        width: 40%;
    }
    
    @keyframes shimmer {
        0% { background-position: 200% 0; }
        100% { background-position: -200% 0; }
    }
    
    @keyframes pulse {
        0%, 100% { opacity: 1; }
        50% { opacity: 0.7; }
    }
}

/* ========================================================================
   DESKTOP - Show tables, hide cards
   ======================================================================== */

@media (min-width: 768px) {
    
    /* Show tables on desktop */
    .table-responsive-mobile {
        display: table !important;
    }
    
    /* Hide card layout on desktop */
    .card-layout-mobile {
        display: none !important;
    }
    
    /* Hide mobile-specific elements */
    .mobile-list-card,
    .mobile-lead-card,
    .mobile-client-card,
    .mobile-quote-card,
    .mobile-task-card,
    .mobile-invoice-card,
    .mobile-search-bar,
    .mobile-sort-bar,
    .mobile-load-more,
    .swipe-hint {
        display: none !important;
    }
}
