/* Laboratorio IoT — light, instrument-panel look.
   Series hues come from a validated categorical palette (teal / blue / amber);
   see app.js SERIES. Text never wears a series color. */

:root {
  --surface: #ffffff;
  --page: #f4f3f0;
  --page-2: #eceae5;
  --ink: #1b1a17;
  --ink-2: #57534b;
  --ink-3: #8a857b;
  --line: #e2dfd8;
  --line-soft: #efedE8;

  --teal: #00866c;
  --teal-soft: #d9ece7;
  --blue: #3f6fd8;
  --blue-soft: #dee6f9;
  --amber: #bd8a12;
  --amber-soft: #f5eAd2;
  --warn: #b4521f;
  --warn-soft: #f7e6dd;

  --radius: 14px;
  --shadow: 0 1px 2px rgba(27, 26, 23, .05), 0 8px 24px -12px rgba(27, 26, 23, .14);
  --sans: "Inter", "Segoe UI Variable Text", "Segoe UI", system-ui, -apple-system, "Helvetica Neue", Arial, sans-serif;
}

* { box-sizing: border-box; }

html { -webkit-text-size-adjust: 100%; }

body {
  margin: 0;
  font-family: var(--sans);
  background: var(--page);
  color: var(--ink);
  /* Tipografía deliberadamente grande: la página la usa gente mayor. */
  font-size: 17px;
  line-height: 1.55;
  -webkit-font-smoothing: antialiased;
}

h1, h2, h3 { margin: 0; font-weight: 600; letter-spacing: -.015em; }

/* ── Top bar ─────────────────────────────────────────────────────── */

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  flex-wrap: wrap;
  padding: 20px clamp(16px, 4vw, 40px);
  background: var(--surface);
  border-bottom: 1px solid var(--line);
}

.brand { display: flex; align-items: center; gap: 14px; }

.brand-mark {
  width: 34px; height: 34px; border-radius: 10px;
  background: var(--teal);
  position: relative; flex: none;
}
.brand-mark::after {
  content: ""; position: absolute; inset: 10px;
  border-radius: 50%; background: var(--surface);
}

.brand-text h1 { font-size: 17px; }
.brand-text p { margin: 0; font-size: 13px; color: var(--ink-3); }

.feed {
  display: flex; align-items: center; gap: 10px;
  padding: 8px 14px 8px 12px;
  background: var(--page-2);
  border-radius: 999px;
}
.feed-text { display: flex; flex-direction: column; line-height: 1.25; }
.feed-text strong { font-size: 13px; font-weight: 600; }
.feed-text span { font-size: 12px; color: var(--ink-3); }

.dot {
  width: 9px; height: 9px; border-radius: 50%;
  background: var(--ink-3); flex: none;
}
.feed.live .dot { background: var(--teal); animation: pulse 2.4s ease-out infinite; }
.feed.down .dot { background: var(--warn); }

@keyframes pulse {
  0%   { box-shadow: 0 0 0 0 rgba(0, 134, 108, .45); }
  70%  { box-shadow: 0 0 0 8px rgba(0, 134, 108, 0); }
  100% { box-shadow: 0 0 0 0 rgba(0, 134, 108, 0); }
}

/* ── Avisos de falla ─────────────────────────────────────────────── */

.alert-bar {
  display: flex; align-items: flex-start; gap: 14px;
  margin: 18px clamp(16px, 4vw, 40px) 0;
  padding: 16px 20px;
  background: var(--warn-soft);
  border: 1px solid #e6b9a0;
  border-left: 6px solid var(--warn);
  border-radius: 11px;
  color: #6b2d0d;
  font-size: 16px;
}
.alert-bar[hidden] { display: none; }
.alert-bar strong { display: block; font-size: 17px; }
.alert-icon {
  flex: none;
  width: 26px; height: 26px; border-radius: 50%;
  background: var(--warn); color: #fff;
  display: flex; align-items: center; justify-content: center;
  font-weight: 700;
}

.stale-notice {
  margin-top: 16px;
  padding: 14px 16px;
  background: var(--warn-soft);
  border-left: 6px solid var(--warn);
  border-radius: 9px;
  color: #6b2d0d;
  font-size: 15.5px;
}
.stale-notice[hidden] { display: none; }

/* La tarjeta con dato viejo se marca en el borde y el número se apaga, para que
   nadie lea un valor congelado como si fuera el de ahora. */
.card.is-stale { border-color: #e6b9a0; box-shadow: inset 5px 0 0 -1px var(--warn), var(--shadow); }
.card.is-stale .stat-value,
.card.is-stale .beacon-read strong { color: var(--ink-3); }

body.offline .card { opacity: .72; }

/* ── Selector de período ─────────────────────────────────────────── */

.ranges {
  display: flex;
  align-items: center;
  gap: 14px;
  flex-wrap: wrap;
  padding: 18px clamp(16px, 4vw, 40px) 0;
}
.ranges-label { font-size: 16px; font-weight: 600; color: var(--ink-2); }

.range-buttons { display: flex; flex-wrap: wrap; gap: 8px; }
.range-buttons button {
  font: inherit;
  font-size: 16px;
  font-weight: 500;
  /* Objetivos grandes: dedos poco precisos, pantallas táctiles. */
  padding: 11px 20px;
  min-height: 46px;
  border: 1px solid var(--line);
  border-radius: 999px;
  background: var(--surface);
  color: var(--ink-2);
  cursor: pointer;
  transition: background .15s ease, color .15s ease, border-color .15s ease;
}
.range-buttons button:hover { border-color: var(--ink-3); color: var(--ink); }
.range-buttons button.on {
  background: var(--teal);
  border-color: var(--teal);
  color: #fff;
  font-weight: 600;
}
.range-buttons button:focus-visible { outline: 3px solid var(--teal); outline-offset: 2px; }

/* ── Layout ──────────────────────────────────────────────────────── */

.grid {
  display: grid;
  /* min() keeps the track from exceeding the viewport on narrow phones,
     which would otherwise force the whole page to scroll sideways. */
  grid-template-columns: repeat(auto-fit, minmax(min(420px, 100%), 1fr));
  gap: clamp(16px, 2vw, 24px);
  padding: clamp(16px, 3vw, 32px) clamp(16px, 4vw, 40px);
  align-items: start;
  transition: opacity .2s ease;
}
.grid.refreshing { opacity: .55; }

.card {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: clamp(18px, 2.4vw, 26px);
}

.card-head {
  display: flex; justify-content: space-between; align-items: flex-start;
  gap: 16px; flex-wrap: wrap;
  padding-bottom: 18px;
  border-bottom: 1px solid var(--line-soft);
}
.card-head h2 { font-size: 18px; }
.sub { margin: 4px 0 0; font-size: 13px; color: var(--ink-3); }

.chip {
  display: inline-block;
  padding: 1px 7px;
  border-radius: 5px;
  background: var(--page-2);
  color: var(--ink-2);
  font-size: 12px;
}

.freshness { text-align: right; line-height: 1.3; }
.freshness strong { display: block; font-size: 15px; font-weight: 600; }
.freshness span { font-size: 12px; color: var(--ink-3); }
.freshness.stale strong { color: var(--warn); }

/* ── Stats ───────────────────────────────────────────────────────── */

.stat-row {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 20px;
  align-items: start;
  padding: 22px 0 18px;
}
/* El dispensador muestra un solo dato: la distancia cruda. */
#cardDispenser .stat-row { grid-template-columns: 1fr; }

.stat { min-width: 0; }
.stat-label {
  display: block;
  font-size: 12px; font-weight: 500;
  color: var(--ink-3);
  text-transform: uppercase; letter-spacing: .05em;
}

.stat-value {
  display: block;
  margin-top: 6px;
  font-size: clamp(38px, 6vw, 50px);
  font-weight: 600;
  line-height: 1.05;
  letter-spacing: -.03em;
  /* proportional figures on purpose — tabular-nums reads loose at this size */
}
.stat-value .unit {
  font-size: .34em; font-weight: 500;
  color: var(--ink-3); margin-left: 5px; letter-spacing: 0;
}
.stat-value.muted { color: var(--ink-3); }

.delta {
  display: block;
  margin-top: 6px;
  font-size: 13px;
  color: var(--ink-2);
  min-height: 20px;
}
.delta .up::before   { content: "▲ "; }
.delta .down::before { content: "▼ "; }
.delta .flat::before { content: "= "; }

/* Barras tipo celular: el indicador de señal que todo el mundo ya sabe leer. */
.bars { display: flex; align-items: flex-end; gap: 5px; height: 40px; }
.bars i {
  width: 12px; border-radius: 3px 3px 1px 1px;
  background: var(--page-2);
  transition: background .3s ease;
}
.bars i:nth-child(1) { height: 30%; }
.bars i:nth-child(2) { height: 48%; }
.bars i:nth-child(3) { height: 66%; }
.bars i:nth-child(4) { height: 83%; }
.bars i:nth-child(5) { height: 100%; }

/* ── Última lectura + beacons detectados ─────────────────────────── */

.last-read { padding: 22px 0 14px; }
.last-read h3 { font-size: 17px; }
.last-read-when { margin: 4px 0 0; font-size: 15px; color: var(--ink-3); }

.beacon-list { display: flex; flex-direction: column; gap: 16px; padding-bottom: 6px; }

.beacon {
  display: grid;
  grid-template-columns: 1fr auto auto;
  align-items: center;
  gap: 18px;
  padding: 12px 14px;
  background: var(--page);
  border-radius: 11px;
}
.beacon-name { display: flex; align-items: center; gap: 10px; font-weight: 600; font-size: 22px; }
.swatch { width: 13px; height: 13px; border-radius: 4px; flex: none; }

.beacon-read { text-align: right; line-height: 1.3; min-width: 104px; }
.beacon-read strong { display: block; font-size: 19px; font-weight: 600; }
.beacon-read span { font-size: 15px; color: var(--ink-2); }

.no-beacons {
  padding: 18px;
  background: var(--page);
  border-radius: 11px;
  color: var(--ink-2);
  font-size: 16px;
}
.dim { color: var(--ink-3); }

/* ── Meta + next report ──────────────────────────────────────────── */

.meta-row {
  display: flex; flex-wrap: wrap; gap: 10px;
  padding: 18px 0 0;
  margin-top: 14px;
  border-top: 1px solid var(--line-soft);
}
.meta {
  display: flex; flex-direction: column;
  padding: 10px 14px;
  background: var(--page);
  border-radius: 9px;
  min-width: 110px;
  flex: 1 1 auto;
}
.meta span { font-size: 14px; color: var(--ink-3); }
.meta strong { font-size: 19px; font-weight: 600; font-variant-numeric: tabular-nums; }

.next-report {
  margin-top: 12px;
  padding: 10px 14px;
  border-radius: 9px;
  background: var(--teal-soft);
  color: #0a4d3e;
  font-size: 13px;
}
.next-report.overdue { background: var(--warn-soft); color: #7a340f; }

/* ── Charts ──────────────────────────────────────────────────────── */

.chart-block { margin-top: 22px; }
.chart-head {
  display: flex; justify-content: space-between; align-items: baseline;
  gap: 12px; flex-wrap: wrap; margin-bottom: 4px;
}
.chart-head h3 { font-size: 14px; }
.chart-note { font-size: 12px; color: var(--ink-3); }

.legend { display: flex; flex-wrap: wrap; gap: 14px; margin: 8px 0 4px; }
.legend-item { display: flex; align-items: center; gap: 6px; font-size: 12.5px; color: var(--ink-2); }
.legend-key { width: 14px; height: 2px; border-radius: 2px; }

.chart { position: relative; width: 100%; }
.chart svg { display: block; width: 100%; height: auto; overflow: visible; }
.chart .empty {
  padding: 34px 0; text-align: center;
  color: var(--ink-3); font-size: 13px;
}

.ax-line { stroke: var(--line); stroke-width: 1; }        /* hairline, solid */
.ax-text { fill: var(--ink-3); font-size: 10.5px; font-variant-numeric: tabular-nums; }
.crosshair { stroke: var(--ink-3); stroke-width: 1; opacity: .5; }
.end-label { fill: var(--ink); font-size: 11.5px; font-weight: 600; }

.tip {
  position: absolute;
  pointer-events: none;
  background: var(--ink);
  color: #fff;
  padding: 7px 10px;
  border-radius: 8px;
  font-size: 12px;
  line-height: 1.45;
  white-space: nowrap;
  transform: translate(-50%, 0);
  opacity: 0;
  transition: opacity .12s ease;
  z-index: 5;
}
.tip.on { opacity: 1; }
.tip b { font-weight: 600; }
.tip .tip-t { color: #bdb9b0; display: block; font-size: 11px; margin-bottom: 2px; }
.tip .tip-k { display: inline-block; width: 8px; height: 8px; border-radius: 2px; margin-right: 5px; }

/* ── Table view ──────────────────────────────────────────────────── */

.table-block { margin-top: 18px; border-top: 1px solid var(--line-soft); padding-top: 12px; }
.table-block summary {
  cursor: pointer; font-size: 16px; font-weight: 500; color: var(--ink-2);
  display: flex; justify-content: space-between; align-items: center;
  list-style: none;
  padding: 10px 2px;
  min-height: 44px;
}
.table-block summary:focus-visible { outline: 3px solid var(--teal); outline-offset: 2px; }
.table-block summary::-webkit-details-marker { display: none; }
.table-block summary::before { content: "▸ "; color: var(--ink-3); }
.table-block[open] summary::before { content: "▾ "; }
.summary-hint { font-size: 11.5px; color: var(--ink-3); font-weight: 400; }

.table-scroll { overflow-x: auto; margin-top: 10px; max-height: 320px; overflow-y: auto; }

table { width: 100%; border-collapse: collapse; font-size: 15px; }
thead th {
  position: sticky; top: 0;
  background: var(--surface);
  text-align: left; font-weight: 500; font-size: 13px;
  color: var(--ink-3); text-transform: uppercase; letter-spacing: .04em;
  padding: 6px 10px 6px 0;
  border-bottom: 1px solid var(--line);
  white-space: nowrap;
}
tbody td {
  padding: 7px 10px 7px 0;
  border-bottom: 1px solid var(--line-soft);
  white-space: nowrap;
}
.num { text-align: right; font-variant-numeric: tabular-nums; }
tbody tr:last-child td { border-bottom: none; }

.tag { display: inline-flex; align-items: center; gap: 6px; }

/* ── Footer ──────────────────────────────────────────────────────── */

.foot {
  padding: 8px clamp(16px, 4vw, 40px) 40px;
  color: var(--ink-2);
  font-size: 12.5px;
}
.foot p { margin: 3px 0; }
.foot-dim { color: var(--ink-3); }

@media (max-width: 480px) {
  .stat-row, #cardTracker .stat-row { grid-template-columns: 1fr; }
  .stat-ring { text-align: left; }
  .ring-wrap { margin-left: 0; }
  .freshness { text-align: left; }
}

@media (prefers-reduced-motion: reduce) {
  * { animation: none !important; transition: none !important; }
}
