@use 'global/common' as global;

/* ------------------------------
 モーダル
------------------------------- */

@keyframes fade-in-bottom {
  0% {
    opacity: 0;
    transform: translateY(50px);
  }

  100% {
    opacity: 1;
    transform: translateY(0);
  }
}

@keyframes fade-out-top {
  0% {
    visibility: visible;
    opacity: 1;
    transform: translateY(0);
  }

  100% {
    visibility: hidden;
    opacity: 0;
    transform: translateY(-50px);
  }
}

.acms-modal {
  --acms-modal-width: 800px;
  --acms-modal-margin: 10px;
  --acms-modal-content-padding: 5px;
  --acms-modal-header-padding-x: 10px;
  --acms-modal-header-padding-y: 5px;
  --acms-modal-body-padding-x: 10px;
  --acms-modal-body-padding-y: 10px;
  --acms-modal-footer-padding-x: 10px;
  --acms-modal-footer-padding-y: 10px;
  --acms-modal-border-radius: 6px;

  position: fixed;
  inset: 0;
  z-index: global.zIndex(acms-modal);
  width: 100%;
  height: 100%;
  padding-right: calc(constant(safe-area-inset-right));
  padding-left: calc(constant(safe-area-inset-left));
  overflow: hidden auto;
  outline: 0;
  opacity: 0;
  transform: translate3d(0, 0, 0);
  -webkit-overflow-scrolling: touch;

  @if global.$admin == true {
    font-family: global.$acms-admin-font-family;
  }
}

.acms-modal.in {
  opacity: 1;
  transition: opacity 0.3s;
}

.acms-modal.out {
  opacity: 0;
  transition: opacity 0.3s;
}

.acms-modal.display {
  opacity: 1;
}

.acms-modal.in .acms-modal-dialog {
  animation: fade-in-bottom 0.3s cubic-bezier(0.39, 0.575, 0.565, 1) forwards;
}

.acms-modal.out .acms-modal-dialog {
  animation: fade-out-top 0.3s cubic-bezier(0.25, 0.46, 0.45, 0.94) forwards;
}

@media (prefers-reduced-motion) {
  .acms-modal.in .acms-modal-dialog {
    animation: none;
  }

  .acms-modal.out .acms-modal-dialog {
    animation: none;
  }
}

.acms-modal-middle {
  position: fixed;
  overflow: hidden;

  &.display {
    bottom: 0;
  }

  .acms-modal-dialog {
    height: 100vh;
    box-shadow: none;
  }

  .acms-modal-content {
    margin: 50px auto;
  }
}

.acms-modal-middle-scroll {
  max-height: 50vh;
  overflow: auto;
}

.acms-modal-dialog {
  position: relative;
  width: 95%;
  max-width: var(--acms-modal-width);
  margin: var(--acms-modal-margin) auto;

  // dialog-centered などで dialog が画面いっぱいに広がるケースのために
  // 余白部分のクリックを backdrop に透過させる (Bootstrap 5 と同じ手法)
  pointer-events: none;
}

.acms-modal-dialog.large {
  --acms-modal-width: 1200px;
}

.acms-modal-dialog.medium {
  --acms-modal-width: 1200px;
}

.acms-modal-dialog.small {
  --acms-modal-width: 600px;
}

.acms-modal-dialog.acms-modal-dialog-centered {
  display: flex;
  align-items: center;
  min-height: calc(100% - var(--acms-modal-margin) * 2);
}

.acms-modal-dialog.acms-modal-dialog-scrollable {
  height: calc(100% - var(--acms-modal-margin) * 2);

  .acms-modal-content {
    max-height: 100%;
    overflow: hidden;
  }

  .acms-modal-body {
    overflow-y: auto;
  }
}

@include global.media-breakpoint-up(md) {
  .acms-modal-dialog {
    --acms-modal-margin: 30px;

    margin: var(--acms-modal-margin) auto;
  }

  .acms-modal-dialog.medium {
    width: 75%;
  }
}

.acms-modal-content {
  box-sizing: border-box;
  display: flex;
  flex-direction: column;
  width: 100%;
  padding: var(--acms-modal-content-padding);
  overflow: hidden;

  // 親の dialog で pointer-events: none にしているため、実コンテンツでは復活させる
  pointer-events: auto;
  background: global.$acms-color-white;
  border-radius: var(--acms-modal-border-radius);
  box-shadow: 0 4px 48px 0 rgb(0 0 0 / 25%);
}

.acms-modal-header {
  display: flex;
  flex-shrink: 0;
  align-items: center;
  justify-content: space-between;
  padding: var(--acms-modal-header-padding-y) var(--acms-modal-header-padding-x);
  margin: 0 calc(-1 * var(--acms-modal-content-padding));
  border-bottom: 1px solid global.$acms-color-gray60;
}

.acms-modal-heading {
  margin: 0;
  color: global.$acms-color-black;

  @include global.font-size(14);
}

.acms-modal-body {
  padding: var(--acms-modal-body-padding-y) var(--acms-modal-body-padding-x);
  margin: 0 -5px;

  @include global.font-size(14);
}

.acms-modal-body-fit {
  margin: 0 -10px;
}

.acms-modal-body-tab-scrollable .acms-tabs-panel {
  max-height: calc(100vh - 300px);
  overflow-y: auto;
}

.acms-modal-backdrop {
  @include global.backdrop;
}

.acms-modal-hide {
  order: 99; // 一番右に配置（互換性のために指定している。利用する場合はHTML構造として最後に配置することを推奨）
  padding: 0;
  margin-left: auto;
  font-size: 20px;
  line-height: 1;
  color: global.$acms-color-gray90;
  cursor: pointer;
  background: global.$acms-color-white;
  border: 1px solid transparent;

  &:focus {
    border-color: global.$acms-btn-focus-border-color;
    outline: 0;
  }
}

.acms-modal-footer {
  padding: var(--acms-modal-body-padding-y) var(--acms-modal-body-padding-x);
  margin: 0 calc(-1 * var(--acms-modal-content-padding));
  text-align: right;
  border-top: 1px solid global.$acms-color-gray60;
}

.acms-modal .acms-modal-quick-search {
  max-width: 700px;
  height: auto;

  .acms-table-hover tr:hover td,
  .acms-table-hover tr:focus-within td {
    background: global.$acms-color-info10;
  }

  .acms-table-hover tr.hover td {
    background: global.$acms-color-info10;
  }
}

@include global.media-breakpoint-up(md) {
  .acms-modal-header {
    --acms-modal-header-padding-x: 15px;
    --acms-modal-header-padding-y: 15px;
  }

  .acms-modal-heading {
    @include global.font-size(18);
  }

  .acms-modal-body {
    --acms-modal-body-padding-x: 15px;
  }
}

// モジュールのタイトル
.acms-title-wrapper {
  position: relative;

  .acms-modal-heading {
    margin: 15px 0;
  }

  // アイコン
  .acms-icon {
    position: absolute;
    top: 2px;
    left: 0;
  }

  strong {
    display: block;
    margin-bottom: 10px;

    @include global.font-size(13);
  }

  h1 {
    margin: 0;

    @include global.font-size(20);
  }

  .acms-module-en {
    display: inline-block;
    margin: 0 15px 10px 0;
    font-weight: bold;
    color: global.$acms-color-gray90;

    @include global.font-size(12);
  }
}
