/* ==========================================================================
   JOLLY COURSE STUDIO v2 — Editor con Vista Previa en Vivo
   Identidad Jolly Academy: azul #0084c7 · ámbar #f59e0b
   ========================================================================== */

body.studio-body {
  height: 100vh;
  overflow: hidden;
  background: #eef2f7;
}

/* ---------- Header ---------- */
.cs-header {
  background: #ffffff;
  border-bottom: 1px solid var(--border-color);
  height: 62px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 18px;
  gap: 16px;
  flex-shrink: 0;
  z-index: 50;
}

.cs-header .brand-logo-img { height: 40px; }

.cs-pill {
  background: linear-gradient(135deg, #0284c7, #0369a1);
  color: #fff;
  font-weight: 800;
  font-size: 0.68rem;
  letter-spacing: 0.8px;
  padding: 4px 10px;
  border-radius: 999px;
  text-transform: uppercase;
  box-shadow: var(--shadow-brand);
}

.cs-header-nav {
  display: flex;
  gap: 4px;
  list-style: none;
}

.cs-header-nav a {
  font-size: 0.86rem;
  font-weight: 600;
  color: #475569;
  padding: 7px 12px;
  border-radius: 8px;
}

.cs-header-nav a:hover { background: #f1f5f9; color: var(--primary); }
.cs-header-nav a.active { background: #e0f2fe; color: #0369a1; }

/* ---------- Toolbar ---------- */
.cs-toolbar {
  background: #ffffff;
  border-bottom: 1px solid var(--border-color);
  padding: 10px 18px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 14px;
  flex-wrap: wrap;
  flex-shrink: 0;
}

.cs-toolbar-group {
  display: flex;
  align-items: center;
  gap: 10px;
  flex-wrap: wrap;
}

.cs-course-select {
  min-width: 300px;
  font-weight: 700;
  font-size: 0.95rem;
  padding: 8px 12px;
  border: 2px solid #bae6fd;
  border-radius: 10px;
  background: #f8fbff;
  color: #0f172a;
}

.cs-segmented {
  display: inline-flex;
  background: #f1f5f9;
  border-radius: 10px;
  padding: 3px;
  gap: 2px;
}

.cs-segmented button {
  border: none;
  background: transparent;
  padding: 6px 12px;
  border-radius: 8px;
  font-size: 0.8rem;
  font-weight: 700;
  color: #64748b;
  cursor: pointer;
  transition: var(--transition);
  white-space: nowrap;
}

.cs-segmented button:hover { color: #0369a1; }

.cs-segmented button.active {
  background: #ffffff;
  color: #0369a1;
  box-shadow: 0 1px 3px rgba(15, 23, 42, 0.12);
}

.cs-switch {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  font-size: 0.8rem;
  font-weight: 700;
  color: #475569;
  cursor: pointer;
  user-select: none;
}

.cs-switch input { display: none; }

.cs-switch .track {
  width: 34px;
  height: 20px;
  border-radius: 999px;
  background: #cbd5e1;
  position: relative;
  transition: var(--transition);
}

.cs-switch .track::after {
  content: "";
  position: absolute;
  top: 3px;
  left: 3px;
  width: 14px;
  height: 14px;
  border-radius: 50%;
  background: #fff;
  transition: var(--transition);
  box-shadow: 0 1px 2px rgba(0,0,0,0.2);
}

.cs-switch input:checked + .track { background: #10b981; }
.cs-switch input:checked + .track::after { left: 17px; }

/* ---------- Workspace (3 panes) ---------- */
.cs-workspace {
  --tree-w: 290px;
  --preview-w: 46%;
  flex: 1;
  min-height: 0;
  display: grid;
  grid-template-columns: var(--tree-w) minmax(380px, 1fr) 8px var(--preview-w);
  grid-template-rows: 100%;
}

.cs-workspace.mode-editor { grid-template-columns: var(--tree-w) 1fr 0 0; }
.cs-workspace.mode-preview { grid-template-columns: var(--tree-w) 0 0 1fr; }
.cs-workspace.mode-editor .cs-splitter,
.cs-workspace.mode-editor .cs-preview-pane,
.cs-workspace.mode-preview .cs-splitter,
.cs-workspace.mode-preview .cs-editor-pane { display: none; }

.cs-tree-pane    { grid-column: 1; }
.cs-editor-pane  { grid-column: 2; }
.cs-splitter     { grid-column: 3; }
.cs-preview-pane { grid-column: 4; }

/* ---------- Outline tree ---------- */
.cs-tree-pane {
  background: #ffffff;
  border-right: 1px solid var(--border-color);
  display: flex;
  flex-direction: column;
  min-height: 0;
}

.cs-tree-head {
  padding: 14px 14px 10px 14px;
  border-bottom: 1px solid #f1f5f9;
}

.cs-tree-head h3 {
  font-size: 1rem;
  margin: 0;
}

.cs-tree-stats {
  font-size: 0.74rem;
  color: #64748b;
  font-weight: 600;
}

.cs-tree-search {
  width: 100%;
  margin-top: 10px;
  padding: 7px 10px 7px 30px;
  border: 1px solid #e2e8f0;
  border-radius: 8px;
  font-size: 0.82rem;
  background: #f8fafc url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 20 20' fill='%2394a3b8'%3E%3Cpath fill-rule='evenodd' d='M8 4a4 4 0 100 8 4 4 0 000-8zM2 8a6 6 0 1110.89 3.476l4.817 4.817a1 1 0 01-1.414 1.414l-4.816-4.816A6 6 0 012 8z' clip-rule='evenodd'/%3E%3C/svg%3E") no-repeat 9px center / 14px;
  outline: none;
}

.cs-tree-search:focus { border-color: #7dd3fc; background-color: #fff; }

.cs-tree-body {
  flex: 1;
  overflow-y: auto;
  padding: 10px;
}

.cs-tree-foot {
  padding: 10px;
  border-top: 1px solid #f1f5f9;
}

.cs-module {
  margin-bottom: 8px;
  border-radius: 10px;
  border: 1px solid transparent;
}

.cs-module-head {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 7px 8px;
  border-radius: 8px;
  cursor: pointer;
  user-select: none;
}

.cs-module-head:hover { background: #f8fafc; }

.cs-chevron {
  font-size: 0.7rem;
  color: #94a3b8;
  width: 14px;
  transition: transform 0.2s ease;
  flex-shrink: 0;
}

.cs-module.collapsed .cs-chevron { transform: rotate(-90deg); }
.cs-module.collapsed .cs-lessons { display: none; }

.cs-module-num {
  background: #e0f2fe;
  color: #0369a1;
  font-size: 0.66rem;
  font-weight: 800;
  padding: 2px 6px;
  border-radius: 5px;
  flex-shrink: 0;
}

.cs-module-title {
  font-size: 0.84rem;
  font-weight: 700;
  color: #0f172a;
  flex: 1;
  min-width: 0;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.cs-row-actions {
  display: flex;
  gap: 2px;
  opacity: 0;
  transition: opacity 0.15s ease;
  flex-shrink: 0;
}

.cs-module-head:hover .cs-row-actions,
.cs-lesson:hover .cs-row-actions,
.cs-lesson.is-active .cs-row-actions { opacity: 1; }

.cs-icon-btn {
  border: none;
  background: transparent;
  width: 24px;
  height: 24px;
  border-radius: 6px;
  font-size: 0.78rem;
  cursor: pointer;
  color: #64748b;
  display: inline-flex;
  align-items: center;
  justify-content: center;
}

.cs-icon-btn:hover { background: #e2e8f0; color: #0f172a; }
.cs-icon-btn.danger:hover { background: #fee2e2; color: #dc2626; }

.cs-lessons {
  list-style: none;
  padding: 2px 0 4px 14px;
  margin-left: 6px;
  border-left: 2px solid #f1f5f9;
  min-height: 8px;
}

.cs-lessons.drop-into { background: #f0f9ff; border-left-color: #0284c7; border-radius: 6px; }

.cs-lesson {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 6px 8px;
  border-radius: 8px;
  cursor: pointer;
  position: relative;
  transition: background 0.15s ease;
}

.cs-lesson:hover { background: #f1f5f9; }

.cs-lesson.is-active {
  background: linear-gradient(90deg, #e0f2fe, #f0f9ff);
  box-shadow: inset 3px 0 0 #0284c7;
}

.cs-lesson.is-active .cs-lesson-title { color: #0369a1; font-weight: 700; }
.cs-lesson.dragging { opacity: 0.4; }
.cs-lesson.drop-before::before,
.cs-lesson.drop-after::after {
  content: "";
  position: absolute;
  left: 4px;
  right: 4px;
  height: 3px;
  border-radius: 3px;
  background: #f59e0b;
}
.cs-lesson.drop-before::before { top: -2px; }
.cs-lesson.drop-after::after { bottom: -2px; }

.cs-grip {
  color: #cbd5e1;
  font-size: 0.7rem;
  cursor: grab;
  letter-spacing: -2px;
  flex-shrink: 0;
}

.cs-lesson-icon {
  width: 24px;
  height: 24px;
  border-radius: 6px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 0.74rem;
  flex-shrink: 0;
}

.cs-lesson-text { flex: 1; min-width: 0; }

.cs-lesson-title {
  font-size: 0.82rem;
  color: #334155;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  display: block;
}

.cs-lesson-meta { font-size: 0.68rem; color: #94a3b8; }

.cs-add-lesson {
  border: 1px dashed #cbd5e1;
  background: transparent;
  width: calc(100% - 20px);
  margin: 4px 0 0 20px;
  padding: 5px;
  border-radius: 8px;
  font-size: 0.75rem;
  font-weight: 700;
  color: #0284c7;
  cursor: pointer;
}

.cs-add-lesson:hover { background: #f0f9ff; border-color: #7dd3fc; }

.tree-rename-input {
  flex: 1;
  min-width: 0;
  font-size: 0.84rem;
  font-weight: 700;
  padding: 3px 6px;
  border: 2px solid #0284c7;
  border-radius: 6px;
  outline: none;
}

/* ---------- Editor pane ---------- */
.cs-editor-pane {
  overflow-y: auto;
  min-height: 0;
  padding: 18px 22px 40px 22px;
}

.cs-editor-card {
  background: #ffffff;
  border: 1px solid var(--border-color);
  border-radius: 16px;
  box-shadow: var(--shadow-sm);
  padding: 20px 22px;
}

.cs-lesson-head {
  display: flex;
  flex-wrap: wrap;
  gap: 12px;
  align-items: flex-end;
  padding-bottom: 16px;
  margin-bottom: 14px;
  border-bottom: 1px solid #f1f5f9;
}

.cs-title-input {
  width: 100%;
  border: 2px solid transparent;
  background: #f8fafc;
  border-radius: 10px;
  padding: 8px 12px;
  font-family: 'Baloo 2', 'Plus Jakarta Sans', sans-serif;
  font-size: 1.45rem;
  font-weight: 800;
  color: #0f172a;
  outline: none;
  transition: var(--transition);
}

.cs-title-input:hover { background: #f1f5f9; }
.cs-title-input:focus { border-color: #7dd3fc; background: #fff; }

.cs-breadcrumb {
  display: flex;
  gap: 6px;
  align-items: center;
  margin-bottom: 6px;
  flex-wrap: wrap;
}

.cs-chip {
  font-size: 0.7rem;
  font-weight: 800;
  padding: 3px 8px;
  border-radius: 5px;
}

/* Lesson type picker (visual) */
.cs-type-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(118px, 1fr));
  gap: 8px;
  margin-bottom: 16px;
}

.cs-type-card {
  border: 2px solid #e2e8f0;
  background: #fff;
  border-radius: 10px;
  padding: 8px 10px;
  cursor: pointer;
  text-align: left;
  transition: var(--transition);
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 0.76rem;
  font-weight: 700;
  color: #334155;
}

.cs-type-card:hover { border-color: #7dd3fc; transform: translateY(-1px); }
.cs-type-card.active {
  border-color: #0284c7;
  background: #f0f9ff;
  color: #0369a1;
  box-shadow: 0 0 0 3px rgba(2, 132, 199, 0.12);
}
.cs-type-card .ico { font-size: 1rem; }

.cs-editor-foot {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 10px;
  flex-wrap: wrap;
  margin-top: 22px;
  padding-top: 16px;
  border-top: 1px solid #f1f5f9;
}

.cs-kbd {
  font-family: 'JetBrains Mono', monospace;
  font-size: 0.7rem;
  background: #f1f5f9;
  border: 1px solid #e2e8f0;
  border-bottom-width: 2px;
  border-radius: 4px;
  padding: 1px 5px;
  color: #475569;
}

/* ---------- Splitter ---------- */
.cs-splitter {
  cursor: col-resize;
  background: #e2e8f0;
  position: relative;
  transition: background 0.15s ease;
}

.cs-splitter::after {
  content: "";
  position: absolute;
  top: 50%;
  left: 50%;
  width: 2px;
  height: 36px;
  transform: translate(-50%, -50%);
  border-left: 2px dotted #94a3b8;
}

.cs-splitter:hover,
.cs-workspace.is-resizing .cs-splitter { background: #7dd3fc; }
.cs-workspace.is-resizing { cursor: col-resize; user-select: none; }
.cs-workspace.is-resizing iframe { pointer-events: none; }

/* ---------- Preview pane ---------- */
.cs-preview-pane {
  display: flex;
  flex-direction: column;
  min-height: 0;
  background: #e2e8f0;
}

.cs-preview-bar {
  background: #0f172a;
  color: #e2e8f0;
  padding: 8px 12px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  flex-shrink: 0;
}

.cs-live {
  display: inline-flex;
  align-items: center;
  gap: 7px;
  font-size: 0.74rem;
  font-weight: 800;
  letter-spacing: 0.6px;
  text-transform: uppercase;
  color: #6ee7b7;
}

.cs-live .dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: #10b981;
  box-shadow: 0 0 0 0 rgba(16, 185, 129, 0.7);
  animation: csLivePulse 1.8s infinite;
}

.cs-live.updating { color: #fcd34d; }
.cs-live.updating .dot { background: #f59e0b; animation-duration: 0.6s; }

@keyframes csLivePulse {
  0%   { box-shadow: 0 0 0 0 rgba(16, 185, 129, 0.6); }
  70%  { box-shadow: 0 0 0 8px rgba(16, 185, 129, 0); }
  100% { box-shadow: 0 0 0 0 rgba(16, 185, 129, 0); }
}

.cs-preview-bar .cs-segmented { background: #1e293b; }
.cs-preview-bar .cs-segmented button { color: #94a3b8; padding: 4px 9px; }
.cs-preview-bar .cs-segmented button.active { background: #334155; color: #fff; box-shadow: none; }

.cs-dark-btn {
  border: 1px solid #334155;
  background: #1e293b;
  color: #cbd5e1;
  border-radius: 7px;
  padding: 4px 9px;
  font-size: 0.76rem;
  font-weight: 700;
  cursor: pointer;
}

.cs-dark-btn:hover { background: #334155; color: #fff; }

.cs-zoom {
  font-family: 'JetBrains Mono', monospace;
  font-size: 0.7rem;
  color: #64748b;
  min-width: 36px;
  text-align: right;
}

.cs-preview-stage {
  flex: 1;
  min-height: 0;
  overflow: hidden;
  padding: 16px;
  display: flex;
  justify-content: center;
  align-items: flex-start;
  background:
    radial-gradient(circle at 1px 1px, #cbd5e1 1px, transparent 0) 0 0 / 18px 18px,
    #e8edf3;
}

.cs-device {
  background: #ffffff;
  border-radius: 12px;
  box-shadow: 0 25px 50px -12px rgba(15, 23, 42, 0.35);
  overflow: hidden;
  position: relative;
  transition: width 0.25s ease;
}

.cs-device.is-mobile { border-radius: 26px; border: 8px solid #0f172a; }
.cs-device.is-tablet { border-radius: 18px; border: 8px solid #1e293b; }

.cs-device iframe {
  border: none;
  display: block;
  transform-origin: 0 0;
  background: #f8fafc;
}

/* ---------- Responsive ---------- */
@media (max-width: 1100px) {
  body.studio-body { height: auto; overflow: auto; }
  .cs-workspace,
  .cs-workspace.mode-editor,
  .cs-workspace.mode-preview {
    grid-template-columns: 1fr;
    grid-template-rows: auto;
  }
  .cs-tree-pane, .cs-editor-pane, .cs-preview-pane { grid-column: 1; }
  .cs-tree-body { max-height: 320px; }
  .cs-splitter { display: none; }
  .cs-preview-pane { height: 80vh; }
  .cs-header-nav { display: none; }
}
