/* ==========================================================================
   PCR pages (templates/pcr/*)

   All styles for the ePCR screens, extracted from the embedded <style> block
   that used to sit at the top of pcr/form.html and from inline style=""
   attributes across the pcr templates.

   Scoping (so nothing leaks into other pages):
     - form styles live under #pcr-form (the <form> wrapping the whole editor)
     - popover styles live under .pcr-pop (pcr.js appends it to <body>)
     - everything else uses pcr- prefixed classes only found on pcr pages

   JS hooks (static/js/pcr.js) preserved throughout: .pcr-tab(.active/.has-data),
   .pcr-panel(.active), .chip(-sel/-neg/-has-det), .time-bad, .bm-dot(.bm-open),
   .obs-detail-row display toggling, [data-panel], [data-chip-group], etc.

   Colours come from theme tokens only (tokens.css) — no hardcoded hex except
   white ink on accent fills (house convention, cf. .btn-primary) and the
   signature pads/images, which must stay white so captured ink PNGs look right.
   ========================================================================== */

/* ── Tab strip ─────────────────────────────────────────────────────────── */
#pcr-form .pcr-tabs {
  display: flex; gap: 6px; flex-wrap: wrap; margin-bottom: var(--sp-4);
  position: sticky; top: calc(var(--top-h) + 8px); z-index: 20;
  /* frosted backdrop so content doesn't bleed through when sticky */
  background: color-mix(in srgb, var(--bg) 88%, transparent);
  backdrop-filter: blur(10px); -webkit-backdrop-filter: blur(10px);
  border-radius: var(--r-md); padding: 6px 4px;
}
#pcr-form .pcr-tab {
  padding: 8px 14px; border-radius: var(--r-pill); font-size: 13px; font-weight: 600; cursor: pointer;
  background: var(--card); border: 1px solid var(--border); color: var(--fg-muted);
}
#pcr-form .pcr-tab.active { background: var(--brand-600); color: #fff; border-color: transparent; }
#pcr-form .pcr-tab .dot {
  display: inline-block; width: 7px; height: 7px; border-radius: 50%;
  background: var(--accent-emerald); margin-left: 6px; vertical-align: middle; visibility: hidden;
}
#pcr-form .pcr-tab.has-data .dot { visibility: visible; }
#pcr-form .pcr-panel { display: none; }
#pcr-form .pcr-panel.active { display: block; }

/* ── Section headings & hint text inside the form ─────────────────────── */
#pcr-form .pcr-section-title {
  font-size: 12px; margin: var(--sp-4) 0 6px; font-weight: 600;
  text-transform: uppercase; letter-spacing: .08em; color: var(--fg-subtle);
}
#pcr-form .pcr-section-title .chip-hint { text-transform: none; }
#pcr-form .pcr-sub-title { font-size: 13px; font-weight: 600; margin: var(--sp-4) 0 var(--sp-2); }
#pcr-form .pcr-hint { margin: 0 0 var(--sp-2); }

/* ── Spacing helpers extracted from inline margins ────────────────────── */
#pcr-form .pcr-mt-2 { margin-top: var(--sp-2); }
#pcr-form .pcr-mt-3 { margin-top: var(--sp-3); }
#pcr-form .pcr-mt-4 { margin-top: var(--sp-4); }
#pcr-form .pcr-mb-2 { margin-bottom: var(--sp-2); }
#pcr-form .pcr-mb-3 { margin-bottom: var(--sp-3); }
#pcr-form .pcr-mb-4 { margin-bottom: var(--sp-4); }

/* ── Time fields: datetime input + "now" button ───────────────────────── */
#pcr-form .pcr-time-row { gap: var(--sp-1); }
#pcr-form .time-bad { border-color: var(--accent-rose) !important; color: var(--accent-rose); }
#pcr-form .pcr-gm8-note { font-size: 12px; margin: 6px 0 var(--sp-3); }

/* ── Descriptor chips (also used inside .pcr-pop: GCS calc, body-map) ─── */
:is(#pcr-form, .pcr-pop) .chip-group { margin-bottom: var(--sp-4); }
:is(#pcr-form, .pcr-pop) .chip-head { display: flex; align-items: center; gap: 10px; margin-bottom: 6px; flex-wrap: wrap; }
:is(#pcr-form, .pcr-pop) .chip-label {
  font-size: 11px; text-transform: uppercase; letter-spacing: .08em; color: var(--fg-subtle);
}
:is(#pcr-form, .pcr-pop) .chip-hint { font-size: 10px; color: var(--fg-subtle); }
:is(#pcr-form, .pcr-pop) .chip-search,
:is(#pcr-form, .pcr-pop) .entry-search { padding: 3px 8px; font-size: 12px; max-width: 180px; }
:is(#pcr-form, .pcr-pop) .chip-grid { display: flex; flex-wrap: wrap; gap: 6px; }
:is(#pcr-form, .pcr-pop) .chip {
  padding: 6px 10px; border-radius: 8px; font-size: 12px; cursor: pointer; text-align: left;
  background: var(--card); border: 1px solid var(--border); color: var(--fg); position: relative;
  -webkit-user-select: none; user-select: none;
  transition: transform .06s ease, background .1s ease, border-color .1s ease;
}
:is(#pcr-form, .pcr-pop) .chip:active { transform: scale(.95); }
:is(#pcr-form, .pcr-pop) .chip-sel { background: var(--accent-emerald); border-color: var(--accent-emerald); color: #fff; }
:is(#pcr-form, .pcr-pop) .chip-neg {
  background: var(--accent-amber); border-color: var(--accent-amber);
  color: #1e293b; text-decoration: line-through;
}
:is(#pcr-form, .pcr-pop) .chip-star { font-style: italic; }
:is(#pcr-form, .pcr-pop) .chip-add { border-style: dashed; color: var(--fg-subtle); }
:is(#pcr-form, .pcr-pop) .chip-pencil { margin-left: 6px; opacity: .55; font-size: 11px; }
:is(#pcr-form, .pcr-pop) .chip-has-det .chip-pencil { opacity: 1; color: inherit; }
:is(#pcr-form, .pcr-pop) .chip-custom { border-style: dotted; }
#pcr-form #lookup-results { margin-top: 6px; }

/* ── Popover (pcr.js appends .pcr-pop to <body>) ──────────────────────── */
.pcr-pop {
  position: absolute; z-index: 80; background: var(--card); border: 1px solid var(--border-strong);
  border-radius: var(--r-md); box-shadow: var(--shadow-lg); padding: 12px; width: min(440px, 92vw);
  display: flex; flex-direction: column; gap: 6px; max-height: 70vh; overflow-y: auto;
}
.pcr-pop .pop-label { font-size: 12px; font-weight: 700; }
.pcr-pop .pop-sub {
  font-size: 10px; text-transform: uppercase; letter-spacing: .06em; color: var(--fg-subtle); margin-top: 4px;
}
.pcr-pop .pop-field,
.pcr-pop .pop-text { width: 100%; font-size: 12px; padding: 5px 7px; }
.pcr-pop .pop-foot { display: flex; justify-content: flex-end; margin-top: 6px; }

/* ── Entry sections (timed pick-lists with an editable rows table) ────── */
#pcr-form .entry-section { margin-bottom: var(--sp-5); }
#pcr-form .entry-table td { font-size: 12px; padding: 5px 6px; }

/* ── Obs / score / treatment / medication tables ──────────────────────── */
#pcr-form .obs-table input,
#pcr-form .obs-table select { width: 100%; min-width: 52px; padding: 4px 6px; font-size: 12px; }
#pcr-form .obs-table th { font-size: 10px; white-space: nowrap; }
#pcr-form .obs-table td { padding: 4px 4px; }
#pcr-form .obs-detail-row td { background: var(--tint-slate); }
#pcr-form .pcr-obs-detail { gap: var(--sp-2); flex-wrap: wrap; }
#pcr-form .pcr-input-sm { max-width: 80px; }
/* fixed column widths on the tx/med tables (inline width="" equivalents) */
#pcr-form .obs-table td.pcr-col-time { width: 170px; }
#pcr-form .obs-table td.pcr-col-item { width: 220px; }
#pcr-form .obs-table td.pcr-col-sm { width: 110px; }
#pcr-form .obs-table td.pcr-col-md { width: 120px; }
#pcr-form .pcr-scroll-x { overflow-x: auto; }
#pcr-form .pcr-add-row { margin-top: var(--sp-2); }
#pcr-form .pcr-add-row-end { margin: var(--sp-2) 0 var(--sp-4); }

/* ── Signature pads (white canvas is functional: ink PNGs export on white) */
#pcr-form .sig-pad {
  border: 1px dashed var(--border-strong); border-radius: var(--r-sm);
  background: #fff; touch-action: none; width: 100%; max-width: 420px; height: 130px;
}

/* ── Row delete buttons ────────────────────────────────────────────────── */
#pcr-form .row-del { color: var(--accent-rose); cursor: pointer; background: none; border: none; font-size: 15px; }

/* ── Body map ──────────────────────────────────────────────────────────── */
#pcr-form .bm-wrap { display: flex; gap: 18px; flex-wrap: wrap; }
#pcr-form .bm-view {
  position: relative; width: 170px; height: 380px;
  border: 1px solid var(--border); border-radius: var(--r-md);
  background: var(--card); cursor: crosshair;
}
#pcr-form .bm-view svg { width: 100%; height: 100%; pointer-events: none; }
#pcr-form .bm-view .bm-cap {
  position: absolute; top: 4px; left: 0; right: 0; text-align: center; font-size: 10px;
  color: var(--fg-subtle); text-transform: uppercase; letter-spacing: .08em; pointer-events: none;
}
#pcr-form .bm-dot {
  position: absolute; width: 14px; height: 14px; border-radius: 50%;
  background: var(--accent-emerald); border: 2px solid #fff;
  transform: translate(-50%, -50%); cursor: pointer; padding: 0;
}
#pcr-form .bm-dot.bm-open { background: var(--accent-amber); }
#pcr-form #bm-list {
  list-style: none; display: flex; flex-direction: column; gap: 6px;
  font-size: 12px; flex: 1; min-width: 240px;
}

/* ── Outcome / review misc ─────────────────────────────────────────────── */
#pcr-form .pcr-field-end { display: flex; align-items: flex-end; }
#pcr-form .pcr-check {
  display: inline-flex; align-items: center; gap: var(--sp-2);
  text-transform: none; letter-spacing: 0; font-size: 13px;
}
#pcr-form .pcr-collapse { margin: var(--sp-4) 0; }
#pcr-form .pcr-collapse summary { cursor: pointer; font-size: 13px; font-weight: 600; }
#pcr-form .pcr-check-list { list-style: none; display: flex; flex-direction: column; gap: 5px; }
#pcr-form .pcr-check-item { font-size: 13px; display: flex; align-items: center; gap: var(--sp-2); }

/* ── Save bar ──────────────────────────────────────────────────────────── */
#pcr-form .pcr-savebar {
  position: sticky; bottom: 0; z-index: 25; margin-top: 18px; padding: 12px;
  background: var(--card); border: 1px solid var(--border); border-radius: var(--r-md);
  display: flex; gap: var(--sp-2); align-items: center; flex-wrap: wrap; box-shadow: var(--shadow-lg);
}
#pcr-form .draft-note { font-size: 11px; color: var(--fg-subtle); }

/* ── Small tablets & phones: one-row scrollable tabs ──────────────────── */
@media (max-width: 1024px) {
  #pcr-form .pcr-tabs {
    flex-wrap: nowrap; overflow-x: auto; scrollbar-width: none;
    -webkit-overflow-scrolling: touch; top: calc(var(--top-h) + 2px);
  }
  #pcr-form .pcr-tabs::-webkit-scrollbar { display: none; }
  #pcr-form .pcr-tab { flex: 0 0 auto; white-space: nowrap; }
}

/* ── Small tablets & phones: obs/score/tx/med tables become labelled
      input cards — no sideways scrolling to enter vitals ── */
@media (max-width: 1024px) {
  #pcr-form .obs-table { border: 0; background: none; }
  #pcr-form .obs-table thead { display: none; }
  #pcr-form .obs-table, #pcr-form .obs-table tbody,
  #pcr-form .obs-table tr, #pcr-form .obs-table td { display: block; }
  #pcr-form .obs-table tbody tr {
    display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 10px;
    padding: 14px; padding-right: 46px; margin-bottom: 12px; position: relative;
    background: var(--bg-soft); border: 1px solid var(--border); border-radius: var(--r-lg);
  }
  #pcr-form .obs-table td { padding: 0 !important; border: 0 !important; background: none !important; width: auto !important; }
  #pcr-form .obs-table td[data-label]::before {
    content: attr(data-label); display: block;
    font-size: 10px; font-weight: 700; letter-spacing: .06em; text-transform: uppercase;
    color: var(--fg-subtle); margin-bottom: 4px; white-space: nowrap;
  }
  #pcr-form .obs-table td[data-span="2"] { grid-column: span 2; }
  #pcr-form .obs-table td[data-span="4"] { grid-column: 1 / -1; }
  #pcr-form .obs-table td.td-del { position: absolute; top: 6px; right: 6px; }
  #pcr-form .obs-table input, #pcr-form .obs-table select { width: 100%; min-width: 0; }
  #pcr-form .obs-table tr.obs-detail-row {
    grid-template-columns: 1fr; margin-top: -6px;
    border-style: dashed; background: var(--bg-elevated);
  }
  #pcr-form .obs-table tr:hover { background: var(--bg-soft); }
}
@media (max-width: 560px) {
  #pcr-form .obs-table tbody tr { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  #pcr-form .obs-table td[data-span="2"], #pcr-form .obs-table td[data-span="4"] { grid-column: 1 / -1; }
}

/* ── Touch devices: gloves-on sizing (16px inputs also stop iOS zoom) ─── */
@media (pointer: coarse) {
  #pcr-form .pcr-tab { padding: 12px 18px; font-size: 14px; min-height: 46px; }
  :is(#pcr-form, .pcr-pop) .chip { padding: 11px 14px; font-size: 13.5px; border-radius: var(--r-md); min-height: 42px; }
  :is(#pcr-form, .pcr-pop) .chip-pencil { font-size: 13px; margin-left: 8px; }
  :is(#pcr-form, .pcr-pop) .chip-search,
  :is(#pcr-form, .pcr-pop) .entry-search { min-height: 44px; font-size: 16px; padding: 8px 12px; }
  #pcr-form .obs-table input, #pcr-form .obs-table select { min-height: 46px; font-size: 16px; padding: 8px 10px; }
  #pcr-form .entry-table td { font-size: 13px; padding: 9px 8px; }
  #pcr-form .row-del { font-size: 22px; padding: 6px 10px; }
  .pcr-pop .pop-field, .pcr-pop .pop-text { min-height: 44px; font-size: 16px; }
  .pcr-pop { padding: 14px; gap: 8px; }
  #pcr-form .sig-pad { height: 170px; max-width: none; }
  #pcr-form .bm-dot { width: 20px; height: 20px; }
  #pcr-form .bm-view { cursor: pointer; }
}

/* ── Phones/tablets: entry rows stack — edit/delete always visible,
      never off the right-hand edge ── */
@media (max-width: 760px) {
  #pcr-form .entry-table, #pcr-form .entry-table tbody { display: block; }
  #pcr-form .entry-table tr {
    display: grid; grid-template-columns: minmax(0, 1fr) auto;
    gap: 2px 10px; align-items: start;
    padding: 10px 12px; margin-bottom: 8px;
    background: var(--bg-soft); border: 1px solid var(--border); border-radius: var(--r-md);
  }
  #pcr-form .entry-table td {
    display: block; width: auto !important; padding: 0 !important;
    border: 0 !important; background: none !important; white-space: normal !important;
  }
  #pcr-form .entry-table td:nth-child(1) { order: 3; grid-column: 1 / -1; font-size: 11px; }
  #pcr-form .entry-table td:nth-child(2) { order: 1; }
  #pcr-form .entry-table td:nth-child(3) { order: 2; text-align: right; }
}

/* ── Phones: save bar becomes a fat two-button grid ────────────────────── */
@media (max-width: 560px) {
  #pcr-form .pcr-savebar { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
  #pcr-form .pcr-savebar .btn { width: 100%; justify-content: center; min-height: 50px; }
  #pcr-form .pcr-savebar .spacer { display: none; }
  #pcr-form .pcr-savebar a[href] { grid-column: 1 / -1; min-height: 42px; }
  #pcr-form .pcr-savebar .draft-note { grid-column: 1 / -1; text-align: center; order: 5; }
  #pcr-form .bm-view { width: min(44vw, 190px); }
  #pcr-form .sig-pad { height: 150px; }
}

/* ==========================================================================
   PCR index + detail pages (not wrapped in #pcr-form — pcr- prefixed only)
   ========================================================================== */

/* action row above the list */
.pcr-actions { margin-bottom: var(--sp-4); gap: var(--sp-2); flex-wrap: wrap; }

/* GuardM8 alarms card: rose accent edge */
.pcr-alert-card { margin-bottom: var(--sp-5); border-left: 3px solid var(--accent-rose); }

/* icon-chip tint variants (icon-chip base lives in components.css) */
.pcr-ic-rose    { background: var(--tint-rose);    color: var(--accent-rose); }
.pcr-ic-amber   { background: var(--tint-amber);   color: var(--accent-amber); }
.pcr-ic-cyan    { background: var(--tint-cyan);    color: var(--accent-cyan); }
.pcr-ic-violet  { background: var(--tint-violet);  color: var(--accent-violet); }
.pcr-ic-blue    { background: var(--tint-blue);    color: var(--brand-600); }
.pcr-ic-emerald { background: var(--tint-emerald); color: var(--accent-emerald); }

/* card with a table hard against its edges */
.pcr-flush { padding: 0; }
.pcr-flush-x { padding: 0; overflow-x: auto; }
.pcr-flush-table { border-radius: 0; }

/* small print in table cells */
.pcr-fs-xs { font-size: 11px; }
.pcr-fs-sm { font-size: 12px; }

/* detail page: stacked sections + definition blocks */
.pcr-section { margin-bottom: var(--sp-5); }
.pcr-span-all { grid-column: 1 / -1; }
.pcr-block { margin-bottom: 10px; }
.pcr-block-value { white-space: pre-wrap; font-size: 13px; }
.pcr-list { font-size: 13px; padding-left: 18px; }
.pcr-list-mb { margin-bottom: 10px; }

/* structured-record renderers (pcr/_render.html, detail view) */
.pcr-rec { margin-bottom: var(--sp-3); }
.pcr-rec-values { font-size: 12px; }
.pcr-badge { margin: 1px 2px; }
.pcr-badge-neg { text-decoration: line-through; }
.pcr-entry-nd { text-decoration: line-through; color: var(--fg-subtle); }

/* captured signature image (white bg is functional: transparent PNG ink) */
.pcr-sig-img {
  max-width: 220px; border: 1px solid var(--border);
  border-radius: var(--r-sm); background: #fff;
}
