/* Enhanced Food Safety Scanner Styles v2.1 - MOBILE FIXED */

:root {
    --primary: #2563eb;
    --secondary: #64748b;
    --success: #10b981;
    --warning: #f59e0b;
    --danger: #ef4444;
    --dark: #1e293b;
    --light: #f1f5f9;
}

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

body {
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Oxygen, Ubuntu, Cantarell, sans-serif;
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    min-height: 100vh;
    padding: 20px;
    line-height: 1.6;
}

.container {
    max-width: 900px;
    margin: 0 auto;
    background: white;
    border-radius: 20px;
    box-shadow: 0 20px 60px rgba(0, 0, 0, 0.3);
    overflow: hidden;
}

.header {
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    color: white;
    padding: 40px 30px;
    text-align: center;
}

.logo {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 15px;
    margin-bottom: 10px;
}

.logo-icon {
    font-size: 3em;
}

h1 {
    font-size: 2.5em;
    font-weight: 700;
    margin: 0;
}

.tagline {
    font-size: 1.1em;
    opacity: 0.95;
    margin-top: 10px;
}

.main-content {
    padding: 40px 30px;
}

h2 {
    color: var(--dark);
    margin-bottom: 10px;
    font-size: 1.8em;
}

.instruction {
    color: var(--secondary);
    margin-bottom: 25px;
}

/* ===== IMAGE PREVIEW WITH ROTATION CONTROLS (MOBILE OPTIMIZED) ===== */
.image-preview {
    margin: 25px 0;
    padding: 15px;
    background: var(--light);
    border-radius: 12px;
    border: 2px solid #e2e8f0;
}

.preview-controls {
    display: flex;
    gap: 8px;
    margin-bottom: 15px;
    flex-wrap: wrap;
    justify-content: center;
}

.btn-rotate,
.btn-enhance,
.btn-remove {
    padding: 10px 15px;
    border: none;
    border-radius: 8px;
    font-size: 1em;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.3s;
    flex: 1;
    min-width: 70px;
}

.btn-rotate {
    background: #6366f1;
    color: white;
    font-size: 1.5em;
    padding: 8px;
    max-width: 70px;
}

.btn-rotate:active {
    background: #4f46e5;
    transform: scale(0.95);
}

.btn-enhance {
    background: #8b5cf6;
    color: white;
    max-width: 120px;
}

.btn-enhance:active {
    background: #7c3aed;
    transform: scale(0.95);
}

.btn-remove {
    background: var(--danger);
    color: white;
    max-width: 70px;
}

.btn-remove:active {
    background: #dc2626;
    transform: scale(0.95);
}

/* CRITICAL FIX: Canvas container with scroll */
.canvas-container {
    width: 100%;
    max-height: 400px; /* Prevent overflow */
    overflow: auto; /* Allow scrolling if needed */
    border-radius: 8px;
    border: 2px solid #cbd5e1;
    background: white;
    margin-bottom: 15px;
    display: flex;
    justify-content: center;
    align-items: center;
}

#imageCanvas {
    max-width: 100%;
    height: auto;
    display: block;
    margin: 0 auto;
}

/* Full-width extract button */
.btn-process-full {
    width: 100%;
    padding: 15px;
    background: var(--success);
    color: white;
    border: none;
    border-radius: 10px;
    font-size: 1.1em;
    font-weight: 700;
    cursor: pointer;
    margin-bottom: 15px;
    transition: all 0.3s;
}

.btn-process-full:active {
    background: #059669;
    transform: scale(0.98);
}

.image-tips {
    padding: 10px;
    background: #fef3c7;
    border-radius: 8px;
    border-left: 4px solid #f59e0b;
    font-size: 0.9em;
    color: #92400e;
    text-align: center;
}

/* ===== OCR STATUS ===== */
.ocr-status {
    margin: 20px 0;
    padding: 20px;
    background: #eff6ff;
    border-radius: 10px;
    border: 2px solid #3b82f6;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 10px;
}

.spinner-small {
    width: 30px;
    height: 30px;
    border: 3px solid #e5e7eb;
    border-top-color: #3b82f6;
    border-radius: 50%;
    animation: spin 0.8s linear infinite;
}

#ocrText {
    font-weight: 600;
    color: #1e40af;
    font-size: 1.05em;
    text-align: center;
}

.ocr-progress {
    font-size: 0.9em;
    color: #64748b;
    text-align: center;
}

/* ===== UPLOAD BUTTONS ===== */
.upload-buttons {
    display: flex;
    gap: 15px;
    margin-bottom: 20px;
    flex-wrap: wrap;
}

.btn {
    padding: 15px 30px;
    border: none;
    border-radius: 10px;
    font-size: 1.1em;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.3s;
    flex: 1;
    min-width: 150px;
    text-align: center;
}

.btn-photo {
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    color: white;
    display: inline-block;
}

.btn-photo:active {
    transform: scale(0.98);
    box-shadow: 0 5px 15px rgba(102, 126, 234, 0.3);
}

.btn-barcode-manual {
    background: #10b981;
    color: white;
}

.btn-barcode-manual:active {
    background: #059669;
    transform: scale(0.98);
}

/* ===== DIVIDER ===== */
.divider {
    display: flex;
    align-items: center;
    text-align: center;
    margin: 30px 0;
    color: var(--secondary);
}

.divider::before,
.divider::after {
    content: '';
    flex: 1;
    border-bottom: 2px solid #e2e8f0;
}

.divider span {
    padding: 0 20px;
    font-weight: 600;
}

/* ===== TEXTAREA ===== */
.ingredient-input {
    width: 100%;
    padding: 20px;
    border: 2px solid #e2e8f0;
    border-radius: 12px;
    font-size: 1em;
    font-family: 'Courier New', monospace;
    resize: vertical;
    transition: border-color 0.3s;
}

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

/* ===== BUTTONS ===== */
.button-group {
    display: flex;
    gap: 15px;
    margin-top: 25px;
}

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

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

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

.btn-secondary:active {
    background: #475569;
    transform: scale(0.98);
}

/* ===== LOADING ===== */
.loading {
    text-align: center;
    padding: 40px;
}

.spinner {
    width: 50px;
    height: 50px;
    border: 4px solid #e5e7eb;
    border-top-color: var(--primary);
    border-radius: 50%;
    animation: spin 0.8s linear infinite;
    margin: 0 auto 20px;
}

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

.loading p {
    color: var(--secondary);
    font-weight: 600;
}

/* ===== RESULTS ===== */
.results-section {
    margin-top: 40px;
    padding-top: 40px;
    border-top: 3px solid var(--light);
}

.summary-cards {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(120px, 1fr));
    gap: 12px;
    margin-bottom: 30px;
}

.summary-card {
    padding: 20px 15px;
    border-radius: 12px;
    text-align: center;
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.1);
}

.summary-card.red {
    background: linear-gradient(135deg, #fee2e2 0%, #fecaca 100%);
    border: 2px solid #ef4444;
}

.summary-card.yellow {
    background: linear-gradient(135deg, #fef3c7 0%, #fde68a 100%);
    border: 2px solid #f59e0b;
}

.summary-card.green {
    background: linear-gradient(135deg, #d1fae5 0%, #a7f3d0 100%);
    border: 2px solid #10b981;
}

.summary-card.gray {
    background: linear-gradient(135deg, #f1f5f9 0%, #e2e8f0 100%);
    border: 2px solid #94a3b8;
}

.summary-card .number {
    font-size: 2.5em;
    font-weight: 700;
    margin-bottom: 5px;
}

.summary-card .label {
    font-size: 0.95em;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.5px;
}

/* ===== INGREDIENTS LIST ===== */
.ingredients-list {
    display: flex;
    flex-direction: column;
    gap: 12px;
}

.ingredient-item {
    display: flex;
    align-items: center;
    gap: 15px;
    padding: 15px;
    border-radius: 12px;
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.1);
    transition: transform 0.2s, box-shadow 0.2s;
}

.ingredient-item[style*="cursor:pointer"] {
    cursor: pointer;
}

.ingredient-item[style*="cursor:pointer"]:hover {
    transform: translateX(5px);
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.15);
}

.click-hint {
    font-size: 0.85em;
    color: #6b7280;
    margin-top: 5px;
    font-style: italic;
}

.ingredient-item.red {
    background: #fee2e2;
    border-left: 5px solid #ef4444;
}

.ingredient-item.yellow {
    background: #fef3c7;
    border-left: 5px solid #f59e0b;
}

.ingredient-item.green {
    background: #d1fae5;
    border-left: 5px solid #10b981;
}

.ingredient-item.gray {
    background: #f1f5f9;
    border-left: 5px solid #94a3b8;
}

.ingredient-icon {
    font-size: 1.8em;
    flex-shrink: 0;
}

.ingredient-content {
    flex: 1;
}

.ingredient-name {
    font-size: 1.1em;
    font-weight: 600;
    color: var(--dark);
    margin-bottom: 5px;
}

.ingredient-status {
    color: var(--secondary);
    font-size: 0.9em;
}

.fda-badge {
    display: inline-block;
    padding: 3px 8px;
    border-radius: 6px;
    font-size: 0.8em;
    font-weight: 600;
    margin-left: 8px;
}

.fda-badge.approved {
    background: #d1fae5;
    color: #065f46;
}

.fda-badge.banned {
    background: #fee2e2;
    color: #991b1b;
}

/* ===== LEGEND ===== */
.legend {
    margin-top: 30px;
    padding: 20px;
    background: var(--light);
    border-radius: 12px;
}

.legend h3 {
    margin-bottom: 15px;
    color: var(--dark);
    font-size: 1.1em;
}

.legend-items {
    display: flex;
    flex-wrap: wrap;
    gap: 15px;
}

.legend-item {
    display: flex;
    align-items: center;
    gap: 8px;
    font-size: 0.9em;
}

.color-box {
    width: 25px;
    height: 25px;
    border-radius: 6px;
    border: 2px solid #cbd5e1;
    flex-shrink: 0;
}

.color-box.red { background: #ef4444; }
.color-box.yellow { background: #f59e0b; }
.color-box.green { background: #10b981; }
.color-box.gray { background: #94a3b8; }

/* ===== FOOTER ===== */
.footer {
    background: var(--light);
    padding: 25px 20px;
    text-align: center;
    color: var(--secondary);
    border-top: 2px solid #e2e8f0;
    font-size: 0.9em;
}

.footer p {
    margin: 8px 0;
}

.copyright {
    font-size: 0.85em;
}

/* ===== TOAST NOTIFICATIONS ===== */
.toast {
    position: fixed;
    top: 20px;
    left: 50%;
    transform: translateX(-50%);
    background: #1e293b;
    color: white;
    padding: 15px 25px;
    border-radius: 10px;
    font-weight: 600;
    z-index: 10000;
    animation: slideDown 0.3s ease;
}

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

/* ===== 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: 1000;
    padding: 20px;
}

.modal-content {
    background: white;
    border-radius: 15px;
    padding: 25px;
    max-width: 600px;
    width: 100%;
    max-height: 90vh;
    overflow-y: auto;
    position: relative;
}

.modal-close {
    position: absolute;
    top: 10px;
    right: 10px;
    font-size: 1.8em;
    background: none;
    border: none;
    cursor: pointer;
    color: var(--secondary);
    padding: 5px;
    line-height: 1;
}

.modal-close:hover {
    color: var(--dark);
}

.modal-header {
    margin-bottom: 20px;
    padding-bottom: 15px;
    border-bottom: 2px solid var(--light);
}

.modal-title {
    font-size: 1.8em;
    color: var(--dark);
    margin: 0 0 10px 0;
}

.modal-subtitle {
    font-size: 0.95em;
    color: var(--secondary);
    margin: 5px 0;
}

.info-section {
    margin: 20px 0;
    padding: 15px;
    background: var(--light);
    border-radius: 10px;
}

.info-section h4 {
    margin: 0 0 10px 0;
    color: var(--dark);
    font-size: 1.1em;
}

.info-section p {
    margin: 5px 0;
    color: #4b5563;
    line-height: 1.6;
}

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

/* ===== MOBILE OPTIMIZATIONS ===== */
@media (max-width: 768px) {
    body {
        padding: 0;
    }
    
    .container {
        border-radius: 0;
        min-height: 100vh;
    }
    
    .header {
        padding: 30px 20px;
    }
    
    h1 {
        font-size: 1.8em;
    }
    
    .logo-icon {
        font-size: 2.5em;
    }
    
    .tagline {
        font-size: 1em;
    }
    
    .main-content {
        padding: 25px 20px;
    }
    
    h2 {
        font-size: 1.5em;
    }
    
    .upload-buttons {
        flex-direction: column;
    }
    
    .btn {
        min-width: 100%;
    }
    
    /* Mobile canvas container - CRITICAL */
    .canvas-container {
        max-height: 300px; /* Smaller on mobile */
    }
    
    .preview-controls {
        gap: 6px;
    }
    
    .btn-rotate,
    .btn-enhance,
    .btn-remove {
        font-size: 0.95em;
        padding: 8px 12px;
        min-width: 60px;
    }
    
    .btn-process-full {
        font-size: 1em;
        padding: 12px;
    }
    
    .image-tips {
        font-size: 0.85em;
        padding: 8px;
    }
    
    .summary-cards {
        grid-template-columns: repeat(2, 1fr);
        gap: 10px;
    }
    
    .summary-card {
        padding: 15px 10px;
    }
    
    .summary-card .number {
        font-size: 2em;
    }
    
    .summary-card .label {
        font-size: 0.85em;
    }
    
    .ingredient-item {
        padding: 12px;
        gap: 12px;
    }
    
    .ingredient-icon {
        font-size: 1.5em;
    }
    
    .ingredient-name {
        font-size: 1em;
    }
    
    .ingredient-status {
        font-size: 0.85em;
    }
    
    .button-group {
        flex-direction: column;
        gap: 10px;
    }
    
    .legend-items {
        flex-direction: column;
        gap: 10px;
    }
    
    .footer {
        padding: 20px 15px;
        font-size: 0.85em;
    }
}

/* Extra small phones */
@media (max-width: 375px) {
    .canvas-container {
        max-height: 250px;
    }
    
    .summary-card .number {
        font-size: 1.8em;
    }
    
    .ingredient-icon {
        font-size: 1.3em;
    }
}