/* =============================================================================
 * dashboard.css -- the catalog page (index.html)
 *
 *   1. Hero            4. Table + pager       7. Detail sheet
 *   2. Stat cards      5. Charts              8. Responsive
 *   3. Filters         6. QA log              9. Text-size dialog
 * ========================================================================== */


/* 1. Hero ------------------------------------------------------------------- */

.hero { margin-top: 1.25rem; }
.hero-inner {
  display: grid;
  gap: 1.1rem;
  max-width: 58rem;
  padding-block: clamp(2.2rem, 5vw, 4rem) clamp(6rem, 11vw, 8.5rem);
}
/* Already huge, so it keeps its size when the visitor enlarges the text. */
.hero h1 { font-size: clamp(calc(2.5 * var(--rem0)), calc(1.1 * var(--rem0) + 5vw), calc(5 * var(--rem0))); line-height: 1; letter-spacing: -0.025em; }
.hero .lede { font-size: clamp(1.05rem, 0.95rem + 0.5vw, 1.3rem); }
.hero-cta { display: flex; flex-wrap: wrap; gap: 0.8rem; margin-top: 0.6rem; }
.hero-facts { display: flex; flex-wrap: wrap; gap: 0.5rem 1.4rem; margin-top: 0.4rem; font-size: 0.9rem; color: rgba(255, 255, 255, 0.94); }
.hero-facts span { display: inline-flex; align-items: center; gap: 0.45rem; }


/* 2. Stat cards -------------------------------------------------------------- */

.stats-grid {
  position: relative;
  z-index: 3;
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(min(13rem, 100%), 1fr));
  gap: 1rem;
  margin: -3.4rem clamp(0.6rem, 2.4vw, 1.8rem) 0;
}
.stat-card {
  padding: 1.1rem 1.3rem 1.2rem;
  background: var(--surface-glass);
  -webkit-backdrop-filter: blur(16px) saturate(170%);
  backdrop-filter: blur(16px) saturate(170%);
  border: 1px solid var(--border);
  border-radius: var(--r-lg);
  box-shadow: var(--shadow-md);
  transition: transform 0.35s var(--ease-out), box-shadow 0.35s, filter 0.35s;
}
/* Unique sites, Date range and PP / Raw split open their dropdown under "Find a
   sample" (dashboard.js), so they lift and glow. The other cards only inform:
   they do the opposite, sinking and dimming. */
.stat-link { cursor: pointer; }
.stat-link:hover, .stat-link:focus-visible { transform: translateY(-4px); box-shadow: var(--shadow-lg); }
.stat-link:active { transform: translateY(-1px) scale(0.985); }
.stat-static:hover {
  transform: translateY(4px);
  box-shadow: inset 0 2px 10px -4px rgba(0, 0, 0, 0.22), var(--shadow-sm);
  filter: saturate(0.75) brightness(0.95);
}
:root[data-theme="dark"] .stat-static:hover { filter: saturate(0.7) brightness(0.8); }
.stat-top { display: flex; align-items: center; justify-content: space-between; gap: 0.5rem; color: var(--text-muted); }
.stat-label { font-size: 0.74rem; font-weight: 700; letter-spacing: 0.14em; text-transform: uppercase; }
.stat-icon { width: 1.3rem; height: 1.3rem; color: var(--primary); }
/* The big numbers keep their size when the visitor enlarges the text (--rem0). */
.stat-value {
  margin-top: 0.35rem;
  font-family: var(--font-display);
  font-size: clamp(calc(1.8 * var(--rem0)), calc(1.2 * var(--rem0) + 1.5vw), calc(2.5 * var(--rem0)));
  font-weight: 650;
  line-height: 1.1;
  letter-spacing: -0.02em;
  font-variant-numeric: lining-nums tabular-nums;
}
.stat-value.small { font-size: clamp(calc(1.15 * var(--rem0)), calc(1 * var(--rem0) + 0.5vw), calc(1.45 * var(--rem0))); line-height: 1.35; letter-spacing: -0.01em; }
.stat-sub { margin-top: 0.15rem; font-size: 0.85rem; color: var(--text-muted); }
.split-bar { display: flex; height: 0.4rem; margin-top: 0.7rem; overflow: hidden; background: var(--surface-3); border-radius: 99px; }
.split-bar span { display: block; height: 100%; transition: flex-basis 0.7s var(--ease-out); }
.split-bar span:first-child { background: var(--primary); }
.split-bar span:last-child { background: var(--amber); }
.stat-card .progress { margin-top: 0.7rem; height: 0.4rem; }


/* 3. Filters ------------------------------------------------------------------ */

.filters { display: grid; gap: 1rem; padding: 1.1rem 1.25rem 1.25rem; margin-top: 1.75rem; }
.filters-head { display: flex; flex-wrap: wrap; align-items: center; gap: 0.75rem; }
.filters-head .search-field { flex: 1 1 18rem; max-width: 36rem; }
.filters-head h2 { font-size: 1.15rem; margin-right: 0.5rem; }
.filter-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(min(10.5rem, 100%), 1fr)); gap: 0.85rem; align-items: end; }
.filter-group { display: grid; gap: 0.3rem; min-width: 0; }
.filter-group label { font-size: 0.72rem; font-weight: 700; letter-spacing: 0.12em; text-transform: uppercase; color: var(--text-muted); }
/* The dropdown a stat card opened glows for a moment (dashboard.js) */
.filter-group.flash select { animation: field-flash 1.6s var(--ease-out); }
.filter-group.flash label { color: var(--primary-ink); transition: color 0.3s; }
:root[data-theme="dark"] .filter-group.flash label { color: var(--primary); }
@keyframes field-flash {
  0%, 40% { border-color: var(--primary); box-shadow: 0 0 0 4px var(--primary-soft), 0 0 18px -2px var(--primary-glow); }
}
.filter-badge {
  display: inline-grid;
  place-items: center;
  min-width: 1.4rem;
  height: 1.4rem;
  padding: 0 0.4rem;
  font-size: 0.75rem;
  font-weight: 700;
  color: var(--on-primary);
  background: var(--primary);
  border-radius: 99px;
}
.active-filters { display: flex; flex-wrap: wrap; gap: 0.45rem; min-height: 0; }
.active-filters:empty { display: none; }
.filter-pill {
  display: inline-flex;
  align-items: center;
  gap: 0.35rem;
  padding: 0.18rem 0.3rem 0.18rem 0.75rem;
  font: 700 0.82rem var(--font-text);
  color: var(--primary-ink);
  background: var(--primary-soft);
  border-radius: 99px;
  animation: pop-in 0.3s var(--ease-spring) both;
}
:root[data-theme="dark"] .filter-pill { color: var(--primary); }
.filter-pill button {
  display: grid;
  place-items: center;
  width: 1.35rem;
  height: 1.35rem;
  padding: 0;
  color: inherit;
  background: transparent;
  border: 0;
  border-radius: 50%;
  cursor: pointer;
}
.filter-pill button:hover { background: color-mix(in srgb, currentColor 18%, transparent); }
.filter-pill .icon { width: 0.8rem; height: 0.8rem; }

/* FlowCam measurement ranges (dashboard.js section 5b) */
.measure-filters { display: grid; gap: 0.75rem; padding-top: 0.9rem; border-top: 1px solid var(--border); }
.measure-head { display: flex; flex-wrap: wrap; align-items: center; gap: 0.5rem 0.75rem; }
.measure-head h3 { margin: 0; font-size: 0.72rem; font-weight: 700; letter-spacing: 0.12em; text-transform: uppercase; color: var(--text-muted); }
.measure-note { font-size: 0.85rem; color: var(--text-muted); }
.measure-head .btn { margin-left: auto; }
.measure-busy { display: none; align-items: center; gap: 0.4rem; font-size: 0.85rem; color: var(--text-muted); }
.measure-busy .spinner { width: 0.95rem; height: 0.95rem; border-width: 2px; }
.measure-filters[aria-busy="true"] .measure-busy { display: inline-flex; }
.measure-list { display: grid; grid-template-columns: repeat(auto-fill, minmax(min(22rem, 100%), 1fr)); gap: 0.75rem; }
.measure-list:empty { display: none; }
.measure-row {
  display: grid;
  gap: 0.45rem;
  padding: 0.65rem 0.75rem 0.7rem;
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: var(--r-md, 12px);
  animation: pop-in 0.3s var(--ease-spring) both;
}
.measure-row-head { display: flex; align-items: center; gap: 0.45rem; min-width: 0; }
.measure-label { font-weight: 700; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.measure-unit { font-size: 0.8rem; font-weight: 600; color: var(--text-muted); }
.measure-group { margin-left: auto; font-size: 0.75rem; color: var(--text-muted); white-space: nowrap; }
.measure-range { display: grid; grid-template-columns: minmax(4.5rem, 6.5rem) 1fr minmax(4.5rem, 6.5rem); align-items: center; gap: 0.6rem; }
.measure-range input[type="number"] { min-width: 0; padding: 0.35rem 0.5rem; font-size: 0.9rem; }
@media (max-width: 480px) {
  /* Slider on its own line above the two number boxes */
  .measure-range { grid-template-columns: 1fr 1fr; }
  .measure-range .dual-range { grid-column: 1 / -1; order: -1; }
}
.measure-hint { font-size: 0.78rem; color: var(--text-muted); }
/* Two range inputs on one track: only their thumbs take the pointer */
.dual-range { position: relative; height: 1.75rem; min-width: 5rem; }
.dual-range::before { content: ""; position: absolute; left: 0; right: 0; top: 50%; height: 4px; translate: 0 -50%; background: var(--surface-3); border-radius: 99px; }
.dual-range::after { content: ""; position: absolute; left: var(--lo, 0%); right: calc(100% - var(--hi, 100%)); top: 50%; height: 4px; translate: 0 -50%; background: var(--primary); border-radius: 99px; }
.dual-range input { position: absolute; z-index: 1; inset: 0; width: 100%; height: 100%; margin: 0; background: none; pointer-events: none; accent-color: var(--primary); -webkit-appearance: none; appearance: none; }
.dual-range input::-webkit-slider-runnable-track { background: none; }
.dual-range input::-moz-range-track { background: none; }
.dual-range input::-webkit-slider-thumb { pointer-events: auto; -webkit-appearance: none; width: 1.05rem; height: 1.05rem; background: var(--primary); border: 2px solid var(--surface); border-radius: 50%; box-shadow: 0 1px 3px rgba(0, 0, 0, 0.3); cursor: pointer; }
.dual-range input::-moz-range-thumb { pointer-events: auto; width: 1.05rem; height: 1.05rem; background: var(--primary); border: 2px solid var(--surface); border-radius: 50%; box-shadow: 0 1px 3px rgba(0, 0, 0, 0.3); cursor: pointer; }
.dual-range input:focus-visible { outline: none; }
.dual-range input:focus-visible::-webkit-slider-thumb { box-shadow: 0 0 0 4px var(--primary-soft); }
.dual-range input:focus-visible::-moz-range-thumb { box-shadow: 0 0 0 4px var(--primary-soft); }
.count-cell .of-total { position: relative; font-size: 0.78rem; color: var(--text-muted); }
.th-unit { text-transform: none; letter-spacing: normal; }

/* "Add measurement" dialog */
.measure-picker-body { display: grid; gap: 0.85rem; }
.measure-picker { display: grid; gap: 1rem; max-height: min(60vh, 34rem); overflow-y: auto; padding-right: 0.25rem; }
.measure-picker-group { display: grid; grid-template-columns: repeat(auto-fill, minmax(min(15rem, 100%), 1fr)); gap: 0.45rem; }
.measure-picker-group h3 { grid-column: 1 / -1; margin: 0; font-size: 0.72rem; font-weight: 700; letter-spacing: 0.12em; text-transform: uppercase; color: var(--text-muted); }
.measure-choice {
  display: grid;
  gap: 0.2rem;
  padding: 0.55rem 0.7rem;
  font: inherit;
  text-align: left;
  color: var(--text);
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: 10px;
  cursor: pointer;
}
.measure-choice:hover:not(:disabled) { border-color: var(--primary); background: var(--surface-3); }
.measure-choice:disabled { opacity: 0.6; cursor: default; }
.measure-choice-label { display: flex; align-items: center; gap: 0.4rem; font-weight: 700; }
.measure-choice-label .icon { width: 0.9rem; height: 0.9rem; color: var(--primary); }
.measure-choice small { font-size: 0.78rem; color: var(--text-muted); line-height: 1.35; }


/* 4. Table + pager --------------------------------------------------------------- */

.table-card { margin-top: 1.25rem; }
.table-toolbar { display: flex; align-items: center; justify-content: space-between; gap: 1rem; flex-wrap: wrap; padding: 0.9rem 1.25rem; border-bottom: 1px solid var(--border); }
.results-count { font-size: 0.95rem; color: var(--text-2); }
.results-count strong { font-family: var(--font-display); font-size: 1.15rem; color: var(--text); }

.folders-table th { padding: 0; }
.th-btn {
  display: inline-flex;
  align-items: center;
  gap: 0.35rem;
  width: 100%;
  padding: 0.8rem 0.8rem;
  font: inherit;
  letter-spacing: inherit;
  text-transform: inherit;
  color: inherit;
  text-align: inherit;
  background: none;
  border: 0;
  cursor: pointer;
  transition: color 0.2s, background-color 0.2s;
}
.th-btn:hover { color: var(--text); background: var(--surface-3); }
th.num .th-btn { justify-content: flex-end; }
.sort-icon { width: 0.95em; height: 0.95em; opacity: 0; transition: opacity 0.2s, transform 0.3s var(--ease-spring); }
.th-btn:hover .sort-icon { opacity: 0.45; }
th[aria-sort="ascending"] .th-btn .sort-icon, th[aria-sort="descending"] .th-btn .sort-icon { opacity: 1; }
th[aria-sort="ascending"] .sort-icon { transform: rotate(180deg); }
th[aria-sort="ascending"], th[aria-sort="descending"] { color: var(--primary-ink); }
:root[data-theme="dark"] th[aria-sort="ascending"], :root[data-theme="dark"] th[aria-sort="descending"] { color: var(--primary); }

.folders-table tbody tr { cursor: pointer; animation: row-in 0.45s var(--ease-out) both; animation-delay: calc(var(--i, 0) * 18ms); }
.folders-table tbody tr:hover td:first-child { box-shadow: inset 3px 0 0 var(--primary); }
@keyframes row-in { from { opacity: 0; transform: translateY(0.5rem); } }
.folders-table td { padding: 0.65rem 0.8rem; }
.folders-table .col-folder { max-width: 17rem; }
.row-link {
  display: block;
  max-width: 100%;
  padding: 0;
  overflow: hidden;
  font: 700 0.95rem var(--font-text);
  color: var(--text);
  text-align: left;
  text-overflow: ellipsis;
  white-space: nowrap;
  background: none;
  border: 0;
  cursor: pointer;
}
.row-link:hover { color: var(--primary-ink); text-decoration: underline; text-underline-offset: 0.2em; }
:root[data-theme="dark"] .row-link:hover { color: var(--primary); }
.site-name { font-weight: 700; text-transform: capitalize; white-space: nowrap; }
.code-tag { font: 700 0.8rem var(--font-mono); padding: 0.1rem 0.45rem; background: var(--surface-3); border-radius: 6px; color: var(--text-2); }
.count-cell { position: relative; min-width: 6rem; }
.count-cell .bar { position: absolute; inset: 0.45rem 0.6rem 0.45rem auto; width: var(--pct, 0%); max-width: calc(100% - 1.2rem); background: linear-gradient(90deg, transparent, var(--primary-soft)); border-radius: 6px; }
.count-cell span { position: relative; font-weight: 700; }
.mini-progress { display: grid; gap: 0.25rem; min-width: 5.5rem; }
.mini-progress .progress { height: 0.35rem; }
.mini-progress small { font-size: 0.76rem; color: var(--text-muted); font-variant-numeric: tabular-nums; }
.no-results { padding: 3rem 1rem !important; text-align: center; color: var(--text-muted); font-style: italic; }
.skel-row td { padding: 0.95rem 1rem; }
.skel-row .skeleton { height: 0.95rem; }

.pager {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 0.8rem 1.5rem;
  padding: 1rem 0.25rem 0.25rem;
}
.page-info { font-size: 0.92rem; color: var(--text-muted); }
#pagination-container { display: flex; align-items: center; gap: 0.3rem; flex-wrap: wrap; }
#pagination-container button {
  min-width: 2.4rem;
  min-height: 2.4rem;
  padding: 0.3rem 0.7rem;
  font: 700 0.9rem var(--font-text);
  color: var(--text-2);
  background: var(--surface);
  border: 1px solid var(--border-strong);
  border-radius: 10px;
  cursor: pointer;
  transition: transform 0.15s var(--ease-out), background-color 0.2s, color 0.2s, border-color 0.2s;
}
#pagination-container button:hover:not(:disabled):not(.active) { color: var(--text); background: var(--surface-3); transform: translateY(-1px); }
#pagination-container button.active { color: var(--on-primary); background: linear-gradient(135deg, var(--primary), var(--primary-2)); border-color: transparent; box-shadow: 0 6px 14px -6px var(--primary-glow); }
#pagination-container button:disabled { opacity: 0.4; cursor: not-allowed; }
.page-ellipsis { padding: 0 0.2rem; color: var(--text-muted); }
.page-size { display: flex; align-items: center; gap: 0.5rem; font-size: 0.85rem; color: var(--text-muted); }
#page-size { width: auto; min-height: 2.3rem; padding-block: 0.25rem; }


/* The size range is the least-needed column: it lives in the detail sheet too. */
@media (max-width: 1500px) and (min-width: 761px) {
  .folders-table th:last-child, .folders-table td:last-child { display: none; }
}

/* 5. Charts ----------------------------------------------------------------------- */

#charts-section { display: grid; grid-template-columns: repeat(12, minmax(0, 1fr)); gap: 1.25rem; margin-top: 1.75rem; }
.chart-card { grid-column: span 6; padding: 1.3rem 1.4rem 1.4rem; }
.chart-card.span-5 { grid-column: span 5; }
.chart-card.span-7 { grid-column: span 7; }
.chart-card h3 { display: flex; align-items: center; gap: 0.55rem; margin-bottom: 0.2rem; font-size: 1.2rem; }
.chart-card h3 .icon { color: var(--primary); }
.chart-card .chart-sub { margin-bottom: 1rem; font-size: 0.88rem; color: var(--text-muted); }
/* Graphs are drawn at fixed pixel sizes, text included, so they keep their
   size when the visitor enlarges the text; only titles and legends grow. */
.chart { position: relative; width: 100%; min-height: calc(15 * var(--rem0)); }
.chart svg { display: block; width: 100%; overflow: visible; }
.chart text { font-family: var(--font-text); fill: var(--text-muted); font-size: 11.5px; }
.chart .axis-label { fill: var(--text-2); font-size: 12.5px; font-weight: 700; }
.chart .grid-line { stroke: var(--chart-grid); stroke-width: 1; }
.chart .value-label { fill: var(--text-2); font-size: 12px; font-weight: 700; font-variant-numeric: tabular-nums; }
.chart .bar-h { transform-box: fill-box; transform-origin: left center; animation: grow-x 0.9s var(--ease-out) both; animation-delay: calc(var(--i, 0) * 40ms); }
.chart .bar-v { transform-box: fill-box; transform-origin: center bottom; animation: grow-y 0.9s var(--ease-out) both; animation-delay: calc(var(--i, 0) * 16ms); }
.chart .hit { fill: transparent; cursor: default; }
.chart g.item[data-value], .chart g.item[data-value] .hit { cursor: pointer; }
.chart g.item.picked .axis-label { fill: var(--primary-ink); }
:root[data-theme="dark"] .chart g.item.picked .axis-label { fill: var(--primary); }
.chart g.item:hover .bar-h, .chart g.item:hover .bar-v { filter: brightness(1.18) saturate(1.1); }
.chart g.item:hover .axis-label { fill: var(--text); }
@keyframes grow-x { from { transform: scaleX(0); } }
@keyframes grow-y { from { transform: scaleY(0); } }
.chart-tip {
  position: fixed;
  z-index: 100;
  max-width: 17rem;
  padding: 0.45rem 0.7rem;
  font-size: 0.85rem;
  line-height: 1.35;
  color: var(--text);
  background: var(--surface-elev);
  border: 1px solid var(--border-strong);
  border-radius: 10px;
  box-shadow: var(--shadow-md);
  pointer-events: none;
  opacity: 0;
  transform: translate(-50%, calc(-100% - 10px));
  transition: opacity 0.12s;
}
.chart-tip.on { opacity: 1; }
.chart-tip strong { display: block; font-family: var(--font-display); font-size: 0.95rem; }

/* --rem0 keeps the donut (and the total in its middle) the same size at any text size. */
.donut-wrap { display: grid; grid-template-columns: minmax(calc(10 * var(--rem0)), calc(13.5 * var(--rem0))) minmax(0, 1fr); gap: 1.6rem; align-items: center; }
.donut svg { overflow: visible; }
.donut .dseg { transform-box: view-box; transform-origin: center; animation: seg-in 0.9s var(--ease-out) both; animation-delay: calc(var(--i, 0) * 70ms); transition: transform 0.25s var(--ease-spring), opacity 0.2s; cursor: default; }
.donut .dseg[data-value] { cursor: pointer; }
.donut.dim .dseg:not(.on) { opacity: 0.35; }
.donut .dseg.on { transform: scale(1.045); }
@keyframes seg-in { from { opacity: 0; transform: scale(0.82) rotate(-25deg); } }
.donut-center { font-family: var(--font-display); fill: var(--text) !important; font-size: 30px !important; font-weight: 650; font-variant-numeric: lining-nums tabular-nums; }
.donut-sub { font-size: 11px !important; letter-spacing: 0.14em; text-transform: uppercase; font-weight: 700; }
.legend { display: grid; gap: 0.2rem; margin: 0; padding: 0; list-style: none; }
.legend li { display: flex; align-items: center; gap: 0.6rem; padding: 0.35rem 0.6rem; font-size: 0.95rem; border-radius: 9px; transition: background-color 0.2s; }
.legend li.on { background: var(--surface-3); }
.legend .sw { flex: none; width: 0.75rem; height: 0.75rem; background: var(--c); border-radius: 4px; }
.legend .name { font-weight: 700; text-transform: capitalize; }
.legend .count { margin-left: auto; font-variant-numeric: tabular-nums; color: var(--text-muted); white-space: nowrap; }
/* Legend entries that apply their filter when clicked (dashboard.js) */
.legend li.pick { padding: 0; }
.legend-btn {
  display: flex;
  align-items: center;
  gap: 0.6rem;
  width: 100%;
  padding: 0.35rem 0.6rem;
  font: inherit;
  color: inherit;
  text-align: left;
  background: none;
  border: 0;
  border-radius: inherit;
  cursor: pointer;
}
.legend-btn[aria-pressed="true"] { background: var(--primary-soft); box-shadow: inset 0 0 0 1.5px var(--primary); }
.legend-btn[aria-pressed="true"] .count { color: var(--text-2); }


/* 6. QA log ----------------------------------------------------------------------- */

#qa-section { margin-top: 1.75rem; overflow: hidden; }
.qa-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  width: 100%;
  padding: 1.1rem 1.4rem;
  font: inherit;
  color: inherit;
  text-align: left;
  background: none;
  border: 0;
  cursor: pointer;
  transition: background-color 0.2s;
}
.qa-header:hover { background: var(--surface-2); }
.qa-header h2 { display: flex; align-items: center; gap: 0.6rem; font-size: 1.2rem; }
.qa-header .chev { transition: transform 0.35s var(--ease-spring); }
.qa-header[aria-expanded="true"] .chev { transform: rotate(180deg); }
.qa-content { border-top: 1px solid var(--border); }
.qa-ok { color: var(--success-ink); }
tr.qa-warn td:first-child, tr.qa-warning td:first-child { color: var(--amber-ink); font-weight: 700; }
tr.qa-error td:first-child { color: var(--danger-ink); font-weight: 700; }


/* 7. Detail sheet ------------------------------------------------------------------ */

.sheet-backdrop {
  position: fixed;
  inset: 0;
  z-index: 60;
  background: var(--scrim);
  -webkit-backdrop-filter: blur(4px);
  backdrop-filter: blur(4px);
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.35s;
}
.sheet-backdrop.open { opacity: 1; pointer-events: auto; }

#detail-panel {
  position: fixed;
  top: 0;
  right: 0;
  z-index: 70;
  display: flex;
  flex-direction: column;
  width: min(47rem, 100vw);
  height: 100vh;
  height: 100dvh;
  background: var(--surface);
  border-left: 1px solid var(--border-strong);
  box-shadow: var(--shadow-lg);
  transform: translateX(105%);
  visibility: hidden;
  transition: transform 0.5s var(--ease-out), visibility 0s 0.5s;
}
#detail-panel.open { transform: none; visibility: visible; transition: transform 0.5s var(--ease-out), visibility 0s; }
.panel-header { display: flex; align-items: flex-start; justify-content: space-between; gap: 1rem; padding: 1.3rem 1.5rem 1.1rem; border-bottom: 1px solid var(--border); background: var(--surface-2); }
.panel-header .eyebrow { margin-bottom: 0.25rem; }
.panel-header h2 { font-size: 1.25rem; line-height: 1.3; overflow-wrap: anywhere; }
.panel-content { flex: 1; padding: 1.4rem 1.5rem 2rem; overflow-y: auto; overscroll-behavior: contain; }
.detail-actions { display: flex; flex-wrap: wrap; gap: 0.6rem; margin-bottom: 1.4rem; }
.meta-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(min(10.5rem, 100%), 1fr)); gap: 1rem 1.5rem; margin: 0 0 1.6rem; padding: 1.1rem 1.2rem; background: var(--surface-2); border: 1px solid var(--border); border-radius: var(--r-lg); }
.meta-grid dt { font-size: 0.7rem; font-weight: 700; letter-spacing: 0.13em; text-transform: uppercase; color: var(--text-muted); }
.meta-grid dd { margin: 0.1rem 0 0; font-weight: 700; overflow-wrap: anywhere; }
.detail-images-header { display: flex; align-items: center; justify-content: space-between; gap: 1rem; flex-wrap: wrap; margin-bottom: 0.85rem; }
.detail-images-header h3 { font-size: 1.2rem; }

.img-controls { display: flex; align-items: center; gap: 0.75rem; flex-wrap: wrap; margin-bottom: 0.9rem; }
.img-controls .search-field { flex: 1 1 11rem; }
.img-count { font-size: 0.85rem; color: var(--text-muted); white-space: nowrap; }

.thumb-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(min(7.4rem, 100%), 1fr)); gap: 0.6rem; }
.thumb {
  position: relative;
  aspect-ratio: 1;
  padding: 0;
  overflow: hidden;
  cursor: zoom-in;
  background: var(--media-bg);
  border: 1px solid var(--border);
  border-radius: 12px;
  transition: transform 0.3s var(--ease-spring), box-shadow 0.3s, border-color 0.2s;
  animation: row-in 0.4s var(--ease-out) both;
  animation-delay: calc(var(--i, 0) * 14ms);
}
.thumb:hover, .thumb:focus-visible { z-index: 2; transform: translateY(-3px) scale(1.04); border-color: var(--primary); box-shadow: var(--shadow-md); }
.thumb img { display: block; width: 100%; height: 100%; object-fit: contain; }
.thumb[data-label] { box-shadow: inset 0 -4px 0 var(--c); }
.thumb .thumb-tag { position: absolute; left: 0.3rem; top: 0.3rem; }
.thumb .thumb-dim { position: absolute; right: 0.3rem; bottom: 0.45rem; padding: 0 0.35rem; font: 700 0.66rem var(--font-mono); color: #fff; background: rgba(0, 0, 0, 0.55); border-radius: 5px; opacity: 0; transition: opacity 0.2s; }
.thumb:hover .thumb-dim, .thumb:focus-visible .thumb-dim { opacity: 1; }
.thumb-more { display: grid; place-items: center; margin-top: 1rem; }

.img-table-wrap { overflow-x: auto; border: 1px solid var(--border); border-radius: var(--r); }
.img-table { font-size: 0.85rem; }
.img-table th { padding: 0; position: sticky; top: 0; }
.img-table td { padding: 0.45rem 0.8rem; }
.img-filename { max-width: 14rem; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font: 0.8rem var(--font-mono); }
.img-actions-cell { display: flex; gap: 0.3rem; }
.img-truncated { padding: 0.8rem; text-align: center; font-size: 0.88rem; color: var(--text-muted); }


/* 8. Responsive ----------------------------------------------------------------------- */

@media (max-width: 1100px) {
  .chart-card, .chart-card.span-5, .chart-card.span-7 { grid-column: span 12; }
}

@media (max-width: 860px) {
  .donut-wrap { grid-template-columns: 1fr; justify-items: center; }
  .donut-wrap .legend { width: 100%; }
  .stats-grid { margin-inline: 0; }
}

/* Table rows become cards on phones */
@media (max-width: 760px) {
  .folders-table thead { display: none; }
  .folders-table, .folders-table tbody { display: block; }
  .folders-table tr { display: grid; grid-template-columns: 1fr 1fr; gap: 0.6rem 1rem; padding: 1rem 1.1rem; border-bottom: 1px solid var(--border); }
  .folders-table tr.skel-row, .folders-table tr:has(.no-results) { display: block; }
  .folders-table td { display: grid; gap: 0.1rem; padding: 0; border: 0; min-width: 0; }
  .folders-table td::before { content: attr(data-label); font-size: 0.66rem; font-weight: 700; letter-spacing: 0.12em; text-transform: uppercase; color: var(--text-muted); }
  .folders-table td.col-folder { grid-column: 1 / -1; max-width: none; }
  .folders-table td.col-folder::before { display: none; }
  .folders-table td.no-results::before, .folders-table td.skel-cell::before { display: none; }
  .folders-table .num { text-align: left; }
  .folders-table .count-cell .bar { display: none; }
  .table-toolbar { padding-inline: 1rem; }
  #detail-panel { width: 100vw; }
  .filters { padding: 1rem; }
  .filters-head .search-field { max-width: none; }
  .filter-grid.collapsed { display: none; }
}
@media (min-width: 761px) {
  #filters-toggle { display: none; }
}

/* Large text (theme.js sets data-text-big): stack the graphs as on a narrow
   screen; the donut keeps its size. */
:root[data-text-big] .chart-card, :root[data-text-big] .chart-card.span-5, :root[data-text-big] .chart-card.span-7 { grid-column: span 12; }
:root[data-text-big] .donut-wrap { grid-template-columns: 1fr; justify-items: center; }
:root[data-text-big] .donut { width: min(calc(13.5 * var(--rem0)), 100%); }
:root[data-text-big] .donut-wrap .legend { width: 100%; }
:root[data-text-big] .stats-grid { margin-inline: 0; }


/* 9. Text-size dialog ------------------------------------------------------------------ */

/* --ts is the size being previewed; the sample text and the Cancel/Apply
   buttons are drawn at it (relative to 1x, hence --rem0) before it's applied. */
.ts-dialog { --ts: 1; display: grid; gap: 1.1rem; }
.ts-dialog > * { animation: row-in 0.45s var(--ease-out) both; animation-delay: calc(var(--i, 0) * 70ms + 120ms); }
.ts-intro { font-size: 0.93rem; color: var(--text-muted); }
.ts-control { display: flex; align-items: center; gap: 0.6rem; }
.ts-range { display: grid; flex: 1; min-width: 0; }
.ts-range input { width: 100%; height: 1.75rem; margin: 0; accent-color: var(--primary); cursor: pointer; }
.ts-ticks { display: flex; justify-content: space-between; padding-inline: 0.2rem; font-size: 0.75rem; font-weight: 700; color: var(--text-muted); }
.ts-value {
  min-width: 4rem;
  padding: 0.2rem 0.65rem;
  font: 700 1rem var(--font-mono);
  text-align: center;
  color: var(--primary-ink);
  background: var(--primary-soft);
  border-radius: 99px;
}
:root[data-theme="dark"] .ts-value { color: var(--primary); }
.ts-value.bump { animation: pop-in 0.3s var(--ease-spring); }
.ts-preview {
  max-height: 38vh;
  overflow: auto;
  padding: 1rem 1.15rem;
  background: var(--surface-2);
  border: 1px dashed var(--border-strong);
  border-radius: var(--r);
}
.ts-preview .eyebrow { font-size: calc(0.78 * var(--rem0) * var(--ts)); }
.ts-sample-title { margin-top: 0.25em; font-family: var(--font-display); font-weight: 600; font-size: calc(1.3 * var(--rem0) * var(--ts)); line-height: 1.2; }
.ts-sample-body { margin-top: 0.35em; font-size: calc(1.0625 * var(--rem0) * var(--ts)); color: var(--text-2); }
.ts-preview .eyebrow, .ts-sample-title, .ts-sample-body { transition: font-size 0.25s var(--ease-out); }
.ts-actions { display: flex; flex-wrap: wrap; justify-content: flex-end; gap: 0.6rem; }
.ts-actions .btn {
  min-height: 2.7em;
  padding: 0.55em 1.15em;
  font-size: calc(0.92 * var(--rem0) * var(--ts));
  border-radius: 0.8em;
  transition: font-size 0.25s var(--ease-out), transform 0.18s var(--ease-out), background-color 0.2s, border-color 0.2s, box-shadow 0.25s, color 0.2s, filter 0.2s;
}
