* { box-sizing: border-box; margin: 0; padding: 0; }
html, body { height: 100%; }
body {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  background: #f7f7f7; color: #1a1a1a;
  display: flex; flex-direction: column; min-height: 100vh;
}
.topbar {
  flex: 0 0 auto;
  background: #1a1a1a; color: #fff; padding: 14px 16px;
  align-items: center; justify-content: space-between;
  padding-top: max(14px, env(safe-area-inset-top));
}
.topbar h1 { font-size: 16px; font-weight: 600; border-left: 4px solid #c41230; padding-left: 10px; }
.icon-group { display: flex; gap: 4px; }
.icon-btn { background: none; border: none; color: #fff; padding: 6px; width: 34px; height: 34px; }
.icon-btn svg { width: 100%; height: 100%; }
.icon-btn.hidden { display: none; }
.icon-btn.active-view { background: rgba(255,255,255,0.18); border-radius: 6px; }

main {
  flex: 1 1 auto;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
}

.view { display: none; width: 100%; max-width: 420px; margin: 0 auto; padding: 24px 20px; }
.view.active.centered { display: flex; flex-direction: column; justify-content: center; min-height: 100%; }
.view.active:not(.centered) { display: block; }

label { display: block; margin-bottom: 14px; font-size: 14px; color: #444; }
input[type="text"], input[type="number"], input[type="password"], select {
  width: 100%; padding: 14px; margin-top: 6px; border: 1px solid #ccc; border-radius: 6px; font-size: 16px;
}
input:disabled { background: #eee; color: #888; }
.toggle-group { display: flex; gap: 8px; margin: 16px 0; }
.toggle-btn { flex: 1; padding: 16px; border: 2px solid #ccc; background: #fff; border-radius: 6px; font-weight: 600; font-size: 16px; }
.toggle-btn.active { border-color: #c41230; background: #c41230; color: #fff; }
.primary-btn { width: 100%; padding: 16px; background: #c41230; color: #fff; border: none; border-radius: 6px; font-size: 17px; font-weight: 600; margin-top: 10px; }
.secondary-btn { width: 100%; padding: 12px; background: #fff; color: #666; border: 1px solid #ccc; border-radius: 6px; font-size: 14px; margin-top: 8px; }
.confirm-box {
  margin-top: 16px; padding: 16px; background: #e9f7ef; border: 1px solid #b6e3c6; border-radius: 6px;
  font-size: 16px; font-weight: 700; text-align: center;
}
.confirm-box.hidden { display: none; }
.confirm-box.error { background: #fbe9e9; border-color: #e3b6b6; }

.scan-entry-choice { display: flex; flex-direction: column; gap: 10px; }
.entry-btn { padding: 22px; border: none; border-radius: 8px; font-size: 19px; font-weight: 700; color: #fff; }
.entry-btn-in { background: #1a7a3c; }
.entry-btn-out { background: #b5541a; }
.entry-divider { height: 1px; background: #ddd; margin: 10px 4px; }

.recent-scans-toggle-wrap { margin-top: 24px; text-align: center; }
#recent-scans-toggle { background: none; border: none; color: #666; font-size: 13px; font-weight: 600; text-decoration: underline; padding: 6px; }
.recent-scans-list { margin-top: 10px; max-height: 200px; overflow-y: auto; border: 1px solid #ddd; border-radius: 6px; padding: 10px; text-align: left; background: #fff; }
.recent-scans-list.hidden { display: none; }
.recent-scan-row { font-size: 13px; padding: 6px 0; border-bottom: 1px solid #eee; }
.recent-scan-row:last-child { border-bottom: none; }
.recent-scan-meta { font-size: 11px; color: #999; margin-top: 2px; }

#quick-add-form { margin-top: 16px; padding: 14px; border: 1px solid #ddd; border-radius: 6px; background: #fff; }
.quick-add-title { font-weight: 600; margin-bottom: 10px; font-size: 14px; }
#quick-add-form.hidden { display: none; }

#lookup-results { margin-top: 18px; }
.result-row { display: flex; justify-content: space-between; align-items: center; padding: 12px 0; border-bottom: 1px solid #e5e5e5; }
.result-info { flex: 1; padding-right: 12px; }
.result-title { font-size: 14px; font-weight: 600; }
.result-meta { font-size: 12px; color: #777; margin-top: 2px; }
.select-btn { padding: 8px 14px; border: 1px solid #c41230; color: #c41230; background: #fff; border-radius: 6px; font-weight: 600; font-size: 13px; white-space: nowrap; }
.select-btn.selected { background: #c41230; color: #fff; }
.no-results { font-size: 14px; color: #777; margin-top: 8px; }

fieldset { border: 1px solid #ddd; border-radius: 6px; padding: 14px; margin-bottom: 16px; }
legend { font-weight: 600; padding: 0 6px; font-size: 14px; }
.special-row { display: flex; justify-content: space-between; align-items: center; padding: 8px 0; border-bottom: 1px solid #eee; font-size: 14px; }
.remove-btn { background: none; border: none; color: #c41230; font-size: 13px; font-weight: 600; }
.add-row { display: flex; gap: 8px; margin-top: 10px; }
.add-row input { flex: 1; }
.add-row button { padding: 10px 14px; background: #1a1a1a; color: #fff; border: none; border-radius: 6px; font-weight: 600; }

.log-row { padding: 8px 0; border-bottom: 1px solid #eee; font-size: 13px; }
.log-meta { color: #999; font-size: 11px; }

.add-row-col { display: flex; flex-direction: column; gap: 8px; margin-top: 12px; }
.user-row { display: flex; align-items: center; gap: 8px; padding: 10px 0; border-bottom: 1px solid #eee; flex-wrap: wrap; }
.user-name { flex: 1; font-size: 14px; font-weight: 600; min-width: 80px; }
.user-row select { width: auto; padding: 8px; font-size: 13px; }
.user-row button { padding: 8px 10px; font-size: 12px; border: 1px solid #ccc; background: #fff; border-radius: 6px; }
.user-locked { font-size: 13px; color: #999; padding: 10px 0; border-bottom: 1px solid #eee; }

.store-select { width: 100%; margin-bottom: 14px; }
.store-select.hidden { display: none; }
.store-row { display: flex; justify-content: space-between; padding: 8px 0; border-bottom: 1px solid #eee; font-size: 14px; }

.segment-row { display: flex; gap: 6px; align-items: center; margin-bottom: 8px; flex-wrap: wrap; }
.segment-row select { width: auto; flex: 0 0 100px; padding: 8px; font-size: 13px; margin-top: 0; }
.segment-row input { width: auto; flex: 1; min-width: 60px; padding: 8px; font-size: 13px; margin-top: 0; }
.segment-row button { padding: 6px 8px; font-size: 12px; border: 1px solid #ccc; background: #fff; border-radius: 6px; }
#add-segment-btn { padding: 10px 14px; background: #1a1a1a; color: #fff; border: none; border-radius: 6px; font-weight: 600; margin-bottom: 12px; }
.format-preview { font-size: 13px; color: #666; margin-bottom: 14px; font-style: italic; }

.review-row { padding: 10px 0; border-bottom: 1px solid #eee; }
.review-barcode { font-size: 13px; font-weight: 600; margin-bottom: 6px; }
.review-fields { display: flex; gap: 6px; flex-wrap: wrap; }
.review-fields input { width: auto; flex: 1; min-width: 100px; padding: 8px; font-size: 12px; margin-top: 0; }
.review-fields button { padding: 8px 12px; font-size: 12px; border: 1px solid #1a1a1a; background: #1a1a1a; color: #fff; border-radius: 6px; }

.backup-row { display: flex; justify-content: space-between; align-items: center; padding: 10px 0; border-bottom: 1px solid #eee; }
.backup-info { flex: 1; }
.backup-name { font-size: 13px; font-weight: 600; }
.backup-meta { font-size: 11px; color: #999; margin-top: 2px; }
.backup-actions { display: flex; gap: 6px; }
.backup-actions a, .backup-actions button { padding: 6px 10px; font-size: 12px; border: 1px solid #ccc; background: #fff; border-radius: 6px; text-decoration: none; color: #1a1a1a; }
.restore-btn { border-color: #c41230 !important; color: #c41230 !important; }

.overlay-modal { position: fixed; inset: 0; background: rgba(0,0,0,0.75); z-index: 1000; display: flex; align-items: center; justify-content: center; padding: 20px; }
.overlay-modal.hidden { display: none; }
.overlay-modal-inner { position: relative; background: #fff; border-radius: 10px; padding: 20px; width: 100%; max-width: 420px; max-height: 90vh; overflow-y: auto; text-align: center; }
.modal-close-btn { position: absolute; top: 8px; right: 12px; background: none; border: none; font-size: 26px; line-height: 1; color: #999; }
#camera-video { width: 100%; border-radius: 6px; background: #000; max-height: 320px; object-fit: cover; }
#camera-status { margin: 12px 0; font-size: 14px; color: #444; line-height: 1.6; text-align: left; }
#manual-entry-modal form { text-align: left; }

.recount-row { display: flex; align-items: center; gap: 8px; padding: 8px 0; border-bottom: 1px solid #eee; }
.recount-row .recount-desc { flex: 1; font-size: 13px; }
.recount-row .recount-desc small { display: block; color: #999; font-size: 11px; }
.recount-row input[type="number"] { width: 70px; padding: 8px; font-size: 13px; margin-top: 0; }
.recount-row button { padding: 8px 10px; font-size: 12px; border: 1px solid #c41230; color: #c41230; background: #fff; border-radius: 6px; }

.log-filter-bar { margin-bottom: 16px; padding: 12px; background: #fff; border: 1px solid #ddd; border-radius: 6px; }
.log-filter-bar input[type="text"] { margin-bottom: 8px; }
.log-filter-dates { display: flex; gap: 8px; margin-bottom: 8px; }
.log-filter-dates input { padding: 10px; font-size: 13px; margin-top: 0; }
.log-filter-actions { display: flex; gap: 8px; }
.log-filter-actions button { flex: 1; padding: 10px; font-size: 13px; border-radius: 6px; border: 1px solid #ccc; background: #fff; }
#invlog-filter-btn { background: #1a1a1a; color: #fff; border: none; }

.offline-banner {
  flex: 0 0 auto; position: sticky; top: 0; z-index: 1100;
  background: #b5541a; color: #fff; text-align: center;
  padding: 10px 14px; font-size: 13px; font-weight: 600; cursor: pointer;
}
.offline-banner.hidden { display: none; }
.offline-banner.banner-error { background: #c41230; }

.pending-title { font-size: 16px; margin-bottom: 12px; text-align: left; }
.pending-row { text-align: left; padding: 12px 0; border-bottom: 1px solid #eee; }
.pending-summary { font-size: 14px; font-weight: 600; }
.pending-error { font-size: 12px; color: #c41230; margin-top: 4px; }
.pending-waiting { font-size: 12px; color: #999; margin-top: 4px; }
.pending-fix { margin-top: 10px; padding: 10px; background: #f7f7f7; border-radius: 6px; }
.pending-fix label { font-size: 12px; margin-bottom: 8px; }
.pending-fix input { padding: 8px; font-size: 13px; }
.pf-retry, .pf-add-retry { padding: 8px 14px; background: #1a1a1a; color: #fff; border: none; border-radius: 6px; font-size: 13px; font-weight: 600; margin-top: 4px; }
.pf-remove { padding: 6px 10px; font-size: 12px; border: 1px solid #ccc; background: #fff; border-radius: 6px; margin-top: 8px; color: #666; }

.pending-meta { font-size: 11px; color: #999; margin-top: 2px; }

.hidden { display: none !important; }

.input-with-camera-row { display: flex; gap: 6px; align-items: center; margin-top: 6px; }
.input-with-camera-row input { margin-top: 0; flex: 1; }
.camera-scan-btn { flex: 0 0 44px; height: 44px; background: #1a1a1a; color: #fff; border: none; border-radius: 6px; padding: 8px; }
.camera-scan-btn svg { width: 100%; height: 100%; }

.scan-video { width: 100%; border-radius: 6px; background: #000; max-height: 320px; object-fit: cover; }
.scan-status { margin: 12px 0; font-size: 14px; color: #444; line-height: 1.6; }
.toast {
  position: fixed; bottom: 20px; left: 50%; transform: translateX(-50%);
  background: #1a1a1a; color: #fff; padding: 12px 16px; border-radius: 8px;
  display: flex; align-items: center; gap: 12px; max-width: 90%; z-index: 2000;
  font-size: 14px; box-shadow: 0 4px 12px rgba(0,0,0,0.3);
}
.toast.hidden { display: none; }
.toast button { background: none; border: none; color: #fff; font-size: 18px; line-height: 1; opacity: 0.7; }
