/* AI Workflows dashboard — page-specific styling only.
 *
 * Everything structural (header, panels, tables, chips, typography, spacing scale,
 * theme) comes from the shared portal stylesheet, loaded at runtime from the gateway
 * assets — /opt/ct-mcp-uitests/docs/portal-ui-component-conventions.md says not to fork
 * it. What follows is the operational surface the portal sheet does not have: the wide
 * board layout, stat tiles, the budget meter and the phase/event streams.
 *
 * Two rules from portal-ux-guidelines.md that shape the choices below:
 *   * text uses TEXT tokens (--wa-color-text-*), never structural ones;
 *   * light mode needs stronger accents than dark — sub-20% mixes with white go
 *     invisible — so accents mix against the surface, not against white.
 */

/* This is a documented wide operational surface: a Kanban mirror plus a run table
   do not fit portal-main-wide's 960px. Everything else keeps portal spacing. */
.aiwf-main { max-width: 1320px; }

.aiwf-section { margin-bottom: var(--sp-10); }
.aiwf-section-head {
  display: flex; align-items: flex-end; justify-content: space-between;
  gap: var(--sp-7); flex-wrap: wrap; margin-bottom: var(--sp-6);
}
.aiwf-h2 {
  font-size: var(--wa-portal-font-heading-s);
  color: var(--wa-color-text-normal);
  margin: 0 0 var(--sp-2);
}
.aiwf-main h1.portal-heading { margin-bottom: var(--sp-2); }
.aiwf-note { margin-top: var(--sp-4); }
.aiwf-muted { color: var(--wa-color-text-quiet); }
.aiwf-scroll { overflow-x: auto; }

/* ── Buttons ───────────────────────────────────────────────────────────────── */
.aiwf-btn {
  display: inline-flex; align-items: center; gap: var(--sp-2);
  min-height: var(--wa-form-control-height, 28px);
  padding: 0 var(--sp-5);
  font: inherit; font-size: var(--wa-font-size-2xs); font-weight: 600;
  color: var(--wa-color-text-normal);
  background: var(--wa-color-surface-lowered);
  border: 1px solid var(--wa-color-surface-border);
  border-radius: var(--wa-form-control-border-radius, 4px);
  text-decoration: none; cursor: pointer;
}
.aiwf-btn:hover { background: var(--wa-color-surface-raised); }
.aiwf-btn:focus-visible { outline: 2px solid var(--wa-color-text-link); outline-offset: 2px; }
.aiwf-btn[disabled] { opacity: .5; cursor: default; }
.aiwf-btn-primary {
  color: var(--wa-color-text-link);
  border-color: color-mix(in srgb, var(--wa-color-text-link) 55%, var(--wa-color-surface-border));
  background: color-mix(in srgb, var(--wa-color-text-link) 12%, var(--wa-color-surface-lowered));
}
.aiwf-btn-quiet { background: transparent; color: var(--wa-color-text-quiet); font-weight: 500; }
.aiwf-controls { display: flex; gap: var(--sp-4); align-items: center; }

/* ── Stat tiles ────────────────────────────────────────────────────────────
 * Headline numbers, so they are tiles and not a chart: each is one value with no
 * comparison to plot. Value in the primary ink, label above it, context below.
 */
.aiwf-tiles {
  display: grid; gap: var(--sp-5);
  grid-template-columns: repeat(auto-fit, minmax(158px, 1fr));
}
.aiwf-tile {
  padding: var(--sp-5) var(--sp-6);
  border: 1px solid var(--wa-color-surface-border);
  border-radius: var(--wa-panel-border-radius);
  background: var(--wa-color-surface-default);
}
.aiwf-tile-label {
  font-size: var(--wa-portal-font-4xs); font-weight: 600; letter-spacing: .06em;
  text-transform: uppercase; color: var(--wa-color-text-quiet);
}
.aiwf-tile-value {
  font-size: var(--wa-portal-font-heading-m); line-height: 1.25;
  color: var(--wa-color-text-normal); margin-top: var(--sp-2);
}
.aiwf-tile-sub { font-size: var(--wa-portal-font-4xs); color: var(--wa-color-text-quiet); margin-top: var(--sp-1); }
/* The one tile that carries state gets the page's colour emphasis. */
.aiwf-tile.is-ok    { border-left: 3px solid var(--wa-color-success-on-normal); }
.aiwf-tile.is-warn  { border-left: 3px solid var(--wa-color-warning-on-normal); }
.aiwf-tile.is-error { border-left: 3px solid var(--wa-color-danger-on-normal); }

/* ── Budget meter ──────────────────────────────────────────────────────────
 * One measure against one cap. Thin mark, rounded data-end, recessive track, and
 * the number is always written out — the bar is the glance, the label is the truth.
 */
.aiwf-meter { margin-top: var(--sp-3); }
.aiwf-meter-track {
  height: 6px; border-radius: 3px; overflow: hidden;
  background: color-mix(in srgb, var(--wa-color-text-quiet) 22%, transparent);
}
.aiwf-meter-fill {
  height: 100%; border-radius: 3px; min-width: 3px;
  background: var(--wa-color-text-link);
  transition: width .4s ease;
}
.aiwf-meter-fill.is-warn { background: var(--wa-color-warning-on-normal); }
.aiwf-meter-fill.is-error { background: var(--wa-color-danger-on-normal); }

/* ── Board mirror ──────────────────────────────────────────────────────────── */
.aiwf-columns {
  display: grid; gap: var(--sp-5); align-items: start;
  grid-template-columns: repeat(auto-fill, minmax(216px, 1fr));
}
.aiwf-col {
  border: 1px solid var(--wa-color-surface-border);
  border-radius: var(--wa-panel-border-radius);
  background: var(--wa-color-surface-lowered);
  padding: var(--sp-4);
}
.aiwf-col-head {
  display: flex; align-items: center; justify-content: space-between; gap: var(--sp-3);
  font-size: var(--wa-portal-font-4xs); font-weight: 700; letter-spacing: .05em;
  text-transform: uppercase; color: var(--wa-color-text-quiet);
  padding-bottom: var(--sp-3); margin-bottom: var(--sp-3);
  border-bottom: 1px solid var(--wa-color-surface-border);
}
/* The active column is where the eye should land first. */
.aiwf-col.is-active .aiwf-col-head { color: var(--wa-color-text-link); border-bottom-color: var(--wa-color-text-link); }
.aiwf-col.is-gate .aiwf-col-head { color: var(--wa-color-warning-on-normal); }
.aiwf-col-empty { font-size: var(--wa-portal-font-4xs); color: var(--wa-color-text-quiet); padding: var(--sp-2) 0; }
.aiwf-card {
  display: block; text-decoration: none;
  padding: var(--sp-4); margin-bottom: var(--sp-3);
  border: 1px solid var(--wa-color-surface-border);
  border-radius: 4px; background: var(--wa-color-surface-default);
}
.aiwf-card:last-child { margin-bottom: 0; }
.aiwf-card:hover { border-color: var(--wa-color-text-link); }
.aiwf-card-key { font-family: var(--wa-font-family-code); font-size: var(--wa-portal-font-4xs); color: var(--wa-color-text-link); }
.aiwf-card-summary { font-size: var(--wa-portal-font-4xs); color: var(--wa-color-text-normal); line-height: 1.45; margin-top: 2px; }
.aiwf-card-meta { margin-top: var(--sp-2); display: flex; gap: 4px; flex-wrap: wrap; }
.aiwf-tag {
  font-size: var(--wa-portal-font-4xs); padding: 0 4px; border-radius: 3px;
  color: var(--wa-color-text-quiet); background: var(--wa-color-surface-lowered);
  border: 1px solid var(--wa-color-surface-border);
}
.aiwf-tag.is-blocked { color: var(--wa-color-warning-on-normal); border-color: var(--wa-color-warning-on-normal); }

/* ── Active run + phases ───────────────────────────────────────────────────── */
.aiwf-phases { display: flex; flex-wrap: wrap; gap: var(--sp-2); margin: var(--sp-5) 0 0; }
.aiwf-phase {
  font-size: var(--wa-portal-font-4xs); padding: 2px var(--sp-4); border-radius: 999px;
  border: 1px solid var(--wa-color-surface-border); color: var(--wa-color-text-quiet);
}
.aiwf-phase.is-done { color: var(--wa-color-success-on-normal); border-color: var(--wa-color-success-on-normal); }
.aiwf-phase.is-current {
  color: var(--wa-color-text-link); border-color: var(--wa-color-text-link); font-weight: 600;
  background: color-mix(in srgb, var(--wa-color-text-link) 12%, transparent);
}
.aiwf-idle { color: var(--wa-color-text-quiet); font-size: var(--wa-font-size-s); }

/* ── Event / transcript streams ────────────────────────────────────────────── */
.aiwf-stream {
  margin-top: var(--sp-5); max-height: 320px; overflow-y: auto;
  border: 1px solid var(--wa-color-surface-border); border-radius: var(--wa-panel-border-radius);
  background: var(--wa-color-surface-lowered);
}
.aiwf-ev {
  display: grid; grid-template-columns: 84px 148px 1fr; gap: var(--sp-4);
  padding: var(--sp-2) var(--sp-5); font-size: var(--wa-portal-font-4xs);
  border-bottom: 1px solid var(--wa-color-surface-border);
}
.aiwf-ev:last-child { border-bottom: none; }
.aiwf-ev-time { font-family: var(--wa-font-family-code); color: var(--wa-color-text-quiet); }
.aiwf-ev-type { font-family: var(--wa-font-family-code); color: var(--wa-color-text-link); }
.aiwf-ev-body { color: var(--wa-color-text-normal); word-break: break-word; white-space: pre-wrap; }
.aiwf-ev.is-error .aiwf-ev-type { color: var(--wa-color-danger-on-normal); }
.aiwf-ev.is-warn .aiwf-ev-type { color: var(--wa-color-warning-on-normal); }
.aiwf-ev.is-good .aiwf-ev-type { color: var(--wa-color-success-on-normal); }
@media (max-width: 760px) { .aiwf-ev { grid-template-columns: 1fr; gap: 0; } }

.aiwf-tr { padding: var(--sp-4) var(--sp-5); border-bottom: 1px solid var(--wa-color-surface-border); font-size: var(--wa-portal-font-4xs); }
.aiwf-tr:last-child { border-bottom: none; }
.aiwf-tr-head { color: var(--wa-color-text-quiet); font-family: var(--wa-font-family-code); margin-bottom: 2px; }
.aiwf-tr-body { color: var(--wa-color-text-normal); white-space: pre-wrap; word-break: break-word; line-height: 1.5; }
.aiwf-tr.is-tool .aiwf-tr-body { font-family: var(--wa-font-family-code); color: var(--wa-color-text-quiet); }
.aiwf-tr.is-assistant { border-left: 2px solid color-mix(in srgb, var(--wa-color-text-link) 55%, transparent); }

/* ── Tables ────────────────────────────────────────────────────────────────── */
.portal-table td.aiwf-num, .portal-table th.aiwf-num { text-align: right; font-variant-numeric: tabular-nums; }
.portal-table td a { color: var(--wa-color-text-link); text-decoration: none; }

/* ── Sign-in page ──────────────────────────────────────────────────────────── */
.aiwf-signin { padding-top: var(--sp-11); }
.aiwf-signin .aiwf-btn { margin-top: var(--sp-5); }
.aiwf-deploy { margin-top: var(--sp-6); font-size: var(--wa-portal-font-base); }
