:root {
  --brand: #b42318;
  --brand-dark: #8f1b12;
  --brand-bg: #fdecea;
  --accent: #b42318;
  --bg: #f6f7f9;
  --surface: #ffffff;
  --text: #1d2433;
  --muted: #5b6475;
  --border: #dde1e7;
  --pass: #157f3b;
  --pass-bg: #e7f6ec;
  --fail: #b42318;
  --fail-bg: #fdecea;
  --warn: #9a5b00;
  --warn-bg: #fff4dc;
  --info-bg: #eef3fb;
  --radius: 10px;
  --shadow: 0 1px 2px rgba(16, 24, 40, .06), 0 1px 3px rgba(16, 24, 40, .08);
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, Arial, sans-serif;
  color: var(--text);
  background: var(--bg);
  -webkit-text-size-adjust: 100%;
}
* { box-sizing: border-box; }
body { margin: 0; min-height: 100vh; background: var(--bg); }
a { color: var(--brand); }
h1 { font-size: 1.5rem; margin: 0 0 4px; }
h2 { font-size: 1.15rem; margin: 0 0 12px; }
h3 { font-size: 1rem; margin: 0 0 8px; }
.muted { color: var(--muted); }
.small { font-size: .85rem; }
.container { max-width: 1180px; margin: 0 auto; padding: 20px 16px 64px; }
[hidden] { display: none !important; }

/* top bar */
.topbar { position: sticky; top: 0; z-index: 10; display: flex; align-items: center; gap: 16px; padding: 10px 16px; background: var(--surface); border-bottom: 1px solid var(--border); flex-wrap: wrap; }
.brand { display: flex; align-items: center; gap: 8px; font-weight: 700; color: var(--text); text-decoration: none; }
.nav { display: flex; gap: 4px; flex: 1; flex-wrap: wrap; }
.nav a { padding: 8px 12px; border-radius: 8px; color: var(--muted); text-decoration: none; font-weight: 600; font-size: .95rem; }
.nav a:hover { background: var(--bg); color: var(--text); }
.nav a.active { background: var(--brand-bg); color: var(--brand); }
.userbox { display: flex; align-items: center; gap: 8px; color: var(--muted); font-size: .9rem; }
@media (max-width: 720px) {
  .brand span { display: none; }
  .userbox span { display: none; }
  .nav { order: 3; width: 100%; flex: none; }
  .nav a { flex: 1; text-align: center; padding: 8px 4px; font-size: .9rem; }
}

/* layout */
.page-head { display: flex; justify-content: space-between; align-items: flex-start; gap: 12px; margin-bottom: 16px; flex-wrap: wrap; }
.card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); box-shadow: var(--shadow); padding: 16px; margin-bottom: 16px; }
.grid { display: grid; gap: 16px; }
.grid-2 { grid-template-columns: repeat(auto-fit, minmax(min(100%, 460px), 1fr)); }
td strong { white-space: nowrap; }
.grid-3 { grid-template-columns: repeat(auto-fit, minmax(220px, 1fr)); }
.row { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }
.spacer { flex: 1; }

/* stats */
.stats { display: grid; grid-template-columns: repeat(auto-fit, minmax(160px, 1fr)); gap: 12px; margin-bottom: 16px; }
.stat { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 14px 16px; text-decoration: none; color: inherit; box-shadow: var(--shadow); display: block; }
.stat:hover { border-color: #b8bfca; }
.stat .num { font-size: 1.9rem; font-weight: 700; line-height: 1.1; }
.stat .lbl { color: var(--muted); font-size: .9rem; }
.stat.bad .num { color: var(--fail); }
.stat.warn .num { color: var(--warn); }
.stat.good .num { color: var(--pass); }

/* buttons */
.btn { display: inline-flex; align-items: center; justify-content: center; gap: 6px; min-height: 40px; padding: 8px 16px; border-radius: 8px; border: 1px solid var(--border); background: var(--surface); color: var(--text); font: inherit; font-weight: 600; cursor: pointer; text-decoration: none; white-space: nowrap; }
.btn:hover { background: var(--bg); }
.btn-primary { background: var(--brand); border-color: var(--brand); color: #fff; }
.btn-primary:hover { background: var(--brand-dark); }
.btn-danger { color: var(--fail); border-color: #f1b5ae; }
.btn-ghost { border-color: transparent; background: transparent; }
.btn-sm { min-height: 32px; padding: 4px 10px; font-size: .88rem; }
.btn:disabled { opacity: .6; cursor: not-allowed; }

/* forms */
label { display: block; font-weight: 600; font-size: .9rem; margin-bottom: 4px; }
.field { margin-bottom: 12px; }
input, select, textarea { width: 100%; font: inherit; padding: 9px 11px; border: 1px solid #c9ced6; border-radius: 8px; background: #fff; color: var(--text); min-height: 42px; }
textarea { min-height: 80px; resize: vertical; }
input:focus, select:focus, textarea:focus { outline: 2px solid #f2a59c; border-color: var(--brand); }
input[type=checkbox] { width: auto; min-height: 0; }
.form-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(220px, 1fr)); gap: 0 16px; }
.hint { font-size: .82rem; color: var(--muted); margin-top: 3px; }
.error { background: var(--fail-bg); color: var(--fail); border: 1px solid #f4c1bb; padding: 10px 12px; border-radius: 8px; margin-bottom: 12px; }
.notice { background: var(--warn-bg); color: #6b3f00; border: 1px solid #f3d595; padding: 10px 12px; border-radius: 8px; margin: 12px 0; font-weight: 600; }
.info { background: var(--info-bg); border: 1px solid #cfdcf2; padding: 10px 12px; border-radius: 8px; margin: 12px 0; }

/* segmented choice */
.seg { display: inline-flex; border: 1px solid #c9ced6; border-radius: 8px; overflow: hidden; flex-wrap: wrap; }
.seg label { margin: 0; font-weight: 600; font-size: .9rem; }
.seg input { position: absolute; opacity: 0; width: 1px; height: 1px; }
.seg span { display: block; padding: 9px 14px; cursor: pointer; background: #fff; border-right: 1px solid #c9ced6; min-width: 64px; text-align: center; user-select: none; }
.seg label:last-child span { border-right: 0; }
.seg input:focus-visible + span { outline: 2px solid var(--brand); outline-offset: -2px; }
.seg input:checked + span { background: #374151; color: #fff; }
.seg input[value=pass]:checked + span { background: var(--pass); }
.seg input[value=fail]:checked + span, .seg input[value=repair_needed]:checked + span { background: var(--fail); }

/* checklist */
.check-item { display: flex; justify-content: space-between; align-items: center; gap: 12px; padding: 12px 0; border-bottom: 1px solid var(--border); flex-wrap: wrap; }
.check-item:last-child { border-bottom: 0; }
.check-item .ci-text { flex: 1 1 260px; }
.check-item .ci-text strong { display: block; }
.check-item .ci-note { flex-basis: 100%; }
.check-item.is-fail { background: var(--fail-bg); margin: 0 -16px; padding: 12px 16px; }

/* tables */
.table-wrap { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; font-size: .93rem; }
th, td { text-align: left; padding: 9px 10px; border-bottom: 1px solid var(--border); vertical-align: top; }
th { font-size: .8rem; text-transform: uppercase; letter-spacing: .03em; color: var(--muted); background: #fafbfc; white-space: nowrap; }
tr.clickable { cursor: pointer; }
tr.clickable:hover td { background: #fafbfc; }
.empty { text-align: center; color: var(--muted); padding: 28px 12px; }

/* badges */
.badge { display: inline-block; padding: 2px 9px; border-radius: 999px; font-size: .78rem; font-weight: 700; white-space: nowrap; background: #eef0f3; color: #3c4453; }
.badge.pass, .badge.in_service { background: var(--pass-bg); color: var(--pass); }
.badge.fail, .badge.out_of_service, .badge.repair_needed { background: var(--fail-bg); color: var(--fail); }
.badge.overdue { background: var(--fail-bg); color: var(--fail); }
.badge.soon { background: var(--warn-bg); color: var(--warn); }
.badge.retired { background: #eef0f3; color: #6b7280; }

/* tabs */
.tabs { display: flex; gap: 4px; border-bottom: 1px solid var(--border); margin-bottom: 16px; overflow-x: auto; }
.tabs a { padding: 10px 14px; text-decoration: none; color: var(--muted); font-weight: 600; border-bottom: 3px solid transparent; white-space: nowrap; }
.tabs a.active { color: var(--brand); border-bottom-color: var(--brand); }

/* detail list */
.dl { display: grid; grid-template-columns: max-content 1fr; gap: 6px 16px; margin: 0; }
.dl dt { color: var(--muted); font-size: .9rem; }
.dl dd { margin: 0; font-weight: 600; }

/* signature */
.sig-wrap { border: 1px dashed #9aa3b2; border-radius: 8px; background: #fff; position: relative; touch-action: none; }
.sig-wrap canvas { display: block; width: 100%; height: 160px; }
.sig-wrap .sig-hint { position: absolute; left: 12px; bottom: 8px; color: #9aa3b2; font-size: .85rem; pointer-events: none; }

/* login */
.auth-card { max-width: 420px; margin: 8vh auto 0; }
.auth-card .brand { justify-content: center; margin-bottom: 16px; font-size: 1.2rem; }

/* photos */
.photos { display: flex; gap: 8px; flex-wrap: wrap; }
.photos img { width: 120px; height: 120px; object-fit: cover; border-radius: 8px; border: 1px solid var(--border); }

/* toast */
.toast { position: fixed; bottom: 20px; left: 50%; transform: translateX(-50%); background: #1d2433; color: #fff; padding: 10px 18px; border-radius: 8px; box-shadow: 0 6px 20px rgba(0,0,0,.2); z-index: 50; max-width: calc(100% - 32px); }

/* printable inspection record */
.record { background: #fff; border: 1px solid var(--border); border-radius: var(--radius); padding: 24px; max-width: 820px; margin: 0 auto; }
.record-head { display: flex; justify-content: space-between; align-items: flex-start; border-bottom: 3px solid var(--accent); padding-bottom: 10px; margin-bottom: 14px; gap: 12px; }
.record-head .dept { font-size: .8rem; letter-spacing: .08em; color: var(--muted); font-weight: 700; }
.record-head h1 { font-size: 1.35rem; }
.record h2 { font-size: .95rem; text-transform: uppercase; letter-spacing: .04em; background: #f1f3f6; padding: 6px 10px; margin: 16px 0 8px; }
.record table td, .record table th { padding: 6px 8px; }
.record .mark { font-weight: 700; }
.record .mark.pass { color: var(--pass); }
.record .mark.fail { color: var(--fail); }
.record .sig { max-height: 80px; border-bottom: 1px solid #333; }
.result-banner { padding: 10px 12px; font-weight: 800; border-radius: 6px; margin: 8px 0; }
.result-banner.pass { background: var(--pass-bg); color: var(--pass); }
.result-banner.fail, .result-banner.repair_needed { background: var(--fail-bg); color: var(--fail); }

@media print {
  body { background: #fff; }
  .topbar, .no-print, .toast { display: none !important; }
  .container { padding: 0; max-width: none; }
  .record { border: 0; padding: 0; max-width: none; }
  .card { box-shadow: none; }
  a { color: inherit; text-decoration: none; }
}

/* v2 additions */
.sr-only { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }
.txt-bad { color: var(--fail); }
.type-cards { display: grid; grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); gap: 12px; margin-bottom: 16px; }
.type-cards .num { font-size: 1.5rem; }
.badge.cal { background: var(--info-bg); color: #24529c; }
.badge.out_for_calibration { background: var(--warn-bg); color: var(--warn); }
.badge.lost { background: var(--fail-bg); color: var(--fail); }
#actionPanel:empty { display: none; }

/* QR labels */
.labels { display: grid; gap: 8px; }
.label { display: flex; align-items: center; gap: 8px; background: #fff; border: 1px dashed #c9ced6; border-radius: 6px; overflow: hidden; color: #000; }
.label-qr svg { display: block; width: 100%; height: 100%; }
.label-text { min-width: 0; line-height: 1.15; }
.label-tag { font-weight: 800; font-family: ui-monospace, Menlo, Consolas, monospace; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.label-type { font-size: .78em; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.label-owner { font-size: .62em; color: #333; margin-top: 2px; white-space: nowrap; }
.labels-sheet { grid-template-columns: repeat(auto-fill, 2.625in); }
.labels-sheet .label { width: 2.625in; height: 1in; padding: .06in .1in; font-size: 11pt; }
.labels-sheet .label-qr { width: .85in; height: .85in; flex: none; }
.labels-large { grid-template-columns: repeat(auto-fill, 4in); }
.labels-large .label { width: 4in; height: 2in; padding: .15in .2in; font-size: 18pt; gap: .15in; }
.labels-large .label-qr { width: 1.65in; height: 1.65in; flex: none; }
.labels-roll { grid-template-columns: repeat(auto-fill, 2.25in); }
.labels-roll .label { width: 2.25in; height: 1.25in; padding: .08in .1in; font-size: 11pt; }
.labels-roll .label-qr { width: 1.05in; height: 1.05in; flex: none; }

@media print {
  body.print-labels .container { padding: 0; margin: 0; max-width: none; }
  body.print-labels .label { border: 0; border-radius: 0; break-inside: avoid; }
  /* Avery 5160: 0.5in top margin, 0.1875in side margin, 0.125in column gap, no row gap */
  body.print-labels .labels-sheet { gap: 0 .125in; padding: .5in .1875in 0; }
  body.print-labels .labels-large { gap: 0 .19in; padding: .5in .16in 0; }
  body.print-labels .labels-roll { display: block; }
  body.print-labels .labels-roll .label { break-after: page; }
}
@page { margin: 0.5in; }
@page labels { margin: 0; }
.labels { page: labels; }
table.grouped tr.group th { background: #f1f3f6; color: var(--text); font-size: .85rem; padding-top: 12px; }
table.grouped td:nth-child(1) { width: 40%; }
table.grouped td:nth-child(4) { width: 1%; white-space: nowrap; }

/* employee profile tile */
.profile-main { display: flex; align-items: center; gap: 16px; flex-wrap: wrap; }
.profile .avatar { width: 64px; height: 64px; border-radius: 50%; background: var(--brand-bg); color: var(--brand); display: grid; place-items: center; font-weight: 800; font-size: 1.4rem; flex: none; }
.profile-id { flex: 1 1 200px; min-width: 0; }
.profile-id h1 { margin: 0; }
.profile-actions { display: flex; gap: 8px; flex-wrap: wrap; }
.profile-facts { display: grid; grid-template-columns: repeat(auto-fit, minmax(170px, 1fr)); gap: 12px 20px; margin: 16px 0 0; padding-top: 16px; border-top: 1px solid var(--border); }
.profile-facts dt { font-size: .78rem; text-transform: uppercase; letter-spacing: .04em; color: var(--muted); margin-bottom: 2px; }
.profile-facts dd { margin: 0; font-weight: 600; overflow-wrap: anywhere; }
.profile-stats { display: grid; grid-template-columns: repeat(auto-fit, minmax(140px, 1fr)); gap: 10px; margin-top: 16px; }
.profile-stats > div { background: var(--bg); border-radius: 8px; padding: 10px 12px; display: flex; flex-direction: column; }
.profile-stats .num { font-size: 1.5rem; font-weight: 700; line-height: 1.1; }
.profile-stats .lbl { font-size: .82rem; color: var(--muted); }
.profile-stats .bad .num { color: var(--fail); }
@media (max-width: 600px) {
  table.grouped tr:not(.group) { display: flex; flex-wrap: wrap; align-items: center; gap: 4px 8px; border-bottom: 1px solid var(--border); padding: 8px 0; }
  table.grouped tr:not(.group) td { border: 0; padding: 0 10px; width: auto !important; }
  table.grouped tr:not(.group) td:nth-child(1) { flex: 1 1 100%; }
  table.grouped tr:not(.group) td:nth-child(4) { margin-left: auto; }
}
.back-link { display: inline-flex; align-items: center; gap: 6px; min-height: 40px; padding: 8px 14px; margin-bottom: 12px; border: 1px solid var(--border); border-radius: 8px; background: var(--surface); color: var(--text); font-weight: 600; font-size: 1rem; text-decoration: none; }
.back-link:hover { background: var(--bg); }

/* branding: red top bar */
.topbar { background: var(--brand); border-bottom: 0; color: #fff; }
.topbar .brand { color: #fff; gap: 10px; }
.topbar .brand-name { font-size: 1.08rem; font-weight: 700; white-space: nowrap; }
.topbar .nav a { color: #fde3e0; }
.topbar .nav a:hover { background: rgba(255, 255, 255, .12); color: #fff; }
.topbar .nav a.active { background: rgba(255, 255, 255, .2); color: #fff; }
.topbar .userbox { color: #fde3e0; }
.topbar .userbox .btn { color: #fff; border: 1px solid rgba(255, 255, 255, .55); background: transparent; }
.topbar .userbox .btn:hover { background: rgba(255, 255, 255, .12); }
@media (max-width: 720px) { .topbar .brand .brand-name { display: inline; font-size: .98rem; } }
@media (max-width: 420px) { .topbar .brand-name { white-space: normal; line-height: 1.15; } }

/* login card */
.auth-card { border-top: 5px solid var(--brand); padding: 26px; }
.auth-card .auth-logo { display: block; width: 230px; max-width: 80%; height: auto; margin: 2px auto 14px; }
.auth-card .auth-title { text-align: center; font-weight: 700; font-size: 1.12rem; color: var(--text); }
.auth-card .auth-sub { text-align: center; color: var(--muted); font-size: .92rem; margin: 2px 0 18px; }

/* printout letterhead */
.letterhead { display: flex; justify-content: space-between; align-items: flex-end; gap: 16px; border-bottom: 3px solid var(--brand); padding-bottom: 10px; margin-bottom: 12px; }
.letterhead img { height: 72px; width: auto; display: block; }
.letterhead .lh-right { text-align: right; font-size: .85rem; color: var(--muted); line-height: 1.35; }
.letterhead .lh-right strong { color: var(--text); }
.record h1.lh-title { font-size: 1.3rem; margin: 6px 0 4px; letter-spacing: .01em; }
@media (max-width: 720px) { .userbox { margin-left: auto; } }
@media (max-width: 720px) {
  .topbar .brand { flex: 1 1 0; min-width: 0; }
  .topbar .brand .brand-name { white-space: normal; line-height: 1.15; }
  .topbar .userbox { flex: none; }
}
