/* The admin pages in Settings (admin.js). */

.admin-stats {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 1rem;
}

/* Each figure is a link to the card it sums up. */
.admin-stat {
  display: block;
  padding: 1rem 1.125rem;
  background: var(--bg-card);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-md);
  box-shadow: var(--shadow-sm);
  min-width: 0;
  color: inherit;
  text-decoration: none;
  transition: border-color 150ms ease;
}

@media (hover: hover) {
  .admin-stat:hover {
    border-color: var(--border-strong);
  }
}

.admin-stat-value {
  font-family: var(--font-display);
  margin-top: 0.3rem;
  font-size: var(--fs-title);
  font-weight: 700;
  letter-spacing: -0.02em;
  color: var(--text-primary);
  font-variant-numeric: tabular-nums;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.admin-stat-value.is-warn { color: var(--tint-amber-fg); }
.admin-stat-value.is-bad { color: var(--tint-red-fg); }

.admin-stat-sub {
  margin-top: 0.15rem;
  min-height: 1.1em;
  font-size: var(--fs-label);
  color: var(--text-muted);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.admin-card-title {
  font-size: var(--fs-body);
  margin-bottom: 0.25rem;
}

.admin-card-desc {
  margin-bottom: 1rem;
}

/* A description with "How this works" under it: the space goes under that instead. */
.admin-card-desc:has(+ .how-this-works) {
  margin-bottom: 0;
}

/* A card's title and description, with the switch for what it lists at the line's end,
   under them on a phone. */
.admin-card-head {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: var(--space-3) var(--space-4);
}

.admin-card-head > :first-child {
  min-width: 0;
}

.admin-card-head .seg-toggle {
  flex: 0 0 auto;
  margin-bottom: 1rem;
}

@media (max-width: 600px) {
  .admin-card-head {
    flex-direction: column;
  }
}

/* An opened run's errors. */
.cron-run-errors {
  margin-top: var(--space-2);
  font-size: var(--fs-label);
}

.run-errors-title {
  margin: 0;
  font-family: var(--font-mono);
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: var(--ink-3);
}

.cron-run-errors ul {
  margin: 0.375rem 0 0;
  padding-left: 1.1rem;
  font-family: var(--font-mono);
  line-height: 1.45;
  color: var(--text-secondary);
  word-break: break-word;
  max-width: 40rem;
}

.admin-inline-form {
  display: flex;
  gap: 0.5rem;
  margin-bottom: 1rem;
}

.admin-inline-form .form-input {
  flex: 1;
  min-width: 0;
}

.admin-list {
  display: flex;
  flex-direction: column;
  border: 1px solid var(--border-color);
  border-radius: var(--radius-md);
  overflow: hidden;
}

.admin-list > .metric-subtext {
  padding: 0.875rem 1rem;
}

.admin-list-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.75rem;
  padding: 0.625rem 0.75rem 0.625rem 1rem;
  background: var(--bg-card);
}

.admin-list-row + .admin-list-row {
  border-top: 1px solid var(--border-subtle);
}

.admin-list-email {
  font-size: var(--fs-body-sm);
  font-weight: 500;
  color: var(--text-primary);
  overflow-wrap: anywhere;
}

.admin-list-meta {
  font-size: var(--fs-label);
  color: var(--text-muted);
}

/* Diagnostics: a label column and a value column, collapsing to stacked pairs where
   the box is narrow. */
.admin-kv {
  container: admin-kv / inline-size;
  display: flex;
  flex-direction: column;
  border: 1px solid var(--border-color);
  border-radius: var(--radius-md);
  overflow: hidden;
}

/* One box drawn from two lists, each filled on its own: the server's rows and this
   device's. */
.admin-kv-part {
  display: contents;
}

.admin-kv-part + .admin-kv-part > .admin-kv-row:first-child {
  border-top: 1px solid var(--border-subtle);
}

.admin-kv-row {
  display: grid;
  grid-template-columns: 11rem minmax(0, 1fr);
  gap: 1rem;
  padding: 0.7rem 1rem;
  align-items: baseline;
}

.admin-kv-row + .admin-kv-row {
  border-top: 1px solid var(--border-subtle);
}

.admin-kv dt {
  font-size: var(--fs-meta);
  color: var(--text-secondary);
}

.admin-kv dd {
  margin: 0;
  font-size: var(--fs-body-sm);
  color: var(--text-primary);
  min-width: 0;
}

.admin-kv-note {
  margin-top: 0.2rem;
  font-size: var(--fs-label);
  color: var(--text-muted);
}

.admin-mono {
  font-family: var(--font-mono);
  font-size: var(--fs-meta);
  overflow-wrap: anywhere;
}

.admin-copy-row {
  display: flex;
  align-items: flex-start;
  gap: 0.5rem;
}

.admin-copy-row .admin-mono {
  flex: 1;
  padding: 0.45rem 0.6rem;
  background: var(--bg-inset);
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-sm);
  user-select: all;
}

@container admin-kv (width < 30rem) {
  .admin-kv-row {
    grid-template-columns: minmax(0, 1fr);
    gap: 0.2rem;
  }
  .admin-copy-row {
    flex-direction: column;
    align-items: stretch;
  }
}

@media (max-width: 600px) {
  /* Two lines kept for the line under a figure, which can wrap to a second once it
     lands, so the tiles stay the height their skeleton was. */
  .admin-stat-sub {
    min-height: 2lh;
    white-space: normal;
  }
  .admin-inline-form {
    flex-direction: column;
  }
}

/* ----------------------------------------------------------------------------
   Evergreen: one readable column, words instead of chips, and nightly runs as
   blocks of short lines that fit a phone.
   ---------------------------------------------------------------------------- */
/* A state in words, coloured only when it needs someone. */
.admin-flag {
  font-size: var(--fs-meta);
  font-weight: 500;
  color: var(--ink-2);
}

.admin-flag.is-warn { color: var(--attn); }
.admin-flag.is-bad { color: var(--crit); }

/* People & sign-in: an address, and where it stands as chips under it. */
.person-main {
  display: flex;
  flex-direction: column;
  gap: var(--space-1);
  min-width: 0;
}

.person-chips {
  display: flex;
  flex-wrap: wrap;
  gap: var(--space-1);
}

.person-chip {
  padding: 1px var(--space-2);
  border: 1px solid var(--line);
  border-radius: var(--radius-full);
  font-size: var(--fs-label);
  color: var(--ink-2);
  white-space: nowrap;
}

.person-chip.is-admin {
  border-color: transparent;
  background: var(--accent-soft);
  color: var(--accent);
}

.person-chip.is-attn {
  border-color: transparent;
  background: var(--attn-soft);
  color: var(--attn);
}

/* The admin pages in Settings: their cards one under another, as on the console. */
.settings-admin {
  display: contents;
}

.settings-admin-page {
  display: flex;
  flex-direction: column;
  gap: var(--space-4);
}

.settings-admin-page[hidden] {
  display: none;
}

/* The next run, above the runs it is heading on from. */
.run-next {
  margin: 0 0 var(--space-3);
  padding: var(--space-3) var(--space-4);
  border-radius: var(--radius-md);
  background: var(--accent-soft);
  font-size: var(--fs-body-sm);
  line-height: 1.5;
  color: var(--ink);
}

.run-next strong {
  font-weight: 600;
  white-space: nowrap;
}

.run-next-schedule {
  display: block;
  color: var(--ink-2);
}

.run-empty {
  margin: 0;
  font-size: var(--fs-body-sm);
  color: var(--ink-3);
}

.run-list {
  list-style: none;
  margin: 0;
  padding: 0;
  border: 1px solid var(--line);
  border-radius: var(--radius-md);
}

.run-row {
  min-width: 0;
}

.run-row + .run-row {
  border-top: 1px solid var(--line);
}

/* A run is one line, the whole of it the control that opens it, with a chevron that
   turns as it does. */
.run-line {
  display: block;
  position: relative;
  padding: var(--space-3) calc(var(--space-4) + 1.25rem) var(--space-3) var(--space-4);
  cursor: pointer;
  list-style: none;
}

.run-line::-webkit-details-marker {
  display: none;
}

.run-line::after {
  content: "";
  position: absolute;
  right: var(--space-4);
  top: 50%;
  width: 0.45rem;
  height: 0.45rem;
  border-right: 1.5px solid var(--ink-3);
  border-bottom: 1.5px solid var(--ink-3);
  transform: translateY(-70%) rotate(45deg);
  transition: transform 150ms ease;
}

.run-entry[open] > .run-line::after {
  transform: translateY(-30%) rotate(-135deg);
}

.run-entry > :not(summary) {
  margin-inline: var(--space-4);
}

.run-entry > :last-child {
  margin-bottom: var(--space-3);
}

.run-entry > .run-facts {
  margin-top: 0;
}

.run-head {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: var(--space-3);
}

.run-meta {
  display: block;
}

/* An error every run since some night has reported, said once above the runs. */
.run-ongoing {
  margin: 0 0 var(--space-3);
  padding: var(--space-3) var(--space-4);
  border-radius: var(--radius-md);
  background: var(--attn-soft);
}

.run-ongoing-title {
  margin: 0 0 var(--space-1);
  font-family: var(--font-mono);
  font-size: var(--fs-label);
  font-weight: 600;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: var(--attn);
}

.run-ongoing-list {
  list-style: none;
  margin: 0;
  padding: 0;
}

.run-ongoing-item + .run-ongoing-item {
  margin-top: var(--space-2);
}

.run-ongoing-error {
  margin: 2px 0 0;
  font-family: var(--font-mono);
  font-size: var(--fs-label);
  line-height: 1.45;
  color: var(--ink-2);
  overflow-wrap: anywhere;
}

.run-when {
  font-size: var(--fs-body-sm);
  font-weight: 500;
  color: var(--ink);
}

.run-result {
  flex: 0 0 auto;
  font-size: var(--fs-meta);
  font-weight: 500;
}

.run-ok { color: var(--ink-3); }
.run-attn { color: var(--attn); }
.run-crit { color: var(--crit); }
.run-bad { color: var(--crit); }

.run-meta {
  margin-top: 2px;
  font-size: var(--fs-meta);
  color: var(--ink-3);
}

/* What a run did: three labelled facts side by side where there is room, stacked on a
   phone. */
.run-facts {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: var(--space-2) var(--space-4);
  margin: var(--space-2) 0 0;
}

.run-facts dt {
  font-family: var(--font-mono);
  font-size: var(--fs-label);
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: var(--ink-3);
}

.run-facts dd {
  margin: 2px 0 0;
  font-size: var(--fs-meta);
  color: var(--ink-2);
  overflow-wrap: anywhere;
}

.run-sub {
  color: var(--ink-3);
}

.run-more {
  margin-top: var(--space-3);
}

.run-more[hidden] {
  display: none;
}

@media (max-width: 600px) {
  .run-line {
    padding: var(--space-3) calc(var(--space-3) + 1.25rem) var(--space-3) var(--space-3);
  }

  .run-line::after {
    right: var(--space-3);
  }

  .run-entry > :not(summary) {
    margin-inline: var(--space-3);
  }

  .run-facts {
    grid-template-columns: minmax(0, 1fr);
  }

  .run-facts > div {
    display: grid;
    grid-template-columns: 5.5rem minmax(0, 1fr);
    gap: var(--space-2);
    align-items: baseline;
  }

  .run-facts dd {
    margin: 0;
  }
}

/* Loading: the console's rows while its first data is on the way (drawAdminSkeleton in
   admin.js), spaced as the rows they stand for. */
.admin-list .skel-row {
  padding: 0.625rem 0.75rem 0.625rem 1rem;
  background: var(--bg-card);
}

.admin-list .skel-row + .skel-row {
  border-top-color: var(--border-subtle);
}

#admin-cron-runs-list .skel-row {
  padding-inline: 0;
}

/* The Filing card's lists, each under a small heading. */
.quality-heading {
  margin: var(--space-3) 0 var(--space-1);
  font-size: var(--fs-label);
  font-weight: 600;
  color: var(--ink-3);
}

/* Critical path traces: one line per trace, opening onto its path. On a phone a step's
   name wraps between its parts (admin.js), and a table still too wide scrolls sideways. */
.trace + .trace {
  border-top: 1px solid var(--border-subtle);
}

.trace-filter {
  margin-bottom: var(--space-2);
}

.trace-device {
  color: var(--text-secondary);
}

.trace-source {
  margin: 0 0 var(--space-2);
}

.trace summary {
  padding: 0.6rem 0;
  font-size: var(--fs-body-sm);
  color: var(--text-primary);
  cursor: pointer;
}

.trace-table-wrap {
  overflow-x: auto;
  margin-bottom: var(--space-2);
}

.trace-table {
  width: 100%;
  border-collapse: collapse;
  font-size: var(--fs-meta);
  font-variant-numeric: tabular-nums;
}

.trace-table th,
.trace-table td {
  padding: 0.3rem 0.5rem;
  text-align: right;
  white-space: nowrap;
  border-bottom: 1px solid var(--border-subtle);
}

.trace-table th {
  font-weight: 600;
  color: var(--text-secondary);
}

.trace-table th:first-child,
.trace-table td:first-child {
  text-align: left;
  white-space: normal;
  min-width: 11rem;
}

.trace-table .admin-mono {
  overflow-wrap: normal;
}

.trace-table .trace-depth-1 td { color: var(--text-secondary); }
.trace-table .trace-depth-1 td:first-child { padding-left: 1rem; }
.trace-table .trace-depth-2 td { color: var(--text-muted); }
.trace-table .trace-depth-2 td:first-child { padding-left: 1.75rem; }

.trace-note {
  margin: 0 0 var(--space-2);
}

/* The switch for suggestions from notes, under the person's own AI switches on the Rules
   page, set apart from them because it is for everyone. */
.admin-note-suggest {
  margin-top: var(--space-2);
  padding-top: var(--space-4);
  border-top: 1px solid var(--line);
}

.admin-note-suggest .field-help {
  margin: var(--space-2) 0 0;
}

.admin-switch:has(input:disabled),
.admin-switch input:disabled {
  cursor: default;
}
