:root {
  --fondo: #f6f7f9; --panel: #fff; --texto: #1b1f24; --suave: #667085; --borde: #e4e7ec;
  --acento: #2f5bea; --sube: #0f8a4f; --baja: #c8322b; --aviso: #fff6e0;
  --chip-sube: #dcf5e7; --chip-baja: #fbe0de; --chip-rebaja: #dfe8ff; --chip-dudoso: #fff0c2; --chip-neutro: #eef0f3;
}
@media (prefers-color-scheme: dark) {
  :root {
    --fondo: #0f1216; --panel: #171b21; --texto: #e6e9ee; --suave: #98a2b3; --borde: #2a3039;
    --acento: #7c9bff; --sube: #3ccf87; --baja: #ff6b61; --aviso: #2b2412;
    --chip-sube: #12382a; --chip-baja: #3f1a18; --chip-rebaja: #1c2747; --chip-dudoso: #3a3010; --chip-neutro: #242a33;
  }
}
* { box-sizing: border-box; }
body { margin: 0; background: var(--fondo); color: var(--texto); font: 15px/1.45 system-ui, -apple-system, "Segoe UI", sans-serif; }
a { color: var(--acento); text-decoration: none; }
a:hover { text-decoration: underline; }
h1 { font-size: 1.4rem; margin: 0 0 .5rem; }
h2 { font-size: 1.05rem; margin: 0 0 .75rem; display: flex; justify-content: space-between; align-items: baseline; gap: 1rem; }
small { color: var(--suave); }
code { background: var(--borde); padding: 0 .3em; border-radius: 4px; }

.barra { display: flex; align-items: center; gap: 1.25rem; padding: .7rem 1.25rem; background: var(--panel); border-bottom: 1px solid var(--borde); position: sticky; top: 0; z-index: 5; flex-wrap: wrap; }
.marca { font-weight: 700; color: var(--texto); }
.barra nav { display: flex; gap: .25rem; flex-wrap: wrap; }
.barra nav a { padding: .35rem .7rem; border-radius: 6px; color: var(--suave); }
.barra nav a.activo { background: var(--fondo); color: var(--texto); font-weight: 600; }
.barra .fecha { margin-left: auto; color: var(--suave); font-size: .85rem; }
.salir { font-size: .85rem; }
main { padding: 1.25rem; }

.kpis { display: grid; grid-template-columns: repeat(auto-fit, minmax(220px, 1fr)); gap: .75rem; margin-bottom: 1rem; }
.kpi { background: var(--panel); border: 1px solid var(--borde); border-radius: 10px; padding: .9rem 1rem; display: flex; flex-direction: column; gap: .2rem; }
.kpi-et { color: var(--suave); font-size: .8rem; text-transform: uppercase; letter-spacing: .03em; }
.kpi-val { font-size: 1.5rem; font-weight: 700; font-variant-numeric: tabular-nums; }
.kpi-senales { font-size: 1.05rem; }
.kpi-sub { color: var(--suave); font-size: .8rem; }

.panel { background: var(--panel); border: 1px solid var(--borde); border-radius: 10px; padding: 1rem; margin-bottom: 1rem; }
.panel.aviso { background: var(--aviso); }
.columnas { display: grid; grid-template-columns: repeat(auto-fit, minmax(560px, 1fr)); gap: 1rem; }
.columnas .panel { margin-bottom: 0; }
.mas { font-size: .8rem; font-weight: 400; }
.grafica { position: relative; height: 320px; }
.informe { max-width: 80ch; }
.informe h1, .informe h2, .informe h3 { font-size: 1rem; display: block; margin: 1rem 0 .4rem; }
.informe ul { padding-left: 1.2rem; }

.sube { color: var(--sube); }
.baja { color: var(--baja); }
.tabla-scroll { overflow-x: auto; }
.tabla { width: 100%; border-collapse: collapse; background: var(--panel); }
.tabla th, .tabla td { padding: .45rem .6rem; border-bottom: 1px solid var(--borde); text-align: left; vertical-align: middle; }
.tabla th { font-size: .78rem; color: var(--suave); font-weight: 600; white-space: nowrap; position: sticky; top: 0; background: var(--panel); }
.tabla th a { color: inherit; }
.num { text-align: right !important; font-variant-numeric: tabular-nums; white-space: nowrap; }
.carta-celda a { display: flex; align-items: center; gap: .6rem; color: var(--texto); }
.carta-celda img { width: 34px; height: 47px; object-fit: cover; border-radius: 3px; background: var(--borde); }
.carta-celda span { display: flex; flex-direction: column; }
.vacio { color: var(--suave); text-align: center; padding: 1.5rem; }
.fila-alerta { background: var(--chip-sube); }
.nota { color: var(--suave); font-size: .82rem; }

.chip { display: inline-block; padding: .1rem .55rem; border-radius: 999px; font-size: .78rem; font-weight: 600; white-space: nowrap; background: var(--chip-neutro); }
.chip-sube { background: var(--chip-sube); color: var(--sube); }
.chip-cae { background: var(--chip-baja); color: var(--baja); }
.chip-rebaja { background: var(--chip-rebaja); color: var(--acento); }
.chip-dudoso { background: var(--chip-dudoso); }

.filtros { display: flex; flex-wrap: wrap; gap: .6rem; align-items: flex-end; background: var(--panel); border: 1px solid var(--borde); border-radius: 10px; padding: .8rem; margin-bottom: 1rem; }
.filtros label { display: flex; flex-direction: column; font-size: .75rem; color: var(--suave); gap: .2rem; }
input, select, button { font: inherit; color: var(--texto); background: var(--fondo); border: 1px solid var(--borde); border-radius: 6px; padding: .4rem .55rem; }
button, .boton { background: var(--acento); color: #fff; border-color: var(--acento); cursor: pointer; font-weight: 600; }
.boton { display: inline-block; padding: .5rem .9rem; border-radius: 6px; }
.boton:hover { text-decoration: none; opacity: .9; }
button.enlace { background: none; border: 0; color: var(--acento); padding: 0; font-weight: 400; }
.paginas { display: flex; gap: 1rem; justify-content: center; padding: 1rem; color: var(--suave); }

.ficha { display: flex; gap: 1.5rem; margin-bottom: 1rem; flex-wrap: wrap; }
.ficha-img { width: 260px; max-width: 100%; border-radius: 12px; align-self: flex-start; }
.ficha-datos { flex: 1; min-width: 280px; }
.ficha-set { color: var(--suave); margin-top: 0; }
.pestanas { display: flex; gap: .3rem; margin: .5rem 0; }
.pestanas a { padding: .3rem .7rem; border: 1px solid var(--borde); border-radius: 6px; }
.pestanas a.activo { background: var(--acento); color: #fff; border-color: var(--acento); }
.cotizacion { display: flex; align-items: center; gap: .8rem; margin-top: .6rem; }
.cot-val { font-size: 2.2rem; font-weight: 700; font-variant-numeric: tabular-nums; }
.cot-motivo { color: var(--suave); margin: .2rem 0 .8rem; }
.medias { display: grid; grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); gap: .6rem; margin: 0 0 .5rem; }
.medias div { background: var(--fondo); border-radius: 8px; padding: .5rem .7rem; }
.medias dt { font-size: .75rem; color: var(--suave); }
.medias dd { margin: 0; font-weight: 600; font-variant-numeric: tabular-nums; }
.seguir { display: flex; flex-wrap: wrap; gap: .6rem; align-items: flex-end; margin: 1rem 0 .4rem; }
.seguir label { display: flex; flex-direction: column; font-size: .75rem; color: var(--suave); gap: .2rem; }

.login { display: grid; place-items: center; min-height: 100vh; }
.login-caja { background: var(--panel); border: 1px solid var(--borde); border-radius: 12px; padding: 2rem; display: flex; flex-direction: column; gap: 1rem; width: min(340px, 92vw); }
.login-caja label { display: flex; flex-direction: column; gap: .3rem; font-size: .85rem; color: var(--suave); }
.error { color: var(--baja); margin: 0; }

@media (max-width: 640px) {
  main { padding: .75rem; }
  .columnas { grid-template-columns: 1fr; }
  .barra .fecha { margin-left: 0; }
  .ficha-img { width: 180px; }
}

/* informes a medida */
.informe-form { margin-bottom: 1rem; }
.rejilla { display: grid; grid-template-columns: repeat(auto-fit, minmax(300px, 1fr)); gap: 1rem; margin-bottom: 1rem; }
fieldset { background: var(--panel); border: 1px solid var(--borde); border-radius: 10px; padding: .8rem 1rem 1rem; margin: 0; display: flex; flex-direction: column; gap: .6rem; min-width: 0; }
legend { font-weight: 700; padding: 0 .3rem; }
fieldset > label { display: flex; flex-direction: column; gap: .2rem; font-size: .8rem; color: var(--suave); }
fieldset > label.opcion { flex-direction: row; }
textarea { font: inherit; color: var(--texto); background: var(--fondo); border: 1px solid var(--borde); border-radius: 6px; padding: .5rem; resize: vertical; }
.opciones-titulo { font-size: .8rem; color: var(--suave); }
.opciones-linea { display: flex; flex-wrap: wrap; gap: .2rem 1rem; }
.caja-opciones { max-height: 260px; overflow-y: auto; border: 1px solid var(--borde); border-radius: 6px; padding: .4rem .6rem; background: var(--fondo); }
.caja-opciones.corta { max-height: 150px; }
.opcion { display: flex; align-items: baseline; gap: .4rem; font-size: .88rem; color: var(--texto); padding: .12rem 0; cursor: pointer; }
.opcion[hidden] { display: none; }
.opcion input { margin: 0; }
.informe-enviar { display: flex; align-items: center; justify-content: space-between; gap: 1rem; flex-wrap: wrap; background: var(--panel); border: 1px solid var(--borde); border-radius: 10px; padding: .8rem 1rem; position: sticky; bottom: .75rem; }
.recuento { margin: 0; color: var(--suave); }
.recuento.sin-cartas { color: var(--baja); }
.espera { background: var(--chip-rebaja); }
.error-detalle { white-space: pre-wrap; font-size: .8rem; max-height: 240px; overflow: auto; }
.acciones { display: flex; align-items: center; gap: 1rem; }
.estado-hecho { background: var(--chip-sube); color: var(--sube); }
.estado-error { background: var(--chip-baja); color: var(--baja); }
.estado-pendiente, .estado-en_curso { background: var(--chip-rebaja); color: var(--acento); }
.informe table { border-collapse: collapse; margin: .5rem 0; }
.informe th, .informe td { border: 1px solid var(--borde); padding: .3rem .5rem; }
.boton.secundario { background: var(--panel); color: var(--acento); border: 1px solid var(--acento); }

/* nota de compra */
.nota-badge { display: inline-block; min-width: 2.2em; text-align: center; padding: .1rem .4rem; border-radius: 6px; font-weight: 700; font-size: .85rem; }
.nota-alta { background: var(--sube); color: #fff; }
.nota-buena { background: var(--chip-sube); color: var(--sube); }
.nota-media { background: var(--chip-neutro); color: var(--texto); }
.nota-baja { background: var(--chip-neutro); color: var(--suave); }
.nota-ficha { display: flex; gap: 1rem; align-items: flex-start; background: var(--fondo); border-radius: 10px; padding: .8rem; margin: 0 0 .8rem; }
.nota-grande { min-width: 84px; height: 84px; border-radius: 12px; display: flex; flex-direction: column; align-items: center; justify-content: center; }
.nota-grande span { font-size: 2rem; font-weight: 800; line-height: 1; }
.nota-grande small { color: inherit; opacity: .8; }
.nota-desglose { flex: 1; display: flex; flex-direction: column; gap: .35rem; min-width: 0; }
.nota-parte { display: grid; grid-template-columns: 9.5rem 1fr 3.2rem; gap: .1rem .6rem; align-items: center; }
.np-nombre { font-size: .82rem; }
.np-barra { height: 8px; background: var(--borde); border-radius: 4px; overflow: hidden; }
.np-barra span { display: block; height: 100%; background: var(--acento); }
.np-pts { font-size: .8rem; text-align: right; font-variant-numeric: tabular-nums; }
.np-txt { grid-column: 1 / -1; color: var(--suave); font-size: .76rem; }
@media (max-width: 640px) {
  .nota-ficha { flex-direction: column; }
  .nota-parte { grid-template-columns: 7.5rem 1fr 3rem; }
}
