/* HSAS Store — mobile-first, no framework. */
:root {
  --green: #0b6e4f;
  --green-dark: #085a40;
  --green-light: #e6f2ee;
  --ink: #1a2027;
  --muted: #5b6874;
  --line: #dde3e8;
  --bg: #f4f6f8;
  --card: #ffffff;
  --danger: #c0392b;
  --danger-bg: #fdecea;
  --warn: #b9770e;
  --warn-bg: #fdf3e2;
  --ok: #1e824c;
  --ok-bg: #e7f6ec;
  --radius: 12px;
  --shadow: 0 1px 3px rgba(16, 24, 32, .08), 0 1px 2px rgba(16, 24, 32, .06);
}
* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, Arial, sans-serif;
  color: var(--ink);
  background: var(--bg);
  font-size: 16px;
  line-height: 1.45;
}
a { color: var(--green-dark); }

/* ---- Topbar ---- */
.topbar {
  position: sticky; top: 0; z-index: 40;
  display: flex; align-items: center; gap: 10px;
  background: var(--green); color: #fff;
  padding: 10px 14px; padding-top: calc(10px + env(safe-area-inset-top));
  box-shadow: var(--shadow);
}
.topbar .brand { color: #fff; text-decoration: none; font-weight: 700; font-size: 1.05rem; letter-spacing: .3px; }
.topbar .brand span { font-weight: 400; opacity: .85; }
.topbar-user { margin-left: auto; display: flex; align-items: center; gap: 12px; font-size: .9rem; }
.topbar-user .who { background: rgba(255,255,255,.18); padding: 3px 10px; border-radius: 999px; }
.topbar-user .logout { color: #fff; text-decoration: none; opacity: .9; }
.menu-btn { display: none; background: none; border: 0; color: #fff; font-size: 1.4rem; cursor: pointer; padding: 0 4px; }

/* ---- Side nav ---- */
.sidenav {
  position: fixed; top: 0; left: 0; bottom: 0; width: 230px; z-index: 60;
  background: #fff; border-right: 1px solid var(--line);
  padding: 64px 10px 20px; display: flex; flex-direction: column; gap: 2px;
  transform: translateX(-100%); transition: transform .18s ease;
}
.sidenav a {
  display: block; padding: 12px 14px; border-radius: 10px; text-decoration: none;
  color: var(--ink); font-weight: 500;
}
.sidenav a:hover { background: var(--bg); }
.sidenav a.active { background: var(--green-light); color: var(--green-dark); font-weight: 700; }
.nav-scrim { position: fixed; inset: 0; background: rgba(0,0,0,.35); z-index: 50; display: none; }
body.nav-open .sidenav { transform: translateX(0); }
body.nav-open .nav-scrim { display: block; }

.content { max-width: 960px; margin: 0 auto; padding: 16px; padding-bottom: 60px; }

/* On wider screens pin the nav open and shift content. */
@media (min-width: 860px) {
  .menu-btn { display: none; }
  .sidenav { transform: translateX(0); }
  .nav-scrim { display: none !important; }
  /* Use the available width on a PC instead of a narrow centered column. */
  .content { margin-left: 230px; margin-right: 0; max-width: none; padding: 20px 28px; }
}
@media (min-width: 1500px) {
  /* Keep line lengths sensible on very wide monitors. */
  .content { max-width: 1500px; margin-right: auto; }
}
@media (max-width: 859px) {
  .menu-btn { display: inline-block; }
}

/* ---- Cards & layout ---- */
.card { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); padding: 16px; box-shadow: var(--shadow); margin-bottom: 16px; }
.card h2, .card h3 { margin-top: 0; }
h1 { font-size: 1.5rem; margin: 6px 0 16px; }
.page-head { display: flex; align-items: center; gap: 12px; flex-wrap: wrap; margin-bottom: 12px; }
.page-head h1 { margin: 0; }
.spacer { flex: 1; }
.muted { color: var(--muted); }
.grid { display: grid; gap: 12px; }
.grid-2 { grid-template-columns: 1fr 1fr; }
.grid-3 { grid-template-columns: repeat(3, 1fr); }
@media (max-width: 640px) { .grid-2, .grid-3 { grid-template-columns: 1fr; } }

/* ---- Stat tiles ---- */
.stats { display: grid; grid-template-columns: repeat(auto-fit, minmax(140px, 1fr)); gap: 12px; margin-bottom: 16px; }
.stat { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); padding: 14px; box-shadow: var(--shadow); }
.stat .n { font-size: 1.9rem; font-weight: 700; line-height: 1.1; }
.stat .l { color: var(--muted); font-size: .85rem; }
.stat.alert .n { color: var(--danger); }
.stat.warn .n { color: var(--warn); }

/* ---- Forms ---- */
label { display: block; font-weight: 600; margin: 12px 0 5px; font-size: .92rem; }
input, select, textarea {
  width: 100%; padding: 12px 12px; font-size: 1rem; border: 1px solid var(--line);
  border-radius: 10px; background: #fff; color: var(--ink); font-family: inherit;
}
input:focus, select:focus, textarea:focus { outline: 2px solid var(--green); border-color: var(--green); }
textarea { min-height: 70px; resize: vertical; }
.field-row { display: flex; gap: 12px; }
.field-row > * { flex: 1; }
.hint { color: var(--muted); font-size: .82rem; margin-top: 4px; }

.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  background: var(--green); color: #fff; border: 0; border-radius: 10px;
  padding: 13px 18px; font-size: 1rem; font-weight: 600; cursor: pointer; text-decoration: none;
}
.btn:hover { background: var(--green-dark); }
.btn.big { padding: 16px; font-size: 1.1rem; width: 100%; }
.btn.secondary { background: #fff; color: var(--ink); border: 1px solid var(--line); }
.btn.secondary:hover { background: var(--bg); }
.btn.danger { background: var(--danger); }
.btn.ghost { background: transparent; color: var(--green-dark); }
.btn[disabled] { opacity: .5; cursor: not-allowed; }
.btn-row { display: flex; gap: 10px; flex-wrap: wrap; margin-top: 8px; }

/* ---- Tables ---- */
.table-wrap { overflow-x: auto; -webkit-overflow-scrolling: touch; border-radius: var(--radius); border: 1px solid var(--line); }
table { width: 100%; border-collapse: collapse; background: #fff; font-size: .92rem; }
th, td { text-align: left; padding: 10px 12px; border-bottom: 1px solid var(--line); white-space: nowrap; }
th { background: var(--green-light); color: var(--green-dark); font-weight: 700; position: sticky; top: 0; }
tbody tr:hover { background: #fafcfb; }
td.num, th.num { text-align: right; font-variant-numeric: tabular-nums; }
tr.below td { background: var(--danger-bg); }
tr.flagged td { background: var(--warn-bg); }

/* ---- Badges & flash ---- */
.badge { display: inline-block; padding: 2px 9px; border-radius: 999px; font-size: .78rem; font-weight: 700; }
.badge.ok { background: var(--ok-bg); color: var(--ok); }
.badge.warn { background: var(--warn-bg); color: var(--warn); }
.badge.danger { background: var(--danger-bg); color: var(--danger); }
.badge.muted { background: #eef1f4; color: var(--muted); }
.flash { padding: 12px 14px; border-radius: 10px; margin-bottom: 14px; font-weight: 600; }
.flash-success { background: var(--ok-bg); color: var(--ok); }
.flash-error { background: var(--danger-bg); color: var(--danger); }
.flash-info { background: var(--green-light); color: var(--green-dark); }

/* ---- Login ---- */
.login-wrap { min-height: 100vh; display: grid; place-items: center; padding: 20px; background: linear-gradient(160deg, var(--green) 0%, var(--green-dark) 100%); }
.login-card { background: #fff; border-radius: 16px; padding: 28px 24px; width: 100%; max-width: 380px; box-shadow: 0 12px 40px rgba(0,0,0,.25); }
.login-card h1 { text-align: center; color: var(--green-dark); margin: 0 0 4px; }
.login-card .sub { text-align: center; color: var(--muted); margin: 0 0 18px; font-size: .9rem; }
.pin-input { letter-spacing: .5em; text-align: center; font-size: 1.4rem; }

/* ---- Scanner ---- */
.scanner-box { position: relative; background: #000; border-radius: var(--radius); overflow: hidden; aspect-ratio: 4/3; margin-bottom: 14px; }
.scanner-box video, .scanner-box canvas { width: 100%; height: 100%; object-fit: cover; display: block; }
.scan-frame { position: absolute; inset: 18% 12%; border: 3px solid rgba(255,255,255,.8); border-radius: 10px; box-shadow: 0 0 0 100vmax rgba(0,0,0,.25); }
.scan-hint { position: absolute; bottom: 8px; left: 0; right: 0; text-align: center; color: #fff; font-size: .85rem; text-shadow: 0 1px 2px #000; }

.big-num { font-size: 2rem; font-weight: 800; }
.qty-input { font-size: 1.6rem; text-align: center; padding: 16px; }
.print-only { display: none; }

/* ---- Sticky action bar for mobile forms ---- */
.action-bar { position: sticky; bottom: 0; background: var(--bg); padding: 12px 0; border-top: 1px solid var(--line); margin-top: 12px; }

/* ---- Category slicer (Item Master) ---- */
.slicer { display: flex; flex-wrap: wrap; gap: 8px; margin-bottom: 14px; }
.slicer .chip {
  display: inline-flex; align-items: center; gap: 6px; text-decoration: none;
  padding: 7px 12px; border-radius: 999px; border: 1px solid var(--line);
  background: #fff; color: var(--ink); font-size: .88rem; font-weight: 600; white-space: nowrap;
}
.slicer .chip:hover { border-color: var(--green); }
.slicer .chip.active { background: var(--green); color: #fff; border-color: var(--green); }
.slicer .chip-n { background: rgba(0,0,0,.08); border-radius: 999px; padding: 0 7px; font-size: .78rem; font-weight: 700; }
.slicer .chip.active .chip-n { background: rgba(255,255,255,.25); }

/* ---- Item thumbnails ---- */
.thumb { width: 40px; height: 40px; border-radius: 8px; object-fit: cover; border: 1px solid var(--line); display: inline-block; vertical-align: middle; }
.thumb-empty { display: inline-flex; align-items: center; justify-content: center; background: var(--bg); color: var(--muted); font-size: 1rem; }
.item-photo { width: 100%; max-width: 320px; border-radius: var(--radius); border: 1px solid var(--line); display: block; object-fit: cover; }
.photo-drop { border: 2px dashed var(--line); border-radius: var(--radius); padding: 18px; text-align: center; color: var(--muted); cursor: pointer; }
.photo-drop:hover { border-color: var(--green); color: var(--green-dark); }

/* ---- Toast ---- */
.toast {
  position: fixed; left: 50%; bottom: 20px; transform: translate(-50%, 140%);
  max-width: 92%; z-index: 200; padding: 14px 18px; border-radius: 12px;
  color: #fff; font-weight: 600; box-shadow: 0 8px 30px rgba(0,0,0,.3);
  transition: transform .25s ease; text-align: center;
}
.toast.show { transform: translate(-50%, 0); }
.toast-ok { background: var(--ok); }
.toast-err { background: var(--danger); }

@media print {
  .topbar, .sidenav, .nav-scrim, .action-bar, .no-print { display: none !important; }
  .content { margin: 0; max-width: none; padding: 0; }
  body { background: #fff; }
  .print-only { display: block; }
}
