/* =====================================================
   CRM PRO - MOBILE RESPONSIVE STYLES
   Bottom Navigation, FAB, Touch-friendly UI
   ===================================================== */

/* === CSS Variables for Mobile === */
:root {
    --bottom-nav-height: 64px;
    --fab-size: 56px;
    --fab-bottom: 80px;
    --touch-min-size: 44px;
}

/* =====================================================
   BOTTOM NAVIGATION BAR
   ===================================================== */
.bottom-nav {
    display: none;
    position: fixed;
    bottom: 0;
    left: 0;
    right: 0;
    height: var(--bottom-nav-height);
    background: var(--bg-primary);
    border-top: 1px solid var(--border-color-light);
    z-index: var(--z-sticky);
    padding: 0 var(--spacing-2);
    padding-bottom: env(safe-area-inset-bottom, 0);
}

.bottom-nav-items {
    display: flex;
    justify-content: space-around;
    align-items: center;
    height: 100%;
}

.bottom-nav-item {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    padding: var(--spacing-2);
    min-width: var(--touch-min-size);
    min-height: var(--touch-min-size);
    color: var(--text-secondary);
    text-decoration: none;
    border-radius: var(--radius-lg);
    transition: all var(--transition-fast);
    -webkit-tap-highlight-color: transparent;
}

.bottom-nav-item i {
    font-size: 1.25rem;
    margin-bottom: 2px;
}

.bottom-nav-item span {
    font-size: 10px;
    font-weight: var(--font-weight-medium);
}

.bottom-nav-item.active {
    color: var(--primary-600);
}

.bottom-nav-item.active i {
    transform: scale(1.1);
}

.bottom-nav-item:active {
    background: var(--bg-hover);
    transform: scale(0.95);
}

/* =====================================================
   FLOATING ACTION BUTTON (FAB)
   ===================================================== */
.fab {
    display: none;
    position: fixed;
    right: var(--spacing-4);
    bottom: var(--fab-bottom);
    width: var(--fab-size);
    height: var(--fab-size);
    border-radius: var(--radius-full);
    background: linear-gradient(135deg, var(--primary-500), var(--purple-500));
    color: white;
    box-shadow: var(--shadow-lg), 0 4px 20px rgba(99, 102, 241, 0.4);
    align-items: center;
    justify-content: center;
    cursor: pointer;
    z-index: var(--z-sticky);
    transition: all var(--transition-fast);
    -webkit-tap-highlight-color: transparent;
}

.fab i {
    font-size: 1.5rem;
}

.fab:hover {
    transform: scale(1.05);
    box-shadow: var(--shadow-xl), 0 6px 30px rgba(99, 102, 241, 0.5);
}

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

/* FAB Ripple Effect */
.fab::after {
    content: '';
    position: absolute;
    inset: 0;
    border-radius: inherit;
    background: white;
    opacity: 0;
    transition: opacity 0.3s;
}

.fab:active::after {
    opacity: 0.2;
}

/* =====================================================
   MOBILE HEADER (Simplified)
   ===================================================== */
@media (max-width: 768px) {
    .main-header {
        height: 56px;
        padding: 0 var(--spacing-3);
    }

    .page-title {
        font-size: var(--font-size-lg);
    }

    /* Hide desktop add button on mobile */
    .header-right #addNewBtn {
        display: none;
    }
}

/* =====================================================
   TOUCH-OPTIMIZED ELEMENTS
   ===================================================== */
@media (max-width: 768px) {

    /* Buttons - minimum touch target */
    .btn {
        min-height: var(--touch-min-size);
        padding: var(--spacing-3) var(--spacing-4);
    }

    .btn-icon {
        min-width: var(--touch-min-size);
        min-height: var(--touch-min-size);
    }

    /* Form inputs */
    .form-input,
    .form-select,
    .form-textarea {
        min-height: var(--touch-min-size);
        font-size: 16px;
        /* Prevents iOS zoom on focus */
    }

    /* Table rows */
    .data-table tbody tr {
        min-height: var(--touch-min-size);
    }

    .data-table td {
        padding: var(--spacing-3) var(--spacing-2);
    }

    /* Cards */
    .stat-card,
    .card {
        min-height: var(--touch-min-size);
    }
}

/* =====================================================
   MOBILE CARD VIEW (Instead of Table)
   ===================================================== */
.mobile-card-view {
    display: none;
}

@media (max-width: 768px) {
    .mobile-card-view {
        display: block;
    }

    .data-table-wrapper {
        display: none;
    }
}

.mobile-card {
    background: var(--bg-primary);
    border: 1px solid var(--border-color-light);
    border-radius: var(--radius-xl);
    padding: var(--spacing-4);
    margin-bottom: var(--spacing-3);
    transition: all var(--transition-fast);
}

.mobile-card:active {
    transform: scale(0.98);
    background: var(--bg-hover);
}

.mobile-card-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: var(--spacing-3);
}

.mobile-card-title {
    font-weight: var(--font-weight-semibold);
    color: var(--text-primary);
    font-size: var(--font-size-base);
}

.mobile-card-subtitle {
    font-size: var(--font-size-sm);
    color: var(--text-secondary);
    margin-top: 2px;
}

.mobile-card-body {
    display: flex;
    flex-direction: column;
    gap: var(--spacing-2);
}

.mobile-card-row {
    display: flex;
    justify-content: space-between;
    align-items: center;
    font-size: var(--font-size-sm);
}

.mobile-card-label {
    color: var(--text-secondary);
}

.mobile-card-value {
    color: var(--text-primary);
    font-weight: var(--font-weight-medium);
}

.mobile-card-actions {
    display: flex;
    justify-content: flex-end;
    gap: var(--spacing-2);
    margin-top: var(--spacing-3);
    padding-top: var(--spacing-3);
    border-top: 1px solid var(--border-color-light);
}

/* =====================================================
   DESKTOP/MOBILE VISIBILITY
   ===================================================== */
.desktop-only {
    display: flex;
}

.desktop-table {
    display: block;
}

.mobile-cards {
    display: none;
}

/* Force hide desktop elements on mobile */
@media screen and (max-width: 768px) {

    /* Hide all desktop-specific elements */
    .desktop-only {
        display: none !important;
        visibility: hidden !important;
    }

    .desktop-table {
        display: none !important;
        visibility: hidden !important;
    }

    /* Hide tables globally on mobile */
    table.table,
    .table,
    .table-container,
    thead,
    tbody,
    tr,
    th,
    td {
        display: none !important;
    }

    /* Hide pipeline on mobile */
    .pipeline-container {
        display: none !important;
    }

    /* Show mobile cards */
    .mobile-cards {
        display: block !important;
        visibility: visible !important;
    }

    .mobile-card {
        display: block !important;
        visibility: visible !important;
    }

    /* Ensure proper spacing for mobile cards container */
    .mobile-cards {
        padding: 0;
        margin: 0;
    }
}

/* =====================================================
   MODAL MOBILE OPTIMIZATIONS
   ===================================================== */
@media (max-width: 768px) {
    .modal {
        width: 100%;
        max-width: 100%;
        height: auto;
        max-height: 90vh;
        border-radius: var(--radius-xl) var(--radius-xl) 0 0;
        margin: 0;
        position: fixed;
        bottom: 0;
        left: 0;
        right: 0;
        animation: slideUpModal 0.3s ease;
    }

    .modal-body {
        max-height: 60vh;
        overflow-y: auto;
    }

    .modal-footer {
        padding: var(--spacing-4);
        padding-bottom: calc(var(--spacing-4) + env(safe-area-inset-bottom, 0));
    }
}

@keyframes slideUpModal {
    from {
        transform: translateY(100%);
    }

    to {
        transform: translateY(0);
    }
}

/* =====================================================
   RESPONSIVE CONTENT PADDING
   ===================================================== */
@media (max-width: 768px) {
    .page-container {
        padding: var(--spacing-3);
        padding-bottom: calc(var(--spacing-3) + var(--bottom-nav-height));
    }

    .stats-grid {
        grid-template-columns: repeat(2, 1fr);
        gap: var(--spacing-3);
    }

    .stat-card {
        padding: var(--spacing-3);
    }

    .stat-card h3 {
        font-size: var(--font-size-xl);
    }
}

@media (max-width: 480px) {
    .stats-grid {
        grid-template-columns: 1fr;
    }
}

/* =====================================================
   SHOW MOBILE ELEMENTS
   ===================================================== */
@media (max-width: 768px) {
    .bottom-nav {
        display: block;
    }

    .fab {
        display: flex;
    }

    /* Hide desktop sidebar */
    .sidebar {
        transform: translateX(-100%);
    }

    .sidebar.mobile-open {
        transform: translateX(0);
        box-shadow: var(--shadow-xl);
    }
}

/* =====================================================
   DARK MODE MOBILE ADJUSTMENTS
   ===================================================== */
[data-theme="dark"] .bottom-nav {
    background: var(--gray-900);
    border-color: var(--gray-700);
}

[data-theme="dark"] .mobile-card {
    background: var(--gray-800);
    border-color: var(--gray-700);
}

[data-theme="dark"] .modal {
    background: var(--gray-800);
}

/* =====================================================
   SWIPE GESTURE HINTS
   ===================================================== */
.swipe-hint {
    display: none;
    text-align: center;
    padding: var(--spacing-2);
    color: var(--text-secondary);
    font-size: var(--font-size-xs);
}

@media (max-width: 768px) {
    .swipe-hint {
        display: block;
    }
}

/* =====================================================
   PULL TO REFRESH INDICATOR
   ===================================================== */
.pull-refresh {
    display: none;
    text-align: center;
    padding: var(--spacing-4);
    color: var(--text-secondary);
}

.pull-refresh.visible {
    display: block;
}

.pull-refresh-icon {
    animation: spin 1s linear infinite;
}