/* QCoda UI density (D-NEW-ui-nowrap).
   Loaded after Bootstrap and DataTables so these rules win.
   QA viewports: 1280, 1512, 1728 CSS pixels.
   Text columns (.qc-grow) share leftover width and grow or shrink with the
   table. Utility columns keep a rem width. .qc-pri-2 is hidden below 1512.
   .qc-pri-3 is hidden below 1728. Both th and td need the priority class. */

table.qc-fit {
  table-layout: fixed;
  width: 100% !important;
  max-width: 100% !important;
}

table.qc-fit th,
table.qc-fit td {
  box-sizing: border-box;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  vertical-align: middle;
  max-width: 0;
}

table.qc-fit .qc-grow { width: auto; }

table.qc-fit .qc-col-xs { width: 4.5rem; }
table.qc-fit .qc-col-s { width: 6.5rem; }
table.qc-fit .qc-col-m { width: 9rem; }
table.qc-fit .qc-col-l { width: 12rem; }

table.qc-fit .qc-actions {
  width: 5.75rem;
  max-width: none;
  overflow: visible;
  text-overflow: clip;
  text-align: right;
}

/* Model Ladders (D-NEW-ladders-table-layout).
   The shared rule sets max-width: 0 on every cell, so Name, Status, and
   Scope collapse to about the sort-icon padding. Each of those columns
   has a min-width. The @name grows with the longest name. Description
   (and Models, when that column is shown) keeps max-width: 0 and
   ellipsizes first. */
table.qc-fit.qc-ladders {
  table-layout: auto !important;
}

table.qc-fit.qc-ladders .qc-ladder-name {
  width: max-content;
  min-width: max(14rem, max-content) !important;
  max-width: none !important;
  overflow: visible;
  text-overflow: clip;
  white-space: nowrap;
}

table.qc-fit.qc-ladders .qc-ladder-status {
  width: max-content;
  min-width: max(7.5rem, max-content) !important;
  max-width: none !important;
  overflow: visible;
  text-overflow: clip;
  white-space: nowrap;
}

table.qc-fit.qc-ladders .qc-ladder-desc,
table.qc-fit.qc-ladders .qc-pri-2.qc-grow {
  width: 50%;
  max-width: 0;
}

table.qc-fit.qc-ladders .qc-pri-3 {
  width: 9rem;
  min-width: 9rem !important;
  max-width: 9rem;
}

/* Admin projects (D-NEW-admin-projects-table).
   Same min-width pattern as ladders: Name and Created size to their text.
   Organization and Repository ellipsize, and they hide first when the
   card is the 1024px shell (~770px). Owner still hides below the wide shell. */
table.qc-fit.qc-projects,
table.qc-fit.qc-projects.dataTable {
  table-layout: auto !important;
}

table.qc-fit.qc-projects .qc-project-name,
table.qc-fit.qc-projects .qc-project-when,
table.qc-fit.qc-projects .qc-actions {
  width: max-content;
  max-width: none !important;
  overflow: visible;
  text-overflow: clip;
  white-space: nowrap;
}

table.qc-fit.qc-projects .qc-project-name {
  min-width: max(14rem, max-content) !important;
}

table.qc-fit.qc-projects .qc-project-when {
  min-width: max(6.5rem, max-content) !important;
}

table.qc-fit.qc-projects .qc-actions {
  min-width: 4.75rem !important;
  text-align: right;
}

table.qc-fit.qc-projects .qc-project-org,
table.qc-fit.qc-projects .qc-project-repo,
table.qc-fit.qc-projects .qc-show-lg {
  width: 18%;
  max-width: 0;
}

@container qcfit (max-width: 899px) {
  table.qc-fit.qc-projects .qc-project-org,
  table.qc-fit.qc-projects .qc-project-repo {
    display: none !important;
  }
}

/* Reconciliation (D-NEW-reconciliation-ui, D-NEW-reconciliation-fit).
   Fixed layout, no horizontal scroll at 1024, 1280, 1512, and 1728.
   Work Item takes the leftover width and wraps instead of clipping: it is
   the primary id and is never truncated. Recommendation yields first: a
   single-line ellipsis with the full text in the title tooltip (its header
   may ellipsize too in the 1024 shell; the th carries a title).
   Kind, Evidence, Decision, Decided by, and When keep rem widths. Evidence is
   a PR badge plus commit and ledger icon links. Decided by is the handle;
   the full address is the tooltip. Below 1024 Kind, Evidence, and When hide
   (th and td both carry the class), so the table collapses instead of
   scrolling. */
.qc-fit-wrap { container-type: inline-size; container-name: qcfit; width: 100%; }

table.qc-fit.qc-recon,
table.qc-fit.qc-recon.dataTable {
  table-layout: fixed !important;
  width: 100% !important;
  min-width: 0 !important;
  max-width: 100% !important;
}

/* DataTables sets content-box on cells, so the shared max-width: 0 would
   collapse every rem column to its padding. Fixed layout already bounds them. */
table.qc-fit.qc-recon th,
table.qc-fit.qc-recon td {
  box-sizing: border-box !important;
  max-width: none;
}

table.qc-fit.qc-recon .qc-recon-item { width: auto; }
table.qc-fit.qc-recon .qc-recon-kind { width: 4.75rem; }
table.qc-fit.qc-recon .qc-recon-reco { width: 9.5rem; }
table.qc-fit.qc-recon .qc-recon-ev { width: 6rem; }
/* Decision is a single badge, or Mark ACCEPTED over Dismiss on open rows. */
table.qc-fit.qc-recon .qc-recon-decision { width: 7.25rem; }
table.qc-fit.qc-recon .qc-recon-who { width: 7rem; }
table.qc-fit.qc-recon .qc-recon-when { width: 4.5rem; }

@container qcfit (min-width: 1000px) {
  table.qc-fit.qc-recon .qc-recon-reco { width: 22%; }
  table.qc-fit.qc-recon .qc-recon-who { width: 8rem; }
}

@container qcfit (min-width: 1300px) {
  table.qc-fit.qc-recon .qc-recon-reco { width: 30%; }
}

table.qc-fit.qc-recon td.qc-recon-item {
  white-space: normal;
  overflow: visible;
  text-overflow: clip;
}

table.qc-fit.qc-recon .qc-recon-title-row {
  display: flex;
  align-items: center;
  gap: 0.25rem;
  min-width: 0;
}

table.qc-fit.qc-recon .qc-recon-title {
  flex: 0 1 auto;
  min-width: 0;
  display: block;
  white-space: normal;
  overflow: visible;
  text-overflow: clip;
  overflow-wrap: anywhere;
}

table.qc-fit.qc-recon .qc-recon-title-row .qc-icon-btn { flex: 0 0 auto; }

table.qc-fit.qc-recon .qc-recon-decision,
table.qc-fit.qc-recon .qc-recon-ev { text-overflow: clip; }

table.qc-fit.qc-recon .qc-recon-ev-links {
  display: inline-flex;
  align-items: center;
  gap: 0.25rem;
}

table.qc-fit.qc-recon .qc-recon-ev-links .qc-icon-btn {
  width: 1.25rem;
  height: 1.25rem;
}

table.qc-fit.qc-recon .qc-recon-act {
  padding: 0.0625rem 0.3125rem;
  font-size: 0.75rem;
}

table.qc-fit.qc-recon .qc-recon-acts {
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  gap: 0.25rem;
}

/* Recommendation header: "Rec." (with the full word as the title) when the
   card is under 1000px, i.e. below the 1280 shell. */
table.qc-fit.qc-recon .qc-label-short { display: none; }

@container qcfit (max-width: 999.98px) {
  table.qc-fit.qc-recon .qc-label-full { display: none; }
  table.qc-fit.qc-recon .qc-label-short { display: inline; }
}

table.qc-fit.qc-recon .qc-recon-who-text { display: block; }

@media (max-width: 1023.98px) {
  table.qc-fit.qc-recon .qc-recon-kind,
  table.qc-fit.qc-recon .qc-recon-ev,
  table.qc-fit.qc-recon .qc-recon-when { display: none !important; }
}

@media (max-width: 575.98px) {
  table.qc-fit.qc-recon .qc-recon-who { display: none !important; }
}

/* DataTables Bootstrap 5 wraps the controls, the table, and the pager in
   Bootstrap .row elements. Their -0.75rem gutters stick out 12px past the
   wrapper on both sides, so the wrapper scrolls. Inside .qc-fit-wrap the rows
   lose the negative margin and the table row loses the column padding, so the
   table sits flush and the controls keep a 0.75rem inset. */
.qc-fit-wrap .dataTables_wrapper > .row {
  margin-left: 0;
  margin-right: 0;
}

.qc-fit-wrap .dataTables_wrapper > .row.dt-row > [class*="col-"] {
  padding-left: 0;
  padding-right: 0;
}

/* Executions (D-NEW-executions-fit).
   Same shell as Reconciliation: fixed layout, zero DataTables gutter via
   .qc-fit-wrap, no horizontal scroll at 900, 1024, 1280, 1512, and 1728.
   Work Item keeps the leftover width on one line (ellipsis, full title on
   hover) so the name stays readable. Run id and model ellipsize; the icon
   copies the full value. Concern and confidence are one C/Q cell.
   When and Elapsed hide below 1024px (qc-exec-sec). Rating and Tokens
   hide below 1280px (qc-exec-wide): at the 1024 shell the table is about
   805px, and those two columns plus a readable work-item title do not fit.
   th and td both carry the class.
   Agent fits ENRICHMENT (widest pipeline stage at 16px). Every status
   badge is one line; WAITING_CAPACITY reads "Waiting" and the tooltip is
   the stored status (D-NEW-executions-polish-3). The run column stays at
   least 6.5rem so the id text is at least 70px beside the copy icon.
   From 1512px the run column grows to a 22-character id plus the copy
   icon. The model column stays 5.5rem (88px) and is capped at 140px.
   Work Item is width:auto, so it takes the spare width the model column
   used to absorb on wide shells
   (D-NEW-executions-clip, D-NEW-executions-polish-3, D-NEW-executions-title). */
table.qc-fit.qc-exec,
table.qc-fit.qc-exec.dataTable {
  table-layout: fixed !important;
  width: 100% !important;
  min-width: 0 !important;
  max-width: 100% !important;
}

table.qc-fit.qc-exec th,
table.qc-fit.qc-exec td {
  box-sizing: border-box !important;
  max-width: none;
}

table.qc-fit.qc-exec .qc-exec-item { width: auto; }
table.qc-fit.qc-exec .qc-exec-agent { width: 7.25rem; }
table.qc-fit.qc-exec .qc-exec-run { width: 6.5rem; min-width: 6.5rem; }
table.qc-fit.qc-exec .qc-exec-model {
  width: 5.5rem;
  min-width: 5.5rem;
  max-width: 140px;
}
table.qc-fit.qc-exec .qc-exec-status { width: 6.25rem; }
table.qc-fit.qc-exec .qc-exec-when { width: 4.625rem; }
table.qc-fit.qc-exec .qc-exec-elapsed { width: 5.625rem; }
table.qc-fit.qc-exec .qc-exec-scores { width: 4.25rem; }
table.qc-fit.qc-exec .qc-exec-rating { width: 5.75rem; }
table.qc-fit.qc-exec .qc-exec-tokens { width: 6rem; }
table.qc-fit.qc-exec .qc-exec-log { width: 2.75rem; text-align: right; }

table.qc-fit.qc-exec td.qc-exec-status,
table.qc-fit.qc-exec .qc-exec-status-badge {
  white-space: nowrap;
  line-height: 1.15;
  vertical-align: middle;
}

@media (min-width: 1512px) {
  table.qc-fit.qc-exec .qc-exec-run {
    width: clamp(15.5rem, calc(22ch + 4.25rem), 20rem);
  }
}

table.qc-fit.qc-exec .qc-exec-title {
  display: block;
  max-width: 100%;
}

table.qc-fit.qc-exec .qc-exec-agent-name,
table.qc-fit.qc-exec .qc-exec-scoreline,
table.qc-fit.qc-exec .qc-exec-elapsed-val {
  display: block;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  max-width: 100%;
}

table.qc-fit.qc-exec .qc-exec-id-row {
  display: flex;
  align-items: center;
  gap: 0.15rem;
  min-width: 0;
  max-width: 100%;
}

table.qc-fit.qc-exec .qc-exec-id-row > .qc-clip {
  flex: 1 1 auto;
  min-width: 0;
  width: auto;
}

table.qc-fit.qc-exec .qc-exec-id-row > .qc-icon-btn {
  flex: 0 0 auto;
  width: 1.25rem;
  height: 1.25rem;
}

table.qc-fit.qc-exec .qc-exec-scoreline {
  font-size: 0.75rem;
  letter-spacing: -0.02em;
}

@media (max-width: 1279.98px) {
  table.qc-fit.qc-exec .qc-exec-wide { display: none !important; }
}

@media (max-width: 1023.98px) {
  table.qc-fit.qc-exec .qc-exec-sec { display: none !important; }
}

/* Job Queue (D-NEW-job-queue-view).
   Same approach as Reconciliation: fixed layout, rem widths, no horizontal
   scroll at 1024, 1280, 1512, and 1728. Status is a full-word badge, Task is
   the full task name, Item is the work item title (linked) or the raw id.
   Error takes the leftover width as one line with an ellipsis; the full text
   is the tooltip and the modal. FAILED rows carry an inline Requeue button.
   The wrap is a size container, so columns collapse on the card width:
   under 900px (the 1024 shell) Tries, Duration, and Created hide; under
   760px (below 1024) Updated hides too; Created shows from 1200px (the 1512
   shell). */
table.qc-fit.qc-jq,
table.qc-fit.qc-jq.dataTable {
  table-layout: fixed !important;
  width: 100% !important;
  min-width: 0 !important;
  max-width: 100% !important;
}

table.qc-fit.qc-jq th,
table.qc-fit.qc-jq td {
  box-sizing: border-box !important;
  max-width: none;
}

table.qc-fit.qc-jq .qc-jq-status { width: 5.75rem; }
table.qc-fit.qc-jq .qc-jq-task { width: 12.5rem; }
table.qc-fit.qc-jq .qc-jq-item { width: 10rem; }
table.qc-fit.qc-jq .qc-jq-tries { width: 3.75rem; }
table.qc-fit.qc-jq .qc-jq-dur { width: 5.5rem; }
table.qc-fit.qc-jq .qc-jq-created,
table.qc-fit.qc-jq .qc-jq-updated { width: 6rem; }
table.qc-fit.qc-jq .qc-jq-error { width: auto; }

table.qc-fit.qc-jq .qc-jq-actions {
  width: 8.25rem;
  overflow: visible;
  text-overflow: clip;
  text-align: right;
}

table.qc-fit.qc-jq .qc-jq-acts {
  display: inline-flex;
  align-items: center;
  justify-content: flex-end;
  gap: 0.125rem;
}

table.qc-fit.qc-jq .qc-jq-requeue {
  padding: 0.0625rem 0.375rem;
  font-size: 0.75rem;
  white-space: nowrap;
}

table.qc-fit.qc-jq .qc-jq-item-row {
  display: flex;
  align-items: center;
  gap: 0.25rem;
  min-width: 0;
}

table.qc-fit.qc-jq .qc-jq-item-row > .qc-clip { flex: 0 1 auto; }
table.qc-fit.qc-jq .qc-jq-item-row > .qc-icon-btn { flex: 0 0 auto; }

table.qc-fit.qc-jq .qc-jq-error-text {
  font-size: inherit;
  line-height: inherit;
  width: 100%;
  border: 0;
}

.qc-jq-failed-card { cursor: pointer; }

@container qcfit (max-width: 899.98px) {
  table.qc-fit.qc-jq .qc-jq-tries,
  table.qc-fit.qc-jq .qc-jq-dur,
  table.qc-fit.qc-jq .qc-jq-created { display: none !important; }
}

@container qcfit (max-width: 759.98px) {
  table.qc-fit.qc-jq .qc-jq-updated { display: none !important; }
}

@container qcfit (min-width: 900px) {
  table.qc-fit.qc-jq .qc-jq-item { width: 12rem; }
}

@container qcfit (max-width: 1199.98px) {
  table.qc-fit.qc-jq .qc-jq-created { display: none !important; }
}

@container qcfit (min-width: 1350px) {
  table.qc-fit.qc-jq .qc-jq-item { width: 16rem; }
}

table.qc-fit td[colspan] {
  max-width: none;
  overflow: visible;
  text-overflow: clip;
  white-space: normal;
}

table.qc-fit .d-flex > .qc-clip {
  flex: 1 1 auto;
}

@media (max-width: 1727.98px) {
  table.qc-fit .qc-pri-3 { display: none !important; }
}

@media (max-width: 1511.98px) {
  table.qc-fit .qc-pri-2,
  table.qc-fit .qc-pri-3 { display: none !important; }
}

.qc-clip,
.qc-stamp {
  display: block;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  max-width: 100%;
  min-width: 0;
}

.qc-error-expand summary { cursor: pointer; list-style-position: inside; }
.qc-error-full {
  white-space: pre-wrap;
  word-break: break-word;
  max-height: 16rem;
  overflow: auto;
  font-size: 0.75rem;
  margin-top: 0.25rem;
}

.qc-min { min-width: 0; }

.qc-icon-btn {
  line-height: 1;
  width: 1.75rem;
  height: 1.75rem;
  padding: 0;
  color: #495057;
  text-decoration: none;
  vertical-align: middle;
  display: inline-flex;
  align-items: center;
  justify-content: center;
}

.qc-icon-btn:hover,
.qc-icon-btn:focus-visible { color: #212529; }

.qc-icon-btn.qc-icon-danger { color: #9b1c1c; }
.qc-icon-btn.qc-icon-danger:hover,
.qc-icon-btn.qc-icon-danger:focus-visible { color: #641414; }

.qc-icon-btn svg { display: block; }

.qc-actions .qc-icon-btn + .qc-icon-btn,
.qc-actions .qc-kebab { margin-left: 0.1rem; }

/* Outline buttons. Bootstrap 5.3 info (#0dcaf0) and warning (#ffc107) sit
   under 2:1 on #fff. Secondary (#6c757d) is 4.45:1 on #f8f9fa (bg-light),
   under the 4.5:1 floor. These overrides are the Test, Revoke, and
   Refresh/Reindex variants. */
.btn-outline-info {
  --bs-btn-color: #0b5f6e;
  --bs-btn-border-color: #0b5f6e;
  --bs-btn-hover-color: #fff;
  --bs-btn-hover-bg: #0b5f6e;
  --bs-btn-hover-border-color: #0b5f6e;
  --bs-btn-active-color: #fff;
  --bs-btn-active-bg: #0b5f6e;
  --bs-btn-active-border-color: #0b5f6e;
  --bs-btn-disabled-color: #0b5f6e;
  --bs-btn-disabled-border-color: #0b5f6e;
}

.btn-outline-warning {
  --bs-btn-color: #7a4f01;
  --bs-btn-border-color: #7a4f01;
  --bs-btn-hover-color: #fff;
  --bs-btn-hover-bg: #7a4f01;
  --bs-btn-hover-border-color: #7a4f01;
  --bs-btn-active-color: #fff;
  --bs-btn-active-bg: #7a4f01;
  --bs-btn-active-border-color: #7a4f01;
  --bs-btn-disabled-color: #7a4f01;
  --bs-btn-disabled-border-color: #7a4f01;
}

.btn-outline-secondary,
.qc-btn-refresh {
  --bs-btn-color: #495057;
  --bs-btn-border-color: #495057;
  --bs-btn-hover-color: #fff;
  --bs-btn-hover-bg: #495057;
  --bs-btn-hover-border-color: #495057;
  --bs-btn-active-color: #fff;
  --bs-btn-active-bg: #495057;
  --bs-btn-active-border-color: #495057;
  --bs-btn-disabled-color: #495057;
  --bs-btn-disabled-border-color: #495057;
}
