/* =========================================================
   Mobile Responsive Utilities
   ========================================================= */

/* =========================================================
   BREAKPOINTS & VARIABLES
   ========================================================= */

:root {
    /* Standard Breakpoints */
    --breakpoint-mobile: 480px;
    --breakpoint-tablet-sm: 576px;
    --breakpoint-tablet: 768px;
    --breakpoint-desktop: 1024px;
    --breakpoint-desktop-lg: 1440px;

    /* Mobile-First Sizes */
    --mobile-padding: 0.75rem;
    --tablet-padding: 1rem;
    --desktop-padding: 1.5rem;

    /* Touch Targets */
    --touch-target: 44px;
    --touch-target-min: 32px;

    /* Font Sizes */
    --font-size-base-mobile: 14px;
    --font-size-base-desktop: 16px;
}

/* =========================================================
   GLOBAL MOBILE-FIRST STYLES
   ========================================================= */

/* Ensure tap highlights work on mobile */
button, a, [role="button"] {
    -webkit-tap-highlight-color: rgba(0, 0, 0, 0.1);
    min-height: var(--touch-target-min);
    min-width: var(--touch-target-min);
}

/* Prevent unwanted zoom on input focus on iOS */
input, textarea, select {
    font-size: 16px;
    /* Prevents auto-zoom on iOS when input is focused */
}

/* =========================================================
   CONTAINER QUERIES & RESPONSIVE CONTAINERS
   ========================================================= */

.container-responsive {
    width: 100%;
    padding: var(--mobile-padding);
    overflow-x: hidden;
}

@media (min-width: 576px) {
    .container-responsive {
        padding: var(--tablet-padding);
    }
}

@media (min-width: 1024px) {
    .container-responsive {
        padding: var(--desktop-padding);
    }
}

/* =========================================================
   FLEX & GRID RESPONSIVE HELPERS
   ========================================================= */

/* Stack on mobile, side-by-side on tablet+ */
.flex-responsive {
    display: flex;
    flex-direction: column;
    gap: 1rem;
}

@media (min-width: 768px) {
    .flex-responsive {
        flex-direction: row;
    }

    .flex-responsive > * {
        flex: 1;
    }
}

/* Grid responsive: 1 column mobile, 2+ on tablet */
.grid-responsive {
    display: grid;
    grid-template-columns: 1fr;
    gap: 1rem;
}

@media (min-width: 576px) {
    .grid-responsive {
        grid-template-columns: repeat(2, 1fr);
    }
}

@media (min-width: 768px) {
    .grid-responsive {
        grid-template-columns: repeat(3, 1fr);
    }
}

@media (min-width: 1024px) {
    .grid-responsive {
        grid-template-columns: repeat(4, 1fr);
    }
}

/* =========================================================
   TEXT & TYPOGRAPHY RESPONSIVE
   ========================================================= */

/* Responsive heading sizes */
.h1-responsive {
    font-size: 1.5rem;
    line-height: 1.2;
}

.h2-responsive {
    font-size: 1.25rem;
    line-height: 1.2;
}

.h3-responsive {
    font-size: 1.1rem;
    line-height: 1.3;
}

@media (min-width: 768px) {
    .h1-responsive {
        font-size: 2rem;
    }

    .h2-responsive {
        font-size: 1.5rem;
    }

    .h3-responsive {
        font-size: 1.25rem;
    }
}

/* =========================================================
   DISPLAY RESPONSIVE (Show/Hide)
   ========================================================= */

/* Hide on mobile, show on tablet+ */
.hide-mobile {
    display: none !important;
}

@media (min-width: 768px) {
    .hide-mobile {
        display: block !important;
    }
}

/* Show on mobile, hide on tablet+ */
.show-mobile {
    display: block !important;
}

@media (min-width: 768px) {
    .show-mobile {
        display: none !important;
    }
}

/* =========================================================
   BUTTONS & TOUCH TARGETS
   ========================================================= */

/* Ensure buttons are touch-friendly */
.btn-mobile-full {
    width: 100%;
    min-height: var(--touch-target);
    font-size: 1rem;
    padding: 0.625rem 1rem;
}

@media (min-width: 768px) {
    .btn-mobile-full {
        width: auto;
    }
}

/* Button groups responsive */
.btn-group-responsive {
    display: grid;
    grid-template-columns: 1fr;
    gap: 0.5rem;
}

@media (min-width: 576px) {
    .btn-group-responsive {
        grid-template-columns: repeat(2, 1fr);
        gap: 0.75rem;
    }
}

@media (min-width: 768px) {
    .btn-group-responsive {
        grid-template-columns: repeat(3, 1fr);
        gap: 1rem;
    }
}

/* =========================================================
   FORM RESPONSIVE
   ========================================================= */

.form-group-responsive {
    margin-bottom: 0.50rem;
}

.form-group-responsive label {
    display: block;
    margin-bottom: 0.375rem;
    font-weight: 500;
    font-size: 0.9rem;
}

.form-group-responsive input,
.form-group-responsive select,
.form-group-responsive textarea {
    width: 100%;
    font-size: 16px; /* Prevent iOS auto-zoom */
}

/* Form grid responsive */
.form-grid-responsive {
    display: grid;
    grid-template-columns: 1fr;
    gap: 1rem;
}

@media (min-width: 576px) {
    .form-grid-responsive {
        grid-template-columns: repeat(2, 1fr);
    }
}

@media (min-width: 768px) {
    .form-grid-responsive {
        grid-template-columns: repeat(3, 1fr);
    }
}

/* =========================================================
   TABLES RESPONSIVE (Critical for mobile)
   ========================================================= */

/* Horizontal scroll wrapper for tables on mobile */
.table-responsive-wrapper {
    width: 100%;
    overflow-x: auto;
    -webkit-overflow-scrolling: touch; /* Smooth scrolling on iOS */
    margin-bottom: 1rem;
}

/* Alternative: Card-based table on mobile */
.table-card-mobile {
    display: block;
}

@media (max-width: 767px) {
    .table-card-mobile {
        background: transparent;
        border: none;
    }

    .table-card-mobile tbody {
        display: block;
        margin-bottom: 2rem;
    }

    .table-card-mobile tr {
        display: block;
        border: 1px solid var(--bs-border-color);
        border-radius: 0.375rem;
        margin-bottom: 1rem;
        overflow: hidden;
    }

    .table-card-mobile th {
        display: none;
    }

    .table-card-mobile td {
        display: grid;
        grid-template-columns: 120px 1fr;
        gap: 1rem;
        padding: 0.75rem;
        border: none;
        border-bottom: 1px solid var(--bs-border-color);
    }

    .table-card-mobile td:last-child {
        border-bottom: none;
    }

    /* Data labels for card layout */
    .table-card-mobile td[data-label]::before {
        content: attr(data-label);
        font-weight: 600;
        color: var(--bs-secondary);
    }
}

@media (min-width: 768px) {
    .table-card-mobile {
        display: table;
    }

    .table-card-mobile tbody {
        display: table-row-group;
    }

    .table-card-mobile tr {
        display: table-row;
        border: none;
    }

    .table-card-mobile th {
        display: table-cell;
    }

    .table-card-mobile td {
        display: table-cell;
        grid-template-columns: none;
        gap: 0;
        border: none;
        border-bottom: 1px solid var(--bs-border-color);
        padding: 0.75rem;
    }

    .table-card-mobile td[data-label]::before {
        content: none;
    }
}

/* =========================================================
   CARDS & PANELS RESPONSIVE
   ========================================================= */

.card-responsive {
    margin-bottom: 1rem;
    border: 1px solid var(--bs-border-color);
    border-radius: 0.375rem;
}

.card-responsive-header {
    padding: 0.75rem;
    border-bottom: 1px solid var(--bs-border-color);
    background-color: var(--bs-gray-100);
    font-weight: 600;
}

.card-responsive-body {
    padding: 0.75rem;
}

@media (min-width: 768px) {
    .card-responsive {
        margin-bottom: 1.5rem;
    }

    .card-responsive-header {
        padding: 1rem 1.25rem;
    }

    .card-responsive-body {
        padding: 1rem 1.25rem;
    }
}

/* =========================================================
   MODALS & OVERLAYS RESPONSIVE
   ========================================================= */

.modal-responsive {
    max-height: calc(100vh - 2rem);
    max-width: 95vw;
}

@media (min-width: 576px) {
    .modal-responsive {
        max-width: 500px;
    }
}

@media (min-width: 768px) {
    .modal-responsive {
        max-width: 750px;
    }
}

@media (min-width: 1024px) {
    .modal-responsive {
        max-width: 1000px;
    }
}

/* =========================================================
   SPACING RESPONSIVE
   ========================================================= */

/* Padding responsive */
.p-mobile {
    padding: var(--mobile-padding);
}

.px-mobile {
    padding-left: var(--mobile-padding);
    padding-right: var(--mobile-padding);
}

.py-mobile {
    padding-top: var(--mobile-padding);
    padding-bottom: var(--mobile-padding);
}

@media (min-width: 768px) {
    .p-mobile {
        padding: var(--tablet-padding);
    }

    .px-mobile {
        padding-left: var(--tablet-padding);
        padding-right: var(--tablet-padding);
    }

    .py-mobile {
        padding-top: var(--tablet-padding);
        padding-bottom: var(--tablet-padding);
    }
}

@media (min-width: 1024px) {
    .p-mobile {
        padding: var(--desktop-padding);
    }

    .px-mobile {
        padding-left: var(--desktop-padding);
        padding-right: var(--desktop-padding);
    }

    .py-mobile {
        padding-top: var(--desktop-padding);
        padding-bottom: var(--desktop-padding);
    }
}

/* =========================================================
   UTILITY CLASSES FOR RESPONSIVE PATTERNS
   ========================================================= */

/* Full width on mobile */
.w-mobile-full {
    width: 100%;
}

@media (min-width: 768px) {
    .w-mobile-full {
        width: auto;
    }
}

/* Text alignment responsive */
.text-mobile-center {
    text-align: center;
}

@media (min-width: 768px) {
    .text-mobile-center {
        text-align: left;
    }
}

/* =========================================================
   MEDIA QUERY HELPER CLASSES
   ========================================================= */

/* Print styles - hide interactive elements */
@media print {
    .hide-print {
        display: none !important;
    }

    .print-only {
        display: block !important;
    }

    body {
        background: white;
        color: black;
    }
}

/* Landscape orientation on mobile */
@media (orientation: landscape) and (max-height: 500px) {
    .hide-on-mobile-landscape {
        display: none !important;
    }
}

/* High pixel density displays (Retina) */
@media (-webkit-min-device-pixel-ratio: 2), (min-resolution: 192dpi) {
    /* Optimize for high DPI */
    body {
        -webkit-font-smoothing: antialiased;
        -moz-osx-font-smoothing: grayscale;
    }
}

/* Touch device detection */
@media (hover: none) and (pointer: coarse) {
    /* Touch device - increase touch targets */
    button, a, [role="button"] {
        min-height: var(--touch-target);
        min-width: var(--touch-target);
    }
}

/* Reduced motion for accessibility */
@media (prefers-reduced-motion: reduce) {
    * {
        animation-duration: 0.01ms !important;
        animation-iteration-count: 1 !important;
        transition-duration: 0.01ms !important;
    }
}
