/*
 * Batch upload (backend/docs/BATCH_UPLOAD.md): the dashboard's upload form for one PDF or many (the
 * multi-file uploader; js/app/batch-upload.js), the batch list (batches.html) and the batch page
 * (batch.html). Loaded after style.css, app.css and app-pdfs.css (the uploader and the tables
 * reuse their classes); only batch-specific rules, colours only through tokens.
 *
 *   1. Multi-file uploader (file list, per-file state, summary)
 *   2. Batch list and pager
 *   3. Batch page (progress, counts, results, filter)
 *   4. Running batches on the PDFs page (js/app/batch-active.js)
 *
 * States never rely on colour alone: every file row says its state in text, problem rows also
 * get a thick left bar and an "Error:" prefixed message, progress has its value in text.
 */

/* Elements switched with the hidden attribute (.button sets display, which would win). */
.pdfs-active-batches[hidden],
.batch-uploader [hidden],
.batch-detail [hidden],
.batch-pager[hidden],
.batch-card[hidden] {
  display: none;
}

/* ---------- 1. Multi-file uploader ---------- */
.batch-name-field {
  max-width: 32rem;
}

.batch-name-error:empty,
.batch-limit-error:empty {
  display: none;
}

.batch-selection-heading {
  margin: 0;
  font-weight: 700;
}

.batch-totals {
  margin: 0.25rem 0 0.5rem;
}

.batch-selection-actions {
  margin: 0.5rem 0;
}

/* One page of rows at a time (batch-upload.js listView), so no inner scroll area is needed. */
.batch-file-list {
  margin: 0;
  padding: 0;
  list-style: none;
  border: 1px solid var(--color-border-strong);
  border-radius: var(--radius-sm);
}

.batch-file {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 0.125rem 1rem;
  padding: 0.5rem 0.75rem;
  border-top: 1px solid var(--color-border);
  border-left: 4px solid transparent;
}

.batch-file:first-child {
  border-top: 0;
}

.batch-file > * {
  grid-column: 1;
  margin: 0;
}

.batch-file > .batch-file-remove {
  grid-column: 2;
  grid-row: 1 / span 3;
  align-self: center;
}

.batch-file-name {
  font-weight: 700;
  overflow-wrap: anywhere;
}

/* The automatic contrast pre-check (js/app/batch-upload.js, unified form): per file its finding (amber icon +
   "Kontrastprobleme" + chevron that expands the row with the affected pages, then an information icon whose
   explanation floats below; grey icon + "Kontraste nicht prüfbar") before the remove button; no background. */
.batch-file-contrast {
  position: relative;
  display: inline-flex;
  align-items: center;
  gap: 0.375rem;
  font-size: var(--text-sm);
  font-weight: 600;
  line-height: 1.3;
  white-space: nowrap;
}

/* The amber warning is a button that looks like the label, a chevron after it (up while expanded); it expands only its
   own row: the affected pages on a full-width line below the file's details, after a thin divider. */
.batch-file-contrast-button {
  display: inline-flex;
  align-items: center;
  gap: inherit;
  margin: 0;
  padding: 0;
  border: 0;
  border-radius: 0.25rem;
  background: none;
  color: inherit;
  font: inherit;
  line-height: inherit;
  text-align: inherit;
  cursor: pointer;
}

.batch-file-contrast-button:focus-visible {
  outline: 3px solid var(--color-focus);
  outline-offset: 2px;
}

.batch-file-contrast-chevron {
  flex: none;
  width: 1rem;
  height: 1rem;
  fill: none;
  stroke: currentColor;
  stroke-width: 2.2;
  stroke-linecap: round;
  stroke-linejoin: round;
}

.batch-file-contrast-button[aria-expanded="true"] .batch-file-contrast-chevron {
  transform: rotate(180deg);
}

.batch-file > .batch-file-contrast-pages {
  grid-column: 1 / -1;
  margin-top: 0.375rem;
  padding-top: 0.375rem;
  border-top: 1px solid var(--color-border);
  color: var(--color-text);
  font-size: var(--text-sm);
}

/* The information icon after the warning: quiet grey, a 1.5rem target that takes no more line height than the label.
   Its explanation floats below the warning (absolute: the row and the list keep their size), right-aligned to it,
   left-aligned in a narrow list; hidden until the icon is pressed. */
.batch-file-contrast-info {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 1.5rem;
  height: 1.5rem;
  margin: -0.25rem 0;
  padding: 0;
  border: 0;
  border-radius: 50%;
  background: none;
  color: var(--color-text-muted);
  cursor: pointer;
}

.batch-file-contrast-info:hover,
.batch-file-contrast-info[aria-expanded="true"] {
  color: var(--color-text);
}

.batch-file-contrast-info:focus-visible {
  outline: 3px solid var(--color-focus);
  outline-offset: 0;
}

.batch-file-contrast-info-icon {
  width: 1rem;
  height: 1rem;
  fill: none;
  stroke: currentColor;
  stroke-width: 2;
  stroke-linecap: round;
  stroke-linejoin: round;
}

.batch-file-contrast-help {
  position: absolute;
  top: calc(100% + 0.375rem);
  right: 0;
  z-index: 20;
  width: max-content;
  max-width: min(24rem, calc(100cqi - 1.5rem));
  padding: 0.5rem 0.75rem;
  border: 1px solid var(--color-border-strong);
  border-radius: var(--radius-sm);
  background: var(--color-bg);
  box-shadow: var(--shadow-float);
  color: var(--color-text);
  font-weight: 400;
  line-height: 1.45;
  white-space: normal;
  text-align: left;
}

.batch-file-contrast-help > span {
  display: block;
}

.batch-file-contrast-help > span + span {
  margin-top: 0.5rem;
}

/* The finding stands right of the file, just before the remove button: a third column only while one is shown. */
.batch-file:has(> .batch-file-contrast:not([hidden])) {
  grid-template-columns: minmax(0, 1fr) auto auto;
}

.batch-file > .batch-file-contrast {
  grid-column: 2;
  grid-row: 1 / span 3;
  align-self: center;
}

.batch-file:has(> .batch-file-contrast:not([hidden])) > .batch-file-remove {
  grid-column: 3;
}

/* Amber icon (--color-warning-icon 5.0:1) and dark amber text (--color-warning 7.1:1) on the row's white. */
.batch-file-contrast--issues {
  color: var(--color-warning);
}

.batch-file-contrast--issues .batch-file-contrast-icon {
  color: var(--color-warning-icon);
}

.batch-file-contrast--unknown {
  color: var(--color-text-muted);
}

.batch-file-contrast-icon {
  flex: none;
  width: 1.125rem;
  height: 1.125rem;
  fill: none;
  stroke: currentColor;
  stroke-width: 2.2;
  stroke-linecap: round;
  stroke-linejoin: round;
}

/* A narrow list (phones): the finding goes below the file's name and state across the row (its label and chevron stay
   on one line), the remove button stays on the right beside the name and state. */
.batch-file-list {
  container-type: inline-size;
}

@container (max-width: 40rem) {
  .batch-file:has(> .batch-file-contrast:not([hidden])) {
    grid-template-columns: minmax(0, 1fr) auto;
  }

  .batch-file > .batch-file-contrast {
    grid-column: 1 / -1;
    grid-row: auto;
    justify-self: start;
    white-space: normal;
  }

  .batch-file:has(> .batch-file-contrast:not([hidden])) > .batch-file-remove {
    grid-column: 2;
    grid-row: 1 / span 2;
  }

  .batch-file-contrast-help {
    right: auto;
    left: 0;
  }
}

/* The unified form's convert button: the dominant action across the whole upload section (label and the
   enabled/disabled states as before). */
.batch-uploader--unified .uploader-actions .uploader-submit {
  width: 100%;
  min-height: 3.5rem;
  padding-top: 0.875rem;
  padding-bottom: 0.875rem;
}

.batch-file-size,
.batch-file-note {
  color: var(--color-text-muted);
  font-size: var(--text-sm);
}

.batch-file-size {
  white-space: nowrap;
}

.batch-file-state {
  font-size: var(--text-sm);
  font-weight: 600;
}

.batch-file--active .batch-file-state {
  color: var(--color-primary-dark);
}

.batch-file--done {
  border-left-color: var(--color-primary-dark);
}

.batch-file--problem {
  border-left-width: 6px;
  border-left-color: var(--color-error);
}

.batch-file-error {
  font-size: var(--text-sm);
}

.batch-progress-detail {
  flex-basis: 100%;
  margin: 0;
  color: var(--color-text-muted);
  font-size: var(--text-sm);
}

.batch-summary {
  margin-bottom: 0;
}

.batch-summary > * + * {
  margin-top: 0.5rem;
}

.batch-summary-title {
  margin: 0;
  font-size: var(--text-lg);
}

.batch-summary-title:focus {
  outline: none;
}

.batch-summary-title:focus-visible {
  outline: 3px solid var(--color-focus);
  outline-offset: 3px;
}

.batch-summary-subtitle {
  font-weight: 700;
}

.batch-summary-list {
  max-height: 16rem;
  margin: 0;
  padding-left: 1.25rem;
  overflow-y: auto;
  overflow-wrap: anywhere;
}

.batch-summary-actions {
  margin-top: 0.75rem;
}

/* Unified upload form: the compact result row under the progress bar (status left, batch link right). */
.batch-upload-done {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 0.75rem 1rem;
}

.batch-upload-done-status {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  min-width: 0;
}

.batch-done-icon {
  flex: none;
  width: 1.5rem;
  height: 1.5rem;
  fill: none;
  stroke: var(--color-primary-dark);
  stroke-width: 2;
  stroke-linecap: round;
  stroke-linejoin: round;
}

.app-notice--error .batch-done-icon {
  stroke: var(--color-error);
}

.app-notice--warning .batch-done-icon {
  stroke: var(--color-text);
}

.batch-summary--compact .batch-summary-title {
  font-size: var(--text-base);
}

@media (max-width: 30rem) {
  .batch-upload-open {
    width: 100%;
    text-align: center;
  }
}

/* "Choose files" and "Choose a folder" side by side; each native input stays directly before its
   label (app-pdfs.css draws the input's focus ring on the following label). */
.batch-choose-row {
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  gap: 0.5rem 0.75rem;
}

.batch-folder-note {
  margin: 0.75rem 0 0;
}

/* The file list shows one page of rows; a checkbox narrows it to files with problems or notes. */
.batch-list-filter {
  display: inline-flex;
  align-items: center;
  gap: 0.5rem;
  min-height: 2.75rem;
  font-weight: 600;
  cursor: pointer;
}

.batch-list-filter input {
  width: 1.125rem;
  height: 1.125rem;
  margin: 0;
  accent-color: var(--color-primary-dark);
}

.batch-list-meta {
  margin: 0.25rem 0 0.5rem;
  color: var(--color-text-muted);
  font-size: var(--text-sm);
}

.batch-list-meta:empty {
  display: none;
}

.batch-list-pager {
  margin-top: 0.5rem;
}

/* ---------- 2. Batch list and pager ---------- */
.batches-new {
  margin: 0 0 1rem;
}

.batch-progress-inline {
  display: inline-flex;
  align-items: center;
  gap: 0.5rem;
  min-width: 8rem;
}

.batch-progress-inline progress {
  flex: 1 1 6rem;
  min-width: 4rem;
  height: 0.625rem;
  accent-color: var(--color-primary-dark);
}

.batch-progress-percent {
  font-variant-numeric: tabular-nums;
  white-space: nowrap;
}

/* "n with problems": outlined text next to the state badge (#B91C1C on white 6.5:1). */
.batch-problem-badge {
  display: inline-block;
  margin-top: 0.25rem;
  padding: 0 0.5rem;
  border: 1px dashed var(--color-error);
  border-radius: 999px;
  color: var(--color-error);
  font-size: var(--text-sm);
  font-weight: 700;
  white-space: nowrap;
}

.batch-pager {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 0.5rem 1rem;
  margin-top: 1rem;
}

.batch-pager-status {
  margin: 0;
  color: var(--color-text-muted);
  font-size: var(--text-sm);
}

/* ---------- 3. Batch page ---------- */
.batch-card h2 {
  margin: 0 0 0.75rem;
}

.batch-card h2:focus {
  outline: none;
}

.batch-card h2:focus-visible {
  outline: 3px solid var(--color-focus);
  outline-offset: 3px;
}

.batch-progress {
  display: grid;
  gap: 0.375rem;
  margin-bottom: 1rem;
}

.batch-progress-label {
  font-weight: 600;
}

.batch-progress progress {
  width: 100%;
  height: 0.875rem;
  accent-color: var(--color-primary-dark);
}

.batch-counts-title {
  margin: 1.25rem 0 0.5rem;
  font-size: var(--text-base);
}

.batch-counts {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(10rem, 1fr));
  gap: 0.5rem;
  margin: 0;
}

.batch-count {
  padding: 0.5rem 0.75rem;
  border: 1px solid var(--color-border-strong);
  border-radius: var(--radius-sm);
}

.batch-count dt {
  color: var(--color-text-muted);
  font-size: var(--text-sm);
}

.batch-count dd {
  margin: 0;
  font-size: var(--text-lg);
  font-weight: 700;
  font-variant-numeric: tabular-nums;
}

.batch-count--failed,
.batch-count--rejected {
  border-left: 4px solid var(--color-error);
}

.batch-archive {
  margin-bottom: 0.5rem;
}

/* Inline result of the ZIP preflight (batch.js); never colour alone: the text says what happened. */
.batch-archive-status {
  max-width: 48rem;
  margin: 0 0 0.5rem;
  font-weight: 600;
}

.batch-archive-status:empty {
  display: none;
}

.batch-archive-status[data-tone="error"] {
  color: var(--color-error);
}

.batch-archive-link[aria-disabled="true"] {
  opacity: 0.6;
  cursor: progress;
}

.batch-manage-title {
  margin: 1.25rem 0 0.5rem;
  font-size: var(--text-base);
}

.batch-item-position {
  color: var(--color-text-muted);
  font-size: var(--text-sm);
  font-weight: 400;
  white-space: nowrap;
}

.batch-items-table .jobs-cell--size {
  white-space: nowrap;
}

.batch-item-note {
  font-size: var(--text-sm);
  overflow-wrap: anywhere;
}

/* Four filters: two rows of two on narrow screens. */
@media (max-width: 47.99rem) {
  .segmented.batch-filter {
    grid-template-columns: repeat(2, minmax(0, 1fr));
    border-radius: var(--radius-sm);
  }
}

/* ---------- 4. Running batches (PDFs page) ---------- */
.active-batch-list {
  display: grid;
  gap: 0.75rem;
  margin: 0;
  padding: 0;
  list-style: none;
}

.active-batch {
  display: grid;
  gap: 0.375rem;
  padding: 0.75rem 1rem;
  border: 1px solid var(--color-border-strong);
  border-radius: var(--radius-sm);
}

.active-batch > * {
  margin: 0;
}

.active-batch-head {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 0.25rem 0.75rem;
}

.active-batch-name {
  font-weight: 700;
  overflow-wrap: anywhere;
}

.active-batch-owner,
.active-batch-counts,
.active-batch-note {
  color: var(--color-text-muted);
  font-size: var(--text-sm);
}

.active-batch-progress {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 0.25rem 0.75rem;
}

.active-batch-progress progress {
  flex: 1 1 12rem;
  min-width: 0;
  height: 0.75rem;
  accent-color: var(--color-primary-dark);
}

.active-batch-progress-text {
  font-variant-numeric: tabular-nums;
}

.active-batch-footer {
  margin: 0.75rem 0 0;
}

@media (forced-colors: active) {
  .batch-file--problem,
  .batch-count--failed,
  .batch-count--rejected {
    border-left-color: CanvasText;
  }
}

/* The ZIP link is an inline-flex .button: a leading space inside its count span would collapse. */
.batch-archive-count {
  margin-inline-start: 0.35em;
}
