:root {
  --bg: #f5f6f8;
  --surface: #ffffff;
  --surface-2: #f0f2f5;
  --border: #dde1e7;
  --text: #1c2129;
  --muted: #5f6b7a;
  --accent: #b42318;
  --accent-hover: #912018;
  --accent-soft: #fdecea;
  --nav-bg: #1d232c;
  --nav-text: #c9d1db;
  --nav-active: #ffffff;
  --green: #127a3e; --green-bg: #e3f5ea;
  --amber: #8a5a00; --amber-bg: #fff3d6;
  --red: #b42318; --red-bg: #fdecea;
  --blue: #1f5fae; --blue-bg: #e6effb;
  --gray: #4b5563; --gray-bg: #eceff3;
  --shadow: 0 8px 30px rgba(15, 23, 42, .18);
  --radius: 10px;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #12161c; --surface: #1a2028; --surface-2: #222a34; --border: #2f3946; --text: #e6eaf0; --muted: #96a2b2;
    --accent: #e5483b; --accent-hover: #f0675b; --accent-soft: #3a1d1b; --nav-bg: #0d1116;
    --green: #5fd393; --green-bg: #173325; --amber: #f2c25b; --amber-bg: #3a2e12; --red: #ff8a80; --red-bg: #3d1c1a;
    --blue: #8ab8ff; --blue-bg: #1b2a40; --gray: #b8c1cc; --gray-bg: #2a323d; --shadow: 0 8px 30px rgba(0, 0, 0, .5);
  }
}
* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; }
body { background: var(--bg); color: var(--text); font: 14px/1.45 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif; }
a { color: var(--accent); }
button, input, select, textarea { font: inherit; color: inherit; }
h1 { font-size: 22px; margin: 0; }
h2 { font-size: 17px; margin: 0; }
h3 { font-size: 14px; margin: 18px 0 8px; text-transform: uppercase; letter-spacing: .04em; color: var(--muted); }
.muted { color: var(--muted); }
.boot { display: grid; place-items: center; height: 100vh; color: var(--muted); }

/* Layout */
.shell { display: grid; grid-template-columns: 240px 1fr; min-height: 100vh; }
.sidebar { background: var(--nav-bg); color: var(--nav-text); display: flex; flex-direction: column; position: sticky; top: 0; height: 100vh; overflow-y: auto; }
.brand { display: flex; align-items: center; gap: 10px; padding: 18px 18px 14px; color: #fff; font-weight: 700; }
.brand img { width: 30px; height: 30px; }
.brand small { display: block; font-weight: 400; color: var(--nav-text); font-size: 12px; }
.nav-group { padding: 6px 10px; }
.nav-group-label { font-size: 11px; text-transform: uppercase; letter-spacing: .08em; color: #7d8896; padding: 10px 10px 4px; }
.nav a { display: flex; justify-content: space-between; align-items: center; padding: 7px 10px; border-radius: 7px; color: var(--nav-text); text-decoration: none; }
.nav a:hover { background: rgba(255,255,255,.07); color: #fff; }
.nav a.active { background: var(--accent); color: var(--nav-active); }
.nav .count { background: rgba(255,255,255,.18); border-radius: 99px; padding: 0 7px; font-size: 12px; }
.main { min-width: 0; display: flex; flex-direction: column; }
.topbar { display: flex; align-items: center; justify-content: space-between; gap: 12px; padding: 10px 24px; background: var(--surface); border-bottom: 1px solid var(--border); position: sticky; top: 0; z-index: 5; }
.topbar .who { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; justify-content: flex-end; }
.menu-btn { display: none; }
.content { padding: 22px 24px 60px; max-width: 1400px; width: 100%; }
.page-head { display: flex; align-items: center; justify-content: space-between; gap: 12px; flex-wrap: wrap; margin-bottom: 16px; }
.toolbar { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; }

/* Controls */
.btn { display: inline-flex; align-items: center; gap: 6px; border: 1px solid var(--border); background: var(--surface); padding: 7px 13px; border-radius: 8px; cursor: pointer; text-decoration: none; color: var(--text); white-space: nowrap; }
.btn:hover { background: var(--surface-2); }
.btn.primary { background: var(--accent); border-color: var(--accent); color: #fff; }
.btn.primary:hover { background: var(--accent-hover); }
.btn.danger { color: var(--red); border-color: var(--red); background: transparent; }
.btn.success { background: var(--green); border-color: var(--green); color: #fff; }
.btn.small { padding: 4px 9px; font-size: 13px; }
.btn:disabled { opacity: .55; cursor: not-allowed; }
.icon-btn { border: 0; background: transparent; font-size: 22px; line-height: 1; cursor: pointer; color: var(--muted); padding: 4px 8px; }
input[type=text], input[type=search], input[type=password], input[type=email], input[type=tel], input[type=number], input[type=date], input[type=time], input[type=datetime-local], input[type=url], select, textarea {
  width: 100%; padding: 7px 10px; border: 1px solid var(--border); border-radius: 8px; background: var(--surface); min-height: 36px;
}
textarea { min-height: 80px; resize: vertical; }
input:focus, select:focus, textarea:focus, .btn:focus-visible, .nav a:focus-visible { outline: 2px solid var(--accent); outline-offset: 1px; }
input:disabled, select:disabled, textarea:disabled { background: var(--surface-2); color: var(--text); opacity: 1; }
.toolbar input[type=search] { width: 240px; }
.toolbar select { width: auto; min-width: 160px; }
.check { display: inline-flex; align-items: center; gap: 6px; cursor: pointer; }

/* Cards / stats */
.card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 16px; }
.card + .card { margin-top: 16px; }
.card-head { display: flex; justify-content: space-between; align-items: center; gap: 10px; margin-bottom: 10px; }
.stats { display: grid; grid-template-columns: repeat(auto-fit, minmax(170px, 1fr)); gap: 12px; margin-bottom: 18px; }
.stat { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 14px 16px; text-decoration: none; color: var(--text); display: block; }
a.stat:hover { border-color: var(--accent); }
.stat .label { color: var(--muted); font-size: 12px; text-transform: uppercase; letter-spacing: .05em; }
.stat .value { font-size: 26px; font-weight: 700; margin-top: 4px; font-variant-numeric: tabular-nums; }
.stat .sub { color: var(--muted); font-size: 12px; }
.stat.attention { border-color: var(--accent); background: var(--accent-soft); }
.grid-2 { display: grid; grid-template-columns: 2fr 1fr; gap: 16px; }
.alerts { list-style: none; margin: 0; padding: 0; }
.alerts li { display: flex; gap: 10px; align-items: center; padding: 8px 4px; border-bottom: 1px solid var(--border); }
.alerts li:last-child { border-bottom: 0; }
.alerts a { color: var(--text); text-decoration: none; flex: 1; }
.alerts a:hover { text-decoration: underline; }
.dot { width: 9px; height: 9px; border-radius: 50%; flex: none; }
.dot.high { background: var(--red); }
.dot.medium { background: #e0a100; }
.quick { display: grid; gap: 8px; }

/* Tables */
.table-wrap { overflow-x: auto; background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); }
table { width: 100%; border-collapse: collapse; }
th, td { text-align: left; padding: 9px 12px; border-bottom: 1px solid var(--border); vertical-align: top; }
th { font-size: 12px; text-transform: uppercase; letter-spacing: .04em; color: var(--muted); background: var(--surface-2); position: sticky; top: 0; white-space: nowrap; }
tbody tr { cursor: pointer; }
tbody tr:hover { background: var(--surface-2); }
tbody tr:last-child td { border-bottom: 0; }
td.num { text-align: right; font-variant-numeric: tabular-nums; }
.empty { padding: 30px; text-align: center; color: var(--muted); }
.overdue { color: var(--red); font-weight: 600; }
.due-soon { color: var(--amber); font-weight: 600; }
.low { color: var(--red); font-weight: 700; }

/* Badges */
.badge { display: inline-block; padding: 1px 9px; border-radius: 99px; font-size: 12px; font-weight: 600; background: var(--gray-bg); color: var(--gray); white-space: nowrap; }
.b-in-service, .b-active, .b-pass, .b-completed, .b-approved, .b-low { background: var(--green-bg); color: var(--green); }
.b-out-of-service, .b-fail, .b-emergency, .b-rejected, .b-lost, .b-urgent, .b-closed { background: var(--red-bg); color: var(--red); }
.b-in-shop, .b-in-repair, .b-needs-repair, .b-high, .b-pending, .b-on-leave, .b-waiting-on-vendor, .b-light-duty, .b-under-renovation { background: var(--amber-bg); color: var(--amber); }
.b-in-progress, .b-open, .b-reserve, .b-normal { background: var(--blue-bg); color: var(--blue); }
.role-badge { background: var(--accent-soft); color: var(--accent); }
.badge.lvl-1 { background: var(--gray-bg); color: var(--gray); }
.badge.lvl-2 { background: var(--green-bg); color: var(--green); }
.badge.lvl-3 { background: var(--accent-soft); color: var(--accent); }
.badge.agency-badge { background: var(--blue-bg); color: var(--blue); }
.div-picks { display: flex; flex-wrap: wrap; gap: 4px 14px; }
.div-picks .check { min-width: 220px; }
.role-divhead { margin: 10px 0 2px; font-size: 12px; text-transform: uppercase; letter-spacing: .04em; color: var(--muted); }
.role-cell .badge { margin: 0 4px 4px 0; }
dd.role-cell { display: flex; flex-wrap: wrap; gap: 4px; }
dd.role-cell .badge { margin: 0; }
.roles-table td { vertical-align: middle; }
.roles-table tbody tr { cursor: default; }
.roles-table .lvl-cell { width: 190px; }

/* Modal */
.modal-backdrop { position: fixed; inset: 0; background: rgba(10, 14, 20, .55); display: flex; align-items: flex-start; justify-content: center; padding: 40px 16px; overflow-y: auto; z-index: 50; }
.modal { background: var(--surface); border-radius: 12px; width: 100%; max-width: 720px; box-shadow: var(--shadow); }
.modal.wide { max-width: 980px; }
.modal-head { display: flex; justify-content: space-between; align-items: center; padding: 14px 18px; border-bottom: 1px solid var(--border); }
.modal-body { padding: 18px; }
.modal-foot { display: flex; justify-content: flex-end; gap: 8px; padding: 12px 18px; border-top: 1px solid var(--border); flex-wrap: wrap; }
.modal-foot .spacer { flex: 1; }

/* Forms */
.form-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 12px 16px; }
.field label { display: block; font-size: 12px; font-weight: 600; color: var(--muted); margin-bottom: 4px; }
.field.span2 { grid-column: 1 / -1; }
.req { color: var(--red); }
.hint { font-size: 12px; color: var(--muted); margin-top: 4px; }
.error-box { background: var(--red-bg); color: var(--red); padding: 9px 12px; border-radius: 8px; margin-bottom: 12px; }
.info-box { background: var(--blue-bg); color: var(--blue); padding: 9px 12px; border-radius: 8px; margin-bottom: 12px; }
.secret { font-family: ui-monospace, Consolas, monospace; font-size: 16px; background: var(--surface-2); padding: 10px; border-radius: 8px; user-select: all; text-align: center; }
.inline-form { display: flex; gap: 8px; align-items: flex-end; flex-wrap: wrap; }
.inline-form .field { flex: 1; min-width: 120px; }

/* Auth */
.auth { min-height: 100vh; display: grid; place-items: center; padding: 20px; background: linear-gradient(160deg, var(--nav-bg) 0%, #3a1512 100%); }
.auth .card { width: 100%; max-width: 400px; padding: 28px; }
.auth .brand { color: var(--text); padding: 0 0 18px; }
.auth .brand small { color: var(--muted); }
.auth form > * + * { margin-top: 12px; }
.auth .btn { width: 100%; justify-content: center; padding: 10px; }

/* Tabs */
.tabs { display: flex; gap: 4px; border-bottom: 1px solid var(--border); margin-bottom: 14px; flex-wrap: wrap; }
.tabs button { border: 0; background: transparent; padding: 9px 14px; cursor: pointer; border-bottom: 2px solid transparent; color: var(--muted); font-weight: 600; }
.tabs button.active { color: var(--accent); border-bottom-color: var(--accent); }
.tabs a { padding: 9px 14px; border-bottom: 2px solid transparent; color: var(--muted); font-weight: 600; text-decoration: none; }
.tabs a:hover { color: var(--text, inherit); }
.tabs a.active { color: var(--accent); border-bottom-color: var(--accent); }
.qm-hub-tabs { margin-top: -4px; }

/* Workflow */
.steps { display: flex; gap: 0; margin: 4px 0 16px; flex-wrap: wrap; }
.step { flex: 1; min-width: 140px; padding: 10px 12px; border: 1px solid var(--border); background: var(--surface-2); position: relative; }
.step:first-child { border-radius: 8px 0 0 8px; }
.step:last-child { border-radius: 0 8px 8px 0; }
.step .n { font-size: 11px; color: var(--muted); text-transform: uppercase; }
.step.done { background: var(--green-bg); border-color: var(--green); }
.step.current { background: var(--amber-bg); border-color: #e0a100; }
.step.stopped { background: var(--red-bg); border-color: var(--red); }
.kv { display: grid; grid-template-columns: 180px 1fr; gap: 6px 14px; margin: 0; }
.kv dt { color: var(--muted); font-weight: 600; }
.kv dd { margin: 0; white-space: pre-wrap; }
.timeline { list-style: none; padding: 0; margin: 0; }
.timeline li { padding: 8px 0 8px 14px; border-left: 2px solid var(--border); margin-left: 4px; }
.timeline .when { color: var(--muted); font-size: 12px; }
.tpl-cards { display: grid; grid-template-columns: repeat(auto-fill, minmax(220px, 1fr)); gap: 10px; }
.tpl-card { text-align: left; border: 1px solid var(--border); border-radius: var(--radius); background: var(--surface); padding: 12px; cursor: pointer; }
.tpl-card:hover { border-color: var(--accent); }
.tpl-card .cat { font-size: 11px; text-transform: uppercase; color: var(--accent); font-weight: 700; }
.editor-row { display: grid; gap: 8px; align-items: center; padding: 8px; border: 1px solid var(--border); border-radius: 8px; margin-bottom: 8px; background: var(--surface-2); }
.editor-row.field-row { grid-template-columns: 2fr 1fr 2fr auto auto; }
.editor-row.step-row { grid-template-columns: 1fr 3fr auto; align-items: start; }
.roles-pick { display: flex; flex-wrap: wrap; gap: 4px 12px; font-size: 13px; }

/* Settings */
.settings-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(420px, 1fr)); gap: 16px; }
.settings-grid .card + .card { margin-top: 0; }
.settings-grid .card > * + * { margin-top: 10px; }
.status-pill { font-size: 12px; }
details.help { background: var(--surface-2); border-radius: 8px; padding: 8px 12px; font-size: 13px; }
details.help summary { cursor: pointer; font-weight: 600; }
details.help ol { padding-left: 18px; margin: 8px 0 0; }

/* Toast */
#toast { position: fixed; bottom: 20px; right: 20px; display: grid; gap: 8px; z-index: 100; }
.toast { background: var(--nav-bg); color: #fff; padding: 10px 16px; border-radius: 8px; box-shadow: var(--shadow); max-width: 420px; }
.toast.err { background: var(--red); }

.auth-links { margin-top: 12px; text-align: center; }

.level-picks { display: grid; grid-template-columns: repeat(auto-fill, minmax(230px, 1fr)); gap: 6px 14px; }
.level-pick { display: flex; align-items: center; justify-content: space-between; gap: 8px; font-size: 13px; }
.level-pick select { width: auto; min-width: 150px; }

/* Photos chosen on a new request */
.photo-picks { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 8px; }
.photo-pick { display: inline-flex; align-items: center; gap: 6px; border: 1px solid var(--border); border-radius: 8px; padding: 4px 6px; max-width: 260px; }
.photo-pick img { width: 48px; height: 48px; object-fit: cover; border-radius: 6px; }
.photo-pick .hint { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

/* Printing / Save as PDF: only the print view is shown, always black on white */
#print-root { display: none; }
@media print {
  @page { margin: 14mm; }
  body { background: #fff !important; }
  #app, #modal-root, #toast { display: none !important; }
  #print-root { display: block; color: #000; font: 11pt/1.4 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif; }
  .print-head { display: flex; align-items: center; gap: 12px; border-bottom: 2px solid #b42318; padding-bottom: 8px; margin-bottom: 12px; }
  .print-head img { width: 36px; height: 36px; }
  .print-titles { flex: 1; }
  .print-dept { font-size: 10pt; color: #444; }
  .print-head h1 { font-size: 17pt; margin: 0; }
  .print-meta { font-size: 8.5pt; color: #555; text-align: right; }
  .print-status { font-weight: 700; margin-bottom: 8px; }
  #print-root h2 { font-size: 12pt; margin: 14px 0 6px; border-bottom: 1px solid #999; padding-bottom: 2px; break-after: avoid; }
  .print-kv, .print-grid { width: 100%; border-collapse: collapse; }
  .print-kv th { width: 32%; text-align: left; font-weight: 600; color: #333; vertical-align: top; }
  .print-kv th, .print-kv td, .print-grid th, .print-grid td { border: 1px solid #bbb; padding: 4px 6px; vertical-align: top; white-space: pre-wrap; }
  .print-grid th { background: #eee; text-align: left; }
  .print-grid tr, .print-kv tr { break-inside: avoid; }
  .print-comments { padding-left: 18px; }
  .print-photos { display: grid; grid-template-columns: repeat(2, 1fr); gap: 8px; }
  .print-photos figure { margin: 0; break-inside: avoid; }
  .print-photos img { width: 100%; max-height: 90mm; object-fit: contain; border: 1px solid #ccc; }
  .print-photos figcaption { font-size: 8.5pt; color: #555; }
  .print-foot { font-size: 9pt; color: #555; margin-top: 12px; }
}
.picklist { display: block; }
.picklist .add-new { display: flex; gap: 6px; flex-wrap: wrap; align-items: center; margin-top: 6px; }
.picklist .add-new[hidden] { display: none; }
.picklist .add-new input { flex: 1; min-width: 140px; }
.picklist .add-new .hint { flex-basis: 100%; }
.mono { font-family: ui-monospace, SFMono-Regular, Consolas, monospace; font-size: 12px; white-space: nowrap; }
.kv.compact { grid-template-columns: 1fr; gap: 2px; margin-bottom: 12px; }
.kv.compact dd { margin-bottom: 6px; }

/* Workflow routes */
ol.route { margin: 6px 0 0; padding-left: 20px; }
.hint.warn, .warn-line { color: var(--amber); }
.warn-line { background: var(--amber-bg); border-radius: 6px; padding: 4px 8px; margin: 4px 0 8px; font-size: 13px; }
.step-who select { margin-bottom: 6px; max-width: 100%; }
ul.plain { list-style: none; padding: 0; margin: 0; display: grid; gap: 6px; }

/* Chain of command */
.pills { display: flex; flex-wrap: wrap; gap: 6px; }
.person-pill { display: inline-flex; align-items: center; gap: 6px; padding: 3px 10px; border-radius: 99px; background: var(--surface-2);
  border: 1px solid var(--border); color: var(--text); text-decoration: none; font-size: 13px; }
.person-pill:hover { border-color: var(--accent); }
.person-pill .pr { color: var(--muted); font-size: 12px; }
.person-pill .nl { color: var(--amber); font-size: 11px; font-weight: 600; }
.person-pill.no-login { border-style: dashed; }

/* Roles (assign users to a role) */
.role-group { padding: 0; overflow: hidden; }
.role-group-head { background: var(--surface-2); padding: 8px 16px; font-weight: 700; font-size: 13px; border-bottom: 1px solid var(--border); }
.role-row { display: grid; grid-template-columns: auto 1fr auto; gap: 14px; align-items: center; padding: 10px 16px; border-bottom: 1px solid var(--border); }
.role-row:last-child { border-bottom: 0; }
.role-desc { margin-top: 4px; }
.info-btn { width: 30px; height: 30px; border-radius: 6px; border: 1px solid var(--border); background: var(--surface-2); font: italic 700 15px Georgia, serif;
  color: var(--text); cursor: pointer; }
.info-btn:hover { border-color: var(--accent); }
.assign-tools input[type=search] { flex: 1; min-width: 180px; }
.assign-list { border: 1px solid var(--border); border-radius: 8px; max-height: 55vh; overflow-y: auto; }
.assign-row { display: flex; justify-content: space-between; align-items: center; gap: 12px; padding: 9px 14px; border-bottom: 1px solid var(--border); }
.assign-row:last-child { border-bottom: 0; }
.assign-row.changed { background: var(--amber-bg); }
.switch { position: relative; display: inline-flex; align-items: center; width: 74px; height: 30px; border-radius: 99px; border: 1px solid var(--border);
  background: var(--gray-bg); cursor: pointer; padding: 0 10px 0 34px; flex: none; transition: background .15s, padding .15s; }
.switch .knob { position: absolute; left: 3px; top: 3px; width: 22px; height: 22px; border-radius: 50%; background: #fff; box-shadow: 0 1px 3px rgba(0,0,0,.3); transition: left .15s; }
.switch .switch-text { font-size: 11px; font-weight: 700; color: var(--muted); }
.switch.on { background: var(--green); border-color: var(--green); padding: 0 34px 0 12px; }
.switch.on .knob { left: 47px; }
.switch.on .switch-text { color: #fff; }
.switch:disabled { opacity: .45; cursor: not-allowed; }
.switch:focus-visible, .info-btn:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }

/* Personnel record page */
.rec-top { display: flex; align-items: center; gap: 12px; margin-bottom: 8px; }
.rec-title { flex: 1; min-width: 0; }
.rec-title .hint { margin: 0; }
.rec-title strong { font-size: 17px; }
.rec-hero { text-align: center; padding: 8px 0 18px; }
.rec-hero h1 { font-size: 30px; margin: 10px 0 2px; }
.avatar-wrap { display: inline-flex; flex-direction: column; align-items: center; gap: 8px; }
.avatar { width: 112px; height: 112px; border-radius: 22px; background: var(--surface-2); border: 1px solid var(--border);
  display: grid; place-items: center; font-size: 38px; font-weight: 700; color: var(--muted); object-fit: cover; }
.rec-body { display: grid; grid-template-columns: 220px minmax(0, 1fr); gap: 20px; align-items: start; max-width: 1100px; margin: 0 auto; }
.rec-nav { display: flex; flex-direction: column; gap: 2px; background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius);
  padding: 6px; position: sticky; top: 70px; }
.rec-nav button { text-align: left; border: 0; background: transparent; padding: 9px 12px; border-radius: 7px; cursor: pointer; font-weight: 600; color: var(--text); }
.rec-nav button:hover { background: var(--surface-2); }
.rec-nav button.active { background: var(--accent-soft); color: var(--accent); }
.rec-content { display: grid; grid-template-columns: minmax(0, 1fr); gap: 16px; }
.rec-content .card + .card { margin-top: 0; }
.rec-card .kv { grid-template-columns: 200px 1fr; }
.rec-actions { justify-content: flex-end; }
.timeline.compact li { padding: 4px 0 4px 12px; }
.linkish { border: 0; background: none; padding: 0; color: var(--blue); cursor: pointer; font: inherit; font-size: 13px; }
.linkish:hover { text-decoration: underline; }
.danger-text { color: var(--red); }
.cert-list, .files { list-style: none; padding: 0; margin: 0; }
.cert-item { display: grid; grid-template-columns: 56px 1fr; gap: 14px; padding: 12px 0; border-bottom: 1px solid var(--border); }
.cert-item:last-child { border-bottom: 0; }
.cert-thumb, .file-thumb { width: 56px; height: 56px; border-radius: 8px; object-fit: cover; border: 1px solid var(--border); background: var(--surface-2); }
.cert-thumb.icon, .file-thumb.icon { display: grid; place-items: center; font-size: 22px; }
.cert-links { display: flex; gap: 14px; flex-wrap: wrap; margin: 2px 0; }
.files li { display: grid; grid-template-columns: 56px 1fr auto; gap: 12px; align-items: center; padding: 8px 0; border-bottom: 1px solid var(--border); }
.files li:last-child { border-bottom: 0; }
.file-main { min-width: 0; overflow-wrap: anywhere; }
.upload-form { margin-top: 10px; }
.note-body { white-space: pre-wrap; }

@media (max-width: 960px) {
  .rec-body { grid-template-columns: 1fr; }
  .rec-nav { position: static; flex-direction: row; overflow-x: auto; }
  .rec-nav button { white-space: nowrap; }
  .rec-card .kv { grid-template-columns: 1fr; }
  .rec-hero h1 { font-size: 24px; }
  .role-row { grid-template-columns: auto 1fr; }
  .role-row > .btn { grid-column: 1 / -1; }
}

@media (max-width: 960px) {
  .shell { grid-template-columns: 1fr; }
  .sidebar { position: fixed; left: 0; top: 0; bottom: 0; width: 260px; transform: translateX(-100%); transition: transform .2s; z-index: 40; }
  .shell.nav-open .sidebar { transform: none; box-shadow: var(--shadow); }
  .menu-btn { display: inline-flex; }
  .grid-2 { grid-template-columns: 1fr; }
  .content { padding: 16px; }
  .topbar { padding: 10px 16px; }
  .form-grid { grid-template-columns: 1fr; }
  .kv { grid-template-columns: 1fr; }
  .kv dd { margin-bottom: 8px; }
  .toolbar input[type=search] { width: 100%; }
  .settings-grid { grid-template-columns: 1fr; }
  .editor-row.field-row, .editor-row.step-row { grid-template-columns: 1fr; }
  .topbar .who .badge, .topbar .who .muted { display: none; }
}

/* ---------- Quartermaster ---------- */
.badge.qm-gray { background: var(--gray-bg); color: var(--gray); }
.badge.qm-blue { background: var(--blue-bg); color: var(--blue); }
.badge.qm-amber { background: var(--amber-bg); color: var(--amber); }
.badge.qm-green { background: var(--green-bg); color: var(--green); }
.badge.qm-red { background: var(--red-bg); color: var(--red); }
.qm-form { max-width: 980px; }
.qm-form h2 { font-size: 16px; border-bottom: 2px solid var(--border); padding-bottom: 6px; margin: 20px 0 10px; }
.qm-head { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 12px; }
.qm-head input[readonly] { background: var(--gray-bg); }
.qm-head .field { min-width: 0; }
.qm-head input, .qm-head select { width: 100%; min-width: 0; box-sizing: border-box; }
.qm-lines { display: flex; flex-direction: column; gap: 8px; margin-bottom: 10px; }
.qm-line { display: grid; grid-template-columns: minmax(0, 1.1fr) minmax(0, 2.4fr) 80px 120px 36px; gap: 8px; align-items: end;
  padding-bottom: 8px; border-bottom: 1px dashed var(--border); }
.qm-line label { display: flex; flex-direction: column; gap: 4px; font-size: 12px; font-weight: 600; color: var(--muted); }
.qm-line select, .qm-line input { min-width: 0; width: 100%; }
.qm-max { font-size: 13px; padding: 0 0 9px; color: var(--muted); }
.qm-max.over { color: var(--red); font-weight: 700; }
.qm-remove { height: 36px; color: var(--red); }
.qm-line-note { grid-column: 1 / -1; font-size: 12px; color: var(--muted); }
.qm-line-note:empty { display: none; }
.qm-line-note.warn, .hint.warn { color: var(--red); }
textarea.qm-grow { width: 100%; box-sizing: border-box; resize: none; overflow: hidden; min-height: 76px; }
.qm-actions { margin-top: 12px; justify-content: flex-end; }
.qm-status-line { display: flex; gap: 6px; margin: 4px 0 12px; }
.qm-notes { white-space: pre-wrap; }
.qm-num { width: 80px; }
.qm-detail-lines input[type=text] { min-width: 160px; }
.qm-flag { color: var(--red); }
.qm-filters { margin-bottom: 12px; }
.qm-ev { margin: 4px 0; padding-left: 18px; font-size: 13px; color: var(--muted); }
td.low { color: var(--red); font-weight: 700; }
@media (max-width: 760px) {
  .qm-head { grid-template-columns: 1fr 1fr; }
  .qm-line { grid-template-columns: 1fr 1fr 70px; }
  .qm-line .qm-max { grid-column: 1 / 3; padding: 0; }
  .qm-line .qm-remove { grid-column: 3; }
}
@media print { .qm-actions, .qm-remove { display: none !important; } }

/* Form designer: request forms laid out on a 12-column grid */
.lay-grid { display: grid; grid-template-columns: repeat(12, minmax(0, 1fr)); gap: 12px 16px; }
.lf { grid-column: span 12; min-width: 0; }
.lf.w-three_quarters { grid-column: span 9; }
.lf.w-two_thirds { grid-column: span 8; }
.lf.w-half { grid-column: span 6; }
.lf.w-third { grid-column: span 4; }
.lf.w-quarter { grid-column: span 3; }
.lf[hidden] { display: none; }
.lf > label, .lf-label { display: block; font-size: 12px; font-weight: 600; color: var(--muted); margin-bottom: 4px; }
.lf input:not([type=checkbox]):not([type=radio]):not([type=file]), .lf select, .lf textarea { width: 100%; min-width: 0; box-sizing: border-box; }
.lf textarea { resize: vertical; overflow: hidden; }
.lf-section h3 { margin: 10px 0 0; padding-bottom: 4px; border-bottom: 1px solid var(--border); }
.lf-section p { margin: 6px 0 0; }
.lf-text { white-space: pre-wrap; }
.lf-block { background: var(--surface-2); border-radius: 8px; padding: 8px 12px; font-size: 13px; }
.lf-block strong { display: block; margin-bottom: 2px; }
.lf-choices { display: flex; flex-wrap: wrap; gap: 4px 16px; padding: 4px 0; }
.lf-single { font-weight: 600; padding-top: 18px; }
.lf-value { white-space: pre-wrap; overflow-wrap: anywhere; }
.lf-tbl { width: 100%; border-collapse: collapse; }
.lf-tbl th { font-size: 12px; text-align: left; color: var(--muted); padding: 4px; }
.lf-tbl td { padding: 3px 4px; border-top: 1px solid var(--border); vertical-align: middle; }
.lf-tbl td input:not([type=checkbox]), .lf-tbl td select { min-width: 90px; }
.lf-tbl .lf-tbl-x { width: 32px; text-align: center; }
.lf-tbl.view td { white-space: pre-wrap; }
.lf-table > .btn { margin-top: 6px; }
.lf-extra { margin-top: 14px; }
.sig-pad { display: block; width: 100%; max-width: 600px; height: auto; aspect-ratio: 600 / 160; background: #fff; border: 1px solid var(--border); border-radius: 8px; touch-action: none; cursor: crosshair; }
.sig-foot { display: flex; justify-content: space-between; align-items: center; gap: 8px; max-width: 600px; flex-wrap: wrap; margin-top: 4px; }
.sig-view img { display: block; width: 100%; max-width: 300px; background: #fff; border: 1px solid var(--border); border-radius: 6px; }
@media (max-width: 640px) { .lay-grid > .lf { grid-column: span 12; } }

/* Template editor */
.fd-head { display: flex; align-items: center; justify-content: space-between; gap: 8px; flex-wrap: wrap; }
.fd-card { border: 1px solid var(--border); border-radius: 8px; background: var(--surface-2); padding: 8px; margin-bottom: 8px; }
.fd-card.fd-t-section { border-left: 4px solid var(--accent); }
.fd-card.fd-t-text_block { border-left: 4px solid var(--blue); }
.fd-row { display: grid; grid-template-columns: minmax(0, 2fr) minmax(0, 1.4fr) minmax(0, 0.9fr) auto auto; gap: 8px; align-items: center; }
.fd-row > input, .fd-row > select { width: 100%; min-width: 0; box-sizing: border-box; }
.fd-tools { display: flex; gap: 2px; }
.fd-icon { min-width: 28px; }
.fd-icon[disabled] { opacity: .35; cursor: default; }
.fd-more summary { cursor: pointer; font-size: 12px; color: var(--muted); margin-top: 6px; }
.fd-more-body { display: grid; grid-template-columns: repeat(auto-fill, minmax(220px, 1fr)); gap: 8px 12px; margin-top: 8px; }
.fd-more-body .wide { grid-column: 1 / -1; }
.fd-more-body input, .fd-more-body select, .fd-more-body textarea { width: 100%; min-width: 0; box-sizing: border-box; }
.fd-rule { display: grid; grid-template-columns: minmax(0, 2fr) minmax(0, 1fr) minmax(0, 1.5fr); gap: 6px; }
.fd-col { display: grid; grid-template-columns: minmax(0, 2fr) minmax(0, 1fr) minmax(0, 2fr) auto auto auto; gap: 6px; align-items: center; margin-bottom: 6px; }
.fd-col input, .fd-col select { width: 100%; min-width: 0; box-sizing: border-box; }
.fd-add { display: flex; flex-wrap: wrap; gap: 6px; margin: 4px 0 8px; }
.fd-options { display: flex; flex-wrap: wrap; gap: 8px 18px; align-items: flex-end; margin: 8px 0; }
.fd-options .field { min-width: 200px; }
.fd-pre { white-space: pre-wrap; max-height: 260px; overflow: auto; }
@media (max-width: 700px) {
  .fd-row { grid-template-columns: 1fr 1fr; }
  .fd-row > input { grid-column: 1 / -1; }
  .fd-rule, .fd-col { grid-template-columns: 1fr 1fr; }
}
@media print {
  #print-root .lay-grid { gap: 6px 12px; }
  #print-root .lf-label { color: #333; font-size: 9pt; }
  #print-root .lf { break-inside: avoid; border-bottom: 1px solid #ddd; padding-bottom: 3px; }
  #print-root .lf-section { border-bottom: 0; }
  #print-root .lf-section h3 { font-size: 11pt; border-bottom: 1px solid #999; }
  #print-root .lf-tbl th, #print-root .lf-tbl td { border: 1px solid #bbb; padding: 3px 5px; color: #000; }
  #print-root .photo-pick { border-color: #ccc; }
}.fd-col .check, .fd-row .check { display: flex; align-items: center; gap: 4px; white-space: nowrap; }

/* ---------- form Help / Instructions (help.js) ---------- */
.fh-open-btn { display: inline-flex; align-items: center; gap: 6px; }
.fh-q, .fh-tip { display: inline-grid; place-items: center; width: 18px; height: 18px; border-radius: 50%; font-size: 12px; font-weight: 700; line-height: 1; }
.fh-q { background: var(--blue-bg); color: var(--blue); }
.fh-tip { border: 1px solid var(--blue); background: var(--surface); color: var(--blue); cursor: pointer; padding: 0; margin-left: 6px; vertical-align: middle; }
.fh-tip:hover, .fh-tip[aria-expanded="true"] { background: var(--blue); color: var(--surface); }
.fh-tip:focus-visible, .fh-open-btn:focus-visible, .fh-sec summary:focus-visible { outline: 2px solid var(--blue); outline-offset: 2px; }
.fh-tip[hidden] { display: none; }
.fh-pop { position: fixed; z-index: 60; background: var(--surface); color: var(--text); border: 1px solid var(--border); border-radius: 8px; box-shadow: var(--shadow); padding: 10px 12px; font-size: 13px; display: grid; gap: 6px; }
.fh-pop .linkish { justify-self: start; }
.fh-shade { position: fixed; inset: 0; background: rgba(10, 14, 20, .4); z-index: 45; }
.fh-drawer { position: fixed; top: 0; right: 0; bottom: 0; width: min(480px, 100vw); z-index: 46; background: var(--surface); box-shadow: var(--shadow); display: flex; flex-direction: column; outline: none; }
.fh-head { display: flex; align-items: flex-start; justify-content: space-between; gap: 8px; padding: 16px 16px 12px 20px; border-bottom: 1px solid var(--border); }
.fh-body { overflow-y: auto; padding: 14px 20px 24px; flex: 1; }
.fh-meta { font-size: 12px; color: var(--muted); margin-bottom: 10px; }
.fh-tools { display: flex; flex-wrap: wrap; gap: 6px; margin-bottom: 10px; }
.fh-sec { border: 1px solid var(--border); border-radius: 8px; margin-bottom: 8px; background: var(--surface); }
.fh-sec summary { cursor: pointer; padding: 10px 12px; font-weight: 600; }
.fh-sec[open] summary { border-bottom: 1px solid var(--border); }
.fh-text { padding: 4px 14px 8px; }
.fh-text p { margin: 8px 0; }
.fh-text ul, .fh-text ol { margin: 8px 0; padding-left: 22px; }
.fh-text li { margin: 4px 0; }
.fh-foot { margin-top: 14px; }
.warn-box { background: var(--amber-bg); color: var(--amber); padding: 9px 12px; border-radius: 8px; margin-bottom: 12px; }
body.fh-locked { overflow: hidden; }
.fh-label { display: flex; align-items: center; margin-bottom: 4px; }
.field .fh-label label { margin-bottom: 0; }
h2 .fh-tip { font-size: 12px; }
.fh-edit-sec { border: 1px solid var(--border); border-radius: 8px; padding: 8px; margin-bottom: 8px; display: grid; gap: 6px; }
.fh-edit-row { display: flex; gap: 4px; align-items: center; }
.fh-edit-row input { flex: 1; min-width: 0; }
.fh-area { width: 100%; resize: vertical; overflow: hidden; }
.fh-revs { margin-top: 16px; }
.fh-revs ul { padding-left: 18px; }
.fh-revs li { margin: 6px 0; display: grid; gap: 4px; justify-items: start; }
@media (max-width: 640px) {
  .fh-drawer { width: 100vw; }
  .fh-head { padding: 12px 12px 10px 16px; }
  .fh-body { padding: 12px 16px 20px; }
}
@media print { .fh-tip, .fh-open-btn, .fh-drawer, .fh-shade, .fh-pop { display: none !important; } }
/* ---------- Quartermaster forms (qmforms.js) ---------- */
.qmf-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(280px, 1fr)); gap: 12px; }
.qmf-card { display: grid; gap: 8px; align-content: start; }
.qmf-card-head { display: flex; justify-content: space-between; align-items: flex-start; gap: 8px; }
.qmf-grid3 { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 12px; margin-top: 10px; }
.qmf-grid3 .field { min-width: 0; }
.qmf-grid3 .w2 { grid-column: span 2; }
.qmf-grid3 .w3 { grid-column: 1 / -1; }
.qmf-grid3 input, .qmf-grid3 select, .qmf-grid3 textarea { width: 100%; min-width: 0; box-sizing: border-box; }
.qmf-ro { padding: 7px 0; min-height: 34px; white-space: pre-wrap; }
.qmf-checks { display: flex; flex-wrap: wrap; gap: 6px 16px; padding: 4px 0; }
.qmf-lines td { vertical-align: top; }
.qmf-lines select, .qmf-lines input[type=text] { width: 100%; min-width: 120px; box-sizing: border-box; }
.qmf-item { min-width: 220px; display: grid; gap: 4px; }
.qmf-sys { margin-top: 12px; }
.req { color: var(--red); }
@media (max-width: 760px) {
  .qmf-grid3 { grid-template-columns: 1fr 1fr; }
  .qmf-grid3 .w2, .qmf-grid3 .w3 { grid-column: 1 / -1; }
}
@media (max-width: 480px) { .qmf-grid3 { grid-template-columns: 1fr; } }
@media print {
  .print-instructions { break-before: page; }
  .print-instructions h1 { font-size: 15pt; margin: 4px 0 8px; }
  .print-instr-sec { break-inside: avoid; }
  .print-instr-sec p, .print-instr-sec li { margin: 3px 0; }
}.rec-top { flex-wrap: wrap; }
.rec-title { min-width: 220px; }
@media (max-width: 640px) {
  .rec-title { flex: 1 1 calc(100% - 60px); }
  .rec-top > .toolbar { width: 100%; }
}.qmf-checklist { list-style: none; padding-left: 0; margin: 8px 0 12px; display: grid; gap: 4px; }
.qmf-checklist .qmf-ok { color: var(--green); }
.qmf-checklist .qmf-todo { color: var(--amber); font-weight: 600; }
.qmf-total { font-weight: 700; }.qmf-sigs { display: grid; grid-template-columns: repeat(auto-fill, minmax(240px, 1fr)); gap: 12px; margin-top: 10px; }
.qmf-sig { border: 1px solid var(--border); border-radius: 8px; padding: 10px; display: grid; gap: 2px; }
.qmf-sig .sig-view { max-width: 100%; max-height: 90px; background: #fff; border: 1px solid var(--border); border-radius: 4px; margin-top: 4px; }
@media print { #print-root .qmf-sig { border: 1px solid #bbb; break-inside: avoid; } #print-root .qmf-sigs { grid-template-columns: 1fr 1fr; } }.qmf-var { font-weight: 700; color: var(--red); }
/* ---------- barcode labels & scanning (scan.js) ---------- */
.lbl { box-sizing: border-box; width: 2in; height: 1in; padding: 0.05in 0.08in; display: flex; flex-direction: column;
  overflow: hidden; background: #fff; color: #000; font: 7pt/1.15 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif; }
.lbl-name { font-weight: 700; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.lbl-bar { flex: 1; min-height: 0; padding: 0.02in 0; }
.lbl-bar .c128 { display: block; width: 100%; height: 100%; }
.lbl-bar .c128 path { fill: #000; }
.lbl-foot { display: flex; gap: 6px; align-items: baseline; white-space: nowrap; overflow: hidden; }
.lbl-code { font: 700 8pt ui-monospace, Consolas, monospace; letter-spacing: 0.04em; }
.lbl-sub { font-size: 6pt; overflow: hidden; text-overflow: ellipsis; }
.lbl-err { color: #b42318; font-size: 7pt; }
.lbl-preview { display: flex; flex-wrap: wrap; gap: 10px; }
.lbl-preview .lbl { border: 1px dashed #999; border-radius: 3px; }
.lbl-tools { margin: 10px 0; align-items: center; }
.lbl-layout { align-items: start; }
input.narrow { width: 5em; }
@media print {
  #print-root.labels { font: inherit; }
  #print-root.labels .lbl { break-after: page; page-break-after: always; }
  #print-root.labels .lbl:last-child { break-after: auto; page-break-after: auto; }
}
.scan-box { display: grid; gap: 8px; }
.scan-row { display: flex; gap: 8px; }
.scan-input { flex: 1; font: 600 1.15rem ui-monospace, Consolas, monospace; padding: 10px 12px; min-width: 0; }
.scan-video { width: 100%; max-height: 50vh; object-fit: cover; border-radius: 8px; background: #000; }
.scan-card { display: grid; gap: 10px; }
.scan-head { display: flex; justify-content: space-between; align-items: flex-start; gap: 10px; }
.scan-head h2 { margin: 2px 0 0; }
.scan-qty { text-align: right; white-space: nowrap; }
.scan-qty strong { font-size: 1.6rem; }
.scan-sub { border-top: 1px solid var(--line, #ddd); padding-top: 8px; display: grid; gap: 8px; }
.scan-sub h3 { margin: 0; }
/* label sizes (preview; printing also gets the page size from /api/scan/labels-*.css) */
.lbl.s2_25x1_25 { width: 2.25in; height: 1.25in; }
.lbl.s3_5x1_125 { width: 3.5in; height: 1.125in; }
.lbl.s3x2 { width: 3in; height: 2in; font-size: 9pt; }
.lbl.ssheet5160 { width: 2.625in; height: 1in; padding: 0.08in 0.16in; }
.lbl-blank { width: 2.625in; height: 1in; }
.lbl-opts .lbl-opt-row { display: flex; flex-wrap: wrap; gap: 12px 24px; align-items: flex-start; }
.sheet-map { display: grid; grid-template-columns: repeat(3, 26px); gap: 3px; margin-top: 4px; }
.sheet-slot { width: 26px; height: 10px; padding: 0; border: 1px solid var(--line, #bbb); border-radius: 2px; background: transparent; cursor: pointer; }
.sheet-slot.used { background: repeating-linear-gradient(45deg, #ccc 0 2px, transparent 2px 4px); }
.sheet-slot.fill { background: #b42318; border-color: #b42318; }
.grid-gap { display: grid; gap: 12px; }
@media print {
  #print-root.sheet5160 { font: inherit; }
  #print-root.sheet5160 .sheet { box-sizing: border-box; width: 8.5in; height: 11in; overflow: hidden; padding: 0.5in 0 0 0.1875in;
    display: grid; grid-template-columns: repeat(3, 2.625in); column-gap: 0.125in; grid-auto-rows: 1in; align-content: start;
    break-after: page; page-break-after: always; }
  #print-root.sheet5160 .sheet:last-child { break-after: auto; page-break-after: auto; }
  #print-root.sheet5160 .lbl { width: 2.625in; height: 1in; padding: 0.08in 0.16in; }
}
.scan-list .warn-row td { background: rgba(217, 119, 6, 0.12); }
.scan-count { border: 1px dashed var(--line, #bbb); border-radius: 8px; padding: 10px; margin-bottom: 10px; display: grid; gap: 6px; }
.scan-count h3 { margin: 0; }
@keyframes scanHit { from { background: rgba(22, 163, 74, 0.35); } to { background: transparent; } }
tr.scan-hit td { animation: scanHit 1.2s ease-out; }
/* ---------- Actions & My Requests (actions.js) ---------- */
.tpl-card.action-card { text-decoration: none; color: inherit; display: flex; flex-direction: column; justify-content: flex-start; align-items: flex-start; gap: 2px; font: inherit; }
.action-card strong { display: block; }
.action-group h2 { margin-bottom: 2px; }
.action-group .tpl-cards { margin-top: 10px; }
.badge.type-workflow { background: rgba(37, 99, 235, 0.12); color: #1d4ed8; }
.badge.type-supply { background: rgba(22, 163, 74, 0.12); color: #15803d; }
.badge.type-qm { background: rgba(217, 119, 6, 0.14); color: #b45309; }