/* Panel WhatsApp — Mini App de Telegram. Toma los colores del tema de Telegram cuando existen. */
:root {
  --fondo: var(--tg-theme-secondary-bg-color, #f2f3f7);
  --tarjeta: var(--tg-theme-section-bg-color, var(--tg-theme-bg-color, #ffffff));
  --texto: var(--tg-theme-text-color, #0f1419);
  --suave: var(--tg-theme-hint-color, #8a8f98);
  --acento: var(--tg-theme-button-color, #2481cc);
  --acento-texto: var(--tg-theme-button-text-color, #ffffff);
  --link: var(--tg-theme-link-color, #2481cc);
  --borde: color-mix(in srgb, var(--texto) 8%, transparent);
  --burbuja-yo: color-mix(in srgb, var(--acento) 16%, var(--tarjeta));
  --burbuja: var(--tarjeta);
  --rojo: #e5484d;
  --verde: #30a46c;
  --ambar: #f5a524;
  --radio: 18px;
  --sombra: 0 1px 2px rgb(0 0 0 / 4%), 0 4px 16px rgb(0 0 0 / 4%);
  color-scheme: light dark;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-tg]) {
    --fondo: #0e1116; --tarjeta: #181c22; --texto: #e8eaed; --suave: #8b929c;
    --sombra: 0 1px 2px rgb(0 0 0 / 30%);
  }
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { margin: 0; height: 100%; }
body {
  background: var(--fondo); color: var(--texto);
  font: 15px/1.4 -apple-system, BlinkMacSystemFont, "SF Pro Text", "Inter", "Roboto", "Segoe UI", sans-serif;
  -webkit-font-smoothing: antialiased;
}
button { font: inherit; color: inherit; background: none; border: 0; cursor: pointer; padding: 0; }
svg { width: 22px; height: 22px; fill: none; stroke: currentColor; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; }
a { color: var(--link); text-decoration: none; }
[hidden] { display: none !important; }

#app { display: flex; flex-direction: column; height: 100dvh; max-width: 760px; margin: 0 auto; }

/* Barra superior */
.barra {
  display: flex; align-items: center; gap: 10px; padding: 12px 16px 10px;
  padding-top: max(12px, env(safe-area-inset-top));
  background: color-mix(in srgb, var(--fondo) 85%, transparent); backdrop-filter: blur(16px);
  position: sticky; top: 0; z-index: 5;
}
.titulo { flex: 1; min-width: 0; }
.titulo h1 { margin: 0; font-size: 22px; font-weight: 700; letter-spacing: -0.02em; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.titulo p { margin: 1px 0 0; color: var(--suave); font-size: 13px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.icono { width: 36px; height: 36px; border-radius: 50%; display: grid; place-items: center; flex: none; }
.icono:active { background: var(--borde); }
.estado { font-size: 12px; font-weight: 600; padding: 5px 10px; border-radius: 999px; display: inline-flex; align-items: center; gap: 6px; white-space: nowrap; }
.estado::before { content: ""; width: 7px; height: 7px; border-radius: 50%; background: currentColor; }
.estado.ok { color: var(--verde); background: color-mix(in srgb, var(--verde) 12%, transparent); }
.estado.mal { color: var(--rojo); background: color-mix(in srgb, var(--rojo) 12%, transparent); }
.estado.ok::before { animation: latido 2s infinite; }
@keyframes latido { 50% { opacity: .35; } }

main { flex: 1; overflow-y: auto; padding: 4px 16px 24px; overscroll-behavior: contain; }

/* Pestañas inferiores */
.pestanas {
  display: grid; grid-template-columns: repeat(5, 1fr); padding: 6px 6px max(8px, env(safe-area-inset-bottom));
  background: color-mix(in srgb, var(--tarjeta) 88%, transparent); backdrop-filter: blur(16px);
  border-top: 1px solid var(--borde);
}
.pestanas button { display: flex; flex-direction: column; align-items: center; gap: 2px; padding: 6px 0; color: var(--suave); font-size: 11px; font-weight: 500; border-radius: 12px; }
.pestanas button.activa { color: var(--acento); }
.pestanas button.activa svg { stroke-width: 2.2; }

/* Tarjetas y secciones */
.seccion { margin: 18px 0 8px; font-size: 13px; font-weight: 600; color: var(--suave); text-transform: uppercase; letter-spacing: .04em; display: flex; justify-content: space-between; }
.tarjeta { background: var(--tarjeta); border-radius: var(--radio); box-shadow: var(--sombra); }

.cifras { display: grid; grid-template-columns: repeat(2, 1fr); gap: 10px; margin-top: 8px; }
.cifra { padding: 14px 16px; position: relative; overflow: hidden; }
.cifra b { display: block; font-size: 28px; font-weight: 700; letter-spacing: -0.03em; font-variant-numeric: tabular-nums; }
.cifra span { color: var(--suave); font-size: 13px; }
.cifra .emoji { position: absolute; right: 12px; top: 12px; font-size: 20px; opacity: .9; }
.cifra.destacada { background: linear-gradient(135deg, var(--acento), color-mix(in srgb, var(--acento) 60%, #7c3aed)); color: var(--acento-texto); }
.cifra.destacada span { color: color-mix(in srgb, var(--acento-texto) 80%, transparent); }

.grafico { padding: 14px 14px 10px; }
.grafico .cabecera { display: flex; justify-content: space-between; font-size: 13px; color: var(--suave); margin-bottom: 10px; }
.barras { display: flex; align-items: flex-end; gap: 3px; height: 110px; }
.barras div { flex: 1; border-radius: 4px 4px 2px 2px; background: color-mix(in srgb, var(--acento) 30%, transparent); position: relative; min-height: 2px; }
.barras div i { position: absolute; bottom: 0; left: 0; right: 0; border-radius: inherit; background: var(--acento); }
.barras div.hoy { outline: 2px solid color-mix(in srgb, var(--acento) 45%, transparent); outline-offset: 1px; }
.leyenda { display: flex; gap: 14px; font-size: 12px; color: var(--suave); margin-top: 8px; }
.leyenda i { display: inline-block; width: 9px; height: 9px; border-radius: 3px; margin-right: 5px; vertical-align: -1px; }

.tipos { display: flex; flex-wrap: wrap; gap: 8px; }
.tipo { padding: 8px 12px; border-radius: 12px; background: var(--tarjeta); box-shadow: var(--sombra); font-size: 13px; }
.tipo b { font-variant-numeric: tabular-nums; }

/* Listas */
.lista { overflow: hidden; }
.fila { display: flex; align-items: center; gap: 12px; padding: 10px 14px; width: 100%; text-align: left; position: relative; }
.fila + .fila::before { content: ""; position: absolute; top: 0; left: 70px; right: 0; border-top: 1px solid var(--borde); }
.fila:active { background: var(--borde); }
.avatar { width: 46px; height: 46px; border-radius: 50%; flex: none; display: grid; place-items: center; color: #fff; font-weight: 600; font-size: 16px; letter-spacing: .02em; }
.avatar.chico { width: 36px; height: 36px; font-size: 13px; }
.fila .cuerpo { flex: 1; min-width: 0; }
.fila .linea1 { display: flex; justify-content: space-between; gap: 8px; }
.fila .nombre { font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.fila .hora { color: var(--suave); font-size: 12px; flex: none; font-variant-numeric: tabular-nums; }
.fila .previa { color: var(--suave); font-size: 14px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; margin-top: 1px; }
.contador { min-width: 22px; height: 22px; padding: 0 7px; border-radius: 11px; background: color-mix(in srgb, var(--acento) 14%, transparent); color: var(--acento); font-size: 12px; font-weight: 600; display: inline-grid; place-items: center; flex: none; }
.contador.rojo { background: color-mix(in srgb, var(--rojo) 14%, transparent); color: var(--rojo); }

/* Controles */
.segmentado { display: grid; grid-auto-flow: column; grid-auto-columns: 1fr; background: var(--borde); border-radius: 12px; padding: 3px; margin: 6px 0 10px; }
.segmentado button { padding: 7px 0; border-radius: 9px; font-size: 14px; font-weight: 500; color: var(--suave); }
.segmentado button.activo { background: var(--tarjeta); color: var(--texto); box-shadow: var(--sombra); }

.buscador { position: relative; margin: 6px 0 10px; }
.buscador svg { position: absolute; left: 12px; top: 50%; transform: translateY(-50%); width: 18px; height: 18px; color: var(--suave); }
.buscador input { width: 100%; padding: 11px 14px 11px 38px; border-radius: 12px; border: 0; background: var(--borde); color: var(--texto); font: inherit; outline: none; }
.buscador input:focus { box-shadow: 0 0 0 2px color-mix(in srgb, var(--acento) 50%, transparent); }

.chips { display: flex; gap: 8px; overflow-x: auto; padding: 2px 0 10px; scrollbar-width: none; }
.chips::-webkit-scrollbar { display: none; }
.chip { flex: none; padding: 7px 13px; border-radius: 999px; background: var(--tarjeta); box-shadow: var(--sombra); font-size: 13px; font-weight: 500; white-space: nowrap; }
.chip.activo { background: var(--acento); color: var(--acento-texto); }
.fechas { display: flex; gap: 8px; align-items: center; margin-bottom: 10px; font-size: 13px; color: var(--suave); }
.fechas input { flex: 1; min-width: 0; padding: 8px 10px; border-radius: 10px; border: 0; background: var(--borde); color: var(--texto); font: inherit; }

/* Conversación */
.dia { position: sticky; top: 0; z-index: 2; text-align: center; margin: 14px 0 8px; }
.dia span { display: inline-block; padding: 4px 12px; border-radius: 999px; font-size: 12px; font-weight: 600; background: color-mix(in srgb, var(--tarjeta) 85%, transparent); backdrop-filter: blur(8px); box-shadow: var(--sombra); }
.burbuja { max-width: 82%; width: fit-content; padding: 7px 11px 6px; border-radius: 16px; background: var(--burbuja); box-shadow: var(--sombra); margin: 3px 0; position: relative; word-wrap: break-word; }
.burbuja.yo { margin-left: auto; background: var(--burbuja-yo); border-bottom-right-radius: 6px; }
.burbuja:not(.yo) { border-bottom-left-radius: 6px; }
.burbuja .autor { font-size: 13px; font-weight: 600; margin-bottom: 1px; }
.burbuja .meta { font-size: 11px; color: var(--suave); text-align: right; margin-top: 2px; display: flex; gap: 6px; justify-content: flex-end; align-items: center; }
.burbuja .chatref { font-size: 12px; color: var(--link); font-weight: 600; margin-bottom: 2px; display: block; }
.burbuja.borrado { box-shadow: 0 0 0 1.5px color-mix(in srgb, var(--rojo) 55%, transparent); }
.marca { font-size: 10.5px; font-weight: 700; padding: 1px 6px; border-radius: 6px; letter-spacing: .02em; }
.marca.borrado { background: color-mix(in srgb, var(--rojo) 14%, transparent); color: var(--rojo); }
.marca.editado { background: color-mix(in srgb, var(--ambar) 18%, transparent); color: color-mix(in srgb, var(--ambar) 80%, var(--texto)); }
.original { font-size: 12.5px; color: var(--suave); border-left: 2px solid var(--ambar); padding-left: 8px; margin: 4px 0 2px; }
.texto { white-space: pre-wrap; }
.texto mark { background: color-mix(in srgb, var(--ambar) 40%, transparent); color: inherit; border-radius: 3px; padding: 0 1px; }

.adjunto { margin: 2px -4px 4px; }
.foto { display: block; width: 100%; max-width: 280px; min-height: 120px; border-radius: 12px; object-fit: cover; background: var(--borde); }
.archivo { display: flex; align-items: center; gap: 10px; padding: 8px 10px; border-radius: 12px; background: var(--borde); min-width: 220px; }
.archivo .ico { width: 38px; height: 38px; border-radius: 10px; display: grid; place-items: center; background: var(--acento); color: var(--acento-texto); font-size: 11px; font-weight: 700; flex: none; }
.archivo .nom { font-size: 14px; font-weight: 500; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.archivo .det { font-size: 12px; color: var(--suave); }
.archivo div { min-width: 0; flex: 1; }
.transcripcion { font-size: 13.5px; margin-top: 6px; padding: 8px 10px; border-radius: 10px; background: color-mix(in srgb, var(--acento) 8%, transparent); }
.transcripcion small { display: block; font-size: 11px; color: var(--suave); font-weight: 600; margin-bottom: 2px; }
audio { width: 240px; max-width: 100%; height: 36px; margin-top: 4px; }
.acciones { display: flex; gap: 12px; margin-top: 4px; font-size: 13px; }

.cargar { display: block; margin: 12px auto; padding: 9px 18px; border-radius: 999px; background: var(--tarjeta); box-shadow: var(--sombra); font-size: 14px; font-weight: 500; color: var(--acento); }

/* Galería */
.galeria { display: grid; grid-template-columns: repeat(3, 1fr); gap: 4px; border-radius: 14px; overflow: hidden; }
.galeria button { aspect-ratio: 1; background: var(--borde); position: relative; overflow: hidden; }
.galeria img { width: 100%; height: 100%; object-fit: cover; display: block; transition: opacity .3s; }
.galeria .ph { position: absolute; inset: 0; display: grid; place-items: center; font-size: 22px; opacity: .5; }

/* Vacío y carga */
.vacio { text-align: center; color: var(--suave); padding: 48px 20px; }
.vacio .grande { font-size: 40px; margin-bottom: 8px; }
.esqueleto { height: 64px; border-radius: 14px; margin: 8px 0; background: linear-gradient(90deg, var(--borde) 25%, color-mix(in srgb, var(--borde) 40%, transparent) 50%, var(--borde) 75%); background-size: 200% 100%; animation: brillo 1.2s infinite; }
@keyframes brillo { to { background-position: -200% 0; } }

/* Visor de imágenes */
.visor { position: fixed; inset: 0; z-index: 20; background: rgb(0 0 0 / 92%); display: grid; place-items: center; animation: aparecer .18s; }
.visor img { max-width: 100%; max-height: 86dvh; border-radius: 8px; }
.visor .cerrar { position: absolute; top: max(14px, env(safe-area-inset-top)); right: 14px; color: #fff; background: rgb(255 255 255 / 12%); }
.boton-drive { position: absolute; bottom: max(24px, env(safe-area-inset-bottom)); padding: 10px 18px; border-radius: 999px; background: rgb(255 255 255 / 14%); color: #fff; font-weight: 600; font-size: 14px; }
@keyframes aparecer { from { opacity: 0; } }

.sin-acceso { position: fixed; inset: 0; z-index: 30; background: var(--fondo); display: flex; flex-direction: column; align-items: center; justify-content: center; text-align: center; padding: 32px; }
.sin-acceso .candado { font-size: 48px; }
.sin-acceso h2 { margin: 12px 0 6px; }
.sin-acceso p { color: var(--suave); max-width: 320px; }

.entrar { animation: entrar .22s ease-out; }
@keyframes entrar { from { opacity: 0; transform: translateY(6px); } }
