/* ===========================================
   Admin hub, operation runs and the audit log (design §E.3 Slice 7)

   Hairline rows and panels on neutral surfaces. Status is a tinted word with
   a glyph or a small dot, never a glow, a pulse or the accent. Progress bars
   read their width from --progress-pct, which the style-vars controller
   writes. Rules that touch a shared block (.card, .table) are scoped under
   one of this file's own classes. Mobile first: min-width queries only.
   Colours come from tokens only.
   =========================================== */

/* -------------------------------------------
   Admin hub and global settings: grouped hairline rows. Each group keeps
   .grid and the settings_card .card markup (navigation_permission_parity_spec
   reads them).
   ------------------------------------------- */

.admin-hub {
  display: grid;
  gap: var(--spacing-2xl);
  min-width: 0;
}

.admin-hub__group-title {
  margin: 0 0 var(--spacing-sm);
  color: var(--color-text-muted);
  font-size: var(--text-sm);
  font-weight: var(--font-semibold);
}

.admin-hub .admin-hub__list {
  display: flex;
  flex-direction: column;
  gap: 0;
  overflow: hidden;
  border: 1px solid var(--color-border);
  border-radius: var(--radius-md);
  background: var(--color-surface);
}

.admin-hub .card {
  display: flex;
  flex-direction: column;
  gap: var(--spacing-sm);
  padding: var(--spacing-md) var(--spacing-lg);
  overflow: visible;
  border: 0;
  border-top: 1px solid var(--color-border-subtle);
  border-radius: 0;
  background: transparent;
}

.admin-hub .card:first-child {
  border-top: 0;
}

.admin-hub .card:hover {
  border-color: var(--color-border-subtle);
}

.admin-hub .card__header {
  align-items: center;
  flex-wrap: nowrap;
  padding: 0;
}

.admin-hub .card__avatar {
  width: 2.25rem;
  height: 2.25rem;
  padding: var(--spacing-sm);
}

.admin-hub .card__name {
  margin: 0;
  font-size: var(--text-base);
}

.admin-hub .card__meta {
  margin-top: 2px;
}

/* On phones the action sits under the text, aligned with it. */
.admin-hub .card__body {
  padding: 0 0 0 calc(2.25rem + var(--spacing-md));
  border-top: 0;
}

/* -------------------------------------------
   Operation runs: index rows
   ------------------------------------------- */

.operation-list {
  display: flex;
  flex-direction: column;
  min-width: 0;
  overflow: hidden;
  border: 1px solid var(--color-border);
  border-radius: var(--radius-md);
  background: var(--color-surface);
}

.operation-list:empty {
  display: none;
}

.operation-row {
  display: grid;
  grid-template-columns: auto minmax(0, 1fr);
  align-items: start;
  gap: var(--spacing-sm) var(--spacing-md);
  min-height: var(--touch-target);
  padding: var(--spacing-md) var(--spacing-lg);
  border-top: 1px solid var(--color-border-subtle);
  color: inherit;
  text-decoration: none;
  transition: background-color var(--duration-fast) var(--ease-out);
}

.operation-row:first-child {
  border-top: 0;
}

.operation-row:hover {
  background: var(--color-surface-hover);
  text-decoration: none;
}

/* Status dot: always paired with the status word in the row header. */
.operation-status {
  display: grid;
  place-items: center;
  width: 1.25rem;
  height: 1.25rem;
  margin-top: 2px;
}

.operation-status__dot {
  width: 0.5rem;
  height: 0.5rem;
  border-radius: var(--radius-full);
  background: var(--color-neutral);
}

.operation-status--running .operation-status__dot {
  background: var(--color-info);
}

.operation-status--succeeded .operation-status__dot {
  background: var(--color-success);
}

.operation-status--failed .operation-status__dot {
  background: var(--color-danger);
}

.operation-status--canceled .operation-status__dot {
  background: var(--color-warning);
}

.operation-info {
  display: grid;
  gap: var(--spacing-xs);
  min-width: 0;
}

.operation-info__header {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: var(--spacing-sm);
  min-width: 0;
}

.operation-info__task {
  min-width: 0;
  overflow-wrap: anywhere;
  color: var(--color-text-emphasis);
  font-family: var(--font-mono);
  font-size: var(--text-sm);
  font-weight: var(--font-semibold);
}

.operation-info__meta {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: var(--spacing-xs) var(--spacing-md);
  min-width: 0;
  color: var(--color-text-muted);
  font-size: var(--text-xs);
}

.operation-info__meta-item {
  display: inline-flex;
  align-items: center;
  gap: var(--spacing-xs);
}

.operation-info__meta-item svg {
  width: 0.875rem;
  height: 0.875rem;
}

/* Inline progress: a 6px track (design §D.16) */
.operation-progress {
  display: flex;
  grid-column: 2;
  align-items: center;
  gap: var(--spacing-md);
  min-width: 0;
}

.operation-progress__bar {
  flex: 1 1 auto;
  min-width: 6rem;
  max-width: 14rem;
  height: 6px;
  overflow: hidden;
  border-radius: var(--radius-full);
  background: var(--color-surface-elevated);
}

.operation-progress__fill {
  width: var(--progress-pct, 0%);
  height: 100%;
  border-radius: var(--radius-full);
  background: var(--color-primary);
}

.operation-progress__fill--succeeded {
  background: var(--color-success);
}

.operation-progress__fill--failed {
  background: var(--color-danger);
}

.operation-progress__fill--canceled {
  background: var(--color-warning);
}

.operation-progress__value {
  min-width: 2.5rem;
  color: var(--color-text-muted);
  font-family: var(--font-mono);
  font-size: var(--text-xs);
  font-variant-numeric: tabular-nums;
  text-align: right;
}

.operation-progress__message {
  min-width: 0;
  max-width: 100%;
  overflow: hidden;
  color: var(--color-text-muted);
  font-size: var(--text-xs);
  text-overflow: ellipsis;
  white-space: nowrap;
}

.operation-duration {
  display: flex;
  grid-column: 2;
  align-items: baseline;
  gap: var(--spacing-xs);
}

.operation-duration__value {
  color: var(--color-text);
  font-family: var(--font-mono);
  font-size: var(--text-sm);
  font-weight: var(--font-medium);
  font-variant-numeric: tabular-nums;
}

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

.operation-pagination {
  margin-top: var(--spacing-lg);
}

.operation-pagination:empty {
  display: none;
}

/* -------------------------------------------
   Operation run: detail page
   ------------------------------------------- */

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

.operation-hero,
.operation-progress-section,
.operation-timeline,
.operation-details-grid,
.operation-log,
.operation-args {
  min-width: 0;
  border: 1px solid var(--color-border);
  border-radius: var(--radius-md);
  background: var(--color-surface);
}

.operation-hero {
  display: grid;
  grid-template-columns: auto minmax(0, 1fr);
  align-items: start;
  gap: var(--spacing-md) var(--spacing-lg);
  padding: var(--spacing-lg);
}

.operation-hero__status {
  display: grid;
  flex-shrink: 0;
  place-items: center;
  width: 2.5rem;
  height: 2.5rem;
  border: 1px solid var(--color-border-subtle);
  border-radius: var(--radius-md);
  background: var(--color-surface-raised);
  color: var(--color-neutral);
}

.operation-hero__status svg {
  width: 1.25rem;
  height: 1.25rem;
  stroke: currentColor;
}

.operation-hero__status--running { color: var(--color-info); }
.operation-hero__status--succeeded { color: var(--color-success); }
.operation-hero__status--failed { color: var(--color-danger); }
.operation-hero__status--canceled { color: var(--color-warning); }

.operation-hero__content {
  display: grid;
  gap: var(--spacing-sm);
  min-width: 0;
}

/* The page's one h1 */
.operation-hero__task {
  margin: 0;
  overflow-wrap: anywhere;
  color: var(--color-text-emphasis);
  font-family: var(--font-mono);
  font-size: var(--text-xl);
  font-weight: var(--font-semibold);
  letter-spacing: var(--tracking-tight);
}

.operation-hero__subtitle {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: var(--spacing-xs) var(--spacing-md);
  min-width: 0;
  overflow-wrap: anywhere;
  color: var(--color-text-muted);
  font-size: var(--text-sm);
}

.operation-hero__status-label {
  display: inline-flex;
  align-items: center;
  gap: var(--spacing-xs);
  height: 22px;
  padding: 0 var(--spacing-sm);
  border: 1px solid var(--color-neutral-border);
  border-radius: var(--radius-sm);
  background: var(--color-neutral-surface);
  color: var(--color-neutral);
  font-size: var(--text-xs);
  font-weight: var(--font-medium);
}

.operation-hero__status-label svg {
  width: 0.875rem;
  height: 0.875rem;
}

.operation-hero__status-label--running {
  border-color: var(--color-info-border);
  background: var(--color-info-surface);
  color: var(--color-info);
}

.operation-hero__status-label--succeeded {
  border-color: var(--color-success-border);
  background: var(--color-success-surface);
  color: var(--color-success);
}

.operation-hero__status-label--failed {
  border-color: var(--color-danger-border);
  background: var(--color-danger-surface);
  color: var(--color-danger);
}

.operation-hero__status-label--canceled {
  border-color: var(--color-warning-border);
  background: var(--color-warning-surface);
  color: var(--color-warning);
}

.operation-hero__actions {
  display: flex;
  flex-wrap: wrap;
  grid-column: 1 / -1;
  gap: var(--spacing-sm);
}

.operation-hero__actions:empty {
  display: none;
}

/* Progress */
.operation-progress-section {
  display: grid;
  gap: var(--spacing-md);
  padding: var(--spacing-lg);
}

.operation-progress-header {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: var(--spacing-md);
}

.operation-progress-title {
  color: var(--color-text);
  font-size: var(--text-sm);
  font-weight: var(--font-medium);
}

.operation-progress-percent {
  color: var(--color-text-emphasis);
  font-size: var(--text-2xl);
  font-weight: var(--font-semibold);
  font-variant-numeric: tabular-nums;
}

.operation-progress-large {
  height: 8px;
  overflow: hidden;
  border-radius: var(--radius-full);
  background: var(--color-surface-elevated);
}

.operation-progress-large__fill {
  width: var(--progress-pct, 0%);
  height: 100%;
  border-radius: var(--radius-full);
  background: var(--color-primary);
}

.operation-progress-large__fill--succeeded {
  background: var(--color-success);
}

.operation-progress-large__fill--failed {
  background: var(--color-danger);
}

.operation-progress-large__fill--canceled {
  background: var(--color-warning);
}

.operation-progress-message {
  margin: 0;
  overflow-wrap: anywhere;
  color: var(--color-text-muted);
  font-size: var(--text-sm);
}

/* Timeline: a vertical list on phones, a row of steps from 768px */
.operation-timeline {
  display: grid;
  gap: var(--spacing-md);
  margin: 0;
  padding: var(--spacing-lg);
  list-style: none;
}

.operation-timeline__item {
  position: relative;
  display: grid;
  grid-template-columns: 2rem minmax(0, 1fr);
  align-items: center;
  column-gap: var(--spacing-md);
}

.operation-timeline__dot {
  position: relative;
  z-index: 1;
  display: grid;
  grid-row: span 2;
  place-items: center;
  width: 2rem;
  height: 2rem;
  border: 1px solid var(--color-border-control);
  border-radius: var(--radius-full);
  background: var(--color-surface);
  color: var(--color-text-muted);
}

.operation-timeline__dot svg {
  width: 0.875rem;
  height: 0.875rem;
  stroke: currentColor;
}

.operation-timeline__item--completed .operation-timeline__dot {
  border-color: var(--color-success-border);
  background: var(--color-success-surface);
  color: var(--color-success);
}

.operation-timeline__item--active .operation-timeline__dot {
  border-color: var(--color-info-border);
  background: var(--color-info-surface);
  color: var(--color-info);
}

.operation-timeline__label {
  color: var(--color-text);
  font-size: var(--text-sm);
  font-weight: var(--font-medium);
}

.operation-timeline__time {
  color: var(--color-text-muted);
  font-family: var(--font-mono);
  font-size: var(--text-xs);
  font-variant-numeric: tabular-nums;
}

/* Error */
.operation-error {
  min-width: 0;
  overflow: hidden;
  border: 1px solid var(--color-danger-border);
  border-radius: var(--radius-md);
  background: var(--color-danger-surface);
}

.operation-error__header {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: var(--spacing-sm) var(--spacing-md);
  padding: var(--spacing-md) var(--spacing-lg);
  border-bottom: 1px solid var(--color-danger-border);
}

.operation-error__icon {
  width: 1.25rem;
  height: 1.25rem;
  stroke: var(--color-danger);
  stroke-width: 2;
}

.operation-error__title {
  color: var(--color-danger);
  font-size: var(--text-sm);
  font-weight: var(--font-semibold);
}

.operation-error__class {
  min-width: 0;
  margin-left: auto;
  overflow-wrap: anywhere;
  color: var(--color-danger);
  font-family: var(--font-mono);
  font-size: var(--text-xs);
}

.operation-error__message {
  padding: var(--spacing-md) var(--spacing-lg);
  overflow-wrap: anywhere;
  color: var(--color-text);
  font-size: var(--text-sm);
  line-height: var(--leading-relaxed);
}

.operation-error__backtrace {
  max-height: 12.5rem;
  padding: var(--spacing-md) var(--spacing-lg);
  overflow-y: auto;
  border-top: 1px solid var(--color-danger-border);
  background: var(--color-surface);
  color: var(--color-text-muted);
  font-family: var(--font-mono);
  font-size: var(--text-xs);
  line-height: var(--leading-relaxed);
  white-space: pre-wrap;
  word-break: break-all;
}

/* Arguments */
.operation-args,
.operation-log {
  overflow: hidden;
}

.operation-args__header,
.operation-log__header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--spacing-md);
  padding: var(--spacing-md) var(--spacing-lg);
  border-bottom: 1px solid var(--color-border-subtle);
  background: var(--color-surface-subtle);
}

.operation-args__title,
.operation-log__title {
  display: flex;
  align-items: center;
  gap: var(--spacing-sm);
  margin: 0;
  color: var(--color-text);
  font-size: var(--text-sm);
  font-weight: var(--font-semibold);
}

.operation-args__content {
  margin: 0;
  padding: var(--spacing-md) var(--spacing-lg);
  overflow-x: 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);
}

.operation-args__key {
  color: var(--color-text-emphasis);
  font-weight: var(--font-semibold);
}

.operation-args__value {
  color: var(--color-text-muted);
}

.operation-args__value--string {
  color: var(--color-text);
}

/* Details */
.operation-details-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(min(12rem, 100%), 1fr));
  gap: var(--spacing-md) var(--spacing-xl);
  padding: var(--spacing-lg);
}

.operation-detail-item {
  display: grid;
  gap: var(--spacing-xs);
  min-width: 0;
}

.operation-detail-item__label {
  color: var(--color-text-muted);
  font-size: var(--text-xs);
  font-weight: var(--font-medium);
}

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

.operation-detail-item__value--mono {
  font-family: var(--font-mono);
}

/* Log */
.operation-log__count {
  padding: 0 var(--spacing-sm);
  border: 1px solid var(--color-neutral-border);
  border-radius: var(--radius-sm);
  background: var(--color-neutral-surface);
  color: var(--color-neutral);
  font-size: var(--text-xs);
  font-weight: var(--font-medium);
  font-variant-numeric: tabular-nums;
}

.operation-log__content {
  max-height: 25rem;
  overflow-y: auto;
  font-family: var(--font-mono);
  font-size: var(--text-xs);
  line-height: var(--leading-relaxed);
}

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

.operation-log__line:last-child {
  border-bottom: 0;
}

.operation-log__timestamp {
  color: var(--color-text-muted);
  font-variant-numeric: tabular-nums;
  white-space: nowrap;
  user-select: none;
}

.operation-log__message {
  overflow-wrap: anywhere;
  color: var(--color-text);
}

.operation-log__message--result {
  color: var(--color-success);
}

.operation-log__message--error {
  color: var(--color-danger);
}

.operation-log__empty {
  padding: var(--spacing-2xl) var(--spacing-lg);
  color: var(--color-text-muted);
  font-size: var(--text-sm);
  text-align: center;
}

/* New operation form */
.operation-form {
  max-width: var(--form-max-width);
}

.operation-form .operation-form__args {
  font-family: var(--font-mono);
  font-size: var(--text-sm);
}

/* -------------------------------------------
   Audit log, SIEM delivery and audit exports
   ------------------------------------------- */

.audit-log {
  display: grid;
  gap: var(--spacing-xl);
  min-width: 0;
}

.audit-log .page-header {
  margin-bottom: 0;
}

.card.audit-log__section {
  display: grid;
  gap: var(--spacing-md);
  padding: var(--spacing-lg);
}

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

.audit-log__section > p {
  max-width: var(--prose-max-width);
  margin: 0;
  overflow-wrap: anywhere;
  color: var(--color-text-muted);
  font-size: var(--text-sm);
}

.audit-log__form {
  display: grid;
  gap: var(--spacing-lg);
  min-width: 0;
}

.audit-log__filters {
  display: grid;
  grid-template-columns: minmax(0, 1fr);
  gap: var(--spacing-md) var(--spacing-lg);
}

.audit-log__filters .form__group,
.audit-log__form .form__group {
  margin: 0;
}

/* Multi-selects list their options; no chevron. */
.audit-log__multi {
  height: auto;
  padding: var(--spacing-xs);
  background-image: none;
}

.audit-log__form--narrow {
  max-width: var(--form-max-width);
}

.audit-log__actions {
  display: flex;
  flex-wrap: wrap;
  gap: var(--spacing-sm);
}

.audit-log__cell-actions {
  display: flex;
  flex-wrap: wrap;
  gap: var(--spacing-xs);
}

.audit-log .code-link {
  overflow-wrap: anywhere;
  font-family: var(--font-mono);
  font-size: var(--text-xs);
}

.audit-log .code-block {
  max-height: 40rem;
  margin: 0;
  overflow: auto;
}

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

.audit-log__facts {
  display: grid;
  grid-template-columns: minmax(0, 1fr);
  gap: var(--spacing-xs) var(--spacing-lg);
  margin: 0;
}

.audit-log__facts dt {
  color: var(--color-text-muted);
  font-size: var(--text-sm);
}

.audit-log__facts dd {
  margin: 0 0 var(--spacing-sm);
  overflow-wrap: anywhere;
  color: var(--color-text);
}

.audit-log__secret {
  display: grid;
  gap: var(--spacing-sm);
  margin: 0;
}

/* -------------------------------------------
   Breakpoints
   ------------------------------------------- */

@media (min-width: 640px) {
  .admin-hub .card {
    flex-direction: row;
    align-items: center;
    justify-content: space-between;
    gap: var(--spacing-lg);
  }

  .admin-hub .card__header {
    flex: 1 1 auto;
    min-width: 0;
  }

  .admin-hub .card__body {
    flex-shrink: 0;
    padding: 0;
  }

  .audit-log__filters {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  .audit-log__facts {
    grid-template-columns: 10rem minmax(0, 1fr);
  }

  .audit-log__facts dd {
    margin: 0;
  }
}

@media (min-width: 768px) {
  .operation-row {
    grid-template-columns: auto minmax(0, 1fr) minmax(10rem, 14rem) 6rem;
    align-items: center;
    column-gap: var(--spacing-lg);
  }

  .operation-status {
    margin-top: 0;
  }

  .operation-progress,
  .operation-duration {
    grid-column: auto;
  }

  .operation-duration {
    flex-direction: column;
    align-items: flex-end;
    gap: 2px;
  }

  .operation-hero {
    grid-template-columns: auto minmax(0, 1fr) auto;
    align-items: center;
    padding: var(--spacing-xl);
  }

  .operation-hero__actions {
    grid-column: auto;
    justify-content: flex-end;
  }

  .operation-progress-section,
  .operation-details-grid {
    padding: var(--spacing-xl);
  }

  .operation-timeline {
    display: flex;
    gap: 0;
    padding: var(--spacing-xl) var(--spacing-lg);
  }

  .operation-timeline__item {
    display: flex;
    flex: 1 1 0;
    flex-direction: column;
    align-items: center;
    gap: var(--spacing-xs);
    padding: 0 var(--spacing-md);
    text-align: center;
  }

  /* The connector to the next step */
  .operation-timeline__item:not(:last-child)::after {
    content: "";
    position: absolute;
    top: 1rem;
    right: calc(-50% + 1.25rem);
    left: calc(50% + 1.25rem);
    height: 1px;
    background: var(--color-border);
  }

  .operation-timeline__item--completed:not(:last-child)::after {
    background: var(--color-success-border);
  }

  .operation-timeline__dot {
    margin-bottom: var(--spacing-xs);
  }

  .card.audit-log__section {
    padding: var(--spacing-xl);
  }
}

@media (min-width: 1024px) {
  .operation-hero__task {
    font-size: var(--text-2xl);
  }

  .audit-log__filters {
    grid-template-columns: repeat(3, minmax(0, 1fr));
  }
}

@media (prefers-reduced-motion: reduce) {
  .operation-row {
    transition: none;
  }
}
