/* Inventory Manager — mobile-first styling.
   Design rules: 48px minimum tap targets (56-64px for primary actions), 17px base text on phones,
   nothing under 14px, status always in words not just color, primary actions in the thumb zone. */

:root {
  --bg: #f1f4f2;
  --card: #ffffff;
  --ink: #16201b;
  --muted: #55615b;
  --line: #d9e0dc;
  --brand: #1f7a4d;
  --brand-dark: #155a38;
  --brand-soft: #e2f2e9;
  --warn: #9a5f00;
  --warn-soft: #fff1d6;
  --danger: #b42318;
  --danger-soft: #fde8e6;
  --info: #1d4f9c;
  --info-soft: #e2ecfa;
  --radius: 14px;
  --shadow: 0 1px 2px rgba(0,0,0,.05), 0 2px 10px rgba(0,0,0,.05);
  --tap: 48px;
  --tap-big: 60px;
  --nav-h: 64px;
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }
html { -webkit-text-size-adjust: 100%; font-size: 16px; }
@media (max-width: 800px) { html { font-size: 17px; } }
body {
  margin: 0;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  line-height: 1.45;
  color: var(--ink);
  background: var(--bg);
}
a { color: var(--brand); }
h1, h2, h3 { margin: 0 0 .5rem; line-height: 1.2; }
h1 { font-size: 1.5rem; }
h2 { font-size: 1.15rem; }
h3 { font-size: .9rem; color: var(--muted); font-weight: 700; text-transform: uppercase; letter-spacing: .04em; }
p { margin: 0 0 .75rem; }
.muted { color: var(--muted); }
.small { font-size: .9rem; }
.right { text-align: right; }
.nowrap { white-space: nowrap; }
code { background: #e9eeeb; padding: .1rem .35rem; border-radius: 5px; font-size: .92em; }
:focus-visible { outline: 3px solid #4c9dff; outline-offset: 2px; }

/* ---------- in-place navigation progress bar ---------- */
#nav-progress { position: fixed; top: 0; left: 0; height: 3px; width: 0; background: #ffd166; z-index: 100; opacity: 0;
  transition: width 1.2s cubic-bezier(.1,.7,.3,1), opacity .25s; pointer-events: none; }
#nav-progress.on { opacity: 1; width: 85%; }

/* ---------- top bar (desktop nav lives here) ---------- */
.topbar { background: var(--brand); color: #fff; position: sticky; top: 0; z-index: 10; box-shadow: 0 1px 4px rgba(0,0,0,.2); }
.topbar .inner { max-width: 1100px; margin: 0 auto; padding: .55rem 1rem; display: flex; align-items: center; gap: .75rem; }
.topbar .brand { color: #fff; text-decoration: none; font-weight: 700; font-size: 1.1rem; margin-right: auto; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; min-height: 44px; display: inline-flex; align-items: center; }
.topbar nav { display: flex; gap: .15rem; flex-wrap: wrap; }
.topbar nav a { color: #fff; text-decoration: none; padding: .5rem .55rem; border-radius: 8px; font-size: .92rem; opacity: .92; min-height: 40px; display: inline-flex; align-items: center; }
.topbar nav a:hover, .topbar nav a.active { background: rgba(255,255,255,.18); opacity: 1; }
.topbar .who { font-size: .9rem; opacity: .9; white-space: nowrap; }
@media (max-width: 800px) { .topbar nav { display: none; } }

/* ---------- bottom tab bar (phones) ---------- */
.tabbar { display: none; }
@media (max-width: 800px) {
  .tabbar {
    display: grid; grid-template-columns: repeat(5, 1fr);
    position: fixed; left: 0; right: 0; bottom: 0; z-index: 20;
    background: #fff; border-top: 1px solid var(--line);
    height: calc(var(--nav-h) + env(safe-area-inset-bottom, 0px));
    padding-bottom: env(safe-area-inset-bottom, 0px);
    box-shadow: 0 -2px 10px rgba(0,0,0,.06);
  }
  .tabbar a {
    display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 2px;
    text-decoration: none; color: var(--muted); font-size: .75rem; font-weight: 600; min-height: var(--nav-h);
  }
  .tabbar a svg { width: 26px; height: 26px; stroke: currentColor; fill: none; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; }
  .tabbar a.active { color: var(--brand); }
  .tabbar a.scan { color: #fff; }
  .tabbar a.scan span { color: var(--brand); }
  .tabbar a.scan svg { width: 30px; height: 30px; background: var(--brand); border-radius: 50%; padding: 11px; box-sizing: content-box; margin-top: -22px; box-shadow: 0 3px 10px rgba(31,122,77,.4); }
  .tabbar a.scan.active svg { background: var(--brand-dark); }
  main.wrap { padding-bottom: calc(var(--nav-h) + env(safe-area-inset-bottom, 0px) + 1.5rem); }
  .footer { display: none; }
}

.wrap { max-width: 1100px; margin: 0 auto; padding: 1rem; }
.wrap.narrow { max-width: 600px; }
.page-head { display: flex; justify-content: space-between; align-items: center; gap: .5rem; flex-wrap: wrap; margin-bottom: .75rem; }
.page-head h1 { margin: 0; }

/* ---------- flash messages ---------- */
.flash { display: flex; gap: .6rem; align-items: flex-start; padding: .85rem 1rem; border-radius: var(--radius); margin-bottom: 1rem; font-weight: 600; font-size: 1.02rem; line-height: 1.35; }
.flash::before { flex: none; width: 1.5rem; height: 1.5rem; border-radius: 50%; display: inline-flex; align-items: center; justify-content: center; font-size: .95rem; font-weight: 800; color: #fff; }
.flash.ok { background: var(--brand-soft); color: var(--brand-dark); }
.flash.ok::before { content: "✓"; background: var(--brand); }
.flash.error { background: var(--danger-soft); color: var(--danger); }
.flash.error::before { content: "!"; background: var(--danger); }
.flash.warn { background: var(--warn-soft); color: var(--warn); }
.flash.warn::before { content: "!"; background: var(--warn); }
.flash .btn { margin-left: auto; align-self: center; }

/* ---------- cards & grids ---------- */
.card { background: var(--card); border-radius: var(--radius); box-shadow: var(--shadow); padding: 1rem; margin-bottom: 1rem; }
.card h2 { margin-bottom: .75rem; }
.card.tight { padding: 0; overflow: hidden; }
.grid { display: grid; gap: 1rem; }
.grid.two { grid-template-columns: 1fr; }
@media (min-width: 800px) { .grid.two { grid-template-columns: 1fr 1fr; } }

.stats { display: grid; grid-template-columns: repeat(2, 1fr); gap: .75rem; margin-bottom: 1rem; }
@media (min-width: 700px) { .stats { grid-template-columns: repeat(4, 1fr); } }
.stat { background: var(--card); border-radius: var(--radius); box-shadow: var(--shadow); padding: .9rem 1rem; text-decoration: none; color: inherit; display: block; min-height: 84px; }
.stat .n { font-size: 2rem; font-weight: 800; line-height: 1.1; }
.stat .l { color: var(--muted); font-size: .9rem; margin-top: .15rem; }
.stat.alert .n { color: var(--danger); }
.stat.warn .n { color: var(--warn); }

/* ---------- hero action (dashboard) ---------- */
.hero-actions { display: grid; grid-template-columns: 1fr 1fr; gap: .75rem; margin-bottom: 1rem; }
.hero-actions .btn { min-height: 72px; font-size: 1.15rem; flex-direction: column; gap: .2rem; }
.hero-actions .btn svg { width: 28px; height: 28px; stroke: currentColor; fill: none; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; }
@media (min-width: 800px) { .hero-actions { display: none; } }

/* ---------- badges ---------- */
.badge { display: inline-flex; align-items: center; padding: .15rem .6rem; border-radius: 999px; font-size: .82rem; font-weight: 800; letter-spacing: .03em; white-space: nowrap; line-height: 1.5; }
.badge.qty { font-size: 1.05rem; padding: .25rem .75rem; min-width: 3rem; justify-content: center; }
.badge.OK { background: var(--brand-soft); color: var(--brand-dark); }
.badge.LOW { background: var(--warn-soft); color: var(--warn); }
.badge.OUT { background: var(--danger-soft); color: var(--danger); }
.badge.WORKING { background: var(--brand-soft); color: var(--brand-dark); }
.badge.PARTIAL { background: var(--warn-soft); color: var(--warn); }
.badge.DOWN { background: var(--danger-soft); color: var(--danger); }
.row.DOWN { box-shadow: inset 5px 0 0 var(--danger); }
.badge.requested { background: var(--warn-soft); color: var(--warn); }
.badge.ordered { background: var(--info-soft); color: var(--info); }
.badge.received { background: var(--brand-soft); color: var(--brand-dark); }
.badge.cancelled { background: #eceeed; color: #555; }
.badge.type, .badge.supply { background: #eceeed; color: #4a5650; }
.badge.equipment { background: #ebe6f7; color: #4b3a8c; }
.badge.auto { background: var(--info-soft); color: var(--info); }

/* ---------- tappable row lists ---------- */
.list { display: flex; flex-direction: column; }
.row { display: flex; align-items: center; gap: .75rem; padding: .8rem 1rem; min-height: 64px; border-bottom: 1px solid var(--line); background: #fff; text-decoration: none; color: inherit; }
.row:last-child { border-bottom: none; }
a.row:active, a.row:hover { background: #f4f8f5; }
.row .main { flex: 1; min-width: 0; }
.row .title { display: block; font-weight: 700; font-size: 1.02rem; line-height: 1.25; }
.row .meta { display: block; color: var(--muted); font-size: .9rem; margin-top: .15rem; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.row .side { flex: none; text-align: right; display: flex; align-items: center; gap: .5rem; }
.row .side .unit { color: var(--muted); font-size: .9rem; }
.row.OUT { box-shadow: inset 5px 0 0 var(--danger); }
.row.LOW { box-shadow: inset 5px 0 0 var(--warn); }
.row .chev { color: #b8c2bc; font-size: 1.3rem; flex: none; }

/* ---------- order cards ---------- */
.ocard { padding: .9rem 1rem; border-bottom: 1px solid var(--line); }
.ocard:last-child { border-bottom: none; }
.ocard .top { display: flex; justify-content: space-between; gap: .75rem; align-items: flex-start; }
.ocard .title { font-weight: 700; font-size: 1.02rem; display: inline-block; padding: .6rem 0; margin: -.6rem 0; }
.ocard .meta { color: var(--muted); font-size: .9rem; margin-top: .15rem; }
.ocard .qtybox { flex: none; text-align: right; }
.ocard .qtybox input { width: 5.2rem; text-align: right; font-weight: 700; font-size: 1.1rem; padding: .4rem .5rem; }
.ocard .qtybox .big { font-size: 1.4rem; font-weight: 800; }
.ocard .acts { display: flex; gap: .5rem; margin-top: .7rem; flex-wrap: wrap; }
.ocard .acts .btn { flex: 1 1 auto; }
.ocard .acts .btn.ghost { flex: 0 0 auto; }

/* ---------- tables (desktop-oriented pages) ---------- */
.table-wrap { overflow-x: auto; -webkit-overflow-scrolling: touch; }
table { width: 100%; border-collapse: collapse; font-size: .95rem; }
th, td { text-align: left; padding: .6rem .5rem; border-bottom: 1px solid var(--line); vertical-align: middle; }
th { font-size: .8rem; text-transform: uppercase; letter-spacing: .04em; color: var(--muted); font-weight: 700; }
tr:last-child td { border-bottom: none; }
td.num, th.num { text-align: right; white-space: nowrap; }
.rowlink { color: inherit; text-decoration: none; font-weight: 700; }
.rowlink:hover { color: var(--brand); }

/* ---------- forms ---------- */
label { display: block; font-size: .9rem; font-weight: 700; color: var(--muted); margin-bottom: .3rem; }
input[type=text], input[type=password], input[type=number], input[type=email], input[type=url],
input[type=time], select, textarea {
  width: 100%; padding: .7rem .8rem; border: 1.5px solid var(--line); border-radius: 10px; font-size: 1rem;
  background: #fff; color: var(--ink); font-family: inherit; min-height: var(--tap);
}
input:focus, select:focus, textarea:focus { outline: 3px solid rgba(31,122,77,.35); outline-offset: 0; border-color: var(--brand); }
textarea { min-height: 90px; resize: vertical; }
.field { margin-bottom: 1rem; }
.row-fields { display: grid; gap: .75rem; grid-template-columns: 1fr; }
@media (min-width: 600px) { .row-fields.c2 { grid-template-columns: 1fr 1fr; } .row-fields.c3 { grid-template-columns: 1fr 1fr 1fr; } }
.check { display: flex; align-items: center; gap: .6rem; font-size: 1rem; color: var(--ink); font-weight: 600; min-height: var(--tap); }
.check input { width: 1.4rem; height: 1.4rem; flex: none; }
.help { font-size: .88rem; color: var(--muted); margin-top: .3rem; }
.inline-form { display: inline; }
.actions { display: flex; gap: .6rem; flex-wrap: wrap; align-items: center; margin-top: .85rem; }
.pw-wrap { position: relative; }
.pw-wrap input { padding-right: 4.5rem; }
.pw-wrap button { position: absolute; right: .35rem; top: .35rem; bottom: .35rem; border: none; background: transparent; color: var(--brand); font-weight: 700; font-size: .95rem; padding: 0 .6rem; cursor: pointer; font-family: inherit; }

/* ---------- buttons ---------- */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: .4rem;
  min-height: var(--tap); padding: .6rem 1.1rem; border-radius: 12px; border: 1.5px solid transparent; cursor: pointer;
  font-size: 1.02rem; font-weight: 700; text-decoration: none; background: var(--brand); color: #fff; line-height: 1.2;
  font-family: inherit; -webkit-tap-highlight-color: transparent; touch-action: manipulation;
}
.btn:hover { background: var(--brand-dark); }
.btn:active { transform: scale(.98); }
.btn.secondary { background: #fff; color: var(--ink); border-color: #c9d2cd; }
.btn.secondary:hover { background: #f0f3f1; }
.btn.warn { background: var(--warn); }
.btn.danger { background: var(--danger); }
.btn.ghost { background: transparent; color: var(--brand); border-color: transparent; }
.btn.sm { min-height: 44px; padding: .45rem .9rem; font-size: .95rem; border-radius: 10px; }
.btn.big { min-height: var(--tap-big); padding: 1rem; font-size: 1.2rem; width: 100%; }
.btn.block { width: 100%; }
.btn:disabled { opacity: .5; cursor: default; transform: none; }
.btn svg { width: 1.3em; height: 1.3em; stroke: currentColor; fill: none; stroke-width: 2.2; stroke-linecap: round; stroke-linejoin: round; }

/* ---------- item page (what a QR scan opens) ---------- */
.item-hero { text-align: center; padding: 1.1rem 1rem 1rem; }
.item-hero .code { font-family: ui-monospace, Menlo, monospace; color: var(--muted); font-size: .9rem; }
.item-hero h1 { font-size: 1.4rem; }
.item-hero .qty { font-size: 4.5rem; font-weight: 800; line-height: 1; margin: .4rem 0 .1rem; letter-spacing: -.02em; }
.item-hero .unit { color: var(--muted); font-size: 1.05rem; display: flex; justify-content: center; align-items: center; gap: .5rem; flex-wrap: wrap; }
.quick { display: grid; grid-template-columns: 1fr 1fr; gap: .7rem; margin-top: 1rem; }
.quick .btn { min-height: var(--tap-big); font-size: 1.2rem; }
.quick .btn.minus { background: #fff; color: var(--danger); border: 2.5px solid var(--danger); }
.quick .btn.plus { background: #fff; color: var(--brand); border: 2.5px solid var(--brand); }
.adjust-row { display: grid; grid-template-columns: 1fr auto; gap: .6rem; align-items: end; margin-top: .75rem; }
.adjust-row input[type=number] { font-size: 1.5rem; font-weight: 700; text-align: center; min-height: 56px; }
.adjust-row .btn { min-height: 56px; }
.tabs { display: flex; gap: .4rem; margin-bottom: .75rem; }
.tabs button { flex: 1; min-height: var(--tap); padding: .5rem .3rem; border-radius: 10px; border: 1.5px solid #c9d2cd; background: #fff; font-weight: 700; cursor: pointer; font-size: 1rem; font-family: inherit; color: var(--ink); }
.tabs button.on { background: var(--brand); color: #fff; border-color: var(--brand); }
.kv { display: grid; grid-template-columns: auto 1fr; gap: .4rem 1rem; font-size: 1rem; }
.kv dt { color: var(--muted); } .kv dd { margin: 0; }
.qr-box { text-align: center; }
.qr-box img { width: 170px; height: 170px; image-rendering: pixelated; border: 1px solid var(--line); border-radius: 8px; padding: 6px; background: #fff; }
.undo { display: flex; align-items: center; gap: .75rem; background: #16201b; color: #fff; border-radius: var(--radius); padding: .7rem .8rem .7rem 1rem; margin-bottom: 1rem; }
.undo .msg { flex: 1; font-weight: 600; }
.undo .btn { background: #fff; color: var(--ink); min-height: 44px; }
details.fold { background: var(--card); border-radius: var(--radius); box-shadow: var(--shadow); margin-bottom: 1rem; }
details.fold > summary { list-style: none; cursor: pointer; padding: .9rem 1rem; font-weight: 700; display: flex; align-items: center; justify-content: space-between; min-height: 56px; }
details.fold > summary::-webkit-details-marker { display: none; }
details.fold > summary::after { content: "⌄"; font-size: 1.4rem; color: var(--muted); transition: transform .15s; }
details.fold[open] > summary::after { transform: rotate(180deg); }
details.fold > .body { padding: 0 1rem 1rem; }

/* ---------- misc ---------- */
.filters { display: flex; gap: .6rem; flex-wrap: wrap; align-items: center; margin-bottom: .75rem; }
.filters input[type=text] { flex: 1 1 180px; }
.filters select { width: auto; flex: 1 1 140px; }
.chip { display: inline-flex; align-items: center; min-height: 44px; padding: .4rem .9rem; border-radius: 999px; border: 1.5px solid #c9d2cd; background: #fff; text-decoration: none; color: var(--ink); font-size: .95rem; font-weight: 600; }
.chip.on { background: var(--brand); color: #fff; border-color: var(--brand); }
.empty { text-align: center; color: var(--muted); padding: 2rem 1rem; font-size: 1.02rem; }
.login-box { max-width: 420px; margin: 2rem auto; }
.login-box .logo { text-align: center; font-size: 2.4rem; margin-bottom: .25rem; }
.footer { text-align: center; color: var(--muted); font-size: .85rem; padding: 1rem; }
.supplier-group h3 { display: flex; justify-content: space-between; align-items: center; gap: .5rem; padding: .8rem 1rem .4rem; margin: 0; }
.supplier-group h3 a { text-transform: none; letter-spacing: 0; font-weight: 600; font-size: .9rem; }
.more-list .row { min-height: 60px; }
.more-list .row .title { font-size: 1.05rem; }
.more-list .ico { width: 40px; height: 40px; border-radius: 10px; background: var(--brand-soft); color: var(--brand-dark); display: flex; align-items: center; justify-content: center; flex: none; font-size: 1.2rem; }

@media (max-width: 600px) {
  .hide-sm { display: none !important; }
  h1 { font-size: 1.35rem; }
}

/* ---------- touch devices: nothing smaller than a thumb ---------- */
@media (pointer: coarse) {
  .btn.sm { min-height: var(--tap); }
  select { min-height: var(--tap); }
  td a, th a { padding: .3rem 0; display: inline-block; }
}

/* ---------- print ---------- */
@media print {
  .topbar, .tabbar, .footer, .flash, .noprint { display: none !important; }
  body { background: #fff; }
  main.wrap { padding-bottom: 0; }
}
