* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

body {
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
    line-height: 1.5;
    color: #1a1a1a;
    background: #fafafa;
    min-height: 100vh;
    overflow-x: hidden;
    -webkit-overflow-scrolling: touch;
}

html {
    overflow-x: hidden;
}

.hidden {
    display: none !important;
}

/* Onboarding */
.onboarding {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100vh;
    height: 100dvh; /* Dynamic viewport height for mobile */
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 20px;
    z-index: 2000;
    overflow-y: auto;
    -webkit-overflow-scrolling: touch;
}

.onboarding-card {
    background: white;
    border-radius: 24px;
    padding: 40px;
    max-width: 600px;
    width: 100%;
    box-shadow: 0 20px 60px rgba(0, 0, 0, 0.3);
    margin: auto;
}

.onboarding-card h1 {
    font-size: 2rem;
    margin-bottom: 12px;
    text-align: center;
}

.onboarding-card > p {
    text-align: center;
    color: #666;
    margin-bottom: 32px;
}

.allergen-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(140px, 1fr));
    gap: 12px;
    margin: 20px 0;
}

.allergen-option {
    display: flex;
    flex-direction: column;
    align-items: center;
    padding: 20px;
    background: #f8f8f8;
    border: 2px solid #e0e0e0;
    border-radius: 16px;
    cursor: pointer;
    transition: all 0.2s;
    -webkit-tap-highlight-color: transparent;
    touch-action: manipulation;
    min-height: 100px;
}

.allergen-option:active {
    border-color: #667eea;
    transform: scale(0.98);
}

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

.allergen-option input[type="checkbox"]:checked + .allergen-icon {
    transform: scale(1.2);
}

.allergen-option input[type="checkbox"]:checked ~ span {
    color: #667eea;
    font-weight: 600;
}

.allergen-option:has(input:checked) {
    background: #f0f4ff;
    border-color: #667eea;
}

.allergen-icon {
    font-size: 2.5rem;
    margin-bottom: 8px;
    transition: transform 0.2s;
}

.form-group {
    margin-bottom: 24px;
}

label {
    display: block;
    margin-bottom: 8px;
    font-weight: 500;
    color: #1a1a1a;
}

select {
    width: 100%;
    padding: 12px;
    border: 2px solid #e0e0e0;
    border-radius: 12px;
    font-size: 16px;
    font-family: inherit;
    -webkit-appearance: none;
    appearance: none;
    background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='12' viewBox='0 0 12 12'%3E%3Cpath fill='%23333' d='M6 9L1 4h10z'/%3E%3C/svg%3E");
    background-repeat: no-repeat;
    background-position: right 12px center;
    padding-right: 36px;
}

input[type="email"],
input[type="password"],
input[type="file"] {
    -webkit-appearance: none;
    appearance: none;
}

/* Main App */
.main-app {
    min-height: 100vh;
    padding-bottom: 40px;
}

.app-header {
    background: linear-gradient(135deg, #000000 0%, #2c2c2c 100%);
    color: white;
    padding: 20px;
    display: flex;
    justify-content: space-between;
    align-items: center;
    position: sticky;
    top: 0;
    z-index: 100;
}

.app-header .header-content {
    display: flex;
    flex-direction: column;
    gap: 4px;
}

.app-header h1 {
    font-size: 1.5rem;
    margin: 0;
}

.app-header .tagline {
    font-size: 0.85rem;
    color: rgba(255, 255, 255, 0.7);
    font-weight: 400;
    margin: 0;
}

.onboarding-card .tagline {
    color: #667eea;
    font-weight: 500;
    font-size: 0.95rem;
    margin-bottom: 8px;
}

.btn-icon {
    background: rgba(255, 255, 255, 0.2);
    border: none;
    padding: 8px 16px;
    border-radius: 8px;
    font-size: 1.2rem;
    cursor: pointer;
    transition: all 0.2s;
}

.btn-icon:hover {
    background: rgba(255, 255, 255, 0.3);
}

.container {
    max-width: 800px;
    margin: 0 auto;
    padding: 20px;
}

/* Profile Summary */
.profile-summary {
    background: white;
    border-radius: 16px;
    padding: 20px;
    margin-bottom: 24px;
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.1);
}

.profile-allergies {
    display: flex;
    flex-wrap: wrap;
    gap: 12px;
}

.allergy-badge {
    display: inline-flex;
    align-items: center;
    gap: 8px;
    padding: 8px 16px;
    background: #f0f4ff;
    border: 2px solid #667eea;
    border-radius: 20px;
    font-weight: 500;
    color: #667eea;
}

.allergy-badge .icon {
    font-size: 1.2rem;
}

/* Camera Section */
.camera-section {
    background: white;
    border-radius: 16px;
    padding: 24px;
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.1);
    margin-bottom: 24px;
}

.camera-container {
    position: relative;
    width: 100%;
    max-width: 600px;
    margin: 0 auto 20px;
    border-radius: 16px;
    overflow: hidden;
    background: #000;
}

#camera {
    width: 100%;
    display: block;
}

.image-preview-container {
    width: 100%;
    display: flex;
    justify-content: center;
    align-items: center;
    background: #000;
}

.image-preview-container img {
    max-width: 100%;
    max-height: 500px;
    object-fit: contain;
}

.camera-overlay {
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    pointer-events: none;
}

.scan-frame {
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    width: 80%;
    height: 60%;
    border: 3px solid rgba(102, 126, 234, 0.8);
    border-radius: 16px;
    box-shadow: 0 0 0 9999px rgba(0, 0, 0, 0.3);
}

.camera-controls {
    display: flex;
    gap: 12px;
    justify-content: center;
    flex-wrap: wrap;
}

.divider {
    text-align: center;
    margin: 24px 0;
    position: relative;
}

.divider::before {
    content: '';
    position: absolute;
    top: 50%;
    left: 0;
    right: 0;
    height: 1px;
    background: #e0e0e0;
}

.divider span {
    position: relative;
    background: white;
    padding: 0 16px;
    color: #999;
    font-size: 0.9rem;
    font-weight: 500;
}

.upload-section {
    display: flex;
    gap: 12px;
    justify-content: center;
    flex-wrap: wrap;
}

.camera-hint {
    text-align: center;
    color: #666;
    margin-top: 16px;
    font-size: 0.9rem;
}

/* Buttons */
.btn {
    padding: 12px 24px;
    border: none;
    border-radius: 12px;
    font-size: 15px;
    font-weight: 500;
    cursor: pointer;
    transition: all 0.2s;
    -webkit-tap-highlight-color: transparent;
    touch-action: manipulation;
}

.btn-large {
    padding: 16px 32px;
    font-size: 16px;
    min-height: 48px; /* Better touch target for mobile */
}

.btn-primary {
    background: #667eea;
    color: white;
}

.btn-primary:active {
    background: #5568d3;
    transform: scale(0.98);
}

.btn-secondary {
    background: #f8f8f8;
    color: #1a1a1a;
    border: 2px solid #e0e0e0;
}

.btn-secondary:active {
    background: #e8e8e8;
}

.btn:disabled {
    opacity: 0.5;
    cursor: not-allowed;
}

/* Results */
.results-section {
    background: white;
    border-radius: 16px;
    padding: 24px;
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.1);
}

.result-card {
    background: #f8f8f8;
    border-radius: 12px;
    padding: 20px;
    margin-bottom: 16px;
}

.food-name-header {
    text-align: center;
    padding-bottom: 20px;
    border-bottom: 2px solid #e0e0e0;
    margin-bottom: 20px;
}

.food-name-header h2 {
    font-size: 1.8rem;
    color: #1a1a1a;
    margin-bottom: 8px;
}

.result-type-badge {
    display: inline-block;
    padding: 6px 12px;
    background: #f0f4ff;
    border: 1px solid #667eea;
    border-radius: 12px;
    font-size: 0.85rem;
    color: #667eea;
    font-weight: 500;
}

.safety-result {
    text-align: center;
    margin-bottom: 20px;
}

.result-header {
    display: flex;
    align-items: center;
    gap: 12px;
    margin-bottom: 16px;
    padding-bottom: 16px;
    border-bottom: 2px solid #e0e0e0;
}

.result-type {
    font-size: 2rem;
}

.result-type-text {
    font-size: 0.9rem;
    color: #666;
    font-weight: 500;
}

.safety-level {
    display: inline-block;
    padding: 8px 16px;
    border-radius: 20px;
    font-weight: 600;
    font-size: 0.9rem;
    margin-bottom: 16px;
}

.safety-level.high-risk {
    background: #ff6b6b;
    color: white;
}

.safety-level.moderate-risk {
    background: #ffd93d;
    color: #1a1a1a;
}

.safety-level.low-risk {
    background: #51cf66;
    color: white;
}

.allergen-section {
    margin: 20px 0;
}

.allergen-section h4 {
    font-size: 1rem;
    margin-bottom: 12px;
    color: #1a1a1a;
}

.allergen-list {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
}

.allergen-item {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    padding: 6px 12px;
    background: white;
    border-radius: 12px;
    font-size: 0.9rem;
}

.allergen-item.user-allergy {
    background: #ff6b6b;
    color: white;
    font-weight: 600;
}

.allergen-item.other-allergy {
    background: #e0e0e0;
    color: #666;
}

.reasoning, .recommendations {
    margin: 16px 0;
    padding: 16px;
    background: white;
    border-radius: 12px;
}

.reasoning h4, .recommendations h4 {
    margin-bottom: 8px;
    font-size: 1rem;
}

/* Loading */
.loading {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0, 0, 0, 0.8);
    display: flex;
    flex-direction: column;
    justify-content: center;
    align-items: center;
    color: white;
    z-index: 1000;
}

.spinner {
    width: 50px;
    height: 50px;
    border: 4px solid rgba(255, 255, 255, 0.3);
    border-top: 4px solid white;
    border-radius: 50%;
    animation: spin 1s linear infinite;
    margin-bottom: 20px;
}

@keyframes spin {
    0% { transform: rotate(0deg); }
    100% { transform: rotate(360deg); }
}

@media (max-width: 768px) {
    .onboarding-card {
        padding: 24px;
        max-height: 90vh;
        overflow-y: auto;
        -webkit-overflow-scrolling: touch;
    }
    
    .allergen-grid {
        grid-template-columns: repeat(2, 1fr);
    }
    
    .app-header {
        padding: 16px;
    }
    
    .app-header h1 {
        font-size: 1.2rem;
    }
    
    .app-header .tagline {
        font-size: 0.75rem;
    }
    
    .container {
        padding: 16px;
    }
    
    .camera-section,
    .results-section,
    .history-section,
    .profile-summary {
        margin-bottom: 16px;
    }
    
    .btn-large {
        width: 100%;
        padding: 14px 24px;
    }
    
    .camera-controls,
    .upload-section {
        flex-direction: column;
        width: 100%;
    }
    
    .camera-controls .btn,
    .upload-section .btn {
        width: 100%;
    }
    
    .history-header {
        flex-direction: column;
        align-items: flex-start;
    }
    
    .history-header .btn-small {
        width: 100%;
    }
    
    .modal-content {
        padding: 24px;
        margin: 20px;
    }
    
    /* Improve touch targets */
    .btn-icon {
        min-width: 44px;
        min-height: 44px;
        padding: 10px;
    }
    
    /* Better spacing for mobile */
    .profile-summary {
        padding: 16px;
    }
    
    .camera-section {
        padding: 16px;
    }
    
    .results-section,
    .history-section {
        padding: 16px;
    }
}

/* History Section */
.history-section {
    background: white;
    border-radius: 16px;
    padding: 24px;
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.1);
    margin-top: 24px;
}

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

.history-header h3 {
    margin: 0;
}

.btn-small {
    padding: 8px 16px;
    font-size: 0.85rem;
}

.history-list {
    display: grid;
    gap: 12px;
}

.history-item {
    display: flex;
    gap: 12px;
    padding: 12px;
    background: #f8f8f8;
    border-radius: 12px;
    border: 1px solid #e0e0e0;
    cursor: pointer;
    transition: all 0.2s;
    -webkit-tap-highlight-color: transparent;
    touch-action: manipulation;
}

.history-item:active {
    border-color: #667eea;
    transform: scale(0.98);
    box-shadow: 0 2px 8px rgba(102, 126, 234, 0.2);
}

.history-thumbnail-wrapper {
    position: relative;
    flex-shrink: 0;
}

.history-thumbnail {
    width: 80px;
    height: 80px;
    border-radius: 8px;
    object-fit: cover;
    background: #e0e0e0;
}

.history-thumbnail-placeholder {
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 2rem;
    color: #999;
}

.history-alert-badge {
    position: absolute;
    top: -6px;
    right: -6px;
    width: 28px;
    height: 28px;
    background: #ff6b6b;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 1rem;
    border: 2px solid white;
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.2);
}

.history-info {
    flex: 1;
    min-width: 0;
    display: flex;
    flex-direction: column;
    gap: 6px;
}

.history-food-name {
    font-weight: 600;
    font-size: 1rem;
    margin-bottom: 4px;
    color: #1a1a1a;
}

.history-text {
    font-size: 0.85rem;
    color: #666;
    line-height: 1.4;
}

.history-text strong {
    color: #1a1a1a;
    font-weight: 600;
}

.history-meta {
    display: flex;
    gap: 8px;
    align-items: center;
    font-size: 0.8rem;
    color: #666;
    margin-top: 4px;
}

.history-safety {
    padding: 2px 8px;
    border-radius: 8px;
    font-size: 0.75rem;
    font-weight: 600;
}

.history-safety.high-risk {
    background: #ff6b6b;
    color: white;
}

.history-safety.moderate-risk {
    background: #ffd93d;
    color: #1a1a1a;
}

.history-safety.low-risk {
    background: #51cf66;
    color: white;
}

.history-date {
    color: #999;
}

.no-history {
    text-align: center;
    color: #999;
    padding: 40px 20px;
}

/* Modal */
.modal {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0, 0, 0, 0.7);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 2000;
    padding: 20px;
}

.modal-content {
    background: white;
    border-radius: 20px;
    padding: 32px;
    max-width: 400px;
    width: 100%;
    position: relative;
}

.modal-close {
    position: absolute;
    top: 16px;
    right: 20px;
    font-size: 28px;
    cursor: pointer;
    color: #999;
}

.modal-close:hover {
    color: #1a1a1a;
}

.modal-content h2 {
    margin-bottom: 12px;
}

.modal-content > p {
    color: #666;
    margin-bottom: 24px;
}

.modal-note {
    text-align: center;
    margin-top: 16px;
    font-size: 0.9rem;
    color: #666;
}

.modal-note a {
    color: #667eea;
    text-decoration: none;
    font-weight: 500;
}

.modal-note a:hover {
    text-decoration: underline;
}

input[type="email"],
input[type="password"] {
    width: 100%;
    padding: 12px;
    border: 2px solid #e0e0e0;
    border-radius: 12px;
    font-size: 16px;
    font-family: inherit;
}

input[type="email"]:focus,
input[type="password"]:focus {
    outline: none;
    border-color: #667eea;
}

/* Premium Modal */
.premium-modal {
    text-align: center;
}

.premium-badge {
    display: inline-block;
    padding: 8px 20px;
    background: linear-gradient(135deg, #ffd700 0%, #ffed4e 100%);
    color: #1a1a1a;
    border-radius: 20px;
    font-weight: 700;
    font-size: 0.9rem;
    margin-bottom: 16px;
}

.premium-price {
    font-size: 3rem;
    font-weight: 700;
    color: #667eea;
    margin: 20px 0;
}

.premium-price span {
    font-size: 1.2rem;
    color: #666;
    font-weight: 400;
}

.premium-features {
    text-align: left;
    margin: 24px 0;
    padding: 20px;
    background: #f8f8f8;
    border-radius: 12px;
}

.feature-item {
    padding: 8px 0;
    font-size: 1rem;
}

.usage-indicator {
    display: inline-block;
    padding: 4px 12px;
    background: #f0f4ff;
    border: 1px solid #667eea;
    border-radius: 12px;
    font-size: 0.85rem;
    color: #667eea;
    font-weight: 500;
    margin-left: 8px;
}

.usage-indicator.limit-reached {
    background: #ffe8e8;
    border-color: #ff6b6b;
    color: #ff6b6b;
}
