/* Stocktaking app — mobile-first, no build step needed. */
:root {
  --bg: #f3f5f7;
  --surface: #ffffff;
  --ink: #16202b;
  --muted: #5d6b79;
  --line: #dde3e9;
  --brand: #0f4c5c;
  --brand-ink: #ffffff;
  --accent: #e36414;
  --ok: #1f7a4d;
  --ok-bg: #e5f4ec;
  --warn: #9a5b00;
  --warn-bg: #fff3dc;
  --bad: #b42318;
  --bad-bg: #fde8e7;
  --radius: 12px;
  --tap: 48px;
  color-scheme: light;
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  font-size: 16px;
  line-height: 1.45;
  background: var(--bg);
  color: var(--ink);
  padding-bottom: 76px; /* room for bottom nav on phones */
}
a { color: var(--brand); }
h1 { font-size: 1.35rem; margin: 0 0 .25rem; }
h2 { font-size: 1.1rem; margin: 1.5rem 0 .5rem; }
.muted { color: var(--muted); }
.small { font-size: .875rem; }

/* Top bar */
.topbar {
  position: sticky; top: 0; z-index: 20;
  display: flex; align-items: center; justify-content: space-between; gap: 12px;
  padding: 10px 16px;
  background: var(--brand); color: var(--brand-ink);
}
.topbar .app-name { font-weight: 700; letter-spacing: .02em; color: inherit; text-decoration: none; }
.topbar .who { font-size: .85rem; opacity: .9; display: flex; align-items: center; gap: 10px; }
.topbar form { margin: 0; }
.topbar button { background: transparent; color: inherit; border: 1px solid rgba(255,255,255,.4); border-radius: 8px; padding: 6px 10px; font: inherit; font-size: .85rem; cursor: pointer; }

/* Side/bottom navigation */
.nav {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 20;
  display: flex; overflow-x: auto;
  background: var(--surface); border-top: 1px solid var(--line);
  padding-bottom: env(safe-area-inset-bottom);
}
.nav a {
  flex: 1 0 auto; min-width: 72px; min-height: 60px;
  display: flex; flex-direction: column; align-items: center; justify-content: center;
  font-size: .75rem; color: var(--muted); text-decoration: none; padding: 6px 8px;
}
.nav a .ico { font-size: 1.3rem; line-height: 1; margin-bottom: 2px; }
.nav a.active { color: var(--brand); font-weight: 700; }

.page { max-width: 1100px; margin: 0 auto; padding: 16px; }
.page-head { display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between; gap: 10px; margin-bottom: 14px; }

/* Cards and grids */
.card { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 16px; margin-bottom: 14px; }
.grid { display: grid; gap: 12px; grid-template-columns: repeat(2, 1fr); }
.stat { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 14px; text-decoration: none; color: inherit; display: block; }
.stat .num { font-size: 1.8rem; font-weight: 700; }
.stat .lbl { color: var(--muted); font-size: .875rem; }

/* Buttons */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  min-height: var(--tap); padding: 0 18px;
  border-radius: 10px; border: 1px solid var(--brand);
  background: var(--brand); color: var(--brand-ink);
  font: inherit; font-weight: 600; text-decoration: none; cursor: pointer;
}
.btn.secondary { background: var(--surface); color: var(--brand); }
.btn.danger { background: var(--surface); color: var(--bad); border-color: var(--bad); }
.btn.small { min-height: 36px; padding: 0 12px; font-size: .875rem; }
.btn.block { width: 100%; }
.btn-row { display: flex; flex-wrap: wrap; gap: 8px; }

/* Forms */
label { display: block; font-weight: 600; font-size: .9rem; margin: 12px 0 4px; }
input[type=text], input[type=email], input[type=password], input[type=number], input[type=search], select, textarea {
  width: 100%; min-height: var(--tap);
  padding: 10px 12px; font: inherit; font-size: 16px; /* 16px stops iPhone zoom */
  border: 1px solid var(--line); border-radius: 10px; background: #fff; color: var(--ink);
}
textarea { min-height: 90px; }
input:focus, select:focus, textarea:focus { outline: 3px solid rgba(15,76,92,.25); border-color: var(--brand); }
.check { display: flex; align-items: center; gap: 10px; font-weight: 600; margin: 14px 0; }
.check input { width: 22px; height: 22px; }
.form-row { display: grid; gap: 0 12px; grid-template-columns: 1fr; }
.hint { font-size: .8rem; color: var(--muted); margin-top: 4px; }
.err { color: var(--bad); font-size: .85rem; margin-top: 4px; }

/* Messages */
.flash { padding: 12px 14px; border-radius: 10px; margin-bottom: 14px; font-weight: 600; }
.flash.ok { background: var(--ok-bg); color: var(--ok); }
.flash.bad { background: var(--bad-bg); color: var(--bad); }
.flash.warn { background: var(--warn-bg); color: var(--warn); }

/* Lists / tables */
.list { list-style: none; margin: 0; padding: 0; }
.list li { display: flex; align-items: center; justify-content: space-between; gap: 10px; padding: 12px 0; border-bottom: 1px solid var(--line); }
.list li:last-child { border-bottom: 0; }
.table-wrap { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; font-size: .92rem; }
th, td { text-align: left; padding: 10px 8px; border-bottom: 1px solid var(--line); vertical-align: top; }
th { color: var(--muted); font-weight: 600; font-size: .8rem; text-transform: uppercase; letter-spacing: .04em; }
.badge { display: inline-block; padding: 2px 8px; border-radius: 999px; font-size: .75rem; font-weight: 700; background: var(--bg); color: var(--muted); }
.badge.ok { background: var(--ok-bg); color: var(--ok); }
.badge.warn { background: var(--warn-bg); color: var(--warn); }
.badge.bad { background: var(--bad-bg); color: var(--bad); }
.mono { font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace; }

.filters { display: grid; gap: 8px; grid-template-columns: 1fr; margin-bottom: 12px; }
.pagination { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 12px; }
.pagination a, .pagination span { padding: 8px 12px; border: 1px solid var(--line); border-radius: 8px; background: var(--surface); text-decoration: none; }

/* Login */
.auth-wrap { min-height: 100vh; display: grid; place-items: center; padding: 16px; }
.auth-card { width: 100%; max-width: 380px; }
.auth-card .logo { font-size: 1.5rem; font-weight: 800; color: var(--brand); margin-bottom: 4px; }

/* Larger screens */
@media (min-width: 760px) {
  body { padding-bottom: 0; padding-left: 210px; }
  .nav {
    top: 0; bottom: 0; right: auto; width: 210px;
    flex-direction: column; overflow-y: auto;
    border-top: 0; border-right: 1px solid var(--line); padding-top: 64px;
  }
  .nav a { flex: 0 0 auto; flex-direction: row; justify-content: flex-start; gap: 10px; font-size: .95rem; min-height: 48px; padding: 0 18px; }
  .nav a .ico { margin: 0; }
  .topbar { margin-left: -210px; padding-left: 226px; }
  .grid { grid-template-columns: repeat(3, 1fr); }
  .form-row { grid-template-columns: 1fr 1fr; }
  .filters { grid-template-columns: 2fr 1fr 1fr 1fr auto; align-items: end; }
}

/* ---------- Counting screen ---------- */
.count-head { display: grid; gap: 6px; margin-bottom: 12px; }
.progress { height: 10px; background: #e1eef1; border-radius: 999px; overflow: hidden; }
.progress > i { display: block; height: 100%; background: var(--ok); transition: width .3s; }
.shelfbar { display: flex; align-items: center; justify-content: space-between; gap: 8px; padding: 10px 12px; border-radius: 10px; background: #e1eef1; margin-bottom: 12px; font-weight: 600; }
.shelfbar.none { background: var(--warn-bg); color: var(--warn); }
.scanbtn { width: 100%; min-height: 110px; border-radius: 18px; font-size: 1.25rem; flex-direction: column; gap: 4px; }
.scanbtn svg { width: 38px; height: 38px; }
.manual { display: flex; gap: 8px; margin: 12px 0; }
.manual input { flex: 1; }
.sheet { position: fixed; inset: 0; z-index: 50; background: rgba(10, 20, 26, .55); display: flex; align-items: flex-end; justify-content: center; }
.sheet[hidden] { display: none; }
.sheet .panel { background: var(--surface); width: 100%; max-width: 560px; max-height: 92vh; overflow-y: auto; border-radius: 18px 18px 0 0; padding: 18px 16px calc(18px + env(safe-area-inset-bottom)); display: grid; gap: 12px; }
@media (min-width: 760px) { .sheet { align-items: center; } .sheet .panel { border-radius: 18px; } }
.panel h2 { margin: 0; }
.prodcard { border: 1px solid var(--line); border-radius: 12px; padding: 12px; }
.prodcard .name { font-weight: 700; font-size: 1.05rem; }
.qtyrow { display: flex; gap: 8px; align-items: stretch; }
.qtyrow .val { flex: 1; text-align: center; font-size: 2.2rem; font-weight: 800; font-variant-numeric: tabular-nums; border: 2px solid var(--brand); border-radius: 14px; min-height: 68px; display: grid; place-items: center; }
.qtyrow button { width: 68px; }
.keypad { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; }
.keypad button, .qtyrow button { min-height: 56px; border-radius: 12px; border: 1px solid var(--line); background: var(--surface); color: var(--ink); font: inherit; font-size: 1.3rem; font-weight: 700; cursor: pointer; }
.keypad button.alt { font-size: .95rem; color: var(--muted); }
.camera { position: fixed; inset: 0; z-index: 60; background: #071014; color: #fff; display: flex; flex-direction: column; padding: 12px 12px calc(12px + env(safe-area-inset-bottom)); gap: 10px; }
.camera[hidden] { display: none; }
.camera #reader { flex: 1; min-height: 0; border-radius: 14px; overflow: hidden; background: #000; }
.camera #reader video { object-fit: cover; }
.camera .msg { font-size: .9rem; color: #c9d6dc; text-align: center; }
.toast { position: fixed; left: 50%; transform: translateX(-50%); bottom: calc(86px + env(safe-area-inset-bottom)); z-index: 70; background: var(--ink); color: #fff; padding: 12px 16px; border-radius: 12px; font-weight: 600; max-width: calc(100% - 32px); }
.toast.bad { background: var(--bad); }
.toast[hidden] { display: none; }
.recent li { padding: 10px 0; }
@media (min-width: 760px) { .toast { bottom: 24px; } }
