:root {
  --bg: #f4f6fb; --surface: #ffffff; --surface-2: #eef1f8; --text: #172033; --muted: #5b6478; --line: #dde2ee;
  --primary: #1f3a8a; --primary-ink: #ffffff; --primary-soft: #e3e9fb;
  --ok: #157347; --ok-soft: #e1f3e9; --warn: #9a6700; --warn-soft: #fff4d6; --bad: #b42318; --bad-soft: #fde7e5;
  --radius: 14px; --shadow: 0 1px 2px rgba(16,24,40,.06), 0 1px 3px rgba(16,24,40,.08);
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0e1320; --surface: #171e2e; --surface-2: #1f2840; --text: #e7ebf5; --muted: #a2abc0; --line: #2b3550;
    --primary: #7c9cff; --primary-ink: #0b1020; --primary-soft: #23305a;
    --ok: #4cc38a; --ok-soft: #133526; --warn: #f2c14e; --warn-soft: #3a2f10; --bad: #ff7b72; --bad-soft: #3d1715;
    --shadow: none; color-scheme: dark;
  }
}
* { box-sizing: border-box; }
html, body { margin: 0; background: var(--bg); color: var(--text); font: 16px/1.45 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif; }
body { min-height: 100dvh; padding-bottom: env(safe-area-inset-bottom); }
a { color: var(--primary); }
.bar { position: sticky; top: 0; z-index: 5; display: flex; align-items: center; gap: 8px; padding: 10px 12px; padding-top: calc(10px + env(safe-area-inset-top));
  background: var(--primary); color: var(--primary-ink); }
@media (prefers-color-scheme: dark) { .bar { background: var(--surface); color: var(--text); border-bottom: 1px solid var(--line); } }
.bar h1 { flex: 1; margin: 0; font-size: 1.1rem; font-weight: 650; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.icon-btn { background: transparent; border: 0; color: inherit; font-size: 1.4rem; width: 40px; height: 40px; border-radius: 10px; cursor: pointer; }
.icon-btn:focus-visible { outline: 2px solid currentColor; }
main { max-width: 760px; margin: 0 auto; padding: 16px; }
h2 { font-size: 1.05rem; margin: 18px 0 8px; }
.muted { color: var(--muted); font-size: .9rem; }
.card { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 14px; margin-bottom: 12px; box-shadow: var(--shadow); }
.tiles { display: grid; grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); gap: 10px; }
.tile { display: flex; flex-direction: column; gap: 6px; padding: 16px 14px; min-height: 96px; background: var(--surface); border: 1px solid var(--line);
  border-radius: var(--radius); color: var(--text); text-decoration: none; box-shadow: var(--shadow); }
.tile:active { transform: scale(.99); }
.tile b { font-size: 1rem; }
.tile .count { font-size: 1.6rem; font-weight: 700; color: var(--primary); line-height: 1; }
.tile.primary { background: var(--primary); color: var(--primary-ink); border-color: transparent; }
.tile.primary .count { color: var(--primary-ink); }
label { display: block; font-weight: 600; font-size: .92rem; margin: 12px 0 4px; }
label .req { color: var(--bad); }
input, select, textarea { width: 100%; font: inherit; color: var(--text); background: var(--surface); border: 1px solid var(--line); border-radius: 10px; padding: 11px 12px; min-height: 46px; }
textarea { min-height: 96px; resize: vertical; }
input:focus, select:focus, textarea:focus { outline: 2px solid var(--primary); outline-offset: 0; border-color: transparent; }
.row { display: flex; gap: 10px; flex-wrap: wrap; align-items: center; }
.row > * { flex: 1 1 140px; }
.btn { display: inline-flex; align-items: center; justify-content: center; gap: 6px; min-height: 46px; padding: 10px 16px; font: inherit; font-weight: 650;
  border-radius: 12px; border: 1px solid var(--line); background: var(--surface); color: var(--text); cursor: pointer; text-decoration: none; }
.btn.primary { background: var(--primary); color: var(--primary-ink); border-color: transparent; }
.btn.ok { background: var(--ok); color: #fff; border-color: transparent; }
.btn.bad { background: var(--bad); color: #fff; border-color: transparent; }
.btn.block { width: 100%; }
.btn:disabled { opacity: .55; cursor: progress; }
.actions { position: sticky; bottom: 0; display: grid; gap: 8px; padding: 12px 0 calc(12px + env(safe-area-inset-bottom)); background: linear-gradient(transparent, var(--bg) 30%); }
.badge { display: inline-block; padding: 2px 10px; border-radius: 999px; font-size: .78rem; font-weight: 650; background: var(--surface-2); color: var(--muted); white-space: nowrap; }
.badge.PendingApproval, .badge.Approving, .badge.HoRejected, .badge.Pending { background: var(--warn-soft); color: var(--warn); }
.badge.Assigned, .badge.TripStarted, .badge.OnSite { background: var(--primary-soft); color: var(--primary); }
.badge.WorkDone, .badge.Closed { background: var(--surface-2); color: var(--text); }
.badge.HoApproved { background: var(--ok-soft); color: var(--ok); }
.badge.Rejected { background: var(--bad-soft); color: var(--bad); }
.list { display: grid; gap: 10px; }
.item { display: block; text-decoration: none; color: inherit; }
.item .top { display: flex; justify-content: space-between; gap: 8px; align-items: baseline; }
.item p { margin: 6px 0 0; color: var(--muted); font-size: .92rem; overflow: hidden; display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; }
dl.kv { display: grid; grid-template-columns: minmax(110px, 38%) 1fr; gap: 6px 12px; margin: 0; }
dl.kv dt { color: var(--muted); font-size: .9rem; }
dl.kv dd { margin: 0; word-break: break-word; }
.timeline { list-style: none; padding: 0; margin: 0; }
.timeline li { padding: 8px 0 8px 16px; border-left: 2px solid var(--line); position: relative; }
.timeline li::before { content: ""; position: absolute; left: -6px; top: 13px; width: 10px; height: 10px; border-radius: 50%; background: var(--primary); }
.banner { padding: 10px 12px; border-radius: 10px; margin-bottom: 12px; font-size: .92rem; }
.banner.warn { background: var(--warn-soft); color: var(--warn); }
.banner.info { background: var(--primary-soft); color: var(--primary); }
.banner.bad { background: var(--bad-soft); color: var(--bad); }
.banner.ok { background: var(--ok-soft); color: var(--ok); }
details.section { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); margin-bottom: 10px; }
details.section > summary { padding: 14px; font-weight: 650; cursor: pointer; list-style: none; display: flex; justify-content: space-between; }
details.section > summary::after { content: "+"; color: var(--muted); }
details.section[open] > summary::after { content: "–"; }
details.section > div { padding: 0 14px 14px; }
.yesno { display: flex; gap: 8px; }
.yesno label { flex: 1; margin: 0; font-weight: 600; text-align: center; padding: 10px; border: 1px solid var(--line); border-radius: 10px; cursor: pointer; background: var(--surface); }
.yesno input { position: absolute; opacity: 0; pointer-events: none; }
.yesno input:checked + span { color: var(--primary); }
.yesno label:has(input:checked) { border-color: var(--primary); background: var(--primary-soft); }
.unit { color: var(--muted); font-size: .85rem; }
.otp { letter-spacing: .5em; text-align: center; font-size: 1.4rem; font-variant-numeric: tabular-nums; }
.tabs { display: flex; gap: 6px; overflow-x: auto; padding-bottom: 6px; margin-bottom: 8px; scrollbar-width: none; }
.tabs a { flex: 0 0 auto; padding: 8px 12px; border-radius: 999px; text-decoration: none; color: var(--muted); background: var(--surface-2); font-weight: 600; font-size: .9rem; }
.tabs a.on { background: var(--primary); color: var(--primary-ink); }
table.grid { width: 100%; border-collapse: collapse; font-size: .9rem; }
table.grid th, table.grid td { padding: 8px 6px; border-bottom: 1px solid var(--line); text-align: left; vertical-align: middle; }
table.grid th { color: var(--muted); font-weight: 600; }
.scroll-x { overflow-x: auto; }
.checks { display: grid; grid-template-columns: repeat(auto-fill, minmax(180px, 1fr)); gap: 4px 12px; }
.checks label { font-weight: 400; display: flex; gap: 8px; align-items: center; margin: 4px 0; }
.checks input { width: 20px; min-height: 20px; height: 20px; }
#toast { position: fixed; left: 50%; bottom: calc(20px + env(safe-area-inset-bottom)); transform: translateX(-50%); max-width: min(92vw, 520px);
  background: var(--text); color: var(--bg); padding: 12px 16px; border-radius: 12px; z-index: 20; box-shadow: 0 8px 24px rgba(0,0,0,.25); }
dialog#sheet { border: 0; padding: 0; width: min(100vw, 560px); max-height: 90dvh; margin: auto auto 0; border-radius: 18px 18px 0 0; background: var(--surface); color: var(--text); }
@media (min-width: 640px) { dialog#sheet { margin: auto; border-radius: 18px; } }
dialog#sheet::backdrop { background: rgba(10,14,25,.5); }
dialog#sheet form { padding: 18px 16px calc(18px + env(safe-area-inset-bottom)); }
dialog#sheet h3 { margin: 0 0 6px; }
.spinner { padding: 40px 0; text-align: center; color: var(--muted); }
.pill { display: inline-block; padding: 1px 8px; border-radius: 999px; background: var(--surface-2); font-size: .8rem; margin: 2px 4px 2px 0; }
@media (prefers-reduced-motion: reduce) { * { transition: none !important; animation: none !important; } }

/* ---- step-by-step site report ---- */
.wizard { padding-bottom: 8px; }
.progress { height: 6px; background: var(--surface-2); border-radius: 999px; overflow: hidden; margin: 2px 0 14px; }
.progress > div { height: 100%; width: 0; background: var(--primary); border-radius: 999px; transition: width .25s ease; }
.stephead h2 { margin: 2px 0 2px; font-size: 1.25rem; }
.stephead { margin-bottom: 12px; }
.fsec { display: grid; gap: 14px; }
.ffield { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 14px; box-shadow: var(--shadow); }
.ffield[hidden] { display: none; }
.flabel { margin: 0 0 8px; font-size: .98rem; }
.fhelp { margin-top: 6px; }
.chips { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }
.chips.wrap { grid-template-columns: repeat(auto-fill, minmax(130px, 1fr)); }
.chip { position: relative; display: flex; align-items: center; justify-content: center; min-height: 48px; margin: 0; padding: 8px 10px; text-align: center;
  border: 1.5px solid var(--line); border-radius: 12px; background: var(--surface); font-weight: 600; cursor: pointer; }
.chip input { position: absolute; opacity: 0; pointer-events: none; }
.chip:has(input:checked) { border-color: var(--primary); background: var(--primary-soft); color: var(--primary); }
.chip:has(input:focus-visible) { outline: 2px solid var(--primary); outline-offset: 2px; }
.chip:has(input:disabled) { cursor: default; opacity: .8; }
.stepnav .row > * { flex: 1 1 0; }
.stepnav .muted { display: block; text-align: center; margin-top: 6px; min-height: 1.2em; }
.review-row { display: flex; justify-content: space-between; align-items: center; gap: 10px; width: 100%; text-align: left; font: inherit; color: inherit; cursor: pointer; margin: 0; }

/* ---- form designer ---- */
.dsec { display: grid; gap: 10px; }
.dfields { display: grid; gap: 6px; }
.drow { display: flex; align-items: center; gap: 6px; border: 1px solid var(--line); border-radius: 10px; padding: 6px 6px 6px 12px; background: var(--surface); }
.drow.retired { opacity: .55; border-style: dashed; }
.dmain { flex: 1; min-width: 0; cursor: pointer; padding: 4px 0; }
.dmain > div:first-child { font-weight: 600; overflow-wrap: anywhere; }
.dbtns { display: flex; gap: 2px; }
.dbtns .icon-btn { width: 36px; height: 36px; font-size: 1.05rem; color: var(--muted); border: 1px solid transparent; }
.dbtns .icon-btn:hover:not(:disabled) { border-color: var(--line); color: var(--text); }
.dbtns .icon-btn:disabled { opacity: .3; cursor: not-allowed; }
dialog#sheet form { max-height: 88dvh; overflow-y: auto; }

/* hidden must always win over layout classes like .row */
[hidden] { display: none !important; }

/* ---- photos & documents ---- */
.fupload { display: grid; gap: 10px; }
.ftiles { display: grid; grid-template-columns: repeat(auto-fill, minmax(92px, 1fr)); gap: 8px; }
.ftiles:empty { display: none; }
.ftile { position: relative; aspect-ratio: 1; border: 1px solid var(--line); border-radius: 10px; overflow: hidden; background: var(--surface-2); display: flex; align-items: center; justify-content: center; }
.ftile img { width: 100%; height: 100%; object-fit: cover; display: block; }
.ftile.doc { aspect-ratio: auto; min-height: 56px; grid-column: 1 / -1; justify-content: flex-start; padding: 10px 40px 10px 12px; }
.fdoc { overflow-wrap: anywhere; text-decoration: none; font-weight: 600; }
.ftile.busy { border-style: dashed; }
.fremove { position: absolute; top: 4px; right: 4px; width: 28px; height: 28px; border-radius: 50%; border: 0; background: rgba(0,0,0,.6); color: #fff; cursor: pointer; font-size: .85rem; }

.card.inactive { opacity: .65; }

/* property QR posters (A4, one per page) */
.poster { background: #fff; color: #111; border: 1px solid #ddd; border-radius: 12px; padding: 28px; margin: 0 auto 16px; max-width: 640px; text-align: center; }
.poster h1 { margin: 12px 0 4px; font-size: 30px; }
.poster-head { display: flex; gap: 12px; align-items: center; justify-content: center; font-size: 18px; text-align: left; }
.poster-lead { font-size: 22px; font-weight: 600; margin: 18px 0 8px; }
.poster-qr { width: 300px; height: 300px; image-rendering: pixelated; }
.poster ol { text-align: left; display: inline-block; font-size: 16px; margin: 8px auto; }
.poster-url { font-family: monospace; font-size: 12px; word-break: break-all; }
.poster .muted { color: #555; }
@media print {
  @page { size: A4; margin: 12mm; }
  body { background: #fff !important; }
  header.bar, .no-print, #toast { display: none !important; }
  main, #app { padding: 0 !important; margin: 0 !important; max-width: none !important; }
  .poster { border: none; page-break-after: always; break-after: page; max-width: none; padding: 0; }
}
