/**
 * Mobile-Specific Styles for Android and iOS
 * Touch-friendly, optimized for phones and tablets
 */

/* Touch-friendly tap targets (minimum 44x44px for accessibility) */
@media (max-width: 768px) {
    /* Buttons */
    .btn {
        min-height: 44px;
        padding: 12px 16px;
        font-size: 16px; /* Prevents auto-zoom on iOS */
    }

    /* Form inputs */
    input[type="text"],
    input[type="email"],
    input[type="password"],
    input[type="number"],
    input[type="tel"],
    input[type="search"],
    select,
    textarea {
        min-height: 44px;
        font-size: 16px; /* Prevents auto-zoom on iOS */
        padding: 12px;
    }

    /* Links and nav items */
    a,
    .nav-link {
        min-height: 44px;
        padding: 12px;
        display: flex;
        align-items: center;
    }

    /* Table cells */
    td, th {
        padding: 12px 8px;
    }

    /* Navbar toggler */
    .navbar-toggler {
        min-width: 44px;
        min-height: 44px;
    }
}

/* Responsive Tables */
@media (max-width: 768px) {
    /* Stack table on mobile */
    .table-responsive {
        display: block;
        width: 100%;
        overflow-x: auto;
        -webkit-overflow-scrolling: touch;
    }

    /* Alternative: Card-style table view */
    .table-mobile-cards {
        display: block;
    }

    .table-mobile-cards thead {
        display: none;
    }

    .table-mobile-cards tbody,
    .table-mobile-cards tr {
        display: block;
        width: 100%;
    }

    .table-mobile-cards tr {
        margin-bottom: 16px;
        border: 1px solid #dee2e6;
        border-radius: 8px;
        padding: 12px;
        background: white;
        box-shadow: 0 1px 3px rgba(0, 0, 0, 0.1);
    }

    .table-mobile-cards td {
        display: flex;
        justify-content: space-between;
        padding: 8px 0;
        border: none;
        border-bottom: 1px solid #f8f9fa;
    }

    .table-mobile-cards td:last-child {
        border-bottom: none;
    }

    .table-mobile-cards td::before {
        content: attr(data-label);
        font-weight: 600;
        color: #6c757d;
        min-width: 120px;
    }
}

/* Forms - Mobile Optimization */
@media (max-width: 768px) {
    /* Stack form groups */
    .form-group,
    .mb-3 {
        margin-bottom: 20px;
    }

    /* Full-width inputs */
    .form-control,
    .form-select {
        width: 100%;
    }

    /* Form labels */
    label {
        font-size: 14px;
        font-weight: 600;
        margin-bottom: 8px;
    }

    /* Button groups */
    .btn-group {
        display: flex;
        flex-direction: column;
        width: 100%;
    }

    .btn-group .btn {
        width: 100%;
        margin-bottom: 8px;
    }

    .btn-group .btn:last-child {
        margin-bottom: 0;
    }
}

/* Cards - Mobile Optimization */
@media (max-width: 768px) {
    .card {
        margin-bottom: 16px;
    }

    .card-body {
        padding: 16px;
    }

    .card-title {
        font-size: 18px;
    }
}

/* Modals - Full screen on mobile */
@media (max-width: 768px) {
    .modal-dialog {
        margin: 0;
        max-width: 100%;
        height: 100%;
    }

    .modal-content {
        height: 100%;
        border: none;
        border-radius: 0;
    }

    .modal-header {
        padding: 16px;
    }

    .modal-body {
        padding: 16px;
        overflow-y: auto;
    }

    .modal-footer {
        padding: 16px;
        flex-direction: column;
    }

    .modal-footer .btn {
        width: 100%;
        margin: 4px 0;
    }
}

/* Navigation - Mobile Menu */
@media (max-width: 768px) {
    .navbar {
        padding: 12px 16px;
    }

    .navbar-brand {
        font-size: 18px;
    }

    .navbar-collapse {
        background: rgba(0,0,0,0.15);
        padding: 16px;
        margin: 16px -16px 0;
        border-top: 1px solid rgba(255,255,255,0.15);
        border-radius: 0 0 8px 8px;
    }

    .nav-item {
        margin-bottom: 8px;
    }
}

/* Breadcrumbs - Mobile */
@media (max-width: 768px) {
    .breadcrumb {
        font-size: 14px;
        padding: 8px 12px;
        overflow-x: auto;
        white-space: nowrap;
        -webkit-overflow-scrolling: touch;
    }

    .breadcrumb-item + .breadcrumb-item::before {
        padding: 0 4px;
    }
}

/* Container - Mobile Padding */
@media (max-width: 768px) {
    .container,
    .container-fluid {
        padding-left: 16px;
        padding-right: 16px;
    }
}

/* Footer - Mobile */
@media (max-width: 768px) {
    .footer {
        padding: 16px;
        font-size: 14px;
        text-align: center;
    }
}

/* iOS-specific fixes */
@supports (-webkit-touch-callout: none) {
    /* Fix for iOS Safari bottom bar */
    body {
        padding-bottom: env(safe-area-inset-bottom);
    }

    /* Fix for notch devices */
    .navbar {
        padding-top: max(12px, env(safe-area-inset-top));
    }

    /* Smooth scrolling */
    * {
        -webkit-overflow-scrolling: touch;
    }

    /* Fix for sticky elements */
    .sticky-top {
        top: env(safe-area-inset-top);
    }
}

/* Android-specific fixes */
@media (pointer: coarse) {
    /* Larger touch targets */
    button,
    a,
    input[type="button"],
    input[type="submit"] {
        min-height: 48px;
    }

    /* Remove tap highlight */
    * {
        -webkit-tap-highlight-color: rgba(0, 0, 0, 0.05);
    }
}

/* Landscape orientation on mobile */
@media (max-width: 768px) and (orientation: landscape) {
    /* Reduce vertical spacing */
    .mb-3,
    .my-3 {
        margin-bottom: 12px !important;
    }

    .mt-3 {
        margin-top: 12px !important;
    }

    /* Compact navbar */
    .navbar {
        padding: 8px 16px;
    }

    /* Smaller modals */
    .modal-header,
    .modal-body,
    .modal-footer {
        padding: 12px;
    }
}

/* Pull to refresh indicator */
@media (max-width: 768px) {
    body {
        overscroll-behavior-y: contain;
    }
}

/* Loading states - Better on mobile */
@media (max-width: 768px) {
    .loading-overlay {
        backdrop-filter: blur(8px);
    }

    .loading-spinner-container {
        padding: 24px;
    }
}

/* Accessibility - High contrast mode */
@media (prefers-contrast: high) {
    button,
    .btn {
        border-width: 2px;
    }

    input,
    select,
    textarea {
        border-width: 2px;
    }
}

/* Reduced motion for accessibility */
@media (prefers-reduced-motion: reduce) {
    *,
    *::before,
    *::after {
        animation-duration: 0.01ms !important;
        animation-iteration-count: 1 !important;
        transition-duration: 0.01ms !important;
    }
}

/* Dark mode support */
@media (prefers-color-scheme: dark) {
    body {
        background-color: #1a1a1a;
        color: #f0f0f0;
    }

    .card {
        background-color: #2a2a2a;
        border-color: #3a3a3a;
    }

    .navbar {
        background: linear-gradient(135deg, #4c0519 0%, #3a0413 100%) !important;
        border-bottom-color: #3a3a3a;
    }

    input,
    select,
    textarea {
        background-color: #2a2a2a;
        border-color: #3a3a3a;
        color: #f0f0f0;
    }

    .table {
        color: #f0f0f0;
    }

    .table-striped tbody tr:nth-of-type(odd) {
        background-color: rgba(255, 255, 255, 0.02);
    }
}

/* Utility classes for mobile */
.hide-on-mobile {
    display: none !important;
}

.show-on-mobile {
    display: block !important;
}

@media (min-width: 769px) {
    .hide-on-mobile {
        display: block !important;
    }

    .show-on-mobile {
        display: none !important;
    }
}

/* Touch-friendly scrollbars */
@media (max-width: 768px) {
    ::-webkit-scrollbar {
        width: 8px;
        height: 8px;
    }

    ::-webkit-scrollbar-track {
        background: #f1f1f1;
    }

    ::-webkit-scrollbar-thumb {
        background: #888;
        border-radius: 4px;
    }

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