:root {
  --bg: #101418;
  --panel: #1a2027;
  --panel-2: #232b34;
  --line: #2e3842;
  --text: #eef2f5;
  --muted: #8d9aa6;
  --accent: #2fd27a;
  --warn: #ffb020;
  --danger: #ff5a5a;
  --mode: #3ea6ff;
  --mode-total: #3ea6ff;
  --mode-shelf: #2fd27a;
  --mode-storage: #ffb020;
  --radius: 12px;
  color-scheme: dark;
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { height: 100%; margin: 0; }
body {
  background: var(--bg);
  color: var(--text);
  font: 16px/1.3 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  overscroll-behavior: none;
  user-select: none;
}
button { font: inherit; color: inherit; border: 0; background: none; cursor: pointer; touch-action: manipulation; }
input { font: inherit; }
[hidden] { display: none !important; }

.screen {
  position: fixed; inset: 0;
  display: flex; flex-direction: column;
  padding: env(safe-area-inset-top) 0 env(safe-area-inset-bottom);
}

body[data-mode="total"] { --mode: var(--mode-total); }
body[data-mode="shelf"] { --mode: var(--mode-shelf); }
body[data-mode="storage"] { --mode: var(--mode-storage); }

/* Login */
.login-box { margin: auto; width: min(340px, 90vw); display: grid; gap: 12px; }
.login-box h1 { margin: 0; }
.login-box input { padding: 14px; border-radius: var(--radius); border: 1px solid var(--line); background: var(--panel); color: var(--text); }
.primary { padding: 14px; border-radius: var(--radius); background: var(--accent); color: #062; font-weight: 700; }
.error { color: var(--danger); min-height: 1.2em; margin: 0; }

/* Top bar */
.topbar { padding: 6px 8px 6px; background: var(--panel); display: grid; gap: 6px; }
.topline { display: flex; align-items: center; justify-content: space-between; gap: 8px; min-height: 32px; }
.stores { display: flex; gap: 6px; overflow-x: auto; }
.stores button, .stores span { padding: 4px 10px; border-radius: 999px; background: var(--panel-2); font-size: 14px; color: var(--muted); white-space: nowrap; }
.stores .on { background: var(--text); color: var(--bg); font-weight: 600; }
.status { display: flex; align-items: center; gap: 6px; }
.pill { font-size: 12px; padding: 3px 8px; border-radius: 999px; background: var(--panel-2); color: var(--muted); }
.pill.pending { background: var(--warn); color: #221; }
.pill.offline { background: var(--danger); color: #fff; }
.icon-btn { min-width: 36px; height: 36px; border-radius: 10px; background: var(--panel-2); font-size: 18px; }

.modes { display: grid; grid-template-columns: repeat(3, 1fr); gap: 6px; }
.modes button {
  padding: 10px 0; border-radius: 10px; background: var(--panel-2);
  font-weight: 700; font-size: 17px; color: var(--muted); border: 2px solid transparent;
}
.modes button[data-mode="total"].on { background: var(--mode-total); color: #04121f; }
.modes button[data-mode="shelf"].on { background: var(--mode-shelf); color: #032012; }
.modes button[data-mode="storage"].on { background: var(--mode-storage); color: #241700; }

/* Camera */
.camera { position: relative; flex: 1 1 auto; min-height: 150px; background: #000; overflow: hidden; }
.camera video { position: absolute; inset: 0; width: 100%; height: 100%; object-fit: cover; }
.scan-window {
  position: absolute; left: 6%; right: 6%; top: 12%; bottom: 12%;
  border: 2px solid rgba(255,255,255,.55); border-radius: 10px;
  box-shadow: 0 0 0 100vmax rgba(0,0,0,.35);
}
.scan-window canvas { width: 100%; height: 100%; display: block; }
.camera.hit .scan-window { border-color: var(--accent); }
.camera.paused video { filter: grayscale(.6) brightness(.45); }
.camera.paused .scan-window { border-style: dashed; border-color: rgba(255,255,255,.3); }
.camera.paused::after {
  content: "⏸ Pausado · Guardar, + Sumar o C para seguir";
  position: absolute; left: 50%; top: 50%; transform: translate(-50%, -50%);
  background: rgba(0,0,0,.7); color: #fff; padding: 8px 14px; border-radius: 999px;
  font-size: 14px; font-weight: 600; white-space: nowrap; pointer-events: none;
}
.cam-controls { position: absolute; right: 8px; top: 8px; display: grid; gap: 6px; }
.cam-controls .icon-btn { background: rgba(0,0,0,.55); }
.cam-message {
  position: absolute; inset: 0; display: grid; place-items: center; padding: 20px; text-align: center;
  background: rgba(0,0,0,.75); font-size: 15px;
}
.cam-message button { margin-top: 10px; padding: 10px 16px; border-radius: 10px; background: var(--accent); color: #032012; font-weight: 700; }

/* Item card */
.card { display: flex; gap: 10px; padding: 8px 10px; background: var(--panel); border-top: 1px solid var(--line); min-height: 112px; }
.card.flash { animation: flash .5s ease-out; }
@keyframes flash { from { background: #1e4d33; } to { background: var(--panel); } }
.thumb { width: 96px; height: 96px; object-fit: cover; border-radius: 8px; background: #000; flex: none; border: 2px solid var(--accent); }
.thumb.big { position: fixed; z-index: 20; inset: 10% 4% auto; width: 92%; height: auto; }
.card-body { flex: 1; min-width: 0; display: grid; gap: 4px; align-content: start; }
.card-head { display: flex; justify-content: space-between; align-items: baseline; gap: 8px; }
.code {
  font: 700 19px/1.1 ui-monospace, "SFMono-Regular", Menlo, monospace; letter-spacing: .02em;
  background: #fff3; padding: 2px 6px; border-radius: 6px; overflow-wrap: anywhere;
}
.card:not(.empty) .code { background: #fde047; color: #1a1400; }
.card.empty .code { font: 500 15px system-ui, sans-serif; background: none; padding: 0; color: var(--muted); }
.price { font-weight: 700; font-size: 18px; color: var(--accent); white-space: nowrap; }
.name { font-size: 15px; line-height: 1.2; max-height: 2.4em; overflow: hidden; }
.name.unknown { color: var(--warn); }
.name .dept { color: var(--muted); font-size: 12px; margin-left: 4px; }
.prev { display: grid; grid-template-columns: repeat(3, 1fr); gap: 4px; }
.prev div { background: var(--panel-2); border-radius: 8px; padding: 2px 6px; display: flex; justify-content: space-between; align-items: baseline; border: 2px solid transparent; }
.prev small { color: var(--muted); font-size: 11px; }
.prev b { font-size: 18px; }
.prev div.cur { border-color: var(--mode); }
.prev div.has b { color: var(--warn); }
.when { font-size: 12px; color: var(--muted); min-height: 1em; }
.when.warn { color: var(--warn); }

/* Entry */
.entry { background: var(--panel); padding: 6px 8px 8px; display: grid; gap: 6px; }
.display {
  display: flex; align-items: center; justify-content: space-between;
  border: 2px solid var(--mode); border-radius: var(--radius); padding: 4px 12px; min-height: 52px;
}
#display-label { color: var(--mode); font-weight: 700; }
#display-value { font: 700 34px/1 ui-monospace, Menlo, monospace; }
#display-value:empty::before { content: "0"; color: var(--line); }
.pad { display: grid; grid-template-columns: repeat(3, 1fr) 1.15fr; grid-auto-rows: minmax(52px, 7.2vh); gap: 6px; }
.pad button { border-radius: 12px; background: var(--panel-2); font-size: 26px; font-weight: 600; }
.pad button:active { filter: brightness(1.4); transform: scale(.97); }
.pad .fn { font-size: 20px; color: var(--muted); }
.pad .add { font-size: 16px; color: var(--text); }
.pad .save { grid-row: span 2; background: var(--mode); color: #061018; font-size: 20px; font-weight: 800; }
.pad button:disabled { opacity: .35; }

.toast {
  position: fixed; left: 8px; right: 8px; top: calc(env(safe-area-inset-top) + 112px);
  background: #fff; color: #111; border-radius: var(--radius); padding: 10px 12px;
  display: flex; align-items: center; justify-content: space-between; gap: 10px; z-index: 30;
  box-shadow: 0 8px 30px #0008; font-weight: 600;
}
.toast button { color: #0a58ca; font-weight: 800; padding: 6px 8px; }

/* Sheets */
.sheet { background: var(--bg); z-index: 10; }
.sheet-head { display: flex; align-items: center; gap: 8px; padding: 8px; background: var(--panel); }
.sheet-head h2 { flex: 1; margin: 0; font-size: 18px; }
.sheet-head input, .list-controls input {
  flex: 1; width: 100%; padding: 10px 12px; border-radius: 10px; border: 1px solid var(--line); background: var(--panel-2); color: var(--text);
}
.link { color: var(--mode-total); font-weight: 700; padding: 8px; text-decoration: none; }
.results { list-style: none; margin: 0; padding: 0; overflow-y: auto; flex: 1; -webkit-overflow-scrolling: touch; }
.results li { display: flex; justify-content: space-between; gap: 10px; padding: 10px 12px; border-bottom: 1px solid var(--line); }
.results li:active { background: var(--panel-2); }
.results .r-main { min-width: 0; }
.results .r-name { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.results .r-code { font: 12px ui-monospace, monospace; color: var(--muted); }
.results .r-side { text-align: right; white-space: nowrap; font-size: 14px; }
.results .r-side b { font-size: 17px; }
.results .r-side small { color: var(--muted); display: block; }
.list-controls { padding: 8px; display: grid; gap: 8px; background: var(--panel); }
.chips { display: flex; gap: 6px; }
.chips button { padding: 6px 12px; border-radius: 999px; background: var(--panel-2); color: var(--muted); font-size: 14px; }
.chips button.on { background: var(--text); color: var(--bg); font-weight: 600; }
.progress { height: 6px; background: var(--panel-2); border-radius: 3px; overflow: hidden; }
.progress div { height: 100%; width: 0; background: var(--accent); transition: width .3s; }
.foot { padding: 8px 12px; color: var(--muted); font-size: 12px; background: var(--panel); }
