/* Mobile-First Responsive Design */

/* Extra Small Devices (phones, less than 576px) */
@media (max-width: 575.98px) {
    html {
        font-size: 14px;
    }
    
    .app-header {
        padding: var(--spacing-sm);
        flex-wrap: wrap;
        gap: var(--spacing-sm);
    }
    
    .header-left,
    .header-center,
    .header-right {
        width: 100%;
        justify-content: space-between;
    }
    
    .header-center {
        order: 3;
        margin: var(--spacing-sm) 0 0 0;
    }
    
    .quick-actions {
        justify-content: space-between;
        width: 100%;
    }
    
    .quick-action span:not(.icon) {
        display: none;
    }
    
    .app-title {
        font-size: 1.25rem;
    }
    
    .user-details {
        display: none;
    }
    
    .sidebar {
        position: fixed;
        top: 0;
        left: 0;
        bottom: 0;
        transform: translateX(-100%);
        z-index: var(--z-modal);
        width: 280px;
    }
    
    .sidebar.active {
        transform: translateX(0);
    }
    
    .sidebar-close {
        display: flex;
    }
    
    .main-content {
        flex-direction: column;
    }
    
    .content-area {
        padding: var(--spacing-md);
    }
    
    .pos-container {
        grid-template-columns: 1fr;
        height: auto;
        gap: var(--spacing-md);
    }
    
    .order-panel {
        max-height: 400px;
    }
    
    .product-grid {
        grid-template-columns: repeat(auto-fill, minmax(120px, 1fr));
        gap: var(--spacing-sm);
    }
    
    .modal {
        width: 95vw;
        max-height: 95vh;
    }
    
    .modal.wide {
        width: 95vw;
    }
    
    .payment-methods {
        grid-template-columns: 1fr;
    }
    
    .feature-flags-grid {
        grid-template-columns: 1fr;
    }
    
    .offline-queue {
        width: calc(100vw - var(--spacing-lg) * 2);
        left: var(--spacing-lg);
        right: var(--spacing-lg);
    }
    
    .toast-container {
        position: fixed !important;
        bottom: 0.5rem !important;
        right: 0.5rem !important;
        left: auto !important;
        top: auto !important;
        max-width: calc(100vw - 1rem) !important;
        margin: 0 !important;
        z-index: 9999 !important;
    }
    
    .toast {
        max-width: calc(100vw - 2rem) !important;
    }
    
    .grid-2,
    .grid-3,
    .grid-4 {
        grid-template-columns: 1fr;
    }
    
    .data-table {
        font-size: 0.75rem;
    }
    
    .data-table th,
    .data-table td {
        padding: var(--spacing-sm);
    }
}

/* Small Devices (landscape phones, 576px and up) */
@media (min-width: 576px) and (max-width: 767.98px) {
    .toast-container {
        position: fixed !important;
        bottom: 1rem !important;
        right: 1rem !important;
        left: auto !important;
        top: auto !important;
        max-width: 350px !important;
    }
    
    .pos-container {
        grid-template-columns: 1fr 350px;
    }
    
    .product-grid {
        grid-template-columns: repeat(auto-fill, minmax(130px, 1fr));
    }
    
    .sidebar {
        width: 240px;
    }
    
    .payment-methods {
        grid-template-columns: repeat(2, 1fr);
    }
    
    .grid-3,
    .grid-4 {
        grid-template-columns: repeat(2, 1fr);
    }
}

/* Medium Devices (tablets, 768px and up) */
@media (min-width: 768px) and (max-width: 991.98px) {
    .toast-container {
        position: fixed !important;
        bottom: 1.5rem !important;
        right: 1.5rem !important;
        left: auto !important;
        top: auto !important;
        max-width: 400px !important;
    }
    
    .pos-container {
        grid-template-columns: 1fr 350px;
    }
    
    .product-grid {
        grid-template-columns: repeat(auto-fill, minmax(140px, 1fr));
    }
    
    .sidebar {
        width: 260px;
    }
    
    .quick-action span:not(.icon) {
        display: inline;
    }
    
    .payment-methods {
        grid-template-columns: repeat(3, 1fr);
    }
    
    .grid-4 {
        grid-template-columns: repeat(2, 1fr);
    }
}

/* Large Devices (desktops, 992px and up) */
@media (min-width: 992px) and (max-width: 1199.98px) {
    .product-grid {
        grid-template-columns: repeat(auto-fill, minmax(140px, 1fr));
    }
    
    .payment-methods {
        grid-template-columns: repeat(3, 1fr);
    }
    
    .toast-container {
        right: 1.5rem !important;
        bottom: 1.5rem !important;
        left: auto !important;
        top: auto !important;
        max-width: 400px !important;
    }
}

/* Extra Large Devices (large desktops, 1200px and up) */
@media (min-width: 1200px) {
    .product-grid {
        grid-template-columns: repeat(auto-fill, minmax(160px, 1fr));
    }
    
    .feature-flags-grid {
        grid-template-columns: repeat(auto-fill, minmax(350px, 1fr));
    }
    
    .toast-container {
        right: 1.5rem !important;
        bottom: 1.5rem !important;
        left: auto !important;
        top: auto !important;
        max-width: 450px !important;
    }
}

/* Very Large Screens (4K, 1600px and up) */
@media (min-width: 1600px) {
    .container {
        max-width: 1600px;
        margin: 0 auto;
    }
    
    .product-grid {
        grid-template-columns: repeat(auto-fill, minmax(180px, 1fr));
    }
    
    .pos-container {
        grid-template-columns: 1fr 450px;
    }
    
    .toast-container {
        right: 2rem !important;
        bottom: 2rem !important;
        left: auto !important;
        top: auto !important;
        max-width: 500px !important;
    }
}

/* Landscape Orientation */
@media (orientation: landscape) and (max-height: 600px) {
    .app-header {
        padding: var(--spacing-sm);
    }
    
    .order-panel {
        max-height: 300px;
    }
    
    .product-grid {
        max-height: calc(100vh - 200px);
    }
    
    h1, h2, h3, h4, h5, h6 {
        margin-bottom: var(--spacing-sm);
    }
}

/* Portrait Orientation */
@media (orientation: portrait) {
    .pos-container {
        grid-template-columns: 1fr;
    }
    
    .order-panel {
        max-height: 40vh;
    }
}

/* Foldable Devices */
@media (screen-spanning: single-fold-vertical) {
    .pos-container {
        grid-template-columns: 1fr 1fr;
        gap: env(viewport-segment-width 0 0);
    }
}

/* Touch Device Optimizations */
@media (hover: none) and (pointer: coarse) {
    .btn,
    .nav-item,
    .product-card,
    .quick-action {
        min-height: 44px;
        min-width: 44px;
    }
    
    .item-action {
        min-width: 44px;
        min-height: 44px;
    }
    
    .category-tab,
    .settings-tab {
        padding: var(--spacing-md) var(--spacing-lg);
    }
    
    input,
    select,
    textarea {
        font-size: 16px; /* Prevents iOS zoom on focus */
        padding: var(--spacing-md);
    }
    
    .menu-toggle,
    .header-btn {
        width: 48px;
        height: 48px;
    }
    
    .payment-method {
        padding: var(--spacing-lg);
    }
}

/* Hover Effects on Non-Touch Devices */
@media (hover: hover) and (pointer: fine) {
    .product-card,
    .nav-item,
    .btn {
        transition: all var(--transition-fast);
    }
    
    .product-card:hover {
        transform: translateY(-4px);
    }
}

/* Small Viewport Width */
@media (max-width: 400px) {
    .payment-methods {
        grid-template-columns: 1fr;
    }
    
    .order-summary {
        font-size: 0.75rem;
    }
    
    .modal-body {
        padding: var(--spacing-md);
    }
}

/* Very Wide Screens (Multi-Column Layout) */
@media (min-width: 1400px) {
    .pos-container {
        grid-template-columns: 1fr 1fr 400px;
    }
    
    .product-grid-container {
        display: flex;
        flex-direction: column;
    }
    
    .feature-flags-grid {
        grid-template-columns: repeat(4, 1fr);
    }
}

/* Aspect Ratio Optimizations */
@media (aspect-ratio: 16 / 9) {
    .product-grid-container {
        min-height: 100%;
    }
}

@media (aspect-ratio: 4 / 3) {
    .pos-container {
        height: auto;
    }
}

/* Print - Single Column Layout */
@media print {
    .grid-2,
    .grid-3,
    .grid-4 {
        grid-template-columns: 1fr;
    }
    
    .data-table {
        page-break-inside: avoid;
    }
}

/* Responsive Typography */
@media (max-width: 576px) {
    h1 { font-size: 1.75rem; }
    h2 { font-size: 1.5rem; }
    h3 { font-size: 1.25rem; }
    h4 { font-size: 1rem; }
}

@media (min-width: 1200px) {
    h1 { font-size: 3rem; }
    h2 { font-size: 2.25rem; }
    h3 { font-size: 1.75rem; }
    h4 { font-size: 1.5rem; }
}

/* Responsive Images */
img {
    max-width: 100%;
    height: auto;
    display: block;
}

@media (max-width: 768px) {
    .product-image {
        height: 80px;
    }
}

/* Responsive Modals */
@media (max-width: 600px) {
    .modal {
        width: 100vw;
        height: 100vh;
        max-width: 100vw;
        max-height: 100vh;
        border-radius: 0;
        top: 0;
        left: 0;
        transform: none;
    }
    
    .modal.active {
        transform: none;
    }
    
    .modal.wide {
        width: 100vw;
    }
}

/* Responsive Sidebar */
@media (max-width: 768px) {
    .sidebar {
        position: absolute;
        left: -100%;
        width: 100%;
        max-width: 70vw;
        height: 100%;
        transition: left var(--transition-base);
    }
    
    .sidebar.active {
        left: 0;
    }
}

/* High DPI Screens */
@media (-webkit-min-device-pixel-ratio: 2), (min-resolution: 192dpi) {
    .product-card,
    .btn,
    .modal {
        border-width: 0.5px;
    }
}

/* Viewport-Relative Sizing */
@media (width <= 500px) {
    .pos-container {
        gap: 0.5rem;
    }
    
    .modal-body {
        padding: 1rem;
    }
}

@media (width >= 1920px) {
    .container {
        max-width: 1920px;
    }
    
    .pos-container {
        grid-template-columns: 2fr 1fr 400px;
    }
}
