/* SWMS builder (/tools/swms-builder): wizard, hazard editor, risk matrix and the SWMS document */
.tool .btn { padding: 11px 16px; min-height: 46px; font-size: .9rem; }
.tool .btn-line { border-color: var(--asphalt); color: var(--asphalt); background: var(--white); }
.tool .btn-line:hover { background: var(--asphalt); color: var(--yellow); }
.sw-h { margin: 0; font-size: 1.15rem; font-weight: 800; font-family: var(--body); text-transform: none; letter-spacing: -.01em; }
.tx-src { margin: 0; font-size: .76rem; color: var(--steel); }

/* device bar */
.sw-bar { display: grid; gap: 10px; padding: 12px 14px; margin-bottom: 14px; border-radius: 14px; background: var(--concrete); }
.sw-saved { font-size: .84rem; font-weight: 700; color: #166534; }
.sw-bar-b, .sw-open { display: flex; flex-wrap: wrap; gap: 8px; align-items: end; }
.sw-open label { display: grid; gap: 4px; font-weight: 700; font-size: .84rem; flex: 1 1 220px; min-width: 0; }
.sw-open select { height: 44px; border: 1.5px solid var(--concrete-2); border-radius: 10px; padding: 0 10px; font: inherit; min-width: 0; width: 100%; background: var(--white); }
.sw-open[hidden] { display: none; }
.sw-file { position: relative; cursor: pointer; }
.sw-file input { position: absolute; inset: 0; opacity: 0; width: 100%; cursor: pointer; }
.sw-file:focus-within { outline: 3px solid rgba(255,106,0,.35); }

/* stepper */
.sw-steps { display: grid; grid-template-columns: repeat(5, minmax(0, 1fr)); gap: 6px; margin: 0 0 16px; scroll-margin-top: calc(var(--hdr, 72px) + 10px); }
.sw-steps button { display: grid; justify-items: center; gap: 4px; min-height: 56px; padding: 8px 4px; border: 1.5px solid var(--concrete-2); border-radius: 12px; background: var(--white); font: inherit; font-size: .76rem; font-weight: 700; color: var(--steel); cursor: pointer; line-height: 1.15; text-align: center; }
.sw-steps b { display: grid; place-items: center; width: 26px; height: 26px; border-radius: 50%; background: var(--concrete); color: var(--ink); font-size: .85rem; }
.sw-steps button[aria-current="step"] { border-color: var(--asphalt); background: var(--asphalt); color: var(--white); }
.sw-steps button[aria-current="step"] b { background: var(--yellow); color: var(--asphalt); }
@media (max-width: 560px) { .sw-steps span { font-size: .68rem; } .sw-steps button { padding: 6px 2px; } }

.sw-form section { display: grid; gap: 14px; min-width: 0; }
.sw-form section > *, .sw-preview > *, .sw-doc > * { min-width: 0; }
.sw-form section[hidden] { display: none; }
.sw-checks { display: grid; gap: 10px; }
.sw-checks small { color: var(--steel); font-weight: 600; font-size: .74rem; }
.sw-checks .check span { font-weight: 600; }
.sw-cols { grid-template-columns: repeat(auto-fill, minmax(220px, 1fr)); }
.tool-in .check { min-height: 32px; }

/* activity picker */
.sw-acts { display: grid; grid-template-columns: repeat(auto-fill, minmax(230px, 1fr)); gap: 8px; }
.sw-act-pick { display: flex !important; grid-template-columns: none; align-items: flex-start; gap: 10px !important; padding: 12px; border: 1.5px solid var(--concrete-2); border-radius: 12px; cursor: pointer; min-height: 60px; }
.sw-act-pick input { width: 20px; height: 20px; margin-top: 2px; accent-color: var(--orange); flex: none; }
.sw-act-pick span { display: grid; gap: 2px; }
.sw-act-pick small { color: var(--steel); font-weight: 600; font-size: .76rem; }
.sw-act-pick.on, .sw-act-pick:has(input:checked) { border-color: var(--asphalt); background: #fffbea; }
.sw-add { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; }
.sw-add input { flex: 1 1 220px; }
.sw-inline { display: flex !important; align-items: center; gap: 8px !important; }
.sw-inline input { width: 90px !important; }

/* risk matrix */
.sw-matrix-box > *, .sw-act > *, .sw-hz > * { min-width: 0; }
.sw-matrix-box { display: block; min-width: 0; max-width: 100%; overflow: hidden; border: 1.5px solid var(--concrete-2); border-radius: 14px; padding: 10px 12px; }
.sw-matrix-box > * + * { margin-top: 10px; }
.sw-matrix-box summary { font-weight: 800; cursor: pointer; min-height: 32px; display: flex; align-items: center; }
.sw-mx-scroll { overflow-x: auto; -webkit-overflow-scrolling: touch; max-width: 100%; }
.sw-mx { border-collapse: separate; border-spacing: 3px; width: 100%; min-width: 520px; font-size: .78rem; }
.sw-mx th { font-weight: 700; text-align: left; padding: 4px; vertical-align: bottom; color: var(--ink); }
.sw-mx thead th small { display: block; font-weight: 500; color: var(--steel); font-size: .68rem; }
.sw-mx td { position: relative; height: 46px; text-align: center; border-radius: 6px; font-weight: 700; }
.sw-mx td b { position: absolute; top: 3px; right: 3px; min-width: 20px; height: 20px; border-radius: 99px; background: rgba(0,0,0,.75); color: #fff; font-size: .72rem; display: grid; place-items: center; padding: 0 4px; }
.sw-rt-L { background: #bbf7d0; color: #14532d; } .sw-rt-M { background: #fde68a; color: #713f12; }
.sw-rt-H { background: #fb923c; color: #431407; } .sw-rt-E { background: #dc2626; color: #fff; }
.sw-rt { display: inline-block; padding: 3px 10px; border-radius: 99px; font-size: .78rem; font-weight: 800; }
.sw-mx-key { list-style: none; margin: 0; padding: 0; display: grid; gap: 6px; font-size: .82rem; }
.sw-mx-key .sw-rt { min-width: 70px; text-align: center; margin-right: 6px; }

/* hazards */
.sw-act { display: grid; gap: 10px; padding: 12px; border-radius: 16px; background: var(--concrete); }
.sw-act h4 { margin: 0; font-size: 1rem; font-weight: 800; }
.sw-hz { display: grid; gap: 10px; padding: 12px; border-radius: 12px; background: var(--white); border: 1px solid var(--concrete-2); }
.sw-hz-top { display: flex; gap: 10px; align-items: flex-start; }
.sw-hz-n { flex: none; padding: 4px 8px; border-radius: 8px; background: var(--asphalt); color: var(--yellow); font-weight: 800; font-size: .8rem; margin-top: 24px; }
.sw-grow { flex: 1; min-width: 0; }
.sw-hz textarea { min-height: 0 !important; field-sizing: content; }
.sw-rate { display: grid; grid-template-columns: minmax(0, 1fr) minmax(0, 1fr) auto; gap: 8px; align-items: end; }
.sw-rate-l { grid-column: 1 / -1; font-weight: 800; font-size: .8rem; text-transform: uppercase; letter-spacing: .05em; color: var(--steel); }
.sw-rate label { font-size: .8rem !important; }
.sw-rate [data-pill] { padding-bottom: 10px; }
.sw-ctrls { display: grid; gap: 6px; padding: 8px; border-radius: 10px; background: #f8fafc; border: 1px dashed var(--concrete-2); }
.sw-ctrl { display: grid; grid-template-columns: 24px 132px minmax(0, 1fr) 36px; gap: 6px; align-items: center; }
.sw-ctrl input[type="checkbox"] { width: 20px; height: 20px; accent-color: var(--orange); margin: 0; }
.sw-ctrl select { height: 40px !important; font-size: .8rem !important; padding: 0 6px !important; }
.sw-ctrl textarea { min-height: 40px !important; padding: 8px 10px !important; font-size: .86rem; font-weight: 500 !important; }
.sw-ctrl button { height: 36px; border: 1.5px solid var(--concrete-2); border-radius: 8px; background: var(--white); font-size: 1.1rem; cursor: pointer; }
.sw-ctrl.off textarea, .sw-ctrl.off select { opacity: .45; text-decoration: line-through; }
.sw-ctrl-new { grid-template-columns: 24px 132px minmax(0, 1fr) auto; }
.sw-ctrl-new > span { text-align: center; font-weight: 800; color: var(--steel); }
.sw-ctrl-new .btn { min-height: 40px; padding: 6px 12px; }
@media (max-width: 560px) {
  .sw-ctrl { grid-template-columns: 24px minmax(0, 1fr) 36px; }
  .sw-ctrl select { grid-column: 2; } .sw-ctrl textarea { grid-column: 1 / -1; } .sw-ctrl button { grid-column: 3; grid-row: 1; }
  .sw-ctrl-new { grid-template-columns: 24px minmax(0, 1fr); } .sw-ctrl-new input { grid-column: 1 / -1; } .sw-ctrl-new .btn { grid-column: 1 / -1; }
  .sw-rate { grid-template-columns: 1fr 1fr; } .sw-rate [data-pill] { grid-column: 1 / -1; padding: 0; }
  .sw-hz-n { margin-top: 0; }
  .sw-hz-top { flex-direction: column; gap: 4px; }
}
.sw-warn:empty { display: none; }
.sw-warn p { margin: 0 0 4px; padding: 8px 10px; border-radius: 8px; background: #fef2f2; color: #991b1b; font-size: .84rem; font-weight: 600; }
.sw-del-h { justify-self: start; font-size: .84rem; }
.sw-empty { padding: 16px; border: 1.5px dashed var(--concrete-2); border-radius: 12px; color: var(--steel); }

/* sign-on and checks */
.sw-signon { display: grid; gap: 8px; }
.sw-worker { display: grid; grid-template-columns: minmax(0, 1.3fr) minmax(0, 1fr) minmax(0, 1fr) 40px; gap: 6px; }
.sw-worker button { border: 1.5px solid var(--concrete-2); border-radius: 8px; background: var(--white); font-size: 1.1rem; cursor: pointer; }
@media (max-width: 560px) { .sw-worker { grid-template-columns: minmax(0, 1fr) 44px; } .sw-worker input:not(:first-child) { grid-column: 1; } .sw-worker button { grid-row: 1; grid-column: 2; } }
.sw-complete { list-style: none; margin: 0; padding: 0; display: grid; gap: 6px; }
.sw-complete li { display: flex; gap: 10px; align-items: flex-start; font-size: .88rem; font-weight: 600; }
.sw-complete li b { flex: none; width: 24px; height: 24px; border-radius: 50%; display: grid; place-items: center; color: #fff; font-size: .8rem; }
.sw-complete li.ok b { background: #16a34a; } .sw-complete li.no b { background: var(--red); }
.sw-complete small { color: var(--steel); }
.sw-nav { display: flex; justify-content: space-between; gap: 10px; padding-top: 6px; position: sticky; bottom: 0; background: linear-gradient(transparent, var(--white) 30%); padding-bottom: 8px; z-index: 2; }
.sw-nav .btn { flex: 1 1 0; max-width: 260px; }
.sw-nav .btn:disabled { opacity: .4; cursor: default; }

/* preview: a light page, not the dark result panel */
.sw-preview { margin-top: 26px; display: grid; gap: 10px; scroll-margin-top: calc(var(--hdr, 72px) + 10px); }
.tool-out.sw-out { position: static; background: var(--concrete); color: var(--ink); padding: clamp(10px, 2vw, 18px); }
.sw-out .out-note.alert { color: #991b1b; background: #fef2f2; border-color: #fecaca; }
.sw-out .out-note.good { color: #14532d; background: #f0fdf4; border-color: #bbf7d0; }
.sw-out .tw-actions { border-top-color: var(--concrete-2); }
.sw-out .tw-actions button { border: 1.5px solid var(--asphalt); background: var(--white); color: var(--asphalt); min-height: 44px; }
.sw-out .tw-actions button:hover { background: var(--asphalt); color: var(--yellow); }
.sw-out .tw-gate-blur { max-height: 700px; }

.sw-doc { background: var(--white); color: #111; border-radius: 10px; padding: clamp(12px, 3vw, 28px); font-size: .86rem; line-height: 1.45; box-shadow: 0 1px 3px rgba(0,0,0,.08); display: grid; gap: 8px; min-width: 0; overflow-wrap: anywhere; }
.sw-doc h3 { margin: 14px 0 2px; font-size: 1rem; font-family: var(--body); text-transform: none; letter-spacing: 0; padding-bottom: 4px; border-bottom: 2px solid var(--yellow); }
.sw-doc p, .sw-doc ul { margin: 0; }
.sw-doc ul { padding-left: 18px; }
.sw-d-title { display: flex; justify-content: space-between; gap: 12px; flex-wrap: wrap; padding: 12px 14px; background: var(--asphalt); color: #fff; border-radius: 8px; }
.sw-d-title b { display: block; font-size: 1.25rem; color: var(--yellow); }
.sw-d-no { text-align: right; font-size: .8rem; color: #d6dae0; }
.sw-doc table { border-collapse: collapse; width: 100%; }
.sw-doc th, .sw-doc td { border: 1px solid #cbd5e1; padding: 6px 8px; text-align: left; vertical-align: top; }
.sw-d-kv th { width: 34%; background: #f1f5f9; font-weight: 700; }
.sw-doc .sw-mx-scroll table.sw-d-hz { min-width: 540px; }
.sw-doc table.sw-d-hz td:nth-child(4) { min-width: 140px; }
.sw-d-hz thead th { background: var(--asphalt); color: #fff; font-size: .78rem; }
.sw-d-act td { background: #fffbea; font-weight: 800; }
.sw-d-r { text-align: center !important; white-space: nowrap; }
.sw-d-r b, .sw-d-r small { display: block; } .sw-d-r small { font-size: .7rem; opacity: .85; }
.sw-d-ctrls { margin: 0; padding-left: 18px; display: grid; gap: 3px; }
.sw-d-lines td { height: 30px; }
.sw-d-sign td { height: 34px; }
.sw-d-small { font-size: .76rem; color: #475569; }
.sw-d-disc { margin-top: 10px !important; padding: 8px 10px; border: 1px solid #fecaca; background: #fef2f2; border-radius: 6px; color: #7f1d1d; }
.sw-doc .sw-mx { min-width: 480px; }

/* print: kit.js printReport strips colours; put the risk colours back and lay the SWMS out on A4 */
@media print {
  body.tw-printing #tw-print .sw-doc { box-shadow: none; padding: 0; font-size: 9pt; display: block; }
  body.tw-printing #tw-print .sw-doc h3 { font-size: 11pt; margin: 12px 0 4px; border-bottom: 2px solid #ffc20e !important; break-after: avoid; }
  body.tw-printing #tw-print .sw-doc p, body.tw-printing #tw-print .sw-doc ul { margin: 0 0 6px; }
  body.tw-printing #tw-print .sw-d-title { border: 2px solid #000 !important; padding: 6px 8px; display: flex; justify-content: space-between; }
  body.tw-printing #tw-print .sw-d-title b { font-size: 15pt; }
  body.tw-printing #tw-print .sw-doc table, body.tw-printing #tw-print .sw-doc .sw-mx-scroll table.sw-d-hz { display: table; min-width: 0 !important; width: 100%; }
  body.tw-printing #tw-print .sw-mx-scroll { overflow: visible; }
  body.tw-printing #tw-print .sw-mx { min-width: 0; border-collapse: collapse; }
  body.tw-printing #tw-print .sw-mx td b { position: static; }
  body.tw-printing #tw-print .sw-rt-L, body.tw-printing #tw-print .sw-rt-M, body.tw-printing #tw-print .sw-rt-H, body.tw-printing #tw-print .sw-rt-E, body.tw-printing #tw-print .sw-d-act td, body.tw-printing #tw-print .sw-d-kv th, body.tw-printing #tw-print .sw-d-hz thead th { -webkit-print-color-adjust: exact; print-color-adjust: exact; }
  body.tw-printing #tw-print .sw-rt-L { background: #bbf7d0 !important; } body.tw-printing #tw-print .sw-rt-M { background: #fde68a !important; }
  body.tw-printing #tw-print .sw-rt-H { background: #fdba74 !important; } body.tw-printing #tw-print .sw-rt-E { background: #f87171 !important; }
  body.tw-printing #tw-print .sw-d-act td { background: #fef3c7 !important; } body.tw-printing #tw-print .sw-d-kv th, body.tw-printing #tw-print .sw-d-hz thead th { background: #e5e7eb !important; }
  body.tw-printing #tw-print .sw-d-hz tr, body.tw-printing #tw-print .sw-d-lines tr { break-inside: avoid; }
  body.tw-printing #tw-print .sw-d-break { break-before: page; }
  body.tw-printing #tw-print .sw-d-sign td { height: 9mm; }
  body.tw-printing #tw-print .sw-d-disc { border: 1px solid #000 !important; }
}
