:root {
  color-scheme: light;
  --background: #f5f7f4;
  --surface: #fff;
  --soft: #edf3ef;
  --line: #d7e3dc;
  --green: #0e4741;
  --green-hover: #195e54;
  --text: #18332e;
  --muted: #4f625d;
  --danger: #942d25;
  --radius: 12px;
  --space: 12px;
  --shadow: 0 6px 22px rgb(14 71 65 / 6%);
  font: 16px/1.45 system-ui, sans-serif;
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }

body {
  display: flex;
  flex-direction: column;
  gap: var(--space);
  min-height: 100vh;
  min-height: 100dvh;
  margin: 0;
  padding: var(--space);
  background: radial-gradient(ellipse at top right, #e5eee8, transparent 55%), var(--background);
  color: var(--text);
}

button, input { font: inherit; }

button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  min-height: 44px;
  padding: 8px 14px;
  border: 1px solid var(--green);
  border-radius: 9px;
  background: var(--green);
  color: white;
  font-weight: 650;
  white-space: nowrap;
  cursor: pointer;
}

button:hover { background: var(--green-hover); }

.secondary {
  border-color: #bdcfc5;
  background: var(--surface);
  color: var(--green);
}

.secondary:hover, #camera-open[aria-expanded="true"] { background: var(--soft); }
.icon-button { min-width: 44px; padding: 8px; }
button svg { width: 20px; height: 20px; flex: none; }

button:focus-visible, input:focus-visible, .table-wrap:focus-visible {
  outline: 2px solid var(--green);
  outline-offset: 3px;
}

.topbar {
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(350px, 1.5fr) auto;
  align-items: center;
  gap: var(--space);
  padding: 9px 14px;
  border: 1px solid var(--line);
  border-top: 4px solid var(--green);
  border-radius: var(--radius);
  background: var(--surface);
  box-shadow: var(--shadow);
}

.brand { display: flex; align-items: center; gap: 10px; min-width: 0; }
.brand img { width: clamp(70px, 6vw, 108px); height: auto; flex: none; }
.brand strong { display: block; color: var(--green); font-size: 1rem; line-height: 1.15; }
.brand small { display: block; margin-top: 3px; color: var(--muted); font-size: .875rem; }

form label {
  display: block;
  margin-bottom: 5px;
  color: var(--green);
  font-size: .875rem;
  font-weight: 650;
}

.scan-actions, .input-group { display: flex; gap: 8px; }
.input-group { flex: 1; min-width: 0; }

input {
  width: 100%;
  min-width: 0;
  min-height: 44px;
  padding: 9px 12px;
  border: 1px solid #bdcfc5;
  border-radius: 9px;
  background: #f9fbf9;
  color: var(--text);
}

input::placeholder { color: var(--muted); }
.tools { display: flex; align-items: center; justify-content: flex-end; gap: 10px; }

.status {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  padding: 5px 9px;
  border-radius: 20px;
  background: var(--soft);
  color: var(--green);
  font-size: .875rem;
  font-weight: 650;
}

.status::before {
  width: 8px;
  height: 8px;
  flex: none;
  border-radius: 50%;
  background: currentColor;
  content: '';
}

.status[data-state="loading"] { background: #fdf2d9; color: #744f12; }
.status[data-state="error"], .status[data-state="notfound"] { background: #faeae7; color: var(--danger); }

.workspace {
  display: grid;
  grid-template-columns: minmax(0, 44fr) minmax(0, 56fr);
  flex: 1;
  gap: var(--space);
  min-height: 0;
}

.left-column { display: grid; grid-template-rows: minmax(0, 1fr) clamp(155px, 24%, 225px); gap: var(--space); min-height: 0; }

.panel {
  display: flex;
  flex-direction: column;
  min-width: 0;
  overflow: hidden;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--surface);
  box-shadow: var(--shadow);
}

.panel-heading {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  min-height: 36px;
  padding: 7px 12px;
  border-bottom: 1px solid var(--line);
  background: var(--soft);
  color: var(--green);
  font-size: .875rem;
  font-weight: 700;
}

.muted { color: var(--muted); overflow-wrap: anywhere; }
.current { border-top: 3px solid var(--green); }

.notice {
  display: grid;
  flex: 1;
  align-content: center;
  justify-items: center;
  gap: 7px;
  padding: 14px;
  text-align: center;
}

.notice h1 {
  max-width: 26ch;
  margin: 0;
  color: var(--green);
  font-size: clamp(1.125rem, 1vw, 1.5rem);
  line-height: 1.2;
  overflow-wrap: anywhere;
}

.notice p {
  max-width: 100%;
  margin: 0;
  color: var(--muted);
  overflow-wrap: anywhere;
}

.scan-icon {
  display: grid;
  width: 42px;
  aspect-ratio: 1;
  place-items: center;
  border-radius: 10px;
  background: var(--soft);
  color: var(--green);
}

.scan-icon svg { width: 55%; }
.product { display: flex; flex: 1; flex-direction: column; gap: 9px; min-height: 0; padding: 12px; }
.product h1 { margin: 0; color: var(--green); font-size: clamp(1.25rem, .95vw, 1.5rem); line-height: 1.2; overflow-wrap: anywhere; }
.metrics { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 6px; }
.metric { min-width: 0; padding: 6px 9px; border: 1px solid var(--line); border-radius: 9px; background: #f7faf7; }
.metric small { display: block; color: var(--muted); font-size: .875rem; }
.metric strong { display: block; font-size: 1.125rem; line-height: 1.2; overflow-wrap: anywhere; }
.table-wrap { flex: 1; min-height: 0; overflow: auto; }
table { width: 100%; border-collapse: collapse; table-layout: fixed; }
th, td { padding: 6px 8px; border-bottom: 1px solid var(--line); text-align: left; vertical-align: middle; overflow-wrap: anywhere; }
th { position: sticky; top: 0; background: var(--soft); color: var(--green); font-size: .875rem; }
th:first-child { width: 19%; }
th:last-child { width: 21%; }
td:first-child { color: var(--green); font-weight: 700; }
th:last-child, td:last-child { text-align: right; }

.previous-content {
  display: grid;
  grid-template-columns: minmax(90px, 28%) minmax(0, 1fr);
  flex: 1;
  align-items: center;
  gap: 10px;
  min-height: 0;
  padding: 12px;
  overflow: auto;
}

.previous h2 { margin: 0 0 6px; font-size: 1rem; line-height: 1.2; overflow-wrap: anywhere; }
.previous .metric { padding: 5px 7px; }
.previous .metric strong { font-size: 1rem; }
.thumb { display: grid; height: 100%; min-height: 70px; place-items: center; overflow: hidden; border-radius: 8px; background: var(--soft); }
.thumb img { width: 100%; height: 100%; max-height: 210px; object-fit: contain; }
.empty { margin: 0; padding: 10px 12px; color: var(--muted); }

.photo { display: grid; flex: 1; min-height: 0; min-width: 0; place-items: center; overflow: hidden; padding: 12px; }
.photo > img { display: block; width: 100%; height: 100%; min-height: 0; object-fit: contain; }
.photo-fallback { max-width: 100%; color: var(--muted); text-align: center; overflow-wrap: anywhere; }
#placeholder-logo { display: block; width: min(50vw, 230px); height: auto; margin: 0 auto 8px; }
.photo-fallback span { display: block; }

.camera-panel { flex: none; }
.camera-panel .panel-heading { padding-block: 8px; }
.camera-panel p { margin: 12px 18px; color: var(--muted); }
.camera-panel p[data-error="true"] { color: var(--danger); }
.camera-panel video {
  display: block;
  width: min(calc(100% - 24px), 580px);
  height: clamp(185px, 32vh, 350px);
  height: clamp(185px, 32dvh, 350px);
  margin: 0 auto 12px;
  border-radius: 10px;
  background: #152620;
  object-fit: contain;
}

footer { display: flex; align-items: center; justify-content: space-between; gap: 8px 14px; color: var(--muted); font-size: .875rem; }
footer img { max-width: 140px; max-height: 24px; object-fit: contain; }

@media (min-width: 1000px) and (min-height: 650px) {
  body:not(.camera-open) { height: 100vh; height: 100dvh; overflow: hidden; }
  body:not(.camera-open) .workspace { overflow: hidden; }
  .photo { grid-template: minmax(0, 1fr) / minmax(0, 1fr); }
}

@media (min-width: 1000px) {
  .topbar form, .tools { align-self: end; }
  .tools { width: 218px; }
}

@media (min-width: 1000px) and (pointer: fine) {
  button, input { min-height: 36px; padding-block: 6px; }
  button { font-size: .875rem; }
  input { font-size: .9375rem; }
  .icon-button { min-width: 36px; padding: 6px; }
}

@media (max-width: 999px) {
  .topbar { grid-template-columns: minmax(0, 1fr) auto; gap: 12px; }
  .topbar form { grid-row: 2; grid-column: 1 / -1; }
  .workspace { grid-template-columns: minmax(0, 1fr); }
  .left-column { display: contents; }
  .current { min-height: 220px; }
  .photo-panel { order: 2; min-height: 220px; }
  .photo > img { height: auto; max-height: 65vh; max-height: 65dvh; }
  .previous { order: 3; min-height: 110px; }
  .table-wrap { max-height: 55vh; max-height: 55dvh; }
}

@media (max-width: 560px), (hover: none) and (pointer: coarse) {
  .tools .status[data-state="ready"] { display: none; }
}

@media (max-width: 560px) {
  .topbar { padding: 10px; }
  .brand { grid-area: 1 / 1 / 2 / -1; gap: 7px; padding-right: 56px; }
  .brand img { width: clamp(46px, 15vw, 72px); }
  .brand strong { font-size: .9375rem; }
  .brand small { margin-top: 2px; font-size: .8125rem; }

  .topbar form, .tools { display: contents; }
  .topbar form label { grid-area: 2 / 1; align-self: center; margin: 0; }
  #fullscreen { grid-area: 1 / 2; justify-self: end; }
  .tools .status {
    grid-area: 2 / 2;
    justify-self: end;
    max-width: min(43vw, 180px);
    padding: 4px 8px;
    font-size: .8125rem;
    line-height: 1.2;
  }

  .tools .status::before { display: none; }
  .scan-actions { grid-area: 3 / 1 / 4 / -1; flex-direction: column; }
  .panel-heading { padding-inline: 12px; }
  .metric { padding-inline: 7px; }
  th, td { padding-inline: 4px; }
  .previous-content { grid-template-columns: 1fr; }
  .thumb { height: 96px; }
  footer { flex-wrap: wrap; }
}
