/**
 * Nutrition AI Assistant Styles
 * 
 * Zyra Brand Book Styles:
 * - Zyra Blue: #0077FF (Primary)
 * - Jet Black: #1A1A1A (Background/text)
 * - Glow Teal: #00FFC6 (Accent)
 * - Soft Gray: #EAEAEA (Dividers)
 * 
 * Typography:
 * - Headers: Montserrat Bold
 * - Body: Inter
 * - Numbers: Roboto Mono
 */

/* CSS Variables */
:root {
    --zyra-blue: #0077FF;
    --zyra-blue-dark: #0066DD;
    --zyra-blue-light: #339AFF;
    --jet-black: #1A1A1A;
    --glow-teal: #00FFC6;
    --glow-teal-dim: rgba(0, 255, 198, 0.2);
    --soft-gray: #EAEAEA;
    --dark-gray: #2D2D2D;
    --medium-gray: #3D3D3D;
    --text-secondary: #8A8A8A;
    
    --font-heading: 'Montserrat', sans-serif;
    --font-body: 'Inter', sans-serif;
    --font-mono: 'Roboto Mono', monospace;
    
    --radius-sm: 8px;
    --radius-md: 12px;
    --radius-lg: 16px;
    --radius-xl: 24px;
    --radius-full: 9999px;
    
    --shadow-sm: 0 2px 8px rgba(0, 0, 0, 0.3);
    --shadow-md: 0 4px 16px rgba(0, 0, 0, 0.4);
    --shadow-lg: 0 8px 32px rgba(0, 0, 0, 0.5);
    --shadow-glow: 0 0 20px rgba(0, 119, 255, 0.4);
    --shadow-teal-glow: 0 0 20px rgba(0, 255, 198, 0.3);
}

/* Container */
.nutrition-ai-container {
    max-width: 600px;
    margin: 0 auto;
    padding: 20px;
    min-height: 100vh;
    background: linear-gradient(180deg, var(--jet-black) 0%, #0D0D0D 100%);
    font-family: var(--font-body);
    color: #FFFFFF;
}

/* Header */
.ai-header {
    margin-bottom: 32px;
    text-align: center;
}

.header-content {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 16px;
}

.header-icon {
    width: 48px;
    height: 48px;
    background: linear-gradient(135deg, var(--zyra-blue) 0%, var(--glow-teal) 100%);
    border-radius: var(--radius-md);
    display: flex;
    align-items: center;
    justify-content: center;
    color: white;
}

.header-icon svg {
    width: 28px;
    height: 28px;
}

.header-text h1 {
    font-family: var(--font-heading);
    font-size: 28px;
    font-weight: 700;
    margin: 0;
    letter-spacing: -0.5px;
}

.header-text h1 .accent {
    color: var(--glow-teal);
}

.header-text p {
    font-size: 14px;
    color: var(--text-secondary);
    margin: 4px 0 0;
}

/* Input Section */
.input-section {
    margin-bottom: 24px;
}

/* Voice Button */
.voice-input-container {
    display: flex;
    flex-direction: column;
    align-items: center;
    margin-bottom: 24px;
}

.voice-button {
    width: 120px;
    height: 120px;
    border-radius: 50%;
    border: 3px solid var(--zyra-blue);
    background: linear-gradient(145deg, var(--dark-gray) 0%, var(--jet-black) 100%);
    cursor: pointer;
    transition: all 0.3s ease;
    position: relative;
    overflow: hidden;
}

.voice-button:hover {
    border-color: var(--zyra-blue-light);
    box-shadow: var(--shadow-glow);
    transform: scale(1.02);
}

.voice-button.recording {
    border-color: var(--glow-teal);
    box-shadow: var(--shadow-teal-glow);
    animation: pulse-recording 1.5s ease-in-out infinite;
}

@keyframes pulse-recording {
    0%, 100% { transform: scale(1); }
    50% { transform: scale(1.05); }
}

.voice-button-inner {
    width: 100%;
    height: 100%;
    display: flex;
    align-items: center;
    justify-content: center;
}

.mic-icon {
    width: 40px;
    height: 40px;
    color: var(--zyra-blue);
    transition: color 0.3s ease;
}

.voice-button.recording .mic-icon {
    color: var(--glow-teal);
}

.recording-indicator {
    display: none;
    gap: 4px;
}

.voice-button.recording .mic-icon {
    display: none;
}

.voice-button.recording .recording-indicator {
    display: flex;
}

.recording-indicator span {
    width: 6px;
    height: 24px;
    background: var(--glow-teal);
    border-radius: 3px;
    animation: wave 0.8s ease-in-out infinite;
}

.recording-indicator span:nth-child(2) {
    animation-delay: 0.1s;
}

.recording-indicator span:nth-child(3) {
    animation-delay: 0.2s;
}

@keyframes wave {
    0%, 100% { height: 8px; }
    50% { height: 32px; }
}

.voice-hint {
    font-size: 14px;
    color: var(--text-secondary);
    margin: 12px 0 0;
}

.voice-status {
    font-size: 13px;
    color: var(--glow-teal);
    margin: 8px 0 0;
    min-height: 20px;
}

/* Text Input */
.text-input-container {
    margin-bottom: 16px;
}

.input-wrapper {
    display: flex;
    gap: 8px;
    background: var(--dark-gray);
    border-radius: var(--radius-lg);
    padding: 4px;
    border: 1px solid var(--medium-gray);
    transition: border-color 0.2s ease;
}

.input-wrapper:focus-within {
    border-color: var(--zyra-blue);
}

#textInput {
    flex: 1;
    background: transparent;
    border: none;
    padding: 12px 16px;
    font-size: 16px;
    color: #FFFFFF;
    font-family: var(--font-body);
}

#textInput::placeholder {
    color: var(--text-secondary);
}

#textInput:focus {
    outline: none;
}

.submit-btn {
    width: 48px;
    height: 48px;
    border-radius: var(--radius-md);
    border: none;
    background: var(--zyra-blue);
    color: white;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all 0.2s ease;
}

.submit-btn:hover {
    background: var(--zyra-blue-dark);
}

.submit-btn svg {
    width: 20px;
    height: 20px;
}

/* Photo Buttons */
.photo-buttons {
    display: flex;
    gap: 12px;
}

.photo-btn {
    flex: 1;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    padding: 14px 16px;
    background: var(--dark-gray);
    border: 1px solid var(--medium-gray);
    border-radius: var(--radius-md);
    color: var(--text-secondary);
    font-size: 14px;
    font-family: var(--font-body);
    cursor: pointer;
    transition: all 0.2s ease;
}

.photo-btn:hover {
    border-color: var(--zyra-blue);
    color: var(--zyra-blue);
}

.photo-btn svg {
    width: 20px;
    height: 20px;
}

.hidden-input {
    display: none;
}

/* Meal Settings */
.meal-settings {
    display: flex;
    gap: 16px;
    margin-bottom: 24px;
}

.setting-group {
    flex: 1;
}

.setting-group label {
    display: block;
    font-size: 12px;
    color: var(--text-secondary);
    margin-bottom: 6px;
    text-transform: uppercase;
    letter-spacing: 0.5px;
}

.setting-group select,
.setting-group input[type="date"] {
    width: 100%;
    padding: 12px 14px;
    background: var(--dark-gray);
    border: 1px solid var(--medium-gray);
    border-radius: var(--radius-md);
    color: #FFFFFF;
    font-size: 15px;
    font-family: var(--font-body);
    cursor: pointer;
}

.setting-group select:focus,
.setting-group input[type="date"]:focus {
    outline: none;
    border-color: var(--zyra-blue);
}

/* Results Section */
.results-section {
    margin-top: 24px;
}

.results-section.hidden {
    display: none;
}

.results-header {
    margin-bottom: 16px;
}

.results-header h2 {
    font-family: var(--font-heading);
    font-size: 20px;
    font-weight: 600;
    margin: 0 0 8px;
}

.transcription-text {
    font-size: 14px;
    color: var(--text-secondary);
    font-style: italic;
    background: var(--dark-gray);
    padding: 10px 14px;
    border-radius: var(--radius-sm);
    border-left: 3px solid var(--glow-teal);
}

/* Items Container */
.items-container {
    display: flex;
    flex-direction: column;
    gap: 12px;
    margin-bottom: 20px;
}

/* Item Card */
.item-card {
    background: var(--dark-gray);
    border-radius: var(--radius-lg);
    padding: 16px;
    border: 1px solid var(--medium-gray);
    transition: border-color 0.2s ease;
}

.item-card:hover {
    border-color: var(--zyra-blue);
}

.item-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 12px;
}

.match-badge {
    display: inline-flex;
    align-items: center;
    gap: 4px;
    padding: 4px 10px;
    border-radius: var(--radius-full);
    font-size: 11px;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.5px;
}

.match-badge.exact {
    background: rgba(0, 255, 198, 0.15);
    color: var(--glow-teal);
}

.match-badge.suggestion {
    background: rgba(0, 119, 255, 0.15);
    color: var(--zyra-blue-light);
}

.match-badge.new {
    background: rgba(255, 193, 7, 0.15);
    color: #FFC107;
}

.confidence-indicator {
    width: 8px;
    height: 8px;
    border-radius: 50%;
}

.confidence-indicator.high {
    background: var(--glow-teal);
}

.confidence-indicator.medium {
    background: var(--zyra-blue);
}

.confidence-indicator.low {
    background: #FFC107;
}

.original-text {
    font-size: 12px;
    color: var(--text-secondary);
    margin: 0 0 6px;
}

.original-text::before {
    content: '"';
}

.original-text::after {
    content: '"';
}

.item-name {
    font-family: var(--font-heading);
    font-size: 18px;
    font-weight: 600;
    margin: 0 0 12px;
    color: #FFFFFF;
}

/* Match Selector */
.match-selector {
    margin-bottom: 12px;
}

.match-selector.hidden {
    display: none;
}

.match-selector label {
    display: block;
    font-size: 12px;
    color: var(--text-secondary);
    margin-bottom: 6px;
}

.match-dropdown {
    width: 100%;
    padding: 10px 12px;
    background: var(--jet-black);
    border: 1px solid var(--medium-gray);
    border-radius: var(--radius-sm);
    color: #FFFFFF;
    font-size: 14px;
}

/* Saving As Indicator - shows canonical entity that will be saved */
/* Parsed As (raw input display) */
.parsed-as {
    display: flex;
    align-items: center;
    gap: 8px;
    margin-bottom: 8px;
    font-size: 12px;
}

.parsed-as-label {
    color: var(--text-secondary);
    text-transform: uppercase;
}

.parsed-as-value {
    color: #AAA;
    font-style: italic;
}

/* Keep AI / None of these button */
.keep-ai-btn {
    background: transparent;
    border: 1px solid var(--glow-teal);
    color: var(--glow-teal);
    padding: 6px 12px;
    border-radius: var(--radius-sm);
    font-size: 12px;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.2s;
    white-space: nowrap;
    margin-left: 8px;
}

.keep-ai-btn:hover {
    background: rgba(0, 255, 198, 0.15);
}

.keep-ai-btn.active {
    background: var(--glow-teal);
    color: var(--jet-black);
}

/* Search Again Section */
.search-again-section {
    margin-top: 12px;
    margin-bottom: 12px;
}

.search-input-row {
    display: flex;
    gap: 8px;
}

.search-input {
    flex: 1;
    background: var(--dark-gray);
    border: 1px solid var(--medium-gray);
    border-radius: var(--radius-sm);
    padding: 8px 12px;
    color: white;
    font-size: 14px;
}

.search-input:focus {
    outline: none;
    border-color: var(--zyra-blue);
}

.search-btn {
    background: var(--zyra-blue);
    border: none;
    border-radius: var(--radius-sm);
    padding: 8px 12px;
    color: white;
    cursor: pointer;
    transition: background 0.2s;
}

.search-btn:hover {
    background: var(--zyra-blue-dark);
}

.search-results {
    margin-top: 8px;
    background: var(--dark-gray);
    border-radius: var(--radius-sm);
    max-height: 200px;
    overflow-y: auto;
}

.search-result-item {
    padding: 10px 12px;
    border-bottom: 1px solid var(--medium-gray);
    cursor: pointer;
    transition: background 0.2s;
}

.search-result-item:hover {
    background: var(--medium-gray);
}

.search-result-item:last-child {
    border-bottom: none;
}

.search-result-name {
    font-weight: 500;
    margin-bottom: 2px;
}

.search-result-nutrition {
    font-size: 12px;
    color: var(--text-secondary);
}

/* Nutrition Source Badge - positioned as label above macros */
.nutrition-source-badge {
    display: inline-block;
    font-size: 10px;
    font-weight: 600;
    text-transform: uppercase;
    padding: 3px 8px;
    border-radius: 4px;
    background: rgba(0, 255, 198, 0.2);
    color: var(--glow-teal);
    margin-bottom: 8px;
}

.nutrition-source-badge.from-db {
    background: rgba(0, 119, 255, 0.2);
    color: var(--zyra-blue);
}

/* Nutrition Container - wraps badge + macros */
.nutrition-preview {
    display: flex;
    flex-direction: column;
}

/* Resolution Options (for NEW items) */
.resolution-options {
    margin-top: 12px;
    padding-top: 12px;
    border-top: 1px solid var(--medium-gray);
}

.resolution-option {
    margin-bottom: 8px;
}

.radio-label {
    display: flex;
    align-items: center;
    gap: 10px;
    cursor: pointer;
    font-size: 13px;
    color: #CCC;
}

.radio-label:hover {
    color: white;
}

.resolution-radio {
    width: 16px;
    height: 16px;
    accent-color: var(--glow-teal);
}

.saving-as-indicator {
    background: linear-gradient(135deg, rgba(0, 119, 255, 0.15) 0%, rgba(0, 255, 198, 0.1) 100%);
    border: 1px solid var(--zyra-blue);
    border-radius: var(--radius-sm);
    padding: 10px 12px;
    margin-bottom: 14px;
    display: flex;
    align-items: center;
    gap: 8px;
}

.saving-as-label {
    font-size: 12px;
    color: var(--text-secondary);
    text-transform: uppercase;
    white-space: nowrap;
}

.saving-as-value {
    font-size: 14px;
    font-weight: 600;
    color: var(--glow-teal);
    flex: 1;
}

.saving-as-indicator.is-new {
    border-color: var(--glow-teal);
    background: linear-gradient(135deg, rgba(0, 255, 198, 0.15) 0%, rgba(0, 119, 255, 0.1) 100%);
}

.saving-as-indicator.is-new .saving-as-value {
    color: var(--glow-teal);
}

.saving-as-indicator.is-new::before {
    content: '+ NEW:';
    font-size: 11px;
    font-weight: 700;
    color: var(--glow-teal);
    background: rgba(0, 255, 198, 0.2);
    padding: 2px 6px;
    border-radius: 4px;
    margin-right: 4px;
}

/* Quantity Row */
.quantity-row {
    display: flex;
    gap: 12px;
    margin-bottom: 14px;
}

.quantity-input,
.unit-input {
    flex: 1;
}

.quantity-input label,
.unit-input label {
    display: block;
    font-size: 11px;
    color: var(--text-secondary);
    margin-bottom: 4px;
    text-transform: uppercase;
}

.qty-input,
.unit-dropdown {
    width: 100%;
    padding: 10px 12px;
    background: var(--jet-black);
    border: 1px solid var(--medium-gray);
    border-radius: var(--radius-sm);
    color: #FFFFFF;
    font-family: var(--font-mono);
    font-size: 15px;
}

.qty-input:focus,
.unit-dropdown:focus {
    outline: none;
    border-color: var(--zyra-blue);
}

/* Nutrition Preview - stacked: badge then macro row */
.nutrition-preview {
    display: flex;
    flex-direction: column;
    gap: 8px;
}

/* Macro Row - horizontal flex container */
.macro-row {
    display: flex;
    gap: 8px;
    width: 100%;
}

.macro {
    flex: 1;
    min-width: 0; /* Allow shrinking */
    text-align: center;
    padding: 10px 6px;
    background: var(--jet-black);
    border-radius: var(--radius-sm);
}

.macro .value {
    display: block;
    font-family: var(--font-mono);
    font-size: 16px;
    font-weight: 500;
    color: #FFFFFF;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.macro .label {
    display: block;
    font-size: 10px;
    color: var(--text-secondary);
    text-transform: uppercase;
    margin-top: 2px;
}

/* Special styling for kcal */
.macro .kcal-value {
    color: var(--glow-teal);
}

/* Create New Option */
.create-new-option {
    margin-top: 12px;
    padding-top: 12px;
    border-top: 1px solid var(--medium-gray);
}

.create-new-option.hidden {
    display: none;
}

/* Checkbox Label */
.checkbox-label {
    display: flex;
    align-items: center;
    gap: 10px;
    cursor: pointer;
    font-size: 14px;
    color: var(--text-secondary);
}

.checkbox-label input[type="checkbox"] {
    display: none;
}

.checkmark {
    width: 20px;
    height: 20px;
    border: 2px solid var(--medium-gray);
    border-radius: 4px;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all 0.2s ease;
}

.checkbox-label input:checked + .checkmark {
    background: var(--zyra-blue);
    border-color: var(--zyra-blue);
}

.checkbox-label input:checked + .checkmark::after {
    content: '✓';
    color: white;
    font-size: 12px;
}

/* Results Actions */
.results-actions {
    display: flex;
    flex-direction: column;
    gap: 16px;
    padding-top: 16px;
    border-top: 1px solid var(--medium-gray);
}

.save-options {
    display: flex;
    align-items: center;
    gap: 12px;
}

.recipe-name-input {
    flex: 1;
    padding: 10px 14px;
    background: var(--jet-black);
    border: 1px solid var(--medium-gray);
    border-radius: var(--radius-sm);
    color: #FFFFFF;
    font-size: 14px;
}

.recipe-name-input.hidden {
    display: none;
}

.recipe-name-input:focus {
    outline: none;
    border-color: var(--zyra-blue);
}

.action-buttons {
    display: flex;
    gap: 12px;
}

.btn-secondary {
    flex: 1;
    padding: 14px 24px;
    background: var(--dark-gray);
    border: 1px solid var(--medium-gray);
    border-radius: var(--radius-md);
    color: var(--text-secondary);
    font-size: 15px;
    font-weight: 500;
    cursor: pointer;
    transition: all 0.2s ease;
}

.btn-secondary:hover {
    border-color: var(--zyra-blue);
    color: #FFFFFF;
}

.btn-primary {
    flex: 2;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    padding: 14px 24px;
    background: linear-gradient(135deg, var(--zyra-blue) 0%, var(--zyra-blue-dark) 100%);
    border: none;
    border-radius: var(--radius-md);
    color: #FFFFFF;
    font-size: 15px;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.2s ease;
}

.btn-primary:hover {
    box-shadow: var(--shadow-glow);
    transform: translateY(-1px);
}

.btn-primary svg {
    width: 18px;
    height: 18px;
}

/* Loading State */
.loading-state {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    padding: 48px 20px;
}

.loading-state.hidden {
    display: none;
}

.loading-spinner {
    width: 48px;
    height: 48px;
    border: 3px solid var(--dark-gray);
    border-top-color: var(--zyra-blue);
    border-radius: 50%;
    animation: spin 1s linear infinite;
}

@keyframes spin {
    to { transform: rotate(360deg); }
}

.loading-state p {
    margin-top: 16px;
    color: var(--text-secondary);
}

/* Toast Notification */
.toast {
    position: fixed;
    bottom: 24px;
    left: 50%;
    transform: translateX(-50%) translateY(100px);
    padding: 14px 24px;
    border-radius: var(--radius-md);
    font-size: 14px;
    font-weight: 500;
    z-index: 1000;
    transition: transform 0.3s ease;
}

.toast.show {
    transform: translateX(-50%) translateY(0);
}

.toast.hidden {
    transform: translateX(-50%) translateY(100px);
}

.toast.success {
    background: var(--glow-teal);
    color: var(--jet-black);
}

.toast.error {
    background: #FF4757;
    color: #FFFFFF;
}

.toast.warning {
    background: #FFC107;
    color: var(--jet-black);
}

/* Toast with action button */
.toast.with-action {
    display: flex;
    align-items: center;
    gap: 16px;
    padding: 12px 20px;
}

.toast-action {
    display: inline-block;
    padding: 6px 12px;
    background: rgba(0, 0, 0, 0.2);
    border-radius: var(--radius-sm);
    color: inherit;
    text-decoration: none;
    font-weight: 600;
    white-space: nowrap;
    transition: background 0.2s ease;
}

.toast-action:hover {
    background: rgba(0, 0, 0, 0.3);
}

/* Utility */
.hidden {
    display: none !important;
}

/* ==========================================================================
   MOBILE LAYOUT STABILITY - iPhone 16 Optimized
   ========================================================================== */

/* Mobile page shell structure */
@media (max-width: 768px) {
    .nutrition-ai-container {
        display: flex;
        flex-direction: column;
        min-height: 100vh;
        min-height: 100dvh;
        min-height: -webkit-fill-available;
        padding: 16px;
        padding-bottom: calc(16px + env(safe-area-inset-bottom));
        overflow-x: hidden;
    }
    
    /* Results section - REMOVED height constraints that cause Safari issues */
    .results-section {
        flex: 1 1 auto;
        display: flex;
        flex-direction: column;
        overflow: visible; /* Changed from hidden */
    }
    
    /* Scrollable items container - more flexible height */
    .items-container {
        flex: 1 1 auto;
        overflow-y: auto;
        overflow-x: hidden;
        -webkit-overflow-scrolling: touch;
        overscroll-behavior: contain;
        padding-right: 4px;
        margin-bottom: 16px;
        /* Removed max-height constraints that cause Safari collapsing */
    }
    
    /* Sticky action bar at bottom */
    .results-actions {
        flex-shrink: 0;
        position: sticky;
        bottom: 0;
        background: var(--jet-black);
        padding: 16px 0;
        padding-bottom: calc(16px + env(safe-area-inset-bottom));
        margin: 0 -16px;
        padding-left: 16px;
        padding-right: 16px;
        border-top: 1px solid var(--medium-gray);
    }
    
    /* Prevent voice button jump after transcription */
    .voice-input-container {
        min-height: 180px;
        display: flex;
        flex-direction: column;
        align-items: center;
        justify-content: center;
    }
    
    .voice-button {
        flex-shrink: 0;
    }
    
    /* Text overflow guards for food names */
    .item-header .item-title {
        white-space: nowrap;
        overflow: hidden;
        text-overflow: ellipsis;
        max-width: 100%;
    }
    
    .item-card .item-name,
    .item-card .match-name {
        white-space: normal; /* Allow wrapping instead of truncating */
        word-wrap: break-word;
        overflow-wrap: break-word;
    }
    
    /* Item cards - CRITICAL: ensure content is visible */
    .item-card {
        max-width: 100%;
        overflow: visible; /* Changed from hidden - prevents content collapse on Safari */
        padding: 12px;
        display: block; /* Ensure block display */
        min-height: auto; /* Allow natural height */
    }
    
    /* Ensure item content is visible */
    .item-content {
        display: block;
        overflow: visible;
        width: 100%;
    }
    
    /* Ensure all child elements are visible */
    .item-card .parsed-as,
    .item-card .item-name,
    .item-card .saving-as-indicator,
    .item-card .quantity-row,
    .item-card .nutrition-preview,
    .item-card .match-selector,
    .item-card .search-again-section {
        display: flex;
        visibility: visible;
        opacity: 1;
    }
    
    .item-card .item-name {
        display: block;
    }
    
    .results-header {
        margin-bottom: 12px;
    }
    
    /* Dropdowns don't cause reflow */
    .match-dropdown,
    select {
        max-width: 100%;
    }
    
    /* Macro row - ensure horizontal layout on mobile */
    .macro-row {
        display: flex !important;
        flex-direction: row !important;
        flex-wrap: nowrap;
        width: 100%;
    }
    
    .macro {
        flex: 1 1 0;
        min-width: 0;
    }
}

/* Responsive - narrower screens (mobile phones) */
@media (max-width: 480px) {
    .nutrition-ai-container {
        padding: 12px;
        padding-bottom: calc(12px + env(safe-area-inset-bottom));
    }
    
    .header-content {
        flex-direction: column;
        text-align: center;
    }
    
    .voice-button {
        width: 100px;
        height: 100px;
    }
    
    .photo-buttons {
        flex-direction: column;
    }
    
    .meal-settings {
        flex-direction: column;
    }
    
    .action-buttons {
        flex-direction: column;
    }
    
    .btn-primary,
    .btn-secondary {
        flex: none;
        width: 100%;
        min-height: 48px;
    }
    
    /* Compact mode but ensure visibility */
    .item-card {
        padding: 10px;
        overflow: visible; /* Ensure content doesn't collapse */
    }
    
    /* Allow food names to wrap naturally */
    .item-card .item-name,
    .item-card .match-name {
        white-space: normal;
        word-wrap: break-word;
        overflow-wrap: break-word;
        max-width: 100%;
    }
    
    /* Macro row compact - smaller gaps and padding */
    .macro-row {
        display: flex !important;
        flex-direction: row !important;
        gap: 4px;
    }
    
    .macro {
        flex: 1 1 0;
        min-width: 0;
        padding: 8px 4px;
    }
    
    .macro .value {
        font-size: 14px;
    }
    
    .macro .label {
        font-size: 9px;
    }
    
    /* Nutrition badge compact */
    .nutrition-source-badge {
        font-size: 9px;
        padding: 2px 6px;
    }
    
    /* Quantity row - ensure horizontal layout */
    .quantity-row {
        display: flex;
        flex-direction: row;
        gap: 8px;
    }
    
    .quantity-input,
    .unit-input {
        flex: 1;
    }
    
    .qty-input,
    .unit-dropdown {
        padding: 8px 10px;
        font-size: 14px;
        width: 100%;
    }
    
    /* Saving as indicator compact */
    .saving-as-indicator {
        display: flex;
        padding: 8px 10px;
        margin-bottom: 10px;
    }
    
    .saving-as-value {
        font-size: 13px;
    }
    
    /* Nutrition preview - ensure visible */
    .nutrition-preview {
        display: flex;
        flex-direction: column;
        width: 100%;
    }
}

/* ===================================
   NUTRITION LABEL MODAL (2 images)
   =================================== */

.label-modal {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(0, 0, 0, 0.85);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 1000;
    padding: 20px;
}

.label-modal.hidden {
    display: none;
}

.label-modal-content {
    background: var(--dark-gray);
    border-radius: var(--radius-lg);
    max-width: 500px;
    width: 100%;
    max-height: 90vh;
    overflow-y: auto;
    box-shadow: var(--shadow-lg);
    border: 1px solid var(--medium-gray);
}

.label-modal-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 16px 20px;
    border-bottom: 1px solid var(--medium-gray);
}

.label-modal-header h3 {
    font-family: var(--font-heading);
    font-size: 1.1rem;
    color: white;
    margin: 0;
}

.close-modal-btn {
    background: none;
    border: none;
    color: var(--text-secondary);
    font-size: 24px;
    cursor: pointer;
    padding: 0;
    width: 32px;
    height: 32px;
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: var(--radius-sm);
    transition: all 0.2s;
}

.close-modal-btn:hover {
    color: white;
    background: var(--medium-gray);
}

.label-modal-body {
    padding: 20px;
}

.label-instructions {
    color: var(--text-secondary);
    font-size: 0.9rem;
    margin-bottom: 20px;
    line-height: 1.5;
}

.label-upload-grid {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 16px;
}

.label-upload-card {
    background: var(--jet-black);
    border: 2px dashed var(--medium-gray);
    border-radius: var(--radius-md);
    padding: 20px;
    cursor: pointer;
    transition: all 0.2s;
    position: relative;
    min-height: 150px;
    display: flex;
    align-items: center;
    justify-content: center;
}

.label-upload-card:hover {
    border-color: var(--zyra-blue);
    background: rgba(0, 119, 255, 0.05);
}

.label-upload-card.has-image {
    border-style: solid;
    border-color: var(--glow-teal);
    padding: 8px;
}

.upload-placeholder {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 8px;
    color: var(--text-secondary);
}

.upload-placeholder svg {
    width: 40px;
    height: 40px;
    opacity: 0.6;
}

.upload-placeholder span {
    font-size: 0.9rem;
    font-weight: 500;
}

.upload-placeholder small {
    font-size: 0.75rem;
    opacity: 0.7;
}

.upload-preview {
    width: 100%;
    height: 100%;
    object-fit: contain;
    max-height: 200px;
    border-radius: var(--radius-sm);
}

.upload-preview.hidden {
    display: none;
}

.label-modal-footer {
    display: flex;
    justify-content: flex-end;
    gap: 12px;
    padding: 16px 20px;
    border-top: 1px solid var(--medium-gray);
}

/* Add to Database Button */
.btn-database {
    color: var(--glow-teal) !important;
    border-color: var(--glow-teal) !important;
}

.btn-database:hover {
    background: rgba(0, 255, 198, 0.1) !important;
}

.btn-database svg {
    width: 18px;
    height: 18px;
}

/* Responsive for modal */
@media (max-width: 480px) {
    .label-upload-grid {
        grid-template-columns: 1fr;
    }
    
    .label-modal-footer {
        flex-direction: column;
    }
    
    .label-modal-footer button {
        width: 100%;
    }
}

