/* ═══════════════════════════════════════════════════════════════════════════
   SELECTOR DE MODELO DE IA — chip de los inputs + hoja de opciones
   ═══════════════════════════════════════════════════════════════════════════

   El chip vive PEGADO al input de IA (chat, panel flotante) y dice con qué
   está pensando la app y cuánto queda de límite. Al tocarlo se abre la lista
   de LLM disponibles para cambiarlo.

   Mobile-first: en pantallas chicas la lista es una hoja que sube desde abajo
   (se llega con el pulgar); de 576px para arriba es un popover anclado al chip.

   Los colores salen de los tokens de variables.css, así que acompaña el tema
   claro/oscuro sin reglas duplicadas.
   ═══════════════════════════════════════════════════════════════════════════ */

.cf-llm { display: inline-flex; max-width: 100%; }

/* ── El chip ───────────────────────────────────────────────────────────── */

.cf-llm-chip {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  max-width: 100%;
  min-height: 30px;
  padding: 4px 10px;
  border: 1px solid rgba(155, 89, 182, 0.35);
  border-radius: var(--border-radius-full, 999px);
  background: rgba(155, 89, 182, 0.10);
  color: inherit;
  font-size: 0.72rem;
  line-height: 1.2;
  cursor: pointer;
  transition: border-color .2s ease, background .2s ease;
}

.cf-llm-chip:hover,
.cf-llm-chip[aria-expanded="true"] {
  border-color: rgba(155, 89, 182, 0.75);
  background: rgba(155, 89, 182, 0.18);
}

.cf-llm-chip:disabled { opacity: .55; cursor: default; }

.cf-llm-chip .cf-llm-nombre {
  font-weight: 600;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.cf-llm-chip .cf-llm-modelo {
  font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
  font-size: 0.66rem;
  opacity: .72;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  max-width: 42vw;
}

.cf-llm-chip .cf-llm-cuota {
  font-size: 0.66rem;
  opacity: .8;
  padding-left: 6px;
  border-left: 1px solid currentColor;
  white-space: nowrap;
}

.cf-llm-chip .cf-llm-cuota.agotada { color: #dc3545; opacity: 1; font-weight: 600; }
.cf-llm-chip .cf-llm-cuota.poca    { color: #f59e0b; opacity: 1; }

.cf-llm-chip .cf-llm-caret { font-size: .7rem; opacity: .6; }

/* Cuando respondió otro distinto al elegido */
.cf-llm-chip.cf-llm-fallback { border-color: rgba(245, 158, 11, .6); }

/* ── Hoja / popover ────────────────────────────────────────────────────── */

/* Por encima del panel flotante de CortexAI (z-index 9999) y del modal de
   Bootstrap (1055): el chip vive adentro de los dos. */
.cf-llm-fondo {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.45);
  z-index: 10040;
}

.cf-llm-pop {
  position: fixed;
  z-index: 10050;
  width: min(360px, calc(100vw - 24px));
  max-height: min(70vh, 560px);
  overflow-y: auto;
  overscroll-behavior: contain;
  -webkit-overflow-scrolling: touch;
  background: var(--bg-card, #fff);
  color: var(--text-primary, #111);
  border: 1px solid var(--border-color, #e5e7eb);
  border-radius: var(--border-radius-md, 12px);
  box-shadow: 0 18px 44px rgba(0, 0, 0, 0.28);
  padding: 12px;
}

.cf-llm-pop h6 {
  margin: 0 0 8px;
  font-size: .82rem;
  font-weight: 700;
  display: flex;
  align-items: center;
  gap: 6px;
  color: #b07cc6;
}

/* ── Bloque de límites ─────────────────────────────────────────────────── */

.cf-llm-limites {
  border: 1px solid var(--border-color, #e5e7eb);
  border-radius: var(--border-radius-sm, 8px);
  padding: 8px 10px;
  margin-bottom: 10px;
  background: var(--bg-surface, #f8f9fa);
}

.cf-llm-lim + .cf-llm-lim { margin-top: 8px; }

.cf-llm-lim-txt {
  display: flex;
  justify-content: space-between;
  gap: 8px;
  font-size: .7rem;
  color: var(--text-secondary, #4b5563);
}

.cf-llm-lim-txt strong { color: var(--text-primary, #111); font-weight: 600; }

.cf-llm-barra {
  height: 5px;
  border-radius: 999px;
  background: rgba(127, 127, 127, .22);
  overflow: hidden;
  margin-top: 4px;
}

.cf-llm-barra > div { height: 100%; border-radius: 999px; transition: width .3s ease; }

.cf-llm-nota {
  font-size: .66rem;
  color: var(--text-muted, #596172);
  margin: 8px 0 0;
  line-height: 1.45;
}

/* ── Lista de opciones ─────────────────────────────────────────────────── */

.cf-llm-op {
  display: flex;
  align-items: flex-start;
  gap: 8px;
  width: 100%;
  text-align: left;
  padding: 8px;
  border: 1px solid transparent;
  border-radius: var(--border-radius-sm, 8px);
  background: transparent;
  color: inherit;
  cursor: pointer;
}

.cf-llm-op:hover { background: var(--bg-hover, rgba(127,127,127,.10)); }

.cf-llm-op.activa {
  border-color: rgba(155, 89, 182, .55);
  background: rgba(155, 89, 182, .10);
}

.cf-llm-op.pausada { opacity: .5; }

.cf-llm-op i.cf-llm-ico { font-size: 1rem; line-height: 1.3; }

.cf-llm-op-cuerpo { flex: 1 1 auto; min-width: 0; }

.cf-llm-op-tit {
  display: flex;
  align-items: center;
  gap: 6px;
  flex-wrap: wrap;
  font-size: .78rem;
  font-weight: 600;
}

.cf-llm-op-sub {
  font-size: .66rem;
  color: var(--text-muted, #596172);
  line-height: 1.4;
  margin-top: 2px;
  word-break: break-word;
}

.cf-llm-tag {
  font-size: .58rem;
  text-transform: uppercase;
  letter-spacing: .04em;
  padding: 1px 6px;
  border-radius: 999px;
  border: 1px solid currentColor;
  opacity: .9;
}

.cf-llm-check { color: #9b59b6; font-size: .9rem; }

/* Selector de modelo dentro de la opción elegida */
.cf-llm-modelos {
  margin: 6px 0 2px;
  display: flex;
  align-items: center;
  gap: 6px;
}

.cf-llm-modelos select {
  flex: 1 1 auto;
  min-width: 0;
  font-size: .72rem;
  padding: 5px 8px;
  border-radius: var(--border-radius-sm, 8px);
  border: 1px solid var(--border-color, #e5e7eb);
  background: var(--bg-card, #fff);
  color: var(--text-primary, #111);
}

.cf-llm-pie {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
  margin-top: 10px;
  padding-top: 10px;
  border-top: 1px solid var(--border-color, #e5e7eb);
}

.cf-llm-pie a,
.cf-llm-pie button {
  font-size: .7rem;
  padding: 6px 10px;
  border-radius: var(--border-radius-sm, 8px);
  border: 1px solid var(--border-color, #e5e7eb);
  background: transparent;
  color: var(--text-secondary, #4b5563);
  text-decoration: none;
  cursor: pointer;
}

.cf-llm-pie a:hover,
.cf-llm-pie button:hover { border-color: #9b59b6; color: #b07cc6; }

.cf-llm-cargando {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: .72rem;
  color: var(--text-muted, #596172);
  padding: 6px 2px;
}

/* ── Mobile: hoja desde abajo ──────────────────────────────────────────── */

@media (max-width: 575.98px) {
  .cf-llm-pop {
    top: auto !important;
    left: 0 !important;
    right: 0;
    bottom: 0;
    width: 100%;
    max-width: 100%;
    max-height: 82vh;
    border-radius: 18px 18px 0 0;
    padding: 14px 14px calc(14px + env(safe-area-inset-bottom));
  }

  /* Objetivos táctiles más grandes en la lista */
  .cf-llm-op { padding: 10px 8px; }
  .cf-llm-modelos select { font-size: 16px; }   /* evita el zoom de iOS */

  .cf-llm-chip .cf-llm-modelo { max-width: 34vw; }
}
