/* panels/library-grid.css. My pictures grid (panels/library-grid.js), shared by
   the "Choose a picture" dialog and the Pictures page on /home.
   Tokens only; spacing 4/6/8/12/16; type 12/13/14. */

.cm-lib {
  display: flex;
  flex-direction: column;
  gap: 12px;
  min-height: 0;
}

.cm-lib-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(176px, 1fr));
  grid-auto-rows: max-content;
  align-content: start;
  gap: 12px;
}

.cm-lib-tile {
  position: relative;
  display: flex;
  flex-direction: column;
  gap: 4px;
  box-sizing: border-box;
  min-width: 0;
  padding: 8px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--bg-secondary);
  color: var(--text);
  cursor: pointer;
}
@media (hover: hover) {
  .cm-lib-tile:hover { border-color: var(--border-input); }
}
.cm-lib-tile:focus-visible { outline: 2px solid var(--focus-ring); outline-offset: 2px; }
.cm-lib-tile.is-selected,
.cm-lib-tile[aria-selected="true"] { border-color: var(--accent); outline: 2px solid var(--accent); outline-offset: 0; }
.cm-lib-tile.is-selected:focus-visible { outline-color: var(--focus-ring); }

/* The picture, letterboxed in a 4:3 box. */
.cm-lib-thumb {
  position: relative;
  display: flex;
  align-items: center;
  justify-content: center;
  width: 100%;
  aspect-ratio: 4 / 3;
  border-radius: var(--radius-xs);
  background: var(--bg-primary);
  overflow: hidden;
}
.cm-lib-thumb > img {
  display: block;
  width: 100%;
  height: 100%;
  object-fit: contain;
}
.cm-lib-thumb > img:not([src]) { visibility: hidden; }

.cm-lib-name {
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  font-size: 14px;
  font-weight: 600;
}

.cm-lib-meta {
  display: flex;
  align-items: center;
  gap: 6px;
  min-width: 0;
  min-height: 20px;
  color: var(--text-muted);
  font-size: 12px;
}
.cm-lib-size {
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.cm-lib-fits {
  flex: none;
  padding: 0 6px;
  border-radius: var(--radius-pill);
  background: var(--accent-bg);
  color: var(--accent-ink);
  font-size: 12px;
  font-weight: 700;
  line-height: 20px;
}

.cm-lib-used {
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  color: var(--text-muted);
  font-size: 12px;
}
.cm-lib-used:empty { display: none; }

/* Manage mode corners: the check (top left) and the menu (top right). */
.cm-lib-check {
  position: absolute;
  top: 4px;
  left: 4px;
  display: grid;
  place-items: center;
  width: 28px;
  height: 28px;
  border-radius: var(--radius-xs);
  background: var(--bg-primary);
  cursor: pointer;
}
.cm-lib-check > input { width: 16px; height: 16px; margin: 0; cursor: pointer; }
.cm-lib-check:focus-within { outline: 2px solid var(--focus-ring); }

.cm-lib-more {
  position: absolute;
  top: 4px;
  right: 4px;
  display: grid;
  place-items: center;
  width: 28px;
  height: 28px;
  padding: 0;
  border: 1px solid var(--border);
  border-radius: var(--radius-xs);
  background: var(--bg-primary);
  color: var(--text);
  font: inherit;
  font-size: 14px;
  font-weight: 700;
  line-height: 1;
  cursor: pointer;
}
@media (hover: hover) {
  .cm-lib-more:hover { background: var(--bg-hover-strong); }
}
.cm-lib-more:focus-visible { outline: 2px solid var(--focus-ring); }

/* The upload tile at the end of the dialog's grid. */
.cm-lib-other-box {
  box-sizing: border-box;
  border: 1px dashed var(--border-input);
  background: transparent;
  color: var(--text-muted);
  font-size: 16px;
  font-weight: 400;
}
.cm-lib-other .cm-lib-name {
  white-space: normal;
  font-weight: 600;
}

.cm-lib-empty {
  margin: 0;
  color: var(--text-muted);
  font-size: 13px;
}
.cm-lib-empty[hidden] { display: none; }

/* The failure line keeps the tiles above it and says what is still true. */
.cm-lib-failed {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 8px;
  color: var(--text-secondary);
  font-size: 13px;
}
.cm-lib-failed[hidden] { display: none; }

.cm-lib-foot {
  display: flex;
  justify-content: center;
}
.cm-lib-foot:not(:has(:not([hidden]))) { display: none; }
.cm-lib-loadmore[hidden] { display: none; }

@media (max-width: 739px) {
  .cm-lib-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 8px; }
}

@media (pointer: coarse) {
  .cm-lib-tile { min-height: 44px; }
  .cm-lib-check, .cm-lib-more { width: 44px; height: 44px; }
  .cm-lib-check > input { width: 24px; height: 24px; }
  .cm-lib :is(.cm-lib-loadmore, .cm-lib-retry) { min-height: 44px; }
}
