/* ==========================================================================
   St. Matthew's College — asistente.css
   Panel integrado al design system (tokens de main.css).
   Capas: preview-flag 200 · asistente launcher 199 · nav-open drawer 220 · panel asistente 221
   · galería 210 · nav-drawer cerrado 120 · skip-link focus 999
   ========================================================================== */

.visually-hidden {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
}

.smc-asistente {
  position: relative;
  --asistente-panel-border: color-mix(in srgb, var(--line) 42%, transparent);
  --asistente-sheet-radius: 23px;
  --asistente-sheet-elev: 0 -10px 42px rgba(15, 8, 8, 0.11), 0 -2px 10px rgba(15, 8, 8, 0.06);
  --asistente-bubble-radius: 1.05rem;
  /* Ajuste óptico leve: compensa aire transparente bajo los pies en el asset. */
  --launcher-feet-ground: 0.26rem;
  --launcher-position-nudge: 5px;
  /* Sin z-index aquí: el panel (221) no debe quedar capado por preview-flag (200). */
}

.smc-asistente__launcher {
  position: fixed;
  right: max(0.75rem, var(--gutter));
  /* Mobile/tablet: cerca del filete dorado (.mobile-bar), sin invadir la barra. */
  bottom: calc(66px + env(safe-area-inset-bottom) + 0.15rem);
  z-index: 199;
  display: flex;
  align-items: flex-end;
  justify-content: center;
  width: fit-content;
  height: fit-content;
  min-width: 0;
  min-height: 0;
  padding: 0;
  border: none;
  border-radius: 0;
  background: transparent;
  cursor: pointer;
  transition: transform 0.18s var(--ease);
  -webkit-tap-highlight-color: transparent;
}

.smc-asistente__launcher-hint {
  position: absolute;
  right: calc(100% + 0.55rem);
  bottom: 1.35rem;
  z-index: 1;
  min-width: 8.75rem;
  max-width: 14rem;
  padding: 0.55rem 0.7rem;
  text-align: left;
  background: var(--paper);
  color: var(--ink);
  border: 1px solid var(--line);
  border-radius: var(--radius-md, 8px);
  box-shadow: var(--shadow-lg);
  opacity: 0;
  visibility: hidden;
  transform: translateX(8px);
  transition:
    opacity 0.2s var(--ease),
    transform 0.2s var(--ease),
    visibility 0.2s;
  pointer-events: none;
}

.smc-asistente__launcher-hint::after {
  content: "";
  position: absolute;
  top: 50%;
  right: -6px;
  width: 10px;
  height: 10px;
  margin-top: -5px;
  background: var(--paper);
  border-right: 1px solid var(--line);
  border-top: 1px solid var(--line);
  transform: rotate(45deg);
}

.smc-asistente__launcher-hint-text {
  display: block;
  font-family: var(--font-body);
  font-size: 0.8125rem;
  line-height: 1.4;
  color: var(--ink);
}

.smc-asistente__launcher-hint-text strong {
  font-weight: 700;
  color: var(--bordo);
}

@media (hover: hover) {
  .smc-asistente__launcher:hover .smc-asistente__launcher-hint {
    opacity: 1;
    visibility: visible;
    transform: translateX(0);
  }
}

.smc-asistente__launcher:focus-visible .smc-asistente__launcher-hint {
  opacity: 1;
  visibility: visible;
  transform: translateX(0);
}

.smc-asistente__launcher:hover {
  transform: translateY(-2px);
}

.smc-asistente__launcher:focus-visible {
  outline: 3px solid var(--dorado-light);
  outline-offset: 2px;
  border-radius: var(--radius-sm);
}

/*
 * Launcher animado: visual ~88% del tamaño pre-reducción (+10% sobre el 80% previo).
 * El hitbox sigue la silueta del asset (bbox ~240×309 en lienzo 320×320)
 * y escala con --launcher-visual-w.
 */
.smc-asistente__launcher-figure {
  --launcher-visual-w: 4.6rem;
  --launcher-visual-h: 7.02rem;
  --launcher-hit-w: calc(var(--launcher-visual-w) * 240 / 320);
  --launcher-hit-h: calc(var(--launcher-visual-w) * 309 / 320);
  position: relative;
  display: block;
  width: var(--launcher-hit-w);
  height: var(--launcher-hit-h);
  flex-shrink: 0;
  overflow: visible;
  transform: translateY(calc(var(--launcher-feet-ground) + var(--launcher-position-nudge, 0px)));
}

.smc-asistente__launcher-visual {
  position: absolute;
  left: 50%;
  bottom: 0;
  transform: translateX(-50%);
  width: var(--launcher-visual-w);
  height: var(--launcher-visual-h);
  pointer-events: none;
  overflow: visible;
}

.smc-asistente__launcher-media {
  position: absolute;
  left: 50%;
  bottom: 0;
  transform: translateX(-50%);
  width: 100%;
  height: 100%;
  margin: 0;
  display: block;
  pointer-events: none;
  max-height: none;
  max-width: none;
  object-fit: contain;
  object-position: center bottom;
  background: transparent;
  transition: none;
  /* Sombra oscura + blur mínimo + microajuste óptico (sin glow). */
  filter:
    contrast(0.92)
    saturate(0.84)
    brightness(0.985)
    blur(0.22px)
    drop-shadow(0 10px 26px rgba(0, 0, 0, 0.11))
    drop-shadow(0 6px 14px rgba(0, 0, 0, 0.18))
    drop-shadow(0 2px 3px rgba(0, 0, 0, 0.14));
}

.smc-asistente__launcher-video {
  visibility: hidden;
}

.smc-asistente.has-launcher-video .smc-asistente__launcher-video {
  visibility: visible;
}

.smc-asistente.has-launcher-video .smc-asistente__launcher-fallback {
  visibility: hidden;
}

.smc-asistente.is-open .smc-asistente__launcher {
  visibility: hidden;
  pointer-events: none;
}

.smc-asistente.is-open .smc-asistente__launcher-hint {
  visibility: hidden;
  opacity: 0;
}

.smc-asistente__panel {
  position: fixed;
  z-index: 221;
  display: none;
  flex-direction: column;
  background: var(--paper);
  color: var(--ink);
  border: 1px solid var(--asistente-panel-border, var(--line));
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-lg);
  overflow: hidden;
  transform-origin: center bottom;
}

.smc-asistente.is-open .smc-asistente__panel {
  display: flex;
}

.smc-asistente__sheet-handle {
  display: none;
  flex-shrink: 0;
  padding: 0.5rem 0 0.25rem;
  text-align: center;
  background: var(--paper);
}

.smc-asistente__sheet-handle::before {
  content: "";
  display: inline-block;
  width: 2.25rem;
  height: 0.25rem;
  border-radius: 999px;
  background: color-mix(in srgb, var(--ink) 16%, transparent);
}

.smc-asistente__header {
  display: flex;
  align-items: center;
  gap: 0.65rem;
  padding: 0.55rem 0.85rem 0.75rem;
  background: var(--paper);
  color: var(--ink);
  flex-shrink: 0;
  border-bottom: 1px solid var(--asistente-panel-border, var(--line));
  box-shadow: inset 0 1px 0 color-mix(in srgb, var(--dorado) 22%, transparent);
}

.smc-asistente__avatar-media {
  position: relative;
  display: block;
  width: 48px;
  height: 48px;
  flex-shrink: 0;
  overflow: visible;
}

.smc-asistente__avatar {
  position: absolute;
  inset: 0;
  display: block;
  width: 100%;
  height: 100%;
  max-width: none;
  max-height: none;
  object-fit: contain;
  object-position: center;
  pointer-events: none;
  background: transparent;
  filter:
    contrast(0.92)
    saturate(0.84)
    brightness(0.985)
    blur(0.22px)
    drop-shadow(0 2px 5px rgba(0, 0, 0, 0.22))
    drop-shadow(0 1px 2px rgba(0, 0, 0, 0.16));
}

.smc-asistente__header-text {
  flex: 1;
  min-width: 0;
}

.smc-asistente__title {
  margin: 0;
  font-family: var(--font-head);
  font-size: 1rem;
  font-weight: 400;
  color: var(--bordo);
  line-height: 1.2;
}

.smc-asistente__subtitle {
  margin: 0.15rem 0 0;
  font-size: 0.75rem;
  color: var(--ink-faint);
  line-height: 1.35;
}

.smc-asistente__close {
  flex-shrink: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  width: 2rem;
  height: 2rem;
  border: none;
  border-radius: var(--radius-btn);
  background: transparent;
  color: var(--ink-faint);
  font-size: 1.625rem;
  line-height: 1;
  cursor: pointer;
}

.smc-asistente__close:hover {
  background: color-mix(in srgb, var(--bordo) 6%, transparent);
  color: var(--bordo);
}

.smc-asistente__close:focus,
.smc-asistente__close:focus-visible {
  outline: none !important;
  background: color-mix(in srgb, var(--bordo) 6%, transparent);
  color: var(--bordo);
}

.smc-asistente__log {
  flex: 1 1 auto;
  min-height: 0;
  overflow-y: auto;
  padding: 0.85rem;
  background: color-mix(in srgb, var(--paper-soft) 88%, var(--paper) 12%);
}

.smc-asistente__msg {
  margin: 0 0 0.75rem;
  max-width: 92%;
}

.smc-asistente__msg--bot {
  margin-right: auto;
}

.smc-asistente__msg--user {
  margin-left: auto;
  text-align: right;
}

.smc-asistente__bubble {
  display: inline-block;
  padding: 0.55rem 0.75rem;
  border-radius: var(--asistente-bubble-radius);
  font-size: 0.875rem;
  line-height: 1.45;
  text-align: left;
  border: none;
  background: var(--paper);
  box-shadow: 0 1px 2px rgba(15, 8, 8, 0.05), 0 0 0 1px color-mix(in srgb, var(--line) 35%, transparent);
}

.smc-asistente__msg--user .smc-asistente__bubble {
  background: color-mix(in srgb, var(--bordo) 7%, var(--paper));
  box-shadow: 0 1px 3px rgba(95, 7, 9, 0.06);
}

.smc-asistente__suggestions {
  display: flex;
  flex-wrap: nowrap;
  align-items: stretch;
  gap: 0.4rem;
  padding: 0.35rem 0.85rem 0.5rem;
  flex-shrink: 0;
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
  scrollbar-width: thin;
  background: var(--paper);
  border-top: 1px solid color-mix(in srgb, var(--line) 55%, transparent);
}

.smc-asistente__chip {
  font-family: var(--font-body);
  font-size: 0.8125rem;
  padding: 0.38rem 0.72rem;
  border-radius: 999px;
  border: 1px solid color-mix(in srgb, var(--bordo) 14%, var(--line));
  background: color-mix(in srgb, var(--paper) 92%, var(--bordo) 3%);
  color: var(--bordo);
  cursor: pointer;
  flex: 0 0 auto;
  max-width: min(100%, 14rem);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  transition:
    background-color 0.16s var(--ease),
    border-color 0.16s var(--ease),
    color 0.16s var(--ease),
    box-shadow 0.16s var(--ease);
}

.smc-asistente__chip:hover {
  background: color-mix(in srgb, var(--bordo) 5%, var(--paper));
  border-color: color-mix(in srgb, var(--bordo) 22%, var(--line));
  color: var(--bordo);
}

.smc-asistente__chip:focus,
.smc-asistente__chip:focus-visible {
  outline: none !important;
  box-shadow: none;
}

.smc-asistente__chip:focus-visible {
  background: var(--paper);
  border-color: var(--line);
  color: var(--bordo);
}

.smc-asistente__chip:active {
  background: rgba(95, 7, 9, 0.06);
  border-color: rgba(95, 7, 9, 0.3);
}

.smc-asistente__chip--more {
  font-weight: 600;
}

@media (min-width: 1280px) {
  .smc-asistente__suggestions:not(.is-expanded) {
    flex-wrap: nowrap;
    overflow-x: hidden;
  }

  .smc-asistente__suggestions.is-expanded {
    flex-wrap: wrap;
    overflow-x: hidden;
  }
}

.smc-asistente__scope {
  margin: 0;
  padding: 0 0.85rem 0.45rem;
  font-size: 0.6875rem;
  color: var(--ink-faint);
  line-height: 1.35;
  flex-shrink: 0;
  background: var(--paper);
}

.smc-asistente__form {
  display: flex;
  gap: 0.45rem;
  align-items: center;
  padding: 0.35rem 0.85rem calc(0.65rem + env(safe-area-inset-bottom));
  border-top: none;
  background: var(--paper);
  flex-shrink: 0;
}

.smc-asistente__input {
  flex: 1;
  min-width: 0;
  padding: 0.55rem 0.75rem;
  border: 1px solid color-mix(in srgb, var(--line) 70%, transparent);
  border-radius: 999px;
  font: inherit;
  font-size: 0.9375rem;
  background: color-mix(in srgb, var(--paper-soft) 55%, var(--paper));
  transition: border-color 0.16s var(--ease), box-shadow 0.16s var(--ease), background-color 0.16s var(--ease);
}

.smc-asistente__input:focus,
.smc-asistente__input:focus-visible {
  outline: none !important;
  outline-offset: 0;
  box-shadow: none;
  border-color: var(--line);
}

.smc-asistente__send {
  flex-shrink: 0;
  --btn-bg: transparent;
  --btn-fg: var(--bordo);
  min-height: 42px;
  padding: 0.45rem 0.65rem;
  font-weight: 500;
  font-size: 0.875rem;
  letter-spacing: 0.01em;
  border-color: transparent;
  box-shadow: none;
}

.smc-asistente__send:hover {
  --btn-fg: var(--bordo-dark, var(--bordo));
  background: color-mix(in srgb, var(--bordo) 6%, transparent);
}

@media (min-width: 768px) {
  .smc-asistente__panel {
    right: max(0.75rem, var(--gutter));
    bottom: calc(66px + env(safe-area-inset-bottom) + 0.5rem);
    width: min(400px, calc(100vw - 2rem));
    height: min(560px, calc(100dvh - var(--header-h) - 5rem));
    max-height: calc(100dvh - var(--header-h) - 4rem);
  }
}

@media (min-width: 1280px) {
  .smc-asistente {
    --launcher-feet-ground: 0.3rem;
    --launcher-position-nudge: 9px;
  }

  .smc-asistente__launcher {
    right: calc(50px + 1rem);
    bottom: max(0.55rem, env(safe-area-inset-bottom, 0px));
  }

  .smc-asistente__launcher-figure {
    --launcher-visual-w: 6.93rem;
    --launcher-visual-h: 10.78rem;
  }

  .smc-asistente__launcher-media {
    filter:
      contrast(0.92)
      saturate(0.84)
      brightness(0.985)
      blur(0.22px)
      drop-shadow(0 14px 38px rgba(0, 0, 0, 0.14))
      drop-shadow(0 10px 22px rgba(0, 0, 0, 0.22))
      drop-shadow(0 3px 6px rgba(0, 0, 0, 0.16));
  }

  .smc-asistente__panel {
    right: calc(50px + 1rem);
    bottom: 1.15rem;
    height: min(560px, calc(100dvh - var(--header-h) - 3rem));
  }
}

@media (max-width: 1279px) {
  .smc-asistente:not([hidden]) .smc-asistente__panel {
    display: flex;
  }

  .smc-asistente__panel {
    left: max(10px, env(safe-area-inset-left, 0px));
    right: max(10px, env(safe-area-inset-right, 0px));
    bottom: 0;
    width: auto;
    max-width: none;
    box-sizing: border-box;
    padding-left: 0;
    padding-right: 0;
    padding-bottom: env(safe-area-inset-bottom, 0);
    height: 78dvh;
    max-height: 78dvh;
    border: none;
    border-radius: var(--asistente-sheet-radius) var(--asistente-sheet-radius) 0 0;
    box-shadow: var(--asistente-sheet-elev);
    overflow-x: hidden;
    visibility: hidden;
    pointer-events: none;
    opacity: 0;
    transform: translateY(100%) scale(0.985);
    transition:
      transform 0.28s var(--ease),
      opacity 0.28s var(--ease),
      visibility 0s linear 0.28s;
  }

  .smc-asistente.is-open .smc-asistente__panel {
    visibility: visible;
    pointer-events: auto;
    opacity: 1;
    transform: translateY(0) scale(1);
    transition:
      transform 0.28s var(--ease),
      opacity 0.28s var(--ease),
      visibility 0s;
  }

  .smc-asistente__sheet-handle {
    display: block;
    padding-top: 0.45rem;
  }

  .smc-asistente__header {
    padding-top: 0.35rem;
  }

  .smc-asistente__messages,
  .smc-asistente__composer {
    max-width: 100%;
    overflow-x: hidden;
  }

  .smc-asistente.is-keyboard .smc-asistente__panel {
    height: calc(100dvh - env(safe-area-inset-top));
    max-height: calc(100dvh - env(safe-area-inset-top));
  }

  .smc-asistente__launcher-hint {
    right: auto;
    left: 50%;
    bottom: calc(100% + 0.4rem);
    transform: translate(-50%, 10px);
    text-align: center;
  }

  .smc-asistente__launcher-hint::after {
    top: auto;
    bottom: -6px;
    right: 50%;
    margin-top: 0;
    margin-right: -5px;
    border-right: none;
    border-top: none;
    border-left: 1px solid var(--line);
    border-bottom: 1px solid var(--line);
    transform: rotate(45deg);
  }

  @media (hover: hover) {
    .smc-asistente__launcher:hover .smc-asistente__launcher-hint {
      transform: translate(-50%, 0);
    }
  }

  .smc-asistente__launcher:focus-visible .smc-asistente__launcher-hint {
    transform: translate(-50%, 0);
  }
}

body.smc-asistente-open {
  overflow: hidden;
}

body.smc-asistente-open .preview-flag {
  z-index: 180;
}

@media (prefers-reduced-motion: reduce) {
  .smc-asistente__launcher,
  .smc-asistente__panel,
  .smc-asistente__launcher-hint {
    transition: none;
  }

  @media (max-width: 1279px) {
    .smc-asistente:not(.is-open) .smc-asistente__panel {
      transform: translateY(100%);
      opacity: 0;
    }

    .smc-asistente.is-open .smc-asistente__panel {
      transform: translateY(0);
      opacity: 1;
    }
  }
}
