/*=============================================
Chat · bandeja de conversaciones
Usa los colores de modern.css (--brand, --line, ...)
=============================================*/

.chat-app{
	--chat-h: calc(100vh - 61px);
	--wa-bg: #efeae2;
	--wa-out: #d9fdd3;
	--wa-in: #ffffff;
	display: grid;
	grid-template-columns: 340px minmax(0, 1fr);
	height: var(--chat-h);
	background: var(--surface);
	overflow: hidden;
}

@supports (height: 100dvh){
	.chat-app{ --chat-h: calc(100dvh - 61px); }
}

.chat-app.info-open{ grid-template-columns: 340px minmax(0, 1fr) 320px; }

/*=============================================
Lista de conversaciones
=============================================*/

.chat-list{
	display: flex; flex-direction: column; min-height: 0;
	border-right: 1px solid var(--line);
	background: var(--surface);
}

.chat-list-head{ display: flex; align-items: center; justify-content: space-between; padding: 16px 16px 10px; }
.chat-list-head h1{ font-size: 1.25rem; font-weight: 700; margin: 0; display: flex; align-items: center; gap: 8px; }
.chat-list-head h1 i{ color: var(--brand); }

.chat-live{ display: inline-flex; align-items: center; gap: 6px; font-size: 12px; color: var(--ink-2); }
.chat-live span{ width: 8px; height: 8px; border-radius: 50%; background: var(--ok); box-shadow: 0 0 0 0 rgba(16,185,129,.5); animation: chatPulse 2s infinite; }
@keyframes chatPulse{ 70%{ box-shadow: 0 0 0 7px rgba(16,185,129,0); } 100%{ box-shadow: 0 0 0 0 rgba(16,185,129,0); } }

.chat-search{
	display: flex; align-items: center; gap: 8px;
	margin: 0 12px 10px; padding: 0 12px;
	background: #f1f5f9; border-radius: 12px; border: 1px solid transparent;
}
.chat-search:focus-within{ background: var(--surface); border-color: var(--brand); box-shadow: 0 0 0 3px var(--brand-soft); }
.chat-search i{ color: var(--muted); }
.chat-search input{ flex: 1; min-width: 0; border: 0; outline: 0; background: transparent; padding: 9px 0; font-size: 14px; }

.chat-filters{ display: flex; gap: 6px; padding: 0 12px 10px; overflow-x: auto; }
.chat-filters button{
	border: 1px solid var(--line); background: var(--surface); color: var(--ink-2);
	border-radius: 999px; padding: 5px 12px; font-size: 12.5px; font-weight: 600; white-space: nowrap;
}
.chat-filters button:hover{ border-color: var(--brand-line); color: var(--brand); }
.chat-filters button.active{ background: var(--brand); border-color: var(--brand); color: #fff; }

.chat-contacts{ flex: 1; min-height: 0; overflow-y: auto; padding: 0 6px 8px; }

.ct{
	display: flex; align-items: center; gap: 12px;
	padding: 10px; border-radius: 12px;
	color: var(--ink) !important; text-decoration: none;
	transition: background .12s;
}
.ct + .ct{ margin-top: 2px; }
.ct:hover{ background: #f5f7fb; }
.ct.active{ background: var(--brand-soft); }
.ct.loading{ opacity: .55; }

.ct-avatar{
	--av: var(--brand);
	position: relative; flex-shrink: 0;
	width: 46px; height: 46px; border-radius: 50%;
	display: inline-flex; align-items: center; justify-content: center;
	background: color-mix(in srgb, var(--av) 16%, #fff); color: var(--av);
	font-weight: 700; font-size: 15px;
}
.ct-avatar.lg{ width: 72px; height: 72px; font-size: 24px; }
.ct-ai{
	position: absolute; right: -2px; bottom: -2px;
	width: 19px; height: 19px; border-radius: 50%;
	background: var(--brand); color: #fff; border: 2px solid var(--surface);
	display: inline-flex; align-items: center; justify-content: center; font-size: 9px;
}

.ct-main{ flex: 1; min-width: 0; display: grid; grid-template-columns: minmax(0, 1fr); gap: 2px; }
.ct-top, .ct-bottom{ display: flex; align-items: center; justify-content: space-between; gap: 8px; }
.ct-name{ font-size: 14.5px; font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.ct-time{ font-size: 11.5px; color: var(--muted); flex-shrink: 0; }
.ct-preview{ font-size: 13px; color: var(--ink-2); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; min-width: 0; flex: 1; }
.ct-name{ min-width: 0; }
.ct.pending .ct-name{ font-weight: 700; }
.ct.pending .ct-time{ color: var(--ok); font-weight: 600; }
.ct.pending .ct-preview{ color: var(--ink); }
.ct-dot{ width: 10px; height: 10px; border-radius: 50%; background: var(--ok); flex-shrink: 0; }

.chat-more{ margin: 6px 12px 12px; border: 1px dashed var(--line); background: transparent; border-radius: 10px; padding: 8px; color: var(--ink-2); font-weight: 600; font-size: 13px; }
.chat-more:hover{ border-color: var(--brand); color: var(--brand); }

.chat-empty-list{ text-align: center; color: var(--muted); padding: 40px 18px; }
.chat-empty-list i{ font-size: 2rem; }
.chat-empty-list p{ margin: 8px 0 0; font-size: 13.5px; }

/*=============================================
Conversación
=============================================*/

.chat-main{ display: flex; flex-direction: column; min-width: 0; min-height: 0; background: var(--wa-bg); }

.chat-head{
	display: flex; align-items: center; gap: 12px;
	padding: 10px 16px; background: var(--surface);
	border-bottom: 1px solid var(--line);
}
.chat-head .ct-avatar{ width: 40px; height: 40px; font-size: 14px; }
.chat-head-name{ flex: 1; min-width: 0; display: grid; }
.chat-head-name strong{ font-size: 15px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.chat-head-name small{ color: var(--ink-2); font-size: 12.5px; display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
.chat-head-tools{ display: flex; align-items: center; gap: 4px; }
.chat-back{ display: none; }

.ai-badge{ display: inline-flex; align-items: center; gap: 4px; padding: 1px 8px; border-radius: 999px; background: var(--brand-soft); color: var(--brand); font-weight: 600; font-size: 11.5px; }
.ai-badge[hidden]{ display: none; }

.chat-body{
	flex: 1; min-height: 0; overflow-y: auto;
	padding: 16px clamp(12px, 4vw, 48px) 20px;
	background-color: var(--wa-bg);
	background-image: radial-gradient(rgba(0,0,0,.035) 1px, transparent 1px);
	background-size: 18px 18px;
}

#chatMessages{ display: flex; flex-direction: column; gap: 4px; }

.chat-older, .chat-start{ display: flex; justify-content: center; margin-bottom: 10px; }
.chat-older[hidden], .chat-start[hidden]{ display: none; }
.chat-start{ font-size: 12px; color: #54656f; background: #fff8c5; border-radius: 8px; padding: 6px 12px; width: fit-content; margin: 0 auto 12px; gap: 6px; align-items: center; }

.chat-date{ display: flex; justify-content: center; margin: 12px 0 6px; position: sticky; top: 0; z-index: 2; }
.chat-date span{ background: #fff; color: #54656f; font-size: 12px; font-weight: 600; padding: 5px 12px; border-radius: 8px; box-shadow: 0 1px .5px rgba(11,20,26,.13); }

/* Burbujas */

.msg{
	position: relative; max-width: min(72%, 560px);
	padding: 7px 10px 5px; border-radius: 10px;
	box-shadow: 0 1px .5px rgba(11,20,26,.13);
	font-size: 14.2px; line-height: 1.45; color: #111b21;
	overflow-wrap: anywhere;
}
.msg.in{ align-self: flex-start; background: var(--wa-in); border-top-left-radius: 2px; }
.msg.out{ align-self: flex-end; background: var(--wa-out); border-top-right-radius: 2px; }
.msg.failed{ background: #fff1f1; box-shadow: inset 0 0 0 1px #fecaca; }

.msg-body a{ color: #027eb5; }
.msg-meta{ display: flex; justify-content: flex-end; align-items: center; gap: 6px; margin-top: 2px; font-size: 11px; color: #667781; }
.msg-status i{ font-size: 15px; line-height: 1; }
.msg-status .is-read{ color: #53bdeb; }
.msg-origin{ display: inline-flex; align-items: center; gap: 3px; padding: 0 6px; border-radius: 6px; background: rgba(0,0,0,.05); font-weight: 600; margin-right: auto; }
.msg-error{ margin-top: 4px; font-size: 12px; color: #b91c1c; }
.msg-reply{ color: #027eb5; }

.msg-media{ display: block; margin: -2px -5px 4px; }
.msg-media img, video.msg-media{ display: block; max-width: 100%; max-height: 340px; border-radius: 8px; }
.msg audio{ max-width: 260px; display: block; }
.msg-caption{ margin-top: 2px; }
.msg-doc{ display: flex; align-items: center; gap: 8px; padding: 10px 12px; border-radius: 8px; background: rgba(0,0,0,.05); color: #111b21 !important; text-decoration: none; }
.msg-doc i{ font-size: 1.4rem; color: #e11d48; }
.msg-location{ display: flex; align-items: center; gap: 10px; padding: 10px 12px; border-radius: 8px; background: rgba(0,0,0,.04); text-decoration: none; color: #111b21 !important; }
.msg-location i{ font-size: 1.6rem; color: #ef4444; }
.msg-location span{ display: grid; }
.msg-location small{ color: #667781; }
.msg-foot{ color: #667781; font-size: 12.5px; margin-top: 4px; }
.msg-opts{ display: grid; gap: 4px; margin-top: 6px; }
.msg-opt{ display: block; font-size: 12.5px; padding: 6px 8px; border-radius: 8px; background: rgba(255,255,255,.65); color: #027eb5; }
.msg-opt strong{ color: #111b21; }

/* Escribir */

.chat-compose{
	display: flex; align-items: flex-end; gap: 8px;
	padding: 10px 14px; background: #f0f2f5;
	border-top: 1px solid var(--line);
}
.attach-wrap{ display: inline-flex; }
.chat-compose .btn-icon{ width: 42px; height: 42px; color: #54656f; }
.chat-compose textarea{
	flex: 1; min-width: 0; resize: none; max-height: 160px;
	border: 0; outline: 0; border-radius: 12px;
	padding: 11px 14px; font-size: 14.5px; line-height: 1.4;
	background: #fff; box-shadow: 0 1px .5px rgba(11,20,26,.08);
}
.chat-send{
	width: 44px; height: 44px; flex-shrink: 0; border: 0; border-radius: 50%;
	background: var(--brand); color: #fff; font-size: 1.05rem;
	display: inline-flex; align-items: center; justify-content: center;
}
.chat-send:hover{ filter: brightness(1.08); }
.chat-send:disabled{ opacity: .6; }
.chat-note{ margin: 0; padding: 0 16px 8px; background: #f0f2f5; font-size: 11.5px; color: var(--muted); }

.chat-welcome{ margin: auto; text-align: center; max-width: 380px; padding: 30px; color: var(--ink-2); }
.chat-welcome > span{ width: 76px; height: 76px; border-radius: 22px; background: var(--surface); color: var(--brand); display: inline-flex; align-items: center; justify-content: center; font-size: 2rem; box-shadow: var(--shadow); margin-bottom: 14px; }
.chat-welcome h2{ font-size: 1.2rem; font-weight: 700; color: var(--ink); }

/*=============================================
Panel lateral del contacto
=============================================*/

.chat-info{ display: none; position: relative; min-height: 0; overflow-y: auto; border-left: 1px solid var(--line); background: var(--surface); padding: 22px 18px; }
.chat-app.info-open .chat-info:not([hidden]){ display: block; }
.chat-info-close{ position: absolute; top: 10px; right: 10px; }

.info-head{ text-align: center; padding-bottom: 16px; border-bottom: 1px solid var(--line); }
.info-head h3{ font-size: 1.05rem; font-weight: 700; margin: 10px 0 2px; }
.info-head p{ color: var(--ink-2); margin: 0 0 12px; font-size: 13px; }
.info-actions{ display: flex; justify-content: center; flex-wrap: wrap; gap: 6px; }

.info-ai{ display: flex; align-items: center; justify-content: space-between; gap: 10px; margin: 16px 0 0; padding: 12px; border-radius: 12px; background: var(--brand-soft); cursor: pointer; }
.info-ai > span:first-child{ display: grid; font-size: 13px; }
.info-ai i{ color: var(--brand); }
.info-ai small{ color: var(--ink-2); font-size: 12px; }

.info-stats{ display: grid; grid-template-columns: 1fr 1fr; gap: 8px; margin-top: 12px; }
.info-stats div{ padding: 10px; border-radius: 10px; background: #f8fafc; display: grid; text-align: center; }
.info-stats strong{ font-size: 15px; }
.info-stats span{ font-size: 11.5px; color: var(--muted); }

.info-sec{ margin-top: 18px; }
.info-sec-head{ display: flex; justify-content: space-between; align-items: center; font-size: 13px; font-weight: 700; margin-bottom: 8px; }
.info-sec-head i{ color: var(--brand); margin-right: 4px; }
.info-sec-head a{ font-size: 12px; font-weight: 600; }
.info-empty{ font-size: 12.5px; color: var(--muted); margin: 0; }
.info-item{ display: flex; justify-content: space-between; align-items: center; gap: 8px; padding: 9px 10px; border-radius: 10px; border: 1px solid var(--line); text-decoration: none; color: var(--ink) !important; font-size: 13px; }
.info-item + .info-item{ margin-top: 6px; }
.info-item:hover{ border-color: var(--brand-line); background: var(--brand-soft); }
.info-item > span:first-child{ display: grid; }
.info-item small{ color: var(--muted); font-size: 11.5px; }

/* Estados (pedidos y citas) */

.st{ font-size: 11px; font-weight: 700; padding: 2px 8px; border-radius: 999px; white-space: nowrap; background: #f1f5f9; color: #475569; }
.st-pendiente{ background: #fffbeb; color: #b45309; }
.st-confirmado, .st-confirmada{ background: #eff6ff; color: #1d4ed8; }
.st-enpreparacion{ background: #f5f3ff; color: #6d28d9; }
.st-encamino{ background: #ecfeff; color: #0e7490; }
.st-entregado, .st-atendida{ background: #ecfdf5; color: #047857; }
.st-cancelado, .st-cancelada{ background: #fef2f2; color: #b91c1c; }

/*=============================================
Pantallas medianas y móviles
=============================================*/

@media (max-width: 1279.98px){
	.chat-app.info-open{ grid-template-columns: 300px minmax(0, 1fr); }
	.chat-app.info-open .chat-info:not([hidden]){ position: fixed; right: 0; top: 0; bottom: 0; width: min(340px, 92vw); z-index: 1060; box-shadow: -10px 0 40px rgba(15,23,42,.18); }
	.chat-app{ grid-template-columns: 300px minmax(0, 1fr); }
}

@media (max-width: 991.98px){
	.chat-app, .chat-app.info-open{ grid-template-columns: minmax(0, 1fr); }
	.chat-main{ display: none; }
	.chat-app.has-chat .chat-list{ display: none; }
	.chat-app.has-chat .chat-main{ display: flex; }
	.chat-back{ display: inline-flex; }
	.msg{ max-width: 86%; }
	.chat-head{ padding: 8px 10px; gap: 8px; }
	.chat-compose{ padding: 8px; }
	.chat-note{ display: none; }
}
