:root {
  --red: #A6192E;
  --red-dark: #7f1222;
  --gold: #C9A227;
  --ink: #1f1f22;
  --muted: #6b6b70;
  --line: #d9d9de;
  --band: #ededf0;
  --bg: #f6f6f8;
  --card: #ffffff;
  --ok: #1f8a4c;
  --warn: #b26a00;
  --radius: 12px;
  --tap: 48px;
}
* { box-sizing: border-box; }
[hidden] { display: none !important; }
html, body { margin: 0; height: 100%; }
body {
  font: 16px/1.4 -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  color: var(--ink); background: var(--bg);
  -webkit-text-size-adjust: 100%; -webkit-tap-highlight-color: transparent;
  padding-top: env(safe-area-inset-top);
}
button, input, textarea, select { font: inherit; }
h1, h2, h3 { margin: 0 0 .5em; line-height: 1.2; }
h1 { font-size: 1.5rem; } h2 { font-size: 1.2rem; } h3 { font-size: 1rem; }
a { color: var(--red); }

.topbar {
  position: sticky; top: 0; z-index: 10; background: #fff; border-bottom: 1px solid var(--line);
  display: flex; align-items: center; justify-content: space-between; padding: 8px 16px; gap: 12px;
}
.brand img { height: 34px; display: block; }
.topbar-right { display: flex; align-items: center; gap: 10px; }
.who { color: var(--muted); font-size: .9rem; }
.who a { color: var(--ink); text-decoration: none; font-weight: 600; }
.badge-row:empty { display: none; }
.pill { font-size: .75rem; padding: 3px 9px; border-radius: 999px; background: var(--band); color: var(--muted); white-space: nowrap; }
.pill.online { background: #e3f4ea; color: var(--ok); }
.pill.offline { background: #fdecec; color: var(--red); }
.pill.syncing { background: #fff4df; color: var(--warn); }

.view { max-width: 1040px; margin: 0 auto; padding: 16px; padding-bottom: 96px; }

.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  min-height: var(--tap); padding: 0 18px; border-radius: 10px; border: 1px solid var(--line);
  background: #fff; color: var(--ink); cursor: pointer; font-weight: 600; text-decoration: none;
}
.btn:active { transform: scale(.98); }
.btn-primary { background: var(--red); border-color: var(--red); color: #fff; }
.btn-primary:disabled { opacity: .5; }
.btn-ghost { background: transparent; border-color: transparent; color: var(--muted); }
.btn-sm { min-height: 36px; padding: 0 12px; font-size: .9rem; }
.btn-block { width: 100%; }
.btn-row { display: flex; flex-wrap: wrap; gap: 10px; margin: 12px 0; }

.card { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); padding: 16px; margin-bottom: 14px; }
.field { display: flex; flex-direction: column; gap: 4px; margin-bottom: 12px; }
.field label { font-size: .85rem; color: var(--muted); font-weight: 600; }
.field input, .field textarea, .field select {
  min-height: var(--tap); padding: 10px 12px; border: 1px solid var(--line); border-radius: 10px; background: #fff; width: 100%;
}
.field textarea { min-height: 72px; resize: vertical; }
.grid-2 { display: grid; grid-template-columns: 1fr 1fr; gap: 0 16px; }
@media (max-width: 640px) { .grid-2 { grid-template-columns: 1fr; } }

/* login */
.login { max-width: 400px; margin: 48px auto; }
.error { color: var(--red); font-size: .9rem; margin: 6px 0; }

/* dashboard */
.toolbar { display: flex; flex-wrap: wrap; gap: 10px; align-items: center; margin-bottom: 14px; }
.toolbar input[type=search] { flex: 1 1 220px; min-height: var(--tap); padding: 0 12px; border: 1px solid var(--line); border-radius: 10px; }
.chips { display: flex; gap: 8px; flex-wrap: wrap; }
.chip { min-height: 36px; padding: 0 12px; border-radius: 999px; border: 1px solid var(--line); background: #fff; cursor: pointer; font-size: .9rem; }
.chip.active { background: var(--ink); color: #fff; border-color: var(--ink); }
.stats { display: grid; grid-template-columns: repeat(4, 1fr); gap: 10px; margin-bottom: 14px; }
@media (max-width: 640px) { .stats { grid-template-columns: repeat(2, 1fr); } }
.stat { background: #fff; border: 1px solid var(--line); border-radius: var(--radius); padding: 12px; }
.stat .n { font-size: 1.6rem; font-weight: 700; }
.stat .l { font-size: .8rem; color: var(--muted); }
.list { display: flex; flex-direction: column; gap: 10px; }
.row {
  display: grid; grid-template-columns: 1fr auto; gap: 6px 12px; align-items: center;
  background: #fff; border: 1px solid var(--line); border-radius: var(--radius); padding: 14px 16px; cursor: pointer;
}
.row .t { font-weight: 700; }
.row .s { color: var(--muted); font-size: .9rem; }
.badge { font-size: .75rem; padding: 4px 10px; border-radius: 999px; font-weight: 700; white-space: nowrap; }
.badge.draft { background: var(--band); color: var(--muted); }
.badge.presentation { background: #fff4df; color: var(--warn); }
.badge.final { background: #e6effa; color: #1d4e89; }
.badge.closed { background: #e3f4ea; color: var(--ok); }
.badge.dirty { background: #fdecec; color: var(--red); }
.empty { text-align: center; color: var(--muted); padding: 40px 0; }

/* HOP form */
.hop-head { display: flex; flex-wrap: wrap; justify-content: space-between; align-items: center; gap: 8px; margin-bottom: 10px; }
.hop-head .sub { color: var(--muted); font-size: .9rem; }
.steps { display: flex; gap: 8px; overflow-x: auto; padding: 4px 0 10px; -webkit-overflow-scrolling: touch; scrollbar-width: none; }
.steps::-webkit-scrollbar { display: none; }
.step-tab {
  flex: 0 0 auto; min-height: 40px; padding: 0 14px; border-radius: 999px; border: 1px solid var(--line);
  background: #fff; cursor: pointer; font-size: .9rem; display: inline-flex; align-items: center; gap: 6px;
}
.step-tab.active { background: var(--red); border-color: var(--red); color: #fff; }
.step-tab .dot { width: 8px; height: 8px; border-radius: 50%; background: var(--line); }
.step-tab .dot.done { background: var(--ok); }
.step-tab.active .dot.done { background: #fff; }
.step-title { display: flex; align-items: baseline; gap: 12px; margin: 8px 0 6px; }
.step-title .num { color: var(--red); font-weight: 800; font-size: 1.4rem; letter-spacing: .02em; }
.instruction { color: var(--muted); font-size: .85rem; margin-bottom: 10px; }
.group-title { font-weight: 700; margin: 14px 0 6px; font-size: .9rem; text-transform: uppercase; letter-spacing: .04em; color: var(--muted); }

.item { display: grid; grid-template-columns: 112px 1fr; gap: 8px 12px; align-items: start; padding: 10px 0; border-top: 1px solid var(--line); }
.item:first-of-type { border-top: 0; }
.item .label { font-weight: 600; padding-top: 12px; }
.item .label small { display: block; color: var(--muted); font-weight: 400; font-size: .8rem; }
.item .extra { grid-column: 1 / -1; }
.item textarea { width: 100%; min-height: 56px; padding: 8px 10px; border: 1px solid var(--line); border-radius: 8px; }
.ini {
  min-height: var(--tap); width: 112px; border-radius: 10px; border: 2px dashed var(--line); background: #fff;
  color: var(--muted); font-weight: 700; cursor: pointer; display: flex; flex-direction: column; align-items: center; justify-content: center; line-height: 1.1;
}
.ini.done { border: 2px solid var(--red); color: var(--red); background: #fff7f8; }
.ini small { font-size: .65rem; font-weight: 500; color: var(--muted); }
.ini-imgs { display: flex; gap: 2px; align-items: center; justify-content: center; }
.ini-imgs img { height: 26px; max-width: 52px; object-fit: contain; }
.ini-pair .ini-imgs img { max-width: 60px; }
.ini-img { height: 48px !important; }
.ini-pair { display: flex; gap: 6px; }
.ini-pair .ini { width: 76px; }
.check { display: inline-flex; align-items: center; gap: 8px; min-height: 40px; cursor: pointer; }
.check input { width: 22px; height: 22px; }
.clause { display: grid; grid-template-columns: auto 1fr; gap: 12px; padding: 10px 0; border-top: 1px solid var(--line); font-size: .92rem; }
.clause:first-of-type { border-top: 0; }

.sig-block { border-top: 1px solid var(--line); padding: 12px 0; display: grid; grid-template-columns: 1fr auto; gap: 10px; align-items: center; }
.sig-block .img { height: 56px; max-width: 260px; display: block; }
.sig-block .meta { color: var(--muted); font-size: .8rem; }
.statement { font-size: .9rem; margin: 8px 0 12px; }

.punch-row { display: grid; grid-template-columns: 1fr auto; gap: 10px; padding: 10px 0; border-top: 1px solid var(--line); align-items: start; }
.punch-row:first-of-type { border-top: 0; }
.punch-row textarea { width: 100%; min-height: 56px; padding: 8px 10px; border: 1px solid var(--line); border-radius: 8px; }

.footer-nav { position: fixed; left: 0; right: 0; bottom: 0; background: #fff; border-top: 1px solid var(--line); padding: 10px 16px calc(10px + env(safe-area-inset-bottom)); display: flex; justify-content: space-between; gap: 10px; z-index: 9; }
.footer-nav .btn { flex: 1; }

/* modal + signature pad */
.modal { position: fixed; inset: 0; background: rgba(0,0,0,.55); display: flex; align-items: center; justify-content: center; z-index: 50; padding: 16px; }
.modal .box { background: #fff; border-radius: 16px; padding: 16px; width: min(760px, 100%); }
.modal canvas { width: 100%; height: 240px; border: 2px dashed var(--line); border-radius: 12px; background: #fff; touch-action: none; display: block; }
.modal .hint { color: var(--muted); font-size: .85rem; margin: 6px 0 10px; }

.toast { position: fixed; left: 50%; bottom: 90px; transform: translateX(-50%); background: var(--ink); color: #fff; padding: 10px 16px; border-radius: 999px; z-index: 60; font-size: .9rem; }
.muted { color: var(--muted); }
.small { font-size: .85rem; }
.mt { margin-top: 12px; }

/* archived HOPs are read-only */
.banner { background: #fff4df; border-color: #f0d9a8; display: flex; flex-wrap: wrap; align-items: center; gap: 10px; }
.readonly .ini, .readonly textarea, .readonly input, .readonly select, .readonly [data-sig], .readonly [data-draw], .readonly #addPunch, .readonly #advance, .readonly #reopen, .readonly [data-corr] { pointer-events: none; opacity: .55; }

/* photos on review notes */
.photos { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; margin-top: 8px; }
.ph { position: relative; width: 96px; height: 96px; }
.ph img { width: 100%; height: 100%; object-fit: cover; border-radius: 8px; border: 1px solid var(--line); cursor: pointer; display: block; }
.ph-x { position: absolute; top: -6px; right: -6px; width: 26px; height: 26px; border-radius: 50%; border: 1px solid var(--line); background: #fff; color: var(--red); font-weight: 700; cursor: pointer; line-height: 1; }
.ph-add { cursor: pointer; }
.photo-box img { max-width: 100%; max-height: 70vh; display: block; margin: 0 auto; border-radius: 8px; }
.readonly .ph-add, .readonly .ph-x { pointer-events: none; opacity: .55; }

.ph-tag { position: absolute; left: 4px; bottom: 4px; font-size: .62rem; font-weight: 700; padding: 2px 6px; border-radius: 999px; color: #fff; background: var(--red); pointer-events: none; }
.ph-tag.done { background: var(--ok); }
.ph-btns { display: inline-flex; gap: 6px; flex-wrap: wrap; }
.ph-add.done { border-color: var(--ok); color: var(--ok); }

.row-right { display: flex; flex-direction: column; align-items: flex-end; gap: 6px; }
.row-del { color: var(--red); min-height: 32px; }

.install-btn { border-color: var(--gold); color: #7a5d0e; background: #fff9e8; white-space: nowrap; }
.install-steps { padding-left: 22px; line-height: 1.6; }
.install-steps li { margin-bottom: 8px; }
@media (max-width: 520px) { .install-btn { font-size: .8rem; padding: 0 10px; } .who { display: none; } }

/* in-app PDF viewer */
.pdf-box { width: min(960px, 100%); max-height: 94vh; display: flex; flex-direction: column; padding: 10px; }
.pdf-head { display: flex; align-items: center; justify-content: space-between; gap: 10px; flex-wrap: wrap; padding: 4px 6px 10px; }
.pdf-pages { overflow: auto; -webkit-overflow-scrolling: touch; background: #ddd; padding: 8px; border-radius: 10px; display: flex; flex-direction: column; align-items: center; gap: 10px; }
.pdf-pages canvas { background: #fff; box-shadow: 0 1px 4px rgba(0,0,0,.25); display: block; max-width: 100%; }
