@import '../config/import';

.crayons-modal {
  --modal-max-width: 640px;
  --modal-padding: var(--su-3);
  --modal-backdrop-pointer-events: none;
  --modal-border: none;
  --modal-header-border: 1px solid var(--divider);
  --modal-header-padding: var(--su-2) var(--su-2) var(--su-2)
    var(--modal-padding);
  --modal-alignment: unset;
  --modal-header-alignment: space-between;
  --modal-overflow: hidden;

  @media (min-width: $breakpoint-s) {
    --modal-padding: var(--su-4);
  }

  @media (min-width: $breakpoint-m) {
    --modal-padding: var(--su-7);
  }

  position: fixed;
  left: 0;
  right: 0;
  top: 0;
  bottom: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: var(--z-modal);
  pointer-events: none;

  &--bg-dismissible {
    --modal-backdrop-pointer-events: auto;
  }

  &--prompt {
    --modal-header-border: none;
    --modal-header-padding: var(--modal-padding) var(--su-8) 0
      var(--modal-padding);
    --modal-body-margin: 0;

    @media (min-width: $breakpoint-m) {
      --modal-body-margin: calc((var(--modal-padding) * -1) + var(--su-4));
    }

    .crayons-modal__dismiss {
      position: absolute;
      right: var(--su-2);
      top: var(--su-2);
    }
  }

  &--centered {
    --modal-header-padding: var(--su-7) var(--su-8) 0 var(--su-8);
    --modal-alignment: center;
    --modal-header-alignment: center;
  }

  &--danger {
    --modal-border: 4px solid var(--modal-danger-border-color);
  }

  &__backdrop {
    background: var(--modal-backdrop);
    position: absolute;
    left: 0;
    right: 0;
    top: 0;
    bottom: 0;
    pointer-events: auto;
  }

  &__box {
    display: grid;
    grid-template-rows: auto 1fr;
    max-width: var(--modal-max-width);
    background: var(--modal-bg);
    z-index: var(--z-elevate);
    max-height: 100%;
    width: 100%;
    height: 100%;
    overflow: var(--modal-overflow);
    position: relative;
    pointer-events: auto;
    border-radius: var(--radius-large-auto);
    border: var(--modal-border);
    text-align: var(--modal-alignment);
    box-shadow: var(--shadow-2);

    @media (min-width: $breakpoint-s) {
      max-height: calc(100% - var(--su-6));
      height: auto;
      width: 90%;
    }

    &__header {
      border-bottom: var(--modal-header-border);
      padding: var(--modal-header-padding);
      flex-shrink: 0;
      display: flex;
      justify-content: var(--modal-header-alignment);
      align-items: center;
    }

    &__body {
      padding: var(--modal-padding);
      margin-top: var(--modal-body-margin);
      max-height: 100%;
      overflow-y: auto;
      grid-auto-rows: min-content;
    }
  }

  &--small {
    @media (min-width: $breakpoint-s) {
      --modal-max-width: 480px;
    }
  }

  &--large {
    @media (min-width: $breakpoint-m) {
      --modal-max-width: 768px;
    }
  }

  &--sheet {
    height: 100%;

    .crayons-modal__box {
      height: 100%;
      max-height: 100%;
      border-radius: 0;
      grid-template-rows: 1fr;
    }

    &.crayons-modal--left {
      .crayons-modal__box {
        position: absolute;
        left: 0;
      }
    }

    &.crayons-modal--right {
      .crayons-modal__box {
        position: absolute;
        right: 0;
      }
    }
  }

  &--overflow-visible {
    --modal-overflow: visible;
  }

  &--prompt {
    @media (min-width: $breakpoint-s) {
      --modal-max-width: 480px;
    }
  }
}


.cookie-consent-modal {
  background: white;
  position: fixed;
  padding: var(--su-5);
  bottom: var(--su-2);
  left: var(--su-3);
  right: var(--su-3);
  margin: 0 auto;
  max-width: 700px;
  border-radius: var(--radius);
  box-shadow: var(--shadow-2);
  text-align: center;
  z-index: var(--z-modal);
  p {
    font-size: var(--fs-base);
    color: var(--text-color);
    margin-bottom: var(--su-2);
  }
  .cookie-consent-modal__actions button {
    font-size: var(--fs-base);
    margin: var(--su-2);
  }
}

// Subforem Selection Modal
.subforem-modal {
  position: fixed;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  z-index: 9999;
  display: flex;
  align-items: center;
  justify-content: center;

  &.hidden {
    display: none;
  }

  &__backdrop {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background-color: rgba(0, 0, 0, 0.5);
    backdrop-filter: blur(2px);
  }

  &__container {
    position: relative;
    z-index: 1;
    width: 100%;
    max-width: 800px;
    margin: 0 0.5rem;
  }

  &__box {
    background: var(--card-bg);
    border-radius: 12px;
    box-shadow: 0 20px 25px -5px rgba(0, 0, 0, 0.1), 0 10px 10px -5px rgba(0, 0, 0, 0.04);
    border: 1px solid var(--card-border);
    overflow: hidden;
    animation: subforem-modal-slide-in 0.15s ease-out;
  }

  &__header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 1.5rem 1.5rem 1rem;
    border-bottom: 1px solid var(--card-border);
  }

  &__title {
    font-size: 1.25rem;
    font-weight: 600;
    color: var(--card-color);
    margin: 0;
  }

  &__close {
    background: none;
    border: none;
    padding: 0.5rem;
    border-radius: 6px;
    cursor: pointer;
    color: var(--base-60);
    transition: all 0.2s ease;

    &:hover {
      background-color: var(--base-10);
      color: var(--base-80);
    }
  }

  &__body {
    padding: 1rem 1.5rem 1.5rem;
  }

  &__description {
    color: var(--base-70);
    margin-bottom: 1rem;
    font-size: 0.95rem;
    line-height: 1.5;
  }

  &__options {
    max-height: 400px;
    overflow-y: auto;
    display: flex;
    flex-direction: column;
    gap: 0.4rem;
  }

  &__option {
    background: none;
    border: 1px solid var(--base-20);
    border-radius: 8px;
    padding: 0;
    cursor: pointer;
    transition: all 0.1s ease;
    text-align: left;
    width: 100%;
    text-decoration: none;
    display: block;

    &:hover {
      border-color: var(--base-30);
      background-color: var(--base-5);
      box-shadow: 0 4px 6px -1px rgba(0, 0, 0, 0.1);
      text-decoration: none;
    }

    &:active {
      transform: translateY(0);
    }
  }

  &__option-content {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 1rem;
  }

  &__option-left {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    flex: 1;
  }

  &__option-logo {
    width: 2rem;
    height: 2rem;
    border-radius: 6px;
    object-fit: cover;
    flex-shrink: 0;
  }

  &__option-text {
    flex: 1;
    min-width: 0;
  }

  &__option-name {
    font-weight: 500;
    color: var(--card-color);
    margin-bottom: 0.25rem;
    font-size: 0.95rem;
  }

  &__option-description {
    color: var(--base-60);
    font-size: 0.85rem;
    line-height: 1.4;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
  }

  &__option-arrow {
    color: var(--base-60);
    flex-shrink: 0;
    margin-left: 0.5rem;
  }

  // Responsive adjustments
  @media (max-width: 640px) {
    &__container {
      margin: 0 0.5rem;
    }
    
    &__header {
      padding: 1rem 1rem 0.75rem;
    }
    
    &__body {
      padding: 0.75rem 1rem 1rem;
    }
    
    &__option-content {
      padding: 0.75rem;
    }
    
    &__option-left {
      gap: 0.5rem;
    }
    
    &__option-logo {
      width: 1.75rem;
      height: 1.75rem;
    }
  }
}

@keyframes subforem-modal-slide-in {
  from {
    opacity: 0;
    transform: translateY(-20px) scale(0.95);
  }
  to {
    opacity: 1;
    transform: translateY(0) scale(1);
  }
}
