:root {
  color-scheme: light dark;
  --bg: #f7f3ea;
  --panel: #fffdfa;
  --panel-strong: #ffffff;
  --text: #171a1d;
  --muted: #66706f;
  --line: #d8d1c3;
  --accent: #0b6d66;
  --accent-strong: #064c48;
  --danger: #ad2f2f;
  --shadow: 0 14px 42px rgba(40, 34, 24, 0.12);
  --radius: 8px;
  --code-bg: #ffffff;
  --code-ink: #000000;
}

:root[data-theme="dark"] {
  --bg: #111315;
  --panel: #1a1d20;
  --panel-strong: #202428;
  --text: #f3f0e9;
  --muted: #aab3b0;
  --line: #343a3d;
  --accent: #69d4bf;
  --accent-strong: #9ff1df;
  --danger: #ff8b81;
  --shadow: 0 16px 48px rgba(0, 0, 0, 0.35);
  --code-bg: #ffffff;
  --code-ink: #000000;
}

* {
  box-sizing: border-box;
}

html {
  min-height: 100%;
  background: var(--bg);
  scroll-behavior: smooth;
}

body {
  margin: 0;
  min-height: 100%;
  background:
    linear-gradient(180deg, rgba(11, 109, 102, 0.09), transparent 210px),
    var(--bg);
  color: var(--text);
  font-family: ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  letter-spacing: 0;
}

button,
input,
select {
  font: inherit;
}

button {
  cursor: pointer;
}

.app-shell {
  width: min(100%, 760px);
  margin: 0 auto;
  padding: calc(14px + env(safe-area-inset-top)) 14px calc(28px + env(safe-area-inset-bottom));
}

.topbar {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 14px;
  padding: 6px 0 16px;
}

h1,
h2,
h3,
p {
  margin: 0;
}

h1 {
  font-size: 2rem;
  line-height: 1;
}

h2 {
  font-size: 1.05rem;
  line-height: 1.2;
}

h3 {
  font-size: 1rem;
}

.support-note,
.muted,
.barcode-value,
.render-warning {
  color: var(--muted);
  font-size: 0.88rem;
  line-height: 1.35;
}

.topbar-actions,
.form-actions,
.card-actions,
.scanner-header,
.section-head,
.focus-header {
  display: flex;
  align-items: center;
  gap: 8px;
}

.topbar-actions {
  flex: none;
}

.icon-button,
.small-button,
.text-button,
.primary-button {
  min-height: 40px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--panel-strong);
  color: var(--text);
}

.icon-button {
  display: inline-grid;
  width: 42px;
  height: 42px;
  place-items: center;
  padding: 0;
  font-size: 1.2rem;
}

.file-action {
  position: relative;
  overflow: hidden;
  cursor: pointer;
}

.file-action input {
  position: absolute;
  inset: 0;
  opacity: 0;
  pointer-events: none;
}

.primary-button {
  border-color: transparent;
  background: var(--accent);
  color: #ffffff;
  padding: 0 16px;
  font-weight: 700;
}

:root[data-theme="dark"] .primary-button {
  color: #062320;
}

.text-button,
.small-button {
  padding: 0 12px;
  font-weight: 700;
}

.small-button {
  min-height: 34px;
  font-size: 0.82rem;
}

.danger {
  color: var(--danger);
}

.panel,
.scanner-panel,
.focus-panel,
.empty-state {
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: color-mix(in srgb, var(--panel) 94%, transparent);
  box-shadow: var(--shadow);
}

.entry-panel,
.scanner-panel,
.focus-panel,
.empty-state {
  margin-bottom: 14px;
  padding: 14px;
}

.section-head,
.scanner-header,
.focus-header {
  justify-content: space-between;
  margin-bottom: 12px;
}

.barcode-form {
  display: grid;
  gap: 10px;
}

.barcode-form label {
  display: grid;
  gap: 5px;
  color: var(--muted);
  font-size: 0.85rem;
  font-weight: 700;
}

.barcode-form input,
.barcode-form select {
  width: 100%;
  min-height: 46px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--panel-strong);
  color: var(--text);
  padding: 0 12px;
}

.form-actions {
  justify-content: flex-start;
  margin-top: 2px;
}

.scanner-panel video {
  display: block;
  width: 100%;
  aspect-ratio: 4 / 3;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: #000000;
  object-fit: cover;
}

.focus-panel {
  position: relative;
  overflow: hidden;
  background: var(--panel-strong);
}

.eyebrow {
  color: var(--accent);
  font-size: 0.72rem;
  font-weight: 800;
  letter-spacing: 0.08em;
  text-transform: uppercase;
}

.focus-code {
  display: grid;
  width: 100%;
  min-height: 210px;
  place-items: center;
  border: 1px solid #ffffff;
  border-radius: var(--radius);
  background: var(--code-bg);
  color: var(--code-ink);
  padding: 16px 10px 10px;
}

.list-section {
  padding-bottom: 24px;
}

.empty-state {
  text-align: center;
}

.empty-state p {
  margin-top: 4px;
  color: var(--muted);
}

.barcode-list {
  display: grid;
  gap: 12px;
}

.barcode-card {
  display: grid;
  gap: 8px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--panel);
  padding: 10px;
}

.barcode-main {
  display: grid;
  width: 100%;
  gap: 6px;
  border: 0;
  border-radius: calc(var(--radius) - 2px);
  background: transparent;
  color: inherit;
  padding: 0;
  text-align: left;
}

.item-name {
  color: var(--text);
  font-size: 1rem;
  font-weight: 800;
  line-height: 1.2;
}

.barcode-art {
  display: grid;
  min-height: 104px;
  place-items: center;
  border: 1px solid #ececec;
  border-radius: calc(var(--radius) - 2px);
  background: var(--code-bg);
  color: var(--code-ink);
  overflow: hidden;
}

.barcode-art svg,
.focus-code svg {
  display: block;
  width: 100%;
  max-width: 680px;
  height: auto;
}

.barcode-art svg {
  min-height: 94px;
}

.barcode-value {
  overflow-wrap: anywhere;
}

.render-warning {
  color: var(--danger);
  font-weight: 700;
}

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

.card-actions button {
  padding-inline: 6px;
}

.is-focused-card {
  outline: 3px solid color-mix(in srgb, var(--accent) 80%, transparent);
  outline-offset: 1px;
}

.unsupported-code {
  display: grid;
  min-height: 120px;
  place-items: center;
  color: #111111;
  text-align: center;
  overflow-wrap: anywhere;
  padding: 12px;
}

.unsupported-code strong {
  display: block;
  font-size: 0.9rem;
  margin-bottom: 6px;
}

@media (min-width: 620px) {
  .barcode-form {
    grid-template-columns: 1fr 1.2fr 160px;
    align-items: end;
  }

  .form-actions {
    grid-column: 1 / -1;
  }

  .barcode-card {
    grid-template-columns: 1fr auto;
    align-items: center;
  }

  .card-actions {
    width: 210px;
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }
}

@media (dynamic-range: high) {
  .focus-panel {
    background: color(display-p3 1 1 0.985);
  }

  .focus-code {
    border-color: color(display-p3 1 1 1);
    box-shadow: 0 0 42px color(display-p3 1 1 1 / 0.4);
    filter: contrast(1.08) brightness(1.08);
  }
}

@media (prefers-reduced-motion: reduce) {
  html {
    scroll-behavior: auto;
  }
}
