:root {
  --bg: #111827;
  --surface: #1f2937;
  --surface-2: #374151;
  --border: #374151;
  --text: #f3f4f6;
  --text-dim: #9ca3af;
  --accent: #22d3ee;
  --accent-dark: #0891b2;
  --danger: #f87171;
  --success: #34d399;
  --radius: 10px;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  height: 100%;
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
}

body { display: flex; flex-direction: column; }

button, input, select, textarea { font-family: inherit; font-size: 1rem; }

a { color: var(--accent); text-decoration: none; }

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0.75rem 1rem;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  position: sticky;
  top: 0;
  z-index: 10;
}

.topbar-title { font-weight: 700; font-size: 1.1rem; }

.nav { display: flex; align-items: center; gap: 0.9rem; flex-wrap: wrap; }
.nav a { color: var(--text-dim); font-size: 0.9rem; }
.nav a.active { color: var(--accent); font-weight: 600; }

.link-btn {
  background: none;
  border: none;
  color: var(--text-dim);
  font-size: 0.9rem;
  cursor: pointer;
  padding: 0;
}
.link-btn:hover { color: var(--danger); }

.hidden { display: none !important; }

.app-view {
  flex: 1;
  padding: 1rem;
  max-width: 640px;
  width: 100%;
  margin: 0 auto;
  padding-bottom: 3rem;
}

.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 1rem;
  margin-bottom: 1rem;
}

.field { margin-bottom: 0.9rem; }
.field label { display: block; margin-bottom: 0.3rem; color: var(--text-dim); font-size: 0.85rem; }
.field input, .field textarea, .field select {
  width: 100%;
  padding: 0.6rem 0.7rem;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 8px;
  color: var(--text);
}
.field textarea { min-height: 4.5rem; resize: vertical; }

.row { display: flex; gap: 0.6rem; }
.row > * { flex: 1; }

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 0.4rem;
  padding: 0.65rem 1rem;
  border-radius: 8px;
  border: 1px solid var(--accent-dark);
  background: var(--accent-dark);
  color: #fff;
  font-weight: 600;
  cursor: pointer;
  width: 100%;
}
.btn:active { transform: scale(0.98); }
.btn.secondary { background: var(--surface-2); border-color: var(--border); color: var(--text); }
.btn.danger { background: transparent; border-color: var(--danger); color: var(--danger); }
.btn.small { width: auto; padding: 0.4rem 0.7rem; font-size: 0.85rem; }
.btn:disabled { opacity: 0.5; cursor: not-allowed; }

.btn-icon {
  border: 1px solid var(--border);
  background: var(--surface-2);
  color: var(--text);
  border-radius: 8px;
  width: 2.6rem;
  height: 2.6rem;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  font-size: 1.1rem;
}
.btn-icon.recording { background: var(--danger); border-color: var(--danger); }

.error-msg { color: var(--danger); font-size: 0.9rem; margin-top: 0.5rem; }
.success-msg { color: var(--success); font-size: 0.9rem; margin-top: 0.5rem; }
.hint { color: var(--text-dim); font-size: 0.8rem; }

h1, h2, h3 { margin-top: 0; }
h1 { font-size: 1.3rem; }
h2 { font-size: 1.1rem; }

#qr-reader { width: 100%; border-radius: var(--radius); overflow: hidden; }
#qr-reader video { border-radius: var(--radius); }

.list-item {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  padding: 0.7rem 0.4rem;
  border-bottom: 1px solid var(--border);
  cursor: pointer;
}
.list-item:last-child { border-bottom: none; }
.list-item:hover { background: var(--surface-2); }
.list-item img.thumb, .list-item .thumb-placeholder {
  width: 42px; height: 42px; border-radius: 6px; object-fit: cover;
  background: var(--surface-2); flex-shrink: 0;
  display: flex; align-items: center; justify-content: center; font-size: 1.2rem;
}
.list-item-body { flex: 1; min-width: 0; }
.list-item-title { font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.list-item-sub { color: var(--text-dim); font-size: 0.8rem; }
.qty-badge {
  background: var(--surface-2);
  border-radius: 999px;
  padding: 0.1rem 0.55rem;
  font-size: 0.8rem;
  color: var(--text-dim);
  flex-shrink: 0;
}

.breadcrumb { color: var(--text-dim); font-size: 0.85rem; margin-bottom: 0.8rem; }
.breadcrumb a { color: var(--text-dim); text-decoration: underline; }
.breadcrumb .sep { margin: 0 0.3rem; }

.photo-preview {
  width: 100%;
  max-height: 240px;
  object-fit: contain;
  border-radius: var(--radius);
  background: var(--surface-2);
  margin-bottom: 0.6rem;
}

.history-row { padding: 0.6rem 0; border-bottom: 1px solid var(--border); font-size: 0.9rem; }
.history-row:last-child { border-bottom: none; }
.history-row .when { color: var(--text-dim); font-size: 0.78rem; }

.toast {
  position: fixed;
  bottom: 1.2rem;
  left: 50%;
  transform: translateX(-50%);
  background: var(--surface-2);
  border: 1px solid var(--border);
  padding: 0.6rem 1rem;
  border-radius: 8px;
  z-index: 50;
  max-width: 90vw;
  text-align: center;
}
.toast.error { border-color: var(--danger); color: var(--danger); }

.modal-backdrop {
  position: fixed; inset: 0; background: rgba(0,0,0,0.6);
  display: flex; align-items: center; justify-content: center; z-index: 40; padding: 1rem;
}
.modal {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 1.2rem;
  max-width: 420px;
  width: 100%;
}
.modal h3 { margin-bottom: 0.6rem; }

.label-sheet {
  background: #fff;
  color: #000;
  border-radius: 8px;
  padding: 1rem;
  text-align: center;
}
.label-sheet #label-qr { display: flex; justify-content: center; margin-bottom: 0.5rem; }
.label-sheet .label-code { font-family: monospace; font-size: 1rem; }
.label-sheet .label-desc { font-size: 0.95rem; margin-top: 0.2rem; }

@media print {
  body * { visibility: hidden; }
  .label-sheet, .label-sheet * { visibility: visible; }
  .label-sheet { position: fixed; top: 0; left: 0; width: 100%; border: none; }
}

.centered { text-align: center; margin-top: 3rem; }
.spinner-text { color: var(--text-dim); }
