/* Lab Portal – mobile-first styles. No framework, no web fonts: loads fast on a phone in the cold room. */
:root {
  --navy: #171151; --blue: #0e63ff; --green: #0aa57f; --amber: #b7791f; --red: #d92d20;
  --bg: #f4f5fa; --card: #fff; --text: #1b1b2f; --muted: #6b7086; --line: #e3e5ee; --soft: #eef1fb;
  --ok-bg: #e4f7f1; --warn-bg: #fdf3dc; --bad-bg: #fde8e6;
  --radius: 14px; --tab-h: 62px;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0f1020; --card: #1a1b30; --text: #ecedf5; --muted: #a0a4bd; --line: #2c2e49; --soft: #23254a;
    --blue: #6ea0ff; --green: #34d3a6; --amber: #f0b849; --red: #ff7b6e;
    --ok-bg: #12382f; --warn-bg: #3d3115; --bad-bg: #46201c;
  }
}
* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0; background: var(--bg); color: var(--text);
  font: 16px/1.45 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  padding-bottom: calc(var(--tab-h) + env(safe-area-inset-bottom) + 16px);
}
a { color: var(--blue); text-decoration: none; }
h1 { font-size: 1.45rem; line-height: 1.2; margin: .2rem 0 .4rem; overflow-wrap: anywhere; }
h2 { font-size: 1.02rem; margin: 1.5rem 0 .55rem; color: var(--muted); text-transform: uppercase; letter-spacing: .04em; font-weight: 700; }
h3, h4, h5 { margin: 1rem 0 .4rem; }
p { margin: .4rem 0; }
code, .mono, .code { font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace; }
.muted { color: var(--muted); } .small { font-size: .84rem; } .center { text-align: center; } .mt { margin-top: .8rem; }
.bad { color: var(--red); font-weight: 600; }
[hidden] { display: none !important; }

/* ---- top bar ---- */
.top { position: sticky; top: 0; z-index: 20; background: var(--navy); color: #fff; padding-top: env(safe-area-inset-top); }
.top-in { display: flex; align-items: center; gap: .5rem; max-width: 1040px; margin: auto; padding: .5rem .75rem; min-height: 54px; }
.brand { display: flex; align-items: center; gap: .55rem; color: #fff; font-weight: 700; margin-right: auto; min-width: 0; }
.brand-mark { flex: none; width: 32px; height: 32px; border-radius: 9px; background: linear-gradient(135deg, #10d0a1, #0e63ff); display: grid; place-items: center; font-weight: 800; }
.brand-text { line-height: 1.1; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.brand-text small { display: block; font-weight: 500; opacity: .7; font-size: .72rem; }
.iconbtn { color: #fff; display: grid; place-items: center; width: 42px; height: 42px; border-radius: 50%; flex: none; }
.iconbtn:active { background: rgba(255,255,255,.15); }
.deskn, .top-search { display: none; }
main { max-width: 760px; margin: auto; padding: .9rem .85rem 1rem; }
main.bare { padding-top: 8vh; }

/* ---- bottom tabs (phone) ---- */
.tabs {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 30; display: flex;
  background: var(--card); border-top: 1px solid var(--line);
  padding-bottom: env(safe-area-inset-bottom); height: calc(var(--tab-h) + env(safe-area-inset-bottom));
}
.tabs a { flex: 1; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 2px; color: var(--muted); font-size: .7rem; font-weight: 600; min-width: 0; }
.tabs a.on { color: var(--blue); }
.tabs .tab-add svg { background: var(--blue); color: #fff; border-radius: 50%; padding: 7px; width: 40px; height: 40px; margin-top: -4px; box-shadow: 0 3px 10px rgba(14,99,255,.4); }
.tabs .tab-add span { display: none; }

/* ---- generic pieces ---- */
.card { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); padding: .9rem; margin: .6rem 0; }
.card.list { padding: 0; overflow: hidden; }
.card h2 { margin-top: 0; }
.tip { background: var(--soft); border-color: transparent; }
.tip ol { margin: .4rem 0 0; padding-left: 1.2rem; } .tip li { margin: .3rem 0; }
.flash { padding: .7rem .9rem; border-radius: 12px; margin: .5rem 0; background: var(--ok-bg); font-weight: 500; }
.flash.err { background: var(--bad-bg); }
.empty { text-align: center; padding: 2rem 1rem; color: var(--muted); }
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: .35rem; min-height: 44px; padding: .5rem 1rem;
  border-radius: 12px; border: 1px solid var(--line); background: var(--card); color: var(--text);
  font: inherit; font-weight: 600; cursor: pointer; text-align: center; -webkit-tap-highlight-color: transparent;
}
.btn:active { transform: scale(.98); }
.btn.primary { background: var(--blue); border-color: var(--blue); color: #fff; }
@media (prefers-color-scheme: dark) { .btn.primary { color: #0b1024; } }
.btn.danger { color: var(--red); }
.btn.small { min-height: 36px; padding: .3rem .7rem; font-size: .88rem; border-radius: 10px; }
.btn.block { display: flex; width: 100%; }
.btn[disabled] { opacity: .6; }
.btnrow { display: flex; flex-wrap: wrap; gap: .5rem; align-items: center; }
.btnrow.center { justify-content: center; margin: 1rem 0; }
.badge { display: inline-block; padding: .1rem .5rem; border-radius: 999px; font-size: .76rem; font-weight: 700; background: var(--soft); color: var(--text); white-space: nowrap; }
.badge.st-ok, .badge.v-good, .badge.r-strong { background: var(--ok-bg); color: var(--green); }
.badge.r-moderate { background: var(--soft); color: var(--blue); }
.badge.st-low, .badge.v-weak, .badge.r-weak { background: var(--warn-bg); color: var(--amber); }
.badge.st-empty, .badge.v-bad, .badge.r-failed { background: var(--bad-bg); color: var(--red); }
.pos { display: inline-block; background: var(--navy); color: #fff; border-radius: 7px; padding: 0 .4rem; font-weight: 700; font-size: .85rem; font-family: ui-monospace, Menlo, Consolas, monospace; }
@media (prefers-color-scheme: dark) { .pos { background: var(--blue); color: #0b1024; } }

/* ---- forms ---- */
.field { margin: 0 0 .85rem; min-width: 0; }
.field:last-child { margin-bottom: 0; }
label { display: block; font-size: .86rem; font-weight: 600; margin-bottom: .25rem; color: var(--muted); }
input, select, textarea {
  width: 100%; font: inherit; font-size: 16px; /* 16px stops iOS zooming on focus */
  color: var(--text); background: var(--card); border: 1px solid var(--line); border-radius: 10px; padding: .6rem .7rem; min-height: 46px;
}
textarea { min-height: 0; resize: vertical; }
input[type=checkbox], input[type=radio] { width: auto; min-height: 0; }
input[type=file] { padding: .5rem; }
input:focus, select:focus, textarea:focus { outline: 2px solid var(--blue); outline-offset: 1px; border-color: transparent; }
.row2 { display: grid; grid-template-columns: 1fr 1fr; gap: .6rem; }
.hint { font-size: .82rem; color: var(--muted); margin-top: .25rem; }
.hint.warn { color: var(--amber); font-weight: 600; }
.req { color: var(--red); }
.check { display: flex; align-items: center; gap: .5rem; color: var(--text); font-size: .95rem; }
.check input { width: 20px; height: 20px; }
.chips { display: flex; flex-wrap: wrap; gap: .4rem; }
.chip { margin: 0; }
.chip input { position: absolute; opacity: 0; pointer-events: none; }
.chip span { display: inline-block; padding: .4rem .75rem; border-radius: 999px; border: 1px solid var(--line); color: var(--text); font-size: .9rem; font-weight: 500; cursor: pointer; }
.chip input:checked + span { background: var(--blue); border-color: var(--blue); color: #fff; }
.chip input:focus-visible + span { outline: 2px solid var(--blue); outline-offset: 2px; }
.seg { display: flex; border: 1px solid var(--line); border-radius: 10px; overflow: hidden; }
.seg label { flex: 1; margin: 0; }
.seg input { position: absolute; opacity: 0; }
.seg span { display: block; text-align: center; padding: .55rem .3rem; font-size: .88rem; color: var(--text); cursor: pointer; }
.seg input:checked + span { background: var(--blue); color: #fff; }
.savebar { position: sticky; bottom: calc(var(--tab-h) + env(safe-area-inset-bottom) + 8px); z-index: 10; margin-top: .8rem; }
.savebar .btn { box-shadow: 0 6px 18px rgba(0,0,0,.18); }
.ai-filled { box-shadow: 0 0 0 2px var(--amber) !important; }
.scan .scanbtn { font-size: 1.05rem; min-height: 54px; }
#scantext pre { white-space: pre-wrap; font-size: .82rem; background: var(--soft); padding: .6rem; border-radius: 8px; max-height: 12rem; overflow: auto; }

/* ---- validation result picker ---- */
.results { display: grid; grid-template-columns: 1fr 1fr; gap: .5rem; }
.result { margin: 0; }
.result input { position: absolute; opacity: 0; }
.result span { display: block; border: 2px solid var(--line); border-radius: 12px; padding: .55rem .65rem; cursor: pointer; height: 100%; }
.result strong { display: block; color: var(--text); font-size: .95rem; }
.result small { color: var(--muted); font-weight: 400; }
.result.r-strong input:checked + span { border-color: var(--green); background: var(--ok-bg); }
.result.r-moderate input:checked + span { border-color: var(--blue); background: var(--soft); }
.result.r-weak input:checked + span { border-color: var(--amber); background: var(--warn-bg); }
.result.r-failed input:checked + span { border-color: var(--red); background: var(--bad-bg); }

/* ---- search + lists ---- */
.hero { margin-bottom: .4rem; }
.hello { font-size: 1.2rem; font-weight: 700; margin: .2rem 0 .6rem; }
.bigsearch { display: flex; background: var(--card); border: 1px solid var(--line); border-radius: 14px; overflow: hidden; margin: .5rem 0; }
.bigsearch input { border: 0; background: transparent; min-height: 50px; flex: 1; min-width: 0; }
.bigsearch input:focus { outline: none; }
.bigsearch:focus-within { outline: 2px solid var(--blue); }
.bigsearch button { border: 0; background: transparent; color: var(--blue); width: 52px; cursor: pointer; display: grid; place-items: center; }
.scroller { display: flex; gap: .4rem; overflow-x: auto; padding: .2rem 0 .5rem; margin: 0 -.85rem; padding-left: .85rem; padding-right: .85rem; scrollbar-width: none; -webkit-overflow-scrolling: touch; }
.scroller::-webkit-scrollbar { display: none; }
.pill { flex: none; padding: .4rem .8rem; border-radius: 999px; background: var(--card); border: 1px solid var(--line); color: var(--text); font-size: .88rem; font-weight: 600; white-space: nowrap; }
.pill.on { background: var(--navy); border-color: var(--navy); color: #fff; }
@media (prefers-color-scheme: dark) { .pill.on { background: var(--blue); border-color: var(--blue); color: #0b1024; } }
.morefilters { margin: .2rem 0 .4rem; }
.morefilters summary { cursor: pointer; font-weight: 600; color: var(--blue); padding: .35rem 0; }
.filtergrid { display: grid; grid-template-columns: 1fr 1fr; gap: .6rem; padding: .4rem 0; align-items: end; }
.listhead { display: flex; align-items: center; justify-content: space-between; gap: .5rem; margin: .5rem 0; }
.listhead h1 { margin: 0; }
.tiles { display: grid; grid-template-columns: repeat(3, 1fr); gap: .55rem; }
.tile { position: relative; background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); padding: .8rem .4rem .7rem; text-align: center; color: var(--text); display: flex; flex-direction: column; align-items: center; gap: .25rem; min-width: 0; }
.tile:active { background: var(--soft); }
.tile-ico { font-size: 1.7rem; line-height: 1.1; }
.tile-name { font-size: .8rem; font-weight: 600; line-height: 1.15; overflow-wrap: anywhere; }
.tile-n { position: absolute; top: 6px; right: 8px; font-size: .72rem; font-weight: 700; color: var(--muted); }
.irow { display: flex; gap: .7rem; padding: .7rem .85rem; color: var(--text); border-bottom: 1px solid var(--line); align-items: flex-start; }
.irow:last-child { border-bottom: 0; }
.irow:active { background: var(--soft); }
.ico { flex: none; width: 38px; height: 38px; border-radius: 10px; background: var(--soft); display: grid; place-items: center; font-size: 1.2rem; }
.ibody { display: flex; flex-direction: column; min-width: 0; flex: 1; gap: 1px; }
.iname { font-weight: 650; overflow-wrap: anywhere; }
.isub { font-size: .84rem; color: var(--muted); overflow-wrap: anywhere; }
.iwhere { font-size: .84rem; color: var(--green); font-weight: 600; overflow-wrap: anywhere; }
.iwhere.muted { color: var(--muted); font-weight: 400; }
.ibadges { display: flex; flex-wrap: wrap; gap: .3rem; margin-top: .25rem; }
.feed .act { padding: .45rem 0; border-bottom: 1px solid var(--line); font-size: .92rem; overflow-wrap: anywhere; }
.feed .act:last-of-type { border-bottom: 0; }
.feed .more { display: block; padding-top: .5rem; font-weight: 600; font-size: .9rem; }
.menu { padding: 0; overflow: hidden; }
.menu a { display: block; padding: .85rem .9rem; border-bottom: 1px solid var(--line); color: var(--text); font-weight: 600; }
.menu a:last-child { border-bottom: 0; }
.member { display: flex; flex-wrap: wrap; justify-content: space-between; gap: .5rem; padding: .7rem 0; border-bottom: 1px solid var(--line); }
.member:last-child { border-bottom: 0; } .member.off { opacity: .6; }
.maprow { display: grid; grid-template-columns: 1fr 1fr; gap: .6rem; align-items: center; padding: .5rem 0; border-bottom: 1px solid var(--line); }
.maprow div { min-width: 0; overflow-wrap: anywhere; } .maprow .small { display: block; }
.moverow { display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between; gap: .5rem; border-top: 1px solid var(--line); margin-top: .6rem; padding-top: .6rem; }

/* ---- item page ---- */
.itemhead { display: flex; gap: .8rem; align-items: flex-start; margin-bottom: .4rem; }
.bigico { flex: none; width: 54px; height: 54px; border-radius: 14px; background: var(--card); border: 1px solid var(--line); display: grid; place-items: center; font-size: 1.8rem; }
.itemhead > div { min-width: 0; }
.where { display: block; font-weight: 700; font-size: 1.02rem; color: var(--text); overflow-wrap: anywhere; }
a.where { color: var(--blue); }
.stock.off { opacity: .65; }
.stockmeta { display: flex; flex-wrap: wrap; gap: .3rem .7rem; align-items: center; font-size: .9rem; margin: .45rem 0 .6rem; }
.val { border-left: 5px solid var(--line); }
.val.r-strong { border-left-color: var(--green); } .val.r-moderate { border-left-color: var(--blue); }
.val.r-weak { border-left-color: var(--amber); } .val.r-failed { border-left-color: var(--red); }
.valhead { display: flex; flex-wrap: wrap; justify-content: space-between; gap: .3rem .6rem; align-items: center; margin-bottom: .4rem; }
dl { margin: 0; }
dl.details dt, dl.mini dt { font-size: .78rem; font-weight: 700; color: var(--muted); text-transform: uppercase; letter-spacing: .03em; margin-top: .6rem; }
dl.details dd, dl.mini dd { margin: 0; overflow-wrap: anywhere; }
dl.mini { margin-bottom: .5rem; }
.seq { display: block; background: var(--soft); border-radius: 8px; padding: .5rem .6rem; font-size: .92rem; word-break: break-all; cursor: pointer; }
.files { display: flex; flex-wrap: wrap; gap: .5rem; margin: .5rem 0; }
.thumb { position: relative; width: 104px; height: 104px; border-radius: 10px; overflow: hidden; border: 1px solid var(--line); background: var(--soft); }
.thumb img { width: 100%; height: 100%; object-fit: cover; display: block; }
.filechip { position: relative; display: flex; align-items: center; gap: .3rem; background: var(--soft); border-radius: 10px; padding: .45rem .6rem; max-width: 100%; overflow-wrap: anywhere; font-size: .9rem; }
.file-del button { border: 0; background: rgba(0,0,0,.6); color: #fff; width: 26px; height: 26px; border-radius: 50%; font-size: 1rem; line-height: 1; cursor: pointer; }
.thumb .file-del { position: absolute; top: 4px; right: 4px; }
.prose { overflow-wrap: anywhere; } .prose h3 { font-size: 1.15rem; } .prose h4 { font-size: 1rem; } .prose li { margin: .25rem 0; }

/* ---- storage ---- */
.crumbs { font-size: .86rem; color: var(--muted); margin-bottom: .4rem; overflow-wrap: anywhere; }
.gridwrap { overflow-x: auto; margin: .6rem -.85rem; padding: 0 .85rem; -webkit-overflow-scrolling: touch; }
.boxgrid { display: grid; grid-template-columns: 18px repeat(var(--cols), minmax(30px, 1fr)); gap: 3px; min-width: calc(18px + var(--cols) * 33px); }
.gh { font-size: .68rem; color: var(--muted); display: grid; place-items: center; font-weight: 700; }
.cell { aspect-ratio: 1; border-radius: 7px; display: flex; flex-direction: column; align-items: center; justify-content: center; overflow: hidden; font-size: .56rem; line-height: 1.05; text-align: center; color: var(--text); }
.cell i { font-style: normal; max-width: 100%; overflow: hidden; white-space: nowrap; padding: 0 1px; }
.cell b { font-size: .8rem; font-weight: 400; line-height: 1; }
.cell.free { border: 1.5px dashed var(--line); color: var(--muted); }
.cell.full { background: var(--blue); color: #fff; }
.cell.full.st-low { background: var(--amber); }
.cell.hl { outline: 3px solid var(--red); outline-offset: 1px; animation: pulse 1s ease-in-out 3; }
@keyframes pulse { 50% { transform: scale(1.18); } }
@media (prefers-reduced-motion: reduce) { .cell.hl { animation: none; } }
.gridpick { margin-top: .6rem; }
.gridpick .boxgrid button { font: inherit; font-size: .6rem; padding: 0; cursor: pointer; background: transparent; }
.gridpick .cell.full { background: var(--line); color: var(--muted); cursor: not-allowed; }
.gridpick .cell.sel { background: var(--green); border-color: var(--green); color: #fff; font-weight: 800; }
.gridpick .picked { font-weight: 700; margin: .4rem 0; }

/* ---- auth ---- */
.authbox { max-width: 400px; margin: auto; }
.authbox h1 { text-align: center; }
.authbox > .muted { text-align: center; }
.authlogo { display: block; max-width: 190px; max-height: 70px; margin: 0 auto 1rem; }
@media (prefers-color-scheme: dark) { .authlogo { background: #fff; border-radius: 10px; padding: 6px 10px; } }

/* ---- QR labels ---- */
.qrsheet { display: flex; flex-wrap: wrap; gap: 10px; margin-top: 1rem; }
.qrlabel { display: flex; align-items: center; gap: 8px; width: 62mm; padding: 2mm; border: 1px dashed #999; border-radius: 6px; background: #fff; color: #000; }
.qr { width: 24mm; height: 24mm; flex: none; } .qr svg { width: 100%; height: 100%; display: block; }
.qrtext { display: flex; flex-direction: column; font-size: 9pt; line-height: 1.15; min-width: 0; overflow-wrap: anywhere; }
.qrtext strong { font-size: 11pt; } .qrtext em { font-style: normal; color: #555; font-size: 7pt; margin-top: 2px; }

/* ---- larger screens ---- */
@media (min-width: 860px) {
  body { padding-bottom: 2rem; }
  .tabs { display: none; }
  .deskn { display: flex; align-items: center; gap: .2rem; }
  .deskn a:not(.btn) { color: #fff; opacity: .8; padding: .45rem .7rem; border-radius: 9px; font-weight: 600; }
  .deskn a.on, .deskn a:not(.btn):hover { opacity: 1; background: rgba(255,255,255,.14); }
  .deskn .btn { border: 0; margin: 0 .4rem; }
  .top-search { display: block; }
  .top-search input { background: rgba(255,255,255,.14); border: 0; color: #fff; min-height: 38px; width: 220px; border-radius: 10px; }
  .top-search input::placeholder { color: rgba(255,255,255,.7); }
  main { max-width: 860px; padding-top: 1.4rem; }
  .tiles { grid-template-columns: repeat(6, 1fr); }
  .savebar { position: static; } .savebar .btn.block { width: auto; display: inline-flex; min-width: 220px; }
  .filtergrid { grid-template-columns: repeat(4, 1fr); }
  .cell { font-size: .68rem; } .cell b { font-size: 1rem; }
  .results { grid-template-columns: repeat(4, 1fr); }
  .irow:hover, .tile:hover, .menu a:hover { background: var(--soft); }
}
@media (max-width: 359px) { .row2, .filtergrid { grid-template-columns: 1fr; } .tiles { grid-template-columns: repeat(2, 1fr); } }

@media print {
  .top, .tabs, .noprint, .flash, .savebar { display: none !important; }
  body { background: #fff; color: #000; padding: 0; } main { max-width: none; padding: 0; }
  .card { border: 0; padding: 0; }
}
