/* Receipt-request ops dashboard. Kept in its own file (no inline styles) and linked
   from the dashboard view via content_for(:head). */

/* Reserve the scrollbar gutter always. Expanding a detail row makes the page tall enough to
   need a vertical scrollbar, and without this the whole layout jumps sideways when it
   appears. Falls back harmlessly on browsers without scrollbar-gutter. */
html { scrollbar-gutter: stable; }

.dashboard {
  --border: #e2e8f0;
  --muted: #64748b;
  --bg-soft: #f8fafc;
  --success: #16a34a;
  --failed: #dc2626;
  --pending: #d97706;
  /* Widened from 1200px when the Webhook column was added — the receipts table needs
     1276px of columns, and anything narrower makes every page scroll sideways. */
  max-width: 1340px;
  margin: 0 auto;
  padding: 2rem 1.5rem 4rem;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  color: #0f172a;
}

.dashboard__header {
  display: flex;
  flex-wrap: wrap;
  /* flex-end, not baseline: the filter bar is a stacked label+control block, so baseline
     alignment would hang it off the tiny uppercase label rather than sitting it on the
     same line as the title. */
  align-items: flex-end;
  justify-content: space-between;
  gap: 1rem;
  margin-bottom: 1.5rem;
}

.dashboard__title { font-size: 1.6rem; margin: 0; }
.dashboard__count { color: var(--muted); font-size: 0.9rem; }

/* Section tabs (receipt requests / inspections / STI extractions). The active tab's
   underline sits on the nav's own bottom rule, hence the -1px pull. */
.dashboard__nav {
  display: flex;
  flex-wrap: wrap;
  gap: 0.25rem;
  margin-bottom: 1.5rem;
  border-bottom: 1px solid var(--border);
}

.dashboard__nav-link {
  padding: 0.55rem 0.95rem;
  margin-bottom: -1px;
  border-bottom: 2px solid transparent;
  color: var(--muted);
  font-size: 0.9rem;
  font-weight: 600;
  text-decoration: none;
}
.dashboard__nav-link:hover { color: #0f172a; }
.dashboard__nav-link.is-active { color: #2563eb; border-bottom-color: #2563eb; }

/* Filter bar. Controls are grouped as stacked label+input pairs so the row stays readable
   as fields are added, and wraps instead of overflowing on narrow screens. */
.dashboard__filters {
  display: flex;
  flex-wrap: wrap;
  align-items: flex-end;
  gap: 0.5rem 0.75rem;
}

.dashboard__field { display: flex; flex-direction: column; gap: 0.25rem; }

.dashboard__field-label {
  font-size: 0.7rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.03em;
  color: var(--muted);
}

/* Every control shares one box style — inputs were previously unstyled and rendered as
   raw browser defaults beside the select. */
.dashboard__filters input[type="text"],
.dashboard__filters select,
.dashboard__filters button {
  height: 2.1rem;
  padding: 0 0.6rem;
  border: 1px solid var(--border);
  border-radius: 6px;
  background: #fff;
  color: inherit;
  font-family: inherit;
  font-size: 0.85rem;
  line-height: 1;
}
.dashboard__filters input[type="text"] { width: 11rem; }
.dashboard__filters input[type="text"]::placeholder { color: #94a3b8; }

.dashboard__filters input[type="text"]:focus-visible,
.dashboard__filters select:focus-visible {
  outline: 2px solid #2563eb;
  outline-offset: -1px;
  border-color: #2563eb;
}

.dashboard__filters button {
  cursor: pointer;
  padding: 0 0.9rem;
  font-weight: 600;
  background: #2563eb;
  border-color: #2563eb;
  color: #fff;
}
.dashboard__filters button:hover { background: #1d4ed8; }

/* Sits in the control row, so it needs the controls' height to line up with them. */
.dashboard__clear {
  display: inline-flex;
  align-items: center;
  height: 2.1rem;
  color: var(--muted);
  font-size: 0.85rem;
  text-decoration: none;
}
.dashboard__clear:hover { color: #0f172a; text-decoration: underline; }

.dashboard__table-wrap { overflow-x: auto; border: 1px solid var(--border); border-radius: 10px; }

/* Fixed layout so column widths come from the <colgroup> alone and never from cell content.
   This is what stops the table reflowing when a detail row is expanded. The min-width keeps
   the columns legible; the wrapper scrolls horizontally below that. */
.dashboard__table {
  width: 100%;
  /* Equals the sum of the <colgroup> widths, so the columns are never squeezed below their
     declared size — the wrapper scrolls horizontally instead. Keep the two in sync. */
  min-width: 1276px;
  table-layout: fixed;
  border-collapse: collapse;
  font-size: 0.88rem;
}

/* Each tab has its own column set, so each overrides the min-width with the sum of its
   own <colgroup>. Keep these in sync with the widths below. */
.dashboard__table--inspections  { min-width: 1202px; }
.dashboard__table--sti          { min-width: 834px; }
.dashboard__table--verifications { min-width: 982px; }

/* These must total <= the .dashboard content box (max-width 1340px - 1.5rem padding each
   side = 1292px), otherwise the table always overflows and the wrapper scrolls sideways. */
.col-id      { width: 52px; }
.col-order   { width: 112px; }
.col-rx      { width: 100px; }
.col-files   { width: 160px; }
.col-stage   { width: 128px; }
.col-tokens  { width: 108px; }
.col-success { width: 80px; }
/* Widest of the set: "2026-06-10 06:43" is ~120px of text plus 27px of cell padding. */
.col-created { width: 150px; }
/* Inspections tab */
.col-status   { width: 110px; }
.col-products { width: 190px; }
.col-images   { width: 180px; }
.col-pdf      { width: 180px; }
.col-analyses { width: 210px; }
/* STI extractions tab */
.col-applied { width: 100px; }
.col-value   { width: 110px; }
.col-rows    { width: 70px; }
.col-webhook { width: 130px; }

/* Rx verifications tab: the per-field comparison table nested inside a row's detail block.
   Sits inside .detail-block--wide, so it sizes to the block rather than the page. */
.dashboard__table--compare {
  min-width: 0;
  width: 100%;
  font-size: 0.82rem;
  border: 1px solid var(--border);
  border-radius: 8px;
}
.dashboard__table--compare + .dashboard__table--compare { margin-top: 0.8rem; }
.dashboard__table--compare td { word-break: break-word; }
.dashboard__table--compare tr:last-child td { border-bottom: none; }
.dashboard__table th,
.dashboard__table td {
  text-align: left;
  padding: 0.65rem 0.85rem;
  border-bottom: 1px solid var(--border);
  vertical-align: top;
}
.dashboard__table th { background: var(--bg-soft); font-weight: 600; color: var(--muted); white-space: nowrap; }
.dashboard__table tr:last-child td { border-bottom: none; }

.dashboard__id { font-variant-numeric: tabular-nums; font-weight: 600; }
.dashboard__link { color: #2563eb; text-decoration: none; }
.dashboard__link:hover { text-decoration: underline; }
.dashboard__na { color: var(--muted); }
.dashboard__created { white-space: nowrap; }

/* Cross-tab link under an order number (receipts <-> STI extractions). Block, not inline,
   so it never competes with the order number for the column's width. */
.dashboard__xref {
  display: block;
  margin-top: 0.15rem;
  color: #2563eb;
  font-size: 0.72rem;
  text-decoration: none;
  white-space: nowrap;
}
.dashboard__xref:hover { text-decoration: underline; }

/* Per-analysis status stack in an inspection row: label on the left, pill on the right. */
.dashboard__analyses { white-space: nowrap; }
.analysis-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.4rem;
  margin: 0.12rem 0;
}
.analysis-label { color: var(--muted); font-size: 0.72rem; }

/* Outbound-delivery status cell: pill, then timestamp / failure reason stacked beneath. */
.dashboard__webhook { overflow-wrap: anywhere; }
.webhook-time { display: block; margin-top: 0.15rem; color: var(--muted); font-size: 0.72rem; }
.webhook-reason { display: block; margin-top: 0.15rem; color: var(--failed); font-size: 0.72rem; }

/* One delivery attempt inside the expanded detail. Attempts stack newest-first, so each
   needs its own rule to separate it from the one below. */
.webhook-attempt { padding-bottom: 0.8rem; }
.webhook-attempt + .webhook-attempt { margin-top: 0.8rem; border-top: 1px solid var(--border); padding-top: 0.8rem; }
.webhook-attempt__head { display: flex; flex-wrap: wrap; align-items: center; gap: 0.5rem; margin-bottom: 0.5rem; }
/* Reset the block/margin the cell version sets — inside the head these sit inline. */
.webhook-attempt__head .webhook-time { display: inline; margin-top: 0; }
.webhook-attempt .error-text { margin-bottom: 0.5rem; }
.webhook-subhead {
  margin: 0.5rem 0 0.3rem;
  color: var(--muted);
  font-size: 0.7rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.04em;
}

.file-list { margin: 0; padding-left: 1.1rem; }
.file-list li { margin: 0.1rem 0; max-width: 260px; overflow-wrap: anywhere; }

.pill {
  display: inline-block;
  padding: 0.15rem 0.55rem;
  border-radius: 999px;
  font-size: 0.72rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.03em;
}
/* Per-request Azure AI token usage */
.dashboard__tokens { white-space: nowrap; }
.token-total { display: block; font-weight: 600; font-size: 0.82rem; }
.token-breakdown { display: block; color: var(--muted); font-size: 0.72rem; }
.token-usage {
  margin: 0;
  padding: 0.7rem 0.7rem 0.7rem 1.7rem;
  background: #0f172a;
  color: #e2e8f0;
  border-radius: 8px;
  font-size: 0.78rem;
  line-height: 1.45;
}
.token-usage li { margin: 0.15rem 0; }

.pill.is-success { background: #dcfce7; color: var(--success); }
.pill.is-failed  { background: #fee2e2; color: var(--failed); }
.pill.is-pending { background: #fef3c7; color: var(--pending); }
/* Deliberately grey, not red: a "no" (e.g. no STI on the receipt) is a valid answer,
   not a failure. */
.pill.is-neutral { background: #e2e8f0; color: var(--muted); }

.detail-row td { background: var(--bg-soft); }
.detail-grid {
  display: grid;
  /* min(320px, 100%), not a bare 320px: inside a table cell a hard 320px floor becomes part
     of the table's minimum width, so on a narrow viewport the expanded row would widen the
     whole table instead of the blocks stacking. */
  grid-template-columns: repeat(auto-fit, minmax(min(320px, 100%), 1fr));
  gap: 1rem;
}
.detail-block { min-width: 0; }
/* Delivery history carries two code blocks per attempt, so it gets the full grid width
   rather than being squeezed into one auto-fit column. */
.detail-block--wide { grid-column: 1 / -1; }
.detail-block h4 {
  margin: 0 0 0.4rem;
  font-size: 0.75rem;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: var(--muted);
}
.detail-block pre {
  margin: 0;
  padding: 0.7rem;
  background: #0f172a;
  color: #e2e8f0;
  border-radius: 8px;
  font-size: 0.78rem;
  line-height: 1.45;
  max-height: 320px;
  overflow: auto;
  white-space: pre-wrap;
  word-break: break-word;
}
.detail-block .error-text {
  margin: 0;
  padding: 0.7rem;
  background: #fee2e2;
  color: #991b1b;
  border-radius: 8px;
  font-size: 0.82rem;
  white-space: pre-wrap;
  word-break: break-word;
}

details.detail-toggle > summary {
  cursor: pointer;
  color: #2563eb;
  font-size: 0.82rem;
  user-select: none;
}
/* Open state needs a gap and a rule, otherwise the first block's heading sits directly on
   the summary line and the two read as one collided row. */
details.detail-toggle[open] > summary {
  margin-bottom: 0.9rem;
  padding-bottom: 0.6rem;
  border-bottom: 1px solid var(--border);
  font-weight: 600;
}

/* Placeholder for a block with no data — a muted dash, not a full-size dark code block. */
.detail-empty {
  margin: 0;
  padding: 0.4rem 0;
  color: var(--muted);
  font-size: 0.85rem;
}

.pagination { display: flex; gap: 0.4rem; align-items: center; justify-content: center; margin-top: 1.5rem; }
.pagination a,
.pagination span {
  padding: 0.35rem 0.7rem;
  border: 1px solid var(--border);
  border-radius: 6px;
  font-size: 0.85rem;
  color: #2563eb;
  text-decoration: none;
}
.pagination .current { background: #2563eb; color: #fff; border-color: #2563eb; }
.pagination .disabled { color: var(--muted); pointer-events: none; opacity: 0.5; }

.empty-state { padding: 3rem; text-align: center; color: var(--muted); }
