/* Tema claro fijo (a peticion del usuario), paleta inspirada en el ejemplo
   de referencia: fondo gris muy claro, tarjetas blancas, azul corporativo
   para las cifras, semaforo verde/ambar/naranja/rojo para los indicadores. */
:root {
  color-scheme: light;
  --page:           #f2f4f8;
  --surface-1:      #ffffff;
  --surface-2:      #ffffff;
  --panel-head-bg:  #eaf2ff;
  --text-primary:   #1c2331;
  --text-secondary: #5b6472;
  --text-muted:     #8a92a1;
  --gridline:       #eef1f6;
  --border:         #e3e7ee;
  --accent:         #1a56db;
  --accent-soft:    #e3edfe;
  --good:           #16a34a;
  --good-soft:      #dcfce7;
  --warning:        #d97706;
  --warning-soft:   #fef3c7;
  --serious:        #ea580c;
  --serious-soft:   #ffedd5;
  --critical:       #dc2626;
  --critical-soft:  #fee2e2;
  --neutral-fill:   #94a3b8;
}

* { box-sizing: border-box; }

html, body { height: 100%; }
body {
  margin: 0;
  font-family: system-ui, -apple-system, "Segoe UI", sans-serif;
  background: var(--page);
  color: var(--text-primary);
}

.wrap { max-width: 1280px; margin: 0 auto; }

/* Shell de la aplicacion: barra lateral colapsable + barra superior con el
   nombre del usuario -- aprovecha todo el ancho, el contenido ya no va en una
   columna centrada de anchura fija. Altura FIJA a la ventana (no min-height):
   la barra lateral tiene que quedarse siempre visible aunque la pagina tenga
   mucho contenido, es solo el panel de la derecha el que hace scroll. */
.app-shell { display: flex; height: 100vh; }

#sidebar {
  width: 176px;
  flex: 0 0 auto;
  height: 100vh;
  background: var(--surface-1);
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  transition: width 0.18s ease;
  overflow: hidden;
}
#sidebar.collapsed { width: 60px; }
#sidebar .brand {
  display: flex; align-items: center; justify-content: center; gap: 10px;
  padding: 16px 12px; white-space: nowrap;
  border-bottom: 1px solid var(--border);
}
/* Logo del cliente (BOLLO) -- grande y centrado, es lo primero que se ve del portal. */
#sidebar .brand img { max-height: 72px; max-width: 100%; display: block; margin: 0 auto; }
#sidebar.collapsed .brand img { max-height: 36px; }
/* Modo anonimo: el logo pixelado (logo-cliente.png) se pinta sin suavizar, o el
   navegador difumina los bloques al bajarlo a 72px y se vuelve a leer la marca.
   Colapsada se deja el suavizado normal: a 36px el punto a punto pica. La regla
   cuelga del nombre del fichero, asi no hace falta duplicar el flag en el CSS. */
#sidebar .brand img[src*="logo-cliente"] { image-rendering: pixelated; }
#sidebar.collapsed .brand img[src*="logo-cliente"] { image-rendering: auto; }
#sidebar nav { flex: 1; padding: 12px; display: flex; flex-direction: column; gap: 2px; }
#sidebar nav a {
  display: flex; align-items: center; padding: 10px 12px; border-radius: 8px;
  color: var(--text-secondary); text-decoration: none; font-size: 14px; font-weight: 600; white-space: nowrap;
}
#sidebar nav a:hover { background: #f3f6fb; color: var(--text-primary); }
#sidebar nav a.actual { background: var(--accent-soft); color: var(--accent); }
/* Colapsada: se ve la inicial en vez de la etiqueta completa, para que el
   enlace siga significando algo y no quede como una mancha de color vacia. */
#sidebar nav a .inicial { display: none; width: 100%; text-align: center; }
#sidebar.collapsed .label { display: none; }
#sidebar.collapsed nav a .inicial { display: block; }
#sidebar .toggle-btn {
  margin: 10px; align-self: flex-end; border: 1px solid var(--border); background: var(--surface-2);
  cursor: pointer; color: var(--text-muted); padding: 6px 10px; border-radius: 6px; font-size: 12px;
}
#sidebar .toggle-btn:hover { background: #f3f6fb; }

.app-main { flex: 1; min-width: 0; height: 100vh; display: flex; flex-direction: column; }
.topbar {
  display: flex; align-items: center; justify-content: flex-end; gap: 10px;
  padding: 10px 24px; border-bottom: 1px solid var(--border); background: var(--surface-1);
  flex: 0 0 auto;
}
.topbar .quien { font-size: 13px; color: var(--text-secondary); }
.topbar .quien #u-rol { text-transform: capitalize; }
.app-content { padding: 24px; flex: 1; min-width: 0; overflow-y: auto; }

/* Pie de pagina fijo (no se va con el scroll del contenido): logo de Enira,
   pequeno, abajo a la derecha -- el cliente es BOLLO, ese logo va grande
   arriba en la barra lateral (ver #sidebar .brand). */
.app-footer {
  flex: 0 0 auto; display: flex; justify-content: flex-end; align-items: center;
  padding: 6px 24px; border-top: 1px solid var(--border); background: var(--surface-1);
}
.app-footer img { max-height: 28px; display: block; opacity: 0.85; }
.app-footer .texto { font-size: 11px; color: var(--text-muted); }

.btn-simple {
  font: inherit; font-size: 13px; cursor: pointer; padding: 6px 14px; border-radius: 6px;
  border: 1px solid var(--border); background: var(--surface-2); color: var(--text-primary);
}
.btn-simple:hover { background: #f3f6fb; }

@media (max-width: 720px) {
  #sidebar { position: fixed; z-index: 40; height: 100vh; }
  #sidebar:not(.collapsed) { width: 176px; }
  #sidebar.collapsed { width: 0; border-right: none; }
}

header {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  flex-wrap: wrap;
  gap: 8px;
  margin-bottom: 20px;
}

h1 { font-size: 22px; margin: 0; font-weight: 700; color: var(--text-primary); }

.meta {
  font-size: 13px;
  color: var(--text-muted);
  display: flex;
  align-items: center;
  gap: 8px;
}

.dot {
  width: 8px; height: 8px; border-radius: 50%;
  background: var(--good);
  box-shadow: 0 0 0 3px rgba(22,163,74,0.18);
}
.dot.off { background: var(--critical); box-shadow: 0 0 0 3px rgba(220,38,38,0.18); }

.controls {
  display: flex;
  gap: 18px;
  flex-wrap: wrap;
  align-items: center;
  margin-bottom: 14px;
  padding: 8px 14px;
  background: var(--surface-1);
  border: 1px solid var(--border);
  border-radius: 10px;
  box-shadow: 0 1px 2px rgba(16,24,40,0.04);
}

.control-group { display: flex; align-items: center; gap: 8px; }
#cinta-group { padding-left: 14px; border-left: 1px solid var(--border); }
.control-group label {
  font-size: 11px; text-transform: uppercase; letter-spacing: .04em;
  color: var(--text-muted); font-weight: 600; white-space: nowrap;
}

.seg {
  display: flex;
  border: 1px solid var(--border);
  border-radius: 7px;
  overflow: hidden;
}
.seg button {
  border: none;
  background: var(--surface-2);
  color: var(--text-secondary);
  font-size: 12.5px;
  padding: 6px 12px;
  cursor: pointer;
  border-right: 1px solid var(--border);
  font-family: inherit;
}
.seg button:last-child { border-right: none; }
.seg button.active { background: var(--accent); color: #fff; font-weight: 600; }
.seg button:hover:not(.active) { background: #f3f6fb; }

.rate-input {
  display: flex;
  align-items: center;
  gap: 6px;
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 4px 10px;
}
.rate-input input {
  width: 60px;
  border: none;
  background: transparent;
  color: var(--text-primary);
  font-size: 14px;
  font-variant-numeric: tabular-nums;
  font-family: inherit;
}
.rate-input input:focus { outline: none; }
.rate-input span { font-size: 12px; color: var(--text-muted); white-space: nowrap; }
.rate-input.saved { box-shadow: 0 0 0 2px rgba(22,163,74,0.35); }

.range-input {
  display: flex;
  align-items: center;
  gap: 8px;
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 4px 10px;
}
.range-input input {
  border: none;
  background: transparent;
  color: var(--text-primary);
  font-size: 13px;
  font-family: inherit;
}
.range-input input:focus { outline: none; }
.range-input span { font-size: 12px; color: var(--text-muted); }

.tiles {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(170px, 1fr));
  gap: 12px;
  margin-bottom: 20px;
}

.tile {
  background: var(--surface-1);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 14px 16px;
  box-shadow: 0 1px 2px rgba(16,24,40,0.04);
}
.tile .label { font-size: 11px; text-transform: uppercase; letter-spacing: .04em; color: var(--text-muted); margin-bottom: 8px; font-weight: 600; }
.tile .value { font-size: 26px; font-weight: 700; font-variant-numeric: tabular-nums; line-height: 1.1; color: var(--accent); }
.tile .value .unit { font-size: 13px; font-weight: 500; color: var(--text-secondary); margin-left: 4px; }
.tile .sub { font-size: 11px; color: var(--text-muted); margin-top: 6px; }

.tile.oee .value { color: var(--accent); }
.tile.oee .breakdown {
  margin-top: 8px;
  display: flex;
  gap: 10px;
  font-size: 11px;
  color: var(--text-secondary);
}
.tile.oee .breakdown b { color: var(--text-primary); font-variant-numeric: tabular-nums; }

.panel {
  background: var(--surface-1);
  border: 1px solid var(--border);
  border-radius: 12px;
  overflow: hidden;
  margin-bottom: 20px;
  box-shadow: 0 1px 2px rgba(16,24,40,0.04);
}
.panel-head {
  padding: 14px 16px;
  border-bottom: 1px solid var(--border);
  background: var(--panel-head-bg);
}
.panel-head .title { font-size: 15px; font-weight: 700; color: var(--text-primary); }
.panel-head .sub { font-size: 12px; color: var(--text-secondary); margin-top: 2px; }

table { width: 100%; border-collapse: collapse; font-size: 13px; }
thead th {
  text-align: left;
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: .03em;
  color: var(--text-muted);
  font-weight: 700;
  padding: 10px 16px;
  border-bottom: 1px solid var(--gridline);
  white-space: nowrap;
}
tbody td {
  padding: 10px 16px;
  border-bottom: 1px solid var(--gridline);
  font-variant-numeric: tabular-nums;
  white-space: nowrap;
}
tbody tr:last-child td { border-bottom: none; }
tbody tr:hover td { background: #f7fafe; }
td.name { font-variant-numeric: normal; font-weight: 700; color: var(--accent); }
td.name .tagid { display: block; font-size: 11px; font-weight: 400; color: var(--text-muted); }
tr.sin-atribuir td.name { color: var(--text-muted); font-weight: 400; font-style: italic; }

.pill {
  display: inline-block;
  padding: 3px 12px;
  border-radius: 999px;
  font-size: 12px;
  font-weight: 700;
}
.pill.good { background: var(--good-soft); color: var(--good); }
.pill.warning { background: var(--warning-soft); color: var(--warning); }
.pill.serious { background: var(--serious-soft); color: var(--serious); }
.pill.critical { background: var(--critical-soft); color: var(--critical); }

.stat-text { font-weight: 600; }
.stat-text.good { color: var(--good); }
.stat-text.warning { color: var(--warning); }
.stat-text.serious { color: var(--serious); }
.stat-text.critical { color: var(--critical); }

.bar-cell { display: flex; align-items: center; gap: 8px; min-width: 140px; }
.bar-track {
  flex: 1;
  height: 8px;
  background: var(--gridline);
  border-radius: 999px;
  overflow: hidden;
  position: relative;
}
.bar-fill { height: 100%; border-radius: 999px; }
.bar-fill.good { background: var(--good); }
.bar-fill.warning { background: var(--warning); }
.bar-fill.serious { background: var(--serious); }
.bar-fill.critical { background: var(--critical); }
.bar-label { font-size: 12px; color: var(--text-secondary); width: 42px; text-align: right; font-weight: 600; }

.variance-chart { padding: 14px 16px; display: flex; flex-direction: column; gap: 10px; }
.vrow { display: flex; align-items: center; gap: 12px; }
.vname {
  width: 160px;
  flex-shrink: 0;
  font-size: 13px;
  font-weight: 600;
  color: var(--text-primary);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.vrow.sin-atribuir .vname { color: var(--text-muted); font-weight: 400; font-style: italic; }
.vbar-track {
  flex: 1;
  height: 14px;
  background: var(--gridline);
  border-radius: 4px;
  overflow: hidden;
}
.vbar-fill { height: 100%; border-radius: 4px; min-width: 4px; }
.vbar-fill.good { background: var(--good); }
.vbar-fill.warning { background: var(--warning); }
.vbar-fill.serious { background: var(--serious); }
.vbar-fill.critical { background: var(--critical); }
.vvalue {
  width: 44px;
  flex-shrink: 0;
  text-align: right;
  font-size: 13px;
  font-weight: 700;
  font-variant-numeric: tabular-nums;
  color: var(--text-primary);
}

.na { color: var(--text-muted); }

.footnote {
  font-size: 12px;
  color: var(--text-muted);
  padding: 12px 16px;
  line-height: 1.5;
}

.empty {
  padding: 32px;
  text-align: center;
  color: var(--text-muted);
  font-size: 13px;
}

.tabs {
  display: flex;
  gap: 4px;
  margin-bottom: 16px;
  border-bottom: 1px solid var(--border);
}
.tabs button {
  border: none;
  background: none;
  font-family: inherit;
  font-size: 14px;
  font-weight: 600;
  color: var(--text-secondary);
  padding: 10px 4px;
  margin-right: 20px;
  cursor: pointer;
  border-bottom: 2px solid transparent;
}
.tabs button:hover { color: var(--text-primary); }
.tabs button.active { color: var(--accent); border-bottom-color: var(--accent); }

/* Composicion atribuido / sin atribuir: donut de 2 segmentos + cifra central
   (con 2 categorias un donut es legible; con mas seria mejor una barra). */
.comp-wrap { padding: 16px; display: flex; align-items: center; gap: 28px; flex-wrap: wrap; }
.donut-svg { flex-shrink: 0; }
.donut-seg { fill: none; }
.donut-seg.donut-atrib { stroke: var(--accent); }
.donut-seg.donut-sin { stroke: var(--neutral-fill); }
.donut-center-value { font-size: 22px; font-weight: 700; fill: var(--text-primary); font-family: inherit; }
.donut-center-label { font-size: 10px; fill: var(--text-muted); font-family: inherit; text-transform: uppercase; letter-spacing: .03em; }
.comp-legend { display: flex; flex-direction: column; gap: 10px; }
.comp-key { display: flex; align-items: center; gap: 8px; font-size: 13px; color: var(--text-secondary); }
.comp-key b { color: var(--text-primary); font-variant-numeric: tabular-nums; }
.comp-swatch { width: 10px; height: 10px; border-radius: 3px; display: inline-block; }
.comp-swatch.comp-atrib { background: var(--accent); }
.comp-swatch.comp-sin { background: var(--neutral-fill); }

/* Grafico de evolucion (area + linea, serie unica -- sin leyenda, el titulo
   ya dice que se traza). */
#series-holder { padding: 6px 12px 8px; height: 190px; }
.series-svg { width: 100%; height: 100%; display: block; }
.chart-grid { stroke: var(--gridline); stroke-width: 1; }
.chart-tick { fill: var(--text-muted); font-size: 10px; font-family: inherit; }
.series-area { fill: color-mix(in srgb, var(--accent) 12%, transparent); stroke: none; }
.series-line { fill: none; stroke: var(--accent); stroke-width: 2; stroke-linejoin: round; stroke-linecap: round; }
.series-dot { fill: var(--accent); stroke: var(--surface-1); stroke-width: 2; }
.series-endlabel { fill: var(--text-primary); font-weight: 700; font-size: 12px; font-family: inherit; }

@media (max-width: 640px) {
  body { padding: 12px; }
  table { font-size: 12px; }
  thead th, tbody td { padding: 8px 10px; }
}
