:root {
    --navy-900: #021861;
    --navy-950: #060e26;
    --blue-600: #255dce;
    --blue-500: #3b76ef;
    --amber-500: #E88D14;
    --bg-surface: #f8fafc;
    --bg-panel: #ffffff;
    --bg-chat: #eef2f6;
    --border-color: #e2e8f0;
    --text-main: #0f172a;
    --text-muted: #64748b;
    --out-bubble: #d9fdd3;
    --in-bubble: #ffffff;
    --green-wa: #10b981;
}

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

body {
    font-family: 'DM Sans', -apple-system, BlinkMacSystemFont, sans-serif;
    background-color: var(--bg-surface);
    color: var(--text-main);
    height: 100vh;
    overflow: hidden;
}

.hidden { display: none !important; }

.app-layout {
    display: flex;
    flex-direction: column;
    height: 100vh;
}

/* TOPBAR */
.topbar {
    height: 60px;
    background: var(--navy-900);
    color: #fff;
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0 20px;
    border-bottom: 1px solid rgba(255,255,255,0.1);
}

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

.brand-logo {
    width: 36px;
    height: 36px;
    background: var(--amber-500);
    color: #fff;
    font-weight: 700;
    border-radius: 8px;
    display: grid;
    place-items: center;
    font-size: 0.9rem;
}

.brand h1 { font-size: 1.05rem; font-weight: 700; }
.brand .subtitle { font-size: 0.75rem; color: #cbd5e1; display: block; }

.topbar-actions {
    display: flex;
    align-items: center;
    gap: 14px;
}

.status-badge {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 6px 12px;
    border-radius: 999px;
    font-size: 0.8rem;
    font-weight: 500;
    background: rgba(255,255,255,0.1);
}

.status-badge .dot {
    width: 8px;
    height: 8px;
    border-radius: 50%;
    background: #f59e0b;
}

.status-badge.connected .dot { background: #10b981; box-shadow: 0 0 8px #10b981; }

/* LAYOUT DE 3 COLUMNAS */
.crm-grid {
    display: grid;
    grid-template-columns: 340px 1fr 310px;
    height: calc(100vh - 60px);
}

/* COLUMNA 1: CHATS */
.col-chats {
    background: var(--bg-panel);
    border-right: 1px solid var(--border-color);
    display: flex;
    flex-direction: column;
    overflow: hidden;
}

.search-box {
    padding: 12px;
    border-bottom: 1px solid var(--border-color);
}

.search-box input {
    width: 100%;
    padding: 9px 12px;
    border: 1px solid var(--border-color);
    border-radius: 8px;
    font-size: 0.88rem;
    outline: none;
    background: var(--bg-surface);
}

.search-box input:focus { border-color: var(--blue-600); }

.pipeline-tabs {
    display: flex;
    gap: 4px;
    padding: 8px 10px;
    overflow-x: auto;
    border-bottom: 1px solid var(--border-color);
    background: #f1f5f9;
}

.pipeline-tabs .tab {
    border: none;
    background: transparent;
    padding: 5px 10px;
    border-radius: 6px;
    font-size: 0.76rem;
    font-weight: 600;
    color: var(--text-muted);
    cursor: pointer;
    white-space: nowrap;
}

.pipeline-tabs .tab.active {
    background: var(--blue-600);
    color: #fff;
}

.contact-list {
    flex: 1;
    overflow-y: auto;
}

.contact-item {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 12px 14px;
    border-bottom: 1px solid #f1f5f9;
    cursor: pointer;
    transition: background 0.15s;
}

.contact-item:hover { background: #f8fafc; }
.contact-item.active { background: #eff6ff; border-left: 3px solid var(--blue-600); }

.avatar {
    width: 42px;
    height: 42px;
    border-radius: 50%;
    background: var(--navy-900);
    color: #fff;
    display: grid;
    place-items: center;
    font-weight: 700;
    font-size: 0.95rem;
    flex-shrink: 0;
}

.contact-meta {
    flex: 1;
    min-width: 0;
}

.contact-row-top {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 4px;
}

.contact-name {
    font-weight: 600;
    font-size: 0.92rem;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.contact-time {
    font-size: 0.72rem;
    color: var(--text-muted);
}

.contact-preview {
    font-size: 0.82rem;
    color: var(--text-muted);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.unread-badge {
    background: var(--green-wa);
    color: #fff;
    font-size: 0.7rem;
    font-weight: 700;
    padding: 2px 7px;
    border-radius: 99px;
}

/* COLUMNA 2: CONVERSACIÓN */
.col-conversation {
    background: var(--bg-chat);
    display: flex;
    flex-direction: column;
    height: 100%;
    overflow: hidden;
}

.empty-state {
    margin: auto;
    text-align: center;
    max-width: 360px;
    color: var(--text-muted);
    padding: 20px;
}

.empty-icon { font-size: 2.8rem; margin-bottom: 10px; }
.empty-state h2 { font-size: 1.15rem; color: var(--text-main); margin-bottom: 6px; }
.empty-state p { font-size: 0.88rem; line-height: 1.5; }

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

.chat-header {
    height: 62px;
    background: var(--bg-panel);
    border-bottom: 1px solid var(--border-color);
    padding: 0 20px;
    display: flex;
    align-items: center;
    justify-content: space-between;
}

.chat-contact-info {
    display: flex;
    align-items: center;
    gap: 12px;
}

.mono-phone {
    font-family: 'JetBrains Mono', monospace;
    font-size: 0.78rem;
    color: var(--text-muted);
}

.stage-pill {
    font-size: 0.75rem;
    font-weight: 600;
    padding: 4px 10px;
    border-radius: 99px;
    text-transform: uppercase;
    background: #e0f2fe;
    color: #0369a1;
}

.messages-container {
    flex: 1;
    padding: 20px;
    overflow-y: auto;
    display: flex;
    flex-direction: column;
    gap: 10px;
}

.msg-bubble {
    max-width: 68%;
    padding: 10px 14px;
    border-radius: 12px;
    font-size: 0.9rem;
    line-height: 1.45;
    position: relative;
    box-shadow: 0 1px 2px rgba(0,0,0,0.06);
}

.msg-bubble.inbound {
    align-self: flex-start;
    background: var(--in-bubble);
    border-top-left-radius: 2px;
}

.msg-bubble.outbound {
    align-self: flex-end;
    background: var(--out-bubble);
    border-top-right-radius: 2px;
}

.msg-time {
    display: block;
    font-size: 0.68rem;
    color: #64748b;
    text-align: right;
    margin-top: 4px;
}

.chat-input-bar {
    background: var(--bg-panel);
    padding: 12px 16px;
    border-top: 1px solid var(--border-color);
    display: flex;
    gap: 10px;
    align-items: center;
}

.chat-input-bar input {
    flex: 1;
    padding: 11px 14px;
    border: 1px solid var(--border-color);
    border-radius: 8px;
    font-size: 0.92rem;
    outline: none;
}

.chat-input-bar input:focus { border-color: var(--blue-600); }

.btn-QuickReply {
    background: #f1f5f9;
    border: 1px solid var(--border-color);
    border-radius: 8px;
    width: 40px;
    height: 40px;
    cursor: pointer;
    font-size: 1.1rem;
}

.btn-send {
    background: var(--blue-600);
    color: #fff;
    border: none;
    padding: 11px 18px;
    border-radius: 8px;
    font-weight: 600;
    cursor: pointer;
}

.btn-send:hover { background: var(--blue-500); }

/* COLUMNA 3: FICHA CRM */
.col-crm-details {
    background: var(--bg-panel);
    border-left: 1px solid var(--border-color);
    padding: 18px;
    overflow-y: auto;
}

.empty-state-sm {
    color: var(--text-muted);
    font-size: 0.85rem;
    text-align: center;
    margin-top: 40px;
}

.crm-section {
    margin-bottom: 22px;
    padding-bottom: 18px;
    border-bottom: 1px solid var(--border-color);
}

.crm-label {
    display: block;
    font-size: 0.78rem;
    font-weight: 700;
    text-transform: uppercase;
    color: var(--text-muted);
    margin-bottom: 8px;
    letter-spacing: 0.03em;
}

.crm-input, .crm-select, .note-form textarea {
    width: 100%;
    padding: 9px 11px;
    border: 1px solid var(--border-color);
    border-radius: 7px;
    font-size: 0.88rem;
    margin-bottom: 10px;
    font-family: inherit;
}

.crm-phone-display {
    font-size: 0.78rem;
    color: var(--text-muted);
    display: flex;
    justify-content: space-between;
    background: var(--bg-surface);
    padding: 7px 10px;
    border-radius: 6px;
}

.btn-primary-full {
    width: 100%;
    background: var(--navy-900);
    color: #fff;
    border: none;
    padding: 9px;
    border-radius: 7px;
    font-weight: 600;
    cursor: pointer;
}

.btn-secondary-full {
    width: 100%;
    background: #f1f5f9;
    color: var(--text-main);
    border: 1px solid var(--border-color);
    padding: 8px;
    border-radius: 7px;
    font-weight: 600;
    cursor: pointer;
}

. btn-secondary {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    background: var(--amber-500);
    color: #fff;
    border: none;
    padding: 7px 13px;
    border-radius: 7px;
    font-weight: 600;
    font-size: 0.82rem;
    cursor: pointer;
}

.notes-list {
    display: flex;
    flex-direction: column;
    gap: 8px;
    margin-bottom: 12px;
    max-height: 240px;
    overflow-y: auto;
}

.note-item {
    background: #fffbeb;
    border: 1px solid #fde68a;
    padding: 9px 11px;
    border-radius: 7px;
    font-size: 0.83rem;
}

.note-date {
    display: block;
    font-size: 0.68rem;
    color: #92400e;
    margin-top: 4px;
}

/* MODAL QR */
.modal-backdrop {
    position: fixed;
    inset: 0;
    background: rgba(6, 14, 38, 0.72);
    display: grid;
    place-items: center;
    z-index: 100;
}

.modal-box {
    background: #fff;
    width: 92%;
    max-width: 420px;
    border-radius: 12px;
    overflow: hidden;
    box-shadow: 0 20px 40px rgba(0,0,0,0.25);
}

.modal-header {
    padding: 16px 20px;
    background: var(--navy-900);
    color: #fff;
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.btn-close {
    background: transparent;
    border: none;
    color: #fff;
    font-size: 1.1rem;
    cursor: pointer;
}

.modal-body {
    padding: 20px;
    text-align: center;
    font-size: 0.88rem;
    color: var(--text-muted);
}

.qr-frame {
    width: 240px;
    height: 240px;
    margin: 18px auto;
    border: 2px dashed var(--border-color);
    border-radius: 12px;
    display: grid;
    place-items: center;
    padding: 10px;
}

.qr-frame img {
    width: 100%;
    height: 100%;
    object-fit: contain;
}