@use "colors";
@use "variables";

/* =Dialog Patterns — Nested/stacked dialog styling
-----------------------------------------------------------------------------*/

/* Dialog Sizes */
dialog.dialog-sm {
  max-width: 24rem;
}

dialog.dialog-lg {
  max-width: 48rem;
}

dialog.dialog-full {
  max-width: calc(100vw - 2rem);
  max-height: calc(100vh - 2rem);
  width: 100%;
  height: 100%;
}

/* Dialog Layout Sections */
dialog {
  .dialog-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: variables.$padding * 1.33 variables.$base-line;
    border-bottom: 1px solid var(--ply-border-color);

    h1, h2, h3, h4, h5, h6 {
      margin: 0;
      font-size: variables.$font-size-lg;
    }
  }

  .dialog-body {
    padding: variables.$base-line;
    overflow-y: auto;
  }

  .dialog-footer {
    display: flex;
    align-items: center;
    justify-content: flex-end;
    gap: variables.$grid-gutter-width;
    padding: variables.$padding * 1.33 variables.$base-line;
    border-top: 1px solid var(--ply-border-color);
  }

  .dialog-close {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 2rem;
    height: 2rem;
    padding: 0;
    border: none;
    background: none;
    color: var(--ply-color-secondary);
    font-size: variables.$font-size-xl;
    cursor: pointer;
    border-radius: var(--ply-border-radius);
    transition: background-color 0.15s ease;

    &:hover {
      background-color: var(--ply-bg-surface-alt);
      color: var(--ply-color-body);
    }

    &:focus-visible {
      outline: 2px solid var(--ply-color-focus, colors.$color-blue);
      outline-offset: 2px;
    }
  }
}

/* Stacked Dialogs — z-index layering */
dialog[open] {
  &.dialog-layer-1 {
    z-index: 100;
  }

  &.dialog-layer-2 {
    z-index: 110;
  }

  &.dialog-layer-3 {
    z-index: 120;
  }
}

dialog::backdrop {
  background: var(--ply-backdrop, rgba(0, 0, 0, 0.5));
}

dialog.dialog-layer-2::backdrop {
  background: var(--ply-backdrop-nested, rgba(0, 0, 0, 0.35));
}

dialog.dialog-layer-3::backdrop {
  background: var(--ply-backdrop-nested, rgba(0, 0, 0, 0.25));
}

/* Confirmation Dialog — compact variant */
dialog.dialog-confirm {
  max-width: 28rem;
  text-align: center;

  .dialog-body {
    padding: variables.$base-line * 1.33 variables.$base-line variables.$padding * 1.33;
  }

  .dialog-footer {
    justify-content: center;
    border-top: none;
    padding-top: 0;
  }
}

/* Dialog with scrollable body */
dialog.dialog-scroll[open] {
  display: flex;
  flex-direction: column;
  max-height: calc(100vh - 4rem);

  .dialog-body {
    flex: 1 1 auto;
    overflow-y: auto;
    min-height: 0;
  }

  .dialog-header,
  .dialog-footer {
    flex-shrink: 0;
  }
}

/* Dialog animation */
dialog[open] {
  animation: dialog-fade-in 0.15s ease;
}

dialog[open]::backdrop {
  animation: dialog-backdrop-in 0.15s ease;
}

@keyframes dialog-fade-in {
  from {
    opacity: 0;
    transform: translateY(-0.5rem);
  }

  to {
    opacity: 1;
    transform: translateY(0);
  }
}

@keyframes dialog-backdrop-in {
  from {
    opacity: 0;
  }

  to {
    opacity: 1;
  }
}

@media (prefers-reduced-motion: reduce) {
  dialog[open],
  dialog[open]::backdrop {
    animation: none;
  }
}
