/* =========================================================
   ThingsBit · Dashboard — sistema de diseño
   Tokens según DISENO-THINGSBIT.md. Solo --accent cambia por cliente (fase 2).
   ========================================================= */
:root {
  --accent: #4AA1F2;           /* se sobrescribe por cuenta */

  --bg: #FAFAFB;               /* fondo de la app */
  --surface: #FFFFFF;          /* tarjetas, barra lateral */
  --surface-muted: #F4F5F7;    /* fondo de controles segmentados */
  --surface-active: #F1F2F4;   /* ítem de menú activo, pistas de barras */
  --border: #ECEDF0;           /* borde de tarjetas y controles */
  --divider: #F1F2F4;          /* líneas entre filas */
  --grid-dot: #E3E5E9;         /* trama de puntos de los gráficos */

  --ink: #111111;              /* texto principal, botón primario, tarjeta destacada */
  --text-2: #4B5563;           /* texto secundario */
  --text-3: #6B7280;           /* etiquetas mono y metadatos (gris más claro permitido para texto) */
  --text-4: #9CA3AF;           /* unidades sobre fondo oscuro */
  --decimals: #B8BCC4;         /* decimales atenuados */
  --neutral: #C9CCD3;          /* estado inactivo; texto secundario sobre negro */
  --danger: #B42318;           /* agregado: solo mensajes de error y acciones destructivas */

  --font: Inter, system-ui, sans-serif;
  --mono: 'JetBrains Mono', ui-monospace, monospace;

  --r-card: 14px; --r-ctrl: 10px; --r-sm: 7px;
  --pad-card: 20px; --pad-card-lg: 24px; --gap: 16px;
  --shadow-pop: 0 6px 20px rgba(17,17,17,.06);

  /* Nombres antiguos que todavía usan los widgets: apuntan a los tokens nuevos */
  --panel: var(--surface); --panel-2: var(--surface-active); --line: var(--border);
  --muted: var(--text-3); --signal: var(--accent); --signal-dim: var(--neutral); --warn: var(--danger);
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body { margin: 0; background: var(--bg); color: var(--ink); font-family: var(--font); font-size: 14px; line-height: 1.5; }
a { color: var(--ink); }
a:hover { color: var(--text-2); }
button { font: inherit; cursor: pointer; }
h1, h2, h3, p { margin: 0; }
h1 { font-size: 28px; font-weight: 600; letter-spacing: -.02em; line-height: 1.2; }
h2 { font-size: 16px; font-weight: 600; }
h3 { font-size: 14px; font-weight: 600; }
:focus-visible { outline: 2px solid var(--ink); outline-offset: 2px; }
.sr-only { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }

/* ---------- Tipografía utilitaria ---------- */
.eyebrow { font-family: var(--mono); font-size: 11px; font-weight: 500; letter-spacing: .08em; text-transform: uppercase; color: var(--text-3); text-decoration: none; }
a.eyebrow:hover { color: var(--ink); }
.mono, code { font-family: var(--mono); }
.meta { font-family: var(--mono); font-size: 12px; color: var(--text-3); }
.label { font-size: 13px; color: var(--text-2); }
.hint { font-size: 13px; color: var(--text-2); }
.big { font-size: 34px; font-weight: 600; letter-spacing: -.03em; }
.big-xl { font-size: 40px; font-weight: 600; letter-spacing: -.03em; }
.dec { color: var(--decimals); }
.unit { font-size: 16px; color: var(--text-3); margin-left: 4px; }

/* ---------- Layout: barra lateral + contenido a todo el ancho ---------- */
.app { min-height: 100vh; display: flex; flex-wrap: wrap; }
.sidebar { flex: 1 1 232px; max-width: 100%; background: var(--surface); border-right: 1px solid var(--border);
  padding: 24px 16px; display: flex; flex-direction: column; gap: 28px; }
.main { flex: 999 1 560px; min-width: 0; padding: 28px 40px 48px; display: flex; flex-direction: column; gap: 24px; }
/* En escritorio la barra lateral queda fija a la altura de la ventana: el pie (acento y plan) siempre visible */
@media (min-width: 801px) {
  .sidebar { position: sticky; top: 0; height: 100vh; overflow-y: auto; }
}
@media (max-width: 800px) {
  .main { padding: 20px; }
  .sidebar { border-right: 0; border-bottom: 1px solid var(--border); padding: 16px; gap: 16px; }
  .sidebar-foot { display: none; }
  .span-2 { grid-column: auto !important; }
}

.brand { display: flex; align-items: center; gap: 10px; padding: 0 8px; font-weight: 700; font-size: 18px; letter-spacing: -.02em;
  color: var(--ink); text-decoration: none; }
.brand-dot { width: 10px; height: 10px; border-radius: 50%; background: var(--accent); flex: none; }

.nav { display: flex; flex-direction: column; gap: 2px; }
.nav a { display: flex; align-items: center; gap: 12px; min-height: 40px; padding: 0 10px; border-radius: var(--r-ctrl);
  text-decoration: none; color: var(--text-2); }
.nav a:hover { color: var(--ink); background: var(--surface-muted); }
.nav a.active { background: var(--surface-active); color: var(--ink); font-weight: 600; }
.nav svg { width: 18px; height: 18px; flex: none; }
@media (max-width: 800px) {
  .nav { flex-direction: row; flex-wrap: wrap; }
  .nav a { min-height: 36px; padding: 0 10px; }
}

.sidebar-foot { margin-top: auto; display: flex; flex-direction: column; gap: 20px; }
.plan { border: 1px solid var(--border); border-radius: 12px; padding: 14px; display: flex; flex-direction: column; gap: 12px; }
.plan-head { display: flex; justify-content: space-between; align-items: baseline; }
.plan-head strong { font-size: 13px; text-transform: capitalize; }
.meter-row { display: flex; justify-content: space-between; font-size: 12px; color: var(--text-2); }
.meter { height: 4px; background: var(--surface-active); border-radius: 4px; overflow: hidden; }
.meter > div { height: 4px; border-radius: 4px; background: var(--accent); }

/* Selector del color de acento (solo owner) */
.accent-picker { display: flex; flex-direction: column; gap: 10px; padding: 0 8px; }
.swatches { display: flex; gap: 8px; flex-wrap: wrap; }
.swatch { width: 28px; height: 28px; border-radius: 50%; padding: 0; margin: 0; border: 2px solid var(--surface);
  box-shadow: 0 0 0 1px var(--grid-dot); cursor: pointer; position: relative; }
.swatch[aria-pressed="true"] { box-shadow: 0 0 0 2px var(--ink); }
.swatch-custom { display: grid; place-items: center; overflow: hidden;
  background: conic-gradient(#FF7142, #FFD24D, #A1D76A, #4AA1F2, #995AB5, #FF7142); }
.swatch-custom input { position: absolute; inset: 0; width: 100%; height: 100%; min-height: 0; opacity: 0; cursor: pointer; border: 0; padding: 0; }
.swatch:focus-within, .swatch:focus-visible { outline: 2px solid var(--ink); outline-offset: 2px; }
.accent-picker .msg { margin: 0; min-height: 0; font-size: 12px; }

/* ---------- Encabezado de página ---------- */
.page-head { display: flex; flex-wrap: wrap; gap: 16px; align-items: flex-end; justify-content: space-between; }
.page-head .titles { display: flex; flex-direction: column; gap: 6px; min-width: 0; }
.page-head .title-row { display: flex; flex-wrap: wrap; align-items: center; gap: 12px; }
.actions { display: flex; flex-wrap: wrap; gap: 10px; align-items: center; }
.search { display: flex; align-items: center; gap: 8px; height: 44px; padding: 0 14px; background: var(--surface);
  border: 1px solid var(--border); border-radius: var(--r-ctrl); color: var(--text-3); min-width: 240px; }
.search svg { width: 16px; height: 16px; flex: none; }
.search input { border: 0; outline: none; background: transparent; font: inherit; color: var(--ink); flex: 1; min-width: 0; height: 100%; padding: 0; }
@media (max-width: 800px) { .search { min-width: 0; flex: 1 1 200px; } }

/* Avatar con menú de cuenta */
.account-menu { position: relative; }
.account-menu summary { list-style: none; }
.account-menu summary::-webkit-details-marker { display: none; }
.avatar { width: 44px; height: 44px; border-radius: 50%; border: 1px solid var(--border); background: var(--surface);
  font-weight: 600; font-size: 13px; display: grid; place-items: center; cursor: pointer; user-select: none; }
.account-menu[open] .avatar { border-color: var(--ink); }
.menu-pop { position: absolute; right: 0; top: 52px; z-index: 50; min-width: 220px; background: var(--surface);
  border: 1px solid var(--border); border-radius: var(--r-ctrl); box-shadow: var(--shadow-pop); padding: 6px; }
.menu-pop .who { padding: 8px 10px 10px; border-bottom: 1px solid var(--divider); margin-bottom: 4px; }
.menu-pop .who b { display: block; font-size: 13px; font-weight: 600; overflow-wrap: anywhere; }
.menu-pop a, .menu-pop button { display: flex; width: 100%; align-items: center; min-height: 40px; padding: 0 10px; border: 0;
  background: none; border-radius: var(--r-sm); text-decoration: none; color: var(--text-2); font-size: 14px; text-align: left; }
.menu-pop a:hover, .menu-pop button:hover { background: var(--surface-muted); color: var(--ink); }
.menu-pop form { margin: 0; }

/* ---------- Botones ---------- */
.btn, .btn-ghost, .btn-primary, .btn-solid {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px; height: 44px; padding: 0 18px;
  border-radius: var(--r-ctrl); font-weight: 500; font-size: 14px; text-decoration: none; white-space: nowrap;
  border: 1px solid var(--border); background: var(--surface); color: var(--ink); }
.btn:hover, .btn-ghost:hover { border-color: var(--neutral); color: var(--ink); }
.btn-primary, .btn-solid { border-color: var(--ink); background: var(--ink); color: #fff; }
.btn-primary:hover, .btn-solid:hover { background: #2A2A2A; color: #fff; }
.btn-sm { height: 36px; padding: 0 12px; font-size: 13px; }
.btn-danger { color: var(--danger); }
.btn-danger:hover { border-color: var(--danger); color: var(--danger); }
.btn-primary.btn-danger-solid { background: var(--danger); border-color: var(--danger); }
.btn-primary.btn-danger-solid:hover { background: #8F1B12; }
.btn-ghost.on { border-color: var(--ink); }
.btn-link { background: none; border: 0; padding: 0; font-size: 13px; color: var(--danger); text-decoration: underline; text-underline-offset: 3px; }
.btn-link.ok { color: var(--ink); }
.btn-link:hover { color: var(--ink); }
button:disabled { opacity: .5; cursor: not-allowed; }

/* ---------- Formularios ---------- */
label { display: block; font-size: 13px; color: var(--text-2); margin: 16px 0 6px; }
input, select, textarea {
  width: 100%; min-height: 44px; padding: 0 14px; font: inherit; font-size: 14px; color: var(--ink);
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--r-ctrl); }
textarea { padding: 10px 14px; }
input:focus, select:focus, textarea:focus { outline: none; border-color: var(--ink); }
input[readonly] { background: var(--surface-muted); color: var(--text-2); }
input[type=checkbox], input[type=radio] { width: auto; min-height: 0; padding: 0; accent-color: var(--ink); }
select.mini, input.mini { min-height: 36px; width: auto; padding: 0 10px; font-size: 13px; }
.msg { margin-top: 12px; font-size: 13px; min-height: 18px; color: var(--text-2); }
.msg:empty { margin-top: 0; min-height: 0; }
.msg.error { color: var(--danger); }
.msg.ok { color: var(--ink); }
.form-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(180px, 1fr)); gap: 0 14px; }
.inv-form { display: grid; grid-template-columns: repeat(auto-fit, minmax(170px, 1fr)); gap: 12px; align-items: end; margin-top: 12px; }
.inv-form label { margin: 0 0 6px; }

/* ---------- Tarjetas y grillas ---------- */
.grid { display: grid; gap: var(--gap); }
.grid-kpi { grid-template-columns: repeat(auto-fit, minmax(210px, 1fr)); }
.grid-3 { grid-template-columns: repeat(auto-fit, minmax(320px, 1fr)); }
.span-2 { grid-column: span 2; min-width: 0; }
.card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--r-card); padding: var(--pad-card);
  display: flex; flex-direction: column; gap: 14px; min-width: 0; }
.card-lg { padding: var(--pad-card-lg); gap: 18px; }
.card-dark { background: var(--ink); border-color: var(--ink); color: #fff; }
.card-dark .label, .card-dark .meta { color: var(--neutral); }
.card-dark .unit { color: var(--text-4); }
.card-head { display: flex; justify-content: space-between; align-items: center; gap: 12px; flex-wrap: wrap; }
.stack { display: flex; flex-direction: column; gap: var(--gap); }
.narrow { max-width: 560px; }

/* ---------- Estados ---------- */
.dot { width: 8px; height: 8px; border-radius: 50%; display: inline-block; flex: none; }
.st-online { background: var(--accent); } .st-off { background: var(--neutral); } .st-alarm { background: var(--ink); }
.status { display: inline-flex; align-items: center; gap: 6px; white-space: nowrap; }
.pill { display: inline-flex; align-items: center; gap: 6px; height: 26px; padding: 0 10px; border-radius: 13px;
  background: var(--surface-active); font-size: 12px; font-weight: 500; white-space: nowrap; }
.badge { display: inline-flex; align-items: center; height: 22px; padding: 0 9px; border-radius: 11px; font-size: 12px; font-weight: 500;
  background: var(--surface-active); color: var(--text-2); }
.badge.pendiente { background: var(--ink); color: #fff; }
.badge.usada { background: var(--surface-active); color: var(--ink); }

/* ---------- Tablas ---------- */
.tbl-wrap, .table-wrap { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; font-size: 13px; }
th { text-align: left; font-family: var(--mono); font-size: 11px; letter-spacing: .06em; text-transform: uppercase; color: var(--text-3);
  font-weight: 500; padding: 0 12px 10px 0; white-space: nowrap; }
td { padding: 12px 12px 12px 0; border-top: 1px solid var(--divider); color: var(--text-2); vertical-align: middle; }
td:first-child { color: var(--ink); font-weight: 500; }
td.mono { font-family: var(--mono); font-size: 12px; }
tr.off td { opacity: .5; } tr.off td:last-child { opacity: 1; }
tr.clickable { cursor: pointer; }
tr.clickable:hover td { background: var(--surface-muted); }
td a.row-link { color: var(--ink); text-decoration: none; }
td a.row-link:hover { text-decoration: underline; text-underline-offset: 3px; }
td.acc { white-space: normal; max-width: 360px; }
td.acc b { color: var(--ink); font-weight: 500; }
.grp-row td { padding-top: 22px; border-top: 0; }
.grp-row td:first-child { font-family: var(--mono); font-size: 11px; letter-spacing: .08em; text-transform: uppercase; color: var(--text-3); font-weight: 500; }

/* ---------- Listas ---------- */
.list-rows { display: flex; flex-direction: column; }
.list-row { display: flex; justify-content: space-between; align-items: center; gap: 12px; padding: 14px 0;
  border-top: 1px solid var(--divider); color: inherit; text-decoration: none; }
.list-row:first-child { border-top: 0; }
a.list-row:hover span:first-child { text-decoration: underline; text-underline-offset: 3px; }
.list-row small { color: var(--text-3); font-family: var(--mono); font-size: 12px; }
.empty { color: var(--text-2); text-align: center; padding: 40px 20px; }

/* ---------- Pestañas ---------- */
.tabs { display: inline-flex; gap: 4px; background: var(--surface-muted); padding: 4px; border-radius: var(--r-ctrl); align-self: flex-start; }
.tabs button { min-height: 36px; padding: 0 14px; border: 0; border-radius: var(--r-sm); background: transparent; color: var(--text-2); }
.tabs button.on, .tabs button[aria-selected="true"] { background: var(--surface); color: var(--ink); box-shadow: 0 1px 2px rgba(0,0,0,.08); }
.segmented { display: flex; gap: 4px; background: var(--surface-muted); padding: 4px; border-radius: var(--r-ctrl); }
.segmented button { min-height: 32px; padding: 0 12px; border: 0; border-radius: var(--r-sm); background: transparent; color: var(--text-2); font-family: var(--mono); font-size: 12px; }
.segmented button[aria-pressed="true"] { background: var(--surface); color: var(--ink); box-shadow: 0 1px 2px rgba(0,0,0,.08); }

/* ---------- Diálogos ---------- */
dialog.dlg { border: 1px solid var(--border); border-radius: var(--r-card); padding: 0; width: min(480px, calc(100vw - 32px));
  box-shadow: var(--shadow-pop); color: var(--ink); background: var(--surface); }
dialog.dlg::backdrop { background: rgba(17,17,17,.28); }
.dlg form { padding: var(--pad-card-lg); display: flex; flex-direction: column; }
.dlg h2 { font-size: 18px; margin-bottom: 4px; }
dialog.dlg.dlg-wide { width: min(760px, calc(100vw - 32px)); }
.dlg .access { margin-top: 16px; }
.dlg .role-help { margin-top: 14px; }
.dlg .dlg-actions { display: flex; justify-content: flex-end; gap: 10px; margin-top: 22px; flex-wrap: wrap; }

/* ---------- Token y links de invitación (se muestran una vez) ---------- */
.token-box, .inv-result { margin-top: 14px; padding: 14px 16px; background: var(--surface-muted); border-radius: var(--r-ctrl); font-size: 13px; color: var(--text-2); }
.token-box .mono, .inv-result .mono { display: block; word-break: break-all; margin: 8px 0 10px; color: var(--ink); font-size: 13px; }
.token-box .row, .inv-result .row { display: flex; gap: 8px; flex-wrap: wrap; margin-top: 10px; }
.warn-text { color: var(--ink); font-weight: 500; }

/* ---------- Acceso de clientes (casillas) ---------- */
.access { background: var(--surface-muted); border-radius: var(--r-ctrl); padding: 16px; margin-top: 4px; }
.access:empty { display: none; }
.access h3 { margin: 0 0 4px; }
.access .cols { display: grid; grid-template-columns: repeat(auto-fit, minmax(220px, 1fr)); gap: 14px 24px; margin-top: 10px; }
.access label.chk { display: flex; align-items: center; gap: 8px; margin: 6px 0; font-size: 13px; color: var(--ink); cursor: pointer; }
.access label.chk.inherited { color: var(--text-3); }
.access .sub { font-family: var(--mono); font-size: 11px; color: var(--text-3); letter-spacing: .06em; text-transform: uppercase; margin: 8px 0 2px; }
.access .actions { margin-top: 14px; }
.role-help { font-size: 12px; color: var(--text-2); line-height: 1.7; }
.role-help b { color: var(--ink); font-weight: 600; }

/* ---------- Páginas de acceso (entrar, recuperar, registro) ---------- */
.login-wrap { min-height: 100vh; display: grid; place-items: center; padding: 24px; }
.login-card { width: 100%; max-width: 400px; background: var(--surface); border: 1px solid var(--border); border-radius: var(--r-card); padding: 32px; }
.login-card .brand { padding: 0; margin-bottom: 24px; }
.login-card .sub { font-size: 14px; color: var(--text-2); margin-top: 6px; }
.auth-title { font-size: 24px; font-weight: 600; letter-spacing: -.02em; }
.auth-foot { margin-top: 20px; padding-top: 16px; border-top: 1px solid var(--divider); display: flex; justify-content: space-between; gap: 12px; flex-wrap: wrap; font-size: 13px; }
.auth-foot a { color: var(--text-2); }
.login-card form label:first-of-type { margin-top: 20px; }
#tenantTable td:last-child, #memTable td:last-child, #invTable td:last-child, #memInvTable td:last-child { text-align: right; white-space: nowrap; }
#tenantTable td:last-child .btn + .btn, #memTable td.acc .btn { margin-left: 6px; }
.login-card .btn-primary { width: 100%; margin-top: 24px; }
.login-card .link { display: inline-block; margin-top: 16px; font-size: 13px; color: var(--text-2); }
.notfound { text-align: center; padding: 60px 20px; }
.notfound p { color: var(--text-2); margin-top: 6px; }

/* ---------- Página del dispositivo ---------- */
.dev-tools { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; }

/* =========================================================
   Widgets del panel (DISENO-THINGSBIT.md §5 "Widgets del dashboard de dispositivo")
   Cada widget es una tarjeta: nombre a la izquierda, canal en mono a la derecha.
   Los tamaños de letra se adaptan al tamaño del widget (container queries).
   ========================================================= */
.tb-bar { display: flex; align-items: center; justify-content: space-between; gap: 12px; flex-wrap: wrap;
  font-family: var(--mono); font-size: 12px; color: var(--text-3); margin: 0 0 16px; }
.tb-bar b { color: var(--ink); font-weight: 600; font-family: var(--font); }
.tb-bar button { font-family: var(--font); }
.tb-bar .live { color: var(--ink); }
.tb-bar .live::before { content: ''; display: inline-block; width: 8px; height: 8px; border-radius: 50%; background: var(--accent); margin-right: 6px; vertical-align: 0; }
.tb-grid { display: grid; grid-template-columns: repeat(12, minmax(0, 1fr)); grid-auto-rows: 84px; gap: var(--gap); }
.tb-w { background: var(--surface); border: 1px solid var(--border); border-radius: var(--r-card); padding: 16px 18px;
  display: flex; flex-direction: column; gap: 8px; min-width: 0; min-height: 0; overflow: hidden; }
.tb-w-dark { background: var(--ink); border-color: var(--ink); color: #fff; }
.tb-w-dark .tb-w-title span:first-child { color: var(--neutral); }
.tb-w-dark .tb-w-title .ch { color: var(--text-4); }
.tb-w-dark .meta { color: var(--neutral); }
.tb-w-title { font-size: 13px; color: var(--text-2); display: flex; justify-content: space-between; gap: 8px; white-space: nowrap; }
.tb-w-title span:first-child { overflow: hidden; text-overflow: ellipsis; }
.tb-w-title .ch { font-family: var(--mono); font-size: 11px; letter-spacing: .06em; color: var(--text-3); }
.tb-w-body { flex: 1; min-height: 0; display: flex; flex-direction: column; align-items: center; justify-content: center;
  gap: 8px; position: relative; container-type: size; }
.tb-w-body.tb-left { align-items: stretch; justify-content: flex-start; }
.tb-w-foot { font-size: 11px; color: var(--text-3); text-align: center; min-height: 14px; }
@media (max-width: 760px) {
  .tb-grid > .tb-w { grid-column: 1 / -1 !important; grid-row: auto / span var(--h, 2) !important; }
}

/* cifra grande con decimales atenuados */
.tb-big { font-size: 40px; font-size: clamp(20px, min(46cqh, 15cqw), 64px); font-weight: 600; letter-spacing: -.03em; line-height: 1.05;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis; color: inherit; }
.tb-big.none { color: var(--text-3); }
.tb-num.dec, .tb-gauge-val .dec { color: var(--decimals); }
.tb-big .unit, .tb-gauge-val .unit { font-size: .42em; font-weight: 400; letter-spacing: 0; color: var(--text-3); margin-left: 4px; }
.tb-state { font-size: clamp(18px, min(34cqh, 12cqw), 44px); }
.axis { display: flex; justify-content: space-between; gap: 8px; font-family: var(--mono); font-size: 11px; color: var(--text-3); width: 100%; }
.tb-w-body .meta { font-size: 12px; }

/* valor + minigráfico */
.tb-spark { width: 100%; height: 40px; flex: 1 1 auto; max-height: 64px; min-height: 0; color: var(--ink); }
@container (max-height: 110px) { .tb-spark, .tb-spark-meta { display: none; } }

/* medidor */
.tb-gauge-wrap { position: relative; width: 100%; flex: 1; min-height: 0; display: flex; align-items: flex-end; justify-content: center; }
.tb-gauge { width: 100%; height: 100%; max-height: 180px; display: block; }
.tb-gauge .track { fill: none; stroke: var(--surface-active); stroke-width: 12; stroke-linecap: round; }
.tb-gauge .arc { fill: none; stroke: var(--accent); stroke-width: 12; stroke-linecap: round; transition: stroke-dashoffset .5s ease; }
.tb-gauge .arc.out { stroke: var(--ink); }
.tb-gauge-val { position: absolute; left: 0; right: 0; bottom: 0; text-align: center; white-space: nowrap;
  font-size: clamp(16px, min(22cqh, 11cqw), 44px); font-weight: 600; letter-spacing: -.03em; line-height: 1; }

/* gráfico */
.tb-w-body.tb-chart-body { align-items: stretch; justify-content: stretch; gap: 6px; }
.tb-chart { position: relative; flex: 1; min-height: 0;
  background-image: radial-gradient(var(--grid-dot) 1px, transparent 1px); background-size: 16px 16px; }
.tb-chart canvas { position: absolute; inset: 0; }
.tb-chart-empty { position: absolute; inset: 0; display: grid; place-items: center; color: var(--text-2); font-size: 13px; }
.tb-chart-empty[hidden] { display: none; }
.tb-legend { display: flex; gap: 16px; flex-wrap: wrap; font-size: 12px; color: var(--text-2); }
.tb-legend span { display: inline-flex; align-items: center; gap: 6px; }
.tb-legend i { display: inline-block; width: 14px; }
.tb-legend .l-accent { height: 2px; background: var(--accent); }
.tb-legend .l-ink { border-top: 2px dashed var(--ink); }

/* interruptor */
.tb-row { display: flex; align-items: center; gap: 12px; flex-wrap: wrap; }
.tb-switch { width: 64px; height: 36px; border-radius: 18px; border: 0; padding: 4px; display: flex; justify-content: flex-start;
  background: var(--grid-dot); cursor: pointer; transition: background .2s; flex: none; }
.tb-switch[aria-checked="true"] { background: var(--accent); justify-content: flex-end; }
.tb-switch span { width: 28px; height: 28px; border-radius: 50%; background: #fff; box-shadow: 0 1px 3px rgba(0,0,0,.2); }
.tb-switch:disabled { opacity: .5; cursor: not-allowed; }
@container (max-height: 80px) { .tb-state { display: none; } }

/* deslizador */
.tb-range { margin: 0; }
.tb-range input[type=range] { width: 100%; min-height: 24px; height: 24px; padding: 0; border: 0; background: none; accent-color: var(--accent); }
.tb-range input:disabled { opacity: .5; cursor: not-allowed; }

/* indicador (LED) */
.tb-led-row { display: flex; align-items: center; gap: 10px; min-width: 0; }
.tb-led { width: 12px; height: 12px; border-radius: 50%; background: var(--text-2); flex: none; }
.tb-led.on { background: var(--accent); }
.tb-led-text { font-size: clamp(18px, min(32cqh, 11cqw), 40px); font-weight: 600; letter-spacing: -.02em; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }

/* estados vacíos */
.tb-empty { color: var(--muted); text-align: center; padding: 60px 20px; font-size: 14px; }
.tb-empty button { margin-top: 14px; }

/* editor de plantilla */
.tb-ed-head { display: flex; align-items: center; justify-content: space-between; gap: 12px; flex-wrap: wrap; }
.tb-ed-form { display: grid; grid-template-columns: repeat(auto-fit, minmax(120px, 1fr)); gap: 10px; align-items: end; margin-top: 14px; }
.tb-ed-form label { margin: 0 0 6px; }
.tb-ed input.mini, .tb-ed select.mini { padding: 5px 8px; font-size: 13px; width: 100%; min-width: 60px; }
.tb-ed td .btn-link + .btn-link { margin-left: 10px; }
.tb-ed pre { background: var(--bg); border: 1px dashed var(--line); border-radius: 9px; padding: 12px 14px;
  font-size: 12px; color: var(--ink); overflow-x: auto; margin-top: 10px; font-family: ui-monospace, Consolas, monospace; }
.tb-ed .dir-in { color: var(--text-2); } .tb-ed .dir-out { color: var(--ink); font-weight: 600; }
.tb-tpl-list { display: flex; flex-direction: column; gap: 6px; margin-bottom: 10px; }
.tb-tpl { display: flex; justify-content: space-between; align-items: center; gap: 8px; background: var(--panel);
  border: 1px solid var(--line); border-radius: 9px; padding: 8px 12px; font-size: 13px; cursor: pointer; }
.tb-tpl:hover { border-color: var(--muted); }
.tb-tpl small { color: var(--muted); font-size: 11px; }

/* editor drag & drop (Gridstack) */
.tb-palette { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
.tb-palette button { padding: 5px 10px; font-size: 12px; }
.tb-gs-wrap { margin: 14px -6px 0; min-height: 200px; border-radius: 10px;
  background-image: linear-gradient(to right, var(--divider) 1px, transparent 1px);
  background-size: calc(100% / 12) 100%; }
.tb-gs .grid-stack-item-content { overflow: hidden; cursor: grab; }
.tb-gs .grid-stack-item-content:active { cursor: grabbing; }
.tb-gs .tb-w { height: 100%; }
.tb-gs .tb-w.sel { border-color: var(--ink); box-shadow: 0 0 0 1px var(--ink); }
.tb-gs .tb-w-dark.sel { box-shadow: 0 0 0 3px var(--accent); }
.tb-gs .tb-w button { pointer-events: none; }           /* en la vista previa nada es clicable: solo se arrastra */
.tb-gs .grid-stack-placeholder > .placeholder-content { background: var(--surface-muted); border: 1px dashed var(--text-3); border-radius: var(--r-card); }
.tb-gs.grid-stack > .grid-stack-item > .ui-resizable-se { width: 16px; height: 16px; right: 10px; bottom: 10px; opacity: .7;
  background: none !important; border-right: 2px solid var(--muted); border-bottom: 2px solid var(--muted); border-radius: 0 0 4px 0;
  transform: none !important; }
.tb-props { margin-top: 6px; }
.tb-props:not(:empty) { border-top: 1px solid var(--line); padding-top: 4px; margin-top: 14px; }
.tb-ed-save { margin-top: 16px; display: flex; align-items: center; gap: 14px; flex-wrap: wrap; }

/* pantalla completa: solo los datos */
.tb-bar-actions { display: flex; gap: 8px; flex-wrap: wrap; }
.tb-bar-actions button { height: 36px; padding: 0 12px; font-size: 13px; }
.tb-only-full { display: none; }
.tb-full { position: fixed; inset: 0; z-index: 1000; background: var(--bg); padding: 16px 20px; overflow: auto; }
.tb-full .tb-only-full { display: inline; font-size: 16px; }
.tb-full .tb-not-full { display: none; }
.tb-full .tb-bar { margin: 0 0 14px; }
.tb-full .tb-w { background: var(--surface); }
@media (min-width: 761px) {
  /* las filas crecen para llenar la pantalla */
  .tb-full .tb-grid { grid-auto-rows: max(84px, calc((100vh - 90px - (var(--rows, 4) - 1) * 12px) / var(--rows, 4))); }
  .tb-full .tb-gauge { max-height: none; }
  .tb-full .tb-w-title { font-size: 14px; }
}

/* vista de cliente final (viewer): solo datos */
.tb-client .tb-not-client, .tb-client .tb-w-title .ch { display: none; }

/* Página del dispositivo: el encabezado ya muestra plantilla y acciones */
.dev-dash .tb-bar .tb-not-client { display: none; }
.dev-dash .tb-bar { margin-top: 0; }

/* =========================================================
   Página Inicio
   ========================================================= */
.series-select { min-height: 0; height: auto; width: auto; max-width: 100%; padding: 0 22px 0 0; border: 0; background-color: transparent;
  font-size: 13px; color: var(--text-2); cursor: pointer; text-overflow: ellipsis; }
.series-select:focus { outline: 2px solid var(--ink); outline-offset: 2px; border-radius: 4px; }
.chart-value { white-space: nowrap; }
.chart { position: relative; height: 260px; background-image: radial-gradient(var(--grid-dot) 1px, transparent 1px); background-size: 16px 16px; }
.chart canvas { position: absolute; inset: 0; }
.chart-empty { position: absolute; inset: 0; display: grid; place-items: center; color: var(--text-2); font-size: 13px; text-align: center; padding: 20px; }
.chart-empty[hidden] { display: none; }
.donut-wrap { position: relative; width: 168px; height: 168px; align-self: center; }
.donut-center { position: absolute; inset: 0; display: flex; flex-direction: column; align-items: center; justify-content: center; }
.donut-center > span:first-child { font-size: 30px; font-weight: 600; letter-spacing: -.03em; }
.legend { display: flex; flex-direction: column; gap: 10px; font-size: 13px; }
.legend div { display: flex; align-items: center; gap: 10px; }
.legend div span:nth-child(2) { flex: 1; }
.sq { width: 10px; height: 10px; border-radius: 3px; flex: none; }
.list-item { display: flex; gap: 12px; padding: 12px 0; border-top: 1px solid var(--divider); color: inherit; text-decoration: none; }
.list-item:first-child { border-top: 0; }
a.list-item:hover .li-title { text-decoration: underline; text-underline-offset: 3px; }
.list-bar { width: 3px; border-radius: 3px; align-self: stretch; flex: none; }
.li-body { flex: 1; display: flex; flex-direction: column; gap: 4px; min-width: 0; }
.li-title { font-size: 13px; font-weight: 500; }
.li-detail { font-size: 12px; color: var(--text-2); }
.li-time { font-family: var(--mono); font-size: 11px; color: var(--text-3); white-space: nowrap; }

/* =========================================================
   Conectar dispositivo
   ========================================================= */
.token-row { display: flex; gap: 10px; flex-wrap: wrap; }
.token-row input { flex: 1 1 280px; font-size: 13px; }
.live-state { display: flex; align-items: center; gap: 10px; }
.live-state .dot { width: 10px; height: 10px; }
.live-title { font-size: 20px; font-weight: 600; letter-spacing: -.02em; }
.live-channels { display: flex; flex-wrap: wrap; gap: 6px; }
.live-channels .pill { font-family: var(--mono); font-weight: 400; }
.code-wrap { position: relative; }
.code-copy { position: absolute; top: 10px; right: 10px; }
pre.code { margin: 0; background: var(--surface-muted); border-radius: var(--r-ctrl); padding: 16px 18px; padding-right: 130px;
  overflow: auto; max-height: 520px; font-family: var(--mono); font-size: 12.5px; line-height: 1.6; color: var(--ink); tab-size: 2; }
.how { margin: 0; padding-left: 18px; display: flex; flex-direction: column; gap: 8px; color: var(--text-2); font-size: 13px; }
.how b { color: var(--ink); font-weight: 600; }
@media (max-width: 800px) { pre.code { padding-right: 18px; padding-top: 52px; } }
