/* Celesta Integration Engine — operator console.
 *
 * Palette, typefaces and the asymmetric panel corner are taken from
 * celestahealth.com so the console reads as the same company's back of house.
 *
 * Two deliberate departures from the marketing site:
 *
 *   * Teal is reserved for identity and action. Status keeps its own green,
 *     amber and red, because in a console the one thing that must be findable
 *     is a failure -- and it cannot be findable in a wholly teal interface.
 *   * Density over air. The public site is spacious because it sells. This is
 *     scanned by two people looking for something that broke.
 */

:root {
  /* The brand teal is the logo colour and is used as one: the wordmark, hover
     rules, tinted surfaces. It is only 2.5:1 on white, so anything that has to
     be *read* -- link text, a filled button's label, a focus ring -- uses the
     deeper pair below, which clears WCAG AA at the same hue. */
  --teal: #15b7b9;
  --teal-fill: #0f7b7c;
  --teal-ink: #0c6e6f;
  --teal-wash: #e6fdfd;
  --paper: #f5f8fc;
  --panel: #fff;
  --ink: #2e2e33;
  --muted: #6e6e76;
  --line: #e2e8ec;

  --ok: #1b7f4b;
  --ok-wash: #e4f3ea;
  --warn: #b07400;
  --warn-wash: #fbf1dc;
  --bad: #c0392b;
  --bad-wash: #fbe8e5;
  --idle: #6e6e76;
  --idle-wash: #edf1f4;

  /* The brand's shape: one corner opened up. The public site uses 80px on a
     marketing card; a data panel needs the same gesture at a quarter the size. */
  --corner: 10px 10px 28px 10px;

  --sans: "Montserrat", "Helvetica Neue", Helvetica, Arial, sans-serif;
  --serif: "Alice", Georgia, "Times New Roman", serif;
  --mono: ui-monospace, "SF Mono", SFMono-Regular, Menlo, Consolas, monospace;
}

* { box-sizing: border-box; }

body { margin: 0; background: var(--paper); color: var(--ink);
  font: 14px/1.55 var(--sans); -webkit-font-smoothing: antialiased; }

a { color: var(--teal-ink); text-underline-offset: 2px; }
a:hover { color: var(--teal-fill); }

/* Keyboard focus is visible everywhere, in the brand colour. */
:where(a, button, input, select, textarea):focus-visible {
  outline: 2px solid var(--teal-ink); outline-offset: 2px; border-radius: 2px;
}

/* --- Masthead ---------------------------------------------------------------
   The wordmark is set in Alice, the face the logo uses, rather than shipping a
   copy of the logo file. */

header.bar { display: flex; align-items: center; flex-wrap: wrap; gap: .6rem 2rem;
  padding: .85rem 1.75rem; background: var(--panel);
  border-bottom: 1px solid var(--line); }
header.bar h1 { margin: 0; font: 400 22px/1 var(--serif); letter-spacing: .01em; }
header.bar h1 a { color: var(--teal); text-decoration: none; }
header.bar h1 .sub { font: 400 12px/1 var(--sans); color: var(--muted);
  letter-spacing: .06em; margin-left: .6rem; vertical-align: 2px; }
header.bar nav { display: flex; flex-wrap: wrap; gap: .4rem 1.4rem; }
header.bar nav a { color: var(--muted); text-decoration: none; font-weight: 500;
  padding-bottom: 2px; border-bottom: 2px solid transparent; }
header.bar nav a:hover { color: var(--teal-ink); border-bottom-color: var(--teal); }

/* Pushed to the far right and given its own edge, so signing out is never mistaken
   for one more place to navigate to. */
header.bar .session { margin-left: auto; display: flex; align-items: center; gap: .75rem; }
header.bar .session .who { font-size: 12px; color: var(--muted); letter-spacing: .02em; }
header.bar .session form { margin: 0; }
header.bar .session button { font: 500 12px/1 var(--sans); color: var(--muted);
  background: none; border: 1px solid var(--line); border-radius: 5px;
  padding: .4rem .7rem; cursor: pointer; }
header.bar .session button:hover { color: var(--bad); border-color: var(--bad);
  background: var(--bad-wash); }

main { max-width: 1220px; margin: 0 auto; padding: 1.75rem; }

h2 { font: 400 19px/1.3 var(--serif); margin: 2rem 0 .7rem; color: var(--ink); }
h2:first-child { margin-top: 0; }
h2 a { font: 500 12px/1 var(--sans); }

/* --- Surfaces --------------------------------------------------------------- */

.panel { background: var(--panel); border: 1px solid var(--line);
  border-radius: var(--corner); }
.tile { padding: 1rem 1.15rem; }

/* Counts read as one strip divided by rules, not as five identical cards. Each
   number carries its own status colour so the eye lands on failures first. */
.counts { display: grid; grid-template-columns: repeat(auto-fit, minmax(130px, 1fr));
  overflow: hidden; }
.counts > div { padding: 1rem 1.15rem; border-left: 1px solid var(--line); }
.counts > div:first-child { border-left: 0; }
.counts .n { font: 600 28px/1 var(--sans); font-variant-numeric: tabular-nums;
  color: var(--ink); }
.counts .l { color: var(--muted); font-size: 12px; margin-top: .3rem; }
.counts .n-delivered { color: var(--ok); }
.counts .n-failed { color: var(--bad); }
.counts .n-partially_delivered, .counts .n-processing { color: var(--warn); }

/* --- Tables ----------------------------------------------------------------- */

table { width: 100%; border-collapse: collapse; font-size: 13px; }
th { text-align: left; font-weight: 600; font-size: 12px; color: var(--muted);
  padding: .6rem .85rem; background: var(--teal-wash);
  border-bottom: 1px solid var(--line); white-space: nowrap; }
td { padding: .6rem .85rem; border-bottom: 1px solid var(--line);
  vertical-align: top; }
tbody tr:last-child td, table > tr:last-child td { border-bottom: 0; }
.wrap { overflow-x: auto; border-radius: var(--corner); }

/* --- Status ----------------------------------------------------------------- */

.tag { display: inline-block; padding: .15rem .5rem; border-radius: 4px;
  font-size: 11px; font-weight: 600; white-space: nowrap; }
.s-delivered, .s-succeeded, .s-active { background: var(--ok-wash); color: var(--ok); }
.s-partially_delivered, .s-pending, .s-processing, .s-invited { background: var(--warn-wash); color: var(--warn); }
.s-failed { background: var(--bad-wash); color: var(--bad); }
.s-skipped, .s-received, .s-inactive { background: var(--idle-wash); color: var(--idle); }

/* --- Data ------------------------------------------------------------------
   Monospace here is structural, not stylistic: HL7 is positional, and a segment
   only reads correctly when its delimiters line up. */

code, pre, textarea, .field-insert { font-family: var(--mono); }
code { font-size: 12px; }
pre { background: #f8fafb; border: 1px solid var(--line); border-radius: 6px;
  padding: .85rem; overflow-x: auto; max-height: 340px; font-size: 12px;
  line-height: 1.5; margin: 0; }

.muted { color: var(--muted); }

.pager { display: flex; gap: 1.25rem; margin-top: 1rem; }

/* --- Controls --------------------------------------------------------------- */

label { display: block; font-size: 13px; }
label .muted { font-weight: 400; }

/* Guidance for a control sits under it on its own line. Left inline it wraps
   around the control and reads as prose rather than as help. */
.hint { display: block; color: var(--muted); font-size: 12px; margin-top: .3rem;
  max-width: 62ch; }

input[type=text], input[type=search], input[type=password], select, textarea {
  padding: .5rem .7rem; border: 1px solid var(--line); border-radius: 6px;
  font: inherit; background: var(--panel); color: var(--ink); max-width: 100%; }
textarea { font-size: 12px; line-height: 1.55; }
input[type=text]:hover, input[type=search]:hover, textarea:hover, select:hover {
  border-color: #c9d6de; }
select { padding: .45rem .5rem; }

form.search { display: flex; gap: .5rem; margin-bottom: 1rem; }
form.search input[type=text] { flex: 1; }

button, input[type=submit] { padding: .45rem .9rem; border: 1px solid var(--line);
  background: var(--panel); color: var(--ink); border-radius: 6px; font: inherit;
  font-size: 13px; cursor: pointer; }
button:hover, input[type=submit]:hover { border-color: var(--teal); color: var(--teal-ink); }

/* Rails names the primary submit of a form `commit`; secondary submits carry
   their own name. So the brand fill lands on exactly one button per form. */
input[type=submit][name=commit] {
  background: var(--teal-fill); border-color: var(--teal-fill); color: #fff; font-weight: 500; }
input[type=submit][name=commit]:hover {
  background: var(--teal-ink); border-color: var(--teal-ink); color: #fff; }

fieldset { border: 1px solid var(--line); border-radius: 8px; padding: .9rem 1rem; }
legend { font-size: 12px; color: var(--muted); padding: 0 .35rem; }

.flash { padding: .7rem 1rem; background: var(--teal-wash);
  border: 1px solid #bfeaea; border-radius: 8px; margin-bottom: 1rem; }

dl.kv { display: grid; grid-template-columns: max-content 1fr; gap: .45rem 1.25rem;
  margin: 0; }
dl.kv dt { color: var(--muted); font-size: 12px; padding-top: 1px; }
dl.kv dd { margin: 0; }

/* --- Mapping editor ---------------------------------------------------------
   Template on the left, the fields it can reference on the right. The settings
   above them run several to a row so that pairing gets the full width: the field
   list is only useful beside the box the template is typed into. */

.editor { display: grid; grid-template-columns: minmax(0, 3fr) minmax(0, 2fr);
  gap: 1.1rem; align-items: start; }

.field-grid { display: grid; gap: .85rem 1.25rem; align-items: start;
  grid-template-columns: repeat(auto-fit, minmax(15rem, 1fr)); }
/* A filter expression, a transport's settings and a checkbox with a sentence
   after it all read badly in a narrow column. */
.field-grid > .wide, .field-grid > fieldset { grid-column: 1 / -1; }

/* Both halves of the editor are cut to the window rather than to their contents.
   A template of sixty lines and a message of three hundred fields would
   otherwise each run off the bottom of the page, and the field list would be a
   scroll away from the box it is meant to be read beside. Each scrolls inside
   itself instead, and the pair stays level. */
.mapping { align-items: stretch; }
.mapping > .panel { height: calc(100vh - 8rem); min-height: 26rem; }

.template-panel { display: grid; grid-template-rows: 1fr auto; gap: .85rem;
  min-height: 0; }
.template-panel > label { display: grid; grid-template-rows: auto 1fr; gap: .35rem;
  min-height: 0; }
/* Dragging the corner would only push the buttons out of the panel. */
.template-panel textarea { height: 100%; min-height: 0; resize: none; }

/* The head holds still so the filter box stays reachable; the list and the notes
   under it scroll together. */
.reference { display: flex; flex-direction: column; overflow: hidden; }
.reference-head { flex: none; border-bottom: 1px solid var(--line); }
.reference-scroll { flex: 1 1 auto; min-height: 0; overflow-y: auto; }

/* One column, and nothing cut to the window: on a phone a full-height panel
   would cover the thing being edited. */
@media (max-width: 900px) {
  .editor { grid-template-columns: 1fr; }
  .mapping > .panel { height: auto; }
  .template-panel textarea { height: 24rem; }
  .reference-scroll { overflow: visible; }
}

.fields { border-radius: 0; }
.fields td { padding: .3rem .6rem; font-size: 12px; }
.fields th { position: sticky; top: 0; }
.fields code { font-size: 11px; white-space: nowrap; }
.fields .rep { color: var(--warn); }

/* Field rows are buttons so they can be clicked into the template, but they
   should read as the paths they are, not as controls. */
.field-insert { padding: .15rem .35rem; border: 1px solid transparent;
  background: none; font-size: 11px; color: var(--ink); cursor: pointer;
  text-align: left; border-radius: 4px; }
.field-insert:hover { background: var(--teal-wash); color: var(--teal-ink); }

@media (prefers-reduced-motion: reduce) {
  * { animation: none !important; transition: none !important; }
}

@media (max-width: 640px) {
  main { padding: 1rem; }
  header.bar { padding: .75rem 1rem; }
  header.bar nav { gap: .4rem .95rem; }
  dl.kv { grid-template-columns: 1fr; gap: .1rem .5rem; }
  dl.kv dd { margin-bottom: .5rem; }
}

/* --- Copying, and reading a message body ------------------------------------
   A result message is several hundred lines with the readings buried in the
   middle, so it gets a bar of its own: how big it is, and the ways out of it. */
.visually-hidden { position: absolute; width: 1px; height: 1px; margin: -1px;
  padding: 0; overflow: hidden; clip-path: inset(50%); white-space: nowrap; }

.copy { margin-left: .4rem; }
/* Shown only when a copy fails, so it has to read as a problem rather than as
   a caption that was always there. */
.payload [role="status"]:not(.visually-hidden),
.copy [role="status"]:not(.visually-hidden) {
  display: block; margin: .35rem 0 0; color: var(--bad); font-size: 12px; }
.copy button, .payload-actions button {
  background: none; border: 1px solid var(--line); border-radius: 5px;
  padding: .1rem .45rem; font: 500 11px/1.6 var(--sans); color: var(--muted);
  cursor: pointer; white-space: nowrap; }
.copy button:hover, .payload-actions button:hover {
  border-color: var(--teal); color: var(--teal-ink); background: var(--teal-wash); }

.payload { margin: 0 0 .4rem; }
.payload-bar { display: flex; align-items: center; justify-content: space-between;
  gap: 1rem; margin-bottom: .35rem; font-size: 12px; }
.payload-actions { display: flex; gap: .35rem; flex-wrap: wrap; }

/* The tree replaces the raw text once it has been built. Until then -- and when
   the body is too big to fold, or the browser has no JavaScript -- the <pre> is
   what is shown, so the message is readable either way. */
.payload .json-tree { display: none; }
.payload.json-ready .json-tree { display: block; }
.payload.json-ready pre { display: none; }
.payload.json-ready.showing-raw .json-tree { display: none; }
.payload.json-ready.showing-raw pre { display: block; }

.json-tree { background: #f8fafb; border: 1px solid var(--line); border-radius: 6px;
  padding: .85rem; overflow-x: auto; max-height: 340px; overflow-y: auto;
  font-family: var(--mono); font-size: 12px; line-height: 1.55; }
.json-tree details > summary { cursor: pointer; list-style: none; }
.json-tree details > summary::-webkit-details-marker { display: none; }
.json-tree details > summary::before { content: "▸"; display: inline-block;
  width: 1em; color: var(--muted); }
.json-tree details[open] > summary::before { content: "▾"; }
.json-tree summary:hover { background: var(--teal-wash); border-radius: 3px; }
.json-tree .json-body { margin-left: 1em; border-left: 1px solid var(--line);
  padding-left: .6rem; }
.json-tree .json-row { padding-left: 1em; }
.json-tree .json-key { color: var(--teal-ink); }
.json-tree .json-string { color: #1b7f4b; }
.json-tree .json-number, .json-tree .json-boolean { color: #b07400; }
.json-tree .json-null { color: var(--muted); font-style: italic; }
.json-tree .json-punct { color: var(--muted); }
.json-tree .json-count { color: var(--muted); font-size: 11px; }
.json-tree .json-clipped { cursor: pointer; border-bottom: 1px dotted var(--muted); }
.json-tree .json-clipped:hover { background: var(--teal-wash); }

/* --- HL7 outline ------------------------------------------------------------
   Server-rendered, so it is visible from the first paint and stays readable if
   the JavaScript never arrives. Raw text is the alternate view, not the default. */
.payload.is-hl7 pre { display: none; }
.payload.is-hl7.showing-raw pre { display: block; }
.payload.is-hl7.showing-raw .hl7 { display: none; }

.hl7 { background: #f8fafb; border: 1px solid var(--line); border-radius: 6px;
  padding: .55rem .85rem .85rem; max-height: 520px; overflow-y: auto; }
.hl7-summary { margin: .2rem 0 .6rem; font-size: 12px; }

.hl7-segment { border-top: 1px solid var(--line); }
.hl7-segment:first-of-type { border-top: 0; }
.hl7-segment > summary { cursor: pointer; list-style: none; padding: .35rem 0;
  display: flex; align-items: baseline; gap: .5rem; font-size: 12px; }
.hl7-segment > summary::-webkit-details-marker { display: none; }
.hl7-segment > summary::before { content: "▸"; color: var(--muted); width: 1em; }
.hl7-segment[open] > summary::before { content: "▾"; }
.hl7-segment > summary:hover { background: var(--teal-wash); border-radius: 3px; }
.hl7-name { font-weight: 600; color: var(--teal-ink); }
.hl7-count { margin-left: auto; font-size: 11px; }

table.hl7-fields { width: auto; margin: 0 0 .3rem 1.6rem; font-size: 12px; }
table.hl7-fields tr:last-child th, table.hl7-fields tr:last-child td { border-bottom: 0; }
table.hl7-fields th { background: none; padding: .2rem .9rem .2rem 0; white-space: nowrap;
  border-bottom: 1px solid #eef2f5; font-weight: 400; vertical-align: top; }
table.hl7-fields th code { display: inline-block; min-width: 1.6em; text-align: right;
  color: var(--muted); margin-right: .45rem; }
table.hl7-fields td { padding: .2rem 0; border-bottom: 1px solid #eef2f5;
  font-family: var(--mono); }

.hl7-rep + .hl7-rep { margin-top: .15rem; }
.hl7-repno { color: var(--muted); margin-right: .4rem; }
/* Components are shown side by side with their position, because "which caret am
   I looking at" is the question a composite field raises. */
.hl7-piece { display: inline-block; margin-right: .7rem; }
.hl7-pieceno { color: var(--muted); font-size: 10px; vertical-align: super;
  margin-right: .15rem; }
.hl7-value { color: var(--ink); }
.hl7-empties { margin: .1rem 0 .5rem 1.6rem; font-size: 11px; }

/* --- Questions ---------------------------------------------------------------
   The whole point of the screen is that an unanswered question is louder than an
   answered one, so the difference is carried by four things at once -- the left
   edge, the fill, the weight of the question itself, and whether the answer box
   is already open. One signal would be missed by somebody skimming. */
.question { border: 1px solid var(--line); border-radius: var(--corner);
  background: var(--panel); padding: 1rem 1.15rem; margin: 0 0 .85rem;
  max-width: 62rem; }
.question > header { display: flex; align-items: baseline; gap: .6rem;
  flex-wrap: wrap; font-size: 12px; margin-bottom: .5rem; }
.question-who { color: var(--muted); }
.question-age { margin-left: auto; }
.question-body { margin: 0 0 .4rem; }
.question-context { margin: 0 0 .7rem; font-size: .9rem; max-width: 62ch; }

.question.is-unanswered { border-left: 4px solid var(--warn);
  background: var(--warn-wash); border-color: #ecd9ad; }
.question.is-unanswered .question-body { font-size: 1.05rem; font-weight: 600;
  color: var(--ink); }

.question.is-answered { border-left: 4px solid var(--ok); }
.question.is-answered .question-body { color: var(--muted); }

.answers { margin: 0 0 .7rem; padding-left: 1.1rem; }
.answers li { margin-bottom: .55rem; }
.answers li p { margin: 0; }
.answers li p:first-child { white-space: pre-wrap; }
.answer-by { font-size: 11px; margin-top: .15rem !important; }

/* Answered questions keep their answer box, but out of the way: the common case
   is reading them, not adding a second answer. */
.question.is-answered .answer-form { opacity: .55; }
.question.is-answered .answer-form:focus-within { opacity: 1; }
.question.is-unanswered .answer-form textarea { background: var(--panel); }

/* A count on the tab, so an unanswered question is visible from every screen
   rather than only from this one. */
.nav-count { display: inline-block; min-width: 1.1rem; padding: 0 .3rem;
  margin-left: .25rem; border-radius: 999px; background: var(--warn);
  color: #fff; font-size: 10px; font-weight: 600; text-align: center;
  vertical-align: text-top; }
