/* ============================================================================
   Editor IA de Video — estilo propio tipo editor real (Viro-like), tema oscuro
   con acentos rojos NOXUS. TODO scopeado bajo .vied para no filtrar al resto del
   sitio. Sin dependencias: variables CSS + grid/flex. (Fase B rediseño)
   ========================================================================== */
@font-face { font-family: 'EdMontserrat'; src: url('/static/fonts/Montserrat-Bold.ttf') format('truetype'); font-weight: 700; font-display: swap; }
@font-face { font-family: 'EdPoppins'; src: url('/static/fonts/Poppins-SemiBold.ttf') format('truetype'); font-weight: 600; font-display: swap; }
@font-face { font-family: 'EdBebas'; src: url('/static/fonts/BebasNeue-Regular.ttf') format('truetype'); font-display: swap; }
@font-face { font-family: 'EdImpact'; src: url('/static/fonts/LuckiestGuy-Regular.ttf') format('truetype'); font-display: swap; }

.vied {
  /* Mapea al tema de la web (light/dark automatico via html[data-theme]). */
  --vied-bg: var(--bg, #0a0a0d);
  --vied-bg-2: color-mix(in srgb, var(--bg) 60%, var(--surface-soft, #15181f));
  --vied-panel: var(--surface-solid, #141419);
  --vied-panel-2: var(--surface-soft, #1a1a21);
  --vied-elev: var(--surface-soft, #1f1f27);
  --vied-border: var(--border, #26262f);
  --vied-border-2: var(--border-strong, #313140);
  --vied-text: var(--text, #ececf1);
  --vied-muted: var(--muted, #8b8b96);
  --vied-faint: color-mix(in srgb, var(--muted) 72%, transparent);
  --vied-red: var(--accent, #1268d6);
  --vied-red-2: var(--accent-hover, #0d56b4);
  --vied-red-soft: var(--accent-soft, rgba(18, 104, 214, 0.12));
  --vied-green: #22c55e;
  --vied-radius: 14px;
  --vied-radius-sm: 9px;
  color: var(--vied-text);
  font-family: inherit;
}
.vied *, .vied *::before, .vied *::after { box-sizing: border-box; }
.vied button { font: inherit; cursor: pointer; }

/* ----- contenedor a pantalla casi completa ----- */
.vied-app {
  background: radial-gradient(120% 80% at 50% -10%, color-mix(in srgb, var(--vied-red) 12%, var(--vied-bg)) 0%, var(--vied-bg) 55%);
  border: 1px solid var(--vied-border);
  border-radius: var(--vied-radius);
  overflow: hidden;
  height: 86vh; min-height: 560px;
  display: flex;
  flex-direction: column;
  box-shadow: 0 30px 80px rgba(0, 0, 0, 0.35);
}

/* ----- topbar ----- */
.vied-topbar {
  display: flex; align-items: center; gap: 12px;
  padding: 10px 14px;
  background: linear-gradient(180deg, rgba(255,255,255,0.02), transparent);
  border-bottom: 1px solid var(--vied-border);
}
.vied-topbar .vied-spacer { flex: 1; }
.vied-chip {
  display: inline-flex; align-items: center; gap: 7px;
  padding: 7px 13px; border-radius: 999px;
  background: var(--vied-panel); border: 1px solid var(--vied-border);
  color: var(--vied-text); font-size: 13px; font-weight: 600;
}
.vied-chip--credits { color: var(--vied-muted); }
.vied-btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  padding: 9px 16px; border-radius: 10px; font-weight: 700; font-size: 14px;
  border: 1px solid var(--vied-border-2); background: var(--vied-elev); color: var(--vied-text);
  transition: transform .08s ease, filter .12s ease, background .12s ease;
}
.vied-btn:hover { filter: brightness(1.12); }
.vied-btn:active { transform: translateY(1px); }
.vied-btn:disabled { opacity: .5; cursor: not-allowed; }
.vied-btn--primary {
  background: linear-gradient(180deg, var(--vied-red-2), var(--vied-red));
  border-color: var(--vied-red); color: #fff;
  box-shadow: 0 6px 20px color-mix(in srgb, var(--vied-red) 38%, transparent);
}
.vied-btn--ghost { background: transparent; border-color: transparent; color: var(--vied-muted); }
.vied-btn--ghost:hover { color: var(--vied-text); background: var(--vied-panel); }
.vied-btn--sm { padding: 7px 11px; font-size: 12.5px; border-radius: 8px; }
.vied-btn--block { width: 100%; }

/* ============================ Pantalla de setup ============================ */
.vied-setup { padding: 42px 20px; display: grid; place-items: center; flex: 1; }
.vied-setup__card {
  width: min(560px, 100%);
  background: var(--vied-panel); border: 1px solid var(--vied-border);
  border-radius: var(--vied-radius); padding: 26px;
  display: flex; flex-direction: column; gap: 18px;
}
.vied-setup__title { font-size: 1.35rem; font-weight: 800; margin: 0; }
.vied-setup__sub { color: var(--vied-muted); font-size: .95rem; margin: -8px 0 4px; }
.vied-drop {
  border: 1.5px dashed var(--vied-border-2); border-radius: var(--vied-radius);
  padding: 30px 18px; text-align: center; cursor: pointer; transition: border-color .12s, background .12s;
  background: var(--vied-bg-2); display: flex; flex-direction: column; gap: 6px; align-items: center;
}
.vied-drop:hover, .vied-drop.is-over { border-color: var(--vied-red); background: var(--vied-red-soft); }
.vied-drop strong { font-size: 1rem; }
.vied-drop small { color: var(--vied-faint); font-size: 12px; }
.vied-drop__icon { font-size: 26px; color: var(--vied-red-2); }

.vied-options { display: grid; gap: 12px; }
.vied-switch {
  display: flex; align-items: center; justify-content: space-between; gap: 12px;
  padding: 13px 15px; border: 1px solid var(--vied-border); border-radius: var(--vied-radius-sm);
  background: var(--vied-bg-2); font-weight: 600; font-size: 14px;
}
.vied-switch small { display: block; color: var(--vied-muted); font-weight: 400; font-size: 12px; margin-top: 2px; }
/* toggle */
.vied-toggle { position: relative; width: 44px; height: 25px; flex: 0 0 auto; }
.vied-toggle input { position: absolute; opacity: 0; width: 100%; height: 100%; margin: 0; cursor: pointer; }
.vied-toggle__track {
  position: absolute; inset: 0; background: var(--vied-border-2); border-radius: 999px;
  transition: background .15s; pointer-events: none;
}
.vied-toggle__track::after {
  content: ""; position: absolute; top: 3px; left: 3px; width: 19px; height: 19px;
  background: #fff; border-radius: 50%; transition: transform .15s;
}
.vied-toggle input:checked + .vied-toggle__track { background: var(--vied-red); }
.vied-toggle input:checked + .vied-toggle__track::after { transform: translateX(19px); }

/* segmented (servidor / navegador) */
.vied-seg { display: inline-flex; padding: 4px; gap: 4px; background: var(--vied-bg-2); border: 1px solid var(--vied-border); border-radius: 10px; }
.vied-seg button { flex: 1; padding: 8px 14px; border: 0; border-radius: 7px; background: transparent; color: var(--vied-muted); font-weight: 600; font-size: 13px; }
.vied-seg button.is-active { background: var(--vied-red); color: #fff; }

/* ============================ Editor (3 columnas) ============================ */
.vied-editor { flex: 1; display: grid; grid-template-rows: 1fr auto; min-height: 0; }
.vied-body { display: grid; grid-template-columns: 190px 1fr 270px; min-height: 0; }
@media (max-width: 960px) { .vied-body { grid-template-columns: 1fr; } .vied-left, .vied-right { display: none; } }

.vied-col { min-height: 0; overflow-y: auto; padding: 14px; }
.vied-left { border-right: 1px solid var(--vied-border); background: var(--vied-bg-2); }
.vied-right { border-left: 1px solid var(--vied-border); background: var(--vied-bg-2); }
.vied-center { display: flex; flex-direction: column; align-items: center; gap: 14px; padding: 22px 14px; }

.vied-label { font-size: 11px; font-weight: 800; letter-spacing: .08em; text-transform: uppercase; color: var(--vied-faint); margin: 2px 0 10px; display: flex; align-items: center; gap: 7px; }

/* ----- presets de estilo (panel izq) ----- */
.vied-presets { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; max-height: 260px; overflow-y: auto; padding-right: 4px; }
.vied-preset {
  text-align: left; padding: 11px; border-radius: var(--vied-radius-sm);
  background: var(--vied-panel); border: 1px solid var(--vied-border); color: var(--vied-text);
  display: flex; flex-direction: column; gap: 3px; transition: border-color .12s, background .12s;
}
.vied-preset:hover { border-color: var(--vied-border-2); }
.vied-preset.is-active { border-color: var(--vied-red); background: var(--vied-red-soft); box-shadow: 0 0 0 1px var(--vied-red) inset; }
.vied-preset strong { font-size: 12.5px; }
.vied-preset small { color: var(--vied-muted); font-size: 10.5px; line-height: 1.25; }

/* ----- escenario (preview vertical) ----- */
.vied-stage {
  position: relative; width: 100%; max-width: 300px; aspect-ratio: 9 / 16;
  background: #000; border-radius: 20px; overflow: hidden;
  box-shadow: 0 18px 50px rgba(0,0,0,.55), 0 0 0 1px var(--vied-border);
  container-type: inline-size;
}
.vied-stage video { position: absolute; inset: 0; width: 100%; height: 100%; object-fit: cover; transition: filter .15s ease, transform .2s ease; }
.vied-frame { position: absolute; inset: 0; pointer-events: none; z-index: 2; }
.vied-safe { position: absolute; inset: 0; pointer-events: none; z-index: 5; }
.vied-safe::before, .vied-safe::after { content: ""; position: absolute; left: 5%; right: 5%; height: 1px; background: rgba(255,255,255,.3); }
.vied-safe::before { top: 13%; } .vied-safe::after { bottom: 17%; }

/* imagen IA overlay (arrastrable; width 62% = render out_w*0.62) */
.vied-aiimg { position: absolute; left: 50%; top: 35%; transform: translate(-50%, -50%); width: 62%; z-index: 3; border-radius: 12px; box-shadow: 0 10px 30px rgba(0,0,0,.5); cursor: move; touch-action: none; pointer-events: auto; }

/* caption (subtítulos) */
.vied-cap-layer { position: absolute; inset: 0; z-index: 6; pointer-events: none; }
.vied-caption {
  position: absolute; left: 50%; top: 78%; transform: translate(-50%, -50%); max-width: 88%;
  text-align: center; line-height: 1.08; font-weight: 900; letter-spacing: .01em;
  white-space: pre-wrap; pointer-events: auto; cursor: move; touch-action: none;
}
.vied-emphasis { position: absolute; left: 50%; top: 17%; transform: translateX(-50%); text-align: center; max-width: 92%; z-index: 6; }
.vied-emphasis b { display: block; font-weight: 900; line-height: 1; text-shadow: 0 4px 22px rgba(0,0,0,.7), 0 2px 8px rgba(0,0,0,.5); letter-spacing: .01em; }
.vied-emphasis span { display: block; color: #fff; font-weight: 800; margin-top: 3px; text-shadow: 0 3px 12px rgba(0,0,0,.6); }
@keyframes viedEmphPop { from { transform: scale(.72) rotate(-2deg); opacity: 0; } to { transform: none; opacity: 1; } }

/* focus card (oculta video -> fondo borroso + frase) */
.vied-focus {
  position: absolute; inset: 0; z-index: 7; display: grid; place-items: center; padding: 10%;
  backdrop-filter: blur(16px); -webkit-backdrop-filter: blur(16px);
  text-align: center; transition: background .15s;
}
.vied-focus p { margin: 0; color: #141414; font-weight: 900; line-height: 1.15; letter-spacing: -.01em; }
.vied-focus .vied-focus__w { opacity: 0; display: inline-block; animation: viedWordIn .35s cubic-bezier(.22,1,.36,1) forwards; }
@keyframes viedWordIn { from { opacity: 0; transform: translateY(10px) scale(.92); } to { opacity: 1; transform: none; } }

/* hook title (título gancho, aparece al inicio) */
.vied-hook-title {
  position: absolute; top: 9%; left: 50%; transform: translateX(-50%);
  font-size: clamp(16px, 5.5cqw, 30px); font-weight: 900; color: #fff;
  text-shadow: 0 3px 14px rgba(0,0,0,.8), 0 0 30px rgba(0,0,0,.5);
  text-align: center; max-width: 82%; z-index: 8; line-height: 1.1;
  opacity: 0; pointer-events: none;
  transition: opacity .5s ease;
}
.vied-hook-title.vied-ht--visible { opacity: 1; }

/* player */
.vied-player { display: flex; align-items: center; gap: 12px; width: 100%; max-width: 300px; }
.vied-play { width: 42px; height: 42px; border-radius: 50%; border: 0; background: linear-gradient(180deg, var(--vied-red-2), var(--vied-red)); color: #fff; font-size: 15px; display: grid; place-items: center; box-shadow: 0 6px 18px color-mix(in srgb, var(--vied-red) 42%, transparent); }
.vied-seekbar { flex: 1; appearance: none; height: 5px; border-radius: 999px; background: var(--vied-border-2); outline: none; }
.vied-seekbar::-webkit-slider-thumb { appearance: none; width: 14px; height: 14px; border-radius: 50%; background: var(--vied-red-2); cursor: pointer; box-shadow: 0 0 0 3px color-mix(in srgb, var(--vied-red) 28%, transparent); }
.vied-time { color: var(--vied-muted); font-size: 12px; font-variant-numeric: tabular-nums; min-width: 84px; text-align: right; }

/* ----- panel derecho (acordeón de ajustes IA) ----- */
.vied-acc { border: 1px solid var(--vied-border); border-radius: var(--vied-radius-sm); margin-bottom: 9px; overflow: hidden; background: var(--vied-panel); }
.vied-acc__head { width: 100%; display: flex; align-items: center; gap: 9px; padding: 12px 13px; background: transparent; border: 0; color: var(--vied-text); font-weight: 700; font-size: 13.5px; }
.vied-acc__head .vied-dot { width: 7px; height: 7px; border-radius: 50%; background: var(--vied-green); margin-left: auto; }
.vied-acc__head .vied-caret { margin-left: 8px; color: var(--vied-faint); transition: transform .15s; }
.vied-acc.is-open .vied-acc__head .vied-caret { transform: rotate(180deg); }
.vied-acc__body { padding: 0 13px 13px; display: none; flex-direction: column; gap: 11px; }
.vied-acc.is-open .vied-acc__body { display: flex; }
.vied-acc__icon { color: var(--vied-red-2); }

.vied-field { display: flex; flex-direction: column; gap: 6px; }
.vied-field > span { font-size: 12px; color: var(--vied-muted); display: flex; justify-content: space-between; }
.vied-range { appearance: none; width: 100%; height: 5px; border-radius: 999px; background: var(--vied-border-2); }
.vied-range::-webkit-slider-thumb { appearance: none; width: 15px; height: 15px; border-radius: 50%; background: var(--vied-red); cursor: pointer; }
.vied-swatches { display: flex; gap: 8px; flex-wrap: wrap; }
.vied-color { width: 30px; height: 30px; border-radius: 8px; border: 2px solid var(--vied-border-2); padding: 0; background: none; overflow: hidden; }
.vied-color input { width: 150%; height: 150%; margin: -25%; border: 0; padding: 0; background: none; cursor: pointer; }

/* lista de items IA (énfasis / efectos / focus / imágenes) */
.vied-list { display: flex; flex-direction: column; gap: 6px; }
.vied-item {
  display: flex; align-items: center; gap: 9px; padding: 9px 10px; border-radius: 8px;
  background: var(--vied-bg-2); border: 1px solid var(--vied-border); font-size: 12.5px;
}
.vied-item__t { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.vied-item__time { color: var(--vied-faint); font-size: 11px; font-variant-numeric: tabular-nums; }
.vied-item__x { color: var(--vied-faint); background: none; border: 0; font-size: 15px; line-height: 1; padding: 0 2px; }
.vied-item__x:hover { color: var(--vied-red-2); }
.vied-item__badge { font-size: 9.5px; font-weight: 800; text-transform: uppercase; letter-spacing: .04em; padding: 2px 6px; border-radius: 5px; background: var(--vied-red-soft); color: var(--vied-red-2); }
.vied-empty { color: var(--vied-faint); font-size: 12px; text-align: center; padding: 14px 6px; line-height: 1.4; }

textarea.vied-input, input.vied-input {
  width: 100%; background: var(--vied-bg-2); border: 1px solid var(--vied-border); border-radius: 8px;
  color: var(--vied-text); padding: 9px 10px; font: inherit; font-size: 13px; resize: vertical;
}
.vied-input:focus { outline: none; border-color: var(--vied-red); }
.vied-grid2 { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }

/* ============================ Timeline multipista ============================ */
.vied-timeline {
  border-top: 1px solid var(--vied-border); background: linear-gradient(180deg, #0c0c11, #08080b);
  padding: 8px 12px 12px; user-select: none;
}
.vied-tl__top { display: flex; align-items: center; gap: 12px; color: var(--vied-muted); font-size: 11px; margin-bottom: 6px; }
.vied-tl__time { font-variant-numeric: tabular-nums; color: var(--vied-text); font-weight: 700; }
.vied-tl__zoom { margin-left: auto; display: flex; align-items: center; gap: 8px; }
.vied-tl__scroll { position: relative; overflow-x: auto; }
.vied-tl__ruler { position: relative; height: 16px; margin-left: 84px; color: var(--vied-faint); font-size: 10px; font-variant-numeric: tabular-nums; min-width: 100%; }
.vied-tl__ruler span { position: absolute; top: 0; transform: translateX(-50%); }
.vied-tl__ruler span::after { content: ""; position: absolute; left: 50%; top: 12px; width: 1px; height: 5px; background: var(--vied-border-2); }
.vied-row { display: flex; align-items: center; gap: 8px; margin-bottom: 5px; }
.vied-row__lbl {
  flex: 0 0 76px; display: flex; align-items: center; gap: 6px; height: 30px; padding: 0 9px;
  font-size: 11px; font-weight: 700; color: var(--vied-muted);
  background: var(--vied-panel); border: 1px solid var(--vied-border); border-radius: 7px;
}
.vied-row__lbl .vied-row__ic { color: var(--vied-red-2); font-size: 12px; }
.vied-track {
  position: relative; flex: 1; height: 30px; min-width: 200px;
  background: var(--vied-bg-2); border: 1px solid var(--vied-border); border-radius: 7px; overflow: hidden;
  background-image: repeating-linear-gradient(90deg, transparent 0 47px, rgba(255,255,255,.03) 47px 48px);
}
.vied-clip {
  position: absolute; top: 3px; bottom: 3px; min-width: 5px; box-sizing: border-box; border-radius: 5px;
  cursor: pointer; border: 1px solid rgba(255,255,255,.18); overflow: hidden;
  box-shadow: 0 1px 2px rgba(0,0,0,.4), inset 0 1px 0 rgba(255,255,255,.14);
  display: flex; align-items: center; padding: 0 6px; font-size: 10px; font-weight: 700; color: #fff;
  white-space: nowrap; transition: transform .08s, filter .08s;
}
.vied-clip:hover { transform: translateY(-1px); filter: brightness(1.12); }
.vied-clip--sub { background: linear-gradient(180deg, #ef4444, #c01f1f); }
.vied-clip--sub.is-active { background: linear-gradient(180deg, #60a5fa, #2563eb); border-color: #93c5fd; z-index: 2; box-shadow: 0 0 0 1px #2563eb, 0 4px 12px rgba(37,99,235,.5); }
.vied-clip--fx { background: linear-gradient(180deg, #a855f7, #7c3aed); }
.vied-clip--emph { background: linear-gradient(180deg, #f59e0b, #d97706); }
.vied-clip--focus { background: linear-gradient(180deg, #14b8a6, #0d9488); }
.vied-clip--img { background: linear-gradient(180deg, #ec4899, #be185d); }
.vied-track--video { display: flex; gap: 0; background: #000; }
.vied-track--video img { height: 100%; flex: 1 1 0; min-width: 0; object-fit: cover; }
.vied-track--audio { background: #08111f; background-image: none; }
.vied-track--audio canvas { display: block; width: 100%; height: 100%; }
.vied-cursor { position: absolute; top: 22px; bottom: 8px; width: 2px; left: 84px; pointer-events: none; z-index: 6; background: var(--vied-red-2); box-shadow: 0 0 8px color-mix(in srgb, var(--vied-red) 80%, transparent); }
.vied-cursor::before { content: ""; position: absolute; top: -6px; left: 50%; transform: translateX(-50%); border-left: 6px solid transparent; border-right: 6px solid transparent; border-top: 8px solid var(--vied-red-2); }

/* mensajes / resultado */
.vied-msg { font-size: 13px; min-height: 18px; }
.vied-msg.is-error { color: var(--vied-red-2); }
.vied-msg.is-ok { color: var(--vied-green); }
.vied-busy { display: inline-block; width: 14px; height: 14px; border: 2px solid rgba(255,255,255,.3); border-top-color: #fff; border-radius: 50%; animation: viedSpin .7s linear infinite; vertical-align: -2px; margin-right: 6px; }
@keyframes viedSpin { to { transform: rotate(360deg); } }
/* modal */
.vied-modal { position: fixed; inset: 0; z-index: 1000; display: grid; place-items: center; padding: 20px; }
.vied-modal[hidden] { display: none; }
.vied-modal__backdrop { position: absolute; inset: 0; background: rgba(0,0,0,.6); backdrop-filter: blur(2px); }
.vied-modal__card { position: relative; width: min(520px, 100%); max-height: 84vh; overflow: hidden; display: flex; flex-direction: column; gap: 12px; background: var(--vied-panel); border: 1px solid var(--vied-border); border-radius: var(--vied-radius); padding: 18px; box-shadow: 0 30px 80px rgba(0,0,0,.5); }
.vied-modal__head { display: flex; align-items: center; justify-content: space-between; }
.vied-modal__head strong { font-size: 1.05rem; }
.vied-modal__segs { display: flex; flex-direction: column; gap: 6px; overflow-y: auto; }
.vied-modal__seg { display: flex; gap: 9px; align-items: flex-start; padding: 9px 10px; border: 1px solid var(--vied-border); border-radius: 8px; background: var(--vied-bg-2); font-size: 12.5px; cursor: pointer; }
.vied-modal__seg input { margin-top: 2px; accent-color: var(--vied-red); }
.vied-modal__seg.is-on { border-color: var(--vied-red); background: var(--vied-red-soft); }
.vied-modal__seg small { color: var(--vied-faint); display: block; font-size: 11px; }

.vied-result video { width: 100%; max-width: 300px; border-radius: 12px; background: #000; }
.vied-cost { color: var(--vied-muted); font-size: 12px; }
.vied-cost strong { color: var(--vied-text); }
