@font-face {
  font-family: 'Inter';
  src: url('../fonts/inter-latin.woff2') format('woff2');
  font-style: normal;
  font-weight: 100 900;
  font-display: swap;
}

:root {
  color-scheme: light;
  --primary: #e94e1b;
  --primary-hover: #d8441a;
  --primary-foreground: #ffffff;
  --primary-soft: #fceae4;
  --app-background: #f3f3f3;
  --background: #fcfcfc;
  --card: #ffffff;
  --foreground: #242424;
  --muted-foreground: #6b6b6b;
  --border: #eaeaea;
  --input: #d9d9d9;
  --hover: rgba(0, 0, 0, 0.05);
  --destructive: #d63a2a;
  --destructive-hover: #c0301f;
  --success: #16843f;
  --warning-background: #fff4d1;
  --warning-foreground: #6b4e00;
  --info-background: #e8f4fb;
  --info-foreground: #1d5f82;
  --shadow: 0 1px 2px 0 rgba(0, 0, 0, 0.05);
  --overlay-shadow: 0 8px 24px rgba(0, 0, 0, 0.12);
  --radius: 8px;
  --radius-lg: 12px;
  --font-mono: ui-monospace, SFMono-Regular, Menlo, Consolas, 'Liberation Mono', monospace;
}

@media (prefers-color-scheme: dark) {
  :root {
    color-scheme: dark;
    --primary-hover: #f0612f;
    --primary-soft: rgba(233, 78, 27, 0.18);
    --app-background: #262626;
    --background: #303030;
    --card: #383838;
    --foreground: #ffffff;
    --muted-foreground: #b0b0b0;
    --border: #4a4a4a;
    --input: #5c5c5c;
    --hover: rgba(255, 255, 255, 0.07);
    --destructive: #f27c6f;
    --destructive-hover: #f59488;
    --success: #6ad38f;
    --warning-background: rgba(255, 217, 102, 0.14);
    --warning-foreground: #ffd966;
    --info-background: rgba(69, 181, 230, 0.16);
    --info-foreground: #8fd3f2;
    --shadow: none;
    --overlay-shadow: 0 8px 24px rgba(0, 0, 0, 0.4);
  }
}

*,
*::before,
*::after {
  box-sizing: border-box;
}

html,
body {
  margin: 0;
}

body {
  background: var(--app-background);
  color: var(--foreground);
  font-family: 'Inter', 'Helvetica Neue', Arial, sans-serif;
  font-size: 14px;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
}

a {
  color: var(--primary);
}

a,
button,
summary,
label[for],
input[type='checkbox'] {
  cursor: pointer;
}

:focus-visible {
  outline: 2px solid var(--primary);
  outline-offset: 2px;
}

.icon {
  flex: none;
  width: 16px;
  height: 16px;
}

.mono {
  font-family: var(--font-mono);
}

.text-muted {
  color: var(--muted-foreground);
}

.app {
  display: grid;
  grid-template-columns: 256px minmax(0, 1fr);
  min-height: 100dvh;
}

.sidebar {
  position: sticky;
  top: 0;
  display: flex;
  flex-direction: column;
  gap: 16px;
  height: 100dvh;
  padding: 12px 8px;
  background: var(--app-background);
}

.sidebar-header {
  display: flex;
  align-items: center;
  gap: 8px;
}

.brand {
  display: flex;
  align-items: center;
  gap: 10px;
  min-width: 0;
  padding: 6px 8px;
  color: var(--foreground);
  font-size: 16px;
  font-weight: 600;
  letter-spacing: -0.01em;
  text-decoration: none;
}

.brand-mark {
  flex: none;
  width: 24px;
  height: 24px;
}

.nav {
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.nav-item {
  display: flex;
  align-items: center;
  gap: 10px;
  min-height: 36px;
  padding: 0 10px;
  border-radius: var(--radius);
  color: var(--foreground);
  font-weight: 500;
  text-decoration: none;
}

.nav-item:hover {
  background: var(--hover);
}

.nav-item.active {
  background: var(--primary-soft);
  color: var(--primary);
}

.sidebar-footer {
  display: flex;
  align-items: center;
  gap: 6px;
  margin-top: auto;
  padding: 8px 10px;
  color: var(--muted-foreground);
  font-size: 13px;
  text-decoration: none;
}

.sidebar-footer:hover {
  color: var(--foreground);
}

.sidebar-footer .icon {
  width: 14px;
  height: 14px;
}

.icon-button.sidebar-close,
.icon-button.menu-button,
.sidebar-backdrop {
  display: none;
}

.panel {
  position: relative;
  display: flex;
  flex-direction: column;
  height: calc(100dvh - 8px);
  margin: 4px 4px 4px 0;
  overflow: hidden;
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  background: var(--background);
  box-shadow: var(--shadow);
}

.page-bar {
  display: flex;
  flex: none;
  align-items: center;
  gap: 8px;
  min-height: 56px;
  padding: 8px 16px;
  border-bottom: 1px solid var(--border);
}

.page-title {
  display: flex;
  flex: 1;
  align-items: center;
  gap: 8px;
  min-width: 0;
  margin: 0;
  font-size: 16px;
  font-weight: 600;
  overflow-wrap: anywhere;
}

.page-actions {
  display: flex;
  flex: none;
  gap: 8px;
}

.page-body {
  flex: 1;
  min-height: 0;
  padding: 24px 16px;
  overflow-y: auto;
}

.page-body-flush {
  padding: 0;
}

.stack {
  display: flex;
  flex-direction: column;
  gap: 16px;
  max-width: 32rem;
  margin: 0 auto;
}

.button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  height: 36px;
  padding: 0 12px;
  border: 1px solid transparent;
  border-radius: var(--radius);
  font: inherit;
  font-weight: 500;
  white-space: nowrap;
  text-decoration: none;
  transition: background-color 0.15s, border-color 0.15s, color 0.15s;
  touch-action: manipulation;
}

.button-lg {
  height: 44px;
  padding: 0 16px;
}

.button-primary {
  background: var(--primary);
  color: var(--primary-foreground);
}

.button-primary:hover {
  background: var(--primary-hover);
}

.button-outline {
  border-color: var(--input);
  background: var(--card);
  color: var(--foreground);
}

.button-outline:hover {
  background: var(--hover);
}

.button-destructive {
  background: var(--destructive);
  color: #ffffff;
}

.button-destructive:hover {
  background: var(--destructive-hover);
}

.button-destructive-outline {
  border-color: var(--input);
  background: var(--card);
  color: var(--destructive);
}

.button-destructive-outline:hover {
  background: color-mix(in srgb, var(--destructive) 8%, var(--card));
}

.button[aria-disabled='true'],
.button:disabled {
  opacity: 0.5;
  pointer-events: none;
}

.count {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 20px;
  height: 20px;
  padding: 0 6px;
  border-radius: 999px;
  background: var(--hover);
  font-size: 12px;
  font-variant-numeric: tabular-nums;
}

.icon-button {
  display: inline-flex;
  flex: none;
  align-items: center;
  justify-content: center;
  width: 32px;
  height: 32px;
  padding: 0;
  border: 0;
  border-radius: var(--radius);
  background: transparent;
  color: var(--muted-foreground);
  touch-action: manipulation;
}

.icon-button:hover {
  background: var(--hover);
  color: var(--foreground);
}

.icon-button-destructive,
.icon-button-destructive:hover {
  color: var(--destructive);
}

.button-stack {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.card {
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  background: var(--card);
  box-shadow: var(--shadow);
}

.form {
  display: flex;
  flex-direction: column;
  gap: 16px;
  margin: 0;
  padding: 16px;
}

.field {
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.field label {
  font-weight: 500;
}

.input {
  width: 100%;
  height: 40px;
  padding: 0 12px;
  border: 1px solid var(--input);
  border-radius: var(--radius);
  background: var(--card);
  color: var(--foreground);
  font: inherit;
  font-size: 16px;
}

.input:focus {
  border-color: var(--primary);
  outline: none;
  box-shadow: 0 0 0 3px color-mix(in srgb, var(--primary) 18%, transparent);
}

.checkbox {
  display: flex;
  align-items: center;
  gap: 8px;
}

.checkbox input {
  width: 16px;
  height: 16px;
  margin: 0;
  accent-color: var(--primary);
}

.form-actions {
  display: flex;
  gap: 8px;
}

.form-actions > * {
  flex: 1;
}

.callout {
  display: flex;
  align-items: flex-start;
  gap: 8px;
  margin: 0;
  padding: 12px;
  border-radius: var(--radius);
}

.callout .icon {
  margin-top: 3px;
}

.callout-destructive {
  background: color-mix(in srgb, var(--destructive) 10%, transparent);
  color: var(--destructive);
}

.callout-warning {
  background: var(--warning-background);
  color: var(--warning-foreground);
}

.callout-info {
  background: var(--info-background);
  color: var(--info-foreground);
}

.callout-success {
  background: color-mix(in srgb, var(--success) 12%, transparent);
  color: var(--success);
}

.details {
  margin: 0;
  padding: 4px 16px;
}

.details > div {
  display: flex;
  justify-content: space-between;
  gap: 16px;
  padding: 10px 0;
  border-bottom: 1px solid var(--border);
}

.details > div:last-child {
  border-bottom: 0;
}

.details dt {
  color: var(--muted-foreground);
}

.details dd {
  margin: 0;
  font-weight: 500;
  text-align: right;
  overflow-wrap: anywhere;
}

.status {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  color: var(--muted-foreground);
}

.status-success {
  color: var(--success);
}

.empty-state {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 12px;
  padding: 48px 16px;
  color: var(--muted-foreground);
  text-align: center;
}

.empty-state > .icon {
  width: 32px;
  height: 32px;
}

.empty-state p {
  margin: 0;
}

kbd {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 20px;
  height: 20px;
  padding: 0 2px;
  border: 1px solid var(--input);
  border-radius: 4px;
  background: var(--card);
  color: var(--foreground);
  vertical-align: middle;
}

kbd .icon {
  width: 14px;
  height: 14px;
}

.scan-list {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(min(100%, 340px), 1fr));
  gap: 12px;
  max-width: 80rem;
  margin: 0 auto;
}

.scan-card-title {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  padding: 12px 16px;
  border-bottom: 1px solid var(--border);
  border-radius: var(--radius-lg) var(--radius-lg) 0 0;
  color: var(--foreground);
  font-size: 15px;
  font-weight: 600;
  text-decoration: none;
  overflow-wrap: anywhere;
}

.scan-card-title:hover {
  background: var(--hover);
}

.scan-card-title .icon {
  color: var(--muted-foreground);
}

.scan-card .details > div {
  padding: 8px 0;
}

.scan-card-actions {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 8px;
  padding: 12px 16px;
  border-top: 1px solid var(--border);
}

.scan-card-actions .icon-button {
  width: 36px;
  height: 36px;
  margin-left: auto;
}

.help-card summary {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 12px 16px;
  font-weight: 500;
  list-style: none;
}

.help-card summary::-webkit-details-marker {
  display: none;
}

.help-card summary::after {
  content: '';
  width: 7px;
  height: 7px;
  margin-left: auto;
  border-right: 2px solid var(--muted-foreground);
  border-bottom: 2px solid var(--muted-foreground);
  transform: rotate(45deg) translate(-2px, -2px);
  transition: transform 0.15s;
}

.help-card[open] summary::after {
  transform: rotate(-135deg) translate(-2px, -2px);
}

.help-card p {
  margin: 0 16px 12px;
  color: var(--muted-foreground);
}

.help-card p:last-child {
  margin-bottom: 16px;
}

.qrcode-card {
  display: flex;
  justify-content: center;
  padding: 16px;
}

.share_qrcode {
  display: block;
  width: 100%;
  max-width: 320px;
  height: auto;
  aspect-ratio: 1;
  border-radius: var(--radius);
  background: #ffffff;
}

.prose {
  max-width: 40rem;
  margin: 0 auto;
}

.prose section {
  display: flow-root;
  margin-bottom: 32px;
}

.prose h2 {
  display: flex;
  align-items: center;
  gap: 10px;
  margin: 0 0 8px;
  font-size: 16px;
  font-weight: 600;
}

.prose p {
  margin: 0 0 12px;
}

.step {
  display: inline-flex;
  flex: none;
  align-items: center;
  justify-content: center;
  width: 24px;
  height: 24px;
  border-radius: 999px;
  background: var(--primary-soft);
  color: var(--primary);
  font-size: 13px;
}

.help-scanner {
  float: right;
  width: 100px;
  margin: 0 0 8px 16px;
}

.screenshot {
  display: block;
  width: 100%;
  max-width: 350px;
  margin: 4px 0 16px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
}

.ui-label {
  display: inline-block;
  padding: 0 6px;
  border: 1px solid var(--input);
  border-radius: 6px;
  background: var(--card);
  font-size: 13px;
  font-weight: 500;
  white-space: nowrap;
}

.scan-status {
  display: inline-flex;
  color: var(--primary);
}

.scan-status .icon {
  width: 20px;
  height: 20px;
}

.scan-status-busy,
.scan-status.spin .scan-status-idle {
  display: none;
}

.scan-status.spin .scan-status-busy {
  display: block;
  animation: spin 0.8s linear infinite;
}

#edit-scan-label .icon {
  width: 14px;
  height: 14px;
}

.barcode-table {
  width: 100%;
  border-collapse: collapse;
}

.barcode-table td {
  padding: 8px 16px;
  border-bottom: 1px solid var(--border);
  vertical-align: middle;
}

.barcode-table .quantity-cell {
  width: 1%;
  padding-right: 4px;
  font-size: 16px;
  font-weight: 600;
  font-variant-numeric: tabular-nums;
  text-align: right;
  white-space: nowrap;
}

.barcode-table .barcode {
  font-family: var(--font-mono);
  font-size: 15px;
  overflow-wrap: anywhere;
}

.barcode-table .actions-cell {
  width: 1%;
  padding-left: 4px;
  text-align: right;
  white-space: nowrap;
}

.barcode-table .actions-cell .icon-button {
  width: 36px;
  height: 36px;
  margin-left: 4px;
}

.barcode-table .btn-lower-quantity {
  border: 1px solid var(--input);
  background: var(--card);
  color: var(--foreground);
}

.barcode-table .explanation-row td {
  border-bottom: 0;
}

.numpad-dock {
  flex: none;
  padding: 8px 8px max(8px, env(safe-area-inset-bottom));
  border-top: 1px solid var(--border);
}

#numpad,
.numpad-entry {
  max-width: 48rem;
  margin: 0 auto;
}

#numpad {
  display: grid;
  grid-template-columns: repeat(10, minmax(0, 1fr));
  gap: 4px;
}

.numpad-entry {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 64px;
  gap: 4px;
  margin-top: 4px;
}

.numpad-btn,
#numpad-erase-btn {
  display: flex;
  align-items: center;
  justify-content: center;
  height: 48px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--card);
  color: var(--foreground);
  font-size: 20px;
  font-weight: 500;
  text-decoration: none;
  user-select: none;
  touch-action: manipulation;
  -webkit-tap-highlight-color: transparent;
}

.numpad-btn:active,
#numpad-erase-btn:active {
  background: var(--hover);
}

#numpad-erase-btn {
  color: var(--destructive);
}

#numpad-erase-btn .icon {
  width: 20px;
  height: 20px;
}

#numpad-value {
  display: flex;
  align-items: center;
  justify-content: flex-end;
  height: 48px;
  padding: 0 12px;
  overflow: hidden;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--card);
  color: var(--primary);
  font-size: 24px;
  font-weight: 600;
  font-variant-numeric: tabular-nums;
}

#numpad-value:empty::before {
  content: attr(data-placeholder);
  color: var(--muted-foreground);
  font-size: 14px;
  font-weight: 400;
}

#alert-wrapper {
  position: fixed;
  top: 12px;
  left: 50%;
  z-index: 200;
  display: none;
  width: min(32rem, calc(100% - 24px));
  transform: translateX(-50%);
}

.alert {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 8px 8px 8px 14px;
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  background: var(--card);
  box-shadow: var(--overlay-shadow);
  font-weight: 500;
}

#alert-message {
  flex: 1;
  min-width: 0;
  overflow-wrap: anywhere;
}

.alert-icon {
  display: none;
}

.alert-danger .alert-icon-danger,
.alert-warning .alert-icon-warning,
.alert-info .alert-icon-info,
.alert-success .alert-icon-success {
  display: inline-flex;
}

.alert-danger {
  border-color: color-mix(in srgb, var(--destructive) 40%, var(--border));
}

.alert-danger .alert-icon {
  color: var(--destructive);
}

.alert-warning .alert-icon {
  color: var(--warning-foreground);
}

.alert-info .alert-icon {
  color: var(--info-foreground);
}

.alert-success .alert-icon {
  color: var(--success);
}

.animated.flash {
  animation: flash 1s both;
}

@keyframes flash {
  0%,
  50%,
  100% {
    opacity: 1;
  }

  25%,
  75% {
    opacity: 0;
  }
}

@keyframes spin {
  to {
    transform: rotate(360deg);
  }
}

@media (min-width: 769px) {
  .input {
    height: 36px;
    font-size: 14px;
  }
}

@media (max-width: 768px) {
  .app {
    grid-template-columns: minmax(0, 1fr);
  }

  .sidebar {
    position: fixed;
    top: 0;
    bottom: 0;
    left: 0;
    z-index: 100;
    width: min(280px, 85vw);
    border-right: 1px solid var(--border);
    transform: translateX(-100%);
    transition: transform 0.2s ease;
  }

  .menu-open .sidebar {
    transform: none;
    box-shadow: var(--overlay-shadow);
  }

  .icon-button.sidebar-close {
    display: inline-flex;
    margin-left: auto;
  }

  .sidebar-backdrop {
    position: fixed;
    inset: 0;
    z-index: 99;
    display: block;
    background: rgba(0, 0, 0, 0.4);
    opacity: 0;
    pointer-events: none;
    transition: opacity 0.2s ease;
  }

  .menu-open .sidebar-backdrop {
    opacity: 1;
    pointer-events: auto;
  }

  .panel {
    height: 100dvh;
    margin: 0;
    border: 0;
    border-radius: 0;
    box-shadow: none;
  }

  .icon-button.menu-button {
    position: absolute;
    top: 12px;
    left: 8px;
    z-index: 11;
    display: inline-flex;
  }

  .page-bar {
    padding: 8px 12px 8px 48px;
  }

  .page-body {
    padding: 16px 12px;
  }

  .page-body-flush {
    padding: 0;
  }

  .barcode-table td {
    padding: 8px 12px;
  }
}

@media (prefers-reduced-motion: reduce) {
  .sidebar,
  .sidebar-backdrop {
    transition: none;
  }
}
