/* UFY PHONE — EL CHAT
   Diseño D · Estilos aislados del resto de UFY
*/

.ufy-el-chat {
  --chat-text: #f7f3ff;
  --chat-muted: #d1c4e2;
  --chat-accent: #c4a4ff;
  --chat-border: rgba(214, 190, 255, 0.36);
  --chat-wallpaper: none;

  position: relative;
  isolation: isolate;
  min-height: 100vh;
  min-height: 100dvh;
  color: var(--chat-text);
  background-color: #171124;
  font-family: system-ui, -apple-system, BlinkMacSystemFont,
    "Segoe UI", sans-serif;
  color-scheme: dark;
}

.ufy-el-chat,
.ufy-el-chat *,
.ufy-el-chat *::before,
.ufy-el-chat *::after {
  box-sizing: border-box;
}

.ufy-el-chat::before {
  content: "";
  position: fixed;
  inset: 0;
  z-index: -1;
  pointer-events: none;
  background-image:
    linear-gradient(
      180deg,
      rgba(19, 12, 36, 0.48),
      rgba(19, 12, 36, 0.22) 45%,
      rgba(19, 12, 36, 0.52)
    ),
    var(--chat-wallpaper);
  background-position: center;
  background-size: cover;
  background-repeat: no-repeat;
}

.ufy-el-chat button:not(.ufy-phone-reel-comments button),
.ufy-el-chat input:not(.ufy-phone-reel-comments input) {
  font: inherit;
}

.ufy-el-chat button {
  color: inherit;
}

.ufy-el-chat a {
  color: inherit;
  text-decoration: none;
}

.ufy-el-chat button {
  cursor: pointer;
}

.ufy-el-chat button:disabled {
  cursor: default;
  opacity: 0.5;
}

.ufy-el-chat :focus-visible {
  outline: 2px solid var(--chat-accent);
  outline-offset: 4px;
}

.ufy-el-chat [hidden] {
  display: none !important;
}

.ufy-el-chat svg {
  width: 20px;
  height: 20px;
  flex-shrink: 0;
}

.ufy-el-chat-shell {
  width: min(100%, 620px);
  margin-inline: auto;
  padding:
    max(12px, env(safe-area-inset-top))
    12px
    max(28px, env(safe-area-inset-bottom));
}

/* Cabecera y gesto de cierre */

.ufy-el-chat-topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  min-height: 36px;
}

.ufy-el-chat-brand {
  font-size:calc(18px * var(--ufy-font-scale,1));
  font-weight: 800;
  letter-spacing: 0.04em;
}

.ufy-el-chat-close {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 7px;
  min-width: 44px;
  min-height: 44px;
  padding: 8px;
  border: 0;
  background: transparent;
  color: var(--chat-muted);
  touch-action: pan-x;
}

.ufy-el-chat-close-hint {
  font-size:calc(13px * var(--ufy-font-scale,1));
  animation: ufy-el-chat-hint 1s ease-in-out 4;
}

@keyframes ufy-el-chat-hint {
  0%, 100% { opacity: 1; }
  50% { opacity: 0.4; }
}

.ufy-el-chat-header {
  padding-block: 18px 14px;
}

.ufy-el-chat-members {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 12px;
  width: 100%;
  min-height: 48px;
  padding: 0;
  border: 0;
  background: transparent;
}

.ufy-el-chat-title {
  margin: 0;
  font-size: clamp(22px, 5.4vw, 29px);
  font-weight: 600;
  letter-spacing: -0.03em;
}

.ufy-el-chat-member-avatars {
  display: flex;
  align-items: center;
  padding-left: 9px;
}

.ufy-el-chat-member-avatars img {
  width: 34px;
  height: 34px;
  margin-left: -9px;
  border: 2px solid rgba(239, 226, 255, 0.85);
  border-radius: 50%;
  object-fit: cover;
  background: #34273f;
}

/* Buscador independiente de personas */

.ufy-el-chat-search {
  display: flex;
  align-items: center;
  gap: 9px;
  width: min(100%, 430px);
  min-height: 44px;
  margin: 14px auto 0;
  padding: 9px 14px;
  border: 1px solid var(--chat-border);
  border-radius: 24px;
  background: rgba(39, 27, 61, 0.44);
  backdrop-filter: blur(6px);
  -webkit-backdrop-filter: blur(6px);
  color: var(--chat-muted);
}

.ufy-el-chat-search input {
  width: 100%;
  min-width: 0;
  padding: 0;
  border: 0;
  background: transparent;
  color: var(--chat-text);
  font-size:calc(16px * var(--ufy-font-scale,1));
}

.ufy-el-chat-search input::placeholder {
  color: var(--chat-muted);
  opacity: 1;
}

.ufy-el-chat-search:focus-within {
  outline: 2px solid var(--chat-accent);
  outline-offset: 3px;
}

.ufy-el-chat-search input:focus-visible {
  outline: none;
}

/* Resultados del buscador — Diseño F */

.ufy-el-chat-search-results {
  width: min(100%, 430px);
  margin: 12px auto 0;
  overflow: hidden;

  border: 1px solid rgba(214, 190, 255, 0.25);
  border-radius: 22px;

  background:
    linear-gradient(
      160deg,
      rgba(65, 43, 87, 0.72),
      rgba(27, 19, 42, 0.82)
    );

  backdrop-filter: blur(6px);
  -webkit-backdrop-filter: blur(6px);

  
}



.ufy-el-chat-search-heading {
  margin: 0;
  padding: 8px 20px 4px;

  color: var(--chat-text);
  font-size:calc(22px * var(--ufy-font-scale,1));
  font-weight: 500;
  line-height: 1.3;
  letter-spacing: -0.025em;
}

.ufy-el-chat-search-status {
  margin: 0;
  padding: 4px 20px 14px;

  color: var(--chat-muted);
  font-size:calc(13px * var(--ufy-font-scale,1));
  line-height: 1.5;
  text-align: left;
}

.ufy-el-chat-search-list {
  max-height: 50vh;
  max-height: 50dvh;
  margin: 0;
  padding: 0 14px 8px;
  overflow-y: auto;

  list-style: none;
  overscroll-behavior-y: contain;

  scrollbar-width: thin;
  scrollbar-color: var(--chat-border) transparent;
}

.ufy-el-chat-search-item + .ufy-el-chat-search-item {
  border-top: 1px solid rgba(216, 192, 245, 0.16);
}

.ufy-el-chat-search-person {
  display: flex;
  align-items: center;
  gap: 14px;

  min-width: 0;
  min-height: 44px;
  margin: 0 5px;
  padding: 2px 4px;
  border-radius: 10px;
}



.ufy-el-chat-search-avatar {
  display: grid;
  place-items: center;
  flex: 0 0 40px;

  width: 40px;
  height: 40px;
  overflow: hidden;

  border: 1px solid rgba(214, 190, 255, 0.3);
  border-radius: 50%;

  background: #49325f;
  color: var(--chat-text);
  font-size:calc(20px * var(--ufy-font-scale,1));
  font-weight: 600;
}

.ufy-el-chat-search-avatar img {
  display: block;
  width: 100%;
  height: 100%;
  object-fit: cover;
}

.ufy-el-chat-search-identity {
  display: flex;
  flex-direction: column;
  gap: 4px;
  min-width: 0;
}

.ufy-el-chat-search-name,
.ufy-el-chat-search-username {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.ufy-el-chat-search-name {
  color: var(--chat-text);
  font-size:calc(16px * var(--ufy-font-scale,1));
  font-weight: 500;
}

.ufy-el-chat-search-username {
  color: var(--chat-muted);
  font-size:calc(14px * var(--ufy-font-scale,1));
}




/* Recientes: perfil a la izquierda y quitar a la derecha */

.ufy-el-chat-search-item--recent {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 44px;
  align-items: center;
  column-gap: 4px;
}

.ufy-el-chat-search-item--recent .ufy-el-chat-search-person {
  min-width: 0;
  margin-right: 0;
}

.ufy-el-chat .ufy-el-chat-recent-remove {
  display: grid;
  place-items: center;

  width: 44px;
  height: 44px;
  padding: 0;

  border: 0;
  border-radius: 10px;
  background: transparent;

  color: var(--chat-muted);
  font-size:calc(24px * var(--ufy-font-scale,1));
  line-height: 1;
}

.ufy-el-chat-recent-remove:disabled {
  cursor: wait;
}

.ufy-el-chat-recent-error {
  grid-column: 1 / -1;
  margin: 0;
  padding: 4px 9px 8px;

  color: #ffd0df;
  font-size:calc(12px * var(--ufy-font-scale,1));
  line-height: 1.4;
}



/* Historias: vista previa del contenido */

.ufy-el-chat-stories {
  display: flex;
  gap: 8px;
  overflow-x: auto;
  margin-block: 4px 18px;
  padding: 4px 2px 8px;
  scroll-snap-type: x proximity;
  scrollbar-width: thin;
  scrollbar-color: var(--chat-border) transparent;
}

.ufy-el-chat-story,
.ufy-el-chat-story-add {
  position: relative;
  flex: 0 0 clamp(104px, 29vw, 148px);
  aspect-ratio: 1 / 1;
  overflow: hidden;
  padding: 0;
  border: 1px solid var(--chat-border);
  border-radius: 18px;
  background: #30233f;
  text-align: left;
  scroll-snap-align: start;
}

.ufy-el-chat-stories-row {
  display: flex;
  align-items: flex-start;
  gap: 8px;
  margin-block: 4px 18px;
  padding: 4px 2px 8px;
}

.ufy-el-chat-stories-row > .ufy-el-chat-stories {
  flex: 1;
  min-width: 0;
  margin: 0;
  padding: 0;
}

.ufy-el-chat-story-add {
  display: flex;
  align-items: center;
  justify-content: center;
  flex-direction: column;
  gap: 8px;
  border: 1.5px dashed var(--chat-border);
  background: linear-gradient(135deg, #ffffff0c, #ffffff02);
  text-align: center;
}

.ufy-el-chat-story-add span:first-child {
  font-size: 38px;
  font-weight: 300;
  line-height: 1;
}

.ufy-el-chat-story-add span:last-child {
  font-size: calc(12px * var(--ufy-font-scale, 1));
  line-height: 1.3;
}

.ufy-el-chat-story > img,
.ufy-el-chat-story > video {
  display: block;
  width: 100%;
  height: 100%;
  object-fit: cover;
}

.ufy-el-chat-story::after {
  content: "";
  position: absolute;
  inset: 35% 0 0;
  pointer-events: none;
  background: linear-gradient(transparent, rgba(12, 8, 22, 0.8));
}

.ufy-el-chat-story-person {
  position: absolute;
  z-index: 1;
  right: 7px;
  bottom: 8px;
  left: 7px;
  display: flex;
  align-items: center;
  gap: 5px;
  font-size:calc(12px * var(--ufy-font-scale,1));
}

.ufy-el-chat-story-person img {
  width: 27px;
  height: 27px;
  flex-shrink: 0;
  border: 1px solid rgba(var(--ufy-rgb-255,255,255,255),0.8);
  border-radius: 50%;
  object-fit: cover;
}

.ufy-el-chat-story-person span {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.ufy-el-chat-story-duration {
  position: absolute;
  z-index: 1;
  top: 7px;
  right: 7px;
  padding: 3px 6px;
  border-radius: 9px;
  background: rgba(15, 10, 26, 0.64);
  font-size:calc(11px * var(--ufy-font-scale,1));
}

/* Publicaciones con forma de conversación */

.ufy-el-chat-feed {
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.ufy-el-chat-post {
  display: grid;
  grid-template-columns: 34px minmax(0, 1fr);
  align-items: start;
  gap: 8px;
  margin-right: 12px;
}

.ufy-el-chat-post--right {
  grid-template-columns: minmax(0, 1fr) 34px;
  margin-right: 0;
  margin-left: 12px;
}

.ufy-el-chat-author-avatar {
  grid-column: 1;
  grid-row: 1;
  display: grid;
  place-items: center;
  width: 34px;
  height: 34px;
  overflow: hidden;
  border: 1px solid var(--chat-border);
  border-radius: 50%;
  background: #3b2b4d;
}

.ufy-el-chat-author-avatar img {
  width: 100%;
  height: 100%;
  object-fit: cover;
}

.ufy-el-chat-post--right .ufy-el-chat-author-avatar {
  grid-column: 2;
}

.ufy-el-chat-bubble {
  position: relative;
  grid-column: 2;
  grid-row: 1;
  min-width: 0;
  border: 1px solid var(--chat-border);
  border-radius: 18px;
  background: rgba(37, 25, 53, 0.56);
  backdrop-filter: blur(6px);
  -webkit-backdrop-filter: blur(6px);
}

.ufy-el-chat-post--right .ufy-el-chat-bubble {
  grid-column: 1;
}

.ufy-el-chat-bubble::before {
  content: "";
  position: absolute;
  top: 15px;
  left: -6px;
  width: 10px;
  height: 10px;
  border-bottom: 1px solid var(--chat-border);
  border-left: 1px solid var(--chat-border);
  background: #382845;
  transform: rotate(45deg);
}

.ufy-el-chat-post--right .ufy-el-chat-bubble::before {
  right: -6px;
  left: auto;
  transform: rotate(225deg);
}

.ufy-el-chat-post-header {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 5px;
  min-height: 39px;
  padding: 9px 11px;
  font-size:calc(13px * var(--ufy-font-scale,1));
}

.ufy-el-chat-post-header a {
  overflow-wrap: anywhere;
  font-weight: 600;
}

.ufy-el-chat-post-header time {
  color: var(--chat-muted);
  font-size:calc(12px * var(--ufy-font-scale,1));
}

.ufy-el-chat-media {
  position: relative;
  overflow: hidden;
  margin-inline: 3px;
  border-radius: 13px;
  background: #140e1d;
}

.ufy-el-chat-media img,
.ufy-el-chat-media video {
  display: block;
  width: 100%;
  height: auto;
  max-height: 70vh;
  max-height: 70dvh;
}

.ufy-el-chat-post--reel .ufy-el-chat-media video {
  aspect-ratio: 1 / 1;
  object-fit: cover;
}


.ufy-el-chat-post-footer {
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-wrap: wrap;
  gap: 5px 10px;
  padding: 8px 11px;
}

.ufy-el-chat-caption {
  flex: 1 1 130px;
  margin: 0;
  font-size:calc(13px * var(--ufy-font-scale,1));
  line-height: 1.45;
  overflow-wrap: anywhere;
  white-space: pre-wrap;
}

.ufy-el-chat-actions {
  display: flex;
  align-items: center;

  gap: 6px;

  min-height: 48px;

  padding:
    4px
    9px
    6px;

  border-top:
    1px solid
    rgba(var(--ufy-rgb-255,255,255,255),0.10);
}


.ufy-el-chat-action {
  appearance: none;

  display: inline-flex;
  align-items: center;
  justify-content: center;

  gap: 5px;

  min-width: 54px;
  min-height: 40px;

  padding:
    5px
    8px;

  border: 0;
  border-radius: 12px;

  background: transparent;
  color: rgba(var(--ufy-rgb-255,255,255,255),0.92);

  font: inherit;

  cursor: pointer;

  transition:
    background-color 140ms ease,
    transform 140ms ease;
}


.ufy-el-chat-action:hover {
  background:
    rgba(var(--ufy-rgb-255,255,255,255),0.08);
}


.ufy-el-chat-action:active {
  transform:
    scale(0.94);
}


.ufy-el-chat-action:disabled {
  cursor: default;
  opacity: 0.55;
}


.ufy-el-chat-action-image {
  display: block;

  width: 22px;
  height: 22px;

  object-fit: contain;

  pointer-events: none;
}


.ufy-el-chat-action-count {
  display: inline-block;

  min-width: 10px;

  color: inherit;

  font-size:calc(12px * var(--ufy-font-scale,1));
  font-weight: 600;

  line-height: 1;
  text-align: center;

  pointer-events: none;
}


.ufy-el-chat-action[aria-pressed="true"] {
  color: #ff9ccf;
}

.ufy-el-chat-state {
  padding: 24px 16px;
  border: 1px solid var(--chat-border);
  border-radius: 18px;
  background: rgba(30, 20, 44, 0.7);
  text-align: center;
  font-size:calc(14px * var(--ufy-font-scale,1));
  line-height: 1.6;
}

@media (max-width: 360px) {
  .ufy-el-chat-shell {
    padding-inline: 8px;
  }

  .ufy-el-chat-post {
    grid-template-columns: 28px minmax(0, 1fr);
    gap: 6px;
    margin-right: 0;
  }

  .ufy-el-chat-post--right {
    grid-template-columns: minmax(0, 1fr) 28px;
    margin-left: 0;
  }

  .ufy-el-chat-author-avatar {
    width: 28px;
    height: 28px;
  }

  .ufy-el-chat-member-avatars img {
    width: 29px;
    height: 29px;
  }
}

@media (prefers-reduced-motion: reduce) {
  .ufy-el-chat-close-hint {
    animation: none;
  }
}
