/* ============================================================
   Live values widget — reusable; loaded globally so both
   /sites/:id and /sites/:id/live can host it.
   ============================================================ */

.live-widget { display: flex; flex-direction: column; }
.live-widget__host { min-height: 0; }

.table-wrap { overflow-x: auto; }
.table--compact th,
.table--compact td {
  padding: var(--space-1) var(--space-2);
  font-size: 0.875rem;
}
.font-mono { font-family: var(--font-mono); }

/* Toolbar — search + count, only shown once data is loaded. */
.live-toolbar {
  display: flex;
  align-items: center;
  gap: var(--space-3);
  margin-bottom: var(--space-2);
  flex-wrap: wrap;
}
.live-toolbar[hidden] { display: none; }
.live-toolbar__search {
  flex: 1 1 220px;
  display: inline-flex;
  align-items: center;
  gap: var(--space-2);
  padding: 4px var(--space-2);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-md, 6px);
  background: var(--color-surface, #fff);
  color: var(--color-text-muted);
}
.live-toolbar__search:focus-within {
  border-color: var(--color-primary, #3b82f6);
  color: var(--color-text);
}
.live-toolbar__search input {
  flex: 1;
  border: none;
  outline: none;
  background: transparent;
  font: inherit;
  color: var(--color-text);
  min-width: 0;
}
.live-toolbar__count {
  font-size: 0.8rem;
  color: var(--color-text-muted);
  font-variant-numeric: tabular-nums;
  white-space: nowrap;
}

/* Sticky header so columns stay visible while scrolling. */
.live-table thead th {
  position: sticky;
  top: 0;
  background: var(--color-surface, #fff);
  z-index: 1;
}
.live-table tbody tr {
  transition: background 0.4s ease;
}
.live-cell--adr {
  font-variant-numeric: tabular-nums;
  white-space: nowrap;
  font-weight: 500;
}
.live-cell--id code {
  font-size: 0.8rem;
  color: var(--color-text-muted);
}
.live-cell--name {
  font-weight: 500;
  max-width: 28ch;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.live-cell--val .font-mono {
  font-weight: 600;
  font-variant-numeric: tabular-nums;
}

/* Flash on value change: amber pulse 2 s, lingers a few seconds
   so the operator can still spot recent changes. */
@keyframes live-row-flash {
  0%   { background: var(--color-amber-100, #fef3c7); }
  60%  { background: var(--color-amber-50, #fffbeb); }
  100% { background: var(--color-amber-50, #fffbeb); }
}
.live-table tbody tr.live-row--changed {
  animation: live-row-flash 2s ease-out;
  background: var(--color-amber-50, #fffbeb);
}
.live-table tbody tr.live-row--changed .live-cell--val .font-mono {
  color: var(--color-amber-800, #92400e);
}

.live-pager {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: var(--space-1);
  margin-top: var(--space-3);
  flex-wrap: wrap;
}
/* Top pager: sits above the table, swap the spacing so the
   gap is below it (between pager and table). */
.live-pager:first-child {
  margin-top: 0;
  margin-bottom: var(--space-2);
}
/* Narrow phones: the info text + 4 buttons don't fit on one row,
   so let the info take its own line above the buttons. The four
   nav buttons stay on a single row, no orphan "last" button. */
@media (max-width: 480px) {
  .live-pager { gap: 4px; }
  .live-pager__info {
    order: -1;
    flex-basis: 100%;
    text-align: center;
    margin: 0 0 4px;
  }
}
.live-pager__info {
  margin: 0 var(--space-2);
  font-size: 0.85rem;
  color: var(--color-text-muted);
  font-variant-numeric: tabular-nums;
}

/* ------------------------------------------------------------
   Mobile / narrow viewport — compact card. Same data as desktop
   (Adresse, Nom, ID, Valeur, Unité, Type, MAJ) but laid out as
   tight label:value rows so the user reads top-to-bottom without
   side-scrolling.
   ------------------------------------------------------------ */
@media (max-width: 768px) {
  .live-table thead { display: none; }
  .live-table,
  .live-table tbody,
  .live-table tr,
  .live-table td { display: block; width: auto; }
  .live-table tr {
    border: 1px solid var(--color-border);
    border-radius: var(--radius-md, 8px);
    background: var(--color-surface, #fff);
    margin-bottom: 6px;
    padding: 8px 10px;
  }
  .live-table tr.live-row--changed {
    background: var(--color-amber-50, #fffbeb);
    border-color: var(--color-amber-300, #fcd34d);
  }
  .live-table td {
    display: flex;
    justify-content: space-between;
    align-items: baseline;
    gap: var(--space-2);
    padding: 1px 0;
    border: none;
    white-space: normal;
    font-size: 0.82rem;
  }
  .live-table td::before {
    content: attr(data-label);
    color: var(--color-text-muted);
    font-size: 0.65rem;
    text-transform: uppercase;
    letter-spacing: 0.04em;
    font-weight: 500;
    flex: 0 0 auto;
  }
  /* Nom — title-ish row spanning full width, slightly bigger. */
  .live-table td.live-cell--name {
    flex-direction: column;
    align-items: flex-start;
    gap: 0;
    font-weight: 600;
    font-size: 0.95rem;
    border-bottom: 1px dashed var(--color-border);
    padding-bottom: 4px;
    margin-bottom: 2px;
    max-width: none;
    white-space: normal;
    overflow: visible;
    text-overflow: clip;
  }
  .live-table td.live-cell--name::before {
    font-size: 0.6rem;
    margin-bottom: 1px;
  }
  /* Valeur — keep mono + a touch larger so the eye lands on it. */
  .live-table td.live-cell--val .font-mono {
    font-size: 1rem;
    font-weight: 700;
  }
  .live-table td.live-cell--id { font-family: var(--font-mono); }
  .live-table td.live-cell--id code { font-size: 0.78rem; }

  .site-live__title { font-size: 1.2rem; }
  .site-live__back { padding: 6px 0; }
  .live-toolbar { flex-direction: column; align-items: stretch; }
  .live-toolbar__search { flex: 1 1 auto; }
}

/* ============================================================
   Standalone /sites/:id/live page — minimal chrome, max table.
   ============================================================ */
.site-live {
  display: flex;
  flex-direction: column;
  gap: var(--space-3);
}
.site-live__header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--space-3);
  flex-wrap: wrap;
}
.site-live__title-block { min-width: 0; flex: 1 1 auto; }
.site-live__title {
  margin: 0;
  font-size: 1.4rem;
  line-height: 1.2;
  font-weight: 600;
}
.site-live__sub {
  margin: 2px 0 0;
  color: var(--color-text-muted);
  font-size: 0.85rem;
}
.site-live__sub code { font-family: var(--font-mono); font-size: 0.8rem; }
.site-live__back {
  font-size: 0.875rem;
  color: var(--color-text-muted);
  text-decoration: none;
  display: inline-flex;
  align-items: center;
  gap: var(--space-1);
}
.site-live__back:hover { color: var(--color-text); }

/* 4G signal — bars + textual fallback (sigbar / rsrpDbm). */
.site-live__signal {
  display: inline-flex;
  align-items: center;
  gap: var(--space-2);
  color: var(--color-text-muted);
  font-size: 0.85rem;
  font-variant-numeric: tabular-nums;
  white-space: nowrap;
}
.site-live__signal-rsrp { margin-left: var(--space-1); opacity: 0.8; }
.signal-bars {
  display: inline-flex;
  align-items: flex-end;
  gap: 2px;
  height: 16px;
}
.signal-bars__bar {
  display: block;
  width: 3px;
  background: var(--color-border);
  border-radius: 1px;
}
.signal-bars__bar:nth-child(1) { height: 4px; }
.signal-bars__bar:nth-child(2) { height: 7px; }
.signal-bars__bar:nth-child(3) { height: 10px; }
.signal-bars__bar:nth-child(4) { height: 13px; }
.signal-bars__bar:nth-child(5) { height: 16px; }
.signal-bars__bar--on { background: var(--color-green-600, #16a34a); }
