@import url('https://fonts.googleapis.com/css2?family=Inter:wght@400;500;600;700&display=swap');

:root {
  --fuente: 'Inter', system-ui, sans-serif;
  --fondo: #f5f6f8; --tarjeta: #ffffff; --texto: #14161b; --suave: #667085; --linea: #e4e7ec;
  --acento: #1f6feb; --acento-txt: #ffffff; --sube: #12805c; --baja: #c4320a;
  --c1: #1f6feb; --c2: #e8833a; --c3: #12a383; --c4: #7a5af8; --c5: #d6409f; --c6: #0e9384; --c7: #b54708; --c8: #475467;
  --calor: 31, 111, 235;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --fondo: #0f1115; --tarjeta: #171a21; --texto: #eceef2; --suave: #98a2b3; --linea: #2a2f3a;
    --acento: #4c8dff; --sube: #3ccb7f; --baja: #ff7a59;
    --c1: #4c8dff; --c2: #f5a35c; --c3: #34c79f; --c4: #9b8afb; --c5: #ee6fbf; --c6: #2ed3b7; --c7: #f79009; --c8: #98a2b3;
    --calor: 76, 141, 255;
    color-scheme: dark;
  }
}
* { box-sizing: border-box; }
html, body { margin: 0; }
body { background: var(--fondo); color: var(--texto); font: 15px/1.5 var(--fuente); }
a { color: var(--acento); }
h1, h2, h3, h4 { margin: 0 0 .5rem; line-height: 1.25; }
h2 { font-size: 1.25rem; } h3 { font-size: 1rem; font-weight: 600; } h4 { font-size: .95rem; font-weight: 600; }
.suave { color: var(--suave); } .peque { font-size: .82rem; font-weight: 400; }
.error { color: var(--baja); } .sube { color: var(--sube); font-weight: 600; } .baja { color: var(--baja); font-weight: 600; }
.num { text-align: right; font-variant-numeric: tabular-nums; white-space: nowrap; }

.marca { font-weight: 700; display: flex; align-items: center; gap: .5rem; }
.punto { width: .7rem; height: .7rem; border-radius: 50%; background: var(--acento); display: inline-block; }

.cabecera { position: sticky; top: 0; z-index: 5; background: var(--tarjeta); border-bottom: 1px solid var(--linea);
  display: flex; flex-wrap: wrap; gap: .75rem 1.5rem; align-items: center; justify-content: space-between; padding: .75rem 16px; }
.periodo { display: flex; flex-wrap: wrap; align-items: center; gap: .5rem; }
select, input, textarea, button { font: inherit; color: inherit; }
select, input[type=date], input[type=search], input[type=password], textarea {
  background: var(--fondo); border: 1px solid var(--linea); border-radius: 8px; padding: .45rem .6rem; }
button { background: var(--acento); color: var(--acento-txt); border: 0; border-radius: 8px; padding: .55rem 1rem; font-weight: 600; cursor: pointer; }
button:disabled { opacity: .5; cursor: wait; }

main { max-width: 1280px; margin: 0 auto; padding: 1rem 16px 3rem; display: grid; grid-template-columns: minmax(0, 1fr); gap: 1rem; }
.tarjeta { background: var(--tarjeta); border: 1px solid var(--linea); border-radius: 12px; padding: 1rem; min-width: 0; }
.kpis { display: grid; grid-template-columns: repeat(auto-fit, minmax(200px, 1fr)); gap: 1rem; }
.kpi .valor { font-size: 1.6rem; font-weight: 700; font-variant-numeric: tabular-nums; }
.rejilla { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 1rem; }
.ancha { grid-column: 1 / -1; }
.lienzo { position: relative; height: 260px; } .lienzo.alto { height: 400px; }
@media (max-width: 800px) { .rejilla { grid-template-columns: minmax(0, 1fr); } .lienzo { height: 230px; } }

.mapa { overflow-x: auto; }
.mapa table { border-collapse: separate; border-spacing: 3px; width: 100%; font-size: .75rem; }
.mapa th { color: var(--suave); font-weight: 500; padding: 0 .2rem; }
.mapa td { background: rgba(var(--calor), calc(.06 + var(--a) * .94)); color: transparent; border-radius: 4px; height: 26px; min-width: 26px; text-align: center; }
.mapa td:hover { color: var(--texto); outline: 1px solid var(--texto); }

.chat { border-color: var(--acento); }
.sugerencias { display: flex; flex-wrap: wrap; gap: .5rem; margin: .75rem 0; }
.sugerencias button { background: var(--fondo); color: var(--texto); border: 1px solid var(--linea); font-weight: 500; font-size: .85rem; padding: .4rem .7rem; text-align: left; }
.sugerencias button:hover { border-color: var(--acento); }
.conversacion { display: grid; grid-template-columns: minmax(0, 1fr); gap: .75rem; margin: .5rem 0; }
.burbuja { border-radius: 12px; padding: .75rem 1rem; max-width: 100%; min-width: 0; overflow-wrap: anywhere; }
.burbuja p { margin: .3rem 0; } .burbuja ul, .burbuja ol { margin: .3rem 0; padding-left: 1.4rem; }
.burbuja.yo { background: var(--acento); color: var(--acento-txt); justify-self: end; max-width: 85%; }
.burbuja.ia { background: var(--fondo); border: 1px solid var(--linea); }
.pensando { animation: latido 1.4s ease-in-out infinite; }
@keyframes latido { 50% { opacity: .4; } }
@media (prefers-reduced-motion: reduce) { .pensando { animation: none; } }
.grafico-ia { background: var(--tarjeta); border: 1px solid var(--linea); border-radius: 10px; padding: .75rem; margin-top: .75rem; }
.tabla-ia { overflow-x: auto; } .tabla-ia table { border-collapse: collapse; width: 100%; font-size: .88rem; }
.tabla-ia td, .tabla-ia th { padding: .3rem .5rem; border-bottom: 1px solid var(--linea); text-align: left; }
.consultas { margin-top: .5rem; font-size: .8rem; color: var(--suave); }
.consultas pre { white-space: pre-wrap; background: var(--tarjeta); border: 1px solid var(--linea); border-radius: 6px; padding: .5rem; overflow-x: auto; }
.preguntar { display: flex; gap: .5rem; align-items: stretch; }
.preguntar textarea { flex: 1; resize: vertical; min-height: 2.8rem; }

.tabla-cab { display: flex; flex-wrap: wrap; justify-content: space-between; gap: .5rem; align-items: center; }
#tabla details { border-bottom: 1px solid var(--linea); }
#tabla summary { display: grid; grid-template-columns: 1fr auto 7rem; gap: 1rem; padding: .6rem .25rem; cursor: pointer; font-weight: 600; }
#tabla summary:hover { background: var(--fondo); }
table.productos { width: 100%; border-collapse: collapse; margin: 0 0 .75rem; font-size: .9rem; }
table.productos th { color: var(--suave); font-weight: 500; text-align: left; padding: .3rem .5rem; }
table.productos td { padding: .3rem .5rem; border-top: 1px solid var(--linea); }
@media (max-width: 600px) { #tabla summary { grid-template-columns: 1fr; gap: 0; } table.productos th:nth-child(3), table.productos td:nth-child(3), table.productos th:nth-child(4), table.productos td:nth-child(4) { display: none; } }

body.entrar { display: grid; place-items: center; min-height: 100vh; padding: 16px; }
.tarjeta-entrar { background: var(--tarjeta); border: 1px solid var(--linea); border-radius: 14px; padding: 2rem; width: 100%; max-width: 380px; display: grid; gap: .6rem; }
.tarjeta-entrar h1 { font-size: 1.5rem; margin-top: .5rem; }
.tarjeta-entrar .pie { color: var(--suave); font-size: .8rem; text-align: center; margin: .5rem 0 0; }
@media (max-width: 600px) {
  .cabecera { position: static; }
  .kpis { grid-template-columns: repeat(2, minmax(0, 1fr)); gap: .6rem; }
  .kpi { padding: .75rem; } .kpi .valor { font-size: 1.2rem; }
  .periodo input[type=date] { flex: 1; min-width: 0; }
}
