/**
 * Mobile Responsive Enhancements
 * Comprehensive mobile-first responsive design for Sales Tracking System
 */

/* ============================================
   MOBILE-FIRST BASE STYLES
   ============================================ */

/* Touch-friendly tap targets */
.btn,
.nav-link,
a,
button,
input[type="submit"],
input[type="button"] {
    min-height: 44px;
    min-width: 44px;
}

/* Prevent text size adjustment on mobile */
html {
    -webkit-text-size-adjust: 100%;
    -ms-text-size-adjust: 100%;
}

/* Smooth scrolling for mobile */
html {
    scroll-behavior: smooth;
}

/* ============================================
   MOBILE NAVIGATION & HEADER
   ============================================ */

@media (max-width: 768px) {
    /* Mobile header adjustments */
    .main-header {
        padding: 1rem 0;
        position: sticky;
        top: 0;
        z-index: 1000;
    }
    
    .main-header .container {
        flex-direction: column;
        gap: 1rem;
        padding: 0 15px;
    }
    
    .logo {
        font-size: 1.4rem;
        text-align: center;
        width: 100%;
    }
    
    /* Mobile navigation */
    .user-nav {
        flex-direction: column;
        width: 100%;
        gap: 0.75rem;
    }
    
    .nav-links {
        display: flex;
        flex-direction: column;
        width: 100%;
        gap: 0.5rem;
    }
    
    .nav-link {
        width: 100%;
        text-align: center;
        padding: 0.75rem 1rem;
        font-size: 0.95rem;
    }
    
    .user-info-section {
        flex-direction: column;
        width: 100%;
        gap: 0.75rem;
        text-align: center;
    }
    
    .user-info {
        text-align: center;
        width: 100%;
    }
    
    .btn-logout {
        width: 100%;
        text-align: center;
    }
}

/* ============================================
   MOBILE CARDS & CONTAINERS
   ============================================ */

@media (max-width: 768px) {
    .container {
        padding: 0 15px;
        max-width: 100%;
    }
    
    .card {
        padding: 1.25rem;
        margin: 1rem 0;
        border-radius: 16px;
    }
    
    .dashboard-card {
        padding: 1.25rem;
    }
    
    .card h1 {
        font-size: 1.75rem;
        margin-bottom: 1rem;
    }
    
    .card h2 {
        font-size: 1.5rem;
        margin-bottom: 0.75rem;
    }
    
    .card h3 {
        font-size: 1.25rem;
    }
    
    .card h4 {
        font-size: 1.1rem;
    }
    
    .card p {
        font-size: 0.95rem;
        line-height: 1.5;
    }
}

@media (max-width: 480px) {
    .card {
        padding: 1rem;
        margin: 0.75rem 0;
    }
    
    .card h1 {
        font-size: 1.5rem;
    }
    
    .card h2 {
        font-size: 1.3rem;
    }
}

/* ============================================
   MOBILE BUTTONS
   ============================================ */

@media (max-width: 768px) {
    .btn {
        width: 100%;
        padding: 0.875rem 1.5rem;
        font-size: 0.95rem;
        margin-bottom: 0.5rem;
        text-align: center;
    }
    
    .btn-small {
        padding: 0.625rem 1rem;
        font-size: 0.85rem;
        min-height: 40px;
    }
    
    .btn-large {
        padding: 1rem 1.75rem;
        font-size: 1rem;
    }
    
    /* Flex button groups */
    .d-flex.gap-1 {
        flex-direction: column;
        gap: 0.5rem;
    }
    
    .d-flex.gap-1 .btn {
        width: 100%;
        margin-bottom: 0;
    }
    
    /* Login options */
    .login-options {
        flex-direction: column;
        gap: 1rem;
        width: 100%;
    }
    
    .login-options .btn {
        width: 100%;
        min-width: auto;
        padding: 1.25rem;
    }
}

/* ============================================
   MOBILE FORMS
   ============================================ */

@media (max-width: 768px) {
    .form-group {
        margin-bottom: 1.25rem;
    }
    
    .form-group label {
        font-size: 0.9rem;
        margin-bottom: 0.5rem;
    }
    
    .form-control {
        padding: 0.875rem 1rem;
        font-size: 16px; /* Prevents zoom on iOS */
        border-radius: 12px;
    }
    
    textarea.form-control {
        min-height: 100px;
    }
    
    select.form-control {
        padding-right: 2.5rem;
        background-size: 1.25em 1.25em;
        appearance: none;
        -webkit-appearance: none;
        -moz-appearance: none;
        background-color: rgba(26, 11, 46, 0.8) !important;
        color: #ffffff !important;
    }
    
    select.form-control:focus {
        background-color: rgba(26, 11, 46, 1) !important;
        color: #ffffff !important;
    }
    
    select.form-control option {
        background-color: #2d1b4e !important;
        color: #ffffff !important;
        padding: 0.75rem !important;
        font-size: 1rem !important;
    }
    
    select.form-control option:checked {
        background-color: #8b5cf6 !important;
        color: #ffffff !important;
    }
    
    select.form-control option:disabled {
        background-color: #1a0b2e !important;
        color: rgba(255, 255, 255, 0.5) !important;
    }
    
    /* Filter forms */
    .filter-form {
        padding: 1rem;
    }
    
    .filter-form > div:first-child {
        grid-template-columns: 1fr !important;
        gap: 0.75rem;
    }
    
    .filter-form .form-group {
        margin-bottom: 0.75rem;
    }
}

@media (max-width: 480px) {
    .form-control {
        padding: 0.75rem 0.875rem;
        font-size: 16px;
    }
}

/* ============================================
   MOBILE TABLES
   ============================================ */

@media (max-width: 992px) {
    .table {
        font-size: 0.9rem;
    }
    
    .table th,
    .table td {
        padding: 0.625rem 0.5rem;
    }
    
    .table th {
        font-size: 0.8rem;
        padding: 0.875rem 0.5rem;
    }
}

@media (max-width: 768px) {
    /* Horizontal scroll for tables */
    .table-responsive,
    div[style*="overflow-x: auto"] {
        -webkit-overflow-scrolling: touch;
        margin: 0 -1.25rem;
        padding: 0 1.25rem;
    }
    
    .table {
        font-size: 0.85rem;
        min-width: 800px; /* Ensures table doesn't collapse */
    }
    
    .table th,
    .table td {
        padding: 0.5rem 0.375rem;
        white-space: nowrap;
    }
    
    .table th {
        font-size: 0.75rem;
        padding: 0.75rem 0.375rem;
    }
    
    /* Stack table actions vertically */
    .table td .btn {
        display: block;
        width: 100%;
        margin-bottom: 0.25rem;
        padding: 0.375rem 0.625rem;
        font-size: 0.75rem;
    }
    
    .table td .btn:last-child {
        margin-bottom: 0;
    }
}

/* Mobile-friendly card-based table alternative */
@media (max-width: 640px) {
    .table-mobile-cards {
        display: block;
    }
    
    .table-mobile-cards thead {
        display: none;
    }
    
    .table-mobile-cards tbody {
        display: block;
    }
    
    .table-mobile-cards tr {
        display: block;
        margin-bottom: 1rem;
        background: rgba(255, 255, 255, 0.05);
        border-radius: 12px;
        padding: 1rem;
        border: 1px solid rgba(255, 255, 255, 0.1);
    }
    
    .table-mobile-cards td {
        display: block;
        text-align: left !important;
        padding: 0.5rem 0;
        border: none;
    }
    
    .table-mobile-cards td::before {
        content: attr(data-label);
        font-weight: bold;
        display: inline-block;
        margin-right: 0.5rem;
        color: rgba(255, 255, 255, 0.7);
    }
}

/* ============================================
   MOBILE STATISTICS & GRIDS
   ============================================ */

@media (max-width: 768px) {
    .stats-grid {
        grid-template-columns: repeat(2, 1fr) !important;
        gap: 0.75rem;
    }
    
    .stat-card {
        padding: 1rem !important;
    }
    
    .stat-card h3 {
        font-size: 1.5rem !important;
    }
    
    .stat-card p {
        font-size: 0.85rem !important;
    }
    
    .detail-grid {
        grid-template-columns: 1fr !important;
        gap: 0.75rem;
    }
}

@media (max-width: 480px) {
    .stats-grid {
        grid-template-columns: 1fr !important;
    }
    
    .stat-card {
        padding: 0.875rem !important;
    }
}

/* ============================================
   MOBILE MESSAGES & NOTIFICATIONS
   ============================================ */

@media (max-width: 768px) {
    .message {
        padding: 0.875rem 1rem;
        font-size: 0.9rem;
        margin: 0.75rem 0;
        border-radius: 10px;
    }
    
    .message-dismissible {
        padding-right: 2.5rem;
    }
    
    .message-close {
        top: 0.625rem;
        right: 0.75rem;
        font-size: 1.1rem;
    }
    
    /* Toast notifications */
    .toast-container {
        top: 10px;
        right: 10px;
        left: 10px;
        max-width: none;
    }
    
    .toast {
        font-size: 0.9rem;
        padding: 0.875rem;
    }
}

/* ============================================
   MOBILE BADGES & TAGS
   ============================================ */

@media (max-width: 768px) {
    .badge {
        padding: 0.3rem 0.5rem;
        font-size: 0.7rem;
    }
    
    .filter-tag {
        padding: 0.35rem 0.625rem;
        font-size: 0.75rem;
    }
}

/* ============================================
   MOBILE FOOTER
   ============================================ */

@media (max-width: 768px) {
    .main-footer {
        padding: 1.5rem 0;
        margin-top: 2rem;
    }
    
    .footer-content {
        flex-direction: column;
        text-align: center;
        gap: 0.75rem;
    }
    
    .footer-section {
        width: 100%;
    }
    
    .main-footer p {
        font-size: 0.85rem;
    }
    
    .main-footer small {
        font-size: 0.75rem;
    }
}

/* ============================================
   MOBILE UTILITY CLASSES
   ============================================ */

@media (max-width: 768px) {
    .mobile-hide {
        display: none !important;
    }
    
    .mobile-show {
        display: block !important;
    }
    
    .mobile-text-center {
        text-align: center !important;
    }
    
    .mobile-full-width {
        width: 100% !important;
    }
    
    .mobile-no-padding {
        padding: 0 !important;
    }
    
    .mobile-no-margin {
        margin: 0 !important;
    }
}

/* ============================================
   MOBILE RECORD DETAILS
   ============================================ */

@media (max-width: 768px) {
    .record-details td {
        padding: 1rem !important;
    }
    
    .record-detail-content {
        padding: 0.75rem;
    }
    
    .record-detail-content h4 {
        font-size: 1.1rem;
        margin-bottom: 0.75rem;
    }
    
    .followup-item {
        padding: 0.625rem;
        margin: 0.5rem 0;
        font-size: 0.9rem;
    }
    
    .followup-form-content {
        padding: 0.75rem;
    }
    
    .admin-remarks-display {
        padding: 0.875rem !important;
        font-size: 0.9rem;
    }
}

/* ============================================
   MOBILE DATE RANGE PICKER
   ============================================ */

@media (max-width: 768px) {
    .date-range-btn {
        font-size: 0.75rem;
        padding: 0.375rem 0.625rem;
        min-height: 36px;
    }
    
    #dateRangeModal > div {
        width: 95% !important;
        max-width: 95% !important;
        padding: 1.5rem !important;
    }
    
    #dateRangeModal h3 {
        font-size: 1.25rem !important;
    }
    
    #dateRangeModal > div > div:nth-child(2) {
        grid-template-columns: 1fr !important;
    }
}

/* ============================================
   MOBILE ACTIVE FILTERS
   ============================================ */

@media (max-width: 768px) {
    .active-filters {
        font-size: 0.85rem;
    }
    
    .active-filters > div {
        gap: 0.375rem !important;
    }
}

/* ============================================
   MOBILE LOGIN PAGE
   ============================================ */

@media (max-width: 768px) {
    .login-card {
        margin: 1.5rem auto;
        padding: 1.5rem;
        max-width: 95%;
    }
    
    .admin-badge {
        font-size: 0.85rem;
        padding: 0.5rem 0.875rem;
    }
}

@media (max-width: 480px) {
    .login-card {
        margin: 1rem auto;
        padding: 1.25rem;
    }
}

/* ============================================
   MOBILE ADMIN DASHBOARD
   ============================================ */

@media (max-width: 768px) {
    .d-flex.justify-space-between {
        flex-direction: column;
        gap: 1rem;
    }
    
    .d-flex.justify-space-between .user-nav {
        width: 100%;
    }
    
    .d-flex.justify-space-between .user-nav .btn {
        width: 100%;
        margin: 0 0 0.5rem 0 !important;
    }
}

/* ============================================
   TOUCH INTERACTIONS
   ============================================ */

@media (hover: none) and (pointer: coarse) {
    /* Remove hover effects on touch devices */
    .btn:hover,
    .nav-link:hover,
    .card:hover {
        transform: translateZ(0) !important;
        box-shadow: inherit !important;
    }
    
    /* Disable all animations on touch devices to prevent shaking */
    .card,
    .btn,
    .nav-link,
    body::after,
    body::before {
        animation: none !important;
    }
    
    /* Add active/tap states instead */
    .btn:active {
        transform: scale(0.98) translateZ(0);
        opacity: 0.9;
    }
    
    .nav-link:active {
        background: rgba(255, 255, 255, 0.25);
    }
    
    .card:active {
        transform: translateY(-2px) translateZ(0);
    }
    
    .table tbody tr:active {
        background: rgba(255, 255, 255, 0.12);
    }
}

/* ============================================
   MOBILE LANDSCAPE ORIENTATION
   ============================================ */

@media (max-width: 992px) and (orientation: landscape) {
    .main-header {
        padding: 0.75rem 0;
    }
    
    .card {
        padding: 1rem;
    }
    
    .stats-grid {
        grid-template-columns: repeat(4, 1fr) !important;
    }
}

@media (max-width: 768px) and (orientation: landscape) {
    .main-header .container {
        flex-direction: row;
        justify-content: space-between;
    }
    
    .logo {
        width: auto;
        text-align: left;
    }
    
    .user-nav {
        flex-direction: row;
        width: auto;
    }
    
    .nav-links {
        flex-direction: row;
        width: auto;
    }
}

/* ============================================
   MOBILE ACCESSIBILITY
   ============================================ */

@media (max-width: 768px) {
    /* Larger tap targets for accessibility */
    input[type="checkbox"],
    input[type="radio"] {
        min-width: 24px;
        min-height: 24px;
    }
    
    /* Better focus indicators on mobile */
    .btn:focus-visible,
    .form-control:focus-visible,
    .nav-link:focus-visible {
        outline: 3px solid rgba(236, 72, 153, 0.8);
        outline-offset: 3px;
    }
    
    /* Prevent text selection on buttons */
    .btn,
    .nav-link {
        -webkit-user-select: none;
        user-select: none;
    }
}

/* ============================================
   MOBILE LOADING STATES
   ============================================ */

@media (max-width: 768px) {
    .loading-overlay {
        padding: 1rem;
    }
    
    .loading-content {
        padding: 1.5rem;
        max-width: 90%;
    }
    
    .loading-spinner {
        width: 32px;
        height: 32px;
    }
}

/* ============================================
   MOBILE SCROLLBAR
   ============================================ */

@media (max-width: 768px) {
    ::-webkit-scrollbar {
        width: 6px;
        height: 6px;
    }
    
    ::-webkit-scrollbar-thumb {
        border-radius: 3px;
    }
}

/* ============================================
   MOBILE SAFE AREAS (iOS notch support)
   ============================================ */

@supports (padding: max(0px)) {
    .main-header {
        padding-left: max(1rem, env(safe-area-inset-left));
        padding-right: max(1rem, env(safe-area-inset-right));
    }
    
    .container {
        padding-left: max(15px, env(safe-area-inset-left));
        padding-right: max(15px, env(safe-area-inset-right));
    }
    
    .main-footer {
        padding-bottom: max(2rem, env(safe-area-inset-bottom));
    }
}

/* ============================================
   MOBILE PERFORMANCE OPTIMIZATIONS
   ============================================ */

@media (max-width: 768px) {
    /* Reduce animations on mobile for better performance */
    * {
        animation-duration: 0.2s !important;
        transition-duration: 0.2s !important;
    }
    
    /* Disable complex animations on mobile */
    body::before,
    body::after,
    .card::before {
        animation: none !important;
        transform: translateZ(0) !important;
    }
    
    /* Hardware acceleration for smooth rendering */
    .card,
    .btn,
    .nav-link,
    .form-control {
        transform: translateZ(0);
        backface-visibility: hidden;
        -webkit-backface-visibility: hidden;
        perspective: 1000px;
        -webkit-perspective: 1000px;
    }
    
    /* Prevent card shaking on mobile */
    .card {
        will-change: auto !important;
    }
    
    .card:hover {
        transform: translateZ(0) !important;
    }
}

/* ============================================
   MOBILE PRINT STYLES
   ============================================ */

@media print {
    .main-header,
    .main-footer,
    .btn,
    .nav-link,
    .filter-form {
        display: none !important;
    }
    
    .card {
        border: 1px solid #000;
        page-break-inside: avoid;
    }
    
    .table {
        font-size: 10pt;
    }
}
