:root {
  --black: #000000;
  --ink: #1d2228;
  --muted: #5b6470;
  --line: #dfe3e8;
  --bg: #f4f5f7;
  --card: #ffffff;
  --red: #E4312B;
  --orange: #F15A22;
  --amber: #F7941D;
  --yellow: #FFC20E;
  --ok: #1f8a4c;
  --warn: #b7791f;
  --bad: #c0392b;
  --radius: 10px;
  --grad: linear-gradient(180deg, #F15A22 0%, #F7941D 55%, #FFC20E 100%);
}
* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0; background: var(--bg); color: var(--ink);
  font: 15px/1.45 -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
}
a { color: #c2410c; text-decoration: none; }
a:hover { text-decoration: underline; }
h1 { font-size: 24px; margin: 0 0 4px; letter-spacing: -.01em; }
h2 { font-size: 18px; margin: 0 0 12px; }
h3 { font-size: 15px; margin: 0 0 8px; }
.muted { color: var(--muted); }
.small { font-size: 13px; }

/* ---------- top bar ---------- */
.topbar {
  background: var(--black); color: #fff; position: sticky; top: 0; z-index: 50;
  border-bottom: 3px solid transparent; border-image: linear-gradient(90deg, var(--red), var(--orange), var(--yellow)) 1;
}
.topbar .inner { max-width: 1240px; margin: 0 auto; display: flex; align-items: center; gap: 22px; padding: 8px 18px; }
.brand { display: flex; align-items: center; gap: 12px; color: #fff; }
.brand img { height: 38px; display: block; }
.brand .dept { font-size: 11px; letter-spacing: .14em; text-transform: uppercase; color: #c9ced6; border-left: 1px solid #333; padding-left: 12px; line-height: 1.2; }
.nav { display: flex; gap: 4px; flex: 1; flex-wrap: wrap; }
.nav a { color: #e9ecef; padding: 8px 12px; border-radius: 8px; font-size: 14px; }
.nav a:hover, .nav a.active { background: #1f2126; text-decoration: none; color: #fff; }
.nav a.active { box-shadow: inset 0 -2px 0 var(--orange); }
.userbox { display: flex; align-items: center; gap: 10px; font-size: 13px; color: #c9ced6; }
.userbox form { margin: 0; }
.linkbtn { background: none; border: 0; color: #c9ced6; cursor: pointer; font: inherit; padding: 6px 8px; border-radius: 6px; }
.linkbtn:hover { background: #1f2126; color: #fff; }
.menu-toggle { display: none; }

main { max-width: 1240px; margin: 0 auto; padding: 24px 18px 80px; }
.pagehead { display: flex; align-items: flex-end; justify-content: space-between; gap: 16px; margin-bottom: 18px; flex-wrap: wrap; }
.crumbs { font-size: 13px; color: var(--muted); margin-bottom: 4px; }
.crumbs a { color: var(--muted); }

/* ---------- cards / grid ---------- */
.card { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); padding: 18px 20px; margin-bottom: 18px; }
.card.flush { padding: 0; overflow: hidden; }
.card > .cardhead { display: flex; align-items: center; justify-content: space-between; gap: 10px; margin-bottom: 12px; }
.grid { display: grid; gap: 14px 18px; grid-template-columns: repeat(auto-fill, minmax(230px, 1fr)); }
.grid.two { grid-template-columns: repeat(auto-fill, minmax(320px, 1fr)); }
.span-all { grid-column: 1 / -1; }
.stats { display: grid; grid-template-columns: repeat(4, 1fr); gap: 14px; margin-bottom: 18px; }
.stat { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); padding: 14px 18px; position: relative; overflow: hidden; }
.stat::before { content: ""; position: absolute; left: 0; top: 0; bottom: 0; width: 4px; background: var(--grad); }
.stat .n { font-size: 28px; font-weight: 700; }
.stat .l { color: var(--muted); font-size: 13px; }

/* ---------- tables ---------- */
table.list { width: 100%; border-collapse: collapse; }
table.list th { text-align: left; font-size: 12px; text-transform: uppercase; letter-spacing: .05em; color: var(--muted); padding: 10px 14px; border-bottom: 1px solid var(--line); background: #fafbfc; }
table.list td a strong { white-space: nowrap; }
table.list td { padding: 11px 14px; border-bottom: 1px solid var(--line); vertical-align: top; }
table.list tr:last-child td { border-bottom: 0; }
table.list tr:hover td { background: #fcfcfd; }
.empty { padding: 28px; text-align: center; color: var(--muted); }

/* ---------- badges ---------- */
.badge { display: inline-block; font-size: 11.5px; font-weight: 600; padding: 2px 8px; border-radius: 999px; border: 1px solid transparent; white-space: nowrap; }
.badge.draft { background: #f1f3f5; color: #495057; border-color: #dee2e6; }
.badge.completed { background: #fff4e5; color: #9a4b00; border-color: #ffd8a8; }
.badge.verified { background: #e6f6ec; color: #17693a; border-color: #b2e2c4; }
.std { display: inline-block; font-size: 11px; font-weight: 700; letter-spacing: .04em; padding: 2px 7px; border-radius: 5px; color: #fff; }
.std.LPCB { background: #1d4e89; }
.std.FM { background: #7a1f2b; }
.std.NFPA { background: #b8461b; }

/* ---------- forms ---------- */
label.fl { display: block; font-size: 13px; font-weight: 600; color: #343a40; margin-bottom: 5px; }
.hint { font-size: 12px; color: var(--muted); margin-top: 3px; }
input[type=text], input[type=email], input[type=password], input[type=number], input[type=date], input[type=time],
input[type=tel], input[type=search], select, textarea {
  width: 100%; padding: 9px 11px; font: inherit; color: var(--ink); background: #fff;
  border: 1px solid #cfd5dc; border-radius: 8px; outline: none; transition: border-color .15s, box-shadow .15s;
}
input:focus, select:focus, textarea:focus { border-color: var(--orange); box-shadow: 0 0 0 3px rgba(241, 90, 34, .15); }
textarea { min-height: 84px; resize: vertical; }
.unit { display: flex; align-items: stretch; }
.unit input { border-top-right-radius: 0; border-bottom-right-radius: 0; }
.unit span { display: flex; align-items: center; padding: 0 10px; background: #f1f3f5; border: 1px solid #cfd5dc; border-left: 0; border-radius: 0 8px 8px 0; font-size: 13px; color: var(--muted); white-space: nowrap; }

.btn { display: inline-flex; align-items: center; gap: 8px; padding: 9px 16px; font: inherit; font-weight: 600; font-size: 14px; border-radius: 8px; border: 1px solid #cfd5dc; background: #fff; color: var(--ink); cursor: pointer; text-decoration: none; }
.btn:hover { background: #f8f9fa; text-decoration: none; }
.btn.primary { background: var(--black); color: #fff; border-color: var(--black); }
.btn.primary:hover { background: #26282d; }
.btn.accent { background: var(--orange); border-color: var(--orange); color: #fff; }
.btn.accent:hover { background: #d94b16; }
.btn.danger { color: var(--bad); border-color: #f1b0a9; }
.btn.small { padding: 5px 10px; font-size: 13px; }
.actions { display: flex; gap: 10px; flex-wrap: wrap; align-items: center; }

.flashes { position: sticky; top: 64px; z-index: 45; cursor: pointer; box-shadow: 0 8px 24px rgba(0,0,0,.08); border-radius: 8px; margin-bottom: 14px; }
.flashes .flash:last-child { margin-bottom: 0; }
.flash { padding: 11px 14px; border-radius: 8px; margin-bottom: 12px; font-size: 14px; border: 1px solid; }
.flash.ok { background: #e6f6ec; border-color: #b2e2c4; color: #17693a; }
.flash.error { background: #fdecea; border-color: #f5c2bc; color: #8f2318; }

/* ---------- report editor ---------- */
.formsheet { display: grid; grid-template-columns: 220px 1fr; gap: 22px; align-items: start; }
.toc { position: sticky; top: 78px; background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); padding: 10px; font-size: 13px; max-height: calc(100vh - 100px); overflow: auto; }
.toc a { display: block; padding: 6px 8px; color: var(--ink); border-radius: 6px; }
.toc a:hover { background: #f5f6f8; text-decoration: none; }
.toc .tochead { font-size: 11px; text-transform: uppercase; letter-spacing: .08em; color: var(--muted); padding: 6px 8px; }
.section { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); margin-bottom: 18px; scroll-margin-top: 80px; }
.section > header { padding: 13px 20px; border-bottom: 1px solid var(--line); display: flex; align-items: center; gap: 10px; }
.section > header h2 { margin: 0; font-size: 16px; }
.section > header .num { display: inline-flex; width: 26px; height: 26px; border-radius: 50%; background: var(--black); color: var(--yellow); font-size: 12px; font-weight: 700; align-items: center; justify-content: center; flex: none; }
.section > .body { padding: 16px 20px 20px; }
.section .note { font-size: 13px; color: var(--muted); background: #fafbfc; border-left: 3px solid var(--amber); padding: 8px 12px; margin-bottom: 14px; border-radius: 0 6px 6px 0; }
.section.hidden-by-visit { display: none; }

table.checks { width: 100%; border-collapse: collapse; }
table.checks td, table.checks th { border-bottom: 1px solid var(--line); padding: 8px 6px; vertical-align: middle; }
table.checks th { font-size: 12px; color: var(--muted); text-align: left; text-transform: uppercase; letter-spacing: .04em; }
table.checks td.code { width: 56px; font-weight: 700; color: var(--muted); font-size: 13px; }
table.checks td.ans { width: 220px; white-space: nowrap; }
table.checks td.rem { width: 28%; }
table.checks td.rem input { padding: 6px 8px; font-size: 13px; }

.seg { display: inline-flex; border: 1px solid #cfd5dc; border-radius: 8px; overflow: hidden; }
.seg label { position: relative; cursor: pointer; }
.seg input { position: absolute; opacity: 0; pointer-events: none; }
.seg span { display: block; padding: 6px 12px; font-size: 13px; font-weight: 600; color: #495057; border-right: 1px solid #cfd5dc; background: #fff; min-width: 44px; text-align: center; }
.seg label:last-child span { border-right: 0; }
.seg input:checked + span { background: var(--black); color: #fff; }
.seg input:checked + span.v-yes, .seg input:checked + span.v-pass, .seg input:checked + span.v-sat { background: var(--ok); }
.seg input:checked + span.v-no, .seg input:checked + span.v-fail, .seg input:checked + span.v-unsat { background: var(--bad); }
.seg input:checked + span.v-na { background: #6c757d; }
.seg input:focus-visible + span { outline: 2px solid var(--orange); outline-offset: -2px; }

.tablewrap { overflow-x: auto; border: 1px solid var(--line); border-radius: 8px; }
table.datagrid { border-collapse: collapse; width: 100%; min-width: 640px; }
table.datagrid th { background: #f6f7f9; font-size: 12px; font-weight: 600; color: #343a40; padding: 8px; border-bottom: 1px solid var(--line); border-right: 1px solid var(--line); text-align: left; vertical-align: bottom; }
table.datagrid td { border-bottom: 1px solid var(--line); border-right: 1px solid var(--line); padding: 4px; }
table.datagrid td.rowlabel { background: #fafbfc; font-size: 13px; font-weight: 600; padding: 6px 10px; white-space: nowrap; }
table.datagrid td.hintcell { font-size: 12px; color: var(--muted); padding: 6px 8px; }
table.datagrid input, table.datagrid select { border: 0; border-radius: 4px; padding: 6px; font-size: 13.5px; min-width: 70px; }
table.datagrid input:focus, table.datagrid select:focus { box-shadow: inset 0 0 0 2px var(--orange); }
table.ref { border-collapse: collapse; font-size: 13px; }
table.ref th, table.ref td { border: 1px solid var(--line); padding: 5px 9px; }
table.ref th { background: #f6f7f9; }

.sigpad { border: 1px dashed #aab2bd; border-radius: 8px; background: #fff; position: relative; height: 170px; touch-action: none; }
.sigpad canvas { width: 100%; height: 100%; display: block; border-radius: 8px; cursor: crosshair; }
.sigpad .clear { position: absolute; right: 8px; top: 8px; }
.sigpad .ph { position: absolute; left: 14px; bottom: 10px; font-size: 12px; color: #aab2bd; pointer-events: none; }
.sigimg { max-height: 90px; border-bottom: 1px solid var(--line); }

.photos { display: grid; grid-template-columns: repeat(auto-fill, minmax(180px, 1fr)); gap: 12px; }
.photo { border: 1px solid var(--line); border-radius: 8px; overflow: hidden; background: #fff; }
.photo img { width: 100%; height: 140px; object-fit: cover; display: block; background: #eee; }
.photo .cap { padding: 6px; display: flex; gap: 6px; }
.photo .cap input { font-size: 12.5px; padding: 5px 7px; }
.dropzone { border: 2px dashed #cfd5dc; border-radius: 10px; padding: 20px; text-align: center; color: var(--muted); cursor: pointer; background: #fcfcfd; }
.dropzone:hover, .dropzone.over { border-color: var(--orange); color: var(--ink); }

.savebar { position: fixed; left: 0; right: 0; bottom: 0; background: rgba(255,255,255,.96); border-top: 1px solid var(--line); z-index: 40; backdrop-filter: blur(6px); }
.savebar .inner { max-width: 1240px; margin: 0 auto; padding: 10px 18px; display: flex; align-items: center; gap: 12px; justify-content: space-between; }
.savestate { font-size: 13px; color: var(--muted); }

.kv { display: grid; grid-template-columns: 170px 1fr; gap: 6px 14px; font-size: 14px; }
.kv dt { color: var(--muted); }
.kv dd { margin: 0; }

.tabs { display: flex; gap: 6px; margin-bottom: 14px; flex-wrap: wrap; }
.tabs button { border: 1px solid var(--line); background: #fff; padding: 8px 14px; border-radius: 8px; font: inherit; font-weight: 600; cursor: pointer; }
.tabs button.on { background: var(--black); color: #fff; border-color: var(--black); }
.formpick { display: grid; grid-template-columns: repeat(auto-fill, minmax(260px, 1fr)); gap: 10px; }
.formpick button { text-align: left; border: 1px solid var(--line); background: #fff; border-radius: 10px; padding: 12px 14px; cursor: pointer; font: inherit; }
.formpick button:hover { border-color: var(--orange); box-shadow: 0 2px 10px rgba(241,90,34,.12); }
.formpick .code { font-weight: 700; font-size: 12px; color: var(--muted); }
.formpick .t { font-weight: 600; }

/* ---------- auth pages ---------- */
.authwrap { min-height: 100vh; display: grid; place-items: center; background: var(--black); padding: 20px; }
.authcard { width: 100%; max-width: 410px; background: #fff; border-radius: 14px; overflow: hidden; box-shadow: 0 30px 80px rgba(0,0,0,.45); }
.authcard .head { background: var(--black); padding: 26px; text-align: center; border-bottom: 4px solid transparent; border-image: linear-gradient(90deg, var(--red), var(--orange), var(--yellow)) 1; }
.authcard .head img { max-width: 260px; width: 100%; }
.authcard .head .dept { color: #c9ced6; font-size: 11px; letter-spacing: .16em; text-transform: uppercase; margin-top: 10px; }
.authcard form { padding: 24px 26px 26px; display: grid; gap: 14px; }

@media (max-width: 980px) {
  .formsheet { grid-template-columns: 1fr; }
  .toc { display: none; }
  .stats { grid-template-columns: repeat(2, 1fr); }
}
@media (max-width: 720px) {
  .topbar .inner { flex-wrap: wrap; gap: 8px; }
  .brand .dept { display: none; }
  .menu-toggle { display: inline-block; margin-left: auto; }
  .nav { display: none; flex-basis: 100%; flex-direction: column; }
  .nav.open { display: flex; }
  .userbox { flex-basis: 100%; justify-content: space-between; }
  main { padding: 16px 12px 90px; }
  table.checks td.rem { display: block; width: auto; border-bottom: 0; padding-top: 0; }
  table.checks tr { display: grid; grid-template-columns: 50px 1fr; border-bottom: 1px solid var(--line); }
  table.checks td { border-bottom: 0; }
  table.checks td.ans { grid-column: 2; }
  table.checks td.rem { grid-column: 2; }
  table.checks thead { display: none; }
  .kv { grid-template-columns: 1fr; }
  .section > .body { padding: 14px; }
  .savestate { display: none; }
  .savebar .inner { justify-content: flex-end; }
}
