/* 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;
  max-width: 1200px;
  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; }

/* 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: 1146px;
  table-layout: fixed;
  border-collapse: collapse;
  font-size: 0.88rem;
}

/* These must total <= the .dashboard content box (max-width 1200px - 1.5rem padding each
   side = 1152px), otherwise the table always overflows and the last column is cut off. */
.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; }
.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; }

.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); }

.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; }
.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); }
