:root {
  --brand: #7c252d; --brand-dark: #5a1a20; --brand-tint: #f8eced;
  --ink: #222021; --bg: #f4f2f1; --card: #fff; --line: #e2dedc; --muted: #6b6563;
  --red: #c41e1e; --red-tint: #fdeaea; --green: #2e7d4f; --amber: #a86a00; --blue: #245c9e;
  --radius: 12px; --safe-top: env(safe-area-inset-top); --safe-bottom: env(safe-area-inset-bottom);
  color-scheme: light;
}
* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body { margin: 0; font: 16px/1.4 "Segoe UI", system-ui, -apple-system, Roboto, sans-serif; color: var(--ink); background: var(--bg); }
a { color: var(--brand); }
h1, h2, h3 { margin: 0 0 .4em; line-height: 1.2; }
h2 { font-size: 1.25rem; } h3 { font-size: 1.05rem; }
p { margin: .4em 0; }
.muted { color: var(--muted); } .small { font-size: .85rem; } .center { text-align: center; } .red { color: var(--red); }
[hidden] { display: none !important; }

/* shell */
#topbar { position: sticky; top: 0; z-index: 10; display: flex; align-items: center; gap: 4px;
  padding: calc(var(--safe-top) + 6px) 8px 6px; background: var(--brand); color: #fff; }
#topbar h1 { flex: 1; font-size: 1.1rem; margin: 0 4px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.iconbtn { position: relative; background: none; border: 0; color: inherit; font-size: 1.8rem; line-height: 1; width: 44px; height: 44px;
  display: grid; place-items: center; border-radius: 50%; cursor: pointer; }
.iconbtn:active { background: rgba(255,255,255,.15); }
.badge { position: absolute; top: 4px; right: 2px; min-width: 18px; height: 18px; padding: 0 4px; border-radius: 9px;
  background: #fff; color: var(--brand); font: 700 11px/18px system-ui; text-align: center; }
main { max-width: 760px; margin: 0 auto; padding: 12px 16px calc(84px + var(--safe-bottom)); }
#bottomnav { position: fixed; bottom: 0; left: 0; right: 0; z-index: 10; display: flex; background: #fff;
  border-top: 1px solid var(--line); padding-bottom: var(--safe-bottom); }
#bottomnav a { flex: 1; display: flex; flex-direction: column; align-items: center; padding: 6px 0 8px; font-size: .72rem;
  color: var(--muted); text-decoration: none; }
#bottomnav a span { font-size: 1.3rem; line-height: 1.3; }
#bottomnav a.on { color: var(--brand); font-weight: 600; }

/* building blocks */
.card { display: block; background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); padding: 14px;
  margin: 0 0 10px; color: inherit; text-decoration: none; }
a.card:active { background: #faf8f7; }
.card.error { border-color: var(--red); }
.card.link b { display: block; }
.row { display: flex; align-items: center; justify-content: space-between; gap: 8px; }
.row.gap { justify-content: flex-start; flex-wrap: wrap; margin-bottom: 6px; }
.meta { display: flex; flex-wrap: wrap; gap: 4px 12px; color: var(--muted); font-size: .88rem; margin-top: 4px; }
.wo .t { margin-top: 2px; font-weight: 500; }
.card.em { border: 2px solid var(--red); background: var(--red-tint); }
.empty { text-align: center; color: var(--muted); padding: 32px 12px; }
.loading { display: grid; place-items: center; padding: 60px; }
.spin { width: 28px; height: 28px; border: 3px solid var(--line); border-top-color: var(--brand); border-radius: 50%; animation: spin .8s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }

.btn { display: inline-flex; align-items: center; justify-content: center; gap: 6px; min-height: 44px; padding: 10px 16px;
  border-radius: 10px; border: 1px solid var(--line); background: #fff; color: var(--ink); font-family: inherit; font-size: 1rem; font-weight: 600; line-height: 1.2;
  text-decoration: none; cursor: pointer; text-align: center; }
.btn.primary { background: var(--brand); border-color: var(--brand); color: #fff; }
.btn.primary:active { background: var(--brand-dark); }
.btn.danger { background: var(--red); border-color: var(--red); color: #fff; }
.btn.white { background: #fff; color: var(--red); border-color: #fff; }
.btn.ghost { background: transparent; color: var(--muted); }
.btn.big { min-height: 54px; font-size: 1.05rem; width: 100%; }
.btn:disabled { opacity: .5; cursor: default; }
.btn.busy { position: relative; color: transparent !important; }
.btn.busy::after { content: ""; position: absolute; width: 20px; height: 20px; border: 3px solid rgba(0,0,0,.15); border-top-color: currentColor;
  border-radius: 50%; animation: spin .8s linear infinite; color: var(--ink); }
.btn.primary.busy::after, .btn.danger.busy::after { border-color: rgba(255,255,255,.35); border-top-color: #fff; }
.link { background: none; border: 0; color: var(--brand); font: inherit; text-decoration: underline; cursor: pointer; padding: 4px; }
.actions { display: flex; flex-wrap: wrap; gap: 8px; margin: 0 0 10px; }
.actions .btn { flex: 1 1 140px; }
.card .actions { margin: 10px 0 0; }

.pill { display: inline-block; padding: 2px 10px; border-radius: 999px; font-size: .78rem; font-weight: 600; white-space: nowrap; background: #eee; }
.s-new { background: #e8eef7; color: var(--blue); } .s-assigned { background: #eceaf6; color: #4b3f99; }
.s-progress { background: #fff3dc; color: var(--amber); } .s-waiting { background: #fde9d9; color: #a3480b; }
.s-done { background: #e3f2e8; color: var(--green); } .s-canceled { background: #eee; color: #777; } .s-pm { background: var(--brand-tint); color: var(--brand); }
.pri { font-size: .82rem; font-weight: 600; } .p-high { color: var(--red); } .p-medium { color: var(--amber); } .p-low { color: var(--muted); }

.chips { display: flex; gap: 6px; overflow-x: auto; margin: 0 0 10px; padding-bottom: 2px; scrollbar-width: none; }
.chip { flex: none; padding: 8px 14px; border-radius: 999px; border: 1px solid var(--line); background: #fff; color: var(--ink);
  text-decoration: none; font-family: inherit; font-size: .9rem; font-weight: 500; cursor: pointer; }
.chip.on { background: var(--brand); border-color: var(--brand); color: #fff; }

/* forms */
label { display: block; margin: 0 0 12px; font-size: .9rem; font-weight: 600; color: #3a3637; }
input, select, textarea { display: block; width: 100%; margin-top: 4px; padding: 11px 12px; font-family: inherit; font-size: 1rem; font-weight: 400; color: var(--ink);
  background: #fff; border: 1px solid #cfc9c6; border-radius: 10px; min-height: 46px; }
textarea { resize: vertical; }
input:focus, select:focus, textarea:focus { outline: 2px solid var(--brand); outline-offset: -1px; border-color: var(--brand); }
fieldset { border: 0; margin: 0; padding: 0; min-width: 0; }
fieldset:disabled input, fieldset:disabled select, fieldset:disabled textarea { background: #f7f5f4; }
label.check { display: flex; gap: 10px; align-items: flex-start; font-weight: 500; }
label.check input { width: 22px; height: 22px; min-height: 0; margin: 0; flex: none; accent-color: var(--brand); }
.grid2 { display: grid; grid-template-columns: 1fr 1fr; gap: 0 10px; }
.search { margin: 0 0 10px; display: flex; gap: 8px; }
.search input, .search select, input.search { margin: 0; }
form.inline { display: flex; gap: 8px; margin: 0 0 8px; }
form.inline input { margin: 0; }
form.inline .btn { flex: none; }

/* home */
.hello { display: flex; justify-content: space-between; align-items: center; gap: 10px; margin: 4px 0 12px; }
.hello h2 { margin: 0; }
.plantsel { width: auto; max-width: 48%; margin: 0; }
.tiles { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.tile { display: flex; flex-direction: column; min-height: 104px; padding: 14px; background: #fff; border: 1px solid var(--line);
  border-radius: var(--radius); color: var(--ink); text-decoration: none; }
.tile .n { font-size: 1.8rem; font-weight: 700; color: var(--brand); line-height: 1.1; min-height: 1.1em; }
.tile .l { font-weight: 600; margin-top: auto; } .tile .s { font-size: .8rem; color: var(--muted); }
.tile.warn .n { color: var(--red); }
.emcard { display: flex; flex-direction: column; gap: 2px; padding: 14px; margin: 0 0 10px; border-radius: var(--radius);
  background: var(--red); color: #fff; text-decoration: none; animation: pulse 2s ease-in-out infinite; }
.emcard b { font-size: 1.05rem; } .emcard .who { font-weight: 600; }
@keyframes pulse { 50% { box-shadow: 0 0 0 6px rgba(196,30,30,.25); } }
@media (prefers-reduced-motion: reduce) { .emcard { animation: none; } }

/* details */
.embanner { display: flex; flex-direction: column; gap: 4px; padding: 14px; margin: 0 0 10px; border-radius: var(--radius); background: var(--red); color: #fff; }
.embanner p { margin: 4px 0; } .embanner .btn { margin-top: 8px; }
.scanned { background: #e3f2e8; color: var(--green); font-weight: 600; padding: 8px 12px; border-radius: 10px; margin: 0 0 10px; }
.desc { white-space: pre-wrap; margin: 8px 0; }
.fields { display: grid; grid-template-columns: 1fr 1fr; gap: 10px 14px; margin-top: 10px; }
.fields.done { border-top: 1px solid var(--line); padding-top: 10px; }
.f span { display: block; font-size: .78rem; color: var(--muted); } .f b { font-weight: 600; } .f.wide { grid-column: 1 / -1; }
.f p { margin: 2px 0; white-space: pre-wrap; }
.photos { display: grid; grid-template-columns: repeat(auto-fill, minmax(100px, 1fr)); gap: 8px; margin-bottom: 10px; }
.ph { display: block; text-decoration: none; color: var(--muted); font-size: .75rem; }
.ph img { width: 100%; aspect-ratio: 1; object-fit: cover; border-radius: 8px; background: #eee; display: block; }
.photoform { display: grid; grid-template-columns: 110px 1fr; gap: 8px; }
.photoform select, .photoform input { margin: 0; }
.photoform .filebtn { grid-column: 1 / -1; margin: 0; }

/* emergency form */
.reasons { display: grid; gap: 8px; margin: 0 0 12px; }
.reason { text-align: left; padding: 12px 14px; border: 2px solid var(--line); border-radius: 10px; background: #fff; font: inherit; cursor: pointer; }
.reason b { display: block; } .reason span { color: var(--muted); font-size: .88rem; }
.reason.on { border-color: var(--red); background: var(--red-tint); }

/* scan */
.scanbox { position: relative; overflow: hidden; border-radius: var(--radius); background: #000; aspect-ratio: 3 / 4; max-height: 62vh; margin: 0 auto 10px; }
.scanbox video { width: 100%; height: 100%; object-fit: cover; display: block; }
.frame { position: absolute; inset: 18%; border: 3px solid rgba(255,255,255,.9); border-radius: 16px; box-shadow: 0 0 0 999px rgba(0,0,0,.35); }

/* notifications */
.note.unread { border-left: 4px solid var(--brand); font-weight: 600; }
.note.unread .muted { font-weight: 400; }

/* login */
.login { max-width: 380px; margin: 0 auto; padding: calc(var(--safe-top) + 40px) 4px 20px; text-align: center; }
.login .logo { width: 220px; max-width: 70%; margin-bottom: 8px; }
.login h1 { color: var(--brand); font-size: 1.4rem; margin-bottom: 18px; }
.login form { display: grid; gap: 12px; margin: 16px 0; }
.login input { margin: 0; text-align: center; font-size: 1.15rem; }
.login input.code { letter-spacing: .4em; font-size: 1.5rem; }
.devnote { margin-top: 24px; padding: 8px; background: #fff3dc; border-radius: 8px; font-size: .85rem; }

.toast { position: fixed; left: 50%; bottom: calc(80px + var(--safe-bottom)); transform: translate(-50%, 20px); opacity: 0; pointer-events: none;
  max-width: calc(100% - 32px); width: max-content; padding: 12px 18px; border-radius: 10px; background: #222; color: #fff; z-index: 50;
  transition: .2s; font-weight: 500; }
.toast.show { opacity: 1; transform: translate(-50%, 0); }
.toast.err { background: var(--red); }

/* QR labels: Avery 5163, letter, 2 x 5 labels of 4" x 2", top margin .5", side .156" */
.checks { max-height: 320px; overflow: auto; margin-top: 10px; border-top: 1px solid var(--line); padding-top: 10px; }
.sheet .page { background: #fff; width: 8.5in; height: 11in; padding: .5in .156in; display: grid;
  grid-template-columns: 4in 4in; grid-auto-rows: 2in; column-gap: .1875in; margin: 0 auto 16px; box-shadow: 0 1px 6px rgba(0,0,0,.15);
  transform-origin: top left; }
.label { display: flex; align-items: center; gap: .12in; padding: .14in .16in; overflow: hidden; }
.label .qr { width: 1.6in; height: 1.6in; flex: none; } .label .qr svg { width: 100%; height: 100%; display: block; }
.label .txt { display: flex; flex-direction: column; min-width: 0; font-size: 10pt; line-height: 1.25; }
.label .txt img { width: 1.1in; margin-bottom: 4px; } .label .txt b { font-size: 13pt; line-height: 1.15; }
.label .txt small { margin-top: 4px; font-size: 7.5pt; color: #555; }
@media screen and (max-width: 860px) { .sheet { overflow-x: auto; } .sheet .page { zoom: .42; } }
@media print {
  @page { size: letter; margin: 0; }
  body { background: #fff; }
  #topbar, #bottomnav, .noprint, .toast { display: none !important; }
  main { padding: 0; max-width: none; }
  .sheet .page { box-shadow: none; margin: 0; zoom: 1; page-break-after: always; }
}
@media (min-width: 700px) { .tiles { grid-template-columns: repeat(3, 1fr); } }
