/* ===========================================
   MCP execution monitoring (design §E.3 Slice 7): the list, the detail page
   and the log viewer.

   Quiet number tiles (.status-card__label stays: the monitoring spec reads
   it), a hairline filter row, the shared .table inside a keyboard-scrollable
   .table-responsive, and record sections as heading plus hairline. Mobile
   first: literal min-width queries only (the old var() queries never
   matched). Colours come from tokens only.
   =========================================== */

.mcp-containers {
  display: flex;
  flex-direction: column;
  gap: var(--spacing-xl);
  min-width: 0;
}

/* -------------------------------------------
   Status tiles
   ------------------------------------------- */

.status-cards {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 1px;
  overflow: hidden;
  border: 1px solid var(--color-border);
  border-radius: var(--radius-md);
  background: var(--color-border-subtle);
}

.status-card {
  display: flex;
  flex-direction: column;
  gap: var(--spacing-xs);
  min-width: 0;
  padding: var(--spacing-md) var(--spacing-lg);
  background: var(--color-surface);
}

/* An odd last tile fills its row, so no empty cell shows. */
.status-card:last-child:nth-child(odd) {
  grid-column: 1 / -1;
}

.status-card__value {
  color: var(--color-text-emphasis);
  font-size: var(--text-2xl);
  font-weight: var(--font-semibold);
  font-variant-numeric: tabular-nums;
  line-height: var(--leading-tight);
}

.status-card__label {
  display: inline-flex;
  align-items: center;
  gap: var(--spacing-xs);
  color: var(--color-text-muted);
  font-size: var(--text-sm);
}

/* A status dot beside the word; the word carries the meaning. */
.status-card--running .status-card__label::before,
.status-card--stopped .status-card__label::before,
.status-card--failed .status-card__label::before,
.status-card--stale .status-card__label::before {
  content: "";
  width: 0.5rem;
  height: 0.5rem;
  border-radius: var(--radius-full);
  background: var(--color-neutral);
}

.status-card--running .status-card__label::before {
  background: var(--color-success);
}

.status-card--failed .status-card__label::before {
  background: var(--color-danger);
}

.status-card--stale .status-card__label::before {
  background: var(--color-warning);
}

/* -------------------------------------------
   Filters
   ------------------------------------------- */

.mcp-filters__form {
  display: flex;
  flex-direction: column;
  align-items: stretch;
  gap: var(--spacing-sm);
}

.mcp-filters__form .form__select,
.mcp-filters__form .form__input {
  width: 100%;
}

/* -------------------------------------------
   Execution table (the shared .table inside .table-responsive)
   ------------------------------------------- */

.container-table-wrapper {
  min-width: 0;
}

/* Wide enough to keep each column readable; the wrapper scrolls. */
.container-table {
  min-width: 48rem;
}

.container-table-wrapper .container-table td {
  vertical-align: middle;
}

.container-table td .button--text {
  padding-inline: 0;
}

.mcp-containers__stale-row > td {
  background: var(--color-warning-surface);
}

/* -------------------------------------------
   Detail page
   ------------------------------------------- */

.auto-refresh-control {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: var(--spacing-sm) var(--spacing-md);
  margin-bottom: var(--spacing-xl);
  padding: var(--spacing-xs) var(--spacing-md);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-md);
  background: var(--color-surface);
  font-size: var(--text-sm);
}

.container-details {
  display: flex;
  flex-direction: column;
  gap: var(--spacing-2xl);
  min-width: 0;
}

.detail-section {
  display: grid;
  gap: var(--spacing-md);
  min-width: 0;
}

.detail-section__header {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: var(--spacing-sm) var(--spacing-md);
}

.detail-section__title {
  margin: 0;
  color: var(--color-text-emphasis);
  font-size: var(--text-lg);
  font-weight: var(--font-semibold);
  letter-spacing: var(--tracking-tight);
}

/* Key-value rows */
.detail-list {
  display: flex;
  flex-direction: column;
  margin: 0;
  overflow: hidden;
  border: 1px solid var(--color-border);
  border-radius: var(--radius-md);
  background: var(--color-surface);
}

.detail-item {
  display: grid;
  grid-template-columns: minmax(0, 1fr);
  gap: var(--spacing-xs);
  padding: var(--spacing-md) var(--spacing-lg);
  border-top: 1px solid var(--color-border-subtle);
}

.detail-item:first-child {
  border-top: 0;
}

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

.detail-item__value {
  min-width: 0;
  overflow-wrap: anywhere;
  color: var(--color-text);
  font-size: var(--text-sm);
}

.config-block {
  border: 1px solid var(--color-border);
  border-radius: var(--radius-md);
  background: var(--color-surface);
}

.details-summary {
  display: flex;
  align-items: center;
  min-height: var(--touch-target);
  padding: 0 var(--spacing-lg);
  border-radius: var(--radius-md);
  color: var(--color-text);
  font-size: var(--text-sm);
  font-weight: var(--font-medium);
  cursor: pointer;
}

.details-summary:hover {
  background: var(--color-surface-hover);
}

.details-content {
  margin: 0;
  border: 0;
  border-top: 1px solid var(--color-border-subtle);
  border-radius: 0 0 var(--radius-md) var(--radius-md);
}

/* -------------------------------------------
   Log viewer
   ------------------------------------------- */

.logs-viewer {
  min-width: 0;
  overflow: hidden;
  border: 1px solid var(--color-border);
  border-radius: var(--radius-md);
  background: var(--color-background-subtle);
}

.logs-viewer__content {
  max-height: 25rem;
  margin: 0;
  padding: var(--spacing-md) var(--spacing-lg);
  overflow: auto;
  border: 0;
  border-radius: 0;
  background: transparent;
  color: var(--color-text);
  font-family: var(--font-mono);
  font-size: var(--text-xs);
  line-height: var(--leading-relaxed);
}

.logs-viewer--full .logs-viewer__content {
  max-height: 40rem;
}

.logs-viewer .empty-state {
  background: var(--color-surface);
}

.logs-viewer__footer {
  display: flex;
  justify-content: center;
  padding: var(--spacing-xs) var(--spacing-md);
  border-top: 1px solid var(--color-border-subtle);
  background: var(--color-surface);
}

.logs-page {
  display: flex;
  flex-direction: column;
  gap: var(--spacing-lg);
  min-width: 0;
}

.logs-controls__form {
  display: grid;
  grid-template-columns: minmax(0, 1fr);
  align-items: end;
  gap: var(--spacing-md);
}

.logs-controls__form .form__group {
  min-width: 0;
  margin: 0;
}

.logs-controls__actions {
  display: flex;
  flex-wrap: wrap;
  gap: var(--spacing-sm);
}

.logs-stats {
  display: flex;
  flex-wrap: wrap;
  gap: var(--spacing-xs) var(--spacing-xl);
  color: var(--color-text-muted);
  font-size: var(--text-sm);
}

.logs-stats__item {
  display: flex;
  flex-wrap: wrap;
  align-items: baseline;
  gap: var(--spacing-xs);
  min-width: 0;
}

.logs-stats__value {
  overflow-wrap: anywhere;
  color: var(--color-text-emphasis);
  font-weight: var(--font-semibold);
  font-variant-numeric: tabular-nums;
}

/* The search term being matched */
.logs-stats__value.text-primary {
  font-family: var(--font-mono);
  font-weight: var(--font-medium);
}

.mcp-containers .icon-lg,
.logs-page .icon-lg {
  width: 1.5rem;
  height: 1.5rem;
  color: var(--color-text-muted);
}

/* The refresh glyph turns while a refresh is in flight. */
@keyframes mcp-refresh-rotate {
  to {
    transform: rotate(360deg);
  }
}

.rotating {
  animation: mcp-refresh-rotate 1s linear infinite;
}

@media (min-width: 640px) {
  .mcp-filters__form {
    flex-direction: row;
    flex-wrap: wrap;
    align-items: center;
  }

  .mcp-filters__form .form__select,
  .mcp-filters__form .form__input {
    flex: 1 1 12rem;
    width: auto;
  }

  .detail-item {
    grid-template-columns: 11rem minmax(0, 1fr);
    gap: var(--spacing-lg);
  }

  .logs-controls__form {
    grid-template-columns: minmax(0, 2fr) minmax(0, 1fr) auto;
  }
}

@media (min-width: 768px) {
  .status-cards {
    grid-template-columns: repeat(auto-fit, minmax(8rem, 1fr));
  }

  .status-card:last-child:nth-child(odd) {
    grid-column: auto;
  }
}

@media (prefers-reduced-motion: reduce) {
  .rotating {
    animation: none;
  }
}
