/* Artifacts: the list of cards, an open document or artifact with its
   history, the overlay a chat's link opens it in, and the panel's
   Archived row. */
@layer views {
  /* The view is its own scroller, like Goals: it clears the floating
     controls and keeps its content to the reading column. */
  #view-artifacts {
    --page-top: calc(var(--controls-h) + 8px);
    --page-x: 34px;
    --column: 1180px;
    --preview-h: 176px;
    min-height: 0;
    padding: var(--page-top) var(--page-x) 96px;
    overflow: auto;
    scroll-padding-top: var(--controls-h);
  }
  #view-artifacts > * {
    width: 100%;
    max-width: var(--column);
    margin-right: auto;
    margin-left: auto;
  }
  #view-artifacts > .view-head,
  #view-artifacts > .filter-panel {
    width: auto;
    max-width: none;
    margin-right: calc(-1 * var(--page-x));
    margin-left: calc(-1 * var(--page-x));
  }

  #view-artifacts:has(> .artifact-open:not([hidden])) { --column: 720px; }
  .artifacts-list {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(250px, 1fr));
    gap: 14px;
  }
  .artifact-card {
    display: flex;
    flex-direction: column;
    min-width: 0;
    padding: 8px;
    border: 1px solid var(--line);
    border-radius: 10px;
    background: var(--paper);
    cursor: pointer;
  }
  .artifact-card:has(.artifact-menu) { position: relative; z-index: 1; }
  .artifact-card:hover .row-more,
  .artifact-card:focus-within .row-more { opacity: 1; }
  .artifact-card > .delete-confirm,
  .artifact-card > .artifact-notice { margin: 8px 8px 4px; }

  /* The preview: an inset sheet, the item at a fixed width scaled to the
     card, fading out at its foot. */
  .artifact-preview-slot { flex: none; }
  .artifact-thumb-doc.markdown .md-table { overflow: hidden; }
  .artifact-preview {
    position: relative;
    height: var(--preview-h);
    overflow: hidden;
    border-radius: calc(var(--radius-card) - 6px);
    background: color-mix(in srgb, var(--ink) 4%, transparent);
    pointer-events: none;
    -webkit-mask-image: linear-gradient(to bottom, #000 62%, transparent 100%);
    mask-image: linear-gradient(to bottom, #000 62%, transparent 100%);
  }
  /* A page picture ends at the preview's edge; a fade would blend it into the card. */
  .artifact-card[data-kind="page"] .artifact-preview { -webkit-mask-image: none; mask-image: none; }
  .artifact-preview-inner {
    position: absolute;
    top: 0;
    left: 0;
    transform-origin: 0 0;
  }
  .artifact-page-sheet { position: relative; width: 100%; height: 100%; }
  .artifact-page-picture { position: absolute; inset: 0; width: 100%; height: 100%; object-fit: cover; object-position: left top; }
  .artifact-page-still { display: grid; place-items: center; width: 100%; height: 100%; color: var(--ink-soft); }
  .artifact-page-still .nav-page-glyph { width: 56px; height: 56px; font-size: 24px; }

  .artifact-thumb-doc {
    padding: 30px 34px;
    color: var(--ink);
    font-size: 17px;
    line-height: 1.55;
  }
  .artifact-thumb-doc > :first-child { margin-top: 0; }
  .artifact-thumb-title {
    margin: 0 0 12px;
    font-family: var(--serif);
    font-size: 30px;
    font-weight: 600;
    line-height: 1.2;
    letter-spacing: -0.01em;
  }
  .artifact-thumb-doc .md-heading { margin: 18px 0 6px; font-size: 19px; }
  .artifact-thumb-doc p { margin: 0 0 10px; }
  .artifact-thumb-doc ul,
  .artifact-thumb-doc ol { margin: 0 0 10px; padding-left: 24px; }

  .artifact-card-foot {
    display: grid;
    grid-template-columns: auto minmax(0, 1fr) auto;
    gap: 10px;
    align-items: center;
    padding: 10px 2px 4px 8px;
  }
  .artifact-kind-icon { display: grid; place-items: center; width: 32px; height: 32px; border-radius: 10px; background: color-mix(in srgb, var(--ink) 6%, transparent); color: var(--ink-soft); }
  .artifact-card .row-menu-wrap { margin: 0; }

  .artifact-card-main { display: grid; gap: 1px; min-width: 0; }
  .artifact-card-title {
    margin: 0;
    overflow: hidden;
    font-size: 15px;
    font-weight: 600;
    line-height: 1.35;
    display: -webkit-box;
    -webkit-box-orient: vertical;
    -webkit-line-clamp: 2;
    overflow-wrap: anywhere;
  }
  .artifact-card-link { color: inherit; text-decoration: none; }
  .artifact-card-link:hover { text-decoration: underline; }
  .artifact-card-link:focus-visible { outline: 2px solid var(--green); outline-offset: 2px; border-radius: 4px; }
  .artifact-card-sub {
    margin: 0;
    overflow: hidden;
    color: var(--muted);
    font-size: 13px;
    text-overflow: ellipsis;
    white-space: nowrap;
  }
  .artifact-card-sub > span + span::before { content: "\00b7"; margin: 0 6px; }
  .artifact-card-sub > .artifact-age-short { display: none; }

  .artifact-meta {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: 4px 8px;
    margin: 0;
    color: var(--muted);
    font-size: 13px;
  }
  .artifact-meta > span:not(.avatar) + span:not(.avatar)::before {
    content: "\00b7";
    margin-right: 8px;
  }
  .artifact-agent { color: var(--ink-soft); }

  .artifact-rename { font-size: 18px; }
  .artifact-notice { margin: 0; color: var(--muted); font-size: 13px; }
  .artifact-notice.delete-refusal { color: var(--red); }

  /* An open item: its head (.open-head in components.css: Back, the
     title, and its ⋯), the meta line, the text, then its history. */
  /* One column that may shrink below its content, so a wide code block
     scrolls inside itself, not the page. */
  .artifact-open {
    display: grid;
    grid-template-columns: minmax(0, 1fr);
    gap: 14px;
  }
  .artifact-open-head .artifact-rename { flex: 1; }

  .artifact-content {
    font-size: 16px;
    line-height: 1.6;
    overflow-wrap: anywhere;
  }

  .artifact-entries { margin-top: 18px; padding-top: 18px; border-top: 1px solid var(--line); }
  .artifact-entries-heading { margin: 0 0 12px; }
  .artifact-entry-list {
    display: grid;
    gap: 18px;
    margin: 0;
    padding: 0;
    list-style: none;
  }
  .artifact-entry { display: grid; grid-template-columns: minmax(0, 1fr); gap: 4px; min-width: 0; }
  .artifact-entry-time { color: var(--muted); font-size: 13px; }
  .artifact-entry-text { line-height: 1.55; overflow-wrap: anywhere; }
  .artifact-entry-files {
    display: flex;
    flex-wrap: wrap;
    gap: 4px 12px;
    margin: 0;
    font-size: 14px;
  }
  .artifact-entry-files a { color: var(--green); }
  .artifact-more { margin-top: 16px; }

  /* An item a chat's link opens over the view (artifact-overlay.js): the
     brief's overlay and sheet (brief.css) with the bar's actions at its
     right, above the brief's overlay and quick chat's pane. */
  .brief-overlay.artifact-overlay { z-index: 26; }
  .artifact-overlay .brief-bar { justify-content: flex-end; }
  .artifact-overlay-doc { padding-top: 24px; }

  [data-panel-for="artifacts"] .panel-row .avatar { flex: none; }
  .artifacts-archived-row { margin-top: 20px; }
  .filter-panel .artifacts-archived-row { grid-column: 1 / -1; margin-top: 0; }

  @media (max-width: 719.98px) {
    #view-artifacts { --page-x: 16px; --preview-h: 150px; }
    .artifacts-list { grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 10px; }
    .artifact-card { padding: 6px; }
    .artifact-card-foot { grid-template-columns: minmax(0, 1fr) auto; gap: 4px; padding: 8px 0 2px 6px; }
    /* Anchor each menu to its footer; the first column opens rightward. */
    .artifact-card-foot { position: relative; }
    .artifact-card .row-menu-wrap { position: static; }
    .artifact-card .artifact-menu { top: 100%; }
    .artifact-card:nth-child(odd) .artifact-menu { right: auto; left: 0; }
    .artifact-kind-icon { display: none; }
    .artifact-card-title { font-size: 14px; }
    .artifact-card-sub { font-size: 12px; }
    .artifact-card-sub > .artifact-age-long { display: none; }
    .artifact-card-sub > .artifact-age-short { display: inline; }
  }
}
