/* Clinic SOP Builder — app styles (on top of /assets/labs.css) */
.app-page .page-title { margin-bottom: 18px; }
.app-block { margin-top: 20px; }
.h-sm { font-size: 22px; margin: 0; }
.h-xs { font-size: 17px; margin: 22px 0 8px; }
.jump { display: flex; flex-wrap: wrap; gap: 8px 18px; margin: 0 0 16px; font-size: 15px; }
.block-head { display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between; gap: 12px; margin-bottom: 12px; }
.btn-row { display: flex; flex-wrap: wrap; gap: 10px; align-items: center; margin-top: 12px; }
.btn-row.tight { margin-top: 0; }
.field-msg { min-height: 1.4em; margin: 10px 0 0; font-size: 14px; color: var(--muted); }
.field-msg.err { color: var(--danger); font-weight: 600; }
.field-msg.ok { color: var(--ok); font-weight: 600; }
.danger { color: var(--danger) !important; border-color: color-mix(in srgb, var(--danger) 45%, var(--line)) !important; }
.inline-label { display: flex; flex-wrap: wrap; align-items: center; gap: 10px; font-size: 14px; }
.inline-label select { min-height: 42px; padding: 6px 10px; width: auto; max-width: 100%; }
[aria-invalid="true"] { border-color: var(--danger) !important; box-shadow: 0 0 0 3px color-mix(in srgb, var(--danger) 20%, transparent) !important; }
.disclaimer { margin-top: 24px; }
.undo-bar { position: fixed; left: 50%; bottom: 20px; transform: translateX(-50%); z-index: 20; width: min(560px, calc(100% - 32px)); box-shadow: var(--shadow); display: flex; align-items: center; gap: 12px; flex-wrap: wrap; margin: 12px 0 0; padding: 10px 14px; border-radius: var(--radius-sm); background: var(--accent-soft); border: 1px solid var(--line); font-size: 14px; }
.undo-bar[hidden] { display: none; }
.org-input { min-height: 42px; padding: 6px 10px; width: min(320px, 100%); }
.row-edit { display: grid; gap: 8px; }
.row-edit.two { grid-template-columns: minmax(0, 1fr) minmax(0, 1.3fr); }
.row-edit.three { grid-template-columns: minmax(0, 1.2fr) minmax(0, 0.8fr) minmax(0, 1.2fr); }
.row-edit input { min-height: 42px; padding: 6px 10px; }
@media (max-width: 640px) { .row-edit.two, .row-edit.three { grid-template-columns: 1fr; } }
.doc-changes { margin: 10px 0 0; font-size: 14px; }
.doc-table.ack td { height: 34px; }

/* Library */
.stats { display: grid; gap: 10px; grid-template-columns: repeat(5, minmax(0, 1fr)); margin-bottom: 14px; }
@media (max-width: 760px) { .stats { grid-template-columns: repeat(2, minmax(0, 1fr)); } }
.stat { background: var(--bg); border: 1px solid var(--line); border-radius: var(--radius-sm); padding: 10px 12px; display: grid; gap: 2px; }
.stat strong { font-size: 26px; letter-spacing: -0.02em; line-height: 1.1; }
.stat span { font-size: 13px; color: var(--muted); }
.stat.bad strong { color: var(--danger); }
.stat.warnc strong { color: var(--warn); }
.table-scroll { overflow-x: auto; max-width: 100%; border-radius: var(--radius-sm); }
.table-scroll[hidden] { display: none; }
.lib-table, .raci-table { border-collapse: collapse; width: 100%; font-size: 14px; background: var(--bg); }
.lib-table th, .lib-table td { text-align: left; padding: 10px 12px; border-bottom: 1px solid var(--line); vertical-align: middle; }
.lib-table thead th { font-size: 12px; text-transform: uppercase; letter-spacing: 0.06em; color: var(--muted); font-weight: 650; }
.lib-table tbody th { font-weight: 600; }
.lib-table tr.current { background: var(--accent-soft); }
.link-btn { background: none; border: 0; padding: 4px 0; font: inherit; font-weight: 650; color: var(--accent); cursor: pointer; text-align: left; text-decoration: underline; text-underline-offset: 2px; min-height: 32px; }
.open-tag { margin-left: 8px; font-size: 12px; color: var(--muted); font-weight: 600; }
.chip { display: inline-block; font-size: 12px; font-weight: 700; padding: 3px 10px; border-radius: 999px; background: var(--surface-2); color: var(--text); white-space: nowrap; }
.chip.overdue { background: color-mix(in srgb, var(--danger) 14%, var(--bg)); color: var(--text); box-shadow: inset 0 0 0 1px var(--danger); }
.chip.soon { background: color-mix(in srgb, var(--warn) 14%, var(--bg)); color: var(--text); box-shadow: inset 0 0 0 1px var(--warn); }
.chip.current { background: color-mix(in srgb, var(--ok) 12%, var(--bg)); color: var(--text); box-shadow: inset 0 0 0 1px var(--ok); }
.example-row { display: flex; flex-wrap: wrap; gap: 10px; align-items: flex-end; margin-top: 14px; }

/* Details */
.setup-grid { display: grid; gap: 16px; grid-template-columns: repeat(2, minmax(0, 1fr)); }
.setup-grid .span2 { grid-column: 1 / -1; }
@media (max-width: 760px) { .setup-grid { grid-template-columns: 1fr; } }
.setup-grid textarea { min-height: 76px; }
.next-review { display: flex; flex-wrap: wrap; align-items: center; gap: 6px 12px; background: var(--bg); border: 1px solid var(--line); border-radius: var(--radius-sm); padding: 10px 12px; }
.next-review span { width: 100%; }
.next-review strong { font-size: 15px; }
.next-overdue { color: var(--danger); }
.next-soon { color: var(--warn); }
.next-current { color: var(--ok); }

/* Add forms */
.add-form { display: grid; grid-template-columns: minmax(0, 1fr) auto; gap: 12px; align-items: end; }
.pair-form { display: grid; grid-template-columns: minmax(0, 1fr) minmax(0, 1.3fr) auto; gap: 12px; align-items: end; }
.trio-form { display: grid; grid-template-columns: minmax(0, 1.2fr) minmax(0, 0.8fr) minmax(0, 1.2fr) auto; gap: 12px; align-items: end; }
@media (max-width: 760px) { .add-form, .pair-form, .trio-form { grid-template-columns: 1fr; } }

/* Roles */
.role-list { list-style: none; padding: 0; margin: 12px 0 0; display: grid; gap: 8px; grid-template-columns: repeat(auto-fill, minmax(260px, 1fr)); }
.role-row { display: grid; grid-template-columns: minmax(0, 1fr) auto; gap: 8px; align-items: center; }
.role-row input { min-height: 44px; padding: 8px 10px; }
.icon-btn { background: transparent; border: 1px solid var(--line); color: var(--text); border-radius: 8px; min-height: 44px; min-width: 44px; padding: 0 12px; font: inherit; font-size: 15px; cursor: pointer; }
.icon-btn:hover:not(:disabled) { border-color: var(--accent); color: var(--accent); }
.icon-btn:disabled { opacity: 0.4; cursor: not-allowed; }

/* Steps */
.step-list { list-style: none; padding: 0; margin: 12px 0 0; display: grid; gap: 12px; }
.step-card { background: var(--bg); border: 1px solid var(--line); border-radius: var(--radius-sm); padding: 12px; }
.step-head { display: grid; grid-template-columns: 36px minmax(0, 1fr) auto; gap: 12px; align-items: center; }
.step-num { width: 32px; height: 32px; border-radius: 999px; background: var(--accent); color: var(--accent-ink); display: grid; place-items: center; font-weight: 750; font-size: 14px; }
.step-name input { min-height: 44px; padding: 8px 10px; font-weight: 600; }
.step-ctl { display: flex; gap: 6px; }
.step-grid { display: grid; gap: 12px; grid-template-columns: repeat(2, minmax(0, 1fr)); margin: 12px 0 0 48px; }
.step-grid .span2 { grid-column: 1 / -1; }
.step-grid label { font-size: 14px; }
.step-grid input, .step-grid textarea { min-height: 42px; padding: 8px 10px; }
.step-grid textarea { min-height: 70px; }
.step-who { grid-column: 1 / -1; margin: 0; }
@media (max-width: 640px) {
  .step-head { grid-template-columns: 32px minmax(0, 1fr); }
  .step-ctl { grid-column: 1 / -1; }
  .step-grid { margin-left: 0; grid-template-columns: 1fr; }
}

/* RACI */
.raci-badge { font-size: 13px; font-weight: 700; padding: 4px 12px; border-radius: 999px; }
.raci-badge:empty { display: none; }
.raci-badge.ok { background: color-mix(in srgb, var(--ok) 12%, var(--bg)); color: var(--text); box-shadow: inset 0 0 0 1px var(--ok); }
.raci-badge.bad { background: color-mix(in srgb, var(--danger) 12%, var(--bg)); color: var(--text); box-shadow: inset 0 0 0 1px var(--danger); }
.raci-table th, .raci-table td { border: 1px solid var(--line); padding: 6px 8px; text-align: center; }
.raci-table thead th { font-size: 13px; font-weight: 650; background: var(--surface); min-width: 92px; }
.raci-table thead th:first-child, .raci-table tbody th { text-align: left; min-width: 220px; font-weight: 600; font-size: 14px; }
@media (max-width: 640px) { .raci-table thead th:first-child, .raci-table tbody th { min-width: 140px; font-size: 13px; } .raci-table thead th { min-width: 84px; } }
.raci-sel { min-height: 40px; padding: 4px 8px; width: 78px; text-align: center; font-weight: 700; }
.raci-sel[data-v="R"], .raci-sel[data-v="AR"] { background: var(--accent-soft); border-color: var(--accent); }
.raci-sel[data-v="A"] { background: color-mix(in srgb, var(--warn) 14%, var(--bg)); border-color: var(--warn); }
.chk { font-weight: 750; font-size: 13px; min-width: 56px; }
.chk.ok { color: var(--ok); }
.chk.bad { color: var(--danger); }
.issues { margin: 12px 0 0; padding-left: 20px; font-size: 14px; }
.issues li { margin-bottom: 4px; }
.issues li.bad { color: var(--danger); font-weight: 600; }
.issues li.note { color: var(--muted); }

/* Flow */
.flow-scroll { overflow-x: auto; max-width: 100%; border: 1px solid var(--line); border-radius: var(--radius-sm); background: var(--bg); }
.flow-scroll[hidden] { display: none; }
.flow-svg { max-width: none; font-family: var(--font); }
.flow-svg .lane { fill: var(--bg); }
.flow-svg .lane-alt { fill: var(--surface); }
.flow-svg .lane-line { stroke: var(--line); stroke-width: 1; }
.flow-svg .lane-label { font-size: 14px; font-weight: 700; fill: var(--text); }
.flow-svg .lane-label.none { fill: var(--danger); }
.flow-svg .box { fill: var(--accent-soft); stroke: var(--accent); stroke-width: 1.5; }
.flow-svg .box.none { fill: color-mix(in srgb, var(--danger) 10%, var(--bg)); stroke: var(--danger); }
.flow-svg .secondary .box { fill: var(--bg); stroke-dasharray: 5 4; }
.flow-svg .box-text { font-size: 13px; fill: var(--text); }
.flow-svg .edge { fill: none; stroke: var(--muted); stroke-width: 1.6; }
.flow-svg .arrow-head { fill: var(--muted); }
.flow-svg .shared { stroke: var(--accent); stroke-width: 1.5; stroke-dasharray: 4 4; }

/* Exceptions and metrics */
.row-list { list-style: none; padding: 0; margin: 10px 0 0; display: grid; gap: 8px; }
.row-item { display: grid; grid-template-columns: minmax(0, 1fr) auto; gap: 12px; align-items: center; background: var(--bg); border: 1px solid var(--line); border-radius: var(--radius-sm); padding: 8px 10px; font-size: 15px; }

/* File input styled as a button */
.file-btn { position: relative; overflow: hidden; display: inline-flex; font-weight: 650; }
.file-btn:focus-within { outline: 3px solid var(--accent); outline-offset: 2px; }
.file-input { position: absolute; inset: 0; opacity: 0; cursor: pointer; min-height: 0; width: 100%; height: 100%; padding: 0; }

/* Document preview */
.sop-doc { margin-top: 18px; background: var(--bg); border: 1px solid var(--line); border-radius: var(--radius-sm); padding: clamp(16px, 3vw, 32px); overflow-wrap: anywhere; }
.doc-head { border-bottom: 2px solid var(--text); padding-bottom: 12px; margin-bottom: 8px; }
.doc-kicker { font-size: 12px; text-transform: uppercase; letter-spacing: 0.08em; color: var(--muted); font-weight: 650; margin: 0 0 4px; }
.doc-title { font-size: clamp(22px, 3vw, 28px); margin: 0 0 12px; }
.doc-meta { display: grid; grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); gap: 8px 16px; margin: 0; }
.doc-meta dt, .doc-kv dt { font-size: 12px; color: var(--muted); font-weight: 650; text-transform: uppercase; letter-spacing: 0.05em; }
.doc-meta dd, .doc-kv dd { margin: 0; font-size: 15px; white-space: pre-wrap; }
.doc-sec { margin-top: 22px; }
.doc-sec h4 { font-size: 17px; margin: 0 0 8px; letter-spacing: -0.01em; }
.doc-sec p { margin: 0 0 8px; }
.doc-table-wrap, .doc-flow { overflow-x: auto; max-width: 100%; }
.doc-table { border-collapse: collapse; width: 100%; font-size: 14px; }
.doc-table th, .doc-table td { border: 1px solid var(--line); padding: 6px 8px; text-align: left; vertical-align: top; overflow-wrap: normal; word-break: normal; hyphens: manual; }
.doc-table thead th { white-space: normal; }
.doc-table thead th { background: var(--surface); font-weight: 650; }
.doc-table td.c { text-align: center; font-weight: 700; }
.doc-step { border-top: 1px solid var(--line); padding: 10px 0; }
.doc-step h5 { font-size: 15px; margin: 0 0 6px; }
.doc-kv { display: grid; gap: 6px; margin: 0; }
.doc-kv div { display: grid; grid-template-columns: 120px minmax(0, 1fr); gap: 10px; }
@media (max-width: 560px) { .doc-kv div { grid-template-columns: 1fr; gap: 0; } }
.sign { display: grid; grid-template-columns: 2fr 2fr 1fr; gap: 20px; margin-top: 28px; }
@media (max-width: 560px) { .sign { grid-template-columns: 1fr; } }
.sign-line { border-top: 1px solid var(--text); padding-top: 4px; font-size: 13px; color: var(--muted); min-height: 30px; }
.doc-foot { margin: 26px 0 0; font-size: 12px; color: var(--muted); }
.data-block { margin-top: 18px; border-top: 1px solid var(--line); padding-top: 4px; }

html { scroll-padding-top: 84px; }

@media print {
  :root, :root:not([data-theme="light"]), :root[data-theme="dark"] { --bg: #ffffff; --surface: #f3f4f6; --surface-2: #e5e7eb; --text: #000000; --muted: #374151; --line: #9ca3af; --accent: #00756d; --accent-soft: #e3f4f2; --danger: #b91c1c; color-scheme: light; }
  body { background: #fff; color: #000; font-size: 11pt; }
  .no-print, .skip, .top, .foot { display: none !important; }
  .page { padding: 0; }
  .wrap { width: 100%; }
  .card { border: 0; padding: 0; background: #fff; }
  .sop-doc { border: 0; padding: 0; margin: 0; }
  .doc-table-wrap, .doc-flow { overflow: visible; }
  .doc-flow svg { max-width: 100%; height: auto; }
  .doc-table { font-size: 9.5pt; }
  .undo-bar { display: none !important; }
  .doc-step, .doc-table tr, .sign { break-inside: avoid; }
  .doc-sec h4 { break-after: avoid; }
}
