/*
  The offline panel, as a core element.

  Every selector is scoped to the `offline-panel` tag rather than to a wrapper attribute, so an app
  can drop the tag on any page without inheriting that page's scoping scheme — and so a bare
  `[state]`, `[note]` or `[label]` cannot reach out and restyle whatever surrounds it. The Atomics
  install page is built from market blocks that carry literal `copy` and `headline` attributes, and
  an unscoped rule here would have restyled half of it.

  Colours are `color-mix` against `--text` and `--background`, which every Firebrand layout defines
  and flips with the theme. The panel has no palette of its own to clash with a host it has never
  seen.

  The host is laid out by whoever placed it; this only owns the inside.
*/

offline-panel {
  display: flex;
  flex-direction: column;
  gap: 1.15rem;
  width: 100%;
  box-sizing: border-box;
  color: var(--text);
}

offline-panel[hidden] {
  display: none;
}

/* The one sentence that is always true right now, and the only part somebody has to read. */
offline-panel > [state] {
  max-width: 52rem;
  margin: 0;
  color: var(--text);
  font-size: 1.02rem;
  line-height: 1.55;
  text-wrap: pretty;
}

offline-panel[airplane='true'] > [state] {
  font-weight: 600;
}

offline-panel [meter] {
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
  max-width: 52rem;
}

offline-panel [meter][hidden] {
  display: none;
}

offline-panel [track] {
  position: relative;
  height: 6px;
  border-radius: 100vmax;
  background: color-mix(in srgb, var(--background), var(--text) 14%);
  overflow: hidden;
}

offline-panel [track] [fill] {
  display: block;
  width: 0%;
  height: 100%;
  border-radius: inherit;
  background: var(--text);
  transition: width 120ms linear;
}

/*
  The running commentary under the bar. It changes on every file, so it is held to one line —
  a paragraph that reflows the page a few hundred times is its own kind of broken.
*/
offline-panel [progress] {
  margin: 0;
  min-height: 1.2em;
  color: color-mix(in srgb, var(--background), var(--text) 55%);
  font-size: 0.85rem;
  font-variant-numeric: tabular-nums;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

offline-panel [controls] {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 0.75rem;
}

offline-panel button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: 44px;
  padding: 0 1.25rem;
  border: 1px solid color-mix(in srgb, var(--background), var(--text) 22%);
  border-radius: 100vmax;
  background: transparent;
  color: var(--text);
  font: inherit;
  font-weight: 600;
  cursor: pointer;
  transition: opacity 160ms ease, transform 160ms ease, background 160ms ease;
}

/* The primary action, so it reads like the one to press. */
offline-panel button[download] {
  border-color: transparent;
  background: var(--text);
  color: var(--background);
}

offline-panel button:hover {
  opacity: 0.85;
}

offline-panel button:active {
  transform: translateY(1px);
}

offline-panel button:disabled {
  opacity: 0.45;
  cursor: not-allowed;
  transform: none;
}

offline-panel button[hidden] {
  display: none;
}

offline-panel [airplane] {
  display: inline-flex;
  align-items: center;
  gap: 0.55rem;
  min-height: 44px;
  padding: 0 1rem 0 0.9rem;
  border: 1px solid color-mix(in srgb, var(--background), var(--text) 22%);
  border-radius: 100vmax;
  font-weight: 600;
  cursor: pointer;
  user-select: none;
}

/*
  The checkbox itself is taken out of the flow rather than hidden, so it keeps its place in the tab
  order and keeps announcing its state — `display: none` would take the control away from anybody
  not using a mouse, which on a switch that holds the whole network is not a small loss.
*/
offline-panel [airplane] input {
  position: absolute;
  width: 1px;
  height: 1px;
  margin: -1px;
  padding: 0;
  border: 0;
  clip: rect(0 0 0 0);
  clip-path: inset(50%);
  overflow: hidden;
  white-space: nowrap;
}

offline-panel [airplane] [switch] {
  position: relative;
  display: inline-block;
  width: 34px;
  height: 20px;
  border-radius: 100vmax;
  background: color-mix(in srgb, var(--background), var(--text) 22%);
  transition: background 160ms ease;
}

offline-panel [airplane] [switch]::after {
  content: '';
  position: absolute;
  top: 3px;
  left: 3px;
  width: 14px;
  height: 14px;
  border-radius: 50%;
  background: var(--background);
  transition: transform 160ms ease;
}

offline-panel [airplane] input:checked + [switch] {
  background: var(--text);
}

offline-panel [airplane] input:checked + [switch]::after {
  transform: translateX(14px);
}

/* Visible focus, since the control it belongs to is off-screen. */
offline-panel [airplane] input:focus-visible + [switch] {
  outline: 2px solid var(--text);
  outline-offset: 3px;
}

offline-panel [airplane] input:disabled ~ * {
  opacity: 0.45;
}

offline-panel > [note] {
  max-width: 52rem;
  margin: 0;
  color: color-mix(in srgb, var(--background), var(--text) 58%);
  font-size: 0.9rem;
  line-height: 1.55;
  text-wrap: pretty;
}

/* The table: collapsed by default, because it is a few hundred rows and nobody wants it open. */
offline-panel [assets] {
  display: flex;
  flex-direction: column;
  border-top: 1px solid color-mix(in srgb, var(--background), var(--text) 12%);
}

offline-panel [assets] [empty] {
  margin: 1rem 0 0;
  color: color-mix(in srgb, var(--background), var(--text) 58%);
  font-size: 0.9rem;
}

offline-panel [group] {
  border-bottom: 1px solid color-mix(in srgb, var(--background), var(--text) 12%);
}

offline-panel [group] summary {
  display: grid;
  /* Name, then the meter taking the slack, then the count. The meter is what makes a wall of
     twenty-eight rows answerable without opening it. */
  grid-template-columns: auto minmax(2rem, 1fr) auto;
  align-items: center;
  gap: 1rem;
  padding: 0.85rem 0;
  font-weight: 600;
  cursor: pointer;
  list-style: none;
}

offline-panel [group] summary::-webkit-details-marker {
  display: none;
}

/* The disclosure caret, drawn rather than relying on the default marker this hides. */
offline-panel [group] summary [name]::before {
  content: '';
  display: inline-block;
  width: 0.4em;
  height: 0.4em;
  margin-right: 0.7em;
  border-right: 1.5px solid currentColor;
  border-bottom: 1.5px solid currentColor;
  transform: translateY(-0.15em) rotate(-45deg);
  transition: transform 160ms ease;
}

offline-panel [group][open] summary [name]::before {
  transform: translateY(-0.05em) rotate(45deg);
}

offline-panel [group] summary:focus-visible {
  outline: 2px solid var(--text);
  outline-offset: 2px;
  border-radius: 6px;
}

offline-panel [group] [bar] {
  height: 4px;
  border-radius: 100vmax;
  background: color-mix(in srgb, var(--background), var(--text) 14%);
  overflow: hidden;
}

offline-panel [group] [bar] span {
  display: block;
  height: 100%;
  border-radius: inherit;
  background: color-mix(in srgb, var(--background), var(--text) 45%);
}

/* Complete reads as complete at a glance, rather than as one more grey bar. */
offline-panel [group] [bar][tone='done'] span {
  background: var(--text);
}

offline-panel [group] [tally] {
  font-variant-numeric: tabular-nums;
  font-weight: 500;
  font-size: 0.9rem;
  white-space: nowrap;
}

offline-panel [group] [tally][tone='partial'] {
  color: color-mix(in srgb, var(--background), var(--text) 55%);
}

@media (max-width: 560px) {
  /* The meter is the first thing to go; the name and the count still say everything it did. */
  offline-panel [group] summary {
    grid-template-columns: 1fr auto;
  }

  offline-panel [group] [bar] {
    display: none;
  }
}

offline-panel [group] > [note] {
  margin: 0 0 0.75rem;
  max-width: 52rem;
  color: color-mix(in srgb, var(--background), var(--text) 55%);
  font-size: 0.85rem;
  line-height: 1.5;
}

/*
  A scroller, not a squeeze.

  `flex-direction: column` with a `max-height` is a trap, and it cost this panel its whole point:
  flex items shrink by default, so twenty-eight rows in a 17rem box did not overflow and scroll —
  they were compressed to five pixels each, into slivers of clipped glyphs. It looked for all the
  world like a colour problem, and the computed colours were right the whole time. Libraries was the
  one group anybody could read because five rows never reach the cap.

  `flex: none` on the rows is the fix; `min-height: 0` keeps the scroller able to be shorter than
  its content in the column layouts above it.
*/
offline-panel [entries] {
  margin: 0 0 0.85rem;
  padding: 0;
  list-style: none;
  display: flex;
  flex-direction: column;
  min-height: 0;
  /* Long enough to browse, short enough not to bury the controls above it. */
  max-height: 17rem;
  overflow-y: auto;
  overscroll-behavior: contain;
}

offline-panel [entries] li {
  flex: none;
  display: flex;
  align-items: baseline;
  gap: 0.6rem;
  padding: 0.22rem 0.5rem;
  border-radius: 6px;
  font-size: 0.85rem;
  line-height: 1.5;
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  color: color-mix(in srgb, var(--background), var(--text) 62%);
  /* A CDN URL is long, and wrapping it into three lines each is unreadable. */
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

offline-panel [entries] li:hover {
  background: color-mix(in srgb, var(--background), var(--text) 7%);
}

offline-panel [entries] li[cached='true'] {
  color: var(--text);
}

offline-panel [entries] [label] {
  overflow: hidden;
  text-overflow: ellipsis;
}

offline-panel [entries] [mark] {
  flex: none;
  font-size: 0.7em;
  /* Nudged onto the text's optical centre; a baseline-aligned dot sits too low. */
  transform: translateY(-0.15em);
}

/*
  The state, for anybody who is not looking at the dot. The dot is `aria-hidden`, so without this
  the whole column reads as a list of paths with no answer attached.
*/
offline-panel [sr] {
  position: absolute;
  width: 1px;
  height: 1px;
  margin: -1px;
  clip: rect(0 0 0 0);
  clip-path: inset(50%);
  overflow: hidden;
  white-space: nowrap;
}
