/* 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); }

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 { background: var(--ok-wash); color: var(--ok); }
.s-partially_delivered, .s-pending, .s-processing { background: var(--warn-wash); color: var(--warn); }
.s-failed { background: var(--bad-wash); color: var(--bad); }
.s-skipped, .s-received { 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. */

.editor { display: grid; grid-template-columns: minmax(0, 3fr) minmax(0, 2fr);
  gap: 1.1rem; align-items: start; }
@media (max-width: 900px) { .editor { grid-template-columns: 1fr; } }

.fields { max-height: 32rem; overflow-y: auto; 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; }
}
