/* ============================================================
   Modeer - Mobile-First Responsive Design
   Bottom Navigation Pattern for SaaS Dashboard
   ============================================================ */

/* ================== Base Mobile Styles ================== */

html {
    font-size: 16px;
    -webkit-text-size-adjust: 100%;
    overflow-x: hidden;
}

body {
    min-height: 100vh;
    min-height: 100dvh;
    overflow-x: hidden;
    overflow-y: auto;
    overscroll-behavior: auto;
    -webkit-overflow-scrolling: touch;
}

/* ================== Bottom Navigation (Mobile) - Modern SaaS Style ================== */

.mobile-bottom-nav {
    display: none;
    position: fixed;
    bottom: 0;
    left: 0;
    right: 0;
    height: 64px;
    background: var(--bg-surface);
    border-top: 1px solid var(--border-subtle);
    border-radius: 20px 20px 0 0;
    z-index: 99999;
    padding: 0 8px;
    padding-bottom: env(safe-area-inset-bottom, 8px);
    box-shadow: 0 -2px 12px rgba(0, 0, 0, 0.06);
    -webkit-backdrop-filter: blur(10px);
    backdrop-filter: blur(10px);
}

.mobile-bottom-nav-inner {
    display: flex;
    justify-content: space-between;
    align-items: center;
    height: 100%;
    gap: 4px;
    max-width: 100%;
}

.mobile-bottom-nav-btn {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    flex: 1;
    min-width: 0;
    padding: 6px 4px;
    background: transparent;
    border: none;
    border-radius: 14px;
    cursor: pointer;
    transition: all 0.2s cubic-bezier(0.4, 0, 0.2, 1);
    color: var(--text-muted);
    -webkit-tap-highlight-color: transparent;
    outline: none;
}

.mobile-bottom-nav-btn i {
    font-size: 18px;
    margin-bottom: 2px;
    transition: transform 0.2s ease;
}

.mobile-bottom-nav-btn span {
    font-size: 10px;
    line-height: 1.2;
    white-space: nowrap;
    font-weight: 500;
    transition: all 0.2s ease;
}

.mobile-bottom-nav-btn.active {
    color: var(--modeer-indigo);
    background: rgba(99, 102, 241, 0.08);
}

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

.mobile-bottom-nav-btn.active span {
    font-weight: 600;
}

.mobile-bottom-nav-btn:active {
    transform: scale(0.96);
}

.mobile-bottom-nav-btn:focus {
    outline: none;
    box-shadow: none;
}

.mobile-bottom-nav-btn::-moz-focus-inner {
    border: none;
}

/* Show bottom nav only on mobile - handled in unified media query below */

/* ================== Mobile Page Layout ================== */

.mobile-page {
    padding: 15px;
    min-height: 100vh;
}

.mobile-page-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 20px;
}

.mobile-page-title {
    font-size: 22px;
    font-weight: 700;
    color: var(--text-primary);
}

/* ================== Mobile Cards ================== */

.mobile-card {
    background: var(--bg-surface);
    border: 1px solid var(--border-subtle);
    border-radius: var(--radius-lg);
    padding: 16px;
    margin-bottom: 12px;
    transition: transform 0.2s, box-shadow 0.2s;
}

.mobile-card:active {
    transform: scale(0.98);
}

.mobile-card-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 12px;
}

.mobile-card-title {
    font-size: 16px;
    font-weight: 600;
    color: var(--text-primary);
}

.mobile-card-badge {
    font-size: 11px;
    padding: 4px 8px;
    border-radius: var(--radius-xs);
    font-weight: 600;
}

.mobile-card-badge.success {
    background: rgba(16, 185, 129, 0.15);
    color: #10B981;
}

.mobile-card-badge.warning {
    background: rgba(245, 158, 11, 0.15);
    color: #F59E0B;
}

.mobile-card-badge.danger {
    background: rgba(239, 68, 68, 0.15);
    color: #EF4444;
}

.mobile-card-body {
    font-size: 14px;
    color: var(--text-secondary);
}

.mobile-card-footer {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-top: 12px;
    padding-top: 12px;
    border-top: 1px solid var(--border-subtle);
}

/* ================== Mobile Stats Grid ================== */

.mobile-stats-grid {
    display: grid;
    grid-template-columns: repeat(2, 1fr);
    gap: 12px;
    margin-bottom: 20px;
}

.mobile-stat-card {
    background: var(--bg-surface);
    border: 1px solid var(--border-subtle);
    border-radius: var(--radius-md);
    padding: 16px;
    text-align: center;
}

.mobile-stat-value {
    font-size: 24px;
    font-weight: 700;
    color: var(--modeer-indigo);
    margin-bottom: 4px;
}

.mobile-stat-label {
    font-size: 12px;
    color: var(--text-muted);
}

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

/* ================== Mobile List Items ================== */

.mobile-list {
    background: var(--bg-surface);
    border-radius: var(--radius-lg);
    overflow: hidden;
    border: 1px solid var(--border-subtle);
}

.mobile-list-item {
    display: flex;
    align-items: center;
    padding: 14px 16px;
    border-bottom: 1px solid var(--border-subtle);
    transition: background 0.2s;
}

.mobile-list-item:last-child {
    border-bottom: none;
}

.mobile-list-item:active {
    background: var(--bg-surface-2);
}

.mobile-list-item-icon {
    width: 40px;
    height: 40px;
    border-radius: var(--radius-md);
    display: flex;
    align-items: center;
    justify-content: center;
    margin-left: 12px;
    font-size: 16px;
    flex-shrink: 0;
}

.mobile-list-item-content {
    flex: 1;
    min-width: 0;
}

.mobile-list-item-title {
    font-size: 14px;
    font-weight: 600;
    color: var(--text-primary);
    margin-bottom: 2px;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.mobile-list-item-subtitle {
    font-size: 12px;
    color: var(--text-muted);
}

.mobile-list-item-action {
    margin-right: 8px;
    color: var(--modeer-indigo);
    font-size: 18px;
}

/* ================== Mobile Quick Actions ================== */

.mobile-quick-actions {
    display: grid;
    grid-template-columns: repeat(4, 1fr);
    gap: 10px;
    margin-bottom: 20px;
}

.mobile-quick-action {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    padding: 12px 8px;
    background: var(--bg-surface);
    border: 1px solid var(--border-subtle);
    border-radius: var(--radius-md);
    cursor: pointer;
    transition: all 0.2s;
}

.mobile-quick-action:active {
    transform: scale(0.95);
    background: var(--modeer-indigo-soft);
}

.mobile-quick-action i {
    font-size: 20px;
    color: var(--modeer-indigo);
    margin-bottom: 6px;
}

.mobile-quick-action span {
    font-size: 10px;
    color: var(--text-secondary);
    text-align: center;
}

@media (max-width: 375px) {
    .mobile-quick-actions {
        grid-template-columns: repeat(2, 1fr);
    }
}

/* ================== Mobile Tables (Converted to Cards) ================== */

.mobile-table-card {
    background: var(--bg-surface);
    border: 1px solid var(--border-subtle);
    border-radius: var(--radius-md);
    padding: 0;
    margin-bottom: 10px;
    overflow: hidden;
}

.mobile-table-card-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 12px 16px;
    background: var(--bg-surface-2);
    border-bottom: 1px solid var(--border-subtle);
}

.mobile-table-card-title {
    font-size: 14px;
    font-weight: 600;
    color: var(--text-primary);
}

.mobile-table-card-row {
    display: flex;
    justify-content: space-between;
    padding: 10px 16px;
    border-bottom: 1px solid var(--border-subtle);
}

.mobile-table-card-row:last-child {
    border-bottom: none;
}

.mobile-table-card-label {
    font-size: 13px;
    color: var(--text-muted);
}

.mobile-table-card-value {
    font-size: 13px;
    font-weight: 500;
    color: var(--text-primary);
    text-align: left;
}

/* Hide desktop table on mobile - handled in unified media query below */

.mobile-table-view {
    display: none;
}

/* ================== Mobile Search & Filter ================== */

.mobile-search {
    position: relative;
    margin-bottom: 16px;
}

.mobile-search-input {
    width: 100%;
    padding: 12px 16px 12px 44px;
    border: 1px solid var(--border-subtle);
    border-radius: var(--radius-md);
    font-size: 14px;
    background: var(--bg-surface);
    color: var(--text-primary);
}

.mobile-search-input:focus {
    outline: none;
    border-color: var(--modeer-indigo);
}

.mobile-search-icon {
    position: absolute;
    right: 14px;
    top: 50%;
    transform: translateY(-50%);
    color: var(--text-muted);
    font-size: 16px;
}

.mobile-filters {
    display: flex;
    gap: 8px;
    overflow-x: auto;
    padding-bottom: 12px;
    margin-bottom: 16px;
    -webkit-overflow-scrolling: touch;
}

.mobile-filter-chip {
    padding: 8px 16px;
    background: var(--bg-surface);
    border: 1px solid var(--border-subtle);
    border-radius: var(--radius-full);
    font-size: 12px;
    white-space: nowrap;
    cursor: pointer;
    transition: all 0.2s;
}

.mobile-filter-chip.active {
    background: var(--modeer-indigo);
    color: white;
    border-color: var(--modeer-indigo);
}

/* ================== Mobile FAB (Floating Action Button) ================== */

.mobile-fab {
    display: none;
    position: fixed;
    bottom: 85px;
    left: 20px;
    width: 56px;
    height: 56px;
    border-radius: 50%;
    background: var(--modeer-gradient);
    color: white;
    font-size: 24px;
    border: none;
    box-shadow: 0 4px 20px rgba(99, 102, 241, 0.4);
    z-index: 999;
    cursor: pointer;
    transition: transform 0.2s, box-shadow 0.2s;
}

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

/* FAB display - handled in unified media query below */

/* ================== Mobile Modal ================== */

.mobile-modal {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(0,0,0,0.5);
    z-index: 2000;
    display: none;
    align-items: flex-end;
}

.mobile-modal.active {
    display: flex;
}

.mobile-modal-content {
    background: var(--bg-surface);
    width: 100%;
    max-height: 90vh;
    border-radius: var(--radius-xl) var(--radius-xl) 0 0;
    padding: 20px;
    overflow-y: auto;
    animation: mobileSlideUp 0.3s ease;
}

@keyframes mobileSlideUp {
    from { transform: translateY(100%); }
    to { transform: translateY(0); }
}

.mobile-modal-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 20px;
}

.mobile-modal-title {
    font-size: 18px;
    font-weight: 600;
}

.mobile-modal-close {
    width: 32px;
    height: 32px;
    border-radius: 50%;
    background: var(--bg-surface-2);
    border: none;
    font-size: 18px;
    cursor: pointer;
}

/* ================== Mobile Empty State ================== */

.mobile-empty {
    text-align: center;
    padding: 40px 20px;
}

.mobile-empty-icon {
    font-size: 48px;
    color: var(--text-muted);
    opacity: 0.5;
    margin-bottom: 16px;
}

.mobile-empty-title {
    font-size: 16px;
    font-weight: 600;
    color: var(--text-primary);
    margin-bottom: 8px;
}

.mobile-empty-text {
    font-size: 13px;
    color: var(--text-muted);
    margin-bottom: 20px;
}

.mobile-empty-action {
    padding: 12px 24px;
    background: var(--modeer-gradient);
    color: white;
    border: none;
    border-radius: var(--radius-md);
    font-size: 14px;
    font-weight: 600;
    cursor: pointer;
}

/* ================== Swipe to Delete ================== */

.swipe-action {
    position: relative;
    overflow: hidden;
}

.swipe-content {
    transition: transform 0.3s;
}

.swipe-delete {
    position: absolute;
    top: 0;
    bottom: 0;
    left: 0;
    width: 80px;
    background: #EF4444;
    display: flex;
    align-items: center;
    justify-content: center;
    color: white;
    font-size: 20px;
    transform: translateX(-100%);
    transition: transform 0.3s;
}

.swipe-action.swiped .swipe-delete {
    transform: translateX(0);
}

/* ================== Pull to Refresh ================== */

.pull-to-refresh {
    position: relative;
    overflow: hidden;
}

.pull-indicator {
    position: absolute;
    top: -50px;
    left: 0;
    right: 0;
    height: 50px;
    display: flex;
    align-items: center;
    justify-content: center;
    color: var(--text-muted);
    font-size: 14px;
    transition: top 0.3s;
}

.pull-to-refresh.refreshing .pull-indicator {
    top: 0;
}

/* ================== Skeleton Loading ================== */

.mobile-skeleton {
    background: linear-gradient(90deg, var(--bg-surface-2) 25%, var(--bg-surface) 50%, var(--bg-surface-2) 75%);
    background-size: 200% 100%;
    animation: skeleton 1.5s infinite;
    border-radius: var(--radius-sm);
}

.mobile-skeleton-text {
    height: 16px;
    margin-bottom: 8px;
}

.mobile-skeleton-title {
    height: 24px;
    width: 60%;
    margin-bottom: 12px;
}

.mobile-skeleton-circle {
    width: 40px;
    height: 40px;
    border-radius: 50%;
}

/* ================== iOS Safe Area ================== */

@supports (padding: max(0px)) {
    .mobile-bottom-nav {
        padding-bottom: max(10px, env(safe-area-inset-bottom));
    }
    
    .app-topbar {
        padding-top: max(12px, env(safe-area-inset-top));
    }
}

/* ================== Landscape Mobile ================== */

@media (orientation: landscape) and (max-height: 500px) {
    .mobile-bottom-nav {
        height: 50px;
    }
    
    .mobile-bottom-nav-link i {
        font-size: 16px;
    }
    
    .mobile-bottom-nav-link span {
        display: none;
    }
    
    .mobile-page {
        padding: 10px;
    }
}

/* ==================== UNIFIED MOBILE LAYOUT (@media max-width: 991px) ==================== */
@media (max-width: 991px) {
    /* ===== SCROLL FIX ===== */
    html {
        overflow-x: hidden;
        overflow-y: auto;
    }
    
    body {
        overflow-x: hidden;
        overflow-y: auto;
        -webkit-overflow-scrolling: touch;
        padding-bottom: 0;
    }
    
    .app-main,
    .app-content,
    .page-content,
    #pageContent {
        overflow: visible;
        height: auto;
        max-height: none;
        margin-left: 0 !important;
        padding-bottom: calc(85px + env(safe-area-inset-bottom, 0px));
    }
    
    /* ===== SHOW MOBILE ELEMENTS ===== */
    .mobile-bottom-nav {
        display: block;
    }
    
    /* FAB removed - ensure it stays hidden */
    .mobile-fab {
        display: none !important;
    }
    
    /* Hide desktop elements */
    .app-sidebar {
        display: none !important;
    }
    
    /* Hide hamburger menu */
    .mobile-menu-toggle,
    .sidebar-toggler,
    #sidebarToggler {
        display: none !important;
    }
    
    .desktop-table {
        display: none !important;
    }
    
    .mobile-table-view {
        display: block !important;
    }
    
    /* ===== Z-INDEX STACKING ===== */
    .app-topbar {
        z-index: 1000;
        position: sticky;
        top: 0;
        padding: 12px 15px;
    }
    
    .mobile-bottom-nav {
        z-index: 1001;
        height: 64px;
        border-radius: 20px 20px 0 0;
        padding: 0 6px;
        padding-bottom: env(safe-area-inset-bottom, 8px);
    }
    
    .mobile-fab {
        z-index: 1002;
        width: 52px;
        height: 52px;
        left: 16px;
        bottom: calc(80px + env(safe-area-inset-bottom, 0px));
    }
    
    /* Bootstrap Modal z-index: 1050+, ensure nav doesn't overlap */
    .modal {
        z-index: 1055;
    }
    
    .modal-backdrop {
        z-index: 1050;
    }
    
    /* ===== BOTTOM NAV BUTTONS ===== */
    .mobile-bottom-nav-inner {
        height: 100%;
        gap: 2px;
    }
    
    .mobile-bottom-nav-btn {
        min-height: 48px;
        padding: 6px 3px;
        border-radius: 12px;
    }
    
    .mobile-bottom-nav-btn i {
        font-size: 18px;
        margin-bottom: 2px;
    }
    
    .mobile-bottom-nav-btn span {
        font-size: 10px;
        line-height: 1.2;
    }
    
    .mobile-bottom-nav-btn:active {
        transform: scale(0.96);
    }
    
    /* ===== FAB ===== */
    .mobile-fab i {
        font-size: 22px;
    }
    
    /* ===== MODAL CONFLICT FIX ===== */
    body.modal-open .mobile-fab {
        display: none !important;
    }
    
    body.modal-open .mobile-bottom-nav {
        z-index: 1001;
    }
    
    .modal-dialog {
        margin: 0;
        position: fixed;
        left: 0;
        right: 0;
        bottom: 0;
        max-width: 100%;
    }
    
    .modal-content {
        border-radius: 20px 20px 0 0;
        max-height: 75vh;
    }
    
    .modal-body {
        max-height: 65vh;
        overflow-y: auto;
        padding: 16px;
    }
    
    /* ===== CARD PADDING ===== */
    .card,
    .mobile-card,
    .surface-card,
    .info-box,
    .section-card,
    .stats-card,
    .stat-card {
        padding: 14px;
        margin-bottom: 10px;
        border-radius: 14px;
    }
    
    /* ===== BUTTONS ===== */
    .btn-lg,
    .hero-btn,
    .primary-action-btn,
    .btn-primary,
    .btn-success,
    .btn-info,
    .btn-add {
        min-height: 44px;
        padding: 10px 16px;
        font-size: 14px;
        border-radius: 12px;
    }
    
    .action-buttons .btn,
    .subscription-actions .btn,
    .customer-card-actions .btn,
    .btn-sm {
        min-height: 38px;
        padding: 8px 12px;
        font-size: 13px;
        border-radius: 10px;
    }
    
    /* ===== STATS CARDS ===== */
    .stat-value {
        font-size: 20px;
    }
    
    .stat-label {
        font-size: 11px;
    }
    
    /* ===== LIST ITEMS ===== */
    .list-group-item,
    .customer-row,
    .subscription-row,
    .message-row {
        padding: 12px;
        min-height: 60px;
    }
    
    /* ===== SEARCH INPUT ===== */
    .search-container input,
    #searchInput,
    .form-control {
        padding: 12px 14px 12px 38px;
        font-size: 14px;
        border-radius: 12px;
    }
    
    /* ===== FILTER CHIPS ===== */
    .filter-btn,
    .filter-chip,
    .chip {
        padding: 8px 14px;
        font-size: 12px;
        border-radius: 20px;
    }
    
    /* ===== QUICK ACTIONS ===== */
    .quick-actions {
        gap: 8px;
    }
    
    .quick-action-btn {
        padding: 10px 12px;
        font-size: 12px;
        border-radius: 10px;
    }
    
    /* ===== SECTION PADDING ===== */
    .page-section,
    .dashboard-section,
    .content-section {
        padding: 14px;
        margin-bottom: 14px;
    }
    
    .page-header,
    .section-header {
        padding: 12px 0;
        margin-bottom: 12px;
    }
    
    /* ===== TABLE ===== */
    .table-responsive {
        margin-bottom: 14px;
    }
    
    /* ===== REVENUE ===== */
    .revenue-summary {
        padding: 14px;
    }
    
    .revenue-amount {
        font-size: 22px;
    }
    
    /* ===== GLASS BUTTONS FIX ===== */
    .glass-btn-lg,
    .glass-btn {
        padding: 10px 16px !important;
        font-size: 14px !important;
        border-radius: 12px !important;
        width: 100% !important;
        min-height: 44px !important;
    }
    
    /* ===== ACTION BUTTONS CONTAINER FIX ===== */
    .bg-light-alt.d-flex.justify-content-between,
    .d-flex.justify-content-between.align-items-center.mb-3.p-3.bg-light-alt,
    [class*="bg-light-alt"] {
        flex-direction: column !important;
        width: 100% !important;
        gap: 8px !important;
        text-align: center !important;
    }
    
    /* Remove side margins from buttons in flex containers */
    .bg-light-alt .btn,
    .bg-light-alt .glass-btn,
    .bg-light-alt .glass-btn-lg {
        margin-left: 0 !important;
        margin-right: 0 !important;
    }
    
    /* Ensure profit/summary text is centered above buttons */
    .bg-light-alt .fs-5,
    .bg-light-alt .fw-bold,
    .revenue-summary .fs-5 {
        text-align: center !important;
        width: 100% !important;
    }
    
    /* ===== TOP HEADER ACTION BUTTONS FIX ===== */
    /* Target top header containers */
    .container > .d-flex.justify-content-between.mb-4,
    .container > .d-flex.justify-content-center.mb-4,
    .bg-light-alt.d-flex {
        flex-direction: column !important;
        align-items: stretch !important;
        gap: 12px !important;
    }
    
    /* Target inner button wrappers */
    .container > .d-flex.mb-4 > div,
    .container > .d-flex.justify-content-between.mb-4 > div,
    .bg-light-alt > div {
        display: flex !important;
        flex-direction: column !important;
        width: 100% !important;
        gap: 8px !important;
    }
    
    /* Standardize all action buttons */
    .container > .d-flex .btn,
    .container > .d-flex .glass-btn,
    .container > .d-flex .glass-btn-lg,
    .bg-light-alt .btn,
    .bg-light-alt .glass-btn,
    .bg-light-alt .glass-btn-lg {
        width: 100% !important;
        margin: 0 !important;
        min-height: 44px !important;
        display: flex !important;
        justify-content: center !important;
        align-items: center !important;
    }
    
    /* Fix page header/title layout */
    .page-header,
    .page-header.d-flex,
    .container > .d-flex.justify-content-between:first-child {
        flex-direction: column !important;
        align-items: center !important;
        gap: 12px !important;
        text-align: center !important;
    }
    
    .page-header h2,
    .page-header .fs-4 {
        text-align: center !important;
        width: 100% !important;
    }
}

/* ==================== Small Screens (≤375px) ==================== */
@media (max-width: 375px) {
    .mobile-bottom-nav {
        padding: 0 4px !important;
    }
    
    .mobile-bottom-nav-btn {
        padding: 5px 2px !important;
    }
    
    .mobile-bottom-nav-btn i {
        font-size: 17px !important;
    }
    
    .mobile-bottom-nav-btn span {
        font-size: 9px !important;
    }
    
    .mobile-bottom-nav-btn.active {
        background: rgba(99, 102, 241, 0.1) !important;
    }
}