/* DAW — estética dark underground techno: carbón + acento ácido/champán */
:root {
  --bg: #0c0d0c;
  --bg-2: #131513;
  --bg-3: #1a1d1a;
  --line: #262a26;
  --text: #e8e9e4;
  --muted: #8d938a;
  --acid: #c6f24e;
  --acid-dim: #97bd3e;
  --champagne: #d9c9a3;
  --danger: #ff6b5e;
  --radius: 10px;
  --font: "Inter", "Helvetica Neue", Arial, system-ui, sans-serif;
  --mono: "JetBrains Mono", "SF Mono", ui-monospace, Menlo, monospace;
}

* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; }
body {
  background: var(--bg);
  color: var(--text);
  font-family: var(--font);
  font-size: 16px;
  line-height: 1.6;
  min-height: 100vh;
  display: flex;
  flex-direction: column;
}
[hidden] { display: none !important; }

/* ---------- topbar ---------- */
.topbar {
  display: flex;
  align-items: center;
  gap: 24px;
  padding: 14px 28px;
  border-bottom: 1px solid var(--line);
  background: rgba(12, 13, 12, 0.92);
  position: sticky;
  top: 0;
  z-index: 10;
  backdrop-filter: blur(6px);
}
.brand {
  font-weight: 800;
  letter-spacing: 0.12em;
  color: var(--text);
  text-decoration: none;
  font-size: 18px;
}
.brand-mark { color: var(--acid); margin-right: 6px; }
.brand-sub { color: var(--muted); font-weight: 500; letter-spacing: 0.08em; font-size: 12px; margin-left: 8px; }
.nav { display: flex; gap: 4px; flex: 1; }
.nav a {
  color: var(--muted);
  text-decoration: none;
  padding: 8px 16px;
  border-radius: 8px;
  font-weight: 600;
  font-size: 14px;
  letter-spacing: 0.04em;
  transition: color .15s, background .15s;
}
.nav a:hover { color: var(--text); background: var(--bg-3); }
.nav a.active { color: var(--acid); background: var(--bg-3); }
.topbar-right { margin-left: auto; }

/* ---------- layout ---------- */
main {
  flex: 1;
  width: 100%;
  max-width: 1060px;
  margin: 0 auto;
  padding: 36px 24px 60px;
}
.view h1 {
  font-size: 30px;
  font-weight: 800;
  letter-spacing: 0.02em;
  margin: 0 0 8px;
}
.lead { max-width: 680px; margin-bottom: 28px; }
.muted { color: var(--muted); }
.error { color: var(--danger); font-size: 14px; margin-top: 10px; }

/* ---------- botones / form ---------- */
.btn-primary {
  background: var(--acid);
  color: #101208;
  border: none;
  border-radius: 8px;
  padding: 11px 22px;
  font-weight: 700;
  font-size: 15px;
  cursor: pointer;
  transition: filter .15s;
}
.btn-primary:hover { filter: brightness(1.1); }
.btn-primary:disabled { opacity: .5; cursor: not-allowed; }
.btn-ghost {
  background: transparent;
  color: var(--muted);
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 8px 16px;
  font-weight: 600;
  font-size: 13px;
  cursor: pointer;
  transition: color .15s, border-color .15s;
}
.btn-ghost:hover { color: var(--text); border-color: var(--muted); }

input[type="password"], input[type="text"], textarea {
  width: 100%;
  background: var(--bg-2);
  color: var(--text);
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 12px 14px;
  font-size: 15px;
  font-family: inherit;
  outline: none;
  transition: border-color .15s;
}
input:focus, textarea:focus { border-color: var(--acid-dim); }
label { display: block; font-size: 13px; color: var(--muted); margin: 14px 0 6px; font-weight: 600; letter-spacing: .04em; }

/* ---------- login ---------- */
.login-card {
  max-width: 380px;
  margin: 8vh auto 0;
  background: var(--bg-2);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 36px 32px;
}
.login-card h1 { font-size: 34px; letter-spacing: .18em; margin-bottom: 4px; }
.login-card .btn-primary { width: 100%; margin-top: 22px; }

/* ---------- curso ---------- */
.carril { margin-bottom: 44px; }
.carril-head {
  display: flex;
  align-items: baseline;
  gap: 14px;
  border-bottom: 1px solid var(--line);
  padding-bottom: 10px;
  margin-bottom: 18px;
}
.carril-tag {
  font-family: var(--mono);
  font-size: 12px;
  letter-spacing: .18em;
  color: #101208;
  background: var(--champagne);
  padding: 3px 10px;
  border-radius: 4px;
  font-weight: 700;
}
.carril-tag.b { background: var(--acid); }
.carril-head h2 { margin: 0; font-size: 20px; letter-spacing: .04em; }

.fase-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(300px, 1fr));
  gap: 16px;
}
.fase-card {
  background: var(--bg-2);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 20px;
  text-decoration: none;
  color: var(--text);
  display: block;
  transition: border-color .15s, transform .15s;
}
.fase-card:hover { border-color: var(--acid-dim); transform: translateY(-2px); }
.fase-num {
  font-family: var(--mono);
  color: var(--acid);
  font-size: 12px;
  letter-spacing: .18em;
  text-transform: uppercase;
}
.fase-card h3 { margin: 6px 0 8px; font-size: 18px; }
.fase-card .hito-mini {
  color: var(--champagne);
  font-size: 13px;
  margin-top: 12px;
  padding-top: 12px;
  border-top: 1px dashed var(--line);
}
.progress-track {
  height: 5px;
  background: var(--bg-3);
  border-radius: 3px;
  overflow: hidden;
  margin-top: 14px;
}
.progress-fill { height: 100%; background: var(--acid); border-radius: 3px; transition: width .25s; }

/* ---------- fase detalle ---------- */
.fase-header { margin-bottom: 22px; }
.fase-header .breadcrumb { font-size: 13px; margin-bottom: 10px; }
.fase-header .breadcrumb a { color: var(--muted); text-decoration: none; }
.fase-header .breadcrumb a:hover { color: var(--acid); }
.panel {
  background: var(--bg-2);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 22px 24px;
  margin-bottom: 18px;
}
.panel h2 { margin: 0 0 10px; font-size: 16px; letter-spacing: .12em; text-transform: uppercase; color: var(--muted); font-weight: 700; }
.panel .hito {
  color: var(--champagne);
  border-left: 3px solid var(--champagne);
  padding-left: 14px;
  margin: 0;
  font-size: 15px;
}

.lesson {
  border: 1px solid var(--line);
  border-radius: 8px;
  margin-bottom: 10px;
  overflow: hidden;
}
.lesson-head {
  display: flex;
  align-items: center;
  gap: 12px;
  width: 100%;
  background: var(--bg-3);
  border: none;
  color: var(--text);
  padding: 13px 16px;
  cursor: pointer;
  font-size: 15px;
  font-weight: 600;
  text-align: left;
  font-family: inherit;
}
.lesson-head:hover { background: #202420; }
.lesson-head .chev { color: var(--muted); transition: transform .15s; font-size: 12px; }
.lesson.open .chev { transform: rotate(90deg); }
.badge {
  font-family: var(--mono);
  font-size: 10px;
  letter-spacing: .12em;
  padding: 2px 8px;
  border-radius: 20px;
  text-transform: uppercase;
  font-weight: 700;
}
.badge.pendiente { background: #2c2417; color: var(--champagne); border: 1px solid #4a3d22; }
.badge.generada { background: #1c2b0e; color: var(--acid); border: 1px solid #35501a; }
.lesson-body { padding: 4px 20px 16px; display: none; }
.lesson.open .lesson-body { display: block; }

/* markdown */
.md h1 { font-size: 22px; margin: 18px 0 8px; }
.md h2 { font-size: 18px; margin: 18px 0 8px; }
.md h3 { font-size: 15px; margin: 16px 0 6px; color: var(--champagne); }
.md p { margin: 8px 0; }
.md ul, .md ol { margin: 8px 0; padding-left: 22px; }
.md li { margin: 4px 0; }
.md code {
  font-family: var(--mono);
  font-size: 13px;
  background: var(--bg-3);
  padding: 2px 6px;
  border-radius: 4px;
  color: var(--acid);
}
.md pre {
  background: #0a0b0a;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 14px 16px;
  overflow-x: auto;
}
.md pre code { background: none; padding: 0; color: var(--champagne); }
.md blockquote {
  border-left: 3px solid var(--acid-dim);
  margin: 10px 0;
  padding: 4px 16px;
  color: var(--muted);
  background: var(--bg-3);
  border-radius: 0 8px 8px 0;
}
.md a { color: var(--acid); }
.md hr { border: none; border-top: 1px solid var(--line); margin: 16px 0; }
.md strong { color: var(--text); }

/* checklist */
.checklist { list-style: none; margin: 0; padding: 0; }
.checklist li { margin: 0; }
.checklist label {
  display: flex;
  gap: 12px;
  align-items: flex-start;
  padding: 10px 12px;
  margin: 0 0 6px;
  border: 1px solid var(--line);
  border-radius: 8px;
  cursor: pointer;
  font-size: 14.5px;
  color: var(--text);
  font-weight: 400;
  letter-spacing: 0;
  transition: border-color .15s, background .15s;
}
.checklist label:hover { border-color: var(--acid-dim); }
.checklist input[type="checkbox"] {
  accent-color: var(--acid);
  width: 17px;
  height: 17px;
  margin-top: 3px;
  flex-shrink: 0;
}
.checklist input[type="checkbox"]:checked + span { color: var(--muted); text-decoration: line-through; }
.check-meta { display: flex; align-items: center; gap: 14px; margin-top: 14px; }
.check-meta .progress-track { flex: 1; margin: 0; }

/* ---------- chat ---------- */
.view-chat {
  display: flex;
  flex-direction: column;
  height: calc(100vh - 190px);
  min-height: 480px;
  max-width: 860px;
  margin: 0 auto;
  padding: 20px 24px;
}
.chat-header { display: flex; justify-content: space-between; align-items: flex-start; gap: 16px; }
.chat-header h1 { font-size: 22px; margin: 0 0 2px; }
.chat-log {
  flex: 1;
  overflow-y: auto;
  padding: 18px 4px;
  display: flex;
  flex-direction: column;
  gap: 14px;
  scroll-behavior: smooth;
}
.msg { max-width: 82%; padding: 13px 17px; border-radius: 14px; font-size: 15px; overflow-wrap: break-word; }
.msg.user {
  align-self: flex-end;
  background: var(--acid);
  color: #121407;
  border-bottom-right-radius: 4px;
}
.msg.assistant {
  align-self: flex-start;
  background: var(--bg-2);
  border: 1px solid var(--line);
  border-bottom-left-radius: 4px;
}
.msg.assistant .md pre { font-size: 12.5px; }
.msg .who {
  font-family: var(--mono);
  font-size: 10px;
  letter-spacing: .16em;
  text-transform: uppercase;
  color: var(--muted);
  display: block;
  margin-bottom: 6px;
}
.msg.user .who { color: #3c4212; }
.chat-thinking {
  display: flex;
  align-items: center;
  gap: 10px;
  color: var(--muted);
  font-size: 13.5px;
  padding: 6px 8px;
}
.pulse {
  width: 8px; height: 8px; border-radius: 50%;
  background: var(--acid);
  animation: pulse 1s ease-in-out infinite;
}
@keyframes pulse {
  0%, 100% { opacity: .35; transform: scale(.85); }
  50% { opacity: 1; transform: scale(1.15); }
}
.chat-input { display: flex; gap: 10px; align-items: flex-end; margin-top: 10px; }
.chat-input textarea { resize: none; max-height: 160px; }
.chat-hint { font-size: 11.5px; margin-top: 8px; }

.footer {
  border-top: 1px solid var(--line);
  padding: 14px 28px;
  font-size: 12px;
  letter-spacing: .05em;
}

/* ---------- shell + sidebar de conversaciones ---------- */
.shell { display: flex; flex: 1; width: 100%; min-height: 0; align-items: stretch; }
.shell main { min-width: 0; }
.shell.with-sidebar main { max-width: none; }
.shell.with-sidebar .view-chat { max-width: none; }

.btn-icon {
  background: transparent;
  border: 1px solid var(--line);
  color: var(--muted);
  border-radius: 8px;
  width: 34px;
  height: 34px;
  line-height: 1;
  font-size: 16px;
  cursor: pointer;
  flex-shrink: 0;
  transition: color .15s, border-color .15s;
}
.btn-icon:hover { color: var(--acid); border-color: var(--acid-dim); }

.sidebar {
  width: 276px;
  flex-shrink: 0;
  background: var(--bg-2);
  border-right: 1px solid var(--line);
  display: flex;
  flex-direction: column;
  min-height: 0;
  overflow: hidden;
}
.sidebar-head { display: flex; gap: 8px; padding: 14px 14px 10px; border-bottom: 1px solid var(--line); }
.sidebar-new { flex: 1; padding: 10px 12px; font-size: 14px; }
.conv-list { flex: 1; overflow-y: auto; padding: 8px; display: flex; flex-direction: column; gap: 2px; }
.conv-empty { padding: 14px; font-size: 13.5px; line-height: 1.5; margin: 0; }

.conv-item {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 9px 10px;
  border-radius: 8px;
  cursor: pointer;
  border: 1px solid transparent;
  transition: background .15s, border-color .15s;
}
.conv-item:hover { background: var(--bg-3); }
.conv-item.active { background: var(--bg-3); border-color: var(--acid-dim); }
.conv-main { min-width: 0; flex: 1; display: flex; flex-direction: column; gap: 2px; }
.conv-title {
  font-size: 14px; font-weight: 600;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.conv-item.active .conv-title { color: var(--acid); }
.conv-meta {
  font-family: var(--mono); font-size: 10.5px; letter-spacing: .08em;
  color: var(--muted); text-transform: uppercase;
}
.conv-actions { display: none; gap: 4px; flex-shrink: 0; }
.conv-item:hover .conv-actions,
.conv-item:focus-within .conv-actions { display: flex; }
.conv-btn {
  background: transparent; border: 1px solid var(--line); color: var(--muted);
  width: 26px; height: 26px; border-radius: 6px; cursor: pointer;
  font-size: 12px; line-height: 1; padding: 0;
}
.conv-btn:hover { color: var(--text); border-color: var(--muted); }
.conv-btn.danger:hover { color: var(--danger); border-color: var(--danger); }
.sidebar-foot {
  padding: 10px 14px; border-top: 1px solid var(--line);
  font-size: 11px; letter-spacing: .03em;
}
.sidebar-foot code { font-family: var(--mono); color: var(--acid-dim); background: none; padding: 0; }
.sidebar-overlay { position: fixed; inset: 0; background: rgba(5, 6, 5, .6); z-index: 35; }

@media (max-width: 900px) {
  .sidebar {
    position: fixed; top: 0; left: 0; bottom: 0;
    width: min(84vw, 320px);
    z-index: 40;
    transform: translateX(-100%);
    transition: transform .2s ease;
    box-shadow: 0 0 40px rgba(0, 0, 0, .55);
  }
  .sidebar.open { transform: none; }
}

/* ---------- responsive ---------- */
@media (max-width: 720px) {
  .topbar { padding: 12px 16px; gap: 12px; }
  .brand-sub { display: none; }
  main { padding: 24px 16px 40px; }
  .view-chat { height: calc(100vh - 160px); padding: 12px 8px; }
  .msg { max-width: 92%; }
  .chat-header { flex-direction: column; }
}
