/* ── Reset & Base ──────────────────────────────────────────────────────────── */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

:root {
  --clr-bg:         #0f1117;
  --clr-surface:    #1a1d27;
  --clr-surface2:   #22263a;
  --clr-border:     #2e3250;
  --clr-primary:    #6c63ff;
  --clr-primary-h:  #5a52e0;
  --clr-success:    #22c55e;
  --clr-danger:     #ef4444;
  --clr-warning:    #f59e0b;
  --clr-text:       #e2e8f0;
  --clr-muted:      #94a3b8;
  --radius:         12px;
  --radius-sm:      8px;
  --shadow:         0 4px 24px rgba(0,0,0,.45);
  --transition:     .2s ease;
}

html, body {
  height: 100%;
  font-family: 'Segoe UI', system-ui, -apple-system, sans-serif;
  background: var(--clr-bg);
  color: var(--clr-text);
  line-height: 1.6;
}

a { color: var(--clr-primary); text-decoration: none; }
a:hover { text-decoration: underline; }

/* ── Navbar ─────────────────────────────────────────────────────────────────── */
.navbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: .9rem 2rem;
  background: var(--clr-surface);
  border-bottom: 1px solid var(--clr-border);
  position: sticky;
  top: 0;
  z-index: 100;
}

.nav-brand {
  font-size: 1.15rem;
  font-weight: 700;
  letter-spacing: .02em;
}

.nav-links { display: flex; gap: 1.4rem; align-items: center; }
.nav-links a { font-size: .9rem; color: var(--clr-muted); transition: color var(--transition); }
.nav-links a:hover { color: var(--clr-text); text-decoration: none; }

.btn-logout {
  background: var(--clr-surface2);
  border: 1px solid var(--clr-border);
  border-radius: var(--radius-sm);
  padding: .35rem .85rem;
  font-size: .85rem !important;
  color: var(--clr-muted) !important;
  transition: background var(--transition), color var(--transition) !important;
}
.btn-logout:hover { background: var(--clr-border); color: var(--clr-text) !important; }

/* ── Main ───────────────────────────────────────────────────────────────────── */
.main-content { padding: 0; }

/* ── Buttons ────────────────────────────────────────────────────────────────── */
.btn {
  display: inline-flex;
  align-items: center;
  gap: .45rem;
  padding: .65rem 1.4rem;
  border: none;
  border-radius: var(--radius-sm);
  font-size: .95rem;
  font-weight: 600;
  cursor: pointer;
  transition: opacity var(--transition), transform var(--transition);
  white-space: nowrap;
}
.btn:hover  { opacity: .88; transform: translateY(-1px); }
.btn:active { transform: translateY(0); }

.btn-primary  { background: var(--clr-primary);  color: #fff; }
.btn-primary:hover  { background: var(--clr-primary-h); }
.btn-secondary { background: var(--clr-surface2); color: var(--clr-text); border: 1px solid var(--clr-border); }
.btn-danger   { background: var(--clr-danger);   color: #fff; }
.btn-full     { width: 100%; justify-content: center; }

.btn-icon { font-size: 1.1em; }

/* ── Auth pages ─────────────────────────────────────────────────────────────── */
.auth-container {
  min-height: calc(100vh - 4rem);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 2rem 1rem;
}

.auth-card {
  background: var(--clr-surface);
  border: 1px solid var(--clr-border);
  border-radius: var(--radius);
  padding: 2.5rem 2rem;
  width: 100%;
  max-width: 420px;
  box-shadow: var(--shadow);
}

.auth-logo  { font-size: 2.5rem; text-align: center; margin-bottom: .6rem; }
.auth-title { font-size: 1.35rem; font-weight: 700; text-align: center; margin-bottom: .25rem; }
.auth-subtitle { text-align: center; color: var(--clr-muted); font-size: .9rem; margin-bottom: 1.75rem; }

.auth-form { display: flex; flex-direction: column; gap: 1.1rem; }

.form-group { display: flex; flex-direction: column; gap: .4rem; }
.form-group label { font-size: .88rem; font-weight: 600; color: var(--clr-muted); letter-spacing: .03em; }
.form-group input {
  background: var(--clr-surface2);
  border: 1px solid var(--clr-border);
  border-radius: var(--radius-sm);
  padding: .65rem .9rem;
  color: var(--clr-text);
  font-size: .95rem;
  transition: border-color var(--transition);
  outline: none;
}
.form-group input:focus { border-color: var(--clr-primary); }

.auth-footer {
  text-align: center;
  margin-top: 1.4rem;
  font-size: .88rem;
  color: var(--clr-muted);
}

/* ── Alerts ─────────────────────────────────────────────────────────────────── */
.alert {
  border-radius: var(--radius-sm);
  padding: .75rem 1rem;
  font-size: .9rem;
  margin-bottom: 1rem;
}
.alert-error   { background: rgba(239,68,68,.15); border: 1px solid rgba(239,68,68,.4); color: #fca5a5; }
.alert-success { background: rgba(34,197,94,.15);  border: 1px solid rgba(34,197,94,.4); color: #86efac; }

/* ── Analyse page ───────────────────────────────────────────────────────────── */
.analyse-container {
  max-width: 760px;
  margin: 0 auto;
  padding: 2rem 1rem 4rem;
}

.visually-hidden-input {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
}

/* ─── Upload screen ──────────────────────────────────────────────────────────── */
.hero {
  text-align: center;
  margin-bottom: 2rem;
}
.hero-icon { font-size: 2.8rem; margin-bottom: .5rem; }
.hero h1   { font-size: 1.9rem; font-weight: 800; }
.hero p    { color: var(--clr-muted); margin-top: .4rem; font-size: 1rem; }

/* Drop zone */
.dropzone {
  border: 2px dashed var(--clr-border);
  border-radius: 20px;
  background: var(--clr-surface);
  padding: 3rem 2rem;
  text-align: center;
  transition: border-color var(--transition), background var(--transition);
  cursor: pointer;
}
.dropzone.dz-hover {
  border-color: var(--clr-primary);
  background: rgba(108,99,255,.06);
}

.dz-icon  { font-size: 3rem; margin-bottom: .75rem; opacity: .5; }
.dz-title { font-size: 1.15rem; font-weight: 700; margin-bottom: .3rem; }
.dz-sub   { color: var(--clr-muted); font-size: .9rem; margin-bottom: 1.75rem; }

.dz-actions {
  display: flex;
  justify-content: center;
  gap: 1rem;
  flex-wrap: wrap;
  margin-bottom: 1.2rem;
}
.dz-actions .btn { min-width: 160px; justify-content: center; padding: .75rem 1.6rem; font-size: .95rem; }

.dz-formats { font-size: .78rem; color: var(--clr-muted); letter-spacing: .03em; }

/* ─── Shared screen chrome ───────────────────────────────────────────────────── */
.screen-header {
  display: flex;
  align-items: center;
  gap: 1rem;
  margin-bottom: 1.25rem;
}
.screen-header h2 { font-size: 1.2rem; font-weight: 700; }

.btn-back {
  display: inline-flex;
  align-items: center;
  gap: .3rem;
  background: var(--clr-surface2);
  border: 1px solid var(--clr-border);
  border-radius: var(--radius-sm);
  padding: .45rem .9rem;
  color: var(--clr-muted);
  font-size: .88rem;
  font-weight: 600;
  cursor: pointer;
  transition: background var(--transition), color var(--transition);
}
.btn-back:hover { background: var(--clr-border); color: var(--clr-text); }

/* ─── Camera screen ──────────────────────────────────────────────────────────── */
.camera-frame {
  position: relative;
  border-radius: 16px;
  overflow: hidden;
  background: #000;
  aspect-ratio: 4/3;
}
.camera-frame #videoFeed {
  width: 100%;
  height: 100%;
  object-fit: cover;
  display: block;
}

/* Corner guides */
.camera-overlay {
  position: absolute;
  inset: 0;
  pointer-events: none;
}
.camera-corner {
  position: absolute;
  width: 28px;
  height: 28px;
  border-color: rgba(255,255,255,.7);
  border-style: solid;
  border-width: 0;
}
.camera-corner.tl { top: 14px; left: 14px; border-top-width: 3px; border-left-width: 3px; border-radius: 4px 0 0 0; }
.camera-corner.tr { top: 14px; right: 14px; border-top-width: 3px; border-right-width: 3px; border-radius: 0 4px 0 0; }
.camera-corner.bl { bottom: 14px; left: 14px; border-bottom-width: 3px; border-left-width: 3px; border-radius: 0 0 0 4px; }
.camera-corner.br { bottom: 14px; right: 14px; border-bottom-width: 3px; border-right-width: 3px; border-radius: 0 0 4px 0; }

.camera-bar {
  display: flex;
  justify-content: center;
  padding: 1.5rem 0 .5rem;
}

/* Shutter button */
.btn-shutter {
  position: relative;
  width: 70px;
  height: 70px;
  border-radius: 50%;
  background: #fff;
  border: none;
  cursor: pointer;
  transition: transform var(--transition);
  box-shadow: 0 0 0 5px rgba(255,255,255,.25);
}
.btn-shutter:hover  { transform: scale(1.07); }
.btn-shutter:active { transform: scale(.95); }
.shutter-ring {
  position: absolute;
  inset: 5px;
  border-radius: 50%;
  border: 3px solid #ccc;
  background: #fff;
}

/* ─── Preview screen ─────────────────────────────────────────────────────────── */
.preview-frame {
  border-radius: 16px;
  overflow: hidden;
  background: #000;
  text-align: center;
  max-height: 460px;
}
.preview-frame img {
  max-width: 100%;
  max-height: 460px;
  object-fit: contain;
  display: block;
  margin: 0 auto;
}

.preview-bar {
  display: flex;
  justify-content: center;
  padding: 1.5rem 0 .5rem;
}
.btn-lg { padding: .85rem 2.2rem; font-size: 1.05rem; }

/* ─── Loader screen ──────────────────────────────────────────────────────────── */
.loader-body {
  display: flex;
  flex-direction: column;
  align-items: center;
  padding: 4rem 2rem;
  gap: 1rem;
  text-align: center;
}
.loader-body h2   { font-size: 1.35rem; font-weight: 700; }
.loader-body > p  { color: var(--clr-muted); }

/* Pulse animation */
.pulse-ring {
  width: 90px;
  height: 90px;
  border-radius: 50%;
  background: rgba(108,99,255,.12);
  display: flex;
  align-items: center;
  justify-content: center;
  animation: pulse-outer 1.4s ease-in-out infinite;
  margin-bottom: .5rem;
}
.pulse-dot {
  width: 46px;
  height: 46px;
  border-radius: 50%;
  background: var(--clr-primary);
  animation: pulse-inner 1.4s ease-in-out infinite;
}
@keyframes pulse-outer { 0%,100%{transform:scale(1);opacity:1} 50%{transform:scale(1.15);opacity:.7} }
@keyframes pulse-inner { 0%,100%{transform:scale(1)} 50%{transform:scale(.85)} }

.loader-steps {
  display: flex;
  flex-direction: column;
  gap: .5rem;
  margin-top: .75rem;
  width: 100%;
  max-width: 300px;
}
.loader-steps .step {
  padding: .55rem 1rem;
  border-radius: 99px;
  font-size: .88rem;
  font-weight: 600;
  color: var(--clr-muted);
  background: var(--clr-surface);
  border: 1px solid var(--clr-border);
  transition: all .3s ease;
}
.loader-steps .step.active {
  color: var(--clr-primary);
  border-color: var(--clr-primary);
  background: rgba(108,99,255,.1);
}
.loader-steps .step.done {
  color: var(--clr-success);
  border-color: rgba(34,197,94,.35);
  background: rgba(34,197,94,.07);
}

/* ─── Results screen ─────────────────────────────────────────────────────────── */

/* Top row: image + summary/legend side-by-side */
.res-top-row {
  display: grid;
  grid-template-columns: 180px 1fr;
  gap: 1.25rem;
  margin-bottom: 1.5rem;
  align-items: start;
}

.res-img-col img {
  width: 100%;
  border-radius: 14px;
  object-fit: cover;
  aspect-ratio: 1;
  display: block;
  border: 1px solid var(--clr-border);
}

.res-summary-col {
  display: flex;
  flex-direction: column;
  gap: 1rem;
}

/* Summary count chips */
.res-summary-counts {
  display: flex;
  flex-wrap: wrap;
  gap: .6rem;
}

.summary-chip {
  display: flex;
  align-items: center;
  gap: .45rem;
  background: var(--clr-surface);
  border: 1px solid color-mix(in srgb, var(--chip-color) 30%, transparent);
  border-radius: 99px;
  padding: .4rem .85rem .4rem .6rem;
  transition: background var(--transition);
}
.summary-chip:hover { background: var(--clr-surface2); }

.chip-dot {
  width: 10px;
  height: 10px;
  border-radius: 50%;
  background: var(--chip-color);
  flex-shrink: 0;
}
.chip-count {
  font-size: 1rem;
  font-weight: 800;
  color: var(--chip-color);
  min-width: 1ch;
}
.chip-label {
  font-size: .8rem;
  font-weight: 600;
  color: var(--clr-muted);
}

/* Legend */
.res-legend {
  background: var(--clr-surface);
  border: 1px solid var(--clr-border);
  border-radius: var(--radius);
  padding: .9rem 1rem;
  display: flex;
  flex-direction: column;
  gap: .55rem;
}

.legend-title {
  font-size: .72rem;
  font-weight: 700;
  color: var(--clr-muted);
  text-transform: uppercase;
  letter-spacing: .05em;
  margin-bottom: .1rem;
}

.legend-item {
  display: flex;
  align-items: flex-start;
  gap: .6rem;
}

.legend-dot {
  width: 10px;
  height: 10px;
  border-radius: 50%;
  flex-shrink: 0;
  margin-top: .3rem;
}

.legend-text {
  display: flex;
  flex-direction: column;
  gap: .05rem;
}

.legend-name {
  font-size: .82rem;
  font-weight: 700;
  color: var(--clr-text);
}

.legend-desc {
  font-size: .75rem;
  color: var(--clr-muted);
  line-height: 1.4;
}

/* Section header */
.res-section { margin-bottom: 1.25rem; }

.res-section-title {
  display: flex;
  align-items: center;
  gap: .5rem;
  font-size: .8rem;
  font-weight: 700;
  color: var(--clr-muted);
  text-transform: uppercase;
  letter-spacing: .05em;
  margin-bottom: .85rem;
}

/* Ingredients grid */
.ingredients-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(280px, 1fr));
  gap: .85rem;
}

.ingredient-card {
  background: var(--clr-surface);
  border: 1px solid var(--clr-border);
  border-left: 3px solid var(--ing-color, var(--clr-border));
  border-radius: var(--radius);
  padding: .95rem 1rem;
  display: flex;
  flex-direction: column;
  gap: .45rem;
  transition: border-color var(--transition), background var(--transition);
}
.ingredient-card:hover {
  background: var(--clr-surface2);
}

.ing-header {
  display: flex;
  align-items: center;
  gap: .5rem;
  flex-wrap: wrap;
}

.ing-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  flex-shrink: 0;
}

.ing-name {
  font-size: .95rem;
  font-weight: 700;
  color: var(--clr-text);
  flex: 1;
}

.ing-group-badge {
  font-size: .7rem;
  font-weight: 700;
  padding: .2rem .55rem;
  border-radius: 99px;
  border: 1px solid;
  white-space: nowrap;
}

.ing-alias {
  font-size: .75rem;
  color: var(--clr-muted);
  font-style: italic;
}

.ing-explanation {
  font-size: .83rem;
  color: var(--clr-muted);
  line-height: 1.55;
  margin: 0;
}

/* Source note */
.res-source {
  display: flex;
  align-items: flex-start;
  gap: .5rem;
  background: var(--clr-surface);
  border: 1px solid var(--clr-border);
  border-radius: var(--radius);
  padding: .85rem 1rem;
  font-size: .78rem;
  color: var(--clr-muted);
  line-height: 1.5;
  margin-bottom: 1.25rem;
}
.res-source svg {
  flex-shrink: 0;
  margin-top: .2rem;
  color: var(--clr-primary);
}
#resSourceText {
  display: flex;
  flex-direction: column;
  gap: .55rem;
}
.source-intro {
  display: block;
  color: var(--clr-muted);
  font-size: .78rem;
  padding-bottom: .4rem;
  border-bottom: 1px solid var(--clr-border);
}
.source-row {
  display: flex;
  align-items: flex-start;
  gap: .55rem;
  font-size: .8rem;
  color: var(--clr-muted);
  line-height: 1.5;
}
.source-dot {
  width: 9px;
  height: 9px;
  border-radius: 50%;
  flex-shrink: 0;
  margin-top: .32rem;
}

/* Raw JSON fallback */
.results-table-card {
  background: var(--clr-surface);
  border: 1px solid var(--clr-border);
  border-radius: 16px;
  padding: 1.25rem 1.25rem 1rem;
  margin-bottom: 1.25rem;
}
.results-table-card h3 {
  font-size: .8rem;
  font-weight: 700;
  color: var(--clr-muted);
  text-transform: uppercase;
  letter-spacing: .05em;
  margin-bottom: 1rem;
}

#rawJson {
  background: var(--clr-surface2);
  border: 1px solid var(--clr-border);
  border-radius: var(--radius-sm);
  padding: 1rem;
  font-family: monospace;
  font-size: .82rem;
  white-space: pre-wrap;
  word-break: break-all;
  color: #a5f3fc;
  max-height: 320px;
  overflow-y: auto;
}

/* ─── Error screen ───────────────────────────────────────────────────────────── */
.error-body {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 1rem;
  padding: 4rem 2rem;
  text-align: center;
}
.error-emoji { font-size: 3.5rem; }
.error-body h2 { font-size: 1.4rem; font-weight: 700; }
#errorMsg { color: var(--clr-muted); max-width: 380px; font-size: .95rem; }

/* ── Responsive ─────────────────────────────────────────────────────────────── */
@media (max-width: 700px) {
  .res-top-row { grid-template-columns: 1fr; }
  .res-img-col img { max-height: 220px; aspect-ratio: unset; object-fit: cover; }
  .ingredients-grid { grid-template-columns: 1fr; }
  .dz-actions { flex-direction: column; }
  .dz-actions .btn { min-width: unset; width: 100%; }
}

