:root {
  --primary: #404446;
  --accent: #DDBD5A;
  --bg: #f4f3ef;
  --card: #ffffff;
  --ink: #1f2324;
  --muted: #62686b;
  --line: #d9d7d0;
  --ok: #2e7d4f;
  --warn: #a86a00;
  --bad: #b3261e;
  --pops: #c26a00;
  --pops-bg: #fff4e5;
  --weee: #1f5fa8;
  --weee-bg: #eaf2fc;
  --stop: #b3261e;
  --stop-bg: #fdecea;
  --reuse: #2e7d4f;
  --radius: 12px;
  --tap: 52px;
}
* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0; background: var(--bg); color: var(--ink);
  font: 16px/1.45 system-ui, -apple-system, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  padding-bottom: 96px;
}
a { color: var(--primary); }
h1 { font-size: 1.35rem; margin: 0 0 .5rem; }
h2 { font-size: 1.1rem; margin: 0 0 .5rem; }
h3 { font-size: 1rem; margin: 1rem 0 .4rem; }
p { margin: .4rem 0; }
.muted { color: var(--muted); }
.small { font-size: .85rem; }
.r { text-align: right; }

.top {
  position: sticky; top: 0; z-index: 20; display: flex; align-items: center; justify-content: space-between;
  gap: 8px; padding: 10px 16px; background: var(--primary); color: #fff; border-bottom: 3px solid var(--accent);
}
.brand { color: var(--accent); font-weight: 800; text-decoration: none; letter-spacing: .02em; }
.net { font-size: .8rem; padding: 3px 10px; border-radius: 99px; }
.net.on { background: rgba(255,255,255,.14); }
.net.off { background: var(--accent); color: #1f2324; font-weight: 700; }

main { max-width: 820px; margin: 0 auto; padding: 12px 16px; }
.card { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); padding: 14px 16px; margin: 12px 0; }
.card.link { display: block; color: inherit; text-decoration: none; }
.card.link:active { background: #f7f6f2; }
.card.bad { border-color: var(--bad); }
.step.done { border-left: 6px solid var(--ok); }
.danger-card { border: 2px solid var(--stop); background: var(--stop-bg); }
.row { display: flex; align-items: center; justify-content: space-between; gap: 8px; flex-wrap: wrap; }
.grid2 { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
@media (max-width: 520px) { .grid2 { grid-template-columns: 1fr; } }

label { display: block; margin: 10px 0; font-weight: 600; font-size: .95rem; }
label.inline { display: flex; justify-content: space-between; align-items: center; gap: 8px; font-weight: 500; margin: 4px 0; }
label.inline input { width: 90px; }
input, select, textarea {
  display: block; width: 100%; margin-top: 4px; min-height: 48px; padding: 10px 12px; font: inherit; color: inherit;
  border: 1.5px solid var(--line); border-radius: 10px; background: #fff;
}
textarea { min-height: 72px; }
input[type=checkbox], input[type=radio] { display: inline-block; width: 24px; height: 24px; min-height: 0; margin: 0 8px 0 0; vertical-align: middle; accent-color: var(--primary); }
input[type=file] { padding: 10px; }
label.check { display: flex; align-items: flex-start; gap: 4px; font-weight: 500; padding: 8px 10px; border: 1px solid var(--line); border-radius: 10px; }
label.check input { flex: none; margin-top: 2px; }
label.check.pops { border-color: var(--pops); background: var(--pops-bg); }
.search { margin: 10px 0; }

.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px; min-height: var(--tap); padding: 10px 16px;
  margin: 6px 6px 0 0; border-radius: 10px; border: 1.5px solid var(--primary); background: #fff; color: var(--primary);
  font: inherit; font-weight: 700; text-decoration: none; cursor: pointer;
}
.btn.primary { background: var(--primary); color: #fff; }
.btn.danger { border-color: var(--stop); color: var(--stop); }
.btn.danger.big { background: var(--stop); color: #fff; }
.btn.big { width: 100%; min-height: 60px; font-size: 1.05rem; margin-right: 0; }
.btn.small { min-height: 36px; padding: 4px 10px; font-size: .85rem; }
.btn:disabled { opacity: .45; cursor: not-allowed; }
.btn:active:not(:disabled) { transform: translateY(1px); }
.btnrow { display: flex; flex-wrap: wrap; }
button.link { background: none; border: 0; color: var(--primary); text-decoration: underline; font: inherit; padding: 0; cursor: pointer; }

.pill { display: inline-block; padding: 2px 10px; border-radius: 99px; font-size: .8rem; font-weight: 700; background: #ecebe6; color: var(--muted); }
.pill.ok { background: #e3f3e8; color: var(--ok); }
.pill.warn { background: #fdf1d8; color: var(--warn); }
.pill.bad { background: var(--stop-bg); color: var(--bad); }

.tabs { display: flex; gap: 6px; overflow-x: auto; margin: 4px 0 8px; }
.tabs a { padding: 8px 14px; border-radius: 99px; background: #fff; border: 1px solid var(--line); text-decoration: none; color: var(--ink); white-space: nowrap; font-weight: 600; }
.tabs a.on { background: var(--primary); color: #fff; border-color: var(--primary); }

.load { border-top: 1px solid var(--line); padding: 10px 0; }
.load:first-of-type { border-top: 0; }
.note-row { border-top: 1px solid var(--line); padding: 8px 0; }

/* Tally */
.sticky { position: sticky; top: 50px; z-index: 10; background: var(--bg); padding: 8px 0; border-bottom: 1px solid var(--line); }
.totals { font-size: 1rem; margin: 4px 0 8px; }
.seg { display: grid; grid-template-columns: 1fr 1fr; gap: 6px; }
.seg button { min-height: 44px; border-radius: 10px; border: 1.5px solid var(--primary); background: #fff; color: var(--primary); font: inherit; font-weight: 700; }
.seg button.on { background: var(--primary); color: #fff; }
.seg button.on.reuse { background: var(--reuse); border-color: var(--reuse); }
.sec { margin: 14px 0; }
.sec h3 { margin: 0 0 6px; padding: 6px 10px; border-radius: 8px; background: #e9e7e0; font-size: .9rem; }
.sec.pops h3 { background: var(--pops); color: #fff; }
.sec.weee h3 { background: var(--weee); color: #fff; }
.sec.stop h3 { background: var(--stop); color: #fff; }
.tiles { display: grid; grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); gap: 8px; }
.tile { display: grid; grid-template-columns: 44px 1fr 36px; min-height: 84px; border: 2px solid var(--line); border-radius: 12px; background: #fff; overflow: hidden; }
.tile.has { border-color: var(--primary); }
.tile.pops { border-color: var(--pops); background: var(--pops-bg); }
.tile.weee { border-color: #9dbbe0; background: var(--weee-bg); }
.tile button { border: 0; background: transparent; font: inherit; color: inherit; cursor: pointer; }
.tile .minus { font-size: 1.6rem; font-weight: 800; color: var(--muted); border-right: 1px solid var(--line); }
.tile .set { font-weight: 800; color: var(--muted); border-left: 1px solid var(--line); }
.tile .plus { display: flex; flex-direction: column; align-items: flex-start; justify-content: center; padding: 6px 8px; text-align: left; }
.tile .lbl { font-weight: 700; font-size: .9rem; line-height: 1.2; }
.tile .cnt { font-size: 1.6rem; font-weight: 800; line-height: 1.1; }
.tile .unit { font-size: .72rem; color: var(--muted); }
button.tile.stop { display: flex; flex-direction: column; align-items: flex-start; justify-content: center; padding: 8px 10px; border-color: var(--stop); background: var(--stop-bg); color: var(--stop); text-align: left; font: inherit; }
.bottombar { position: fixed; left: 0; right: 0; bottom: 0; z-index: 15; padding: 10px 16px calc(10px + env(safe-area-inset-bottom)); background: rgba(244,243,239,.96); border-top: 1px solid var(--line); }
.bottombar .btn { max-width: 788px; display: flex; margin: 0 auto; }

/* Tables */
table { width: 100%; border-collapse: collapse; font-size: .92rem; }
th, td { padding: 7px 6px; border-bottom: 1px solid var(--line); text-align: left; vertical-align: top; }
th { font-size: .8rem; color: var(--muted); text-transform: uppercase; letter-spacing: .03em; }
tr.pops td { background: var(--pops-bg); }
table.streams td:first-child, table.streams th:first-child { white-space: nowrap; }
tr.sel td { background: #fff8e0; }
table.list { background: #fff; border-radius: var(--radius); overflow: hidden; }
@media (max-width: 620px) { table.list { display: block; overflow-x: auto; } }
.kv { display: grid; grid-template-columns: 130px 1fr; gap: 8px; padding: 6px 0; border-bottom: 1px solid var(--line); }
.kv span:first-child { color: var(--muted); font-weight: 600; font-size: .9rem; }
.kv.big span:last-child { font-size: 1.15rem; font-weight: 800; }

.check-item { padding: 8px 10px; border-radius: 8px; margin: 6px 0; font-weight: 600; }
.check-item.block { background: var(--stop-bg); color: var(--bad); }
.check-item.warn { background: #fdf1d8; color: var(--warn); }
.ok-text { color: var(--ok); font-weight: 700; }

.sigwrap { position: relative; margin-top: 8px; }
.sigwrap canvas { width: 100%; height: 170px; border: 2px dashed var(--line); border-radius: 10px; background: #fff; touch-action: none; display: block; }
.sigwrap .btn { position: absolute; top: 6px; right: 6px; margin: 0; }

.gate { background: #fff; border: 3px solid var(--primary); border-radius: var(--radius); padding: 14px 16px; margin: 12px 0; }
.gate-h { background: var(--primary); color: var(--accent); font-weight: 800; letter-spacing: .04em; margin: -14px -16px 10px; padding: 10px 16px; border-radius: 9px 9px 0 0; }
.pops-box { background: var(--pops-bg); border: 1px solid var(--pops); border-radius: 8px; padding: 8px 10px; }
ol.rule { padding-left: 1.2rem; font-size: 1.05rem; }
ol.rule li { margin: 4px 0; }
.survey { max-height: 360px; overflow-y: auto; padding: 4px; }
details summary { cursor: pointer; font-weight: 700; min-height: 40px; display: flex; align-items: center; }

.toast { position: fixed; left: 50%; bottom: 90px; transform: translate(-50%, 20px); opacity: 0; z-index: 50; background: #1f2324; color: #fff; padding: 12px 18px; border-radius: 10px; max-width: 90vw; transition: all .25s; font-weight: 600; }
.toast.show { opacity: 1; transform: translate(-50%, 0); }
.toast.ok { background: var(--ok); }
.toast.bad { background: var(--bad); }

/* Note screen */
.note-doc { background: #fff; border: 1px solid var(--line); border-radius: var(--radius); margin: 12px 0; padding-bottom: 8px; overflow: hidden; }
.note-doc > :not(.doc-h) { margin-left: 14px; margin-right: 14px; }
.note-doc > table { width: calc(100% - 28px); }
.doc-h { display: flex; justify-content: space-between; align-items: flex-start; gap: 12px; background: var(--primary); color: #fff; padding: 14px 16px; border-bottom: 3px solid var(--accent); }
.doc-brand { color: var(--accent); font-weight: 800; font-size: .78rem; letter-spacing: .04em; }
.doc-title { font-size: 1.15rem; font-weight: 800; text-transform: uppercase; }
.doc-no { text-align: right; font-size: .9rem; }
.doc-sec { background: var(--primary); color: #fff; font-size: .82rem; text-transform: uppercase; letter-spacing: .03em; padding: 6px 10px; border-radius: 6px; margin-top: 16px; margin-bottom: 6px; }
.doc-load { border-top: 1px solid var(--line); padding-top: 6px; margin-top: 8px; }
.sigs { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; margin-top: 6px; margin-bottom: 6px; }
@media (max-width: 520px) { .sigs { grid-template-columns: 1fr; } }
.sigbox { border: 1px solid var(--line); border-radius: 8px; padding: 8px 10px; }
.siglabel { font-size: .72rem; font-weight: 700; color: var(--muted); text-transform: uppercase; letter-spacing: .03em; }
.sigbox img { display: block; max-width: 100%; height: 64px; object-fit: contain; margin: 4px 0; }
.doc-f { border-top: 1px solid var(--line); margin-top: 16px; padding-top: 8px; font-size: .8rem; color: var(--muted); }
.fp { word-break: break-all; font-family: ui-monospace, Menlo, monospace; font-size: .72rem; }

@media print {
  .top, .tabs, .no-print, .bottombar, .toast { display: none !important; }
  body { background: #fff; padding: 0; }
  main { max-width: none; padding: 0; }
  .note-doc { border: 0; margin: 0; }
  .doc-h, .doc-sec, tr.pops td { -webkit-print-color-adjust: exact; print-color-adjust: exact; }
  .doc-load, .sigs { break-inside: avoid; }
}
.warn-card { border: 2px solid var(--warn); background: #fdf6e6; }
