* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
:root {
  --bg: #0f1419; --card: #1a2230; --line: #2a3550; --muted: #8a94a6;
  --txt: #e6e6e6; --green: #34d058; --red: #ff5b5b; --yellow: #f5c518; --blue: #8ab4ff;
  --appbar: 88px; --nav: 60px;
}
html, body { margin: 0; height: 100%; }
body {
  font-family: Segoe UI, system-ui, -apple-system, sans-serif;
  background: var(--bg); color: var(--txt);
  padding-top: var(--appbar); padding-bottom: var(--nav);
}

/* ===== Barra superior ===== */
.appbar {
  position: fixed; top: 0; left: 0; right: 0; z-index: 10;
  background: #1a2230; border-bottom: 1px solid var(--line);
  padding: env(safe-area-inset-top) 0 0 0;
}
.appbar-top { display: flex; align-items: center; justify-content: space-between; padding: 10px 16px 6px; }
.title { font-size: 18px; font-weight: 700; }
.status { display: flex; align-items: center; gap: 8px; }
.clock { font-size: 13px; color: var(--muted); font-variant-numeric: tabular-nums; }
.dot { width: 11px; height: 11px; border-radius: 50%; display: inline-block; }
.dot.on { background: var(--green); box-shadow: 0 0 7px var(--green); }
.dot.off { background: var(--red); }
.alarm { font-size: 13px; font-weight: 600; padding: 6px 16px; }
.alarm.ok    { background: #16331f; color: var(--green); }
.alarm.warn  { background: #3a3414; color: var(--yellow); }
.alarm.fault { background: #3a1616; color: #ff8a8a; animation: alarmblink 1s steps(1) infinite; }
@keyframes alarmblink { 50% { opacity: .55; } }

/* ===== Contenido ===== */
.content { padding: 14px; max-width: 720px; margin: 0 auto; }

/* ===== Navegacion inferior ===== */
.bottomnav {
  position: fixed; bottom: 0; left: 0; right: 0; z-index: 10;
  height: calc(var(--nav) + env(safe-area-inset-bottom));
  padding-bottom: env(safe-area-inset-bottom);
  display: flex; background: #1a2230; border-top: 1px solid var(--line);
}
.bottomnav button {
  flex: 1; background: none; border: none; color: var(--muted);
  font-size: 12px; display: flex; flex-direction: column; align-items: center;
  justify-content: center; gap: 3px; cursor: pointer; padding: 6px 2px;
}
.bottomnav button .ico { font-size: 18px; line-height: 1; }
.bottomnav button.active { color: var(--blue); }
.bottomnav button.active .ico { filter: drop-shadow(0 0 4px var(--blue)); }

/* ===== INDICE ===== */
.idx-card {
  background: var(--card); border: 1px solid var(--line); border-radius: 12px;
  padding: 18px; margin-bottom: 14px; display: flex; align-items: center;
  justify-content: space-between; cursor: pointer;
}
.idx-card:active { background: #222c3e; }
.idx-card .nm { font-size: 18px; font-weight: 700; }
.idx-card .lb { font-size: 13px; color: var(--muted); margin-top: 2px; }
.pill { font-size: 14px; font-weight: 700; padding: 7px 16px; border-radius: 20px; white-space: nowrap; }
.pill.run  { background: #16331f; color: var(--green); box-shadow: 0 0 10px rgba(52,208,88,.25); }
.pill.stop { background: #232c3a; color: var(--muted); }

/* ===== PANTALLA DE LINEA ===== */
.line-head { display: flex; align-items: center; gap: 10px; margin-bottom: 14px; }
.line-head .nm { font-size: 20px; font-weight: 700; }
.line-head .chip { font-size: 13px; background: #232c3a; color: var(--blue); padding: 3px 10px; border-radius: 12px; }
.flow { display: flex; flex-direction: column; align-items: center; gap: 0; }
.connector { color: var(--muted); font-size: 20px; line-height: 1; margin: 2px 0; }

/* Tarjeta de equipo */
.equip {
  position: relative; width: 100%; max-width: 360px;
  background: var(--card); border: 1px solid var(--line); border-radius: 12px;
  padding: 12px 14px; display: flex; align-items: center; gap: 14px;
}
.equip .sym-wrap { width: 84px; flex: 0 0 84px; display: flex; justify-content: center; }
.equip svg.sym { width: 100%; height: auto; max-height: 76px; }
.eq-info { flex: 1; min-width: 0; }
.eq-info .nm { font-size: 15px; font-weight: 600; }
.eqs { font-size: 12px; font-weight: 700; margin-top: 3px; display: inline-block; }
.eqs.on    { color: var(--green); fill: var(--green); }
.eqs.off   { color: var(--muted); fill: var(--muted); }
.eqs.fault { color: #ff8a8a;      fill: #ff8a8a; }
.eqs.man   { color: var(--yellow); fill: var(--yellow); }
.eqs.blq   { color: #e8a317;       fill: #e8a317; }

/* ===== SINOPTICO (diagrama de linea) ===== */
.mimic { position: relative; width: 100%; height: calc(100dvh - 205px); min-height: 320px; }
.diagram { width: 100%; height: 100%; display: block; touch-action: none; }
.zoomctl { position: absolute; top: 6px; right: 6px; z-index: 3; display: flex; flex-direction: column; gap: 6px; }
.zoomctl button {
  width: 40px; height: 40px; border-radius: 9px; background: rgba(26,34,48,.92);
  border: 1px solid var(--line); color: var(--txt); font-size: 22px; font-weight: 700;
  display: flex; align-items: center; justify-content: center; cursor: pointer;
}
.zoomctl button:active { background: #34416a; }
.diagram .edge { stroke: #4a5570; stroke-width: 3; fill: none; stroke-linecap: round; }
.diagram .eq-lbl { fill: #c4ccd8; font: 600 11px Segoe UI, sans-serif; }
.diagram .eqs { font: 700 10px Segoe UI, sans-serif; }
.tolva-bin { fill: none; stroke: var(--muted); stroke-width: 3; stroke-linejoin: round; }
.tolva-lbl { fill: var(--blue); font: 700 17px Segoe UI, sans-serif; }
.prod-lbl  { fill: var(--blue); font: 700 11px Segoe UI, sans-serif; }
.diagram .cv-lock { display: none; }
.diagram .equip.blocked .cv-lock { display: block; }
.diagram .cv-lock .lk-bd { fill: #e8a317; stroke: none; }
.diagram .cv-lock .lk-sh { fill: none; stroke: #e8a317; stroke-width: 2; }
.diagram .cv-man { display: none; }
.diagram .equip.manual .cv-man { display: block; }
.diagram .cv-man rect { fill: var(--yellow); }
.diagram .cv-man text { fill: #1a2230; font: 700 9px sans-serif; }

/* ===== PANEL DE MANDO (bottom sheet) ===== */
.sheet-backdrop { position: fixed; inset: 0; background: rgba(0,0,0,.55); z-index: 20; }
.sheet {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 21; max-width: 480px; margin: 0 auto;
  background: #1a2230; border-top: 1px solid var(--line); border-radius: 16px 16px 0 0;
  padding: 16px 16px calc(16px + env(safe-area-inset-bottom));
}
.sheet-hd { font-size: 17px; font-weight: 700; margin-bottom: 14px; }
.sheet-row { display: flex; justify-content: space-between; align-items: center; margin-bottom: 12px; gap: 10px; }
.sheet-row > span { color: var(--muted); font-size: 14px; }
.seg { display: flex; gap: 6px; }
.seg-btn {
  background: #232c3a; border: 1px solid var(--line); color: var(--txt);
  border-radius: 9px; padding: 10px 16px; font-size: 14px; font-weight: 700; cursor: pointer;
  transition: background .15s, color .15s, border-color .15s;
}
.seg-btn:active { filter: brightness(1.15); }
/* Colores por estado real de la variable */
.seg-btn.act.yellow { background: #f5c518; color: #1a2230; border-color: #f5c518; }
.seg-btn.act.lblue  { background: #3fb6ff; color: #0f1419; border-color: #3fb6ff; }
.seg-btn.act.green  { background: #2fbf4f; color: #0f1419; border-color: #2fbf4f; }
.seg-btn.act.red    { background: #ff5b5b; color: #0f1419; border-color: #ff5b5b; }
.seg-btn.act.dblue  { background: #1f3fb0; color: #ffffff; border-color: #3a5bd0; }
.sheet-msg { font-size: 13px; min-height: 18px; color: var(--muted); margin: 4px 0 8px; }
.sheet-msg.ok { color: var(--green); }
.sheet-msg.err { color: #ff8a8a; }
.sheet-close { width: 100%; background: #232c3a; border: 1px solid var(--line); color: var(--txt); border-radius: 10px; padding: 12px; font-size: 15px; cursor: pointer; }

/* Boton REARME (flotante) + aviso */
.rearme-fab {
  position: fixed; right: 14px; bottom: calc(var(--nav) + 16px + env(safe-area-inset-bottom)); z-index: 8;
  background: #1f5fd0; color: #fff; border: none; border-radius: 24px;
  padding: 12px 22px; font-size: 15px; font-weight: 700; letter-spacing: .5px;
  box-shadow: 0 4px 14px rgba(0,0,0,.45); cursor: pointer;
}
.rearme-fab:active { background: #2a6fe0; }
.toast {
  position: fixed; left: 50%; bottom: calc(var(--nav) + 76px); transform: translateX(-50%) translateY(10px);
  background: #0f1419; border: 1px solid var(--line); color: var(--txt);
  padding: 10px 16px; border-radius: 10px; font-size: 14px; z-index: 30;
  opacity: 0; transition: opacity .2s, transform .2s; pointer-events: none; white-space: nowrap;
}
.toast.show { opacity: 1; transform: translateX(-50%) translateY(0); }

/* Productos */
.products { display: flex; flex-wrap: wrap; justify-content: center; gap: 10px; margin-top: 12px; }
.product { display: flex; flex-direction: column; align-items: center; width: 64px; }
.product svg { width: 54px; height: auto; }
.product .pl { font-size: 12px; font-weight: 700; color: var(--blue); margin-top: 2px; }
.pile { fill: #9a8160; stroke: #6f5c43; stroke-width: 1.2; stroke-linejoin: round; }
.pile-st { fill: #7d6a4e; stroke: #574a38; stroke-width: 1; }

/* ===== SIMBOLOS: sistema de estados ===== */
/* Parado: gris */
.cv-frame      { fill: none; stroke: var(--muted); stroke-width: 4; stroke-linecap: round; stroke-linejoin: round; transition: stroke .3s; }
.cv-hub        { fill: var(--muted); transition: fill .3s; }
.cv-rotor-part { fill: none; stroke: var(--muted); stroke-width: 3; stroke-linecap: round; transition: stroke .3s; }
.cv-mesh       { fill: none; stroke: var(--muted); stroke-width: 2; stroke-dasharray: 3 4; transition: stroke .3s; }
.cv-belt       { fill: none; stroke: var(--muted); stroke-width: 3; stroke-dasharray: 6 8; transition: stroke .3s; }
.cv-leg        { fill: none; stroke: #6b7280; stroke-width: 3; stroke-linecap: round; stroke-linejoin: round; }
/* En marcha (Orden, sin averia): verde */
.equip.run .cv-frame, .equip.run .cv-rotor-part, .equip.run .cv-mesh, .equip.run .cv-belt { stroke: var(--green); }
.equip.run .cv-hub { fill: var(--green); }
.equip.run svg.sym { filter: drop-shadow(0 0 5px rgba(52,208,88,.4)); }
/* Averia (prioridad de color sobre marcha) + parpadeo */
.equip.fault .cv-frame, .equip.fault .cv-rotor-part, .equip.fault .cv-mesh, .equip.fault .cv-belt { stroke: var(--red); }
.equip.fault .cv-hub { fill: var(--red); }
.equip.fault svg.sym { filter: drop-shadow(0 0 6px rgba(255,80,80,.5)); animation: faultblink 1s steps(1, end) infinite; }
@keyframes faultblink { 50% { opacity: .5; } }
/* Manual: una parte (el nucleo) en amarillo */
.equip.manual .cv-hub { fill: var(--yellow); }
/* Movimiento (Orden, con o sin averia) */
.equip.moving .cv-rotor { animation: cvspin 2.4s linear infinite; }
.equip.moving .cv-screen { animation: cvshake .12s linear infinite; }
.equip.moving .cv-belt { animation: beltdash .6s linear infinite; }
.cv-rotor { transform-box: fill-box; transform-origin: center; }
@keyframes cvspin  { to { transform: rotate(360deg); } }
@keyframes cvshake { 0%,100% { transform: translate(0,0); } 25% { transform: translate(1px,-1px); } 75% { transform: translate(-1px,1px); } }
@keyframes beltdash { to { stroke-dashoffset: -14; } }
/* Cinta vertical: galones que bajan (flujo arriba->abajo) */
.cv-chev { fill: none; stroke: var(--muted); stroke-width: 3; stroke-linecap: round; stroke-linejoin: round; transition: stroke .3s; }
.equip.run .cv-chev   { stroke: var(--green); }
.equip.fault .cv-chev { stroke: var(--red); }
.equip.moving .cv-flowv { animation: flowdown .8s linear infinite; }
@keyframes flowdown { from { transform: translateY(0); } to { transform: translateY(24px); } }

/* Distintivos */
.badge-lock, .badge-manual { position: absolute; top: 6px; display: none; z-index: 2; }
.badge-lock { left: 6px; width: 18px; height: 18px; }
.badge-lock svg { width: 18px; height: 18px; }
.badge-lock .lk-bd { fill: #e8a317; stroke: none; }
.badge-lock .lk-sh { fill: none; stroke: #e8a317; stroke-width: 2; }
.badge-manual { right: 6px; background: var(--yellow); color: #1a2230; font-weight: 700; font-size: 10px; padding: 1px 6px; border-radius: 9px; }
.equip.blocked .badge-lock { display: block; }
.equip.manual  .badge-manual { display: block; }

@media (prefers-reduced-motion: reduce) {
  .equip.moving .cv-rotor, .equip.moving .cv-screen, .equip.moving .cv-belt,
  .equip.moving .cv-flowv, .equip.fault svg.sym, .alarm.fault { animation: none; }
}

/* Pantallas anchas: indice en rejilla */
@media (min-width: 640px) {
  .idx-grid { display: grid; grid-template-columns: 1fr 1fr 1fr; gap: 14px; }
  .idx-grid .idx-card { margin-bottom: 0; flex-direction: column; align-items: flex-start; gap: 14px; }
}
