/* ============================================================
   Site detail (P4) — dense header + 2-column ops grid.
   Mobile-first; collapses to single column under 960 px.
   ============================================================ */

.site-show {
  display: flex;
  flex-direction: column;
  gap: var(--space-4);
}

/* ------------------------------------------------------------
   Header
   ------------------------------------------------------------ */
.site-show__header {
  padding: var(--space-4) var(--space-5);
  background: var(--color-surface, #fff);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-lg, 12px);
  display: flex;
  flex-direction: column;
  gap: var(--space-3);
}

.site-show__header-top {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--space-3);
  flex-wrap: wrap;
}
.site-show__header-actions {
  display: inline-flex;
  align-items: center;
  gap: var(--space-3);
  flex-wrap: wrap;
}
.site-show__back {
  font-size: 0.875rem;
  color: var(--color-text-muted);
  text-decoration: none;
  display: inline-flex;
  align-items: center;
  gap: var(--space-1);
}
.site-show__back:hover { color: var(--color-text); }

.site-show__header-main {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: var(--space-3);
  flex-wrap: wrap;
}
.site-show__title-block { min-width: 0; }
.site-show__title {
  margin: 0;
  font-size: 1.75rem;
  line-height: 1.15;
  font-weight: 600;
}
.site-show__sub {
  margin: var(--space-1) 0 0;
  color: var(--color-text-muted);
  font-size: 0.9rem;
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: var(--space-1);
}
.site-show__sub code { font-family: var(--font-mono); font-size: 0.85rem; }
.site-show__sep { color: var(--color-border); }

.site-show__no-hw {
  margin: 0;
  color: var(--color-text-muted);
  font-style: italic;
}

/* Key facts strip — block per fact (label above, value below). */
.site-show__facts {
  display: flex;
  flex-wrap: wrap;
  gap: var(--space-3) 56px;
  margin: 0;
  padding-top: var(--space-3);
  border-top: 1px solid var(--color-border);
}
.site-show__facts > div {
  display: flex;
  flex-direction: column;
  gap: 2px;
  min-width: 0;
}
.site-show__facts dt {
  font-size: 0.7rem;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--color-text-muted);
  font-weight: 500;
}
.site-show__facts dd {
  margin: 0;
  font-weight: 500;
  font-size: 0.95rem;
  overflow-wrap: anywhere;
}
.site-show__facts dd code { font-family: var(--font-mono); font-size: 0.85rem; }

/* Health block embedded in the header (pellets + gauges). */
.site-show__health {
  padding-top: var(--space-3);
  border-top: 1px solid var(--color-border);
  display: flex;
  flex-direction: column;
  gap: var(--space-2);
}
.site-show__health-row {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: var(--space-2);
  flex-wrap: wrap;
}
.site-show__health-title {
  margin: 0;
  font-size: 0.8rem;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--color-text-muted);
  font-weight: 600;
}

/* ------------------------------------------------------------
   Health badge (header)
   ------------------------------------------------------------ */
.badge {
  display: inline-flex;
  align-items: center;
  gap: var(--space-1);
  padding: 4px var(--space-2);
  border-radius: 999px;
  font-size: 0.85rem;
  font-weight: 500;
  white-space: nowrap;
}
.badge__dot {
  width: 8px; height: 8px; border-radius: 50%;
  background: currentColor;
}
.badge--ok    { background: var(--color-green-50, #ecfdf5); color: var(--color-green-800, #065f46); }
.badge--warn  { background: var(--color-amber-50, #fffbeb); color: var(--color-amber-800, #92400e); }
.badge--down  { background: var(--color-red-50, #fef2f2); color: var(--color-red-800, #991b1b); }

/* ------------------------------------------------------------
   2-column grid
   ------------------------------------------------------------ */
.site-show__grid {
  display: grid;
  grid-template-columns: minmax(0, 1fr);
  gap: var(--space-4);
}
.site-show__col { display: flex; flex-direction: column; gap: var(--space-4); min-width: 0; }

@media (min-width: 960px) {
  .site-show__grid {
    grid-template-columns: minmax(0, 3fr) minmax(0, 2fr);
  }
  /* Match the live widget height to the side column (Exports + Modbus). */
  .site-show__col--main > .live-widget { flex: 1 1 auto; min-height: 0; }
}

/* ------------------------------------------------------------
   Cards
   ------------------------------------------------------------ */
.site-show__card { padding: var(--space-4); }

.card__header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--space-3);
  margin-bottom: var(--space-3);
  flex-wrap: wrap;
}
.card__title { margin: 0; font-size: 1.05rem; font-weight: 600; }
.card__actions { display: inline-flex; align-items: center; gap: var(--space-2); }
.card__hint { font-size: 0.85rem; color: var(--color-text-muted); }
.card__empty {
  margin: 0;
  padding: var(--space-3) 0;
  color: var(--color-text-muted);
  font-style: italic;
}

/* ------------------------------------------------------------
   Stats — unified tile for both boolean indicators and metrics
   ------------------------------------------------------------ */
.stats {
  list-style: none;
  margin: 0;
  padding: 0;
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(150px, 1fr));
  gap: var(--space-2);
}
.stat {
  padding: var(--space-2) var(--space-3);
  border-radius: var(--radius-md, 8px);
  background: var(--color-surface-alt, #f9fafb);
  border: 1px solid var(--color-border);
  display: flex;
  flex-direction: column;
  gap: 4px;
  min-width: 0;
}
.stat__head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--space-2);
}
.stat__name {
  font-size: 0.72rem;
  color: var(--color-text-muted);
  text-transform: uppercase;
  letter-spacing: 0.05em;
  font-weight: 600;
}
.stat__dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--color-border);
  flex: 0 0 auto;
}
.stat__value {
  font-weight: 600;
  font-size: 1rem;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.stat__bar {
  margin-top: 2px;
  height: 5px;
  border-radius: 999px;
  background: var(--color-border);
  overflow: hidden;
}
.stat__bar > span {
  display: block;
  height: 100%;
  background: var(--color-primary, #3b82f6);
  transition: width 0.3s ease;
}

.stat--ok   { border-color: var(--color-green-100, #d1fae5); }
.stat--ok   .stat__dot { background: var(--color-green-600, #16a34a); }
.stat--ok   .stat__bar > span { background: var(--color-green-600, #16a34a); }

.stat--warn { border-color: var(--color-amber-100, #fef3c7); background: var(--color-amber-50, #fffbeb); }
.stat--warn .stat__dot { background: var(--color-amber-500, #f59e0b); }
.stat--warn .stat__bar > span { background: var(--color-amber-500, #f59e0b); }

.stat--down { border-color: var(--color-red-100, #fee2e2); background: var(--color-red-50, #fef2f2); }
.stat--down .stat__dot { background: var(--color-red-600, #dc2626); }
.stat--down .stat__bar > span { background: var(--color-red-600, #dc2626); }

.stat--muted .stat__dot { background: var(--color-border); }

/* ------------------------------------------------------------
   Live + exports tables
   ------------------------------------------------------------ */
.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); }

/* Live values 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;
}

/* Live table — sticky header so the columns stay visible inside
   the page while scrolling a long-ish current page. */
.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--val .font-mono {
  font-weight: 600;
  font-variant-numeric: tabular-nums;
}

/* Flash: amber pulse for two seconds, then a softer tint that
   lingers for a few more seconds so the operator can still spot
   recent changes after the initial blink. */
@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);
}

/* Pager */
.live-pager {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: var(--space-1);
  margin-top: var(--space-3);
  flex-wrap: wrap;
}
.live-pager__info {
  margin: 0 var(--space-2);
  font-size: 0.85rem;
  color: var(--color-text-muted);
  font-variant-numeric: tabular-nums;
}

/* Export calendar — daily presence map.
   Green : received (clickable), orange : pending today, red : missing past day. */
.export-cal {
  display: flex;
  flex-direction: column;
  gap: 6px;
  max-width: 320px;
  margin: 0 auto;
  width: 100%;
}
.export-cal__nav {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--space-1);
}
.export-cal__title {
  font-weight: 600;
  font-size: 0.85rem;
  text-transform: capitalize;
  font-variant-numeric: tabular-nums;
}
.export-cal__weekdays {
  display: grid;
  grid-template-columns: repeat(7, 1fr);
  gap: 3px;
  font-size: 0.62rem;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: var(--color-text-muted);
  text-align: center;
  font-weight: 600;
}
.export-cal__weekday { padding: 1px 0; }
.export-cal__grid {
  display: grid;
  grid-template-columns: repeat(7, 1fr);
  gap: 3px;
}
.export-cal__cell {
  position: relative;
  aspect-ratio: 1 / 1;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: 4px;
  border: 1px solid transparent;
  font-size: 0.72rem;
  font-weight: 500;
  font-variant-numeric: tabular-nums;
  text-decoration: none;
  color: var(--color-text);
  background: var(--color-surface-alt, #f9fafb);
}
.export-cal__day {
  line-height: 1;
}
.export-cal__cell--blank { background: transparent; border-color: transparent; }
.export-cal__cell--mute {
  color: var(--color-text-muted);
  background: transparent;
}
.export-cal__cell--ok {
  background: var(--color-green-50, #ecfdf5);
  color: var(--color-green-800, #065f46);
  border-color: var(--color-green-100, #d1fae5);
  cursor: pointer;
  transition: background 0.15s ease, transform 0.05s ease;
}
.export-cal__cell--ok:hover {
  background: var(--color-green-100, #d1fae5);
  text-decoration: none;
}
.export-cal__cell--ok:hover .export-cal__day { opacity: 0; }
.export-cal__cell--ok:hover .export-cal__dl  { opacity: 1; }
.export-cal__cell--ok:active { transform: scale(0.94); }
.export-cal__dl {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 0.75rem;
  color: var(--color-green-800, #065f46);
  opacity: 0;
  transition: opacity 0.12s ease;
  pointer-events: none;
}
/* Persistent download hint at top-right of received cells (subtle). */
.export-cal__cell--ok::after {
  content: "";
  position: absolute;
  top: 2px;
  right: 2px;
  width: 4px;
  height: 4px;
  border-radius: 50%;
  background: var(--color-green-600, #16a34a);
  opacity: 0.7;
}
.export-cal__cell--ok:hover::after { opacity: 0; }
.export-cal__cell--warn {
  background: var(--color-amber-50, #fffbeb);
  color: var(--color-amber-800, #92400e);
  border-color: var(--color-amber-100, #fef3c7);
}
.export-cal__cell--down {
  background: var(--color-red-50, #fef2f2);
  color: var(--color-red-800, #991b1b);
  border-color: var(--color-red-100, #fee2e2);
}
.export-cal__legend {
  display: flex;
  flex-wrap: wrap;
  gap: var(--space-2);
  font-size: 0.68rem;
  color: var(--color-text-muted);
  align-items: center;
  margin-top: 2px;
}
.export-cal__chip {
  display: inline-block;
  width: 8px;
  height: 8px;
  border-radius: 2px;
  margin-right: 3px;
  vertical-align: middle;
}
.export-cal__chip--ok   { background: var(--color-green-600, #16a34a); }
.export-cal__chip--warn { background: var(--color-amber-500, #f59e0b); }
.export-cal__chip--down { background: var(--color-red-600, #dc2626); }

/* ------------------------------------------------------------
   Modbus actions
   ------------------------------------------------------------ */
.site-show__modbus-actions {
  display: flex;
  flex-wrap: wrap;
  gap: var(--space-2);
  margin-bottom: var(--space-3);
}
.site-show__modbus-meta {
  font-size: 0.85rem;
  color: var(--color-text-muted);
}
.site-show__modbus-meta span { color: var(--color-text); font-weight: 500; }

/* ------------------------------------------------------------
   Viewer toggle
   ------------------------------------------------------------ */
.site-show__viewer-help {
  margin: 0 0 var(--space-3);
  font-size: 0.9rem;
  color: var(--color-text-muted);
}
.site-show__viewer {
  display: flex;
  align-items: center;
  gap: var(--space-3);
  flex-wrap: wrap;
}
.site-show__viewer-link {
  display: inline-flex;
  align-items: center;
  gap: var(--space-2);
  padding: var(--space-1) var(--space-2);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-md, 6px);
  background: var(--color-surface-alt, transparent);
}
.site-show__viewer-link code {
  font-family: var(--font-mono);
  font-size: 0.875rem;
}
.site-show__viewer-link[hidden] { display: none; }

/* Switch — accessible toggle built on a checkbox input. */
.switch {
  display: inline-flex;
  align-items: center;
  gap: var(--space-2);
  cursor: pointer;
  user-select: none;
}
.switch input { position: absolute; opacity: 0; pointer-events: none; }
.switch__slider {
  width: 40px;
  height: 22px;
  border-radius: 999px;
  background: var(--color-border);
  position: relative;
  transition: background 0.2s ease;
}
.switch__slider::after {
  content: "";
  position: absolute;
  top: 2px;
  left: 2px;
  width: 18px;
  height: 18px;
  border-radius: 50%;
  background: #fff;
  transition: transform 0.2s ease;
  box-shadow: 0 1px 2px rgba(0, 0, 0, 0.15);
}
.switch input:checked + .switch__slider { background: var(--color-primary); }
.switch input:checked + .switch__slider::after { transform: translateX(18px); }
.switch__label { font-size: 0.9rem; }

/* ------------------------------------------------------------
   Inline alerts (import preview modal)
   ------------------------------------------------------------ */
.alert {
  margin: 0 0 var(--space-3);
  padding: var(--space-2) var(--space-3);
  border-radius: var(--radius-md, 6px);
  font-size: 0.875rem;
}
.alert ul { margin: var(--space-1) 0 0; padding-left: var(--space-4); }
.alert--warn  { background: var(--color-blue-50); color: var(--color-text); }
.alert--error { background: var(--color-red-50); color: var(--color-red-800); }

.modal--wide { max-width: min(880px, 96vw); }

/* ------------------------------------------------------------
   Box logs (admin only)
   ------------------------------------------------------------ */
.logs {
  display: flex;
  flex-direction: column;
  gap: var(--space-1);
}
.logs__row {
  border: 1px solid var(--color-border);
  border-radius: var(--radius-md, 6px);
  background: var(--color-surface, #fff);
}
.logs__row[open] { border-color: var(--color-primary, #2563eb); }
.logs__row--flat { padding: var(--space-2) var(--space-3); }
.logs__summary {
  display: grid;
  grid-template-columns: 110px 1fr auto;
  align-items: center;
  gap: var(--space-3);
  padding: var(--space-2) var(--space-3);
  cursor: pointer;
  font-size: 0.875rem;
  list-style: none;
}
.logs__row--flat .logs__summary { padding: 0; cursor: default; }
.logs__summary::-webkit-details-marker { display: none; }
.logs__when { color: var(--color-text-muted); font-variant-numeric: tabular-nums; }
.logs__action { font-weight: 500; }
.logs__pre {
  margin: 0;
  padding: var(--space-2) var(--space-3);
  border-top: 1px solid var(--color-border);
  background: var(--color-bg-subtle, #f9fafb);
  font-size: 0.8125rem;
  font-family: var(--font-mono, ui-monospace, monospace);
  white-space: pre-wrap;
  word-break: break-word;
  max-height: 240px;
  overflow: auto;
}
.logs__pre--err { color: var(--color-red-800, #991b1b); background: var(--color-red-50, #fef2f2); }
.logs__more {
  margin-top: var(--space-3);
  display: flex;
  justify-content: center;
}
