/* Mobile Optimizations */
@media (max-width: 768px) {
    /* Base adjustments */
    body {
        font-size: 16px; /* Prevent zoom on iOS */
    }
    
    /* Auth screen mobile */
    .auth-container {
        padding: 1rem;
        justify-content: flex-start;
        padding-top: 10vh;
    }
    
    .app-header {
        margin-bottom: 3rem;
    }
    
    .app-icon {
        font-size: 3rem;
    }
    
    .app-header h1 {
        font-size: 1.8rem;
    }
    
    /* Dashboard mobile */
    .dashboard-content {
        padding: 1rem;
    }
    
    .lists-grid {
        grid-template-columns: 1fr;
        gap: 1rem;
    }
    
    .list-card {
        padding: 1.25rem;
    }
    
    /* FAB mobile positioning */
    .fab-container {
        bottom: 1rem;
        right: 1rem;
    }
    
    .fab {
        width: 60px;
        height: 60px;
        font-size: 1.8rem;
    }
    
    /* Modal mobile */
    .modal {
        padding: 0.5rem;
        align-items: flex-end;
    }
    
    .modal-content {
        border-radius: 16px 16px 0 0;
        max-height: 80vh;
        width: 100%;
        margin: 0;
    }
    
    /* Create options mobile */
    .create-option {
        padding: 1.25rem;
    }
    
    .option-icon {
        font-size: 2.5rem;
    }
    
    .option-text strong {
        font-size: 1.1rem;
    }
    
    /* List detail mobile */
    .list-header {
        padding: 1rem;
    }
    
    .list-header h2 {
        font-size: 1.2rem;
    }
    
    .total-value {
        font-size: 1rem;
    }
    
    .list-content {
        padding: 0 1rem;
        margin-bottom: 100px; /* Space for add section */
    }
    
    /* Items mobile */
    .item-card {
        display: flex;
        align-items: center;
        justify-content: space-between;
        gap: 0.5rem;
        padding: 0.5rem;
        border-radius: 8px;
        border: 1px solid var(--border);
        background: var(--surface);
        transition: all 0.2s;
        margin-bottom: 0.5rem;
        overflow-x: hidden;
        min-width: 0;
        -webkit-tap-highlight-color: transparent;
        touch-action: manipulation;
    }

    .item-name-input {
        flex: 1;
        font-size: 16px;
        color: var(--text-primary);
        background: transparent;
        border: none;
        outline: none;
        padding: 0;
        width: 100%;
        text-align: left;
        min-width: 0;
    }

    .item-price-input {
        flex: 0 0 auto;
        padding: 0.3rem 0.5rem;
        border: 1px solid var(--primary);
        border-radius: 4px;
        background: var(--surface-light);
        color: var(--success);
        font-weight: 500;
        text-align: center;
        width: 33%;
        font-size: 14px;
        min-width: 50px;
    }

    .btn-icons {
        display: flex;
        gap: 0.3rem;
    }

    .btn-icon {
        width: 28px;
        height: 28px;
        border: none;
        border-radius: 50%;
        background: var(--surface-light);
        color: var(--text-secondary);
        cursor: pointer;
        display: flex;
        align-items: center;
        justify-content: center;
        font-size: 14px;
        transition: background-color 0.2s;
    }

    .btn-icon:hover {
        background: var(--primary-dark);
        color: white;
    }

    .btn-icon.disabled {
        opacity: 0.5;
        cursor: not-allowed;
    }
    
    /* Add item section mobile */
    .add-item-section {
        padding: 1rem;
        position: fixed;
        bottom: 0;
        left: 0;
        right: 0;
        box-shadow: 0 -2px 10px var(--shadow);
        background: var(--surface);
        border-top: 1px solid var(--border);
    }
    
    .add-item-form .form-row {
        display: flex;
        gap: 0.5rem;
        flex-wrap: wrap;
        width: 100%;
    }
    
    #item-name,
    #item-price {
        flex: 1;
        min-width: 0;
        border: 1px solid var(--border);
        border-radius: 6px;
        padding: 0.5rem;
        font-size: 14px;
        background-color: var(--surface-light);
        color: var(--text-primary);
    }
    
    #add-item-btn {
        min-width: 40px;
        height: 40px;
        border-radius: 50%;
        padding: 0;
        font-size: 1.2rem;
        background-color: var(--primary);
        color: white;
        border: none;
        cursor: pointer;
        transition: background-color 0.2s;
    }
    
    #add-item-btn:hover {
        background-color: var(--primary-dark);
    }
    
    /* Touch improvements */
    .list-card,
    .item-card,
    .create-option,
    .add-option,
    .btn-primary,
    .btn-secondary,
    .fab {
        -webkit-tap-highlight-color: transparent;
        touch-action: manipulation;
    }
    
    /* Prevent horizontal scroll */
    .modal-content,
    .add-item-section,
    .list-content {
        overflow-x: hidden;
    }
    
    /* Safe area for notched devices */
    @supports (padding: max(0px)) {
        .app-header-small,
        .list-header {
            padding-top: max(1rem, env(safe-area-inset-top));
        }
        
        .add-item-section {
            padding-bottom: max(1.5rem, env(safe-area-inset-bottom));
        }
        
        .fab-container {
            bottom: max(1rem, env(safe-area-inset-bottom));
            right: max(1rem, env(safe-area-inset-right));
        }
    }
}

/* Small mobile devices */
@media (max-width: 375px) {
    .auth-container {
        padding: 0.75rem;
    }
    
    .dashboard-content {
        padding: 0.75rem;
    }
    
    .list-card {
        padding: 1rem;
    }
    
    .item-card {
        padding: 0.5rem;
        gap: 0.3rem;
    }

    .item-name-input {
        font-size: 14px;
    }

    .btn-icon {
        width: 24px;
        height: 24px;
        font-size: 12px;
    }
    
    .add-item-section {
        padding: 1rem 0.75rem;
    }
    
    .modal-content {
        padding: 1.5rem;
    }
}

/* Landscape mobile */
@media (max-width: 768px) and (orientation: landscape) {
    .auth-container {
        padding-top: 2vh;
        justify-content: center;
    }
    
    .app-header {
        margin-bottom: 1.5rem;
    }
    
    .app-icon {
        font-size: 2.5rem;
    }
    
    .modal {
        align-items: center;
    }
    
    .modal-content {
        border-radius: 16px;
        max-height: 85vh;
    }
}

/* High DPI displays */
@media (-webkit-min-device-pixel-ratio: 2), (min-resolution: 192dpi) {
    .loading-spinner {
        border-width: 2px;
    }
    
    .item-checkbox,
    .form-group input,
    .btn-primary,
    .btn-secondary {
        border-width: 1px;
    }
}

/* Dark mode adjustments for mobile */
@media (prefers-color-scheme: dark) {
    /* Already using dark theme, but ensure proper contrast on mobile */
    .form-group input,
    .form-row input {
        background: var(--background);
        border-color: var(--border);
    }
    
    .item-card,
    .list-card {
        background: var(--surface);
        border-color: var(--border);
    }
}

/* Reduced motion */
@media (prefers-reduced-motion: reduce) {
    *,
    *::before,
    *::after {
        animation-duration: 0.01ms !important;
        animation-iteration-count: 1 !important;
        transition-duration: 0.01ms !important;
    }
    
    .loading-spinner {
        animation: none;
        border-top-color: var(--primary);
    }
}