:root {
  --primary: #E40000;
  --primary-dark: #cc0000;
  --bg: #f8fafc;
  --bg-card: #ffffff;
  --text: #0f172a;
  --text-secondary: #64748b;
  --border: #e2e8f0;
  --success: #16a34a;
  --warning: #f59e0b;
  --danger: #E40000;
  --radius: 12px;
  --shadow: 0 1px 3px rgba(0,0,0,.1), 0 1px 2px rgba(0,0,0,.06);
  --shadow-lg: 0 10px 15px -3px rgba(0,0,0,.1), 0 4px 6px -2px rgba(0,0,0,.05);
}

* { margin: 0; padding: 0; box-sizing: border-box; }
body { font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif; background: var(--bg); color: var(--text); line-height: 1.6; }
a { color: var(--primary); text-decoration: none; }

/* NAV */
.nav { position: sticky; top: 0; z-index: 100; background: var(--bg-card); border-bottom: 1px solid var(--border); padding: 0 24px; display: flex; align-items: center; height: 60px; gap: 24px; }
.nav-brand { display: flex; align-items: center; gap: 10px; font-weight: 700; font-size: 18px; margin-right: 8px; }
.nav-brand span { color: var(--primary); }
.nav-links { display: flex; gap: 4px; }
.nav-links button { background: none; border: none; padding: 8px 16px; border-radius: 8px; font-size: 14px; font-weight: 500; color: var(--text-secondary); cursor: pointer; transition: all .15s; }
.nav-links button:hover { background: var(--bg); color: var(--text); }
.nav-links button.active { background: var(--primary); color: white; }
.nav-right { margin-left: auto; display: flex; align-items: center; gap: 8px; }
.nav-status { display: flex; align-items: center; gap: 6px; font-size: 12px; color: var(--text-secondary); }
.nav-status .dot { width: 8px; height: 8px; border-radius: 50%; background: var(--success); }

/* LANG TOGGLE */
.lang-toggle { background: none; border: 1px solid var(--border); border-radius: 6px; padding: 4px 10px; font-size: 12px; font-weight: 700; cursor: pointer; color: var(--text-secondary); transition: all .15s; }
.lang-toggle:hover { border-color: var(--primary); color: var(--primary); }

/* GDPR BUTTON */
.gdpr-btn { background: none; border: none; font-size: 16px; cursor: pointer; color: var(--text-secondary); padding: 4px 6px; border-radius: 6px; line-height: 1; }
.gdpr-btn:hover { background: var(--bg); }

/* GDPR MODAL */
.gdpr-body { font-size: 14px; line-height: 1.7; }
.gdpr-body ul { margin: 12px 0; padding-left: 20px; }
.gdpr-body li { margin-bottom: 8px; color: var(--text); }
.gdpr-note { margin-top: 16px; font-size: 13px; color: var(--text-secondary); }
.gdpr-note a { color: var(--primary); text-decoration: underline; }

/* LAYOUT */
.container { max-width: 1100px; margin: 0 auto; padding: 32px 24px; }
.view { display: none; }
.view.active { display: block; }

/* CARDS */
.card { background: var(--bg-card); border: 1px solid var(--border); border-radius: var(--radius); box-shadow: var(--shadow); overflow: hidden; }
.card-header { padding: 20px 24px 0; font-size: 13px; font-weight: 600; text-transform: uppercase; letter-spacing: .05em; color: var(--text-secondary); }
.card-body { padding: 20px 24px 24px; }

/* UPLOAD */
.upload-zone { border: 2px dashed var(--border); border-radius: var(--radius); padding: 60px 24px; text-align: center; cursor: pointer; transition: all .2s; position: relative; }
.upload-zone:hover, .upload-zone.dragover { border-color: var(--primary); background: rgba(228,0,0,.03); }
.upload-zone .icon { font-size: 48px; margin-bottom: 16px; }
.upload-zone h3 { font-size: 18px; margin-bottom: 8px; }
.upload-zone p { color: var(--text-secondary); font-size: 14px; }
.upload-zone input { position: absolute; inset: 0; opacity: 0; cursor: pointer; }
.upload-zone .formats { display: flex; gap: 6px; justify-content: center; margin-top: 16px; }
.upload-zone .formats span { padding: 4px 10px; background: var(--bg); border-radius: 6px; font-size: 11px; font-weight: 600; color: var(--text-secondary); }

/* PREVIEW */
.preview { display: flex; gap: 16px; align-items: center; padding: 16px; background: var(--bg); border-radius: var(--radius); margin-bottom: 16px; }
.preview img { width: 120px; height: 90px; object-fit: cover; border-radius: 8px; }
.preview .info { flex: 1; }
.preview .info .name { font-weight: 600; }
.preview .info .size { font-size: 13px; color: var(--text-secondary); }
.preview .remove { background: none; border: none; color: var(--danger); cursor: pointer; font-size: 18px; padding: 4px 8px; border-radius: 6px; }
.preview .remove:hover { background: rgba(228,0,0,.1); }

/* BUTTONS */
.btn { display: inline-flex; align-items: center; gap: 8px; padding: 10px 20px; border-radius: 8px; font-size: 14px; font-weight: 600; border: none; cursor: pointer; transition: all .15s; }
.btn-primary { background: var(--primary); color: white; }
.btn-primary:hover { background: var(--primary-dark); }
.btn-primary:disabled { opacity: .5; cursor: not-allowed; }
.btn-secondary { background: var(--bg); color: var(--text); border: 1px solid var(--border); }
.btn-secondary:hover { background: var(--border); }

/* PROGRESS */
.progress-bar { width: 100%; height: 6px; background: var(--bg); border-radius: 3px; overflow: hidden; margin: 16px 0; }
.progress-bar .fill { height: 100%; background: linear-gradient(90deg, var(--primary), #ff6b6b); border-radius: 3px; transition: width .3s; }
.progress-steps { display: flex; flex-direction: column; gap: 8px; margin-top: 12px; }
.progress-steps .step { font-size: 13px; color: var(--text-secondary); display: flex; align-items: center; gap: 8px; }
.progress-steps .step.done { color: var(--success); }
.progress-steps .step .check { font-size: 14px; }

/* RESULTS */
.result-header { display: flex; align-items: center; justify-content: space-between; padding: 16px 0; border-bottom: 1px solid var(--border); margin-bottom: 24px; }
.result-header h2 { font-size: 20px; }
.confidence-badge { padding: 4px 12px; border-radius: 20px; font-size: 12px; font-weight: 700; }
.confidence-high { background: rgba(22,163,74,.1); color: var(--success); }
.confidence-medium { background: rgba(245,158,11,.1); color: var(--warning); }
.confidence-low { background: rgba(228,0,0,.1); color: var(--danger); }

.fields-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(200px, 1fr)); gap: 12px; margin-bottom: 24px; }
.field-item { padding: 12px; background: var(--bg); border-radius: 8px; }
.field-item .label { font-size: 11px; font-weight: 600; text-transform: uppercase; letter-spacing: .05em; color: var(--text-secondary); margin-bottom: 4px; }
.field-item .value { font-size: 15px; font-weight: 600; }

.match-card { border: 1px solid var(--border); border-radius: var(--radius); padding: 16px; margin-bottom: 12px; transition: border-color .15s; }
.match-card:hover { border-color: var(--primary); }
.match-card .match-header { display: flex; justify-content: space-between; align-items: center; margin-bottom: 8px; }
.match-card .match-header h4 { font-size: 15px; }
.match-card .match-score { font-weight: 700; color: var(--primary); }
.match-card .match-details { display: flex; gap: 16px; font-size: 13px; color: var(--text-secondary); flex-wrap: wrap; }
.match-card .match-reason { margin-top: 8px; font-size: 13px; color: var(--text-secondary); padding: 8px 12px; background: var(--bg); border-radius: 6px; }

.raw-text { padding: 16px; background: #1e293b; color: #e2e8f0; border-radius: 8px; font-family: 'SF Mono', Menlo, monospace; font-size: 13px; white-space: pre-wrap; word-break: break-word; max-height: 200px; overflow-y: auto; margin-top: 16px; }

/* TABLE */
.table-wrap { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; font-size: 14px; }
th { text-align: left; padding: 12px 16px; font-size: 12px; font-weight: 600; text-transform: uppercase; letter-spacing: .05em; color: var(--text-secondary); border-bottom: 2px solid var(--border); }
td { padding: 12px 16px; border-bottom: 1px solid var(--border); }
tr:hover td { background: rgba(0,0,0,.01); }

/* STATS */
.stats-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(200px, 1fr)); gap: 16px; margin-bottom: 24px; }
.stat-card { background: var(--bg-card); border: 1px solid var(--border); border-radius: var(--radius); padding: 20px; }
.stat-card .stat-value { font-size: 32px; font-weight: 700; }
.stat-card .stat-label { font-size: 13px; color: var(--text-secondary); margin-top: 4px; }

/* SEARCH */
.search-bar { display: flex; gap: 8px; margin-bottom: 20px; }
.search-bar input { flex: 1; padding: 10px 16px; border: 1px solid var(--border); border-radius: 8px; font-size: 14px; outline: none; }
.search-bar input:focus { border-color: var(--primary); box-shadow: 0 0 0 3px rgba(228,0,0,.1); }

/* FILTERS */
.filter-bar { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; margin-top: 12px; }
.filter-bar select { padding: 8px 12px; border: 1px solid var(--border); border-radius: 6px; font-size: 13px; background: white; outline: none; cursor: pointer; }
.filter-bar select:focus { border-color: var(--primary); }
.browser-controls { display: flex; flex-direction: column; gap: 0; }

/* PAGINATION */
.pagination { display: flex; gap: 4px; justify-content: center; align-items: center; margin-top: 16px; padding: 8px 0; }
.pagination button { min-width: 36px; padding: 6px 10px; border: 1px solid var(--border); border-radius: 6px; background: white; font-size: 13px; cursor: pointer; transition: all .15s; }
.pagination button:hover { background: var(--bg); border-color: var(--primary); }
.pagination button.active { background: var(--primary); color: white; border-color: var(--primary); }
.pagination button:disabled { opacity: .4; cursor: not-allowed; }
.pagination .page-info { font-size: 13px; color: var(--text-secondary); margin: 0 8px; }

/* DETAIL PANEL */
.detail-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.detail-field { padding: 12px; background: var(--bg); border-radius: 8px; }
.detail-field .label { font-size: 11px; font-weight: 600; text-transform: uppercase; letter-spacing: .05em; color: var(--text-secondary); margin-bottom: 4px; }
.detail-field .value { font-size: 15px; font-weight: 600; word-break: break-word; }
.detail-raw { margin-top: 16px; }
.detail-raw summary { cursor: pointer; font-size: 13px; color: var(--text-secondary); }
.detail-raw pre { margin-top: 8px; padding: 12px; background: #1e293b; color: #e2e8f0; border-radius: 8px; font-size: 12px; max-height: 300px; overflow: auto; }

/* EMPTY */
.empty { text-align: center; padding: 48px 24px; color: var(--text-secondary); }
.empty .icon { font-size: 48px; margin-bottom: 12px; }

/* ENERGY BADGE */
.energy-badge { display: inline-block; padding: 2px 8px; border-radius: 4px; font-size: 12px; font-weight: 700; background: #166534; color: #bbf7d0; }

/* ERROR */
.error { padding: 12px 16px; background: rgba(228,0,0,.05); border: 1px solid rgba(228,0,0,.2); border-radius: 8px; color: var(--danger); font-size: 14px; margin-bottom: 16px; }

/* CAMERA BUTTON + UPLOAD LAYOUT */
.upload-actions { display: flex; gap: 16px; align-items: stretch; }
.upload-zone { flex: 1; }
.divider { display: flex; align-items: center; color: var(--text-secondary); font-size: 13px; }
.btn-camera { padding: 20px 32px; background: var(--bg); border: 2px solid var(--border); border-radius: var(--radius); font-size: 15px; font-weight: 600; cursor: pointer; transition: all .2s; display: flex; align-items: center; gap: 8px; white-space: nowrap; }
.btn-camera:hover { border-color: var(--primary); background: rgba(228,0,0,.03); }

/* LOCATION BADGE */
.location-badge { font-size: 12px; color: var(--primary); margin-top: 4px; display: flex; align-items: center; gap: 4px; cursor: pointer; }
.location-badge:hover { text-decoration: underline; }
.location-badge.add { color: var(--text-secondary); font-style: italic; }
.location-badge.add:hover { color: var(--primary); }

/* MODAL */
.modal { position: fixed; inset: 0; z-index: 200; background: rgba(0,0,0,.5); display: flex; align-items: center; justify-content: center; }
.modal-content { background: var(--bg-card); border-radius: var(--radius); width: 90%; max-width: 500px; max-height: 90vh; overflow-y: auto; box-shadow: var(--shadow-lg); }
.modal-header { display: flex; align-items: center; justify-content: space-between; padding: 20px 24px 0; }
.modal-header h3 { font-size: 18px; }
.modal-close { background: none; border: none; font-size: 24px; cursor: pointer; color: var(--text-secondary); padding: 4px 8px; border-radius: 6px; }
.modal-close:hover { background: var(--bg); }
.modal-body { padding: 20px 24px; }
.modal-footer { padding: 0 24px 20px; display: flex; gap: 8px; justify-content: flex-end; }

/* CAMERA */
#camera-preview { width: 100%; border-radius: 8px; background: #000; }

/* LOCATION */
.location-options { display: flex; flex-direction: column; gap: 8px; }
.loc-btn { justify-content: center; }
.form-row { display: flex; gap: 8px; margin-bottom: 8px; }
.form-input { flex: 1; padding: 10px 14px; border: 1px solid var(--border); border-radius: 8px; font-size: 14px; outline: none; }
.form-input:focus { border-color: var(--primary); box-shadow: 0 0 0 3px rgba(228,0,0,.1); }

/* GUIDE PROMPT */
.guide-prompt { font-size: 13px; color: var(--text-secondary); margin-bottom: 16px; display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
.btn-link { background: none; border: none; color: var(--primary); cursor: pointer; font-size: 13px; font-weight: 600; text-decoration: underline; padding: 0; }
.btn-link:hover { color: var(--primary-dark); }

/* GUIDE MODAL */
.guide-diagram { background: var(--bg); border-radius: 8px; padding: 12px; margin-bottom: 16px; border: 1px solid var(--border); }
.guide-legend { display: flex; flex-wrap: wrap; gap: 12px; margin-bottom: 16px; padding: 12px; background: var(--bg); border-radius: 8px; }
.legend-item { display: flex; align-items: center; gap: 6px; font-size: 13px; }
.legend-item .dot { width: 10px; height: 10px; border-radius: 50%; flex-shrink: 0; }
.guide-tips { background: rgba(228,0,0,.03); border: 1px solid rgba(228,0,0,.1); border-radius: 8px; padding: 16px; }
.guide-tips h4 { font-size: 14px; margin-bottom: 8px; color: var(--text); }
.guide-tips ul { margin: 0; padding-left: 20px; }
.guide-tips li { font-size: 13px; color: var(--text-secondary); margin-bottom: 6px; line-height: 1.5; }

/* IMAGE GALLERY */
.image-gallery { display: flex; gap: 10px; overflow-x: auto; padding: 8px 0 12px; scroll-snap-type: x mandatory; }
.image-gallery .gallery-item { flex-shrink: 0; width: 140px; scroll-snap-align: start; cursor: pointer; position: relative; }
.image-gallery .gallery-item img { width: 140px; height: 100px; object-fit: cover; border-radius: 8px; border: 2px solid var(--border); transition: border-color .15s; display: block; }
.image-gallery .gallery-item:hover img { border-color: var(--primary); }
.image-gallery .gallery-item .gallery-name { font-size: 11px; color: var(--text-secondary); margin-top: 4px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; max-width: 140px; }
.image-gallery .gallery-item .gallery-check { position: absolute; top: 4px; right: 4px; background: var(--primary); color: white; width: 20px; height: 20px; border-radius: 50%; display: flex; align-items: center; justify-content: center; font-size: 11px; font-weight: bold; }

/* PER-IMAGE RESULTS */
.per-image-toggle { background: none; border: 1px solid var(--border); border-radius: 6px; padding: 6px 12px; font-size: 12px; cursor: pointer; color: var(--text-secondary); margin-top: 12px; }
.per-image-toggle:hover { border-color: var(--primary); color: var(--primary); }
.per-image-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(240px, 1fr)); gap: 12px; margin-top: 12px; }
.per-image-card { border: 1px solid var(--border); border-radius: 8px; padding: 12px; font-size: 13px; }
.per-image-card .img-head { font-weight: 600; margin-bottom: 4px; font-size: 12px; }
.per-image-card .img-conf { color: var(--text-secondary); font-size: 11px; margin-bottom: 6px; }
.per-image-card .img-field { display: flex; justify-content: space-between; padding: 2px 0; }
.per-image-card .img-field .lbl { color: var(--text-secondary); }
.per-image-card .img-field .val { font-weight: 500; }
.per-image-card .img-empty { color: var(--text-secondary); font-size: 11px; }

/* RESPONSIVE */
@media (max-width: 640px) {
  .search-bar { flex-wrap: wrap; }
  .search-bar input { flex: 1 1 100%; }
  .search-bar .btn { flex: 1 1 45%; justify-content: center; }
  .upload-actions { flex-direction: column; }
  .divider { padding: 8px 0; }
  .nav { padding: 10px 16px; gap: 12px; flex-wrap: wrap; height: auto; }
  .nav-brand { margin-right: auto; }
  .nav-right { gap: 4px; }
  .nav-links { order: 3; flex-basis: 100%; display: flex; gap: 6px; padding-top: 10px; margin-top: 4px; border-top: 1px solid var(--border); }
  .nav-links button { flex: 1; padding: 9px 6px; font-size: 13px; text-align: center; white-space: nowrap; }
  .container { padding: 16px 12px; }
  .fields-grid { grid-template-columns: 1fr 1fr; }
  .stats-grid { grid-template-columns: 1fr 1fr; }
  .form-row { flex-direction: column; }
  .image-gallery .gallery-item { width: 100px; }
  .image-gallery .gallery-item img { width: 100px; height: 72px; }
  .guide-legend { gap: 8px; }
  .legend-item { font-size: 12px; }
}
