:root {
  color-scheme: light;
  --blue: #2454f4;
  --blue-dark: #1542de;
  --ink: #111111;
  --muted: #808083;
  --line: #e8e8ef;
  --page: #f0f0f6;
  --card: #ffffff;
  --tab: #f7f7f8;
  --purple: #a98cf7;
  --cyan: #8bdde7;
  --shadow: 0 20px 50px rgba(38, 63, 130, 0.14);
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

* {
  box-sizing: border-box;
}

html {
  background: var(--blue);
}

body {
  margin: 0;
  min-height: 100vh;
  color: var(--ink);
  background:
    linear-gradient(180deg, var(--blue) 0 130px, rgba(36, 84, 244, 0.42) 130px 220px, var(--page) 220px 100%);
}

button,
input,
select {
  font: inherit;
}

button {
  border: 0;
  cursor: pointer;
}

button:disabled {
  cursor: default;
}

h1,
h2,
h3,
p {
  overflow-wrap: anywhere;
}

.app-shell {
  width: min(980px, 100%);
  margin: 0 auto;
  padding: max(54px, env(safe-area-inset-top)) 28px max(34px, env(safe-area-inset-bottom));
}

.food-card,
.scanner,
.selected-product {
  border: 1px solid rgba(232, 232, 239, 0.96);
  border-radius: 28px;
  background: var(--card);
  box-shadow: var(--shadow);
}

h1 {
  margin: 0;
  color: var(--ink);
  font-size: clamp(1.65rem, 4vw, 2.35rem);
  line-height: 1.08;
  letter-spacing: 0;
}

.macro-progress,
.result-bars {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 10px;
}

.result-bars p {
  margin: 7px 0 0;
  color: var(--muted);
  font-size: 0.78rem;
  font-weight: 700;
  text-transform: lowercase;
}

.result-bars p strong {
  color: var(--ink);
  font-weight: 900;
}

.bar {
  display: block;
  overflow: hidden;
  height: 12px;
  border: 1px solid currentColor;
  border-radius: 999px;
  background: #f7fbff;
}

.bar i {
  display: block;
  width: 45%;
  height: 100%;
  background: currentColor;
}

.bar.purple {
  color: var(--purple);
}

.bar.blue {
  color: #3f8df4;
}

.bar.cyan {
  color: var(--cyan);
}

.food-card,
.scanner,
.selected-product {
  margin-top: 0;
}

.scanner,
.selected-product,
.history-section {
  margin-top: 26px;
}

.search-panel,
.history-section {
  padding: 0;
}

.food-card-header,
.section-heading {
  display: flex;
  align-items: center;
  gap: 14px;
}

.food-card-header {
  min-height: 94px;
  padding: 22px 26px;
  border-bottom: 1px solid var(--line);
}

.food-card-header.tight {
  min-height: auto;
  padding: 0;
  border-bottom: 0;
}

.food-card-header h1,
.food-card-header h2,
.history-section h2,
.scanner h2 {
  margin: 0;
  font-size: 1.42rem;
  line-height: 1.1;
}

.food-card-header p,
.scanner p {
  margin: 6px 0 0;
  color: var(--muted);
  font-size: 0.95rem;
}

.round-icon {
  display: grid;
  flex: 0 0 auto;
  place-items: center;
  width: 46px;
  height: 46px;
  border-radius: 50%;
  color: var(--blue);
  background: #f5f5f8;
  font-size: 1.35rem;
  font-weight: 900;
}

.search-form,
.barcode-form,
.actions-row,
.status {
  margin-inline: 26px;
}

.search-form {
  margin-top: 22px;
}

label {
  display: block;
  margin-bottom: 9px;
  color: var(--muted);
  font-size: 0.94rem;
  font-weight: 700;
}

.search-row {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 12px;
}

input,
select {
  min-width: 0;
  width: 100%;
  border: 1px solid var(--line);
  border-radius: 18px;
  padding: 17px 16px;
  color: var(--ink);
  background: #fbfbfd;
  outline: none;
}

input:focus,
select:focus {
  border-color: var(--blue);
  box-shadow: 0 0 0 4px rgba(36, 84, 244, 0.12);
}

.search-row button,
.secondary-button {
  min-height: 56px;
  border-radius: 18px;
  padding: 0 20px;
  color: #fff;
  background: var(--blue);
  font-weight: 800;
}

#scan-button {
  background: var(--ink);
}

.actions-row {
  display: grid;
  grid-template-columns: 1fr;
  gap: 12px;
  margin-top: 14px;
}

.barcode-icon {
  display: inline-block;
  width: 26px;
  height: 18px;
  margin-right: 10px;
  vertical-align: -3px;
  background:
    linear-gradient(90deg, #fff 0 2px, transparent 2px 5px, #fff 5px 8px, transparent 8px 12px, #fff 12px 13px, transparent 13px 17px, #fff 17px 21px, transparent 21px 24px, #fff 24px 26px);
}

.ghost-button {
  min-height: 56px;
  border: 1px solid var(--line);
  border-radius: 18px;
  padding: 0 18px;
  color: var(--blue);
  background: #fff;
  font-weight: 800;
}

.compact {
  min-height: 44px;
}

.barcode-form {
  margin-top: 18px;
}

.status {
  min-height: 24px;
  margin-top: 16px;
  margin-bottom: 24px;
  color: var(--muted);
}

.search-progress {
  height: 8px;
  margin: 0 26px 22px;
  overflow: hidden;
  border-radius: 999px;
  background: #e8eefc;
}

.search-progress span {
  display: block;
  width: 42%;
  height: 100%;
  border-radius: inherit;
  background: linear-gradient(90deg, var(--blue), #77d8e4);
  animation: searchProgress 1.05s ease-in-out infinite;
}

.search-progress.preparing span {
  width: 28%;
  animation-duration: 1.35s;
}

@keyframes searchProgress {
  0% {
    transform: translateX(-110%);
  }

  55% {
    transform: translateX(85%);
  }

  100% {
    transform: translateX(250%);
  }
}

.scanner {
  padding: 18px;
}

.scanner-header,
.section-heading {
  justify-content: space-between;
}

.icon-button {
  width: 46px;
  height: 46px;
  border-radius: 50%;
  color: var(--ink);
  background: #f5f5f8;
  font-size: 1.6rem;
  line-height: 1;
}

.video-frame {
  position: relative;
  overflow: hidden;
  margin-top: 14px;
  border-radius: 24px;
  background: #101828;
  aspect-ratio: 4 / 3;
}

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

.scan-target {
  position: absolute;
  inset: 29% 12%;
  border: 3px solid rgba(255, 255, 255, 0.92);
  border-radius: 18px;
  box-shadow: 0 0 0 999px rgba(16, 24, 40, 0.34);
}

.results {
  display: grid;
  gap: 12px;
  margin-top: 26px;
}

.product-card {
  display: grid;
  grid-template-columns: 58px minmax(0, 1fr) auto;
  gap: 16px;
  align-items: start;
  min-width: 0;
  border: 1px solid var(--line);
  border-radius: 24px;
  padding: 16px 20px;
  background: #fff;
  box-shadow: 0 10px 24px rgba(38, 63, 130, 0.08);
}

.product-card::after {
  content: "+";
  display: grid;
  place-items: center;
  width: 34px;
  height: 34px;
  border-radius: 50%;
  background: #f3f6ff;
  color: var(--blue);
  font-size: 1.25rem;
  font-weight: 800;
}

.product-card:focus-within,
.product-card:hover {
  border-color: rgba(36, 84, 244, 0.45);
}

.product-image {
  width: 58px;
  height: 58px;
  border-radius: 50%;
  object-fit: cover;
  background: #f5f5f8;
}

.product-info {
  min-width: 0;
}

.product-info h3 {
  margin: 0 0 5px;
  font-size: 1.18rem;
  line-height: 1.2;
}

.verified-badge {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  margin-left: 8px;
  border-radius: 999px;
  background: #eaf7ef;
  color: #137a3c;
  padding: 4px 8px;
  vertical-align: 2px;
  font-size: 0.72rem;
  font-weight: 900;
  white-space: nowrap;
}

.brand {
  margin: 0 0 12px;
  color: var(--muted);
  font-size: 0.94rem;
}

.result-nutrition {
  display: grid;
  grid-template-columns: auto 1fr;
  gap: 14px;
  align-items: center;
}

.results-more {
  width: 100%;
  border: 0;
  border-radius: 18px;
  background: #eef3ff;
  color: var(--blue);
  padding: 15px 18px;
  font-size: 1rem;
  font-weight: 900;
  cursor: pointer;
}

.results-more:hover,
.results-more:focus-visible {
  background: #e0e9ff;
}

.result-calories strong,
.result-calories span {
  display: block;
}

.result-calories strong {
  font-size: 1.45rem;
  line-height: 1;
}

.result-calories span {
  margin-top: 4px;
  color: var(--muted);
  font-size: 0.74rem;
  font-weight: 800;
}

.selected-product {
  overflow: hidden;
  padding: 0;
}

.selected-layout {
  display: grid;
  grid-template-columns: 112px 1fr;
  gap: 18px;
  padding: 22px 26px;
  border-bottom: 1px solid var(--line);
}

.selected-layout img {
  width: 112px;
  aspect-ratio: 1;
  border-radius: 50%;
  object-fit: cover;
  background: #f5f5f8;
}

.selected-product h2 {
  margin: 0 0 6px;
  font-size: 1.45rem;
}

.selected-product .subtitle {
  margin: 0 0 18px;
  color: var(--muted);
}

.portion-control {
  display: grid;
  gap: 10px;
  max-width: 340px;
}

.portion-control select,
.portion-control input {
  width: 100%;
  border-radius: 16px;
  padding: 13px 12px;
}

.portion-multiplier {
  display: grid;
  gap: 7px;
}

.portion-multiplier span {
  color: var(--muted);
  font-size: 0.82rem;
  font-weight: 800;
}

.macro-grid {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 0;
}

.macro-tile {
  min-height: 112px;
  border-right: 1px solid var(--line);
  border-bottom: 1px solid var(--line);
  padding: 18px;
  background: #fff;
}

.macro-tile:nth-child(4n) {
  border-right: 0;
}

.macro-tile span {
  display: block;
  color: var(--muted);
  font-size: 0.86rem;
  font-weight: 800;
}

.macro-tile strong {
  display: block;
  margin-top: 9px;
  font-size: 1.55rem;
}

.macro-tile.energy {
  color: var(--blue);
}

.macro-tile.energy span {
  color: var(--muted);
}

.history-section {
  overflow: hidden;
}

.section-heading {
  min-height: 94px;
  padding: 22px 26px;
  border-bottom: 1px solid var(--line);
}

.eyebrow {
  margin: 0 0 4px;
  color: var(--muted);
  font-size: 0.75rem;
  font-weight: 900;
  letter-spacing: 0.08em;
  text-transform: uppercase;
}

.history-list {
  display: grid;
}

.history-item {
  border-bottom: 1px solid var(--line);
  background: #fff;
}

.history-item:last-child {
  border-bottom: 0;
}

.history-main {
  width: 100%;
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 8px 16px;
  align-items: center;
  border: 0;
  background: transparent;
  padding: 17px 26px;
  color: inherit;
  font: inherit;
  text-align: left;
  cursor: pointer;
}

.history-main:hover,
.history-main:focus-visible {
  background: #f7f8ff;
}

.history-item strong {
  display: block;
  font-size: 1.08rem;
}

.history-item small,
.history-details p {
  display: block;
  color: var(--muted);
  font-size: 0.95rem;
}

.history-item .history-kcal {
  align-self: center;
  color: var(--ink);
  font-size: 1.08rem;
  font-weight: 700;
}

.history-details {
  padding: 0 26px 18px;
}

.history-more {
  width: calc(100% - 52px);
  margin: 16px 26px 22px;
  border: 0;
  border-radius: 16px;
  background: #eef3ff;
  color: var(--blue);
  padding: 14px 16px;
  font-size: 0.98rem;
  font-weight: 900;
  cursor: pointer;
}

.history-more:hover,
.history-more:focus-visible {
  background: #e0e9ff;
}

.history-detail-grid {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  overflow: hidden;
  border: 1px solid var(--line);
  border-radius: 18px;
}

.history-detail-grid .macro-tile {
  min-height: 86px;
  padding: 14px;
}

.history-detail-grid .macro-tile:nth-child(3n) {
  border-right: 1px solid var(--line);
}

.history-detail-grid .macro-tile:nth-child(4n) {
  border-right: 0;
}

.hidden {
  display: none !important;
}

@media (max-width: 720px) {
  body {
    background:
      linear-gradient(180deg, var(--blue) 0 112px, rgba(36, 84, 244, 0.42) 112px 195px, var(--page) 195px 100%);
  }

  .app-shell {
    padding-top: max(38px, env(safe-area-inset-top));
    padding-inline: 18px;
  }

  .selected-layout {
    grid-template-columns: 84px 1fr;
    padding-inline: 18px;
  }

  .selected-layout img {
    width: 84px;
  }

  .macro-grid {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  .macro-tile:nth-child(3n) {
    border-right: 1px solid var(--line);
  }

  .macro-tile:nth-child(4n) {
    border-right: 1px solid var(--line);
  }

  .macro-tile:nth-child(2n) {
    border-right: 0;
  }
}

@media (max-width: 520px) {
  .app-shell {
    padding-inline: 12px;
  }

  .food-card-header,
  .section-heading,
  .search-form,
  .barcode-form,
  .actions-row,
  .status,
  .search-progress {
    margin-inline: 18px;
  }

  .food-card-header,
  .section-heading {
    margin-inline: 0;
    padding-inline: 18px;
  }

  .search-row,
  .actions-row,
  .portion-control {
    grid-template-columns: 1fr;
  }

  .product-card {
    grid-template-columns: 50px 1fr;
    padding-inline: 14px;
  }

  .product-card::after {
    grid-column: 2;
  }

  .result-nutrition {
    grid-template-columns: 1fr;
    gap: 10px;
  }

  .result-bars {
    grid-template-columns: 1fr;
    gap: 8px;
  }

  .product-image {
    width: 50px;
    height: 50px;
  }

  .history-detail-grid {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  .history-detail-grid .macro-tile:nth-child(2n) {
    border-right: 0;
  }

  .history-detail-grid .macro-tile:nth-child(4n) {
    border-right: 0;
  }

  .selected-layout {
    grid-template-columns: 1fr;
    text-align: left;
  }

  .macro-grid {
    grid-template-columns: 1fr;
  }

  .macro-tile,
  .macro-tile:nth-child(2n),
  .macro-tile:nth-child(3n) {
    border-right: 0;
  }
}
