/* === RESET & BASE === */
*, *::before, *::after {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

:root {
    --bg: #000000;
    --surface: #1C1C1E;
    --surface-2: #2C2C2E;
    --text: #FFFFFF;
    --text-2: #8E8E93;
    --accent: #0A84FF;
    --accent-hover: #409CFF;
    --success: #30D158;
    --warning: #FF9F0A;
    --danger: #FF453A;
    
    --radius: 16px;
    --radius-sm: 12px;
    --radius-lg: 24px;
    
    --font: 'Inter', -apple-system, BlinkMacSystemFont, sans-serif;
}

html, body {
    height: 100%;
    background: var(--bg);
    color: var(--text);
    font-family: var(--font);
    font-size: 16px;
    line-height: 1.5;
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
}

.app {
    min-height: 100%;
    display: flex;
    flex-direction: column;
    max-width: 480px;
    margin: 0 auto;
    background: var(--bg);
}

/* === HEADER === */
.header {
    padding: 20px 24px 12px;
    text-align: center;
}

.header h1 {
    font-size: 34px;
    font-weight: 700;
    letter-spacing: -0.5px;
}

/* === MAIN === */
.main {
    flex: 1;
    padding: 0 20px 40px;
}

/* === SCANNER VIEW === */
.scanner-view {
    display: flex;
    flex-direction: column;
    gap: 24px;
}

.scanner-frame {
    position: relative;
    aspect-ratio: 1;
    background: var(--surface);
    border-radius: var(--radius-lg);
    overflow: hidden;
}

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

.scan-overlay {
    position: absolute;
    inset: 0;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    pointer-events: none;
}

.scan-corners {
    position: relative;
    width: 60%;
    height: 60%;
}

.scan-corners span {
    position: absolute;
    width: 24px;
    height: 24px;
    border-color: var(--accent);
    border-style: solid;
    border-width: 0;
}

.scan-corners span:nth-child(1) {
    top: 0; left: 0;
    border-top-width: 3px;
    border-left-width: 3px;
    border-top-left-radius: 8px;
}

.scan-corners span:nth-child(2) {
    top: 0; right: 0;
    border-top-width: 3px;
    border-right-width: 3px;
    border-top-right-radius: 8px;
}

.scan-corners span:nth-child(3) {
    bottom: 0; left: 0;
    border-bottom-width: 3px;
    border-left-width: 3px;
    border-bottom-left-radius: 8px;
}

.scan-corners span:nth-child(4) {
    bottom: 0; right: 0;
    border-bottom-width: 3px;
    border-right-width: 3px;
    border-bottom-right-radius: 8px;
}

.scan-hint {
    position: absolute;
    bottom: 40px;
    color: var(--text-2);
    font-size: 14px;
    background: rgba(0,0,0,0.6);
    padding: 6px 12px;
    border-radius: 20px;
}

/* === BUTTONS === */
.scanner-controls {
    display: flex;
    gap: 12px;
}

.btn-scan, .btn-stop, .btn-primary {
    flex: 1;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    padding: 16px 24px;
    border: none;
    border-radius: var(--radius);
    font-size: 17px;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.2s;
}

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

.btn-scan:hover {
    background: var(--accent-hover);
    transform: scale(0.98);
}

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

.btn-primary {
    background: var(--surface-2);
    color: var(--text);
    border: 1px solid var(--surface-2);
    margin-top: 8px;
}

.btn-primary:hover {
    background: var(--surface);
    border-color: var(--text-2);
}

/* === DIVIDER === */
.divider {
    display: flex;
    align-items: center;
    gap: 16px;
    color: var(--text-2);
    font-size: 13px;
}

.divider::before,
.divider::after {
    content: '';
    flex: 1;
    height: 1px;
    background: var(--surface-2);
}

/* === UPLOAD === */
.upload-section {
    display: flex;
    justify-content: center;
}

.upload-btn {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 10px;
    width: 100%;
    padding: 16px 24px;
    background: var(--surface);
    border: 2px dashed var(--surface-2);
    border-radius: var(--radius);
    color: var(--text);
    font-size: 16px;
    font-weight: 500;
    cursor: pointer;
    transition: all 0.2s;
}

.upload-btn:hover {
    border-color: var(--accent);
    background: var(--surface-2);
}

#image-upload {
    display: none;
}

/* === MANUAL SEARCH === */
.manual-search {
    background: var(--surface);
    border-radius: var(--radius);
    padding: 16px;
}

.manual-search-label {
    font-size: 13px;
    color: var(--text-2);
    margin-bottom: 10px;
}

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

.manual-search-input input {
    flex: 1;
    background: var(--surface-2);
    border: none;
    border-radius: var(--radius-sm);
    padding: 14px 16px;
    color: var(--text);
    font-size: 16px;
    outline: none;
}

.manual-search-input input::placeholder {
    color: var(--text-2);
}

.manual-search-input input:focus {
    background: var(--bg);
    box-shadow: 0 0 0 2px var(--accent);
}

.manual-search-input button {
    width: 50px;
    background: var(--accent);
    border: none;
    border-radius: var(--radius-sm);
    color: white;
    cursor: pointer;
    transition: background 0.2s;
}

.manual-search-input button:hover {
    background: var(--accent-hover);
}

/* === LOADING === */
.loading {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    padding: 80px 20px;
    gap: 16px;
}

.loading-spinner {
    width: 40px;
    height: 40px;
    border: 3px solid var(--surface-2);
    border-top-color: var(--accent);
    border-radius: 50%;
    animation: spin 0.8s linear infinite;
}

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

.loading p {
    color: var(--text-2);
}

/* === ERROR === */
.error {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    padding: 60px 20px;
    gap: 16px;
    text-align: center;
}

.error-icon {
    font-size: 48px;
}

.error p {
    color: var(--text-2);
    max-width: 280px;
}

.btn-secondary {
    background: var(--surface);
    color: var(--text);
    border: 1px solid var(--surface-2);
    padding: 14px 28px;
    border-radius: var(--radius);
    font-size: 16px;
    font-weight: 500;
    cursor: pointer;
    transition: all 0.2s;
}

.btn-secondary:hover {
    background: var(--surface-2);
}

/* === RESULT VIEW === */
.result-view {
    display: flex;
    flex-direction: column;
    gap: 20px;
}

.product-card {
    background: var(--surface);
    border-radius: var(--radius-lg);
    padding: 24px;
}

.product-image-wrap {
    width: 100%;
    height: 200px;
    background: var(--surface-2);
    border-radius: var(--radius);
    overflow: hidden;
    margin-bottom: 20px;
    display: flex;
    align-items: center;
    justify-content: center;
}

.product-image-wrap img {
    max-width: 100%;
    max-height: 100%;
    object-fit: contain;
}

.product-name {
    font-size: 22px;
    font-weight: 700;
    line-height: 1.3;
    margin-bottom: 4px;
}

.product-brand {
    color: var(--text-2);
    font-size: 15px;
    margin-bottom: 20px;
}

/* === NUTRI SCORE === */
.nutri-score {
    display: flex;
    align-items: center;
    gap: 16px;
    background: var(--surface-2);
    border-radius: var(--radius);
    padding: 16px;
    margin-bottom: 20px;
}

.score-circle {
    width: 56px;
    height: 56px;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 26px;
    font-weight: 700;
    color: white;
}

.score-circle.A { background: var(--success); }
.score-circle.B { background: #84CC16; }
.score-circle.C { background: var(--warning); }
.score-circle.D { background: #F97316; }
.score-circle.E { background: var(--danger); }

.score-text {
    flex: 1;
}

.score-text span {
    font-size: 12px;
    color: var(--text-2);
    text-transform: uppercase;
    letter-spacing: 0.5px;
}

.score-text p {
    font-size: 14px;
    color: var(--text-2);
    margin-top: 2px;
}

/* === INFO GRID === */
.info-grid {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 12px;
    margin-bottom: 20px;
}

.info-item {
    background: var(--surface-2);
    border-radius: var(--radius-sm);
    padding: 14px;
}

.info-label {
    display: block;
    font-size: 11px;
    color: var(--text-2);
    text-transform: uppercase;
    letter-spacing: 0.5px;
    margin-bottom: 4px;
}

.info-value {
    font-size: 15px;
    font-weight: 500;
}

/* === SECTIONS === */
.section {
    margin-bottom: 16px;
}

.section h3 {
    font-size: 12px;
    color: var(--text-2);
    text-transform: uppercase;
    letter-spacing: 0.5px;
    margin-bottom: 8px;
}

.ingredients-text {
    font-size: 14px;
    line-height: 1.6;
    color: var(--text-2);
}

/* === ALLERGENS === */
.allergens {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
}

.allergen-tag {
    padding: 8px 14px;
    border-radius: 20px;
    font-size: 13px;
    font-weight: 500;
}

.allergen-tag.high {
    background: rgba(255, 69, 58, 0.15);
    color: var(--danger);
}

.allergen-tag.medium {
    background: rgba(255, 159, 10, 0.15);
    color: var(--warning);
}

/* === BARCODE === */
.barcode-info {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding-top: 16px;
    border-top: 1px solid var(--surface-2);
    margin-top: 8px;
}

.barcode-value {
    font-family: 'SF Mono', Monaco, monospace;
    font-size: 13px;
    color: var(--text-2);
}
