/*
 * Internal ops dashboard: PTAG documents and their delivery to Forma.
 *
 * Every colour comes from the tokens in application.css, so the dashboard
 * follows the app's light and dark schemes without defining a palette of its
 * own. The only new tokens are the four outcome colours, which are semantic
 * (state of a transfer) rather than brand, and are declared for both schemes.
 */

.dashboard {
  --outcome-success: var(--color-notice);
  --outcome-success-bg: var(--color-notice-bg);
  --outcome-failed: var(--color-alert);
  --outcome-failed-bg: var(--color-alert-bg);
  --outcome-pending: #8a5a09;
  --outcome-pending-bg: #fdf3e3;
  --outcome-drift: #6b4396;
  --outcome-drift-bg: #f3ecfb;

  max-width: 1180px;
  margin: 0 auto;
  padding: var(--space-xl) var(--space-md) var(--space-2xl);
}

@media (prefers-color-scheme: dark) {
  .dashboard {
    --outcome-pending: #f0be6a;
    --outcome-pending-bg: #2b2011;
    --outcome-drift: #c9a6ee;
    --outcome-drift-bg: #241a30;
  }
}

/* Expanding a detail row makes the page tall enough to need a scrollbar; the
   stable gutter stops the whole layout jumping sideways when it appears. */
html { scrollbar-gutter: stable; }

.dashboard__header {
  display: flex;
  flex-wrap: wrap;
  /* flex-end, not baseline: the filter bar is a stacked label+control block,
     so baseline would hang it off the small uppercase label. */
  align-items: flex-end;
  justify-content: space-between;
  gap: var(--space-md);
  margin-bottom: var(--space-lg);
}

.dashboard__title {
  margin: 0;
  font-size: var(--font-size-xl);
  letter-spacing: -0.01em;
}

.dashboard__count {
  color: var(--color-text-muted);
  font-size: var(--font-size-sm);
}

/* --- filters ----------------------------------------------------------- */

.dashboard__filters {
  display: flex;
  flex-wrap: wrap;
  align-items: flex-end;
  gap: var(--space-xs) var(--space-sm);
}

.dashboard__field {
  display: flex;
  flex-direction: column;
  gap: var(--space-2xs);
}

.dashboard__field-label {
  font-size: var(--font-size-xs);
  font-weight: 600;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  color: var(--color-text-subtle);
}

.dashboard__filters input[type="text"],
.dashboard__filters select,
.dashboard__filters button,
.dashboard__clear {
  height: 2.25rem;
  padding: 0 var(--space-sm);
  border: 1px solid var(--color-border-strong);
  border-radius: var(--radius-sm);
  background: var(--color-surface);
  color: var(--color-text);
  font-family: inherit;
  font-size: var(--font-size-sm);
}

.dashboard__filters input[type="text"] { width: 11rem; }
.dashboard__filters input[type="text"]::placeholder { color: var(--color-text-subtle); }

.dashboard__filters input[type="text"]:focus-visible,
.dashboard__filters select:focus-visible,
.dashboard__filters button:focus-visible,
.dashboard__clear:focus-visible {
  outline: 2px solid var(--color-focus);
  outline-offset: 1px;
}

.dashboard__filters button {
  border-color: var(--color-brand);
  background: var(--color-brand);
  color: var(--color-brand-contrast);
  font-weight: 600;
  cursor: pointer;
}
.dashboard__filters button:hover { background: var(--color-brand-hover); }

.dashboard__clear {
  display: inline-flex;
  align-items: center;
  color: var(--color-text-muted);
  text-decoration: none;
}
.dashboard__clear:hover { color: var(--color-text); }

/* --- table ------------------------------------------------------------- */

.dashboard__table-wrap {
  overflow-x: auto;
  border: 1px solid var(--color-border);
  border-radius: var(--radius-md);
  background: var(--color-surface);
}

.dashboard__table {
  width: 100%;
  min-width: 940px;
  border-collapse: collapse;
  table-layout: fixed;
  font-size: var(--font-size-sm);
}

.col-file    { width: 26%; }
.col-project { width: 11%; }
.col-event   { width: 10%; }
.col-status  { width: 12%; }
.col-ref     { width: 18%; }
.col-tries   { width: 7%; }
.col-time    { width: 16%; }

.dashboard__table th,
.dashboard__table td {
  padding: var(--space-sm) var(--space-md);
  text-align: left;
  vertical-align: top;
  border-bottom: 1px solid var(--color-border);
}

.dashboard__table thead th {
  position: sticky;
  top: 0;
  background: var(--color-surface-muted);
  color: var(--color-text-subtle);
  font-size: var(--font-size-xs);
  font-weight: 600;
  letter-spacing: 0.05em;
  text-transform: uppercase;
}

.dashboard__file {
  font-weight: 600;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.dashboard__tag {
  margin-left: var(--space-2xs);
  padding: 0 var(--space-2xs);
  border: 1px solid var(--color-border-strong);
  border-radius: var(--radius-sm);
  color: var(--color-text-subtle);
  font-size: var(--font-size-xs);
  font-weight: 500;
}

.dashboard__event { color: var(--color-text-muted); }
.dashboard__num { font-variant-numeric: tabular-nums; }
.dashboard__na { color: var(--color-text-subtle); }

.dashboard__ref code,
.dashboard__ref {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  font-size: var(--font-size-xs);
}

.dashboard__time time { color: var(--color-text-muted); font-variant-numeric: tabular-nums; }

/* --- expandable detail -------------------------------------------------- */

.dashboard__detail-row td { padding: 0; border-bottom: 1px solid var(--color-border); }

.dashboard__detail-row summary {
  padding: var(--space-xs) var(--space-md);
  color: var(--color-brand);
  font-size: var(--font-size-xs);
  font-weight: 600;
  cursor: pointer;
}
.dashboard__detail-row summary:focus-visible {
  outline: 2px solid var(--color-focus);
  outline-offset: -2px;
}

.detail {
  padding: var(--space-md);
  background: var(--color-surface-muted);
  border-top: 1px solid var(--color-border);
}

.detail__subhead {
  margin: var(--space-md) 0 var(--space-xs);
  font-size: var(--font-size-xs);
  font-weight: 600;
  letter-spacing: 0.05em;
  text-transform: uppercase;
  color: var(--color-text-subtle);
}

.detail-empty { margin: 0; color: var(--color-text-muted); font-size: var(--font-size-sm); }

.detail__meta,
.attempt__meta-list {
  display: grid;
  grid-template-columns: minmax(7rem, max-content) 1fr;
  gap: var(--space-2xs) var(--space-md);
  margin: 0;
  font-size: var(--font-size-xs);
}

.detail__meta dt,
.attempt__meta-list dt { color: var(--color-text-subtle); }

.detail__meta dd,
.attempt__meta-list dd { margin: 0; overflow-wrap: anywhere; }

/* --- one delivery attempt ---------------------------------------------- */

.attempt {
  padding: var(--space-sm) 0;
  border-bottom: 1px solid var(--color-border);
}
.attempt:last-child { border-bottom: 0; }

.attempt__head {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: var(--space-xs) var(--space-sm);
  margin-bottom: var(--space-xs);
}

.attempt__meta { color: var(--color-text-muted); font-size: var(--font-size-xs); }

.error-text {
  margin: var(--space-xs) 0;
  padding: var(--space-xs) var(--space-sm);
  border-left: 3px solid var(--color-alert);
  background: var(--color-alert-bg);
  color: var(--color-text);
  font-size: var(--font-size-xs);
  overflow-wrap: anywhere;
}

.json-block {
  margin: 0;
  padding: var(--space-sm);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-sm);
  background: var(--color-bg);
  font-size: var(--font-size-xs);
  overflow-x: auto;
}

/* --- pills -------------------------------------------------------------- */

.pill {
  display: inline-block;
  padding: 0.1rem var(--space-xs);
  border: 1px solid currentcolor;
  border-radius: 999px;
  font-size: var(--font-size-xs);
  font-weight: 600;
  line-height: 1.5;
  white-space: nowrap;
}

.pill.is-success { color: var(--outcome-success); background: var(--outcome-success-bg); }
.pill.is-failed  { color: var(--outcome-failed);  background: var(--outcome-failed-bg); }
.pill.is-pending { color: var(--outcome-pending); background: var(--outcome-pending-bg); }
/* Drift is not a failure -- it is a reconciliation finding, so it must not
   read as red alongside genuine delivery failures. */
.pill.is-drift   { color: var(--outcome-drift);   background: var(--outcome-drift-bg); }
.pill.is-neutral { color: var(--color-text-subtle); background: var(--color-surface-muted); }

/* --- pagination / empty ------------------------------------------------- */

.pagination {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: var(--space-md);
  margin-top: var(--space-lg);
  font-size: var(--font-size-sm);
}

.pagination__link {
  padding: var(--space-2xs) var(--space-sm);
  border: 1px solid var(--color-border-strong);
  border-radius: var(--radius-sm);
  color: var(--color-brand);
  text-decoration: none;
}
.pagination__link:hover { background: var(--color-brand-soft); }
.pagination__link.is-disabled {
  color: var(--color-text-subtle);
  border-color: var(--color-border);
  pointer-events: none;
}

.pagination__status { color: var(--color-text-muted); font-variant-numeric: tabular-nums; }

.dashboard__empty {
  padding: var(--space-2xl) var(--space-md);
  border: 1px dashed var(--color-border-strong);
  border-radius: var(--radius-md);
  color: var(--color-text-muted);
  text-align: center;
}

@media (max-width: 40rem) {
  .dashboard__header { flex-direction: column; align-items: stretch; }
  .dashboard__filters input[type="text"] { width: 100%; }
  .dashboard__field { flex: 1 1 8rem; }
}
