/* ============ layout de dos columnas (cliente y admin) ============ */

body { background: var(--panel); }
body::before {
  content: ""; position: fixed; inset: 0 0 auto 0; height: 127px; background: var(--teal); z-index: 0;
}
[data-theme="dark"] body::before { background: #0b141a; }

.wa-web {
  position: relative; z-index: 1;
  display: grid; grid-template-columns: minmax(300px, 30%) 1fr;
  height: 100dvh; max-width: 1600px; margin: 0 auto;
  background: var(--panel-2); box-shadow: 0 6px 24px rgba(11,20,26,.16);
  overflow: hidden;
}
@media (min-width: 1441px) { .wa-web { height: calc(100dvh - 38px); margin: 19px auto; } }

/* ---- sidebar ---- */

.sidebar {
  display: flex; flex-direction: column; min-width: 0;
  border-right: 1px solid var(--divider); background: var(--panel-2);
}

.side-header {
  flex: none; height: 60px; display: flex; align-items: center; gap: 4px;
  padding: 0 10px 0 16px; background: var(--panel);
}
.side-header .me { display: flex; align-items: center; gap: 10px; flex: 1; min-width: 0; }
.side-header .me strong {
  font-size: 15px; font-weight: 500; white-space: nowrap;
  overflow: hidden; text-overflow: ellipsis;
}

.search-bar { flex: none; padding: 7px 12px; display: flex; gap: 8px; align-items: center; background: var(--panel-2); }
.search-bar .box {
  flex: 1; display: flex; align-items: center; gap: 10px;
  background: var(--panel); border-radius: 8px; padding: 0 12px; height: 35px;
}
.search-bar .box svg { width: 18px; height: 18px; fill: var(--text-2); flex: none; }
.search-bar input { flex: 1; min-width: 0; border: 0; outline: 0; background: none; color: var(--text); font-size: 14px; }

.chat-list { flex: 1; overflow-y: auto; }
.chat-list::-webkit-scrollbar { width: 6px; }
.chat-list::-webkit-scrollbar-thumb { background: rgba(11,20,26,.2); border-radius: 3px; }
[data-theme="dark"] .chat-list::-webkit-scrollbar-thumb { background: rgba(255,255,255,.16); }

.chat-item { display: flex; align-items: center; gap: 13px; padding: 0 0 0 13px; cursor: pointer; height: 72px; }
.chat-item:hover { background: var(--hover); }
.chat-item.active { background: var(--panel); }
[data-theme="dark"] .chat-item.active { background: #2a3942; }

.chat-item .ci-av { position: relative; flex: none; }
.chat-item .ci-av .dot {
  position: absolute; right: 0; bottom: 1px; width: 12px; height: 12px; border-radius: 50%;
  background: #06d755; border: 2px solid var(--panel-2); display: none;
}
.chat-item.online .ci-av .dot { display: block; }

.chat-item .ci-body {
  flex: 1; min-width: 0; height: 100%; display: flex; flex-direction: column;
  justify-content: center; gap: 2px; padding-right: 15px;
  border-bottom: 1px solid var(--divider);
}
.chat-item:last-child .ci-body { border-bottom: 0; }
.ci-row { display: flex; align-items: center; gap: 8px; }
.ci-name { flex: 1; min-width: 0; font-size: 16px; color: var(--text); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.ci-time { font-size: 12px; color: var(--text-2); flex: none; }
.chat-item.unread .ci-time { color: var(--green); }
.ci-last {
  flex: 1; min-width: 0; font-size: 14px; color: var(--text-2);
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
  display: flex; align-items: center; gap: 4px;
}
.ci-last svg { width: 15px; height: 15px; fill: currentColor; flex: none; }
.ci-last .ticks-mini { display: inline-flex; }
.ci-last .ticks-mini.read { color: var(--tick); }
.ci-last em { font-style: normal; color: var(--green); }
.ci-badge {
  flex: none; min-width: 20px; height: 20px; border-radius: 10px; padding: 0 6px;
  background: var(--green); color: #fff; font-size: 12px; font-weight: 600;
  display: none; place-items: center;
}
.chat-item.unread .ci-badge { display: grid; }

.list-empty { padding: 40px 24px; text-align: center; color: var(--text-2); font-size: 14px; line-height: 20px; }

/* ---- panel derecho ---- */

.panel { display: flex; flex-direction: column; min-width: 0; background: var(--chat-bg); position: relative; }

/* el encabezado se pinta con variables: gris por defecto, con color si el asesor lo pide */
body { --hdr-bg: var(--panel); --hdr-fg: var(--text); --hdr-fg2: var(--text-2); --hdr-hover: var(--hover); }

.panel .chat-header { background: var(--hdr-bg); color: var(--hdr-fg); }
.panel .chat-header .icon-btn { color: var(--hdr-fg); }
.panel .chat-header .icon-btn:hover { background: var(--hdr-hover); }
.panel .header-meta h1 { color: var(--hdr-fg); }
.panel .header-meta .status { color: var(--hdr-fg2); }

.panel-empty {
  display: flex; flex-direction: column; align-items: center; justify-content: center;
  gap: 18px; height: 100%; background: var(--panel); border-bottom: 6px solid var(--green);
  text-align: center; padding: 30px;
}
.panel-empty h2 { font-size: 32px; font-weight: 300; color: var(--text); margin: 0; }
.panel-empty p { font-size: 14px; color: var(--text-2); max-width: 460px; line-height: 20px; margin: 0; }
.panel-empty .glyph { width: 250px; opacity: .55; }

.btn-back { display: none; }

/* ============ modos de vista del cliente ============ */

body.client[data-layout="full"] .sidebar,
body.client[data-layout="phone"] .sidebar { display: none; }

body.client[data-layout="full"] .wa-web {
  grid-template-columns: 1fr; max-width: none; margin: 0;
  height: 100dvh; box-shadow: none;
}

body.client[data-layout="phone"] .wa-web {
  grid-template-columns: 1fr; max-width: 500px;
}
@media (min-width: 760px) {
  body.client[data-layout="phone"] .wa-web {
    height: calc(100dvh - 38px); margin: 19px auto; border-radius: 3px;
  }
}

/* encabezado con color: modo celular, pantallas chicas, o porque el asesor lo activo */
body.client[data-layout="phone"],
body.client.hdr-color {
  --hdr-bg: var(--teal);
  --hdr-fg: var(--header-text, #fff);
  --hdr-fg2: var(--header-text-2, rgba(255,255,255,.78));
  --hdr-hover: rgba(255,255,255,.14);
}
/* en oscuro WhatsApp usa encabezado gris, salvo que el asesor pida color a proposito */
[data-theme="dark"] body.client[data-layout="phone"]:not(.hdr-color) {
  --hdr-bg: var(--panel); --hdr-fg: var(--text); --hdr-fg2: var(--text-2); --hdr-hover: var(--hover);
}

/* ============ responsive ============ */

@media (max-width: 900px) {
  /* anclar la app al area visible: el documento nunca scrollea (evita que el
     header quede cortado) y la app sigue al teclado via --app-h (shared.js) */
  body { position: fixed; inset: 0; width: 100%; overflow: hidden; }
  .wa-web {
    grid-template-columns: 1fr; height: var(--app-h, 100dvh); margin: 0;
    max-width: none; box-shadow: none;
    transform: translateY(var(--app-top, 0px));
  }

  /* 16px evita que iOS haga zoom automatico al enfocar el campo */
  .pill textarea { font-size: 16px; }

  /* el admin desliza el panel sobre la lista */
  body.admin .panel {
    position: fixed; inset: 0; z-index: 60; transform: translateX(100%);
    transition: transform .22s ease-out;
  }
  body.admin .panel.open { transform: translateX(0); }
  body.admin .btn-back { display: grid; }

  /* el cliente siempre ve el chat a pantalla completa, con encabezado de color */
  body.client .sidebar { display: none; }
  body.client {
    --hdr-bg: var(--teal);
    --hdr-fg: var(--header-text, #fff);
    --hdr-fg2: var(--header-text-2, rgba(255,255,255,.78));
    --hdr-hover: rgba(255,255,255,.14);
  }
  [data-theme="dark"] body.client:not(.hdr-color) {
    --hdr-bg: var(--panel); --hdr-fg: var(--text); --hdr-fg2: var(--text-2); --hdr-hover: var(--hover);
  }
}

/* Los colores (encabezado, botones, burbujas, fondo) los calcula appearanceVars()
   en shared.js y se aplican como variables CSS inline. Un solo lugar de verdad,
   compartido entre el chat del cliente y la vista previa del panel. */
