@layer components {
  /* History: the versions and the log on the left, the chosen version on the right. */
  .document-history { display: flex; flex-direction: column; gap: 16px; }
  .document-history-head { display: flex; flex-direction: column; gap: 6px; }
  .document-history-title { margin: 0; font-family: var(--font-heading); font-size: 22px; font-weight: 600; }
  .document-history-columns { display: grid; grid-template-columns: minmax(220px, 280px) 1fr; gap: 24px; align-items: start; }
  .document-history-list {
    display: flex; flex-direction: column; gap: 2px; margin: 0; padding: 0; list-style: none; font-size: 13px;
  }
  .document-history-version, .document-history-event {
    display: flex; flex-direction: column; gap: 2px; padding: 8px 10px; border-radius: var(--radius-md);
  }
  .document-history-version.is-shown { background: var(--muted); }
  .document-history-link { display: flex; flex-wrap: wrap; gap: 4px 8px; color: var(--foreground); text-decoration: none; }
  .document-history-link:hover .document-history-number { text-decoration: underline; }
  .document-history-number { font-weight: 600; }
  .document-history-list time { color: var(--muted-foreground); }
  .document-history-summary { margin: 0; color: var(--muted-foreground); }
  .document-history-event { color: var(--muted-foreground); border-left: 2px solid var(--border); border-radius: 0; }
  .document-history-version .badge { align-self: flex-start; }
  /* A person's run of ticked boxes: one line that opens on its versions. */
  .document-history-group summary, .history-sheet-group summary {
    cursor: pointer; padding: 6px 0; color: var(--muted-foreground);
  }
  .history-sheet-group { border-bottom: 1px solid var(--border); }
  .history-sheet-group summary { min-height: var(--tap); padding: 12px 0; box-sizing: border-box; }
  .document-history-group-list { list-style: none; margin: 0; padding: 0 0 0 12px; border-left: 1px solid var(--border); }

  .document-history-version-shown { display: flex; flex-direction: column; gap: 12px; min-width: 0; }
  .document-history-shown-title { margin: 0; font-weight: 600; font-size: 14px; }
  .document-history-restore {
    display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between; gap: 8px;
    padding: 10px 12px; border: 1px solid var(--border); border-radius: var(--radius-md); background: var(--surface);
  }
  .document-history-restore .hint { margin: 0; }

  /* The panel is narrow whatever the window: the list sits above the version. */
  .document-history--panel .document-history-columns { grid-template-columns: 1fr; }

  @media (max-width: 767px) {
    .document-history-columns { grid-template-columns: 1fr; }
  }

  /* The history in its bottom sheet: a list a finger tall, then one version with its restoration at the foot. */
  .history-sheet-list { display: flex; flex-direction: column; margin: 0; padding: 0; list-style: none; }
  .history-sheet-item { border-bottom: 1px solid var(--border); }
  .history-sheet-link {
    display: grid; grid-template-columns: 1fr auto; align-items: center; gap: 2px 12px; min-height: var(--tap);
    padding: 10px 0; color: var(--foreground); text-decoration: none;
  }
  .history-sheet-link:is(:hover, :active) { background: var(--accent); text-decoration: none; }
  .history-sheet-link svg { grid-column: 2; grid-row: 1 / span 2; color: var(--muted-foreground); }
  .history-sheet-main { display: flex; flex-wrap: wrap; align-items: baseline; gap: 4px 8px; min-width: 0; }
  .history-sheet-by, .history-sheet-link time, .history-sheet-summary { color: var(--muted-foreground); font-size: 0.8125rem; }
  .history-sheet-event {
    display: flex; justify-content: space-between; gap: 12px; padding: 10px 0 10px 12px;
    border-left: 2px solid var(--border); color: var(--muted-foreground); font-size: 0.8125rem;
  }
  .history-sheet-shown { display: flex; flex-direction: column; gap: 12px; min-width: 0; }
  .history-sheet-back {
    display: inline-flex; align-items: center; gap: 2px; align-self: flex-start; min-height: var(--tap);
    margin-left: -6px; padding: 0 12px 0 2px; color: var(--jx-accent); font-weight: 500; text-decoration: none;
  }
  .history-sheet-title { display: flex; flex-direction: column; gap: 2px; margin: 0; font-weight: 600; }
  .history-sheet-title .history-sheet-by { font-weight: 400; }
  .history-sheet-foot {
    position: sticky; bottom: 0; display: flex; flex-direction: column; gap: 6px; margin-top: 8px;
    padding: 10px 0 calc(10px + var(--safe-bottom)); border-top: 1px solid var(--border); background: var(--background);
  }
  .history-sheet-foot .hint { margin: 0; }
  .history-sheet-foot form { display: block; margin: 0; }
  .history-sheet-foot .button { width: 100%; min-height: var(--tap); }
}
