/*
 * The interactive portal preview.
 *
 * An application window sitting on the greenbar paper — same palette, same
 * type, same flat bordered industrial language as the rest of the site, but
 * framed so it reads as software rather than marketing. Tokens all come from
 * styles.css; nothing is redefined here.
 *
 * Everything is keyboard reachable and every state change is announced, because
 * the whole point is showing what the product is like to use.
 */

.demo {
  margin-top: 8px;
}

/* --- window frame -------------------------------------------------------- */

.win {
  border: 1px solid var(--rule-strong);
  background: var(--paper);
  box-shadow: 6px 6px 0 var(--rule);
  display: grid;
  /*
   * `minmax(0, 1fr)`, not the implicit `auto`.
   *
   * An auto column sizes to its content's max-content width, and the sign-in card
   * inside asks for 400px plus padding. On a 360px phone that made the column
   * 487px wide inside a 328px frame — and because this element clips rather than
   * scrolls, the right third of the preview was simply not there. The card's own
   * `width: min(400px, 100%)` was already correct and could not help: its 100%
   * resolved against a track that had sized itself to the card.
   *
   * Measured with `node tools/mobile-audit.mjs`, which is also the only way this
   * was ever going to be noticed — it looks perfect on a laptop.
   */
  grid-template-columns: minmax(0, 1fr);
  grid-template-rows: auto 1fr;
  min-height: 560px;
  overflow: hidden;
}

.win-bar {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 9px 14px;
  border-bottom: 1px solid var(--rule-strong);
  background: var(--band);
  font-family: var(--mono);
  font-size: 12px;
  letter-spacing: 0.04em;
}

.win-bar strong {
  font-weight: 600;
  text-transform: uppercase;
}

.win-bar .dot {
  width: 8px;
  height: 8px;
  border: 1px solid var(--rule-strong);
  background: var(--ok);
  flex: none;
}

.win-url {
  color: var(--muted);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  /* A flex item's `min-width` is `auto`, so the ellipsis above never engaged. */
  min-width: 0;
}

.win-bar .spacer {
  flex: 1;
}

.win-tag {
  border: 1px solid var(--rule-strong);
  padding: 2px 7px;
  background: var(--paper);
  color: var(--muted);
  font-size: 11px;
  white-space: nowrap;
}

.signin-card p.hint {
  margin: 0 0 20px;
  color: var(--muted);
  font-size: 13.5px;
  line-height: 1.5;
}

.field {
  display: block;
  margin-bottom: 14px;
}

.field > span {
  display: block;
  font-family: var(--mono);
  font-size: 11px;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--muted);
  margin-bottom: 5px;
}

.field input,
.field select,
.field textarea {
  width: 100%;
  font-family: var(--mono);
  font-size: 13px;
  color: var(--ink);
  background: var(--bg);
  border: 1px solid var(--rule-strong);
  padding: 9px 10px;
}

.field input:focus-visible,
.field select:focus-visible,
.field textarea:focus-visible {
  outline: 2px solid var(--blue);
  outline-offset: 1px;
}

@media (max-width: 760px) {
  .app {
    grid-template-columns: 1fr;
  }
}

@media (max-width: 760px) {
  .rail {
    border-right: 0;
    border-bottom: 1px solid var(--rule-strong);
    flex-direction: row;
    overflow-x: auto;
    padding: 0;
  }
}

@media (max-width: 760px) {
  .rail-who {
    display: none;
  }
}

@media (max-width: 760px) {
  .rail button {
    border-left: 0;
    border-bottom: 3px solid transparent;
  }

  .rail button[aria-current='true'] {
    border-left: 0;
    border-bottom-color: var(--blue);
  }
}

.rail .count {
  font-family: var(--mono);
  font-size: 10.5px;
  color: var(--muted);
}

.rail .spacer {
  flex: 1;
}

@media (max-width: 760px) {
  .rail-out {
    border-top: 0;
    margin: 0;
    padding-top: 0;
  }
}

.view-head .spacer {
  flex: 1;
}

.view > p.note {
  margin: 0 0 18px;
  color: var(--muted);
  font-size: 13.5px;
  line-height: 1.55;
  max-width: 62ch;
}

/* --- data tables --------------------------------------------------------- */

.tbl-wrap {
  overflow-x: auto;
  border: 1px solid var(--rule-strong);
}

table.tbl {
  width: 100%;
  border-collapse: collapse;
  font-family: var(--mono);
  font-size: 12.5px;
}

table.tbl th {
  text-align: left;
  font-weight: 600;
  font-size: 10.5px;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--muted);
  padding: 8px 12px;
  border-bottom: 1px solid var(--rule-strong);
  background: var(--paper);
  white-space: nowrap;
}

table.tbl td {
  padding: 8px 12px;
  border-bottom: 1px solid var(--rule);
  white-space: nowrap;
}

table.tbl tbody tr:nth-child(odd) {
  background: var(--band);
}

table.tbl tbody tr.clickable {
  cursor: pointer;
}

table.tbl tbody tr.clickable:hover {
  background: var(--band-edge);
}

table.tbl tbody tr:focus-visible {
  outline: 2px solid var(--blue);
  outline-offset: -2px;
}

/* Head and body together. The validator's "Quantity" and "Price" headers are
   marked `num` in the markup and were never turned round here, so each sat at
   the left of a column of right-aligned figures. */
table.tbl th.num,
table.tbl td.num {
  text-align: right;
}

table.tbl td.wide {
  white-space: normal;
  min-width: 18ch;
}

/* --- status pills -------------------------------------------------------- */

.pill {
  display: inline-block;
  font-family: var(--mono);
  font-size: 10.5px;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  border: 1px solid currentcolor;
  padding: 1px 6px;
  white-space: nowrap;
}

.pill--warn {
  color: var(--warn);
}

.pill--fail {
  color: var(--fail);
}

/* --- buttons ------------------------------------------------------------- */

.mini {
  appearance: none;
  font-family: var(--mono);
  font-size: 11.5px;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  color: var(--ink);
  background: var(--paper);
  border: 1px solid var(--rule-strong);
  padding: 5px 10px;
  cursor: pointer;
}

.mini:hover {
  background: var(--band);
}

.mini:disabled {
  color: var(--muted);
  cursor: not-allowed;
  background: var(--bg);
}

.mini--primary {
  background: var(--ink);
  color: var(--paper);
  border-color: var(--ink);
}

.mini--primary:hover {
  background: var(--ink);
  opacity: 0.86;
}

.mini--primary:disabled {
  opacity: 0.5;
  background: var(--ink);
  color: var(--paper);
}

.card {
  border: 1px solid var(--rule-strong);
  padding: 14px;
  background: var(--paper);
  min-width: 0;
}

.card h4 {
  margin: 0 0 3px;
  font-size: 14px;
}

.card p {
  margin: 0;
  color: var(--muted);
  font-size: 12.5px;
  line-height: 1.5;
}

.card .meta {
  font-family: var(--mono);
  font-size: 11px;
  color: var(--muted);
  margin-top: 9px;
  word-break: break-all;
}

.card--metric span.label {
  display: block;
  font-family: var(--mono);
  font-size: 10.5px;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--muted);
  margin-bottom: 6px;
}

.panel {
  border: 1px solid var(--rule-strong);
  padding: 16px;
  background: var(--band);
  margin-top: 16px;
}

.panel h4 {
  margin: 0 0 8px;
  font-size: 14px;
}

.panel p {
  margin: 0 0 10px;
  font-size: 13px;
  line-height: 1.55;
  color: var(--muted);
  max-width: 62ch;
}

.panel p:last-child {
  margin-bottom: 0;
}

@media (max-width: 900px) {
  .detail-grid {
    grid-template-columns: 1fr;
  }
}

.code {
  border: 1px solid var(--rule-strong);
  background: var(--paper);
  min-width: 0;
}

.code h4 {
  margin: 0;
  padding: 7px 12px;
  border-bottom: 1px solid var(--rule);
  font-family: var(--mono);
  font-size: 10.5px;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--muted);
  font-weight: 600;
}

.code pre {
  margin: 0;
  padding: 12px;
  overflow-x: auto;
  font-family: var(--mono);
  font-size: 12px;
  line-height: 1.75;
  tab-size: 2;
}

.code pre .seg {
  color: var(--blue);
  font-weight: 600;
}

.code pre .sep {
  color: var(--muted);
}

.code pre .k {
  color: var(--num);
}

.code pre .s {
  color: var(--str);
}

.code pre .d {
  color: var(--ok);
}

/* --- inline messages ----------------------------------------------------- */

.msg {
  border: 1px solid currentcolor;
  padding: 10px 12px;
  font-size: 13px;
  line-height: 1.5;
  margin-top: 14px;
}

.msg--ok {
  color: var(--ok);
}

.msg--fail {
  color: var(--fail);
}

.msg--info {
  color: var(--blue);
}

.msg b {
  font-weight: 600;
}

.msg .mono {
  font-family: var(--mono);
  font-size: 12px;
  word-break: break-all;
}

/* --- working indicator --------------------------------------------------- */

.working {
  display: inline-block;
  font-family: var(--mono);
  font-size: 11.5px;
  color: var(--muted);
}

.working::after {
  content: '';
  animation: dots 1.2s steps(4, end) infinite;
}

@keyframes dots {
  0% {
    content: '';
  }
  25% {
    content: '.';
  }
  50% {
    content: '..';
  }
  75% {
    content: '...';
  }
}

@media (prefers-reduced-motion: reduce) {
  .working::after {
    content: '...';
    animation: none;
  }

  .meter i {
    transition: none;
  }
}

.empty {
  border: 1px dashed var(--rule-strong);
  padding: 22px;
  text-align: center;
  color: var(--muted);
  font-size: 13px;
}

/* --- request-a-sandbox form --------------------------------------------- */

.sandbox-form {
  display: grid;
  gap: 0 16px;
  grid-template-columns: 1fr 1fr;
  margin-top: 18px;
}

@media (max-width: 620px) {
  .sandbox-form {
    grid-template-columns: 1fr;
  }
}

.sandbox-form .wide {
  grid-column: 1 / -1;
}

/* --- phones ---------------------------------------------------------------
 *
 * The portal preview on the landing page is a real copy of the real portal, so
 * it inherits the real portal's density — 13px fields, 27px buttons, 10.5px
 * tags — and on a phone that means the one interactive thing on the page is the
 * least usable thing on the page.
 *
 * Measured, not guessed: `DIR=site PORT=8788 node tools/portal-dev-server.mjs`
 * and then `SITE=true node tools/mobile-audit.mjs http://localhost:8788`.
 */
@media (max-width: 760px) {
  /*
   * 16px is a threshold, not a preference: iOS zooms the whole page when a field
   * under it takes focus. In a preview that is merely ugly; the same rule in the
   * real portal is the difference between signing in on a phone and not.
   */
  /*
   * `.field textarea` explicitly, because that is the selector that set 13px
   * fifteen hundred lines up. A bare `textarea` in a media query has lower
   * specificity than a class-plus-element rule and quietly loses to it — which is
   * how the validator's one input stayed small enough to zoom the page after the
   * fix was supposedly in.
   */
  .field input,
  .field select,
  .field textarea,
  input,
  select,
  textarea {
    font-size: 16px;
    min-height: 44px;
  }

  .mini,
  .btn,
  button {
    min-height: 44px;
    font-size: 13px;
  }

  .field > span {
    font-size: 12.5px;
  }

  #demo-app {
    min-width: 0;
  }

  /*
   * The chrome of the fake browser window, which has nothing to say on a phone.
   * The hostname is the part that carries meaning — it tells you this is the
   * portal — so that stays and the decoration goes.
   */
  .win-bar {
    gap: 8px;
    padding: 9px 12px;
  }

  .win-tag {
    display: none;
  }

  .win {
    min-height: 480px;
  }

  .rail button {
    min-height: 44px;
    font-size: 15px;
    align-items: center;
  }

  .rail .count {
    font-size: 12.5px;
  }
}

/* --- The validator's readable view --------------------------------------- */

/*
 * The payoff of the free validator.
 *
 * It used to answer "is this valid" with a verdict, an error table and two
 * hundred lines of JSON. The JSON is right for somebody writing an integration
 * and wrong for the supplier this product is for, whose entire complaint is
 * that they were handed something unreadable. Answering that with a different
 * unreadable thing proves we can parse and not that we are any use.
 */
.readable {
  border: 1px solid var(--rule-strong);
  background: var(--paper);
  padding: 16px 18px;
}

.readable h4 {
  margin: 0 0 12px;
  font-size: 13px;
  letter-spacing: 0.02em;
}

.readable-kv {
  display: grid;
  grid-template-columns: max-content minmax(0, 1fr);
  gap: 6px 18px;
  margin: 0 0 14px;
  font-size: 13.5px;
}

.readable-kv dt {
  color: var(--muted);
  text-transform: capitalize;
}

.readable-kv dd {
  margin: 0;
  min-width: 0;
  overflow-wrap: anywhere;
}

.readable-lines {
  width: 100%;
  border-collapse: collapse;
  font-size: 13px;
}

.readable-lines th,
.readable-lines td {
  text-align: left;
  padding: 7px 10px 7px 0;
  border-bottom: 1px solid var(--rule);
  vertical-align: top;
}

.readable-lines th {
  font-family: var(--mono);
  font-size: 9.5px;
  letter-spacing: 0.1em;
  text-transform: uppercase;
  color: var(--muted);
  font-weight: 500;
}

.readable-lines .num {
  text-align: right;
  white-space: nowrap;
  font-family: var(--mono);
  padding-right: 0;
}

/* The JSON is still one click away, and the cursor should say so. */
details.code > summary {
  cursor: pointer;
  list-style: revert;
}

details.code > summary h4 {
  margin: 0;
}

/* --- What the file implies ----------------------------------------------- */

/*
 * The part nobody asked for.
 *
 * A verdict is a commodity; every EDI vendor's validator produces one. Telling
 * somebody that six named grocers will never send them the pair they just
 * pasted is the thing they did not know to ask, and it is the only part of this
 * page that comes from having read the guides.
 *
 * Marked out from the error list on purpose: it is not a fault with the file.
 */
.insight {
  border: 1px solid var(--accent, var(--ok));
  border-left-width: 3px;
  background: var(--paper);
  padding: 14px 16px;
  margin-top: 14px;
}

.insight h4 {
  margin: 0 0 6px;
  font-size: 13.5px;
}

.insight p {
  margin: 0;
  font-size: 13.5px;
  line-height: 1.55;
  color: var(--muted);
}

.insight-who {
  margin-top: 8px !important;
  font-family: var(--mono);
  font-size: 11.5px;
  letter-spacing: 0.04em;
  color: var(--ink) !important;
}

/* --- The public error catalogue ------------------------------------------ */

/*
 * A hundred and fifty errors on one page.
 *
 * Somebody arrives here having pasted a code into a search engine at the worst
 * moment of their week. The page has to answer that one code immediately and
 * still be readable if they scroll, so the entries are plain blocks rather than
 * anything collapsible: a disclosure widget hides the answer behind a click
 * from the person least willing to make one.
 */
.err {
  border-top: 1px solid var(--rule);
  padding: 18px 0;
  max-width: 76ch;
}

.err[hidden] {
  display: none;
}

.err h3 {
  margin: 0 0 6px;
  font-family: var(--mono);
  font-size: 14px;
  letter-spacing: 0.02em;
}

.err h3 a {
  color: var(--ink);
  text-decoration: none;
}

.err h3 a:hover {
  text-decoration: underline;
}

.err p {
  margin: 0 0 8px;
  font-size: 14px;
  line-height: 1.6;
}

.err-summary {
  font-weight: 600;
}

.err-do {
  color: var(--ink);
}

.err-tech {
  font-family: var(--mono);
  font-size: 12px;
  color: var(--muted);
}

.err-find input {
  max-width: 34rem;
}
