/* =============================================
   Mobile CSS - Mobile-First Improvements
   ============================================= */

/* Bottom Navigation Bar (Mobile Only) */
.bottom-nav {
    display: none;
    position: fixed;
    bottom: 0;
    left: 0;
    right: 0;
    background: white;
    border-top: 2px solid #e0e0e0;
    padding: 0.5rem 0;
    z-index: 1050;
    box-shadow: 0 -4px 12px rgba(0, 0, 0, 0.1);
}

.bottom-nav-items {
    display: flex;
    justify-content: space-around;
    align-items: center;
    max-width: 100%;
    margin: 0 auto;
}

.bottom-nav-item {
    display: flex;
    flex-direction: column;
    align-items: center;
    text-decoration: none;
    color: #7f8c8d;
    font-size: 0.7rem;
    font-weight: 600;
    padding: 0.25rem 0.5rem;
    transition: all var(--transition-base);
    position: relative;
    flex: 1;
    min-width: 0;
}

.bottom-nav-item i {
    font-size: 1.5rem;
    margin-bottom: 0.25rem;
    transition: all var(--transition-base);
}

.bottom-nav-item span {
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    max-width: 100%;
}

.bottom-nav-item:hover,
.bottom-nav-item:focus {
    color: var(--primary-color);
    text-decoration: none;
}

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

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

.bottom-nav-item.active::before {
    content: '';
    position: absolute;
    top: -2px;
    left: 50%;
    transform: translateX(-50%);
    width: 30px;
    height: 3px;
    background: var(--primary-color);
    border-radius: 0 0 3px 3px;
}

/* Show bottom nav on mobile */
@media (max-width: 768px) {
    .bottom-nav {
        display: block;
    }

    /* Add bottom padding to body to prevent content from being hidden */
    body {
        padding-bottom: 70px;
    }

    /* Hide desktop navbar on mobile */
    .navbar-collapse {
        display: none !important;
    }

    .navbar-toggler {
        display: none !important;
    }
}

/* Pull to Refresh Indicator */
.pull-to-refresh {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    height: 60px;
    display: flex;
    align-items: center;
    justify-content: center;
    background: linear-gradient(135deg, var(--primary-color) 0%, var(--primary-dark) 100%);
    color: white;
    transform: translateY(-100%);
    transition: transform var(--transition-base);
    z-index: 9999;
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.2);
}

.pull-to-refresh.visible {
    transform: translateY(0);
}

.pull-to-refresh .spinner-border {
    width: 1.5rem;
    height: 1.5rem;
    border-width: 3px;
    margin-right: 0.5rem;
}

/* Touch-Optimized Tables */
@media (max-width: 768px) {
    /* Compact table for mobile */
    .table-mobile th,
    .table-mobile td {
        padding: 0.5rem;
        font-size: 0.875rem;
    }

    /* Make tables horizontally scrollable */
    .table-responsive {
        position: relative;
        overflow-x: auto;
        -webkit-overflow-scrolling: touch;
    }

    /* Scroll indicator shadow */
    .table-responsive::after {
        content: '';
        position: absolute;
        right: 0;
        top: 0;
        bottom: 0;
        width: 20px;
        background: linear-gradient(to right, transparent, rgba(0, 0, 0, 0.1));
        pointer-events: none;
        opacity: 0.5;
    }

    /* Hide less important columns on mobile */
    .hide-mobile {
        display: none !important;
    }

    /* Stack cards vertically on mobile */
    .row.g-3 > [class*='col-'] {
        margin-bottom: 1rem;
    }
}

/* Swipeable Rows */
.swipe-row {
    position: relative;
    overflow: hidden;
    touch-action: pan-y;
}

.swipe-actions {
    position: absolute;
    right: 0;
    top: 0;
    bottom: 0;
    display: flex;
    transform: translateX(100%);
    transition: transform var(--transition-base);
    z-index: 1;
}

.swipe-row.open .swipe-actions {
    transform: translateX(0);
}

.swipe-action {
    padding: 1rem;
    color: white;
    display: flex;
    align-items: center;
    justify-content: center;
    min-width: 80px;
    cursor: pointer;
    font-weight: 600;
    transition: all var(--transition-fast);
}

.swipe-action:hover {
    filter: brightness(1.1);
}

.swipe-action.edit {
    background: linear-gradient(135deg, #3498db 0%, #2980b9 100%);
}

.swipe-action.delete {
    background: linear-gradient(135deg, #e74c3c 0%, #c0392b 100%);
}

.swipe-action i {
    font-size: 1.25rem;
}

/* Touch-Friendly Buttons */
@media (max-width: 768px) {
    .btn-mobile,
    .btn {
        padding: 0.75rem 1.5rem;
        font-size: 1rem;
        min-height: 44px;
        touch-action: manipulation;
    }

    .btn-sm {
        padding: 0.5rem 1rem;
        font-size: 0.875rem;
        min-height: 38px;
    }

    .btn-lg {
        padding: 1rem 2rem;
        font-size: 1.125rem;
        min-height: 52px;
    }
}

/* Larger Form Controls on Mobile */
@media (max-width: 768px) {
    .form-control,
    .form-select {
        padding: 0.75rem;
        font-size: 1rem;
        min-height: 44px;
    }

    .form-control-sm {
        padding: 0.5rem;
        font-size: 0.875rem;
        min-height: 38px;
    }

    .form-check-input {
        width: 1.5rem;
        height: 1.5rem;
    }
}

/* Mobile-Optimized Charts */
@media (max-width: 768px) {
    .chart-container {
        height: 250px !important;
    }

    .metric-card h3 {
        font-size: 1.5rem;
    }

    .metric-icon {
        width: 40px;
        height: 40px;
        font-size: 1.25rem;
    }
}

/* Mobile Card Stacking */
@media (max-width: 576px) {
    .card {
        margin-bottom: 1rem;
    }

    .card-body {
        padding: 1rem;
    }

    .card-header {
        padding: 0.75rem 1rem;
    }

    .card-header h5,
    .card-header h4 {
        font-size: 1rem;
    }
}

/* Mobile Typography */
@media (max-width: 768px) {
    h1 {
        font-size: 1.75rem;
    }

    h2 {
        font-size: 1.5rem;
    }

    h3 {
        font-size: 1.25rem;
    }

    h4 {
        font-size: 1.125rem;
    }

    h5 {
        font-size: 1rem;
    }
}

/* Mobile Navigation Improvements */
@media (max-width: 768px) {
    .navbar-brand {
        font-size: 1rem;
    }

    .navbar-brand i {
        font-size: 1.25rem;
    }

    /* Hide language and theme toggles on very small screens */
    @media (max-width: 576px) {
        .navbar .dropdown {
            display: none;
        }
    }
}

/* Touch Feedback */
@media (hover: none) {
    /* Add active state for touch devices */
    .btn:active,
    .nav-link:active,
    .bottom-nav-item:active {
        transform: scale(0.95);
        opacity: 0.8;
    }

    .card.hover-lift:active {
        transform: translateY(-2px);
    }
}

/* Mobile Modal Improvements */
@media (max-width: 768px) {
    .modal-dialog {
        margin: 0.5rem;
    }

    .modal-content {
        border-radius: 12px;
    }

    .modal-header,
    .modal-footer {
        padding: 1rem;
    }

    .modal-body {
        padding: 1rem;
    }
}

/* Mobile Dropdown Improvements */
@media (max-width: 768px) {
    .dropdown-menu {
        border-radius: 12px;
        box-shadow: 0 4px 12px rgba(0, 0, 0, 0.15);
    }

    .dropdown-item {
        padding: 0.75rem 1rem;
        font-size: 1rem;
    }
}

/* Mobile Table Enhancements */
@media (max-width: 768px) {
    /* Sticky table header */
    .table-responsive {
        max-height: calc(100vh - 200px);
        overflow-y: auto;
    }

    .table thead th {
        position: sticky;
        top: 0;
        background: white;
        z-index: 10;
        box-shadow: 0 2px 4px rgba(0, 0, 0, 0.1);
    }

    [data-bs-theme="dark"] .table thead th {
        background: #2c3e50;
    }

    /* Compact table padding */
    .table th,
    .table td {
        padding: 0.5rem;
        font-size: 0.875rem;
    }

    /* Horizontal scrolling indicator */
    .table-responsive::-webkit-scrollbar {
        height: 6px;
    }

    .table-responsive::-webkit-scrollbar-track {
        background: #f1f1f1;
        border-radius: 3px;
    }

    .table-responsive::-webkit-scrollbar-thumb {
        background: #888;
        border-radius: 3px;
    }

    .table-responsive::-webkit-scrollbar-thumb:hover {
        background: #555;
    }
}

/* Mobile Alert/Toast Position */
@media (max-width: 768px) {
    .alert,
    .toast {
        margin: 0.5rem;
        font-size: 0.875rem;
    }

    /* Position toasts above bottom nav */
    .toast-container {
        bottom: 80px !important;
    }
}

/* Mobile Spacing Adjustments */
@media (max-width: 768px) {
    .container-fluid {
        padding-left: 1rem;
        padding-right: 1rem;
    }

    .row {
        margin-left: -0.5rem;
        margin-right: -0.5rem;
    }

    .row > [class*='col-'] {
        padding-left: 0.5rem;
        padding-right: 0.5rem;
    }

    .mb-4 {
        margin-bottom: 1rem !important;
    }

    .mt-4 {
        margin-top: 1rem !important;
    }
}

/* Landscape Orientation Adjustments */
@media (max-width: 768px) and (orientation: landscape) {
    .bottom-nav {
        padding: 0.25rem 0;
    }

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

    .bottom-nav-item span {
        font-size: 0.65rem;
    }

    body {
        padding-bottom: 60px;
    }
}

/* Dark Mode Mobile Adjustments */
[data-bs-theme="dark"] .bottom-nav {
    background: #2c3e50;
    border-top-color: #34495e;
}

[data-bs-theme="dark"] .bottom-nav-item {
    color: #bdc3c7;
}

[data-bs-theme="dark"] .bottom-nav-item.active,
[data-bs-theme="dark"] .bottom-nav-item:hover {
    color: #3498db;
}

[data-bs-theme="dark"] .swipe-action.edit {
    background: linear-gradient(135deg, #2980b9 0%, #1f618d 100%);
}

[data-bs-theme="dark"] .swipe-action.delete {
    background: linear-gradient(135deg, #c0392b 0%, #a93226 100%);
}

/* Accessibility - Larger Touch Targets */
@media (max-width: 768px) {
    a,
    button,
    input[type="checkbox"],
    input[type="radio"],
    select {
        min-height: 44px;
        min-width: 44px;
    }

    /* Exception for inline elements */
    a.btn,
    button.btn {
        display: inline-flex;
        align-items: center;
        justify-content: center;
    }
}

/* Loading State for Mobile */
@media (max-width: 768px) {
    .spinner-overlay {
        background: rgba(0, 0, 0, 0.7);
    }

    .spinner-border {
        width: 3rem;
        height: 3rem;
    }
}

/* Mobile-Specific Utilities */
@media (max-width: 768px) {
    .mobile-hidden {
        display: none !important;
    }

    .mobile-only {
        display: block !important;
    }

    .mobile-full-width {
        width: 100% !important;
    }

    .mobile-text-center {
        text-align: center !important;
    }
}

/* Prevent Text Selection on Touch */
.no-select {
    -webkit-user-select: none;
    -moz-user-select: none;
    -ms-user-select: none;
    user-select: none;
}

/* Safe Area Insets for Notched Devices */
@supports (padding-top: env(safe-area-inset-top)) {
    body {
        padding-top: env(safe-area-inset-top);
    }

    .bottom-nav {
        padding-bottom: calc(0.5rem + env(safe-area-inset-bottom));
    }
}

/* Optimize for Very Small Screens */
@media (max-width: 375px) {
    .container-fluid {
        padding-left: 0.75rem;
        padding-right: 0.75rem;
    }

    .btn {
        font-size: 0.875rem;
        padding: 0.625rem 1.25rem;
    }

    .card-body {
        padding: 0.75rem;
    }

    h1 {
        font-size: 1.5rem;
    }

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

    .bottom-nav-item span {
        font-size: 0.65rem;
    }
}

/* Print Styles - Hide Mobile UI */
@media print {
    .bottom-nav,
    .pull-to-refresh,
    .swipe-actions {
        display: none !important;
    }

    body {
        padding-bottom: 0 !important;
    }
}
