:root {
  color-scheme: light;
  --brand: #159bd3;
  --brand-dark: #0879ad;
  --ink: #14212b;
  --muted: #60717d;
  --line: #d6e1e7;
  --surface: #ffffff;
  --soft: #eef6f9;
  --danger: #b3261e;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  min-height: 100vh;
  overflow: hidden;
  font-family: Arial, Helvetica, sans-serif;
  background: #dfeff5;
  color: var(--ink);
}

button,
input {
  font: inherit;
}

.app-shell {
  width: min(100vw, 430px);
  height: 100dvh;
  margin: 0 auto;
  display: grid;
  grid-template-rows: auto 1fr auto;
  background: var(--soft);
  border-left: 1px solid rgba(20, 33, 43, 0.08);
  border-right: 1px solid rgba(20, 33, 43, 0.08);
}

.app-header {
  min-height: 84px;
  padding: max(12px, env(safe-area-inset-top)) 16px 12px;
  display: grid;
  grid-template-columns: 56px 1fr;
  gap: 12px;
  align-items: center;
  background: var(--surface);
  border-bottom: 1px solid var(--line);
}

.app-logo {
  width: 56px;
  height: 56px;
  border-radius: 8px;
}

.app-header h1 {
  margin: 0;
  font-size: 18px;
  line-height: 1.15;
  letter-spacing: 0;
}

.app-header p {
  margin: 5px 0 0;
  color: var(--muted);
  font-size: 13px;
}

.screen-stack {
  min-height: 0;
  overflow: hidden;
}

.screen {
  height: 100%;
  display: none;
  padding: 12px;
  overflow-y: auto;
}

.screen.is-active {
  display: block;
}

.barcode-panel {
  height: 232px;
  display: grid;
  grid-template-rows: auto 1fr auto;
  gap: 7px;
  padding: 12px;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 8px;
}

.barcode-label {
  min-height: 22px;
  color: var(--ink);
  font-size: 16px;
  font-weight: 700;
  line-height: 1.25;
  text-align: center;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

#barcode-canvas {
  width: 100%;
  height: 142px;
  display: block;
  background: #fff;
  border: 1px solid #e5edf1;
}

.barcode-value {
  min-height: 18px;
  color: var(--muted);
  font-size: 14px;
  line-height: 1.2;
  text-align: center;
  overflow-wrap: anywhere;
}

.form-card {
  margin-top: 12px;
  padding: 12px;
  display: grid;
  gap: 12px;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 8px;
}

label {
  display: grid;
  gap: 6px;
  color: var(--muted);
  font-size: 13px;
  font-weight: 700;
}

input {
  width: 100%;
  min-height: 44px;
  padding: 10px 12px;
  border: 1px solid #b9c9d2;
  border-radius: 8px;
  color: var(--ink);
  background: #fff;
  outline: none;
}

input:focus {
  border-color: var(--brand);
  box-shadow: 0 0 0 3px rgba(21, 155, 211, 0.16);
}

.form-actions {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
}

button {
  min-height: 44px;
  border: 0;
  border-radius: 8px;
  font-weight: 700;
  cursor: pointer;
}

.primary-button {
  color: #fff;
  background: var(--brand);
}

.secondary-button {
  color: var(--brand-dark);
  background: #e5f4fa;
}

.input-note {
  margin: 0;
  color: var(--muted);
  font-size: 12px;
  line-height: 1.35;
}

.input-note.is-error {
  color: var(--danger);
}

.list-toolbar {
  position: sticky;
  top: 0;
  z-index: 1;
  padding-bottom: 10px;
  background: var(--soft);
}

.code-list {
  display: grid;
  gap: 9px;
  padding-bottom: 8px;
}

.code-item,
.code-main {
  width: 100%;
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 10px;
  align-items: center;
  text-align: left;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 8px;
  color: var(--ink);
}

.code-item {
  padding: 0;
}

button.code-item,
.code-main {
  padding: 11px 12px;
}

.code-main {
  min-height: 64px;
  grid-template-columns: 1fr;
  border: 0;
  background: transparent;
}

.code-item strong,
.code-main strong {
  display: block;
  margin-bottom: 3px;
  font-size: 14px;
  line-height: 1.25;
}

.code-item span,
.code-main span {
  display: block;
  color: var(--muted);
  font-size: 13px;
  line-height: 1.2;
}

.delete-button {
  width: 42px;
  min-height: 42px;
  margin-right: 10px;
  color: var(--danger);
  background: #f8e9e8;
}

.empty-state {
  display: none;
  margin: 26px 0 0;
  color: var(--muted);
  text-align: center;
}

.empty-state.is-visible {
  display: block;
}

.bottom-area {
  padding: 8px 10px max(8px, env(safe-area-inset-bottom));
  background: var(--surface);
  border-top: 1px solid var(--line);
}

.tab-bar {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 7px;
}

.tab-button {
  min-height: 46px;
  padding: 8px 6px;
  color: var(--muted);
  background: #edf3f6;
  font-size: 12px;
  line-height: 1.15;
}

.tab-button.is-active {
  color: #fff;
  background: var(--brand);
}

.author {
  padding-top: 7px;
  color: var(--muted);
  font-size: 12px;
  text-align: center;
}

@media (max-width: 360px) {
  .app-header {
    grid-template-columns: 48px 1fr;
  }

  .app-logo {
    width: 48px;
    height: 48px;
  }

  .app-header h1 {
    font-size: 16px;
  }

  .barcode-panel {
    height: 214px;
  }

  #barcode-canvas {
    height: 126px;
  }
}
