:root {
  --marca: #1f4e79;
  --marca-suave: color-mix(in srgb, var(--marca) 10%, white);
  --fondo: #f5f6f8;
  --papel: #ffffff;
  --texto: #1b1f24;
  --tenue: #6b7280;
  --borde: #e5e7eb;
  --ok: #15803d;
  --ok-suave: #dcfce7;
  --mal: #b91c1c;
  --mal-suave: #fee2e2;
  --aviso: #92400e;
  --aviso-suave: #fef3c7;
  --wa: #128c7e;
  --radio: 14px;
  --sombra: 0 1px 2px rgb(0 0 0 / .04), 0 4px 16px rgb(0 0 0 / .05);
  --menu: 232px;
  color-scheme: light;
}
* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body { margin: 0; font: 16px/1.5 Inter, system-ui, -apple-system, "Segoe UI", sans-serif; background: var(--fondo); color: var(--texto); }
a { color: var(--marca); text-decoration: none; }
h1 { font-size: 1.75rem; line-height: 1.2; margin: 0; font-weight: 700; letter-spacing: -.02em; }
h2 { font-size: 1.1rem; margin: 0 0 .75rem; font-weight: 600; }
h3 { font-size: .8rem; text-transform: uppercase; letter-spacing: .06em; color: var(--tenue); margin: 1rem 0 .5rem; font-weight: 600; }
button, input, select, textarea { font: inherit; color: inherit; }
.tenue { color: var(--tenue); }
.sub { color: var(--tenue); margin: .25rem 0 0; font-size: .95rem; }
.sub::first-letter { text-transform: uppercase; }

/* ---------- Menú lateral ---------- */
.menu { position: fixed; inset: 0 auto 0 0; width: var(--menu); background: var(--papel); border-right: 1px solid var(--borde); display: flex; flex-direction: column; padding: 20px 14px; z-index: 20; }
.marca { display: flex; align-items: center; gap: 10px; padding: 4px 8px 22px; min-height: 64px; }
.marca img { max-width: 100%; max-height: 56px; object-fit: contain; }
.marca-ini { width: 40px; height: 40px; border-radius: 12px; background: var(--marca); color: #fff; display: grid; place-items: center; font-weight: 700; flex: none; }
.marca-nombre { font-weight: 600; line-height: 1.2; }
#nav { display: flex; flex-direction: column; gap: 4px; }
#nav a { display: flex; align-items: center; gap: 12px; padding: 12px 12px; border-radius: 10px; color: var(--texto); font-weight: 500; }
#nav a:hover { background: var(--fondo); }
#nav a.activo { background: var(--marca-suave); color: var(--marca); }
.menu-pie { margin-top: auto; display: flex; align-items: center; justify-content: space-between; padding: 8px; }
.idioma { display: inline-flex; border: 1px solid var(--borde); border-radius: 999px; padding: 2px; }
.idioma button { border: 0; background: none; padding: 4px 10px; border-radius: 999px; font-size: .8rem; font-weight: 600; cursor: pointer; color: var(--tenue); }
.idioma button.activo { background: var(--marca); color: #fff; }
.salir { color: var(--tenue); font-size: .9rem; }

.vista { margin-left: var(--menu); padding: 32px 40px 120px; max-width: calc(var(--menu) + 1100px); outline: none; }
.barra-movil { display: none; }

/* ---------- Bloques ---------- */
.cabecera { display: flex; align-items: center; justify-content: space-between; gap: 16px; margin-bottom: 24px; flex-wrap: wrap; }
.contador { font-size: 1rem; color: var(--tenue); font-weight: 500; vertical-align: middle; background: var(--papel); border: 1px solid var(--borde); padding: 2px 10px; border-radius: 999px; }
.tarjeta { background: var(--papel); border: 1px solid var(--borde); border-radius: var(--radio); padding: 20px; box-shadow: var(--sombra); margin-bottom: 16px; min-width: 0; }
.tarjeta-cab { display: flex; justify-content: space-between; align-items: baseline; gap: 8px; }
.tarjeta-cab a { font-size: .9rem; font-weight: 500; }
.dos-col { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; }
.dos-col > .tarjeta { margin: 0; }
.vacio { color: var(--tenue); text-align: center; padding: 24px 8px; margin: 0; }
.aviso { display: block; background: var(--aviso-suave); color: var(--aviso); border-radius: 12px; padding: 12px 16px; margin-bottom: 16px; font-size: .95rem; }
.aviso.suave { background: var(--marca-suave); color: var(--texto); }
.aviso.error { background: var(--mal-suave); color: var(--mal); }
.volver { display: inline-block; margin-bottom: 12px; font-weight: 500; }
.cargando { height: 3px; width: 120px; margin: 40px auto; border-radius: 3px; background: linear-gradient(90deg, transparent, var(--marca), transparent); background-size: 200% 100%; animation: carga 1s linear infinite; }
@keyframes carga { to { background-position: -200% 0; } }

/* Botones */
.boton { display: inline-flex; align-items: center; justify-content: center; gap: 8px; border: 1px solid var(--marca); background: var(--marca); color: #fff; padding: 11px 18px; border-radius: 12px; font-weight: 600; cursor: pointer; min-height: 46px; white-space: nowrap; }
.boton:hover { filter: brightness(1.08); }
.boton:disabled { opacity: .6; cursor: progress; }
.boton.secundario { background: var(--papel); color: var(--texto); border-color: var(--borde); }
.boton.secundario:hover { background: var(--fondo); filter: none; }
.boton.whatsapp { background: var(--wa); border-color: var(--wa); }
.boton.peligro-suave { background: var(--papel); color: var(--mal); border-color: var(--borde); }
.boton.pequeno { min-height: 38px; padding: 7px 14px; font-size: .92rem; }
.boton.grande { min-height: 54px; padding: 14px 28px; font-size: 1.05rem; }
.botones-fila { display: flex; gap: 10px; flex-wrap: wrap; margin-bottom: 16px; }
.icono { border: 0; background: none; cursor: pointer; width: 40px; height: 40px; border-radius: 10px; font-size: 1.1rem; color: var(--tenue); }
.icono:hover { background: var(--fondo); }

/* Inicio */
.acciones-rapidas { display: grid; grid-template-columns: repeat(3, 1fr); gap: 12px; margin-bottom: 20px; }
.accion { display: flex; align-items: center; gap: 14px; padding: 18px; background: var(--papel); border: 1px solid var(--borde); border-radius: var(--radio); font-weight: 600; font-size: 1.05rem; color: var(--texto); cursor: pointer; text-align: left; box-shadow: var(--sombra); }
.accion:hover { border-color: var(--marca); }
.accion-ico { width: 48px; height: 48px; border-radius: 12px; background: var(--marca-suave); color: var(--marca); display: grid; place-items: center; flex: none; }
.accion.destacada { background: var(--marca); color: #fff; border-color: var(--marca); }
.accion.destacada .accion-ico { background: rgb(255 255 255 / .18); color: #fff; }
.cifras { display: grid; grid-template-columns: repeat(4, 1fr); gap: 12px; margin-bottom: 20px; }
.cifras.tres { grid-template-columns: repeat(3, 1fr); }
.cifra { background: var(--papel); border: 1px solid var(--borde); border-radius: var(--radio); padding: 16px 18px; display: flex; flex-direction: column; color: var(--texto); box-shadow: var(--sombra); min-width: 0; }
.cifra span { color: var(--tenue); font-size: .88rem; }
.cifra b { font-size: 1.5rem; font-weight: 700; letter-spacing: -.02em; font-variant-numeric: tabular-nums; }
.cifra small { color: var(--tenue); font-size: .82rem; overflow: hidden; text-overflow: ellipsis; }
.cifra.alerta b { color: var(--mal); }
.titular { font-weight: 600; font-size: 1.05rem; margin: 0 0 12px; }
.titular.grande { font-size: 1.35rem; line-height: 1.3; letter-spacing: -.01em; }
.mini-cotis { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; }
.mini-cotis div { background: var(--fondo); border-radius: 10px; padding: 10px; display: flex; flex-direction: column; min-width: 0; }
.mini-cotis span { font-size: .78rem; color: var(--tenue); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.mini-cotis b { font-variant-numeric: tabular-nums; }
.cambio { font-size: .82rem; font-weight: 600; color: var(--tenue); font-variant-numeric: tabular-nums; white-space: nowrap; }
.cambio.sube { color: var(--ok); }
.cambio.baja { color: var(--mal); }
.claves { margin: 12px 0 0; padding-left: 20px; }
.claves li { margin-bottom: 4px; }

/* Listas */
.lista { display: flex; flex-direction: column; }
.fila-lista { display: flex; align-items: center; gap: 12px; padding: 12px 4px; border-bottom: 1px solid var(--borde); color: var(--texto); min-width: 0; }
.fila-lista:last-child { border-bottom: 0; }
.fila-lista > div:not(.dcha) { flex: 1; min-width: 0; display: flex; flex-direction: column; }
.fila-lista b { font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.fila-lista small { color: var(--tenue); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.fila-lista:hover { background: var(--fondo); }
.lista.grande { background: var(--papel); border: 1px solid var(--borde); border-radius: var(--radio); padding: 4px 12px; box-shadow: var(--sombra); }
.dcha { margin-left: auto; text-align: right; display: flex; flex-direction: column; align-items: flex-end; gap: 2px; flex: none; }
.flecha { color: var(--tenue); font-size: 1.4rem; }
.avatar { width: 42px; height: 42px; border-radius: 50%; background: var(--marca-suave); color: var(--marca); display: grid; place-items: center; font-weight: 700; font-size: .9rem; flex: none; }
.avatar.grande { width: 60px; height: 60px; font-size: 1.2rem; }
.cliente-tit { display: flex; align-items: center; gap: 14px; min-width: 0; }
.cliente-tit h1 { overflow-wrap: anywhere; }
.estado { font-size: .75rem; font-weight: 600; padding: 2px 9px; border-radius: 999px; background: var(--fondo); color: var(--tenue); vertical-align: middle; }
.estado.pendiente { background: var(--aviso-suave); color: var(--aviso); }
.estado.vencida { background: var(--mal-suave); color: var(--mal); }
.estado.cobrada { background: var(--ok-suave); color: var(--ok); }
h1 .estado { font-size: .85rem; letter-spacing: 0; }
.buscador { width: 100%; padding: 14px 16px; border: 1px solid var(--borde); border-radius: 12px; background: var(--papel); margin-bottom: 14px; font-size: 1rem; }
.buscador:focus, .formulario input:focus, .formulario select:focus, .formulario textarea:focus { outline: 2px solid var(--marca); outline-offset: -1px; border-color: transparent; }
.filtros { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; margin-bottom: 4px; }
.filtros .buscador { flex: 1 1 220px; width: auto; margin: 0 0 14px; }
.chip { padding: 8px 14px; border-radius: 999px; background: var(--papel); border: 1px solid var(--borde); color: var(--texto); font-weight: 500; font-size: .92rem; margin-bottom: 14px; }
.chip.activo { background: var(--marca); border-color: var(--marca); color: #fff; }
.datos { display: grid; grid-template-columns: repeat(auto-fill, minmax(220px, 1fr)); gap: 14px 20px; margin: 0; }
.datos dt { font-size: .8rem; color: var(--tenue); }
.datos dd { margin: 0; overflow-wrap: anywhere; }

/* Formularios */
.formulario label { display: flex; flex-direction: column; gap: 6px; font-size: .88rem; font-weight: 500; color: var(--tenue); margin-bottom: 12px; min-width: 0; }
.formulario label small { font-weight: 400; }
.formulario input, .formulario select, .formulario textarea { padding: 12px 14px; border: 1px solid var(--borde); border-radius: 10px; background: var(--papel); color: var(--texto); font-size: 1rem; width: 100%; min-height: 46px; }
.formulario textarea { resize: vertical; }
.rejilla { display: grid; grid-template-columns: 1fr 1fr; gap: 0 14px; }
.rejilla.cuatro { grid-template-columns: repeat(4, 1fr); margin-top: 16px; }
.rejilla .ancho { grid-column: 1 / -1; }
details summary { cursor: pointer; color: var(--marca); font-weight: 500; margin: 4px 0 12px; }
.linea { display: grid; grid-template-columns: 1fr 110px 160px 40px; gap: 10px; align-items: end; }
.linea .quitar { margin-bottom: 15px; }
.totales { display: flex; flex-direction: column; gap: 6px; max-width: 340px; margin-left: auto; }
.totales div { display: flex; justify-content: space-between; gap: 16px; font-variant-numeric: tabular-nums; }
.totales .gran-total { border-top: 2px solid var(--marca); padding-top: 8px; margin-top: 4px; font-size: 1.3rem; color: var(--marca); }
.botones-fila.fijo { position: sticky; bottom: 16px; background: color-mix(in srgb, var(--fondo) 85%, transparent); backdrop-filter: blur(8px); padding: 10px; border-radius: 16px; margin: 0; z-index: 5; }
.tabla { width: 100%; border-collapse: collapse; margin: 16px 0; }
.tabla th { text-align: left; font-size: .78rem; color: var(--tenue); text-transform: uppercase; letter-spacing: .05em; padding: 8px; border-bottom: 2px solid var(--borde); }
.tabla td { padding: 10px 8px; border-bottom: 1px solid var(--borde); }
.tabla .n { text-align: right; font-variant-numeric: tabular-nums; white-space: nowrap; }
.factura-vista p { margin: 0 0 8px; }
.logo-fila { display: flex; align-items: center; gap: 12px; flex-wrap: wrap; }
.logo-fila label.boton { flex-direction: row; color: var(--texto); margin: 0; font-size: .92rem; }
.logo-prev { width: 160px; height: 64px; border: 1px dashed var(--borde); border-radius: 10px; display: grid; place-items: center; color: var(--tenue); overflow: hidden; }
.logo-prev img { max-width: 100%; max-height: 100%; }
.logo-fila .color { flex-direction: row; align-items: center; margin: 0 0 0 auto; }
.logo-fila .color input { width: 56px; padding: 4px; min-height: 40px; }

/* Mercado */
.mercado-texto p { margin: 0 0 12px; }
.fiscal { margin-top: 16px; padding: 12px 14px; border-radius: 10px; background: var(--marca-suave); }
.cotis { display: grid; grid-template-columns: repeat(auto-fill, minmax(260px, 1fr)); gap: 16px; margin-bottom: 16px; }
.cotis .tarjeta { margin: 0; }
.cotis h3 { margin-top: 0; }
.coti { display: grid; grid-template-columns: 1fr auto 72px; gap: 8px; padding: 7px 0; border-bottom: 1px solid var(--borde); align-items: baseline; }
.coti:last-child { border: 0; }
.coti b { font-variant-numeric: tabular-nums; font-weight: 600; }
.coti .cambio { text-align: right; }
.noticias { margin: 0; padding-left: 18px; }
.noticias li { margin-bottom: 8px; }
.noticias small { color: var(--tenue); }

/* ---------- Asistente ---------- */
.boton-ia { position: fixed; right: 24px; bottom: 24px; z-index: 30; display: flex; align-items: center; gap: 10px; background: var(--marca); color: #fff; border: 0; border-radius: 999px; padding: 14px 22px 14px 18px; font-weight: 600; font-size: 1rem; cursor: pointer; box-shadow: 0 8px 24px color-mix(in srgb, var(--marca) 40%, transparent); }
.chat-abierto .boton-ia { display: none; }
.chat { position: fixed; right: 24px; bottom: 24px; width: 420px; height: min(680px, calc(100dvh - 48px)); background: var(--papel); border: 1px solid var(--borde); border-radius: 20px; box-shadow: 0 20px 60px rgb(0 0 0 / .18); display: flex; flex-direction: column; z-index: 40; transform: translateY(20px) scale(.98); opacity: 0; pointer-events: none; transition: .18s ease; }
.chat.abierto { transform: none; opacity: 1; pointer-events: auto; }
.chat header { display: flex; align-items: center; justify-content: space-between; padding: 14px 14px 14px 20px; border-bottom: 1px solid var(--borde); }
.chat header h2 { margin: 0; }
.chat-mensajes { flex: 1; overflow-y: auto; padding: 16px; display: flex; flex-direction: column; gap: 10px; overscroll-behavior: contain; }
.burbuja { max-width: 88%; padding: 10px 14px; border-radius: 16px; overflow-wrap: anywhere; }
.burbuja p { margin: 0 0 6px; }
.burbuja p:last-child { margin: 0; }
.burbuja.yo { align-self: flex-end; background: var(--marca); color: #fff; border-bottom-right-radius: 4px; }
.burbuja.ia { align-self: flex-start; background: var(--fondo); border-bottom-left-radius: 4px; }
.burbuja.error { background: var(--mal-suave); color: var(--mal); }
.burbuja.accion-ia { background: var(--papel); border: 2px solid var(--marca); }
.burbuja.accion-ia .botones-fila { margin: 10px 0 0; }
.burbuja .hecho { color: var(--ok); font-weight: 600; }
.burbuja .error-txt { color: var(--mal); }
.bienvenida { max-width: 100%; }
.ejemplos { display: flex; flex-direction: column; gap: 6px; margin-top: 10px; }
.ejemplos button { text-align: left; border: 1px solid var(--borde); background: var(--papel); border-radius: 10px; padding: 9px 12px; cursor: pointer; font-size: .92rem; }
.ejemplos button:hover { border-color: var(--marca); }
.puntos { display: inline-flex; gap: 3px; vertical-align: middle; }
.puntos i { width: 6px; height: 6px; border-radius: 50%; background: var(--tenue); animation: punto 1s infinite; }
.puntos i:nth-child(2) { animation-delay: .15s; }
.puntos i:nth-child(3) { animation-delay: .3s; }
@keyframes punto { 50% { opacity: .2; } }
.chat-form { display: flex; align-items: flex-end; gap: 8px; padding: 12px; border-top: 1px solid var(--borde); padding-bottom: max(12px, env(safe-area-inset-bottom)); }
.chat-form textarea { flex: 1; resize: none; border: 1px solid var(--borde); border-radius: 14px; padding: 12px 14px; max-height: 140px; min-height: 48px; font-size: 1rem; background: var(--fondo); }
.chat-form textarea:focus { outline: 2px solid var(--marca); border-color: transparent; }
.mic, .enviar { width: 48px; height: 48px; border-radius: 50%; border: 0; cursor: pointer; display: grid; place-items: center; flex: none; }
.mic { background: var(--marca-suave); color: var(--marca); }
.mic.grabando { background: var(--mal); color: #fff; animation: latido 1.2s infinite; }
@keyframes latido { 50% { box-shadow: 0 0 0 10px rgb(185 28 28 / .15); } }
.enviar { background: var(--marca); color: #fff; }

/* Modal y avisos */
.modal { position: fixed; inset: 0; background: rgb(15 23 42 / .45); display: none; align-items: center; justify-content: center; z-index: 60; padding: 16px; }
.modal.abierto { display: flex; }
.modal-caja { background: var(--papel); border-radius: 20px; padding: 24px; width: min(560px, 100%); max-height: calc(100dvh - 32px); overflow-y: auto; }
.toast { position: fixed; left: 50%; bottom: 28px; transform: translate(-50%, 20px); background: #111827; color: #fff; padding: 12px 18px; border-radius: 12px; opacity: 0; pointer-events: none; transition: .2s; z-index: 70; max-width: calc(100vw - 32px); }
.toast.visible { opacity: 1; transform: translate(-50%, 0); }
.toast.ok { background: var(--ok); }
.toast.error { background: var(--mal); }

/* Login */
.login { min-height: 100dvh; display: grid; place-items: center; padding: 16px; }
.login-caja { background: var(--papel); border: 1px solid var(--borde); border-radius: 20px; padding: 32px; width: min(400px, 100%); box-shadow: var(--sombra); display: flex; flex-direction: column; gap: 14px; }
.login-caja .marca { justify-content: center; padding: 0 0 8px; }
.login-caja label { display: flex; flex-direction: column; gap: 6px; font-size: .9rem; color: var(--tenue); font-weight: 500; }
.login-caja input { padding: 13px 14px; border: 1px solid var(--borde); border-radius: 10px; font-size: 1rem; }
.login-caja .error { color: var(--mal); margin: 0; min-height: 1.2em; font-size: .9rem; }
.login-caja .idioma { align-self: center; }

/* ---------- Móvil ---------- */
@media (max-width: 1100px) {
  .cifras { grid-template-columns: repeat(2, 1fr); }
  .dos-col { grid-template-columns: 1fr; }
}
@media (max-width: 900px) {
  .menu { display: none; }
  .vista { margin: 0; padding: 20px 16px calc(150px + env(safe-area-inset-bottom)); padding-top: max(20px, env(safe-area-inset-top)); }
  h1 { font-size: 1.5rem; }
  .barra-movil { display: grid; grid-template-columns: repeat(5, 1fr); position: fixed; inset: auto 0 0 0; background: var(--papel); border-top: 1px solid var(--borde); padding: 6px 4px max(6px, env(safe-area-inset-bottom)); z-index: 25; }
  .barra-movil a { display: flex; flex-direction: column; align-items: center; gap: 2px; font-size: .7rem; color: var(--tenue); padding: 4px 0; font-weight: 500; }
  .barra-movil a.activo { color: var(--marca); }
  .boton-ia { right: 16px; bottom: calc(80px + env(safe-area-inset-bottom)); padding: 14px; }
  .boton-ia span { display: none; }
  .chat { inset: 0; width: auto; height: 100dvh; border-radius: 0; border: 0; padding-top: env(safe-area-inset-top); }
  .acciones-rapidas { grid-template-columns: 1fr; gap: 10px; }
  .accion { padding: 14px; }
  .cifras, .cifras.tres { grid-template-columns: 1fr 1fr; gap: 10px; }
  .cifra b { font-size: 1.2rem; }
  .cifras.tres .cifra:last-child { grid-column: 1 / -1; }
  .rejilla, .rejilla.cuatro { grid-template-columns: 1fr; }
  .linea { grid-template-columns: 1fr 1fr 40px; }
  .linea .concepto { grid-column: 1 / -1; }
  .linea .quitar { grid-row: 2; grid-column: 3; }
  .tarjeta { padding: 16px; }
  .totales { max-width: none; }
  .botones-fila .boton { flex: 1 1 auto; }
  .botones-fila.fijo { position: static; background: none; backdrop-filter: none; padding: 0; }
  .logo-fila .color { margin-left: 0; }
  .tabla th:nth-child(2), .tabla td:nth-child(2), .tabla th:nth-child(3), .tabla td:nth-child(3) { display: none; }
}
@media (max-width: 380px) {
  .mini-cotis { grid-template-columns: 1fr 1fr; }
}
