/**
 * Responsive Design Utilities
 * Mobile-first approach
 */

/* ===== BASE STYLES ===== */
* {
    box-sizing: border-box;
}

html {
    -webkit-text-size-adjust: 100%;
    -ms-text-size-adjust: 100%;
}

body {
    margin: 0;
    padding: 0;
    overflow-x: hidden;
}

img {
    max-width: 100%;
    height: auto;
    display: block;
}

/* ===== TOUCH-FRIENDLY ELEMENTS ===== */
button,
a.btn,
.touch-target {
    min-height: 44px;
    min-width: 44px;
    padding: 12px 16px;
}

/* Larger tap targets on mobile */
@media (max-width: 768px) {
    button,
    a.btn,
    input[type="submit"],
    input[type="button"] {
        min-height: 48px;
        padding: 14px 20px;
        font-size: 16px; /* Prevents zoom on iOS */
    }
    
    input,
    textarea,
    select {
        font-size: 16px; /* Prevents zoom on iOS */
    }
}

/* ===== RESPONSIVE CONTAINERS ===== */
.container {
    width: 100%;
    max-width: 1280px;
    margin: 0 auto;
    padding: 0 16px;
}

@media (min-width: 768px) {
    .container {
        padding: 0 24px;
    }
}

@media (min-width: 1024px) {
    .container {
        padding: 0 32px;
    }
}

/* ===== RESPONSIVE GRID ===== */
.grid-responsive {
    display: grid;
    gap: 16px;
    grid-template-columns: 1fr;
}

@media (min-width: 640px) {
    .grid-responsive {
        grid-template-columns: repeat(2, 1fr);
        gap: 20px;
    }
}

@media (min-width: 1024px) {
    .grid-responsive {
        grid-template-columns: repeat(3, 1fr);
        gap: 24px;
    }
}

@media (min-width: 1280px) {
    .grid-responsive {
        grid-template-columns: repeat(4, 1fr);
        gap: 32px;
    }
}

/* ===== RESPONSIVE TABLES ===== */
.table-responsive {
    width: 100%;
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
}

@media (max-width: 768px) {
    .table-mobile-cards table {
        display: block;
    }
    
    .table-mobile-cards thead {
        display: none;
    }
    
    .table-mobile-cards tbody,
    .table-mobile-cards tr,
    .table-mobile-cards td {
        display: block;
        width: 100%;
    }
    
    .table-mobile-cards tr {
        margin-bottom: 16px;
        border: 1px solid #e5e7eb;
        border-radius: 8px;
        padding: 12px;
    }
    
    .table-mobile-cards td {
        text-align: right;
        padding: 8px 0;
        border-bottom: 1px solid #f3f4f6;
    }
    
    .table-mobile-cards td:last-child {
        border-bottom: none;
    }
    
    .table-mobile-cards td:before {
        content: attr(data-label);
        float: left;
        font-weight: 600;
        color: #6b7280;
    }
}

/* ===== RESPONSIVE TEXT ===== */
.text-responsive {
    font-size: 14px;
    line-height: 1.6;
}

@media (min-width: 768px) {
    .text-responsive {
        font-size: 16px;
    }
}

.heading-responsive {
    font-size: 24px;
    line-height: 1.3;
}

@media (min-width: 768px) {
    .heading-responsive {
        font-size: 32px;
    }
}

@media (min-width: 1024px) {
    .heading-responsive {
        font-size: 40px;
    }
}

/* ===== RESPONSIVE SPACING ===== */
.section-padding {
    padding: 32px 0;
}

@media (min-width: 768px) {
    .section-padding {
        padding: 48px 0;
    }
}

@media (min-width: 1024px) {
    .section-padding {
        padding: 64px 0;
    }
}

/* ===== MOBILE NAVIGATION ===== */
@media (max-width: 768px) {
    .mobile-menu {
        position: fixed;
        top: 0;
        left: -100%;
        width: 80%;
        max-width: 320px;
        height: 100vh;
        background: white;
        box-shadow: 2px 0 10px rgba(0,0,0,0.1);
        transition: left 0.3s ease;
        z-index: 1000;
        overflow-y: auto;
    }
    
    .mobile-menu.active {
        left: 0;
    }
    
    .mobile-overlay {
        position: fixed;
        top: 0;
        left: 0;
        width: 100%;
        height: 100vh;
        background: rgba(0,0,0,0.5);
        opacity: 0;
        visibility: hidden;
        transition: opacity 0.3s ease, visibility 0.3s ease;
        z-index: 999;
    }
    
    .mobile-overlay.active {
        opacity: 1;
        visibility: visible;
    }
}

/* ===== RESPONSIVE CARDS ===== */
.card-responsive {
    padding: 16px;
    border-radius: 8px;
}

@media (min-width: 768px) {
    .card-responsive {
        padding: 24px;
        border-radius: 12px;
    }
}

/* ===== RESPONSIVE FORMS ===== */
@media (max-width: 768px) {
    .form-row {
        flex-direction: column;
    }
    
    .form-row > * {
        width: 100% !important;
        margin-bottom: 16px;
    }
}

/* ===== HIDE/SHOW UTILITIES ===== */
.hide-mobile {
    display: none;
}

@media (min-width: 768px) {
    .hide-mobile {
        display: block;
    }
}

.show-mobile {
    display: block;
}

@media (min-width: 768px) {
    .show-mobile {
        display: none;
    }
}

.hide-tablet {
    display: none;
}

@media (min-width: 768px) and (max-width: 1023px) {
    .hide-tablet {
        display: block;
    }
}

.hide-desktop {
    display: block;
}

@media (min-width: 1024px) {
    .hide-desktop {
        display: none;
    }
}

/* ===== RESPONSIVE IMAGES ===== */
.img-responsive {
    width: 100%;
    height: auto;
    object-fit: cover;
}

.img-contain {
    width: 100%;
    height: auto;
    object-fit: contain;
}

/* ===== RESPONSIVE VIDEO ===== */
.video-responsive {
    position: relative;
    padding-bottom: 56.25%; /* 16:9 */
    height: 0;
    overflow: hidden;
}

.video-responsive iframe,
.video-responsive video {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
}

/* ===== RESPONSIVE MODALS ===== */
@media (max-width: 768px) {
    .modal {
        width: 95%;
        max-width: none;
        margin: 16px;
    }
    
    .modal-fullscreen-mobile {
        width: 100%;
        height: 100vh;
        margin: 0;
        border-radius: 0;
    }
}

/* ===== RESPONSIVE SIDEBAR ===== */
@media (max-width: 1024px) {
    .sidebar {
        width: 100%;
        margin-bottom: 24px;
    }
    
    .main-content {
        width: 100%;
    }
}

@media (min-width: 1024px) {
    .sidebar {
        width: 300px;
    }
    
    .main-content {
        width: calc(100% - 324px);
    }
}

/* ===== RESPONSIVE BUTTONS ===== */
@media (max-width: 768px) {
    .btn-group {
        flex-direction: column;
        width: 100%;
    }
    
    .btn-group button,
    .btn-group a {
        width: 100%;
        margin-bottom: 8px;
    }
}

/* ===== PRINT STYLES ===== */
@media print {
    .no-print {
        display: none !important;
    }
    
    body {
        font-size: 12pt;
        color: black;
        background: white;
    }
    
    a {
        text-decoration: underline;
    }
    
    a[href]:after {
        content: " (" attr(href) ")";
    }
}

/* ===== 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) {
    .auto-dark {
        background-color: #1f2937;
        color: #f9fafb;
    }
    
    .auto-dark-card {
        background-color: #374151;
        border-color: #4b5563;
    }
}

/* ===== LANDSCAPE ORIENTATION ===== */
@media (max-width: 768px) and (orientation: landscape) {
    .landscape-adjust {
        padding: 8px 0;
    }
    
    .landscape-hide {
        display: none;
    }
}

/* ===== SAFE AREAS (iOS) ===== */
@supports (padding: max(0px)) {
    body {
        padding-left: max(0px, env(safe-area-inset-left));
        padding-right: max(0px, env(safe-area-inset-right));
    }
    
    .safe-area-bottom {
        padding-bottom: max(16px, env(safe-area-inset-bottom));
    }
}
