
/* Layout: phone = header, content, fixed bottom tab bar. Desktop = left sidebar + content. Single light theme by spec. */
:root {
  --bg: #fff; --fg: #000; --muted: #666; --line: #ddd; --soft: #f5f5f5; --side: #fafafa; --hover: #ececec;
  --occ: #c62828; --emp: #2e7d32;
  --font: Arial, Helvetica, sans-serif;
  color-scheme: light;
}
* { box-sizing: border-box; }
html, body { background: var(--bg); color: var(--fg); }
body { font-family: var(--font); font-size: 16px; line-height: 1.4; overflow-x: hidden; }
button, input, select { font: inherit; color: var(--fg); }
button:focus-visible, input:focus-visible, select:focus-visible { outline: 2px solid var(--fg); outline-offset: 1px; }

/* ---- Shell (phone first) ---- */
.wrap { max-width: 720px; margin: 0 auto; min-width: 0; padding-inline: 16px; padding-block: 12px calc(150px + env(safe-area-inset-bottom, 0px)); }
.sidebar .brand, .side-foot, .desk { display: none; }
.top { display: grid; gap: 10px; padding-bottom: 12px; border-bottom: 1px solid var(--line); }
.head { display: flex; align-items: baseline; justify-content: space-between; gap: 8px; flex-wrap: wrap; }
.head h1 { font-size: 20px; margin: 0; }
.pdesc { display: none; color: var(--muted); font-size: 14px; margin-top: 4px; }
.upd { font-size: 12px; color: var(--muted); font-variant-numeric: tabular-nums; display: inline-flex; align-items: center; gap: 4px; }
.sum { display: grid; gap: 6px; font-size: 14px; font-variant-numeric: tabular-nums; }
.sum b.o { color: var(--occ); } .sum b.e { color: var(--emp); }
.occbar { display: flex; height: 6px; border-radius: 3px; overflow: hidden; background: var(--emp); }
.occbar span { background: var(--occ); }

/* Bottom tab bar on phones: big touch targets, icon over label. */
.tabs { position: fixed; left: 0; right: 0; bottom: 0; z-index: 25; display: grid; grid-template-columns: repeat(4, 1fr);
  background: var(--bg); border-top: 1px solid var(--line); padding-bottom: env(safe-area-inset-bottom, 0px); }
.tabs a { display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 4px; min-height: 62px;
  background: none; border: 0; border-top: 3px solid transparent; margin-top: -1px; padding: 0; font-size: 12px; color: var(--muted); cursor: pointer; }
.tabs a .i { width: 24px; height: 24px; }
.tabs a.on { color: var(--fg); font-weight: bold; border-top-color: var(--fg); }

/* Sidebar on desktop. */
@media (min-width: 900px) {
  .app { display: grid; grid-template-columns: 236px minmax(0, 1fr); min-height: 100vh; }
  .sidebar { position: sticky; top: 0; align-self: start; height: 100vh; display: flex; flex-direction: column; gap: 28px;
    padding: 24px 14px; background: var(--side); border-right: 1px solid var(--line); }
  .sidebar .brand { display: block; font-size: 20px; font-weight: bold; padding: 0 10px; }
  .brand small { display: block; margin-top: 4px; font-size: 12px; font-weight: normal; color: var(--muted); }
  .tabs { position: static; display: grid; grid-template-columns: none; gap: 4px; background: none; border: 0; padding: 0; }
  .tabs a { flex-direction: row; justify-content: flex-start; gap: 12px; min-height: 0; padding: 11px 12px;
    border: 0; margin: 0; border-radius: 4px; font-size: 15px; color: var(--fg); }
  .tabs a .i { width: 20px; height: 20px; }
  .tabs a:hover { background: var(--hover); }
  .tabs a.on, .tabs a.on:hover { background: var(--fg); color: var(--bg); }
  .side-foot { display: grid; gap: 6px; margin-top: auto; padding: 12px 10px 0; border-top: 1px solid var(--line); font-size: 12px; color: var(--muted); overflow-wrap: anywhere; }
  .wrap { max-width: 1120px; padding-inline: 40px; padding-block: 32px 64px; }
  .mob { display: none; }
  .desk { display: inline; }
  .head h1 { font-size: 28px; }
  .pdesc { display: block; }
  .top { gap: 14px; padding-bottom: 18px; }
  .wrap > section { padding-top: 24px; }
}

section { padding-top: 14px; display: grid; gap: 12px; }
.row { display: flex; gap: 8px; flex-wrap: wrap; }
.row > * { min-width: 0; }
input[type=text], input[type=search], select { border: 1px solid var(--line); border-radius: 4px; padding: 10px; background: var(--bg); font-size: 16px; }
input[type=text], input[type=search] { flex: 1 1 180px; }
.btn { border: 1px solid var(--fg); border-radius: 4px; background: var(--bg); padding: 10px 14px; cursor: pointer; }
.btn.dark { background: var(--fg); color: var(--bg); }
.muted { color: var(--muted); font-size: 14px; }
.box { border: 1px solid var(--line); border-radius: 4px; padding: 12px; }

/* Scan */
#scanInput { font-size: 20px; text-transform: uppercase; letter-spacing: .02em; }
.status { color: #fff; border-radius: 4px; padding: 16px; text-align: center; }
.status.o { background: var(--occ); } .status.e { background: var(--emp); }
.status .word { font-size: 32px; font-weight: bold; letter-spacing: .04em; }
.status .code { font-size: 20px; margin-top: 4px; word-break: break-all; }
.status.none { background: var(--soft); color: var(--fg); border: 1px solid var(--line); }
.kv { display: grid; grid-template-columns: repeat(4, 1fr); gap: 8px; text-align: center; }
.kv div { border: 1px solid var(--line); border-radius: 4px; padding: 8px 4px; }
.kv small { display: block; font-size: 12px; color: var(--muted); }
.kv strong { font-size: 18px; font-variant-numeric: tabular-nums; }
.items { list-style: none; margin: 0; padding: 0; border: 1px solid var(--line); border-radius: 4px; }
.items li { padding: 10px 12px; border-top: 1px solid var(--line); display: flex; gap: 10px; justify-content: space-between; }
.items li:first-child { border-top: 0; }
.items .nm { min-width: 0; overflow-wrap: anywhere; font-size: 14px; }
.items .nm small { display: block; color: var(--muted); font-size: 12px; }
.items .q { font-weight: bold; white-space: nowrap; font-variant-numeric: tabular-nums; }
.list { display: grid; gap: 6px; }
.pick { display: flex; justify-content: space-between; gap: 8px; text-align: left; border: 1px solid var(--line); border-radius: 4px; background: var(--bg); padding: 10px 12px; cursor: pointer; }
.pick span:first-child { overflow-wrap: anywhere; min-width: 0; }
.t-o { color: var(--occ); font-weight: bold; } .t-e { color: var(--emp); font-weight: bold; }
h2 { font-size: 14px; margin: 4px 0 0; text-transform: uppercase; letter-spacing: .06em; color: var(--muted); }

/* Map */
.mapctl select { flex: 1 1 140px; }
/* Aisle view: even rows on the left, walkway in the middle, odd rows on the right. */
.rack { display: grid; }
.aisle-head, .aline { display: grid; grid-template-columns: minmax(0, 1fr) 32px minmax(0, 1fr); column-gap: 8px; }
.aisle-head { font-size: 12px; color: var(--muted); text-transform: uppercase; letter-spacing: .04em; padding-bottom: 6px; align-items: end; }
.aisle-head span:first-child { text-align: right; }
.aisle-head b { color: var(--fg); text-align: center; font-size: 13px; letter-spacing: 0; }
.walk { background: var(--soft); border-inline: 1px dashed var(--line); }
.aisle-foot .walk, .aisle-head .walk { background: none; border: 0; }
.side { display: flex; flex-direction: column; gap: 3px; padding: 4px 0; min-width: 0; border-bottom: 1px solid var(--line); }
.side.left { align-items: flex-end; }
.side.none { border-bottom-color: transparent; }
.rlab { font-size: 12px; font-weight: bold; font-variant-numeric: tabular-nums; }
.cells { display: flex; flex-wrap: wrap; gap: 3px; min-width: 0; }
.side.left .cells { justify-content: flex-end; }
.cell { width: 28px; height: 28px; border: 0; border-radius: 4px; color: #fff; font-size: 11px; cursor: pointer; padding: 0; font-variant-numeric: tabular-nums; }
@media (min-width: 900px) {
  .side { flex-direction: row; align-items: center; gap: 8px; }
  .side.left { flex-direction: row-reverse; }
  .rlab { width: 40px; flex: none; }
  .side.left .rlab { text-align: left; }
  .side.right .rlab { text-align: right; }
  .cells { flex: 1; }
  .cell { width: 34px; height: 30px; font-size: 12px; }
}
.shelf { display: grid; gap: 3px; min-width: 0; flex: 1; }
.lvl { display: flex; align-items: center; gap: 6px; min-width: 0; padding-bottom: 3px; border-bottom: 2px solid var(--line); }
.side.left .lvl { flex-direction: row-reverse; }
.llab { width: 22px; flex: none; font-size: 11px; color: var(--muted); font-variant-numeric: tabular-nums; }
.side.left .llab { text-align: left; }
.lvl .cells { flex: 1; }
.cell.o { background: var(--occ); } .cell.e { background: var(--emp); }
.cell.sel { outline: 3px solid var(--fg); outline-offset: 1px; }
.legend { display: flex; gap: 16px; font-size: 13px; flex-wrap: wrap; }
.legend span::before { content: ""; display: inline-block; width: 12px; height: 12px; border-radius: 2px; margin-right: 6px; vertical-align: -1px; }
.legend .lo::before { background: var(--occ); } .legend .le::before { background: var(--emp); }

/* Table */
.tw { overflow-x: auto; border: 1px solid var(--line); border-radius: 4px; }
table { border-collapse: collapse; width: 100%; font-size: 14px; }
th, td { text-align: left; padding: 9px 10px; border-top: 1px solid var(--line); white-space: nowrap; }
thead th { border-top: 0; background: var(--soft); font-size: 12px; text-transform: uppercase; letter-spacing: .04em; }
td.n, th.n { text-align: right; font-variant-numeric: tabular-nums; }
tbody tr { cursor: pointer; }
tbody tr:hover { background: var(--soft); }

/* Ask */
.chat { display: grid; gap: 10px; }
.msg { border: 1px solid var(--line); border-radius: 4px; padding: 10px 12px; white-space: pre-wrap; overflow-wrap: anywhere; font-size: 15px; min-width: 0; }
.msg.me { background: var(--soft); justify-self: end; max-width: 88%; }
.msg.bot { justify-self: start; max-width: 100%; }
.msg.err { color: var(--occ); }
.msg small { display: block; color: var(--muted); font-size: 12px; margin-bottom: 4px; }
.chip { border: 1px solid var(--line); border-radius: 4px; background: var(--bg); padding: 8px 10px; font-size: 14px; cursor: pointer; text-align: left; }
.keybox { display: grid; gap: 10px; font-size: 14px; }
.fab { position: fixed; right: 16px; bottom: calc(78px + env(safe-area-inset-bottom, 0px)); z-index: 20;
  width: 60px; height: 60px; display: grid; place-items: center;
  background: var(--fg); color: var(--bg); border: 0; border-radius: 50%; padding: 0; cursor: pointer; }
.fab svg { display: block; }
.panel { position: fixed; inset: 0; z-index: 30; background: var(--bg); display: flex; flex-direction: column;
  padding-top: env(safe-area-inset-top, 0px); padding-bottom: env(safe-area-inset-bottom, 0px); }
.panel[hidden] { display: none; }
.phead { display: flex; justify-content: space-between; align-items: center; gap: 8px; padding: 10px 16px; border-bottom: 1px solid var(--line); }
.phead strong { font-size: 18px; }
.phead .btn { padding: 8px 12px; }
.pbody { flex: 1; overflow-y: auto; padding: 12px 16px; display: grid; gap: 12px; align-content: start; min-height: 0; }
.pfoot { border-top: 1px solid var(--line); padding: 10px 16px; display: grid; gap: 6px; }
.askrow { display: flex; gap: 8px; }
.askrow input { flex: 1 1 auto; min-width: 0; }
.linkbtn { background: none; border: 0; padding: 4px 0; color: var(--muted); font-size: 13px; text-decoration: underline; cursor: pointer; justify-self: start; }
/* Desktop: wider page, Scan and Data split into two columns. */
@media (min-width: 900px) {
  .fab { right: 24px; bottom: 24px; }
  #p-scan { grid-template-columns: minmax(0, 3fr) minmax(0, 2fr); align-items: start; column-gap: 24px; }
  #scanForm, #result { grid-column: 1; }
  #histWrap { grid-column: 2; grid-row: 1 / span 2; display: grid; gap: 8px; }
  #histWrap[hidden] { display: none; }
  #p-data { grid-template-columns: minmax(0, 1fr) minmax(0, 1fr); align-items: start; column-gap: 24px; }
  .mapctl { max-width: 560px; }
}
.dcol { display: grid; gap: 12px; min-width: 0; align-content: start; }
@media (min-width: 720px) {
  .panel { inset: auto 16px 16px auto; width: 400px; height: min(640px, calc(100% - 32px)); border: 1px solid var(--line); border-radius: 4px; padding: 0; }
}

/* Icons: line icons that follow the text color. */
.i { width: 1.15em; height: 1.15em; flex: none; fill: none; stroke: currentColor; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; vertical-align: -0.2em; }
.btn, .linkbtn, .phead .btn { display: inline-flex; align-items: center; justify-content: center; gap: 6px; }
h2 { display: flex; align-items: center; gap: 6px; }
.status .big { width: 40px; height: 40px; margin: 0 auto 4px; display: block; }
.st { display: inline-flex; align-items: center; gap: 4px; }

dl { display: grid; grid-template-columns: max-content 1fr; gap: 6px 14px; margin: 0; font-size: 14px; }
dt { color: var(--muted); } dd { margin: 0; overflow-wrap: anywhere; }

/* ---- Multi-page additions ---- */
.tabs a { text-decoration: none; }

/* Drop area for a new inventory file. */
.vh { position: absolute; width: 1px; height: 1px; opacity: 0; overflow: hidden; clip: rect(0 0 0 0); }
.drop { position: relative; display: grid; justify-items: center; gap: 6px; text-align: center; padding: 32px 16px;
  border: 2px dashed #bbb; border-radius: 4px; background: var(--bg); cursor: pointer; transition: background .15s, border-color .15s; }
.drop:hover { border-color: var(--fg); }
.drop.drag { border-style: solid; border-color: var(--fg); background: var(--soft); }
.drop:focus-within { outline: 2px solid var(--fg); outline-offset: 2px; }
.drop.busy { cursor: progress; opacity: .6; pointer-events: none; }
.drop .big { width: 40px; height: 40px; margin-bottom: 4px; }
.drop strong { font-size: 17px; }
.drop u { text-underline-offset: 3px; color: var(--fg); }
.drop .hint { font-size: 12px; color: var(--muted); margin-top: 6px; }
.filestat { display: flex; gap: 8px; align-items: flex-start; font-size: 14px; padding: 10px 12px; border: 1px solid var(--line); border-radius: 4px; }
.filestat .i { margin-top: 1px; }
.filestat.ok { border-color: var(--emp); color: var(--emp); }
.filestat.err { border-color: var(--occ); color: var(--occ); }
.inuse { display: flex; flex-wrap: wrap; gap: 10px 16px; align-items: center; justify-content: space-between; }
.inuse .meta { display: grid; gap: 3px; min-width: 0; font-size: 14px; }
.inuse .meta b { overflow-wrap: anywhere; font-size: 15px; }
@media (prefers-reduced-motion: reduce) { .drop { transition: none; } }

/* Map page: one compact bar. */
.maptool { display: grid; gap: 10px; }
.mapbar { display: grid; grid-template-columns: 46px minmax(0, 1fr) 46px; gap: 6px; }
.mapbar select { width: 100%; min-width: 0; height: 46px; font-weight: bold; }
.ibtn { height: 46px; display: grid; place-items: center; border: 1px solid var(--line); border-radius: 4px; background: var(--bg); cursor: pointer; padding: 0; }
.ibtn:hover { border-color: var(--fg); }
.ibtn .i { width: 20px; height: 20px; }
.mstats { display: flex; flex-wrap: wrap; gap: 6px; align-items: stretch; }
.mstats .mstat { flex: 1 1 0; }
.mstats .mtype { flex-basis: 100%; padding: 0 2px; }
.mstat { display: flex; align-items: center; gap: 6px; padding: 8px 10px; border: 1px solid var(--line); border-radius: 4px; font-size: 14px; white-space: nowrap; }
.mstat::before { content: ""; width: 10px; height: 10px; border-radius: 2px; flex: none; }
.mstat.o::before { background: var(--occ); } .mstat.e::before { background: var(--emp); }
.mstat b { font-size: 16px; font-variant-numeric: tabular-nums; }
.mstat.o b { color: var(--occ); } .mstat.e b { color: var(--emp); }
.mstat.n::before { background: var(--bg); border: 1px dashed #999; }
.mstat.n b { color: var(--muted); }
.cell.n { background: var(--soft); color: #888; border: 1px dashed #bbb; }
.mtype { display: flex; align-items: center; padding: 0 4px; font-size: 13px; color: var(--muted); white-space: nowrap; }
@media (min-width: 640px) {
  .maptool { grid-template-columns: minmax(260px, 380px) minmax(0, 1fr); align-items: center; }
  .mstats { justify-content: flex-end; }
  .mstats .mstat { flex: none; }
  .mstats .mtype { flex-basis: auto; }
}
/* Shelf bins sit in a fixed 6-column grid (L6 uses the first 3), so every level stays on one line. */
.shelf .cells { display: grid; grid-template-columns: repeat(6, 34px); gap: 3px; }
.side.left .shelf .cells { justify-content: end; }
.side.left .lvl.l6 .cell:first-child { grid-column-start: 4; }
@media (max-width: 899px) {
  .shelf .cells { grid-template-columns: repeat(6, minmax(0, 1fr)); gap: 2px; }
  .shelf .cell { width: auto; height: 28px; font-size: 11px; }
}
.side > .shelf { align-self: stretch; }
@media (max-width: 479px) {
  .aline { grid-template-columns: minmax(0, 1fr) 14px minmax(0, 1fr); column-gap: 5px; }
  .aisle-head { grid-template-columns: minmax(0, 1fr) auto minmax(0, 1fr); column-gap: 8px; }
  .aisle-head b { font-size: 12px; }
  .llab { width: 16px; font-size: 10px; }
  .lvl { gap: 3px; }
}
.aisle-head { padding-top: 4px; border-bottom: 1px solid var(--line); margin-bottom: 2px; }

/* Table page. */
.tfilters { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 8px; }
.tfilters select { width: 100%; min-width: 0; }
.fsearch { grid-column: 1 / -1; display: flex; align-items: center; gap: 8px; border: 1px solid var(--line); border-radius: 4px; padding-inline: 10px; background: var(--bg); color: var(--muted); }
.fsearch:focus-within { outline: 2px solid var(--fg); outline-offset: 1px; }
.fsearch input { border: 0; padding: 10px 0; flex: 1; min-width: 0; outline: none; }
.tmeta { display: flex; justify-content: space-between; align-items: baseline; gap: 8px; flex-wrap: wrap; font-size: 14px; }
.dk { display: none; }
td.item { max-width: 320px; overflow: hidden; text-overflow: ellipsis; color: var(--muted); }
@media (min-width: 900px) {
  .tfilters { grid-template-columns: minmax(0, 2fr) repeat(3, minmax(0, 1fr)); }
  .fsearch { grid-column: auto; }
  .dk { display: table-cell; }
  .tw.tall { max-height: calc(100vh - 300px); overflow: auto; }
  .tw.tall thead th { position: sticky; top: 0; z-index: 1; }
  #tMore { justify-self: start; }
}

/* Assistant is hidden for now: remove this rule to bring the chat button back. */
#askOpen, #askPanel { display: none !important; }

/* Credit: sidebar footer on desktop, page footer on phones. */
.credit { color: var(--fg); font-weight: bold; margin-top: 4px; }
.mfoot { margin-top: 28px; padding-top: 12px; border-top: 1px solid var(--line); font-size: 12px; color: var(--muted); text-align: center; }
@media (min-width: 900px) { .mfoot { display: none; } }
