/* ==========================================================================
   HUD — Monitor cognitivo sci-fi
   Los valores de tema se sobrescriben en runtime desde config/client_profile.json
   ========================================================================== */
:root {
  --bg: #05070a;
  --panel-bg: rgba(10, 16, 24, 0.55);
  --panel-border: rgba(120, 200, 255, 0.18);
  --accent: #38e1ff;
  --text: #e6f1ff;
  --text-dim: #7f93ad;
  --font-mono: 'Geist Mono', ui-monospace, monospace;
  --font-sans: 'Geist', system-ui, sans-serif;
  --gutter: 20px;
  --radius: 10px;
  --glow: 0 0 18px color-mix(in srgb, var(--accent) 35%, transparent);
  color-scheme: dark;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  height: 100%;
  overflow: hidden;
  background: var(--bg);
  color: var(--text);
  font-family: var(--font-sans);
  -webkit-font-smoothing: antialiased;
}

#stage { position: fixed; inset: 0; }
#stage canvas { display: block; }

/* Viñeta + líneas de barrido muy sutiles */
.scanlines {
  position: fixed; inset: 0; pointer-events: none; z-index: 1;
  background:
    radial-gradient(ellipse at center, transparent 55%, rgba(0, 0, 0, 0.55) 100%),
    repeating-linear-gradient(to bottom, rgba(255, 255, 255, 0.018) 0 1px, transparent 1px 3px);
}

/* ------------------------------------------------------------------ Panels */
.panel {
  position: fixed; z-index: 5;
  background: var(--panel-bg);
  border: 1px solid var(--panel-border);
  border-radius: var(--radius);
  backdrop-filter: blur(12px) saturate(140%);
  -webkit-backdrop-filter: blur(12px) saturate(140%);
  box-shadow: 0 10px 40px rgba(0, 0, 0, 0.45), inset 0 1px 0 rgba(255, 255, 255, 0.04);
}
.panel::before { /* esquinas tipo HUD */
  content: ""; position: absolute; inset: -1px; border-radius: inherit; pointer-events: none;
  background:
    linear-gradient(var(--accent), var(--accent)) top left / 14px 1px no-repeat,
    linear-gradient(var(--accent), var(--accent)) top left / 1px 14px no-repeat,
    linear-gradient(var(--accent), var(--accent)) bottom right / 14px 1px no-repeat,
    linear-gradient(var(--accent), var(--accent)) bottom right / 1px 14px no-repeat;
  opacity: 0.7;
}

/* --------------------------------------------------------- Control (top-left) */
.panel--control {
  top: var(--gutter); left: var(--gutter);
  width: 330px; max-height: calc(100vh - 220px);
  display: flex; flex-direction: column; gap: 16px; padding: 16px;
}

.metrics { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; }
.metric {
  display: flex; flex-direction: column; gap: 4px; padding: 8px 10px;
  border: 1px solid var(--panel-border); border-radius: 6px;
  background: rgba(255, 255, 255, 0.02);
}
.metric__label {
  font-family: var(--font-mono); font-size: 8.5px; letter-spacing: 0.12em;
  color: var(--text-dim); line-height: 1.25;
}
.metric__value {
  font-family: var(--font-mono); font-size: 20px; font-weight: 600;
  color: var(--accent); text-shadow: var(--glow); font-variant-numeric: tabular-nums;
}

.search { display: flex; flex-direction: column; gap: 6px; }
.search__label, .regions__head, .inspector__kicker, .inspector__section h3 {
  font-family: var(--font-mono); font-size: 10px; letter-spacing: 0.22em; color: var(--accent);
}
.search__field {
  display: flex; align-items: center; gap: 8px; padding: 0 12px;
  border: 1px solid var(--panel-border); border-radius: 6px; background: rgba(0, 0, 0, 0.35);
  transition: border-color .2s, box-shadow .2s;
}
.search__field:focus-within { border-color: var(--accent); box-shadow: var(--glow); }
.search__icon { color: var(--accent); font-size: 16px; }
.search input {
  flex: 1; min-width: 0; height: 38px; border: 0; outline: 0; background: transparent;
  color: var(--text); font-family: var(--font-mono); font-size: 13px;
}
.search input::placeholder { color: var(--text-dim); opacity: .7; }
.search input::-webkit-search-cancel-button { filter: invert(1) opacity(.5); }
.search__meta {
  display: flex; justify-content: space-between; min-height: 14px;
  font-family: var(--font-mono); font-size: 9.5px; letter-spacing: 0.1em; color: var(--text-dim);
}
#search-count { color: var(--accent); }

.regions { display: flex; flex-direction: column; gap: 8px; min-height: 0; }
.regions__head { display: flex; justify-content: space-between; align-items: center; }
.regions__list {
  list-style: none; margin: 0; padding: 0 4px 0 0; overflow-y: auto; min-height: 0;
  display: flex; flex-direction: column; gap: 2px;
  scrollbar-width: thin; scrollbar-color: var(--panel-border) transparent;
}
.region {
  display: grid; grid-template-columns: 10px 1fr auto; align-items: center; gap: 10px;
  padding: 7px 8px; border-radius: 5px; cursor: pointer; border: 1px solid transparent;
  font-size: 12px; color: var(--text); transition: background .15s, opacity .2s, border-color .15s;
}
.region:hover { background: rgba(255, 255, 255, 0.05); }
.region.is-active { border-color: var(--c); background: color-mix(in srgb, var(--c) 12%, transparent); }
.region.is-muted { opacity: 0.3; }
.region.is-hidden { display: none; }
.region__dot { width: 8px; height: 8px; border-radius: 50%; background: var(--c); box-shadow: 0 0 8px var(--c); }
.region__name { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.region__count { font-family: var(--font-mono); font-size: 10px; color: var(--text-dim); }
.region.has-hits .region__count { color: var(--c); }

.chip {
  font-family: var(--font-mono); font-size: 9px; letter-spacing: 0.15em;
  color: var(--text-dim); background: transparent; cursor: pointer;
  border: 1px solid var(--panel-border); border-radius: 4px; padding: 4px 8px;
}
.chip:hover { color: var(--accent); border-color: var(--accent); }

/* ------------------------------------------------------------- Brand (bottom-left) */
.brand {
  position: fixed; z-index: 4; left: var(--gutter); bottom: var(--gutter);
  max-width: 420px; pointer-events: none;
}
.brand__title {
  margin: 0; font-family: var(--font-mono); font-weight: 600; font-size: 28px;
  letter-spacing: 0.18em; text-shadow: var(--glow);
}
.brand__subtitle { margin: 6px 0 0; font-size: 13px; color: var(--text); opacity: .85; }
.brand__tagline {
  margin: 6px 0 0; font-family: var(--font-mono); font-size: 10px; letter-spacing: 0.18em;
  color: var(--text-dim);
}

/* ------------------------------------------------------------- Status (bottom-center) */
.panel--status {
  left: 50%; bottom: var(--gutter); transform: translateX(-50%);
  display: flex; gap: 18px; padding: 10px 16px; white-space: nowrap;
  font-family: var(--font-mono); font-size: 10px; letter-spacing: 0.12em; color: var(--text-dim);
}
.status__item { display: inline-flex; align-items: center; gap: 6px; }
.status__item b { font-weight: 400; color: var(--text-dim); opacity: .7; }
.status__item span { color: var(--text); font-variant-numeric: tabular-nums; }
.dot { width: 6px; height: 6px; border-radius: 50%; display: inline-block; }
.dot--live { background: #3dff9a; box-shadow: 0 0 8px #3dff9a; animation: blink 2.4s infinite; }
@keyframes blink { 50% { opacity: .35; } }

/* ------------------------------------------------------------- Legend (bottom-right) */
.panel--legend {
  right: var(--gutter); bottom: var(--gutter); padding: 12px 14px;
  display: flex; flex-direction: column; gap: 8px;
  font-family: var(--font-mono); font-size: 10px; letter-spacing: 0.12em; color: var(--text-dim);
}
.legend__row { display: flex; align-items: center; gap: 8px; }
.legend__row b { color: var(--text); font-weight: 400; }
.legend__glyph { display: inline-flex; align-items: center; gap: 3px; width: 34px; }
.legend__glyph--size i { display: block; border-radius: 50%; background: var(--accent); box-shadow: 0 0 6px var(--accent); }
.legend__glyph--size i:nth-child(1) { width: 4px; height: 4px; }
.legend__glyph--size i:nth-child(2) { width: 7px; height: 7px; }
.legend__glyph--size i:nth-child(3) { width: 10px; height: 10px; }
.legend__glyph--line { height: 1px; background: linear-gradient(90deg, transparent, var(--accent), transparent); }
.legend__glyph--chunk::before, .legend__glyph--concept::before {
  content: ""; width: 8px; height: 8px; border-radius: 50%; background: var(--accent); opacity: .75;
}
.legend__glyph--chunk, .legend__glyph--concept { width: 12px; }
.legend__glyph--concept::before {
  width: 10px; height: 10px; background: radial-gradient(circle, #fff 0 30%, var(--accent) 60%);
  box-shadow: 0 0 0 2px rgba(255,255,255,.15), 0 0 10px var(--accent); opacity: 1;
}

/* ------------------------------------------------------------- Inspector (right) */
.panel--inspector {
  top: var(--gutter); right: var(--gutter); bottom: 120px;
  width: min(420px, calc(100vw - 2 * var(--gutter)));
  padding: 18px; display: flex; flex-direction: column; gap: 14px; overflow-y: auto;
  transform: translateX(calc(100% + 40px)); opacity: 0;
  transition: transform .45s cubic-bezier(.2, .8, .2, 1), opacity .3s;
  scrollbar-width: thin; scrollbar-color: var(--panel-border) transparent;
}
.panel--inspector.is-open { transform: none; opacity: 1; }
.inspector__head { display: flex; justify-content: space-between; align-items: center; }
.inspector__title {
  margin: 0; font-size: 17px; font-weight: 600; line-height: 1.35;
  border-left: 2px solid var(--c, var(--accent)); padding-left: 10px;
}
.inspector__facts {
  margin: 0; display: grid; grid-template-columns: 1fr 1fr; gap: 8px;
}
.inspector__facts div {
  padding: 7px 9px; border: 1px solid var(--panel-border); border-radius: 6px; min-width: 0;
}
.inspector__facts dt { font-family: var(--font-mono); font-size: 8.5px; letter-spacing: .14em; color: var(--text-dim); }
.inspector__facts dd {
  margin: 3px 0 0; font-family: var(--font-mono); font-size: 11.5px; color: var(--text);
  overflow-wrap: anywhere;
}
#i-cluster { color: var(--c, var(--accent)); }
.inspector__keywords { display: flex; flex-wrap: wrap; gap: 6px; }
.inspector__keywords span {
  font-family: var(--font-mono); font-size: 10px; padding: 3px 7px; border-radius: 3px;
  color: var(--c, var(--accent)); background: color-mix(in srgb, var(--c, var(--accent)) 12%, transparent);
}
.inspector__section { display: flex; flex-direction: column; gap: 8px; }
.inspector__section h3 { margin: 0; }
.inspector__text {
  white-space: pre-wrap; overflow-wrap: anywhere; font-size: 12.5px; line-height: 1.6;
  color: color-mix(in srgb, var(--text) 85%, transparent);
  max-height: 34vh; overflow-y: auto; padding: 10px 12px; border-radius: 6px;
  background: rgba(0, 0, 0, 0.3); border: 1px solid var(--panel-border);
  scrollbar-width: thin; scrollbar-color: var(--panel-border) transparent;
}
.inspector__text mark { background: color-mix(in srgb, var(--accent) 30%, transparent); color: inherit; }

.neighbors { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 2px; }
.neighbor {
  display: grid; grid-template-columns: 8px 1fr auto; gap: 10px; align-items: center;
  padding: 7px 8px; border-radius: 5px; cursor: pointer; font-size: 12px;
  border: 1px solid transparent; transition: background .15s, border-color .15s;
}
.neighbor:hover { background: rgba(255, 255, 255, .05); border-color: var(--panel-border); }
.neighbor__dot { width: 7px; height: 7px; border-radius: 50%; background: var(--c); box-shadow: 0 0 6px var(--c); }
.neighbor__dot.is-concept { border-radius: 1px; transform: rotate(45deg); }
.neighbor__label { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.neighbor__meta { font-family: var(--font-mono); font-size: 9.5px; color: var(--text-dim); white-space: nowrap; }

/* ------------------------------------------------------------- Tooltip */
.tooltip {
  position: fixed; z-index: 20; pointer-events: none; max-width: 300px;
  padding: 9px 11px; border-radius: 6px; display: flex; flex-direction: column; gap: 4px;
  background: rgba(5, 9, 14, 0.82); border: 1px solid var(--c, var(--accent));
  backdrop-filter: blur(12px); -webkit-backdrop-filter: blur(12px);
  box-shadow: 0 0 20px color-mix(in srgb, var(--c, var(--accent)) 25%, transparent);
}
.tooltip[hidden] { display: none; }
.tooltip__meta { font-family: var(--font-mono); font-size: 9px; letter-spacing: .14em; color: var(--c, var(--accent)); }
.tooltip__title { font-size: 12.5px; font-weight: 600; }
.tooltip__body { font-size: 11.5px; line-height: 1.45; color: var(--text-dim); }

/* ------------------------------------------------------------- Loader */
.loader {
  position: fixed; inset: 0; z-index: 50; display: grid; place-content: center; justify-items: center; gap: 18px;
  background: var(--bg); transition: opacity .8s;
}
.loader.is-done { opacity: 0; pointer-events: none; }
.loader__ring {
  width: 54px; height: 54px; border-radius: 50%;
  border: 1px solid var(--panel-border); border-top-color: var(--accent);
  animation: spin 1s linear infinite; box-shadow: var(--glow);
}
.loader__text { font-family: var(--font-mono); font-size: 11px; letter-spacing: .22em; color: var(--text-dim); max-width: 80vw; text-align: center; }
.loader.is-error .loader__ring { border-top-color: #ff5e5e; animation: none; }
@keyframes spin { to { transform: rotate(360deg); } }

/* ------------------------------------------------------------- Responsive */
@media (max-width: 1100px) {
  .panel--status { display: none; }
}
@media (max-width: 720px) {
  :root { --gutter: 16px; }
  .panel--control { width: calc(100vw - 2 * var(--gutter)); max-height: 46vh; padding: 12px; gap: 12px; }
  .metric__value { font-size: 16px; }
  .panel--legend { display: none; }
  .brand__title { font-size: 18px; }
  .brand__subtitle, .brand__tagline { display: none; }
  .panel--inspector { top: auto; bottom: var(--gutter); max-height: 62vh; transform: translateY(calc(100% + 40px)); }
  .tooltip { display: none !important; }
}
@media (prefers-reduced-motion: reduce) {
  .dot--live, .loader__ring { animation: none; }
  .panel--inspector { transition: opacity .2s; }
}

/* ==========================================================================
   Agente conversacional (drawer derecho) — el inspector se superpone encima
   ========================================================================== */
.panel--chat {
  top: var(--gutter); right: var(--gutter); bottom: 120px; z-index: 6;
  width: min(410px, calc(100vw - 2 * var(--gutter)));
  display: flex; flex-direction: column; overflow: hidden;
  transition: transform .45s cubic-bezier(.2, .8, .2, 1), opacity .3s;
}
.panel--chat.is-collapsed { transform: translateX(calc(100% + 40px)); opacity: 0; pointer-events: none; }
.panel--inspector { z-index: 8; }

.chat-launcher {
  position: fixed; z-index: 6; top: var(--gutter); right: var(--gutter);
  font-family: var(--font-mono); font-size: 10px; letter-spacing: .2em; color: var(--accent);
  padding: 10px 14px; border-radius: 8px; cursor: pointer;
  background: var(--panel-bg); border: 1px solid var(--panel-border);
  backdrop-filter: blur(12px); -webkit-backdrop-filter: blur(12px); box-shadow: var(--glow);
}
.chat-launcher:hover { border-color: var(--accent); }
.chat-launcher[hidden] { display: none; }

.chat__head {
  display: flex; justify-content: space-between; align-items: flex-start; gap: 12px;
  padding: 16px 16px 12px; border-bottom: 1px solid var(--panel-border);
}
.chat__kicker {
  display: inline-flex; align-items: center; gap: 8px;
  font-family: var(--font-mono); font-size: 10px; letter-spacing: .22em; color: var(--accent);
}
.chat__title { margin: 6px 0 0; font-size: 15px; font-weight: 600; }
.chat__actions { display: flex; flex-direction: column; align-items: flex-end; gap: 6px; }
.chat__mode {
  font-family: var(--font-mono); font-size: 9px; letter-spacing: .16em; color: var(--text-dim);
  padding: 3px 7px; border: 1px solid var(--panel-border); border-radius: 3px;
}
.chat__mode[data-mode="llm"] { color: #3dff9a; border-color: rgba(61, 255, 154, .35); }
.chat__mode[data-mode="extractive"] { color: #ffb238; border-color: rgba(255, 178, 56, .35); }
.chat__mode:empty { display: none; }

.chat__log {
  flex: 1; min-height: 0; overflow-y: auto; padding: 14px 16px; display: flex; flex-direction: column; gap: 14px;
  scrollbar-width: thin; scrollbar-color: var(--panel-border) transparent;
}
.msg { display: flex; flex-direction: column; gap: 6px; animation: msg-in .35s ease-out; }
@keyframes msg-in { from { opacity: 0; transform: translateY(6px); } }
.msg__who { font-family: var(--font-mono); font-size: 9px; letter-spacing: .2em; color: var(--text-dim); }
.msg--user { align-items: flex-end; }
.msg--user .msg__body {
  background: color-mix(in srgb, var(--accent) 12%, transparent);
  border: 1px solid color-mix(in srgb, var(--accent) 30%, transparent);
  border-radius: 10px 10px 2px 10px; max-width: 88%;
}
.msg--agent .msg__body {
  border-left: 2px solid var(--accent); padding-left: 12px; border-radius: 0;
}
.msg__body {
  padding: 9px 12px; font-size: 13px; line-height: 1.6; white-space: pre-wrap; overflow-wrap: anywhere;
  color: color-mix(in srgb, var(--text) 92%, transparent);
}
.msg__body.is-typing::after {
  content: ""; display: inline-block; width: 7px; height: 14px; margin-left: 2px; vertical-align: -2px;
  background: var(--accent); box-shadow: var(--glow); animation: blink .8s steps(2) infinite;
}
.msg--system .msg__body { color: var(--text-dim); font-size: 12px; padding-left: 0; }
.msg--error .msg__body { color: #ff8a8a; border-left-color: #ff5e5e; }
.msg__note { font-family: var(--font-mono); font-size: 9px; letter-spacing: .08em; color: var(--text-dim); }
.cite {
  font-family: var(--font-mono); font-size: 10px; color: var(--accent); cursor: pointer;
  padding: 0 3px; border-radius: 3px; background: color-mix(in srgb, var(--accent) 10%, transparent);
}
.cite:hover { background: color-mix(in srgb, var(--accent) 25%, transparent); }

.msg__sources { display: flex; flex-direction: column; gap: 6px; margin-top: 2px; }
.msg__sources-label { font-family: var(--font-mono); font-size: 9px; letter-spacing: .2em; color: var(--accent); }
.chips { display: flex; flex-wrap: wrap; gap: 6px; }
.mem-chip {
  display: inline-flex; align-items: center; gap: 6px; max-width: 100%;
  font-size: 11px; color: var(--text); padding: 4px 9px 4px 7px; border-radius: 999px; cursor: pointer;
  background: color-mix(in srgb, var(--c) 10%, rgba(0, 0, 0, .3));
  border: 1px solid color-mix(in srgb, var(--c) 40%, transparent);
  transition: background .15s, box-shadow .15s; animation: msg-in .3s ease-out backwards;
}
.mem-chip:hover { background: color-mix(in srgb, var(--c) 22%, transparent); box-shadow: 0 0 10px color-mix(in srgb, var(--c) 40%, transparent); }
.mem-chip i { width: 6px; height: 6px; border-radius: 50%; background: var(--c); box-shadow: 0 0 6px var(--c); flex: none; }
.mem-chip.is-concept i { border-radius: 1px; transform: rotate(45deg); }
.mem-chip span { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; max-width: 220px; }

.thinking { display: inline-flex; align-items: center; gap: 10px; font-family: var(--font-mono); font-size: 10px; letter-spacing: .2em; color: var(--accent); }
.thinking i { width: 5px; height: 5px; border-radius: 50%; background: var(--accent); animation: think 1s infinite ease-in-out; }
.thinking i:nth-child(2) { animation-delay: .15s; }
.thinking i:nth-child(3) { animation-delay: .3s; }
@keyframes think { 50% { transform: scale(1.8); opacity: .4; } }

.chat__suggestions { display: flex; flex-direction: column; gap: 6px; padding: 0 16px 10px; }
.chat__suggestions[hidden] { display: none; }
.chat__suggestions-label { font-family: var(--font-mono); font-size: 9px; letter-spacing: .2em; color: var(--text-dim); }
.suggestion {
  text-align: left; font: inherit; font-size: 12px; color: var(--text); cursor: pointer;
  background: rgba(255, 255, 255, .03); border: 1px solid var(--panel-border); border-radius: 6px; padding: 7px 10px;
}
.suggestion:hover { border-color: var(--accent); color: var(--accent); }

.chat__form {
  display: flex; gap: 8px; align-items: flex-end; padding: 12px 16px 16px; border-top: 1px solid var(--panel-border);
}
.chat__form textarea {
  flex: 1; min-width: 0; resize: none; max-height: 140px; min-height: 40px;
  font: inherit; font-size: 13px; line-height: 1.45; color: var(--text);
  background: rgba(0, 0, 0, .35); border: 1px solid var(--panel-border); border-radius: 6px; padding: 10px 12px; outline: 0;
}
.chat__form textarea:focus { border-color: var(--accent); box-shadow: var(--glow); }
.chat__form textarea::placeholder { color: var(--text-dim); }
.chat__send {
  font-family: var(--font-mono); font-size: 10px; letter-spacing: .18em; height: 40px; padding: 0 14px; cursor: pointer;
  color: var(--bg); background: var(--accent); border: 0; border-radius: 6px; box-shadow: var(--glow);
}
.chat__send:disabled { opacity: .4; cursor: progress; }

@media (max-width: 720px) {
  .panel--chat { top: auto; bottom: var(--gutter); height: 58vh; }
  .panel--chat.is-collapsed { transform: translateY(calc(100% + 40px)); }
  .chat-launcher { top: auto; bottom: var(--gutter); }
}
@media (prefers-reduced-motion: reduce) {
  .msg, .mem-chip { animation: none; }
  .panel--chat { transition: opacity .2s; }
}

/* ==========================================================================
   Importación de memorias: botón, modal, dropzone, progreso y notificaciones
   ========================================================================== */
.import-btn {
  display: flex; align-items: center; gap: 10px; width: 100%; padding: 9px 12px; cursor: pointer;
  font-family: var(--font-mono); font-size: 10px; letter-spacing: .2em; color: var(--accent);
  background: color-mix(in srgb, var(--accent) 6%, transparent);
  border: 1px dashed color-mix(in srgb, var(--accent) 45%, transparent); border-radius: 6px;
  transition: background .2s, border-color .2s, box-shadow .2s;
}
.import-btn:hover, .import-btn:focus-visible {
  background: color-mix(in srgb, var(--accent) 14%, transparent); border-style: solid; box-shadow: var(--glow); outline: 0;
}
.import-btn__plus { margin-left: auto; font-size: 14px; line-height: 1; opacity: .7; }

.modal { position: fixed; inset: 0; z-index: 40; display: grid; place-items: center; padding: 16px; }
.modal[hidden] { display: none; }
.modal__backdrop { position: absolute; inset: 0; background: rgba(2, 4, 7, .62); backdrop-filter: blur(3px); animation: fade-in .25s ease-out; }
.modal__card {
  position: relative; inset: auto; width: min(560px, 100%); max-height: calc(100vh - 32px); overflow-y: auto;
  display: flex; flex-direction: column; gap: 16px; padding: 22px;
  background: color-mix(in srgb, var(--bg) 70%, var(--panel-bg));
  animation: modal-in .35s cubic-bezier(.2, .8, .2, 1);
}
@keyframes modal-in { from { opacity: 0; transform: translateY(14px) scale(.98); } }
@keyframes fade-in { from { opacity: 0; } }
.modal__head { display: flex; justify-content: space-between; gap: 16px; align-items: flex-start; }
.modal__kicker { font-family: var(--font-mono); font-size: 10px; letter-spacing: .22em; color: var(--accent); }
.modal__title { margin: 6px 0 4px; font-size: 18px; font-weight: 600; }
.modal__subtitle { margin: 0; font-size: 12.5px; line-height: 1.5; color: var(--text-dim); }
.icon-btn {
  flex: none; display: grid; place-items: center; width: 30px; height: 30px; cursor: pointer; color: var(--text-dim);
  background: transparent; border: 1px solid var(--panel-border); border-radius: 6px;
}
.icon-btn:hover { color: var(--accent); border-color: var(--accent); }

.dropzone {
  display: flex; flex-direction: column; align-items: center; gap: 6px; padding: 28px 18px; text-align: center; cursor: pointer;
  border: 1.5px dashed color-mix(in srgb, var(--accent) 40%, transparent); border-radius: 10px;
  background:
    radial-gradient(ellipse at center, color-mix(in srgb, var(--accent) 8%, transparent), transparent 70%),
    rgba(0, 0, 0, .25);
  transition: border-color .2s, background .2s, transform .2s;
}
.dropzone:hover, .dropzone:focus-visible { border-color: var(--accent); outline: 0; }
.dropzone.is-over { border-style: solid; border-color: var(--accent); transform: scale(1.01); box-shadow: inset 0 0 40px color-mix(in srgb, var(--accent) 18%, transparent), var(--glow); }
.dropzone.is-disabled { pointer-events: none; opacity: .45; }
.dropzone__icon { color: var(--accent); filter: drop-shadow(0 0 8px color-mix(in srgb, var(--accent) 60%, transparent)); }
.dropzone.is-over .dropzone__icon { animation: bob .8s ease-in-out infinite; }
@keyframes bob { 50% { transform: translateY(-5px); } }
.dropzone__title { font-size: 14px; font-weight: 600; }
.dropzone__hint { font-size: 12px; color: var(--text-dim); }
.dropzone__formats { margin-top: 6px; font-family: var(--font-mono); font-size: 9.5px; letter-spacing: .12em; color: var(--text-dim); }

.filelist { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 6px; }
.filelist:empty { display: none; }
.file {
  display: grid; grid-template-columns: 34px 1fr auto auto; align-items: center; gap: 10px;
  padding: 8px 10px; border: 1px solid var(--panel-border); border-radius: 6px; background: rgba(255, 255, 255, .02);
  animation: msg-in .25s ease-out;
}
.file__ext {
  font-family: var(--font-mono); font-size: 9px; font-weight: 600; letter-spacing: .06em; text-align: center;
  padding: 4px 0; border-radius: 3px; color: var(--bg); background: var(--accent);
}
.file__info { min-width: 0; display: flex; flex-direction: column; gap: 2px; }
.file__name { font-size: 12.5px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.file__meta { font-family: var(--font-mono); font-size: 9.5px; color: var(--text-dim); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.file__badge { font-family: var(--font-mono); font-size: 9px; letter-spacing: .12em; padding: 3px 6px; border-radius: 3px; border: 1px solid currentColor; }
.file__badge:empty { display: none; }
.file--saved .file__badge { color: #3dff9a; }
.file--duplicate .file__badge { color: #ffb238; }
.file--rejected .file__badge, .file--invalid .file__badge { color: #ff6b6b; }
.file--rejected .file__ext, .file--invalid .file__ext { background: #ff6b6b; }
.file--invalid .file__meta, .file--rejected .file__meta { color: #ff9a9a; }
.file__remove { width: 24px; height: 24px; border: 0; background: transparent; color: var(--text-dim); cursor: pointer; border-radius: 4px; font-size: 15px; line-height: 1; }
.file__remove:hover { color: var(--text); background: rgba(255, 255, 255, .06); }
.file__remove[hidden] { display: none; }

.token-row { display: flex; flex-direction: column; gap: 6px; }
.token-row[hidden] { display: none; }
.token-row label { font-family: var(--font-mono); font-size: 9.5px; letter-spacing: .16em; color: var(--accent); }
.token-row input {
  height: 36px; padding: 0 12px; font-family: var(--font-mono); font-size: 13px; color: var(--text);
  background: rgba(0, 0, 0, .35); border: 1px solid var(--panel-border); border-radius: 6px; outline: 0;
}
.token-row input:focus { border-color: var(--accent); }
.token-row small { font-size: 11px; color: var(--text-dim); }

.progress { display: flex; flex-direction: column; gap: 8px; }
.progress[hidden] { display: none; }
.progress__track { position: relative; height: 4px; border-radius: 2px; overflow: hidden; background: rgba(255, 255, 255, .06); }
.progress__bar {
  position: absolute; inset: 0 auto 0 0; width: 0; border-radius: inherit;
  background: linear-gradient(90deg, color-mix(in srgb, var(--accent) 60%, transparent), var(--accent));
  box-shadow: 0 0 12px var(--accent); transition: width .2s ease-out;
}
.progress.is-processing .progress__bar { width: 35% !important; animation: sweep 1.2s ease-in-out infinite; transition: none; }
@keyframes sweep { from { left: -35%; } to { left: 100%; } }
.progress__meta { display: flex; flex-direction: column; gap: 2px; }
.progress__status { font-family: var(--font-mono); font-size: 10.5px; letter-spacing: .18em; color: var(--accent); }
.progress__hint { font-size: 11.5px; color: var(--text-dim); }

.modal__error { margin: 0; padding: 9px 12px; font-size: 12.5px; color: #ffb0b0; border: 1px solid rgba(255, 94, 94, .35); border-radius: 6px; background: rgba(255, 94, 94, .08); }
.modal__error[hidden] { display: none; }
.modal__foot { display: flex; justify-content: flex-end; gap: 10px; }
.modal__foot .chip { padding: 8px 12px; }
.btn-primary {
  font-family: var(--font-mono); font-size: 10px; letter-spacing: .18em; height: 36px; padding: 0 16px; cursor: pointer;
  color: var(--bg); background: var(--accent); border: 0; border-radius: 6px; box-shadow: var(--glow);
}
.btn-primary:disabled { opacity: .35; cursor: not-allowed; box-shadow: none; }

.toasts {
  position: fixed; z-index: 60; top: var(--gutter); left: 50%; transform: translateX(-50%);
  display: flex; flex-direction: column; gap: 8px; align-items: center; pointer-events: none;
  width: min(440px, calc(100vw - 2 * var(--gutter)));
}
.toast {
  pointer-events: auto; width: 100%; display: grid; grid-template-columns: 28px 1fr; gap: 12px; align-items: center;
  padding: 12px 14px; border-radius: 8px; background: rgba(6, 12, 18, .85);
  border: 1px solid color-mix(in srgb, var(--tc, var(--accent)) 55%, transparent);
  box-shadow: 0 0 24px color-mix(in srgb, var(--tc, var(--accent)) 28%, transparent), 0 10px 40px rgba(0, 0, 0, .5);
  backdrop-filter: blur(12px); -webkit-backdrop-filter: blur(12px);
  animation: toast-in .45s cubic-bezier(.2, .8, .2, 1);
}
.toast.is-leaving { animation: toast-out .35s ease-in forwards; }
@keyframes toast-in { from { opacity: 0; transform: translateY(-12px) scale(.97); } }
@keyframes toast-out { to { opacity: 0; transform: translateY(-10px); } }
.toast--error { --tc: #ff5e5e; }
.toast--warn { --tc: #ffb238; }
.toast__icon { display: grid; place-items: center; width: 28px; height: 28px; border-radius: 50%; color: var(--tc, var(--accent)); border: 1px solid currentColor; box-shadow: 0 0 10px currentColor; }
.toast__title { display: block; font-family: var(--font-mono); font-size: 10px; letter-spacing: .2em; color: var(--tc, var(--accent)); }
.toast__body { display: block; margin-top: 3px; font-size: 12.5px; line-height: 1.45; }

@media (prefers-reduced-motion: reduce) {
  .modal__card, .modal__backdrop, .toast, .file { animation: none; }
  .progress.is-processing .progress__bar { animation: none; width: 100% !important; opacity: .6; }
}
.mem-chip.is-stale, .cite.is-stale { opacity: .35; cursor: default; box-shadow: none; filter: grayscale(.6); }

/* ==========================================================================
   Modo alumno (por defecto): solo marca + conversación + cerebro de fondo.
   El modo administrador (/?admin) conserva el HUD completo.
   ========================================================================== */
.chat__disclaimer { display: none; }

body.is-student .panel--control,
body.is-student .panel--status,
body.is-student .panel--legend,
body.is-student .chat-launcher,
body.is-student #chat-close,
body.is-student .chat__mode,
body.is-student .tooltip__meta,
body.is-student .inspector__facts > div:not(:first-child),
body.is-student .inspector__section:last-of-type { display: none !important; }

body.is-student .brand { top: var(--gutter); bottom: auto; }
body.is-student .brand__tagline { display: block; }

/* La conversación vive en un panel lateral: el cerebro queda grande y centrado en el espacio libre */
body.is-student .panel--chat {
  top: var(--gutter); bottom: var(--gutter); right: var(--gutter);
  width: clamp(320px, 34vw, 440px); max-height: none;
}
body.is-student .panel--chat.is-collapsed { transform: none; opacity: 1; pointer-events: auto; }
body.is-student .panel--inspector { bottom: var(--gutter); width: clamp(320px, 34vw, 440px); }
body.is-student .chat__head { padding: 14px 18px 10px; }
body.is-student .chat__title { font-size: 17px; }
body.is-student .chat__log { padding: 12px 18px; }
body.is-student .chat__suggestions { flex-direction: row; flex-wrap: wrap; align-items: center; padding: 0 18px 10px; gap: 6px; }
body.is-student .chat__suggestions-label { width: 100%; }
body.is-student .suggestion { border-radius: 999px; padding: 6px 12px; font-size: 12px; }
body.is-student .chat__form { padding: 10px 18px 8px; }
body.is-student .chat__form textarea { font-size: 14px; min-height: 44px; padding: 11px 13px; }
body.is-student .chat__send { height: 44px; }
body.is-student .chat__disclaimer {
  display: block; margin: 0; padding: 0 18px 12px; font-size: 10.5px; line-height: 1.4; color: var(--text-dim);
}
body.is-student .msg__body { font-size: 14px; }
body.is-student .cite { font-size: 9.5px; vertical-align: super; padding: 0 4px; }
body.is-student .mem-chip b { font-family: var(--font-mono); font-size: 10px; color: var(--c); }

@media (max-width: 720px) {
  body.is-student .brand__title { font-size: 18px; }
  body.is-student .brand__subtitle { display: block; font-size: 12px; }
  body.is-student .brand__tagline { display: none; }
  /* móvil: hoja inferior que deja ver el cerebro arriba */
  body.is-student .panel--chat { top: auto; left: var(--gutter); right: var(--gutter); width: auto; height: 56vh; }
}

/* ==========================================================================
   Alumno · dos estados
   - Reposo: barra de pregunta flotante, estilo buscador de IA, sobre el cerebro completo
   - Conversación (body.chat-open): panel lateral con botón para volver al cerebro
   ========================================================================== */
.chat__back, .chat__resume { display: none; }

body.is-student:not(.chat-open) .panel--chat {
  top: auto; right: auto; left: 50%; bottom: 28px;
  width: min(720px, calc(100vw - 2 * var(--gutter)));
  transform: translateX(-50%);
  border-radius: 18px;
  border-color: color-mix(in srgb, var(--accent) 35%, transparent);
  box-shadow: 0 0 40px color-mix(in srgb, var(--accent) 16%, transparent), 0 18px 50px rgba(0, 0, 0, .55);
  animation: bar-in .45s cubic-bezier(.2, .8, .2, 1);
}
body.is-student:not(.chat-open) .chat__head,
body.is-student:not(.chat-open) .chat__log { display: none; }
body.is-student:not(.chat-open) .chat__suggestions { padding: 14px 18px 4px; justify-content: center; }
body.is-student:not(.chat-open) .chat__suggestions-label { text-align: center; }
body.is-student:not(.chat-open) .chat__form { border-top: 0; padding: 10px 14px 6px; }
body.is-student:not(.chat-open) .chat__form textarea { border-radius: 12px; font-size: 15px; }
body.is-student:not(.chat-open) .chat__send { border-radius: 12px; }
body.is-student:not(.chat-open) .chat__disclaimer { text-align: center; padding-bottom: 10px; }
body.is-student:not(.chat-open) .chat__resume:not([hidden]) {
  display: block; align-self: center; margin: 12px auto 0; cursor: pointer;
  font: inherit; font-size: 12px; color: var(--accent); background: color-mix(in srgb, var(--accent) 8%, transparent);
  border: 1px solid color-mix(in srgb, var(--accent) 35%, transparent); border-radius: 999px; padding: 6px 14px;
}
body.is-student:not(.chat-open) .chat__resume:hover { background: color-mix(in srgb, var(--accent) 16%, transparent); }

body.is-student.chat-open .panel--chat { animation: panel-in .45s cubic-bezier(.2, .8, .2, 1); }
body.is-student.chat-open .chat__back { display: inline-block; }
body.is-student .chat__head { align-items: center; }

@keyframes bar-in { from { opacity: 0; transform: translate(-50%, 16px); } }
@keyframes panel-in { from { opacity: 0; transform: translateX(24px); } }

@media (max-width: 720px) {
  body.is-student:not(.chat-open) .panel--chat { bottom: var(--gutter); height: auto; }
  body.is-student:not(.chat-open) .suggestion { font-size: 11.5px; }
}
@media (prefers-reduced-motion: reduce) {
  body.is-student .panel--chat { animation: none !important; }
}

/* Alumno · barra en reposo: caja primero; "Temas sugeridos" debajo, plegable */
.chat__topics-toggle { display: none; }
body.is-student:not(.chat-open) .chat__resume { order: 1; }
body.is-student:not(.chat-open) .chat__form { order: 2; }
body.is-student:not(.chat-open) .chat__topics-toggle:not([hidden]) {
  order: 3; display: inline-flex; align-items: center; gap: 6px; align-self: center; margin: 2px auto 0;
  font: inherit; font-size: 12px; color: var(--accent); background: none; border: 0; cursor: pointer; padding: 4px 8px;
}
body.is-student:not(.chat-open) .chat__topics-toggle::after {
  content: ""; width: 6px; height: 6px; border-right: 1.5px solid currentColor; border-bottom: 1.5px solid currentColor;
  transform: rotate(45deg) translateY(-2px); transition: transform .25s;
}
body.is-student:not(.chat-open) .chat__topics-toggle[aria-expanded="true"]::after { transform: rotate(-135deg) translateY(-1px); }
body.is-student:not(.chat-open) .chat__topics-toggle:hover { text-decoration: underline; }
body.is-student:not(.chat-open) .chat__suggestions { order: 4; padding: 4px 18px 6px; }
body.is-student:not(.chat-open) .chat__suggestions-label { display: none; }
body.is-student:not(.chat-open) #chat:not(.topics-open) .chat__suggestions { display: none; }
body.is-student:not(.chat-open) #chat.topics-open .chat__suggestions { animation: msg-in .3s ease-out; }
body.is-student:not(.chat-open) .chat__disclaimer { order: 5; padding-top: 4px; }

/* Firma del desarrollador: al final, centrada y discreta (patrón de las landings de Grupo Clúster) */
.site-credit {
  position: fixed; z-index: 3; left: 50%; bottom: 6px; transform: translateX(-50%);
  max-width: calc(100vw - 32px); white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
  font-family: var(--font-sans); font-size: 11px; letter-spacing: .06em; color: var(--text);
  opacity: .28; text-decoration: none; transition: opacity .2s;
}
.site-credit:hover, .site-credit:focus-visible { opacity: .7; }
.site-credit[hidden] { display: none; }
body.is-student.chat-open .site-credit { left: calc((100vw - clamp(320px, 34vw, 440px) - 20px) / 2); }
@media (max-width: 720px) {
  body.is-student .panel--chat { bottom: 26px !important; }
  body.is-student.chat-open .site-credit { left: 50%; }
}
.loader__credit {
  position: absolute; bottom: 28px; left: 0; right: 0; text-align: center;
  font-family: var(--font-mono); font-size: 10px; letter-spacing: .24em; text-transform: uppercase; color: var(--text-dim); opacity: .7;
}

/* ==========================================================================
   Fórmulas (KaTeX), seguimiento y práctica
   ========================================================================== */
.math .katex { font-size: 1.06em; color: var(--text); }
.math--block { display: block; margin: 8px 0; overflow-x: auto; overflow-y: hidden; scrollbar-width: thin; }
.inspector__text .math .katex { font-size: 1em; }

.msg__followups { display: flex; flex-direction: column; gap: 6px; margin-top: 6px; animation: msg-in .35s ease-out .15s backwards; }
.msg__followups-label { font-family: var(--font-mono); font-size: 9px; letter-spacing: .2em; color: var(--text-dim); }
.followups { display: flex; flex-wrap: wrap; gap: 6px; }
.followup {
  font: inherit; font-size: 12px; color: var(--text); cursor: pointer; padding: 6px 12px; border-radius: 999px;
  background: rgba(255, 255, 255, .03); border: 1px solid var(--panel-border); transition: border-color .15s, color .15s, background .15s;
}
.followup:hover { border-color: var(--accent); color: var(--accent); }
.followup--quiz {
  color: var(--bg); background: var(--accent); border-color: var(--accent); font-weight: 600; box-shadow: var(--glow);
}
.followup--quiz:hover { color: var(--bg); filter: brightness(1.1); }

.quiz {
  display: flex; flex-direction: column; gap: 10px; padding: 14px; border-radius: 10px;
  border: 1px solid color-mix(in srgb, var(--accent) 35%, transparent);
  background: linear-gradient(160deg, color-mix(in srgb, var(--accent) 7%, transparent), rgba(0, 0, 0, .25));
}
.quiz__title { font-family: var(--font-mono); font-size: 10px; letter-spacing: .18em; color: var(--accent); text-transform: uppercase; }
.quiz__stage { display: flex; flex-direction: column; gap: 10px; }
.quiz__progress { font-family: var(--font-mono); font-size: 10px; color: var(--text-dim); letter-spacing: .1em; }
.quiz__stem { margin: 0; font-size: 14px; line-height: 1.6; }
.quiz__blank {
  display: inline-block; min-width: 64px; margin: 0 4px; text-align: center; font-family: var(--font-mono); font-size: 12px;
  color: var(--accent); border-bottom: 2px solid var(--accent); line-height: 1.2;
}
.quiz__options { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }
.quiz__option {
  font: inherit; font-size: 13px; text-align: left; color: var(--text); cursor: pointer; padding: 10px 12px; border-radius: 8px;
  background: rgba(0, 0, 0, .3); border: 1px solid var(--panel-border); transition: border-color .15s, background .15s, transform .15s;
}
.quiz__option:not(:disabled):hover { border-color: var(--accent); transform: translateY(-1px); }
.quiz__option:disabled { cursor: default; opacity: .55; }
.quiz__option.is-correct { opacity: 1; border-color: #3dff9a; background: rgba(61, 255, 154, .12); color: #c9ffe2; }
.quiz__option.is-wrong { opacity: 1; border-color: #ffb238; background: rgba(255, 178, 56, .1); }
.quiz__feedback { display: flex; flex-direction: column; gap: 8px; padding: 10px 12px; border-radius: 8px; animation: msg-in .3s ease-out; }
.quiz__feedback.is-correct { background: rgba(61, 255, 154, .07); border-left: 2px solid #3dff9a; }
.quiz__feedback.is-wrong { background: rgba(255, 178, 56, .07); border-left: 2px solid #ffb238; }
.quiz__feedback strong { font-size: 13px; }
.quiz__explanation { margin: 0; font-size: 12.5px; line-height: 1.55; color: color-mix(in srgb, var(--text) 85%, transparent); }
.quiz__explanation-label { color: var(--text-dim); }
.quiz__next {
  align-self: flex-start; font-family: var(--font-mono); font-size: 10px; letter-spacing: .16em; cursor: pointer;
  color: var(--bg); background: var(--accent); border: 0; border-radius: 6px; padding: 8px 14px; box-shadow: var(--glow);
}
.quiz__result { display: flex; flex-direction: column; gap: 8px; align-items: flex-start; }
.quiz__score { font-family: var(--font-mono); font-size: 22px; font-weight: 600; color: var(--accent); text-shadow: var(--glow); }
.quiz__verdict { margin: 0; font-size: 13px; }
@media (max-width: 720px) { .quiz__options { grid-template-columns: 1fr; } }
@media (prefers-reduced-motion: reduce) { .msg__followups, .quiz__feedback { animation: none; } }

/* ==========================================================================
   Pantalla de acceso por código
   ========================================================================== */
.sr-only { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }
.gate {
  position: fixed; inset: 0; z-index: 70; display: grid; place-items: center; padding: 16px;
  background:
    radial-gradient(ellipse at 50% 38%, color-mix(in srgb, var(--accent) 16%, transparent), transparent 60%),
    radial-gradient(1px 1px at 20% 30%, rgba(255,255,255,.5), transparent),
    radial-gradient(1px 1px at 70% 20%, rgba(255,255,255,.4), transparent),
    radial-gradient(1px 1px at 85% 70%, rgba(255,255,255,.35), transparent),
    radial-gradient(1px 1px at 35% 80%, rgba(255,255,255,.3), transparent),
    var(--bg);
  transition: opacity .5s;
}
.gate[hidden] { display: none; }
.gate.is-leaving { opacity: 0; pointer-events: none; }
.gate__card {
  width: min(400px, 100%); display: flex; flex-direction: column; gap: 12px; padding: 28px 26px;
  background: var(--panel-bg); border: 1px solid var(--panel-border); border-radius: 16px;
  backdrop-filter: blur(12px); -webkit-backdrop-filter: blur(12px);
  box-shadow: 0 0 60px color-mix(in srgb, var(--accent) 14%, transparent), 0 20px 60px rgba(0,0,0,.5);
  animation: modal-in .5s cubic-bezier(.2, .8, .2, 1);
}
.gate__kicker { display: inline-flex; align-items: center; gap: 8px; font-family: var(--font-mono); font-size: 10px; letter-spacing: .22em; color: var(--accent); }
.gate__title { margin: 4px 0 0; font-family: var(--font-mono); font-size: 30px; font-weight: 600; letter-spacing: .2em; text-shadow: var(--glow); }
.gate__subtitle { margin: 0; font-size: 14px; }
.gate__hint { margin: 6px 0 2px; font-size: 13px; line-height: 1.5; color: var(--text-dim); }
.gate__field input {
  width: 100%; height: 46px; padding: 0 14px; font: inherit; font-size: 15px; letter-spacing: .08em; color: var(--text);
  background: rgba(0,0,0,.35); border: 1px solid var(--panel-border); border-radius: 10px; outline: 0;
}
.gate__field input:focus { border-color: var(--accent); box-shadow: var(--glow); }
.gate__submit { height: 44px; border-radius: 10px; }
.gate__error { margin: 0; font-size: 12.5px; color: #ffb0b0; }
.gate__error[hidden] { display: none; }
.gate ~ .site-credit, body:has(.gate:not([hidden])) .site-credit { z-index: 80; }
.import-btn[hidden] { display: none; }

/* Barra en reposo: solo la caja y "Temas sugeridos". El aviso del emulador se muestra en la conversación. */
body.is-student:not(.chat-open) .chat__disclaimer { display: none; }
body.is-student:not(.chat-open) .chat__topics-toggle:not([hidden]) { margin-bottom: 8px; }
