/* GitHub's settings layout, shared by repository, personal, organization and site administration settings. The
   area layouts mark their container with .theme-settings; Forgejo's own menu and form markup stays underneath. */

/* Context header: who or what the settings belong to. */
.theme-settings-context {
  display: flex;
  align-items: center;
  gap: 8px;
  margin: 24px 0 16px;
  & > img,
  & .theme-settings-context-icon {
    flex: none;
    width: 48px;
    height: 48px;
    border-radius: 50%;
  }
  & .theme-settings-context-icon {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    border: 1px solid var(--color-light-border);
    background: var(--color-box-header);
    color: var(--color-text-light-1);
  }
  & > .button > .svg {
    color: var(--color-text-light-1);
  }
}

/* On a phone the button takes a row of its own under the name instead of squeezing it. */
@media (max-width: 767.98px) {
  .theme-settings-context {
    flex-wrap: wrap;
    & > .button {
      flex-basis: 100%;
      justify-content: center;
    }
  }
}

.theme-settings-context-title {
  flex: 1;
  min-width: 0;
  & h1 {
    margin: 0;
    font-size: 20px;
    font-weight: 600;
    line-height: 30px;
    overflow-wrap: anywhere;
  }
  & h1 > span,
  & p {
    color: var(--color-text-light-1);
  }
  & p {
    margin: 0;
    font-size: 14px;
    line-height: 21px;
  }
}

/* Columns: a 256px nav and the page, 40px apart. */
.ui.container.flex-container.theme-settings {
  gap: 40px;
  margin-top: 24px;
}

.theme-settings-context-container + .ui.container.flex-container.theme-settings {
  margin-top: 0;
}

/* Personal settings sit in GitHub's 1012px column, centred, as github.com/settings does; repository, organization and
   site administration settings keep the page's width. */
.page-content.user.settings > .ui.container:is(.theme-settings-context-container, .theme-settings) {
  width: calc(100% - 32px) !important;
  max-width: 980px !important;
}

/* GitHub's Add beside the new email address is a secondary button; the form's own button is the green primary. */
.page-content.user.settings.account form:has(> .field > input[name="email"]) > .ui.primary.button {
  border-color: var(--color-light-border);
  background: var(--color-button);
  color: var(--color-text);
}

.page-content.user.settings.account form:has(> .field > input[name="email"]) > .ui.primary.button:hover {
  background: var(--color-hover);
}

/* Nav column: 256px, holding the shared nav list (components/common/nav-list). */
.theme-settings > .flex-container-nav {
  width: 256px;
}

.theme-settings-group,
.theme-settings-separator {
  margin: 8px 0 0;
  border-top: 1px solid color-mix(in srgb, var(--color-light-border) 70%, transparent);
}

.theme-settings-group {
  padding: 14px 8px 6px;
  color: var(--color-text-light-1);
  font-size: 12px;
  font-weight: 600;
  line-height: 19.5px;
}

.theme-settings-separator {
  margin-bottom: 8px;
}

/* The page side is anchored on the page structure, which outranks the theme's older boxed style for settings
   content. */
.page-content > .ui.container.flex-container.theme-settings > .flex-container-main {
  min-width: 0;

  /* Sections: GitHub's subhead, a 24px title over a border, with forms flat beneath it. Lists and tables keep a
     box, and the danger zone gets GitHub's red-bordered box. */
  & .ui.top.attached.header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 8px;
    margin: 0 0 16px;
    padding: 0 0 8px;
    border: 0 !important;
    border-bottom: 1px solid color-mix(in srgb, var(--color-light-border) 70%, transparent) !important;
    border-radius: 0;
    background: transparent !important;
    color: var(--color-text);
    font-size: 24px;
    font-weight: 400;
    line-height: 36px;
    /* Buttons in a subhead are GitHub's small buttons: 28px, 12px labels. */
    & .ui.button,
    & .button {
      min-height: 28px;
      padding: 4px 12px;
      font-size: 12px;
      font-weight: 500;
      line-height: 18px;
    }
    & > :is(.ui.right, .right) {
      display: flex;
      gap: 8px;
      margin-left: auto;
      font-size: 14px;
      line-height: 20px;
    }
  }
  & .ui.attached.segment ~ .ui.top.attached.header,
  & .ui.attached.segment ~ * .ui.top.attached.header {
    margin-top: 40px;
  }
  & .ui.attached.segment {
    margin: 0;
    padding: 0;
    border: 0 !important;
    border-radius: 0;
    background: transparent;
    box-shadow: none;
    /* GitHub's Box: tables are boxed, so a description or an add form beside them stays flat. */
    & > table,
    & > form > table {
      margin: 0 0 16px;
      border: 1px solid var(--color-light-border);
      border-radius: var(--border-radius);
      background: var(--color-box-body);
      border-collapse: separate;
      border-spacing: 0;
      overflow: hidden;
    }
    & > :last-child {
      margin-bottom: 0;
    }
  }
  /* In lists the box is drawn by the rows with content, so a row Forgejo uses for the description stays a flat
     paragraph above the box, and a list with only its description shows no empty box. Rows carry the padding, so
     separators span the box. */
  & .ui.attached.segment:not(.error) > .flex-list {
    margin: 0 0 16px;
    &:last-child {
      margin-bottom: 0;
    }
    & > .flex-item {
      padding: 16px;
    }
    /* A row's actions stay side by side, also on phones. */
    & > .flex-item > .flex-item-trailing {
      flex-direction: row;
      flex-wrap: nowrap;
      align-items: center;
    }
    & > .flex-item:not(:has(> .flex-item-main)) {
      padding: 0 0 16px;
      border: 0;
      font-size: 14px;
      line-height: 21px;
    }
    & > .flex-item:has(> .flex-item-main) {
      border: 1px solid var(--color-light-border);
      border-radius: 0;
      background: var(--color-box-body);
      &:not(:has(+ .flex-item:has(> .flex-item-main))) {
        border-bottom-right-radius: var(--border-radius);
        border-bottom-left-radius: var(--border-radius);
      }
    }
    & > .flex-item:has(> .flex-item-main) + .flex-item:has(> .flex-item-main) {
      margin-top: -1px;
    }
    & > .flex-item:has(> .flex-item-main):not(.flex-item:has(> .flex-item-main) + *) {
      border-top-left-radius: var(--border-radius);
      border-top-right-radius: var(--border-radius);
    }
  }
  /* Fomantic lists (emails, personal repositories, git hooks) get the same box rows; what is not an item, such as the
     emails' description, stays a flat paragraph above. A list wrapping a form (the theme picker) is no list. */
  & .ui.attached.segment > .ui.list:has(> form) {
    margin: 0;
    & > .item {
      margin: 0 0 16px;
      padding: 0;
    }
  }
  & .ui.attached.segment:not(.error) > .ui.list:not(:has(> form)) {
    margin: 0;
    padding: 0;
    & > :not(.item) {
      margin: 0 0 16px;
      font-size: 14px;
      line-height: 21px;
    }
    & > .item {
      display: flow-root;
      margin: 0;
      padding: 16px;
      border: 1px solid var(--color-light-border);
      background: var(--color-box-body);
      &:first-of-type {
        border-top-left-radius: var(--border-radius);
        border-top-right-radius: var(--border-radius);
      }
      &:last-of-type {
        border-bottom-left-radius: var(--border-radius);
        border-bottom-right-radius: var(--border-radius);
      }
      & + .item {
        margin-top: -1px;
      }
      &::before {
        display: none;
      }
    }
  }
  /* An add form below its list (Forgejo's bottom attached segment) sits 16px under the box. */
  & .ui.attached.segment + .ui.bottom.attached.segment {
    margin-top: 16px;
  }
  /* The danger zone's rows sit in a red box; a deletion form (an account, an organization) stays flat under its red
     heading, its warning a danger flash. */
  & .ui.attached.error.segment {
    padding: 0;
    border: 0 !important;
    background: transparent;
    &:has(> .flex-list) {
      border: 1px solid color-mix(in srgb, var(--color-red) 40%, transparent) !important;
      border-radius: var(--border-radius);
      background: var(--color-box-body);
    }
    & > .flex-list {
      margin: 0;
      border: 0;
      background: transparent;
    }
    & .flex-item-title {
      font-size: 14px;
      font-weight: 600;
    }
    & > .ui.red.message {
      margin: 0 0 16px;
      padding: 16px;
      border: 1px solid color-mix(in srgb, var(--color-red) 40%, transparent);
      border-radius: var(--border-radius);
      background: color-mix(in srgb, var(--color-red) 10%, transparent);
      box-shadow: none;
      color: var(--color-text);
      font-size: 14px;
      & .svg {
        color: var(--color-red);
      }
    }
  }

  /* GitHub's box rows for actions (the indexers): what it is on the left, the button on the right. */
  & .flex-list.theme-settings-rows {
    margin: 16px 0 0;
    border: 1px solid var(--color-light-border);
    border-radius: var(--border-radius);
    background: var(--color-box-body);
    & > .flex-item {
      align-items: center;
      padding: 16px;
    }
    & .flex-item-title {
      font-size: 14px;
      font-weight: 600;
    }
    & .flex-item-body {
      color: var(--color-text-light-1);
      font-size: 12px;
    }
  }

  /* Add forms with a search field (collaborators, teams): the field and its button in one row. */
  & .ui.attached.segment > form.ui.form:has(> .ui.search) {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: 8px;
    & > .ui.search {
      width: 240px;
      max-width: 100%;
    }
    & > .ui.search > input {
      width: 100%;
    }
  }

  /* A control and its button in one row (the default branch). */
  & form.ui.form.theme-settings-inline-form {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: 8px;
    & > .ui.dropdown {
      width: 320px;
      max-width: 100%;
    }
  }

  /* A form of one field and its button (adding an email) puts the button beside the input, as on GitHub. */
  & form.ui.form:has(> .field:first-child + .ui.button:last-child) {
    display: flex;
    flex-wrap: wrap;
    align-items: flex-end;
    gap: 8px;
    & > .field {
      flex: 0 1 440px;
      margin: 0;
    }
  }

  /* A section's description above its box, as on GitHub. */
  & .theme-settings-description {
    margin: 0 0 16px;
    font-size: 14px;
    line-height: 21px;
  }

  /* GitHub's empty state (components/common/settings/blankslate.tmpl). */
  & .theme-settings-blankslate-plain {
    margin: 0 0 16px;
    color: var(--color-text-light-1);
    font-size: 14px;
    line-height: 21px;
  }

  & .theme-settings-blankslate {
    margin: 0 0 16px;
    padding: 32px;
    border: 1px solid var(--color-light-border);
    border-radius: var(--border-radius);
    background: var(--color-box-body);
    text-align: center;
    & h3 {
      margin: 0;
      font-size: 16px;
      font-weight: 600;
      line-height: 24px;
    }
    & p {
      margin: 4px 0 0;
      color: var(--color-text-light-1);
      font-size: 14px;
      line-height: 21px;
    }
  }

  /* GitHub's summary row (a repository's visibility): an icon in a bordered square, a semibold title over a muted
     line, and an action on the right. */
  & .theme-settings-summary {
    display: flex;
    align-items: center;
    gap: 12px;
    margin: 0 0 8px;
    padding: 0 0 16px;
    & > .theme-settings-summary-main {
      display: flex;
      flex: 1;
      flex-direction: column;
      min-width: 0;
      & > strong {
        font-size: 14px;
        font-weight: 600;
        line-height: 21px;
      }
      & > span {
        color: var(--color-text-light-1);
        font-size: 14px;
        line-height: 21px;
      }
    }
  }
  & .theme-settings-summary-icon,
  & .theme-settings-team-icon {
    display: inline-flex;
    flex: none;
    align-items: center;
    justify-content: center;
    border: 1px solid var(--color-light-border);
    border-radius: var(--border-radius);
    color: var(--color-text-light-1);
  }
  & .theme-settings-summary-icon {
    width: 50px;
    height: 50px;
  }
  & .theme-settings-team-icon {
    width: 32px;
    height: 32px;
  }

  /* GitHub's bordered panel ("Direct access"): a semibold title with its icon on the right, and a muted line. */
  & .theme-settings-panel {
    margin: 0 0 32px;
    padding: 16px;
    border: 1px solid color-mix(in srgb, var(--color-light-border) 70%, transparent);
    border-radius: var(--border-radius);
    & > .theme-settings-panel-title {
      display: flex;
      align-items: center;
      justify-content: space-between;
      font-size: 14px;
      font-weight: 600;
      line-height: 21px;
      & > .svg {
        color: var(--color-text-light-1);
      }
    }
    & > p {
      margin: 8px 0 0;
      color: var(--color-text-light-1);
      font-size: 12px;
      line-height: 18px;
      & > strong {
        color: var(--color-text);
      }
    }
  }

  /* A titled part inside a section ("Manage access"): a 16px semibold title with its action on the right. */
  & .theme-settings-subsection {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 8px;
    min-height: 32px;
    margin: 0 0 16px;
    * + & {
      margin-top: 32px;
    }
    & > h3 {
      margin: 0;
      font-size: 16px;
      font-weight: 600;
      line-height: 24px;
    }
  }

  /* An empty state with an illustration icon is GitHub's spacious one: a larger title and an action below. */
  & .theme-settings-blankslate:has(> .svg) {
    & > .svg {
      color: var(--color-primary);
    }
    & > h3 {
      margin: 16px 0;
      font-size: 20px;
      line-height: 30px;
    }
  }

  /* GitHub's two columns (public profile): the form, and a 200px column on the right for the picture. */
  & .ui.attached.segment.theme-settings-columns {
    display: grid;
    grid-template-columns: minmax(0, 1fr) 200px;
    gap: 32px;
    align-items: start;
  }
  & .theme-settings-aside {
    /* Forgejo caps avatar images in forms; the picture here is GitHub's 200px circle, with Edit on its lower left
       opening a menu below it. */
    & .theme-avatar-edit {
      position: relative;
      width: 200px;
      height: 200px;
      & > img.theme-settings-avatar {
        display: block;
        width: 200px !important;
        height: 200px !important;
        margin: 0;
        border-radius: 50%;
        box-shadow: 0 0 0 1px var(--color-light-border);
      }
      & > .theme-dropdown {
        position: absolute;
        bottom: 12px;
        left: 8px;
      }
      & > .theme-dropdown > .theme-dropdown-panel {
        inset: calc(100% + 4px) auto auto 0;
        width: 200px;
      }
    }
    & > .help {
      margin: 12px 0 0;
      color: var(--color-text-light-1);
      font-size: 12px;
      line-height: 18px;
    }
    & .field.tw-pl-4 {
      padding-left: 20px !important;
    }
    & input:is([type="file"], [type="text"], :not([type])) {
      width: 100%;
      max-width: 100%;
    }
    & .button-sequence {
      display: flex;
      flex-direction: column;
      align-items: stretch;
      gap: 8px;
    }
  }
  /* Forgejo's form groups ("About you", "Privacy") read as small section titles. A legend is drawn across its
     fieldset's top border, which put "Privacy" on the divider above it; floated, it sits inside the fieldset like any
     heading, 16px below the divider. The profile picture's title in the aside matches it. */
  & .ui.form fieldset {
    margin-top: 0;
  }
  & .ui.form fieldset > legend,
  & .theme-settings-aside > h3 {
    margin: 0 0 8px;
    padding: 0;
    font-size: 16px;
    font-weight: 600;
    line-height: 24px;
  }
  & .ui.form fieldset > legend {
    float: left;
    width: 100%;
    border: 0;
    & + * {
      clear: both;
    }
  }
  & .ui.form fieldset + fieldset {
    margin-top: 24px;
    padding-top: 16px;
    border-top: 1px solid color-mix(in srgb, var(--color-light-border) 70%, transparent);
  }

  /* Buttons: GitHub's 32px controls with 500-weight labels, for Fomantic's .ui.button and Forgejo's newer .button. */
  & :is(.ui.button, .button:not(.ui)):not(.tiny, .mini, .compact, .icon) {
    min-height: 32px;
    padding: 5px 16px;
    font-size: 14px;
    font-weight: 500;
    line-height: 20px;
  }

  /* GitHub's settings checkbox (components/common/settings/checkbox.tmpl): the box in a 20px gutter beside a
     semibold title, with the note beneath the title. */
  & .theme-settings-checkbox {
    position: relative;
    margin: 15px 0;
    padding-left: 20px;
    & > input[type="checkbox"] {
      position: absolute;
      top: 4px;
      left: 0;
      margin: 0;
    }
    & > label {
      display: inline;
      margin: 0;
      color: var(--color-text);
      font-size: 14px;
      font-weight: 600;
      line-height: 21px;
      cursor: pointer;
    }
    & > input:disabled + label {
      color: var(--color-text-light-1);
      cursor: default;
    }
  }
  & .theme-settings-checkbox-note {
    margin: 0;
    color: var(--color-text-light-1);
    font-size: 12px;
    line-height: 18px;
  }
}

@media (max-width: 767.98px) {
  .ui.container.flex-container.theme-settings {
    gap: 24px;
  }

  .theme-settings > .flex-container-nav {
    width: auto;
  }

  .page-content
    > .ui.container.flex-container.theme-settings
    > .flex-container-main
    .ui.attached.segment.theme-settings-columns {
    grid-template-columns: minmax(0, 1fr);
  }

  .theme-settings-context {
    flex-wrap: wrap;
  }
}
