@import url('https://fonts.googleapis.com/css2?family=Oswald:wght@500;600;700&family=IBM+Plex+Mono:wght@400;500;600&family=Inter:wght@400;500;600&display=swap');

:root {
  --bg: #14161a;
  --surface: #1c1f24;
  --surface-2: #262a31;
  --border: #33383f;
  --accent: #f2b705;
  --accent-dim: #7a5f08;
  --alert: #ff5a3c;
  --alert-dim: #5c2318;
  --ok: #4caf6d;
  --ok-dim: #1f3d2a;
  --text: #ece9e2;
  --text-dim: #8b8f96;
  --text-faint: #565b62;
  --radius: 3px;
  --stencil: 'Oswald', sans-serif;
  --mono: 'IBM Plex Mono', monospace;
  --body: 'Inter', sans-serif;
}

* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; }

body {
  background: var(--bg);
  color: var(--text);
  font-family: var(--body);
  -webkit-tap-highlight-color: transparent;
  overscroll-behavior: none;
}

#app { display: flex; flex-direction: column; min-height: 100vh; }

/* ---- HEADER ---- */
header.top {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 12px 16px;
  border-bottom: 3px solid var(--accent);
  background: var(--surface);
}
header.top .brand {
  font-family: var(--stencil);
  font-weight: 700;
  font-size: 18px;
  letter-spacing: 0.05em;
  text-transform: uppercase;
  color: var(--text);
}
header.top .brand span { color: var(--accent); }
.header-project-name {
  font-family: var(--mono);
  font-size: 10.5px;
  color: var(--text-dim);
  margin-top: 1px;
}

.btn:disabled { opacity: 0.4; cursor: not-allowed; }

.hamburger-btn {
  display: flex;
  flex-direction: column;
  justify-content: center;
  align-items: center;
  gap: 4px;
  flex: 0 0 auto;
  width: 32px;
  height: 32px;
  padding: 0;
  background: none;
  border: none;
  cursor: pointer;
}
.hamburger-btn span {
  display: block;
  width: 20px;
  height: 2px;
  background: var(--text);
  border-radius: 1px;
}

/* ---- NAV DRAWER ---- */
.nav-drawer-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.6);
  z-index: 300;
  display: flex;
}
.nav-drawer {
  display: flex;
  flex-direction: column;
  width: 250px;
  max-width: 80vw;
  height: 100%;
  background: var(--surface);
  border-right: 1px solid var(--border);
  padding-bottom: 20px;
  overflow-y: auto;
}
.nav-drawer-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 18px 10px 18px 20px;
  margin-bottom: 8px;
  border-bottom: 1px solid var(--border);
}
.nav-drawer-brand {
  font-family: var(--stencil);
  font-weight: 700;
  font-size: 28px;
  letter-spacing: 0.05em;
  text-transform: uppercase;
  color: var(--text);
}
.nav-drawer-brand span { color: var(--accent); }
.nav-drawer-close {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 48px;
  height: 48px;
  background: none;
  border: none;
  color: var(--text-dim);
  cursor: pointer;
  padding: 0;
  flex: 0 0 auto;
}
.nav-drawer-item {
  text-align: left;
  background: none;
  border: none;
  color: var(--text-dim);
  font-family: var(--stencil);
  font-size: 14.5px;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  padding: 14px 18px;
  cursor: pointer;
}
.nav-drawer-item.active {
  color: var(--accent);
  background: rgba(242, 183, 5, 0.08);
}
.nav-drawer-version {
  margin-top: auto;
  padding: 14px 18px 4px;
  font-family: var(--mono);
  font-size: 10.5px;
  color: var(--text-faint);
}

main { flex: 1; padding: 16px; padding-bottom: 90px; max-width: 720px; margin: 0 auto; width: 100%; }
.view { display: none; }
.view.active { display: block; animation: fadein .15s ease; }
@keyframes fadein { from { opacity: 0 } to { opacity: 1 } }

h2.section-title {
  font-family: var(--stencil);
  text-transform: uppercase;
  letter-spacing: 0.05em;
  font-size: 15px;
  color: var(--text-dim);
  margin: 0 0 12px;
  padding-bottom: 6px;
  border-bottom: 1px solid var(--border);
}

/* ---- CARDS / TAGS ---- */
.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 12px 14px;
  margin-bottom: 10px;
  position: relative;
}
/* Status-colored cards: 2px + stronger alpha — at 1px/low-alpha the yellow
   and green borders read as nearly the same color. Padding drops 1px so
   colored and plain cards keep the exact same outer size. */
.card.tag.alert { border-width: 2px; padding: 11px 13px; border-color: rgba(255, 90, 60, 0.75); }
.card.tag.ok { border-width: 2px; padding: 11px 13px; border-color: rgba(76, 175, 109, 0.7); }
.card.tag.accent { border-width: 2px; padding: 11px 13px; border-color: rgba(242, 183, 5, 0.75); }

/* The native calendar glyph on date inputs renders near-black — invert it so
   it reads against the dark field (Add Tag's due-back date). */
input[type="date"]::-webkit-calendar-picker-indicator { filter: invert(1); opacity: 0.85; cursor: pointer; }

/* Small X in a modal's top-right corner (project quick actions) — replaces a
   full-width Cancel row; tapping outside the sheet still closes it too. */
.modal-close-x {
  position: absolute;
  top: 14px;
  right: 14px;
  background: none;
  border: none;
  color: var(--text-faint);
  padding: 6px;
  cursor: pointer;
  line-height: 0;
}
.modal-close-x:hover { color: var(--text); }

.tag-desc { font-weight: 600; font-size: 14.5px; margin-bottom: 3px; }
.tag-meta {
  font-family: var(--mono);
  font-size: 11.5px;
  color: var(--text-dim);
  display: flex;
  flex-wrap: wrap;
  gap: 4px 12px;
}
.tag-meta b { color: var(--text); font-weight: 500; }
.badge {
  display: inline-block;
  font-family: var(--mono);
  font-size: 10px;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  padding: 2px 7px;
  border-radius: 2px;
  background: var(--surface-2);
  color: var(--text-dim);
  border: 1px solid var(--border);
}
.badge.accent { color: var(--accent); border-color: var(--accent-dim); }
.badge.alert { color: var(--alert); border-color: var(--alert); background: var(--alert-dim); }
.badge.ok { color: var(--ok); border-color: var(--ok); background: var(--ok-dim); }

/* ---- SCAN VIEW ---- */
.scan-wrap {
  background: #000;
  border-radius: var(--radius);
  overflow: hidden;
  border: 1px solid var(--border);
  position: relative;
  aspect-ratio: 4/3;
  display: flex;
  align-items: center;
  justify-content: center;
}
.scan-wrap video { width: 100%; height: 100%; object-fit: cover; }
/* Close-camera control — top-right over the video feed, sized for gloved
   thumbs. Backed with a dark disc so it stays visible over bright frames. */
.scan-close-x {
  position: absolute;
  top: 10px;
  right: 10px;
  width: 36px;
  height: 36px;
  display: flex;
  align-items: center;
  justify-content: center;
  background: rgba(0,0,0,0.55);
  border: 1px solid rgba(255,255,255,0.25);
  border-radius: 50%;
  color: #fff;
  cursor: pointer;
  line-height: 0;
  z-index: 2;
}
.scan-reticle {
  position: absolute;
  inset: 20% 12%;
  border: 2px solid var(--accent);
  border-radius: 6px;
  box-shadow: 0 0 0 2000px rgba(0,0,0,0.35);
  pointer-events: none;
}
.scan-hint {
  position: absolute; bottom: 10px; left: 0; right: 0;
  text-align: center;
  font-family: var(--mono);
  font-size: 11px;
  color: #fff;
  text-shadow: 0 1px 3px rgba(0,0,0,0.8);
}

.field-row { margin-bottom: 12px; }
label { display: block; font-family: var(--mono); font-size: 11px; text-transform: uppercase; letter-spacing: 0.05em; color: var(--text-dim); margin-bottom: 5px; }
input, select, textarea {
  width: 100%;
  background: var(--surface-2);
  border: 1px solid var(--border);
  color: var(--text);
  font-family: var(--mono);
  /* iOS Safari auto-zooms the page on focus for any text input under 16px —
     16px is the floor for every input/select/textarea in the app so that
     never happens, even where a tighter visual size is otherwise wanted. */
  font-size: 16px;
  padding: 10px 11px;
  border-radius: var(--radius);
}
input:focus, select:focus, textarea:focus { outline: none; border-color: var(--accent); }
textarea { font-family: var(--body); resize: vertical; min-height: 60px; }

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  font-family: var(--stencil);
  text-transform: uppercase;
  letter-spacing: 0.05em;
  font-size: 13px;
  font-weight: 600;
  border: none;
  border-radius: var(--radius);
  padding: 12px 18px;
  cursor: pointer;
  width: 100%;
}
.btn-primary { background: var(--accent); color: #1a1502; }
.btn-secondary { background: var(--surface-2); color: var(--text); border: 1px solid var(--border); }
.btn-danger { background: var(--alert); color: #2a0a04; }
.btn-row { display: flex; gap: 8px; flex-wrap: wrap; }

/* Fixed-position centering via left:50%/transform, not left:16px;right:16px;
   margin:auto — the latter fights with .btn's own width:100% and resolves
   to full viewport width, overflowing past the right edge. */
#fab-scan {
  position: fixed;
  bottom: 16px;
  left: 50%;
  transform: translateX(-50%);
  width: calc(100% - 32px);
  max-width: 688px;
  z-index: 50;
}
.btn-row .btn { width: auto; flex: 1; }

select.event-type { font-family: var(--mono); }

.empty-state {
  text-align: center;
  padding: 40px 20px;
  color: var(--text-faint);
  font-family: var(--mono);
  font-size: 12.5px;
}

.toast {
  position: fixed;
  bottom: 90px;
  left: 50%;
  transform: translateX(-50%);
  background: var(--accent);
  color: #1a1502;
  font-family: var(--stencil);
  font-weight: 600;
  font-size: 13px;
  letter-spacing: 0.03em;
  text-transform: uppercase;
  padding: 10px 18px;
  border-radius: var(--radius);
  box-shadow: 0 4px 16px rgba(0,0,0,0.4);
  z-index: 100;
  animation: toastin .2s ease;
}
.toast.err { background: var(--alert); color: #2a0a04; }
/* UNDO action inside a delete toast — inverted chip so it reads as a button
   against the yellow toast. */
.toast-undo-btn {
  margin-left: 10px;
  padding: 4px 12px;
  background: #1a1502;
  color: var(--accent);
  border: none;
  border-radius: var(--radius);
  font-family: var(--stencil);
  font-weight: 600;
  font-size: 12px;
  letter-spacing: 0.05em;
  text-transform: uppercase;
  cursor: pointer;
}
@keyframes toastin { from { opacity: 0; transform: translateX(-50%) translateY(8px); } to { opacity: 1; transform: translateX(-50%) translateY(0); } }

.update-banner {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  z-index: 400;
  background: var(--accent);
  color: #1a1502;
  border: none;
  font-family: var(--stencil);
  font-weight: 600;
  font-size: 12.5px;
  letter-spacing: 0.03em;
  text-transform: uppercase;
  padding: 10px;
  cursor: pointer;
  animation: toastin .2s ease;
}

.history-log { border-left: 2px solid var(--border); margin-left: 6px; padding-left: 16px; }
.history-item { position: relative; padding-bottom: 16px; }
.history-item::before {
  content: '';
  position: absolute;
  left: -21px; top: 3px;
  width: 9px; height: 9px;
  background: var(--accent);
  border-radius: 50%;
}
.history-time { font-family: var(--mono); font-size: 10.5px; color: var(--text-faint); }
.history-type { font-family: var(--stencil); font-size: 12.5px; text-transform: uppercase; letter-spacing: 0.03em; }

.history-photo-thumb {
  display: block;
  width: 72px;
  height: 72px;
  object-fit: cover;
  border-radius: var(--radius);
  border: 1px solid var(--border);
  margin-top: 6px;
  cursor: pointer;
}
/* Replaces the inline thumbnail (unreliable from IndexedDB Blobs on iOS Safari)
   with a compact button that opens the full photo viewer. */
.history-photo-btn {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  width: auto;
  margin-top: 8px;
  padding: 6px 12px;
  font-size: 12.5px;
}
.photo-preview { margin-top: 8px; }
.photo-preview-img {
  max-width: 140px;
  max-height: 140px;
  border-radius: var(--radius);
  border: 1px solid var(--border);
  display: block;
}
.photo-viewer-img {
  width: 100%;
  border-radius: var(--radius);
  border: 1px solid var(--border);
  display: block;
}

.stat-row { display: flex; gap: 10px; margin-bottom: 16px; }
.stat {
  flex: 1;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 12px;
  text-align: center;
}
.stat .num { font-family: var(--stencil); font-size: 24px; color: var(--accent); }
.stat .lbl { font-family: var(--mono); font-size: 9.5px; color: var(--text-dim); text-transform: uppercase; letter-spacing: 0.04em; margin-top: 2px; }

.modal-overlay {
  position: fixed; inset: 0; background: rgba(0,0,0,0.6);
  display: flex; align-items: flex-end; justify-content: center;
  z-index: 200;
}
.modal {
  background: var(--surface);
  border: 1px solid var(--border);
  border-top: 3px solid var(--accent);
  border-radius: var(--radius) var(--radius) 0 0;
  padding: 18px 16px calc(18px + env(safe-area-inset-bottom));
  width: 100%;
  max-width: 720px;
  /* 100% = the overlay height, which showModal() pins to the visualViewport
     when the keyboard is open — so the sheet never grows taller than the
     visible area above the keyboard. Falls back to 85vh with no keyboard. */
  max-height: min(85vh, 100%);
  overflow-y: auto;
  overscroll-behavior-y: contain;
  position: relative; /* anchors .modal-close-x */
}
.modal h3 { font-family: var(--stencil); text-transform: uppercase; letter-spacing: 0.04em; margin: 0 0 14px; font-size: 15px; }

.link-row { display: flex; justify-content: space-between; align-items: center; cursor: pointer; }
.chevron { color: var(--text-faint); font-family: var(--mono); }

/* Long-pressing a tag row for quick actions shouldn't trigger the native
   text-selection magnifier/callout. */
#tags-list .link-row {
  -webkit-touch-callout: none;
  -webkit-user-select: none;
  user-select: none;
  border-radius: var(--radius);
  transition: background-color 0.45s ease;
}
/* Visible "charging up" fill during the hold — vibrate() is a silent no-op
   on iOS Safari, so this is the only real-time feedback available there. */
#tags-list .link-row.long-press-active { background-color: rgba(242, 183, 5, 0.2); }

/* ---- TAG PICKER (scan flow) ---- */
.tag-picker { display: flex; flex-wrap: wrap; gap: 6px; }
.tag-chip {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 7px 10px;
  font-family: var(--mono);
  font-size: 12px;
  color: var(--text-dim);
  cursor: pointer;
}
/* Every checkbox, not a fragile per-context whitelist: the global
   `input { width: 100% }` rule otherwise stretches a checkbox to fill its flex
   row (e.g. it collapsed the item labels in the carnet "Add Items" list to 0px
   wide). Any checkbox anywhere stays its natural size. */
input[type="checkbox"] {
  accent-color: var(--accent);
  margin: 0;
  width: auto;
  flex: 0 0 auto;
}
.tag-chip.checked { border-color: var(--accent); color: var(--accent); background: rgba(242,183,5,0.08); }

.items-select-check { margin-right: 12px; }

.items-bulk-bar {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 12px 14px;
  margin-bottom: 12px;
}

/* ---- BATCH SCAN QUEUE ---- */
.queue-chip {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 9px 10px;
  margin-bottom: 6px;
}
.queue-chip-main { display: flex; flex-direction: column; gap: 2px; min-width: 0; }
.queue-chip-bc { font-family: var(--mono); font-size: 12.5px; font-weight: 600; color: var(--accent); }
.queue-chip-desc { font-size: 13px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.queue-chip-serial { font-family: var(--mono); font-size: 11px; color: var(--text-dim); }
.queue-chip-remove {
  flex: 0 0 auto;
  background: none;
  border: none;
  color: var(--text-faint);
  font-size: 20px;
  line-height: 1;
  cursor: pointer;
  padding: 0 4px;
}
.queue-chip-remove:hover { color: var(--alert); }

.multi-serial-panel {
  background: var(--surface);
  border: 1px solid var(--border);
  border-left: 3px solid var(--accent);
  border-radius: var(--radius);
  padding: 12px 14px 2px;
  margin-bottom: 14px;
}

/* ---- ORDER IMPORT ---- */
.import-warnings {
  background: var(--alert-dim);
  border: 1px solid var(--alert);
  border-radius: var(--radius);
  padding: 8px 10px;
  margin-bottom: 12px;
  font-size: 12px;
  color: var(--text);
}
.import-group {
  border: 1px solid var(--border);
  border-radius: var(--radius);
  margin-bottom: 8px;
  overflow: hidden;
}
.import-group-header {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 4px 8px;
  background: var(--surface-2);
  padding: 9px 10px;
  cursor: pointer;
}
.import-group-desc { flex: 1; font-weight: 600; font-size: 13.5px; }
.import-group-desc-edit {
  flex: 1 1 100%;
  order: 2;
  width: auto;
  min-width: 0;
  resize: none;
  overflow: hidden;
  white-space: normal;
  word-break: break-word;
  min-height: 0;
  background: none;
  border: none;
  border-bottom: 1px solid transparent;
  color: var(--text);
  font-family: var(--body);
  font-weight: 600;
  font-size: 16px;
  line-height: 1.3;
  padding: 2px 0;
}
.import-group-desc-edit:focus { border-bottom-color: var(--accent); }
.import-group-count {
  order: 1;
  margin-left: auto;
  font-family: var(--mono);
  font-size: 11px;
  color: var(--text-dim);
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 2px;
  padding: 1px 6px;
}
.import-group-rows { padding: 4px 10px 6px 32px; }
.import-row {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 4px 0;
  font-family: var(--mono);
  font-size: 12px;
  color: var(--text-dim);
  cursor: pointer;
}
.import-row-bc { color: var(--text); font-weight: 600; }
.import-row-serial, .import-row-order { color: var(--text-faint); }
.import-row-edit {
  width: auto;
  min-width: 0;
  flex: 0 1 110px;
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: 2px;
  padding: 3px 6px;
  font-family: var(--mono);
  font-size: 16px;
}
.import-row-edit.import-row-bc { color: var(--text); font-weight: 600; }
.import-row-edit.import-row-serial { color: var(--text-dim); }
.import-row-edit:focus { border-color: var(--accent); }
