/* Admin pages (docs/design-system.md, Surfaces and Type): sections are a
   section title over a white panel, 32px apart; facts are rows of a note
   label and a value; ids, codes and payloads are Space Grotesk with
   tabular figures, never mono. */

.admin__sections {
  display: flex;
  flex-direction: column;
  gap: var(--space-8);
}

/* Panels of one section, such as the outlines of a generation. */
.admin__stack {
  display: flex;
  flex-direction: column;
  gap: var(--space-4);
}

/* The spinner while a page or a section loads. */
.admin__placeholder {
  display: flex;
  justify-content: center;
  padding: var(--space-12);
}

/* A table inside a panel: its cells carry their own padding, so the table
   steps out by that padding and its text lines up with the panel's. */
.admin__panel > .table {
  margin: calc(-1 * var(--space-3)) calc(-1 * var(--space-4));
}

.admin__filter {
  margin-bottom: var(--space-6);
}

/* A row of list filters inside a panel; on a narrow screen they wrap. */
.admin__filters {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(180px, 1fr));
  gap: var(--space-4);
}

/* The active Generation chip and "Clear filters" under the filters. */
.admin__filter-actions {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: var(--space-4);
  margin-top: var(--space-4);
}

/* Splits of the filtered totals, two per row on a wide screen. */
.admin__breakdowns {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(320px, 1fr));
  gap: var(--space-8);
}

/* Paging under a long list: "Page 2 of 7, 312 calls", then Previous and
   Next. */
.admin__pager {
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: var(--space-4);
}

.admin__note {
  margin: 0;
  font-size: var(--text-note);
  color: var(--color-text-muted);
}

.admin__footnote {
  margin-top: var(--space-4);
}

.admin__note--error {
  color: var(--color-error);
}

.admin__strong {
  font-weight: var(--weight-semibold);
}

/* A warning before an action: status text, never a status fill. */
.admin__warning {
  margin: 0;
  font-size: var(--text-note);
  color: var(--color-warning);
}

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

/* A line of facts: "Signed up 12/10/2026  Last active ...". */
.admin__meta {
  display: flex;
  flex-wrap: wrap;
  gap: var(--space-2) var(--space-6);
  margin: 0 0 var(--space-4);
  font-size: var(--text-note);
  color: var(--color-text-muted);
}

.admin__meta:last-child {
  margin-bottom: 0;
}

/* Facts as rows of a note label and a value (.card__row draws the
   line-soft lines between them). */
.admin__row {
  display: grid;
  grid-template-columns: minmax(160px, max-content) minmax(0, 1fr);
  column-gap: var(--space-6);
  align-items: baseline;
}

.admin__row-label {
  font-size: var(--text-note);
  color: var(--color-text-muted);
}

.admin__row-value {
  min-width: 0;
  white-space: pre-wrap;
  overflow-wrap: anywhere;
  font-variant-numeric: tabular-nums;
}

.admin__chips {
  display: flex;
  flex-wrap: wrap;
  gap: var(--space-2);
}

/* A payload, a document or a URL: white on white, so it takes the line. */
.admin__code {
  margin: 0;
  padding: var(--space-3) var(--space-4);
  font-family: var(--font-sans);
  font-size: var(--text-note);
  line-height: var(--leading-normal);
  font-variant-numeric: tabular-nums;
  white-space: pre-wrap;
  word-break: break-word;
  color: var(--color-text);
  background: var(--color-bg-surface);
  border: var(--border-width) solid var(--color-border);
  border-radius: var(--border-radius);
  max-height: 60vh;
  overflow: auto;
}

.admin__code--short {
  max-height: 40vh;
}

.admin__block + .admin__block {
  margin-top: var(--space-6);
}

.admin__block-title {
  margin: 0 0 var(--space-2);
  font-size: var(--text-note);
  color: var(--color-text-muted);
}

/* The fields of a modal or a form panel. */
.admin__form {
  display: flex;
  flex-direction: column;
  gap: var(--space-4);
}

.admin__actions {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: var(--space-4);
}

.admin__actions--end {
  justify-content: flex-end;
}

/* The ids under the page title of a detail page, each with a copy button. */
.admin-detail__head {
  margin-bottom: var(--space-12);
}

.admin-detail__head .page-header {
  margin-bottom: var(--space-4);
}

.admin-detail__field {
  display: flex;
  align-items: center;
  gap: var(--space-2);
  font-size: var(--text-note);
  color: var(--color-text-muted);
}

.admin-detail__field-label {
  min-width: 96px;
}

.admin-detail__field-value {
  min-width: 0;
  overflow-wrap: anywhere;
  color: var(--color-text);
  font-variant-numeric: tabular-nums;
}

/* Inside a line of text the copy button is a plain icon. */
.admin-detail__field .button--toolbar {
  background: none;
}

.admin-detail__head .admin__actions {
  margin-top: var(--space-4);
}

.admin-detail__tabs {
  margin-bottom: var(--space-8);
}

/* The daily spend chart; its empty label is HTML over the chart, since
   SVG text would stretch with it. */
.admin-sparkline {
  position: relative;
}

.admin-sparkline__empty {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: var(--text-note);
  color: var(--color-text-muted);
}

/* The credits balance: the number in the section title's size. */
.admin-credits__balance {
  display: flex;
  flex-wrap: wrap;
  align-items: baseline;
  gap: var(--space-2) var(--space-6);
}

.admin-credits__amount {
  font-size: var(--text-section);
  font-weight: var(--weight-semibold);
  font-variant-numeric: tabular-nums;
}

.admin-credits__balance + .admin__actions {
  margin: var(--space-4) 0 var(--space-8);
}

/* A list whose rows open in place (generations, posts): a chevron, the
   facts of the row, and under an open row its detail on the page grey. */
.admin-expand__item + .admin-expand__item {
  border-top: var(--border-width) solid var(--color-border-subtle);
}

.admin-expand__row {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: var(--space-2) var(--space-4);
  width: 100%;
  padding: var(--space-3) 0;
  font: inherit;
  text-align: left;
  color: inherit;
  background: none;
  border: 0;
  cursor: pointer;
}

.admin-expand__row:focus-visible {
  outline: 2px solid var(--color-text);
  outline-offset: 2px;
}

.admin-expand__chevron {
  display: inline-flex;
  color: var(--color-text-muted);
}

.admin-expand__cell {
  min-width: 120px;
  font-size: var(--text-note);
  color: var(--color-text-muted);
  font-variant-numeric: tabular-nums;
}

.admin-expand__cell--success {
  color: var(--color-success);
}

.admin-expand__main {
  flex: 1 1 240px;
  min-width: 0;
  overflow: hidden;
  white-space: nowrap;
  text-overflow: ellipsis;
}

.admin-expand__body {
  margin-bottom: var(--space-3);
  padding: var(--space-4);
  background: var(--color-bg-page);
  border-radius: var(--border-radius);
}

.admin-expand__body > .admin__note {
  margin-bottom: var(--space-4);
}

/* One outline of a generation: white on the grey of the open row. */
.admin-outline {
  padding: var(--space-4);
  background: var(--color-bg-surface);
  border-radius: var(--border-radius);
}

.admin-outline + .admin-outline {
  margin-top: var(--space-4);
}

.admin-outline--rejected {
  opacity: 0.5;
}

.admin-outline__head {
  display: flex;
  align-items: baseline;
  gap: var(--space-4);
  margin-bottom: var(--space-2);
}

.admin-outline__title {
  flex: 1;
  min-width: 0;
  margin: 0 0 var(--space-2);
  font-size: var(--text-body);
  font-weight: var(--weight-semibold);
}

.admin-outline__head .admin-outline__title {
  margin: 0;
}

.admin-outline__description {
  margin: 0 0 var(--space-3);
  font-size: var(--text-note);
  color: var(--color-text-muted);
  white-space: pre-wrap;
}

.admin-outline__slide {
  display: flex;
  align-items: baseline;
  gap: var(--space-3);
  padding: var(--space-2) 0;
  font-size: var(--text-note);
  border-top: var(--border-width) solid var(--color-border-subtle);
}

.admin-outline__slide-number {
  min-width: 32px;
  color: var(--color-text-muted);
  font-variant-numeric: tabular-nums;
}

.admin-outline__slide-text {
  flex: 1;
  min-width: 0;
}

.admin-outline__feedback {
  margin-top: var(--space-3);
  font-size: var(--text-note);
}

/* Slides of an open post, each as the user sees it. */
.admin-slides {
  display: flex;
  flex-wrap: wrap;
  gap: var(--space-4);
}

.admin-slides__item {
  flex: 0 0 200px;
  display: flex;
  flex-direction: column;
  gap: var(--space-2);
}

.admin-slides__head {
  display: flex;
  align-items: center;
  gap: var(--space-2);
  font-size: var(--text-note);
  color: var(--color-text-muted);
  font-variant-numeric: tabular-nums;
}

.admin-slides__preview {
  cursor: zoom-in;
}

/* A slide or an image at full size in a modal. */
.admin-viewer {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: var(--space-3);
}

.admin-viewer__image {
  max-width: 100%;
  max-height: 70vh;
  object-fit: contain;
  border-radius: var(--radius-media);
}

.admin-viewer__caption {
  font-size: var(--text-note);
  color: var(--color-text-muted);
  text-align: center;
}

.admin-thumbs {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(80px, 1fr));
  gap: var(--space-2);
}

.admin-thumbs__image {
  width: 100%;
  aspect-ratio: 1;
  object-fit: cover;
  border-radius: var(--radius-thumb);
  cursor: zoom-in;
}

.admin-connection {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: var(--space-2) var(--space-4);
}

.admin-connection__avatar {
  width: var(--space-6);
  height: var(--space-6);
  border-radius: var(--radius-thumb);
  object-fit: cover;
}

.admin-connection__dates {
  margin-left: auto;
  display: flex;
  flex-wrap: wrap;
  gap: var(--space-2) var(--space-4);
  font-size: var(--text-note);
  color: var(--color-text-muted);
  font-variant-numeric: tabular-nums;
}

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

.admin-list__item {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--space-4);
}

/* Templates: a row is the name over its slide count, then the Published
   checkbox and the actions. */
.admin-templates__row {
  flex-wrap: wrap;
}

.admin-templates__main {
  flex: 1 1 200px;
  min-width: 0;
  display: flex;
  flex-direction: column;
  gap: var(--space-1);
}

.admin-templates__name {
  overflow: hidden;
  white-space: nowrap;
  text-overflow: ellipsis;
}

/* The layout's slides and the example's, each strip under its label. */
.admin-templates__previews {
  display: flex;
  flex-wrap: wrap;
  gap: var(--space-4);
  margin-top: var(--space-2);
}

.admin-templates__strip {
  display: flex;
  flex-direction: column;
  gap: var(--space-1);
  min-width: 0;
}

.admin-templates__thumbs {
  display: flex;
  gap: var(--space-1);
  overflow-x: auto;
}

.admin-templates__example {
  display: flex;
  align-items: center;
  gap: var(--space-2);
}

.admin-templates__actions {
  display: flex;
  align-items: center;
  gap: var(--space-4);
}

/* Feature flags: the email field and Add user on one line. */
.admin-flags__add {
  display: flex;
  align-items: flex-end;
  gap: var(--space-2);
}

.admin-flags__add > .form-field {
  flex: 1;
  min-width: 0;
}

/* Prompts: the validation errors a save answers. */
.admin-prompts__errors {
  margin: 0;
  padding-left: var(--space-6);
  font-size: var(--text-note);
  color: var(--color-text-muted);
}

/* One segment of the prompt preview: an editable segment in ink with an
   ink bar, a fixed one in muted text. */
.admin-segment {
  padding: var(--space-3);
}

.admin-segment--editable {
  border-left: var(--accent-bar-height) solid var(--color-text);
}

.admin-segment__label {
  margin: 0 0 var(--space-1);
  font-size: var(--text-note);
  font-weight: var(--weight-semibold);
}

.admin-segment__text {
  margin: 0;
  font-family: var(--font-sans);
  font-size: var(--text-note);
  line-height: var(--leading-relaxed);
  white-space: pre-wrap;
  word-break: break-word;
  color: var(--color-text-muted);
}

.admin-segment--editable .admin-segment__text {
  color: var(--color-text);
}

.admin-segments {
  display: flex;
  flex-direction: column;
  gap: var(--space-2);
  margin-top: var(--space-4);
}

/* Prompts: the AI operations as a rail beside the chosen operation's
   card. A rail row is the operation over its model as a note. */
.admin-ai-ops {
  display: grid;
  grid-template-columns: 280px minmax(0, 1fr);
  gap: var(--space-6);
  align-items: start;
}

.admin-ai-ops__rail {
  position: sticky;
  top: var(--space-8);
  padding: var(--space-4);
}

.admin-ai-ops__item {
  flex-direction: column;
  align-items: flex-start;
  gap: 0;
  text-align: left;
}

.admin-ai-ops__item-name {
  overflow-wrap: anywhere;
}

/* The card's tabs under the version line. */
.admin-prompt__tabs {
  margin: var(--space-4) 0 var(--space-2);
}

/* The Prompt tab: the settings row stays in view while the tab scrolls;
   under it the editor column beside the preview column, each at most
   820px (about 90 characters a line), at the left of the card. The tab
   is a query container: narrower than 1200px, the columns stack and the
   preview stops sticking. */
.admin-prompt {
  container-type: inline-size;
}

.admin-prompt__settings {
  position: sticky;
  top: 0;
  z-index: var(--z-sticky);
  display: flex;
  flex-wrap: wrap;
  align-items: flex-end;
  gap: var(--space-4);
  padding: var(--space-4) 0;
  background: var(--color-bg-surface);
}

.admin-prompt__settings-actions {
  margin-left: auto;
}

/* A select as wide as its options, not as the column; on a phone an
   option longer than the row (a long email) does not push the row out. */
.admin-prompt__select {
  width: auto;
  max-width: 100%;
}

.admin-prompt__settings > .form-field,
.admin-prompt__preview-head > .form-field {
  max-width: 100%;
}

.admin-prompt__columns {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 820px));
  justify-content: start;
  align-items: start;
  gap: var(--space-6);
  margin-top: var(--space-4);
}

.admin-prompt__editor,
.admin-prompt__preview {
  display: flex;
  flex-direction: column;
  gap: var(--space-4);
}

/* The settings row is 100px tall (its label, the 40px control and 16px
   above and under it), so the preview sticks under it and scrolls
   inside; the assembled text scrolls with the column, not on its own. */
.admin-prompt__preview {
  position: sticky;
  top: 100px;
  max-height: calc(100vh - 100px);
  overflow: auto;
}

.admin-prompt__preview .admin__code {
  max-height: none;
}

.admin-prompt__preview-head {
  display: flex;
  flex-wrap: wrap;
  align-items: flex-end;
  gap: var(--space-4);
}

/* The Draft badge and "Updating...", centred on the controls' height. */
.admin-prompt__preview-state {
  display: flex;
  align-items: center;
  gap: var(--space-4);
  height: var(--control-height);
}

@container (max-width: 1200px) {
  .admin-prompt__columns {
    grid-template-columns: minmax(0, 820px);
  }

  .admin-prompt__preview {
    position: static;
    max-height: none;
    overflow: visible;
  }
}

.admin-ai-ops__history-item {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--space-4);
}

/* Leads: the composer panel beside the grid of lead posts. */
.admin-leads {
  display: grid;
  grid-template-columns: 372px minmax(0, 1fr);
  gap: var(--space-6);
  align-items: start;
}

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

.admin-leads__url {
  display: flex;
  align-items: flex-start;
  gap: var(--space-2);
}

.admin-leads__url > :first-child {
  flex: 1;
  min-width: 0;
}

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

.admin-leads__image {
  display: flex;
  align-items: center;
  gap: var(--space-3);
}

.admin-leads__thumb {
  width: 64px;
  height: 114px;
  object-fit: cover;
  border-radius: var(--radius-thumb);
}

.admin-leads__submit {
  margin-top: var(--space-4);
}

.admin-leads__grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(185px, 1fr));
  gap: var(--space-4);
}

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

/* Image library: the tag rail beside the drop zone and the grid. */
.admin-library {
  display: grid;
  grid-template-columns: 220px minmax(0, 1fr);
  gap: var(--space-6);
  align-items: start;
}

.admin-library__tag {
  position: relative;
  display: flex;
  align-items: stretch;
}

.admin-library__tag-label {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--space-2);
  width: 100%;
}

.admin-library__tag-count {
  font-size: var(--text-note);
  color: var(--color-text-muted);
  font-variant-numeric: tabular-nums;
}

.admin-library__tag-actions {
  position: absolute;
  top: 50%;
  right: var(--space-1);
  display: flex;
  gap: var(--space-1);
  background: var(--color-bg-surface);
  transform: translateY(-50%);
}

.admin-library__new-tag {
  margin-top: var(--space-3);
}

.admin-library__toolbar {
  display: flex;
  justify-content: flex-end;
  margin: var(--space-4) 0;
}

.admin-library__grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(160px, 1fr));
  gap: var(--space-4);
}

/* Impersonation: one panel of the auth width centred on the grey page. */
.admin-impersonate {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: var(--space-6);
}

.admin-impersonate .auth-card {
  text-align: center;
}

.admin-impersonate .auth-card__title {
  margin-bottom: var(--space-2);
}

.admin-impersonate .auth-card__muted {
  margin: 0;
}

.admin-impersonate .spinner {
  margin: 0 auto;
}

@media (max-width: 860px) {
  .admin-leads,
  .admin-library,
  .admin-ai-ops {
    grid-template-columns: minmax(0, 1fr);
  }

  .admin-ai-ops__rail,
  .admin-prompt__settings {
    position: static;
  }

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

  .admin__row {
    grid-template-columns: minmax(0, 1fr);
    row-gap: var(--space-1);
  }
}
