:root {
  --bg: #f4f6f7;
  --surface: #ffffff;
  --surface-2: #f8fafa;
  --ink: #17242a;
  --ink-2: #4a5a61;
  --ink-3: #7b8a90;
  --line: #dfe5e7;
  --line-2: #eef2f3;
  --brand: #0e6e6e;
  --brand-ink: #ffffff;
  --brand-soft: #e3f2f1;
  --danger: #b42318;
  --danger-soft: #fdecea;
  --warn: #a15c00;
  --warn-soft: #fff4e0;
  --ok: #1b7a3d;
  --ok-soft: #e6f4ea;
  --info: #2851a3;
  --info-soft: #e8eefb;
  --radius: 10px;
  --shadow: 0 1px 2px rgba(16, 30, 36, .06), 0 2px 8px rgba(16, 30, 36, .04);
  --font: system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  --mono: ui-monospace, "Cascadia Mono", Consolas, monospace;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0f1719; --surface: #162125; --surface-2: #1b282c; --ink: #e6eef0; --ink-2: #b2c2c6;
    --ink-3: #82959a; --line: #2a3a3f; --line-2: #213034; --brand: #3fb5ad; --brand-ink: #062322;
    --brand-soft: #173a38; --danger: #ff8a7a; --danger-soft: #3a1d1a; --warn: #f0b45a; --warn-soft: #3a2c14;
    --ok: #6fd391; --ok-soft: #173322; --info: #9db8ff; --info-soft: #1c2742;
    --shadow: 0 1px 2px rgba(0,0,0,.3);
  }
}
* { box-sizing: border-box; }
html, body { margin: 0; }
body { background: var(--bg); color: var(--ink); font: 15px/1.5 var(--font); }
a { color: var(--brand); }
h1, h2, h3 { line-height: 1.25; margin: 0 0 .5rem; }
h1 { font-size: 1.5rem; }
h2 { font-size: 1.1rem; }
h3 { font-size: .95rem; }
[hidden] { display: none !important; }

/* top bar */
.topbar { position: sticky; top: 0; z-index: 10; display: flex; align-items: center; gap: 1.25rem;
  padding: .6rem 1.25rem; background: var(--surface); border-bottom: 1px solid var(--line); }
.brand { display: flex; align-items: center; gap: .55rem; font-weight: 650; color: var(--ink); text-decoration: none; white-space: nowrap; }
.brand-mark { display: grid; place-items: center; width: 28px; height: 28px; border-radius: 7px;
  background: var(--brand); color: var(--brand-ink); font-weight: 800; font-size: 1.1rem; }
.nav { display: flex; gap: .25rem; flex: 1; overflow-x: auto; }
.nav a { padding: .4rem .7rem; border-radius: 7px; color: var(--ink-2); text-decoration: none; white-space: nowrap; }
.nav a:hover { background: var(--line-2); }
.nav a.active { background: var(--brand-soft); color: var(--brand); font-weight: 600; }
.who { display: flex; align-items: center; gap: .6rem; font-size: .85rem; color: var(--ink-2); white-space: nowrap; }

.app { max-width: 1180px; margin: 0 auto; padding: 1.5rem 1.25rem 4rem; }
.loading { padding: 3rem; text-align: center; color: var(--ink-3); }

/* cards & layout */
.card { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); box-shadow: var(--shadow); }
.card-pad { padding: 1.25rem; }
.page-head { display: flex; align-items: flex-end; justify-content: space-between; gap: 1rem; flex-wrap: wrap; margin-bottom: 1.25rem; }
.page-head p { margin: .15rem 0 0; color: var(--ink-2); }
.grid { display: grid; gap: 1rem; }
.cols-2 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
.cols-3 { grid-template-columns: repeat(3, minmax(0, 1fr)); }
.cols-4 { grid-template-columns: repeat(4, minmax(0, 1fr)); }
.span-2 { grid-column: span 2; }
.span-all { grid-column: 1 / -1; }
.row { display: flex; gap: .6rem; align-items: center; flex-wrap: wrap; }
.spacer { flex: 1; }
.muted { color: var(--ink-3); }
.small { font-size: .85rem; }

/* stats */
.stats { display: grid; grid-template-columns: repeat(auto-fit, minmax(160px, 1fr)); gap: .75rem; margin-bottom: 1.25rem; }
.stat { padding: .9rem 1rem; }
.stat .n { font-size: 1.7rem; font-weight: 700; font-variant-numeric: tabular-nums; }
.stat .l { color: var(--ink-2); font-size: .85rem; }
.stat.alert { border-color: var(--danger); background: var(--danger-soft); }
.stat.alert .n { color: var(--danger); }

/* forms */
label.f { display: flex; flex-direction: column; gap: .3rem; font-size: .85rem; color: var(--ink-2); font-weight: 550; }
label.f .req { color: var(--danger); }
input, select, textarea { font: inherit; color: var(--ink); background: var(--surface); border: 1px solid var(--line);
  border-radius: 8px; padding: .55rem .65rem; width: 100%; }
textarea { min-height: 96px; resize: vertical; }
input:focus, select:focus, textarea:focus { outline: 2px solid var(--brand); outline-offset: -1px; border-color: var(--brand); }
input[type=checkbox], input[type=radio] { width: auto; accent-color: var(--brand); }
.choice { display: flex; gap: .5rem; flex-wrap: wrap; }
.choice label { display: inline-flex; align-items: center; gap: .4rem; padding: .45rem .75rem; border: 1px solid var(--line);
  border-radius: 8px; cursor: pointer; font-size: .9rem; color: var(--ink); background: var(--surface); }
.choice label:has(input:checked) { border-color: var(--brand); background: var(--brand-soft); }
.hint { font-size: .8rem; color: var(--ink-3); font-weight: 400; }

/* buttons */
.btn { display: inline-flex; align-items: center; justify-content: center; gap: .4rem; font: inherit; font-weight: 600;
  padding: .55rem 1rem; border-radius: 8px; border: 1px solid var(--line); background: var(--surface); color: var(--ink);
  cursor: pointer; text-decoration: none; white-space: nowrap; }
.btn:hover { background: var(--line-2); }
.btn.primary { background: var(--brand); border-color: var(--brand); color: var(--brand-ink); }
.btn.primary:hover { filter: brightness(1.08); }
.btn.danger { background: var(--danger); border-color: var(--danger); color: #fff; }
.btn.ghost { border-color: transparent; background: transparent; }
.btn.sm { padding: .3rem .65rem; font-size: .85rem; }
.btn:disabled { opacity: .55; cursor: not-allowed; }

/* badges */
.badge { display: inline-flex; align-items: center; gap: .3rem; padding: .12rem .55rem; border-radius: 999px;
  font-size: .78rem; font-weight: 600; white-space: nowrap; background: var(--line-2); color: var(--ink-2); }
.badge.reported { background: var(--info-soft); color: var(--info); }
.badge.received, .badge.reviewed { background: var(--warn-soft); color: var(--warn); }
.badge.capa, .badge.assessed { background: var(--brand-soft); color: var(--brand); }
.badge.returned { background: var(--danger-soft); color: var(--danger); }
.badge.closed { background: var(--ok-soft); color: var(--ok); }
.badge.sentinel { background: var(--danger); color: #fff; }
.badge.overdue { background: var(--danger-soft); color: var(--danger); }
.badge.low { background: var(--ok-soft); color: var(--ok); }
.badge.moderate { background: var(--warn-soft); color: var(--warn); }
.badge.high { background: #fde3cf; color: #9a3b00; }
.badge.extreme { background: var(--danger); color: #fff; }

/* tables */
.table-wrap { overflow-x: auto; }
table.list { width: 100%; border-collapse: collapse; font-size: .9rem; }
table.list th { text-align: left; font-weight: 600; color: var(--ink-3); font-size: .78rem; text-transform: uppercase;
  letter-spacing: .03em; padding: .6rem .75rem; border-bottom: 1px solid var(--line); white-space: nowrap; }
table.list td { padding: .65rem .75rem; border-bottom: 1px solid var(--line-2); vertical-align: top; }
table.list tr.click { cursor: pointer; }
table.list tr.click:hover td { background: var(--surface-2); }
.code { font-family: var(--mono); font-size: .85rem; font-weight: 600; }
.filters { display: flex; gap: .6rem; flex-wrap: wrap; padding: .9rem 1rem; border-bottom: 1px solid var(--line); }
.filters > * { width: auto; min-width: 150px; }
.filters input[type=search] { flex: 1; min-width: 200px; }
.empty { padding: 2.5rem 1rem; text-align: center; color: var(--ink-3); }

/* alerts */
.alert-box { display: flex; gap: .75rem; padding: .85rem 1rem; border-radius: var(--radius); border: 1px solid; margin-bottom: 1rem; }
.alert-box.danger { background: var(--danger-soft); border-color: var(--danger); color: var(--danger); }
.alert-box.warn { background: var(--warn-soft); border-color: var(--warn); color: var(--warn); }
.alert-box.info { background: var(--info-soft); border-color: var(--info); color: var(--info); }
.alert-box strong { display: block; }
.alert-box a { color: inherit; }

/* incident detail */
.detail { display: grid; grid-template-columns: minmax(0, 1fr) 300px; gap: 1.25rem; align-items: start; }
.section { margin-bottom: 1rem; }
.section-head { display: flex; align-items: center; gap: .75rem; padding: .85rem 1.25rem; border-bottom: 1px solid var(--line); }
.section-num { display: grid; place-items: center; width: 26px; height: 26px; border-radius: 50%; flex: none;
  background: var(--line-2); color: var(--ink-2); font-weight: 700; font-size: .8rem; }
.section.done .section-num { background: var(--ok-soft); color: var(--ok); }
.section.active { border-color: var(--brand); box-shadow: 0 0 0 3px var(--brand-soft); }
.section.active .section-num { background: var(--brand); color: var(--brand-ink); }
.section-head h2 { margin: 0; flex: 1; font-size: 1rem; }
.section-body { padding: 1.1rem 1.25rem 1.25rem; }
.section-foot { display: flex; gap: .6rem; justify-content: flex-end; padding: .85rem 1.25rem; border-top: 1px solid var(--line); background: var(--surface-2); border-radius: 0 0 var(--radius) var(--radius); }
dl.kv { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: .8rem 1.5rem; margin: 0; }
dl.kv div.full { grid-column: 1 / -1; }
dl.kv dt { font-size: .78rem; color: var(--ink-3); text-transform: uppercase; letter-spacing: .03em; font-weight: 600; }
dl.kv dd { margin: .15rem 0 0; white-space: pre-wrap; word-break: break-word; }
.sig { display: inline-flex; flex-direction: column; padding: .5rem .8rem; border-left: 3px solid var(--ok); background: var(--ok-soft); border-radius: 0 8px 8px 0; font-size: .85rem; }
.sig b { color: var(--ok); }
.sig.no { border-color: var(--danger); background: var(--danger-soft); }
.sig.no b { color: var(--danger); }
.sig-slot { padding: .75rem; border: 1px dashed var(--line); border-radius: 8px; }
.side .card { margin-bottom: 1rem; }
.side h3 { font-size: .8rem; text-transform: uppercase; letter-spacing: .04em; color: var(--ink-3); }
.steps { list-style: none; margin: 0; padding: 0; }
.steps li { display: flex; gap: .6rem; padding: .35rem 0; font-size: .88rem; color: var(--ink-3); }
.steps li::before { content: ""; width: 10px; height: 10px; border-radius: 50%; margin-top: .4rem; flex: none; border: 2px solid var(--line); }
.steps li.done { color: var(--ink-2); }
.steps li.done::before { background: var(--ok); border-color: var(--ok); }
.steps li.now { color: var(--ink); font-weight: 600; }
.steps li.now::before { border-color: var(--brand); background: var(--brand-soft); }
.timeline { list-style: none; margin: 0; padding: 0; font-size: .84rem; }
.timeline li { padding: .5rem 0; border-bottom: 1px solid var(--line-2); }
.timeline li:last-child { border: 0; }
.timeline .t { color: var(--ink-3); font-size: .78rem; }

/* fishbone */
.fish { display: grid; grid-template-columns: repeat(5, minmax(0, 1fr)); gap: .6rem; }
.fish-cat { border: 1px solid var(--line); border-radius: 8px; padding: .6rem; }
.fish-cat.on { border-color: var(--brand); background: var(--brand-soft); }
.fish-cat label.t { display: flex; align-items: center; gap: .4rem; font-weight: 650; margin-bottom: .4rem; }
.fish-cat textarea { min-height: 70px; font-size: .85rem; }

/* risk matrix */
.matrix { display: grid; grid-template-columns: 110px repeat(5, minmax(0, 1fr)); gap: 3px; font-size: .78rem; }
.matrix .hd { display: grid; place-items: center; text-align: center; color: var(--ink-2); font-weight: 600; padding: .3rem; }
.matrix button { border: 0; border-radius: 5px; padding: .55rem 0; font: inherit; font-weight: 700; cursor: pointer; color: #1d2b20; }
.matrix button.low { background: #bfe5c9; } .matrix button.moderate { background: #ffe1a6; }
.matrix button.high { background: #ffbe8f; } .matrix button.extreme { background: #f59a8f; }
.matrix button.sel { outline: 3px solid var(--ink); outline-offset: -3px; }
.matrix button:disabled { cursor: default; }

/* auth */
.auth { max-width: 420px; margin: 8vh auto; }
.auth .brand { justify-content: center; font-size: 1.15rem; margin-bottom: 1.5rem; }
.tabs { display: flex; border-bottom: 1px solid var(--line); }
.tabs button { flex: 1; padding: .8rem; background: none; border: 0; font: inherit; font-weight: 600; color: var(--ink-3); cursor: pointer; border-bottom: 2px solid transparent; }
.tabs button.on { color: var(--brand); border-color: var(--brand); }

.toast { position: fixed; bottom: 1.25rem; left: 50%; transform: translateX(-50%) translateY(20px); opacity: 0; pointer-events: none;
  background: var(--ink); color: var(--surface); padding: .65rem 1rem; border-radius: 8px; font-size: .9rem; transition: .2s; z-index: 50; max-width: calc(100% - 32px); }
.toast.show { opacity: 1; transform: translateX(-50%); }
.toast.err { background: var(--danger); color: #fff; }

.brand-logo { height: 36px; width: auto; display: block; background: #fff; border-radius: 6px; padding: 2px 4px; }
.brand #brand-name { padding-left: .6rem; border-left: 1px solid var(--line); }
.auth-brand { text-align: center; margin-bottom: 1.25rem; font-weight: 650; color: var(--ink-2); }
.auth-brand img { width: 190px; max-width: 70%; height: auto; display: block; margin: 0 auto .5rem; background: #fff; border-radius: 10px; padding: 6px; }

/* print sheet */
.sheet-head { display: grid; grid-template-columns: 1fr auto 1fr; align-items: center; gap: 12px; margin-bottom: 6px; }
.sheet-head .sh-logo { height: 70px; width: auto; }
.sheet-head .sh-badge { height: 70px; width: auto; justify-self: end; }
.sheet-head .codeline { text-align: center; }
.sheet { background: #fff; color: #000; max-width: 800px; margin: 0 auto; padding: 24px; font: 12.5px/1.45 Arial, sans-serif; }
.sheet h1 { text-align: center; font-size: 17px; margin: 4px 0 10px; letter-spacing: .04em; }
.sheet .hosp { text-align: center; font-weight: 700; font-size: 14px; }
.sheet .codeline { text-align: right; font-weight: 700; }
.sheet table { width: 100%; border-collapse: collapse; margin-bottom: 8px; }
.sheet td, .sheet th { border: 1px solid #000; padding: 4px 6px; vertical-align: top; text-align: left; }
.sheet th.sec { background: #e8e8e8; font-size: 13px; }
.sheet .lbl { width: 34%; font-weight: 600; }
.sheet .box { white-space: pre-wrap; min-height: 40px; }
.print-bar { max-width: 800px; margin: 0 auto 1rem; display: flex; gap: .6rem; }

@media (max-width: 900px) {
  .detail { grid-template-columns: 1fr; }
  .fish { grid-template-columns: 1fr 1fr; }
}
@media (max-width: 640px) {
  .app { padding: 1rem 16px 3rem; }
  .topbar { flex-wrap: wrap; gap: .5rem; padding: .5rem 16px; }
  .nav { order: 3; flex-basis: 100%; }
  .cols-2, .cols-3, .cols-4 { grid-template-columns: 1fr; }
  .span-2 { grid-column: auto; }
  dl.kv { grid-template-columns: 1fr; }
  .fish { grid-template-columns: 1fr; }
  .matrix { grid-template-columns: 70px repeat(5, minmax(0, 1fr)); }
  .section-head, .section-body, .section-foot { padding-left: 1rem; padding-right: 1rem; }
}
@media print {
  .topbar, .print-bar, .toast { display: none !important; }
  body, .app { background: #fff; padding: 0; margin: 0; max-width: none; }
  .sheet { padding: 0; max-width: none; }
  .sheet tr { break-inside: avoid; }
}
