/* Settings, set as the docs are: the head (the mark on the left, the ways out on the right, the
   account beside them), the sections in a column on the mark's rule, and the section beside it.
   One size for everything but the section's title, in the site's tokens. */

.settings-page,
.settings-page * {
  font-size: inherit;
}

.settings-page .button.small {
  font-size: inherit;
}

.settings-head {
  position: sticky;
  top: 0;
  z-index: 4;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1.5rem;
  padding: var(--edge) calc(var(--edge) + 3.5rem) 1rem var(--edge); /* the account's circle sits at the right */
  line-height: 2rem;
  background: var(--bg);
  border-bottom: 1px solid var(--line);
}

.settings-head .mark {
  margin: 0;
  white-space: nowrap;
}

.settings-links {
  display: flex;
  gap: clamp(1rem, 2.2vw, 2rem);
}

.settings-links a,
.settings-nav a {
  color: var(--quiet);
}

.settings-links a:hover,
.settings-nav a:hover {
  color: var(--ink);
}

.settings-body {
  display: grid;
  grid-template-columns: 13rem minmax(0, 1fr);
  gap: clamp(2rem, 5vw, 5rem);
  align-items: start;
  padding: 2.5rem var(--edge) 4rem;
}

.settings-nav {
  position: sticky;
  top: calc(var(--edge) + 5.5rem + 1px); /* the head's height and the gap under it, so it never moves down */
  padding-top: calc((2.4rem - 1.3em) / 2); /* the first section level with the title beside it */
  display: flex;
  flex-direction: column;
  gap: 0.6rem;
  line-height: 1.3;
}

.settings-nav a[aria-current="page"] {
  color: var(--ink);
  text-decoration: underline;
  text-underline-offset: 0.25em;
  text-decoration-thickness: from-font;
}

.settings-main {
  min-width: 0;
}

.settings-title {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  min-height: 2.4rem;
  margin-bottom: 1.25rem;
}

.settings-page h1 {
  margin: 0;
  font-size: 1.3em;
  font-weight: 400;
  line-height: 1.25;
  letter-spacing: -0.015em;
}

.settings-main p {
  margin: 0;
}

.settings-notice {
  margin: 0 0 1.25rem !important;
  padding: 0.6em 0.9em;
  border-radius: 8px;
  background: rgba(255, 170, 0, 0.14);
}

.settings-notice.ok {
  background: rgba(31, 157, 85, 0.1);
}

.settings-page .button {
  padding: 0.3em 0.85em;
  border-radius: 8px;
  white-space: nowrap;
}

.settings-page a.button {
  text-decoration: none;
}

.settings-page .button.primary:hover {
  background: var(--ink);
  opacity: 0.85;
}

.row-actions {
  display: inline-flex;
  flex-wrap: nowrap;
  align-items: center;
  gap: 0.5rem;
}

/* Tables: rules between rows, the header in the quiet ink at the same size. */

.settings-table {
  width: 100%;
  border-collapse: collapse;
}

.settings-table th,
.settings-table td {
  padding: 0.7rem 1.5rem 0.7rem 0;
  border-bottom: 1px solid var(--line);
  text-align: left;
  vertical-align: middle;
  white-space: nowrap;
}

/* Names, groups, actions and people wrap; keys, dates and buttons never do. */
.keys-table td:is(:nth-child(1), :nth-child(3), :nth-child(4), :nth-child(5)) {
  white-space: normal;
}

.settings-table th {
  padding-top: 0;
  color: var(--quiet);
  font-weight: 400;
}

.settings-table .end,
.settings-table th:last-child,
.settings-table td:last-child {
  padding-right: 0;
}

.settings-table .end {
  text-align: right;
}

.settings-table tr.gone td {
  color: var(--quiet);
}

.table-scroll {
  overflow-x: auto;
}

/* Connections: the source, then the organization's side and the person's, each a state and its actions. */

.connections-table th:first-child {
  width: 30%;
}

.connections-table th:not(:first-child) {
  width: 35%;
}

.source-cell {
  display: inline-flex;
  align-items: center;
  gap: 0.75rem;
}

.source-cell .icon {
  width: 1.25em;
  height: 1.25em;
}

.scope {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  min-height: 2rem;
}

.linked span {
  color: var(--ink);
}

.connections-table tr.panel td {
  padding: 0.25rem 0 1.25rem calc(1.25em + 0.75rem);
  white-space: normal;
}

.panel-body {
  display: grid;
  gap: 0.9rem;
  max-width: 44rem;
}

.pair {
  display: grid;
  grid-template-columns: 11rem minmax(0, 1fr);
  align-items: center;
  gap: 1rem;
}

.pair .copy {
  margin: 0;
  background: var(--bg);
}

.pair .copy code,
.key-row code {
  font-family: inherit;
}

.steps {
  margin: 0;
  padding-left: 1.2em;
  list-style: decimal;
}

.steps li + li {
  margin-top: 0.3rem;
}

.steps code {
  font-family: inherit;
}

.steps a {
  text-decoration: underline;
  text-underline-offset: 0.18em;
}

.token-fields {
  display: grid;
  gap: 0.5rem;
}

.choice {
  display: inline-flex;
  align-items: center;
  gap: 0.5rem;
  cursor: pointer;
}

.choice input {
  margin: 0;
  accent-color: var(--ink);
}

.settings-page input[type="text"],
.settings-page input[type="number"],
.settings-page input[type="password"] {
  width: 100%;
  min-width: 0;
  padding: 0.45rem 0.7rem;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--bg);
  color: var(--ink);
  font: inherit;
}

.settings-page input:focus {
  border-color: var(--quiet);
}

/* API keys: the form and the new key in panels above the table. */

.key-form,
.key-created {
  display: grid;
  gap: 1.1rem;
  margin-bottom: 1.75rem;
  padding: 1.25rem;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: var(--card);
}

.key-form .settings-notice {
  margin: 0 !important;
}

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

.form-field {
  display: grid;
  gap: 0.4rem;
  align-content: start;
  min-width: 0;
  margin: 0;
  padding: 0;
  border: 0;
}

.form-field legend {
  margin-bottom: 0.4rem;
  padding: 0;
}

.choices input[type="text"] {
  flex: 1 1 12rem;
  width: auto;
}

.choices {
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem 1.4rem;
  min-height: 2.35rem;
  align-items: center;
}

.key-row {
  display: flex;
  align-items: center;
  gap: 0.5rem;
}

.key-row code {
  flex: 1;
  min-width: 0;
  padding: 0.35rem 0.7rem;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--bg);
  overflow-wrap: anywhere;
}

/* A phone: the sections become a row of links under the head, and each source stacks its two sides. */
@media (max-width: 52rem) {
  .settings-head {
    padding-right: calc(var(--edge) + 3rem);
  }

  .settings-body {
    grid-template-columns: minmax(0, 1fr);
    gap: 1.5rem;
    padding-top: 1.25rem;
  }

  .settings-nav {
    position: static;
    flex-direction: row;
    gap: 1.5rem;
    padding-bottom: 1rem;
    border-bottom: 1px solid var(--line);
  }

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

  /* The keys' table keeps its rows on one line each and scrolls sideways in its own box. */
  .keys-table td:is(:nth-child(1), :nth-child(3), :nth-child(4), :nth-child(5)) {
    white-space: nowrap;
  }

  .pair {
    grid-template-columns: minmax(0, 1fr);
    gap: 0.35rem;
  }

  .connections-table thead {
    display: none;
  }

  .connections-table,
  .connections-table tbody,
  .connections-table tr,
  .connections-table td {
    display: block;
    width: 100%;
  }

  .connections-table tr {
    padding: 0.8rem 0;
    border-bottom: 1px solid var(--line);
  }

  .connections-table td {
    padding: 0;
    border: 0;
    white-space: normal;
  }

  .connections-table td[data-label] {
    display: grid;
    grid-template-columns: 7.5rem minmax(0, 1fr);
    align-items: center;
    margin-top: 0.5rem;
  }

  .connections-table td[data-label]::before {
    content: attr(data-label);
    color: var(--quiet);
  }

  .connections-table .scope {
    flex-wrap: wrap;
    gap: 0.5rem 1rem;
  }

  .connections-table td.none {
    display: none;
  }

  .connections-table tr.panel {
    padding-top: 0;
  }

  .connections-table tr.panel td {
    padding: 0.25rem 0 0.5rem;
  }
}

@media (max-width: 30rem) {
  .settings-links a[href="https://generalforecast.com/docs"] {
    display: none;
  }

  .key-row {
    flex-wrap: wrap;
  }

  .key-row code {
    flex-basis: 100%;
  }
}
