/* The assistant: a sheet floating over the bottom right corner of the atelier */
body.workshop {
  .ai-drawer {
    align-self: auto;
    animation: rise 220ms ease;
    background: var(--surface);
    block-size: min(var(--sheet-height, 520px), calc(100dvh - 104px));
    border: 0;
    border-radius: var(--radius-xl);
    box-shadow: var(--shadow-sheet);
    display: none;
    font-size: 13.5px;
    grid-area: auto;
    inline-size: min(var(--sheet-width, 380px), calc(100vw - 40px));
    inset: auto 20px 52px auto;
    max-block-size: none;
    min-block-size: 0;
    overflow: hidden;
    position: fixed;
    text-align: start;
    z-index: 30;
  }

  .ai-drawer--open {
    display: flex;
    flex-direction: column;
  }

  .ai-drawer__panel {
    background: transparent;
    block-size: 100%;
    border: 0;
    box-shadow: none;
    display: flex;
    flex-direction: column;
    font-size: inherit;
    inline-size: 100%;
    min-block-size: 0;
    position: static;
    transform: none;
  }

  .ai-drawer__backdrop {
    display: none;
  }

  /* Pulled by its left and top edges, for it is held by the bottom right corner */
  .ai-drawer__resizer {
    position: absolute;
    touch-action: none;
    z-index: 2;
  }

  .ai-drawer__resizer--left {
    cursor: ew-resize;
    inline-size: 6px;
    inset: 0 auto 0 0;
  }

  .ai-drawer__resizer--top {
    block-size: 6px;
    cursor: ns-resize;
    inset: 0 0 auto 0;
  }

  /* Two strokes past the rounded corner, which would cut them off */
  .ai-drawer__resizer--corner {
    background: linear-gradient(135deg, transparent 46%, var(--ink-4) 46% 52%, transparent 52% 62%, var(--ink-4) 62% 68%, transparent 68%);
    block-size: 20px;
    cursor: nwse-resize;
    inline-size: 20px;
    inset: 0 auto auto 0;
    opacity: 0.45;
    transition: opacity 120ms ease;
    z-index: 3;

    &:hover {
      opacity: 1;
    }
  }

  .ai-drawer.resizing {
    user-select: none;
  }

  .ai-drawer__sheet-header {
    align-items: center;
    background: linear-gradient(120deg, oklch(62% 0.2 300 / 0.06), oklch(62% 0.16 255 / 0.06));
    border-block-end: 1px solid var(--border-soft);
    display: flex;
    flex-shrink: 0;
    gap: 10px;
    padding: 12px 12px 12px 18px;

    > img {
      opacity: 0.6;
    }
  }

  .ai-drawer__sheet-title {
    font-size: 13.5px;
    font-weight: 700;
    line-height: 1.2;
  }

  .ai-drawer__context {
    color: var(--ink-3);
    font-size: 11.5px;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
  }

  .ai-drawer .ai-drawer__close {
    align-self: center;
    display: grid;
    margin: 0;
  }

  .ai-drawer__frame,
  .ai-drawer__content {
    display: flex;
    flex: 1;
    flex-direction: column;
    gap: 0;
    min-block-size: 0;
    padding: 0;
  }

  /* The conversation at hand, and the menu to change it */
  .ai-drawer__header {
    align-items: center;
    background: transparent;
    display: flex;
    flex-shrink: 0;
    gap: 6px;
    padding: 8px 12px 4px 14px;
    position: relative;
  }

  .ai-drawer__title {
    color: var(--ink-2);
    font-size: 12.5px;
    font-weight: 600;
  }

  .ai-drawer__back,
  .ai-drawer__title-edit {
    --btn-background: transparent;
    --btn-padding: 2px 6px;
    --btn-shadow: none;

    color: var(--ink-3);
  }

  .ai-drawer__new {
    --btn-padding: 5px 10px;

    font-size: 11.5px;
    white-space: nowrap;
  }

  .ai-drawer__menu {
    summary {
      block-size: 28px;
      border-radius: var(--radius-xs);
      cursor: pointer;
      display: grid;
      inline-size: 28px;
      list-style: none;
      place-items: center;

      &::-webkit-details-marker {
        display: none;
      }

      img {
        opacity: 0.55;
      }

      &:hover {
        background: var(--surface-hover);
      }
    }

    &[open] summary {
      background: var(--surface-hover);
    }
  }

  .ai-drawer__menu-body {
    animation: pop 150ms ease;
    background: var(--surface);
    border-radius: var(--radius-menu);
    box-shadow: var(--shadow-lg);
    display: flex;
    flex-direction: column;
    gap: 6px;
    inline-size: 300px;
    inset: calc(100% + 2px) 12px auto auto;
    max-block-size: 320px;
    overflow: auto;
    padding: 12px;
    position: absolute;
    z-index: 3;
  }

  .ai-drawer__model-form {
    margin: 0 0 6px;
  }

  .ai-drawer__list,
  .ai-drawer__sibling-list {
    display: flex;
    flex-direction: column;
    gap: 2px;
    list-style: none;
    margin: 0;
    padding: 0 8px;
  }

  .ai-drawer__sibling-list {
    padding: 0;
  }

  .ai-conversation {
    align-items: center;
    border-radius: var(--radius);
    display: flex;
    gap: 4px;

    &:hover {
      background: var(--bg-flat);
    }
  }

  .ai-conversation--active {
    background: var(--panel);
  }

  .ai-conversation__link {
    color: var(--ink);
    flex: 1;
    font-size: 13px;
    min-inline-size: 0;
    overflow: hidden;
    padding: 7px 10px;
    text-overflow: ellipsis;
    white-space: nowrap;
  }

  /* Messages */
  .ai-drawer__messages {
    display: flex;
    flex: 1;
    flex-direction: column;
    gap: 10px;
    min-block-size: 0;
    overflow-y: auto;
    padding: 10px 16px 12px;
  }

  .ai-message {
    border: 0;
    margin: 0;
    max-inline-size: 86%;
  }

  .ai-message--user {
    align-self: flex-end;
    background: var(--accent-deep);
    border-radius: 16px;
    color: oklch(100% 0 0);
    font-size: 13.5px;
    padding: 9px 13px;
  }

  .ai-message--assistant {
    align-self: flex-start;
    background: var(--panel);
    border-radius: 16px;
    color: var(--ink);
    font-family: var(--font-book);
    font-size: 15px;
    line-height: 1.5;
    padding: 11px 14px;
  }

  .ai-message__body {
    > :first-child { margin-block-start: 0; }
    > :last-child { margin-block-end: 0; }
  }

  .ai-message--pending {
    align-items: center;
    color: var(--ink-3);
    display: flex;
    font-family: var(--font-sans);
    font-size: 12.5px;
    gap: 10px;
  }

  .ai-message__stop,
  .ai-message__retry {
    --btn-padding: 4px 9px;

    font-size: 11.5px;
  }

  .ai-message__failed {
    color: var(--danger);
    font-family: var(--font-sans);
    font-size: 12.5px;
    margin: 0 0 8px;
  }

  .ai-drawer__empty,
  .ai-drawer__loading,
  .ai-drawer__placeholder {
    color: var(--ink-3);
    font-size: 12.5px;
    margin: 0;
    padding: 14px 18px;
    text-align: start;
  }

  /* Suggestions and the composer */
  .ai-drawer__suggestions {
    display: flex;
    flex-shrink: 0;
    flex-wrap: wrap;
    gap: 6px;
    padding: 0 16px 10px;
  }

  .ai-drawer__suggestion {
    background: var(--panel);
    border: 0;
    border-radius: var(--radius-pill);
    color: var(--ink-2);
    cursor: pointer;
    font-size: 11.5px;
    font-weight: 600;
    padding: 5px 10px;

    &:hover {
      background: var(--surface-hover);
    }
  }

  .ai-drawer__composer {
    align-items: flex-end;
    background: var(--bg-flat);
    border: 1px solid var(--border);
    border-radius: var(--radius-menu);
    display: flex;
    flex-shrink: 0;
    gap: 8px;
    margin: 0 12px 12px;
    padding: 8px 8px 8px 12px;

    &:focus-within {
      border-color: var(--accent);
    }
  }

  .ai-drawer__input {
    background: transparent;
    border: 0;
    color: inherit;
    field-sizing: content;
    flex: 1;
    font-size: 13.5px;
    line-height: 1.45;
    max-block-size: 120px;
    min-block-size: 38px;
    outline: 0;
    padding: 4px 0;
    resize: none;

    &:disabled {
      opacity: 0.5;
    }
  }

  .ai-drawer__send {
    background: var(--accent);
    block-size: 32px;
    border: 0;
    border-radius: 11px;
    cursor: pointer;
    display: grid;
    flex-shrink: 0;
    inline-size: 32px;
    place-items: center;

    img {
      filter: invert(1);
    }

    &:disabled {
      opacity: 0.4;
    }
  }
}
