:root {
  --bg: #f5f6f8; --panel: #ffffff; --ink: #1c2330; --muted: #667085; --line: #e2e6ec;
  --accent: #0b6e8a; --accent-ink: #ffffff; --accent-soft: #e3f2f6;
  --err: #b42318; --err-soft: #fdecea; --warn: #8a5a00; --warn-soft: #fff4d6; --ok: #1a7f4b; --ok-soft: #e4f5ec;
  --radius: 10px; --shadow: 0 1px 2px rgba(16, 24, 40, .06), 0 1px 3px rgba(16, 24, 40, .08);
  --mono: ui-monospace, "SF Mono", Menlo, Consolas, monospace;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #12161c; --panel: #1b212a; --ink: #e8ecf2; --muted: #9aa5b5; --line: #2c3541;
    --accent: #4cb4d2; --accent-ink: #06222b; --accent-soft: #14323c;
    --err: #ff8a80; --err-soft: #3b1d1b; --warn: #f5c15a; --warn-soft: #3a2f12; --ok: #5fd39a; --ok-soft: #153325;
    --shadow: none;
  }
}
* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body { margin: 0; background: var(--bg); color: var(--ink); font: 15px/1.45 -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif; }
a { color: var(--accent); }
h1 { font-size: 22px; margin: 0 0 4px; }
h2 { font-size: 16px; margin: 0 0 10px; }
.muted { color: var(--muted); }
.small { font-size: 13px; }
.mono { font-family: var(--mono); }
.right { text-align: right; }
.nowrap { white-space: nowrap; }
.hidden { display: none !important; }

header.top { position: sticky; top: 0; z-index: 20; background: var(--panel); border-bottom: 1px solid var(--line); }
header.top .in { max-width: 1180px; margin: 0 auto; padding: 0 16px; display: flex; align-items: center; gap: 18px; min-height: 52px; flex-wrap: wrap; }
.brand { font-weight: 700; letter-spacing: -.01em; }
nav { display: flex; gap: 2px; flex-wrap: wrap; flex: 1; }
nav a { padding: 15px 12px 13px; color: var(--muted); text-decoration: none; border-bottom: 2px solid transparent; font-weight: 500; }
nav a.active { color: var(--accent); border-color: var(--accent); }
main { max-width: 1180px; margin: 0 auto; padding: 20px 16px 80px; }

.card { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); box-shadow: var(--shadow); padding: 16px; margin-bottom: 16px; }
.row { display: flex; gap: 12px; flex-wrap: wrap; align-items: flex-end; }
.row.center { align-items: center; }
.grow { flex: 1; }
.grid { display: grid; gap: 12px; grid-template-columns: repeat(auto-fit, minmax(170px, 1fr)); }
.spread { display: flex; justify-content: space-between; align-items: center; gap: 12px; flex-wrap: wrap; }

label { display: block; font-size: 12.5px; font-weight: 600; color: var(--muted); margin-bottom: 4px; }
input, select, textarea { width: 100%; font: inherit; color: var(--ink); background: var(--bg); border: 1px solid var(--line); border-radius: 8px; padding: 9px 10px; min-height: 40px; }
input:focus, select:focus, textarea:focus { outline: 2px solid var(--accent); outline-offset: -1px; background: var(--panel); }
input[type=checkbox] { width: auto; min-height: 0; accent-color: var(--accent); }
input.bad, select.bad { border-color: var(--err); background: var(--err-soft); }
input.warnfield, select.warnfield { border-color: var(--warn); }
.check { display: flex; gap: 8px; align-items: center; font-size: 14px; font-weight: 500; color: var(--ink); margin: 0; min-height: 40px; }

button, .btn { font: inherit; font-weight: 600; border: 1px solid var(--line); background: var(--panel); color: var(--ink); border-radius: 8px; padding: 9px 14px; min-height: 40px; cursor: pointer; text-decoration: none; display: inline-flex; align-items: center; gap: 6px; }
button:hover, .btn:hover { border-color: var(--accent); }
button.primary, .btn.primary { background: var(--accent); color: var(--accent-ink); border-color: var(--accent); }
button.danger { color: var(--err); }
button.ghost { border-color: transparent; background: transparent; color: var(--accent); padding: 6px 8px; min-height: 32px; }
button.icon { padding: 4px 8px; min-height: 32px; }
button:disabled { opacity: .5; cursor: not-allowed; }

table { width: 100%; border-collapse: collapse; }
th { text-align: left; font-size: 12px; text-transform: uppercase; letter-spacing: .04em; color: var(--muted); padding: 8px 10px; border-bottom: 1px solid var(--line); white-space: nowrap; }
td { padding: 9px 10px; border-bottom: 1px solid var(--line); vertical-align: middle; }
tr.click { cursor: pointer; }
tr.click:hover td { background: var(--accent-soft); }

.pill { display: inline-block; font-size: 12px; font-weight: 600; padding: 2px 9px; border-radius: 99px; background: var(--bg); border: 1px solid var(--line); color: var(--muted); }
.pill.draft { background: var(--warn-soft); color: var(--warn); border-color: transparent; }
.pill.exported { background: var(--accent-soft); color: var(--accent); border-color: transparent; }
.pill.submitted, .pill.paid { background: var(--ok-soft); color: var(--ok); border-color: transparent; }
.pill.rejected { background: var(--err-soft); color: var(--err); border-color: transparent; }
.tag { font-size: 11px; padding: 1px 7px; border-radius: 6px; background: var(--accent-soft); color: var(--accent); font-weight: 600; }
.tag.modifier { background: var(--warn-soft); color: var(--warn); }

.stats { display: grid; gap: 12px; grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); margin-bottom: 16px; }
.stat { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); padding: 12px 14px; cursor: pointer; }
.stat b { font-size: 22px; display: block; letter-spacing: -.02em; }
.stat.on { border-color: var(--accent); background: var(--accent-soft); }

.banner { padding: 10px 14px; border-radius: 8px; margin-bottom: 16px; }
.banner.warn { background: var(--warn-soft); color: var(--warn); }
.banner.err { background: var(--err-soft); color: var(--err); }
.banner.ok { background: var(--ok-soft); color: var(--ok); }

.issues { list-style: none; margin: 0; padding: 0; display: grid; gap: 6px; }
.issues li { padding: 7px 10px; border-radius: 8px; font-size: 14px; }
.issues li.error { background: var(--err-soft); color: var(--err); }
.issues li.warn { background: var(--warn-soft); color: var(--warn); }
.issues li.ok { background: var(--ok-soft); color: var(--ok); }

.picker { position: relative; }
.results { position: absolute; z-index: 15; left: 0; right: 0; top: 100%; margin-top: 4px; background: var(--panel); border: 1px solid var(--line); border-radius: 10px; box-shadow: 0 8px 24px rgba(0, 0, 0, .18); max-height: 360px; overflow: auto; }
.results .opt { display: flex; gap: 10px; align-items: baseline; padding: 8px 12px; cursor: pointer; border-bottom: 1px solid var(--line); }
.results .opt:last-child { border: 0; }
.results .opt.sel, .results .opt:hover { background: var(--accent-soft); }
.results .opt .c { font-family: var(--mono); font-weight: 700; min-width: 56px; }
.results .opt .d { flex: 1; font-size: 14px; }
.results .opt .f { color: var(--muted); white-space: nowrap; font-size: 13px; }
.chips { display: flex; gap: 6px; flex-wrap: wrap; }
.chip { border: 1px solid var(--line); border-radius: 99px; padding: 5px 11px; min-height: 0; font-size: 13px; background: var(--bg); font-family: var(--mono); }
.chip:hover { background: var(--accent-soft); }

table.items td { padding: 6px 6px; }
table.items input { padding: 7px 8px; min-height: 36px; }
.hn-ok { color: var(--ok); font-weight: 600; font-size: 13px; }
.hn-bad { color: var(--err); font-weight: 600; font-size: 13px; }

.records { font-family: var(--mono); font-size: 12px; line-height: 1.5; overflow-x: auto; background: var(--bg); border: 1px solid var(--line); border-radius: 8px; padding: 10px; white-space: pre; }
.records .rec-HEB { color: var(--accent); font-weight: 700; }
.records .rec-HEE { color: var(--accent); font-weight: 700; }
.records .rec-HEH { color: var(--ink); font-weight: 700; }

dialog { border: 1px solid var(--line); border-radius: 14px; padding: 20px; width: min(560px, calc(100vw - 24px)); background: var(--panel); color: var(--ink); box-shadow: 0 20px 60px rgba(0, 0, 0, .35); }
dialog::backdrop { background: rgba(10, 14, 20, .5); }
.toast { position: fixed; left: 50%; bottom: 24px; transform: translateX(-50%); background: var(--ink); color: var(--bg); padding: 10px 18px; border-radius: 99px; font-weight: 600; z-index: 100; box-shadow: 0 6px 20px rgba(0, 0, 0, .3); }

.sticky-actions { position: sticky; bottom: 0; background: var(--panel); border-top: 1px solid var(--line); margin: 16px -16px -16px; padding: 12px 16px; border-radius: 0 0 var(--radius) var(--radius); display: flex; gap: 10px; flex-wrap: wrap; z-index: 5; }

@media (max-width: 760px) {
  main { padding: 14px 12px 90px; }
  table.items thead, table.responsive thead { display: none; }
  table.items, table.items tbody, table.items tr, table.items td { display: block; width: 100%; }
  table.items tr { border: 1px solid var(--line); border-radius: 10px; padding: 8px; margin-bottom: 10px; display: grid; grid-template-columns: 1fr 1fr; gap: 6px; }
  table.items td { border: 0; padding: 0; }
  table.items td.full { grid-column: 1 / -1; }
  table.items td[data-l]::before { content: attr(data-l); display: block; font-size: 11px; font-weight: 600; color: var(--muted); }
  table.responsive td.hide-sm, table.responsive th.hide-sm { display: none; }
  nav a { padding: 12px 9px 10px; }
}

/* assistant / anaesthesia unit calculator */
tr.has-units td { border-bottom: 0; }
tr.unitrow td { padding-top: 0; }
.unitbox { display: flex; flex-wrap: wrap; gap: 10px; align-items: flex-end; background: var(--accent-soft); border-radius: 8px; padding: 8px 10px; }
.unitbox input { min-height: 34px; padding: 6px 8px; }
.unitbox .usum { flex: 1; min-width: 220px; font-size: 14px; padding-bottom: 7px; }
.extras { display: grid; gap: 10px; margin: 10px 0; }
.chip.suggest { border-color: var(--accent); background: var(--accent-soft); color: var(--accent); }
.chip .muted { font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif; font-size: 12px; }
@media (max-width: 760px) {
  table.items tr.has-units { border-bottom-left-radius: 0; border-bottom-right-radius: 0; margin-bottom: 0; border-bottom: 0; }
  table.items tr.unitrow { display: block; border-top: 0; border-top-left-radius: 0; border-top-right-radius: 0; padding-top: 0; }
}
.picker.mn .results { right: auto; }
.picker.mn .opt .c { min-width: 44px; }

/* diagnostic code picker */
.results.dxpop { position: fixed; right: auto; margin: 0; z-index: 30; max-height: min(360px, 50vh); }
.dxcell .dxd { max-width: 220px; margin-top: 2px; line-height: 1.25; }
@media (max-width: 760px) { .dxcell .dxd { max-width: none; } table.items td.dxcell input { width: 100% !important; } }

/* remittance */
pre.ra-msg { white-space: pre-wrap; font-family: var(--mono); font-size: 12.5px; background: var(--bg); border: 1px solid var(--line); border-radius: 8px; padding: 10px; margin: 0 0 10px; }
label.btn input[type=file] { display: none; }

/* Simplebilling: billing context (surgical assist) */
.brand { color: var(--ink); text-decoration: none; }
.ctx-tag { font-size: 12px; font-weight: 600; padding: 2px 8px; border-radius: 99px; background: var(--accent-soft); color: var(--accent); text-decoration: none; margin-left: -10px; }
.step { display: inline-grid; place-items: center; width: 22px; height: 22px; border-radius: 50%; background: var(--accent); color: var(--accent-ink); font-size: 12px; margin-right: 8px; vertical-align: 1px; }
details.card > summary { cursor: pointer; font-weight: 600; }
details.help { padding: 10px 16px; }
details.help ol { margin: 10px 0 2px; padding-left: 20px; font-size: 14px; }
details.help li { margin: 4px 0; }
details.more > summary .muted { font-weight: 400; margin-left: 6px; }
.linkbtn { background: none; border: 0; padding: 4px 0; min-height: 0; color: var(--accent); cursor: pointer; text-decoration: underline; }
.items.no-date .c-date { display: none; }
.prow { display: grid; grid-template-columns: 170px 1fr; gap: 12px; padding: 10px 0; border-top: 1px solid var(--line); }
.prow:first-child { border-top: 0; padding-top: 0; }
#other-sit .prow { margin-top: 12px; padding-top: 12px; border-top: 1px solid var(--line); }
.plabel { font-weight: 600; font-size: 14px; }
.pchips { display: flex; flex-wrap: wrap; gap: 8px; }
.pchip { display: grid; text-align: left; gap: 1px; padding: 7px 11px; border: 1px solid var(--line); border-radius: 8px; background: var(--bg); color: var(--ink); max-width: 260px; min-height: 0; cursor: pointer; }
.pchip:hover { border-color: var(--accent); }
.pchip .pc { font-family: var(--mono); font-weight: 700; font-size: 13px; }
.pchip .pl { font-size: 13px; }
.pchip .pw { font-size: 12px; color: var(--muted); }
.pchip.suggest { border-color: var(--accent); border-style: dashed; background: var(--accent-soft); }
.pchip.on { border-color: var(--ok); background: var(--ok-soft); }
.pchip.on .pc { color: var(--ok); }
.ctxopts { display: grid; gap: 10px; grid-template-columns: repeat(auto-fit, minmax(260px, 1fr)); }
.ctxopt { display: flex; gap: 10px; align-items: flex-start; border: 1px solid var(--line); border-radius: 8px; padding: 12px; cursor: pointer; }
.ctxopt:has(input:checked) { border-color: var(--accent); background: var(--accent-soft); }
.ctxopt > span { display: grid; gap: 2px; }
.ctxopt input { width: auto; min-height: 0; margin-top: 3px; }
@media (max-width: 640px) { .prow { grid-template-columns: 1fr; gap: 6px; } .pchip { max-width: none; flex: 1 1 100%; } }
.tag.soon { background: var(--warn-soft); color: var(--warn); }
.linkbtn:disabled { color: var(--muted); text-decoration: none; cursor: default; }
@media (max-width: 640px) { header.top nav { flex-basis: 100%; flex-wrap: nowrap; overflow-x: auto; } header.top nav a { padding: 10px 10px 9px; white-space: nowrap; } header.top .in { gap: 0 18px; padding-top: 8px; } }
/* online sign-in */
body.locked #nav, body.locked #ctx-tag { display: none; }
.login { max-width: 380px; margin: 8vh auto 0; display: grid; gap: 14px; }
.login h1 { margin: 0; }

/* ---------------------------------------------------------------- phones
   bottom tab bar, 16px inputs (iOS doesn't zoom), 44px touch targets, lists as cards,
   claim form: save bar fixed to the bottom in place of the tab bar */
.ni { display: none; }
@media (max-width: 760px) {
  body { font-size: 16px; }
  input, select, textarea { font-size: 16px; min-height: 44px; }
  input[type=checkbox] { width: 22px; height: 22px; min-height: 0; }
  label { font-size: 13px; }
  button, .btn { min-height: 44px; }
  button.ghost, .btn.ghost, button.icon { min-height: 44px; min-width: 44px; justify-content: center; }
  .chip { min-height: 38px; padding: 7px 12px; }
  .linkbtn { padding: 10px 0; min-height: 0; }
  .check { min-height: 44px; }
  h1 { font-size: 24px; }

  header.top { position: static; }
  header.top .in { min-height: 52px; padding: 0 16px; }
  header.top nav { position: fixed; z-index: 30; left: 0; right: 0; bottom: 0; flex: none; display: grid; grid-auto-flow: column; grid-auto-columns: 1fr;
    gap: 0; overflow: visible; background: var(--panel); border-top: 1px solid var(--line); padding-bottom: env(safe-area-inset-bottom); }
  header.top nav a { display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 3px; min-height: 58px;
    padding: 6px 2px; font-size: 11px; font-weight: 600; border-bottom: 0; border-top: 2px solid transparent; white-space: nowrap; }
  header.top nav a.active { border-top-color: var(--accent); }
  .ni { display: block; width: 24px; height: 24px; fill: none; stroke: currentColor; stroke-width: 1.9; stroke-linecap: round; stroke-linejoin: round; }
  #signout { display: none; }
  /* typing: the tab bar would sit on top of the keyboard */
  body:has(:is(input:not([type=checkbox]):not([type=radio]), select, textarea):focus) header.top nav { display: none; }
  main { padding: 14px 16px calc(100px + env(safe-area-inset-bottom)); }
  .toast { bottom: calc(84px + env(safe-area-inset-bottom)); max-width: calc(100vw - 32px); text-align: center; }
  dialog { width: calc(100vw - 16px); max-height: calc(100dvh - 32px); padding: 16px; }

  /* claim form: Close · Save & new · Save, always reachable with the thumb */
  body:has(.sticky-actions) header.top nav { display: none; }
  .sticky-actions { position: fixed; left: 0; right: 0; bottom: 0; margin: 0; border-radius: 0; z-index: 30; display: grid;
    grid-template-columns: auto 1fr 1fr; gap: 8px; padding: 10px 16px calc(10px + env(safe-area-inset-bottom)); box-shadow: 0 -4px 16px rgba(0, 0, 0, .12); }
  .sticky-actions #cancel { order: 1; } .sticky-actions #save-new { order: 2; } .sticky-actions #save { order: 3; }
  .sticky-actions button { justify-content: center; }
  .claim-more { margin-top: 12px; }
  .claim-more button { flex: 1; justify-content: center; }
  .row > div:has(> select), .row > div:has(> input:not([type=checkbox])) { flex: 1 1 100%; }

  /* claims: status tiles scroll sideways instead of filling the first screen */
  .stats { display: flex; gap: 8px; overflow-x: auto; margin: 0 -16px 14px; padding: 0 16px 2px; scroll-snap-type: x proximity; scroll-padding-inline: 16px; scrollbar-width: none; }
  .stats::-webkit-scrollbar { display: none; }
  .stat { flex: 0 0 auto; min-width: 100px; padding: 8px 12px; scroll-snap-align: start; }
  .stat b { font-size: 19px; }
  .row.filters { display: grid; grid-template-columns: 1fr 1fr; }
  .row.filters .grow { grid-column: 1 / -1; }
  .row.filters > div, .grid > div { min-width: 0; }
  input[type=date], input[type=time] { min-width: 0; }
  #bulk { display: grid; grid-template-columns: 1fr 1fr; }
  #bulk #bulk-n { grid-column: 1 / -1; }

  /* tables become a list of cards: label on the left, value on the right */
  table.responsive, table.responsive tbody, table.responsive tr, table.responsive td { display: block; width: 100%; }
  table.responsive tr { padding: 10px 16px; border-bottom: 1px solid var(--line); }
  table.responsive tr:last-child { border-bottom: 0; }
  table.responsive td { border: 0; padding: 3px 0; display: flex; justify-content: space-between; align-items: baseline; gap: 12px; text-align: right; }
  table.responsive td:not([data-l]) { justify-content: flex-end; }
  table.responsive td[data-l]::before { content: attr(data-l); flex: none; color: var(--muted); font-size: 13px; font-weight: 600; text-align: left; }
  table.responsive td[colspan] { display: block; text-align: center; }
  table.responsive td:empty { display: none; }
  /* claim rows: checkbox | date, patient, codes | total, status */
  table.claims-list tr { display: grid; grid-template-columns: auto 1fr auto; gap: 2px 12px; align-items: center; padding: 12px 16px; }
  table.claims-list td { display: block; padding: 0; text-align: left; }
  table.claims-list td::before { content: none !important; }
  table.claims-list td:nth-child(1) { grid-row: 1 / span 3; align-self: start; padding-top: 1px; }
  table.claims-list td:nth-child(2) { grid-column: 2; grid-row: 1; font-weight: 600; }
  table.claims-list td:nth-child(3) { grid-column: 2; grid-row: 2; }
  table.claims-list td:nth-child(4) { grid-column: 2; grid-row: 3; color: var(--muted); }
  table.claims-list td:nth-child(5) { grid-column: 3; grid-row: 1; text-align: right; font-weight: 600; }
  table.claims-list td:nth-child(6) { grid-column: 3; grid-row: 2 / span 2; text-align: right; align-self: start; }
  table.claims-list td:nth-child(7) { display: none; }   /* Copy: on the claim itself */
  table.claims-list td[colspan] { grid-column: 1 / -1; grid-row: auto; text-align: center; }

  /* codes on the claim: one card per code, fields at full width */
  table.items tr:not(.unitrow) { position: relative; padding: 12px; gap: 10px; }
  table.items input { width: 100% !important; }
  table.items td.dxcell, table.items td.c-date { grid-column: 1 / -1; }
  table.items td.right:last-child { position: absolute; top: 6px; right: 6px; width: auto; }
  table.items td.full.small { font-size: 14px; padding-right: 48px; }
  .unitbox { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; padding: 10px; }
  .unitbox input { width: 100% !important; min-height: 44px; }
  .unitbox > div:has([data-if=start_time]) { order: 1; }
  .unitbox > div:has([data-if=end_time]) { order: 2; }
  .unitbox > div:has([data-if=basic_units]) { order: 3; }
  .unitbox > div:has([data-if=minutes]) { order: 4; }
  .unitbox .usum { order: 5; grid-column: 1 / -1; min-width: 0; padding: 0; }

  /* search results: bigger rows, and room left above the keyboard */
  .results { max-height: 45dvh; }
  .results .opt { padding: 12px; }
  .picker.mn .results { right: 0; }
  details.card > summary { padding: 6px 0; }
  .ctxopt input { width: 20px; height: 20px; }
}
