/*
 * Brand admin
 *
 * The brand's own settings. Panels and form furniture are the dashboard's;
 * what is new is the strip that switches between the admin's sections and the
 * grid the rules are typed into.
 */

/* Links, not buttons: each section is a page with a URL, unlike the command
   center's tabs, which swap panels in place. Same selected state as those —
   deep violet with a rule under it. */
.page-tabs {
  display: flex;
  gap: 4px;
  margin: 0 0 14px;
  border-bottom: 1px solid var(--k-color-line);
}

.page-tabs__tab {
  position: relative;
  display: inline-flex;
  align-items: center;
  gap: 8px;
  min-height: 44px;
  padding: 0 16px;
  font-size: 13px;
  font-weight: 700;
  color: var(--k-color-muted);
  text-decoration: none;
}

a.page-tabs__tab:hover {
  color: var(--k-color-ink);
}

.page-tabs__tab.active {
  color: var(--k-color-violet-deep);
}

.page-tabs__tab.active::after {
  content: "";
  position: absolute;
  left: 16px;
  right: 16px;
  bottom: -1px;
  height: 2px;
  background: currentcolor;
}

/* The strip is wider than a phone: it scrolls rather than wrapping. */
@media (width <= 680px) {
  .page-tabs {
    overflow-x: auto;
  }
}

.settings-form {
  display: flex;
  flex-direction: column;
  gap: 14px;
}

.settings-summary {
  margin: 4px 0 0;
  font-size: 12px;
  line-height: 1.5;
  color: var(--k-color-muted);
}

.settings-grid {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  align-items: start;
  gap: 20px;
  padding: 20px;
}

.settings-grid .field__hint {
  margin: -2px 0 0;
  font-size: 12px;
  line-height: 1.5;
  color: var(--k-color-muted);
}

.settings-note {
  max-width: 90ch;
  margin: 18px 20px 0;
  font-size: 13px;
  line-height: 1.65;
  color: var(--k-color-ink-soft);
}

.settings-note--foot {
  margin: 0 20px 20px;
  font-size: 12px;
  color: var(--k-color-muted);
}

.panel-empty--short {
  padding: 32px 20px;
}

.settings-errors {
  margin: 0;
  padding-inline-start: 18px;
}

.settings-actions {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 16px;
  margin: 4px 0 18px;
}

.settings-actions span {
  font-family: var(--mono);
  font-size: 12px;
  color: var(--k-color-muted);
}

/* The time zone is one field in a panel of its own, not a row of the rules
   grid: a zone's name is too long for a third of the width, and the save
   button belongs inside the card, under what it saves. */
.settings-zone {
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  gap: 16px;
  padding: 20px;
}

.settings-zone .field {
  width: 100%;
  max-width: 34rem;
}

.settings-zone .field__hint {
  margin: 0;
  font-size: 12px;
}

.settings-zone__note {
  max-width: 90ch;
  margin: 0;
  font-size: 12px;
  line-height: 1.65;
  color: var(--k-color-muted);
}

.settings-zone__actions {
  padding-top: 4px;
}

@media (width <= 900px) {
  .settings-grid {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }
}

@media (width <= 580px) {
  .settings-grid {
    grid-template-columns: minmax(0, 1fr);
  }
}

/* Admin › Users. Inviting is a strip at the top of the members panel, so a
   new person lands in the rows directly under the form that added them. */
.member-invite {
  padding: 18px 20px 16px;
  border-bottom: 1px solid var(--k-color-line);
}

.member-invite__fields {
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(200px, 300px) auto;
  align-items: end;
  gap: 12px;
}

.member-invite .field {
  margin: 0;
}

.member-invite .button {
  min-height: 48px;
  margin-top: 0;
}

.member-invite .field__hint {
  max-width: 90ch;
  margin-top: 8px;
  font-size: 12px;
  color: var(--k-color-muted);
}

/* One grid for every row, each row a subgrid of it, so the badges, the role
   pickers and the buttons stand in columns down the list and a role can be
   read by running an eye down one edge. */
.member-list,
.role-list {
  display: grid;
  margin: 0;
  padding: 4px 20px;
  list-style: none;
  column-gap: 16px;
}

.member-list {
  grid-template-columns: minmax(0, 1fr) max-content minmax(160px, 200px) minmax(max-content, 180px);
}

.member-row,
.role-row {
  display: grid;
  grid-column: 1 / -1;
  grid-template-columns: subgrid;
  align-items: center;
  padding: 14px 0;
  border-bottom: 1px solid var(--k-color-line);
}

.member-row:last-child,
.role-row:last-child {
  border-bottom: 0;
}

.member-row__who {
  min-width: 0;
}

.member-row__who strong {
  display: block;
  font-size: 14px;
  font-weight: 700;
  color: var(--k-color-ink);
  overflow-wrap: anywhere;
}

/* Dates and addresses: measurement, so mono. */
.member-row__who span {
  display: block;
  margin-top: 3px;
  font-family: var(--mono);
  font-size: 12px;
  color: var(--k-color-muted);
  overflow-wrap: anywhere;
}

.member-row__role {
  display: flex;
  align-items: center;
  gap: 8px;
  min-width: 0;
}

.member-row__role .field__input {
  min-width: 0;
  min-height: 38px;
  padding: 0.375rem 2rem 0.375rem 0.75rem;
  font-size: 13px;
  font-weight: 600;
}

.member-row__role .button {
  flex: none;
}

/* `.button` sets its own display, which would outrank the attribute the
   submit-on-change controller hides it with. */
.member-row__role .button[hidden] {
  display: none;
}

.member-row__actions {
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: 4px;
}

.member-row__own {
  margin: 0;
  font-size: 12px;
  line-height: 1.4;
  text-align: end;
  color: var(--k-color-muted);
}

/* Removing is findable and quiet: ten red buttons down a list would make the
   page about leaving. It turns red under the pointer, and asks first. */
.member-row__remove {
  min-height: 36px;
  padding: 0 10px;
  font: inherit;
  font-size: 13px;
  font-weight: 700;
  color: var(--k-color-muted);
  background: none;
  border: 0;
  border-radius: var(--k-radius-control);
  cursor: pointer;
  transition: color var(--k-duration-fast) var(--k-ease-standard),
    background-color var(--k-duration-fast) var(--k-ease-standard);
}

.member-row__remove:hover {
  color: var(--k-color-error);
  background-color: var(--k-color-error-bg);
}

.member-row__remove:focus-visible {
  outline: 2px solid var(--k-color-violet-deep);
  outline-offset: 2px;
}

.role-list {
  grid-template-columns: minmax(120px, max-content) minmax(0, 1fr) max-content max-content;
}

.role-row strong {
  font-size: 14px;
  font-weight: 700;
  color: var(--k-color-ink);
}

.role-row p {
  margin: 0;
  font-size: 13px;
  line-height: 1.5;
  color: var(--k-color-ink-soft);
}

.role-row__count {
  font-family: var(--mono);
  font-size: 12px;
  color: var(--k-color-muted);
  white-space: nowrap;
}

.role-row__action {
  display: flex;
  justify-content: flex-end;
  min-width: 64px;
}

/* "Built in" on both built-in roles alike; the account admin's keeps the
   violet it wears on a member's row. */
.role-row__action .badge:not(.badge--admin) {
  color: var(--k-color-ink-soft);
  background-color: var(--k-color-lavender-soft);
}

.role-row__action .button {
  margin-top: 0;
}

@media (width <= 760px) {
  .member-invite__fields {
    grid-template-columns: minmax(0, 1fr);
  }

  .member-list,
  .role-list {
    grid-template-columns: minmax(0, 1fr) auto;
  }

  .member-row__who,
  .role-row strong,
  .role-row p {
    grid-column: 1 / -1;
  }

  .member-row__status:empty {
    display: none;
  }

  .member-row__status {
    grid-column: 1 / -1;
    margin-top: 6px;
  }

  .member-row__role {
    margin-top: 10px;
  }

  .member-row__actions,
  .member-row__own {
    margin-top: 10px;
  }

  .role-row p {
    margin-top: 2px;
  }

  .role-row__count,
  .role-row__action {
    margin-top: 8px;
  }
}

/* A phone has no room for the picker and two buttons abreast. */
@media (width <= 480px) {
  .member-row__role,
  .member-row__actions,
  .member-row__own {
    grid-column: 1 / -1;
  }

  .member-row__actions {
    justify-content: flex-start;
  }

  .member-row__actions > form:only-child .member-row__remove {
    margin-inline-start: -10px;
  }

  .member-row__own {
    text-align: start;
  }
}

/* A role's form: its name, the apps it opens as switches, and its pages
   grouped by the apps that draw them. The panels stack as .admin-stack's
   do, so the form is its own stack inside it. */
.role-form {
  display: flex;
  flex-direction: column;
  gap: 14px;
}

.role-form__lede {
  margin: 4px 0 0;
  max-width: 68ch;
  font-size: 13px;
  line-height: 1.5;
  color: var(--k-color-muted);
}

/* The apps, one tile each, the switch leading. A tile is the whole label, so
   the switch is not the only target; an open app takes the brand's lavender
   and a closed one recedes to the line. */
.role-apps {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(min(100%, 240px), 1fr));
  gap: 10px;
  padding: 16px 20px 20px;
}

.role-app {
  display: flex;
  align-items: flex-start;
  gap: 12px;
  padding: 14px 16px;
  border: 1px solid var(--k-color-line);
  border-radius: 12px;
  cursor: pointer;
  transition: border-color 160ms ease-out, background-color 160ms ease-out;
}

.role-app:hover {
  border-color: var(--k-color-control-border);
}

.role-app:has(.role-switch:checked) {
  border-color: color-mix(in srgb, var(--k-color-violet) 45%, transparent);
  background: var(--k-color-lavender-soft);
}

.role-app__body {
  display: flex;
  flex-direction: column;
  gap: 4px;
  min-width: 0;
}

.role-app__name {
  font-family: var(--display);
  font-size: 16px;
  font-weight: 600;
  letter-spacing: -0.01em;
  line-height: 1.3;
  color: var(--k-color-ink);
}

.role-app__description {
  font-size: 12px;
  line-height: 1.5;
  color: var(--k-color-muted);
}

.role-app__reach {
  margin-top: 4px;
  font-family: var(--mono);
  font-size: 12px;
  color: var(--k-color-violet-deep);
}

.role-app:not(:has(.role-switch:checked)) .role-app__name,
.role-app:not(:has(.role-switch:checked)) .role-app__reach {
  color: var(--k-color-muted);
}

/* The system's checkbox drawn as a switch: still a checkbox to the form and
   to a screen reader, a track and a knob to the eye. */
.role-switch {
  flex: none;
  position: relative;
  width: 34px;
  height: 20px;
  margin: 1px 0 0;
  appearance: none;
  background: var(--k-color-control-border);
  border-radius: var(--k-radius-pill);
  cursor: pointer;
  transition: background-color 160ms ease-out;
}

.role-switch::before {
  content: "";
  position: absolute;
  top: 2px;
  inset-inline-start: 2px;
  width: 16px;
  height: 16px;
  background: var(--k-color-paper);
  border-radius: 50%;
  box-shadow: 0 1px 2px color-mix(in srgb, var(--k-color-ink) 30%, transparent);
  transition: inset-inline-start 180ms cubic-bezier(0.16, 1, 0.3, 1);
}

.role-switch:checked {
  background: var(--k-color-violet);
}

.role-switch:checked::before {
  inset-inline-start: 16px;
}

.role-switch:focus-visible {
  outline: 2px solid var(--k-color-violet-deep);
  outline-offset: 2px;
}

/* The pages, a group per set of apps that draws them, ruled off from the
   group above. Two columns where there is room: ten pages in one column is
   a scroll for a decision that fits on a screen. */
.role-group {
  padding: 16px 20px 20px;
}

.role-group + .role-group {
  border-top: 1px solid var(--k-color-line);
}

.role-group__head {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 10px;
}

.role-group__title {
  margin: 0;
  font-size: 13px;
  font-weight: 700;
  color: var(--k-color-ink);
}

.role-group__bulk {
  display: flex;
  gap: 4px;
}

.role-group__toggle {
  padding: 2px 8px;
  font: inherit;
  font-size: 12px;
  font-weight: 700;
  color: var(--k-color-violet-deep);
  background: none;
  border: 0;
  border-radius: 6px;
  cursor: pointer;
}

.role-group__toggle:hover {
  background: var(--k-color-lavender-soft);
}

.role-group__toggle:focus-visible {
  outline: 2px solid var(--k-color-violet-deep);
  outline-offset: 1px;
}

.role-group__pages {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(min(100%, 300px), 1fr));
  gap: 4px 12px;
}

.role-page {
  display: flex;
  align-items: flex-start;
  gap: 12px;
  padding: 10px 12px;
  margin-inline: -12px;
  border-radius: 10px;
  cursor: pointer;
  transition: background-color 120ms ease-out, opacity 160ms ease-out;
}

.role-page:hover {
  background: var(--k-color-ivory);
}

.role-page .field__check {
  flex: none;
  margin: 2px 0 0;
}

.role-page__body {
  display: flex;
  flex-direction: column;
  gap: 2px;
  min-width: 0;
}

.role-page__name {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 6px;
  font-size: 13px;
  color: var(--k-color-ink);
}

.role-page small {
  font-size: 12px;
  line-height: 1.5;
  color: var(--k-color-muted);
}

/* Pages no app the role opens draws: still tickable, since opening the app
   again brings them back, but quieter, with the reason said once above them. */
.role-group--unreached .role-group__pages {
  opacity: 0.55;
}

.role-group__unreached {
  margin: -2px 0 10px;
  padding: 8px 12px;
  font-size: 12px;
  line-height: 1.5;
  color: var(--k-color-warning);
  background: var(--k-color-warning-bg);
  border-radius: 8px;
}

/* The save stays in reach the whole way down the pages. */
.role-form__actions {
  position: sticky;
  bottom: 0;
  z-index: 2;
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 10px;
  padding: 14px 0 18px;
  background: linear-gradient(to bottom, transparent, var(--k-color-ivory) 14px);
}

.role-form__actions .button {
  margin: 0;
}

/* Panels one after another, spaced as the settings form spaces its own. */
.admin-stack {
  display: flex;
  flex-direction: column;
  gap: 14px;
  margin-bottom: 18px;
}

/* The brand's audit log. The filter is the panel's head, so it takes the
   head's padding and rule; its links are quieter than the page tabs above,
   because they narrow one panel rather than switch pages. */
.audit-filter {
  display: flex;
  flex-wrap: wrap;
  gap: 4px;
  padding: 12px 16px;
  border-bottom: 1px solid var(--k-color-line);
}

.audit-filter__link {
  padding: 6px 12px;
  font-size: 13px;
  font-weight: 600;
  color: var(--k-color-muted);
  text-decoration: none;
  border-radius: var(--k-radius-pill);
  transition: color 120ms ease, background-color 120ms ease;
}

.audit-filter__link:hover {
  color: var(--k-color-ink);
  background-color: var(--k-color-paper);
}

.audit-filter__link.active {
  font-weight: 700;
  color: var(--k-color-violet-deep);
  background-color: var(--k-color-lavender);
}

.audit-day {
  margin: 0;
  padding: 20px 20px 2px;
  font-size: 11px;
  font-weight: 700;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: var(--k-color-muted);
}

.audit-list {
  margin: 0;
  padding: 0 20px 6px;
  list-style: none;
}

.audit-entry {
  display: grid;
  grid-template-columns: 44px minmax(0, 1fr) auto;
  align-items: baseline;
  gap: 4px 16px;
  padding: 12px 0;
  border-bottom: 1px solid var(--k-color-line);
}

.audit-list .audit-entry:last-child {
  border-bottom: 0;
}

/* Mono, as a clock reading: the times line up down the day. */
.audit-entry__time {
  font-family: var(--mono);
  font-size: 12px;
  color: var(--k-color-muted);
}

.audit-entry__summary {
  margin: 0;
  font-size: 14px;
  font-weight: 600;
  line-height: 1.4;
  color: var(--k-color-ink);
  overflow-wrap: anywhere;
}

.audit-entry__meta {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 4px 8px;
  margin: 4px 0 0;
  font-size: 12px;
  color: var(--k-color-muted);
  overflow-wrap: anywhere;
}

.audit-entry__reason::before {
  content: "·";
  margin-inline-end: 8px;
}

.audit-entry__area {
  font-size: 12px;
  font-weight: 600;
  color: var(--k-color-muted);
  white-space: nowrap;
}

/* A refusal changed nothing, so it reads quieter than a change, with the
   badge to say why it is there at all. */
.audit-entry--refused .audit-entry__summary {
  font-weight: 500;
  color: var(--k-color-ink-soft);
}

.audit-entry__summary .badge {
  margin-inline-end: 6px;
  vertical-align: 1px;
}

.badge--refused {
  color: var(--k-color-error);
  background-color: var(--k-color-error-bg);
}

.badge--kairo {
  padding: 0 0.4rem;
  font-size: 0.6875rem;
  color: var(--k-color-violet-deep);
  background-color: var(--k-color-lavender-soft);
}

.audit-scope {
  margin: 12px 4px 0;
  font-size: 12px;
  line-height: 1.5;
  color: var(--k-color-muted);
}

/* On a phone the area drops under the entry rather than squeezing it. */
@media (max-width: 640px) {
  .audit-entry {
    grid-template-columns: 44px minmax(0, 1fr);
  }

  .audit-entry__area {
    grid-column: 2;
  }
}
