﻿/* ── Reset y variables ──────────────────────────── */
* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

:root {
    --primary: #075E54;
    --secondary: #128C7E;
    --accent: #25D366;
    --bg: #f0f2f5;
    --white: #ffffff;
    --bubble-out: #DCF8C6;
    --bubble-in: #ffffff;
    --text: #111b21;
    --text-light: #667781;
    --border: #e9edef;
    --sidebar-w: 360px;
}

body {
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
    background: var(--bg);
    color: var(--text);
    height: 100vh;
    overflow: hidden;
}

/* ── Auth ───────────────────────────────────────── */
.auth-container {
    min-height: 100vh;
    display: flex;
    align-items: center;
    justify-content: center;
    background: linear-gradient(135deg, var(--primary), var(--secondary));
    padding: 1rem;
}

.auth-card {
    background: var(--white);
    border-radius: 16px;
    padding: 2.5rem;
    width: 100%;
    max-width: 400px;
    box-shadow: 0 20px 60px rgba(0,0,0,0.15);
}

.auth-logo {
    text-align: center;
    margin-bottom: 2rem;
}

    .auth-logo span {
        font-size: 3rem;
    }

    .auth-logo h1 {
        font-size: 1.8rem;
        color: var(--primary);
        margin-top: 0.5rem;
    }

    .auth-logo p {
        color: var(--text-light);
        margin-top: 0.25rem;
    }

.form-group {
    margin-bottom: 1.2rem;
}

    .form-group label {
        display: block;
        font-size: 0.85rem;
        font-weight: 600;
        color: var(--text-light);
        margin-bottom: 0.4rem;
    }

.form-input {
    width: 100%;
    padding: 0.75rem 1rem;
    border: 2px solid var(--border);
    border-radius: 10px;
    font-size: 1rem;
    transition: border-color 0.2s;
    outline: none;
}

    .form-input:focus {
        border-color: var(--accent);
    }

.btn-primary {
    width: 100%;
    padding: 0.85rem;
    background: var(--accent);
    color: var(--white);
    border: none;
    border-radius: 10px;
    font-size: 1rem;
    font-weight: 600;
    cursor: pointer;
    margin-top: 0.5rem;
    transition: background 0.2s;
}

    .btn-primary:hover:not(:disabled) {
        background: var(--secondary);
    }

    .btn-primary:disabled {
        opacity: 0.6;
        cursor: not-allowed;
    }

.auth-link {
    text-align: center;
    margin-top: 1.5rem;
    color: var(--text-light);
    font-size: 0.9rem;
}

    .auth-link a {
        color: var(--accent);
        text-decoration: none;
        font-weight: 600;
    }

.alert-error {
    background: #fee2e2;
    color: #dc2626;
    padding: 0.75rem 1rem;
    border-radius: 8px;
    margin-bottom: 1rem;
    font-size: 0.9rem;
}

/* ── Layout del chat ────────────────────────────── */
.chat-layout {
    display: flex;
    height: 100vh;
    overflow: hidden;
}

/* ── Sidebar ────────────────────────────────────── */
.sidebar {
    width: var(--sidebar-w);
    background: var(--white);
    border-right: 1px solid var(--border);
    display: flex;
    flex-direction: column;
    flex-shrink: 0;
}

.sidebar-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 1rem 1.2rem;
    background: #f0f2f5;
    border-bottom: 1px solid var(--border);
}

.user-info {
    display: flex;
    align-items: center;
    gap: 0.75rem;
}

.username {
    font-weight: 600;
    font-size: 1rem;
}

.header-actions {
    display: flex;
    gap: 0.5rem;
}

.icon-btn {
    background: none;
    border: none;
    cursor: pointer;
    padding: 0.4rem;
    border-radius: 50%;
    font-size: 1.1rem;
    transition: background 0.2s;
}

    .icon-btn:hover {
        background: var(--border);
    }

/* Buscador */
.search-box {
    padding: 0.75rem;
    border-bottom: 1px solid var(--border);
    position: relative;
}

.search-input {
    width: 100%;
    padding: 0.6rem 1rem;
    background: var(--bg);
    border: none;
    border-radius: 20px;
    font-size: 0.95rem;
    outline: none;
}

.search-results {
    position: absolute;
    top: 100%;
    left: 0;
    right: 0;
    background: var(--white);
    border: 1px solid var(--border);
    border-radius: 8px;
    box-shadow: 0 4px 20px rgba(0,0,0,0.1);
    z-index: 100;
    max-height: 250px;
    overflow-y: auto;
}

.search-result-item {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    padding: 0.75rem 1rem;
    cursor: pointer;
    transition: background 0.15s;
}

    .search-result-item:hover {
        background: var(--bg);
    }

.result-name {
    font-weight: 600;
    font-size: 0.9rem;
}

.result-email {
    font-size: 0.8rem;
    color: var(--text-light);
}

/* Conversaciones */
.conversations-list {
    flex: 1;
    overflow-y: auto;
}

.conversation-item {
    display: flex;
    align-items: center;
    gap: 0.85rem;
    padding: 0.85rem 1.2rem;
    cursor: pointer;
    border-bottom: 1px solid var(--border);
    transition: background 0.15s;
}

    .conversation-item:hover {
        background: #f5f6f6;
    }

    .conversation-item.active {
        background: #f0f2f5;
    }

.conv-info {
    flex: 1;
    min-width: 0;
}

.conv-header {
    display: flex;
    justify-content: space-between;
    align-items: baseline;
    margin-bottom: 0.2rem;
}

.conv-name {
    font-weight: 600;
    font-size: 0.95rem;
}

.conv-time {
    font-size: 0.75rem;
    color: var(--text-light);
}

.conv-last-msg {
    font-size: 0.85rem;
    color: var(--text-light);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.empty-state {
    text-align: center;
    padding: 3rem 1rem;
    color: var(--text-light);
}

/* Avatar */
.avatar {
    width: 46px;
    height: 46px;
    border-radius: 50%;
    background: var(--secondary);
    color: white;
    display: flex;
    align-items: center;
    justify-content: center;
    font-weight: 700;
    font-size: 1.1rem;
    flex-shrink: 0;
}

.avatar-sm {
    width: 36px;
    height: 36px;
    font-size: 0.9rem;
}

/* ── Ventana de chat ─────────────────────────────── */
.chat-window {
    flex: 1;
    display: flex;
    flex-direction: column;
    background: #efeae2;
    min-width: 0;
}

.no-chat-selected {
    flex: 1;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    color: var(--text-light);
    background: var(--white);
}

.no-chat-icon {
    font-size: 4rem;
    margin-bottom: 1rem;
}

.no-chat-selected h2 {
    color: var(--text);
    margin-bottom: 0.5rem;
}

/* Header del chat */
.chat-header {
    display: flex;
    align-items: center;
    gap: 0.85rem;
    padding: 0.75rem 1.2rem;
    background: #f0f2f5;
    border-bottom: 1px solid var(--border);
}

.chat-header-info {
    flex: 1;
}

.chat-name {
    font-weight: 600;
}

.chat-status {
    font-size: 0.8rem;
    color: var(--text-light);
}

.typing-indicator {
    font-size: 0.8rem;
    color: var(--accent);
    font-style: italic;
}

.mobile-back {
    display: none;
}

/* Mensajes */
.messages-container {
    flex: 1;
    overflow-y: auto;
    padding: 1rem;
    display: flex;
    flex-direction: column;
    gap: 0.3rem;
}

.message-wrapper {
    display: flex;
    margin-bottom: 0.2rem;
}

    .message-wrapper.mine {
        justify-content: flex-end;
    }

    .message-wrapper.theirs {
        justify-content: flex-start;
    }

.message-bubble {
    max-width: 65%;
    padding: 0.6rem 0.85rem;
    border-radius: 8px;
    position: relative;
    word-wrap: break-word;
}

.bubble-mine {
    background: var(--bubble-out);
    border-radius: 8px 0 8px 8px;
}

.bubble-theirs {
    background: var(--bubble-in);
    border-radius: 0 8px 8px 8px;
    box-shadow: 0 1px 2px rgba(0,0,0,0.1);
}

.msg-sender {
    font-size: 0.75rem;
    font-weight: 700;
    color: var(--secondary);
    margin-bottom: 0.2rem;
}

.msg-content {
    font-size: 0.95rem;
    line-height: 1.4;
}

.msg-meta {
    display: flex;
    align-items: center;
    justify-content: flex-end;
    gap: 0.3rem;
    margin-top: 0.25rem;
}

.msg-time {
    font-size: 0.7rem;
    color: var(--text-light);
}

.msg-status {
    font-size: 0.75rem;
}

/* Input de mensaje */
.message-input-area {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    padding: 0.75rem 1rem;
    background: #f0f2f5;
    border-top: 1px solid var(--border);
}

.message-input {
    flex: 1;
    padding: 0.7rem 1.2rem;
    background: var(--white);
    border: none;
    border-radius: 25px;
    font-size: 0.95rem;
    outline: none;
}

.btn-send {
    width: 44px;
    height: 44px;
    background: var(--accent);
    color: white;
    border: none;
    border-radius: 50%;
    cursor: pointer;
    font-size: 1.1rem;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: background 0.2s;
    flex-shrink: 0;
}

    .btn-send:hover:not(:disabled) {
        background: var(--secondary);
    }

    .btn-send:disabled {
        opacity: 0.5;
        cursor: not-allowed;
    }

/* Loading */
.loading-screen {
    height: 100vh;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 1rem;
    color: var(--text-light);
}

.spinner {
    width: 40px;
    height: 40px;
    border: 4px solid var(--border);
    border-top-color: var(--accent);
    border-radius: 50%;
    animation: spin 0.8s linear infinite;
}

@keyframes spin {
    to {
        transform: rotate(360deg);
    }
}

/* ── Responsive móvil ───────────────────────────── */
@media (max-width: 768px) {
    .sidebar {
        position: fixed;
        left: -100%;
        top: 0;
        height: 100%;
        z-index: 200;
        transition: left 0.3s;
        width: 100%;
    }

        .sidebar.sidebar-open {
            left: 0;
        }

    .mobile-back {
        display: flex !important;
    }

    .chat-window {
        width: 100%;
    }
}

/* ── Fila de último mensaje + badge ── */
.conv-last-msg-row {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 6px;
}

.conv-last-msg {
    flex: 1;
    font-size: 0.82rem;
    color: #667781;
    overflow: hidden;
    white-space: nowrap;
    text-overflow: ellipsis;
}

/* Badge de mensajes no leídos (círculo verde) */
.unread-badge {
    min-width: 20px;
    height: 20px;
    padding: 0 5px;
    border-radius: 10px;
    background: #25d366;
    color: white;
    font-size: 0.72rem;
    font-weight: 700;
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
}
/* ── Banner de instalación PWA ── */
.install-banner {
    position: fixed;
    bottom: 20px;
    left: 50%;
    transform: translateX(-50%);
    background: #1f2c34;
    color: #e9edef;
    padding: 12px 20px;
    border-radius: 12px;
    display: flex;
    align-items: center;
    gap: 12px;
    box-shadow: 0 4px 20px rgba(0,0,0,0.5);
    z-index: 9999;
    font-size: 0.9rem;
    white-space: nowrap;
}

.btn-install {
    background: #00a884;
    color: white;
    border: none;
    padding: 6px 16px;
    border-radius: 8px;
    font-weight: 600;
    cursor: pointer;
}

    .btn-install:hover {
        background: #017561;
    }

.btn-dismiss {
    background: transparent;
    color: #8696a0;
    border: none;
    font-size: 1rem;
    cursor: pointer;
    padding: 0 4px;
}