/**
 * SGVM - Responsive Design System
 * Mobile-first approach with fluid layouts
 */

/* ============================================
   BASE RESPONSIVE UTILITIES
   ============================================ */

/* Fluid Typography */
:root {
    /* Base font sizes using clamp for fluid scaling */
    --font-xs: clamp(0.75rem, 0.7rem + 0.25vw, 0.875rem);
    --font-sm: clamp(0.875rem, 0.8rem + 0.375vw, 1rem);
    --font-base: clamp(1rem, 0.9rem + 0.5vw, 1.125rem);
    --font-lg: clamp(1.125rem, 1rem + 0.625vw, 1.25rem);
    --font-xl: clamp(1.25rem, 1.1rem + 0.75vw, 1.5rem);
    --font-2xl: clamp(1.5rem, 1.3rem + 1vw, 2rem);
    --font-3xl: clamp(1.875rem, 1.5rem + 1.875vw, 2.5rem);
    
    /* Spacing scale */
    --space-xs: clamp(0.25rem, 0.2rem + 0.25vw, 0.5rem);
    --space-sm: clamp(0.5rem, 0.4rem + 0.5vw, 0.75rem);
    --space-md: clamp(0.75rem, 0.6rem + 0.75vw, 1rem);
    --space-lg: clamp(1rem, 0.8rem + 1vw, 1.5rem);
    --space-xl: clamp(1.5rem, 1.2rem + 1.5vw, 2rem);
    --space-2xl: clamp(2rem, 1.5rem + 2.5vw, 3rem);
    
    /* Container widths */
    --container-sm: 640px;
    --container-md: 768px;
    --container-lg: 1024px;
    --container-xl: 1280px;
    --container-2xl: 1536px;
}

/* ============================================
   MOBILE SIDEBAR (Drawer)
   ============================================ */

/* Mobile overlay */
.mobile-overlay {
    display: none;
    position: fixed;
    inset: 0;
    background-color: rgba(0, 0, 0, 0.5);
    z-index: 40;
    transition: opacity 0.3s ease;
}

.mobile-overlay.active {
    display: block;
}

/* Mobile sidebar toggle button */
.mobile-menu-button {
    display: none;
}

@media (max-width: 1023px) {
    .mobile-menu-button {
        display: flex;
    }
    
    /* Hide sidebar by default on mobile */
    aside.sidebar {
        position: fixed;
        left: -100%;
        top: 0;
        height: 100vh;
        z-index: 50;
        transition: left 0.3s ease;
        width: 280px;
        max-width: 85vw;
    }
    
    aside.sidebar.mobile-open {
        left: 0;
    }
    
    /* Adjust main content on mobile */
    main {
        width: 100% !important;
        margin-left: 0 !important;
    }
}

/* ============================================
   RESPONSIVE TABLES
   ============================================ */

@media (max-width: 768px) {
    /* Stack table on mobile */
    .responsive-table {
        display: block;
        overflow-x: auto;
        -webkit-overflow-scrolling: touch;
    }
    
    .responsive-table table {
        min-width: 600px;
    }
    
    /* Card-style table for very small screens */
    .table-card-mobile {
        display: none;
    }
    
    @media (max-width: 640px) {
        .responsive-table table {
            display: none;
        }
        
        .table-card-mobile {
            display: block;
        }
    }
}

/* ============================================
   RESPONSIVE GRID SYSTEM
   ============================================ */

.responsive-grid {
    display: grid;
    gap: var(--space-lg);
    grid-template-columns: repeat(auto-fit, minmax(min(100%, 300px), 1fr));
}

.responsive-grid-2 {
    display: grid;
    gap: var(--space-lg);
    grid-template-columns: 1fr;
}

@media (min-width: 768px) {
    .responsive-grid-2 {
        grid-template-columns: repeat(2, 1fr);
    }
}

.responsive-grid-3 {
    display: grid;
    gap: var(--space-lg);
    grid-template-columns: 1fr;
}

@media (min-width: 768px) {
    .responsive-grid-3 {
        grid-template-columns: repeat(2, 1fr);
    }
}

@media (min-width: 1024px) {
    .responsive-grid-3 {
        grid-template-columns: repeat(3, 1fr);
    }
}

.responsive-grid-4 {
    display: grid;
    gap: var(--space-lg);
    grid-template-columns: 1fr;
}

@media (min-width: 640px) {
    .responsive-grid-4 {
        grid-template-columns: repeat(2, 1fr);
    }
}

@media (min-width: 1024px) {
    .responsive-grid-4 {
        grid-template-columns: repeat(4, 1fr);
    }
}

/* ============================================
   RESPONSIVE IMAGES & MEDIA
   ============================================ */

img, video, iframe {
    max-width: 100%;
    height: auto;
}

.responsive-img {
    width: 100%;
    height: auto;
    object-fit: cover;
}

/* ============================================
   RESPONSIVE FORMS
   ============================================ */

@media (max-width: 640px) {
    /* Stack form fields on mobile */
    .form-row {
        flex-direction: column !important;
    }
    
    .form-row > * {
        width: 100% !important;
    }
    
    /* Full-width buttons on mobile */
    .btn-group {
        flex-direction: column;
        width: 100%;
    }
    
    .btn-group button,
    .btn-group a {
        width: 100%;
    }
}

/* ============================================
   RESPONSIVE NAVIGATION
   ============================================ */

/* Topbar adjustments */
@media (max-width: 640px) {
    .topbar-title {
        display: none;
    }
    
    .topbar-actions {
        gap: 0.5rem;
    }
    
    .topbar-search {
        max-width: 150px;
    }
}

/* ============================================
   RESPONSIVE CARDS
   ============================================ */

.card {
    padding: var(--space-lg);
    border-radius: 0.75rem;
}

@media (max-width: 640px) {
    .card {
        padding: var(--space-md);
        border-radius: 0.5rem;
    }
}

/* ============================================
   RESPONSIVE MODALS
   ============================================ */

@media (max-width: 640px) {
    .modal-content {
        width: 95vw !important;
        max-height: 90vh;
        margin: 1rem;
    }
    
    .modal-header {
        padding: 1rem;
    }
    
    .modal-body {
        padding: 1rem;
    }
    
    .modal-footer {
        padding: 1rem;
        flex-direction: column-reverse;
    }
    
    .modal-footer button {
        width: 100%;
    }
}

/* ============================================
   RESPONSIVE STATS CARDS
   ============================================ */

.stats-grid {
    display: grid;
    gap: 1rem;
    grid-template-columns: 1fr;
}

@media (min-width: 640px) {
    .stats-grid {
        grid-template-columns: repeat(2, 1fr);
    }
}

@media (min-width: 1024px) {
    .stats-grid {
        grid-template-columns: repeat(4, 1fr);
    }
}

/* ============================================
   RESPONSIVE UTILITIES
   ============================================ */

/* Hide/Show based on screen size */
.mobile-only {
    display: block;
}

.tablet-up {
    display: none;
}

.desktop-only {
    display: none;
}

@media (min-width: 768px) {
    .mobile-only {
        display: none;
    }
    
    .tablet-up {
        display: block;
    }
}

@media (min-width: 1024px) {
    .desktop-only {
        display: block;
    }
}

/* Responsive text alignment */
@media (max-width: 640px) {
    .text-sm-center {
        text-align: center;
    }
}

/* Responsive padding */
.responsive-padding {
    padding: var(--space-md);
}

@media (min-width: 768px) {
    .responsive-padding {
        padding: var(--space-lg);
    }
}

@media (min-width: 1024px) {
    .responsive-padding {
        padding: var(--space-xl);
    }
}

/* ============================================
   TOUCH-FRIENDLY INTERACTIONS
   ============================================ */

@media (hover: none) and (pointer: coarse) {
    /* Increase touch targets on touch devices */
    button, a, input, select, textarea {
        min-height: 44px;
        min-width: 44px;
    }
    
    /* Remove hover effects on touch devices */
    .hover-effect:hover {
        transform: none;
    }
}

/* ============================================
   PRINT STYLES
   ============================================ */

@media print {
    aside.sidebar,
    .topbar,
    .mobile-menu-button,
    .no-print {
        display: none !important;
    }
    
    main {
        width: 100% !important;
        margin: 0 !important;
    }
    
    .card {
        break-inside: avoid;
    }
}

/* ============================================
   ACCESSIBILITY IMPROVEMENTS
   ============================================ */

/* Focus visible for keyboard navigation */
*:focus-visible {
    outline: 2px solid #1130ce;
    outline-offset: 2px;
}

/* Reduced 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 contrast mode support */
@media (prefers-contrast: high) {
    .card {
        border: 2px solid currentColor;
    }
}
