/**
 * css/components.css
 * =====================================================================
 * Piezas de shell y componentes chicos que comparten varias vistas:
 * topbar, tabbar, overlays, cards, botones primario/secundario, toast.
 *
 * OJO — por qué algunas reglas usan `body:has(.tabbar)`:
 * `.app` y `.overlay` (en su forma base) son clases que también usa
 * el demo standalone de Corregir (corregir-demo.html), que NO tiene
 * tabbar ni necesita la reserva de espacio para el sidebar de
 * escritorio. En vez de duplicar `.app` con otro nombre, la reserva de
 * layout específica de la app completa (con tabbar) se activa solo
 * cuando hay un `.tabbar` en la página — así layout.css sigue siendo
 * 100% compartible entre el prototipo completo y el demo aislado.
 * =====================================================================
 */
:root{
  --tabbar-h: calc(64px + env(safe-area-inset-bottom));
}
html{ scroll-behavior:smooth; }
body{ min-height:100dvh; overflow-x:hidden; }
::selection{ background:var(--accent-bg); }
@media (prefers-reduced-motion:reduce){
  *,*::before,*::after{ animation:none!important; transition:none!important; }
  html{ scroll-behavior:auto; }
}

/* ---------------- vistas (tabs de contenido) ---------------- */
.view{ display:none; animation:viewIn .28s ease both; }
.view.active{ display:block; }
@keyframes viewIn{ from{opacity:0;transform:translateY(6px)} to{opacity:1;transform:none} }

/* ---------------- topbar ---------------- */
.topbar{
  position:sticky; top:0; z-index:40;
  display:flex; align-items:center; justify-content:space-between;
  padding:14px 0 12px;
  background:linear-gradient(to bottom, var(--bg) 78%, transparent);
}
.brand{ display:flex; flex-direction:column; gap:1px; }
.brand .hola{ font-family:var(--font-d); font-size:1.15rem; font-weight:600; letter-spacing:-.01em; }
.brand .fecha{ font-size:.72rem; color:var(--faint); text-transform:capitalize; }
.curso-chip{
  display:flex; align-items:center; gap:8px;
  background:var(--card); border:1px solid var(--line);
  border-radius:999px; padding:8px 14px;
  font-family:var(--font-d); font-size:.8rem; font-weight:600;
  transition:border-color .2s;
}
.curso-chip:hover{ border-color:var(--accent); }
.curso-chip .dot{ width:7px; height:7px; border-radius:50%; background:var(--accent); box-shadow:0 0 8px var(--accent); }

/* ---------------- títulos de sección + card genérica ---------------- */
.sec-title{ display:flex; align-items:baseline; justify-content:space-between; margin:26px 0 12px; }
.sec-title h2{ font-family:var(--font-d); font-size:.95rem; font-weight:600; letter-spacing:.01em; }
.sec-title .link{ font-size:.76rem; color:var(--accent); font-weight:600; }
.card{ background:var(--card); border:1px solid var(--line); border-radius:var(--r-md); padding:16px; }

/* ---------------- tabbar (mobile: barra inferior · desktop: sidebar) ---------------- */
.tabbar{
  position:fixed; left:0; right:0; bottom:0; z-index:50;
  background:color-mix(in srgb, var(--bg) 85%, transparent); backdrop-filter:blur(18px); -webkit-backdrop-filter:blur(18px);
  border-top:1px solid var(--line);
  padding-bottom:env(safe-area-inset-bottom);
}
.tabbar-inner{ max-width:480px; margin:0 auto; display:flex; height:64px; }
.tab{
  flex:1; display:flex; flex-direction:column; align-items:center; justify-content:center; gap:3px;
  color:var(--faint); font-size:.62rem; font-weight:600;
  transition:color .2s; position:relative;
}
.tab svg{ width:21px; height:21px; stroke:currentColor; fill:none; stroke-width:1.8; stroke-linecap:round; stroke-linejoin:round; }
.tab.on{ color:var(--accent-2); }
.tab.on::before{
  content:''; position:absolute; top:0; width:24px; height:3px; border-radius:0 0 4px 4px;
  background:var(--accent); box-shadow:0 2px 10px var(--accent);
}
body:has(.tabbar){ padding-bottom:var(--tabbar-h); }

/* ---------------- botones y campos genéricos ---------------- */
.btn-primario{
  width:100%; height:48px; border-radius:14px; margin-top:14px;
  background:var(--accent); color:#0B1020; font-weight:700; font-family:var(--font-d);
  font-size:.9rem; letter-spacing:.01em;
  box-shadow:0 8px 22px -8px rgba(108,140,255,.55);
  transition:transform .12s;
}
.btn-primario:active{ transform:scale(.98); }
.btn-secundario{
  width:100%; height:46px; border-radius:14px; margin-top:8px;
  background:var(--card); border:1px solid var(--line); color:var(--text);
  font-weight:600; font-size:.85rem;
}
.field{ margin-bottom:4px; }
.field label{ display:block; font-size:.7rem; color:var(--muted); font-weight:600; margin-bottom:6px; }
.field input{
  width:100%; height:46px; background:var(--card); border:1px solid var(--line); border-radius:12px;
  padding:0 14px; font-size:.88rem; color:var(--text); outline:none;
}
.field input:focus{ border-color:var(--accent); }
.field input::placeholder{ color:var(--faint); }

/* ---------------- overlay (ficha, editores) ---------------- */
.overlay{
  position:fixed; inset:0; z-index:60; background:var(--bg);
  transform:translateX(100%); transition:transform .3s cubic-bezier(.32,.72,.32,1);
  overflow-y:auto; overscroll-behavior:contain;
}
.overlay.open{ transform:translateX(0); }
.overlay-inner{ max-width:480px; margin:0 auto; padding:0 16px 40px; }
.ficha-top{
  position:sticky; top:0; z-index:5; display:flex; align-items:center; gap:10px;
  padding:14px 0 10px; background:linear-gradient(to bottom, var(--bg) 80%, transparent);
}
.btn-back{
  width:40px; height:40px; border-radius:12px; background:var(--card);
  border:1px solid var(--line); display:flex; align-items:center; justify-content:center; font-size:1.05rem;
}
@media (min-width:920px){
  .overlay{ left:auto; right:0; width:560px; border-left:1px solid var(--line); box-shadow:-30px 0 60px rgba(0,0,0,.4); }
}

/* ---------------- toast ---------------- */
.toast{
  position:fixed; left:50%; bottom:calc(var(--tabbar-h) + 16px); transform:translate(-50%,16px);
  background:var(--card-2); border:1px solid var(--line); border-radius:14px;
  padding:11px 18px; font-size:.82rem; font-weight:600; z-index:80;
  opacity:0; pointer-events:none; transition:all .3s; box-shadow:var(--shadow);
  display:flex; align-items:center; gap:9px; white-space:nowrap;
}
.toast.show{ opacity:1; transform:translate(-50%,0); pointer-events:auto; }
.toast .ok{ color:var(--verde); }
.toast-action{ color:var(--accent-2); font-weight:700; margin-left:4px; text-decoration:underline; text-underline-offset:2px; }

/* ---------------- tarjetas del Copiloto (las usan Dashboard y Copiloto) ---------------- */
.cop-card{
  background:var(--card); border:1px solid var(--line);
  border-radius:var(--r-md); padding:14px 14px 14px 16px;
  display:flex; gap:12px; margin-bottom:10px;
  position:relative; overflow:hidden;
}
.cop-card::before{ content:''; position:absolute; left:0; top:0; bottom:0; width:3px; background:var(--cop-color, var(--accent)); }
.cop-icon{
  flex:0 0 36px; height:36px; border-radius:10px;
  display:flex; align-items:center; justify-content:center;
  background:var(--cop-bg, var(--accent-bg)); font-size:1rem;
}
.cop-body{ flex:1; min-width:0; }
.cop-body h3{ font-family:var(--font-d); font-size:.85rem; font-weight:600; margin-bottom:3px; }
.cop-body p{ font-size:.8rem; color:var(--muted); line-height:1.45; }
.cop-body p b{ color:var(--text); font-weight:600; }
.cop-meta{ display:flex; align-items:center; gap:8px; margin-top:9px; flex-wrap:wrap; }
.cop-chip{ font-family:var(--font-m); font-size:.68rem; padding:3px 9px; border-radius:999px; background:var(--card-2); border:1px solid var(--line); color:var(--muted); }
.cop-action{ font-size:.72rem; font-weight:600; color:var(--accent); padding:3px 2px; }
.cop-spark{ flex:0 0 auto; align-self:center; }
.cop-header{
  display:flex; align-items:center; gap:10px;
  background:linear-gradient(135deg, rgba(108,140,255,.14), rgba(108,140,255,.04));
  border:1px solid rgba(108,140,255,.25);
  border-radius:var(--r-md); padding:14px 16px; margin-bottom:14px;
}
.cop-header .pulse{
  width:10px; height:10px; border-radius:50%; background:var(--accent);
  box-shadow:0 0 0 0 rgba(108,140,255,.5); animation:pulse 2.2s infinite; flex:0 0 auto;
}
@keyframes pulse{
  0%{ box-shadow:0 0 0 0 rgba(108,140,255,.45); }
  70%{ box-shadow:0 0 0 10px rgba(108,140,255,0); }
  100%{ box-shadow:0 0 0 0 rgba(108,140,255,0); }
}
.cop-header .t{ font-family:var(--font-d); font-weight:600; font-size:.9rem; }
.cop-header .s{ font-size:.72rem; color:var(--muted); }

/* ---------------- reserva de layout de escritorio (solo si hay tabbar) ---------------- */
@media (min-width:920px){
  body:has(.tabbar) .app{ max-width:1180px; padding:0 32px 60px 252px; }
  body:has(.tabbar) .tabbar{
    top:0; bottom:auto; left:0; right:auto; width:220px; height:100dvh;
    border-top:none; border-right:1px solid var(--line);
    background:var(--surface); padding:0;
  }
  body:has(.tabbar) .tabbar-inner{ flex-direction:column; height:auto; max-width:none; padding:84px 12px 0; gap:4px; }
  body:has(.tabbar) .tab{ flex:0 0 auto; flex-direction:row; justify-content:flex-start; gap:12px; padding:11px 14px; border-radius:12px; font-size:.84rem; }
  body:has(.tabbar) .tab.on{ background:var(--accent-bg); }
  body:has(.tabbar) .tab.on::before{ display:none; }
  body:has(.tabbar) .tabbar::before{
    content:'Insight · Aula'; position:absolute; top:28px; left:26px;
    font-family:var(--font-d); font-weight:700; font-size:1.05rem; color:var(--text);
  }
  body:has(.tabbar){ padding-bottom:0; }
}
