:root {
  --fondo: #f4f5f7; --panel: #ffffff; --tinta: #16202c; --tenue: #5d6b7c; --borde: #dfe3e8;
  --acento: #0b5cad; --acento-osc: #094a8c; --ok: #1a7f4b; --alerta: #9a6400; --error: #b3261e;
  --radio: 10px;
}
* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body { margin: 0; background: var(--fondo); color: var(--tinta); font: 16px/1.45 system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif; }
a { color: var(--acento); }
h1 { font-size: 1.45rem; margin: 0 0 .8rem; line-height: 1.2; }
h2 { font-size: 1.05rem; margin: 1.6rem 0 .6rem; }
.tenue { color: var(--tenue); }
.oculto { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); }
[hidden] { display: none !important; }

.barra { background: var(--tinta); color: #fff; display: flex; flex-wrap: wrap; align-items: center; gap: .3rem 1rem; padding: .55rem 1rem; }
.barra .marca { color: #fff; font-weight: 700; text-decoration: none; font-size: 1.05rem; margin-right: auto; }
.barra nav { display: flex; flex-wrap: wrap; align-items: center; gap: .15rem; }
.barra nav a, .barra .enlace { color: #cfd8e3; text-decoration: none; padding: .4rem .6rem; border-radius: 6px; font-size: .93rem; }
.barra nav a:hover, .barra .enlace:hover { color: #fff; background: rgba(255,255,255,.1); }
.barra nav a.activa { color: #fff; background: rgba(255,255,255,.16); }
.enlace { background: none; border: 0; cursor: pointer; font: inherit; }
.en-linea { display: inline; margin: 0; }

.contenido { max-width: 1040px; margin: 0 auto; padding: 1rem; }
.contenido.centrado { min-height: 100vh; display: flex; align-items: center; justify-content: center; }
.tarjeta { background: var(--panel); border: 1px solid var(--borde); border-radius: var(--radio); padding: 1.1rem; }
.tarjeta.sin-relleno { padding: 0; overflow: hidden; }
.tarjeta.estrecha { max-width: 640px; }
.tarjeta.vacio { text-align: center; color: var(--tenue); padding: 2.5rem 1rem; }
.login { width: 100%; max-width: 360px; }
.login h1 { margin-bottom: .1rem; }
.login p { margin: 0 0 1rem; }

label { display: block; margin: 0 0 .9rem; font-size: .9rem; font-weight: 600; }
input[type=text], input[type=password], input[type=datetime-local], select {
  display: block; width: 100%; margin-top: .3rem; padding: .6rem .7rem; font: inherit; font-weight: 400; color: var(--tinta);
  background: #fff; border: 1px solid #b9c2cd; border-radius: 8px; min-height: 44px;
}
input:focus, select:focus, button:focus-visible, a:focus-visible { outline: 3px solid rgba(11,92,173,.35); outline-offset: 1px; }
label.casilla { font-weight: 400; display: flex; gap: .55rem; align-items: flex-start; margin-bottom: .55rem; font-size: .95rem; }
label.casilla input { margin-top: .25rem; width: 18px; height: 18px; flex: none; }
fieldset { border: 1px solid var(--borde); border-radius: 8px; padding: .8rem .9rem .4rem; margin: 0 0 1rem; }
legend { font-size: .9rem; font-weight: 600; padding: 0 .4rem; }
.ayuda { font-size: .85rem; color: var(--tenue); margin: -.4rem 0 .9rem; }
.dos { display: grid; gap: 0 1rem; }
.con-boton { display: flex; gap: .5rem; margin-top: .3rem; }
.con-boton input { margin-top: 0; }
.botones { display: flex; gap: .6rem; flex-wrap: wrap; margin-top: .4rem; }

.boton { display: inline-flex; align-items: center; justify-content: center; min-height: 44px; padding: .5rem 1rem; font: inherit; font-size: .95rem; font-weight: 600;
  color: var(--tinta); background: #fff; border: 1px solid #b9c2cd; border-radius: 8px; text-decoration: none; cursor: pointer; white-space: nowrap; }
.boton:hover { background: #f0f2f5; }
.boton.primario { background: var(--acento); border-color: var(--acento); color: #fff; }
.boton.primario:hover { background: var(--acento-osc); }
.boton.peligro { color: var(--error); border-color: #e3b5b1; }
.boton.pequeno { min-height: 36px; padding: .3rem .7rem; font-size: .85rem; }
.boton.ancho { width: 100%; }
.boton:disabled { opacity: .55; cursor: default; }

.aviso { padding: .7rem .9rem; border-radius: 8px; margin: 0 0 1rem; font-size: .93rem; border: 1px solid; }
.aviso.ok { background: #e9f6ef; border-color: #b5dec7; color: #12613a; }
.aviso.error { background: #fdecea; border-color: #f2c1bd; color: #8c1d18; }
.aviso.alerta { background: #fff6e0; border-color: #ecd596; color: #6f4a00; }

.chip { display: inline-block; padding: .1rem .55rem; border-radius: 999px; font-size: .78rem; font-weight: 600; background: #e8ebef; color: #3c4858; white-space: nowrap; }
.chip.en_curso, .chip.ok { background: #dff3e8; color: #12613a; }
.chip.pendiente { background: #e3edf9; color: #0a4a8a; }
.chip.terminado, .chip.gris { background: #e8ebef; color: #3c4858; }
.chip.error { background: #fbe0de; color: #8c1d18; }

.cab-pagina { display: flex; align-items: center; justify-content: space-between; gap: 1rem; flex-wrap: wrap; margin-bottom: .8rem; }
.cab-pagina h1 { margin: 0; }

.tabla { width: 100%; border-collapse: collapse; font-size: .94rem; }
.tabla th, .tabla td { padding: .65rem .8rem; text-align: left; border-bottom: 1px solid var(--borde); vertical-align: middle; }
.tabla thead th { font-size: .78rem; text-transform: uppercase; letter-spacing: .03em; color: var(--tenue); background: #f8f9fb; white-space: nowrap; }
.tabla tbody tr:last-child td { border-bottom: 0; }
.tabla .num { text-align: right; font-variant-numeric: tabular-nums; }
.tabla .acciones { text-align: right; white-space: nowrap; }
.tabla th.ordenable { cursor: pointer; user-select: none; }
.tabla th.ordenable:hover { color: var(--tinta); }
.tabla th[aria-sort=ascending]::after { content: " ▲"; }
.tabla th[aria-sort=descending]::after { content: " ▼"; }
.tabla tfoot td { font-weight: 700; background: #f8f9fb; border-top: 2px solid var(--borde); border-bottom: 0; }
.sub { display: block; font-size: .8rem; color: var(--tenue); }
.barra-pct { display: block; height: 4px; border-radius: 2px; background: var(--acento); margin-top: .25rem; margin-left: auto; min-width: 2px; }

.datos { margin: 0 0 1rem; }
.datos dt { font-size: .8rem; text-transform: uppercase; letter-spacing: .03em; color: var(--tenue); margin-top: .8rem; }
.datos dd { margin: .15rem 0 0; }

/* Dashboard */
.cab-evento { display: flex; flex-direction: column; gap: .8rem; margin-bottom: .6rem; }
.titulo-evento h1 { margin: 0; }
.selector { font-size: 1.1rem; font-weight: 700; margin-top: 0; }
.periodo { margin: .4rem 0 0; color: var(--tenue); font-size: .93rem; }
.acciones-evento { display: flex; gap: .5rem; }
.acciones-evento .boton { flex: 1; }
.estado-sync { margin: 0 0 .5rem; font-size: .88rem; color: var(--tenue); min-height: 1.3rem; display: flex; align-items: center; gap: .45rem; }
.spinner { width: 14px; height: 14px; border: 2px solid #c5cdd7; border-top-color: var(--acento); border-radius: 50%; animation: giro .8s linear infinite; flex: none; }
@keyframes giro { to { transform: rotate(360deg); } }
.progreso { height: 6px; background: #dfe3e8; border-radius: 3px; overflow: hidden; margin-bottom: .8rem; }
.progreso div { height: 100%; width: 0; background: var(--acento); transition: width .4s; }
.kpis { display: grid; gap: .7rem; margin: .4rem 0 1rem; }
.kpi { background: var(--panel); border: 1px solid var(--borde); border-radius: var(--radio); padding: .9rem 1rem; display: flex; flex-direction: column; }
.kpi-t { font-size: .8rem; text-transform: uppercase; letter-spacing: .04em; color: var(--tenue); font-weight: 600; }
.kpi-v { font-size: 2rem; font-weight: 700; line-height: 1.2; font-variant-numeric: tabular-nums; }
.kpi-n { font-size: .82rem; color: var(--tenue); }
.cab-grafica { display: flex; align-items: center; justify-content: space-between; gap: 1rem; margin: 1.6rem 0 .6rem; flex-wrap: wrap; }
.cab-grafica h2 { margin: 0; }
.vista-panel { display: inline-flex; border: 1px solid #b9c2cd; border-radius: 8px; overflow: hidden; background: #fff; margin: .2rem 0 0; }
.vista-panel button { font: inherit; font-size: .9rem; font-weight: 600; padding: .45rem 1.1rem; min-height: 40px; border: 0; background: none; color: var(--tenue); cursor: pointer; }
.vista-panel button + button { border-left: 1px solid #b9c2cd; }
.vista-panel button.activa { background: var(--tinta); color: #fff; }
.cab-tabla { display: flex; align-items: center; justify-content: space-between; gap: .5rem 1rem; flex-wrap: wrap; }
.orden-movil { display: none; }
.conmutador { display: inline-flex; border: 1px solid #b9c2cd; border-radius: 8px; overflow: hidden; background: #fff; }
.conmutador button { font: inherit; font-size: .85rem; font-weight: 600; padding: .4rem .8rem; min-height: 36px; border: 0; background: none; color: var(--tenue); cursor: pointer; }
.conmutador button + button { border-left: 1px solid #b9c2cd; }
.conmutador button.activa { background: var(--tinta); color: #fff; }
.grafica { display: flex; flex-direction: column; align-items: center; gap: 1rem; }
.quesito { width: 100%; max-width: 230px; flex: none; }
.quesito svg { display: block; width: 100%; height: auto; }
.quesito:empty { display: none; }
.porcion { stroke: var(--panel); stroke-width: 2; stroke-linejoin: round; transition: opacity .15s; }
.quesito svg:hover .porcion { opacity: .55; }
.quesito svg:hover .porcion:hover { opacity: 1; }
.leyenda { list-style: none; margin: 0; padding: 0; width: 100%; font-size: .93rem; }
.leyenda li { display: flex; align-items: center; gap: .6rem; padding: .4rem 0; border-bottom: 1px solid var(--borde); }
.leyenda li:last-child { border-bottom: 0; }
.leyenda li.ley-item { cursor: pointer; }
.leyenda li.ley-item:hover .ley-nombre { text-decoration: underline; }
.leyenda li.ley-item:focus-visible { outline: 3px solid rgba(11,92,173,.35); outline-offset: 2px; border-radius: 4px; }
.leyenda li.ley-item.apagado { opacity: .55; }
.leyenda li.ley-item.apagado .ley-nombre { text-decoration: line-through; }
.leyenda li.ley-resto { color: var(--tenue); }
.leyenda li.ley-fija { cursor: default; }
.leyenda li.ley-reset { justify-content: flex-end; cursor: pointer; font-size: .85rem; color: var(--acento); font-weight: 600; border-bottom: 0; }
.leyenda li.ley-reset:hover { text-decoration: underline; }
.punto { width: 12px; height: 12px; flex: none; }
.ley-txt { flex: 1; min-width: 0; display: flex; flex-direction: column; }
.ley-nombre { overflow-wrap: anywhere; }
.ley-valor { color: var(--tenue); font-variant-numeric: tabular-nums; white-space: nowrap; font-size: .85rem; }
.ley-pct { font-weight: 700; font-variant-numeric: tabular-nums; min-width: 4.2em; text-align: right; white-space: nowrap; }

/* Tablas de administración apiladas en móvil */
@media (max-width: 719px) {
  .tabla.apilable thead { display: none; }
  .tabla.apilable tr { display: block; padding: .6rem .8rem; border-bottom: 1px solid var(--borde); }
  .tabla.apilable tr:last-child { border-bottom: 0; }
  .tabla.apilable td { display: flex; justify-content: space-between; gap: 1rem; padding: .2rem 0; border: 0; text-align: right; }
  .tabla.apilable td[data-t]::before { content: attr(data-t); color: var(--tenue); font-size: .8rem; text-align: left; flex: none; }
  .tabla.apilable td.acciones { justify-content: flex-end; padding-top: .5rem; gap: .4rem; }
  /* Tabla de productos en móvil: el nombre en una línea y las tres cifras debajo */
  #tabla-productos thead { display: none; }
  #tabla-productos tbody tr { display: grid; grid-template-columns: 1fr 1.25fr .9fr; gap: .1rem .6rem; padding: .65rem .8rem; border-bottom: 1px solid var(--borde); }
  #tabla-productos tbody tr:last-child { border-bottom: 0; }
  #tabla-productos tbody td { padding: 0; border: 0; }
  #tabla-productos tbody td:first-child { grid-column: 1 / -1; font-weight: 600; overflow-wrap: anywhere; margin-bottom: .15rem; }
  #tabla-productos tbody td.num { text-align: left; white-space: nowrap; }
  #tabla-productos tbody td.num:last-child { text-align: right; }
  #tabla-productos tbody td[data-t]::before { content: attr(data-t); display: block; font-size: .68rem; text-transform: uppercase; letter-spacing: .03em; color: var(--tenue); }
  #tabla-productos .barra-pct { display: none; }
  /* En móvil no hay cabecera de tabla: la ordenación se hace con este selector. */
  .orden-movil { display: flex; align-items: center; gap: .5rem; margin: 1.6rem 0 .6rem; font-size: .85rem; font-weight: 400; }
  .orden-movil select { width: auto; min-height: 36px; margin: 0; padding: .3rem .5rem; }
  .cab-tabla { align-items: flex-start; }
}
@media (min-width: 720px) {
  .contenido { padding: 1.5rem; }
  h1 { font-size: 1.7rem; }
  .dos { grid-template-columns: 1fr 1fr; }
  .kpis { grid-template-columns: repeat(3, 1fr); }
  .kpi-v { font-size: 2.3rem; }
  .cab-evento { flex-direction: row; align-items: flex-end; justify-content: space-between; }
  .acciones-evento .boton { flex: none; }
  .selector { min-width: 340px; }
  .grafica { flex-direction: row; align-items: center; gap: 2rem; padding: 1.4rem; }
  .ley-txt { flex-direction: row; align-items: baseline; gap: 1rem; }
  .ley-nombre { flex: 1; }
  .ley-valor { font-size: inherit; }
}
