:root {
  --pri: #17336b; --pri2: #0d8078; --acc: #f59e0b; --bg: #f3f5fb; --card: #fff; --ink: #0f172a; --mut: #64748b;
  --line: #e2e8f0; --ok: #16a34a; --bad: #dc2626; --warn: #d97706; --r: 16px;
  --sh: 0 1px 2px rgba(15,23,42,.06), 0 4px 16px rgba(15,23,42,.06);
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, "Noto Sans", "Noto Sans Devanagari", sans-serif;
}
* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { margin: 0; background: var(--bg); color: var(--ink); }
body { padding-bottom: calc(72px + env(safe-area-inset-bottom)); min-height: 100vh; }
a { color: var(--pri); text-decoration: none; }
h1, h2, h3 { margin: 0 0 8px; line-height: 1.2; }
h2 { font-size: 1.15rem; } h3 { font-size: 1rem; }
.muted { color: var(--mut); } .small { font-size: .82rem; } .tiny { font-size: .72rem; }
.row { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }
.between { justify-content: space-between; } .grow { flex: 1; } .right { text-align: right; }
.hidden { display: none !important; }

/* top bar */
.topbar { position: sticky; top: 0; z-index: 20; display: flex; align-items: center; gap: 10px; padding: 10px 14px;
  padding-top: calc(10px + env(safe-area-inset-top));
  background: linear-gradient(120deg, var(--pri), var(--pri2)); color: #fff; box-shadow: 0 2px 12px rgba(30,64,175,.3); }
.topbar .logo { width: 36px; height: 36px; border-radius: 10px; background: rgba(255,255,255,.18); display: grid; place-items: center;
  font-weight: 800; font-size: .85rem; overflow: hidden; flex: none; }
.topbar .logo img { width: 100%; height: 100%; object-fit: cover; }
.topbar .ttl { flex: 1; min-width: 0; }
.topbar .ttl b { display: block; font-size: .98rem; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.topbar .ttl span { font-size: .74rem; opacity: .85; }
.iconbtn { border: 0; background: rgba(255,255,255,.16); color: #fff; border-radius: 10px; height: 34px; min-width: 34px; padding: 0 10px;
  font-weight: 700; cursor: pointer; font-size: .85rem; }

/* bottom nav */
.bottomnav { position: fixed; bottom: 0; left: 0; right: 0; z-index: 20; display: flex; background: #fff; border-top: 1px solid var(--line);
  padding-bottom: env(safe-area-inset-bottom); box-shadow: 0 -4px 18px rgba(15,23,42,.06); }
.bottomnav a { flex: 1; display: flex; flex-direction: column; align-items: center; gap: 2px; padding: 8px 0 9px; color: var(--mut); font-size: .7rem; font-weight: 600; }
.bottomnav a .ic { font-size: 1.25rem; line-height: 1; filter: grayscale(.6); }
.bottomnav a.on { color: var(--pri); } .bottomnav a.on .ic { filter: none; transform: translateY(-1px); }

main { max-width: 980px; margin: 0 auto; padding: 14px; }
.card { background: var(--card); border-radius: var(--r); box-shadow: var(--sh); padding: 14px; margin-bottom: 12px; }
.card.flat { box-shadow: none; border: 1px solid var(--line); }
.hero { background: linear-gradient(135deg, #312e81, #1e40af 55%, #0ea5e9); color: #fff; position: relative; overflow: hidden; }
.hero::after { content: ""; position: absolute; right: -40px; top: -40px; width: 160px; height: 160px; border-radius: 50%; background: rgba(255,255,255,.08); }
.hero .muted { color: rgba(255,255,255,.8); }
.grid2 { display: grid; grid-template-columns: repeat(2, minmax(0,1fr)); gap: 10px; }
.grid3 { display: grid; grid-template-columns: repeat(3, minmax(0,1fr)); gap: 10px; }
@media (min-width: 760px) { .grid2.w4 { grid-template-columns: repeat(4, 1fr); } }
.stat { background: #fff; border-radius: 14px; padding: 12px; box-shadow: var(--sh); }
.stat b { display: block; font-size: 1.4rem; } .stat span { font-size: .75rem; color: var(--mut); }

.tile { display: flex; flex-direction: column; gap: 6px; background: #fff; border-radius: 14px; padding: 14px 12px; box-shadow: var(--sh); color: var(--ink); min-height: 86px; }
.tile .ic { font-size: 1.5rem; } .tile b { font-size: .9rem; } .tile span { font-size: .72rem; color: var(--mut); }

/* buttons & inputs */
.btn { border: 0; border-radius: 12px; padding: 10px 14px; font-weight: 700; font-size: .9rem; cursor: pointer; background: var(--pri); color: #fff;
  display: inline-flex; align-items: center; gap: 6px; justify-content: center; }
.btn:disabled { opacity: .45; cursor: not-allowed; }
.btn.sec { background: #e0e7ff; color: var(--pri); } .btn.ghost { background: transparent; color: var(--pri); border: 1.5px solid #c7d2fe; }
.btn.ok { background: var(--ok); } .btn.bad { background: var(--bad); } .btn.warn { background: var(--warn); }
.btn.sm { padding: 6px 10px; font-size: .8rem; border-radius: 10px; } .btn.block { width: 100%; }
input, select, textarea { font: inherit; font-size: 16px; border: 1.5px solid var(--line); border-radius: 12px; padding: 10px 12px; background: #fff; color: var(--ink); width: 100%; }
input:focus, select:focus, textarea:focus { outline: none; border-color: #818cf8; box-shadow: 0 0 0 3px #e0e7ff; }
label.f { display: block; font-size: .78rem; font-weight: 600; color: var(--mut); margin: 8px 0 4px; }
.fields { display: grid; grid-template-columns: repeat(auto-fit, minmax(200px, 1fr)); gap: 0 12px; }
select.inline { width: auto; padding: 7px 10px; font-size: .9rem; }
.check { display: flex; gap: 8px; align-items: center; font-size: .9rem; margin: 8px 0; } .check input { width: auto; }

/* chips */
.chip { display: inline-flex; align-items: center; gap: 4px; padding: 3px 9px; border-radius: 999px; font-size: .72rem; font-weight: 700; background: #eef2ff; color: var(--pri); white-space: nowrap; }
.st-draft { background: #f1f5f9; color: #475569; } .st-submitted { background: #e0f2fe; color: #0369a1; }
.st-reviewed { background: #ede9fe; color: #6d28d9; } .st-approved { background: #fef3c7; color: #b45309; }
.st-final { background: #dcfce7; color: #15803d; } .st-returned { background: #fee2e2; color: #b91c1c; }
.res-PASS { color: var(--ok); font-weight: 700; } .res-FAIL { color: var(--bad); font-weight: 700; } .res-COMPARTMENT { color: var(--warn); font-weight: 700; }

.bar { height: 8px; background: #e2e8f0; border-radius: 99px; overflow: hidden; }
.bar > i { display: block; height: 100%; background: linear-gradient(90deg, #22c55e, #16a34a); border-radius: 99px; }
.bar.blue > i { background: linear-gradient(90deg, #6366f1, #1e40af); }

/* tables */
.tw { overflow-x: auto; border-radius: 12px; border: 1px solid var(--line); background: #fff; }
table.t { border-collapse: collapse; width: 100%; font-size: .86rem; }
table.t th, table.t td { padding: 8px 9px; border-bottom: 1px solid var(--line); text-align: left; white-space: nowrap; }
table.t th { background: #f8fafc; font-size: .74rem; color: var(--mut); text-transform: uppercase; letter-spacing: .02em; position: sticky; top: 0; }
table.t td.num, table.t th.num { text-align: center; }
table.t tr:last-child td { border-bottom: 0; }
table.t tr.click { cursor: pointer; } table.t tr.click:hover td { background: #f8fafc; }

/* entry grid */
.grid-wrap { overflow: auto; max-height: calc(100vh - 290px); border-radius: 12px; border: 1px solid var(--line); background: #fff; }
table.g { border-collapse: separate; border-spacing: 0; width: 100%; font-size: .9rem; }
table.g th { position: sticky; top: 0; background: #eef2ff; color: #3730a3; font-size: .74rem; padding: 8px 6px; z-index: 2; text-align: center; }
table.g td { border-bottom: 1px solid var(--line); padding: 4px 5px; text-align: center; }
table.g td.nm { text-align: left; position: sticky; left: 0; background: #fff; z-index: 1; max-width: 150px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
table.g th.nm { left: 0; z-index: 3; text-align: left; }
table.g input.cell { width: 64px; text-align: center; padding: 8px 4px; border-radius: 9px; font-weight: 700; }
table.g input.cell.bad { border-color: var(--bad); background: #fef2f2; color: var(--bad); }
table.g input.cell.code { background: #fffbeb; color: #b45309; }
table.g input.cell:disabled { background: #f8fafc; color: #334155; border-color: transparent; }
.codes { position: sticky; bottom: calc(66px + env(safe-area-inset-bottom)); display: flex; gap: 6px; padding: 8px; background: rgba(255,255,255,.95);
  border-radius: 14px; box-shadow: var(--sh); margin-top: 10px; z-index: 5; flex-wrap: wrap; }
.saved { font-size: .75rem; color: var(--ok); font-weight: 700; }

.timeline { list-style: none; margin: 0; padding: 0; }
.timeline li { padding: 6px 0 6px 18px; position: relative; font-size: .84rem; border-left: 2px solid #e2e8f0; margin-left: 6px; }
.timeline li::before { content: ""; position: absolute; left: -6px; top: 10px; width: 10px; height: 10px; border-radius: 50%; background: var(--pri2); }

.tabs { display: flex; gap: 6px; overflow-x: auto; padding-bottom: 6px; margin-bottom: 8px; scrollbar-width: none; }
.tabs a { padding: 8px 12px; border-radius: 999px; background: #fff; color: var(--mut); font-weight: 700; font-size: .82rem; white-space: nowrap; box-shadow: var(--sh); }
.tabs a.on { background: var(--pri); color: #fff; }

/* login */
.login { min-height: 100vh; display: flex; flex-direction: column; justify-content: center; padding: 20px; max-width: 460px; margin: 0 auto; }
.login .brand { text-align: center; margin-bottom: 18px; }
.login .brand .big { width: 74px; height: 74px; border-radius: 22px; margin: 0 auto 10px; display: grid; place-items: center; font-size: 2.2rem;
  background: linear-gradient(135deg, #6366f1, #1e40af); box-shadow: 0 10px 30px rgba(79,70,229,.35); }
.demo-list { display: grid; grid-template-columns: 1fr 1fr; gap: 6px; }
.demo-list button { border: 1px solid var(--line); background: #fff; border-radius: 12px; padding: 8px; text-align: left; cursor: pointer; font-size: .78rem; }
.demo-list button b { display: block; font-size: .8rem; color: var(--ink); }

/* modal & toast */
.modal-bg { position: fixed; inset: 0; background: rgba(15,23,42,.45); z-index: 50; display: flex; align-items: flex-end; justify-content: center; }
.modal { background: #fff; width: 100%; max-width: 560px; max-height: 88vh; overflow: auto; border-radius: 20px 20px 0 0; padding: 18px; animation: up .18s ease-out; }
@media (min-width: 700px) { .modal-bg { align-items: center; } .modal { border-radius: 20px; } }
@keyframes up { from { transform: translateY(30px); opacity: 0; } to { transform: none; opacity: 1; } }
.toast { position: fixed; left: 50%; bottom: calc(84px + env(safe-area-inset-bottom)); transform: translateX(-50%); background: #0f172a; color: #fff;
  padding: 10px 16px; border-radius: 12px; font-size: .88rem; z-index: 60; box-shadow: 0 8px 24px rgba(0,0,0,.25); max-width: 90vw; }
.progress-ov { position: fixed; inset: 0; background: rgba(255,255,255,.85); z-index: 55; display: grid; place-items: center; text-align: center; }
canvas.chart { width: 100%; height: 190px; display: block; }
.empty { text-align: center; padding: 26px 10px; color: var(--mut); } .empty .ic { font-size: 2rem; }
.conflict td { background: #fff7ed; }
@media print { .topbar, .bottomnav, .codes, .btn { display: none !important; } body { padding: 0; background: #fff; } .card { box-shadow: none; } }

/* v2 additions */
.pgrid { display: grid; grid-template-columns: repeat(auto-fill, minmax(140px, 1fr)); gap: 6px 10px; margin-top: 10px; }
.pg { display: flex; align-items: center; justify-content: space-between; gap: 6px; min-width: 0; font-size: .72rem; font-weight: 600; color: var(--mut);
  background: #f8fafc; border: 1px solid var(--line); border-radius: 10px; padding: 4px 4px 4px 8px; }
.pg span { flex: 1; min-width: 0; line-height: 1.15; overflow-wrap: anywhere; }
.pg select { flex: none; width: 62px; min-width: 0; padding: 4px 4px; }
.failtxt, .failtxt b { color: var(--bad) !important; }
.design-pick { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.design-pick label { border: 2px solid var(--line); border-radius: 14px; padding: 10px; cursor: pointer; display: block; }
.design-pick label.on { border-color: var(--pri); background: #eef2ff; }
.design-pick .sw { height: 54px; border-radius: 8px; margin-bottom: 6px; }
.sw.classic { background: linear-gradient(90deg, #f2b134 0 20%, #f4c7a8 20% 45%, #c8dcab 45% 70%, #ffd92f 70%); }
.sw.modern { background: linear-gradient(180deg, #11264a 0 30%, #f4f6fa 30%); border: 1px solid var(--line); }
.thumb { width: 64px; height: 40px; object-fit: contain; background: #fff; border: 1px solid var(--line); border-radius: 8px; }

/* v3 compartment / retest */
.chip.st-rt { background: #fff1f2; color: #be123c; border: 1px solid #fecdd3; }
table.g input.cell.carry { color: #94a3b8; font-style: italic; background: #f8fafc; }
table.g td.orig { font-size: .8rem; font-weight: 700; text-align: center; }
.rt-head { border-left: 4px solid #be123c; }
.rt-card { border-left: 4px solid #fda4af; }
.rt-routine input, .rt-routine select { min-width: 0; }
.rt-routine td { vertical-align: top; }
.rt-routine .cls-pick { display: flex; flex-wrap: wrap; gap: 4px 10px; max-width: 260px; }
.rt-routine .cls-pick label { display: inline-flex; align-items: center; gap: 3px; font-size: .78rem; white-space: nowrap; }
.rt-routine .cls-pick input { width: auto; }
.res-Eligible { color: var(--warn); font-weight: 700; } .res-Failed { color: var(--bad); font-weight: 700; }
/* v4: live sync chip, demo banner, staff screen */
.syncchip { border: 0; background: rgba(255,255,255,.16); color: #fff; border-radius: 999px; height: 30px; padding: 0 10px; font-size: .72rem; font-weight: 600;
  display: inline-flex; align-items: center; gap: 6px; white-space: nowrap; max-width: 46vw; overflow: hidden; text-overflow: ellipsis; cursor: pointer; }
.syncchip .dot { width: 8px; height: 8px; border-radius: 50%; background: #94a3b8; flex: none; }
.syncchip .dot.ok { background: #4ade80; } .syncchip .dot.off { background: #fbbf24; } .syncchip .dot.bad { background: #f87171; }
.syncchip .dot.sy { background: #60a5fa; animation: syncpulse 1s infinite alternate; }
@keyframes syncpulse { from { opacity: .35; } to { opacity: 1; } }
.demobar { background: #fef3c7; color: #78350f; font-size: .78rem; padding: 7px 12px; display: flex; gap: 8px; align-items: center; flex-wrap: wrap; justify-content: center; text-align: center; }
.demobar .btn { padding: 4px 10px; }
.allot-grid { max-height: 46vh; overflow: auto; border: 1px solid var(--line); border-radius: 12px; padding: 6px 10px; margin-top: 6px; }
.allot-grid .cls { padding: 6px 0; border-top: 1px solid var(--line); } .allot-grid .cls:first-child { border-top: 0; }
.allot-grid label { display: inline-flex; align-items: center; gap: 4px; margin: 3px 10px 3px 0; font-size: .82rem; }
.allot-grid label input { width: auto; }
.allot-grid .taken { color: var(--mut); font-size: .7rem; }
.needroll { background: #fff7ed; }
@media (max-width: 380px) { .syncchip { max-width: 38vw; } }
