/* Responsive CSS for Mobile Optimization */

/* Touch-friendly tap targets */
@media (max-width: 768px) {
    /* Minimum 44px tap targets for mobile */
    button, 
    a, 
    input[type="checkbox"],
    input[type="radio"],
    select {
        min-height: 44px;
        min-width: 44px;
    }
    
    /* Better spacing for mobile forms */
    input[type="text"],
    input[type="email"],
    input[type="password"],
    textarea,
    select {
        font-size: 16px; /* Prevents zoom on iOS */
    }
}

/* Smooth scrolling */
html {
    scroll-behavior: smooth;
    -webkit-overflow-scrolling: touch;
}

/* Hide scrollbars on horizontal scroll areas */
.scrollbar-hide {
    -ms-overflow-style: none;
    scrollbar-width: none;
}

.scrollbar-hide::-webkit-scrollbar {
    display: none;
}

/* Responsive tables */
@media (max-width: 640px) {
    /* Force table to not be like tables anymore */
    table.responsive-table,
    .responsive-table thead,
    .responsive-table tbody,
    .responsive-table th,
    .responsive-table td,
    .responsive-table tr {
        display: block;
    }
    
    /* Hide table headers (but not display: none;, for accessibility) */
    .responsive-table thead tr {
        position: absolute;
        top: -9999px;
        left: -9999px;
    }
    
    .responsive-table tr {
        border: 1px solid #ccc;
        margin-bottom: 10px;
        border-radius: 8px;
    }
    
    .responsive-table td {
        /* Behave like a "row" */
        border: none;
        position: relative;
        padding-left: 50%;
    }
    
    .responsive-table td:before {
        /* Now like a table header */
        position: absolute;
        /* Top/left values mimic padding */
        top: 6px;
        left: 6px;
        width: 45%;
        padding-right: 10px;
        white-space: nowrap;
        font-weight: bold;
    }
}

/* Touch gesture support */
.swipeable {
    touch-action: pan-y;
}

.swipeable-x {
    touch-action: pan-x;
}

/* Improved mobile navigation */
.mobile-nav-open {
    overflow: hidden;
}

/* Card view for mobile */
@media (max-width: 640px) {
    .card-on-mobile {
        display: flex;
        flex-direction: column;
        background: white;
        border-radius: 8px;
        padding: 16px;
        margin-bottom: 12px;
        box-shadow: 0 1px 3px rgba(0, 0, 0, 0.1);
    }
}

/* Responsive modals */
@media (max-width: 640px) {
    .modal-content {
        margin: 0;
        width: 100%;
        height: 100%;
        max-height: 100vh;
        border-radius: 0;
    }
}

/* Responsive charts */
@media (max-width: 640px) {
    canvas {
        max-width: 100%;
        height: auto !important;
    }
}

/* Better touch feedback */
button,
a,
.clickable {
    -webkit-tap-highlight-color: rgba(0, 0, 0, 0.1);
}

button:active,
a:active,
.clickable:active {
    opacity: 0.8;
    transform: scale(0.98);
}

/* Loading states */
.skeleton {
    background: linear-gradient(90deg, #f0f0f0 25%, #e0e0e0 50%, #f0f0f0 75%);
    background-size: 200% 100%;
    animation: loading 1.5s infinite;
}

@keyframes loading {
    0% {
        background-position: 200% 0;
    }
    100% {
        background-position: -200% 0;
    }
}

/* Responsive typography */
@media (max-width: 640px) {
    h1 { font-size: 1.5rem; }
    h2 { font-size: 1.25rem; }
    h3 { font-size: 1.125rem; }
    h4 { font-size: 1rem; }
    
    .text-xs { font-size: 0.75rem; }
    .text-sm { font-size: 0.875rem; }
    .text-base { font-size: 1rem; }
    .text-lg { font-size: 1.125rem; }
    .text-xl { font-size: 1.25rem; }
    .text-2xl { font-size: 1.5rem; }
}

/* Safe area insets for modern phones */
.safe-top {
    padding-top: env(safe-area-inset-top);
}

.safe-bottom {
    padding-bottom: env(safe-area-inset-bottom);
}

.safe-left {
    padding-left: env(safe-area-inset-left);
}

.safe-right {
    padding-right: env(safe-area-inset-right);
}

/* Responsive grid utilities */
@media (max-width: 640px) {
    .grid-cols-1-mobile {
        grid-template-columns: repeat(1, minmax(0, 1fr)) !important;
    }
}

/* Pull to refresh indicator */
.pull-to-refresh {
    position: fixed;
    top: -60px;
    left: 50%;
    transform: translateX(-50%);
    transition: top 0.3s;
    z-index: 9999;
}

.pull-to-refresh.visible {
    top: 20px;
}

/* Mobile-first utilities */
@media (min-width: 640px) {
    .mobile-only {
        display: none !important;
    }
}

@media (max-width: 639px) {
    .desktop-only {
        display: none !important;
    }
}

/* Improved form inputs for mobile */
@media (max-width: 640px) {
    input, select, textarea {
        width: 100%;
        box-sizing: border-box;
    }
    
    .form-group {
        margin-bottom: 1rem;
    }
}

/* Responsive spacing */
@media (max-width: 640px) {
    .p-responsive {
        padding: 1rem;
    }
    
    .m-responsive {
        margin: 1rem;
    }
}