/* Bulk downloader (download.html). Every row is one fixed height, so nothing loading in ever moves the list. */
#dl-app { padding-bottom: 48px; }
.dl-btn { min-height: 36px; padding: 6px 12px; border: 1px solid var(--border); border-radius: 6px; background: var(--alt); color: var(--text); font: inherit; font-size: 14px; cursor: pointer; }
.dl-btn:disabled { opacity: .5; cursor: default; }
.dl-btn.btn-primary { border-color: transparent; font-weight: 600; }

#dl-bar { position: sticky; top: var(--site-header-height); z-index: 20; background: var(--bg); padding: 12px 0 8px; border-bottom: 1px solid var(--border); }
.dl-bar-row { display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between; gap: 8px 16px; }
.dl-pager, .dl-actions { display: flex; flex-wrap: wrap; align-items: center; gap: 8px; }
#dl-page-form { display: flex; align-items: center; gap: 6px; font-size: 14px; }
#dl-page { width: 72px; height: 36px; box-sizing: border-box; padding: 4px 6px; border: 1px solid var(--border); border-radius: 6px; background: var(--bg-input); color: var(--text); font: inherit; }
.dl-rule { margin: 8px 0 0; font-size: 13px; color: var(--muted); }
.dl-rule-static, .dl-tools-static { display: none; }
/* Fixed heights: the bar stays on screen, and any change in its height would move the whole list. */
#dl-count { margin: 4px 0 0; height: 18px; line-height: 18px; font-size: 13px; font-variant-numeric: tabular-nums; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
#dl-status { margin: 2px 0 0; height: 36px; line-height: 18px; font-size: 13px; color: var(--info); overflow: hidden; display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; }

#dl-newer { display: flex; flex-wrap: wrap; align-items: center; gap: 8px 12px; margin: 12px 0 0; padding: 8px 12px; border: 1px solid var(--border); border-radius: 6px; background: var(--surface); font-size: 13px; }
#dl-newer[hidden] { display: none; }

#dl-list { margin-top: 8px; }
#dl-list.dl-loading { opacity: .55; pointer-events: none; }
#dl-empty { margin: 32px 0; text-align: center; color: var(--muted); }

.dl-row { display: grid; grid-template-columns: 32px 320px minmax(0, 1fr); gap: 16px; height: 336px; padding: 8px 4px; box-sizing: border-box; border-bottom: 1px solid var(--border); cursor: pointer; }
.dl-row.dl-ticked { background: var(--bg-active); }
.dl-row.dl-unavailable { cursor: default; opacity: .6; }
.dl-tick { width: 22px; height: 22px; margin: 8px 0 0 4px; accent-color: var(--action); cursor: pointer; }
.dl-tick:disabled { cursor: default; }
.dl-thumb { display: grid; place-items: center; width: 320px; height: 320px; padding: 0; border: 0; border-radius: 6px; background: var(--bg-alt); overflow: hidden; cursor: zoom-in; }
.dl-thumb:disabled { cursor: default; }
.dl-thumb img { display: block; max-width: 100%; max-height: 100%; object-fit: contain; }
.dl-thumb-note { padding: 8px; font-size: 13px; color: var(--muted); text-align: center; }
.dl-info { display: flex; flex-direction: column; gap: 6px; min-width: 0; overflow: hidden; font-size: 14px; }
.dl-meta { display: flex; flex-wrap: wrap; gap: 2px 12px; font-size: 13px; color: var(--muted); }
.dl-meta strong { color: var(--text); }
.dl-done { color: var(--success); font-weight: 600; }
.dl-done[hidden] { display: none; }
.dl-prompt { margin: 0; line-height: 1.45; overflow-wrap: anywhere; display: -webkit-box; -webkit-line-clamp: 10; -webkit-box-orient: vertical; overflow: hidden; }
.dl-neg { margin: 0; font-size: 13px; line-height: 1.4; color: var(--muted); overflow-wrap: anywhere; display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; }
.dl-reason { margin: 0; font-size: 13px; color: var(--warning); }

.dl-pager-bottom { display: flex; align-items: center; justify-content: space-between; gap: 8px; margin-top: 16px; font-size: 14px; }

#dl-lightbox { width: min(1400px, 96vw); height: 94dvh; max-width: none; max-height: none; padding: 0; border: 1px solid var(--border); border-radius: 8px; background: var(--surface); color: var(--text); }
#dl-lightbox[open] { display: flex; flex-direction: column; }
#dl-lightbox::backdrop { background: #000c; }
.dl-lb-bar { display: flex; align-items: center; gap: 12px; padding: 8px 12px; border-bottom: 1px solid var(--border); }
.dl-lb-bar strong { flex: 1; text-align: center; }
.dl-lb-tick { display: flex; align-items: center; gap: 8px; font-size: 14px; cursor: pointer; }
.dl-lb-tick input { width: 20px; height: 20px; accent-color: var(--action); }
#dl-lb-close { width: 40px; font-size: 22px; line-height: 1; padding: 0; }
.dl-lb-body { flex: 1; min-height: 0; display: grid; grid-template-columns: minmax(0, 1fr) 340px; }
.dl-lb-media { display: grid; place-items: center; min-height: 0; background: var(--bg); overflow: hidden; }
.dl-lb-media img { display: block; width: 100%; height: 100%; object-fit: contain; grid-area: 1 / 1; }
.dl-lb-media .dl-thumb-note { grid-area: 1 / 1; }
.dl-lb-info { overflow: auto; padding: 12px; font-size: 13px; border-left: 1px solid var(--border); }
.dl-lb-info .detail-header-row { display: flex; align-items: center; gap: 8px; margin-bottom: 8px; }
.dl-lb-info .detail-source-badge { font-size: 11px; padding: 1px 6px; border: 1px solid var(--border); border-radius: 4px; color: var(--muted); }
.dl-lb-info .detail-row { margin-bottom: 6px; overflow-wrap: anywhere; }
.dl-lb-info .detail-label { display: block; font-size: 11px; color: var(--muted); }
.dl-lb-info .detail-prompt { white-space: pre-wrap; }

#dl-leave { width: min(480px, calc(100vw - 32px)); max-width: none; box-sizing: border-box; padding: 20px; border: 1px solid var(--border); border-radius: 8px; background: var(--surface); color: var(--text); }
#dl-leave::backdrop { background: #0008; }
#dl-leave h2 { margin: 0 0 8px; font-size: 18px; }
#dl-leave p { margin: 0 0 16px; font-size: 14px; line-height: 1.45; }
.dl-leave-actions { display: flex; flex-direction: column; gap: 8px; }

@media (max-width: 760px) {
    /* The bar that stays on screen is one row: the pages and Download. Ticking all, the count and the rule sit
       above the list and scroll away; a message shows as a notice over the foot of the screen, there only while
       it has something to say and out of the page's flow, so it never moves the list. */
    #dl-app { padding-bottom: 124px; }   /* (room for the notice at its tallest, four lines: the bottom pager stays clear) */
    #dl-bar { padding: 8px 0; }
    .dl-bar-row { gap: 6px 8px; }
    .dl-pager { gap: 6px; }
    .dl-long, .dl-wide-only, #dl-count, .dl-rule-sticky { display: none; }
    #dl-page { width: 56px; }
    .dl-btn { min-height: 36px; padding: 4px 10px; }
    .dl-tools-static { display: flex; flex-wrap: wrap; align-items: center; gap: 8px; margin: 10px 0 0; font-size: 13px; font-variant-numeric: tabular-nums; }
    /* (a line of its own, one line high, at every width: a count growing a digit never wraps it and moves the list) */
    #dl-count-narrow { flex-basis: 100%; height: 18px; line-height: 18px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
    .dl-rule-static { display: block; }
    /* (four lines at most, the longest message whole at 320 px; a tap closes it, its ✕ says so) */
    #dl-status { position: fixed; left: 12px; right: 12px; bottom: 12px; z-index: 40; height: auto; max-height: 72px; margin: 0;
                 padding: 10px 36px 10px 12px; box-sizing: content-box; display: -webkit-box; -webkit-line-clamp: 4; overflow: hidden;
                 background: var(--surface); color: var(--text); border: 1px solid var(--border); border-radius: 8px; box-shadow: var(--shadow);
                 cursor: pointer; }
    #dl-status::after { content: "✕"; position: absolute; top: 9px; right: 12px; color: var(--muted); }
    #dl-status:empty { display: none; }
    .dl-row { grid-template-columns: 28px 45vw minmax(0, 1fr); gap: 10px; height: calc(45vw + 16px); }
    .dl-thumb { width: 45vw; height: 45vw; }
    .dl-info { font-size: 13px; gap: 4px; }
    .dl-meta { font-size: 12px; }
    .dl-prompt { -webkit-line-clamp: 5; }
    .dl-neg { -webkit-line-clamp: 1; }
    .dl-lb-body { grid-template-columns: 1fr; grid-template-rows: minmax(0, 1fr) auto; }
    .dl-lb-info { max-height: 38dvh; border-left: 0; border-top: 1px solid var(--border); }
    #dl-lightbox { width: 100vw; height: 100dvh; border-radius: 0; border: 0; }
}

/* Narrow phones: the picture goes on top, full width, the details under it. */
@media (max-width: 420px) {
    /* (the details' room: three lines of facts on the narrowest phone, four of prompt, one of negative) */
    .dl-row { grid-template-columns: 28px minmax(0, 1fr); grid-template-rows: calc(100vw - 70px) 180px; height: calc(100vw + 136px); }
    .dl-thumb { grid-column: 2; grid-row: 1; width: 100%; height: 100%; }
    .dl-info { grid-column: 1 / -1; grid-row: 2; }
    .dl-prompt { -webkit-line-clamp: 4; }
    .dl-actions .dl-btn, .dl-pager .dl-btn { padding: 4px 8px; }
}

/* The narrowest phones (320 px): the bar's one row, a little tighter. */
@media (max-width: 340px) {
    .dl-bar-row, .dl-pager { gap: 4px; }
    #dl-page { width: 48px; }
    #dl-page-form { gap: 4px; }
    #dl-download { font-size: 13px; padding: 4px 6px; }
}
