/**
 * Global Responsive Styles
 * Ensures full mobile responsiveness across all devices
 */

/* ===== BASE RESPONSIVE SETTINGS ===== */
* {
    -webkit-tap-highlight-color: transparent;
}

html {
    -webkit-text-size-adjust: 100%;
    -ms-text-size-adjust: 100%;
}

body {
    overflow-x: hidden;
    min-width: 0;
}

/* ===== VIEWPORT META TAG ENHANCEMENT ===== */
/* Ensure proper viewport for all devices */
@supports (width: 100dvw) {
    :root {
        --viewport-width: 100dvw;
    }
}

/* ===== TOUCH-FRIENDLY ELEMENTS ===== */
/* Minimum touch target size: 44x44px (Apple & Google guidelines) */
button,
a,
input[type="submit"],
input[type="button"],
select,
label {
    min-height: 44px;
    min-width: 44px;
}

/* Improve touch interactions */
button,
a,
input,
select,
textarea {
    touch-action: manipulation;
}

/* ===== RESPONSIVE TYPOGRAPHY ===== */
/* Fluid typography that scales with viewport */
h1 {
    font-size: clamp(1.5rem, 4vw, 2.5rem);
}

h2 {
    font-size: clamp(1.25rem, 3vw, 2rem);
}

h3 {
    font-size: clamp(1.125rem, 2.5vw, 1.5rem);
}

/* Ensure readable font sizes on mobile */
body {
    font-size: clamp(14px, 2.5vw, 16px);
}

/* ===== RESPONSIVE IMAGES ===== */
img,
video,
iframe {
    max-width: 100%;
    height: auto;
}

/* Responsive images with aspect ratio */
.img-responsive {
    width: 100%;
    height: auto;
    object-fit: cover;
}

/* ===== RESPONSIVE TABLES ===== */
/* Card layout for tables on mobile */
@media (max-width: 768px) {
    table {
        display: block;
        width: 100%;
        overflow-x: auto;
        -webkit-overflow-scrolling: touch;
        white-space: nowrap;
    }
    
    /* Alternative: Card-based table layout */
    .table-responsive-card {
        display: block;
    }
    
    .table-responsive-card thead {
        display: none;
    }
    
    .table-responsive-card tbody,
    .table-responsive-card tr,
    .table-responsive-card td {
        display: block;
        width: 100%;
    }
    
    .table-responsive-card tr {
        margin-bottom: 1rem;
        border: 1px solid rgba(220, 56, 44, 0.2);
        border-radius: 8px;
        padding: 1rem;
        background: rgba(26, 26, 26, 0.5);
    }
    
    .table-responsive-card td {
        border: none;
        padding: 0.5rem 0;
        text-align: left !important;
    }
    
    .table-responsive-card td:before {
        content: attr(data-label) ": ";
        font-weight: bold;
        color: #dc382c;
        display: inline-block;
        min-width: 100px;
    }
}

/* Horizontal scroll for tables on small screens */
@media (max-width: 640px) {
    .table-wrapper {
        overflow-x: auto;
        -webkit-overflow-scrolling: touch;
        margin: 0 -1rem;
        padding: 0 1rem;
    }
    
    .table-wrapper table {
        min-width: 600px;
    }
}

/* ===== RESPONSIVE GRIDS ===== */
/* Grid layouts that stack on mobile */
.grid-responsive {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(280px, 1fr));
    gap: 1rem;
}

@media (max-width: 640px) {
    .grid-responsive {
        grid-template-columns: 1fr;
    }
}

/* Tailwind grid utilities enhancement */
@media (max-width: 768px) {
    .md\\:grid-cols-2 > *,
    .md\\:grid-cols-3 > *,
    .md\\:grid-cols-4 > * {
        grid-column: span 1;
    }
}

/* ===== RESPONSIVE FORMS ===== */
/* Touch-friendly form elements */
input[type="text"],
input[type="email"],
input[type="password"],
input[type="number"],
input[type="tel"],
input[type="url"],
textarea,
select {
    width: 100%;
    padding: 12px 16px;
    font-size: 16px; /* Prevents iOS zoom on focus */
    border-radius: 8px;
    min-height: 44px;
}

/* Prevent zoom on iOS for inputs */
@media screen and (max-width: 768px) {
    input[type="text"],
    input[type="email"],
    input[type="password"],
    input[type="number"],
    input[type="tel"],
    input[type="url"],
    select,
    textarea {
        font-size: 16px !important;
    }
}

/* Responsive form layouts */
.form-group {
    margin-bottom: 1rem;
}

@media (max-width: 640px) {
    .form-row {
        flex-direction: column;
    }
    
    .form-row > * {
        width: 100% !important;
        margin-bottom: 1rem;
    }
}

/* ===== RESPONSIVE CARDS ===== */
.card,
.card-responsive {
    padding: clamp(1rem, 3vw, 1.5rem);
    margin-bottom: 1rem;
}

@media (max-width: 640px) {
    .card,
    .card-responsive {
        border-radius: 8px;
        padding: 1rem;
    }
}

/* ===== RESPONSIVE BUTTONS ===== */
.btn,
button {
    padding: 12px 24px;
    font-size: 16px;
    min-height: 44px;
    white-space: nowrap;
}

@media (max-width: 640px) {
    .btn-group {
        flex-direction: column;
        width: 100%;
    }
    
    .btn-group > .btn {
        width: 100%;
        margin-bottom: 0.5rem;
    }
}

/* ===== RESPONSIVE SPACING ===== */
/* Responsive padding and margins */
@media (max-width: 768px) {
    .container {
        padding-left: 1rem;
        padding-right: 1rem;
    }
    
    .p-6 {
        padding: 1rem;
    }
    
    .px-6 {
        padding-left: 1rem;
        padding-right: 1rem;
    }
    
    .py-4 {
        padding-top: 1rem;
        padding-bottom: 1rem;
    }
    
    .mb-8 {
        margin-bottom: 1.5rem;
    }
    
    .gap-6 {
        gap: 1rem;
    }
}

/* ===== SIDEBAR RESPONSIVENESS ===== */
@media (max-width: 768px) {
    /* Sidebar overlay on mobile */
    #sidebar {
        z-index: 50;
    }
    
    /* Main content full width on mobile */
    .main-content,
    .md\\:ml-64 {
        margin-left: 0 !important;
    }
    
    /* Hide sidebar by default on mobile */
    #sidebar {
        transform: translateX(-100%);
    }
    
    #sidebar.active {
        transform: translateX(0);
    }
}

/* ===== HEADER RESPONSIVENESS ===== */
@media (max-width: 768px) {
    header {
        padding: 1rem;
    }
    
    header h1,
    header h2 {
        font-size: 1.25rem;
    }
    
    /* Stack header elements on mobile */
    header .flex {
        flex-direction: column;
        gap: 1rem;
    }
    
    header .flex-row {
        flex-direction: row;
        justify-content: space-between;
        align-items: center;
        width: 100%;
    }
}

/* ===== NAVIGATION RESPONSIVENESS ===== */
@media (max-width: 768px) {
    nav {
        flex-wrap: wrap;
    }
    
    nav a {
        padding: 0.75rem 1rem;
        font-size: 0.875rem;
    }
}

/* ===== MODAL RESPONSIVENESS ===== */
@media (max-width: 768px) {
    .modal,
    .modal-content {
        width: 95%;
        max-width: 95%;
        margin: 1rem;
        padding: 1rem;
    }
    
    .modal-header {
        padding: 1rem;
    }
    
    .modal-body {
        padding: 1rem;
    }
    
    .modal-footer {
        padding: 1rem;
        flex-direction: column;
    }
    
    .modal-footer button {
        width: 100%;
        margin-bottom: 0.5rem;
    }
}

/* ===== PAGINATION RESPONSIVENESS ===== */
@media (max-width: 640px) {
    .pagination {
        flex-wrap: wrap;
        justify-content: center;
    }
    
    .pagination a,
    .pagination span {
        padding: 0.5rem;
        min-width: 36px;
        font-size: 0.875rem;
    }
}

/* ===== STATS GRID RESPONSIVENESS ===== */
@media (max-width: 768px) {
    .stats-grid {
        grid-template-columns: 1fr;
        gap: 1rem;
    }
}

@media (min-width: 769px) and (max-width: 1024px) {
    .stats-grid {
        grid-template-columns: repeat(2, 1fr);
    }
}

/* ===== TEXT RESPONSIVENESS ===== */
@media (max-width: 640px) {
    .text-2xl {
        font-size: 1.5rem;
    }
    
    .text-3xl {
        font-size: 1.75rem;
    }
    
    .text-4xl {
        font-size: 2rem;
    }
    
    .text-sm {
        font-size: 0.875rem;
    }
    
    .text-xs {
        font-size: 0.75rem;
    }
}

/* ===== UTILITY CLASSES ===== */
/* Hide on mobile */
@media (max-width: 768px) {
    .hide-mobile {
        display: none !important;
    }
}

/* Show only on mobile */
@media (min-width: 769px) {
    .show-mobile {
        display: none !important;
    }
}

/* Hide on small mobile */
@media (max-width: 480px) {
    .hide-small {
        display: none !important;
    }
}

/* ===== SAFE AREA INSETS (iOS) ===== */
/* Support for iPhone notch and safe areas */
@supports (padding: max(0px)) {
    body {
        padding-left: max(12px, env(safe-area-inset-left));
        padding-right: max(12px, env(safe-area-inset-right));
    }
    
    .fixed-bottom {
        padding-bottom: max(1rem, env(safe-area-inset-bottom));
    }
}

/* ===== LANDSCAPE ORIENTATION ===== */
@media (orientation: landscape) and (max-height: 500px) {
    header {
        padding: 0.5rem 1rem;
    }
    
    .modal {
        max-height: 90vh;
        overflow-y: auto;
    }
}

/* ===== PRINT STYLES ===== */
@media print {
    .sidebar,
    .mobile-bottom-nav,
    header button,
    .no-print {
        display: none !important;
    }
    
    .main-content {
        margin-left: 0 !important;
    }
}

/* ===== ACCESSIBILITY IMPROVEMENTS ===== */
/* Focus states for keyboard navigation */
*:focus-visible {
    outline: 2px solid #dc382c;
    outline-offset: 2px;
    border-radius: 4px;
}

/* Reduce motion for users who prefer it */
@media (prefers-reduced-motion: reduce) {
    *,
    *::before,
    *::after {
        animation-duration: 0.01ms !important;
        animation-iteration-count: 1 !important;
        transition-duration: 0.01ms !important;
    }
}

/* ===== HIGH DPI DISPLAYS ===== */
@media (-webkit-min-device-pixel-ratio: 2), (min-resolution: 192dpi) {
    /* Sharper borders and shadows */
    .card,
    .btn {
        border-width: 0.5px;
    }
}

/* ===== FLEX UTILITIES ===== */
@media (max-width: 768px) {
    .flex-wrap-mobile {
        flex-wrap: wrap;
    }
    
    .flex-col-mobile {
        flex-direction: column;
    }
    
    .w-full-mobile {
        width: 100% !important;
    }
}

/* ===== TABLE SPECIFIC RESPONSIVE FIXES ===== */
.table-container {
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
}

@media (max-width: 768px) {
    .table-container {
        margin: 0 -1rem;
        padding: 0 1rem;
    }
}

