@import url('https://fonts.googleapis.com/css2?family=Outfit:wght@400;500;600&display=swap');

:root {
    --bg-color: #F3F4F6;
    --chat-bg: #FFFFFF;
    --primary: #0F172A;
    --sent-bg: #E2E8F0;
    --sent-text: #0F172A;
    --recv-bg: #3B82F6;
    --recv-text: #FFFFFF;
    --text-muted: #64748B;
    --border: #E2E8F0;
}

* {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
    font-family: 'Outfit', sans-serif;
}

html, body {
    height: 100%;
    margin: 0;
    padding: 0;
    overflow: hidden; 
    touch-action: none;
}

body {
    background-color: var(--bg-color);
    display: flex;
    justify-content: center;
    align-items: center;
}

.chat-container {
    width: 100%;
    max-width: 480px;
    height: 100%;
    position: absolute; 
    top: 0;
    bottom: 0;
    background: var(--chat-bg);
    display: flex;
    flex-direction: column;
    box-shadow: 0 4px 6px -1px rgba(0, 0, 0, 0.1);
    overflow: hidden;
}

.view {
    display: flex;
    flex-direction: column;
    flex: 1; 
    width: 100%;
    overflow: hidden;
}

#viewChat, #viewDashboard {
    justify-content: flex-start;
    align-items: stretch;
}

.header {
    background: var(--primary);
    color: white;
    padding: 1rem;
    display: flex;
    align-items: center;
    gap: 1rem;
    z-index: 2;
    flex-shrink: 0; 
}

.header img {
    width: 40px;
    height: 40px;
    border-radius: 50%;
    object-fit: cover;
    object-position: center;
    transition: opacity 0.3s ease;
}

.header h2 {
    font-size: 1.1rem;
    font-weight: 500;
}

.header .status {
    font-size: 0.8rem;
    opacity: 0.8;
}

.messages {
    flex: 1;
    padding: 1.5rem 1rem;
    overflow-y: auto;
    display: flex;
    flex-direction: column;
    gap: 0.75rem;
    position: relative;
    touch-action: pan-y;
    -webkit-overflow-scrolling: touch;
}

.message {
    max-width: 80%;
    padding: 0.8rem 1rem;
    border-radius: 12px;
    position: relative;
    font-size: 0.95rem;
    line-height: 1.4;
    transition: opacity 0.3s ease;
    cursor: pointer;
    -webkit-tap-highlight-color: transparent;
}

.message.appearing {
    animation: popIn 0.3s cubic-bezier(0.175, 0.885, 0.32, 1.275) forwards;
}

@keyframes popIn {
    0% { opacity: 0; transform: scale(0.8) translateY(10px); }
    100% { opacity: 1; transform: scale(1) translateY(0); }
}

.msg-sent {
    align-self: flex-end;
    background: var(--sent-bg);
    color: var(--sent-text);
    border-bottom-right-radius: 4px;
    border: 1px solid #cbd5e1;
}

.msg-recv {
    align-self: flex-start;
    background: var(--recv-bg);
    color: var(--recv-text);
    border-bottom-left-radius: 4px;
}

.meta {
    display: flex;
    justify-content: flex-end;
    align-items: center;
    gap: 4px;
    font-size: 0.7rem;
    margin-top: 6px;
    opacity: 0.8;
}

.msg-deleted {
    font-style: italic;
    opacity: 0.7;
    font-size: 0.85rem;
}

.input-area {
    padding: 1rem;
    border-top: 1px solid var(--border);
    display: flex;
    gap: 0.5rem;
    background: var(--chat-bg);
    z-index: 2;
    flex-shrink: 0;
}

#msgInput {
    flex: 1;
    padding: 0.75rem 1.2rem;
    border: 1px solid var(--border);
    border-radius: 24px;
    outline: none;
    font-size: 0.95rem;
    transition: border-color 0.2s;
}

#msgInput:focus {
    border-color: var(--recv-bg);
}

button.btn-send {
    background: var(--recv-bg);
    color: white;
    border: none;
    padding: 0.75rem 1.5rem;
    border-radius: 24px;
    cursor: pointer;
    font-weight: 500;
    transition: opacity 0.2s;
}

button.btn-send:hover {
    opacity: 0.9;
}

/* -- ESTILOS PARA AUDIO MICRÓFONO -- */
.btn-mic {
    background: var(--bg-color);
    border: 1px solid var(--border);
    border-radius: 50%;
    width: 44px;
    height: 44px;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 1.2rem;
    cursor: pointer;
    transition: all 0.2s;
    flex-shrink: 0;
    padding: 0;
}

.btn-mic:hover {
    filter: brightness(0.95);
}

.btn-mic.recording {
    background: #EF4444;
    color: white;
    border-color: #EF4444;
    animation: mic-pulse 1.5s infinite;
}

@keyframes mic-pulse {
    0% { box-shadow: 0 0 0 0 rgba(239, 68, 68, 0.4); }
    70% { box-shadow: 0 0 0 10px rgba(239, 68, 68, 0); }
    100% { box-shadow: 0 0 0 0 rgba(239, 68, 68, 0); }
}

.offline-banner {
    background: #EF4444;
    color: white;
    text-align: center;
    padding: 0.5rem;
    font-size: 0.85rem;
    display: none;
}

.form-box {
    width: 90%;
    max-width: 360px;
    padding: 2rem 1.5rem;
    display: flex;
    flex-direction: column;
    gap: 0.85rem;
    background: white;
    border-radius: 12px;
    box-shadow: 0 4px 15px rgba(0, 0, 0, 0.06);
    border: 1px solid var(--border);
    margin: auto;
    touch-action: pan-y;
}

.form-box h2 {
    color: var(--primary);
    margin-bottom: 0.5rem;
    text-align: center;
    font-size: 1.3rem;
}

.form-box input {
    width: 100%;
    padding: 0.85rem 1rem;
    border: 1.5px solid var(--border);
    border-radius: 16px;
    outline: none;
    font-size: 0.95rem;
    background-color: #F8FAFC;
    transition: all 0.3s ease;
}

.search-box input {
    flex: 1;
    padding: 0.85rem 1rem;
    border: 1.5px solid var(--border);
    border-radius: 16px;
    outline: none;
    font-size: 0.95rem;
    background-color: #F8FAFC;
    transition: all 0.3s ease;
}

.form-box input:focus, .search-box input:focus {
    border-color: var(--recv-bg);
    background-color: #FFFFFF;
    box-shadow: 0 0 0 4px rgba(59, 130, 246, 0.1);
}

.form-box button {
    width: 100%;
    padding: 0.85rem;
    border: none;
    border-radius: 16px;
    background: var(--recv-bg);
    color: white;
    cursor: pointer;
    font-weight: 600;
    font-size: 0.95rem;
}

.form-box button.btn-alt {
    background: var(--bg-color);
    color: var(--primary);
}

.dash-actions {
    display: flex;
    gap: 0.5rem;
    margin-left: auto;
}

.dash-actions button, .header > button {
    background: rgba(255,255,255,0.2);
    border: none;
    color: white;
    padding: 0.5rem 1rem;
    border-radius: 4px;
    cursor: pointer;
}

.search-box {
    display: flex;
    padding: 1rem;
    gap: 0.5rem;
    background: white;
    border-bottom: 1px solid var(--border);
}

.search-box input {
    flex: 1;
    padding: 0.6rem;
    border: 1px solid var(--border);
    border-radius: 8px;
    outline: none;
}

.search-box button {
    padding: 0.6rem 1rem;
    border: none;
    border-radius: 8px;
    background: var(--recv-bg);
    color: white;
    cursor: pointer;
}

.user-list {
    flex: 1;
    overflow-y: auto;
    padding: 1rem;
    display: flex;
    flex-direction: column;
    gap: 0.5rem;
    touch-action: pan-y;
    -webkit-overflow-scrolling: touch;
}

.user-item {
    display: flex;
    align-items: center;
    padding: 1rem;
    background: white;
    border-radius: 8px;
    cursor: pointer;
    box-shadow: 0 1px 3px rgba(0,0,0,0.1);
    gap: 0.5rem;
}

.user-item img {
    width: 48px;
    height: 48px;
    border-radius: 50%;
    object-fit: cover;
}

.user-item span {
    flex: 1;
    font-weight: 500;
    color: var(--primary);
}

.user-item button {
    padding: 0.4rem 0.8rem;
    font-size: 0.8rem;
    border-radius: 6px;
    border: none;
    background: var(--recv-bg);
    color: white;
    cursor: pointer;
}

.user-item button.btn-deny {
    background: #EF4444;
}

.user-item button.btn-block {
    background: #0F172A;
}

.badge {
    background: #EF4444;
    color: white;
    padding: 0.2rem 0.6rem;
    border-radius: 12px;
    font-size: 0.8rem;
    font-weight: bold;
}

#myAvatarPreview {
    width: 100px;
    height: 100px;
    border-radius: 50%;
    object-fit: cover;
    margin: 0 auto 0.5rem auto;
    background: #e2e8f0;
}

.flying-bubble {
    position: fixed;
    z-index: 9999;
    padding: 0.8rem 1rem;
    border-radius: 18px;
    font-size: 0.95rem;
    line-height: 1.4;
    pointer-events: none;
    box-shadow: 0 4px 12px rgba(0,0,0,0.15);
    transition: all 0.35s cubic-bezier(0.25, 1, 0.5, 1);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    max-width: 250px;
}

.flying-bubble.bubble-sent {
    background: var(--sent-bg);
    color: var(--sent-text);
    border-bottom-right-radius: 4px;
}

.flying-bubble.bubble-recv {
    background: var(--recv-bg);
    color: var(--recv-text);
    border-bottom-left-radius: 4px;
}

.modal-overlay {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0,0,0,0.5);
    z-index: 1000;
    display: flex;
    justify-content: center;
    align-items: center;
}

.modal-content {
    position: relative;
    background: white;
    width: 90%;
    max-width: 340px;
    border-radius: 16px;
    padding: 1.5rem;
    display: flex;
    flex-direction: column;
    gap: 0.8rem;
    box-shadow: 0 10px 25px rgba(0,0,0,0.2);
}

.close-btn {
    position: absolute;
    top: 12px;
    right: 15px;
    background: transparent;
    border: none;
    font-size: 1.8rem;
    color: var(--text-muted);
    cursor: pointer;
    z-index: 10;
    padding: 5px;
    line-height: 1;
}

.modal-content h3 {
    text-align: center;
    margin-bottom: 0.5rem;
    color: var(--primary);
    font-size: 1.1rem;
}

.modal-content p {
    font-size: 0.95rem;
    color: var(--primary);
    margin-bottom: 0.2rem;
}

.modal-content p strong {
    color: var(--text-muted);
}

.modal-btn {
    width: 100%;
    padding: 1rem;
    border: none;
    border-radius: 12px;
    font-size: 1rem;
    font-weight: 500;
    cursor: pointer;
    background: var(--bg-color);
    color: var(--primary);
    transition: background 0.2s, filter 0.2s;
    -webkit-tap-highlight-color: transparent;
}

.modal-btn.danger {
    background: #FEE2E2;
    color: #DC2626;
}

.modal-btn.cancel {
    background: transparent;
    border: 1px solid #E2E8F0;
    color: #475569;
    margin-top: 0.5rem;
}

.modal-btn:active {
    filter: brightness(0.9);
}

#expandAvatar {
    width: 300px;
    height: 300px;
    border-radius: 50%;
    object-fit: cover;
    margin: 0 auto 1rem auto;
    background: var(--sent-bg);
}

#viewChat, #viewDashboard, #viewProfile {
    justify-content: flex-start;
    align-items: stretch;
}