/* Pepper Heat Database page blocks (templates/tools/pepper-database.php). Loaded after tools.css (data-page-style).
   Frame classes do the rest: .tool-stats, .tool-card, .tool-select, .tier-chip, .heat-range, .heat-axis, .tool-tray.
   Comp: tmp/design-v3/comps/tool-database.png. Prefix: .db-* */

.db-band { padding-bottom: 0; }
.db-stack > * + * { margin-top: var(--ktp-space-6); }

/* Stat tiles: glyph left, value + label right */
.db-stats .tool-stat { display: flex; align-items: center; gap: var(--ktp-space-4); padding: var(--ktp-space-4) var(--ktp-space-5); text-align: left; }
.db-stat__icon { flex: none; color: var(--ktp-muted); } /* chili is kept for the action, active state and heat data */
.db-stats .tool-stat__value { font-size: clamp(1.4rem, 2.2vw, 2.2rem); white-space: nowrap; } /* "3,000,000" broke as "3,000,00 / 0" near 1000 px */
.db-stats .tool-stat__label { margin-top: 2px; font-size: 13px; }
@media (max-width: 520px) {
  .db-stats .tool-stat { flex-direction: column; align-items: flex-start; gap: var(--ktp-space-2); padding: var(--ktp-space-4); }
}

/* Filter bar */
.db-filters { padding: var(--ktp-space-4) var(--ktp-space-5); background: var(--ktp-smoke); box-shadow: none; }
.db-filters__row { display: flex; flex-wrap: wrap; align-items: center; gap: var(--ktp-space-3); }
.db-filters__row > .tool-field { flex: 1 1 120px; min-width: 0; }
.db-filters__row > .db-filters__search { flex: 1.3 1 200px; }
.db-filters__row > .db-filters__sort { flex: 1.5 1 195px; }
.db-search { padding-left: 44px; }
.db-filters .tool-select-wrap > .tool-select__icon:not(.ktp-icon--chevron) { right: auto; left: 16px; }
.db-filters .tool-select { color: var(--ktp-ink); font-size: 16px; text-overflow: ellipsis; }
.db-reset { border-color: transparent; color: var(--ktp-chili); }
.db-reset:hover { background: var(--ktp-white); }
.db-view { display: inline-flex; flex: none; gap: var(--ktp-space-2); padding-left: var(--ktp-space-4); border-left: 1px solid var(--ktp-hairline); }
.db-view__btn { background: var(--ktp-white); }
.db-view__btn.is-active { border-color: var(--ktp-chili); background: var(--ktp-chili); color: var(--ktp-white); }
.db-view__btn.is-active:hover { background: var(--ktp-chili-dark); }
@media (max-width: 640px) {
  .db-filters { padding: var(--ktp-space-4); }
  .db-filters__row > .tool-field { flex: 1 1 calc(50% - 8px); }
  .db-filters__row > .db-filters__search { flex: 1 1 100%; }
  .db-view { display: none; } /* phones always show the card grid */
}

/* Results header: count on the left, the one shared log axis on the right */
.db-results__bar { display: flex; flex-wrap: wrap; align-items: flex-end; justify-content: space-between; gap: var(--ktp-space-4) var(--ktp-space-6); margin-bottom: var(--ktp-space-5); }
.db-count { color: var(--ktp-muted); font-size: var(--ktp-fs-body); }
.db-legend { width: min(100%, 480px); padding-inline: 24px; } /* ticks are centred on their lines: side room for 100 and 10M */
.db-legend .heat-axis__marks { display: none; }
.db-legend .heat-axis__bar { height: 10px; border-radius: 5px; }
.db-legend .heat-axis__ticks { height: 30px; }
.db-legend .heat-axis__tick { font-size: 13px; }

/* Grid view */
.db-grid { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: var(--tool-gap); }
.db-grid[hidden], .db-table-wrap[hidden] { display: none; }
.db-card { display: flex; flex-direction: column; min-width: 0; padding: var(--ktp-space-2); border: var(--ktp-line); border-radius: var(--ktp-radius); background: var(--ktp-white); box-shadow: var(--tool-shadow); }
.db-card__art { position: relative; display: block; aspect-ratio: 4 / 3; border-radius: var(--ktp-radius-sm); background: var(--ktp-smoke); }
.db-card__art .db-art { position: absolute; inset: 12%; width: 76%; height: 76%; object-fit: contain; }
.db-card__art .db-art__fallback { position: absolute; top: 50%; left: 50%; transform: translate(-50%, -50%); }
.db-card__body { display: flex; flex: 1; flex-direction: column; align-items: flex-start; gap: var(--ktp-space-2); padding: var(--ktp-space-4) var(--ktp-space-3) var(--ktp-space-3); }
.db-card__name, .db-col__name { margin: 0; color: var(--ktp-ink); font-family: var(--ktp-font-display); font-size: 1.25rem; font-weight: 800; line-height: 1.2; letter-spacing: -0.01em; overflow-wrap: anywhere; }
.db-card__name a, .db-col__name a, .db-table__name { color: inherit; text-decoration: none; }
.db-card__name a:hover, .db-col__name a:hover, .db-table__name:hover { text-decoration: underline; text-decoration-color: var(--ktp-chili-40); text-underline-offset: 3px; }
.db-card__sci { color: var(--ktp-muted); font-size: 15px; font-style: italic; line-height: 1.35; }
.db-card .tier-chip, .db-col .tier-chip, .db-table .tier-chip { margin-top: var(--ktp-space-1); white-space: nowrap; }
.db-card__shu { color: var(--ktp-ink); font-family: var(--ktp-font-display); font-size: 1.1rem; font-weight: 800; line-height: 1.25; }
.db-card__shu span { color: var(--ktp-muted); font-family: var(--ktp-font-body, inherit); font-size: 13px; font-weight: 600; }
.db-card .heat-range { align-self: stretch; margin-block: var(--ktp-space-1); }
.db-card__origin { margin-bottom: var(--ktp-space-2); color: var(--ktp-muted); font-size: 14px; line-height: 1.35; }
.db-pick { align-self: stretch; margin-top: auto; }
.db-pick:disabled { opacity: .45; cursor: not-allowed; }
.db-pick.is-picked { border-color: var(--ktp-ink); background: var(--ktp-ink); color: var(--ktp-white); }
.db-pick.is-picked:hover { background: var(--ktp-ancho); }
@media (max-width: 1100px) { .db-grid { grid-template-columns: repeat(3, minmax(0, 1fr)); } }
@media (max-width: 760px) {
  .db-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); gap: var(--ktp-space-3); }
  .db-card__body { padding-inline: var(--ktp-space-2); }
  .db-card__name { font-size: 1.1rem; }
  .db-card__shu { font-size: 1rem; }
}

.db-empty { grid-column: 1 / -1; display: flex; flex-direction: column; align-items: center; gap: var(--ktp-space-2); padding: var(--ktp-space-8, 48px) var(--ktp-space-4); color: var(--ktp-muted); text-align: center; }
.db-empty strong { color: var(--ktp-ink); font-size: 1.1rem; }
.db-more { margin-top: var(--ktp-space-6); margin-bottom: var(--ktp-section-y-sm); text-align: center; }
.db-more .tool-btn { min-width: 240px; }

/* Table view (today's columns) */
.db-table-wrap { overflow-x: auto; border: var(--ktp-line); border-radius: var(--ktp-radius); background: var(--ktp-white); box-shadow: var(--tool-shadow); }
.db-table { width: 100%; min-width: 920px; border-collapse: collapse; font-size: 16px; }
.db-table th { padding: 14px 16px; border-bottom: 1.5px solid var(--ktp-hairline); background: var(--ktp-smoke); color: var(--ktp-ink); font-size: 14px; font-weight: 700; line-height: 1.3; text-align: left; white-space: nowrap; }
.db-table td { padding: 12px 16px; border-top: 1px solid var(--ktp-hairline); color: var(--ktp-ink); line-height: 1.4; vertical-align: middle; }
.db-table tbody tr:first-child td { border-top: 0; }
.db-table tbody tr:hover td { background: #fcfaf9; }
.db-table em { color: var(--ktp-muted); white-space: nowrap; }
.db-table__name { font-weight: 700; }
.db-num { font-variant-numeric: tabular-nums; text-align: right; }
.db-table th:nth-child(3), .db-table th:nth-child(4) { text-align: right; }
.db-table__scale { width: 170px; }
.db-table .db-pick { align-self: auto; white-space: nowrap; }
.db-sort { display: inline-flex; align-items: center; gap: 6px; padding: 0; border: 0; background: none; color: inherit; font: inherit; font-weight: 700; cursor: pointer; }
.db-sort:hover { color: var(--ktp-chili); }
.db-sort:focus-visible { outline: 3px solid var(--ktp-habanero); outline-offset: 2px; }
th[aria-sort="ascending"] .db-sort::after { content: "\2191"; color: var(--ktp-chili); }
th[aria-sort="descending"] .db-sort::after { content: "\2193"; color: var(--ktp-chili); }

/* Compare tray additions (frame .tool-tray does the sticky bar) */
.db-tray { transition: none; }
.db-tray.is-idle { visibility: hidden; pointer-events: none; } /* keeps its height, so showing it never moves the page */
.db-tray .tool-tray__inner { padding-block: var(--ktp-space-3); }
.db-tray .tool-tray__slots { flex: 1 1 320px; }
.db-tray .ktp-pepper-art { width: 28px; height: 28px; }
.db-tray .db-art__fallback { --icon-size: 28px !important; color: var(--ktp-chili); }
.db-slot__name { max-width: 14ch; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.db-tray .tool-btn:disabled { opacity: .5; cursor: not-allowed; }
.db-tray .tool-btn--on-dark:disabled { opacity: .35; }
@media (max-width: 640px) { /* the frame makes the tray one compact row; the slot buttons remove, so Clear and empty slots go */
  .db-tray .tool-tray__slot--empty, .db-tray #btn-clear-compare { display: none; }
  .db-slot__name { max-width: 11ch; }
}

/* Side-by-side panel above the tray */
.db-tray { position: sticky; }
.db-compare { color: var(--ktp-ink); position: absolute; right: 0; bottom: 100%; left: 0; max-height: calc(100vh - var(--ktp-header-h, 72px) - 120px); padding-bottom: var(--ktp-space-3); overflow-y: auto; }
.db-compare[hidden] { display: none; }
.db-compare__card { box-shadow: 0 -12px 40px -16px rgba(42, 20, 16, .45); }
.db-compare__head { display: flex; align-items: flex-start; justify-content: space-between; gap: var(--ktp-space-4); margin-bottom: var(--ktp-space-4); }
.db-compare__cols { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: var(--ktp-space-4); }
.db-col { display: flex; flex-direction: column; align-items: flex-start; gap: var(--ktp-space-2); padding: var(--ktp-space-4); border: var(--ktp-line); border-radius: var(--ktp-radius-sm); }
.db-col .heat-range { align-self: stretch; margin-top: var(--ktp-space-2); }
.db-col__facts { align-self: stretch; margin: var(--ktp-space-2) 0 0; }
.db-col__facts > div { display: flex; justify-content: space-between; gap: var(--ktp-space-3); padding-block: 6px; border-top: 1px solid var(--ktp-hairline); font-size: 15px; }
.db-col__facts dt, .db-col__facts dd { font-size: 15px; line-height: 1.4; }
.db-col__facts dt { color: var(--ktp-muted); }
.db-col__facts dd { margin: 0; font-weight: 700; text-align: right; }
.db-compare__actions { margin-top: var(--ktp-space-4); }
@media (max-width: 760px) { .db-compare__cols { grid-template-columns: minmax(0, 1fr); } }

/* How to use this data: tips with a round icon tile (same tile as the conversion calculator) */
.db-tips > li { display: grid; grid-template-columns: 44px minmax(0, 1fr); grid-template-areas: "art title" "art text"; gap: var(--ktp-space-1) var(--ktp-space-4); align-items: start; }
.db-tip__art, .db-method__art { display: flex; flex: none; align-items: center; justify-content: center; width: 44px; height: 44px; border-radius: 50%; background: var(--ktp-smoke); color: var(--ktp-ink); }
.db-tip__art { grid-area: art; }
.db-tips h3 { grid-area: title; align-self: center; margin: 0; }
.db-tips p { grid-area: text; }

/* Sources & methodology: three kinds of source feed one SHU range, shown with a real profile on the log axis */
.db-method { display: flex; flex-direction: column; gap: var(--ktp-space-3); padding: var(--ktp-space-5); border: var(--ktp-line); border-radius: var(--ktp-radius); background: var(--ktp-white); }
.db-method__sources { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: var(--ktp-space-3); margin: 0; padding: 0; list-style: none; }
.db-method__sources li { display: flex; flex-direction: column; align-items: center; gap: var(--ktp-space-2); color: var(--ktp-ink); font-size: 15px; font-weight: 700; line-height: 1.3; text-align: center; }
.db-method__join { display: flex; justify-content: center; color: var(--ktp-muted); }
.db-method__result { display: grid; grid-template-columns: 56px minmax(0, 1fr) minmax(120px, 40%); align-items: center; gap: var(--ktp-space-4); padding: var(--ktp-space-3) var(--ktp-space-4); border-radius: var(--ktp-radius-sm); background: var(--ktp-smoke); }
.db-method__result .ktp-pepper-art { display: block; width: 56px; height: 56px; object-fit: contain; }
.db-method__text { min-width: 0; }
.db-method__name { display: block; color: var(--ktp-ink); font-family: var(--ktp-font-display); font-size: 1.15rem; font-weight: 800; line-height: 1.2; }
.db-method__shu { display: block; margin-top: 2px; color: var(--ktp-muted); font-size: 15px; line-height: 1.35; }
.db-method__result .heat-range { background: repeating-linear-gradient(90deg, transparent 0 calc(20% - 1px), var(--ktp-smoke) calc(20% - 1px) 20%), var(--ktp-clay); }
@media (max-width: 560px) {
  .db-method { padding: var(--ktp-space-4); }
  .db-method__sources li { font-size: 14px; }
  .db-method__result { grid-template-columns: 56px minmax(0, 1fr); }
  .db-method__result .heat-range { grid-column: 1 / -1; }
}

@media print {
  .db-filters, .db-tray, .db-more, .db-pick, .db-view, .tool-head__actions, .db-table th:last-child, .db-table td:last-child { display: none !important; }
  .db-card { break-inside: avoid; box-shadow: none; }
  .db-table-wrap { overflow: visible; }
}

/* card names reserve two lines, so the heat bar and origin line up across a row when one name wraps */
.db-card__name { min-height: 2.4em; }
