/* Bloco isolado: gerador de Reels (Pexels + preview) */

.reels-instagram {
  box-sizing: border-box;
  margin: 28px 2em 0;
  padding-top: 22px;
  border-top: 1px solid var(--border-subtle);
  width: auto;
  max-width: 100%;
}

.reels-instagram__head.preview-area-section-head {
  margin-bottom: 16px;
}

.reels-instagram__row {
  display: flex;
  flex-wrap: wrap;
  gap: 28px;
  align-items: stretch;
  justify-content: flex-start;
}

.reels-instagram__left {
  flex: 1 1 280px;
  min-width: 0;
  width: auto;
  max-width: none;
  display: flex;
  flex-direction: column;
  gap: 10px;
  align-self: stretch;
  min-height: 0;
}

.reels-instagram__status {
  flex: 0 0 auto;
}

.reels-instagram__text-shell {
  position: relative;
  flex: 0 0 auto;
  width: 100%;
  min-width: 0;
}

.reels-instagram__text-toolbar {
  position: absolute;
  top: 8px;
  right: 8px;
  z-index: 2;
  display: flex;
  flex-direction: row;
  align-items: center;
  justify-content: flex-end;
  gap: 6px;
  pointer-events: auto;
}

.reels-instagram__text-style-btn {
  width: 30px;
  height: 28px;
  padding: 0;
  border-radius: 6px;
  border: 1px solid var(--border-default);
  background: var(--bg-elevated);
  color: var(--text-secondary);
  font-size: 14px;
  font-weight: 700;
  font-style: normal;
  line-height: 1;
  cursor: pointer;
  font-family: inherit;
  box-sizing: border-box;
}

.reels-instagram__text-style-btn--italic {
  font-style: italic;
  font-weight: 600;
}

.reels-instagram__text-style-btn:hover {
  border-color: var(--brand);
  background: var(--brand-muted);
}

.reels-instagram__text-style-btn:active {
  transform: scale(0.96);
}

body.light-theme .reels-instagram__text-style-btn {
  border-color: var(--border-default);
  background: var(--bg-input);
  color: var(--text-primary);
}

body.light-theme .reels-instagram__text-style-btn:hover {
  border-color: var(--brand);
  background: var(--brand-muted);
}

.reels-instagram__text {
  width: 100%;
  min-height: 120px;
  max-height: 280px;
  overflow: auto;
  padding: 10px 12px;
  border-radius: var(--radius-md, 8px);
  border: 1px solid var(--border-subtle);
  background: var(--bg-input);
  color: var(--text-primary);
  font-size: 14px;
  font-weight: 400;
  line-height: 1.45;
  resize: vertical;
  font-family: inherit;
  white-space: pre-wrap;
  word-break: break-word;
  box-sizing: border-box;
}

.reels-instagram__text:focus {
  outline: none;
  border-color: var(--brand);
}

.reels-instagram__viral-loading-msg {
  flex: 0 0 100%;
  width: 100%;
  min-width: 100%;
  box-sizing: border-box;
  padding: 12px 14px;
  border-radius: var(--radius-md, 8px);
  border: 1px dashed var(--border-default);
  background: var(--bg-elevated);
  color: var(--text-muted);
  font-size: 13px;
  line-height: 1.4;
}


.reels-instagram__viral-picks-scroll {
  container-type: inline-size;
  container-name: reels-viral-picks;
  flex: 0 0 auto;
  width: 100%;
  overflow-x: auto;
  overflow-y: hidden;
  padding: 2px 0 8px;
  -webkit-overflow-scrolling: touch;
}

.reels-instagram__viral-picks {
  display: flex;
  flex-direction: row;
  flex-wrap: nowrap;
  gap: 10px;
  width: max-content;
  max-width: none;
  padding: 2px 0;
}

.reels-instagram__viral-chip {
  flex: 0 0 calc((100cqi - 20px) / 3);
  width: calc((100cqi - 20px) / 3);
  max-width: calc((100cqi - 20px) / 3);
  min-height: 72px;
  max-height: 200px;
  overflow-y: auto;
  padding: 10px 10px 10px 12px;
  border-radius: var(--radius-md, 8px);
  border: 1px solid var(--border-subtle);
  background: var(--bg-elevated);
  color: var(--text-primary);
  font-size: 12px;
  line-height: 1.35;
  text-align: left;
  cursor: pointer;
  font-family: inherit;
  box-sizing: border-box;
  display: flex;
  flex-direction: row;
  align-items: flex-start;
  justify-content: space-between;
  gap: 6px;
}

.reels-instagram__viral-chip-text {
  flex: 1 1 auto;
  min-width: 0;
  white-space: pre-line;
  word-break: break-word;
  text-align: left;
}

.reels-instagram__viral-chip-arrow {
  flex: 0 0 auto;
  font-size: 20px;
  font-weight: 300;
  line-height: 1;
  color: var(--brand);
  opacity: 0.9;
  margin-top: 1px;
  user-select: none;
}

.reels-instagram__viral-chip:hover .reels-instagram__viral-chip-arrow {
  opacity: 1;
}

.reels-instagram__viral-chip:hover {
  border-color: var(--border-default);
  background: var(--bg-surface-mid);
}

.reels-instagram__viral-chip.is-selected {
  border-color: var(--brand);
  background: var(--brand-muted);
  box-shadow: 0 0 0 1px var(--brand-muted);
}

.reels-instagram__font-toolbar-rule {
  flex: 0 0 auto;
  width: 100%;
  height: 1px;
  margin: 0;
  padding: 0;
  border: none;
  background: rgba(255, 255, 255, 0.07);
}

body.light-theme .reels-instagram__font-toolbar-rule {
  background: rgba(0, 0, 0, 0.08);
}

.reels-instagram__font-toolbar {
  display: grid;
  grid-template-columns: minmax(0, 7fr) minmax(0, 3fr);
  align-items: start;
  column-gap: 16px;
  row-gap: 12px;
  width: 100%;
  flex: 0 0 auto;
  padding: 4px 0;
  box-sizing: border-box;
}

.reels-instagram__font-toolbar-left {
  min-width: 0;
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 8px;
}

.reels-instagram__font-toolbar-right {
  min-width: 0;
  display: flex;
  flex-direction: column;
  align-items: stretch;
  gap: 12px;
  box-sizing: border-box;
  color-scheme: dark;
}

body.light-theme .reels-instagram__font-toolbar-right {
  color-scheme: light;
}

@media (max-width: 640px) {
  .reels-instagram__font-toolbar {
    grid-template-columns: 1fr;
  }
}

.reels-instagram__font-size {
  display: flex;
  flex-direction: column;
  align-items: stretch;
  gap: 6px;
  width: 100%;
}

.reels-instagram__line-height {
  display: flex;
  flex-direction: column;
  align-items: stretch;
  gap: 6px;
  width: 100%;
}

.reels-instagram__font-size-label,
.reels-instagram__line-height-label {
  font-size: 12px;
  font-weight: 600;
  color: var(--text-muted);
  white-space: nowrap;
}

.reels-instagram__font-size-slider,
.reels-instagram__line-height-slider {
  width: 100%;
  min-width: 0;
  height: 18px;
  border-radius: 3px;
  accent-color: var(--brand);
  cursor: pointer;
  appearance: none;
  background: transparent;
  box-sizing: border-box;
}

.reels-instagram__font-size-slider::-webkit-slider-runnable-track,
.reels-instagram__line-height-slider::-webkit-slider-runnable-track {
  height: 6px;
  border-radius: 3px;
  background: var(--border-subtle);
}

.reels-instagram__font-size-slider::-webkit-slider-thumb,
.reels-instagram__line-height-slider::-webkit-slider-thumb {
  -webkit-appearance: none;
  appearance: none;
  width: 14px;
  height: 14px;
  margin-top: -4px;
  border-radius: 50%;
  background: var(--brand);
  border: 2px solid var(--bg-input);
  box-shadow: 0 1px 2px rgba(0, 0, 0, 0.25);
  cursor: pointer;
  box-sizing: border-box;
}

.reels-instagram__font-size-slider::-moz-range-track,
.reels-instagram__line-height-slider::-moz-range-track {
  height: 6px;
  border-radius: 3px;
  background: var(--border-subtle);
}

.reels-instagram__font-size-slider::-moz-range-thumb,
.reels-instagram__line-height-slider::-moz-range-thumb {
  width: 14px;
  height: 14px;
  border-radius: 50%;
  background: var(--brand);
  border: 2px solid var(--bg-input);
  box-shadow: 0 1px 2px rgba(0, 0, 0, 0.25);
  cursor: pointer;
  box-sizing: border-box;
}

.reels-instagram__font-size-slider::-moz-focus-outer,
.reels-instagram__line-height-slider::-moz-focus-outer {
  border: 0;
}

body.light-theme .reels-instagram__font-toolbar-right .reels-instagram__font-size-label,
body.light-theme .reels-instagram__font-toolbar-right .reels-instagram__line-height-label {
  color: var(--text-secondary);
}

.reels-instagram__font-btn {
  padding: 6px 12px;
  border-radius: var(--radius-md, 8px);
  border: 1px solid var(--border-subtle);
  background: var(--bg-input);
  color: var(--text-primary);
  font-size: 13px;
  font-weight: 600;
  line-height: 1.2;
  cursor: pointer;
  font-family: inherit;
  transition: border-color 0.15s, background 0.15s;
}

.reels-instagram__font-btn:hover {
  border-color: var(--border-default);
  background: var(--bg-elevated);
}

.reels-instagram__font-btn.is-active {
  border-color: var(--brand);
  background: var(--brand-muted);
  box-shadow: 0 0 0 1px var(--brand-muted);
}

.reels-instagram__grid-scroll {
  flex: 1 1 auto;
  min-height: 0;
  width: 100%;
  overflow-x: auto;
  overflow-y: hidden;
  -webkit-overflow-scrolling: touch;
}

.reels-instagram__grid {
  display: flex;
  flex-direction: row;
  flex-wrap: nowrap;
  align-items: stretch;
  gap: 8px;
  width: max-content;
  max-width: none;
  margin: 0;
  padding: 0;
  box-sizing: border-box;
}

.reels-instagram__thumb {
  position: relative;
  flex: 0 0 auto;
  width: 120px;
  min-width: 120px;
  aspect-ratio: 9 / 16;
  border-radius: var(--radius-md, 8px);
  overflow: hidden;
  border: 2px solid transparent;
  cursor: pointer;
  background: var(--bg-elevated);
  padding: 0;
  display: block;
  box-sizing: border-box;
}

.reels-instagram__thumb:hover {
  border-color: var(--border-default);
}

.reels-instagram__thumb.is-selected {
  border-color: var(--brand);
}

.reels-instagram__thumb img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  display: block;
}

.reels-instagram__thumb-dur {
  position: absolute;
  bottom: 4px;
  right: 4px;
  font-size: 10px;
  font-weight: 600;
  color: #fff;
  background: rgba(0, 0, 0, 0.65);
  padding: 1px 4px;
  border-radius: 3px;
  line-height: 1.2;
}

.reels-instagram__right {
  flex: 0 0 auto;
  min-width: 0;
  margin-left: auto;
  display: flex;
  flex-direction: column;
  align-items: flex-end;
  justify-content: flex-start;
  gap: 12px;
  align-self: stretch;
}

.reels-instagram__frame {
  --reel-caption-px: 42;
  --reel-caption-line-height: 1.095238;
  position: relative;
  width: min(360px, 34vw);
  max-width: 100%;
  aspect-ratio: 9 / 16;
  border-radius: 14px;
  overflow: hidden;
  background: #000;
  box-shadow: 0 12px 40px rgba(0, 0, 0, 0.45);
  /* Mesma proporção de tipografia que o export 1080×1920 */
  container-type: size;
  container-name: reelframe;
}

.reels-instagram__frame video {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  object-fit: cover;
}

.reels-instagram__overlay {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  pointer-events: none;
  /* Camada preta com alpha em todo o frame (igual ao canvas exportado) */
  background: rgba(0, 0, 0, 0.45);
  z-index: 1;
}

.reels-instagram__mute-music {
  position: absolute;
  bottom: 10px;
  right: 10px;
  z-index: 4;
  width: 40px;
  height: 40px;
  padding: 0;
  border-radius: 10px;
  border: 1px solid rgba(255, 255, 255, 0.35);
  background: rgba(0, 0, 0, 0.55);
  color: #fff;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  font-family: inherit;
  box-sizing: border-box;
  pointer-events: auto;
}

.reels-instagram__mute-music svg {
  display: block;
  flex-shrink: 0;
}

.reels-instagram__mute-music:hover {
  border-color: var(--brand);
  background: rgba(20, 35, 48, 0.75);
}

.reels-instagram__mute-music[aria-pressed='true'] {
  opacity: 0.85;
}

body.light-theme .reels-instagram__mute-music {
  border-color: rgba(0, 0, 0, 0.2);
  background: rgba(255, 255, 255, 0.88);
  color: #111;
}

.reels-instagram__caption {
  position: absolute;
  inset: 0;
  z-index: 2;
  display: flex;
  align-items: center;
  justify-content: center;
  text-align: center;
  /* 40px de margem horizontal no export = 40/1080 da largura */
  padding: 0 clamp(8px, 3.704cqw, 48px);
  box-sizing: border-box;
  font-weight: 400;
  /* Escala com o slider: px no export 1080 ↔ (px/1080) × largura do frame */
  font-size: calc((var(--reel-caption-px, 42) / 1080) * 100cqw);
  line-height: var(--reel-caption-line-height, 1.095238);
  color: #fff;
  text-shadow: 0 1px 12px rgba(0, 0, 0, 0.85);
}

.reels-instagram__caption-inner {
  display: block;
  min-width: 0;
  width: 100%;
  max-width: 100%;
  text-align: center;
  white-space: pre-wrap;
  overflow-wrap: break-word;
  word-break: break-word;
}

.reels-instagram__caption b,
.reels-instagram__caption strong,
.reels-instagram__caption-inner b,
.reels-instagram__caption-inner strong {
  font-weight: 700;
}

.reels-instagram__caption i,
.reels-instagram__caption em,
.reels-instagram__caption-inner i,
.reels-instagram__caption-inner em {
  font-style: italic;
}

.reels-instagram__loading,
.reels-instagram__error,
.reels-instagram__empty {
  font-size: 13px;
  padding: 12px;
  border-radius: 8px;
}

.reels-instagram__loading {
  color: var(--text-muted);
  background: var(--bg-elevated);
}

.reels-instagram__error {
  color: #ffb4b4;
  background: #3a2020;
}

.reels-instagram__empty {
  color: var(--text-muted);
  background: var(--bg-elevated);
}

.reels-instagram__download {
  padding: 10px 18px;
  border-radius: var(--radius-md, 8px);
  border: none;
  background: var(--brand);
  color: #fff;
  font-weight: 600;
  font-size: 13px;
  cursor: pointer;
  font-family: inherit;
}

.reels-instagram__download:hover:not(:disabled) {
  filter: brightness(1.08);
}

.reels-instagram__download:disabled {
  opacity: 0.45;
  cursor: not-allowed;
}

@media (max-width: 900px) {
  .reels-instagram__row {
    flex-direction: column;
  }

  .reels-instagram__left {
    flex: 1 1 auto;
    width: 100%;
  }

  .reels-instagram__right {
    margin-left: 0;
    align-items: center;
    width: 100%;
  }

  .reels-instagram__frame {
    width: min(100%, 320px);
  }
}

@media (max-width: 720px) {
  .reels-instagram {
    margin-left: 1em;
    margin-right: 1em;
  }

  .reels-instagram__frame {
    width: min(100%, 300px);
  }
}
