/*
 * Markdown editor: GitHub's comment editor, written once for every place Forgejo renders its own
 * markdown editor: a bordered box whose header carries the Write/Preview tabs and the toolbar, and
 * a plain attachment line instead of a dashed drop area. To style another editor, add its container
 * to the list. Forms whose description is their main field set a taller editor below. The release
 * form keeps Forgejo's drop area and only takes the editor.
 */
:is(
    .page-content.repository.view.issue.github-conversation .comment.form,
    .ui.form.theme-issue-form,
    .review-box-panel,
    .comment-code-cloud,
    .page-content.repository.new.release,
    .page-content.repository.wiki.new
  )
  .combo-markdown-editor {
  overflow: visible;
  border: 1px solid var(--color-light-border);
  border-radius: var(--border-radius);
  background: var(--color-body);

  /* The header is 38px high with its bottom border. */
  & markdown-toolbar {
    min-height: 38px;
    padding: 0 8px 0 0;
    gap: 8px;
    border-bottom: 1px solid var(--color-light-border);
    border-radius: var(--border-radius) var(--border-radius) 0 0;
    background: var(--color-box-header);

    /*
     * The button groups, which templates/shared/combomarkdowneditor.tmpl wraps, stay one row beside
     * the tabs and scroll sideways when they do not fit, as on a phone, spaced as the header is.
     */
    & .theme-markdown-toolbar-actions {
      display: flex;
      flex: 1 1 0;
      align-items: center;
      gap: inherit;
      min-width: 0;
      overflow-x: auto;
      scrollbar-width: thin;
      & > :first-child {
        margin-inline-start: auto;
      }
    }
    & .markdown-toolbar-group {
      flex: 0 0 auto;
    }
    /*
     * GitHub's tabs lie on the box's top and left border and on the header's bottom border, and
     * span the header, which grows while a scrollbar under the buttons takes room.
     */
    & .switch {
      align-self: stretch;
      align-items: stretch;
      height: auto;
      margin: -1px 0 -1px -1px;
      border: 0;
      border-radius: 0;
      background: transparent;
    }
    & .switch .item {
      height: auto;
      min-height: 39px;
      margin: 0;
      padding: 9px 16px;
      border: 1px solid transparent;
      border-bottom: 0;
      border-radius: var(--border-radius) var(--border-radius) 0 0;
      background: transparent;
      box-shadow: none;
      outline: 0;
      color: var(--color-text-light-1);
      font-size: 14px;
      font-weight: 400;
      line-height: 20px;
    }
    /* The selected tab, with its own rounded border, opens into the body below it. */
    & .switch .item.active {
      border-color: var(--color-light-border);
      background: var(--color-body);
      color: var(--color-text);
    }
    & .switch .item:focus-visible {
      outline: 2px solid var(--github-fgColor-accent);
      outline-offset: -6px;
    }
    & .switch .item.active::before,
    & .switch .item.active::after {
      display: none;
    }
  }
  & .markdown-toolbar-button {
    width: 28px;
    height: 28px;
    padding: 6px;
    border: 0;
    border-radius: var(--border-radius);
    background: transparent;
    color: var(--color-text-light-1);
    &:hover {
      background: var(--github-control-transparent-bgColor-hover);
      color: var(--color-text-light-1);
    }
    /* Inside the button, so the scrolling button row never clips it. */
    &:focus-visible {
      outline: 2px solid var(--github-fgColor-accent);
      outline-offset: -2px;
    }
  }
  /* No background of its own, so it leaves the box's rounded bottom corners visible. */
  & > .ui.tab.markup {
    min-height: 136px;
    padding: 16px;
    font-size: 14px;
    line-height: 21px;
  }
  & textarea {
    width: calc(100% - 16px);
    height: auto;
    min-height: var(--theme-editor-min-height, 123px);
    max-height: calc(35lh + 18px);
    margin: 8px;
    padding: 8px;
    field-sizing: content;
    border: 1px solid var(--color-light-border);
    border-radius: var(--border-radius);
    background: var(--color-body);
    box-shadow: none;
    font-family: var(--fonts-proportional);
    font-size: 14px;
    line-height: 20px;
    /* GitHub's focus ring takes the place of the border. */
    &:focus {
      border-color: transparent;
      outline: 2px solid var(--github-borderColor-accent-emphasis);
      outline-offset: -2px;
    }
  }
  /*
   * The attach line inside the box, below the text area (shared/combomarkdowneditor's Upload), as
   * GitHub's: a 36px row with the paperclip 15px from the box's edge, the text area's bottom margin
   * given up to it.
   */
  & [data-tab-panel="markdown-writer"]:has(> .ui.dropzone) textarea {
    margin-bottom: 0;
  }
  & [data-tab-panel="markdown-writer"] > .ui.dropzone {
    padding: 2px 7px;
  }
}
.ui.form.theme-issue-form,
.page-content.repository.new.release {
  --theme-editor-min-height: 200px;
}
:is(
    .page-content.repository.view.issue.github-conversation .comment.form,
    .ui.form.theme-issue-form,
    .review-box-panel,
    .comment-code-cloud
  )
  .ui.dropzone {
  min-height: 32px;
  padding: 0;
  border: 0;
  background: transparent;
  & .dz-message {
    margin: 0;
    text-align: left;
  }
  /* Forgejo colours the button with !important (features/dropzone.css). */
  & .dz-button {
    display: inline-flex;
    align-items: center;
    gap: 4px;
    padding: 6px 8px;
    min-height: 32px;
    font-size: 12px;
    line-height: 18px;
    font-weight: 400;
    color: var(--color-text-light-1) !important;
    background: transparent;
    border: 0;
    box-shadow: none;
  }
}

/* GitHub's attach control leads with a paperclip; Dropzone renders the button, so draw it in CSS. */
.page-content.repository.view.issue.github-conversation .comment.form .ui.dropzone .dz-button::before,
.ui.form.theme-issue-form .ui.dropzone .dz-button::before {
  content: "";
  flex-shrink: 0;
  width: 16px;
  height: 16px;
  background-color: currentcolor;
  mask: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 16 16'%3E%3Cpath d='M12.212 3.02a1.753 1.753 0 0 0-2.478.003l-5.83 5.83a3 3 0 0 0-.88 2.127c0 .795.315 1.551.88 2.116.567.567 1.333.89 2.126.89.79 0 1.548-.321 2.116-.89l5.48-5.48a.75.75 0 0 1 1.061 1.06l-5.48 5.48a4.5 4.5 0 0 1-3.177 1.33c-1.2 0-2.345-.487-3.187-1.33a4.48 4.48 0 0 1-1.32-3.177c0-1.195.475-2.341 1.32-3.186l5.83-5.83a3.25 3.25 0 0 1 5.553 2.297c0 .863-.343 1.691-.953 2.301L7.439 12.39c-.375.377-.884.59-1.416.593a2 2 0 0 1-1.412-.593 1.99 1.99 0 0 1 0-2.828l5.48-5.48a.75.75 0 0 1 1.042.018.75.75 0 0 1 .018 1.042l-5.48 5.48a.49.49 0 0 0 0 .707.5.5 0 0 0 .352.154.5.5 0 0 0 .356-.154l5.833-5.827a1.755 1.755 0 0 0 0-2.481Z'/%3E%3C/svg%3E")
    center / 16px no-repeat;
}
