/* =====================================================================
   Barra común (appbar), diálogo de ayuda, avisos y arranque.
   Igual en las tres vistas: es lo que permite cambiar entre ellas.
   ===================================================================== */

body { display: flex; flex-direction: column; min-height: 100dvh; }

.appbar {
  position: sticky; top: 0; z-index: 40;
  height: var(--appbar-h);
  display: flex; align-items: center; gap: 12px;
  padding: 0 16px;
  background: color-mix(in srgb, var(--shell-surface) 88%, transparent);
  backdrop-filter: saturate(1.4) blur(14px);
  border-bottom: 1px solid var(--shell-border);
  color: var(--shell-text);
}

.brand { display: flex; align-items: center; gap: 10px; min-width: 0; text-decoration: none; color: inherit; }
.brand__mark {
  width: 30px; height: 30px; border-radius: 8px; display: grid; place-items: center;
  background: linear-gradient(135deg, #1f2a44, #0e1116); color: #22d3ee;
  box-shadow: inset 0 0 0 1px rgba(255,255,255,.08);
}
.brand__name { font-weight: 700; letter-spacing: -.01em; white-space: nowrap; }
.brand__robot { color: var(--shell-muted); font-size: 12.5px; white-space: nowrap; }
.brand__robot b { color: var(--shell-text); font-weight: 600; }
.mode-chip {
  font: 600 10.5px/1 var(--font-mono); letter-spacing: .06em; text-transform: uppercase;
  padding: 4px 7px; border-radius: 999px; border: 1px solid var(--shell-border); color: var(--shell-muted);
  white-space: nowrap; flex: none;
}
.mode-chip[data-mode="demo"] { color: #a78bfa; border-color: color-mix(in srgb, #a78bfa 40%, transparent); }
.mode-chip[data-mode="real"], .mode-chip[data-mode="robot"] { color: var(--sem-ok); border-color: color-mix(in srgb, var(--sem-ok) 40%, transparent); }

/* ---- Selector de vistas ---- */
.views {
  display: flex; gap: 2px; padding: 3px; margin: 0 auto;
  background: var(--shell-surface-2); border: 1px solid var(--shell-border); border-radius: 12px;
  position: relative;
}
.views__btn {
  position: relative; z-index: 1;
  display: flex; align-items: center; gap: 8px;
  border: 0; background: transparent; color: var(--shell-muted);
  padding: 6px 12px; border-radius: 9px; font-weight: 600; font-size: 13px; white-space: nowrap;
  transition: color .2s var(--ease);
}
.views__btn kbd { font-size: 10px; padding: 2px 5px; opacity: .8; }
.views__btn:hover { color: var(--shell-text); }
.views__btn[aria-pressed="true"] { color: var(--shell-text); }
.views__thumb {
  position: absolute; z-index: 0; top: 3px; bottom: 3px; left: 0; width: 0;
  background: var(--shell-surface); border-radius: 9px;
  box-shadow: 0 1px 2px rgba(0,0,0,.25), inset 0 0 0 1px var(--shell-border);
  transition: transform .28s var(--ease), width .28s var(--ease);
}

/* ---- Conexión ---- */
.conn { display: flex; align-items: center; gap: 8px; }
.pill {
  display: inline-flex; align-items: center; gap: 8px;
  height: 32px; padding: 0 12px; border-radius: 999px;
  border: 1px solid var(--shell-border); background: var(--shell-surface-2);
  font: 500 12px/1 var(--font-mono); color: var(--shell-muted); white-space: nowrap;
}
.pill:hover { color: var(--shell-text); }
.pill__dot { width: 8px; height: 8px; border-radius: 50%; background: var(--shell-muted); flex: none; }
.pill[data-state="live"] .pill__dot { background: var(--sem-ok); box-shadow: 0 0 0 0 color-mix(in srgb, var(--sem-ok) 60%, transparent); animation: live 2s infinite; }
.pill[data-state="live"] .pill__label { color: var(--shell-text); }
.pill[data-state="connecting"] .pill__dot,
.pill[data-state="reconnecting"] .pill__dot,
.pill[data-state="stale"] .pill__dot { background: var(--sem-warn); animation: blink 1s infinite; }
.pill[data-state="offline"] .pill__dot { background: var(--sem-crit); }
.pill[data-paused="true"] .pill__dot { background: var(--shell-accent); animation: none; }
@keyframes live { 70% { box-shadow: 0 0 0 7px transparent; } 100% { box-shadow: 0 0 0 0 transparent; } }
@keyframes blink { 50% { opacity: .35; } }

.icon-btn {
  width: 34px; height: 34px; display: grid; place-items: center; flex: none;
  border-radius: 9px; border: 1px solid transparent; background: transparent; color: var(--shell-muted);
}
.icon-btn:hover { color: var(--shell-text); background: var(--shell-surface-2); border-color: var(--shell-border); }
.icon-btn[aria-pressed="true"] { color: var(--shell-accent); }

/* ---- Popover de conexión ---- */
.popover {
  position: absolute; top: calc(var(--appbar-h) - 4px); right: 12px; z-index: 60;
  width: min(380px, calc(100vw - 24px));
  background: var(--shell-surface); color: var(--shell-text);
  border: 1px solid var(--shell-border); border-radius: 14px;
  box-shadow: 0 20px 50px rgba(0,0,0,.35);
  padding: 16px; display: grid; gap: 14px;
  transform-origin: top right;
  animation: pop .18s var(--ease);
}
.popover[hidden] { display: none; }
@keyframes pop { from { opacity: 0; transform: scale(.96) translateY(-4px); } }
.popover h3 { margin: 0; font-size: 14px; }
.popover p { margin: 0; color: var(--shell-muted); font-size: 12.5px; }
.field { display: grid; gap: 6px; }
.field[hidden] { display: none; }
.field > span { font-size: 12px; color: var(--shell-muted); font-weight: 600; }
.input {
  height: 36px; padding: 0 10px; border-radius: 9px;
  border: 1px solid var(--shell-border); background: var(--shell-surface-2); color: var(--shell-text);
  font-family: var(--font-mono); font-size: 13px; width: 100%;
}
.seg { display: flex; gap: 2px; padding: 3px; border-radius: 10px; background: var(--shell-surface-2); border: 1px solid var(--shell-border); }
.seg button { flex: 1; border: 0; background: transparent; padding: 6px 8px; border-radius: 7px; color: var(--shell-muted); font-weight: 600; font-size: 12.5px; }
.seg button[aria-checked="true"] { background: var(--shell-surface); color: var(--shell-text); box-shadow: inset 0 0 0 1px var(--shell-border); }
.btn {
  height: 36px; padding: 0 14px; border-radius: 9px; border: 1px solid var(--shell-border);
  background: var(--shell-surface-2); color: var(--shell-text); font-weight: 600;
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
}
.btn--primary { background: var(--shell-accent); border-color: var(--shell-accent); color: var(--shell-accent-text); }
.popover__stats { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; }
.stat { background: var(--shell-surface-2); border: 1px solid var(--shell-border); border-radius: 10px; padding: 8px 10px; }
.stat b { display: block; font: 600 15px/1.2 var(--font-mono); }
.stat span { font-size: 11px; color: var(--shell-muted); }

/* ---- Vista ---- */
.view { flex: 1; min-height: 0; position: relative; outline: none; }
.view--enter { animation: view-in .32s var(--ease); }
@keyframes view-in { from { opacity: 0; transform: translateY(6px); } }

.boot { height: calc(100dvh - var(--appbar-h)); display: grid; place-content: center; justify-items: center; gap: 16px; color: var(--shell-muted); }
.boot__spinner { width: 36px; height: 36px; border-radius: 50%; border: 3px solid var(--shell-border); border-top-color: var(--shell-accent); animation: spin 1s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }

/* ---- Diálogo de ayuda ---- */
.dialog {
  width: min(680px, calc(100vw - 24px)); max-height: calc(100dvh - 48px);
  padding: 0; border: 1px solid var(--shell-border); border-radius: 16px;
  background: var(--shell-surface); color: var(--shell-text);
  box-shadow: 0 30px 80px rgba(0,0,0,.45);
}
.dialog::backdrop { background: rgba(5, 7, 12, .55); backdrop-filter: blur(3px); }
.dialog[open] { animation: pop .2s var(--ease); }
.dialog__head { display: flex; align-items: center; justify-content: space-between; padding: 16px 20px; border-bottom: 1px solid var(--shell-border); }
.dialog__head h2 { margin: 0; font-size: 16px; }
.dialog__body { padding: 16px 20px 20px; display: grid; gap: 18px; overflow: auto; }
.dialog__body h3 { margin: 0 0 8px; font-size: 12px; text-transform: uppercase; letter-spacing: .08em; color: var(--shell-muted); }
.keys { display: grid; grid-template-columns: repeat(auto-fill, minmax(240px, 1fr)); gap: 6px 20px; margin: 0; }
.keys div { display: flex; justify-content: space-between; align-items: center; gap: 12px; padding: 4px 0; border-bottom: 1px dashed var(--shell-border); }
.keys dt { color: var(--shell-text); }
.keys dd { margin: 0; display: flex; gap: 4px; }
.legend-sem { display: flex; flex-wrap: wrap; gap: 14px; }
.legend-sem span { display: inline-flex; align-items: center; gap: 6px; }
.legend-sem i { width: 10px; height: 10px; border-radius: 50%; display: inline-block; }

/* ---- Avisos ---- */
.toasts { position: fixed; z-index: 80; right: 16px; bottom: 44px; display: grid; gap: 8px; justify-items: end; pointer-events: none; }
.toast {
  pointer-events: auto; display: flex; align-items: center; gap: 10px;
  max-width: min(420px, calc(100vw - 32px));
  padding: 10px 14px; border-radius: 12px;
  background: var(--shell-surface); color: var(--shell-text); border: 1px solid var(--shell-border);
  box-shadow: 0 12px 30px rgba(0,0,0,.3);
  opacity: 0; transform: translateY(8px) scale(.98);
  transition: opacity .2s var(--ease), transform .2s var(--ease);
}
.toast.is-in { opacity: 1; transform: none; }
.toast--ok .icon { color: var(--sem-ok); }
.toast--warn .icon { color: var(--sem-warn); }
.toast--crit { border-color: color-mix(in srgb, var(--sem-crit) 50%, var(--shell-border)); }
.toast--crit .icon { color: var(--sem-crit); }
.toast--info .icon { color: var(--shell-accent); }

/* ---- Fuente de datos ---- */
.mode-chip { display: inline-flex; align-items: center; gap: 6px; background: transparent; cursor: pointer; white-space: nowrap; }
.mode-chip:hover { border-color: currentColor; }
.mode-chip__dot { width: 6px; height: 6px; border-radius: 50%; background: currentColor; }
.mode-chip[data-mode="real"] .mode-chip__dot { animation: live 2s infinite; box-shadow: 0 0 0 0 color-mix(in srgb, var(--sem-ok) 60%, transparent); }
.popover { max-height: calc(100dvh - var(--appbar-h) - 16px); overflow: auto; }
.popover__section { display: grid; gap: 12px; }
.popover__sep { border: 0; border-top: 1px solid var(--shell-border); margin: 2px 0; width: 100%; }
.popover__note { font-size: 11.5px !important; }
.sources { display: grid; gap: 6px; }
.source {
  display: flex; gap: 10px; align-items: flex-start; padding: 10px 12px; border-radius: 10px;
  border: 1px solid var(--shell-border); background: var(--shell-surface-2); cursor: pointer;
  transition: border-color .15s, background .15s;
}
.source:hover { border-color: color-mix(in srgb, var(--shell-accent) 50%, var(--shell-border)); }
.source:has(input:checked) { border-color: var(--shell-accent); background: color-mix(in srgb, var(--shell-accent) 10%, var(--shell-surface-2)); }
.source input { margin: 3px 0 0; accent-color: var(--shell-accent); }
.source__body { display: grid; gap: 2px; min-width: 0; }
.source__body b { display: flex; align-items: center; gap: 6px; flex-wrap: wrap; font-size: 13px; }
.source__body b em { font: 600 10px/1 var(--font-mono); font-style: normal; text-transform: uppercase; letter-spacing: .05em; padding: 3px 6px; border-radius: 999px; background: var(--shell-accent); color: var(--shell-accent-text); }
.source__real { font: 600 10px/1 var(--font-mono); font-style: normal; color: var(--sem-ok); }
.source__body > span { font-size: 12px; color: var(--shell-muted); line-height: 1.4; }
.source.is-disabled { opacity: .55; cursor: not-allowed; }
.btn:disabled { opacity: .55; cursor: default; }

/* ---- Responsive ---- */
/* Con poco ancho, primero se va el nombre del dashboard: el robot y su fuente importan más */
@media (max-width: 1480px) {
  .brand__name { display: none; }
}
@media (max-width: 1240px) {
  .brand__robot, .views__btn kbd { display: none; }
}
@media (max-width: 900px) {
  /* Las vistas tienen una barra de acciones fija abajo: los avisos van arriba de ella */
  .toasts { bottom: 112px; }
}
@media (max-width: 760px) {
  .appbar { gap: 6px; padding: 0 8px; }
  .brand__name, .brand__robot { display: none; }
  .brand { gap: 6px; flex: none; }
  .mode-chip { padding: 4px 6px; font-size: 9.5px; }
  .views { margin: 0; flex: 1; min-width: 0; justify-content: space-between; }
  .views__btn { flex: 1; justify-content: center; padding: 7px 0; min-width: 0; }
  .views__btn span { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); }
  .views__btn .icon { display: inline-block; }
  .pill__label, .pill__stats { display: none; }
  .pill { padding: 0 9px; height: 30px; }
  .conn { gap: 2px; }
  .appbar .icon-btn { width: 30px; }
  .appbar .icon-btn[data-optional] { display: none; }
  .toasts { left: 12px; right: 12px; justify-items: stretch; }
}
@media (max-width: 400px) {
  /* En el celular la etiqueta de fuente queda como un punto de color (verde = real) */
  .mode-chip { font-size: 0; padding: 6px; gap: 0; }
  .mode-chip__dot { width: 8px; height: 8px; }
}

/* ---- Esquema | 3D real (FigureSwitch) ---- */
.fig3d { position: absolute; inset: 0; z-index: 1; }
.fig3d[hidden] { display: none; }
.fig-toggle { display: inline-flex; gap: 2px; padding: 2px; border-radius: 8px; border: 1px solid var(--shell-border); background: var(--shell-surface-2); flex: none; }
.fig-toggle button { border: 0; background: transparent; color: var(--shell-muted); font: 600 11.5px/1 var(--font-ui); padding: 5px 9px; border-radius: 6px; white-space: nowrap; }
.fig-toggle button[aria-checked="true"] { background: var(--shell-accent); color: var(--shell-accent-text); }
.fig-toggle--compact button { padding: 4px 7px; font-size: 11px; }

/* ---- El robot y su fuente se ven como desplegables (abren el selector) ---- */
.brand__robot {
  display: inline-flex; align-items: center; gap: 4px;
  border: 1px solid transparent; background: transparent; color: var(--shell-muted);
  padding: 4px 8px; margin-left: -4px; border-radius: 8px; font-size: 12.5px; white-space: nowrap;
  transition: background .15s, border-color .15s;
}
.brand__robot:hover { background: var(--shell-surface-2); border-color: var(--shell-border); color: var(--shell-text); }
.brand__caret, .mode-chip__caret { font-size: 10px; opacity: .8; margin-left: 2px; }
@media (max-width: 1240px) { .brand__robot { display: none; } }
.popover__title { display: flex; align-items: baseline; justify-content: space-between; gap: 12px; }
.link-btn { border: 0; background: none; padding: 0; color: var(--shell-accent); font-size: 12.5px; font-weight: 600; text-decoration: underline; text-underline-offset: 2px; }

/* ---- Menú del robot (Go2 / G1) ---- */
.robot-menu {
  position: absolute; top: calc(var(--appbar-h) - 6px); z-index: 61; min-width: 260px;
  padding: 6px; border-radius: 12px; border: 1px solid var(--shell-border);
  background: var(--shell-surface); box-shadow: 0 16px 40px rgba(0,0,0,.3);
  display: grid; gap: 2px; animation: pop .16s var(--ease); transform-origin: top left;
}
.robot-menu[hidden] { display: none; }
.robot-menu__head { margin: 4px 10px 4px; font-size: 11px; text-transform: uppercase; letter-spacing: .08em; color: var(--shell-muted); font-weight: 650; }
.robot-menu__item {
  display: flex; gap: 10px; align-items: center; text-align: left; width: 100%;
  border: 0; background: transparent; color: var(--shell-text); padding: 8px 10px; border-radius: 8px;
}
.robot-menu__item:hover, .robot-menu__item:focus-visible { background: var(--shell-surface-2); }
.robot-menu__item b { display: block; font-size: 13.5px; }
.robot-menu__item small { color: var(--shell-muted); font-size: 12px; }
.robot-menu__check { width: 16px; color: var(--shell-accent); font-weight: 800; visibility: hidden; }
.robot-menu__item[aria-checked="true"] .robot-menu__check { visibility: visible; }
.robot-menu__more { border: 0; border-top: 1px solid var(--shell-border); background: transparent; color: var(--shell-accent); text-align: left; padding: 9px 10px 5px 36px; font-weight: 600; font-size: 12.5px; margin-top: 4px; }
select.input { appearance: auto; font-family: var(--font-mono); }
.input[hidden] { display: none; }
.field__hint { font-size: 11.5px; color: var(--shell-muted); }
