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

:root {
    /* Color palette */
    --primary: #F1A719;
    --primary-dark: #D89515;
    --primary-light: #FFB93A;
    --background: #F8F8F8;
    --white: #FFFFFF;
    --text-dark: #2C2C2C;
    --text-medium: #666666;
    --text-light: #999999;
    --success: #4CAF50;
    --warning: #FF9800;
    --danger: #F44336;
    --info: #2196F3;
    --border: #E0E0E0;
    
    /* Shadows */
    --shadow-sm: 0 2px 4px rgba(0,0,0,0.08);
    --shadow-md: 0 4px 8px rgba(0,0,0,0.12);
    --shadow-lg: 0 8px 16px rgba(0,0,0,0.16);
}

body {
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, 'Helvetica Neue', Arial, sans-serif;
    background: var(--background);
    color: var(--text-dark);
    line-height: 1.5;
    -webkit-font-smoothing: antialiased;
    overflow: hidden;
    height: 100vh;
    position: fixed;
    width: 100%;
}

.container {
    max-width: 430px;
    margin: 0 auto;
    height: 100vh;
    background: var(--white);
    position: relative;
    display: flex;
    flex-direction: column;
    overflow: hidden;
}

/* Header - Compact */
header {
    background: var(--primary);
    padding: 12px 16px;
    padding-top: env(safe-area-inset-top, 12px);
    color: var(--white);
    box-shadow: var(--shadow-md);
    z-index: 100;
    flex-shrink: 0;
}

h1 {
    font-size: 18px;
    font-weight: 600;
    display: flex;
    align-items: center;
    gap: 8px;
}

.subtitle {
    display: none; /* Hide subtitle for more space */
}

/* Main Content Area */
.main-content {
    flex: 1;
    overflow-y: auto;
    overflow-x: hidden;
    -webkit-overflow-scrolling: touch;
    background: var(--background);
}

/* Scanner Container */
.scanner-container {
    background: var(--white);
    height: 100%;
    display: flex;
    flex-direction: column;
}

/* Viewport - Smaller */
.viewport {
    position: relative;
    width: 100%;
    height: 200px;
    background: #000;
    overflow: hidden;
    flex-shrink: 0;
}

#interactive {
    width: 100%;
    height: 100%;
    position: relative;
}

#interactive video {
    width: 100%;
    height: 100%;
    object-fit: cover;
}

#interactive canvas {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
}

/* Scanner overlay */
.scanner-overlay {
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    pointer-events: none;
    z-index: 10;
}

.scanner-line {
    position: absolute;
    width: 70%;
    height: 2px;
    left: 15%;
    top: 50%;
    background: linear-gradient(90deg, transparent, var(--primary), transparent);
    transform: translateY(-50%);
    animation: scan 2s ease-in-out infinite;
    opacity: 0;
}

.scanning .scanner-line {
    opacity: 1;
}

@keyframes scan {
    0% { transform: translateY(-80px); }
    50% { transform: translateY(0); }
    100% { transform: translateY(80px); }
}

/* Corner frame */
.corner-frame {
    position: absolute;
    top: 20%;
    left: 15%;
    right: 15%;
    bottom: 20%;
}

.corner {
    position: absolute;
    width: 20px;
    height: 20px;
    border: 2px solid var(--primary);
    opacity: 0.8;
}

.corner.top-left {
    top: 0;
    left: 0;
    border-right: none;
    border-bottom: none;
}

.corner.top-right {
    top: 0;
    right: 0;
    border-left: none;
    border-bottom: none;
}

.corner.bottom-left {
    bottom: 0;
    left: 0;
    border-right: none;
    border-top: none;
}

.corner.bottom-right {
    bottom: 0;
    right: 0;
    border-left: none;
    border-top: none;
}

.scan-instruction {
    position: absolute;
    bottom: 10px;
    left: 10px;
    right: 10px;
    text-align: center;
    color: var(--white);
    background: rgba(0, 0, 0, 0.6);
    padding: 6px;
    border-radius: 8px;
    font-size: 12px;
}

/* Controls - Compact */
.controls {
    padding: 12px;
    display: flex;
    gap: 10px;
    justify-content: center;
    background: var(--white);
    border-bottom: 1px solid var(--border);
}

/* Compact Buttons */
.btn {
    padding: 10px 20px;
    border: none;
    border-radius: 20px;
    font-size: 14px;
    font-weight: 600;
    cursor: pointer;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 6px;
    transition: all 0.2s ease;
    -webkit-tap-highlight-color: transparent;
}

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

.btn-primary:active {
    background: var(--primary-dark);
    transform: scale(0.98);
}

.btn-secondary {
    background: var(--danger);
    color: var(--white);
}

.icon {
    font-size: 16px;
}

/* Scan feedback */
.scan-feedback {
    padding: 8px;
    background: var(--success);
    color: var(--white);
    text-align: center;
    font-size: 12px;
    font-weight: 600;
}

/* Manual input - Compact */
.manual-input {
    padding: 12px;
    background: var(--background);
    border-top: 1px solid var(--border);
}

.manual-input p {
    font-size: 12px;
    color: var(--text-medium);
    margin-bottom: 8px;
}

.manual-input input {
    padding: 8px 12px;
    border: 1px solid var(--border);
    border-radius: 20px;
    width: calc(100% - 80px);
    margin-right: 8px;
    font-size: 14px;
    background: var(--white);
}

.manual-input input:focus {
    outline: none;
    border-color: var(--primary);
}

.manual-input .btn {
    width: 70px;
    padding: 8px 16px;
    font-size: 12px;
}

/* Result container - Popup style */
.result-container {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: var(--white);
    z-index: 1000;
    display: flex;
    flex-direction: column;
    transform: translateY(100%);
    transition: transform 0.3s ease;
}

.result-container.show {
    transform: translateY(0);
}

/* Result Header */
.result-header {
    background: var(--primary);
    color: var(--white);
    padding: 12px 16px;
    padding-top: env(safe-area-inset-top, 12px);
    display: flex;
    align-items: center;
    justify-content: space-between;
    flex-shrink: 0;
}

.result-header h2 {
    font-size: 16px;
    font-weight: 600;
}

.close-btn {
    background: none;
    border: none;
    color: var(--white);
    font-size: 24px;
    cursor: pointer;
    padding: 0;
    width: 32px;
    height: 32px;
    display: flex;
    align-items: center;
    justify-content: center;
}

/* Result Content - Scrollable */
.result-content {
    flex: 1;
    overflow-y: auto;
    -webkit-overflow-scrolling: touch;
    padding: 16px;
    background: var(--background);
}

.result-card {
    background: var(--white);
    border-radius: 12px;
    padding: 16px;
    margin-bottom: 12px;
    box-shadow: var(--shadow-sm);
}

.product-info {
    font-size: 18px;
    font-weight: 600;
    color: var(--text-dark);
    margin-bottom: 4px;
}

.barcode-info {
    font-size: 12px;
    color: var(--text-medium);
    margin-bottom: 12px;
}

/* Compact Alert Styles */
.alert-container {
    display: flex;
    flex-direction: column;
    gap: 8px;
}

.alert {
    padding: 10px 12px;
    border-radius: 8px;
    font-size: 13px;
    font-weight: 500;
    display: flex;
    align-items: center;
    gap: 8px;
    border-left: 3px solid;
}

.alert.safe {
    background: rgba(76, 175, 80, 0.1);
    color: var(--success);
    border-left-color: var(--success);
}

.alert.warning {
    background: rgba(255, 152, 0, 0.1);
    color: var(--warning);
    border-left-color: var(--warning);
}

.alert.danger {
    background: rgba(244, 67, 54, 0.1);
    color: var(--danger);
    border-left-color: var(--danger);
}

.alert.info {
    background: rgba(33, 150, 243, 0.1);
    color: var(--info);
    border-left-color: var(--info);
}

/* Ingredients section - Expandable */
.ingredients-section {
    background: var(--white);
    border-radius: 12px;
    overflow: hidden;
    box-shadow: var(--shadow-sm);
}

.ingredients-header {
    padding: 12px 16px;
    background: var(--background);
    display: flex;
    justify-content: space-between;
    align-items: center;
    cursor: pointer;
}

.ingredients-header h3 {
    font-size: 14px;
    font-weight: 600;
    color: var(--text-dark);
}

.expand-icon {
    color: var(--text-medium);
    transition: transform 0.3s ease;
}

.ingredients-section.expanded .expand-icon {
    transform: rotate(180deg);
}

.ingredients-text {
    padding: 12px 16px;
    font-size: 13px;
    line-height: 1.6;
    color: var(--text-medium);
    max-height: 0;
    overflow: hidden;
    transition: max-height 0.3s ease;
}

.ingredients-section.expanded .ingredients-text {
    max-height: 200px;
    overflow-y: auto;
}

/* Additives section - Collapsible */
.additives-section {
    margin-top: 8px;
}

.additives-alert {
    background: var(--white);
    border-radius: 12px;
    padding: 12px;
    box-shadow: var(--shadow-sm);
}

.additives-alert h4 {
    font-size: 14px;
    margin-bottom: 8px;
    color: var(--text-dark);
}

.additives-alert ul {
    list-style: none;
    padding: 0;
    margin: 4px 0;
}

.additives-alert li {
    padding: 4px 0;
    font-size: 12px;
    color: var(--text-medium);
    border-bottom: 1px solid var(--border);
}

.additives-alert li:last-child {
    border-bottom: none;
}

/* Bottom Navigation Bar */
.bottom-nav {
    position: fixed;
    bottom: 0;
    left: 0;
    right: 0;
    background: var(--white);
    border-top: 1px solid var(--border);
    padding: 8px;
    padding-bottom: env(safe-area-inset-bottom, 8px);
    display: flex;
    justify-content: space-around;
    z-index: 900;
}

.nav-btn {
    background: none;
    border: none;
    padding: 8px;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 4px;
    cursor: pointer;
    color: var(--text-medium);
    font-size: 11px;
    transition: color 0.2s ease;
}

.nav-btn:active {
    color: var(--primary);
}

.nav-btn .icon {
    font-size: 20px;
}

/* Loading - Full screen overlay */
.loading {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(255, 255, 255, 0.95);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 9999;
}

.loading > div {
    text-align: center;
}

.spinner {
    width: 48px;
    height: 48px;
    border: 3px solid var(--border);
    border-top: 3px solid var(--primary);
    border-radius: 50%;
    animation: spin 0.8s linear infinite;
    margin: 0 auto 12px;
}

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

.loading p {
    color: var(--text-medium);
    font-size: 14px;
}

/* Error toast */
.error-message {
    position: fixed;
    top: 60px;
    left: 50%;
    transform: translateX(-50%);
    background: var(--danger);
    color: var(--white);
    padding: 12px 20px;
    border-radius: 20px;
    box-shadow: var(--shadow-lg);
    z-index: 10000;
    font-size: 13px;
    font-weight: 500;
    animation: slideDown 0.3s ease;
}

@keyframes slideDown {
    from {
        opacity: 0;
        transform: translate(-50%, -20px);
    }
    to {
        opacity: 1;
        transform: translate(-50%, 0);
    }
}

/* Animations */
@keyframes slideIn {
    from {
        opacity: 0;
        transform: translateX(-10px);
    }
    to {
        opacity: 1;
        transform: translateX(0);
    }
}

@keyframes fadeIn {
    from { opacity: 0; }
    to { opacity: 1; }
}

/* Mobile optimizations */
@media (max-width: 430px) {
    .container {
        max-width: 100%;
        border-radius: 0;
    }
}

@media (max-height: 600px) {
    .viewport {
        height: 150px;
    }
    
    header {
        padding: 8px 16px;
    }
    
    h1 {
        font-size: 16px;
    }
}

/* iOS specific */
@supports (-webkit-touch-callout: none) {
    input {
        font-size: 16px; /* Prevent zoom */
    }
}

/* Accessibility */
@media (prefers-reduced-motion: reduce) {
    * {
        animation-duration: 0.01ms !important;
        transition-duration: 0.01ms !important;
    }
}
/* OCR Styles */
.ocr-container {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: var(--white);
    z-index: 1001;
    display: flex;
    flex-direction: column;
}

.ocr-header {
    background: var(--primary);
    color: var(--white);
    padding: 12px 16px;
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.ocr-content {
    flex: 1;
    overflow-y: auto;
    padding: 16px;
    background: var(--background);
}

.ocr-preview {
    width: 100%;
    max-height: 200px;
    object-fit: contain;
    border-radius: 8px;
    margin-bottom: 16px;
    box-shadow: var(--shadow-md);
}

.ocr-progress {
    background: var(--white);
    padding: 16px;
    border-radius: 8px;
    margin-bottom: 16px;
}

.progress-bar {
    height: 4px;
    background: var(--primary);
    border-radius: 2px;
    transition: width 0.3s ease;
    width: 0%;
    margin-bottom: 8px;
}

.ocr-result {
    background: var(--white);
    padding: 16px;
    border-radius: 8px;
    margin-bottom: 16px;
}

.ocr-result h4 {
    color: var(--text-dark);
    margin-bottom: 8px;
    font-size: 14px;
}

.detected-text {
    background: var(--background);
    padding: 12px;
    border-radius: 6px;
    font-size: 12px;
    color: var(--text-medium);
    margin-bottom: 16px;
    max-height: 150px;
    overflow-y: auto;
}

.identified-ingredients {
    background: var(--background);
    padding: 12px;
    border-radius: 6px;
    font-size: 13px;
    color: var(--text-dark);
}

#analyze-ocr-btn {
    width: 100%;
    margin-top: 12px;
}
/* AI Enhanced Styles */
.ai-badge {
    display: inline-block;
    margin-left: 10px;
    padding: 4px 8px;
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    color: white;
    border-radius: 12px;
    font-size: 11px;
    font-weight: 600;
    animation: pulse 2s infinite;
}

@keyframes pulse {
    0%, 100% { opacity: 1; }
    50% { opacity: 0.7; }
}

.ai-recommendations {
    margin-top: 16px;
}

.recommendation-card {
    background: linear-gradient(135deg, #f3f4f6 0%, #e5e7eb 100%);
    border-left: 4px solid #667eea;
    padding: 16px;
    border-radius: 8px;
}

.recommendation-card h4 {
    color: #4f46e5;
    margin-bottom: 8px;
    font-size: 14px;
}

.recommendation-card p {
    color: var(--text-medium);
    font-size: 13px;
    line-height: 1.5;
}

.additives-alert.ai-enhanced {
    border: 2px solid #667eea;
    background: linear-gradient(135deg, #f9fafb 0%, #f3f4f6 100%);
}

.additives-alert.ai-enhanced h4 {
    color: #4f46e5;
}

/* Loading indicator AI style */
.loading small {
    display: block;
    margin-top: 8px;
    color: var(--text-light);
    font-size: 12px;
}
.progress-bar-container {
    width: 100%;
    height: 4px;
    background: var(--border);
    border-radius: 2px;
    overflow: hidden;
    margin-bottom: 8px;
}

.progress-bar {
    height: 100%;
    background: var(--primary);
    border-radius: 2px;
    transition: width 0.3s ease;
    width: 0%;
}

.tabs {
    display: flex;
    gap: 8px;
    padding: 8px;
    background: var(--white);
    border-bottom: 1px solid var(--border);
}
.tab-btn {
    flex: 1;
    padding: 8px;
    border: none;
    background: var(--background);
    border-radius: 8px;
    cursor: pointer;
    font-weight: 600;
    color: var(--text-medium);
}
.tab-btn.active {
    background: var(--primary);
    color: white;
}
.tab-content { display: none; }
.tab-content.active { display: block; }

.venues-header { padding: 12px; background: var(--white); border-bottom: 1px solid var(--border); }
.filters { display: flex; gap: 8px; margin-bottom: 8px; }
.filters select { padding: 8px; border: 1px solid var(--border); border-radius: 8px; }
.search-bar { display: flex; gap: 8px; }
.search-bar input { flex: 1; padding: 8px; border: 1px solid var(--border); border-radius: 8px; }
.auth-cta { display: flex; align-items: center; gap: 8px; margin-top: 8px; }
.btn-sm { padding: 6px 12px; font-size: 12px; border-radius: 12px; }

.venues-list { padding: 12px; display: grid; grid-template-columns: 1fr; gap: 12px; }
.venue-card { display: flex; gap: 12px; background: var(--white); border-radius: 12px; box-shadow: var(--shadow-sm); overflow: hidden; }
.venue-thumb { width: 100px; height: 100px; object-fit: cover; background: #eee; }
.venue-info { padding: 8px 8px 8px 0; flex: 1; }
.venue-title { font-weight: 700; margin-bottom: 4px; }
.venue-meta { font-size: 12px; color: var(--text-medium); margin-bottom: 6px; }
.venue-tags { display: flex; gap: 6px; flex-wrap: wrap; }
.tag { font-size: 11px; padding: 2px 6px; border-radius: 12px; background: var(--background); color: var(--text-medium); }
.tag.verified { background: #e6ffe9; color: #177a2f; }
.tag.level-3 { background: #e8f5e9; color: #1b5e20; }
.tag.level-2 { background: #fff8e1; color: #8d6e63; }
.tag.level-1 { background: #e3f2fd; color: #1565c0; }

.pagination { display: flex; justify-content: center; align-items: center; gap: 12px; padding: 12px; }
#page-info { font-size: 12px; color: var(--text-medium); }

.venue-modal { position: fixed; inset: 0; background: rgba(0,0,0,0.5); display: flex; align-items: flex-end; z-index: 2000; }
.venue-modal.hidden { display: none; }
.venue-modal-content { background: white; width: 100%; max-height: 90vh; border-top-left-radius: 12px; border-top-right-radius: 12px; overflow: hidden; display: flex; flex-direction: column; }
.venue-modal-header { padding: 12px; background: var(--primary); color: white; display: flex; align-items: center; justify-content: space-between; }
.venue-modal-body { padding: 12px; overflow-y: auto; }
.venue-photo { width: 100%; max-height: 220px; object-fit: cover; border-radius: 8px; margin-bottom: 8px; }
.feedback-form-container { margin-top: 12px; padding: 12px; background: var(--background); border-radius: 8px; }
.feedback-form-container form { display: grid; gap: 8px; }
.feedback-form-container textarea { width: 100%; min-height: 80px; padding: 8px; border: 1px solid var(--border); border-radius: 8px; }
.feedback-form-container select, .feedback-form-container input { padding: 8px; border: 1px solid var(--border); border-radius: 8px; }

.auth-modal { position: fixed; inset: 0; background: rgba(0,0,0,0.6); display: flex; align-items: center; justify-content: center; z-index: 2500; }
.auth-modal.hidden { display: none; }
.auth-modal-content { background: white; width: 92%; max-width: 420px; border-radius: 12px; overflow: hidden; }
.auth-modal-header { padding: 12px; background: var(--primary); color: white; display: flex; justify-content: space-between; align-items: center; }
.auth-modal-body { padding: 12px; }
#auth-tabs { display: flex; gap: 8px; margin-bottom: 12px; }
.auth-tab-btn { flex: 1; border: none; padding: 8px; border-radius: 8px; background: var(--background); font-weight: 600; }
.auth-tab-btn.active { background: var(--primary); color: white; }
.auth-form { display: none; gap: 8px; }
.auth-form.active { display: grid; }
.auth-form input { padding: 10px; border: 1px solid var(--border); border-radius: 8px; }

.leaderboard-list { padding: 12px; }
.lb-item { background: white; border-radius: 8px; padding: 10px; margin-bottom: 8px; display: flex; justify-content: space-between; box-shadow: var(--shadow-sm); }

.btn-link { background: transparent; border: none; color: var(--primary); text-decoration: underline; cursor: pointer; font-size: 13px; }

@media (min-width: 520px) {
    .venues-list { grid-template-columns: 1fr 1fr; }
}
