/* UI Modals — 15 named overlay patterns */

[data-modal] {
  position: relative;
  min-height: 28rem;
  height: 100%;
}

@media (max-width: 40rem) {
  [data-modal] {
    min-height: 30rem;
  }

  .modal-form-create,
  .modal-form-invite,
  .modal-form-feedback,
  .modal-sheet-action {
    min-height: 34rem;
  }
}

[data-modal].is-open .demo-canvas {
  pointer-events: none;
}

/* Shared overlay shell (centered dialogs) */
.modal-layer {
  position: absolute;
  inset: 0;
  z-index: 10;
  display: grid;
  place-items: center;
  padding: 1rem;
  opacity: 0;
  visibility: hidden;
  pointer-events: none;
  transition: opacity var(--motion), visibility var(--motion);
}

.is-open > .modal-layer,
.modal-layer.is-open {
  opacity: 1;
  visibility: visible;
  pointer-events: auto;
}

.modal-scrim {
  position: absolute;
  inset: 0;
  background: var(--scrim);
}

.modal-panel {
  position: relative;
  z-index: 1;
  width: min(100%, 26rem);
  max-height: calc(100% - 2rem);
  overflow-x: hidden;
  overflow-y: auto;
  border-radius: var(--modal-radius);
  background: var(--surface-raised);
  box-shadow: var(--modal-shadow);
  transform: translateY(0.5rem) scale(0.98);
  transition: transform var(--motion);
  scrollbar-gutter: stable;
  scrollbar-width: thin;
}

.modal-confirm-delete .modal-panel,
.modal-confirm-discard .modal-panel,
.modal-alert-info .modal-panel,
.modal-alert-success .modal-panel,
.modal-alert-error .modal-panel {
  overflow-y: visible;
  max-height: none;
}

.is-open > .modal-layer .modal-panel,
.modal-layer.is-open .modal-panel {
  transform: none;
}

.modal-panel__head {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 0.75rem;
  padding: 1.15rem 1.15rem 0;
}

.modal-panel__head h3 {
  margin: 0;
  font-size: 1.05rem;
  font-weight: 700;
  letter-spacing: -0.01em;
}

.modal-panel__body {
  padding: 0.75rem 1.15rem 1.15rem;
  color: var(--ink-muted);
  font-size: 0.9375rem;
}

.modal-panel__body > p:first-child {
  margin-top: 0;
}

.modal-panel__body > p:last-child {
  margin-bottom: 0;
}

.modal-panel__actions {
  display: flex;
  flex-wrap: wrap;
  justify-content: flex-end;
  gap: 0.5rem;
  padding: 0 1.15rem 1.15rem;
}

.modal-panel__icon {
  display: grid;
  place-items: center;
  width: 2.5rem;
  height: 2.5rem;
  margin: 1.15rem 1.15rem 0;
  border-radius: 999px;
  font-size: 1.15rem;
  font-weight: 700;
}

.modal-panel__icon--danger {
  background: var(--danger-soft);
  color: var(--danger);
}

.modal-panel__icon--warn {
  background: var(--warn-soft);
  color: var(--warn);
}

.modal-panel__icon--info {
  background: var(--info-soft);
  color: var(--info);
}

.modal-panel__icon--success {
  background: var(--success-soft);
  color: var(--success);
}

.modal-panel__list {
  margin: 0.75rem 0 0;
  padding: 0;
  list-style: none;
}

.modal-panel__list li {
  display: flex;
  justify-content: space-between;
  gap: 0.75rem;
  padding: 0.45rem 0;
  border-top: 1px solid var(--border);
  font-size: 0.875rem;
  color: var(--ink);
}

.modal-panel__list span {
  color: var(--ink-muted);
}

.modal-form {
  display: flex;
  flex-direction: column;
  gap: 0.85rem;
}

.modal-form__row {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 0.75rem;
}

@media (max-width: 28rem) {
  .modal-form__row {
    grid-template-columns: 1fr;
  }
}

/* 1. Confirm Delete */
.modal-confirm-delete .modal-panel {
  width: min(100%, 24rem);
}

.modal-confirm-delete .modal-panel__body strong {
  color: var(--ink);
}

/* 2. Confirm Discard */
.modal-confirm-discard .modal-panel {
  width: min(100%, 24rem);
}

/* 3. Confirm Bulk */
.modal-confirm-bulk .modal-panel {
  width: min(100%, 26rem);
}

.modal-confirm-bulk__meta {
  display: inline-flex;
  align-items: center;
  padding: 0.15rem 0.5rem;
  border-radius: 999px;
  background: var(--warn-soft);
  color: var(--warn);
  font-size: 0.75rem;
  font-weight: 700;
}

/* 4. Form Create */
.modal-form-create .modal-panel {
  width: min(100%, 28rem);
}

/* 5. Form Invite */
.modal-form-invite .modal-panel {
  width: min(100%, 28rem);
}

.modal-form-invite__chips {
  display: flex;
  flex-wrap: wrap;
  gap: 0.35rem;
  margin: 0;
  padding: 0;
  list-style: none;
}

.modal-form-invite__chips li {
  display: inline-flex;
  align-items: center;
  gap: 0.35rem;
  padding: 0.25rem 0.55rem;
  border-radius: 999px;
  background: var(--accent-soft);
  color: var(--accent-deep);
  font-size: 0.75rem;
  font-weight: 600;
}

/* 6. Form Feedback */
.modal-form-feedback .modal-panel {
  width: min(100%, 26rem);
}

.modal-form-feedback__rating {
  display: flex;
  gap: 0.35rem;
}

.modal-form-feedback__rating label {
  display: grid;
  place-items: center;
  width: 2.25rem;
  height: 2.25rem;
  border: 1px solid var(--border-strong);
  border-radius: 8px;
  background: #fff;
  color: var(--ink-muted);
  font-weight: 700;
  cursor: pointer;
}

.modal-form-feedback__rating input {
  position: absolute;
  opacity: 0;
  pointer-events: none;
}

.modal-form-feedback__rating label:has(input:checked) {
  border-color: var(--accent);
  background: var(--accent-soft);
  color: var(--accent-deep);
}

/* 7. Lightbox single */
.modal-lightbox .modal-layer {
  place-items: center;
  padding: 0.75rem;
  background: transparent;
}

.modal-lightbox .modal-scrim {
  background: rgb(10 14 22 / 0.94);
}

.modal-lightbox__frame {
  position: relative;
  z-index: 1;
  width: min(100%, 34rem);
  max-height: calc(100% - 1.5rem);
  display: flex;
  flex-direction: column;
  gap: 0.65rem;
}

.modal-lightbox__frame img {
  width: 100%;
  max-height: min(18rem, 55vh);
  object-fit: cover;
  border-radius: 10px;
  box-shadow: var(--modal-shadow);
}

.modal-lightbox__close {
  position: absolute;
  top: 0.5rem;
  right: 0.5rem;
  z-index: 2;
  width: 2.25rem;
  height: 2.25rem;
  border: 0;
  border-radius: 999px;
  background: rgb(255 255 255 / 0.92);
  color: var(--ink);
  font-size: 1.25rem;
  line-height: 1;
  cursor: pointer;
}

/* 8. Lightbox gallery */
.modal-lightbox-gallery .modal-layer {
  place-items: center;
  align-content: center;
  padding: 0.75rem;
  overflow: auto;
}

.modal-lightbox-gallery .modal-scrim {
  background: rgb(10 14 22 / 0.94);
}

.modal-lightbox-gallery__frame {
  position: relative;
  z-index: 1;
  width: min(100%, 36rem);
  display: grid;
  gap: 0.65rem;
  margin-block: auto;
}

.modal-lightbox-gallery__media {
  position: relative;
  display: grid;
  place-items: center;
}

.modal-lightbox-gallery__media img {
  width: 100%;
  max-height: min(16rem, 48vh);
  object-fit: cover;
  border-radius: 10px;
}

.modal-lightbox-gallery__nav {
  position: absolute;
  inset-block: 0;
  display: flex;
  align-items: center;
  justify-content: space-between;
  width: 100%;
  padding-inline: 0.35rem;
  pointer-events: none;
}

.modal-lightbox-gallery__nav button {
  pointer-events: auto;
  width: 2.25rem;
  height: 2.25rem;
  border: 0;
  border-radius: 999px;
  background: rgb(255 255 255 / 0.92);
  color: var(--ink);
  font-size: 1.1rem;
  font-weight: 700;
  cursor: pointer;
}

.modal-lightbox-gallery__meta {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.75rem;
  color: #f3f6fa;
  font-size: 0.875rem;
}

.modal-lightbox-gallery__meta p {
  margin: 0;
}

.modal-lightbox-gallery__close {
  justify-self: end;
  border: 0;
  border-radius: 8px;
  padding: 0.4rem 0.7rem;
  background: rgb(255 255 255 / 0.14);
  color: #fff;
  font-size: 0.8125rem;
  font-weight: 700;
  cursor: pointer;
}

/* 9. Lightbox caption */
.modal-lightbox-caption .modal-scrim {
  background: rgb(10 14 22 / 0.94);
}

.modal-lightbox-caption__card {
  position: relative;
  z-index: 1;
  width: min(100%, 32rem);
  overflow: hidden;
  border-radius: 12px;
  background: #111827;
  box-shadow: var(--modal-shadow);
}

.modal-lightbox-caption__card img {
  width: 100%;
  max-height: 12rem;
  object-fit: cover;
}

.modal-lightbox-caption__copy {
  padding: 0.9rem 1rem 1rem;
  color: #e5e7eb;
}

.modal-lightbox-caption__copy h3 {
  margin: 0 0 0.25rem;
  font-size: 0.95rem;
  color: #fff;
}

.modal-lightbox-caption__copy p {
  margin: 0;
  font-size: 0.8125rem;
  color: #9ca3af;
}

.modal-lightbox-caption__close {
  position: absolute;
  top: 0.5rem;
  right: 0.5rem;
  width: 2rem;
  height: 2rem;
  border: 0;
  border-radius: 999px;
  background: rgb(0 0 0 / 0.45);
  color: #fff;
  font-size: 1.1rem;
  cursor: pointer;
}

/* 10. Bottom sheet */
.modal-sheet-bottom .modal-layer {
  place-items: end center;
  padding: 0;
}

.modal-sheet-bottom .modal-panel {
  width: min(100%, 28rem);
  max-height: 85%;
  border-radius: 16px 16px 0 0;
  transform: translateY(100%);
}

.modal-sheet-bottom.is-open .modal-panel {
  transform: none;
}

.modal-sheet-bottom__handle {
  width: 2.5rem;
  height: 0.3rem;
  margin: 0.65rem auto 0.25rem;
  border-radius: 999px;
  background: var(--border-strong);
}

.modal-sheet-bottom .modal-panel__actions {
  justify-content: stretch;
}

.modal-sheet-bottom .modal-panel__actions .modal-btn {
  flex: 1;
}

/* 11. Right drawer */
.modal-drawer-right .modal-layer {
  place-items: stretch end;
  padding: 0;
}

.modal-drawer-right .modal-panel {
  width: min(100%, 22rem);
  max-height: none;
  height: 100%;
  border-radius: 0;
  transform: translateX(100%);
  display: flex;
  flex-direction: column;
}

.modal-drawer-right.is-open .modal-panel {
  transform: none;
}

.modal-drawer-right .modal-panel__body {
  flex: 1;
  overflow: auto;
}

.modal-drawer-right .modal-panel__actions {
  border-top: 1px solid var(--border);
  padding-top: 0.85rem;
  margin-top: auto;
  justify-content: space-between;
}

.modal-drawer-right__section {
  margin: 0 0 1rem;
}

.modal-drawer-right__section h4 {
  margin: 0 0 0.5rem;
  font-size: 0.75rem;
  font-weight: 700;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  color: var(--ink-faint);
}

.modal-drawer-right__section ul {
  margin: 0;
  padding: 0;
  list-style: none;
}

.modal-drawer-right__section li + li {
  margin-top: 0.35rem;
}

.modal-drawer-right__section label {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  font-size: 0.875rem;
  color: var(--ink);
}

/* 12. Action sheet */
.modal-sheet-action .modal-layer {
  place-items: end center;
  padding: 0.75rem;
}

.modal-sheet-action .modal-panel {
  width: min(100%, 22rem);
  background: transparent;
  box-shadow: none;
  overflow: visible;
  transform: translateY(1rem);
}

.modal-sheet-action.is-open .modal-panel {
  transform: none;
}

.modal-sheet-action__group {
  overflow: hidden;
  margin-bottom: 0.5rem;
  border-radius: 14px;
  background: var(--surface-raised);
  box-shadow: var(--modal-shadow);
}

.modal-sheet-action__hint {
  margin: 0;
  padding: 0.75rem 1rem;
  text-align: center;
  font-size: 0.75rem;
  color: var(--ink-faint);
  border-bottom: 1px solid var(--border);
}

.modal-sheet-action__group button {
  display: block;
  width: 100%;
  padding: 0.85rem 1rem;
  border: 0;
  border-top: 1px solid var(--border);
  background: transparent;
  color: var(--accent-deep);
  font-size: 0.95rem;
  font-weight: 600;
  text-align: center;
  cursor: pointer;
}

.modal-sheet-action__group button:first-child {
  border-top: 0;
}

.modal-sheet-action__group button:hover {
  background: var(--surface);
}

.modal-sheet-action__group button.is-danger {
  color: var(--danger);
}

.modal-sheet-action__cancel {
  width: 100%;
  padding: 0.85rem 1rem;
  border: 0;
  border-radius: 14px;
  background: var(--surface-raised);
  box-shadow: var(--modal-shadow);
  color: var(--ink);
  font-size: 0.95rem;
  font-weight: 700;
  cursor: pointer;
}

/* 13–15 Alerts */
.modal-alert-info .modal-panel,
.modal-alert-success .modal-panel,
.modal-alert-error .modal-panel {
  width: min(100%, 24rem);
  text-align: left;
}

.modal-alert-info .modal-panel__actions,
.modal-alert-success .modal-panel__actions,
.modal-alert-error .modal-panel__actions {
  justify-content: stretch;
}

.modal-alert-info .modal-panel__actions .modal-btn,
.modal-alert-success .modal-panel__actions .modal-btn,
.modal-alert-error .modal-panel__actions .modal-btn {
  flex: 1;
}

.modal-alert-error[data-modal-static] .modal-scrim {
  cursor: default;
}

/* Open state: layer visible; centered panels un-scale via shared rule above.
   Sheet / drawer / action keep their own transform overrides. */
[data-modal].is-open > .modal-layer {
  opacity: 1;
  visibility: visible;
  pointer-events: auto;
}

[data-modal].is-open:not(.modal-sheet-bottom):not(.modal-drawer-right):not(.modal-sheet-action) > .modal-layer .modal-panel {
  transform: none;
}
