/* =============================================================================
   public/css/alarms-popup.css — Popup de historial de alarmas
   F2R Engineering

   Mismo diseño general que los popups de parámetros: overlay con blur,
   tarjeta centrada por design tokens, válida en light y dark. Tabs en la
   cabecera para ACTIVAS / HISTÓRICO. Tablas compactas con tipografía
   tabular.
   ============================================================================= */

/* ── OVERLAY + CONTAINER ─────────────────────────────────────────────────── */
.aph-popup-overlay {
  position: fixed; inset: 0;
  background: rgba(0, 0, 0, 0.6);
  backdrop-filter: blur(4px);
  z-index: var(--z-overlay);
  animation: aph-fade-in var(--transition-base);
}
body.light-mode .aph-popup-overlay { background: rgba(15, 23, 42, 0.4); }
@keyframes aph-fade-in { from { opacity: 0; } to { opacity: 1; } }

.aph-popup {
  /* Centrado en el área DISPONIBLE bajo el header global (que mide
   * ~80-100 px y crece con --font-scale). Antes usábamos top:50% +
   * transform:translate(-50%,-50%), que centra contra el viewport
   * entero y dejaba la parte superior del popup oculta tras el header
   * en pantallas pequeñas o con font-scale alto. */
  position: fixed;
  inset: 90px 24px 24px 24px;
  margin: auto;
  /* 1500 px da espacio cómodo a las 9-10 columnas de la pestaña
     Estadísticas y evita que Categoría se monte sobre Estación. En
     pantallas <1500 px cae a calc(100vw - 48px) — para HMIs táctiles
     1280 px el popup ocupa casi toda la pantalla, que es lo deseado. */
  width:      min(1500px, calc(100vw - 48px));
  max-width:  min(1500px, calc(100vw - 48px));
  max-height: calc(100vh - 114px);
  background: var(--surface-raised);
  border: 1px solid var(--border-base);
  border-radius: var(--radius-xl);
  box-shadow: var(--shadow-xl);
  z-index: calc(var(--z-overlay) + 1);
  display: flex; flex-direction: column;
  overflow: hidden;
  animation: aph-pop-in 0.25s cubic-bezier(0.34, 1.4, 0.64, 1);
}
@keyframes aph-pop-in {
  from { transform: scale(0.92); opacity: 0; }
  to   { transform: scale(1);    opacity: 1; }
}

/* ── HEADER ─────────────────────────────────────────────────────────────── */
.aph-popup-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--space-3);
  padding: var(--space-4) var(--space-6);
  background: var(--surface-overlay);
  border-bottom: 1px solid var(--border-base);
}
.aph-popup-title-block { display: flex; flex-direction: column; gap: 2px; }
.aph-popup-title-lbl {
  font-size: var(--fs-sm);
  letter-spacing: 1.5px;
  color: var(--text-muted);
  text-transform: uppercase;
  font-weight: var(--fw-medium);
}
.aph-popup-title-text {
  font-size: var(--fs-lg);
  font-weight: var(--fw-bold);
  color: var(--text-primary);
}
.aph-popup-close {
  background: transparent;
  border: 1px solid var(--border-base);
  color: var(--text-secondary);
  width: 36px; height: 36px;
  border-radius: var(--radius-sm);
  cursor: pointer;
  display: inline-flex; align-items: center; justify-content: center;
  font-size: calc(20px * var(--font-scale));
  transition: background var(--transition-base), color var(--transition-base);
}
.aph-popup-close:hover { background: var(--surface-elevated); color: var(--text-primary); }

/* ── TABS ───────────────────────────────────────────────────────────────── */
.aph-tabs {
  display: flex;
  gap: 0;
  background: var(--surface-base);
  border-bottom: 1px solid var(--border-subtle);
  padding: 0 var(--space-4);
}
.aph-tab {
  display: inline-flex;
  align-items: center;
  gap: var(--space-2);
  padding: var(--space-3) var(--space-4);
  background: transparent;
  border: none;
  border-bottom: 2px solid transparent;
  color: var(--text-secondary);
  font-size: var(--fs-sm);
  font-weight: var(--fw-bold);
  letter-spacing: 0.8px;
  text-transform: uppercase;
  cursor: pointer;
  transition: color var(--transition-base), border-color var(--transition-base);
}
.aph-tab:hover { color: var(--text-primary); }
.aph-tab.is-active {
  color: var(--accent);
  border-bottom-color: var(--accent);
}
.aph-tab-count {
  display: inline-flex;
  align-items: center; justify-content: center;
  min-width: 22px; height: 22px; padding: 0 6px;
  border-radius: var(--radius-pill);
  background: var(--accent-soft);
  color: var(--accent);
  font-size: calc(11px * var(--font-scale)); font-weight: var(--fw-bold);
  font-variant-numeric: tabular-nums;
}

/* ── BODY ───────────────────────────────────────────────────────────────── */
.aph-body {
  flex: 1 1 auto;
  overflow: auto;
  padding: var(--space-4) var(--space-5);
}
.aph-empty {
  padding: var(--space-6) var(--space-4);
  text-align: center;
  color: var(--text-muted);
  font-size: var(--fs-sm);
}
.aph-empty.aph-error { color: var(--color-danger); }

/* ── TABLE ──────────────────────────────────────────────────────────────── */
.aph-table {
  width: 100%;
  border-collapse: collapse;
  font-size: var(--fs-sm);
  color: var(--text-primary);
  /* La columna de descripcion (aph-cell-text) usa slide-on-hover, que
     necesita overflow real. Sin table-layout:fixed la columna se
     estira con la descripcion y la animacion no tiene donde deslizar.
     Con fixed, el TD respeta su ancho asignado y el span interno
     puede ocultar el resto. */
  table-layout: fixed;
}
/* Con table-layout:fixed, el browser respeta los width SOLO de la
   primera fila (las TH). Las min-width en TD son IGNORADAS. Por eso
   asignamos width explícito a las TH vía nth-child por tabla — sin
   esto, con 9-10 columnas en la pestaña Estadísticas todas se reparten
   ~130 px y los timestamps + categorías colisionan con las celdas
   contiguas.

   La columna de descripción (la 4ª en todas las tablas) NO recibe
   width explícito: absorbe el resto del ancho disponible mediante
   table-layout:fixed (las columnas sin width se reparten el espacio
   sobrante).

   ── Pestaña ACTIVAS (5 cols): Estación · Categoría · ID · Texto · Hora */
.aph-table thead th:nth-child(1)     { width: 140px; }   /* Estación */
.aph-table thead th:nth-child(2)     { width: 150px; }   /* Categoría */
.aph-table thead th:nth-child(3)     { width: 70px;  }   /* ID */
/* th:nth-child(4) = Texto, sin width (absorbe el resto) */
.aph-table thead th:nth-child(5)     { width: 150px; }   /* Hora Activación */

/* ── Pestaña HISTÓRICO (8 cols): + Hora baja, Duración, Usuario */
.aph-table.aph-history-table thead th:nth-child(6)  { width: 150px; }  /* Hora baja */
.aph-table.aph-history-table thead th:nth-child(7)  { width: 110px; }  /* Duración */
.aph-table.aph-history-table thead th:nth-child(8)  { width: 130px; }  /* Usuario */

/* ── Pestaña ESTADÍSTICAS (9-10 cols): + Activaciones, Última, Últ.dur,
   Tiempo total, Última ACK [, Del] */
.aph-table.aph-stats-table thead th:nth-child(5)    { width: 100px; }  /* Activaciones */
.aph-table.aph-stats-table thead th:nth-child(6)    { width: 150px; }  /* Última */
.aph-table.aph-stats-table thead th:nth-child(7)    { width: 110px; }  /* Últ. duración */
.aph-table.aph-stats-table thead th:nth-child(8)    { width: 110px; }  /* Tiempo total */
.aph-table.aph-stats-table thead th:nth-child(9)    { width: 130px; }  /* Última ACK */
.aph-table.aph-stats-table thead th:nth-child(10)   { width: 40px;  }  /* Del (admin) */

/* Anti-overflow en las celdas para que el texto no rompa el ancho fijado
   por la TH. */
.aph-cell-time                       { white-space: nowrap; }
.aph-cell-duration                   { white-space: nowrap; }
/* Texto: el TD se trata como un contenedor "block-ish" para que la
   animacion slide-on-hover funcione. */
.aph-cell-text { color: var(--text-primary); overflow: hidden; }
.aph-cell-text .slide-on-hover {
  display: block;
  max-width: 100%;
  overflow: hidden;
}
.aph-table thead th {
  font-size: var(--fs-xs);
  text-transform: uppercase;
  letter-spacing: 0.8px;
  color: var(--text-muted);
  text-align: left;
  font-weight: var(--fw-medium);
  padding: var(--space-2) var(--space-3);
  background: var(--surface-overlay);
  border-bottom: 1px solid var(--border-subtle);
  position: sticky; top: 0;
}
.aph-table tbody td {
  padding: var(--space-2) var(--space-3);
  border-bottom: 1px solid var(--border-subtle);
  vertical-align: middle;
}
.aph-table tbody tr:last-child td { border-bottom: none; }
.aph-table tbody tr:hover { background: var(--surface-overlay); }

/* Como .aph-cell-text: el TD clipa, el span interno desliza al hover si
   el nombre completo no cabe. Sin overflow:hidden el "ST1 - Pre-form"
   sobresalía del ancho de columna y pisaba el badge de Categoría a su
   derecha. */
.aph-cell-station {
  font-weight: var(--fw-medium);
  overflow: hidden;
}
.aph-cell-station .slide-on-hover {
  display: block;
  max-width: 100%;
  overflow: hidden;
}

/* Badge de categoria: pill coloreado con el color de la categoria. La
   variable --aph-cat-color la inyecta el JS via inline style basandose
   en machine.config.yaml.alarmCategories[].color. Si la categoria es
   desconocida, el badge usa un gris neutro. */
.aph-cell-cat { white-space: nowrap; min-width: 110px; }
.aph-cat-badge {
  display: inline-block;
  padding: 2px 8px;
  border-radius: var(--radius-pill);
  font-size: 10px;
  font-weight: var(--fw-bold);
  text-transform: uppercase;
  letter-spacing: 0.5px;
  background: color-mix(in srgb, var(--aph-cat-color, var(--text-muted)) 14%, transparent);
  color: var(--aph-cat-color, var(--text-muted));
  border: 1px solid color-mix(in srgb, var(--aph-cat-color, var(--text-muted)) 35%, transparent);
}

.aph-cell-id {
  font-family: var(--font-tech);
  font-variant-numeric: tabular-nums;
  color: var(--text-muted);
  white-space: nowrap;
}
.aph-cell-time   {
  font-family: var(--font-tech);
  font-variant-numeric: tabular-nums;
  color: var(--text-secondary);
  white-space: nowrap;
}
.aph-cell-duration {
  font-family: var(--font-tech);
  font-variant-numeric: tabular-nums;
  color: var(--text-secondary);
  white-space: nowrap;
}

/* Fila marcada como reservada: tono atenuado (no debería estar activa) */
.aph-row.is-reserved {
  color: var(--text-muted);
  font-style: italic;
}
/* Histórico: una alarma sin cleared_at (open) se enmarca con acento. */
.aph-row.is-open { background: var(--color-danger-soft); }
.aph-row.is-open .aph-cell-text { color: var(--color-danger-strong, var(--color-danger)); }

/* ── FILTROS DEL HISTÓRICO ──────────────────────────────────────────────── */
.aph-filters {
  display: flex; gap: var(--space-3);
  align-items: end;
  padding: var(--space-3) 0;
  margin-bottom: var(--space-3);
  border-bottom: 1px solid var(--border-subtle);
  flex-wrap: wrap;
}
.aph-filter {
  display: flex; flex-direction: column;
  gap: 4px;
  font-size: var(--fs-xs);
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.5px;
}
.aph-filter select {
  font-family: var(--font-tech);
  background: var(--surface-overlay);
  border: 1px solid var(--border-base);
  border-radius: var(--radius-sm);
  padding: 4px 8px;
  color: var(--text-primary);
  font-size: var(--fs-sm);
}
.aph-filter select:focus { outline: none; border-color: var(--accent); }
.aph-btn {
  display: inline-flex; align-items: center; justify-content: center;
  padding: var(--space-2) var(--space-4);
  border-radius: var(--radius-sm);
  border: 1px solid var(--accent);
  background: var(--accent-soft);
  color: var(--accent);
  font-size: var(--fs-sm);
  font-weight: var(--fw-bold);
  text-transform: uppercase;
  letter-spacing: 0.5px;
  cursor: pointer;
  transition: background var(--transition-base);
}
.aph-btn:hover { background: var(--accent); color: var(--text-inverse, white); }

/* ── BADGE EN EL BANNER ─────────────────────────────────────────────────── */
/* El banner del header (#ALARM_BANNER) ya tiene su estilo. Cuando activamos
   `cursor:pointer` desde JS, marcamos visualmente que es clickable
   añadiendo un sutil hover sin invadir el diseño actual. */
.alarm-banner[role="button"] { transition: filter 0.15s ease; }
.alarm-banner[role="button"]:hover { filter: brightness(1.1); }

/* ── PANEL "ALARMAS" EN PRODUCCIÓN (sidebar de estación) ────────────────── */
/* Mismo layout que prod-station-params / prod-counters: tarjeta + botón
   ancho clickable que abre el AlarmsPopup pre-filtrado a la estación. */
.prod-alarms-panel { /* hereda layout del .panel base */ }
.prod-alarms-btn {
  width: 100%;
  display: flex;
  align-items: center;
  gap: var(--space-3);
  padding: var(--space-3) var(--space-4);
  background: var(--surface-overlay);
  border: 1px solid var(--border-base);
  border-radius: var(--radius-sm);
  cursor: pointer;
  color: var(--text-primary);
  text-align: left;
  transition: background var(--transition-base), border-color var(--transition-base);
}
.prod-alarms-btn:hover {
  background: var(--surface-elevated);
  border-color: var(--accent);
}
.prod-alarms-btn-icon {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 32px; height: 32px;
  border-radius: var(--radius-sm);
  background: var(--surface-base);
  color: var(--color-warning);
}
.prod-alarms-body {
  flex: 1 1 auto;
  display: flex;
  flex-direction: column;
  gap: 2px;
}
.prod-alarms-label {
  font-size: var(--fs-xs);
  letter-spacing: 1px;
  text-transform: uppercase;
  color: var(--text-muted);
  font-weight: var(--fw-medium);
}
.prod-alarms-count {
  font-family: var(--font-tech);
  font-variant-numeric: tabular-nums;
  font-size: var(--fs-xl);
  font-weight: var(--fw-bold);
  color: var(--text-primary);
  line-height: 1;
}
/* En cuanto hay >0 activas, el contador se pone en color de fault para
   que sea obvio que esa estación tiene alarmas vivas ahora mismo. */
.prod-alarms-count.has-active { color: var(--color-danger-strong, var(--color-danger)); }
.prod-alarms-meta {
  font-size: var(--fs-xs);
  color: var(--text-muted);
}
.prod-alarms-cta {
  margin-left: auto;
  font-size: var(--fs-sm);
  font-weight: var(--fw-bold);
  letter-spacing: 0.5px;
  color: var(--accent);
}

/* Botón "RESET" hold-to-set: hold-press = Reset=true, soltar = Reset=false.
   Aspecto de "acción destructiva pero recuperable": fondo warning suave,
   se pone más intenso mientras está pulsado. */
.prod-alarms-reset {
  margin-top: var(--space-2);
  width: 100%;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: var(--space-2);
  padding: var(--space-3) var(--space-4);
  background: var(--color-warning-soft);
  border: 1px solid var(--color-warning);
  border-radius: var(--radius-sm);
  color: var(--color-warning);
  font-size: var(--fs-sm);
  font-weight: var(--fw-bold);
  letter-spacing: 0.8px;
  text-transform: uppercase;
  cursor: pointer;
  user-select: none;
  transition: background var(--transition-base), color var(--transition-base);
}
.prod-alarms-reset:hover { background: var(--color-warning); color: var(--text-inverse, white); }
.prod-alarms-reset.is-pressed {
  background: var(--color-danger);
  border-color: var(--color-danger);
  color: var(--text-inverse, white);
  transform: scale(0.98);
}

/* ── ACK button + label en la pestaña Activas ──────────────────────────── */
.aph-cell-ack { white-space: nowrap; }
.aph-ack-btn {
  padding: 4px 12px;
  border-radius: var(--radius-sm);
  border: 1px solid var(--accent);
  background: var(--accent-soft);
  color: var(--accent);
  font-size: var(--fs-xs);
  font-weight: var(--fw-bold);
  letter-spacing: 0.6px;
  cursor: pointer;
  transition: background var(--transition-base), color var(--transition-base);
}
.aph-ack-btn:hover { background: var(--accent); color: var(--text-inverse, white); }
.aph-ack-btn[disabled] { opacity: 0.5; cursor: not-allowed; }
.aph-ack-label {
  font-size: var(--fs-xs);
  color: var(--color-success-strong, var(--color-success));
  font-weight: var(--fw-medium);
}
.aph-ack-disabled { color: var(--text-muted); }
.aph-row.is-acked { background: var(--color-success-soft); }
.aph-row.is-acked .aph-cell-text { color: var(--text-secondary); }

/* ── Pestaña Estadísticas ──────────────────────────────────────────────── */
.aph-stats-toolbar {
  display: flex; gap: var(--space-3);
  align-items: center;
  padding: var(--space-3) 0;
  border-bottom: 1px solid var(--border-subtle);
  margin-bottom: var(--space-3);
}
.aph-search {
  flex: 1 1 auto;
  background: var(--surface-overlay);
  border: 1px solid var(--border-base);
  border-radius: var(--radius-sm);
  padding: 6px 10px;
  color: var(--text-primary);
  font-size: var(--fs-sm);
  font-family: var(--font-tech);
}
.aph-search:focus { outline: none; border-color: var(--accent); }
.aph-cell-num {
  font-family: var(--font-tech);
  font-variant-numeric: tabular-nums;
  text-align: right;
  font-weight: var(--fw-bold);
}
.aph-stats-table .aph-row.is-active-now {
  background: var(--color-danger-soft);
}
.aph-stats-table .aph-row.is-active-now .aph-cell-text {
  color: var(--color-danger-strong, var(--color-danger));
  font-weight: var(--fw-medium);
}

/* ── Admin bar + row delete button ─────────────────────────────────────── */
.aph-admin-bar {
  display: flex; align-items: center; gap: var(--space-3);
  padding: var(--space-2) var(--space-3);
  margin-bottom: var(--space-3);
  background: var(--color-danger-soft);
  border: 1px dashed var(--color-danger);
  border-radius: var(--radius-sm);
}
.aph-admin-label {
  font-size: var(--fs-xs);
  font-weight: var(--fw-bold);
  letter-spacing: 1.5px;
  color: var(--color-danger-strong, var(--color-danger));
}
.aph-btn-danger {
  border-color: var(--color-danger);
  background: var(--surface-base);
  color: var(--color-danger);
}
.aph-btn-danger:hover {
  background: var(--color-danger);
  color: var(--text-inverse, white);
}
.aph-row-del {
  display: inline-flex;
  width: 22px; height: 22px;
  align-items: center; justify-content: center;
  border-radius: var(--radius-sm);
  border: 1px solid transparent;
  background: transparent;
  color: var(--text-muted);
  cursor: pointer;
  font-size: calc(16px * var(--font-scale)); line-height: 1;
  transition: background var(--transition-base), color var(--transition-base);
}
.aph-row-del:hover {
  background: var(--color-danger-soft);
  color: var(--color-danger);
  border-color: var(--color-danger);
}
.aph-cell-del { width: 28px; text-align: center; }
