/* ── Reset & Custom Properties ──────────────────────── */
:root {
  --bg:           #0d0d1a;
  --bg2:          #13132a;
  --surface:      rgba(255,255,255,0.06);
  --surface-hi:   rgba(255,255,255,0.10);
  --border:       rgba(255,255,255,0.10);
  --accent:       #7c6af7;
  --accent2:      #e96adb;
  --accent-glow:  rgba(124,106,247,0.25);
  --green:        #4ade80;
  --amber:        #fbbf24;
  --red:          #f87171;
  --text:         #f0f0f8;
  --text2:        #9898b8;
  --text3:        #5a5a7a;
  --radius-s:     10px;
  --radius-m:     16px;
  --radius-l:     24px;
  --radius-xl:    32px;
  --safe-top:     env(safe-area-inset-top, 0px);
  --safe-bottom:  env(safe-area-inset-bottom, 0px);
  --safe-left:    env(safe-area-inset-left, 0px);
  --safe-right:   env(safe-area-inset-right, 0px);
  --sheet-radius: 28px;
}

*, *::before, *::after {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
  -webkit-tap-highlight-color: transparent;
}

html {
  height: 100%;
  height: -webkit-fill-available;
}

body {
  min-height: 100%;
  min-height: -webkit-fill-available;
  overflow: hidden;
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, 'SF Pro Text', 'Segoe UI', system-ui, sans-serif;
  font-size: 16px;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
}

/* ── App Shell ─────────────────────────────────────── */
#app {
  display: flex;
  flex-direction: column;
  height: 100dvh;
  position: relative;
  overflow: hidden;
}

/* ── Header ────────────────────────────────────────── */
.app-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: calc(12px + var(--safe-top)) 20px 12px;
  background: linear-gradient(to bottom, rgba(13,13,26,0.95), rgba(13,13,26,0.7));
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
  position: relative;
  z-index: 20;
  border-bottom: 1px solid var(--border);
}

.header-logo {
  display: flex;
  align-items: center;
  gap: 10px;
}

.header-title {
  font-size: 20px;
  font-weight: 700;
  letter-spacing: -0.3px;
  color: var(--text);
}

.header-title span {
  background: linear-gradient(135deg, var(--accent), var(--accent2));
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  background-clip: text;
}

/* ── Icon Buttons ─────────────────────────────────── */
.icon-btn {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 40px;
  height: 40px;
  border: none;
  background: var(--surface);
  color: var(--text2);
  border-radius: var(--radius-s);
  cursor: pointer;
  transition: background 0.15s, color 0.15s;
  flex-shrink: 0;
}

.icon-btn:hover, .icon-btn:active {
  background: var(--surface-hi);
  color: var(--text);
}

/* ── Camera Wrapper ───────────────────────────────── */
.camera-wrapper {
  position: relative;
  flex: 1;
  overflow: hidden;
  background: #000;
}

#camera-feed {
  width: 100%;
  height: 100%;
  object-fit: cover;
  display: block;
}

#scan-canvas {
  display: none;
}

/* ── Viewfinder ───────────────────────────────────── */
.viewfinder {
  position: absolute;
  inset: 0;
  pointer-events: none;
}

/* Landscape scan bracket — full visible rectangle with corner accents */
.vf-corner {
  position: absolute;
  width: 24px;
  height: 24px;
  border-color: #fff;
  border-style: solid;
  opacity: 1;
  z-index: 1;
}

.vf-tl { top: 38%; left: 4%;  border-width: 3px 0 0 3px; border-radius: 4px 0 0 0; }
.vf-tr { top: 38%; right: 4%; border-width: 3px 3px 0 0; border-radius: 0 4px 0 0; }
.vf-bl { bottom: 38%; left: 4%;  border-width: 0 0 3px 3px; border-radius: 0 0 0 4px; }
.vf-br { bottom: 38%; right: 4%; border-width: 0 3px 3px 0; border-radius: 0 0 4px 0; }

/* Full rectangle connecting the corners — makes the landscape shape unmistakable */
.vf-rect {
  position: absolute;
  top: 38%;
  left: 4%;
  right: 4%;
  bottom: 38%;
  border: 1px solid rgba(255, 255, 255, 0.25);
  border-radius: 6px;
  pointer-events: none;
}

.scan-line {
  position: absolute;
  left: 4%;
  right: 4%;
  height: 2px;
  background: linear-gradient(to right, transparent, var(--accent), transparent);
  top: 38%;
  animation: scanDown 2.5s ease-in-out infinite;
  box-shadow: 0 0 8px var(--accent-glow);
  opacity: 0;
}

.scan-line.active {
  opacity: 1;
}

@keyframes scanDown {
  0%   { transform: translateY(0);    opacity: 0; }
  10%  { opacity: 1; }
  90%  { opacity: 1; }
  100% { transform: translateY(20vh); opacity: 0; }
}

/* ── Camera Hint ──────────────────────────────────── */
.camera-hint {
  position: absolute;
  bottom: 32px;
  left: 50%;
  transform: translateX(-50%);
  display: flex;
  align-items: center;
  gap: 6px;
  background: rgba(0,0,0,0.55);
  backdrop-filter: blur(8px);
  -webkit-backdrop-filter: blur(8px);
  color: rgba(255,255,255,0.85);
  font-size: 13px;
  padding: 8px 16px;
  border-radius: 999px;
  border: 1px solid rgba(255,255,255,0.15);
  white-space: nowrap;
  pointer-events: none;
}

/* ── Scan Pulse Ring ──────────────────────────────── */
.scan-pulse {
  position: absolute;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  width: 80px;
  height: 80px;
  border-radius: 50%;
  border: 2px solid var(--accent);
  pointer-events: none;
  animation: pulseRing 1s ease-out infinite;
}

@keyframes pulseRing {
  0%   { transform: translate(-50%,-50%) scale(0.8); opacity: 1; }
  100% { transform: translate(-50%,-50%) scale(2);   opacity: 0; }
}

/* ── Loading Indicator ────────────────────────────── */
.loading-indicator {
  position: fixed;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  z-index: 60;
  pointer-events: none;
}

.loading-pill {
  display: flex;
  align-items: center;
  gap: 10px;
  background: rgba(13,13,26,0.92);
  backdrop-filter: blur(16px);
  -webkit-backdrop-filter: blur(16px);
  border: 1px solid var(--border);
  color: var(--text);
  font-size: 14px;
  font-weight: 500;
  padding: 12px 20px;
  border-radius: 999px;
  box-shadow: 0 8px 32px rgba(0,0,0,0.5), 0 0 0 1px var(--accent-glow);
}

.loading-dots {
  display: flex;
  gap: 4px;
}

.loading-dots span {
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: var(--accent);
  animation: dotBounce 1.2s ease-in-out infinite;
}

.loading-dots span:nth-child(2) { animation-delay: 0.2s; }
.loading-dots span:nth-child(3) { animation-delay: 0.4s; }

@keyframes dotBounce {
  0%, 80%, 100% { transform: scale(0.7); opacity: 0.5; }
  40% { transform: scale(1); opacity: 1; }
}

/* ── Dish Overlay (Bottom Sheet) ─────────────────── */
.dish-overlay {
  position: fixed;
  inset: 0;
  z-index: 50;
  display: flex;
  flex-direction: column;
  justify-content: flex-end;
}

.overlay-backdrop {
  position: absolute;
  inset: 0;
  background: rgba(0,0,0,0.55);
  backdrop-filter: blur(4px);
  -webkit-backdrop-filter: blur(4px);
  animation: fadeIn 0.25s ease;
}

.overlay-sheet {
  position: relative;
  background: var(--bg2);
  border-radius: var(--sheet-radius) var(--sheet-radius) 0 0;
  border-top: 1px solid var(--border);
  max-height: 80dvh;
  display: flex;
  flex-direction: column;
  animation: slideUp 0.35s cubic-bezier(0.32, 0.72, 0, 1);
  box-shadow: 0 -8px 40px rgba(0,0,0,0.6);
  padding-bottom: var(--safe-bottom);
}

@keyframes slideUp {
  from { transform: translateY(100%); }
  to   { transform: translateY(0); }
}

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

.sheet-handle {
  width: 36px;
  height: 4px;
  background: var(--border);
  border-radius: 2px;
  margin: 10px auto 0;
  flex-shrink: 0;
}

.overlay-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 12px 20px 8px;
  flex-shrink: 0;
}

.detected-chip {
  display: flex;
  align-items: center;
  gap: 6px;
  background: rgba(74,222,128,0.12);
  color: var(--green);
  font-size: 12px;
  font-weight: 600;
  padding: 5px 10px;
  border-radius: 999px;
  border: 1px solid rgba(74,222,128,0.2);
  max-width: 220px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.close-overlay-btn {
  background: var(--surface);
  color: var(--text2);
}

.overlay-scroll {
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  padding: 0 20px 24px;
  flex: 1;
}

/* ── Dish Content ─────────────────────────────────── */
.dish-name {
  font-size: 26px;
  font-weight: 700;
  letter-spacing: -0.5px;
  line-height: 1.2;
  color: var(--text);
  margin-bottom: 10px;
}

.dish-meta {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  margin-bottom: 18px;
}

.badge {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  font-size: 12px;
  font-weight: 600;
  padding: 4px 10px;
  border-radius: 999px;
  border: 1px solid transparent;
}

.badge-cuisine  { background: rgba(124,106,247,0.15); color: var(--accent); border-color: rgba(124,106,247,0.25); }
.badge-diet     { background: rgba(74,222,128,0.12);  color: var(--green);  border-color: rgba(74,222,128,0.2); }
.badge-spicy    { background: rgba(248,113,113,0.12); color: var(--red);    border-color: rgba(248,113,113,0.2); }
.badge-vegan    { background: rgba(74,222,128,0.12);  color: var(--green);  border-color: rgba(74,222,128,0.2); }
.badge-allergen { background: rgba(251,191,36,0.12);  color: var(--amber);  border-color: rgba(251,191,36,0.2); }

/* ── Image Gallery ────────────────────────────────── */
.image-gallery {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 6px;
  margin-bottom: 18px;
  border-radius: var(--radius-m);
  overflow: hidden;
}

.image-gallery:has(.gallery-img:nth-child(1):last-child) {
  grid-template-columns: 1fr;
}

.image-gallery:has(.gallery-img:nth-child(2):last-child) {
  grid-template-columns: 1fr 1fr;
}

.gallery-img-wrap {
  position: relative;
  aspect-ratio: 1;
  overflow: hidden;
  background: var(--surface);
}

.gallery-img-wrap:first-child:nth-last-child(n+3) {
  grid-column: span 2;
  grid-row: span 2;
  aspect-ratio: auto;
}

.gallery-img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  display: block;
  transition: transform 0.3s ease;
}

.gallery-img:active {
  transform: scale(1.05);
}

.gallery-img-placeholder {
  width: 100%;
  height: 100%;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 28px;
  background: var(--surface);
  color: var(--text3);
}

/* ── Dish Description & Extras ───────────────────── */
.dish-description {
  font-size: 15px;
  line-height: 1.65;
  color: var(--text2);
  margin-bottom: 18px;
}

.dish-extras {
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.extra-row {
  display: flex;
  gap: 10px;
  align-items: flex-start;
  font-size: 14px;
}

.extra-label {
  flex-shrink: 0;
  font-weight: 600;
  color: var(--text3);
  min-width: 90px;
  font-size: 12px;
  text-transform: uppercase;
  letter-spacing: 0.5px;
  padding-top: 2px;
}

.extra-value {
  color: var(--text2);
  line-height: 1.5;
}

/* ── Toast Area ──────────────────────────────────── */
.toast-area {
  position: fixed;
  bottom: calc(24px + var(--safe-bottom));
  left: 50%;
  transform: translateX(-50%);
  display: flex;
  flex-direction: column;
  gap: 8px;
  align-items: center;
  z-index: 80;
  pointer-events: none;
  width: min(360px, calc(100vw - 32px));
}

.toast {
  width: 100%;
  background: var(--bg2);
  border: 1px solid var(--border);
  border-radius: var(--radius-m);
  padding: 14px 16px;
  display: flex;
  gap: 12px;
  align-items: flex-start;
  box-shadow: 0 8px 32px rgba(0,0,0,0.5);
  animation: toastIn 0.3s cubic-bezier(0.32, 0.72, 0, 1);
  pointer-events: auto;
}

.toast.toast-exit {
  animation: toastOut 0.25s ease forwards;
}

@keyframes toastIn {
  from { transform: translateY(20px) scale(0.95); opacity: 0; }
  to   { transform: translateY(0) scale(1); opacity: 1; }
}

@keyframes toastOut {
  to { transform: translateY(10px) scale(0.95); opacity: 0; }
}

.toast-icon {
  font-size: 22px;
  line-height: 1;
  flex-shrink: 0;
}

.toast-body strong {
  display: block;
  font-size: 14px;
  color: var(--text);
  margin-bottom: 2px;
}

.toast-body p {
  font-size: 13px;
  color: var(--text2);
}

/* ── Settings Panel ──────────────────────────────── */
.settings-panel {
  position: fixed;
  inset: 0;
  z-index: 70;
  display: flex;
  flex-direction: column;
  justify-content: flex-end;
}

.settings-backdrop {
  position: absolute;
  inset: 0;
  background: rgba(0,0,0,0.6);
  backdrop-filter: blur(4px);
  -webkit-backdrop-filter: blur(4px);
}

.settings-sheet {
  position: relative;
  background: var(--bg2);
  border-radius: var(--sheet-radius) var(--sheet-radius) 0 0;
  border-top: 1px solid var(--border);
  max-height: 90dvh;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  animation: slideUp 0.3s cubic-bezier(0.32, 0.72, 0, 1);
  padding-bottom: calc(24px + var(--safe-bottom));
}

.settings-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 20px 20px 12px;
  position: sticky;
  top: 0;
  background: var(--bg2);
  z-index: 1;
  border-bottom: 1px solid var(--border);
}

.settings-header h2 {
  font-size: 18px;
  font-weight: 700;
}

.settings-body {
  padding: 20px;
  display: flex;
  flex-direction: column;
  gap: 24px;
}

.settings-section h3 {
  font-size: 13px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.6px;
  color: var(--text3);
  margin-bottom: 14px;
}

.settings-note {
  font-size: 13px;
  color: var(--text2);
  margin-bottom: 16px;
  line-height: 1.5;
}

/* ── Form Fields ─────────────────────────────────── */
.field-label {
  display: flex;
  align-items: center;
  justify-content: space-between;
  font-size: 13px;
  font-weight: 600;
  color: var(--text2);
  margin-bottom: 6px;
  margin-top: 14px;
}

.field-label:first-of-type {
  margin-top: 0;
}

.field-link {
  color: var(--accent);
  text-decoration: none;
  font-size: 12px;
}

.field-wrapper {
  position: relative;
  display: flex;
  align-items: center;
}

.field-input {
  width: 100%;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-s);
  color: var(--text);
  font-size: 14px;
  padding: 12px 14px;
  outline: none;
  font-family: 'SF Mono', 'Fira Mono', monospace;
  transition: border-color 0.15s;
  appearance: none;
  -webkit-appearance: none;
}

.field-input:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-glow);
}

select.field-input {
  font-family: inherit;
  cursor: pointer;
  padding-right: 36px;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='12' viewBox='0 0 24 24' fill='none' stroke='%239898b8' stroke-width='2'%3E%3Cpolyline points='6 9 12 15 18 9'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 12px center;
}

select.field-input option {
  background: var(--bg2);
}

.field-eye {
  position: absolute;
  right: 10px;
  background: none;
  border: none;
  color: var(--text3);
  cursor: pointer;
  padding: 4px;
  display: flex;
  align-items: center;
}

/* ── Buttons ─────────────────────────────────────── */
.btn-primary {
  width: 100%;
  background: linear-gradient(135deg, var(--accent), var(--accent2));
  color: #fff;
  border: none;
  border-radius: var(--radius-m);
  font-size: 15px;
  font-weight: 600;
  padding: 15px;
  cursor: pointer;
  transition: opacity 0.15s, transform 0.1s;
}

.btn-primary:active {
  opacity: 0.85;
  transform: scale(0.98);
}

.settings-status {
  font-size: 13px;
  text-align: center;
  min-height: 20px;
  color: var(--green);
}

/* ── Full-screen Messages ────────────────────────── */
.fullscreen-message {
  position: fixed;
  inset: 0;
  z-index: 90;
  background: var(--bg);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px;
}

.message-card {
  text-align: center;
  max-width: 300px;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 16px;
}

.message-icon {
  font-size: 56px;
}

.message-card h2 {
  font-size: 22px;
  font-weight: 700;
  color: var(--text);
}

.message-card p {
  font-size: 15px;
  color: var(--text2);
  line-height: 1.6;
}

/* ── Utility ─────────────────────────────────────── */
.hidden {
  display: none !important;
}

/* ── Responsive tweaks (tablet+) ─────────────────── */
@media (min-width: 480px) {
  .overlay-sheet,
  .settings-sheet {
    max-width: 480px;
    margin: 0 auto;
  }
}

/* ── Landscape guard on phone ─────────────────────── */
@media (orientation: landscape) and (max-height: 500px) {
  .vf-tl, .vf-tr { top: 30%; }
  .vf-bl, .vf-br { bottom: 30%; }
  .camera-hint   { bottom: 14px; }
}
