/* HCI Ref's own styles. tokens.css and base.css from BlueTools' shell load first and hold
   the fonts, the colours, the reset, the theme picker, the views switch, the chips, the search
   box, the listing table, the panel's header and the toast; this file adds the columns, the
   filters, the opcode and packet decoder and the details panel.
   What the colours mean here: OGF blue, OCF amber, failures red. */
:root {
  --ogf: var(--blue);
  --ogf-tint: var(--blue-tint);
  --on-ogf: var(--on-blue);
  --ocf: var(--amber);
  --ocf-tint: var(--amber-tint);
  --on-ocf: var(--on-amber);
  --warn: var(--red);
  --warn-tint: var(--red-tint);
}

/* Layout. Narrow screens: one column. JavaScript puts the panel under the row it describes,
   or above the table for a lookup without a row, and hides it when it has nothing to say. */

.page {
  max-width: var(--page);
  margin-inline: auto;
  /* 3rem, not 4rem, above the title: the suite bar takes the top of the window */
  padding: clamp(2rem, 3.5vw, 3rem) var(--gutter) 4rem;
  display: grid;
  grid-template-columns: minmax(0, 1fr);
  gap: 1.5rem 3rem;
}
/* One grid item for everything but the panel, so the search bar can stick all the way down */
.content { display: grid; grid-template-columns: minmax(0, 1fr); align-content: start; gap: 1.25rem; min-width: 0; }
main, .decoder { min-width: 0; }

@media (max-width: 79.99rem) {
  html:not(.js) .decoder { display: none; }
}

/* Wide screens: the panel sits beside the table and stays in view while it scrolls. */

@media (min-width: 80rem) {
  .page { grid-template-columns: minmax(0, 1fr) 23rem; }
  .decoder {
    position: sticky;
    top: 1.25rem;
    align-self: start;
    max-height: calc(100dvh - 2.5rem);
    overflow-y: auto;
    overscroll-behavior: contain;
  }
  /* there is more below: fade the bottom edge */
  .decoder.has-more { mask-image: linear-gradient(to bottom, #000 calc(100% - 3rem), transparent); }
}
@media (min-width: 80rem) and (max-width: 89.99rem) {
  .page { grid-template-columns: minmax(0, 1fr) 21rem; column-gap: 2rem; }
}

/* Heading, version and links */

h1 {
  margin: 0 0 0.875rem;
  font-size: clamp(2.125rem, 1.5rem + 2.4vw, 3rem);
  font-weight: 750;
  line-height: 1;
  letter-spacing: -0.025em;
  text-wrap: balance;
}

.links { display: flex; flex-wrap: wrap; align-items: baseline; gap: 0.375rem 1.25rem; margin: 0; }
.links a { font-weight: 600; }
.downloads { color: var(--muted); }
.downloads a { color: var(--ink); }

/* Search bar: Commands | Events | Errors, the search box and, on phones, the filter button */

@media (min-width: 48rem) {
  .finder .filters-toggle { display: none; }
}

.filters-toggle {
  display: flex;
  align-items: center;
  gap: 0.375rem;
  min-height: 2.75rem;
  padding: 0 1rem;
  border: 1.5px solid var(--edge);
  font: 650 1rem var(--sans);
  white-space: nowrap;
  color: var(--ink);
  background: transparent;
  border-radius: 6px;
  cursor: pointer;
}
.filters-toggle .n { font-weight: 400; color: var(--muted); font-variant-numeric: tabular-nums; }
.filters-toggle:hover, .filters-toggle[aria-expanded="true"] { background: var(--raise); }

@media (max-width: 47.99rem) {
  /* three views and the Filters button on one row */
  .filters-toggle { margin-left: auto; padding: 0 0.75rem; font-size: 0.9375rem; }
  .search { order: 1; }
}

/* Under the search box, for a lookup: how the search was read */

.search-hint { margin-top: -0.375rem; font-size: 0.875rem; color: var(--muted); }
.search-hint p { margin: 0; }
.search-hint strong { color: var(--ink); font-weight: 600; }
.search-hint kbd { padding: 0 0.3rem; border: 1px solid var(--line); border-radius: 4px; font-size: 0.8125rem; }
/* "Also error code 0x0C, Command Disallowed": a link to the other reading */
.search-hint button {
  font: inherit; font-weight: 600; color: var(--ink); background: none; border: 0; padding: 0; cursor: pointer;
  text-decoration: underline; text-decoration-color: color-mix(in srgb, currentColor 40%, transparent); text-underline-offset: 0.18em;
}
.search-hint button:hover { text-decoration-color: currentColor; }

/* Filters: a group (radio buttons drawn as chips) and the release that added it */

.filters { display: grid; gap: 0.75rem; }
.filter {
  display: grid;
  grid-template-columns: 4.5rem minmax(0, 1fr);
  align-items: start;
  margin: 0; padding: 0; border: 0;
  min-width: 0;
}
.filter legend { float: left; padding: 0.4rem 0 0; font-size: 0.875rem; font-weight: 700; color: var(--muted); }

.release-controls { display: flex; flex-wrap: wrap; align-items: center; gap: 0.5rem 1rem; }
.release select {
  font: 600 0.9375rem var(--sans);
  color: var(--ink);
  background-color: var(--paper);
  border: 1px solid var(--edge);
  border-radius: 6px;
  padding: 0.3rem 0.5rem;
  min-width: 12rem;
}
.check { display: inline-flex; align-items: center; gap: 0.375rem; font-size: 0.9375rem; font-weight: 600; cursor: pointer; }
.check input { width: 1.0625rem; height: 1.0625rem; margin: 0; accent-color: var(--ink); cursor: inherit; }
.check:has(input:disabled) { color: var(--muted); cursor: default; }

.filters.is-bypassed .filter { opacity: 0.45; }
.filters-note { margin: 0; font-size: 0.875rem; color: var(--muted); }

@media (max-width: 47.99rem) {
  /* on phones the filters fold away behind the Filters button */
  .js .content:not(.filters-open) .filters { display: none; }
  .filter { grid-template-columns: minmax(0, 1fr); }
  .filter legend { padding: 0 0 0.375rem; }
}

.count { display: flex; flex-wrap: wrap; gap: 0.25rem 0.75rem; margin: 0 0 0.5rem; font-size: 0.875rem; color: var(--muted); }
.count button {
  font: 600 0.875rem var(--sans); color: var(--ink); background: none; border: 0; padding: 0;
  text-decoration: underline; text-decoration-color: color-mix(in srgb, currentColor 40%, transparent);
  text-underline-offset: 0.18em; cursor: pointer;
}
.count button:hover { text-decoration-color: currentColor; }

/* The table's columns */

.listing thead th.c-code { color: var(--ogf); }
.listing thead th.c-sub { color: var(--ocf); }
.th-sub { display: block; font-size: 0.75rem; }
.th-sub .ogf { color: var(--ogf); }
.th-sub .ocf { margin-left: 0.375rem; color: var(--ocf); }

.c-name { width: 31%; }
.c-op { width: 7rem; }
.c-code { width: 4.75rem; }
.c-sub { width: 5.75rem; }
.c-since { width: 5.5rem; font-size: 0.875rem; font-variant-numeric: tabular-nums; }
.c-spec { width: 7rem; }
.c-op, .c-code, .c-sub, .c-spec { white-space: nowrap; }
.c-sum { line-height: 1.45; text-wrap: pretty; }

.name { font: 600 0.875rem var(--mono); text-decoration: none; overflow-wrap: anywhere; }
.name:hover { text-decoration: underline; }
.c-op .opcode, .c-code code { font-weight: 600; }
.c-op .fields { display: block; margin-top: 0.125rem; font-size: 0.8125rem; }
.c-op .fields code { font-size: 1em; }
.c-op .ogf, .c-code code { color: var(--ogf); }
.c-op .ocf, .c-sub code { color: var(--ocf); }
.c-op .ocf { margin-left: 0.375rem; }
.field-name { position: absolute; width: 1px; height: 1px; overflow: hidden; clip-path: inset(50%); white-space: nowrap; }

/* a tag after a name: v2 */
.tag { margin-left: 0.25rem; }
.formerly { display: block; margin-top: 0.125rem; font-size: 0.8125rem; color: var(--muted); overflow-wrap: anywhere; }

.c-spec a { font: 0.875rem var(--mono); }

/* Error codes: names are words, not identifiers; codes aren't OGFs or event codes */
#errors .name { font: 600 0.9375rem var(--sans); }
#errors thead th.c-code, #errors .c-code code { color: inherit; }

/* Without JavaScript both tables show, one after the other, under these headings */
.table-title { margin: 2.5rem 0 0.5rem; font-size: 1.25rem; }
.js .table-title { display: none; }

.empty { padding: 3rem 0; text-align: center; color: var(--muted); }
.empty p { margin: 0 0 1rem; }
.empty-actions, .switches { display: flex; flex-wrap: wrap; justify-content: center; gap: 0.5rem; }
.empty button {
  font: 600 0.875rem var(--sans);
  color: var(--ink);
  background: transparent;
  border: 1px solid var(--edge);
  border-radius: 6px;
  padding: 0.375rem 0.75rem;
  cursor: pointer;
}
.empty button:hover { background: var(--raise); }
.empty button.primary { background: var(--ink); border-color: var(--ink); color: var(--paper); }

/* The panel: what it shows, then the opcode bits or event packet, then the details */

.decoder-help { margin: 0 0 1rem; color: var(--muted); }

/* Opcode decoder: the 16 opcode bits split into the 6-bit OGF and 10-bit OCF */

.decoder-opcode {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 0.25rem 0.375rem;
  margin: 0 0 0.75rem;
}
.decoder-opcode > code { font-size: 2rem; font-weight: 650; letter-spacing: 0.01em; }
.decoder-bytes { display: inline-flex; align-items: center; gap: 0.375rem; margin-left: auto; color: var(--muted); font-size: 0.875rem; }
.decoder-bytes code { color: var(--ink); font-size: 1rem; }

.bits {
  display: grid;
  grid-template-columns: auto 6fr 10fr auto;
  align-items: center;
  gap: 0.5rem;
}
.bit-index { font: 0.75rem var(--mono); color: var(--muted); }
.bits-ogf, .bits-ocf { display: grid; gap: 2px; }
.bits-ogf { grid-template-columns: repeat(6, 1fr); --c: var(--ogf); --tint: var(--ogf-tint); --on: var(--on-ogf); }
.bits-ocf { grid-template-columns: repeat(10, 1fr); --c: var(--ocf); --tint: var(--ocf-tint); --on: var(--on-ocf); }

.bit {
  display: grid;
  place-items: center;
  height: 2.5rem;
  background: var(--tint);
  color: var(--c);
  font: 600 1rem var(--mono);
  transition: background-color 120ms, color 120ms;
}
.bit.on { background: var(--c); color: var(--on); }
.bits-ogf .bit:first-child, .bits-ocf .bit:first-child { border-radius: 4px 0 0 4px; }
.bits-ogf .bit:last-child, .bits-ocf .bit:last-child { border-radius: 0 4px 4px 0; }

.field { grid-row: 2; display: flex; flex-wrap: wrap; gap: 0 0.375rem; align-items: baseline; align-self: start; min-width: 0; margin: 0; font-size: 0.875rem; }
.field-ogf { grid-column: 2; }
.field-ocf { grid-column: 3; }
.field-label { font-weight: 700; }
.field code { font-size: 0.9375rem; font-weight: 600; }
.field-note { flex-basis: 100%; color: var(--muted); }
.field-ogf .field-label, .field-ogf code { color: var(--ogf); }
.field-ocf .field-label, .field-ocf code { color: var(--ocf); }

/* A packet: H4 indicator, opcode or event code, length, subevent (LE events), parameters.
   Cells without a value from the search are dashed. */
.packet {
  display: grid;
  grid-template-columns: repeat(var(--cells, 4), minmax(0, 1fr)) minmax(0, 2fr);
  gap: 2px;
}
[data-command-packet] { margin-top: 1rem; }
.packet span {
  display: block; height: 2.5rem; padding-inline: 0.25rem; border-radius: 4px;
  font: 600 1rem/2.5rem var(--mono); text-align: center;
  overflow: hidden; white-space: nowrap; text-overflow: ellipsis;
  background: var(--raise); color: var(--muted);
}
.packet .packet-code { background: var(--ogf); color: var(--on-ogf); }
.packet .packet-sub { background: var(--ocf); color: var(--on-ocf); }
.packet .packet-op { background: var(--ink); color: var(--paper); }
.packet .is-given { color: var(--ink); }
.packet .is-unknown { background: transparent; outline: 1.5px dashed var(--line); outline-offset: -1.5px; }
.packet .is-bad { background: var(--warn-tint); color: var(--warn); }
.packet small { padding-top: 0.25rem; font: 0.75rem var(--sans); color: var(--muted); text-align: center; }

.decoder-result { margin-top: 1rem; padding-top: 0.875rem; border-top: 1px solid var(--line); }
.decoder-result p { margin: 0; }
.decoder-result p + p { margin-top: 0.25rem; color: var(--muted); }
.decoder-result .warn { color: var(--warn); }
.decoder-name-line { display: flex; flex-wrap: wrap; align-items: center; gap: 0 0.25rem; }

/* Details: parameters and return parameters with their sizes (and values, from a packet),
   and the events a command generates or the commands that generate an event */

.details { margin-top: 0.75rem; font-size: 0.875rem; }
.details h3 { margin: 1.125rem 0 0.25rem; font-size: 0.875rem; font-weight: 700; }
.params { margin: 0; }
.params div {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 0 1rem;
  align-items: baseline;
  padding: 0.3rem 0;
  border-bottom: 1px solid var(--line);
}
.params div:last-child { border-bottom: 0; }
.params dt code, .links-list code { font-size: 0.8125rem; font-weight: 600; overflow-wrap: anywhere; }
.params dd { margin: 0; max-width: 11rem; color: var(--muted); text-align: right; }
.params dd.value { grid-column: 1 / -1; max-width: none; margin-top: 0.125rem; color: var(--ink); text-align: left; font: 600 0.8125rem var(--mono); overflow-wrap: anywhere; }
.params dd.value::before { content: "= "; color: var(--muted); font-weight: 400; }
.params dd.value.is-failure { color: var(--warn); }
.params dd.value .rest { color: var(--muted); font: 400 0.8125rem var(--sans); }
.details .note { margin: 0.375rem 0 0; color: var(--muted); }
.none { margin: 0; color: var(--muted); }
.links-list { display: grid; gap: 0.25rem; margin: 0; padding: 0; list-style: none; }
.links-list a { text-decoration: none; }
.links-list a:hover code { text-decoration: underline; }
.links-list .tag { margin-left: 0.375rem; }
/* the versions of an event in a list stay quiet: base.css draws a linked tag in ink */
.links-list a.tag { border-color: var(--line); color: var(--muted); }
.links-list a.tag:hover { background: transparent; }

/* The versions of a command or event; the one shown is filled */
.versions { display: flex; flex-wrap: wrap; align-items: center; gap: 0.375rem; margin: 0 0 0.625rem; }
.versions-label { margin-right: 0.125rem; color: var(--muted); }
.versions .tag { margin: 0; padding: 0.125rem 0.5rem; font-size: 0.8125rem; text-decoration: none; }
.versions .tag[aria-current] { background: var(--ink); border-color: var(--ink); color: var(--paper); }

/* Narrow screens: the panel above the table (a lookup without a row) or under a row */
main > .decoder { max-width: 40rem; margin-bottom: 1.5rem; padding-bottom: 1.5rem; border-bottom: 1px solid var(--line); }
.decoder.is-inline .result-row { display: none; }
.decoder.is-inline .decoder-result { padding-top: 0; border-top: 0; }
.decoder.is-inline .decoder-result:not(:has(p:not(.result-row))) { display: none; }
@media (min-width: 48rem) {
  .decoder.is-inline {
    display: grid;
    grid-template-columns: minmax(0, 23rem) minmax(0, 1fr);
    grid-template-rows: auto auto 1fr;
    grid-template-areas: "top top" "head details" "result details";
    gap: 0 2.5rem;
  }
  .decoder.is-inline .decoder-top { grid-area: top; }
  .decoder.is-inline [data-head] { grid-area: head; }
  .decoder.is-inline .decoder-result { grid-area: result; }
  .decoder.is-inline .details { grid-area: details; margin-top: 0; }
}

/* Phones: each row becomes a small block, its cells placed like this */

@media (max-width: 47.99rem) {
  .listing tbody tr[id] { grid-template-areas: "name spec" "op since" "sum sum"; }
  .c-name { grid-area: name; }
  .c-op { grid-area: op; }
  .c-op { white-space: normal; }
  .c-op code { white-space: nowrap; }
  .c-op .fields { display: inline; margin: 0 0 0 0.75rem; }
  .c-op .ocf { margin-left: 0.75rem; }
  .field-name { position: static; width: auto; height: auto; overflow: visible; clip-path: none; margin-right: 0.25rem; font: 700 0.8125rem var(--sans); }
  .c-sum { grid-area: sum; }
  .c-spec { grid-area: spec; text-align: right; }
  .c-spec a { display: inline-block; padding-block: 0.25rem; margin-block: -0.25rem; }
  .c-since { grid-area: since; text-align: right; }
  .c-since::before { content: "since "; color: var(--muted); }
  #events tbody tr[id] { grid-template-columns: auto auto 1fr auto; grid-template-areas: "name name name spec" "code sub . since" "sum sum sum sum"; }
  #errors tbody tr[id] { grid-template-areas: "name spec" "code code" "sum sum"; }
  .c-code { grid-area: code; }
  .c-sub { grid-area: sub; }
  .c-sub:not(:empty)::before { content: "subevent "; font-size: 0.8125rem; font-weight: 700; color: var(--ocf); }
}

@media (pointer: coarse) {
  .release select { padding-block: 0.5rem; }
}

@media (prefers-reduced-motion: reduce) {
  .bit { transition: none; }
}
