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

:root {
  --fondo: #EEF1EF;
  --papel: #FFFFFF;
  --tinta: #1D2A2E;
  --tinta-2: #4B5B60;
  --tinta-3: #7D8B8F;
  --raya: #D5DCDA;
  --raya-suave: #E7ECEA;
  --ambar: #C98A12;
  --ambar-claro: #F6E7C4;
  --ambar-oscuro: #8E5F06;
  --lupulo: #4F7A34;
  --lupulo-claro: #E2EED8;
  --rojo: #B3412E;
  --rojo-claro: #F7E1DC;
  --latas: #2E6F8E;
  --vidrio: #4F7A34;
  --barriles: #8A5A2B;
  --radio: 6px;
  --sombra: 0 1px 0 rgba(29, 42, 46, .06);
  --fuente: 'Barlow', system-ui, -apple-system, 'Segoe UI', sans-serif;
  --fuente-titulos: 'Barlow Semi Condensed', 'Barlow', system-ui, sans-serif;
}

* { box-sizing: border-box; }
html, body { margin: 0; }
body {
  background: var(--fondo);
  color: var(--tinta);
  font-family: var(--fuente);
  font-size: 15px;
  line-height: 1.45;
  font-variant-numeric: tabular-nums;
}
h1, h2, h3, h4 { font-family: var(--fuente-titulos); margin: 0; line-height: 1.2; font-weight: 600; }
h1 { font-size: 1.45rem; }
h2 { font-size: 1.2rem; }
h3 { font-size: 1.05rem; }
p { margin: 0 0 .6em; }
a { color: var(--latas); }
button, input, select { font: inherit; color: inherit; }
:focus-visible { outline: 2px solid var(--ambar); outline-offset: 2px; }
.oculto { display: none !important; }
.num { text-align: right; white-space: nowrap; }
.suave { color: var(--tinta-2); }
.tenue { color: var(--tinta-3); font-size: .88rem; }

/* ---------- Botones y campos ---------- */
.btn {
  display: inline-flex; align-items: center; gap: .4em;
  border: 1px solid var(--raya); background: var(--papel);
  padding: .45em .9em; border-radius: var(--radio); cursor: pointer;
  font-weight: 500; white-space: nowrap;
}
.btn:hover { border-color: var(--tinta-3); }
.btn:disabled { opacity: .5; cursor: not-allowed; }
.btn-principal { background: var(--tinta); color: #fff; border-color: var(--tinta); }
.btn-principal:hover { background: #2C3E43; }
.btn-ambar { background: var(--ambar); border-color: var(--ambar); color: #fff; font-weight: 600; }
.btn-ambar:hover { background: var(--ambar-oscuro); border-color: var(--ambar-oscuro); }
.btn-peligro { color: var(--rojo); }
.btn-peligro:hover { border-color: var(--rojo); }
.btn-mini { padding: .2em .55em; font-size: .85rem; }
.btn-enlace { border: 0; background: none; color: var(--latas); padding: 0; cursor: pointer; text-decoration: underline; }

input[type=text], input[type=password], input[type=number], select {
  border: 1px solid var(--raya); background: #fff; border-radius: 4px;
  padding: .35em .5em; min-width: 0;
}
input:focus, select:focus { border-color: var(--ambar); outline: none; box-shadow: 0 0 0 2px var(--ambar-claro); }
input.cifra { text-align: right; width: 9.5em; }
input.corto { width: 4.5em; text-align: right; }
input.error { border-color: var(--rojo); background: var(--rojo-claro); }
label.campo { display: flex; flex-direction: column; gap: .2em; font-size: .9rem; color: var(--tinta-2); }

/* ---------- Barra superior ---------- */
.barra {
  background: var(--tinta); color: #fff;
  display: flex; align-items: center; gap: 1.2rem; flex-wrap: wrap;
  padding: .7rem 1.4rem;
}
.barra .marca { display: flex; align-items: center; gap: .6rem; }
.barra .marca svg { flex: none; }
.barra h1 { font-size: 1.15rem; letter-spacing: .01em; }
.barra .equipo { color: #C9D3D1; font-size: .95rem; }
.barra .espacio { flex: 1; }
.barra .btn { background: transparent; color: #fff; border-color: rgba(255,255,255,.3); }
.barra .btn:hover { border-color: #fff; }
.barra .btn-ambar { background: var(--ambar); border-color: var(--ambar); }
.mes-actual { display: flex; align-items: baseline; gap: .5rem; }
.mes-actual strong { font-family: var(--fuente-titulos); font-size: 1.35rem; color: var(--ambar-claro); }
.mes-actual span { color: #C9D3D1; font-size: .9rem; }

.pestanas { display: flex; gap: .2rem; padding: 0 1.4rem; background: #DDE3E1; border-bottom: 1px solid var(--raya); }
.pestanas button {
  border: 0; background: none; padding: .65rem 1rem; cursor: pointer; font-weight: 500; color: var(--tinta-2);
  border-bottom: 3px solid transparent;
}
.pestanas button[aria-selected=true] { color: var(--tinta); border-bottom-color: var(--ambar); }

/* ---------- Estructura ---------- */
.principal { padding: 1.2rem 1.4rem 3rem; max-width: 1720px; margin: 0 auto; }
.rejilla {
  display: grid; gap: 1.1rem;
  grid-template-columns: minmax(270px, 320px) minmax(0, 1fr) minmax(290px, 340px);
  align-items: start;
}
.columna { display: flex; flex-direction: column; gap: 1.1rem; min-width: 0; }
.pegajosa { position: sticky; top: 1rem; }
@media (max-width: 1280px) {
  .rejilla { grid-template-columns: minmax(260px, 300px) minmax(0, 1fr); }
  .rejilla > .columna:last-child { grid-column: 1 / -1; }
  .pegajosa { position: static; }
}
@media (max-width: 820px) {
  .rejilla { grid-template-columns: 1fr; }
  .principal { padding: 1rem; }
  .barra { padding: .7rem 1rem; }
}

.panel { background: var(--papel); border: 1px solid var(--raya); border-radius: var(--radio); box-shadow: var(--sombra); }
.panel > header { display: flex; align-items: center; gap: .8rem; padding: .75rem 1rem; border-bottom: 1px solid var(--raya-suave); flex-wrap: wrap; }
.panel > header .espacio { flex: 1; }
.panel .cuerpo { padding: .8rem 1rem; }
.panel .cuerpo + .cuerpo { border-top: 1px solid var(--raya-suave); }
.panel.zona-fija { background: #F7F9F8; }
.panel.zona-fija > header h2::after { content: ' (datos de partida)'; font-weight: 500; font-size: .85rem; color: var(--tinta-3); font-family: var(--fuente); }

/* ---------- Tablas ---------- */
table { border-collapse: collapse; width: 100%; }
th, td { padding: .32em .45em; border-bottom: 1px solid var(--raya-suave); vertical-align: middle; }
th { text-align: left; font-weight: 600; color: var(--tinta-2); font-size: .85rem; }
th.num { text-align: right; }
tr:last-child td { border-bottom: 0; }
tfoot td { border-top: 1px solid var(--raya); font-weight: 600; }
.tabla-scroll { overflow-x: auto; }
.tabla-compacta td, .tabla-compacta th { padding: .25em .4em; font-size: .9rem; }
.tabla-compacta td:first-child, .formatos td:first-child, .nowrap { white-space: nowrap; }
.tabla-compacta th { vertical-align: bottom; }

/* ---------- Líneas de envasado ---------- */
.linea { border-left: 5px solid var(--color-linea, var(--tinta)); }
.linea[data-linea=latas] { --color-linea: var(--latas); }
.linea[data-linea=vidrio] { --color-linea: var(--vidrio); }
.linea[data-linea=barriles] { --color-linea: var(--barriles); }
.linea > header h2 { color: var(--color-linea); }

.segmentado { display: inline-flex; border: 1px solid var(--raya); border-radius: var(--radio); overflow: hidden; }
.segmentado button { border: 0; background: #fff; padding: .35em .8em; cursor: pointer; border-right: 1px solid var(--raya); min-width: 2.6em; }
.segmentado button:last-child { border-right: 0; }
.segmentado button[aria-pressed=true] { background: var(--color-linea, var(--tinta)); color: #fff; font-weight: 600; }

.controles-linea { display: flex; flex-wrap: wrap; gap: 1rem 1.6rem; align-items: flex-end; }
.controles-linea .grupo { display: flex; flex-direction: column; gap: .25rem; }
.controles-linea .grupo > span { font-size: .85rem; color: var(--tinta-2); }

.datos-linea { display: grid; grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); gap: .5rem 1rem; margin-top: .8rem; }
.dato { display: flex; flex-direction: column; }
.dato span { font-size: .82rem; color: var(--tinta-3); }
.dato strong { font-size: 1.02rem; font-weight: 600; }

/* Medidor de capacidad: un depósito que se llena de cerveza */
.deposito { margin-top: .9rem; }
.deposito .tubo { position: relative; height: 18px; background: #F1F3F2; border: 1px solid var(--raya); border-radius: 9px; overflow: hidden; }
.deposito .relleno {
  position: absolute; inset: 0 auto 0 0; width: 0;
  background: linear-gradient(180deg, #F2C65A 0%, var(--ambar) 55%, #B57A0C 100%);
  transition: width .35s ease;
}
.deposito .relleno::before { content: ''; position: absolute; inset: 0 0 auto 0; height: 4px; background: rgba(255,255,255,.75); }
.deposito.lleno .relleno { background: linear-gradient(180deg, #E07A66 0%, var(--rojo) 60%); }
.deposito .pie { display: flex; justify-content: space-between; font-size: .85rem; color: var(--tinta-2); margin-top: .25rem; }
@media (prefers-reduced-motion: reduce) { .deposito .relleno { transition: none; } }

.formatos td:first-child { font-weight: 500; }
.formatos .necesidad { color: var(--tinta-3); font-size: .85rem; }

/* ---------- Resultados ---------- */
.cuenta td { padding: .28em 0; }
.cuenta .grupo-cuenta td { padding-top: .6em; font-weight: 600; color: var(--tinta-2); font-size: .85rem; }
.cuenta .total td { border-top: 1px solid var(--raya); font-weight: 700; }
.beneficio { display: flex; justify-content: space-between; align-items: baseline; padding: .7rem 1rem; border-top: 1px solid var(--raya-suave); }
.beneficio strong { font-family: var(--fuente-titulos); font-size: 1.55rem; }
.positivo { color: var(--lupulo); }
.negativo { color: var(--rojo); }

.mensajes { display: flex; flex-direction: column; gap: .4rem; }
.mensaje { padding: .5em .7em; border-radius: 4px; font-size: .9rem; }
.mensaje.error { background: var(--rojo-claro); color: #7A2414; }
.mensaje.aviso { background: var(--ambar-claro); color: #6A4704; }
.mensaje.ok { background: var(--lupulo-claro); color: #2F4D1E; }

.aviso-banda { padding: .7rem 1rem; border-radius: var(--radio); background: var(--ambar-claro); color: #5E3F04; margin-bottom: 1rem; }
.aviso-banda.fin { background: var(--lupulo-claro); color: #2F4D1E; }

.chip { display: inline-block; padding: .05em .5em; border-radius: 99px; font-size: .8rem; background: var(--raya-suave); color: var(--tinta-2); }
.chip.latas { background: #DCEAF1; color: var(--latas); }
.chip.vidrio { background: var(--lupulo-claro); color: var(--vidrio); }
.chip.barriles { background: #F0E3D5; color: var(--barriles); }

/* ---------- Gráfico ---------- */
.grafico svg { width: 100%; height: auto; display: block; }
.grafico .eje { stroke: var(--raya); }
.grafico text { font-size: 11px; fill: var(--tinta-3); font-family: var(--fuente); }

/* ---------- Diálogos ---------- */
dialog { border: 1px solid var(--raya); border-radius: var(--radio); padding: 0; max-width: min(92vw, 980px); width: 100%; color: var(--tinta); }
dialog::backdrop { background: rgba(29, 42, 46, .45); }
dialog > header { display: flex; align-items: center; padding: .8rem 1rem; border-bottom: 1px solid var(--raya-suave); }
dialog > header h2 { flex: 1; }
dialog .cuerpo { padding: 1rem; max-height: 72vh; overflow: auto; }
dialog footer { display: flex; justify-content: flex-end; gap: .5rem; padding: .8rem 1rem; border-top: 1px solid var(--raya-suave); }

/* ---------- Acceso ---------- */
.acceso { min-height: 100vh; display: grid; grid-template-columns: 1.1fr 1fr; }
.acceso .lado-marca {
  background: var(--tinta); color: #fff; padding: 3rem; display: flex; flex-direction: column; justify-content: space-between;
  position: relative; overflow: hidden;
}
.acceso .lado-marca h1 { font-size: 2.4rem; max-width: 14ch; line-height: 1.08; }
.acceso .lado-marca p { color: #C9D3D1; max-width: 42ch; }
.acceso .lineas-deco { display: flex; gap: 1.2rem; align-items: flex-end; }
.acceso .lado-form { display: flex; align-items: center; justify-content: center; padding: 2rem; }
.acceso form { width: 100%; max-width: 340px; display: flex; flex-direction: column; gap: 1rem; }
.acceso form input { padding: .6em .7em; }
.acceso form .btn { justify-content: center; padding: .65em; }
@media (max-width: 760px) {
  .acceso { grid-template-columns: 1fr; }
  .acceso .lado-marca { padding: 2rem 1.4rem; min-height: auto; gap: 1.5rem; }
  .acceso .lado-marca h1 { font-size: 1.8rem; }
}

/* ---------- Profesor ---------- */
.rejilla-profesor { display: grid; grid-template-columns: 260px minmax(0, 1fr); gap: 1.1rem; align-items: start; }
@media (max-width: 860px) { .rejilla-profesor { grid-template-columns: 1fr; } }
.lista-grupos { list-style: none; margin: 0; padding: 0; }
.lista-grupos li button {
  width: 100%; text-align: left; border: 0; background: none; padding: .6rem 1rem; cursor: pointer;
  border-left: 3px solid transparent; display: flex; justify-content: space-between; gap: .5rem;
}
.lista-grupos li button[aria-current=true] { background: var(--ambar-claro); border-left-color: var(--ambar); font-weight: 600; }
.lista-grupos li + li button { border-top: 1px solid var(--raya-suave); }
.fila-form { display: flex; flex-wrap: wrap; gap: .6rem 1rem; align-items: flex-end; }
.params fieldset { border: 1px solid var(--raya-suave); border-radius: var(--radio); margin: 0 0 1rem; padding: .7rem 1rem 1rem; }
.params legend { font-family: var(--fuente-titulos); font-weight: 600; padding: 0 .3em; }
.params .rejilla-campos { display: grid; grid-template-columns: repeat(auto-fill, minmax(190px, 1fr)); gap: .7rem 1rem; }
.params input { width: 100%; }
.credenciales td { font-family: ui-monospace, 'SFMono-Regular', Consolas, monospace; }

.toast {
  position: fixed; bottom: 1.2rem; left: 50%; transform: translateX(-50%);
  background: var(--tinta); color: #fff; padding: .6rem 1rem; border-radius: var(--radio); z-index: 50; max-width: 90vw;
}

/* ---------- Gráfico de demanda y stock ---------- */
.grafico-demanda svg { width: 100%; height: auto; display: block; }
.grafico-demanda svg text { font-size: 11px; fill: var(--tinta-3); font-family: var(--fuente); }
.leyenda { display: flex; flex-wrap: wrap; gap: .3rem 1.1rem; font-size: .85rem; color: var(--tinta-2); margin-bottom: .4rem; }
.leyenda span { display: inline-flex; align-items: center; gap: .4rem; }
.leyenda i { display: inline-block; width: 18px; }
.leyenda i.punto { width: 9px; height: 9px; border-radius: 50%; }
.leyenda i.caja { width: 12px; height: 12px; border-radius: 3px; }
.leyenda i.rayada { background: repeating-linear-gradient(45deg, #C98A12 0 3px, rgba(201,138,18,.35) 3px 6px); }
.lienzo .tooltip {
  position: absolute; background: var(--papel); border: 1px solid var(--raya); border-radius: var(--radio);
  padding: .5rem .7rem; font-size: .85rem; min-width: 210px; box-shadow: 0 4px 14px rgba(29,42,46,.12); pointer-events: none;
}
.lienzo .tooltip div { display: flex; justify-content: space-between; gap: 1rem; }
.lienzo .tooltip span { color: var(--tinta-2); }
.ver-tabla { margin-top: .5rem; font-size: .9rem; }
.ver-tabla summary { cursor: pointer; color: var(--latas); }
.selector-producto { flex-wrap: wrap; }
.selector-producto button[aria-pressed=true] { background: var(--tinta); }

.formatos input.cifra { width: 7.6em; }
.formatos th, .formatos td { padding-left: .3em; padding-right: .3em; }
.formatos th { font-size: .82rem; vertical-align: bottom; }

/* ---------- Desglose de costes ---------- */
.desglose .plegar { border: 0; background: none; padding: 0; cursor: pointer; font: inherit; color: inherit; text-align: left; display: inline-flex; gap: .4em; align-items: baseline; }
.desglose .plegar::before { content: '▸'; color: var(--tinta-3); display: inline-block; width: .8em; transition: transform .15s; }
.desglose .plegar[aria-expanded=true]::before { transform: rotate(90deg); }
.desglose .sin-plegar { padding-left: 1.2em; }
.desglose tr.nivel0 td { font-weight: 600; }
.desglose tr.nivel0.subtotal td { background: var(--ambar-claro); }
.desglose tr.nivel1 td:first-child { padding-left: 1.6em; }
.desglose tr.nivel2 td:first-child { padding-left: 3.4em; color: var(--tinta-2); }
.desglose tr.nivel1 td, .desglose tr.nivel2 td { font-weight: 400; }
@media (prefers-reduced-motion: reduce) { .desglose .plegar::before { transition: none; } }
.formatos .cobertura { color: var(--tinta-2); font-size: .82rem; }
.detalle-mes { max-width: 1100px; }
.detalle-mes .desglose, .detalle-mes > p { max-width: 820px; }
.formatos input.cifra { width: 6.8em; }
.formatos th { font-size: .78rem; }
.detalle-mes > div > table { width: auto; }

.cuenta.desglose { width: 100%; }
.cuenta.desglose td { padding: .28em .2em; }
.cuenta.desglose tr.nivel1 td:first-child { padding-left: 1.4em; }
.cuenta.desglose tr.nivel2 td:first-child { padding-left: 2.8em; }
.cuenta.desglose tr.total-cuenta td { border-top: 2px solid var(--raya); font-weight: 700; }
.valoracion td .tenue { font-size: .78rem; }
.detalle-mes { white-space: normal; }
