/* ===================================
   PackSmart AI - Responsive Design
   =================================== */

/* Mobile First Approach - Default styles are for mobile */

/* Small devices (landscape phones, 576px and up) */
@media (min-width: 576px) {
    .home-grid {
        grid-template-columns: repeat(2, 1fr);
        gap: var(--spacing-lg);
    }
    
    .action-card {
        padding: var(--spacing-2xl) var(--spacing-lg);
    }
    
    .stats-bar {
        padding: var(--spacing-xl);
    }
    
    .modal-content {
        max-width: 500px;
    }
}

/* Medium devices (tablets, 768px and up) */
@media (min-width: 768px) {
    .app-container {
        max-width: 768px;
        margin: 0 auto;
        box-shadow: var(--shadow-xl);
    }
    
    .home-grid {
        grid-template-columns: repeat(2, 1fr);
        gap: var(--spacing-xl);
    }
    
    .photo-strip {
        gap: var(--spacing-md);
    }
    
    .photo-thumb {
        min-width: 100px;
        height: 100px;
    }
    
    .search-filters {
        justify-content: center;
    }
    
    .bottom-nav {
        max-width: 768px;
        left: 50%;
        transform: translateX(-50%);
    }
}

/* Large devices (desktops, 992px and up) */
@media (min-width: 992px) {
    .app-container {
        max-width: 992px;
    }
    
    .home-grid {
        grid-template-columns: repeat(4, 1fr);
    }
    
    .stats-bar {
        max-width: 600px;
        margin: var(--spacing-xl) auto;
    }
    
    .camera-container {
        max-width: 640px;
        margin: 0 auto var(--spacing-lg);
    }
    
    .items-list {
        max-height: 400px;
    }
    
    .action-buttons {
        display: flex;
        gap: var(--spacing-md);
        justify-content: center;
    }
    
    .action-buttons .btn {
        width: auto;
        min-width: 200px;
    }
    
    .bottom-nav {
        max-width: 992px;
    }
}

/* Extra large devices (large desktops, 1200px and up) */
@media (min-width: 1200px) {
    .app-container {
        max-width: 1200px;
    }
    
    .main-content {
        padding: var(--spacing-xl);
    }
    
    .view {
        padding: var(--spacing-xl);
    }
    
    .settings-panel {
        display: grid;
        grid-template-columns: repeat(2, 1fr);
        gap: var(--spacing-lg);
    }
    
    .settings-panel h3 {
        grid-column: 1 / -1;
    }
}

/* Portrait orientation specific styles */
@media (orientation: portrait) {
    .camera-container {
        aspect-ratio: 4/3;
    }
    
    .home-grid {
        grid-template-columns: repeat(2, 1fr);
    }
}

/* Landscape orientation specific styles */
@media (orientation: landscape) and (max-height: 600px) {
    .app-header {
        padding: var(--spacing-sm);
    }
    
    .app-header h1 {
        font-size: var(--font-size-xl);
    }
    
    .header-subtitle {
        display: none;
    }
    
    .stats-bar {
        padding: var(--spacing-md);
    }
    
    .stat-value {
        font-size: var(--font-size-xl);
    }
    
    .camera-container {
        max-height: 50vh;
    }
    
    .items-list {
        max-height: 200px;
    }
    
    .bottom-nav {
        padding: var(--spacing-xs) 0;
    }
    
    .nav-item-icon {
        font-size: var(--font-size-lg);
    }
    
    .nav-item-label {
        display: none;
    }
}

/* High resolution screens (Retina displays) */
@media (-webkit-min-device-pixel-ratio: 2),
       (min-resolution: 192dpi) {
    .app-header {
        background: linear-gradient(135deg, var(--primary-color) 0%, var(--secondary-color) 100%);
        background-size: 200% 200%;
    }
    
    .btn {
        font-weight: 500;
    }
    
    .photo-thumb {
        border-width: 1px;
    }
}

/* Touch device optimizations */
@media (hover: none) and (pointer: coarse) {
    .action-card:active {
        transform: scale(0.95);
    }
    
    .btn:active {
        transform: scale(0.95);
    }
    
    .nav-item {
        padding: var(--spacing-sm) var(--spacing-xs);
    }
    
    .photo-thumb {
        min-width: 70px;
        height: 70px;
    }
    
    /* Increase touch target sizes */
    .toggle-switch {
        width: 54px;
        height: 30px;
    }
    
    .toggle-switch-handle {
        width: 24px;
        height: 24px;
    }
    
    .toggle-switch.active .toggle-switch-handle {
        transform: translateX(24px);
    }
}

/* Reduced motion preferences */
@media (prefers-reduced-motion: reduce) {
    * {
        animation-duration: 0.01ms !important;
        animation-iteration-count: 1 !important;
        transition-duration: 0.01ms !important;
        scroll-behavior: auto !important;
    }
}

/* Dark mode support */
@media (prefers-color-scheme: dark) {
    :root {
        --gray-50: #1F2937;
        --gray-100: #374151;
        --gray-200: #4B5563;
        --gray-300: #6B7280;
        --gray-400: #9CA3AF;
        --gray-500: #D1D5DB;
        --gray-600: #E5E7EB;
        --gray-700: #F3F4F6;
        --gray-800: #F9FAFB;
        --gray-900: #FFFFFF;
    }
    
    body {
        background: linear-gradient(135deg, #1F2937 0%, #111827 100%);
    }
    
    .app-container {
        background: #111827;
    }
    
    .action-card {
        background: #1F2937;
        box-shadow: 0 4px 20px rgba(0,0,0,0.3);
    }
    
    .stats-bar {
        background: linear-gradient(135deg, #1F2937 0%, #374151 100%);
    }
    
    .settings-panel {
        background: #1F2937;
    }
    
    .items-list {
        background: #1F2937;
    }
    
    .item-tag {
        background: #374151;
    }
    
    .search-input {
        background: #1F2937;
        color: white;
    }
    
    .results-container {
        background: #1F2937;
    }
    
    .result-card {
        background: #374151;
    }
    
    .modal-content {
        background: #1F2937;
    }
    
    .bottom-nav {
        background: #1F2937;
        border-top-color: #374151;
    }
    
    .qr-display {
        background: #1F2937;
    }
    
    #qrcode {
        background: white;
    }
}

/* Print styles */
@media print {
    .app-header,
    .bottom-nav,
    .action-buttons,
    .settings-panel {
        display: none !important;
    }
    
    .qr-display {
        box-shadow: none;
        border: 1px solid #000;
    }
    
    #qrcode {
        page-break-inside: avoid;
    }
}

/* Foldable device support */
@media (screen-spanning: single-fold-vertical) {
    .app-container {
        max-width: env(viewport-segment-width 0 0);
        margin: 0;
    }
}

/* Notch/Safe area support for modern phones */
.app-header {
    padding-top: max(var(--spacing-md), env(safe-area-inset-top));
}

.bottom-nav {
    padding-bottom: max(var(--spacing-sm), env(safe-area-inset-bottom));
}

.main-content {
    padding-left: max(var(--spacing-md), env(safe-area-inset-left));
    padding-right: max(var(--spacing-md), env(safe-area-inset-right));
}

/* Accessibility - Focus visible states */
@media (prefers-reduced-motion: no-preference) {
    :focus-visible {
        outline: 3px solid var(--primary-color);
        outline-offset: 2px;
    }
}

/* iOS specific fixes */
@supports (-webkit-touch-callout: none) {
    /* Prevent iOS bounce scroll */
    .app-container {
        position: fixed;
        width: 100%;
        height: 100%;
        overflow-y: auto;
        -webkit-overflow-scrolling: touch;
    }
    
    /* Fix for iOS input zoom */
    input, select, textarea {
        font-size: 16px !important;
    }
    
    /* iOS safe area adjustments */
    .bottom-nav {
        padding-bottom: calc(env(safe-area-inset-bottom) + 8px);
    }
}

/* Android specific fixes */
@media screen and (-webkit-min-device-pixel-ratio: 0) {
    select {
        background-image: url("data:image/svg+xml;charset=UTF-8,%3csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='currentColor' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'%3e%3cpolyline points='6 9 12 15 18 9'%3e%3c/polyline%3e%3c/svg%3e");
        background-repeat: no-repeat;
        background-position: right 0.5rem center;
        background-size: 1.5em 1.5em;
        padding-right: 2.5rem;
    }
}

/* Small phone specific (iPhone SE, etc) */
@media (max-width: 375px) {
    .app-header h1 {
        font-size: var(--font-size-xl);
    }
    
    .home-grid {
        grid-template-columns: 1fr;
    }
    
    .action-card {
        padding: var(--spacing-lg) var(--spacing-md);
    }
    
    .action-card-icon {
        font-size: 2.5rem;
    }
    
    .stat-value {
        font-size: var(--font-size-xl);
    }
    
    .photo-thumb {
        min-width: 60px;
        height: 60px;
    }
}

/* Tablet portrait specific */
@media (min-width: 768px) and (max-width: 991px) and (orientation: portrait) {
    .home-grid {
        grid-template-columns: repeat(2, 1fr);
        gap: var(--spacing-xl);
    }
    
    .camera-container {
        max-width: 100%;
    }
}

/* Tablet landscape specific */
@media (min-width: 768px) and (max-width: 991px) and (orientation: landscape) {
    .home-grid {
        grid-template-columns: repeat(4, 1fr);
    }
    
    .camera-container {
        max-height: 60vh;
    }
}
