/* Solo2 Component: Message Bubbles (Premium Geometry) */

.message-row {
    display: flex;
    width: 100%;
    margin-bottom: 2px;
    animation: messageFadeIn 0.2s ease-out forwards;
}

.message-row.sent { justify-content: flex-end; }
.message-row.received { justify-content: flex-start; }

/* Espaciado contextual */
.message-row.different-sender { margin-top: 12px; }
.message-row.same-sender { margin-top: 4px; }

.message-bubble {
    max-width: 75%;
    padding: 10px 16px;
    position: relative;
    font-size: var(--fs-md);
    line-height: 1.5;
    word-wrap: break-word;
}

/* Burbuja Enviada — glassmorphism con presencia visible */
.message-bubble.sent {
    background-color: rgba(99, 102, 241, 0.32);
    backdrop-filter: blur(12px);
    -webkit-backdrop-filter: blur(12px);
    color: var(--color-text, #e2e8f0);
    border-radius: 18px 18px 4px 18px;
    border: 1px solid rgba(99, 102, 241, 0.25);
}

/* Burbuja Recibida — cristal sutil pero distinguible */
.message-bubble.received {
    background-color: rgba(200, 200, 220, 0.15);
    backdrop-filter: blur(12px);
    -webkit-backdrop-filter: blur(12px);
    color: var(--color-text);
    border-radius: 18px 18px 18px 4px;
    border: 1px solid rgba(255, 255, 255, 0.10);
}

/* Emoji-only messages: giant, no bubble */
.message-bubble.emoji-only {
    background: transparent !important;
    border: none !important;
    backdrop-filter: none !important;
    -webkit-backdrop-filter: none !important;
    font-size: 2.5rem;
    line-height: 1.2;
    padding: 4px 8px;
}

.message-bubble.ephemeral {
    border-left: 3px solid rgba(147, 51, 234, 0.5);
}

/* Light theme overrides */
[data-theme="light"] .message-bubble.sent {
    background-color: rgba(99, 102, 241, 0.18);
    border-color: rgba(99, 102, 241, 0.22);
}

[data-theme="light"] .message-bubble.received {
    background-color: rgba(0, 0, 0, 0.06);
    border-color: rgba(0, 0, 0, 0.10);
}

/* Colas triangulares (solo primera burbuja del grupo) */
.message-row.sent.different-sender .message-bubble::before {
    content: '';
    position: absolute;
    bottom: 0;
    right: -6px;
    width: 12px;
    height: 12px;
    background: inherit;
    clip-path: polygon(0 0, 0% 100%, 100% 100%);
}

.message-row.received.different-sender .message-bubble::before {
    content: '';
    position: absolute;
    bottom: 0;
    left: -6px;
    width: 12px;
    height: 12px;
    background: inherit;
    clip-path: polygon(100% 0, 0% 100%, 100% 100%);
}

/* No tail on emoji-only bubbles */
.message-bubble.emoji-only::before {
    display: none !important;
}

/* Metadatos — sutiles, no compiten con el mensaje */
.msg-meta {
    display: flex;
    align-items: center;
    justify-content: flex-end;
    gap: 6px;
    font-size: var(--fs-2xs);
    opacity: 0.5;
    margin-top: 4px;
}

.msg-time { font-family: monospace; }

/* Estados de entrega - VISIBLES PARA PRESBICIA */
.msg-status {
    font-size: var(--fs-lg);
    display: inline-flex;
    align-items: center;
    line-height: 1;
    min-width: 20px;
    justify-content: center;
    font-weight: 600;
}

.msg-status span {
    transition: all 0.2s ease;
}

/* Animación para el reloj de arena */
@keyframes spin-slow {
    from { transform: rotate(0deg); }
    to { transform: rotate(360deg); }
}

.msg-status [title*="cola"] {
    display: inline-block;
    animation: spin-slow 3s linear infinite;
}

/* Estabilizar scrollbar — evitar "latido" al cambiar status bar */
#chat-area > .overflow-y-auto {
    scrollbar-gutter: stable;
}

/* Viñeta: Umbral del Túnel */
#chat-area {
    position: relative;
}

#chat-area::before {
    content: '';
    position: absolute;
    inset: 0;
    pointer-events: none;
    box-shadow: inset 0 0 60px 10px rgba(0,0,0,0.15);
    z-index: 5;
}

@keyframes messageFadeIn {
    from { opacity: 0; transform: translateY(5px); }
    to { opacity: 1; transform: translateY(0); }
}

/* Pop animation for real-time messages (not vault loads) */
@keyframes msg-pop {
    from { opacity: 0; transform: scale(0.97) translateY(4px); }
    to { opacity: 1; transform: scale(1) translateY(0); }
}

.message-row.msg-new {
    animation: msg-pop 200ms ease-out;
}

/* ========================================================================
   DATE SEPARATORS (Hoy / Ayer / fecha)
   ======================================================================== */

.date-separator {
    display: flex;
    justify-content: center;
    margin: 16px 0 8px;
}

.date-separator::before,
.date-separator::after {
    display: none;
}

.date-separator-text {
    font-size: var(--fs-2xs);
    color: var(--color-text);
    background: rgba(255, 255, 255, 0.08);
    padding: 3px 12px;
    border-radius: 999px;
    opacity: 0.6;
    white-space: nowrap;
}

[data-theme="light"] .date-separator-text {
    background: rgba(0, 0, 0, 0.06);
}

/* ========================================================================
   FILE BUBBLES
   ======================================================================== */

.file-bubble {
    padding: 8px;
    max-width: 280px;
}

/* File preview for images */
.file-preview {
    position: relative;
    border-radius: 12px;
    overflow: hidden;
    margin-bottom: 6px;
}

.file-thumbnail {
    display: block;
    width: 100%;
    max-height: 200px;
    object-fit: cover;
    border-radius: 8px;
}

.file-thumbnail.clickable {
    cursor: pointer;
    transition: transform 0.15s ease;
}

.file-thumbnail.clickable:hover {
    transform: scale(1.02);
}

/* Progress overlay for images */
.file-overlay {
    position: absolute;
    inset: 0;
    background: rgba(0, 0, 0, 0.5);
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: 8px;
}

/* Progress ring (for images) */
.file-progress-ring {
    width: 60px;
    height: 60px;
    position: relative;
}

.file-progress-ring svg {
    width: 100%;
    height: 100%;
    transform: rotate(-90deg);
}

.file-progress-ring .ring-bg {
    fill: none;
    stroke: rgba(255, 255, 255, 0.2);
    stroke-width: 3;
}

.file-progress-ring .ring-fill {
    fill: none;
    stroke: var(--color-primary);
    stroke-width: 3;
    stroke-linecap: round;
    transition: stroke-dasharray 0.2s ease;
}

.file-progress-ring .progress-percent {
    position: absolute;
    inset: 0;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: var(--fs-xs);
    font-weight: bold;
    color: white;
}

/* File info */
.file-info {
    display: flex;
    flex-direction: column;
    gap: 2px;
}

.file-name {
    font-size: var(--fs-sm);
    font-weight: 500;
    word-break: break-word;
    opacity: 0.9;
}

.file-size {
    font-size: var(--fs-xs);
    opacity: 0.6;
}

/* Non-image file content */
.file-content {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 4px;
}

.file-icon {
    font-size: var(--fs-3xl);
    flex-shrink: 0;
}

.file-details {
    flex: 1;
    min-width: 0;
    display: flex;
    flex-direction: column;
    gap: 2px;
}

/* Progress bar (for non-images) */
.file-progress-bar {
    width: 100%;
    height: 4px;
    background: rgba(255, 255, 255, 0.1);
    border-radius: 2px;
    margin-top: 6px;
    overflow: hidden;
}

.file-progress-bar .progress-fill {
    height: 100%;
    background: var(--color-primary);
    border-radius: 2px;
    transition: width 0.2s ease;
}

/* Download button */
.file-download-btn {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 32px;
    height: 32px;
    background: rgba(255, 255, 255, 0.1);
    border-radius: 50%;
    text-decoration: none;
    transition: background 0.15s ease;
    flex-shrink: 0;
}

.file-download-btn:hover {
    background: rgba(255, 255, 255, 0.2);
}

/* Error state */
.file-bubble.file-error {
    opacity: 0.7;
}

.file-error-icon {
    font-size: var(--fs-2xl);
}

/* ========================================================================
   IMAGE VIEWER (fullscreen)
   ======================================================================== */

.image-viewer {
    position: fixed;
    inset: 0;
    z-index: 9999;
    display: flex;
    align-items: center;
    justify-content: center;
}

.image-viewer-backdrop {
    position: absolute;
    inset: 0;
    background: rgba(0, 0, 0, 0.9);
    cursor: pointer;
}

.image-viewer-content {
    position: relative;
    z-index: 1;
    max-width: 90vw;
    max-height: 90vh;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 16px;
}

.image-viewer-content img {
    max-width: 100%;
    max-height: calc(90vh - 60px);
    object-fit: contain;
    border-radius: 8px;
    box-shadow: 0 10px 40px rgba(0, 0, 0, 0.5);
}

.image-viewer-actions {
    display: flex;
    gap: 12px;
}

.image-viewer-actions .btn-secondary {
    background: rgba(255, 255, 255, 0.1);
    border: 1px solid rgba(255, 255, 255, 0.2);
    color: white;
    padding: 8px 16px;
    border-radius: 8px;
    cursor: pointer;
    font-size: var(--fs-base);
    text-decoration: none;
    transition: background 0.15s ease;
}

.image-viewer-actions .btn-secondary:hover {
    background: rgba(255, 255, 255, 0.2);
}

/* ========================================================================
   DROP ZONE OVERLAY
   ======================================================================== */

#drop-zone-overlay {
    backdrop-filter: blur(4px);
    animation: dropZoneFadeIn 0.15s ease;
}

@keyframes dropZoneFadeIn {
    from { opacity: 0; }
    to { opacity: 1; }
}

#drop-zone-overlay > div {
    animation: dropZoneScale 0.2s ease;
}

@keyframes dropZoneScale {
    from { transform: scale(0.9); opacity: 0; }
    to { transform: scale(1); opacity: 1; }
}