:root {
  --bg: #f4f6f7; --card: #fff; --text: #14202b; --muted: #5b6b78; --line: #dde3e8;
  --accent: #0f766e; --accent-text: #fff; --good: #15803d; --bad: #b91c1c; --warn: #b45309; --chip: #e8eef1;
  --radius: 12px;
}
@media (prefers-color-scheme: dark) {
  :root { --bg: #0f1519; --card: #19222a; --text: #e8eef2; --muted: #93a4b1; --line: #2a3640;
          --accent: #2dd4bf; --accent-text: #05221f; --good: #4ade80; --bad: #f87171; --warn: #fbbf24; --chip: #243039; }
}
* { box-sizing: border-box; }
html, body { margin: 0; background: var(--bg); color: var(--text);
  font: 16px/1.4 -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif; -webkit-text-size-adjust: 100%; }
[hidden] { display: none !important; }
h1, h3 { margin: 0 0 .5rem; }
.muted { color: var(--muted); }
.error { color: var(--bad); min-height: 1.2em; margin: .5rem 0 0; }
.spacer, .grow { flex: 1; }
.row { display: flex; gap: .5rem; align-items: center; flex-wrap: wrap; }
.bar { margin-bottom: .75rem; }

input, select, textarea, button { font: inherit; color: inherit; }
input, select, textarea { background: var(--bg); border: 1px solid var(--line); border-radius: 8px; padding: .6rem .7rem; min-width: 0; width: 100%; }
.row input { width: auto; }
.row input.grow { flex: 1; width: 0; min-width: 8rem; }
input:focus, select:focus, textarea:focus { outline: 2px solid var(--accent); outline-offset: 1px; }
label { display: block; font-size: .85rem; color: var(--muted); margin-bottom: .6rem; }
label input, label select, label textarea { margin-top: .25rem; color: var(--text); }
label.check { display: flex; gap: .4rem; align-items: center; margin: 0; }
label.check input { width: auto; margin: 0; }

button { background: var(--chip); border: 1px solid var(--line); border-radius: 8px; padding: .6rem .9rem; cursor: pointer; min-height: 44px; }
button:active { transform: translateY(1px); }
button.primary { background: var(--accent); color: var(--accent-text); border-color: transparent; font-weight: 600; }
button.good { background: var(--good); color: #fff; border-color: transparent; font-weight: 600; }
button.bad { background: var(--bad); color: #fff; border-color: transparent; font-weight: 600; }
button.link { background: none; border: 0; padding: .2rem; min-height: 0; color: var(--accent); text-decoration: underline; }
button.danger { color: var(--bad); }
button:disabled { opacity: .5; }

.card { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); padding: 1rem; margin-bottom: .9rem; }
.table-card { padding: 0; overflow: hidden; }

header { display: flex; align-items: center; gap: .6rem; padding: calc(.6rem + env(safe-area-inset-top)) 1rem .6rem;
  background: var(--card); border-bottom: 1px solid var(--line); position: sticky; top: 0; z-index: 5; }
.brand { font-size: 1.05rem; }
.dot { width: .7rem; height: .7rem; border-radius: 50%; background: var(--muted); }
.dot.on { background: var(--good); } .dot.off { background: var(--bad); }
.badge { font-size: .75rem; padding: .15rem .5rem; border-radius: 99px; background: var(--chip); }
.badge.warn { color: var(--warn); border: 1px solid var(--warn); }

/* phone: tabs along the bottom */
nav#tabs { position: fixed; left: 0; right: 0; bottom: 0; z-index: 6; display: flex; background: var(--card);
  border-top: 1px solid var(--line); padding-bottom: env(safe-area-inset-bottom); }
nav#tabs button { flex: 1; border: 0; border-radius: 0; background: none; padding: .85rem .2rem; color: var(--muted); }
nav#tabs button.active { color: var(--accent); font-weight: 700; box-shadow: inset 0 3px 0 var(--accent); }
main { padding: 1rem 1rem calc(5.5rem + env(safe-area-inset-bottom)); max-width: 1100px; margin: 0 auto; }

/* PC: side navigation */
@media (min-width: 900px) {
  nav#tabs { position: fixed; top: 52px; bottom: 0; right: auto; width: 160px; flex-direction: column; border-top: 0;
    border-right: 1px solid var(--line); padding: .5rem; gap: .25rem; }
  nav#tabs button { flex: none; text-align: left; border-radius: 8px; padding: .7rem .8rem; box-shadow: none !important; }
  nav#tabs button.active { background: var(--chip); }
  main { margin-left: 160px; max-width: none; padding: 1.2rem 1.5rem; }
  #app main > .view { max-width: 1100px; }
}

#reader { width: 100%; max-width: 480px; margin: 0 auto .75rem; border-radius: 10px; overflow: hidden; }
#reader:empty { display: none; }
#reader video { border-radius: 10px; }

.tds { display: flex; gap: .5rem; align-items: center; flex-wrap: wrap; margin-top: .6rem; }
a.btn { display: inline-block; background: var(--accent); color: var(--accent-text); text-decoration: none; font-weight: 600;
  border-radius: 8px; padding: .6rem 1rem; min-height: 44px; line-height: 1.7; }
.doc a { color: var(--accent); overflow-wrap: anywhere; }
.big-stock { font-size: 3rem; font-weight: 800; line-height: 1; }
.big-stock.low { color: var(--bad); }
.sku { font-family: ui-monospace, Menlo, Consolas, monospace; font-size: .85rem; color: var(--muted); }
.qty { display: flex; align-items: center; gap: .5rem; margin: .75rem 0; }
.qty button { width: 48px; font-size: 1.3rem; padding: 0; }
.qty input { width: 4.5rem; text-align: center; font-size: 1.3rem; }
.actions { display: grid; grid-template-columns: 1fr 1fr; gap: .6rem; }
.actions button { min-height: 54px; font-size: 1.05rem; }
.grid2 { display: grid; grid-template-columns: 1fr 1fr; gap: .6rem; }
@media (max-width: 420px) { .grid2 { grid-template-columns: 1fr; } }

table { width: 100%; border-collapse: collapse; }
th, td { text-align: left; padding: .65rem .8rem; border-bottom: 1px solid var(--line); vertical-align: middle; }
th { font-size: .75rem; text-transform: uppercase; letter-spacing: .04em; color: var(--muted); background: var(--bg); }
tr.clickable { cursor: pointer; } tr.clickable:hover td { background: var(--bg); }
td.num, th.num { text-align: right; font-variant-numeric: tabular-nums; }
td.low { color: var(--bad); font-weight: 700; }
.pos { color: var(--good); } .neg { color: var(--bad); }
.swatch { display: inline-block; width: .8em; height: .8em; border-radius: 50%; background: var(--muted); margin-right: .4em; vertical-align: -1px; }
.empty { padding: 1.5rem; text-align: center; color: var(--muted); }
@media (max-width: 620px) { .hide-sm { display: none; } th, td { padding: .6rem .55rem; } }

dialog { border: 1px solid var(--line); border-radius: var(--radius); background: var(--card); color: var(--text);
  width: min(560px, calc(100vw - 1.5rem)); max-height: 92vh; padding: 1.1rem; }
dialog::backdrop { background: rgba(0, 0, 0, .5); }
.chips { display: flex; gap: .4rem; flex-wrap: wrap; margin: .25rem 0 .6rem; }
.chip { background: var(--chip); border-radius: 99px; padding: .2rem .3rem .2rem .7rem; font-family: ui-monospace, Menlo, Consolas, monospace; font-size: .85rem; }
.chip button { min-height: 0; border: 0; background: none; padding: .1rem .4rem; color: var(--muted); }

.login-card { max-width: 380px; margin: 18vh auto 0; }
#toast { position: fixed; left: 50%; transform: translateX(-50%); bottom: calc(5.5rem + env(safe-area-inset-bottom)); z-index: 20;
  background: #111; color: #fff; padding: .7rem 1.1rem; border-radius: 99px; max-width: 92vw; opacity: 0; pointer-events: none; transition: opacity .2s; }
#toast.show { opacity: .95; }
@media (min-width: 900px) { #toast { bottom: 1.5rem; } }
