/* Media Library tab and Candidates tab.
   Tokens and shared components (.btn, .segmented, .badge, .info-btn, .card, .selbar,
   .check-box, .details-dialog) are in styles.css. */

/* ---------------------------------------------------------------------------
   Media Library layout: the tab fills the window below the tab bar. Toolbar and chips on
   top, then the sidebar (facets) and the works side by side, each with its own scrolling,
   so the images stay in view while filtering. */
#panel-media-library { padding-top: 0.75rem; padding-bottom: 0; }

.ml {
  display: flex; flex-direction: column; gap: 0.6rem;
  height: max(560px, calc(100dvh - var(--app-header-h, 3rem) - 0.75rem));
}

.ml-toolbar {
  display: flex; flex-wrap: wrap; align-items: center; gap: 0.6rem 1.25rem;
  padding: 0.5rem 0.75rem; background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius-lg);
}
.ml-facets-btn[aria-expanded="true"] { color: var(--accent); background: var(--accent-soft); border-color: var(--accent-soft-border); }
.ml-facets-btn .count-pill { color: #fff; background: var(--accent); }
.ml-summary { margin: 0; font-size: 0.9rem; white-space: nowrap; }
.ml-date-wrap { display: flex; align-items: center; gap: 0.6rem; }
.ml-date-label { display: inline-flex; align-items: center; font-weight: 600; font-size: 0.9rem; }
.ml-search { flex: 1 1 220px; }

/* active filters as removable chips */
.ml-active { display: flex; flex-wrap: wrap; align-items: center; gap: 0.4rem; }
.ml-chip {
  display: inline-flex; align-items: center; gap: 0.35rem; height: var(--control-h-sm); padding: 0 0.7rem;
  border: none; border-radius: 999px; background: var(--accent); color: #fff; font: inherit; font-size: 0.8rem; cursor: pointer;
}
.ml-chip:hover { background: var(--accent-hover); }

.ml-body { flex: 1; min-height: 0; display: flex; gap: 0.75rem; }

/* sidebar with facets */
.ml-facets {
  flex: 0 0 260px; overflow-y: auto;
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius-lg);
}
.ml-facet { padding: 0.65rem 0.9rem; border-bottom: 1px solid var(--border-soft); }
.ml-facet:last-child { border-bottom: none; }
.ml-facet summary { cursor: pointer; font-weight: 600; font-size: 0.9rem; }
.ml-facet summary .badge { margin-left: 0.3rem; }
.ml-facet-list { display: flex; flex-direction: column; margin-top: 0.35rem; }
.facet {
  display: flex; align-items: center; gap: 0.5rem; min-height: 1.9rem; padding: 0 0.25rem;
  border-radius: 4px; font-size: 0.88rem; cursor: pointer;
}
.facet:hover { background: var(--hover); }
.facet input { margin: 0; width: 1rem; height: 1rem; cursor: pointer; }
.facet-label { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.facet .n { color: var(--muted); font-size: 0.8rem; font-variant-numeric: tabular-nums; }
.facet:has(input:checked) .facet-label { font-weight: 600; }
.facet.empty { opacity: 0.45; cursor: default; }
.ml-facet-list .link-btn { align-self: flex-start; margin-top: 0.2rem; }

/* date filter in the toolbar: histogram and slider, then START/END fields in one row */
.ml-date { width: 250px; }
.df-hist { display: block; width: 100%; height: 24px; }
.df-hist .exact { fill: var(--bar); }
.df-hist .span { fill: var(--span); opacity: 0.55; }
.df-hist .out rect { opacity: 0.2; }
.df-slider { position: relative; height: 18px; margin: 2px 0 4px; }
.df-track { position: absolute; left: 7px; right: 7px; top: 8px; height: 2px; background: var(--border); }
.df-fill { position: absolute; top: 0; bottom: 0; background: var(--fg); }
.df-slider input[type=range] {
  position: absolute; left: 0; top: 0; width: 100%; height: 18px; margin: 0;
  background: none; pointer-events: none; -webkit-appearance: none; appearance: none;
}
.df-slider input[type=range]::-webkit-slider-runnable-track { background: none; height: 18px; }
.df-slider input[type=range]::-moz-range-track { background: none; }
.df-slider input[type=range]::-webkit-slider-thumb {
  -webkit-appearance: none; appearance: none; pointer-events: auto; cursor: pointer;
  width: 14px; height: 14px; margin-top: 2px; border-radius: 50%;
  background: #fff; border: 1.5px solid var(--fg); box-shadow: 0 1px 2px rgba(0,0,0,0.2);
}
.df-slider input[type=range]::-moz-range-thumb {
  pointer-events: auto; cursor: pointer; width: 12px; height: 12px; border-radius: 50%;
  background: #fff; border: 1.5px solid var(--fg);
}
.df-slider input[type=range]:focus-visible { outline: none; }
.df-slider input[type=range]:focus-visible::-webkit-slider-thumb { outline: 2px solid var(--accent); outline-offset: 2px; }
.df-slider input[type=range]:focus-visible::-moz-range-thumb { outline: 2px solid var(--accent); outline-offset: 2px; }
.df-fields { display: flex; align-items: flex-end; justify-content: space-between; gap: 0.5rem; }
.df-fields label:not(.df-exact) { display: flex; flex-direction: column; gap: 0.15rem; }
.df-fields label:last-child { align-items: flex-end; }
.df-fields span { font-size: 0.68rem; letter-spacing: 0.06em; text-transform: uppercase; color: var(--muted); }
.df-fields input[type=number] {
  width: 4.6rem; height: auto; padding: 0.15rem 0.3rem; font-size: var(--text-sm); text-align: center;
  border-radius: var(--radius-sm);
}
.df-exact { display: inline-flex; gap: 0.3rem; align-items: center; font-size: 0.78rem; color: var(--muted); padding-bottom: 0.2rem; }
/* in the toolbar: no START/END captions, smaller fields */
.ml-date .df { display: grid; grid-template-columns: 250px; }
.ml-toolbar .df-fields { align-items: center; }
.ml-toolbar .df-fields span { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); }
.ml-toolbar .df-fields input[type=number] { width: 4rem; }
.ml-toolbar .df-exact { padding-bottom: 0; white-space: nowrap; }

/* works: mosaic or list, scrolling on their own */
.ml-works {
  flex: 1; min-width: 0; display: flex; flex-direction: column; overflow: hidden;
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius-lg);
}
.ml-works > [data-pane] { flex: 1; min-height: 0; display: flex; flex-direction: column; }
.ml-view-toggle > button { padding: 0 0.6rem; color: var(--muted); }

.ml-mosaic-note { margin: 0; padding: 0.4rem 0.75rem; font-size: 0.8rem; color: var(--muted); background: #faf9f6; border-bottom: 1px solid var(--border); }
/* similarity map (cluster-map.js): Plotly fills the pane, custom hover card with thumbnail */
.ml-map-bar {
  display: flex; flex-wrap: wrap; align-items: center; gap: 0.25rem 1rem; padding: 0.4rem 0.75rem;
  font-size: 0.8rem; color: var(--muted); background: #faf9f6; border-bottom: 1px solid var(--border);
}
.ml-map-bar p { margin: 0; }
.ml-map-note { flex: 1; display: flex; align-items: center; gap: 0.25rem; }
.ml-map-labels { display: inline-flex; align-items: center; gap: 0.3rem; white-space: nowrap; color: var(--fg); }
.ml-map-wrap { position: relative; flex: 1; min-height: 0; }
.ml-map-plot { position: absolute; inset: 0; }
.ml-map-status { position: absolute; inset: 0; display: grid; place-items: center; margin: 0; color: var(--muted); }
.ml-map-tip {
  position: absolute; z-index: 5; width: 200px; padding: 6px; pointer-events: none;
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); box-shadow: var(--shadow-pop);
  font-size: var(--text-xs);
}
.ml-map-tip-img { position: relative; overflow: hidden; border-radius: var(--radius-sm); background: #e9e6df; margin-bottom: 4px; }
.ml-map-tip-img img { display: block; width: 100%; height: auto; }
.ml-map-tip-img.cropped img { position: absolute; max-width: none; }
.ml-map-tip-title { font-weight: 600; color: var(--fg); overflow: hidden; display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; }
.ml-map-tip-meta { display: flex; align-items: center; gap: 0.35rem; color: var(--muted); margin-top: 2px; }
.ml-map-tip-meta .swatch { flex: none; width: 8px; height: 8px; border-radius: 50%; }

.ml-mosaic-scroll { position: relative; flex: 1; min-height: 0; overflow-y: auto; overflow-x: hidden; padding: 6px; }
.ml-mosaic-spacer { position: relative; }

/* Tiles: click selects (outline + check box), double-click opens the details dialog. */
.ml-tile {
  position: absolute; overflow: hidden; border-radius: var(--radius-sm); cursor: pointer; background: #e9e6df;
  -webkit-user-select: none; user-select: none;
}
.ml-tile img { width: 100%; height: 100%; object-fit: cover; display: block; transition: transform 0.2s; }
/* cropped to the print area: position and width set inline by mosaic.js */
.ml-tile img.cropped { position: absolute; height: auto; max-width: none; object-fit: fill; }
.ml-tile:hover img { transform: scale(1.03); }
.ml-tile.selected { outline: 3px solid var(--accent); outline-offset: -3px; }
.ml-tile:focus-visible { outline: 3px solid var(--accent); outline-offset: 1px; }
.ml-tile .check-box {
  position: absolute; top: 6px; left: 6px; box-shadow: 0 0 0 2px rgba(255, 255, 255, 0.85);
  opacity: 0; transition: opacity 0.15s;
}
.ml-tile:hover .check-box, .ml-tile:focus-visible .check-box, .ml-tile.selected .check-box { opacity: 1; }
.ml-tile-caption {
  position: absolute; left: 0; right: 0; bottom: 0; padding: 1.2rem 0.5rem 0.35rem;
  font-size: var(--text-xs); color: #fff; background: linear-gradient(transparent, rgba(0,0,0,0.65));
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis; opacity: 0; transition: opacity 0.15s;
}
.ml-tile:hover .ml-tile-caption, .ml-tile:focus-visible .ml-tile-caption { opacity: 1; }
@media (hover: none) { .ml-tile .check-box { opacity: 1; } }

.ml-list-head, .ml-row {
  display: grid; align-items: center; gap: 0.75rem;
  grid-template-columns: 2rem 56px minmax(0, 1fr) 7.5rem minmax(0, 13rem) 9rem 8.5rem;
  padding: 0 0.75rem;
}
.ml-list-head { height: 2.4rem; border-bottom: 1px solid var(--border); font-size: 0.8rem; color: var(--muted); }
.ml-list-head .sort {
  border: none; background: none; font: inherit; color: inherit; text-align: left; padding: 0; cursor: pointer;
}
.ml-list-head .sort[aria-sort="ascending"], .ml-list-head .sort[aria-sort="descending"] { color: var(--fg); font-weight: 600; }
.ml-list-scroll { position: relative; flex: 1; min-height: 0; overflow-y: auto; }
.ml-list-spacer { position: relative; }
.ml-row {
  position: absolute; left: 0; right: 0; height: 64px;
  border-bottom: 1px solid var(--border-soft); font-size: 0.88rem; cursor: pointer;
  -webkit-user-select: none; user-select: none;
}
.ml-row:hover { background: var(--hover); }
.ml-row.selected { background: var(--selected); }
.ml-row:focus-visible { outline-offset: -2px; }
.ml-row .col-title, .ml-row .col-place { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.ml-row .col-check { display: flex; justify-content: center; }
.ml-row .col-img img { width: 56px; height: 52px; object-fit: cover; border-radius: var(--radius-sm); display: block; background: #eee; }
.ml-row .no-img { width: 56px; height: 52px; }
.ml-row .col-date, .ml-row .col-genre { color: var(--muted); }
.ml-empty { padding: 1.5rem; color: var(--muted); margin: 0; }

@media (max-width: 760px) {
  /* narrow screens: sidebar above the works, the page scrolls */
  .ml { height: auto; }
  .ml-body { flex-direction: column; }
  .ml-facets { flex: none; max-height: 45vh; }
  .ml-works { height: 75vh; }
  .ml-list-head, .ml-row { grid-template-columns: 1.6rem 48px minmax(0, 1fr) 5.5rem; gap: 0.5rem; padding: 0 0.5rem; }
  .ml-list-head .col-place, .ml-list-head .col-genre, .ml-list-head .col-source,
  .ml-row .col-place, .ml-row .col-genre, .ml-row .col-source { display: none; }
  .ml-row .col-img img, .ml-row .no-img { width: 48px; height: 48px; }
}

/* ---------------------------------------------------------------------------
   Candidates tab: toolbar, suggested pairs, selected works (cards: styles.css) */
#panel-pair-matching { padding-bottom: 0; }
/* keeps the selection bar at the bottom of the window */
#panel-pair-matching .cand-main { min-height: calc(100vh - var(--app-header-h, 3rem) - 4.5rem); padding-bottom: 1rem; }
.cand-toolbar { display: flex; flex-wrap: wrap; gap: 0.5rem 0.75rem; align-items: center; margin: 0 0 0.5rem; }
.cand-status { font-size: var(--text-sm); }
.cand-section { margin-top: 1rem; }
.cand-section h3 { display: flex; align-items: center; gap: 0.4rem; margin: 0 0 0.3rem; font-size: 1rem; }
.cand-section > p { margin: 0.3rem 0; font-size: var(--text-sm); }

/* Selected works: the whole card is the checkbox ("pick for comparison"). */
.pm-card { cursor: pointer; -webkit-user-select: none; user-select: none; }
.pm-card:hover { border-color: var(--accent-soft-border); }
.pm-card.picked { outline: 3px solid var(--accent); outline-offset: -3px; }
.pm-card:focus-visible { outline: 3px solid var(--accent); outline-offset: 1px; }
.pm-card .check-box { position: absolute; top: 6px; left: 6px; box-shadow: 0 0 0 2px rgba(255, 255, 255, 0.85); }
.card-remove { position: absolute; top: 6px; right: 6px; opacity: 0; transition: opacity 0.15s; }
.pm-card:hover .card-remove, .pm-card:focus-within .card-remove { opacity: 1; }
@media (hover: none) { .card-remove { opacity: 1; } }

/* Suggested pairs: both images side by side; double-click one for its details. */
.cand-pairs { grid-template-columns: repeat(auto-fill, minmax(280px, 1fr)); }
.cand-pair-imgs { display: grid; grid-template-columns: 1fr 1fr; gap: 2px; background: var(--border); }
.cand-pair-imgs img { display: block; width: 100%; height: 130px; object-fit: cover; cursor: zoom-in; }

@media (prefers-reduced-motion: reduce) {
  .ml-tile img, .ml-tile .check-box, .ml-tile-caption, .card-remove { transition: none; }
  .ml-tile:hover img { transform: none; }
}
