:root {
  --bg: #14090b; --card: #221417; --line: #3a2328; --accent: #dc2626;
  --text: #ede6e6; --muted: #a78f92; --ok: #4ade80; --warn: #fb7185;
}
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }
body {
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
  background: var(--bg); color: var(--text);
  min-height: 100vh; padding-bottom: 2rem;
  -webkit-text-size-adjust: 100%;
}

.topbar {
  display: flex; align-items: center; justify-content: space-between;
  padding: 0.9rem 1rem; border-bottom: 1px solid var(--line);
  position: sticky; top: 0; background: var(--bg); z-index: 10;
}
.topbar h1 { font-size: 1.2rem; letter-spacing: 0.05em; }
.topbar-right { display: flex; gap: 0.6rem; align-items: center; }
.user-badge { font-size: 0.75rem; color: var(--muted); }
.signin-btn { background: var(--accent); color: #fff; border: none; border-radius: 8px; padding: 0.4rem 0.7rem; font-size: 0.8rem; font-weight: 600; cursor: pointer; }
.signin-btn[hidden] { display: none; }
.net-badge { font-size: 0.7rem; padding: 2px 8px; border-radius: 99px; font-weight: 600; }
.net-badge.online { background: #0a1f10; color: var(--ok); }
.net-badge.offline { background: #2a1010; color: var(--warn); }

.tabs { display: flex; border-bottom: 1px solid var(--line); }
.tab {
  flex: 1; padding: 0.9rem; background: none; border: none; color: var(--muted);
  font-size: 0.95rem; font-weight: 600; cursor: pointer; border-bottom: 2px solid transparent;
}
.tab.active { color: #fff; border-bottom-color: var(--accent); }

main { max-width: 640px; margin: 0 auto; padding: 1.25rem 1rem; }
.view { display: none; }
.view.active { display: block; }

.field { margin-bottom: 1.1rem; }
.field label { display: block; font-size: 0.8rem; color: var(--muted); margin-bottom: 0.35rem; }
select, input[type="text"], input[type="number"] {
  width: 100%; padding: 0.8rem; font-size: 1rem;
  background: var(--card); color: var(--text);
  border: 1px solid var(--line); border-radius: 10px;
}
.link-btn { background: none; border: none; color: var(--accent); font-size: 0.8rem; margin-top: 0.4rem; cursor: pointer; }
.toggle { display: flex; align-items: center; gap: 0.5rem; font-size: 0.85rem; color: var(--muted); margin: -0.4rem 0 1rem; }
.toggle input { width: 1.1rem; height: 1.1rem; }

.btn {
  width: 100%; padding: 0.95rem; font-size: 1rem; font-weight: 600;
  border: 1px solid var(--line); border-radius: 12px; cursor: pointer;
  background: var(--card); color: var(--text); margin-top: 0.5rem;
}
.btn.primary { background: var(--accent); border-color: var(--accent); color: #fff; }
.btn.big { padding: 1.1rem; font-size: 1.05rem; }
.btn.confirm { background: #16331f; border-color: #1f5a31; color: var(--ok); margin-top: 1rem; }
.btn:disabled { opacity: 0.4; cursor: not-allowed; }

.cart { list-style: none; margin: 1rem 0; }
.cart li {
  display: flex; align-items: center; justify-content: space-between;
  gap: 0.5rem; padding: 0.75rem; background: var(--card);
  border: 1px solid var(--line); border-radius: 10px; margin-bottom: 0.5rem;
}
.cart li.empty { color: var(--muted); font-size: 0.9rem; justify-content: center; }
.cart .item-main { flex: 1; min-width: 0; }
.cart .item-desc { font-size: 0.92rem; }
.cart .item-sub { font-size: 0.72rem; color: var(--muted); }
.cart .item-qty { font-weight: 700; }
.cart .item-remove { background: none; border: none; color: var(--warn); font-size: 1rem; cursor: pointer; }
.cart .pending-tag { color: #fbbf24; font-size: 0.68rem; }
.cart .consumable-tag { color: var(--muted); font-size: 0.68rem; margin-left: 0.3rem; }

/* Return rows have a checkbox + qty input */
.ret-row { display: flex; align-items: center; gap: 0.6rem; }
.ret-row input[type="checkbox"] { width: 1.2rem; height: 1.2rem; }
.ret-row input[type="number"] { width: 4.5rem; padding: 0.45rem; }

/* Modals */
.modal {
  display: none; position: fixed; inset: 0; z-index: 100;
  background: rgba(0,0,0,0.92); align-items: center; justify-content: center; padding: 1rem;
}
.modal.open { display: flex; }
.modal-card { width: 100%; max-width: 520px; background: var(--card); border: 1px solid var(--line); border-radius: 16px; overflow: hidden; }
.modal-card.small { max-width: 380px; padding-bottom: 1rem; }
.modal-top { display: flex; align-items: center; justify-content: space-between; padding: 0.9rem 1.1rem; border-bottom: 1px solid var(--line); }
.modal-close { background: none; border: none; color: var(--muted); font-size: 1.3rem; cursor: pointer; }
.modal-card.small input { margin: 0.8rem 1.1rem; width: calc(100% - 2.2rem); }
.modal-card.small .btn { width: calc(100% - 2.2rem); margin: 0 1.1rem; }
.modal-card.small label { display: block; padding: 0 1.1rem; font-size: 0.8rem; color: var(--muted); }
.qty-desc, .warn { padding: 0.9rem 1.1rem 0; font-size: 0.9rem; }
.warn { color: var(--warn); }

.scanner-viewport { position: relative; width: 100%; aspect-ratio: 4/3; background: #000; overflow: hidden; }
#scanVideo { width: 100%; height: 100%; object-fit: cover; }
.viewfinder { position: absolute; inset: 18% 12%; border: 3px solid rgba(255,255,255,0.7); border-radius: 12px; pointer-events: none; }
.scan-status { padding: 0.85rem 1.1rem; text-align: center; font-size: 0.85rem; color: var(--muted); }
.scan-status.found { color: var(--ok); }

.toast {
  position: fixed; bottom: 1.5rem; left: 50%; transform: translateX(-50%);
  background: #222; color: #fff; padding: 0.7rem 1.1rem; border-radius: 10px;
  font-size: 0.9rem; opacity: 0; transition: opacity 0.2s; pointer-events: none; z-index: 200;
  max-width: 90vw; text-align: center;
}
.toast.show { opacity: 1; }
.toast.ok { background: #16331f; color: var(--ok); }
.toast.err { background: #2a1010; color: var(--warn); }
