@import url('https://fonts.googleapis.com/css2?family=Plus+Jakarta+Sans:wght@400;500;700;800&display=swap');

:root,
:root[data-theme="dark"] {
  --bg: #0B0F19;
  --card: #12172a;
  --border: #232a42;
  --text: #f5f5f7;
  --muted: #8b8fa3;
  --indigo: #4F46E5;
  --purple: #A855F7;
  --input-bg: #0d1220;
  --hover-overlay: rgba(255, 255, 255, 0.04);
  --status-error: #f87171;
  --status-success: #86efac;
  --badge-app-bg: rgba(79, 70, 229, 0.2);
  --badge-app-text: #a5b4fc;
  --badge-ig-bg: rgba(168, 85, 247, 0.2);
  --badge-ig-text: #d8b4fe;
  --badge-manual-bg: rgba(255, 255, 255, 0.08);
}

/* Modo claro — minimalista y blanco, no solo un degradado de marca sobre fondo
   oscuro. Especificidad [data-theme="light"] > :root plano, así siempre gana
   incluso sobre el <style> con --bg de marca que el servidor inyecta por cliente. */
:root[data-theme="light"] {
  --bg: #ffffff;
  --card: #f7f7f9;
  --border: #e4e4e8;
  --text: #14161f;
  --muted: #6b7280;
  --input-bg: #ffffff;
  --hover-overlay: rgba(0, 0, 0, 0.04);
  --status-error: #dc2626;
  --status-success: #16a34a;
  --badge-app-bg: rgba(79, 70, 229, 0.12);
  --badge-app-text: #4338ca;
  --badge-ig-bg: rgba(168, 85, 247, 0.12);
  --badge-ig-text: #7e22ce;
  --badge-manual-bg: rgba(0, 0, 0, 0.05);
}

* { box-sizing: border-box; }

body {
  margin: 0;
  font-family: 'Plus Jakarta Sans', sans-serif;
  background: var(--bg);
  color: var(--text);
  min-height: 100vh;
}

.layout {
  min-height: 100vh;
  padding-left: 220px; /* espacio reservado para el sidebar, que ahora es fixed */
}

/* Fijo al viewport (no a la altura del contenido) — si no, cuando una vista es
   muy larga, flexbox estira el sidebar a esa misma altura y el hueco antes del
   footer (créditos/tema/usuario) se alarga muchísimo. Con position:fixed el
   sidebar siempre mide exactamente 100vh sin importar cuánto contenido tenga
   la vista activa. */
.sidebar {
  position: fixed;
  top: 0;
  left: 0;
  width: 220px;
  height: 100vh;
  overflow-y: auto;
  background: var(--card);
  border-right: 1px solid var(--border);
  padding: 28px 16px;
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.nav-item {
  margin-top: 0;
  background: transparent;
  color: var(--muted);
  border: none;
  border-radius: 10px;
  padding: 12px 14px;
  text-align: left;
  font-size: 15px;
  font-weight: 600;
  cursor: pointer;
}

.nav-item:hover { background: var(--hover-overlay); color: var(--text); }

.nav-item.active {
  background: linear-gradient(135deg, rgba(79, 70, 229, 0.25) 0%, rgba(168, 85, 247, 0.25) 100%);
  color: var(--text);
}

.sidebar-footer {
  margin-top: auto;
  padding: 14px 14px 0;
  border-top: 1px solid var(--border);
}

.user-info {
  font-size: 13px;
  font-weight: 600;
  margin-bottom: 8px;
}

.user-info .role-badge {
  display: block;
  font-size: 11px;
  font-weight: 500;
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: 0.05em;
}

.logout-link {
  margin: 0;
  padding: 0;
  background: none;
  border: none;
  color: var(--muted);
  font-size: 12px;
  font-weight: 600;
  cursor: pointer;
  text-decoration: underline;
}

.logout-link:hover { color: var(--text); }

.theme-toggle {
  width: 100%;
  margin: 0 0 12px;
  padding: 10px 14px;
  background: var(--input-bg);
  border: 1px solid var(--border);
  border-radius: 10px;
  color: var(--text);
  font-size: 13px;
  font-weight: 600;
  cursor: pointer;
  text-align: left;
}

.theme-toggle:hover { border-color: var(--indigo); }

.credits-indicator {
  font-size: 12px;
  font-weight: 600;
  margin-bottom: 10px;
  padding: 0 2px;
}

.credits-indicator.low { color: var(--status-error); }

.chip-row {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-bottom: 16px;
}

.content {
  max-width: 960px;
  margin: 0 auto;
  padding: 48px 24px 80px;
  width: 100%;
}

.view.hidden { display: none; }

.logo {
  font-size: 20px;
  font-weight: 800;
  margin-bottom: 24px;
  padding: 0 14px;
}

.grad {
  background: linear-gradient(135deg, var(--indigo) 0%, var(--purple) 100%);
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
}

.tag {
  font-size: 12px;
  text-transform: uppercase;
  letter-spacing: 0.15em;
  color: var(--muted);
  font-weight: 600;
}

.card {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: 20px;
  padding: 28px;
  margin-bottom: 24px;
}

label {
  display: block;
  font-size: 14px;
  font-weight: 600;
  margin-bottom: 8px;
}

.muted { color: var(--muted); font-weight: 400; }

textarea, input[type="text"], input[type="password"] {
  width: 100%;
  background: var(--input-bg);
  border: 1px solid var(--border);
  border-radius: 12px;
  color: var(--text);
  font-family: inherit;
  font-size: 15px;
  padding: 14px;
  resize: vertical;
  margin-bottom: 16px;
}

.section-title {
  margin: 0 0 16px;
  font-size: 15px;
}

select {
  width: 100%;
  background: var(--input-bg);
  border: 1px solid var(--border);
  border-radius: 12px;
  color: var(--text);
  font-family: inherit;
  font-size: 15px;
  padding: 14px;
  margin-bottom: 16px;
}

.list-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 12px;
  padding: 10px 0;
  border-bottom: 1px solid var(--border);
  font-size: 14px;
}

.list-row:last-child { border-bottom: none; }
.list-row .meta { color: var(--muted); font-size: 12px; }

.badge {
  display: inline-block;
  font-size: 11px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  padding: 2px 8px;
  border-radius: 999px;
  margin-right: 6px;
}

.badge.app { background: var(--badge-app-bg); color: var(--badge-app-text); }
.badge.manual { background: var(--badge-manual-bg); color: var(--muted); }
.badge.instagram { background: var(--badge-ig-bg); color: var(--badge-ig-text); }
.badge.facebook { background: var(--badge-app-bg); color: var(--badge-app-text); }

.agg-row {
  padding: 14px 0;
  border-bottom: 1px solid var(--border);
}
.agg-row:last-child { border-bottom: none; }

.agg-label {
  display: flex;
  justify-content: space-between;
  font-size: 13px;
  margin-bottom: 6px;
}

.agg-bar-track {
  background: var(--input-bg);
  border-radius: 8px;
  height: 8px;
  overflow: hidden;
}

.agg-bar-fill {
  height: 100%;
  background: linear-gradient(90deg, var(--indigo), var(--purple));
  border-radius: 8px;
}

.carousel-toggle-row {
  display: flex;
  align-items: center;
  gap: 12px;
  margin: 4px 0 16px;
  flex-wrap: wrap;
}
.carousel-toggle {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 14px;
  font-weight: 500;
  cursor: pointer;
  margin: 0;
}
.carousel-toggle input { accent-color: var(--indigo); }
#carouselSlideCount { width: auto; margin: 0; padding: 8px 12px; font-size: 13px; }

.filter-bar {
  display: flex;
  flex-wrap: wrap;
  gap: 20px;
}

.filter-group {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
}

.filter-label { font-size: 13px; }

.filter-chip {
  margin: 0;
  padding: 6px 14px;
  border-radius: 999px;
  border: 1px solid var(--border);
  background: transparent;
  color: var(--muted);
  font-size: 13px;
  font-weight: 600;
  cursor: pointer;
}

.filter-chip.active {
  background: linear-gradient(135deg, var(--indigo) 0%, var(--purple) 100%);
  color: white;
  border-color: transparent;
}

.boost-link {
  margin: 0 0 0 10px;
  padding: 3px 10px;
  border-radius: 999px;
  border: 1px solid var(--border);
  background: transparent;
  color: var(--text);
  font-size: 11px;
  font-weight: 700;
  cursor: pointer;
}

.boost-link:hover { border-color: var(--purple); }

textarea:focus, button:focus {
  outline: 2px solid var(--indigo);
  outline-offset: 1px;
}

button {
  margin-top: 16px;
  border: none;
  border-radius: 12px;
  padding: 14px 22px;
  font-family: inherit;
  font-size: 15px;
  font-weight: 700;
  cursor: pointer;
  background: linear-gradient(135deg, var(--indigo) 0%, var(--purple) 100%);
  color: white;
}

button:disabled {
  opacity: 0.5;
  cursor: not-allowed;
}

button.secondary {
  background: transparent;
  border: 1px solid var(--border);
  color: var(--text);
}

.status {
  margin-top: 12px;
  font-size: 14px;
  color: var(--muted);
  white-space: pre-wrap;
}

.status.error { color: var(--status-error); }
.status.success { color: var(--status-success); }

.hidden { display: none !important; }

.preview-grid {
  display: grid;
  grid-template-columns: minmax(0, 320px) 1fr;
  gap: 28px;
}

#previewVideo {
  width: 100%;
  border-radius: 14px;
  border: 1px solid var(--border);
  aspect-ratio: 1080 / 1350;
  object-fit: cover;
}

/* ---------- Mockup de vista previa (Instagram / Facebook) ----------
   Siempre con la estética real de cada red (tarjeta blanca, tipografía y
   colores propios) independiente del tema claro/oscuro del panel — igual
   criterio que el login, para que se vea creíble como si fuera la app real. */
.post-mockup { display: flex; flex-direction: column; gap: 10px; }

.mockup-tabs { display: flex; gap: 8px; }
.mockup-tab {
  flex: 1;
  padding: 8px 10px;
  border-radius: 10px;
  border: 1px solid var(--border);
  background: var(--input-bg);
  color: var(--muted);
  font-family: inherit;
  font-size: 13px;
  font-weight: 700;
  cursor: pointer;
}
.mockup-tab.active {
  background: linear-gradient(135deg, var(--indigo) 0%, var(--purple) 100%);
  color: white;
  border-color: transparent;
}

.mockup-frame {
  background: #ffffff;
  color: #14161f;
  border: 1px solid #dbdbdb;
  border-radius: 12px;
  overflow: hidden;
  font-family: -apple-system, 'Segoe UI', Roboto, sans-serif;
}

.mockup-avatar {
  width: 34px;
  height: 34px;
  border-radius: 50%;
  background: linear-gradient(135deg, var(--indigo) 0%, var(--purple) 100%);
  color: white;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 14px;
  font-weight: 800;
  flex-shrink: 0;
}

/* Contenedor de la imagen — cuando es un carrusel, guarda varias <img> apiladas
   (una visible a la vez vía .active) más flechas y puntos de navegación; en un
   post normal solo tiene la única imagen ya existente, sin flechas/puntos. */
.mockup-slider {
  position: relative;
  width: 100%;
  aspect-ratio: 1080 / 1350;
  overflow: hidden;
}
.mockup-slider img {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  object-fit: cover;
  display: block;
  margin: 0;
  border: none;
  border-radius: 0;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.25s ease;
}
.mockup-slider img.active { opacity: 1; pointer-events: auto; cursor: zoom-in; }

/* Fondo blanco sólido + sombra en vez de negro translúcido — sobre diseños
   oscuros (el caso más común) un círculo negro semi-transparente casi no se
   distinguía del fondo de la imagen. */
.slider-arrow {
  position: absolute;
  top: 50%;
  transform: translateY(-50%);
  z-index: 3;
  width: 36px;
  height: 36px;
  border-radius: 50%;
  border: none;
  background: rgba(255, 255, 255, 0.92);
  color: #14161f;
  box-shadow: 0 2px 10px rgba(0, 0, 0, 0.4);
  font-size: 20px;
  font-weight: 800;
  line-height: 1;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 0;
}
.slider-arrow:hover { background: #ffffff; transform: translateY(-50%) scale(1.08); }
.slider-arrow.slider-prev { left: 10px; }
.slider-arrow.slider-next { right: 10px; }

.slider-dots {
  position: absolute;
  bottom: 10px;
  left: 0;
  right: 0;
  z-index: 3;
  display: flex;
  justify-content: center;
  gap: 6px;
}
.slider-dots .dot {
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: rgba(255, 255, 255, 0.55);
  border: none;
  padding: 0;
  cursor: pointer;
}
.slider-dots .dot.active { background: #ffffff; }

/* Vista ampliada al hacer clic en la imagen del mockup — un overlay simple,
   sin nombre "modal" a secas para no repetir el choque de CSS que ya tuvimos
   con .avatar-modal vs .modal en otra parte del panel. */
.image-lightbox {
  position: fixed;
  inset: 0;
  z-index: 999;
  background: rgba(0, 0, 0, 0.85);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 40px;
  cursor: zoom-out;
}
.image-lightbox img {
  max-width: 90vw;
  max-height: 90vh;
  border-radius: 12px;
  box-shadow: 0 20px 60px rgba(0, 0, 0, 0.5);
}

/* Pantalla completa gris mientras se genera — un esqueleto animado con la
   forma de un post (avatar + imagen + líneas de texto) en vez de un spinner
   genérico, para que no se "pierda la idea" de qué se está armando. */
.generate-overlay {
  position: fixed;
  inset: 0;
  z-index: 998;
  background: rgba(11, 15, 25, 0.82);
  backdrop-filter: blur(3px);
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 22px;
  padding: 24px;
}
.generate-overlay-card {
  width: 100%;
  max-width: 280px;
  background: #ffffff;
  border-radius: 16px;
  padding: 16px;
  box-shadow: 0 20px 60px rgba(0, 0, 0, 0.45);
  display: flex;
  flex-direction: column;
  gap: 12px;
}
.skeleton-header { display: flex; align-items: center; gap: 10px; }
.skeleton {
  background: linear-gradient(90deg, #e4e4e8 25%, #f2f2f5 37%, #e4e4e8 63%);
  background-size: 400% 100%;
  animation: skeleton-shimmer 1.4s ease infinite;
  border-radius: 8px;
}
.skeleton-avatar { width: 36px; height: 36px; border-radius: 50%; flex-shrink: 0; }
.skeleton-line { height: 12px; border-radius: 6px; }
.skeleton-image { width: 100%; aspect-ratio: 1080 / 1350; border-radius: 10px; }
@keyframes skeleton-shimmer {
  0% { background-position: 100% 50%; }
  100% { background-position: 0 50%; }
}
.generate-overlay-text {
  color: #ffffff;
  font-size: 15px;
  font-weight: 600;
  text-align: center;
  max-width: 320px;
  margin: 0;
}

/* -- Instagram -- */
.ig-header { display: flex; align-items: center; gap: 10px; padding: 10px 12px; }
.ig-header-text { flex: 1; min-width: 0; }
.ig-username { font-size: 13px; font-weight: 700; color: #14161f; }
.ig-more { color: #262626; font-weight: 700; padding: 0 4px; }
.ig-icons { display: flex; align-items: center; gap: 14px; padding: 10px 12px 4px; font-size: 20px; }
.ig-icons .ig-bookmark { margin-left: auto; font-size: 17px; }
.ig-likes { padding: 4px 12px 4px; font-size: 13px; font-weight: 700; }
.ig-caption {
  padding: 0 12px 4px;
  font-size: 13px;
  line-height: 1.4;
  word-break: break-word;
}
.ig-caption b { margin-right: 4px; }
.ig-comments { padding: 2px 12px 12px; font-size: 12.5px; color: #8e8e8e; }

/* -- Facebook -- */
.fb-header { display: flex; align-items: center; gap: 10px; padding: 12px; }
.fb-header-text { flex: 1; min-width: 0; display: flex; flex-direction: column; }
.fb-username { font-size: 14px; font-weight: 700; color: #050505; }
.fb-timestamp { font-size: 12px; color: #65676b; }
.fb-more { color: #65676b; font-weight: 700; padding: 0 4px; }
.fb-caption {
  padding: 0 12px 10px;
  font-size: 14px;
  line-height: 1.4;
  color: #050505;
  word-break: break-word;
}

/* Recorte "Ver más" — puramente visual (no despliega nada al hacer clic),
   solo para que el mockup no muestre el caption completo sin cortar. */
.caption-see-more { color: #65676b; font-weight: 700; }
.fb-reactions {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 8px 12px;
  font-size: 12px;
  color: #65676b;
  border-bottom: 1px solid #ced0d4;
  white-space: nowrap;
}
.fb-reaction-icons { font-size: 13px; flex-shrink: 0; }
.fb-reaction-count { flex-shrink: 0; }
.fb-comments-count { margin-left: auto; overflow: hidden; text-overflow: ellipsis; }
.fb-action-row { display: flex; }
.fb-action-row span {
  flex: 1;
  text-align: center;
  padding: 8px 0;
  font-size: 13px;
  font-weight: 600;
  color: #65676b;
}

.preview-side {
  display: flex;
  flex-direction: column;
}

.preview-side textarea {
  flex: 1;
}

.actions {
  display: flex;
  gap: 12px;
  flex-wrap: wrap;
}

@media (max-width: 720px) {
  .preview-grid {
    grid-template-columns: 1fr;
  }
}

/* Video con presentador IA (HeyGen) — vertical 9:16, distinto del post 4:5 */
#previewAvatarVideo {
  width: 100%;
  border-radius: 14px;
  border: 1px solid var(--border);
  aspect-ratio: 9 / 16;
  object-fit: cover;
  background: #000;
}

/* Selector de avatar en Configuración */
.avatar-picker-current {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 10px 0;
}

.avatar-picker-current img {
  width: 56px;
  height: 56px;
  border-radius: 10px;
  object-fit: cover;
  border: 1px solid var(--border);
}

/* Prefijo avatar- para no chocar con .modal/.modal-content ya usados por el
   modal del calendario (ese usa .modal-backdrop como overlay) — esa colisión
   de nombres hacía que este modal se viera siempre, sin importar .hidden,
   porque esta regla .modal quedaba después en la cascada y ganaba el empate. */
.avatar-modal {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.6);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 100;
}

.avatar-modal.hidden { display: none; }

.avatar-modal-content {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: 16px;
  padding: 24px;
  width: min(900px, 92vw);
  max-height: 85vh;
  display: flex;
  flex-direction: column;
  gap: 16px;
}

.avatar-modal-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.avatar-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(120px, 1fr));
  gap: 12px;
  overflow-y: auto;
  padding-right: 4px;
}

.avatar-card {
  cursor: pointer;
  border: 2px solid var(--border);
  border-radius: 12px;
  padding: 8px;
  text-align: center;
  background: rgba(255, 255, 255, 0.02);
  transition: border-color 0.15s ease;
}

.avatar-card:hover {
  border-color: #4F46E5;
}

.avatar-card img {
  width: 100%;
  aspect-ratio: 1 / 1;
  object-fit: cover;
  border-radius: 8px;
  margin-bottom: 6px;
  background: #fff;
}

.avatar-card span {
  font-size: 12px;
  color: var(--muted);
}

/* Calendario */
.calendar-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 20px;
}

.calendar-header h2 {
  margin: 0;
  font-size: 18px;
  text-transform: capitalize;
}

button.small {
  margin-top: 0;
  padding: 8px 14px;
}

.calendar-grid {
  display: grid;
  grid-template-columns: repeat(7, 1fr);
  gap: 6px;
}

.calendar-weekday {
  text-align: center;
  font-size: 12px;
  font-weight: 700;
  color: var(--muted);
  padding-bottom: 6px;
}

.calendar-day {
  min-height: 84px;
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 8px;
  cursor: pointer;
  background: var(--input-bg);
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.calendar-day:hover { border-color: var(--indigo); }
.calendar-day.other-month { opacity: 0.35; }
.calendar-day.today { border-color: var(--purple); }

.calendar-day-number {
  font-size: 13px;
  font-weight: 700;
}

.calendar-event {
  font-size: 11px;
  border-radius: 6px;
  padding: 2px 6px;
  color: white;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.calendar-event.pending { background: #6366f1; }
.calendar-event.running { background: #a855f7; }
.calendar-event.done { background: #16a34a; }
.calendar-event.failed { background: #dc2626; }

/* Modal */
.modal-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.6);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 20px;
  z-index: 10;
}

.modal-backdrop.hidden { display: none; }

.modal {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: 16px;
  padding: 24px;
  width: 100%;
  max-width: 440px;
  max-height: 90vh;
  overflow-y: auto;
}

.modal h3 { margin-top: 0; }

input[type="time"] {
  width: 100%;
  background: var(--input-bg);
  border: 1px solid var(--border);
  border-radius: 12px;
  color: var(--text);
  font-family: inherit;
  font-size: 15px;
  padding: 12px 14px;
  margin-bottom: 16px;
}

.day-events {
  margin-top: 20px;
  border-top: 1px solid var(--border);
  padding-top: 16px;
}

.day-events h4 { margin: 0 0 10px; font-size: 13px; color: var(--muted); }

.day-event-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 8px;
  padding: 8px 0;
  border-bottom: 1px solid var(--border);
  font-size: 13px;
}

.day-event-row:last-child { border-bottom: none; }

.cancel-link {
  color: var(--status-error);
  cursor: pointer;
  font-size: 12px;
  font-weight: 600;
  background: none;
  border: none;
  margin: 0;
  padding: 0;
}
