/* ═══════════════════════════════════════════════════
   Miuix Editor — immersive compose stage
   ═══════════════════════════════════════════════════ */

.editor-overlay {
  position: fixed;
  inset: 0;
  z-index: 2147482000;
  display: flex;
  align-items: stretch;
  justify-content: stretch;
  padding: 0;
  box-sizing: border-box;
  background: var(--mi-surface);
  backdrop-filter: none;
  -webkit-backdrop-filter: none;
  opacity: 0;
  pointer-events: none;
  height: var(--editor-stage-h, 100dvh);
  min-height: var(--editor-stage-h, 100dvh);
  overflow: hidden;
  overscroll-behavior: none;
  touch-action: none;
  transition: opacity var(--mi-duration-dialog-dim-in) var(--ease-out), backdrop-filter var(--mi-duration-dialog-dim-in) var(--ease-out);
  --editor-keyboard-inset: 0px;
}

.editor-overlay.open {
  opacity: 1;
  pointer-events: auto;
}

.editor-sheet {
  --editor-sheet-pad-x: max(18px, calc((100vw - 760px) / 2));
  width: 100%;
  height: var(--editor-stage-h, 100dvh);
  max-height: none;
  display: flex;
  flex-direction: column;
  overflow: hidden;
  padding: calc(var(--safe-top) + 16px) var(--editor-sheet-pad-x) calc(var(--safe-bottom) + 18px);
  box-sizing: border-box;
  border-radius: 0;
  background: transparent;
  color: var(--mi-on-background);
  box-shadow: none;
  backdrop-filter: none;
  -webkit-backdrop-filter: none;
  opacity: 0;
  transition: opacity var(--mi-duration-dialog) var(--ease-out);
  will-change: opacity;
  touch-action: auto;
}

.editor-overlay.open .editor-sheet {
  opacity: 1;
}

.editor-overlay.closing {
  opacity: 0;
  pointer-events: none;
  transition-duration: var(--mi-duration-dialog-reset);
}

.editor-overlay.closing .editor-sheet {
  opacity: 0;
  transition-duration: var(--mi-duration-dialog-reset);
  transition-timing-function: var(--ease-out);
}

.editor-sheet::before {
  display: none;
}

.editor-sheet:active::before {
  width: var(--bottom-sheet-handle-w);
  transform: none;
}

.editor-header {
  position: relative;
  flex: 0 0 auto;
  width: 100%;
  display: grid;
  grid-template-columns: 48px minmax(0, 1fr) 48px;
  align-items: center;
  gap: var(--content-gap);
  margin: 0 auto;
  padding: 0;
  z-index: 2;
}

.editor-header .title {
  grid-column: 2;
  width: fit-content;
  max-width: 100%;
  justify-self: center;
  padding: 8px 16px;
  border-radius: var(--r-full);
  background: var(--mi-surface-container);
  color: var(--mi-on-secondary-variant);
  font-size: var(--fs-body2);
  font-weight: var(--fw-medium);
  line-height: 1.2;
  text-align: center;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.editor-upload-progress {
  flex: 0 0 auto;
  max-height: 0;
  margin-top: 0;
  margin-bottom: 0;
  overflow: hidden;
  opacity: 0;
  transform: translateY(calc(var(--button-content-gap) * -1));
  transition: max-height var(--mi-duration-popup-in) var(--ease-out), margin-top var(--mi-duration-popup-in) var(--ease-out), margin-bottom var(--mi-duration-popup-in) var(--ease-out), opacity var(--mi-duration-popup-in) var(--ease-out), transform var(--mi-duration-popup-in) var(--ease-spring);
}

.editor-upload-progress.show {
  max-height: calc(var(--snackbar-min-h));
  margin-top: var(--content-gap);
  margin-bottom: var(--content-gap);
  opacity: 1;
  transform: translateY(0);
}

.editor-upload-progress-label {
  padding: 0 var(--selection-label-gap) var(--button-content-gap);
  color: var(--mi-on-surface-summary);
  font-size: var(--fs-footnote1);
  line-height: 1.2;
}

.editor-upload-progress-track {
  width: 100%;
  height: var(--bottom-sheet-handle-h);
  overflow: hidden;
  border-radius: var(--r-full);
  background: var(--mi-surface-container);
}

.editor-upload-progress-fill {
  width: 0;
  height: 100%;
  border-radius: inherit;
  background: var(--mi-primary);
  transition: width var(--mi-duration-press-in) var(--ease-out);
}

.editor-title-action {
  width: 48px;
  height: 48px;
  min-width: 48px;
  min-height: 48px;
  justify-self: start;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  padding: 0;
  border-radius: var(--r-full);
  color: var(--mi-on-secondary-variant);
  background: var(--mi-surface-container);
  transition: background var(--mi-duration-press-out) var(--ease), color var(--mi-duration-press-out) var(--ease), transform var(--mi-duration-nav) var(--ease-spring);
}

.editor-title-action svg {
  width: var(--icon-size);
  height: var(--icon-size);
  fill: none;
  stroke: currentColor;
  stroke-width: 1.9;
  stroke-linecap: round;
  stroke-linejoin: round;
}

.editor-title-action:active {
  background: var(--mi-surface-container);
  transform: scale(var(--mi-sink-scale));
}

.editor-title-action.primary {
  justify-self: end;
  color: var(--mi-on-primary);
  background: var(--mi-primary);
}

.editor-title-action.primary:active {
  background: var(--mi-primary-container);
}

.editor-title-action.danger {
  justify-self: end;
  color: var(--mi-error);
  background: var(--mi-error-container);
}

.editor-body {
  position: relative;
  flex: 1 1 auto;
  width: 100%;
  min-height: 0;
  display: flex;
  flex-direction: column;
  overflow: visible;
  margin: 0 auto;
  padding: 22px 0 0;
  scrollbar-width: none;
  transition: padding-top 320ms var(--ease-spring);
}

.editor-body::-webkit-scrollbar {
  display: none;
  width: 0;
  height: 0;
}

.editor-body textarea {
  position: relative;
  order: 2;
  z-index: 5;
  display: block;
  width: 100%;
  flex: 0 0 auto;
  min-height: 108px;
  max-height: 168px;
  margin: var(--content-gap) 0 0;
  padding: 16px 18px;
  box-sizing: border-box;
  border: 0;
  outline: 0;
  resize: none;
  border-radius: var(--r-lg);
  background: var(--mi-surface-container);
  box-shadow: inset 0 0 0 0.5px color-mix(in srgb, var(--mi-outline) 46%, transparent);
  backdrop-filter: none;
  -webkit-backdrop-filter: none;
  color: var(--mi-on-surface);
  font-size: var(--fs-main);
  font-weight: var(--fw-normal);
  line-height: 1.48;
  letter-spacing: 0;
  opacity: 1;
  transform: translateY(0);
  transition:
    background var(--mi-duration-press-out) var(--ease),
    box-shadow var(--mi-duration-press-out) var(--ease),
    opacity 180ms var(--ease-out),
    top 260ms var(--ease-spring),
    bottom 260ms var(--ease-spring),
    max-height 320ms var(--ease-spring);
}

.editor-overlay.keyboard-active .editor-body textarea {
  z-index: 20;
  transform: translateY(calc(var(--editor-keyboard-lift, 0px) * -1));
}

.editor-overlay.keyboard-fixed.keyboard-active .editor-body textarea {
  position: fixed;
  left: var(--editor-sheet-pad-x);
  right: var(--editor-sheet-pad-x);
  bottom: calc(var(--safe-bottom) + var(--editor-keyboard-inset, 0px) + 14px);
  width: calc(100% - var(--editor-sheet-pad-x) * 2);
  max-height: min(168px, calc(var(--editor-stage-h, 100dvh) - var(--editor-keyboard-inset, 0px) - 132px));
  margin: 0;
  transform: none;
}

.editor-overlay.android-keyboard.keyboard-active .editor-body textarea {
  top: calc(var(--safe-top) + 82px);
  bottom: auto;
  max-height: min(144px, calc(var(--editor-stage-h, 100dvh) * 0.28));
  transform: translateY(0);
}

.editor-overlay.android-keyboard.keyboard-active .editor-body {
  padding-top: calc(138px + var(--button-content-gap));
}

.editor-overlay.android-keyboard.keyboard-active .editor-photos,
.editor-overlay.android-keyboard.keyboard-active .editor-edit-photo-preview {
  min-height: min(var(--editor-media-h, 42vh), 360px);
  max-height: min(var(--editor-media-h, 46vh), 420px);
  align-items: flex-start;
}

.editor-body textarea:focus {
  background: var(--mi-surface-container);
  box-shadow: inset 0 0 0 2px var(--mi-primary);
}

.editor-body textarea::placeholder {
  color: var(--mi-on-surface-summary);
}

.editor-edit-photo-preview {
  order: 1;
  flex: 1 1 auto;
  min-height: min(var(--editor-media-h, 50vh), 460px);
  max-height: min(var(--editor-media-h, 56vh), 540px);
  display: flex;
  align-items: center;
  gap: var(--content-gap);
  width: calc(100% + var(--editor-sheet-pad-x) * 2);
  margin: 0;
  padding: 2px var(--editor-sheet-pad-x) 8px;
  margin-left: calc(var(--editor-sheet-pad-x) * -1);
  margin-right: calc(var(--editor-sheet-pad-x) * -1);
  box-sizing: border-box;
  overflow-x: auto;
  scrollbar-width: none;
  scroll-snap-type: x proximity;
  cursor: grab;
  transform: translateY(0);
  transition: transform 320ms var(--ease-spring), min-height 320ms var(--ease-spring), max-height 320ms var(--ease-spring);
}

.editor-edit-photo-preview.dragging,
.editor-edit-photo-preview.wheel-scrolling {
  cursor: grabbing;
  scroll-snap-type: none;
}

.editor-edit-photo-preview::-webkit-scrollbar {
  display: none;
}

.editor-edit-photo-item {
  position: relative;
  flex: 0 0 clamp(188px, 34vw, 280px);
  width: clamp(188px, 34vw, 280px);
  aspect-ratio: 4 / 5;
  overflow: hidden;
  border-radius: var(--r-xl);
  background: var(--mi-surface-container);
  scroll-snap-align: center;
  transition: box-shadow var(--mi-duration-press-out) var(--ease);
}

.editor-edit-photo-item:active {
  transform: none;
}

.editor-edit-photo-item img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  -webkit-user-drag: none;
  user-select: none;
  pointer-events: none;
}

.editor-time-field {
  position: relative;
  order: 3;
  flex: 0 0 auto;
  width: fit-content;
  max-width: 100%;
  display: inline-flex;
  align-items: center;
  min-height: 32px;
  margin: 6px 0 0;
  padding: 0 6px;
  color: var(--mi-on-surface-summary);
  font-size: var(--fs-body2);
  text-align: left;
  cursor: pointer;
  background: transparent;
  border-radius: var(--r-full);
  transition: color var(--mi-duration-press-out) var(--ease), background var(--mi-duration-press-out) var(--ease), transform var(--mi-duration-press-out) var(--ease-spring);
}

.editor-time-field span {
  flex: 0 0 auto;
  white-space: nowrap;
  font-weight: var(--fw-normal);
}

.editor-time-field:hover {
  color: var(--mi-primary);
  background: var(--mi-primary-state-hover);
}

.editor-time-field:active {
  color: var(--mi-primary);
  background: var(--mi-primary-state-focus);
  transform: scale(var(--mi-sink-scale));
}

.editor-time-value {
  min-width: 0;
  color: inherit;
  font-size: var(--fs-body2);
  line-height: 1.2;
  text-align: left;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.editor-time-field input {
  position: absolute;
  width: 1px;
  height: 1px;
  opacity: 0;
  pointer-events: none;
}

.editor-location-fields {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: var(--content-gap);
  margin: var(--selection-label-gap) 0 var(--content-gap);
}

.editor-location-field {
  min-width: 0;
  display: flex;
  flex-direction: column;
  gap: var(--selection-label-gap);
  padding: var(--navbar-pad-x) var(--content-card-pad);
  border-radius: var(--r-md);
  background: var(--mi-surface-container);
  color: var(--mi-on-background);
}

.editor-location-field span {
  color: var(--mi-on-surface-summary);
  font-size: var(--fs-footnote1);
  line-height: 1.2;
}

.editor-location-field input {
  width: 100%;
  min-width: 0;
  padding: 0;
  border: 0;
  outline: 0;
  background: transparent;
  color: var(--mi-on-surface);
  font: inherit;
  line-height: 1.4;
}

.editor-location-field input::placeholder {
  color: var(--mi-on-surface-summary);
}

.editor-photos {
  order: 1;
  flex: 0 0 auto;
  display: grid;
  grid-auto-flow: column;
  grid-auto-columns: clamp(188px, 34vw, 280px);
  grid-template-columns: none;
  gap: var(--content-gap);
  width: calc(100% + var(--editor-sheet-pad-x) * 2);
  min-height: min(var(--editor-media-h, 50vh), 460px);
  max-height: min(var(--editor-media-h, 56vh), 540px);
  padding: 2px var(--editor-sheet-pad-x) 8px;
  margin-left: calc(var(--editor-sheet-pad-x) * -1);
  margin-right: calc(var(--editor-sheet-pad-x) * -1);
  box-sizing: border-box;
  align-content: center;
  align-items: center;
  justify-content: flex-start;
  overflow-x: auto;
  scrollbar-width: none;
  scroll-snap-type: x proximity;
  cursor: grab;
  transform: translateY(0);
  transition: transform 320ms var(--ease-spring), min-height 320ms var(--ease-spring), max-height 320ms var(--ease-spring);
}

.editor-photos.dragging,
.editor-photos.wheel-scrolling {
  cursor: grabbing;
  scroll-snap-type: none;
}

.editor-photos::-webkit-scrollbar {
  display: none;
}

.editor-photo-option {
  width: clamp(188px, 34vw, 280px);
  aspect-ratio: 4 / 5;
  min-height: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 0;
  border-radius: var(--r-xl);
  background: var(--mi-surface-container);
  color: var(--mi-on-surface-container);
  border: 0;
  box-shadow: inset 0 0 0 0.5px var(--mi-outline);
  cursor: pointer;
  overflow: hidden;
  position: relative;
  scroll-snap-align: center;
  transition: background var(--mi-duration-press-out) var(--ease), box-shadow var(--mi-duration-press-out) var(--ease);
}

.editor-photo-option::after {
  content: '';
  position: absolute;
  inset: 0;
  z-index: 1;
  border-radius: inherit;
  box-shadow: inset 0 0 0 0.5px var(--mi-outline);
  pointer-events: none;
}

.editor-photo-option:active {
  background: var(--mi-surface-container);
  transform: none;
}

.editor-photo-option img {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  border-radius: inherit;
  object-fit: cover;
  z-index: 0;
  -webkit-user-drag: none;
  user-select: none;
  pointer-events: none;
}

.editor-upload-option,
.editor-photo-option[data-filename=''] {
  flex: 0 0 86px;
  width: 86px;
  aspect-ratio: 1;
  align-self: center;
  flex-direction: column;
  gap: var(--button-content-gap);
  background: var(--mi-surface-container);
  border-radius: clamp(var(--r-md), 22%, var(--r-lg));
  text-align: center;
  scroll-snap-align: center;
}

.editor-photos:has(.editor-upload-option:only-child),
.editor-photos:has(.editor-photo-option[data-filename='']:only-child) {
  display: flex;
  justify-content: center;
}

.editor-upload-option:only-child,
.editor-photo-option[data-filename='']:only-child {
  flex: 0 0 118px;
  width: 118px;
  border-radius: var(--r-lg);
}

.editor-upload-icon {
  width: 30px;
  height: 30px;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: var(--r-full);
  background: var(--mi-tertiary-container);
  color: var(--mi-on-tertiary-container);
  font-size: var(--icon-size);
  line-height: 1;
  font-weight: var(--fw-normal);
  flex: 0 0 auto;
}

.editor-upload-option {
  color: var(--mi-primary);
}

.editor-photo-option-text {
  max-width: calc(100% - 12px);
  color: inherit;
  font-size: var(--fs-footnote1);
  font-weight: var(--fw-normal);
  line-height: var(--content-card-pad);
  min-height: var(--content-card-pad);
  white-space: nowrap;
  text-overflow: ellipsis;
  overflow: hidden;
  text-align: center;
}

.editor-photo-delete {
  position: absolute;
  right: calc(var(--button-content-gap) + 8px);
  top: calc(var(--button-content-gap) + 8px);
  z-index: 2;
  width: var(--nav-rail-icon);
  height: var(--nav-rail-icon);
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: var(--r-full);
  color: var(--mi-on-secondary-variant);
  background: var(--mi-translucent-surface);
  backdrop-filter: blur(14px) saturate(1.2);
  -webkit-backdrop-filter: blur(14px) saturate(1.2);
  transition: background var(--mi-duration-press-out) var(--ease), color var(--mi-duration-press-out) var(--ease), transform var(--mi-duration-press-out) var(--ease-spring);
}

.editor-photo-delete svg {
  width: 17px;
  height: 17px;
  fill: none;
  stroke: currentColor;
  stroke-width: 1.9;
  stroke-linecap: round;
  stroke-linejoin: round;
}

.editor-photo-delete:active {
  background: var(--mi-state-focus);
  color: var(--mi-primary);
  transform: scale(var(--mi-sink-scale));
}

.editor-photo-location {
  position: absolute;
  left: calc(var(--button-content-gap) + 8px);
  bottom: calc(var(--button-content-gap) + 8px);
  z-index: 2;
  width: var(--nav-rail-icon);
  height: var(--nav-rail-icon);
  display: flex;
  align-items: center;
  justify-content: center;
  border: 0;
  border-radius: var(--r-full);
  color: var(--mi-on-secondary-variant);
  background: var(--mi-surface-container);
  backdrop-filter: none;
  -webkit-backdrop-filter: none;
  transition: background var(--mi-duration-press-out) var(--ease), color var(--mi-duration-press-out) var(--ease), transform var(--mi-duration-press-out) var(--ease-spring);
}

.editor-photo-location.has-location {
  color: var(--mi-on-tertiary-container);
  background: var(--mi-tertiary-container);
}

.editor-photo-location svg {
  width: 17px;
  height: 17px;
  fill: none;
  stroke: currentColor;
  stroke-width: 1.9;
  stroke-linecap: round;
  stroke-linejoin: round;
}

.editor-photo-location:active {
  background: var(--mi-state-focus);
  color: var(--mi-primary);
  transform: scale(var(--mi-sink-scale));
}

.editor-photo-location.has-location:active {
  background: var(--mi-active-tertiary-pressed);
}

.editor-edit-footer {
  display: none;
  order: 4;
  flex: 0 0 auto;
  padding: var(--content-gap) 0 0;
}

.editor-edit-footer.show {
  display: block;
}

.editor-republish-btn {
  width: 100%;
  min-height: var(--menu-item-h);
  border-radius: var(--r-md);
  background: var(--mi-primary);
  color: var(--mi-on-primary);
  font-size: var(--fs-button);
  font-weight: var(--fw-normal);
  box-shadow: none;
  transition: background var(--mi-duration-press-out) var(--ease), transform var(--mi-duration-press-out) var(--ease-spring);
}

.editor-republish-btn:active {
  background: var(--mi-primary-container);
  transform: scale(var(--mi-sink-scale));
  box-shadow: none;
}

@media (min-width: 768px) {
  .editor-edit-photo-preview,
  .editor-photos {
    scroll-snap-type: none;
  }

  .editor-overlay.open .editor-sheet {
    opacity: 1;
  }

  .editor-overlay.closing .editor-sheet {
    opacity: 0;
  }
}

@media (max-width: 420px) {
  .editor-sheet {
    --editor-sheet-pad-x: 16px;
  }

  .editor-body textarea {
    min-height: 102px;
    max-height: 154px;
    font-size: var(--fs-main);
  }

  .editor-overlay.keyboard-fixed.keyboard-active .editor-body textarea {
    max-height: min(154px, calc(var(--editor-stage-h, 100dvh) - var(--editor-keyboard-inset, 0px) - 116px));
  }

  .editor-overlay.android-keyboard.keyboard-active .editor-body textarea {
    top: calc(var(--safe-top) + 76px);
    max-height: min(132px, calc(var(--editor-stage-h, 100dvh) * 0.3));
  }

  .editor-overlay.android-keyboard.keyboard-active .editor-body {
    padding-top: calc(126px + var(--button-content-gap));
  }

  .editor-overlay.android-keyboard.keyboard-active .editor-photos,
  .editor-overlay.android-keyboard.keyboard-active .editor-edit-photo-preview {
    min-height: min(var(--editor-media-h, 38vh), 310px);
    max-height: min(var(--editor-media-h, 42vh), 360px);
    align-items: flex-start;
  }

  .editor-photos {
    grid-auto-columns: min(72vw, 280px);
    min-height: min(var(--editor-media-h, 50vh), 390px);
    max-height: min(var(--editor-media-h, 56vh), 450px);
  }

  .editor-edit-photo-preview {
    align-items: center;
    min-height: min(var(--editor-media-h, 50vh), 390px);
    max-height: min(var(--editor-media-h, 56vh), 450px);
  }

  .editor-edit-photo-item,
  .editor-photo-option {
    width: min(72vw, 280px);
    flex-basis: min(72vw, 280px);
  }

  .editor-upload-option,
  .editor-photo-option[data-filename=''] {
    width: 82px;
    flex-basis: 82px;
    border-radius: var(--r-md);
  }

  .editor-upload-option:only-child,
  .editor-photo-option[data-filename='']:only-child {
    width: 108px;
    flex-basis: 108px;
    border-radius: var(--r-lg);
  }

  .editor-time-field {
    max-width: calc(100vw - 32px);
  }

  .editor-time-field input {
    max-width: 190px;
    font-size: var(--fs-body2);
  }
}

/* ── Desktop: editor becomes a centered dialog card ──
   The fullscreen phone sheet looks empty on wide screens; on PC the
   editor renders as a dimmed-backdrop modal in the dialog family
   (28px corner, dialog surface/shadow, capped media strip). */
@media (min-width: 840px) and (min-height: 480px) {
  .editor-overlay {
    align-items: center;
    justify-content: center;
    padding: 32px;
    background: var(--mi-window-dimming);
    backdrop-filter: blur(14px) saturate(1.08);
    -webkit-backdrop-filter: blur(14px) saturate(1.08);
  }

  .editor-sheet {
    --editor-sheet-pad-x: 24px;
    width: min(640px, calc(100vw - 64px));
    height: auto;
    max-height: min(720px, calc(100vh - 64px));
    padding: 20px 24px 24px;
    border: 0.5px solid var(--mi-dialog-border);
    border-radius: var(--dialog-corner);
    background: var(--mi-dialog-surface);
    box-shadow: var(--mi-dialog-shadow);
    transform: scale3d(var(--mi-dialog-enter-scale), var(--mi-dialog-enter-scale), 1);
    transition: opacity var(--mi-duration-dialog) var(--ease-out), transform var(--mi-duration-dialog) var(--ease-spring);
  }

  .editor-overlay.open .editor-sheet {
    opacity: 1;
    transform: scale3d(1, 1, 1);
  }

  .editor-overlay.closing .editor-sheet {
    opacity: 0;
    transform: scale3d(var(--mi-dialog-enter-scale), var(--mi-dialog-enter-scale), 1);
  }

  .editor-body {
    overflow-y: auto;
    padding-top: 16px;
  }

  .editor-photos,
  .editor-edit-photo-preview {
    min-height: 240px;
    max-height: 300px;
  }

  .editor-photos {
    grid-auto-columns: 210px;
  }
}
