/* ESAR Stock — same tokens and look as the ESAR Logbook */
:root {
  --bg: #f4f5f7; --surface: #ffffff; --surface-2: #eef0f3; --border: #d9dde3;
  --text: #16191d; --muted: #5d6673; --accent: #b91c1c; --accent-text: #ffffff;
  --red: #dc2626; --red-bg: #fde8e8; --amber: #b45309; --amber-bg: #fef3c7; --teal: #0f766e; --teal-bg: #ccfbf1;
  --green: #15803d; --green-bg: #dcfce7; --blue: #1d4ed8; --blue-bg: #dbeafe;
  --purple: #7e22ce; --purple-bg: #f3e8ff; --gray: #4b5563; --gray-bg: #e5e7eb;
  --shadow: 0 1px 3px rgba(0,0,0,.08), 0 4px 16px rgba(0,0,0,.06);
  --radius: 10px;
  --side: var(--accent);
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #0f1216; --surface: #181c22; --surface-2: #222831; --border: #2f3640;
    --text: #e8eaed; --muted: #9aa3ae; --accent: #ef4444;
    --red: #f87171; --red-bg: #3b1515; --amber: #fbbf24; --amber-bg: #3a2c0b; --teal: #2dd4bf; --teal-bg: #0b2e2a;
    --green: #4ade80; --green-bg: #0f2e1b; --blue: #60a5fa; --blue-bg: #0f2342;
    --purple: #c084fc; --purple-bg: #2a1740; --gray: #aab2bd; --gray-bg: #2a3039;
    --shadow: 0 1px 3px rgba(0,0,0,.4);
  }
}
:root[data-theme="dark"] {
  --bg: #0f1216; --surface: #181c22; --surface-2: #222831; --border: #2f3640;
  --text: #e8eaed; --muted: #9aa3ae; --accent: #ef4444;
  --red: #f87171; --red-bg: #3b1515; --amber: #fbbf24; --amber-bg: #3a2c0b; --teal: #2dd4bf; --teal-bg: #0b2e2a;
  --green: #4ade80; --green-bg: #0f2e1b; --blue: #60a5fa; --blue-bg: #0f2342;
  --purple: #c084fc; --purple-bg: #2a1740; --gray: #aab2bd; --gray-bg: #2a3039;
  --shadow: 0 1px 3px rgba(0,0,0,.4);
}
body.s-medical { --side: var(--red); }
body.s-logistics { --side: var(--blue); }
body.s-clothing { --side: var(--teal); }
body.s-ocp { --side: var(--purple); }

* { box-sizing: border-box; }
html, body { margin: 0; background: var(--bg); color: var(--text);
  font: 15px/1.45 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif; }
a { color: var(--blue); }
button, input, select, textarea { font: inherit; color: inherit; }
.muted { color: var(--muted); }
.center { text-align: center; padding: 40px 16px; }
.small { font-size: 13px; }
.num { font-variant-numeric: tabular-nums; text-align: right; white-space: nowrap; }

/* top bar */
#topbar { position: sticky; top: 0; z-index: 20; display: flex; align-items: center; gap: 10px;
  padding: 8px 16px; background: var(--surface); border-bottom: 1px solid var(--border); min-height: 52px;
  box-shadow: inset 0 -3px 0 var(--side); }
#topbar .brand { display: flex; align-items: center; gap: 8px; font-weight: 700; text-decoration: none; color: var(--text); white-space: nowrap; }
#topbar .brand img { width: 32px; height: 32px; display: block; }
#topbar .spacer { flex: 1; }
#topbar select { padding: 4px 6px; border-radius: 6px; border: 1px solid var(--border); background: var(--surface-2); }
.sides { display: flex; gap: 4px; overflow-x: auto; scrollbar-width: none; }
.sides a { padding: 6px 12px; border-radius: 999px; text-decoration: none; color: var(--muted); white-space: nowrap; font-weight: 600; border: 1px solid transparent; }
.sides a.on { color: var(--surface); background: var(--side); }
.sides a:not(.on):hover { border-color: var(--border); }
.menu { position: relative; }
.menu-pop { position: absolute; right: 0; top: 110%; background: var(--surface); border: 1px solid var(--border); border-radius: 8px;
  box-shadow: var(--shadow); min-width: 200px; padding: 4px; display: none; z-index: 30; }
.menu-pop.open { display: block; }
.menu-pop a, .menu-pop button { display: block; width: 100%; text-align: left; padding: 8px 12px; border: 0; background: none; color: var(--text);
  text-decoration: none; border-radius: 6px; cursor: pointer; }
.menu-pop a:hover, .menu-pop button:hover { background: var(--surface-2); }
.menu-pop .who { padding: 8px 12px; color: var(--muted); font-size: 13px; border-bottom: 1px solid var(--border); margin-bottom: 4px; }

main { max-width: 1300px; margin: 0 auto; padding: 16px; }

/* buttons */
.btn { display: inline-flex; align-items: center; gap: 6px; padding: 8px 14px; border-radius: 8px;
  border: 1px solid var(--border); background: var(--surface); cursor: pointer; white-space: nowrap; text-decoration: none; color: var(--text); }
.btn:hover { background: var(--surface-2); }
.btn.primary { background: var(--accent); color: var(--accent-text); border-color: var(--accent); font-weight: 600; }
.btn.primary:hover { filter: brightness(1.08); }
.btn.danger { color: var(--red); }
.btn.sm { padding: 4px 10px; font-size: 13px; }
.btn:disabled { opacity: .5; cursor: not-allowed; }
.acts { display: flex; gap: 4px; flex-wrap: wrap; }

/* cards & layout */
.card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); box-shadow: var(--shadow); }
.card-pad { padding: 16px; }
.row { display: flex; gap: 10px; align-items: center; flex-wrap: wrap; }
.grid2 { display: grid; gap: 16px; grid-template-columns: repeat(auto-fit, minmax(380px, 1fr)); align-items: start; }
.head { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; margin-bottom: 12px; }
.head h2 { margin: 0; font-size: 20px; }
.head .spacer { flex: 1; }
h3 { margin: 0 0 10px; font-size: 15px; }
.mb { margin-bottom: 16px; }

/* tabs */
.tabs { display: flex; gap: 2px; border-bottom: 1px solid var(--border); margin: 0 0 16px; overflow-x: auto; scrollbar-width: none; }
.tabs a { padding: 10px 14px; text-decoration: none; color: var(--muted); border-bottom: 3px solid transparent; white-space: nowrap; font-weight: 500; }
.tabs a.on { color: var(--text); border-bottom-color: var(--side); }
.tabs .count { display: inline-block; min-width: 20px; padding: 0 6px; margin-left: 4px; border-radius: 10px; background: var(--red); color: #fff; font-size: 12px; text-align: center; }

/* badges */
.badge { display: inline-block; padding: 2px 8px; border-radius: 999px; font-size: 12px; font-weight: 600; white-space: nowrap; background: var(--gray-bg); color: var(--gray); }
.b-red { background: var(--red-bg); color: var(--red); }
.b-amber { background: var(--amber-bg); color: var(--amber); }
.b-green { background: var(--green-bg); color: var(--green); }
.b-blue { background: var(--blue-bg); color: var(--blue); }
.b-teal { background: var(--teal-bg); color: var(--teal); }
.b-purple { background: var(--purple-bg); color: var(--purple); }

/* stats */
.stats { display: grid; grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); gap: 12px; margin-bottom: 16px; }
.stat { padding: 14px 16px; }
.stat .n { font-size: 30px; font-weight: 700; line-height: 1.1; font-variant-numeric: tabular-nums; }
.stat .l { color: var(--muted); font-size: 13px; }
.stat.alert .n { color: var(--red); }
.stat.warn .n { color: var(--amber); }

/* tables */
.tbl-wrap { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; }
th, td { padding: 8px 10px; border-bottom: 1px solid var(--border); text-align: left; vertical-align: top; }
th { font-size: 12px; text-transform: uppercase; letter-spacing: .03em; color: var(--muted); font-weight: 600; background: var(--surface-2); }
tr.click { cursor: pointer; }
tr.click:hover td { background: var(--surface-2); }
tr.sub td { background: var(--surface-2); font-size: 14px; }
tr.off td { opacity: .55; }
td .badge + .badge { margin-left: 4px; }

/* alert lists */
.alist { list-style: none; margin: 0; padding: 0; }
.alist li { display: flex; gap: 8px; align-items: center; padding: 8px 0; border-bottom: 1px solid var(--border); flex-wrap: wrap; }
.alist li:last-child { border-bottom: 0; }
.alist .grow { flex: 1; min-width: 140px; }
.sec-title { display: flex; align-items: center; gap: 8px; font-weight: 700; margin: 0 0 6px; }
.sec-title.red { color: var(--red); } .sec-title.amber { color: var(--amber); } .sec-title.blue { color: var(--blue); }

/* forms */
.toolbar { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; margin-bottom: 12px; }
.toolbar input[type=search] { flex: 1; min-width: 180px; }
input, select, textarea { padding: 8px 10px; border: 1px solid var(--border); border-radius: 8px; background: var(--surface); width: 100%; }
textarea { min-height: 70px; resize: vertical; }
input[type=checkbox] { width: auto; }
label.f { display: block; margin-bottom: 12px; }
label.f > span { display: block; font-size: 13px; color: var(--muted); margin-bottom: 4px; font-weight: 500; }
label.chk { display: flex; gap: 8px; align-items: center; margin-bottom: 12px; cursor: pointer; }
.frow { display: grid; grid-template-columns: repeat(auto-fit, minmax(140px, 1fr)); gap: 0 12px; }
.hint { font-size: 12px; color: var(--muted); margin-top: 4px; }
.err { color: var(--red); font-weight: 600; margin: 8px 0; }
.lines .line { display: grid; grid-template-columns: 1fr 90px 80px 36px; gap: 6px; margin-bottom: 6px; }
.lines .line.nosize { grid-template-columns: 1fr 80px 36px; }

/* modal */
.modal-back { position: fixed; inset: 0; background: rgba(0,0,0,.45); z-index: 50; display: flex; align-items: flex-start; justify-content: center; padding: 40px 12px; overflow-y: auto; }
.modal { background: var(--surface); border-radius: 12px; width: 100%; max-width: 560px; box-shadow: 0 10px 40px rgba(0,0,0,.3); }
.modal.wide { max-width: 860px; }
.modal-h { display: flex; align-items: center; gap: 10px; padding: 14px 18px; border-bottom: 1px solid var(--border); border-top: 4px solid var(--side); border-radius: 12px 12px 0 0; }
.modal-h h3 { margin: 0; flex: 1; font-size: 17px; }
.modal-b { padding: 18px; }
.modal-f { display: flex; justify-content: flex-end; gap: 8px; padding: 12px 18px; border-top: 1px solid var(--border); flex-wrap: wrap; }
.modal-f .left { margin-right: auto; }
.x { background: none; border: 0; font-size: 22px; cursor: pointer; color: var(--muted); line-height: 1; }

/* toast */
#toast { position: fixed; bottom: 20px; left: 50%; transform: translateX(-50%); z-index: 80; }
#toast div { background: var(--text); color: var(--surface); padding: 10px 18px; border-radius: 8px; margin-top: 8px; box-shadow: var(--shadow); }
#toast div.e { background: var(--red); color: #fff; }

/* login */
.login { max-width: 360px; margin: 10vh auto; padding: 28px; text-align: center; }
.login img { width: 96px; height: 96px; }
.login h1 { margin: 8px 0 20px; font-size: 22px; }
.login form { text-align: left; }

/* location tree */
.tree .node { padding: 10px 12px; border-bottom: 1px solid var(--border); display: flex; gap: 10px; align-items: center; cursor: pointer; }
.tree .node:hover { background: var(--surface-2); }
.tree .node .ico { width: 24px; text-align: center; }
.tree .node .nm { flex: 1; font-weight: 500; }

.pill-sizes { display: flex; gap: 4px; flex-wrap: wrap; }
.kit-card { padding: 14px 16px; }
.kit-card + .kit-card { margin-top: 12px; }

@media (max-width: 700px) {
  #topbar { flex-wrap: wrap; }
  #topbar .brand span { display: none; }
  .sides { order: 5; width: 100%; }
  .grid2 { grid-template-columns: 1fr; }
  main { padding: 12px; }
  .hide-sm { display: none; }
  th, td { padding: 7px 6px; }
}
[hidden] { display: none !important; }
#topbar select { width: auto; }
#topbar .sides { flex: 0 1 auto; min-width: 0; }
input[type=radio] { width: auto; }
.code-in { font-size: 22px; letter-spacing: .25em; text-align: center; font-variant-numeric: tabular-nums; }
.qr { background: #fff; padding: 10px; border-radius: 8px; width: 240px; margin: 8px auto; }
.qr svg { display: block; width: 220px; height: 220px; }
.secret { display: block; margin-top: 6px; padding: 8px; background: var(--surface-2); border-radius: 6px; word-break: break-all; }
.steps { padding-left: 20px; margin: 0 0 8px; } .steps li { margin-bottom: 6px; }
.rcodes { display: grid; grid-template-columns: 1fr 1fr; gap: 6px; }
.rcodes code { padding: 6px 8px; background: var(--surface-2); border-radius: 6px; text-align: center; font-size: 15px; }
.loc-hit .node { border-bottom: 1px solid var(--border); cursor: pointer; }
.loc-hit .node:hover { background: var(--surface-2); }
.loc-hit table td { font-size: 14px; }
