/* ===========================================================================
   styles.css — Python de a poco
   Paleta inspirada en los colores oficiales de Python (azul/amarillo) sobre
   un fondo oscuro cómodo para programar.
   =========================================================================== */

:root {
  --bg: #0f1117;
  --bg-soft: #171a23;
  --bg-card: #1c2030;
  --border: #2a3040;
  --text: #e6e9f0;
  --text-dim: #9aa3b6;
  --py-blue: #4b8bbe;
  --py-blue-light: #5fa8e0;
  --py-yellow: #ffd43b;
  --green: #3fb950;
  --green-soft: #1f3a26;
  --red: #f85149;
  --red-soft: #3a1f1f;
  --radius: 10px;
  --font: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  --mono: "SF Mono", "Fira Code", "JetBrains Mono", Consolas, Menlo, monospace;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  font-family: var(--font);
  background: var(--bg);
  color: var(--text);
  line-height: 1.55;
}

/* ---------- Topbar ---------- */
.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 14px 24px;
  background: var(--bg-soft);
  border-bottom: 1px solid var(--border);
  gap: 16px;
  flex-wrap: wrap;
}
.brand { display: flex; align-items: center; gap: 12px; }
.logo { font-size: 32px; }
.topbar h1 { margin: 0; font-size: 20px; letter-spacing: -0.3px; }
.subtitle { margin: 0; font-size: 13px; color: var(--text-dim); }

.progress-global { display: flex; align-items: center; gap: 10px; min-width: 200px; }
.progress-global .bar {
  flex: 1; height: 8px; background: var(--bg-card);
  border-radius: 99px; overflow: hidden; min-width: 120px;
}
.progress-global .bar-fill {
  height: 100%; width: 0%;
  background: linear-gradient(90deg, var(--py-blue), var(--py-yellow));
  transition: width .4s ease;
}
#progresoTexto { font-size: 13px; color: var(--text-dim); white-space: nowrap; }

.topbar-right { display: flex; align-items: center; gap: 18px; flex-wrap: wrap; }

/* ---------- Auth area (topbar) ---------- */
.auth-area { display: flex; align-items: center; }
.btn-sm { padding: 6px 14px; font-size: 13px; }
.user-chip {
  display: flex; align-items: center; gap: 10px;
  background: var(--bg-card); border: 1px solid var(--border);
  padding: 5px 8px 5px 12px; border-radius: 99px;
}
.user-email { font-size: 13px; color: var(--text); max-width: 180px;
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

/* ---------- Modal ---------- */
.modal-overlay {
  position: fixed; inset: 0; background: rgba(5, 7, 12, .72);
  display: flex; align-items: center; justify-content: center; z-index: 200;
  backdrop-filter: blur(3px);
}
.modal {
  position: relative; background: var(--bg-card); border: 1px solid var(--border);
  border-radius: 14px; padding: 28px 28px 22px; width: 380px; max-width: calc(100vw - 32px);
  box-shadow: 0 24px 60px rgba(0,0,0,.5);
}
.modal h2 { margin: 0 0 4px; font-size: 22px; }
.modal-sub { margin: 0 0 18px; color: var(--text-dim); font-size: 14px; }
.modal-close {
  position: absolute; top: 14px; right: 14px; background: none; border: none;
  color: var(--text-dim); font-size: 18px; cursor: pointer; line-height: 1;
}
.modal-close:hover { color: var(--text); }
.modal form label {
  display: block; font-size: 13px; color: var(--text-dim); margin-bottom: 12px;
}
.modal form input {
  display: block; width: 100%; margin-top: 5px; padding: 10px 12px;
  background: #0c0e14; border: 1px solid var(--border); border-radius: 8px;
  color: var(--text); font-size: 14px; font-family: var(--font);
}
.modal form input:focus { outline: none; border-color: var(--py-blue); }
.btn-block { width: 100%; margin-top: 6px; }
.auth-error {
  color: var(--red); font-size: 13px; margin: 0 0 10px;
  background: var(--red-soft); padding: 8px 12px; border-radius: 8px;
}
.auth-toggle, .auth-skip { text-align: center; font-size: 13px; color: var(--text-dim); margin: 14px 0 0; }
.auth-skip { margin-top: 8px; }
.auth-toggle a, .auth-skip a { color: var(--py-blue-light); text-decoration: none; }
.auth-toggle a:hover, .auth-skip a:hover { text-decoration: underline; }

/* ---------- Layout ---------- */
.layout {
  display: grid;
  grid-template-columns: 290px 1fr;
  min-height: calc(100vh - 64px);
}

/* ---------- Sidebar ---------- */
.sidebar {
  background: var(--bg-soft);
  border-right: 1px solid var(--border);
  padding: 16px 12px;
  overflow-y: auto;
}
.modulo { margin-bottom: 20px; }
.modulo-header {
  display: flex; align-items: center; gap: 8px;
  font-size: 14px; font-weight: 700; text-transform: uppercase;
  letter-spacing: .5px; color: var(--text-dim);
  padding: 6px 8px;
}
.modulo-header .emoji { font-size: 18px; }
.modulo-progress { margin-left: auto; font-size: 11px; }

.ej-item {
  display: flex; align-items: center; gap: 10px;
  padding: 9px 10px; border-radius: 8px; cursor: pointer;
  font-size: 14px; color: var(--text); transition: background .15s;
  border: 1px solid transparent;
}
.ej-item:hover { background: var(--bg-card); }
.ej-item.activo { background: var(--bg-card); border-color: var(--py-blue); }
.ej-item.bloqueado { opacity: .45; cursor: not-allowed; }
.ej-item .estado { font-size: 15px; width: 18px; text-align: center; }
.ej-item .nombre { flex: 1; }
.ej-item .nivel-dots { font-size: 10px; color: var(--py-yellow); letter-spacing: -1px; }

/* ---------- Workspace ---------- */
.workspace { padding: 24px 28px; overflow-y: auto; max-width: 920px; }
.hidden { display: none !important; }

.welcome { max-width: 640px; }
.welcome h2 { margin-top: 0; }
.welcome-list { list-style: none; padding: 0; }
.welcome-list li {
  padding: 10px 14px; background: var(--bg-card);
  border-radius: 8px; margin-bottom: 8px; border: 1px solid var(--border);
}
.loading-note {
  margin-top: 20px; padding: 10px 14px; border-radius: 8px;
  background: var(--green-soft); color: var(--text); font-size: 14px;
  border: 1px solid var(--border);
}

/* ---------- Exercise ---------- */
.exercise-header { margin-bottom: 16px; }
.exercise-header h2 { margin: 8px 0 0; font-size: 24px; }
.badge {
  display: inline-block; font-size: 12px; font-weight: 600;
  padding: 3px 10px; border-radius: 99px; background: var(--bg-card);
  border: 1px solid var(--border); color: var(--text-dim); margin-right: 6px;
}
.badge.nivel { color: var(--py-yellow); border-color: #3a3520; }

.statement {
  background: var(--bg-card); border: 1px solid var(--border);
  border-radius: var(--radius); padding: 16px 20px; margin-bottom: 12px;
}
.statement p:first-child { margin-top: 0; }
.statement p:last-child { margin-bottom: 0; }
.statement code, .hint-text code {
  background: #0c0e14; padding: 1px 6px; border-radius: 5px;
  font-family: var(--mono); font-size: 13px; color: var(--py-yellow);
}
.statement pre {
  background: #0c0e14; padding: 12px 14px; border-radius: 8px;
  overflow-x: auto; border: 1px solid var(--border);
}
.statement pre code { background: none; color: var(--py-blue-light); padding: 0; }

.hint { margin-bottom: 18px; }
.hint summary {
  cursor: pointer; font-size: 14px; color: var(--py-yellow);
  user-select: none; padding: 6px 0;
}
.hint p { margin: 6px 0 0; color: var(--text-dim); font-size: 14px; }

/* ---------- Editor ---------- */
.editor-zone {
  border: 1px solid var(--border); border-radius: var(--radius);
  overflow: hidden; margin-bottom: 18px;
}
.editor-toolbar {
  display: flex; align-items: center; justify-content: space-between;
  background: var(--bg-soft); padding: 8px 14px; font-size: 13px;
  color: var(--text-dim); font-family: var(--mono);
  border-bottom: 1px solid var(--border);
}
.btn-mini {
  background: none; border: 1px solid var(--border); color: var(--text-dim);
  padding: 3px 10px; border-radius: 6px; cursor: pointer; font-size: 12px;
}
.btn-mini:hover { color: var(--text); border-color: var(--py-blue); }

.CodeMirror {
  height: auto; min-height: 180px; font-family: var(--mono) !important;
  font-size: 14px; line-height: 1.6;
}
.CodeMirror-scroll { min-height: 180px; }

/* Columna de números de línea (gutter): ancho propio + separación del código */
.CodeMirror-gutters {
  background: #14161e;
  border-right: 1px solid var(--border);
  width: 44px;
}
.CodeMirror-linenumbers { width: 44px; }
.CodeMirror-linenumber {
  color: var(--text-dim);
  padding: 0 10px 0 6px;     /* aire entre el número y el código */
  min-width: 28px;
  text-align: right;
}
/* El texto del código arranca después del gutter, no debajo */
.CodeMirror-lines { padding: 8px 0; }
.CodeMirror pre.CodeMirror-line,
.CodeMirror pre.CodeMirror-line-like { padding-left: 10px; }

.stdin-box { border-top: 1px solid var(--border); background: var(--bg-soft); }
.stdin-box summary {
  cursor: pointer; padding: 8px 14px; font-size: 13px; color: var(--text-dim);
  user-select: none;
}
.stdin-box .hint-text { padding: 0 14px; margin: 4px 0; font-size: 12px; color: var(--text-dim); }
#stdin {
  width: calc(100% - 28px); margin: 4px 14px 12px; min-height: 56px;
  background: #0c0e14; color: var(--text); border: 1px solid var(--border);
  border-radius: 6px; padding: 8px 10px; font-family: var(--mono); font-size: 13px;
  resize: vertical;
}

/* ---------- Actions ---------- */
.actions {
  display: flex; gap: 10px; padding: 12px 14px;
  background: var(--bg-soft); border-top: 1px solid var(--border);
  flex-wrap: wrap;
}
.btn {
  border: none; padding: 9px 18px; border-radius: 8px; cursor: pointer;
  font-size: 14px; font-weight: 600; transition: transform .08s, filter .15s;
}
.btn:active { transform: translateY(1px); }
.btn:disabled { opacity: .4; cursor: not-allowed; }
.btn-primary { background: var(--green); color: #08130a; }
.btn-primary:hover:not(:disabled) { filter: brightness(1.1); }
.btn-secondary { background: var(--py-blue); color: #04121d; }
.btn-secondary:hover:not(:disabled) { filter: brightness(1.1); }
.btn-ghost { background: transparent; border: 1px solid var(--border); color: var(--text); }
.btn-ghost:hover:not(:disabled) { border-color: var(--py-blue); }

/* ---------- Output ---------- */
.output-zone h3 { font-size: 15px; margin: 0 0 8px; }
.output {
  background: #0c0e14; border: 1px solid var(--border); border-radius: var(--radius);
  padding: 14px 16px; font-family: var(--mono); font-size: 13.5px;
  white-space: pre-wrap; word-break: break-word; min-height: 60px;
  color: var(--text); margin: 0;
}
.output.ok { border-color: var(--green); }
.output.fail { border-color: var(--red); }
.output .ok-line { color: var(--green); }
.output .fail-line { color: var(--red); }
.output .err-line { color: var(--red); }
.output .dim { color: var(--text-dim); }

.toast {
  position: fixed; bottom: 24px; left: 50%; transform: translateX(-50%);
  background: var(--green); color: #08130a; padding: 12px 24px;
  border-radius: 99px; font-weight: 700; box-shadow: 0 8px 30px rgba(0,0,0,.4);
  animation: pop .3s ease; z-index: 100;
}
@keyframes pop { from { transform: translateX(-50%) scale(.85); opacity: 0; } }

/* ---------- Responsive ---------- */
@media (max-width: 760px) {
  .layout { grid-template-columns: 1fr; }
  .sidebar {
    border-right: none; border-bottom: 1px solid var(--border);
    max-height: 240px;
  }
  .workspace { padding: 18px; }
}

/* ---------- Botón Pizarra (topbar) ---------- */
.btn-pizarra {
  background: linear-gradient(135deg, #16a085, #2ecc71); color: #04121d;
  border: none; border-radius: 8px; padding: 6px 14px; font-size: 13px;
  font-weight: 700; cursor: pointer; margin-right: 8px;
}
.btn-pizarra:hover { filter: brightness(1.08); }

/* ---------- Pizarra flotante ---------- */
.pizarra {
  position: fixed; right: 24px; bottom: 96px; z-index: 180;
  width: 460px; max-width: calc(100vw - 24px);
  background: var(--bg-card); border: 1px solid var(--border);
  border-radius: 12px; box-shadow: 0 18px 50px rgba(0,0,0,.55);
  display: flex; flex-direction: column; overflow: hidden;
}
.pizarra-head {
  display: flex; align-items: center; justify-content: space-between;
  padding: 8px 12px; background: var(--bg-soft); border-bottom: 1px solid var(--border);
  user-select: none;
}
.pizarra-title { font-weight: 700; font-size: 14px; }
.pizarra-head-btns { display: flex; gap: 6px; }
.pizarra-editor { border-bottom: 1px solid var(--border); }
.pizarra-editor .CodeMirror { height: 240px; }
.pizarra-actions {
  display: flex; align-items: center; gap: 12px; padding: 8px 12px;
  background: var(--bg-soft); border-bottom: 1px solid var(--border);
}
.pizarra-hint { font-size: 11px; color: var(--text-dim); }
.pizarra-out {
  margin: 0; max-height: 140px; overflow-y: auto; border: none;
  border-radius: 0; font-size: 13px; min-height: 32px;
}
@media (max-width: 760px) {
  .pizarra { right: 8px; left: 8px; width: auto; bottom: 80px; }
}

/* ---------- Botón Prueba (topbar) ---------- */
.btn-prueba {
  background: linear-gradient(135deg, #f6a609, #f25c54); color: #fff;
  border: none; border-radius: 8px; padding: 6px 14px; font-size: 13px;
  font-weight: 700; cursor: pointer; margin-right: 8px;
}
.btn-prueba:hover { filter: brightness(1.08); }

/* Intro de prueba */
.prueba-previa { background: var(--green-soft); border: 1px solid var(--border);
  padding: 8px 12px; border-radius: 8px; font-size: 14px; }
.prueba-reqs { background: var(--bg-soft); border: 1px solid var(--border);
  border-radius: 8px; padding: 12px 14px; margin: 14px 0; }
.prueba-reqs-title { font-size: 13px; color: var(--text-dim); margin-bottom: 6px; }
.prueba-reqs ul, .prueba-rules { list-style: none; padding: 0; margin: 0; font-size: 14px; }
.prueba-reqs li, .prueba-rules li { padding: 3px 0; }
.prueba-rules { margin: 10px 0 16px; }
.prueba-aviso { color: var(--py-yellow); font-size: 14px; }

/* Overlay de examen */
.exam-overlay {
  position: fixed; inset: 0; background: var(--bg); z-index: 300; overflow-y: auto;
}
.exam-top {
  position: sticky; top: 0; z-index: 2; display: flex; align-items: center;
  justify-content: space-between; padding: 14px 28px; background: var(--bg-soft);
  border-bottom: 1px solid var(--border);
}
.exam-top h2 { margin: 0; font-size: 19px; }
.exam-sub { font-size: 13px; color: var(--text-dim); }
.exam-top-right { display: flex; align-items: center; gap: 14px; }
.exam-timer {
  font-family: var(--mono); font-size: 20px; font-weight: 700; color: var(--py-yellow);
  background: var(--bg-card); padding: 4px 12px; border-radius: 8px; min-width: 84px; text-align: center;
}
.exam-timer.urgente { color: var(--red); animation: aiblink 1s infinite; }

.exam-body { max-width: 880px; margin: 0 auto; padding: 22px 24px 60px; }
.exam-card {
  background: var(--bg-card); border: 1px solid var(--border); border-radius: 12px;
  padding: 18px 20px; margin-bottom: 20px;
}
.exam-card-head { display: flex; align-items: center; gap: 8px; margin-bottom: 4px; }
.exam-num { font-weight: 700; color: var(--text-dim); font-size: 13px; }
.exam-card h3 { margin: 4px 0 10px; font-size: 18px; }
.exam-editor-wrap { border: 1px solid var(--border); border-radius: 8px; overflow: hidden; margin-top: 8px; }
.exam-actions { display: flex; align-items: center; gap: 12px; margin: 10px 0 8px; flex-wrap: wrap; }
.exam-hint-text { font-size: 12px; color: var(--text-dim); }
.exam-out { min-height: 36px; font-size: 13px; }

/* Resultado */
.exam-result { max-width: 620px; margin: 30px auto; text-align: center; }
.nota-circle {
  width: 160px; height: 160px; border-radius: 50%; margin: 0 auto 18px;
  display: flex; flex-direction: column; align-items: center; justify-content: center;
  border: 6px solid;
}
.nota-circle.ok { border-color: var(--green); background: var(--green-soft); }
.nota-circle.fail { border-color: var(--red); background: var(--red-soft); }
.nota-num { font-size: 52px; font-weight: 800; line-height: 1; }
.nota-lbl { font-size: 12px; color: var(--text-dim); margin-top: 6px; }
.nota-msg { font-size: 16px; margin: 6px 0; }
.nota-logro { color: var(--text-dim); }
.nota-disclaimer { font-size: 13px; color: var(--text-dim); margin-top: 16px;
  background: var(--bg-soft); padding: 10px 14px; border-radius: 8px; border: 1px solid var(--border); }
.exam-result-actions { display: flex; gap: 10px; justify-content: center; margin-top: 20px; }

/* ---------- Botón Admin (topbar) ---------- */
.btn-admin {
  background: linear-gradient(135deg, #e056fd, #686de0); color: #fff;
  border: none; border-radius: 8px; padding: 6px 14px; font-size: 13px;
  font-weight: 700; cursor: pointer; margin-right: 8px;
}
.btn-admin:hover { filter: brightness(1.1); }

/* ---------- Panel Admin (overlay completo) ---------- */
.admin-overlay {
  position: fixed; inset: 0; background: var(--bg); z-index: 300;
  overflow-y: auto; padding: 0;
}
.admin-top {
  position: sticky; top: 0; display: flex; align-items: center; justify-content: space-between;
  padding: 16px 28px; background: var(--bg-soft); border-bottom: 1px solid var(--border);
  z-index: 2;
}
.admin-top h2 { margin: 0; font-size: 20px; }
.admin-body { padding: 24px 28px; max-width: 1100px; margin: 0 auto; }

.admin-cards { display: flex; gap: 16px; flex-wrap: wrap; margin-bottom: 26px; }
.admin-card {
  background: var(--bg-card); border: 1px solid var(--border); border-radius: 12px;
  padding: 18px 22px; min-width: 160px;
}
.admin-card .num { font-size: 30px; font-weight: 800; color: var(--py-yellow); }
.admin-card .lbl { color: var(--text-dim); font-size: 13px; margin-top: 2px; }

.admin-section-title { font-size: 15px; font-weight: 700; margin: 24px 0 12px; }

.ex-bars { display: flex; flex-direction: column; gap: 8px; }
.ex-bar-row { display: grid; grid-template-columns: 160px 1fr 40px; align-items: center; gap: 10px; font-size: 13px; }
.ex-bar-track { background: var(--bg-card); border-radius: 99px; height: 12px; overflow: hidden; }
.ex-bar-fill { height: 100%; background: linear-gradient(90deg, var(--py-blue), var(--py-yellow)); }

/* Celda de % de avance en la tabla de alumnos */
.avance-cell { display: flex; flex-direction: column; gap: 3px; min-width: 120px; }
.avance-track { background: var(--bg-card); border-radius: 99px; height: 8px; overflow: hidden; }
.avance-fill { height: 100%; border-radius: 99px; }
.avance-num { font-size: 12px; white-space: nowrap; }

.admin-table { width: 100%; border-collapse: collapse; font-size: 14px; }
.admin-table th, .admin-table td {
  text-align: left; padding: 10px 12px; border-bottom: 1px solid var(--border);
}
.admin-table th { color: var(--text-dim); font-weight: 600; font-size: 12px; text-transform: uppercase; }
.admin-table tr:hover td { background: var(--bg-soft); }
.admin-table .acciones { display: flex; gap: 6px; }
.tag-admin { background: #3a2456; color: #e056fd; border: 1px solid #5a3a82;
  font-size: 11px; padding: 1px 7px; border-radius: 99px; }
.btn-row {
  background: var(--bg-card); border: 1px solid var(--border); color: var(--text);
  border-radius: 6px; padding: 4px 10px; font-size: 12px; cursor: pointer;
}
.btn-row:hover { border-color: var(--py-blue); }
.btn-row.danger:hover { border-color: var(--red); color: var(--red); }

.admin-loading { color: var(--text-dim); padding: 30px; text-align: center; }

/* Detalle de usuario */
.admin-detail {
  background: var(--bg-card); border: 1px solid var(--border); border-radius: 12px;
  padding: 18px; margin-top: 16px;
}
.detail-ex {
  border: 1px solid var(--border); border-radius: 8px; margin-bottom: 10px; overflow: hidden;
}
.detail-ex summary {
  cursor: pointer; padding: 8px 12px; background: var(--bg-soft); font-size: 13px;
  display: flex; gap: 8px; align-items: center;
}
.detail-ex pre {
  margin: 0; padding: 12px; background: #0c0e14; font-family: var(--mono);
  font-size: 12.5px; color: var(--py-blue-light); overflow-x: auto;
}

/* ---------- Asistente de IA ---------- */
.ai-fab {
  position: fixed; bottom: 22px; right: 22px; z-index: 150;
  display: flex; align-items: center; gap: 8px;
  background: linear-gradient(135deg, var(--py-blue), #6c5ce7);
  color: #fff; border: none; border-radius: 99px;
  padding: 12px 18px; font-size: 15px; font-weight: 700; cursor: pointer;
  box-shadow: 0 8px 24px rgba(75, 139, 190, .45);
  transition: transform .12s, box-shadow .15s;
}
.ai-fab:hover { transform: translateY(-2px); box-shadow: 0 12px 30px rgba(75,139,190,.55); }
.ai-fab-icon { font-size: 20px; }

.ai-panel {
  position: fixed; bottom: 22px; right: 22px; z-index: 160;
  width: 380px; max-width: calc(100vw - 24px);
  height: 560px; max-height: calc(100vh - 44px);
  background: var(--bg-soft); border: 1px solid var(--border);
  border-radius: 16px; display: flex; flex-direction: column;
  box-shadow: 0 24px 60px rgba(0,0,0,.5); overflow: hidden;
}
.ai-header {
  display: flex; align-items: center; justify-content: space-between;
  padding: 14px 16px; background: var(--bg-card); border-bottom: 1px solid var(--border);
}
.ai-title { font-weight: 700; font-size: 15px; }
.ai-head-btns { display: flex; gap: 4px; }
.ai-header { cursor: move; }
.ai-close {
  background: none; border: none; color: var(--text-dim);
  font-size: 17px; cursor: pointer; width: 26px; line-height: 1;
}
.ai-close:hover { color: var(--text); }

/* Estado minimizado: solo la barra de título */
.ai-panel.min { height: auto !important; }
.ai-panel.min .ai-messages,
.ai-panel.min .ai-input { display: none; }

.ai-messages {
  flex: 1; overflow-y: auto; padding: 16px; display: flex;
  flex-direction: column; gap: 12px;
}
.ai-msg {
  max-width: 88%; padding: 10px 13px; border-radius: 12px;
  font-size: 14px; line-height: 1.5; word-wrap: break-word;
}
.ai-msg.bot { background: var(--bg-card); border: 1px solid var(--border);
  align-self: flex-start; border-bottom-left-radius: 4px; }
.ai-msg.user { background: var(--py-blue); color: #04121d;
  align-self: flex-end; border-bottom-right-radius: 4px; }
.ai-msg.error { background: var(--red-soft); border: 1px solid var(--red);
  color: var(--text); align-self: flex-start; }
.ai-msg p { margin: 0 0 8px; }
.ai-msg p:last-child { margin-bottom: 0; }
.ai-msg code {
  background: #0c0e14; padding: 1px 5px; border-radius: 4px;
  font-family: var(--mono); font-size: 12.5px; color: var(--py-yellow);
}
.ai-msg pre {
  background: #0c0e14; border: 1px solid var(--border); border-radius: 8px;
  padding: 10px 12px; overflow-x: auto; margin: 8px 0;
}
.ai-msg pre code { background: none; color: var(--py-blue-light); padding: 0; }
.ai-typing { display: inline-flex; gap: 4px; align-items: center; }
.ai-typing span {
  width: 7px; height: 7px; border-radius: 50%; background: var(--text-dim);
  animation: aiblink 1.2s infinite both;
}
.ai-typing span:nth-child(2) { animation-delay: .2s; }
.ai-typing span:nth-child(3) { animation-delay: .4s; }
@keyframes aiblink { 0%, 80%, 100% { opacity: .25; } 40% { opacity: 1; } }

.ai-input {
  display: flex; gap: 8px; padding: 12px; border-top: 1px solid var(--border);
  background: var(--bg-card);
}
.ai-input textarea {
  flex: 1; resize: none; background: #0c0e14; color: var(--text);
  border: 1px solid var(--border); border-radius: 10px; padding: 10px 12px;
  font-family: var(--font); font-size: 14px; max-height: 120px; line-height: 1.4;
}
.ai-input textarea:focus { outline: none; border-color: var(--py-blue); }
.ai-input button {
  background: var(--py-blue); color: #04121d; border: none; border-radius: 10px;
  width: 44px; font-size: 17px; cursor: pointer; flex-shrink: 0;
}
.ai-input button:disabled { opacity: .5; cursor: not-allowed; }

/* Botón de micrófono: neutro en reposo, rojo pulsante mientras graba */
#aiMic { background: var(--bg-soft, #1a1d27); color: var(--text); border: 1px solid var(--border); }
#aiMic.grabando { background: var(--red, #e5484d); color: #fff; border-color: transparent; animation: micPulse 1s ease-in-out infinite; }
@keyframes micPulse { 0%,100% { box-shadow: 0 0 0 0 rgba(229,72,77,.5); } 50% { box-shadow: 0 0 0 6px rgba(229,72,77,0); } }

@media (max-width: 760px) {
  .ai-fab-text { display: none; }
  .ai-panel { bottom: 0; right: 0; width: 100vw; height: 100vh;
    max-height: 100vh; border-radius: 0; }
}

.spinner {
  display: inline-block; width: 14px; height: 14px; border: 2px solid var(--text-dim);
  border-top-color: var(--py-blue); border-radius: 50%;
  animation: spin .7s linear infinite; vertical-align: middle; margin-right: 6px;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* ---------- Clases en audio/video (panel de media) ---------- */
.media-panel { max-width: 760px; }
.media-head { margin-bottom: 18px; }
.media-head h2 { margin: 8px 0 6px; font-size: 24px; }
.media-sub { color: var(--text-dim); margin: 0; font-size: 15px; }
.media-sub code, .media-teoria code { font-family: var(--mono); font-size: .92em; }

.media-players { display: flex; flex-direction: column; gap: 16px; margin-bottom: 24px; }
.media-card {
  background: var(--bg-card); border: 1px solid var(--border);
  border-radius: var(--radius); padding: 14px 16px;
}
.media-card-label { font-weight: 600; margin-bottom: 10px; font-size: 14px; }
.media-slot { position: relative; }
.media-el { width: 100%; display: block; border-radius: 8px; background: #000; }
video.media-el { aspect-ratio: 16 / 9; }
audio.media-el { height: 44px; background: var(--bg-soft); }
.media-pending {
  padding: 28px 16px; text-align: center; color: var(--text-dim);
  background: var(--bg-soft); border: 1px dashed var(--border);
  border-radius: 8px; font-size: 14px; line-height: 1.7;
}
.media-dl {
  display: inline-block; margin-top: 10px; font-size: 13px;
  color: var(--py-blue-light); text-decoration: none;
}
.media-dl:hover { text-decoration: underline; }

.media-teoria {
  background: var(--bg-card); border: 1px solid var(--border);
  border-radius: var(--radius); padding: 2px 20px 10px;
}
.media-teoria pre {
  background: var(--bg); border: 1px solid var(--border);
  border-radius: 8px; padding: 12px 14px; overflow-x: auto;
}

/* Entradas de media en el sidebar (no se bloquean) */
.ej-item.media-link { color: var(--py-blue-light); }
.ej-item.media-link .nivel-dots {
  color: var(--text-dim); text-transform: uppercase;
  font-size: 9px; letter-spacing: .5px;
}
