@keyframes modal-enter {
  from {
    opacity: 0;
    transform: scale(0.95) translateY(8px);
  }
  to {
    opacity: 1;
    transform: scale(1) translateY(0);
  }
}

@keyframes modal-sheet-enter {
  from {
    transform: translateY(100%);
  }
  to {
    transform: translateY(0);
  }
}

@keyframes modal-exit {
  from {
    opacity: 1;
    transform: scale(1) translateY(0);
  }
  to {
    opacity: 0;
    transform: scale(0.95) translateY(8px);
  }
}

dialog.modal {
  position: fixed;
  margin: auto;
  border: none;
  padding: 0;
  background-color: var(--surface-overlay);
  border-radius: var(--radius-2xl);
  box-shadow: var(--shadow-xl);
  width: 420px;
  max-width: 100vw;
  max-height: 90vh;
  overflow: hidden;
  animation: modal-enter var(--duration-normal) var(--ease-spring);
}

dialog.modal[open] {
  display: flex;
  flex-direction: column;
}

dialog.modal::backdrop,
.studio__window:popover-open::backdrop {
  background: rgba(0, 0, 0, 0.5);
  backdrop-filter: blur(4px);
  -webkit-backdrop-filter: blur(4px);
  animation: fade-in var(--duration-normal);
}

dialog.modal.modal--wide {
  width: 35rem;
}

@keyframes modal-launch {
  from {
    opacity: 0;
    transform: scale(0.97);
  }
}

dialog.modal.modal--launch {
  overscroll-behavior: contain;
  animation: modal-launch var(--duration-normal) var(--ease-out);
}
dialog.modal.modal--launch .modal__body { overscroll-behavior: contain; }

@media (prefers-reduced-motion: reduce) {
  dialog.modal.modal--launch { animation: fade-in var(--duration-normal); }
}

@media (min-width: 481px) {
  dialog.modal.modal--launch {
    width: auto;
    height: min(844px, 90vh);
    aspect-ratio: 390 / 844;
    border-radius: var(--radius-2xl);
  }
}

.modal__header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: var(--space-3) var(--space-4);
  border-bottom: 1px solid var(--border-subtle);
  flex-shrink: 0;
}

.modal__title {
  font-size: var(--text-base);
  font-weight: 700;
  color: var(--text-primary);
  margin: 0;
  flex: 1;
}

.modal__head-icon {
  width: 28px;
  height: 28px;
  border-radius: var(--radius-sm);
  background: var(--accent-subtle);
  color: var(--accent-primary);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  margin-right: var(--space-2);
}
.modal__head-icon .material-symbols-rounded { font-size: 18px; }

.modal__head-icon--warn {
  background: var(--status-warning-bg);
  color: var(--status-warning);
}
.modal__head-icon--danger {
  background: var(--status-error-bg);
  color: var(--status-error);
}

.modal__close {
  background: transparent;
  border: none;
  cursor: pointer;
  color: var(--text-tertiary);
  padding: var(--space-1);
  border-radius: var(--radius-lg);
  display: flex;
  align-items: center;
  justify-content: center;
  transition: color var(--duration-fast);
}

.modal__close:hover {
  color: var(--text-primary);
}
.modal__close:focus,
.modal__close:focus-visible {
  outline: none;
}

dialog.modal > form,
dialog.modal > turbo-frame > form {
  display: flex;
  flex-direction: column;
  flex: 1 1 auto;
  min-height: 0;

  min-width: 0;
}

dialog.modal > turbo-frame {
  display: flex;
  flex-direction: column;
  flex: 1 1 auto;
  min-height: 0;
  min-width: 0;
}

.modal__body {
  padding: var(--space-4);
  overflow-y: auto;

  flex: 1 1 auto;
  min-height: 0;

  min-width: 0;
}

.modal__body .form-row:has([type="datetime-local"]) {
  grid-template-columns: 1fr;
}

.modal__footer {
  display: flex;
  justify-content: flex-end;
  gap: var(--space-3);
  padding: var(--space-3) var(--space-4);
  border-top: 1px solid var(--border-subtle);
  flex-shrink: 0;
}

dialog.modal.modal--settings {
  width: 360px;
}

.modal__divider {
  position: relative;
  display: block;
  height: calc(var(--space-4) * 3);
  margin: calc(var(--space-4) * -1) 0;
  padding: 0;
  border: none;
  background: transparent;
}
.modal__divider::before {
  content: "";
  position: absolute;
  left: 0;
  right: 0;
  top: 50%;
  border-top: 1px dashed var(--border-subtle);
}

.modal__fields {
  display: flex;
  flex-direction: column;
  gap: var(--space-4);
  overflow: hidden;
  max-height: 1000px;
  opacity: 1;
  transition: max-height var(--duration-normal) var(--ease-out),
              opacity var(--duration-normal) var(--ease-out);
}

.modal__body > .switch-row--hero {
  margin-bottom: var(--space-4);
}
.modal__fields--collapsed {
  max-height: 0;
  opacity: 0;
  pointer-events: none;
}

.modal__autoclose {
  position: relative;
  padding: 8px var(--space-4);
  display: flex;
  align-items: center;
  gap: var(--space-2);
  background: var(--surface-sunken);
  border-top: 1px solid var(--border-subtle);
  font-size: 11px;
  color: var(--text-secondary);
  flex-shrink: 0;
}
.modal__autoclose[hidden] { display: none; }
.modal__autoclose-msg { flex: 1; }
.modal__autoclose-msg strong {
  color: var(--text-primary);
  font-weight: var(--weight-semibold);
}
.modal__autoclose-link {
  background: transparent;
  border: none;
  padding: 0;
  font: inherit;
  font-size: 11px;
  font-weight: var(--weight-semibold);
  color: var(--accent-primary);
  cursor: pointer;
  text-decoration: underline;
  text-underline-offset: 2px;
}
.modal__autoclose-progress {
  position: absolute;
  left: 0;
  right: 0;
  bottom: 0;
  height: 2px;
  overflow: hidden;
}
.modal__autoclose-progress::after {
  content: "";
  position: absolute;
  left: 0;
  top: 0;
  bottom: 0;
  width: 0;
  background: var(--accent-primary);
  border-radius: 0 1px 1px 0;
}
.modal__autoclose-progress--running::after {
  animation: modal-autoclose-bar 2s linear forwards;
}
@keyframes modal-autoclose-bar {
  from { width: 0; }
  to   { width: 100%; }
}

dialog.modal.modal--lightbox {
  width: auto;
  height: auto;
  max-width: min(90vw, 800px);
  max-height: 90vh;
}

.participation-lightbox {
  width: min(95vw, 1400px);
  max-width: 95vw;
  max-height: 95vh;
  padding: 0;
  background: var(--surface-base);
  border: 0;
  border-radius: var(--radius-lg);
  position: relative;
}
.participation-lightbox::backdrop {
  background: rgba(0, 0, 0, 0.85);
}
.participation-lightbox__image {
  display: block;
  width: 100%;
  max-height: 80vh;
  object-fit: contain;
  background: var(--text-primary);
}
.participation-lightbox__nav {
  position: absolute;
  top: 50%;
  transform: translateY(-50%);
  width: 48px;
  height: 48px;
  border-radius: var(--radius-full);
  background: rgba(0, 0, 0, 0.6);
  border: 0;
  color: white;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 1;
}
.participation-lightbox__nav:hover {
  background: rgba(0, 0, 0, 0.85);
}
.participation-lightbox__nav--prev { left: var(--space-3); }
.participation-lightbox__nav--next { right: var(--space-3); }
.participation-lightbox__footer {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: var(--space-3) var(--space-4);
  background: var(--surface-raised);
  font-size: var(--text-sm);
  color: var(--text-secondary);
}

.modal__body--lightbox {
  display: flex;
  align-items: center;
  justify-content: center;
  padding: var(--space-3);
}

.modal__lightbox-img {
  max-width: 100%;
  max-height: 70vh;
  object-fit: contain;
  border-radius: var(--radius-md);
}

@media (max-width: 767px) {
  dialog.modal.modal--sheet {
    width: 100vw;
    max-width: 100vw;
    height: auto;
    max-height: calc(100dvh - var(--space-12));
    inset: auto 0 0;
    margin: 0;
    border-radius: var(--radius-2xl) var(--radius-2xl) 0 0;
    padding-bottom: env(safe-area-inset-bottom, 0px);
    animation: modal-sheet-enter var(--duration-normal) var(--ease-out);
  }

  dialog.modal.modal--sheet .modal__footer {
    flex-direction: column-reverse;
    align-items: stretch;
    gap: var(--space-2);
    border-top: 0;
  }

  dialog.modal.modal--sheet .modal__footer .btn {
    width: 100%;
  }
}

@media (max-width: 480px) {
  dialog.modal {
    width: 100vw;
    height: 100vh;
    max-height: none;
    border-radius: 0;
    margin: 0;
    inset: 0;
  }

  dialog.modal:not(.modal--sheet) {
    padding-top: env(safe-area-inset-top, 0px);
    padding-bottom: env(safe-area-inset-bottom, 0px);
  }

  dialog.modal.modal--launch {
    top: var(--viewport-top, 0px);
    bottom: auto;
    padding-bottom: max(env(safe-area-inset-bottom, 0px), 100vh - var(--viewport-height, 100vh));
    transform-origin: top center;
  }

  dialog.modal.modal--launch::backdrop {
    background: none;
    backdrop-filter: none;
    -webkit-backdrop-filter: none;
  }

  .modal__close {
    min-width: var(--tap-target);
    min-height: var(--tap-target);
  }

  .modal__header {
    padding: var(--space-4);
  }

  .modal__body {
    padding: var(--space-4);
  }

  .modal__footer {
    padding: var(--space-3) var(--space-4);
  }
}

.modal .ee-picker__options {
  max-height: min(40vh, 240px);
}

.ee-picker__search {
  width: 100%;
  padding: var(--space-2) var(--space-3);
  border: 1px solid var(--input-border);
  border-radius: var(--radius-md);
  font-size: var(--text-sm);
  outline: none;
  background: var(--input-bg);
  margin-bottom: var(--space-3);
}

.ee-picker__search:focus {
  border-color: var(--input-border-focus);
  box-shadow: 0 0 0 3px var(--accent-muted);
}

.ee-picker__search::placeholder {
  color: var(--text-secondary);
}

.ee-picker__options {
  display: flex;
  flex-direction: column;
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-md);
  background: var(--surface-base);
  max-height: 200px;
  overflow-y: auto;
}

.ee-picker__option {
  display: flex;
  align-items: center;
  gap: var(--space-2);
  padding: var(--space-2) var(--space-3);
  cursor: pointer;
  transition: background var(--duration-fast) var(--ease-out);
}

.ee-picker__option[hidden] {
  display: none;
}

.ee-picker__option[data-org-hidden] {
  display: none;
}

.ee-picker__option:hover {
  background: var(--surface-hover);
}

.ee-picker__option input[type="checkbox"],
.ee-picker__option input[type="radio"] {
  accent-color: var(--accent-primary);
  flex-shrink: 0;
  width: 16px;
  height: 16px;
  margin: 0;
}

.ee-picker__option-label {
  font-size: var(--text-sm);
  color: var(--text-primary);
  line-height: 1.4;
}

.ee-picker__option-meta {
  margin-left: auto;
  font-size: var(--text-xs);
  color: var(--text-tertiary);
  white-space: nowrap;
}

.ee-inline-multi-select .ee-picker__option {
  justify-content: flex-start;
  gap: var(--space-2);
}

.ee-inline-multi-select .ee-picker__chips:not(:empty) {
  margin-bottom: var(--space-2);
}

.ee-picker__empty {
  padding: var(--space-3);
  text-align: center;
  color: var(--text-secondary);
  font-size: var(--text-sm);
  font-style: italic;
}

.highlight-publish-modal__filter-list {
  max-height: min(24vh, 160px);
}
