/* ==========================================================================
   Buscador de noticias CIREN — widget autónomo
   --------------------------------------------------------------------------
   Prefijo .cns- (CIREN News Search). No depende de styles.css: todas las
   variables llevan valor de reserva, así el widget se puede copiar tal cual
   a otra web junto con buscador-noticias.js.
   Ver docs/buscador-noticias.md
   ========================================================================== */

/* --------------------------------------------------------------------------
   1. Disparador (la lupa del header)
   -------------------------------------------------------------------------- */

.cns-toggle {
  width: 32px;
  height: 32px;
  padding: 0;
  border: 0;
  background: transparent;
  color: var(--ink-dim, #9FB0A4);
  border-radius: 50%;
  display: grid;
  place-items: center;
  cursor: pointer;
  transition: transform .2s ease, background .2s ease, color .2s ease;
}

.cns-toggle:hover {
  transform: translateY(-2px);
  color: #07130B;
  background: var(--paper, #F3F7F1);
}

.cns-toggle:focus-visible {
  outline: 2px solid var(--brand-bright, #4E9A5C);
  outline-offset: 3px;
}

.cns-toggle svg {
  width: 18px;
  height: 18px;
  fill: none;
  stroke: currentColor;
  stroke-width: 2;
  stroke-linecap: round;
}

/* Variante para el menú móvil: se ve como un ítem más de la lista. */
.cns-toggle--mobile {
  width: auto;
  height: auto;
  gap: 10px;
  grid-auto-flow: column;
  justify-content: start;
  align-items: center;
  border-radius: 12px;
  padding: 6px 0;
  color: var(--ink, #EEF3EE);
  font-size: 1.05rem;
  font-weight: 700;
}

.cns-toggle--mobile:hover {
  transform: none;
  background: transparent;
  color: var(--brand-bright, #4E9A5C);
}

/* --------------------------------------------------------------------------
   2. Overlay a pantalla completa
   El círculo nace en --cns-ox/--cns-oy (el punto donde queda el botón ×).
   Para incrustarlo en otra web con el botón en otra posición, basta
   redefinir esas dos variables.
   -------------------------------------------------------------------------- */

.cns-overlay {
  --cns-ox: calc(100% - 53px);
  --cns-oy: 88px;
  --cns-ease-in: cubic-bezier(.4, 0, .2, 1);
  --cns-ease-out: cubic-bezier(.16, 1, .3, 1);

  position: fixed;
  inset: 0;
  min-height: 100svh;
  min-height: 100dvh;
  z-index: 200;
  overflow: hidden;
  background: rgba(0, 0, 0, .88);
  visibility: hidden;
  clip-path: circle(0px at var(--cns-ox) var(--cns-oy));
  transition:
    clip-path 380ms var(--cns-ease-in),
    visibility 0s linear 380ms;
}

.cns-overlay.is-open {
  visibility: visible;
  clip-path: circle(160% at var(--cns-ox) var(--cns-oy));
  transition:
    clip-path 520ms var(--cns-ease-in),
    visibility 0s linear 0s;
}

.cns-backdrop {
  position: absolute;
  inset: 0;
  border: 0;
  padding: 0;
  background: transparent;
  cursor: pointer;
}

/* Bloqueo del scroll de fondo mientras el buscador está abierto. */
body.cns-lock {
  overflow: hidden;
}

/* --------------------------------------------------------------------------
   3. Botón de cierre
   -------------------------------------------------------------------------- */

.cns-close {
  position: absolute;
  top: calc(var(--cns-oy) - 29px);
  right: 24px;
  width: 58px;
  height: 58px;
  border: 0;
  border-radius: 50%;
  background: #fff;
  color: #111;
  display: grid;
  place-items: center;
  cursor: pointer;
  opacity: 0;
  transform: scale(.5);
  transition: opacity 160ms linear, transform 160ms var(--cns-ease-in);
}

.cns-overlay.is-open .cns-close {
  opacity: 1;
  transform: scale(1);
  transition:
    opacity 260ms linear 340ms,
    transform 260ms var(--cns-ease-out) 340ms;
}

.cns-close:hover {
  background: var(--paper, #F3F7F1);
  transform: scale(1.06);
}

.cns-close:focus-visible {
  outline: 3px solid var(--brand-bright, #4E9A5C);
  outline-offset: 3px;
}

.cns-close svg {
  width: 22px;
  height: 22px;
  fill: none;
  stroke: currentColor;
  stroke-width: 2;
  stroke-linecap: round;
}

/* --------------------------------------------------------------------------
   4. Panel: campo de búsqueda + resultados
   Centrado en reposo; cuando hay resultados sube para dejarles sitio.
   -------------------------------------------------------------------------- */

.cns-panel {
  position: absolute;
  top: 50%;
  left: 50%;
  width: min(650px, 78vw);
  max-width: calc(100% - 32px);
  transform: translate(-50%, -50%);
  transition: top 400ms var(--cns-ease-out), transform 400ms var(--cns-ease-out);
}

.cns-overlay.has-results .cns-panel {
  top: 18vh;
  transform: translate(-50%, 0);
}

.cns-form {
  display: flex;
  align-items: center;
  gap: 12px;
  padding-bottom: 10px;
  border-bottom: 1px solid rgba(255, 255, 255, .55);
  opacity: 0;
  transform: translateY(10px);
  transition: opacity 140ms linear, transform 140ms var(--cns-ease-in);
}

.cns-overlay.is-open .cns-form {
  opacity: 1;
  transform: translateY(0);
  transition:
    opacity 320ms linear 230ms,
    transform 380ms var(--cns-ease-out) 230ms;
}

.cns-input {
  flex: 1;
  min-width: 0;
  border: 0;
  background: transparent;
  color: #fff;
  font-family: inherit;
  font-size: clamp(1.4rem, 3vw, 2.1rem);
  font-weight: 700;
  line-height: 1.3;
  padding: 4px 0;
  appearance: none;
  -webkit-appearance: none;
}

/* La "x" nativa de input[type=search] competiría con nuestra lupa. */
.cns-input::-webkit-search-cancel-button,
.cns-input::-webkit-search-decoration {
  -webkit-appearance: none;
  appearance: none;
  display: none;
}

.cns-input::placeholder {
  color: rgba(255, 255, 255, .82);
  font-weight: 700;
}

.cns-input:focus {
  outline: none;
}

.cns-submit {
  flex: none;
  width: 44px;
  height: 44px;
  border: 0;
  border-radius: 50%;
  background: transparent;
  color: #fff;
  display: grid;
  place-items: center;
  cursor: pointer;
  opacity: 0;
  transition: opacity 120ms linear, background .2s ease;
}

.cns-overlay.is-open .cns-submit {
  opacity: 1;
  transition: opacity 200ms linear 400ms, background .2s ease;
}

.cns-submit:hover {
  background: rgba(255, 255, 255, .12);
}

.cns-submit:focus-visible {
  outline: 2px solid var(--brand-bright, #4E9A5C);
  outline-offset: 2px;
}

.cns-submit svg {
  width: 26px;
  height: 26px;
  fill: none;
  stroke: currentColor;
  stroke-width: 2;
  stroke-linecap: round;
}

/* --------------------------------------------------------------------------
   5. Resultados y estados
   -------------------------------------------------------------------------- */

.cns-results {
  margin-top: 18px;
  max-height: 58vh;
  overflow-y: auto;
  overscroll-behavior: contain;
  opacity: 0;
  transition: opacity 200ms linear;
  scrollbar-width: thin;
  scrollbar-color: rgba(255, 255, 255, .3) transparent;
}

.cns-overlay.is-open .cns-results {
  opacity: 1;
  transition: opacity 260ms linear 420ms;
}

.cns-results::-webkit-scrollbar {
  width: 6px;
}

.cns-results::-webkit-scrollbar-thumb {
  background: rgba(255, 255, 255, .28);
  border-radius: 999px;
}

.cns-hint,
.cns-state {
  color: var(--ink-dim, #9FB0A4);
  font-size: .95rem;
  line-height: 1.6;
  padding: 6px 2px;
}

.cns-state strong {
  color: var(--ink, #EEF3EE);
}

.cns-retry {
  margin-top: 10px;
  border: 1px solid var(--hairline, rgba(238, 243, 238, .15));
  background: transparent;
  color: var(--ink, #EEF3EE);
  border-radius: 999px;
  padding: 7px 16px;
  font-size: .85rem;
  font-weight: 700;
  cursor: pointer;
  transition: background .2s ease, border-color .2s ease;
}

.cns-retry:hover {
  background: rgba(255, 255, 255, .1);
  border-color: rgba(255, 255, 255, .4);
}

.cns-list {
  list-style: none;
  margin: 0;
  padding: 0;
  display: grid;
  gap: 6px;
}

.cns-item a {
  display: grid;
  grid-template-columns: 84px 1fr;
  gap: 14px;
  align-items: center;
  padding: 10px;
  border-radius: 14px;
  color: inherit;
  text-decoration: none;
  transition: background .2s ease;
}

.cns-item a:hover,
.cns-item a:focus-visible {
  background: rgba(255, 255, 255, .08);
  outline: none;
}

.cns-item a:focus-visible {
  box-shadow: inset 0 0 0 1px var(--brand-bright, #4E9A5C);
}

.cns-thumb {
  width: 84px;
  height: 60px;
  border-radius: 10px;
  background-color: rgba(255, 255, 255, .08);
  background-size: cover;
  background-position: center;
}

.cns-meta {
  display: flex;
  gap: 10px;
  align-items: center;
  font-size: .72rem;
  letter-spacing: .04em;
  text-transform: uppercase;
  color: var(--brand-bright, #4E9A5C);
  margin-bottom: 4px;
}

.cns-meta span:not(:first-child)::before {
  content: '·';
  margin-right: 10px;
  color: var(--ink-dim, #9FB0A4);
}

.cns-item h3 {
  margin: 0;
  font-size: 1rem;
  font-weight: 700;
  color: var(--ink, #EEF3EE);
  line-height: 1.35;
}

.cns-item p {
  margin: 4px 0 0;
  font-size: .85rem;
  line-height: 1.5;
  color: var(--ink-dim, #9FB0A4);
}

/* Esqueletos de carga */
.cns-skeleton {
  display: grid;
  grid-template-columns: 84px 1fr;
  gap: 14px;
  padding: 10px;
}

.cns-skeleton i,
.cns-skeleton span {
  display: block;
  border-radius: 8px;
  background: linear-gradient(90deg, rgba(255, 255, 255, .06), rgba(255, 255, 255, .14), rgba(255, 255, 255, .06));
  background-size: 200% 100%;
  animation: cns-shimmer 1.2s linear infinite;
}

.cns-skeleton i {
  height: 60px;
}

.cns-skeleton span {
  height: 12px;
  margin-bottom: 8px;
}

.cns-skeleton span:last-child {
  width: 60%;
  margin-bottom: 0;
}

@keyframes cns-shimmer {
  from { background-position: 200% 0; }
  to { background-position: -200% 0; }
}

/* --------------------------------------------------------------------------
   6. Responsive
   -------------------------------------------------------------------------- */

@media (max-width: 640px) {
  .cns-overlay {
    --cns-ox: calc(100% - 40px);
    --cns-oy: 74px;
  }

  .cns-close {
    right: 16px;
    width: 48px;
    height: 48px;
    top: calc(var(--cns-oy) - 24px);
  }

  .cns-panel {
    width: calc(100% - 32px);
  }

  .cns-overlay.has-results .cns-panel {
    top: 15vh;
  }

  .cns-item a,
  .cns-skeleton {
    grid-template-columns: 64px 1fr;
    gap: 10px;
    /* Con títulos de varias líneas, la miniatura centrada deja huecos raros. */
    align-items: start;
  }

  .cns-thumb,
  .cns-skeleton i {
    width: 64px;
    height: 48px;
  }

  .cns-results {
    max-height: calc(100dvh - 190px);
    padding-bottom: calc(16px + env(safe-area-inset-bottom));
  }

  .cns-input {
    font-size: 1.25rem;
  }

  .cns-item h3,
  .cns-item p {
    overflow-wrap: anywhere;
  }
}

@media (max-width: 420px) {
  .cns-overlay {
    --cns-ox: calc(100% - 32px);
    --cns-oy: calc(58px + env(safe-area-inset-top));
  }

  .cns-close {
    top: calc(12px + env(safe-area-inset-top));
    right: 10px;
    width: 44px;
    height: 44px;
  }

  .cns-panel {
    width: calc(100% - 24px);
  }

  .cns-overlay.has-results .cns-panel {
    top: calc(76px + env(safe-area-inset-top));
  }

  .cns-form {
    gap: 8px;
  }

  .cns-item a,
  .cns-skeleton {
    grid-template-columns: 56px minmax(0, 1fr);
    padding: 9px 6px;
  }

  .cns-thumb,
  .cns-skeleton i {
    width: 56px;
    height: 44px;
  }

  .cns-item p {
    display: -webkit-box;
    overflow: hidden;
    -webkit-box-orient: vertical;
    -webkit-line-clamp: 2;
  }
}

/* --------------------------------------------------------------------------
   7. Movimiento reducido
   -------------------------------------------------------------------------- */

@media (prefers-reduced-motion: reduce) {

  .cns-overlay,
  .cns-overlay.is-open {
    clip-path: none;
    opacity: 0;
    transition: opacity 150ms linear, visibility 0s linear 150ms;
  }

  .cns-overlay.is-open {
    opacity: 1;
    transition: opacity 150ms linear, visibility 0s linear 0s;
  }

  .cns-panel,
  .cns-form,
  .cns-close,
  .cns-submit,
  .cns-results,
  .cns-overlay.is-open .cns-form,
  .cns-overlay.is-open .cns-close,
  .cns-overlay.is-open .cns-submit,
  .cns-overlay.is-open .cns-results {
    transition: none;
    opacity: 1;
  }

  .cns-overlay.has-results .cns-panel {
    transform: translate(-50%, 0);
  }

  .cns-skeleton i,
  .cns-skeleton span {
    animation: none;
  }
}

@media (max-width: 900px) and (max-height: 520px) and (orientation: landscape) {
  .cns-close {
    top: calc(8px + env(safe-area-inset-top));
    right: calc(10px + env(safe-area-inset-right));
  }

  .cns-panel,
  .cns-overlay.has-results .cns-panel {
    top: calc(62px + env(safe-area-inset-top));
    width: min(720px, calc(100% - 96px));
    transform: translate(-50%, 0);
  }

  .cns-results {
    max-height: calc(100dvh - 145px);
  }
}
