/* PayaSim dossier template and required-document dialog. Design pass based on
   Unslop by Damir Sokolovsky (@heydamir), CC BY 4.0. */
.paya-dialog[role="dialog"]:has(.paya-card > p.break-words[dir="ltr"] + form.space-y-3) {
  --templates-inset: 24px;
  --templates-columns: minmax(0, 1fr) minmax(0, 1fr);
  container: dossier-templates / inline-size;
  max-inline-size: min(1080px, calc(100vw - 24px));
  border-radius: 12px;

  & > [data-paya-focus-scope] > header {
    background: var(--surface);
    border-start-start-radius: 12px;
    border-start-end-radius: 12px;
    padding: 12px var(--templates-inset) !important;

    & span[id] {
      font-size: 18px !important;
      font-weight: 600 !important;
      line-height: 26px;
      letter-spacing: 0;
    }
  }

  & > [data-paya-focus-scope] > div {
    min-inline-size: 0;

    & > div {
      padding: 16px var(--templates-inset) 20px !important;
    }
  }

  & [data-paya-field-message][data-paya-message-empty="true"] { display: none; }

  & label {
    min-inline-size: 0;
    gap: 4px;

    & > span:first-child {
      color: var(--foreground);
      font-size: 13px;
      line-height: 20px;
      font-weight: 500;
    }
  }

  & :is(.paya-input-wrap, select) {
    min-block-size: var(--paya-control-height, 36px) !important;
  }

  & .space-y-4:has(> label + label + .space-y-4) {
    display: grid;
    grid-template-columns: var(--templates-columns);
    align-items: end;
    gap: 12px;

    & > * { margin-block: 0; }

    & > .space-y-4 {
      grid-column: 1 / -1;
      display: grid;
      gap: 0;
      margin-inline: calc(-1 * var(--templates-inset));

      & > .paya-card {
        min-inline-size: 0;
        margin: 0;
        padding: 16px var(--templates-inset) 20px;
        border: 0;
        border-block-start: 1px solid var(--border);
        border-radius: 0;
        background: transparent;
        box-shadow: none;

        & h2 {
          margin: 0;
          font-size: 16px;
          font-weight: 600;
          line-height: 24px;
        }

        & p {
          color: var(--muted);
          font-size: 13px;
          line-height: 1.75;
        }
      }
    }
  }

  & .paya-card > p.break-words[dir="ltr"] {
    margin: 8px 0 12px;
    padding: 8px 12px;
    background: var(--surface-secondary);
    border: 1px solid var(--border);
    border-radius: 8px;
    font-family: ui-monospace, monospace;
    font-size: 12px;
    text-align: start;
    overflow-wrap: anywhere;
    user-select: text;

    &:empty { display: none; }
  }

  & :is(.paya-card > form.space-y-3, .paya-card:not(:has(> form.space-y-3))) {
    display: grid;
    grid-template-columns: var(--templates-columns);
    align-items: start;
    gap: 12px;

    & > * { margin-block: 0; }
    & > :is(p, div) { grid-column: 1 / -1; }
    & > button { justify-self: start; max-inline-size: 100%; }
  }

  & .paya-card > form.space-y-3 {
    & > label:first-child, & > label:nth-of-type(4), & > label:has(textarea), & > button {
      grid-column: 1 / -1;
    }

    & textarea {
      min-block-size: 152px !important;
      block-size: 152px;
    }
  }

  & .paya-card:not(:has(> form.space-y-3)) {
    & > button:first-of-type { justify-self: end; }
    & > button:last-child { grid-column: 1 / -1; }

    & > div:has(> [data-paya-choice]) {
      display: flex;
      flex-wrap: wrap;
      gap: 8px 16px;

      & > label {
        margin: 0;
        min-block-size: var(--paya-control-height, 36px);
      }
    }
  }
}

@container dossier-templates (max-width: 600px) {
  .paya-dialog[role="dialog"]:has(.paya-card > p.break-words[dir="ltr"] + form.space-y-3) > [data-paya-focus-scope] {
    --templates-inset: 16px;
    --templates-columns: minmax(0, 1fr);
  }

  .paya-dialog[role="dialog"]:has(.paya-card > p.break-words[dir="ltr"] + form.space-y-3)
    .paya-card:not(:has(> form.space-y-3)) > button:first-of-type {
    justify-self: start;
  }

  .paya-dialog[role="dialog"]:has(.paya-card > p.break-words[dir="ltr"] + form.space-y-3)
    .paya-card > p.break-words[dir="ltr"] {
    max-block-size: 144px;
    overflow: auto;
    scrollbar-gutter: stable;
    font-size: 12px;
    line-height: 1.6;
  }
}
