/* ============================================================================
   ZKELETON // HL7 v2 -> FHIR R4 converter — page styles
   A full-height IDE shell: a thin top bar, a tool bar (lede + samples), a
   50/50 split-pane converter that fills the viewport, and a VS Code-style
   status bar. One accent (vermillion) reserved for the signature: the
   "needs review" drawer inside the FHIR pane. Extends tokens.css.
============================================================================ */

/* ------------------------------------------------------------------ app shell */
html, body { height: 100%; }
.app {
  display: flex;
  flex-direction: column;
  height: 100dvh;
  overflow: hidden;            /* desktop: only the code panes scroll */
  background: var(--bg-app);
}

/* --------------------------------------------------------------------- top bar */
.topbar {
  flex: none;
  display: flex; align-items: center; justify-content: space-between; gap: 12px;
  height: 40px; padding: 0 var(--pad);
  border-bottom: 1px solid var(--border);
  background: var(--bg-app);
}
.tb-left, .tb-right { display: flex; align-items: center; gap: 12px; min-width: 0; }
.brand {
  font-family: var(--font-mono); font-weight: 700; font-size: 12px;
  letter-spacing: 0.12em; color: var(--text);
  display: inline-flex; align-items: center; gap: 9px; white-space: nowrap;
}
.brand .dot {
  width: 7px; height: 7px; border-radius: 50%; background: var(--accent);
  box-shadow: 0 0 0 3px color-mix(in srgb, var(--accent) 16%, transparent);
  animation: dotpulse 2.4s var(--ease) infinite;
}
.brand .sep { color: var(--faint); font-weight: 500; }
.brand .sub { color: var(--muted); font-weight: 600; }
.tag-free {
  font-family: var(--font-mono); font-size: 9px; font-weight: 500;
  letter-spacing: 0.16em; text-transform: uppercase; color: var(--muted-2);
  border: 1px solid var(--border-strong); border-radius: 3px; padding: 2px 6px;
}
.tb-right { font-family: var(--font-mono); font-size: 11px; color: var(--muted); letter-spacing: 0.04em; }
.tb-sep { color: var(--faint); }
.tb-meta { display: inline-flex; align-items: center; gap: 7px; white-space: nowrap; }
.tb-key { color: var(--faint); text-transform: uppercase; letter-spacing: 0.12em; font-size: 10px; font-weight: 600; }
.tb-val { color: var(--muted-2); }
#clock { color: var(--text); }
@keyframes dotpulse { 0%,100% { opacity: 1; } 50% { opacity: 0.45; } }

/* -------------------------------------------------------------------- tool bar */
.toolbar {
  flex: none;
  display: flex; align-items: center; justify-content: space-between; gap: 18px;
  padding: 9px var(--pad);
  background: var(--bg-app);
}
.samples { display: flex; align-items: center; gap: 8px; min-width: 0; }
.samples .lab {
  flex: none; font-family: var(--font-mono); font-size: 10px; font-weight: 500;
  letter-spacing: 0.16em; text-transform: uppercase; color: var(--faint);
}
#sampleChips { display: flex; gap: 8px; min-width: 0; overflow-x: auto; scrollbar-width: none; }
#sampleChips::-webkit-scrollbar { display: none; }

.chip-btn {
  flex: none; cursor: pointer; white-space: nowrap;
  font-family: var(--font-mono); font-size: 12px; font-weight: 500; color: var(--text);
  background: transparent; border: 1px solid var(--border); border-radius: 4px;
  padding: 5px 9px; display: inline-flex; align-items: baseline; gap: 7px;
  transition: background .12s var(--ease), border-color .12s var(--ease), color .12s var(--ease);
}
.chip-btn:hover { background: var(--bg-surface-2); border-color: var(--border-strong); }
.chip-btn .sub { color: var(--muted); font-size: 10px; font-weight: 400; }
/* Clear is a utility, not a sample — strip its border so it reads as secondary */
.chip-btn.ghost { color: var(--muted); border-color: transparent; background: transparent; font-weight: 500; }
.chip-btn.ghost:hover { color: var(--text); background: var(--border); border-color: transparent; }

/* ----------------------------------------------------------- the split panes */
.conv-grid {
  flex: 1 1 auto; min-height: 0;
  display: grid; grid-template-columns: 1fr 1fr; gap: 0;
  padding: 14px var(--pad);
}
.pane {
  display: flex; flex-direction: column; min-height: 0; min-width: 0;
  border: 1px solid var(--border); border-radius: 0;
  background: var(--bg-surface); overflow: hidden;
}
.pane.output { border-left: 0; }   /* the two panes share one crisp 1px seam */
.pane-head {
  flex: none; display: flex; align-items: center; gap: 10px;
  height: 38px; padding: 0 8px 0 12px;
  border-bottom: 1px solid var(--border); background: var(--bg-surface);
}
.pane-tag {
  font-family: var(--font-mono); font-weight: 700; font-size: 11px;
  letter-spacing: 0.11em; text-transform: uppercase; color: var(--muted-2);
  white-space: nowrap;
}
.pane-io {
  font-family: var(--font-mono); font-size: 9.5px; font-weight: 500;
  letter-spacing: 0.18em; color: var(--text);
  border: 1px solid var(--faint); border-radius: 3px; padding: 1px 5px;
}
.pane-sub { font-family: var(--font-mono); font-size: 11px; color: var(--faint); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; min-width: 0; }
.pane-actions { margin-left: auto; display: flex; gap: 2px; flex: none; }
.act {
  font-family: var(--font-sans); font-size: 12px; color: var(--muted);
  background: transparent; border: 0; border-radius: 4px; padding: 5px 8px;
  cursor: pointer; display: inline-flex; align-items: center; gap: 6px;
  transition: color .12s var(--ease), background .12s var(--ease); white-space: nowrap;
}
.act:hover:not(:disabled) { color: var(--text); background: var(--bg-surface-2); }
.act:disabled { opacity: 0.38; cursor: default; }
.act.done { color: var(--text); }
.act svg { width: 14px; height: 14px; flex: none; }

.pane-body { position: relative; flex: 1 1 auto; min-height: 0; min-width: 0; display: flex; flex-direction: column; }

textarea.hl7-in {
  flex: 1 1 auto; min-height: 0; width: 100%; resize: none; border: 0; outline: none;
  background: transparent; color: var(--text);
  font-family: var(--font-mono); font-size: 13px; line-height: 1.5;
  padding: 16px; tab-size: 2; overflow: auto;
}
textarea.hl7-in::placeholder { color: var(--faint); }

.fhir-out {
  flex: 1 1 auto; min-height: 0; margin: 0; overflow: auto;
  padding: 16px; font-family: var(--font-mono); font-size: 13px; line-height: 1.5;
  color: var(--text); white-space: pre;
}
.fhir-out .placeholder {
  color: var(--faint); white-space: normal; display: block; text-align: center;
  margin: 15% auto 0; max-width: 46ch; line-height: 1.6;
}
.fhir-out .placeholder .ph-glyph { display: block; color: var(--faint); font-size: 15px; letter-spacing: 0.04em; margin-bottom: 10px; }
.fhir-out .err { color: var(--accent); white-space: normal; display: block; max-width: 64ch; }

/* JSON syntax — strictly monochromatic. Vermillion is sacred: reserved for the
   brand, the needs-review drawer, and errors — never routine data. */
.j-key  { color: var(--muted); }
.j-str  { color: var(--text); }
.j-num  { color: #a3a3a3; }
.j-bool { color: #a3a3a3; }
.j-null { color: var(--faint); }

/* live reaction: pulse the FHIR pane border when output updates */
.pane.output.live { animation: panepulse 0.5s var(--ease); }
@keyframes panepulse {
  0%   { border-color: var(--border-strong); box-shadow: inset 0 0 0 1px var(--border-strong); }
  100% { border-color: var(--border); box-shadow: inset 0 0 0 1px transparent; }
}

/* ----------------------------------------- needs-review drawer (inside FHIR pane) */
.review-panel {
  flex: none; max-height: 46%; overflow: auto;
  border-top: 2px solid var(--accent); background: var(--accent-surface);
  padding: 12px 16px 14px;
}
.review-panel.hidden { display: none; }
.review-panel:not(.hidden) { animation: drawerup 0.26s var(--ease); }
@keyframes drawerup { from { opacity: 0; transform: translateY(8px); } to { opacity: 1; transform: translateY(0); } }
.review-panel h4 {
  margin: 0 0 3px; display: flex; align-items: center; gap: 8px;
  font-family: var(--font-mono); font-size: 11px; font-weight: 700;
  letter-spacing: 0.12em; text-transform: uppercase; color: var(--accent);
}
.review-panel h4::before {
  content: "!"; flex: none; display: inline-grid; place-items: center;
  width: 15px; height: 15px; border: 1.5px solid var(--accent); border-radius: 50%;
  font-size: 10px; font-weight: 700; line-height: 1;
}
.review-panel h4 .ct { color: var(--muted-2); font-weight: 500; letter-spacing: 0.04em; }
.review-panel .rp-sub { margin: 0 0 16px; font-size: 12px; color: var(--muted); }
.review-list { display: flex; flex-direction: column; gap: 7px; }
.review-item {
  font-family: var(--font-mono); font-size: 12px; color: var(--text);
  display: flex; gap: 9px; align-items: baseline; line-height: 1.45;
}
.review-item .tag {
  flex: none; font-family: var(--font-mono); font-size: 10px; letter-spacing: 0.06em;
  text-transform: uppercase; color: var(--accent); background: #3a1a1e;
  border: 1px solid var(--accent-border); border-radius: 3px; padding: 2px 6px;
}
.review-item .mono { color: var(--muted); }
.review-item + .review-item { border-top: 1px solid color-mix(in srgb, var(--accent) 13%, var(--border)); padding-top: 8px; }

/* ------------------------------------------------------------ bottom status bar */
.statusbar {
  flex: none; display: flex; align-items: center; justify-content: space-between; gap: 16px;
  height: 32px; padding: 0 var(--pad);
  border-top: 1px solid var(--border); background: var(--bg-app);
  font-family: var(--font-mono); font-size: 11px; color: var(--muted); overflow: hidden;
}
.status-left { display: flex; align-items: center; min-width: 0; overflow: hidden; }
.stat-bar { display: flex; align-items: center; gap: 7px; min-width: 0; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.stat-bar.hidden { display: none; }
.stat-bar .fmt { color: var(--text); font-weight: 700; }
.stat-bar .res { color: var(--text); }
.stat-bar .sep { color: var(--faint); }
.stat-bar .pill-ct { color: var(--muted); }
.stat-bar .pill-ct.review { color: var(--accent); font-weight: 500; }
.status-idle { color: var(--faint); white-space: nowrap; }

.trust { display: flex; align-items: center; gap: 18px; flex: none; }
.trust .fact { display: inline-flex; align-items: center; gap: 7px; color: #b8b8b8; font-weight: 500; white-space: nowrap; }
.trust .fact svg { width: 13px; height: 13px; flex: none; color: var(--muted); }

/* ---------------------------------------------------------------- scrollbars */
/* custom across the whole app — never the chunky native OS bar on dark UI */
* { scrollbar-width: thin; scrollbar-color: var(--border-strong) transparent; }
::-webkit-scrollbar { width: 8px; height: 8px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: var(--border-strong); border-radius: 4px; }
::-webkit-scrollbar-thumb:hover { background: var(--faint); }
::-webkit-scrollbar-corner { background: transparent; }

/* ----------------------------------------------------------- keyboard focus */
.chip-btn:focus-visible, .act:focus-visible, .tb-link:focus-visible {
  outline: 2px solid var(--muted-2); outline-offset: 2px; border-radius: 4px;
}
.pane:focus-within { border-color: var(--border-strong); }

/* --------------------------------------------------------------- responsive */
/* toolbar is one compact strip at all widths; mobile rules handled below */
@media (max-width: 860px) {
  .app { height: auto; min-height: 100dvh; overflow: visible; }   /* mobile: page scrolls */
  .conv-grid { grid-template-columns: 1fr; gap: 12px; padding: 12px var(--pad); }
  .pane { height: auto; }
  /* bounded code viewports so each pane keeps a horizontal scrollbar near the
     content (panes are stacked here, so the output regains its left border) */
  .pane.input { min-height: 240px; max-height: 52vh; }
  .pane.output { min-height: 360px; max-height: 68vh; border-left: 1px solid var(--border); }
  .review-panel { max-height: none; }
  /* give the horizontal chip scroller room so chips don't ride the divider */
  .toolbar { padding-bottom: 12px; }
  #sampleChips { padding-bottom: 4px; }
  /* status bar stacks so nothing is clipped on small screens */
  .statusbar { height: auto; flex-direction: column; align-items: flex-start; gap: 6px; padding: 9px var(--pad); }
  .status-left { width: 100%; }
  .stat-bar { white-space: normal; overflow: visible; flex-wrap: wrap; }
  .trust { flex-wrap: wrap; gap: 8px 16px; }
}
@media (max-width: 560px) {
  :root { --pad: 14px; }
  .toolbar { padding: 9px var(--pad); }
  .tb-meta.runtime { display: none; }          /* tighten the header: drop runtime/clock on phones */
  .act .lbl { display: none; }                 /* icon-only actions */
  .pane-sub { display: none; }                 /* free up the narrow output header */
  .statusbar { font-size: 10px; }
  ::-webkit-scrollbar { width: 4px; height: 4px; }
}
@media (max-width: 430px) {
  .brand .sub, .tag-free { display: none; }     /* keep just the wordmark + accent dot */
}
