/* The bandit dashboard (/admin/nudges): totals, the bandit against its holdout, each bucket's arms with the
   bandit's current guess, and the latest nudges. Tables borrow the leaderboard's sheet look. */
@layer sections {
  .admin {
    max-inline-size: 1100px;
    display: flex;
    flex-direction: column;
    gap: 28px;
    padding: 24px 16px 48px;
  }

  .admin__heading {
    margin: 0 0 6px;
    font: 600 15px var(--font-cell);
    color: var(--text-primary);
  }

  .admin__tiles {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(150px, 1fr));
    border: 1px solid var(--border-header);
    background: var(--border-grid);
    gap: 1px;
  }

  .admin__tile {
    display: flex;
    flex-direction: column;
    gap: 2px;
    padding: 10px 12px;
    background: var(--surface-grid);
    font: 12px var(--font-cell);
    color: var(--text-secondary);

    strong {
      font: 600 22px var(--font-mono);
      color: var(--text-primary);
    }

    small {
      color: var(--text-placeholder);
    }
  }

  /* An order's address, a line each as it'd go on the parcel. */
  .admin__address {
    white-space: pre-line;
  }

  /* Approving a ship: the hours it grants, in a box by the button. */
  .admin__approve {
    display: flex;
    align-items: center;
    gap: 8px;
  }

  .admin__hours {
    inline-size: 80px;
    padding: 4px 6px;
    border: 1px solid var(--border-header);
    font: 13px var(--font-mono);
  }

  /* On the admin home, a tile is a link to the page with what's waiting, and says so when something is. */
  .admin__tile--link {
    text-decoration: none;

    &:hover,
    &:focus-visible {
      background: var(--blue-50);
    }

    &[data-waiting] strong {
      color: var(--blue-700);
    }
  }

  .admin__table--pages a {
    color: var(--blue-700);
  }

  .leaderboard__table.admin__table {
    table-layout: auto;

    th[scope="row"] {
      font-weight: 500;
      text-align: start;
      white-space: nowrap;
    }

    tr[data-leading] {
      background: var(--green-50);
    }
  }

  .admin__muted {
    color: var(--text-placeholder);
    font-size: 12px;
  }

  .admin__guess {
    inline-size: 260px;
    white-space: nowrap;
  }

  td.admin__guess {
    display: flex;
    align-items: center;
    gap: 10px;
  }

  /* A 0–100% track: the 95% interval as a bar, the mean as a tick. */
  .admin__interval {
    position: relative;
    flex: 1;
    block-size: 10px;
    border-radius: 5px;
    background: var(--grey-100);
  }

  .admin__interval-range {
    position: absolute;
    inset-block: 0;
    inset-inline-start: calc(var(--low) * 100%);
    inline-size: calc((var(--high) - var(--low)) * 100%);
    border-radius: 5px;
    background: var(--blue-150);
  }

  .admin__interval-mean {
    position: absolute;
    inset-block: -3px;
    inset-inline-start: calc(var(--mean) * 100%);
    inline-size: 2px;
    background: var(--blue-700);
  }

  .admin__guess-number {
    inline-size: 3.5em;
    font: 13px var(--font-mono);
    text-align: end;
  }

  .admin__columns {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(320px, 1fr));
    gap: 28px;
  }

  .admin__clippy {
    inline-size: 24px;
    block-size: 24px;
    margin-inline-end: 8px;
    vertical-align: middle;
    border-radius: 4px;
  }

  .admin__days {
    display: flex;
    flex-direction: column;
    gap: 4px;
    font: 12px var(--font-mono);
  }

  .admin__day {
    display: grid;
    grid-template-columns: 56px 1fr 40px;
    align-items: center;
    gap: 10px;
  }

  .admin__day-bar {
    display: flex;
    gap: 2px;
    block-size: 14px;

    span {
      inline-size: calc(var(--share) * 100%);
      border-radius: 2px;
    }
  }

  .admin__day-count {
    text-align: end;
  }

  .admin [data-kind="bandit"] {
    background: var(--blue-600);
  }

  .admin [data-kind="fixed"] {
    background: var(--grey-400);
  }

  .admin__key {
    display: inline-block;
    inline-size: 10px;
    block-size: 10px;
    margin-inline: 8px 4px;
    border-radius: 2px;
  }

  .admin__table--recent td {
    vertical-align: top;

    &:first-child {
      white-space: nowrap;
    }
  }

  .admin__table--recent .admin__message {
    inline-size: 45%;
  }

  .admin__table th[scope="row"] .admin__muted,
  .admin__table--recent .admin__muted {
    display: block;
  }

  /* The numbers page (/admin/metrics): a column per day, scrolling sideways, with today's marked. */
  .admin__scroll {
    overflow-x: auto;
  }

  .admin__table--history {
    th[scope="row"] {
      position: sticky;
      inset-inline-start: 0;
      background: var(--surface-grid);
    }

    td,
    th[scope="col"] {
      white-space: nowrap;
    }

    [data-latest] {
      background: var(--green-50);
    }
  }

  .admin__change {
    font-size: 0.75em;

    &[data-up="true"] {
      color: var(--green);
    }
  }

  @media (max-width: 700px) {
    .admin__table {
      display: block;
      overflow-x: auto;
    }
  }
}

/* The people page (/admin/users): a search box, everyone in a table, and seeing the site as any of them. */
@layer sections {
  .admin__search {
    display: flex;
    gap: 8px;
    align-items: center;
    margin-block-start: 12px;
    font: 13px var(--font-cell);

    input {
      flex: 1;
      max-inline-size: 360px;
      padding: 6px 10px;
      border: 1px solid var(--border-control);
      border-radius: 4px;
      font: inherit;
      background: var(--surface-grid);
    }

    a {
      color: var(--blue-700);
    }
  }

  .admin__search button,
  .admin__button {
    padding: 6px 12px;
    border: 1px solid var(--border-control);
    border-radius: 4px;
    background: var(--surface-grid);
    font: 500 13px var(--font-cell);
    color: var(--text-primary);
    cursor: pointer;

    &:hover {
      background: var(--grey-100);
    }
  }

  .admin__table--users {
    th[scope="row"] {
      white-space: normal;
    }

    td {
      vertical-align: top;
    }

    .admin__muted {
      display: block;
    }
  }

  /* Whether someone reviews ships: a box each, and Save. */
  .admin__roles {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: 4px 10px;
    white-space: nowrap;
  }

  .admin__avatar {
    inline-size: 20px;
    block-size: 20px;
    margin-inline-end: 6px;
    vertical-align: middle;
  }

  .admin__actions {
    white-space: nowrap;

    form {
      display: inline-block;
      margin-inline-end: 6px;
    }
  }
}

/* The extensions page (/admin/extensions), and the sellers one (/admin/seller_requests) laid out the same: who's
   asked, for what, and a button each way. The admin pages' nav sits above every one of them. */
@layer sections {
  .admin__nav {
    display: flex;
    flex-wrap: wrap;
    gap: 14px;
    margin-block-end: 12px;
    font: 13px var(--font-cell);

    a {
      color: var(--blue-700);

      &[aria-current] {
        font-weight: 600;
        color: var(--text-primary);
      }
    }
  }

  .admin__table--extensions {
    th[scope="row"] {
      white-space: normal;
    }

    td {
      vertical-align: top;
    }

    .admin__muted {
      display: block;
    }

    [data-decision="approved"] {
      color: var(--green);
    }
  }

  .admin__reason {
    min-inline-size: 240px;
    max-inline-size: 440px;
    white-space: pre-line;
  }
}

/* The ships pages (/admin/ships): every ship in a table, and one in full with its description and screenshot. */
@layer sections {
  .admin__table--ships {
    th[scope="row"] {
      white-space: normal;
    }

    td {
      vertical-align: top;
    }

    td a {
      color: var(--blue-700);
    }

    .admin__muted {
      display: block;
    }
  }

  .admin [data-decision="approved"] {
    color: var(--green);
  }

  .admin [data-decision="rejected"] {
    color: var(--text-secondary);
  }

  .admin__ship {
    display: flex;
    flex-direction: column;
    gap: 16px;
  }

  .admin__ship-details {
    display: grid;
    grid-template-columns: max-content 1fr;
    gap: 6px 16px;
    margin: 0;
    font: 13px var(--font-cell);

    dt {
      color: var(--text-secondary);
    }

    dd {
      margin: 0;
      overflow-wrap: anywhere;
    }

    a {
      color: var(--blue-700);
    }
  }

  .admin__ship-description {
    max-inline-size: 640px;
    white-space: pre-line;
  }

  .admin__ship-shot {
    margin: 0;

    img {
      display: block;
      max-inline-size: min(100%, 640px);
      block-size: auto;
      border: 1px solid var(--border-header);
    }

    figcaption {
      margin-block-start: 6px;
    }
  }
}

/* The projects pages (/admin/projects): every project in a table, and one in full with each day built. */
@layer sections {
  .admin__table--projects,
  .admin__table--days {
    th[scope="row"] {
      white-space: normal;
    }

    td {
      vertical-align: top;
    }

    a {
      color: var(--blue-700);
    }

    .admin__muted {
      display: block;
    }
  }

  .admin__tile a {
    color: inherit;
  }
}

/* The strip while an admin's viewing as someone: floats at the bottom like Sheets' snackbar, on every page. */
@layer sections {
  .impersonation {
    position: fixed;
    inset-block-end: 16px;
    inset-inline-start: 16px;
    z-index: 100;
    display: flex;
    align-items: center;
    gap: 14px;
    padding: 10px 14px;
    border-radius: 6px;
    background: var(--navy-900);
    color: var(--white);
    font: 13px var(--font-cell);
    box-shadow: 0 4px 12px rgb(0 0 0 / 30%);
  }

  .impersonation__detail {
    color: var(--grey-400);
  }

  .impersonation__form {
    margin: 0;
  }

  .impersonation__stop {
    padding: 4px 10px;
    border: 0;
    border-radius: 4px;
    background: var(--white);
    font: 600 12px var(--font-cell);
    color: var(--navy-900);
    cursor: pointer;
  }
}
