/* ============================================
   CHAT MOBILE - Estilos para dispositivos móviles
   Diseño profesional y moderno para redes sociales
   Con soporte completo para modo claro y oscuro
   ============================================ */

/* ===== IMPORTAR DESIGN TOKENS ===== */
@import url('./design-tokens.css');

/* ===== VARIABLES PARA CHAT MÓVIL ===== */
:root {
    --chat-mobile-primary: #76ED00;
    --chat-mobile-primary-dark: #5db300;
    --chat-mobile-bg: var(--color-surface-primary);
    --chat-mobile-surface: var(--color-surface-secondary);
    --chat-mobile-elevated: var(--color-surface-elevated);
    --chat-mobile-text: var(--color-text-primary);
    --chat-mobile-text-secondary: var(--color-text-secondary);
    --chat-mobile-text-muted: var(--color-text-tertiary);
    --chat-mobile-border: var(--color-border-secondary);
    --chat-mobile-border-light: var(--color-border-tertiary);
    --chat-mobile-shadow: var(--shadow-md);
    --chat-mobile-fab-bg: linear-gradient(135deg, #2563eb 0%, #1d4ed8 100%);
    --chat-mobile-fab-shadow: 0 4px 12px rgba(37, 99, 235, 0.4);
}

.dark-mode {
    --chat-mobile-bg: #0F0F0F;
    --chat-mobile-surface: #0F0F0F;
    --chat-mobile-elevated: #0F0F0F;
    --chat-mobile-text: #E4E6EB;
    --chat-mobile-text-secondary: #B0B3B8;
    --chat-mobile-text-muted: #8A8D91;
    --chat-mobile-border: rgba(255, 255, 255, 0.08);
    --chat-mobile-border-light: rgba(255, 255, 255, 0.04);
    --chat-mobile-shadow: 0 2px 8px rgba(0, 0, 0, 0.3);
    --chat-mobile-fab-shadow: 0 4px 12px rgba(37, 99, 235, 0.6);
}

/* Fondo uniforme #0F0F0F en modo oscuro - Diseño sutil y elegante */
.dark-mode .chat-mobile-root {
    background: #0F0F0F !important;
}

.dark-mode .chat-mobile-list {
    background: #0F0F0F !important;
}

.dark-mode .chat-mobile-conversation {
    background: #0F0F0F !important;
}

/* ===== CONTENEDOR RAÍZ MÓVIL ===== */
.chat-mobile-root {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    height: 100vh; /* Fallback para navegadores antiguos */
    height: 100dvh; /* Altura dinámica del viewport para móviles modernos */
    z-index: 10002;
    pointer-events: none;
    overflow: hidden;
    display: none;
    background: var(--chat-mobile-bg);
    transition: background-color 0.3s ease;
}

/* Mostrar solo en móviles */
@media (max-width: 768px) {
    .chat-mobile-root {
        display: block;
    }

    /* Ocultar ventanas flotantes de desktop en móvil */
    .chat-ui-root .chat-window {
        display: none !important;
    }
}

/* Ocultar en desktop */
@media (min-width: 769px) {
    .chat-mobile-root {
        display: none !important;
    }
}

/* ===== VISTA DE LISTA DE CHATS ===== */
.chat-mobile-list {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: var(--chat-mobile-bg);
    display: flex;
    flex-direction: column;
    opacity: 0;
    transform: translateX(-100%);
    transition: transform 0.3s cubic-bezier(0.4, 0.0, 0.2, 1), 
                opacity 0.3s cubic-bezier(0.4, 0.0, 0.2, 1),
                background-color 0.3s ease;
    pointer-events: none;
    z-index: 1;
}

.chat-mobile-list.is-active {
    opacity: 1;
    transform: translateX(0);
    pointer-events: all;
}

/* Header de lista */
.chat-mobile-list__header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 16px 20px;
    background: linear-gradient(135deg, var(--chat-mobile-primary) 0%, var(--chat-mobile-primary-dark) 100%);
    color: #ffffff;
    box-shadow: var(--chat-mobile-shadow);
    position: relative;
    z-index: 10;
}

.chat-mobile-list__title {
    font-size: 24px;
    font-weight: 700;
    margin: 0;
    color: #ffffff;
    flex: 1;
}

.chat-mobile-list__actions {
    display: flex;
    align-items: center;
    gap: 8px;
}

.chat-mobile-list__new-btn,
.chat-mobile-list__close-btn {
    width: 44px;
    height: 44px;
    border-radius: 50%;
    border: none;
    background: rgba(255, 255, 255, 0.2);
    color: #ffffff;
    font-size: 20px;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: background 0.2s ease, transform 0.1s ease;
    -webkit-tap-highlight-color: transparent;
}

.chat-mobile-list__close-btn {
    font-size: 22px;
}

.chat-mobile-list__new-btn:active,
.chat-mobile-list__close-btn:active {
    background: rgba(255, 255, 255, 0.3);
    transform: scale(0.95);
}

.chat-mobile-list__close-btn:hover,
.chat-mobile-list__new-btn:hover {
    background: rgba(255, 255, 255, 0.25);
}

/* Búsqueda */
.chat-mobile-list__search {
    position: relative;
    padding: 12px 20px;
    background: var(--chat-mobile-surface);
    border-bottom: 1px solid var(--chat-mobile-border);
    transition: background-color 0.3s ease, border-color 0.3s ease;
}

.chat-mobile-list__search i {
    position: absolute;
    left: 32px;
    top: 50%;
    transform: translateY(-50%);
    color: var(--chat-mobile-text-muted);
    font-size: 16px;
}

.chat-mobile-list__search-input {
    width: 100%;
    padding: 12px 16px 12px 44px;
    border: 1px solid var(--chat-mobile-border);
    border-radius: 24px;
    font-size: 16px;
    background: var(--chat-mobile-bg);
    color: var(--chat-mobile-text);
    outline: none;
    transition: border-color 0.2s ease, box-shadow 0.2s ease, background-color 0.3s ease, color 0.3s ease;
    -webkit-appearance: none;
    appearance: none;
}

.chat-mobile-list__search-input::placeholder {
    color: var(--chat-mobile-text-muted);
}

.chat-mobile-list__search-input:focus {
    border-color: var(--chat-mobile-primary);
    box-shadow: 0 0 0 3px rgba(118, 237, 0, 0.15);
}

/* Contenido de lista */
.chat-mobile-list__content {
    flex: 1;
    overflow-y: auto;
    -webkit-overflow-scrolling: touch;
    background: var(--chat-mobile-bg);
    transition: background-color 0.3s ease;
}

/* Fondo uniforme #0F0F0F */
.dark-mode .chat-mobile-list__content {
    background: #0F0F0F !important;
}

/* Mensaje de búsqueda sin resultados */
.chat-mobile-no-results {
    padding: 48px 24px;
    text-align: center;
    color: var(--chat-mobile-text-muted);
    font-size: 15px;
    display: none;
}

/* Estilos para la lista móvil */
.friends-list--mobile .friend-item {
    padding: 16px 20px;
    border-bottom: 1px solid var(--chat-mobile-border-light);
    min-height: 72px;
    background: var(--chat-mobile-bg);
    transition: background-color 0.2s ease, border-color 0.3s ease;
}

.friends-list--mobile .friend-item:active {
    background: var(--chat-mobile-surface);
}

/* Diseño sutil y elegante con fondo uniforme #0F0F0F */
.dark-mode .friends-list--mobile .friend-item {
    background: #0F0F0F !important;
    border: 1px solid rgba(255, 255, 255, 0.06) !important;
    box-shadow: 0 1px 3px rgba(0, 0, 0, 0.2);
}

.dark-mode .friends-list--mobile .friend-item:active {
    background: #0F0F0F !important;
    border-color: rgba(118, 237, 0, 0.3) !important;
    box-shadow: 0 0 0 2px rgba(118, 237, 0, 0.1);
}

.dark-mode .friends-list--mobile .friend-item:hover {
    background: #0F0F0F !important;
    border-color: rgba(255, 255, 255, 0.1) !important;
}

/* Estilos para los elementos internos de friend-item en modo oscuro */
.dark-mode .friends-list--mobile .friend-item .friend-name,
.dark-mode .friends-list--mobile .friend-item .friend-item__name {
    color: #E4E6EB !important;
}

.dark-mode .friends-list--mobile .friend-item .friend-status,
.dark-mode .friends-list--mobile .friend-item .friend-status-text,
.dark-mode .friends-list--mobile .friend-item .friend-item__last-message,
.dark-mode .friends-list--mobile .friend-item .friend-item__time {
    color: #B0B3B8 !important;
}

.dark-mode .friends-list--mobile .friend-item .friend-chat-btn {
    background: #0F0F0F;
    border: 1px solid rgba(255, 255, 255, 0.1);
    color: #E4E6EB;
}

.dark-mode .friends-list--mobile .friend-item .friend-chat-btn:hover {
    border-color: rgba(255, 255, 255, 0.2);
}

/* Badge en modo oscuro */
.dark-mode .friend-unread-badge {
    background: #76ED00;
    color: #0f172a;
    box-shadow: 0 2px 8px rgba(118, 237, 0, 0.3);
}

/* ===== VISTA DE CONVERSACIÓN ===== */
.chat-mobile-conversation {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: var(--chat-mobile-bg);
    display: flex;
    flex-direction: column;
    opacity: 0;
    transform: translateX(100%);
    transition: transform 0.3s cubic-bezier(0.4, 0.0, 0.2, 1), 
                opacity 0.3s cubic-bezier(0.4, 0.0, 0.2, 1),
                background-color 0.3s ease;
    pointer-events: none;
    z-index: 2;
}

.chat-mobile-conversation.is-active {
    opacity: 1;
    transform: translateX(0);
    pointer-events: all;
}

/* Header de conversación */
.chat-mobile-conversation__header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 12px 16px;
    background: linear-gradient(135deg, var(--chat-mobile-primary) 0%, var(--chat-mobile-primary-dark) 100%);
    color: #ffffff;
    box-shadow: var(--chat-mobile-shadow);
    position: relative;
    z-index: 10;
    min-height: 56px;
}

.chat-mobile-conversation__back-btn {
    width: 44px;
    height: 44px;
    border: none;
    background: transparent;
    color: #ffffff;
    font-size: 20px;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: 50%;
    transition: background 0.2s ease;
    -webkit-tap-highlight-color: transparent;
    margin-right: 8px;
}

.chat-mobile-conversation__back-btn:active {
    background: rgba(255, 255, 255, 0.2);
}

.chat-mobile-conversation__header-info {
    display: flex;
    align-items: center;
    gap: 12px;
    flex: 1;
    min-width: 0;
}

.chat-mobile-conversation__avatar {
    width: 40px;
    height: 40px;
    border-radius: 50%;
    object-fit: cover;
    border: 2px solid rgba(255, 255, 255, 0.3);
    flex-shrink: 0;
}

.chat-mobile-conversation__header-text {
    flex: 1;
    min-width: 0;
}

.chat-mobile-conversation__name {
    font-weight: 600;
    font-size: 16px;
    color: #ffffff;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.chat-mobile-conversation__status {
    font-size: 12px;
    opacity: 0.9;
    color: #ffffff;
}

.chat-mobile-conversation__menu-btn {
    width: 44px;
    height: 44px;
    border: none;
    background: transparent;
    color: #ffffff;
    font-size: 18px;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: 50%;
    transition: background 0.2s ease;
    -webkit-tap-highlight-color: transparent;
    margin-left: 8px;
}

.chat-mobile-conversation__menu-btn:active {
    background: rgba(255, 255, 255, 0.2);
}

/* Mensajes */
.chat-mobile-conversation__messages {
    flex: 1;
    overflow-y: auto;
    -webkit-overflow-scrolling: touch;
    padding: 16px;
    background: var(--chat-mobile-surface);
    display: flex;
    flex-direction: column;
    gap: 12px;
    transition: background-color 0.3s ease;
}

.chat-mobile-message {
    display: flex;
    flex-direction: column;
    max-width: 75%;
    animation: messageSlideIn 0.3s ease;
}

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

.chat-mobile-message--own {
    align-self: flex-end;
    align-items: flex-end;
}

.chat-mobile-message--received {
    align-self: flex-start;
    align-items: flex-start;
}

.chat-mobile-message__content {
    padding: 12px 16px;
    border-radius: 18px;
    font-size: 16px;
    line-height: 1.4;
    word-wrap: break-word;
    position: relative;
    display: inline-block;
    transition: background-color 0.3s ease, color 0.3s ease;
}

.chat-mobile-message--own .chat-mobile-message__content {
    background: linear-gradient(135deg, var(--chat-mobile-primary) 0%, var(--chat-mobile-primary-dark) 100%);
    color: #ffffff;
    border-bottom-right-radius: 4px;
}

.chat-mobile-message--received .chat-mobile-message__content {
    background: var(--chat-mobile-elevated);
    color: var(--chat-mobile-text);
    border-bottom-left-radius: 4px;
    box-shadow: 0 1px 3px rgba(0, 0, 0, 0.1);
}

.dark-mode .chat-mobile-message--received .chat-mobile-message__content {
    background: #0F0F0F !important;
    border: 1px solid rgba(255, 255, 255, 0.08);
    box-shadow: 0 1px 3px rgba(0, 0, 0, 0.3);
}

.chat-mobile-message__status {
    display: inline-block;
    margin-left: 4px;
    font-size: 12px;
    opacity: 0.8;
}

.chat-mobile-message__time {
    font-size: 11px;
    color: var(--chat-mobile-text-muted);
    margin-top: 4px;
    padding: 0 4px;
    transition: color 0.3s ease;
}

.chat-mobile-empty {
    text-align: center;
    color: var(--chat-mobile-text-muted);
    padding: 40px 20px;
    font-size: 14px;
    transition: color 0.3s ease;
}

/* Input container */
.chat-mobile-conversation__input-container {
    padding: 12px 16px;
    background: var(--chat-mobile-bg);
    border-top: 1px solid var(--chat-mobile-border);
    padding-bottom: calc(12px + env(safe-area-inset-bottom));
    position: relative;
    transition: background-color 0.3s ease, border-color 0.3s ease;
}

.chat-mobile-conversation__form {
    display: flex;
    gap: 12px;
    align-items: center;
}

.chat-mobile-conversation__input {
    flex: 1;
    padding: 12px 16px;
    border: 1px solid var(--chat-mobile-border);
    border-radius: 24px;
    font-size: 16px;
    outline: none;
    transition: border-color 0.2s ease, box-shadow 0.2s ease, background-color 0.3s ease, color 0.3s ease;
    -webkit-appearance: none;
    appearance: none;
    background: var(--chat-mobile-surface);
    color: var(--chat-mobile-text);
}

.chat-mobile-conversation__input::placeholder {
    color: var(--chat-mobile-text-muted);
}

.chat-mobile-conversation__input:focus {
    border-color: var(--chat-mobile-primary);
    box-shadow: 0 0 0 3px rgba(118, 237, 0, 0.15);
    background: var(--chat-mobile-elevated);
}

.chat-mobile-conversation__send {
    width: 48px;
    height: 48px;
    border: none;
    border-radius: 50%;
    background: linear-gradient(135deg, var(--chat-mobile-primary) 0%, var(--chat-mobile-primary-dark) 100%);
    color: #ffffff;
    font-size: 18px;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: transform 0.1s ease, box-shadow 0.2s ease;
    -webkit-tap-highlight-color: transparent;
    flex-shrink: 0;
    box-shadow: 0 2px 8px rgba(118, 237, 0, 0.3);
}

.dark-mode .chat-mobile-conversation__send {
    box-shadow: 0 2px 8px rgba(118, 237, 0, 0.5);
}

.chat-mobile-conversation__send:active {
    transform: scale(0.95);
}

/* FAB para abrir chat */
.chat-mobile-fab {
    position: fixed;
    bottom: 80px;
    right: 20px;
    width: 56px;
    height: 56px;
    border-radius: 50%;
    background: var(--chat-mobile-fab-bg);
    color: #ffffff;
    border: none;
    font-size: 24px;
    cursor: pointer;
    box-shadow: var(--chat-mobile-fab-shadow);
    z-index: 10003;
    display: none;
    align-items: center;
    justify-content: center;
    transition: transform 0.2s ease, box-shadow 0.2s ease, opacity 0.2s ease, visibility 0.2s ease;
    -webkit-tap-highlight-color: transparent;
}

/* Mostrar FAB solo en móvil cuando el chat esté cerrado */
@media (max-width: 768px) {
    .chat-mobile-fab {
        display: flex !important;
        visibility: visible;
        opacity: 1;
    }
    
    /* Ocultar FAB cuando el chat esté abierto */
    .chat-mobile-root.is-open ~ .chat-mobile-fab,
    .chat-mobile-fab.is-hidden {
        display: none !important;
        visibility: hidden !important;
        opacity: 0 !important;
    }
}

.chat-mobile-fab:active {
    transform: scale(0.9);
    box-shadow: 0 2px 6px rgba(37, 99, 235, 0.3);
}

.chat-mobile-fab:hover {
    transform: scale(1.05);
    box-shadow: 0 6px 16px rgba(37, 99, 235, 0.5);
}

.dark-mode .chat-mobile-fab:hover {
    box-shadow: 0 6px 16px rgba(37, 99, 235, 0.7);
}

/* Safe area para dispositivos con notch */
@supports (padding: max(0px)) {
    .chat-mobile-list__header,
    .chat-mobile-conversation__header {
        padding-top: max(16px, env(safe-area-inset-top));
    }

    .chat-mobile-conversation__input-container {
        padding-bottom: max(12px, env(safe-area-inset-bottom));
    }

    .chat-mobile-fab {
        bottom: max(80px, calc(80px + env(safe-area-inset-bottom)));
    }
}

/* Scrollbar personalizado móvil */
.chat-mobile-conversation__messages::-webkit-scrollbar,
.chat-mobile-list__content::-webkit-scrollbar {
    width: 4px;
}

.chat-mobile-conversation__messages::-webkit-scrollbar-thumb,
.chat-mobile-list__content::-webkit-scrollbar-thumb {
    background: rgba(0, 0, 0, 0.2);
    border-radius: 2px;
}

.dark-mode .chat-mobile-conversation__messages::-webkit-scrollbar-thumb,
.dark-mode .chat-mobile-list__content::-webkit-scrollbar-thumb {
    background: rgba(255, 255, 255, 0.2);
}

/* Animaciones de entrada/salida */
@keyframes slideInFromRight {
    from {
        transform: translateX(100%);
        opacity: 0;
    }
    to {
        transform: translateX(0);
        opacity: 1;
    }
}

@keyframes slideOutToRight {
    from {
        transform: translateX(0);
        opacity: 1;
    }
    to {
        transform: translateX(100%);
        opacity: 0;
    }
}

/* ===== MENÚ DE OPCIONES MÓVIL ===== */
.chat-mobile-menu {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    z-index: 10004;
    opacity: 0;
    visibility: hidden;
    transition: opacity 0.2s ease, visibility 0.2s ease;
}

.chat-mobile-menu.is-visible {
    opacity: 1;
    visibility: visible;
}

.chat-mobile-menu__overlay {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: transparent;
}

.chat-mobile-menu__content {
    position: absolute;
    top: 60px;
    right: 12px;
    min-width: 200px;
    background: #ffffff !important;
    border-radius: 12px;
    box-shadow: 0 4px 20px rgba(0, 0, 0, 0.15);
    overflow: hidden;
    opacity: 0;
    transform: scale(0.95) translateY(-10px);
    transform-origin: top right;
    transition: opacity 0.2s ease, transform 0.2s cubic-bezier(0.4, 0.0, 0.2, 1);
}

.chat-mobile-menu.is-visible .chat-mobile-menu__content {
    opacity: 1;
    transform: scale(1) translateY(0);
}

.chat-mobile-menu__option {
    width: 100%;
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 14px 16px;
    border: none;
    background: #ffffff !important;
    color: #1a1a1a;
    font-size: 15px;
    text-align: left;
    cursor: pointer;
    transition: background 0.2s ease;
    -webkit-tap-highlight-color: transparent;
    border-bottom: 1px solid #f0f0f0;
}

.chat-mobile-menu__option:last-child {
    border-bottom: none;
}

.chat-mobile-menu__option:active {
    background: #f8f9fa !important;
}

.chat-mobile-menu__option i {
    font-size: 18px;
    width: 20px;
    text-align: center;
    flex-shrink: 0;
}

.chat-mobile-menu__option span {
    flex: 1;
}

.chat-mobile-menu__option--danger {
    color: #dc3545;
}

.chat-mobile-menu__option--danger:active {
    background: #fff5f5;
}

/* Toast notification móvil */
.chat-mobile-toast {
    position: fixed;
    bottom: 100px;
    left: 50%;
    transform: translateX(-50%) translateY(100px);
    padding: 12px 24px;
    background: #28a745;
    color: #ffffff;
    border-radius: 24px;
    font-size: 14px;
    font-weight: 500;
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.2);
    z-index: 10005;
    opacity: 0;
    transition: opacity 0.3s ease, transform 0.3s ease;
}

.chat-mobile-toast.is-visible {
    opacity: 1;
    transform: translateX(-50%) translateY(0);
}

/* Modo oscuro para menú móvil */
.dark-mode .chat-mobile-menu__content {
    background: #242526 !important;
    box-shadow: 0 4px 20px rgba(0, 0, 0, 0.5);
    border: 1px solid #3A3B3C;
}

.dark-mode .chat-mobile-menu__option {
    color: #E4E6EB !important;
    background: #242526 !important;
    border-bottom-color: #3A3B3C;
}

.dark-mode .chat-mobile-menu__option:active {
    background: #3A3B3C !important;
}

.dark-mode .chat-mobile-menu__option--danger {
    color: #ff6b6b !important;
    background: #242526 !important;
}

.dark-mode .chat-mobile-menu__option--danger:active {
    background: #2a1a1a !important;
}

/* Diseño sutil y elegante - Todo con fondo #0F0F0F */
.dark-mode .chat-mobile-list__search {
    background: #0F0F0F !important;
    border-bottom: 1px solid rgba(255, 255, 255, 0.08);
}

.dark-mode .chat-mobile-list__search i {
    color: var(--chat-mobile-text-secondary);
}

.dark-mode .chat-mobile-list__search-input {
    background: #0F0F0F !important;
    border: 1px solid rgba(255, 255, 255, 0.1);
    color: #E4E6EB;
}

.dark-mode .chat-mobile-list__search-input:focus {
    border-color: rgba(118, 237, 0, 0.4);
    box-shadow: 0 0 0 3px rgba(118, 237, 0, 0.1);
}

.dark-mode .chat-mobile-conversation__messages {
    background: #0F0F0F !important;
}

.dark-mode .chat-mobile-conversation__input-container {
    background: #0F0F0F !important;
    border-top: 1px solid rgba(255, 255, 255, 0.08);
}

.dark-mode .chat-mobile-conversation__input {
    background: #0F0F0F !important;
    border: 1px solid rgba(255, 255, 255, 0.1);
    color: #E4E6EB;
}

.dark-mode .chat-mobile-conversation__input:focus {
    background: #0F0F0F !important;
    border-color: rgba(118, 237, 0, 0.4);
    box-shadow: 0 0 0 3px rgba(118, 237, 0, 0.1);
}
