:root {
  --font-display: "Fraunces", "Times New Roman", serif;
  --font-body: "Sora", "Trebuchet MS", "Segoe UI", sans-serif;

  --bg-body: #f7f1e7;
  --bg-body-alt: #e5f4ec;
  --bg-surface: rgba(255, 255, 255, 0.76);
  --bg-surface-strong: #ffffff;
  --bg-surface-soft: #f4f7f6;
  --bg-camera: #020810;

  --accent-primary: #0fa87a;
  --accent-primary-hover: #0b8d66;
  --accent-secondary: #cd8f1e;
  --accent-ink: #264662;
  --accent-light: #d8f6ea;

  --text-primary: #1c2233;
  --text-secondary: #5d667c;
  --text-tertiary: #8d95aa;

  --border-soft: rgba(34, 51, 79, 0.1);
  --border-strong: rgba(29, 46, 76, 0.18);

  --status-good-bg: #dbf7e9;
  --status-good-text: #16614a;
  --status-good-border: #bae9d4;

  --status-warn-bg: #fff2d6;
  --status-warn-text: #9a6210;
  --status-warn-border: #f8d596;

  --status-error-bg: #ffe3dd;
  --status-error-text: #a6281f;
  --status-error-border: #f8b8ad;

  --radius-sm: 10px;
  --radius-md: 18px;
  --radius-lg: 28px;
  --radius-xl: 36px;
  --radius-pill: 999px;

  --shadow-soft: 0 12px 28px -22px rgba(20, 30, 50, 0.45);
  --shadow-card: 0 26px 60px -32px rgba(15, 31, 58, 0.5);
  --shadow-elevated: 0 34px 84px -40px rgba(15, 31, 58, 0.62);
}

* {
  box-sizing: border-box;
  -webkit-tap-highlight-color: transparent;
}

body {
  margin: 0;
  padding: 0;
  font-family: var(--font-body);
  color: var(--text-primary);
  background:
    radial-gradient(circle at 8% 14%, rgba(245, 201, 116, 0.42) 0%, transparent 33%),
    radial-gradient(circle at 88% 17%, rgba(143, 217, 185, 0.5) 0%, transparent 37%),
    linear-gradient(160deg, var(--bg-body) 0%, var(--bg-body-alt) 52%, #f8ede4 100%);
  display: flex;
  justify-content: center;
  align-items: flex-start;
  min-height: 100vh;
  min-height: 100dvh;
  overflow: hidden;
}

.ambient {
  position: fixed;
  pointer-events: none;
  z-index: 0;
  filter: blur(38px);
  opacity: 0.6;
}

.ambient-a {
  width: 220px;
  height: 220px;
  top: -60px;
  left: -80px;
  background: radial-gradient(circle, rgba(12, 165, 120, 0.56) 0%, transparent 70%);
}

.ambient-b {
  width: 260px;
  height: 260px;
  right: -120px;
  bottom: -60px;
  background: radial-gradient(circle, rgba(203, 143, 29, 0.48) 0%, transparent 72%);
}

#toast-container {
  position: fixed;
  top: calc(1rem + env(safe-area-inset-top, 0px));
  left: 50%;
  transform: translateX(-50%);
  z-index: 220;
  display: flex;
  flex-direction: column;
  gap: 0.6rem;
  width: min(92vw, 430px);
  pointer-events: none;
}

.app-container {
  width: min(100%, 430px);
  height: 100vh;
  height: 100dvh;
  margin: 0 auto;
  display: flex;
  flex-direction: column;
  position: relative;
  z-index: 2;
  overflow: hidden;
  background: linear-gradient(180deg, rgba(255, 255, 255, 0.56), rgba(255, 255, 255, 0.4));
  backdrop-filter: blur(14px);
  -webkit-backdrop-filter: blur(14px);
  border: 1px solid rgba(255, 255, 255, 0.72);
  box-shadow: var(--shadow-elevated);
}

@media (min-width: 421px) {
  .app-container {
    margin-top: 3vh;
    margin-top: 3dvh;
    height: 94vh;
    height: 94dvh;
    border-radius: var(--radius-xl);
  }
}

.top-header {
  position: sticky;
  top: 0;
  z-index: 25;
  padding: calc(0.9rem + env(safe-area-inset-top, 0px)) 1.15rem 1rem;
  background: linear-gradient(180deg, rgba(255, 255, 255, 0.82) 0%, rgba(255, 255, 255, 0.62) 100%);
  border-bottom: 1px solid rgba(255, 255, 255, 0.75);
}

.brand-shell {
  border-radius: var(--radius-lg);
  border: 1px solid rgba(255, 255, 255, 0.86);
  background: linear-gradient(135deg, rgba(255, 255, 255, 0.93), rgba(255, 255, 255, 0.72));
  box-shadow: var(--shadow-soft);
  padding: 0.7rem 1rem 0.66rem;
}

.top-header h1 {
  margin: 0;
  color: var(--accent-ink);
  font-family: var(--font-display);
  font-size: 1.5rem;
  font-weight: 700;
  letter-spacing: 0.2px;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 0.55rem;
}

.top-header h1 svg {
  width: 22px;
  height: 22px;
  color: var(--accent-primary);
}

.brand-shell p {
  margin: 0.25rem 0 0;
  text-align: center;
  color: var(--text-secondary);
  font-size: 0.76rem;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  font-weight: 600;
}

.view {
  display: none;
  flex: 1;
  min-height: 0;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  padding: 1.25rem;
  padding-bottom: calc(1.45rem + env(safe-area-inset-bottom, 0px));
  animation: fadeIn 0.35s cubic-bezier(0.2, 0.8, 0.2, 1);
}

.view.active {
  display: flex;
  flex-direction: column;
}

@keyframes fadeIn {
  from {
    opacity: 0;
    transform: translateY(14px) scale(0.99);
  }
  to {
    opacity: 1;
    transform: translateY(0) scale(1);
  }
}

h2,
h3,
h4 {
  margin: 0;
  color: var(--text-primary);
}

h2 {
  font-family: var(--font-display);
  font-weight: 700;
  letter-spacing: 0.2px;
}

p {
  margin: 0;
  color: var(--text-secondary);
  line-height: 1.55;
}

.card {
  background: var(--bg-surface);
  border: 1px solid rgba(255, 255, 255, 0.85);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-card);
  backdrop-filter: blur(10px);
  -webkit-backdrop-filter: blur(10px);
  padding: 1.25rem;
}

button {
  border: none;
  width: 100%;
  min-height: 49px;
  border-radius: var(--radius-pill);
  font-family: var(--font-body);
  font-size: 0.95rem;
  font-weight: 600;
  letter-spacing: 0.01em;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 0.62rem;
  cursor: pointer;
  transition: transform 0.2s ease, box-shadow 0.25s ease, background 0.25s ease;
}

button svg {
  width: 18px;
  height: 18px;
}

button:active {
  transform: scale(0.98);
}

button:focus-visible,
input:focus-visible,
textarea:focus-visible {
  outline: 3px solid rgba(15, 168, 122, 0.35);
  outline-offset: 2px;
}

button.primary {
  color: #ffffff;
  background: linear-gradient(115deg, #17b487 0%, #0f8e68 62%, #0e7e5e 100%);
  border: 1px solid rgba(7, 102, 75, 0.45);
  box-shadow: 0 14px 30px -18px rgba(16, 154, 113, 0.92);
}

button.secondary {
  color: var(--text-primary);
  background: linear-gradient(130deg, rgba(255, 255, 255, 0.95), rgba(246, 250, 249, 0.76));
  border: 1px solid var(--border-strong);
  box-shadow: var(--shadow-soft);
}

button.tertiary {
  color: var(--accent-ink);
  background: linear-gradient(125deg, rgba(37, 70, 98, 0.17), rgba(204, 143, 29, 0.2));
  border: 1px solid rgba(38, 70, 98, 0.2);
  box-shadow: var(--shadow-soft);
}

button.icon-only {
  width: 2.95rem;
  min-width: 2.95rem;
  height: 2.95rem;
  min-height: 2.95rem;
  padding: 0;
  border-radius: 50%;
  border: 1px solid rgba(255, 255, 255, 0.4);
  color: #ffffff;
  background: rgba(255, 255, 255, 0.16);
  backdrop-filter: blur(14px);
  -webkit-backdrop-filter: blur(14px);
}

@media (hover: hover) {
  button.primary:hover {
    transform: translateY(-1px);
    background: linear-gradient(115deg, #20ba8e 0%, #128f69 60%, #0f7b5d 100%);
    box-shadow: 0 18px 34px -18px rgba(16, 154, 113, 0.9);
  }

  button.secondary:hover,
  button.tertiary:hover {
    transform: translateY(-1px);
  }
}

@media (hover: none) {
  button.primary:hover,
  button.secondary:hover,
  button.tertiary:hover {
    transform: none;
    box-shadow: none;
  }
}

.hero-card {
  margin-top: clamp(0.6rem, 5vh, 3.3rem);
  text-align: center;
  position: relative;
  overflow: hidden;
  background:
    radial-gradient(circle at 86% 12%, rgba(206, 146, 40, 0.18) 0%, transparent 42%),
    radial-gradient(circle at 16% 78%, rgba(15, 168, 122, 0.14) 0%, transparent 48%),
    linear-gradient(140deg, rgba(255, 255, 255, 0.94), rgba(247, 251, 249, 0.8));
}

.hero-card::before {
  content: "";
  position: absolute;
  inset: 0;
  border-radius: inherit;
  border: 1px solid rgba(255, 255, 255, 0.75);
  pointer-events: none;
}

.hero-badge {
  display: inline-flex;
  align-items: center;
  gap: 0.42rem;
  border-radius: var(--radius-pill);
  border: 1px solid rgba(206, 143, 32, 0.34);
  background: rgba(206, 143, 32, 0.11);
  color: #855209;
  font-size: 0.72rem;
  font-weight: 700;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  padding: 0.42rem 0.78rem;
}

.hero-badge svg {
  width: 14px;
  height: 14px;
}

.hero-icon-wrap {
  width: 76px;
  height: 76px;
  border-radius: var(--radius-pill);
  margin: 1.1rem auto 1rem;
  display: flex;
  align-items: center;
  justify-content: center;
  background: linear-gradient(145deg, rgba(217, 246, 233, 0.95), rgba(193, 238, 220, 0.8));
  border: 1px solid rgba(17, 143, 106, 0.22);
  box-shadow: 0 18px 26px -18px rgba(15, 139, 102, 0.6);
}

.hero-icon-wrap svg {
  width: 36px;
  height: 36px;
  color: var(--accent-primary);
}

.hero-title {
  font-size: clamp(1.65rem, 5.2vw, 2.1rem);
}

.hero-subtitle {
  margin-top: 0.56rem;
  color: var(--text-secondary);
  font-size: 0.95rem;
}

.hero-action-grid {
  margin-top: 1.3rem;
  display: grid;
  gap: 0.72rem;
}

#scan-gallery-input,
#ocr-file-input {
  display: none;
}

.hero-btn {
  min-height: 50px;
}

.hero-feature-row {
  margin-top: 1rem;
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  gap: 0.52rem;
}

.feature-pill {
  display: inline-flex;
  align-items: center;
  gap: 0.35rem;
  border-radius: var(--radius-pill);
  background: rgba(255, 255, 255, 0.68);
  border: 1px solid rgba(39, 66, 100, 0.14);
  color: #394c6f;
  font-size: 0.74rem;
  font-weight: 600;
  padding: 0.38rem 0.7rem;
}

.feature-pill svg {
  width: 14px;
  height: 14px;
  color: var(--accent-primary);
}

.view-camera {
  position: absolute;
  inset: 0;
  z-index: 50;
  padding: 0;
  overflow: hidden;
  background: radial-gradient(circle at center, #0d1b2f 0%, var(--bg-camera) 70%);
}

.camera-header {
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  z-index: 53;
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: calc(0.86rem + env(safe-area-inset-top, 0px)) 1.15rem 1rem;
}

#reader {
  width: 100% !important;
  height: 100% !important;
  position: absolute;
  inset: 0;
  border: none !important;
  overflow: hidden;
  z-index: 51;
}

#reader video {
  object-fit: cover !important;
}

#reader__dashboard_section_csr,
#reader__dashboard_section_swaplink {
  display: none !important;
}

.scanner-reticle {
  position: absolute;
  top: 50%;
  left: 50%;
  width: min(78vw, 290px);
  height: min(46vw, 185px);
  transform: translate(-50%, -50%);
  border-radius: var(--radius-md);
  border: 2px solid rgba(255, 255, 255, 0.32);
  box-shadow: 0 0 0 4000px rgba(0, 0, 0, 0.52);
  pointer-events: none;
  z-index: 52;
}

.scanner-reticle::before {
  content: "";
  position: absolute;
  inset: 0;
  border-radius: inherit;
  border: 1px solid rgba(15, 168, 122, 0.78);
  filter: drop-shadow(0 0 8px rgba(15, 168, 122, 0.6));
}

.scanner-reticle::after {
  content: "";
  position: absolute;
  left: 8px;
  right: 8px;
  height: 2px;
  border-radius: 999px;
  background: linear-gradient(90deg, transparent 0%, #34e5b2 48%, transparent 100%);
  box-shadow: 0 0 14px rgba(32, 224, 173, 0.86);
  animation: scanLine 2.35s linear infinite;
}

@keyframes scanLine {
  0% {
    top: 8px;
    opacity: 0;
  }
  10% {
    opacity: 1;
  }
  90% {
    opacity: 1;
  }
  100% {
    top: calc(100% - 10px);
    opacity: 0;
  }
}

.camera-controls {
  position: absolute;
  left: 0;
  right: 0;
  bottom: 0;
  z-index: 53;
  padding: 2.35rem 1.45rem calc(1.3rem + env(safe-area-inset-bottom, 0px));
  display: flex;
  justify-content: center;
  align-items: center;
  background: linear-gradient(to top, rgba(2, 8, 16, 0.9) 0%, rgba(2, 8, 16, 0.12) 100%);
}

.camera-controls p {
  color: #e7eef7;
  font-size: 0.88rem;
  font-weight: 500;
  text-shadow: 0 3px 12px rgba(0, 0, 0, 0.55);
}

.processing-view {
  justify-content: center;
  align-items: center;
  text-align: center;
}

.processing-view h3 {
  margin-top: 0.2rem;
  margin-bottom: 0.3rem;
  font-size: 1.18rem;
}

.processing-view p {
  max-width: 250px;
}

.spinner {
  width: 56px;
  height: 56px;
  border-radius: 50%;
  border: 4px solid rgba(15, 168, 122, 0.16);
  border-top-color: var(--accent-primary);
  border-right-color: rgba(205, 143, 30, 0.8);
  margin-bottom: 1rem;
  animation: spin 0.95s linear infinite;
}

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

.not-found-view {
  justify-content: center;
}

.not-found-card {
  text-align: center;
}

.status-icon {
  width: 70px;
  height: 70px;
  margin: 0 auto 1rem;
  border-radius: var(--radius-pill);
  display: flex;
  align-items: center;
  justify-content: center;
}

.status-icon i {
  width: 34px;
  height: 34px;
}

.status-icon-warn {
  background: var(--status-warn-bg);
  color: var(--status-warn-text);
  border: 1px solid var(--status-warn-border);
}

.not-found-card h2 {
  margin-bottom: 0.4rem;
}

.not-found-card p {
  margin-bottom: 0.75rem;
}

#not-found-barcode {
  color: var(--text-primary);
  font-weight: 700;
  overflow-wrap: anywhere;
}

.stack-actions {
  display: flex;
  flex-direction: column;
  gap: 0.7rem;
  margin-top: 1rem;
}

.back-btn {
  width: auto;
  align-self: flex-start;
  min-height: 42px;
  padding: 0.52rem 1rem;
  margin-bottom: 1.15rem;
}

.view-title {
  margin-bottom: 1.1rem;
}

.upload-step-card {
  text-align: center;
  border: 2px dashed var(--border-strong);
  background: linear-gradient(140deg, rgba(255, 255, 255, 0.72), rgba(245, 248, 247, 0.5));
  box-shadow: none;
}

.upload-step-icon {
  width: 46px;
  height: 46px;
  color: var(--text-tertiary);
  margin-bottom: 0.9rem;
}

.upload-step-card p {
  margin-bottom: 1.1rem;
}

.upload-label-btn {
  max-width: 220px;
  margin: 0 auto;
}

.ocr-preview-step {
  display: none;
  margin-bottom: 1.15rem;
  text-align: center;
}

#ocr-image-preview {
  width: 100%;
  max-height: 220px;
  object-fit: contain;
  border-radius: var(--radius-md);
  border: 1px solid var(--border-soft);
  background: #ffffff;
  padding: 0.55rem;
  box-shadow: var(--shadow-soft);
}

#product-form {
  padding: 1.15rem;
}

.form-group {
  margin-bottom: 1.15rem;
}

.form-group label {
  display: block;
  color: var(--text-primary);
  font-size: 0.84rem;
  margin-bottom: 0.45rem;
  font-weight: 700;
  letter-spacing: 0.04em;
  text-transform: uppercase;
}

.form-group input,
.form-group textarea {
  width: 100%;
  border-radius: var(--radius-md);
  border: 1px solid var(--border-soft);
  background: var(--bg-surface-soft);
  color: var(--text-primary);
  font-family: var(--font-body);
  font-size: 0.96rem;
  padding: 0.86rem;
  transition: border-color 0.2s ease, background 0.2s ease, box-shadow 0.2s ease;
}

.form-group input:focus,
.form-group textarea:focus {
  border-color: rgba(15, 168, 122, 0.65);
  background: #ffffff;
  box-shadow: 0 0 0 3px rgba(15, 168, 122, 0.12);
}

.form-group textarea {
  resize: vertical;
  min-height: 7.4rem;
  line-height: 1.45;
}

.save-btn {
  margin-top: 0.35rem;
}

.result-header {
  text-align: center;
  margin-bottom: 1.2rem;
  background:
    radial-gradient(circle at 20% 20%, rgba(15, 168, 122, 0.15) 0%, transparent 45%),
    radial-gradient(circle at 80% 14%, rgba(205, 143, 30, 0.16) 0%, transparent 40%),
    linear-gradient(150deg, rgba(255, 255, 255, 0.95), rgba(245, 249, 247, 0.74));
}

.result-badge {
  display: inline-flex;
  align-items: center;
  gap: 0.45rem;
  border-radius: var(--radius-pill);
  padding: 0.45rem 0.92rem;
  font-size: 0.82rem;
  font-weight: 700;
  margin-bottom: 0.8rem;
}

.result-badge svg {
  width: 17px;
  height: 17px;
}

.badge-good {
  background: var(--status-good-bg);
  color: var(--status-good-text);
  border: 1px solid var(--status-good-border);
}

.badge-warning {
  background: var(--status-warn-bg);
  color: var(--status-warn-text);
  border: 1px solid var(--status-warn-border);
}

.badge-error {
  background: var(--status-error-bg);
  color: var(--status-error-text);
  border: 1px solid var(--status-error-border);
}

.badge-info {
  background: #e3f2ff;
  color: #1d5d94;
  border: 1px solid #b7ddfb;
}

#result-name {
  font-size: 1.65rem;
  line-height: 1.15;
  overflow-wrap: anywhere;
}

#result-brand {
  margin: 0.2rem 0 0.45rem;
  color: var(--text-secondary);
  font-weight: 600;
}

.result-quantity-row {
  margin: 0;
  color: var(--text-secondary);
  font-size: 0.9rem;
  display: none;
}

.result-quantity-row i {
  width: 15px;
  height: 15px;
  vertical-align: -2px;
  margin-right: 4px;
}

.section-title {
  font-size: 1rem;
  font-weight: 700;
  margin: 0 0 0.8rem;
  color: #394965;
  letter-spacing: 0.08em;
  text-transform: uppercase;
}

.result-flags {
  margin-bottom: 1.1rem;
}

.insight-card {
  display: flex;
  align-items: center;
  gap: 0.8rem;
  border-radius: var(--radius-md);
  border: 1px solid var(--border-soft);
  background: rgba(255, 255, 255, 0.78);
  padding: 0.85rem;
  margin-bottom: 0.65rem;
}

.insight-card span {
  font-size: 0.9rem;
  font-weight: 600;
  overflow-wrap: anywhere;
}

.ingredients-card {
  margin-bottom: 1.4rem;
}

#result-ingredients {
  color: var(--text-primary);
  font-size: 0.94rem;
  line-height: 1.62;
  overflow-wrap: anywhere;
}

.result-source-note {
  margin-bottom: 0.9rem;
  text-align: center;
  color: var(--text-tertiary);
  font-size: 0.8rem;
}

.toast {
  border-radius: var(--radius-md);
  border: 1px solid rgba(255, 255, 255, 0.35);
  background: linear-gradient(150deg, rgba(27, 38, 60, 0.92), rgba(20, 27, 44, 0.9));
  color: #f6f9fc;
  box-shadow: var(--shadow-card);
  display: flex;
  align-items: center;
  gap: 0.65rem;
  font-size: 0.9rem;
  font-weight: 500;
  padding: 0.9rem 1.05rem;
  animation: toastSlideIn 0.28s ease;
}

.toast svg {
  width: 18px;
  height: 18px;
}

@keyframes toastSlideIn {
  from {
    opacity: 0;
    transform: translateY(-10px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

.fade-out {
  animation: fadeOut 0.26s forwards;
}

@keyframes fadeOut {
  to {
    opacity: 0;
    transform: translateY(-8px);
  }
}

@media (max-width: 360px) {
  .view {
    padding: 1rem;
  }

  .card {
    padding: 1.05rem;
  }

  .hero-feature-row {
    gap: 0.42rem;
  }

  .feature-pill {
    font-size: 0.7rem;
  }

  .section-title {
    font-size: 0.92rem;
  }
}
