/* Viewer publico IoT — estilo minimal, sin dependencias. */
:root {
  --bg: #f7f9fb;
  --fg: #0f172a;
  --muted: #64748b;
  --border: #e2e8f0;
  --card: #ffffff;
  --accent: #0891b2;
  --ok: #16a34a;
  --warn: #d97706;
  --stale: #dc2626;
  --shadow: 0 1px 3px rgba(0,0,0,0.05);
}

* { box-sizing: border-box; }

body {
  margin: 0;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  background: var(--bg);
  color: var(--fg);
  line-height: 1.5;
}

.topbar {
  display: flex;
  align-items: center;
  gap: 1rem;
  padding: 0.75rem 1.5rem;
  background: var(--card);
  border-bottom: 1px solid var(--border);
}
.topbar h1 {
  font-size: 1.15rem;
  margin: 0;
  font-weight: 600;
}
.env-pill {
  font-size: 0.75rem;
  color: var(--muted);
  background: #f1f5f9;
  padding: 0.15rem 0.5rem;
  border-radius: 999px;
}

.layout {
  display: grid;
  grid-template-columns: 280px 1fr;
  min-height: calc(100vh - 110px);
}
@media (max-width: 720px) {
  .layout { grid-template-columns: 1fr; }
}

.sidebar {
  padding: 1rem;
  border-right: 1px solid var(--border);
  background: var(--card);
}
.sidebar h2 {
  font-size: 0.85rem;
  margin: 0 0 0.5rem;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--muted);
}

.device-list {
  list-style: none;
  padding: 0;
  margin: 0 0 1rem;
}
.device-list li {
  padding: 0.6rem 0.5rem;
  border-radius: 6px;
  cursor: pointer;
  display: flex;
  align-items: center;
  gap: 0.5rem;
  margin-bottom: 0.25rem;
}
.device-list li:hover { background: #f1f5f9; }
.device-list li.active { background: #e0f2fe; }
.device-list li.empty { color: var(--muted); cursor: default; }

.dot {
  width: 0.5rem;
  height: 0.5rem;
  border-radius: 50%;
  flex-shrink: 0;
}
.dot.ok { background: var(--ok); }
.dot.warn { background: var(--warn); }
.dot.stale { background: var(--stale); }
.dot.unknown { background: var(--muted); }

.legend {
  font-size: 0.7rem;
  color: var(--muted);
  display: flex;
  flex-direction: column;
  gap: 0.25rem;
  margin-top: 1rem;
}
.legend .badge {
  display: inline-block;
  width: 0.6rem;
  height: 0.6rem;
  border-radius: 50%;
  margin-right: 0.3rem;
}
.badge-ok { background: var(--ok); }
.badge-warn { background: var(--warn); }
.badge-stale { background: var(--stale); }

.content { padding: 1.5rem; }
.placeholder { color: var(--muted); }

.summary-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(160px, 1fr));
  gap: 0.75rem;
  margin-bottom: 1.5rem;
}
.card {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 0.75rem 1rem;
  box-shadow: var(--shadow);
}
.card .label {
  font-size: 0.7rem;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--muted);
}
.card .value {
  font-size: 1.4rem;
  font-weight: 600;
  margin-top: 0.25rem;
}
.card .sub {
  font-size: 0.75rem;
  color: var(--muted);
  margin-top: 0.15rem;
}

.image-block {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 0.75rem;
  margin-bottom: 1.5rem;
  box-shadow: var(--shadow);
}
.image-block h3 {
  font-size: 0.9rem;
  margin: 0 0 0.5rem;
  color: var(--muted);
  font-weight: 600;
}
.image-block img {
  max-width: 100%;
  border-radius: 4px;
  background: #f1f5f9;
}

table.readings {
  width: 100%;
  border-collapse: collapse;
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: 8px;
  overflow: hidden;
  box-shadow: var(--shadow);
}
table.readings th, table.readings td {
  padding: 0.5rem 0.75rem;
  text-align: left;
  border-bottom: 1px solid var(--border);
  font-size: 0.85rem;
}
table.readings thead { background: #f8fafc; }
table.readings tr:last-child td { border-bottom: none; }
table.readings td.num { font-variant-numeric: tabular-nums; }

.quality {
  display: inline-block;
  font-size: 0.7rem;
  padding: 0.1rem 0.5rem;
  border-radius: 999px;
  background: #f1f5f9;
  color: var(--muted);
}
.quality.q-accepted_initial,
.quality.q-accepted_validated { background: #dcfce7; color: #166534; }
.quality.q-ocr_error,
.quality.q-invalid_value,
.quality.q-invalid_negative,
.quality.q-negative_delta,
.quality.q-raw_processed_mismatch,
.quality.q-rejected { background: #fee2e2; color: #991b1b; }

.footer {
  padding: 0.75rem 1.5rem;
  border-top: 1px solid var(--border);
  color: var(--muted);
  background: var(--card);
}

/* Boton "Ver" en la columna Imagen */
.btn-image {
  font-size: 0.75rem;
  padding: 0.2rem 0.6rem;
  border: 1px solid var(--accent);
  color: var(--accent);
  background: transparent;
  border-radius: 6px;
  cursor: pointer;
  transition: background 0.15s, color 0.15s;
}
.btn-image:hover { background: var(--accent); color: #fff; }
.no-image { color: var(--muted); }

/* Modal de imagen */
.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(15, 23, 42, 0.6);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 1rem;
  z-index: 1000;
}
.modal-box {
  background: var(--card);
  border-radius: 10px;
  max-width: min(90vw, 720px);
  max-height: 90vh;
  display: flex;
  flex-direction: column;
  overflow: hidden;
  box-shadow: 0 10px 40px rgba(0,0,0,0.3);
}
.modal-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  padding: 0.6rem 1rem;
  border-bottom: 1px solid var(--border);
}
.modal-title { font-size: 0.85rem; font-weight: 600; }
.modal-close {
  border: none;
  background: transparent;
  font-size: 1rem;
  cursor: pointer;
  color: var(--muted);
  line-height: 1;
  padding: 0.2rem 0.4rem;
}
.modal-close:hover { color: var(--fg); }
.modal-body {
  padding: 0.75rem;
  overflow: auto;
  display: flex;
  justify-content: center;
}
.modal-body img {
  max-width: 100%;
  max-height: 78vh;
  border-radius: 4px;
  background: #f1f5f9;
}
.modal-error { color: var(--stale); font-size: 0.85rem; }
