/* Roger image editor: aspect-ratio frame (imageAspectFrame.js). Uses the Video Creator palette when it
   is loaded and falls back to the same values otherwise. */
.af-root {
  --af-accent: var(--vc-accent, #7c5cff);
  --af-accent-light: var(--vc-accent-light, #a18bff);
  --af-accent-glow: var(--vc-accent-glow, rgba(124, 92, 255, 0.42));
  --af-text: var(--vc-text, #eceefe);
  --af-text-muted: var(--vc-text-muted, #a3abcc);
  --af-shade: rgba(4, 5, 12, 0.62);
  --af-area: rgba(248, 249, 252, 0.96);
  --af-area-border: rgba(120, 128, 150, 0.55);
  --af-area-button: rgba(58, 63, 82, 0.9);
  --af-area-button-hover: rgba(74, 80, 104, 0.96);
  --af-success: var(--vc-success, #3ddc97);
  --af-danger: var(--vc-danger, #ff5d6c);
  --af-radius: var(--vc-radius-control, 5px);
  --af-font: var(--vc-font, "Inter", "Segoe UI", system-ui, sans-serif);
  position: absolute;
  inset: 0;
  font-family: var(--af-font);
  user-select: none;
}

.af-viewport {
  position: absolute;
  inset: 0;
  overflow: hidden;
  /* Opaque: the editor canvas underneath must never show through the new areas. */
  background-color: #0b0d17;
  background:
    radial-gradient(ellipse at 50% 40%, rgba(124, 92, 255, 0.08), transparent 60%),
    repeating-conic-gradient(rgba(255, 255, 255, 0.045) 0% 25%, rgba(255, 255, 255, 0.015) 0% 50%) 0 0 / 18px 18px,
    #0b0d17;
}

.af-picture,
.af-result {
  position: absolute;
  object-fit: fill;
  pointer-events: none;
}

.af-result {
  z-index: 2;
  animation: af-fade-in 0.45s ease;
}

/* The frame-sized hole: everything outside it is dimmed (cropped away). */
.af-shade {
  position: absolute;
  z-index: 3;
  pointer-events: none;
  box-shadow: 0 0 0 100vmax var(--af-shade);
  transition: box-shadow 0.2s ease;
}

.af-frame {
  position: absolute;
  z-index: 5;
  cursor: grab;
  border: 2px solid var(--af-accent-light);
  border-radius: 2px;
  box-shadow: 0 0 0 1px rgba(0, 0, 0, 0.35), 0 0 28px var(--af-accent-glow);
  background:
    linear-gradient(rgba(255, 255, 255, 0.18), rgba(255, 255, 255, 0.18)) 33.33% 0 / 1px 100% no-repeat,
    linear-gradient(rgba(255, 255, 255, 0.18), rgba(255, 255, 255, 0.18)) 66.66% 0 / 1px 100% no-repeat,
    linear-gradient(rgba(255, 255, 255, 0.18), rgba(255, 255, 255, 0.18)) 0 33.33% / 100% 1px no-repeat,
    linear-gradient(rgba(255, 255, 255, 0.18), rgba(255, 255, 255, 0.18)) 0 66.66% / 100% 1px no-repeat;
  touch-action: none;
}

.af-dragging .af-frame { cursor: grabbing; }
.af-busy .af-frame { cursor: default; }

.af-move-tag {
  position: absolute;
  z-index: 8;
  transform: translateX(-50%);
  padding: 6px 12px 6px 30px;
  border-radius: var(--af-radius);
  background: rgba(11, 14, 27, 0.78) url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='%23eceefe' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='M5 9l-3 3 3 3M9 5l3-3 3 3M15 19l-3 3-3-3M19 9l3 3-3 3M2 12h20M12 2v20'/%3E%3C/svg%3E") 9px 50% / 14px no-repeat;
  color: var(--af-text);
  font-size: 0.78rem;
  font-weight: 600;
  letter-spacing: 0.02em;
  white-space: nowrap;
  pointer-events: none;
  backdrop-filter: blur(6px);
  box-shadow: 0 6px 18px rgba(0, 0, 0, 0.35);
  transition: opacity 0.2s ease;
}

.af-dragging .af-move-tag,
.af-busy .af-move-tag { opacity: 0; }

.af-handle {
  position: absolute;
  width: 16px;
  height: 16px;
  border: 2px solid var(--af-accent-light);
  border-radius: 3px;
  background: var(--af-accent);
  box-shadow: 0 0 10px var(--af-accent-glow);
}

.af-handle-nw { left: -9px; top: -9px; cursor: nwse-resize; }
.af-handle-ne { right: -9px; top: -9px; cursor: nesw-resize; }
.af-handle-sw { left: -9px; bottom: -9px; cursor: nesw-resize; }
.af-handle-se { right: -9px; bottom: -9px; cursor: nwse-resize; }

/* Extension areas: light, partly transparent boxes with a darker Generate box. */
/* Above the frame (z 5): the Generate and Redo buttons must receive the click, not start a frame drag. */
.af-area-layer { position: absolute; inset: 0; z-index: 6; pointer-events: none; }

.af-area {
  position: absolute;
  display: flex;
  align-items: center;
  justify-content: center;
  border: 2px dashed var(--af-area-border);
  background: var(--af-area);
  overflow: hidden;
}

.af-area-done {
  /* The generated picture must read as one photo: no seams drawn over it. */
  border-color: transparent;
  background: transparent;
  backdrop-filter: none;
  align-items: flex-end;
  padding-bottom: 12px;
}

.af-progress {
  position: relative;
  z-index: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 10px;
  width: min(80%, 220px);
  color: #3a3f52;
  font: 600 0.8rem var(--af-font);
  text-align: center;
}

.af-spinner {
  width: 30px;
  height: 30px;
  border: 3px solid rgba(58, 63, 82, 0.18);
  border-top-color: var(--af-accent);
  border-radius: 50%;
  animation: af-spin 0.9s linear infinite;
}

.af-progress-bar {
  width: 100%;
  height: 6px;
  border-radius: 3px;
  background: rgba(58, 63, 82, 0.15);
  overflow: hidden;
}

.af-progress-fill {
  height: 100%;
  border-radius: 3px;
  background: var(--af-accent);
  transition: width 0.6s ease;
}

.af-progress-text { line-height: 1.35; }

@keyframes af-spin { to { transform: rotate(360deg); } }

.af-area-busy::after {
  content: "";
  position: absolute;
  inset: 0;
  background: linear-gradient(110deg, transparent 20%, rgba(255, 255, 255, 0.22) 45%, transparent 70%);
  animation: af-shimmer 1.4s linear infinite;
}

.af-area-btn {
  position: relative;
  z-index: 1;
  pointer-events: auto;
  padding: 9px 16px 9px 34px;
  border: 1px solid rgba(255, 255, 255, 0.16);
  border-radius: var(--af-radius);
  background: var(--af-area-button) url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='%23c4b5fd'%3E%3Cpath d='M12 2l1.9 5.6L19.5 9.5l-5.6 1.9L12 17l-1.9-5.6L4.5 9.5l5.6-1.9zM19 14l.9 2.6 2.6.9-2.6.9L19 21l-.9-2.6-2.6-.9 2.6-.9z'/%3E%3C/svg%3E") 11px 50% / 16px no-repeat;
  color: var(--af-text);
  font: 600 0.84rem var(--af-font);
  cursor: pointer;
  box-shadow: 0 8px 22px rgba(0, 0, 0, 0.35);
  transition: background-color 0.18s ease, transform 0.18s ease, box-shadow 0.18s ease;
}

.af-area-btn:hover:not(:disabled) {
  background-color: var(--af-area-button-hover);
  transform: translateY(-1px);
  box-shadow: 0 10px 26px rgba(0, 0, 0, 0.42), 0 0 0 1px var(--af-accent-glow);
}

.af-area-btn:disabled { opacity: 0.75; cursor: progress; }

.af-area-redo {
  padding: 7px 14px 7px 30px;
  font-size: 0.78rem;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='%23c4b5fd' stroke-width='2.2' stroke-linecap='round'%3E%3Cpath d='M20 11a8 8 0 1 0-2.3 5.7M20 5v6h-6'/%3E%3C/svg%3E");
  background-size: 14px;
}

/* Actions sit on the original picture inside the frame. */
.af-actions {
  position: absolute;
  z-index: 7;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: flex-end;
  gap: 8px;
  padding-bottom: 18px;
  pointer-events: none;
}

.af-accept {
  pointer-events: auto;
  padding: 11px 20px 11px 38px;
  border: 0;
  border-radius: var(--af-radius);
  background: var(--af-accent) url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='white' stroke-width='2.6' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='M5 12.5l4.5 4.5L19 7.5'/%3E%3C/svg%3E") 13px 50% / 17px no-repeat;
  color: #fff;
  font: 700 0.9rem var(--af-font);
  cursor: pointer;
  box-shadow: 0 10px 28px var(--af-accent-glow);
  animation: af-rise 0.35s ease;
  transition: transform 0.18s ease, filter 0.18s ease;
}

.af-accept:hover:not(:disabled) { transform: translateY(-1px); filter: brightness(1.08); }
.af-accept:disabled { opacity: 0.6; cursor: progress; }

.af-error {
  padding: 7px 12px;
  border-radius: var(--af-radius);
  background: rgba(255, 93, 108, 0.16);
  color: var(--af-danger);
  font-size: 0.8rem;
  font-weight: 600;
}

/* Ratio selector (segmented control, same look as the Video Creator format switch). */
.af-ratio-bar {
  display: inline-flex;
  padding: 3px;
  gap: 2px;
  border: 1px solid var(--vc-border, rgba(141, 120, 255, 0.16));
  border-radius: var(--af-radius, 5px);
  background: var(--vc-bg-elev, #0b0e1b);
}

.af-ratio-bar button {
  display: inline-flex;
  align-items: center;
  gap: 0.45rem;
  height: 32px;
  padding: 0 0.8rem;
  border: 0;
  border-radius: 3px;
  background: transparent;
  color: var(--vc-text-muted, #a3abcc);
  font: 600 0.82rem var(--vc-font, "Inter", system-ui, sans-serif);
  cursor: pointer;
  transition: background 0.2s ease, color 0.2s ease;
}

.af-ratio-bar button:hover:not(:disabled) { color: var(--vc-text, #eceefe); background: rgba(255, 255, 255, 0.06); }
.af-ratio-bar button:disabled { opacity: 0.4; cursor: default; }
.af-ratio-bar button.af-on { background: var(--vc-accent, #7c5cff); color: #fff; box-shadow: 0 4px 14px var(--vc-accent-glow, rgba(124, 92, 255, 0.42)); }
.af-ratio-icon { display: inline-block; flex: none; border: 1.5px solid currentColor; border-radius: 2px; }
.af-ratio-icon-original { border-style: dashed; }

@keyframes af-shimmer { from { transform: translateX(-100%); } to { transform: translateX(100%); } }
@keyframes af-fade-in { from { opacity: 0; } to { opacity: 1; } }
@keyframes af-rise { from { opacity: 0; transform: translateY(6px); } to { opacity: 1; transform: translateY(0); } }

/* ── Image editor host (ImageEditor.razor, RogerFeatures:ImageEditorAspectRatioEnabled) ── */
.image-editor-popup.image-editor-studio {
  width: 100vw;
  height: 100vh;
  max-width: none;
  max-height: none;
  border-radius: 0;
}

.editor-aspect-ratio-bar {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  margin: 0.25rem 0 0.5rem;
}

.editor-aspect-ratio-title {
  color: var(--vc-text-muted, #a3abcc);
  font: 600 0.78rem var(--vc-font, "Inter", system-ui, sans-serif);
  letter-spacing: 0.04em;
  text-transform: uppercase;
}

.editor-aspect-ratio-more { position: relative; display: inline-flex; }
.editor-aspect-ratio-more > button { padding: 0 0.55rem; }

.editor-aspect-ratio-menu {
  position: absolute;
  top: calc(100% + 6px);
  left: 50%;
  z-index: 210;
  display: flex;
  flex-direction: column;
  min-width: 150px;
  padding: 4px;
  transform: translateX(-50%);
  border: 1px solid var(--vc-border, rgba(141, 120, 255, 0.16));
  border-radius: var(--vc-radius-control, 5px);
  background: var(--vc-bg-elev, #0b0e1b);
  box-shadow: 0 14px 34px rgba(0, 0, 0, 0.45);
  animation: af-menu-in 0.18s ease;
}

@keyframes af-menu-in { from { opacity: 0; transform: translate(-50%, 6px); } to { opacity: 1; transform: translate(-50%, 0); } }

.af-ratio-bar .editor-aspect-ratio-menu button { justify-content: flex-start; width: 100%; gap: 0.6rem; color: var(--vc-text, #eceefe); }
.editor-aspect-ratio-menu[hidden] { display: none; }

.editor-aspect-ratio-close {
  height: 32px;
  padding: 0 0.9rem;
  border: 1px solid var(--vc-border, rgba(141, 120, 255, 0.16));
  border-radius: var(--vc-radius-control, 5px);
  background: transparent;
  color: var(--vc-text-muted, #a3abcc);
  font: 600 0.82rem var(--vc-font, "Inter", system-ui, sans-serif);
  cursor: pointer;
}

.editor-aspect-ratio-close:hover { color: var(--vc-text, #eceefe); background: rgba(255, 255, 255, 0.06); }

/* The frame covers the editor stage; the drawing tools stay hidden underneath while it is open. */
.image-aspect-frame-host { position: absolute; inset: 0; z-index: 50; }
.image-aspect-frame-host[data-status]::after {
  content: attr(data-status);
  position: absolute;
  left: 50%;
  bottom: 12px;
  z-index: 7;
  transform: translateX(-50%);
  padding: 6px 12px;
  border-radius: var(--vc-radius-control, 5px);
  background: rgba(11, 14, 27, 0.78);
  color: var(--vc-text, #eceefe);
  font: 600 0.78rem var(--vc-font, "Inter", system-ui, sans-serif);
  white-space: nowrap;
  pointer-events: none;
}
.image-aspect-frame-host:not(:has(.af-busy))[data-status]::after { display: none; }

/* Aspect ratio of a new picture (ImageSettings.razor). */
.image-settings-aspect-ratio { display: flex; margin: 0.2rem 0 0.6rem; }

/* Ratio bar inside the image editor toolbar (imageEditor.js mountAspectRatioToolbar). */
/* Above the frame overlay (host z 50): the menu opens over the picture and must stay clickable. */
.editor-aspect-toolbar {
  position: relative;
  z-index: 200;
  display: inline-flex;
  align-items: center;
  gap: 8px;
  margin-left: 12px;
  vertical-align: middle;
}

.editor-aspect-toolbar .editor-aspect-ratio-title { margin-right: 2px; }

.editor-aspect-toolbar .editor-aspect-accept {
  height: 32px;
  padding: 0 0.9rem;
  border: 0;
  border-radius: var(--vc-radius-control, 5px);
  background: var(--vc-accent, #7c5cff);
  color: #fff;
  font: 700 0.82rem var(--vc-font, "Inter", system-ui, sans-serif);
  cursor: pointer;
  box-shadow: 0 4px 14px var(--vc-accent-glow, rgba(124, 92, 255, 0.42));
}

.editor-aspect-toolbar .editor-aspect-accept:disabled {
  opacity: 0.45;
  cursor: default;
  box-shadow: none;
}

.editor-aspect-toolbar [hidden] { display: none !important; }

.editor-esc-warning {
  position: absolute;
  left: 50%;
  top: 45%;
  z-index: 60;
  transform: translate(-50%, -50%);
  padding: 16px 26px 16px 52px;
  border: 1px solid rgba(255, 193, 7, 0.55);
  border-radius: var(--vc-radius-control, 5px);
  background: rgba(11, 14, 27, 0.96) url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='%23ffc107' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='M12 3l10 18H2z'/%3E%3Cpath d='M12 10v5M12 18h.01'/%3E%3C/svg%3E") 18px 50% / 22px no-repeat;
  color: #fff;
  font: 700 1rem var(--vc-font, "Inter", system-ui, sans-serif);
  box-shadow: 0 18px 44px rgba(0, 0, 0, 0.6);
  pointer-events: none;
  animation: af-rise 0.2s ease;
}

/* The toolbar menu is moved to <body> (the toolbar clips): fixed, above the editor window (z 90000). */
body > .editor-aspect-ratio-menu {
  position: fixed;
  z-index: 100000;
  display: flex;
  flex-direction: column;
  min-width: 170px;
  padding: 4px;
  transform: translateX(-50%);
  border: 1px solid var(--vc-border, rgba(141, 120, 255, 0.16));
  border-radius: var(--vc-radius-control, 5px);
  background: var(--vc-bg-elev, #0b0e1b);
  box-shadow: 0 14px 34px rgba(0, 0, 0, 0.45);
  animation: af-menu-in 0.18s ease;
}

body > .editor-aspect-ratio-menu[hidden] { display: none; }

body > .editor-aspect-ratio-menu button {
  display: flex;
  align-items: center;
  gap: 0.6rem;
  width: 100%;
  height: 34px;
  padding: 0 0.8rem;
  border: 0;
  border-radius: 3px;
  background: transparent;
  color: var(--vc-text, #eceefe);
  font: 600 0.82rem var(--vc-font, "Inter", system-ui, sans-serif);
  text-align: left;
  cursor: pointer;
}

body > .editor-aspect-ratio-menu button:hover { background: rgba(255, 255, 255, 0.07); }
body > .editor-aspect-ratio-menu button.af-on { background: var(--vc-accent, #7c5cff); color: #fff; }

/* With the frame open the row also holds Accept changes and Cancel: drop the title to stay within the stage. */
.editor-aspect-toolbar.af-open .editor-aspect-ratio-title { display: none; }

/* Kendo's desktop toolbar clips overflow. On phones the ratio controls need
   their own wrapping row, including Accept/Cancel while the frame is open. */
@media (max-width: 480px) {
  .image-editor-popup .k-imageeditor-toolbar {
    flex-wrap: wrap !important;
    height: auto !important;
    overflow: visible !important;
  }

  .image-editor-popup .editor-aspect-toolbar {
    /* Kendo adds k-hidden when its desktop overflow calculation runs on resize. */
    display: flex !important;
    flex: 1 0 100%;
    flex-wrap: wrap;
    justify-content: center;
    gap: 6px;
    width: 100%;
    min-width: 0;
    margin: 4px 0 0;
    padding: 4px 0;
    box-sizing: border-box;
  }

  .image-editor-popup .editor-aspect-ratio-title {
    display: none;
  }

  .image-editor-popup .af-area-btn {
    max-width: 100%;
    box-sizing: border-box;
    padding: 8px 4px;
    font-size: 8px;
    line-height: 1.2;
    white-space: normal;
    overflow-wrap: anywhere;
    background-image: none;
  }

  .image-editor-popup .af-move-tag {
    max-width: 90%;
    box-sizing: border-box;
    padding: 5px;
    font-size: 0.65rem;
    background-image: none;
  }
}
