:root {
    --primary: #6366f1; /* Indigo */
    --primary-light: #818cf8;
    --primary-dark: #4f46e5;
    --bg-dark: #0f172a; /* Slate 900 */
    --bg-card: #1e293b; /* Slate 800 */
    --bg-sidebar: #0f172a;
    --text-main: #f1f5f9;
    --text-muted: #94a3b8;
    --border: #334155;
    --accent-success: #10b981;
    --accent-error: #f43f5e;
    --accent-warning: #f59e0b;
    --glass: rgba(255, 255, 255, 0.05);
    --glass-border: rgba(255, 255, 255, 0.1);
}

* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

body {
    font-family: 'Outfit', sans-serif;
    background-color: var(--bg-dark);
    color: var(--text-main);
    height: 100vh;
    overflow: hidden;
    letter-spacing: -0.01em;
}

.app-container {
    display: flex;
    height: 100vh;
    width: 100vw;
}

/* --- SIDEBAR --- */
.sidebar {
    width: 320px;
    background-color: var(--bg-sidebar);
    border-right: 1px solid var(--border);
    display: flex;
    flex-direction: column;
    z-index: 10;
}

.sidebar-header {
    padding: 24px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    border-bottom: 1px solid var(--border);
}

.brand {
    display: flex;
    align-items: center;
    gap: 12px;
}

.brand-logo {
    font-size: 24px;
    background: linear-gradient(135deg, var(--primary), #ec4899);
    width: 40px;
    height: 40px;
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: 12px;
    box-shadow: 0 4px 12px rgba(139, 92, 246, 0.3);
}

.brand-text h2 {
    font-size: 16px;
    font-weight: 700;
    letter-spacing: -0.02em;
}

.brand-text span {
    font-size: 10px;
    color: var(--text-muted);
    text-transform: uppercase;
    letter-spacing: 0.1em;
}

.header-actions {
    display: flex;
    gap: 8px;
}

.icon-btn {
    background: var(--glass);
    border: 1px solid var(--glass-border);
    color: var(--text-main);
    width: 34px;
    height: 34px;
    border-radius: 8px;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    transition: all 0.2s;
}

.icon-btn:hover {
    background: var(--primary);
    border-color: var(--primary);
    transform: translateY(-2px);
}

.icon-btn.secondary i {
    width: 16px;
    height: 16px;
}

/* SEARCH */
.search-container {
    padding: 16px;
}

.search-bar {
    background: rgba(255,255,255,0.05);
    border: 1px solid var(--border);
    border-radius: 12px;
    padding: 10px 14px;
    display: flex;
    align-items: center;
    gap: 10px;
    transition: all 0.2s;
}

.search-bar:focus-within {
    border-color: var(--primary);
    background: rgba(255,255,255,0.08);
    box-shadow: 0 0 0 2px rgba(139, 92, 246, 0.2);
}

.search-bar i {
    color: var(--text-muted);
    width: 18px;
}

.search-bar input {
    background: transparent;
    border: none;
    color: white;
    font-family: inherit;
    font-size: 14px;
    width: 100%;
    outline: none;
}

/* CONTACT LIST */
.contacts-list {
    flex: 1;
    overflow-y: auto;
    padding: 8px;
}

.contacts-list::-webkit-scrollbar {
    width: 4px;
}

.contacts-list::-webkit-scrollbar-thumb {
    background: var(--border);
    border-radius: 4px;
}

.contact-item {
    padding: 12px 16px;
    border-radius: 12px;
    cursor: pointer;
    transition: all 0.2s;
    margin-bottom: 4px;
    position: relative;
    border: 1px solid transparent;
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.contact-item:hover {
    background: rgba(255, 255, 255, 0.03);
}

.contact-item.active {
    background: rgba(139, 92, 246, 0.1);
    border-color: rgba(139, 92, 246, 0.3);
}

.contact-item .name {
    font-size: 14px;
    font-weight: 600;
}

.contact-item .phone {
    font-size: 12px;
    color: var(--text-muted);
}

.contact-item .preview {
    font-size: 12px;
    color: var(--text-muted);
    margin-top: 4px;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.contact-item .badge {
    background: var(--primary);
    color: white;
    font-size: 10px;
    font-weight: 700;
    padding: 2px 6px;
    border-radius: 6px;
}

.contact-main {
    flex: 1;
    overflow: hidden;
}

.contact-actions {
    display: flex;
    flex-direction: column;
    align-items: flex-end;
    gap: 6px;
}

.small-delete-btn {
    background: rgba(255,255,255,0.05);
    border: 1px solid var(--border);
    color: var(--text-muted);
    padding: 6px;
    border-radius: 8px;
    cursor: pointer;
    transition: all 0.2s;
    opacity: 0;
}

.contact-item:hover .small-delete-btn {
    opacity: 1;
}

.small-delete-btn:hover {
    background: var(--accent-error);
    border-color: var(--accent-error);
    color: white;
}

/* --- CHAT AREA --- */
.chat-area {
    flex: 1;
    background-color: var(--bg-dark);
    display: flex;
    flex-direction: column;
}

.chat-panel {
    display: flex;
    flex-direction: column;
    height: 100%;
}

.chat-header {
    padding: 16px 24px;
    background: rgba(9, 9, 11, 0.8);
    backdrop-filter: blur(12px);
    border-bottom: 1px solid var(--border);
    display: flex;
    align-items: center;
    gap: 16px;
}

.avatar {
    width: 44px;
    height: 44px;
    border-radius: 50%;
    background: linear-gradient(135deg, var(--primary-dark), var(--primary-light));
    display: flex;
    align-items: center;
    justify-content: center;
    font-weight: 700;
    font-size: 18px;
    box-shadow: 0 4px 12px rgba(0,0,0,0.3);
}

.header-user-info h4 {
    font-size: 16px;
    font-weight: 600;
}

.header-user-info span {
    font-size: 12px;
    color: var(--text-muted);
}

.chat-actions {
    margin-left: auto;
    display: flex;
    gap: 8px;
}

.action-btn {
    background: var(--glass);
    border: 1px solid var(--glass-border);
    color: var(--text-main);
    padding: 6px 12px;
    border-radius: 8px;
    font-size: 12px;
    font-weight: 500;
    cursor: pointer;
    transition: all 0.2s;
}

.action-btn:hover {
    background: rgba(255,255,255,0.08);
}

/* --- MESSAGES REFINED --- */
.messages-container {
    flex: 1;
    overflow-y: auto;
    padding: 30px 40px;
    display: flex;
    flex-direction: column;
    gap: 20px;
    background: radial-gradient(circle at top right, rgba(139, 92, 246, 0.05), transparent 400px),
                radial-gradient(circle at bottom left, rgba(236, 72, 153, 0.03), transparent 400px);
}

.message-row {
    display: flex;
    flex-direction: column;
    max-width: 65%;
    position: relative;
    animation: messageReveal 0.4s cubic-bezier(0.16, 1, 0.3, 1);
}

@keyframes messageReveal {
    from { opacity: 0; transform: translateY(15px) scale(0.98); }
    to { opacity: 1; transform: translateY(0) scale(1); }
}

.message-row.entrada {
    align-self: flex-start;
    align-items: flex-start;
}

.message-row.salida {
    align-self: flex-end;
    align-items: flex-end;
}

.bubble {
    padding: 14px 22px;
    border-radius: 20px;
    font-size: 15px;
    line-height: 1.5;
    position: relative;
    box-shadow: 0 2px 10px rgba(0, 0, 0, 0.1);
    width: fit-content;
    word-wrap: break-word;
}

.bubble:hover {
    transform: translateY(-1px);
}

.entrada .bubble {
    background: var(--bg-card);
    color: var(--text-main);
    border: 1px solid var(--border);
    border-bottom-left-radius: 6px;
    box-shadow: 0 8px 24px rgba(0, 0, 0, 0.15);
}

.salida .bubble {
    background: linear-gradient(135deg, var(--primary), var(--primary-dark));
    color: white;
    border-bottom-right-radius: 6px;
    box-shadow: 0 10px 30px rgba(139, 92, 246, 0.25);
    text-shadow: 0 1px 2px rgba(0,0,0,0.1);
}

/* Distinguir entre Mila y Admin */
.salida[data-sender="Admin"] .bubble {
    background: linear-gradient(135deg, #475569, #1e293b);
}

.msg-meta {
    font-size: 10px;
    color: var(--text-muted);
    margin-top: 4px;
    letter-spacing: 0.02em;
    opacity: 0.8;
}

.entrada .msg-meta { margin-left: 4px; }
.salida .msg-meta { margin-right: 4px; text-align: right; }

/* REPLY AREA REFINED */
.reply-area {
    padding: 24px 40px;
    background: rgba(9, 9, 11, 0.4);
    backdrop-filter: blur(20px);
    border-top: 1px solid var(--border);
}

.reply-box {
    display: flex;
    gap: 15px;
    align-items: flex-end;
    background: rgba(255, 255, 255, 0.03);
    border: 1px solid var(--border);
    border-radius: 20px;
    padding: 10px 18px;
    transition: all 0.3s;
    box-shadow: inset 0 2px 4px rgba(0,0,0,0.1);
}

.reply-box:focus-within {
    border-color: var(--primary);
    background: rgba(255, 255, 255, 0.05);
    box-shadow: 0 0 0 4px rgba(139, 92, 246, 0.15);
}

.reply-box textarea {
    flex: 1;
    background: transparent;
    border: none;
    color: white;
    padding: 10px 0;
    font-family: inherit;
    font-size: 15px;
    resize: none;
    outline: none;
    max-height: 180px;
}

.btn-send {
    background: var(--primary);
    color: white;
    border: none;
    width: 46px;
    height: 46px;
    border-radius: 14px;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    transition: all 0.3s cubic-bezier(0.175, 0.885, 0.32, 1.275);
    box-shadow: 0 4px 12px rgba(139, 92, 246, 0.4);
}

.btn-send:hover {
    background: var(--primary-light);
    transform: scale(1.1) rotate(-5deg);
    box-shadow: 0 6px 20px rgba(139, 92, 246, 0.6);
}

/* SIDEBAR REFINED */
.contact-item {
    padding: 16px 20px;
    margin: 4px 12px;
    border-radius: 16px;
    border: 1px solid transparent;
}

.contact-item.active {
    background: linear-gradient(to right, rgba(139, 92, 246, 0.15), rgba(139, 92, 246, 0.05));
    border-color: rgba(139, 92, 246, 0.4);
}

.contact-item:hover:not(.active) {
    background: rgba(255, 255, 255, 0.05);
}

/* SCROLLBARS */
::-webkit-scrollbar {
    width: 6px;
}
::-webkit-scrollbar-track {
    background: transparent;
}
::-webkit-scrollbar-thumb {
    background: var(--border);
    border-radius: 10px;
}
::-webkit-scrollbar-thumb:hover {
    background: var(--text-muted);
}

/* EMPTY STATE */
.chat-panel.empty {
    justify-content: center;
    align-items: center;
    background: radial-gradient(circle at center, #1e1b4b 0%, var(--bg-dark) 70%);
}

.empty-state {
    text-align: center;
    max-width: 400px;
    animation: fadeIn 0.5s ease-out;
}

.empty-icon {
    font-size: 64px;
    margin-bottom: 24px;
    filter: drop-shadow(0 0 20px var(--primary));
}

.empty-state h3 {
    font-size: 24px;
    margin-bottom: 12px;
}

.empty-state p {
    color: var(--text-muted);
    margin-bottom: 32px;
}

.btn-primary {
    background: var(--primary);
    color: white;
    border: none;
    padding: 12px 24px;
    border-radius: 12px;
    font-family: inherit;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.2s;
}

.btn-primary:hover {
    background: var(--primary-dark);
    box-shadow: 0 0 20px rgba(139, 92, 246, 0.4);
}

/* MODALS */
.modal-overlay {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(0,0,0,0.8);
    backdrop-filter: blur(4px);
    display: none;
    align-items: center;
    justify-content: center;
    z-index: 1000;
}

.modal-overlay.active {
    display: flex;
}

.modal-card {
    background: var(--bg-sidebar);
    border: 1px solid var(--border);
    border-radius: 24px;
    width: 100%;
    max-width: 480px;
    overflow: hidden;
    animation: zoomIn 0.3s cubic-bezier(0.34, 1.56, 0.64, 1);
}

.modal-header {
    padding: 24px;
    border-bottom: 1px solid var(--border);
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.close-modal {
    background: transparent;
    border: none;
    color: var(--text-muted);
    font-size: 20px;
    cursor: pointer;
}

.modal-body {
    padding: 24px;
}

.form-group {
    margin-bottom: 20px;
}

.form-group label {
    display: block;
    font-size: 12px;
    color: var(--text-muted);
    margin-bottom: 8px;
    text-transform: uppercase;
    letter-spacing: 0.05em;
}

.input-with-icon {
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: 12px;
    display: flex;
    align-items: center;
    padding: 12px 16px;
    gap: 12px;
}

.input-with-icon.top {
    align-items: flex-start;
}

.input-with-icon input, .input-with-icon textarea {
    background: transparent;
    border: none;
    color: white;
    width: 100%;
    font-family: inherit;
    outline: none;
}

.input-with-icon textarea {
    height: 100px;
    resize: none;
}

.help-text {
    font-size: 11px;
    color: var(--text-muted);
    margin-top: 6px;
    display: block;
}

.modal-footer {
    padding: 20px 24px;
    background: rgba(0,0,0,0.2);
    display: flex;
    justify-content: flex-end;
    gap: 12px;
}

.btn-ghost {
    background: transparent;
    color: var(--text-muted);
    border: none;
    padding: 10px 20px;
    border-radius: 10px;
    cursor: pointer;
}

/* UTILS */
.spinner {
    width: 24px;
    height: 24px;
    border: 3px solid rgba(255,255,255,0.1);
    border-top-color: var(--primary);
    border-radius: 50%;
    animation: spin 1s linear infinite;
}

@keyframes spin { to { transform: rotate(360deg); } }
@keyframes fadeIn { from { opacity: 0; } to { opacity: 1; } }
@keyframes zoomIn { from { transform: scale(0.9); opacity: 0; } to { transform: scale(1); opacity: 1; } }

/* QR OVERLAY */
.qr-overlay {
    position: fixed;
    inset: 0;
    background: rgba(0,0,0,0.9);
    z-index: 2000;
    display: none;
    align-items: center;
    justify-content: center;
}

.qr-overlay.active {
    display: flex;
}

.qr-card {
    background: white;
    padding: 32px;
    border-radius: 32px;
    text-align: center;
    color: #000;
}

.qr-header h2 { font-size: 24px; margin-bottom: 8px; }
.qr-header p { font-size: 14px; color: #666; margin-bottom: 24px; }
.qr-box { background: #f4f4f5; padding: 20px; border-radius: 16px; min-width: 240px; min-height: 240px; display: flex; align-items: center; justify-content: center; }
.qr-placeholder { color: #666; font-size: 12px; display: flex; flex-direction: column; align-items: center; gap: 12px; }

/* STATUS DOTS */
.status-indicator { display: flex; align-items: center; gap: 8px; font-size: 12px; color: var(--text-muted); padding: 16px 24px; border-top: 1px solid var(--border); }
.dot { width: 8px; height: 8px; border-radius: 50%; background: var(--accent-error); }
.dot.online { background: var(--accent-success); box-shadow: 0 0 8px var(--accent-success); }

#toast {
    position: fixed;
    bottom: 24px;
    right: 24px;
    background: var(--primary);
    color: white;
    padding: 12px 20px;
    border-radius: 12px;
    font-size: 14px;
    font-weight: 500;
    box-shadow: 0 8px 32px rgba(0,0,0,0.5);
    transform: translateY(100px);
    transition: transform 0.3s cubic-bezier(0.18, 0.89, 0.32, 1.28);
    z-index: 5000;
}

#toast.show { transform: translateY(0); }

.status-dot-pulse {
    display: inline-block;
    width: 8px;
    height: 8px;
    background-color: var(--accent-error);
    border-radius: 50%;
    margin-left: 8px;
    vertical-align: middle;
    box-shadow: 0 0 0 0 rgba(244, 63, 94, 0.7);
    animation: pulse-red 2s infinite;
}

@keyframes pulse-red {
    0% {
        transform: scale(0.95);
        box-shadow: 0 0 0 0 rgba(244, 63, 94, 0.7);
    }
    70% {
        transform: scale(1);
        box-shadow: 0 0 0 10px rgba(244, 63, 94, 0);
    }
    100% {
        transform: scale(0.95);
        box-shadow: 0 0 0 0 rgba(244, 63, 94, 0);
    }
}

