/* T.U.P.S.E.P — Tutor Único Para Superarte En PAES. Usa los tokens de styles.css. */
.tupsep-launcher,
.tupsep-panel,
.tupsep-ask {
  --tp-navy: var(--accent-dark, #062e61);
  --tp-blue: var(--accent, #0756d8);
  --tp-teal: var(--teal, #079a9d);
  --tp-ink: var(--ink, #09214a);
  --tp-muted: var(--muted, #5f708c);
  --tp-line: var(--line, #dce5f1);
  --tp-paper: var(--paper, #fff);
  --tp-bg: #f3f6fb;
  --tp-online: #22c55e;
  --tp-grad: linear-gradient(135deg, #0a3a7a 0%, #062e61 45%, #041f45 100%);
  --tp-user: linear-gradient(135deg, #1566ea 0%, #0756d8 55%, #0647b5 100%);
  --tp-shadow-lg: 0 1px 2px rgba(9, 33, 74, 0.06), 0 12px 28px rgba(9, 33, 74, 0.14), 0 32px 72px rgba(9, 33, 74, 0.18);
  --tp-shadow-sm: 0 1px 2px rgba(9, 33, 74, 0.06), 0 2px 8px rgba(9, 33, 74, 0.06);
}

/* ---------- Avatar ---------- */
.tupsep-avatar {
  position: relative;
  display: inline-grid;
  place-items: center;
  flex: none;
  width: 36px;
  height: 36px;
  border-radius: 11px;
  background:
    radial-gradient(120% 90% at 20% 10%, rgba(255, 255, 255, 0.45), transparent 55%),
    linear-gradient(145deg, #12b5b0 0%, #0a7fd6 55%, #1d4fd8 100%);
  color: #fff;
  font-weight: 800;
  font-size: 16px;
  letter-spacing: -0.02em;
  box-shadow: inset 0 0 0 1px rgba(255, 255, 255, 0.25), 0 4px 10px rgba(7, 86, 216, 0.28);
}
.tupsep-avatar::after {
  content: "";
  position: absolute;
  top: -3px;
  right: -3px;
  width: 9px;
  height: 9px;
  background: #ffd166;
  clip-path: polygon(50% 0, 62% 38%, 100% 50%, 62% 62%, 50% 100%, 38% 62%, 0 50%, 38% 38%);
}
.tupsep-avatar-sm { width: 28px; height: 28px; border-radius: 9px; font-size: 13px; }
.tupsep-avatar-sm::after { width: 7px; height: 7px; top: -2px; right: -2px; }
.tupsep-avatar-lg { width: 56px; height: 56px; border-radius: 16px; font-size: 24px; }
.tupsep-avatar-lg::after { width: 13px; height: 13px; top: -4px; right: -4px; }

/* ---------- Botón flotante ---------- */
.tupsep-launcher {
  position: fixed;
  right: 22px;
  bottom: 22px;
  z-index: 60;
  display: inline-flex;
  align-items: center;
  gap: 11px;
  padding: 7px 18px 7px 7px;
  border: 1px solid rgba(255, 255, 255, 0.12);
  border-radius: 999px;
  background: var(--tp-grad);
  color: #fff;
  box-shadow: var(--tp-shadow-lg);
  cursor: pointer;
  font: inherit;
  text-align: left;
  transition: transform 0.18s ease, box-shadow 0.18s ease;
}
.tupsep-launcher:hover { transform: translateY(-2px); box-shadow: 0 16px 40px rgba(6, 46, 97, 0.32); }
.tupsep-launcher:active { transform: translateY(0); }
.tupsep-launcher:focus-visible { outline: 3px solid var(--warm, #f27a1a); outline-offset: 3px; }
.tupsep-launcher-text { display: flex; flex-direction: column; line-height: 1.2; }
.tupsep-launcher-text strong { font-size: 14px; letter-spacing: 0.06em; }
.tupsep-launcher-text small { display: inline-flex; align-items: center; gap: 6px; font-size: 12px; color: rgba(255, 255, 255, 0.78); }

.tupsep-dot {
  display: inline-block;
  flex: none;
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: var(--tp-online, #22c55e);
  box-shadow: 0 0 0 0 rgba(34, 197, 94, 0.55);
  animation: tupsep-pulse 2.4s infinite;
}
@keyframes tupsep-pulse {
  0% { box-shadow: 0 0 0 0 rgba(34, 197, 94, 0.5); }
  70% { box-shadow: 0 0 0 6px rgba(34, 197, 94, 0); }
  100% { box-shadow: 0 0 0 0 rgba(34, 197, 94, 0); }
}

/* ---------- Panel ---------- */
.tupsep-panel {
  position: fixed;
  right: 22px;
  bottom: 22px;
  z-index: 61;
  display: flex;
  flex-direction: column;
  width: min(420px, calc(100vw - 32px));
  height: min(660px, calc(100vh - 44px));
  border: 1px solid rgba(9, 33, 74, 0.08);
  border-radius: 20px;
  background: var(--tp-paper);
  color: var(--tp-ink);
  box-shadow: var(--tp-shadow-lg);
  overflow: hidden;
  transform-origin: bottom right;
  animation: tupsep-open 0.22s cubic-bezier(0.2, 0.9, 0.3, 1.1);
}
@keyframes tupsep-open {
  from { opacity: 0; transform: translateY(12px) scale(0.97); }
  to { opacity: 1; transform: none; }
}

.tupsep-head {
  position: relative;
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 16px 14px 16px 16px;
  background:
    radial-gradient(90% 140% at 100% 0%, rgba(18, 181, 176, 0.28), transparent 60%),
    radial-gradient(70% 120% at 0% 100%, rgba(29, 79, 216, 0.35), transparent 60%),
    var(--tp-grad);
  color: #fff;
}
.tupsep-head::after {
  content: "";
  position: absolute;
  inset: 0;
  background-image: radial-gradient(rgba(255, 255, 255, 0.09) 1px, transparent 1px);
  background-size: 14px 14px;
  mask-image: linear-gradient(90deg, transparent 30%, #000 100%);
  -webkit-mask-image: linear-gradient(90deg, transparent 30%, #000 100%);
  pointer-events: none;
}
.tupsep-head .tupsep-avatar { width: 42px; height: 42px; border-radius: 13px; font-size: 18px; box-shadow: inset 0 0 0 1px rgba(255, 255, 255, 0.3), 0 0 0 3px rgba(255, 255, 255, 0.12); }
.tupsep-head > div { position: relative; z-index: 1; flex: 1; min-width: 0; }
.tupsep-head h2 { margin: 0; font-size: 16px; font-weight: 800; letter-spacing: 0.07em; }
.tupsep-status { display: flex; align-items: center; gap: 7px; margin: 3px 0 0; font-size: 12.5px; color: rgba(255, 255, 255, 0.8); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.tupsep-icon-btn {
  position: relative;
  z-index: 1;
  display: inline-grid;
  place-items: center;
  width: 34px;
  height: 34px;
  border: 1px solid rgba(255, 255, 255, 0.14);
  border-radius: 10px;
  background: rgba(255, 255, 255, 0.08);
  color: #fff;
  cursor: pointer;
  transition: background 0.15s ease;
}
.tupsep-icon-btn svg { width: 17px; height: 17px; }
.tupsep-icon-btn:hover { background: rgba(255, 255, 255, 0.2); }
.tupsep-icon-btn:focus-visible { outline: 2px solid #fff; outline-offset: 2px; }

/* ---------- Contexto de pregunta ---------- */
.tupsep-context {
  display: flex;
  align-items: center;
  gap: 10px;
  margin: 12px 14px 0;
  padding: 9px 10px 9px 12px;
  border: 1px solid #cfe0fb;
  border-left: 3px solid var(--tp-blue);
  border-radius: 10px;
  background: var(--info-soft, #eaf2ff);
  color: var(--tp-navy);
  font-size: 13px;
}
.tupsep-context svg { flex: none; width: 16px; height: 16px; color: var(--tp-blue); }
.tupsep-context span { flex: 1; min-width: 0; }
.tupsep-context button {
  flex: none;
  padding: 4px 9px;
  border: 1px solid #cfe0fb;
  border-radius: 7px;
  background: #fff;
  color: var(--tp-blue);
  font: inherit;
  font-size: 12.5px;
  font-weight: 600;
  cursor: pointer;
}
.tupsep-context button:hover { border-color: var(--tp-blue); }

/* ---------- Conversación ---------- */
.tupsep-log {
  flex: 1;
  display: flex;
  flex-direction: column;
  gap: 14px;
  padding: 18px 16px;
  overflow-y: auto;
  background: linear-gradient(180deg, #f7f9fd 0%, var(--tp-bg) 100%);
  scroll-behavior: smooth;
}
.tupsep-log::-webkit-scrollbar { width: 8px; }
.tupsep-log::-webkit-scrollbar-thumb { background: #cfd9e8; border-radius: 8px; border: 2px solid var(--tp-bg); }

.tupsep-row { display: flex; align-items: flex-end; gap: 8px; animation: tupsep-in 0.2s ease-out; }
.tupsep-row-user { justify-content: flex-end; }
@keyframes tupsep-in { from { opacity: 0; transform: translateY(4px); } to { opacity: 1; transform: none; } }

.tupsep-msg {
  max-width: 84%;
  padding: 11px 14px;
  border-radius: 16px;
  font-size: 14.5px;
  line-height: 1.55;
  overflow-wrap: anywhere;
}
.tupsep-msg p { margin: 0 0 8px; }
.tupsep-msg p:last-child { margin-bottom: 0; }
.tupsep-msg ul, .tupsep-msg ol { margin: 4px 0 8px; padding-left: 20px; }
.tupsep-msg li { margin: 2px 0; }
.tupsep-msg li::marker { color: var(--tp-blue); font-weight: 700; }
.tupsep-msg strong { color: var(--tp-navy); }
.tupsep-model {
  background: var(--tp-paper);
  border: 1px solid rgba(9, 33, 74, 0.07);
  border-bottom-left-radius: 5px;
  box-shadow: var(--tp-shadow-sm);
}
.tupsep-user {
  background: var(--tp-user);
  color: #fff;
  border-bottom-right-radius: 5px;
  box-shadow: 0 4px 14px rgba(7, 86, 216, 0.25);
}
.tupsep-user strong { color: #fff; }

.tupsep-error {
  display: flex;
  gap: 10px;
  border-color: #f5d9a8;
  background: var(--warning-soft, #fff7e8);
}
.tupsep-error > svg { flex: none; width: 18px; height: 18px; margin-top: 2px; color: #c47a06; }
.tupsep-retry {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  margin-top: 8px;
  padding: 5px 11px;
  border: 1px solid #e9c783;
  border-radius: 8px;
  background: #fff;
  color: #8a5300;
  font: inherit;
  font-size: 13px;
  font-weight: 700;
  cursor: pointer;
}
.tupsep-retry svg { width: 14px; height: 14px; }
.tupsep-retry:hover { border-color: #c47a06; }

/* Bienvenida */
.tupsep-welcome { display: flex; flex-direction: column; align-items: center; gap: 10px; padding: 6px 4px 2px; text-align: center; }
.tupsep-welcome h3 { margin: 6px 0 0; font-size: 18px; color: var(--tp-navy); }
.tupsep-welcome p { margin: 0; max-width: 320px; color: var(--tp-muted); font-size: 14px; line-height: 1.5; }
.tupsep-subjects { display: flex; flex-wrap: wrap; justify-content: center; gap: 6px; margin-top: 4px; }
.tupsep-subjects span {
  padding: 3px 9px;
  border-radius: 999px;
  font-size: 12px;
  font-weight: 700;
  letter-spacing: 0.01em;
}
.tupsep-subjects span:nth-child(1) { background: #eaf2ff; color: #0756d8; }
.tupsep-subjects span:nth-child(2) { background: #e6f7f3; color: #07866f; }
.tupsep-subjects span:nth-child(3) { background: #f0ebff; color: #6a3fd0; }
.tupsep-subjects span:nth-child(4) { background: #e5f6f6; color: #067f82; }
.tupsep-subjects span:nth-child(5) { background: #fff1e5; color: #c25b0a; }

.tupsep-starters { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }
.tupsep-starters button {
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  gap: 6px;
  padding: 11px 12px;
  border: 1px solid rgba(9, 33, 74, 0.08);
  border-radius: 12px;
  background: var(--tp-paper);
  color: var(--tp-ink);
  box-shadow: var(--tp-shadow-sm);
  font: inherit;
  font-size: 13px;
  line-height: 1.35;
  text-align: left;
  cursor: pointer;
  transition: border-color 0.15s ease, transform 0.15s ease, box-shadow 0.15s ease;
}
.tupsep-starters button:hover { border-color: rgba(7, 86, 216, 0.45); transform: translateY(-1px); box-shadow: 0 6px 16px rgba(9, 33, 74, 0.1); }
.tupsep-starters button:focus-visible { outline: 2px solid var(--tp-blue); outline-offset: 2px; }
.tupsep-starter-tag { font-size: 11px; font-weight: 800; letter-spacing: 0.06em; text-transform: uppercase; color: var(--tp-blue); }

/* Escribiendo */
.tupsep-typing { display: inline-flex; align-items: center; gap: 5px; padding: 14px 16px; }
.tupsep-typing span {
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: var(--tp-blue);
  opacity: 0.35;
  animation: tupsep-bounce 1.1s infinite ease-in-out;
}
.tupsep-typing span:nth-child(2) { animation-delay: 0.15s; }
.tupsep-typing span:nth-child(3) { animation-delay: 0.3s; }
@keyframes tupsep-bounce { 0%, 80%, 100% { opacity: 0.3; transform: translateY(0); } 40% { opacity: 1; transform: translateY(-4px); } }

/* ---------- Redactor ---------- */
.tupsep-form {
  padding: 12px 14px 8px;
  border-top: 1px solid rgba(9, 33, 74, 0.06);
  background: var(--tp-paper);
}
.tupsep-composer {
  display: flex;
  align-items: flex-end;
  gap: 8px;
  padding: 6px 6px 6px 14px;
  border: 1px solid var(--tp-line);
  border-radius: 16px;
  background: #fbfcfe;
  transition: border-color 0.15s ease, box-shadow 0.15s ease;
}
.tupsep-composer:focus-within { border-color: var(--tp-blue); background: #fff; box-shadow: 0 0 0 4px rgba(7, 86, 216, 0.12); }
.tupsep-form textarea {
  flex: 1;
  min-height: 24px;
  max-height: 140px;
  padding: 8px 0;
  border: 0;
  background: transparent;
  color: var(--tp-ink);
  font: inherit;
  font-size: 14.5px;
  line-height: 1.45;
  resize: none;
  outline: none;
}
.tupsep-form textarea::placeholder { color: #8896ad; }
.tupsep-send {
  display: inline-grid;
  place-items: center;
  flex: none;
  width: 38px;
  height: 38px;
  border: 0;
  border-radius: 12px;
  background: var(--tp-user);
  color: #fff;
  box-shadow: 0 4px 12px rgba(7, 86, 216, 0.3);
  cursor: pointer;
  transition: transform 0.15s ease, opacity 0.15s ease;
}
.tupsep-send svg { width: 18px; height: 18px; }
.tupsep-send:hover:not(:disabled) { transform: translateY(-1px); }
.tupsep-send:focus-visible { outline: 2px solid var(--tp-navy); outline-offset: 2px; }
.tupsep-send:disabled { opacity: 0.45; cursor: default; box-shadow: none; }
.tupsep-meta { display: flex; justify-content: space-between; gap: 8px; margin-top: 6px; padding: 0 4px; color: #8896ad; font-size: 11.5px; }
.tupsep-meta > span:first-child { min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.tupsep-meta [data-tupsep="remaining"] { flex: none; white-space: nowrap; }
.tupsep-meta [data-tupsep="remaining"]:not(:empty) { color: var(--tp-navy); font-weight: 600; }

.tupsep-foot {
  display: flex;
  gap: 6px;
  margin: 0;
  padding: 0 18px 12px;
  background: var(--tp-paper);
  color: var(--tp-muted);
  font-size: 11px;
  line-height: 1.4;
}
.tupsep-foot svg { flex: none; width: 13px; height: 13px; margin-top: 1px; opacity: 0.7; }
.tupsep-sr { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }

/* ---------- Botón "Pregúntale" del solucionario ---------- */
.tupsep-ask {
  display: inline-flex;
  align-items: center;
  gap: 9px;
  margin-top: 10px;
  padding: 6px 14px 6px 6px;
  border: 1px solid rgba(7, 86, 216, 0.25);
  border-radius: 999px;
  background: linear-gradient(180deg, #fff 0%, #f1f6ff 100%);
  color: var(--tp-navy);
  box-shadow: var(--tp-shadow-sm);
  font: inherit;
  font-size: 14px;
  font-weight: 700;
  cursor: pointer;
  transition: border-color 0.15s ease, box-shadow 0.15s ease;
}
.tupsep-ask .tupsep-avatar { width: 26px; height: 26px; border-radius: 8px; font-size: 12px; }
.tupsep-ask .tupsep-avatar::after { width: 7px; height: 7px; top: -2px; right: -2px; }
.tupsep-ask:hover { border-color: var(--tp-blue); box-shadow: 0 4px 14px rgba(7, 86, 216, 0.16); }

@media (prefers-reduced-motion: reduce) {
  .tupsep-panel, .tupsep-row, .tupsep-typing span, .tupsep-dot { animation: none; }
  .tupsep-launcher, .tupsep-starters button, .tupsep-send { transition: none; }
}

@media (max-width: 560px) {
  .tupsep-launcher { right: 14px; bottom: 14px; }
  .tupsep-launcher-text small { display: none; }
  .tupsep-panel { right: 0; bottom: 0; width: 100vw; height: 100dvh; max-height: 100dvh; border-radius: 0; border: 0; }
  .tupsep-head { padding-top: max(16px, env(safe-area-inset-top)); }
  .tupsep-form { padding-bottom: max(8px, env(safe-area-inset-bottom)); }
  .tupsep-starters { grid-template-columns: 1fr; }
  .tupsep-msg { max-width: 88%; }
}

@media print {
  .tupsep-launcher, .tupsep-panel, .tupsep-ask { display: none !important; }
}
