:root {
  --sidebar-w: 240px;
  --brand: #1f3a5f;
  --brand-2: #2c5282;
}
body { background: #f4f6f9; font-size: 0.925rem; }
.layout { display: flex; min-height: 100vh; }
.sidebar {
  width: var(--sidebar-w); background: var(--brand); color: #dfe7f1; flex-shrink: 0;
  display: flex; flex-direction: column; position: sticky; top: 0; height: 100vh; overflow-y: auto;
}
.sidebar-brand { display: flex; align-items: center; gap: .6rem; padding: 1rem; font-weight: 600; line-height: 1.15; font-size: .95rem; border-bottom: 1px solid rgba(255,255,255,.1); }
.sidebar-brand i { font-size: 1.6rem; color: #f6c445; }
.sidebar .nav-link { color: #dfe7f1; padding: .6rem 1rem; display: flex; align-items: center; gap: .6rem; }
.sidebar .nav-link:hover { background: rgba(255,255,255,.08); color: #fff; }
.sidebar .nav-link.active { background: var(--brand-2); color: #fff; border-left: 3px solid #f6c445; }
.sidebar .nav-link .badge { margin-left: auto !important; }
.sidebar-footer { margin-top: auto; padding: 1rem; border-top: 1px solid rgba(255,255,255,.1); color: #9fb3c8 !important; }
.main { flex: 1; min-width: 0; display: flex; flex-direction: column; }
.topbar { background: #fff; border-bottom: 1px solid #e3e7ec; padding: .6rem 1.25rem; display: flex; align-items: center; gap: .75rem; position: sticky; top: 0; z-index: 1020; }
.content { padding: 1.25rem; }
@media (max-width: 991.98px) {
  .sidebar { position: fixed; left: calc(-1 * var(--sidebar-w)); z-index: 1030; transition: left .2s; }
  .sidebar.open { left: 0; box-shadow: 0 0 20px rgba(0,0,0,.3); }
}

.stat-card { transition: transform .1s; border-left-width: 4px; }
.stat-card:hover { transform: translateY(-2px); }
.stat-card .card-body { padding: .75rem .9rem; }
.stat-icon { font-size: 1.2rem; }
.stat-value { font-size: 1.5rem; font-weight: 700; color: #1f2937; line-height: 1.1; }
.stat-label { font-size: .75rem; color: #6b7280; }
.chart-body { height: 260px; }
.chart-body-wide { height: 220px; }

.score { display: inline-block; min-width: 2.6em; text-align: center; padding: .15em .5em; border-radius: 1em; font-weight: 700; font-size: .85rem; }
.score-lg { font-size: 1.8rem; min-width: 2.2em; padding: .1em .4em; }
.score-excelente { background: #d1fae5; color: #065f46; border: 1px solid #10b981; }
.score-interesante { background: #dbeafe; color: #1e40af; border: 1px solid #3b82f6; }
.score-revisar { background: #fef3c7; color: #92400e; border: 1px solid #f59e0b; }
.score-baja { background: #e5e7eb; color: #374151; border: 1px solid #9ca3af; }

.badge.status-nuevo { background: #0dcaf0; color: #062c33; }
.badge.status-pendiente { background: #adb5bd; color: #212529; }
.badge.status-interesante { background: #ffc107; color: #212529; }
.badge.status-contactar { background: #0d6efd; }
.badge.status-contactado { background: #20c997; color: #062c33; }
.badge.status-seguimiento { background: #6f42c1; }
.badge.status-cliente { background: #198754; }
.badge.status-no_interesado { background: #6c757d; }
.badge.status-descartado { background: #343a40; }
.badge.status-no_contactar { background: #dc3545; }
.badge.prio-alta { background: #dc3545; }
.priority-select.prio-alta { border-color: #dc3545; }
.priority-select.prio-baja { border-color: #adb5bd; color: #6c757d; }
.badge.prio-media { background: #6c757d; }
.badge.prio-baja { background: #adb5bd; color: #212529; }

.status-select { min-width: 150px; font-size: .78rem; padding: .15rem 1.6rem .15rem .4rem; }
.status-select.status-nuevo { border-color: #0dcaf0; }
.status-select.status-interesante { border-color: #ffc107; }
.status-select.status-contactar { border-color: #0d6efd; }
.status-select.status-cliente { border-color: #198754; }
.status-select.status-descartado, .status-select.status-no_contactar { border-color: #dc3545; }

.leads-table th { white-space: nowrap; font-size: .8rem; }
.leads-table td { font-size: .85rem; }
.sort-link { color: inherit; text-decoration: none; }
.sort-link.active { color: var(--brand-2); }
.filter-card .form-label { margin-bottom: .1rem; }
.bulk-bar { background: #fff8e1; padding: .35rem .5rem; border-radius: .4rem; border: 1px solid #ffe08a; }

.dl-compact dt { font-size: .75rem; color: #6b7280; text-transform: uppercase; letter-spacing: .03em; margin-top: .4rem; }
.dl-compact dd { margin-bottom: .1rem; }
.reason-badge { font-weight: 500; font-size: .8rem; margin-bottom: .25rem; }
.notes-pre { white-space: pre-wrap; font-family: inherit; font-size: .875rem; background: #f8f9fa; padding: .6rem; border-radius: .4rem; max-height: 260px; overflow: auto; }
.lead-map { height: 260px; }
.main-map { height: calc(100vh - 230px); min-height: 420px; border-radius: .4rem; }
.timeline .list-group-item { border-left: 3px solid #e5e7eb; }

.check-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(230px, 1fr)); gap: .1rem .5rem; max-height: 220px; overflow: auto; border: 1px solid #e3e7ec; border-radius: .4rem; padding: .5rem; }
.search-log { font-family: ui-monospace, SFMono-Regular, Menlo, monospace; font-size: .75rem; background: #1f2937; color: #d1d5db; padding: .5rem; border-radius: .4rem; max-height: 220px; overflow: auto; white-space: pre-wrap; }
.legend .dot { display: inline-block; width: 10px; height: 10px; border-radius: 50%; margin: 0 .2rem 0 .6rem; vertical-align: middle; }
.marker-dot { border-radius: 50%; border: 2px solid #fff; box-shadow: 0 0 3px rgba(0,0,0,.5); }
.flash-area { position: relative; z-index: 5; }
select[multiple][data-multi] { height: calc(1.5em + .5rem + 2px); }
select[multiple][data-multi]:focus { height: auto; min-height: 8em; position: absolute; z-index: 20; width: auto; min-width: 100%; }
.col-md-1, .col-md-2, .col-md-3 { position: relative; }
.map-sidebar { height: calc(100vh - 230px); min-height: 420px; overflow: auto; }
.map-card { cursor: pointer; }
.map-card:hover { background: #f8f9fa; }
.map-card.active-card { background: #e8f0fe; border-left: 3px solid #2c5282; }
@media (max-width: 991.98px) { .map-sidebar { height: auto; max-height: 40vh; } }

/* Chat interno (estilo mensajería) */
:root { --wa-green: #008069; --wa-light: #25d366; --wa-bg: #efeae2; --wa-mine: #d9fdd3; --wa-tick: #53bdeb; }
.content:has(.wa) { padding: 0; }
.wa { display: flex; height: calc(100vh - 57px); background: #fff; }
.wa-list { width: 340px; flex-shrink: 0; border-right: 1px solid #e3e7ec; display: flex; flex-direction: column; background: #fff; }
.wa-list-head { display: flex; align-items: center; gap: .6rem; padding: .6rem .9rem; background: #f0f2f5; border-bottom: 1px solid #e3e7ec; }
.wa-search { position: relative; padding: .45rem .6rem; border-bottom: 1px solid #e3e7ec; }
.wa-search i { position: absolute; left: 1.3rem; top: 50%; transform: translateY(-50%); color: #8696a0; font-size: .85rem; }
.wa-search input { width: 100%; border: 0; background: #f0f2f5; border-radius: .5rem; padding: .35rem .6rem .35rem 2.2rem; font-size: .9rem; outline: none; }
.wa-items { flex: 1; overflow-y: auto; }
.wa-item { display: flex; align-items: center; gap: .7rem; padding: .55rem .9rem; color: inherit; text-decoration: none; border-bottom: 1px solid #f0f2f5; }
.wa-item:hover { background: #f5f6f6; }
.wa-item.active { background: #f0f2f5; }
.wa-item-body { flex: 1; min-width: 0; }
.wa-item-top { display: flex; justify-content: space-between; align-items: baseline; gap: .5rem; }
.wa-item-title { font-weight: 500; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.wa-item-time { font-size: .72rem; color: #667781; flex-shrink: 0; }
.wa-item-bottom { display: flex; justify-content: space-between; align-items: center; gap: .5rem; }
.wa-item-preview { font-size: .84rem; color: #667781; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.wa-tick-small { color: var(--wa-tick); }
.wa-unread { background: var(--wa-light); color: #fff; font-size: .7rem; font-weight: 600; border-radius: 999px; padding: .1rem .45rem; min-width: 1.3rem; text-align: center; flex-shrink: 0; }
.wa-avatar { width: 42px; height: 42px; border-radius: 50%; display: flex; align-items: center; justify-content: center; color: #fff; font-weight: 600; flex-shrink: 0; font-size: 1.05rem; }
.wa-avatar-general { background: #00a884; }
.wa-avatar-lead { background: #ff8a00; }
.wa-avatar-group { background: #128c7e !important; }
.wa-color-0 { background: #6c8ebf; } .wa-color-1 { background: #d67c3d; } .wa-color-2 { background: #8e6cbf; } .wa-color-3 { background: #3d9e8a; } .wa-color-4 { background: #c25b78; } .wa-color-5 { background: #5c8f3d; }
.wa-avatar-general.wa-color-0, .wa-avatar-general.wa-color-1, .wa-avatar-general.wa-color-2, .wa-avatar-general.wa-color-3, .wa-avatar-general.wa-color-4, .wa-avatar-general.wa-color-5 { background: #00a884; }
.wa-avatar-lead.wa-color-0, .wa-avatar-lead.wa-color-1, .wa-avatar-lead.wa-color-2, .wa-avatar-lead.wa-color-3, .wa-avatar-lead.wa-color-4, .wa-avatar-lead.wa-color-5 { background: #ff8a00; }
.wa-color-text-0 { color: #3d6bb3; } .wa-color-text-1 { color: #b85c1a; } .wa-color-text-2 { color: #7048b3; } .wa-color-text-3 { color: #1f8a72; } .wa-color-text-4 { color: #b0365a; } .wa-color-text-5 { color: #3f7a1f; }
.wa-conv { flex: 1; min-width: 0; display: flex; flex-direction: column; background: var(--wa-bg); }
.wa-chat { display: flex; flex-direction: column; height: 100%; position: relative; }
.wa-head { display: flex; align-items: center; gap: .7rem; padding: .5rem .9rem; background: var(--wa-green); color: #fff; }
.wa-head .wa-avatar { width: 38px; height: 38px; }
.wa-back { color: #fff; font-size: 1.2rem; display: none; }
.wa-messages { flex: 1; overflow-y: auto; padding: 1rem 4% .6rem; display: flex; flex-direction: column; gap: .18rem;
  background-color: var(--wa-bg);
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='120' height='120' viewBox='0 0 120 120'%3E%3Cg fill='none' stroke='%23d9d2c7' stroke-width='1.2' opacity='.55'%3E%3Ccircle cx='20' cy='20' r='6'/%3E%3Cpath d='M70 15l8 8-8 8-8-8z'/%3E%3Cpath d='M100 60c0-6 10-6 10 0s-10 6-10 0'/%3E%3Cpath d='M30 80l6 10h-12z'/%3E%3Cpath d='M60 100h14M67 93v14'/%3E%3Ccircle cx='95' cy='100' r='4'/%3E%3Cpath d='M15 55h10'/%3E%3C/g%3E%3C/svg%3E"); }
.wa-empty { align-self: center; margin: auto; background: #fff7d6; color: #54656f; font-size: .82rem; padding: .4rem .8rem; border-radius: .5rem; box-shadow: 0 1px .5px rgba(0,0,0,.13); }
.wa-day { align-self: center; margin: .6rem 0 .4rem; }
.wa-day span { background: #fff; color: #54656f; font-size: .72rem; font-weight: 500; padding: .3rem .7rem; border-radius: .5rem; box-shadow: 0 1px .5px rgba(0,0,0,.13); }
.wa-msg { position: relative; max-width: 68%; padding: .35rem .5rem .35rem .6rem; border-radius: .55rem; background: #fff; box-shadow: 0 1px .5px rgba(0,0,0,.13); font-size: .92rem; line-height: 1.35; }
.wa-msg.theirs { align-self: flex-start; border-top-left-radius: 0; }
.wa-msg.mine { align-self: flex-end; background: var(--wa-mine); border-top-right-radius: 0; }
.wa-msg::before { content: ""; position: absolute; top: 0; width: 0; height: 0; border-style: solid; }
.wa-msg.theirs::before { left: -8px; border-width: 0 8px 10px 0; border-color: transparent #fff transparent transparent; }
.wa-msg.mine::before { right: -8px; border-width: 0 0 10px 8px; border-color: transparent transparent transparent var(--wa-mine); }
.wa-msg + .wa-msg.theirs.theirs, .wa-msg.theirs + .wa-msg.theirs { border-top-left-radius: .55rem; }
.wa-msg.theirs + .wa-msg.theirs::before, .wa-msg.mine + .wa-msg.mine::before { display: none; }
.wa-msg.mine + .wa-msg.mine { border-top-right-radius: .55rem; }
.wa-sender { font-size: .78rem; font-weight: 600; margin-bottom: .1rem; }
.wa-text { white-space: normal; word-break: break-word; padding-right: 3.6rem; }
.wa-msg:has(.wa-img) .wa-text, .wa-msg:has(.wa-file) .wa-text { padding-right: 0; margin-top: .25rem; }
.wa-text a { color: #027eb5; }
.wa-time { float: right; font-size: .68rem; color: #667781; margin: .35rem 0 -.15rem .5rem; display: flex; align-items: center; gap: .2rem; }
.wa-tick { color: #8696a0; font-size: .95rem; }
.wa-edited { font-style: italic; margin-right: .25rem; }
.wa-reply-btn { position: absolute; top: 2px; right: 4px; border: 0; background: rgba(255,255,255,.85); color: #54656f; border-radius: 50%; width: 22px; height: 22px; font-size: .8rem; line-height: 1; display: none; align-items: center; justify-content: center; box-shadow: 0 1px 2px rgba(0,0,0,.2); }
.wa-msg:hover .wa-reply-btn { display: flex; }
.wa-tools { position: absolute; top: 2px; right: 4px; display: flex; gap: 2px; }
.wa-tools .wa-reply-btn { position: static; }
.wa-deleted { opacity: .65; border: 1px dashed #c0392b; }
.wa-deleted .wa-text { text-decoration: line-through; }
.wa-del-label { font-size: .72rem; color: #c0392b; font-style: italic; margin-top: .2rem; }
.wa-removed .wa-removed-text { font-style: italic; color: #667781; padding-right: 3.2rem; }
.wa-quote { display: block; border-left: 4px solid #06cf9c; background: rgba(0,0,0,.05); border-radius: .3rem; padding: .3rem .5rem; margin-bottom: .3rem; text-decoration: none; color: inherit; font-size: .84rem; }
.wa-msg.mine .wa-quote { background: rgba(0,0,0,.06); }
.wa-quote-who { font-weight: 600; color: #06a37c; font-size: .78rem; }
.wa-quote-text { color: #54656f; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; max-width: 420px; }
.wa-card { background: rgba(0,0,0,.04); border-radius: .5rem; padding: .5rem .6rem; min-width: 260px; max-width: 340px; margin-bottom: .3rem; }
.wa-card-head { display: flex; align-items: center; gap: .5rem; margin-bottom: .35rem; }
.wa-card-name { font-weight: 600; }
.wa-card-sub { font-size: .76rem; color: #667781; }
.wa-card-lines { font-size: .82rem; display: flex; flex-direction: column; gap: .1rem; }
.wa-card-lines i { color: #8696a0; width: 1.1rem; display: inline-block; }
.wa-card-link { display: block; text-align: center; border-top: 1px solid rgba(0,0,0,.08); margin-top: .4rem; padding-top: .35rem; font-size: .84rem; font-weight: 500; color: #027eb5; text-decoration: none; }
.wa-flash { animation: waflash 1.2s; }
@keyframes waflash { 0% { background: #fff3b0; } 100% { background: inherit; } }
.wa-replybar { display: flex; align-items: center; gap: .5rem; background: #f0f2f5; padding: .4rem .8rem 0; }
.wa-replybar-body { flex: 1; min-width: 0; border-left: 4px solid #06cf9c; background: #fff; border-radius: .3rem; padding: .3rem .6rem; }
.wa-replybar-who { font-weight: 600; color: #06a37c; font-size: .78rem; }
.wa-replybar-text { font-size: .84rem; color: #54656f; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.wa-tick.read { color: var(--wa-tick); }
.wa-img img { max-width: 320px; max-height: 320px; border-radius: .4rem; display: block; }
.wa-audio { max-width: 300px; display: block; }
.wa-video { max-width: 320px; border-radius: .4rem; display: block; }
.wa-file { display: flex; align-items: center; gap: .6rem; background: rgba(0,0,0,.05); border-radius: .4rem; padding: .5rem .6rem; color: inherit; text-decoration: none; min-width: 220px; }
.wa-file > i:first-child { font-size: 1.7rem; color: #d33; }
.wa-file > i:last-child { color: #8696a0; }
.wa-file > div { flex: 1; min-width: 0; }
.wa-file-name { font-weight: 500; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; max-width: 260px; }
.wa-file-meta { font-size: .72rem; color: #667781; }
.wa-compose { display: flex; align-items: flex-end; gap: .4rem; padding: .45rem .7rem; background: #f0f2f5; }
.wa-icon { border: 0; background: transparent; color: #54656f; font-size: 1.35rem; padding: .25rem .35rem; line-height: 1; }
.wa-icon:hover { color: #111b21; }
.wa-input { flex: 1; border: 0; border-radius: .6rem; padding: .55rem .8rem; resize: none; max-height: 140px; font-size: .95rem; outline: none; background: #fff; }
.wa-send { border: 0; background: var(--wa-green); color: #fff; width: 42px; height: 42px; border-radius: 50%; font-size: 1.05rem; flex-shrink: 0; display: flex; align-items: center; justify-content: center; }
.wa-send:hover { background: #016a57; }
.wa-emoji { position: absolute; bottom: 62px; left: .6rem; right: .6rem; max-height: 200px; overflow-y: auto; background: #fff; border-radius: .6rem; box-shadow: 0 2px 12px rgba(0,0,0,.2); padding: .4rem; display: grid; grid-template-columns: repeat(auto-fill, minmax(36px, 1fr)); gap: .1rem; z-index: 5; }
.wa-emoji button { border: 0; background: transparent; font-size: 1.35rem; line-height: 1.6; border-radius: .3rem; }
.wa-emoji button:hover { background: #f0f2f5; }
.wa-drop-hint { position: absolute; inset: 0; background: rgba(0,128,105,.85); color: #fff; display: flex; align-items: center; justify-content: center; font-size: 1.3rem; gap: .6rem; z-index: 6; pointer-events: none; }
.wa-placeholder { margin: auto; text-align: center; max-width: 420px; color: #54656f; padding: 2rem; }
.wa-placeholder > i { font-size: 4rem; color: #c5ccd1; }
/* Conversación incrustada en la ficha */
.wa-embed { border: 1px solid #e3e7ec; border-radius: .4rem; overflow: hidden; }
.wa-embed .wa-chat { height: auto; }
.wa-embed .wa-messages { height: 260px; padding: .8rem 1rem .4rem; }
.wa-embed .wa-head { padding: .4rem .8rem; }
.wa-embed .wa-emoji { bottom: 58px; }
/* Móvil: lista o conversación a pantalla completa, botones de grupo desplazables, sin zoom al escribir */
.wa { height: calc(100dvh - 57px); }
.wa-messages { -webkit-overflow-scrolling: touch; overscroll-behavior: contain; }
#groupBar { max-width: 100%; }
@media (hover: none) {
  .wa-tools .wa-reply-btn { display: flex; opacity: .55; }
}
@media (max-width: 767.98px) {
  .wa { height: calc(100dvh - 53px); }
  .wa-list { width: 100%; border-right: 0; }
  .wa-conv { display: none; }
  .wa-has-conv .wa-list { display: none; }
  .wa-has-conv .wa-conv { display: flex; }
  .wa-back { display: inline; }
  .wa-msg { max-width: 88%; }
  .wa-img img { max-width: 100%; max-height: 260px; }
  .wa-video { max-width: 100%; }
  .wa-quote-text { max-width: 100%; }
  .wa-card { min-width: 0; max-width: 100%; }
  .wa-messages { padding: .6rem 3% .4rem; }
  .wa-input, .wa-search input { font-size: 16px; }
  .wa-compose { padding-bottom: calc(.45rem + env(safe-area-inset-bottom)); }
  .wa-emoji { bottom: calc(62px + env(safe-area-inset-bottom)); max-height: 160px; }
  .wa-head .btn { padding: .2rem .45rem; }
  #groupBar { flex-wrap: nowrap !important; overflow-x: auto; white-space: nowrap; scrollbar-width: none; padding: 2px 0; }
  #groupBar::-webkit-scrollbar { display: none; }
  #groupBar .btn { flex-shrink: 0; }
  .topbar { padding: .45rem .6rem; gap: .4rem; }
  .content:has(.wa) { padding: 0; }
  body:has(.wa) { overflow: hidden; height: 100dvh; }
  .wa-compose { flex-shrink: 0; }
  .wa-head { flex-shrink: 0; }
}
}
