/* app.css — Humind dashboard, dark vendor-style theme. Responsive to ~400px. */

:root {
  --bg: #0d1117;
  --surface: #161b22;
  --surface-2: #1c232d;
  --surface-3: #222b36;
  --border: #2a3441;
  --text: #e6edf5;
  --text-muted: #8b98a9;
  --accent: #2f81f7;
  --accent-2: #1f6feb;
  --accent-contrast: #ffffff;
  --ok: #3fb950;
  --ok-bg: #10251a;
  --warn: #d29922;
  --warn-bg: #2a2410;
  --err: #f85149;
  --err-bg: #2a1515;
  --crit: #ff7b72;
  --radius: 10px;
  --radius-sm: 7px;
  --shadow: 0 2px 8px rgba(0, 0, 0, 0.45);
  --gap: 14px;
  /* ---- one shared size scale (icons / dots / controls) ---- */
  --icon-sm: 16px;   /* inline text icons */
  --icon-md: 20px;   /* top-bar / menu button icons, logo mark */
  --icon-lg: 24px;   /* nav-menu tile icons, fallback hero icons stay separate */
  --dot: 9px;        /* status / liveness dots */
  --ctl-h: 34px;     /* standard control height (buttons, jog, selects) */
  --ctl-h-lg: 40px;  /* prominent controls (E-STOP) + touch target on desktop */
  --ctl-pad-y: 7px;
  --ctl-pad-x: 12px;
  --ctl-font: 0.85rem;
  --tap: 44px;       /* minimum touch target on phones */
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 14px/1.45 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
}

h1, h2, h3, h4, h5 { margin: 0 0 0.4em; font-weight: 600; }
h3 { font-size: 0.95rem; }
h4 { font-size: 0.85rem; }
a { color: var(--accent); }
.muted { color: var(--text-muted); }
.form-error { color: var(--err); }
[hidden] { display: none !important; }

.skip-link {
  position: absolute; left: -999px; top: 0;
  background: var(--accent); color: #fff; padding: 8px 12px; z-index: 100;
}
.skip-link:focus { left: 8px; top: 8px; }

.icon { display: inline-flex; }
.icon svg { width: var(--icon-sm); height: var(--icon-sm); display: block; }

/* ---- buttons ---- */
.btn {
  font: inherit; font-size: var(--ctl-font); cursor: pointer; border: 1px solid var(--border);
  background: var(--surface-2); color: var(--text);
  min-height: var(--ctl-h); padding: var(--ctl-pad-y) var(--ctl-pad-x);
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  border-radius: var(--radius-sm); line-height: 1.1; transition: background .12s, border-color .12s;
}
.btn:hover:not(:disabled) { background: var(--surface-3); border-color: #3a4756; }
.btn:disabled { opacity: 0.45; cursor: not-allowed; }
.btn.primary { background: var(--accent); border-color: var(--accent); color: #fff; }
.btn.primary:hover:not(:disabled) { background: var(--accent-2); }
.btn.danger { border-color: var(--err); color: var(--err); }
.btn.danger:hover:not(:disabled) { background: var(--err-bg); }
.btn.ghost { background: transparent; }
.btn.cmd { padding: var(--ctl-pad-y) 10px; }

input, select {
  font: inherit; background: var(--bg); color: var(--text);
  border: 1px solid var(--border); border-radius: var(--radius-sm); padding: 6px 8px;
}
select { min-height: var(--ctl-h); }
input:focus, select:focus { outline: 2px solid var(--accent); outline-offset: 0; }

/* ---- login ---- */
.login-wrap { min-height: 100vh; display: grid; place-items: center; padding: 24px 16px; }
.login-form {
  width: 100%; max-width: 340px; background: var(--surface); border: 1px solid var(--border);
  border-radius: var(--radius); padding: 26px; box-shadow: var(--shadow);
  display: flex; flex-direction: column; gap: 8px;
}
.login-form label { font-size: 0.8rem; color: var(--text-muted); margin-top: 6px; }
.login-form .btn { margin-top: 14px; }
.brand-lockup { display: flex; align-items: center; gap: 8px; font-size: 1.5rem; font-weight: 700; }
.brand-lockup .logo-mark svg { width: 1.4em; height: 1.4em; color: var(--accent); }
.brand-word { font-weight: 700; letter-spacing: 0.2px; }
.subtitle { color: var(--text-muted); margin: 2px 0 10px; }

/* ---- top bar ---- */
.topbar {
  display: flex; align-items: center; gap: 12px; padding: 10px 16px;
  background: var(--surface); border-bottom: 1px solid var(--border); flex-wrap: wrap;
}
.topbar-left { display: flex; align-items: center; gap: 10px; }
.logo-mark { color: var(--accent); display: inline-flex; }
.logo-mark svg { width: var(--icon-md); height: var(--icon-md); }
.topbar-title { margin: 0; font-size: 1rem; }
.topbar-right { margin-left: auto; display: flex; align-items: center; gap: 10px; }
.topbar-center { display: flex; gap: 22px; flex-wrap: wrap; }
.dash-topbar { position: sticky; top: 0; z-index: 20; }
.rc-status { font-size: 0.85rem; }
.rc-label { color: var(--text-muted); }
.rc-value { font-weight: 600; color: var(--accent); }
.robot-pill {
  display: inline-flex; align-items: center; gap: 5px; background: var(--surface-2);
  border: 1px solid var(--border); border-radius: 999px; padding: 3px 10px; cursor: pointer; color: var(--text);
}
.robot-pill-id { font-weight: 600; }
.user-badge { color: var(--text-muted); font-size: 0.8rem; }
.conn-pill { font-size: 0.72rem; border: 1px solid var(--border); border-radius: 999px; padding: 2px 9px; }
.conn-ok { color: var(--ok); border-color: var(--ok); }
.conn-bad { color: var(--err); border-color: var(--err); }

.nav-grid-btn {
  background: var(--surface-2); border: 1px solid var(--border); border-radius: var(--radius-sm);
  padding: 6px 9px; cursor: pointer; color: var(--text);
}
.grid-glyph { display: grid; grid-template-columns: repeat(3, 3px); gap: 3px; }
.grid-dot { width: 3px; height: 3px; background: currentColor; border-radius: 1px; }

/* ---- nav menu (2x3 grid) ---- */
.nav-menu {
  position: absolute; right: 16px; top: 56px; z-index: 40; background: var(--surface);
  border: 1px solid var(--border); border-radius: var(--radius); box-shadow: var(--shadow); padding: 12px;
}
.nav-grid { display: grid; grid-template-columns: repeat(3, 92px); gap: 10px; }
.nav-tile {
  display: flex; flex-direction: column; align-items: center; gap: 8px; padding: 14px 6px;
  background: var(--surface-2); border: 1px solid var(--border); border-radius: var(--radius);
  cursor: pointer; color: var(--text);
}
.nav-tile:hover { background: var(--surface-3); }
.nav-tile.active { border-color: var(--accent); color: var(--accent); }
.nav-tile-icon svg { width: var(--icon-lg); height: var(--icon-lg); }
.nav-tile-label { font-size: 0.72rem; text-align: center; line-height: 1.2; }
@media (max-width: 420px) { .nav-grid { grid-template-columns: repeat(2, 1fr); } .nav-menu { left: 16px; right: 16px; } }

/* ---- tab root ---- */
.tab-root { padding: 16px; }

/* ---- robot list ---- */
.robot-list-wrap { padding: 16px; }
.robot-list { list-style: none; margin: 0; padding: 0; display: grid; gap: 10px; max-width: 620px; }
.robot-item {
  width: 100%; display: flex; align-items: center; gap: 12px; text-align: left; cursor: pointer;
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 14px 16px; color: var(--text);
}
.robot-item:hover { border-color: var(--accent); }
.robot-name { font-weight: 700; font-size: 1.05rem; }
.robot-meta { color: var(--text-muted); }
.robot-status { margin-left: auto; display: inline-flex; align-items: center; gap: 6px; font-size: 0.78rem; padding: 2px 10px; border-radius: 999px; border: 1px solid var(--border); }
.robot-meta { color: var(--text-muted); font-size: 0.8rem; }

/* ---- robot-select at-a-glance badges (uplink · battery · WiFi + 5G signal) ---- */
.robot-badges { display: inline-flex; align-items: center; gap: 6px; flex-wrap: wrap; }
.robot-badge {
  display: inline-flex; align-items: center; gap: 4px; font-size: 0.74rem; line-height: 1;
  padding: 2px 7px; border-radius: 999px; border: 1px solid var(--border);
  background: var(--surface-2); color: var(--text); white-space: nowrap;
}
.robot-sig .robot-sig-icon { font-size: 0.72rem; }
.robot-sig-bars { display: inline-flex; align-items: flex-end; gap: 1px; height: 11px; }
.robot-sig-bar { width: 2px; background: var(--surface-3); border: 1px solid var(--border); border-radius: 1px; }
.robot-sig-bar:nth-child(1) { height: 30%; } .robot-sig-bar:nth-child(2) { height: 52%; }
.robot-sig-bar:nth-child(3) { height: 76%; } .robot-sig-bar:nth-child(4) { height: 100%; }
.robot-sig-dbm { font-variant-numeric: tabular-nums; color: var(--text-muted); }
.robot-sig.sig-ok .robot-sig-bar.on { background: var(--ok); border-color: var(--ok); }
.robot-sig.sig-warn .robot-sig-bar.on { background: var(--warn); border-color: var(--warn); }
.robot-sig.sig-bad .robot-sig-bar.on { background: var(--err); border-color: var(--err); }

/* ---- health status colours (shared) ---- */
.health-online { color: var(--ok); } .health-online.robot-status { border-color: var(--ok); }
.health-abnormal { color: var(--warn); } .health-abnormal.robot-status { border-color: var(--warn); }
.health-offline { color: var(--err); } .health-offline.robot-status { border-color: var(--err); }
.health-unknown { color: var(--text-muted); }
.health-dot { width: var(--dot); height: var(--dot); border-radius: 50%; background: var(--text-muted); display: inline-block; flex: 0 0 auto; }
.health-online .health-dot { background: var(--ok); }
.health-abnormal .health-dot { background: var(--warn); }
.health-offline .health-dot { background: var(--err); }

/* generic card */
.ss-card, .jv-panel, .cg-panel, .led-panel, .about-card {
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 14px; margin-bottom: 14px;
}

/* ===================== State Model ===================== */
.sm-grid { display: grid; grid-template-columns: 300px 1fr 320px; gap: 14px; align-items: start; }
@media (max-width: 1100px) { .sm-grid { grid-template-columns: 1fr 1fr; } .sm-center { grid-column: 1 / -1; order: -1; } }
@media (max-width: 720px) { .sm-grid { grid-template-columns: 1fr; } }

.sm-left-head { display: flex; align-items: center; justify-content: space-between; gap: 8px; margin-bottom: 8px; flex-wrap: wrap; }
.sm-sync { display: inline-flex; align-items: center; gap: 6px; font-size: 0.8rem; color: var(--text-muted); }
.sm-live { display: inline-flex; align-items: center; gap: 6px; font-size: 0.72rem; color: var(--text-muted); }
.sm-updated { font-variant-numeric: tabular-nums; }
.live-dot { width: var(--dot); height: var(--dot); border-radius: 50%; background: var(--ok); display: inline-block; flex: 0 0 auto; box-shadow: 0 0 0 0 rgba(63,185,80,.6); }
.live-dot.pulsing { animation: live-pulse 0.9s ease-out; }
@keyframes live-pulse {
  0% { box-shadow: 0 0 0 0 rgba(63,185,80,.6); transform: scale(1); }
  50% { transform: scale(1.35); }
  100% { box-shadow: 0 0 0 7px rgba(63,185,80,0); transform: scale(1); }
}
.jv-val.jv-changed { color: var(--accent); animation: jv-flash 0.7s ease-out; }
@keyframes jv-flash {
  0% { background: rgba(47,129,247,.35); }
  100% { background: transparent; }
}
.jv-panel { padding: 10px 12px; }
.jv-panel-head { display: flex; align-items: center; justify-content: space-between; margin-bottom: 6px; }
.joint-panel-status { font-size: 0.72rem; padding: 1px 8px; border: 1px solid var(--border); border-radius: 999px; }
.jv-rows { display: grid; gap: 3px; }
.jv-row { display: flex; justify-content: space-between; font-variant-numeric: tabular-nums; font-size: 0.85rem; }
.jv-name { color: var(--text-muted); }
.jv-val { font-weight: 600; }
.jv-vals { display: inline-flex; align-items: baseline; gap: 8px; }
.jv-metrics { display: inline-flex; gap: 6px; }
.jv-sub { font-size: 0.68rem; color: var(--text-muted); font-weight: 400; }
.jv-sub:empty { display: none; }

.sm-center-head { display: flex; align-items: center; justify-content: space-between; margin-bottom: 8px; }
.viewer-stage {
  position: relative; width: 100%; height: 460px; background: radial-gradient(circle at 50% 40%, #1b2430, #0d1117);
  border: 1px solid var(--border); border-radius: var(--radius); overflow: hidden;
}
.viewer-stage canvas { display: block; width: 100% !important; height: 100% !important; }
.viewer-status, .viewer-fallback {
  position: absolute; inset: 0; display: flex; flex-direction: column; align-items: center; justify-content: center;
  gap: 6px; color: var(--text-muted); text-align: center; padding: 20px;
}
.viewer-fallback-icon { font-size: 3rem; }

.cg-head { margin-bottom: 8px; }
.cg-cells { display: grid; grid-template-columns: 1fr 1fr; gap: 6px; }
.cg-cell { display: flex; align-items: center; gap: 7px; background: var(--surface-2); border: 1px solid var(--border); border-radius: var(--radius-sm); padding: 6px 8px; font-size: 0.78rem; }
.cg-label { flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.cg-status { font-size: 0.68rem; color: var(--text-muted); }
.cg-cell.health-online { border-color: rgba(63,185,80,.4); }
.cg-cell.health-abnormal { border-color: rgba(210,153,34,.4); }
.cg-cell.health-offline { border-color: rgba(248,81,73,.4); }

.led-head { display: flex; align-items: center; justify-content: space-between; margin-bottom: 8px; }
.led-current { font-size: 0.8rem; }
.led-state { font-weight: 600; color: var(--accent); }
.led-btns { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }

/* ===================== Joint Teach ===================== */
.jt-limbs, .jt-subtabs, .ss-subtabs { display: flex; gap: 6px; flex-wrap: wrap; margin-bottom: 12px; }
.jt-limb, .jt-subtab, .ss-subtab {
  background: var(--surface-2); border: 1px solid var(--border); border-radius: var(--radius-sm);
  padding: 6px 12px; cursor: pointer; color: var(--text); font: inherit;
}
.jt-limb.active, .jt-subtab.active, .ss-subtab.active { background: var(--accent); border-color: var(--accent); color: #fff; }
.jt-subtabs { border-bottom: 1px solid var(--border); padding-bottom: 12px; }
.jt-body { max-width: 720px; }
.stp-rows { display: grid; gap: 8px; margin-bottom: 14px; }
.stp-row { display: grid; grid-template-columns: 80px 1fr auto; align-items: center; gap: 10px; background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius-sm); padding: 8px 10px; }
.stp-name { font-weight: 600; }
.stp-cur { font-weight: 600; font-variant-numeric: tabular-nums; }
.stp-ctl { display: flex; align-items: center; gap: 6px; }
.stp-btn { width: var(--ctl-h); height: var(--ctl-h); display: inline-flex; align-items: center; justify-content: center; border: 1px solid var(--border); background: var(--surface-2); color: var(--text); border-radius: var(--radius-sm); cursor: pointer; font-size: 1.05rem; line-height: 1; touch-action: none; }
.stp-btn:hover:not(:disabled) { background: var(--surface-3); border-color: var(--accent); }
.stp-btn:disabled { opacity: 0.45; cursor: not-allowed; }
.stp-target { width: 84px; text-align: right; }
.jt-actions { display: flex; gap: 8px; flex-wrap: wrap; margin-top: 8px; }
.jt-hint, .jt-joint .muted { font-size: 0.78rem; color: var(--text-muted); }
.jt-joint h4 { margin-bottom: 10px; }
.det-grid { display: grid; gap: 6px; margin-bottom: 14px; max-width: 340px; }
.det-row { display: flex; justify-content: space-between; border-bottom: 1px dashed var(--border); padding: 4px 0; }
.det-label { color: var(--text-muted); }
.det-val { font-weight: 600; }
.det-ok { color: var(--ok); } .det-err { color: var(--err); }
.lim-block { margin-bottom: 12px; }
.lim-block h5 { color: var(--text-muted); margin-bottom: 6px; }
.lim-row { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
.lim-in { width: 90px; }

/* ===================== System Settings ===================== */
.ss-state { display: grid; grid-template-columns: 1fr 1fr; gap: 14px; align-items: start; }
@media (max-width: 720px) { .ss-state { grid-template-columns: 1fr; } }
.sys-rows, .pi-rows { display: grid; gap: 6px; }
.sys-row { display: grid; grid-template-columns: 1fr auto auto; align-items: center; gap: 10px; }
.sys-name { font-weight: 600; }
.sys-st { font-size: 0.8rem; padding: 1px 8px; border-radius: 999px; border: 1px solid var(--border); }
.sys-ok { color: var(--ok); border-color: rgba(63,185,80,.4); }
.sys-err { color: var(--err); border-color: rgba(248,81,73,.4); }
.sys-unknown { color: var(--text-muted); }
.pi-row { display: flex; justify-content: space-between; gap: 12px; border-bottom: 1px dashed var(--border); padding: 5px 0; }
.pi-label { color: var(--text-muted); }
.pi-val { font-weight: 600; font-variant-numeric: tabular-nums; text-align: right; word-break: break-word; }
.fps-list { display: grid; gap: 6px; }
.fps-row { display: grid; grid-template-columns: 1fr auto auto auto; gap: 10px; align-items: center; font-size: 0.85rem; }
.fps-codec { color: var(--text-muted); font-size: 0.72rem; }

/* ===================== Video Camera ===================== */
.vc-head { display: flex; align-items: center; gap: 14px; flex-wrap: wrap; margin-bottom: 12px; }
.vc-picker { display: flex; align-items: center; gap: 6px; }
.cam-select { min-width: 200px; }
.vc-status { font-size: 0.75rem; padding: 1px 8px; border-radius: 999px; border: 1px solid var(--border); color: var(--text-muted); }
.vc-connecting { color: var(--warn); border-color: rgba(210,153,34,.4); }
.vc-connected { color: var(--ok); border-color: rgba(63,185,80,.4); }
.vc-unavailable { color: var(--err); border-color: rgba(248,81,73,.4); }
.cam-badge2 { margin-left: auto; font-size: 0.75rem; color: var(--text-muted); }
.cam-stage {
  position: relative; width: 100%; max-width: 960px; aspect-ratio: 16 / 10; background: #05070a;
  border: 1px solid var(--border); border-radius: var(--radius); overflow: hidden; display: grid; place-items: center;
}
.cam-video { width: 100%; height: 100%; object-fit: contain; }
/* Shoulder cams: rotated 90° for upright display (client-side; JS sizes the box
   to the video aspect so the full image fits the stage — no crop). */
.cam-video.cam-rot90 { position: absolute; top: 50%; left: 50%; transform: translate(-50%, -50%) rotate(90deg); object-fit: contain; }
/* Hidden until a freshly-switched stream settles (skips reused-transceiver stale frames). */
.cam-video.cam-loading { opacity: 0; }
.cam-placeholder, .cam-h264 { display: flex; flex-direction: column; align-items: center; gap: 8px; color: var(--text-muted); text-align: center; padding: 20px; }
.cam-placeholder-icon { font-size: 2.4rem; }
.cam-h264-icon { font-size: 2.6rem; }

/* ===================== Data Collection / About ===================== */
.kpi-tiles { display: grid; grid-template-columns: repeat(auto-fit, minmax(120px, 1fr)); gap: 10px; }
.kpi-tile { background: var(--surface-2); border: 1px solid var(--border); border-radius: var(--radius-sm); padding: 12px; text-align: center; }
.kpi-value { display: block; font-size: 1.4rem; font-weight: 700; font-variant-numeric: tabular-nums; }
.kpi-label { display: block; font-size: 0.72rem; color: var(--text-muted); margin-top: 2px; }
.dc-wrap, .about-wrap, .ss-wrap, .jt-wrap, .vc-wrap { max-width: 1200px; }
.about-card { max-width: 560px; }
.about-brand h2 { color: var(--accent); }
.about-tag { color: var(--text-muted); margin-bottom: 12px; }
.about-links { margin-top: 14px; display: flex; gap: 14px; }
.cmd-note { font-size: 0.78rem; color: var(--warn); }

/* ---- toasts ---- */
.toast-stack { position: fixed; right: 16px; bottom: 16px; display: flex; flex-direction: column; gap: 8px; z-index: 200; max-width: min(92vw, 380px); }
.error-toast { background: var(--surface); border: 1px solid var(--border); border-left-width: 4px; border-radius: var(--radius-sm); padding: 10px 12px; box-shadow: var(--shadow); position: relative; }
.error-toast.sev-info { border-left-color: var(--accent); }
.error-toast.sev-warning { border-left-color: var(--warn); }
.error-toast.sev-error { border-left-color: var(--err); }
.error-toast.sev-critical { border-left-color: var(--crit); }
.error-message { margin: 0; }
.toast-close { position: absolute; top: 4px; right: 6px; background: none; border: none; color: var(--text-muted); font-size: 1.1rem; cursor: pointer; }

/* ---- error feed / rows (used by shared components if mounted) ---- */
.error-row { border: 1px solid var(--border); border-left-width: 4px; border-radius: var(--radius-sm); padding: 8px 10px; margin-bottom: 6px; }
.error-row.sev-critical { border-left-color: var(--crit); }
.error-row.sev-error { border-left-color: var(--err); }
.error-row.sev-warning { border-left-color: var(--warn); }
.error-row.sev-info { border-left-color: var(--accent); }
.error-code { font-weight: 700; }
.error-action { color: var(--text-muted); font-size: 0.82rem; }

/* ===================== Top-bar battery indicator ===================== */
/* RealMan-vendor-inspired: a horizontal battery shell that fills to SoC%,
   green (amber/red when low), blinking while charging. */
.batt-ind { display: inline-flex; align-items: center; gap: 2px; margin-left: 6px; }
.batt-shell {
  position: relative; width: 62px; height: 22px; border: 1.5px solid var(--text-muted);
  border-radius: 5px; overflow: hidden; background: var(--surface-2); display: inline-flex;
  align-items: center; justify-content: center;
}
.batt-cap { width: 4px; height: 10px; border-radius: 0 2px 2px 0; background: var(--text-muted); }
.batt-fill {
  position: absolute; left: 0; top: 0; bottom: 0; width: 0%;
  background: var(--ok); transition: width .5s ease, background .3s ease; z-index: 0;
}
.batt-pct { position: relative; z-index: 1; font-size: 0.72rem; font-weight: 700; font-variant-numeric: tabular-nums; color: var(--text); text-shadow: 0 0 3px rgba(0,0,0,.6); }
.batt-bolt { position: relative; z-index: 1; margin-left: 2px; font-size: 0.72rem; color: #fdf6b2; display: none; }
.batt-ind.charging .batt-bolt { display: inline; }
/* SoC banding drives the fill + shell colour. */
.batt-ind.soc-ok .batt-fill { background: var(--ok); }
.batt-ind.soc-ok .batt-shell { border-color: var(--ok); }
.batt-ind.soc-warn .batt-fill { background: var(--warn); }
.batt-ind.soc-warn .batt-shell { border-color: var(--warn); }
.batt-ind.soc-critical .batt-fill { background: var(--err); }
.batt-ind.soc-critical .batt-shell { border-color: var(--err); }
.batt-ind.soc-unknown .batt-fill { background: var(--text-muted); }
/* Blink while charging. */
.batt-ind.charging .batt-fill { animation: batt-charge 1.3s ease-in-out infinite; }
.batt-ind.charging .batt-shell { border-color: var(--ok); box-shadow: 0 0 0 0 rgba(63,185,80,.5); animation: batt-glow 1.3s ease-in-out infinite; }
@keyframes batt-charge { 0%,100% { opacity: 1; } 50% { opacity: .55; } }
@keyframes batt-glow { 0% { box-shadow: 0 0 0 0 rgba(63,185,80,.5); } 70% { box-shadow: 0 0 0 6px rgba(63,185,80,0); } 100% { box-shadow: 0 0 0 0 rgba(63,185,80,0); } }
@media (prefers-reduced-motion: reduce) {
  .batt-ind.charging .batt-fill, .batt-ind.charging .batt-shell { animation: none; }
}

/* ===================== System Settings — extra cards ===================== */
.ss-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(280px, 1fr)); gap: 14px; align-items: start; }
.chg-badge { font-weight: 700; }
.chg-active { color: var(--ok); }
.chg-ok { color: var(--ok); }
.chg-idle { color: var(--text-muted); }
.chg-fault { color: var(--err); }
.chg-unknown { color: var(--text-muted); }
.pi-val.pi-warn { color: var(--warn); }
.pi-val.pi-err { color: var(--err); }
.pi-val.pi-ok { color: var(--ok); }
.pi-val.pi-stale, .sys-st.pi-stale, .chg-badge.pi-stale { color: var(--text-muted); }
.ss-card h3 .card-sub { font-weight: 400; font-size: 0.75rem; color: var(--text-muted); margin-left: 8px; }

/* ---- per-component DISCONNECTED (explicit none-marker in a fresh package) ---- */
/* Distinct from the whole-view stale blank: the package IS arriving, but this
   one subsystem reports disconnected. Muted amber pill on the card header. */
.card-disc {
  display: inline-block; margin-left: 8px; padding: 1px 7px;
  font-size: 0.66rem; font-weight: 700; letter-spacing: .04em;
  color: var(--warn); background: var(--warn-bg);
  border: 1px solid var(--warn); border-radius: 999px; vertical-align: middle;
}
.card-disc[hidden] { display: none; }
.card-disc-note { color: var(--text-muted); font-style: italic; }
.batt-ind.disconnected .batt-shell { border-color: var(--warn); border-style: dashed; }
.batt-ind.disconnected .batt-pct { color: var(--warn); }
.compute-node-head {
  display: flex; align-items: center; justify-content: space-between;
  margin: 8px 0 2px; font-weight: 700; border-top: 1px solid var(--border);
  padding-top: 6px;
}
.compute-node-head:first-child { border-top: none; padding-top: 0; }
.compute-node-src { font-weight: 400; font-size: 0.7rem; color: var(--text-muted); }

/* ---- stale / no-data banner (status page) ---- */
.ss-state-wrap { display: grid; gap: 14px; }
.ss-stale-banner {
  display: flex; align-items: center; gap: 8px; padding: 8px 12px;
  background: var(--err-bg); border: 1px solid var(--err); border-radius: var(--radius-sm);
  color: var(--crit); font-weight: 600;
}
.ss-stale-dot { width: var(--dot); height: var(--dot); border-radius: 50%; background: var(--err); animation: batt-charge 1.1s ease-in-out infinite; }
@media (prefers-reduced-motion: reduce) { .ss-stale-dot { animation: none; } }

/* ---- top-bar Emergency Stop (always visible) ---- */
.tb-estop-wrap { display: inline-flex; align-items: center; margin-right: 4px; }
/* E-STOP: deliberately prominent (bold, red, a touch taller) but on-scale. */
.tb-estop { min-height: var(--ctl-h-lg); font-weight: 800; letter-spacing: .05em; text-transform: uppercase; font-size: var(--ctl-font); padding: 0 16px; border-radius: var(--radius-sm); }
.tb-estop-engage { background: var(--err); border-color: var(--err); color: #fff; box-shadow: 0 0 0 1px rgba(248,81,73,.35); }
.tb-estop-engage:hover:not(:disabled) { background: #d5372f; border-color: #d5372f; }
.tb-estop-release { background: var(--warn-bg); border: 2px solid var(--warn); color: var(--warn); }
.tb-estop-release:hover:not(:disabled) { background: #3a3110; }
/* pulse the RELEASE button while the e-stop latch is engaged (attention cue) */
.tb-estop-wrap.engaged .tb-estop-release { animation: batt-glow 1.3s ease-in-out infinite; box-shadow: 0 0 0 0 rgba(210,153,34,.5); }
@media (prefers-reduced-motion: reduce) { .tb-estop-wrap.engaged .tb-estop-release { animation: none; } }

/* ---- trolley bumper / pipe indicators ---- */
.tind-sub { color: var(--text-muted); margin: 12px 0 6px; }
.tind-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(120px, 1fr)); gap: 8px; }
.tind-row { display: flex; align-items: center; justify-content: space-between; gap: 8px; padding: 6px 8px; background: var(--surface-2); border: 1px solid var(--border); border-radius: var(--radius-sm); }
.tind-label { color: var(--text-muted); font-size: 0.85rem; }
.tind { font-weight: 700; font-size: 0.82rem; padding: 1px 8px; border-radius: 999px; border: 1px solid var(--border); }
.tind-ok { color: var(--ok); border-color: rgba(63,185,80,.4); }
.tind-bad { color: #fff; background: var(--err); border-color: var(--err); }
.tind-unknown, .tind-stale { color: var(--text-muted); }

/* ===================== Status page (redesign) ===================== */
.status-wrap { max-width: 1200px; }
.kv-card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 14px; margin-bottom: 14px; }
/* The key-state tiles are sized to sit on ONE line at desktop width (see the
   >=1000px rule below, which pins them to a single 8-up row); on narrower/phone
   widths they wrap gracefully via the auto-fit floor + the media queries. */
.kv-strip { display: grid; grid-template-columns: repeat(auto-fit, minmax(104px, 1fr)); gap: 6px; }
.kv-stat { display: flex; flex-direction: column; gap: 1px; background: var(--surface-2); border: 1px solid var(--border); border-radius: var(--radius-sm); padding: 6px 8px; min-width: 0; }
.kv-stat-label { font-size: 0.56rem; color: var(--text-muted); text-transform: uppercase; letter-spacing: .04em; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.kv-stat-val { font-size: 0.92rem; font-weight: 700; font-variant-numeric: tabular-nums; line-height: 1.15; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.kv-stat-sub { font-size: 0.62rem; color: var(--text-muted); font-variant-numeric: tabular-nums; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
/* Desktop: guarantee all key-state tiles on a single no-wrap line. */
@media (min-width: 1000px) { .kv-strip { grid-template-columns: repeat(8, minmax(0, 1fr)); } }
.kv-stat.kv-ok .kv-stat-val { color: var(--ok); }
.kv-stat.kv-bad .kv-stat-val { color: var(--err); }
.kv-stat.kv-warn .kv-stat-val { color: var(--warn); }
.kv-stat.kv-muted .kv-stat-val, .kv-stat.kv-stale .kv-stat-val { color: var(--text-muted); }
.kv-stat.kv-bad { border-color: rgba(248,81,73,.5); }
/* signal-bar glyph */
.kv-sig { display: flex; align-items: center; gap: 5px; min-width: 0; }
.kv-sig .kv-stat-val { min-width: 0; }
.kv-bars { display: inline-flex; align-items: flex-end; gap: 2px; height: 15px; flex: 0 0 auto; }
.kv-bar { width: 3px; background: var(--surface-3); border: 1px solid var(--border); border-radius: 1px; }
.kv-bar:nth-child(1) { height: 30%; } .kv-bar:nth-child(2) { height: 52%; }
.kv-bar:nth-child(3) { height: 76%; } .kv-bar:nth-child(4) { height: 100%; }
.kv-bar.on { background: var(--ok); border-color: var(--ok); }
.kv-stat.kv-warn .kv-bar.on { background: var(--warn); border-color: var(--warn); }
.kv-stat.kv-bad .kv-bar.on { background: var(--err); border-color: var(--err); }

.status-grid { display: grid; grid-template-columns: minmax(300px, 360px) 1fr; gap: 14px; align-items: start; }
.status-col { display: grid; gap: 14px; align-content: start; }
@media (max-width: 860px) { .status-grid { grid-template-columns: 1fr; } }

/* ---- drive controls (motion — guarded) ---- */
.drive-card { background: var(--surface); border: 1px solid var(--border); border-top: 3px solid var(--warn); border-radius: var(--radius); padding: 14px; }
.drive-head { display: flex; align-items: center; justify-content: space-between; gap: 8px; margin-bottom: 4px; flex-wrap: wrap; }
.drive-mode { font-size: 0.82rem; }
.drive-mode-val { font-weight: 700; }
.drive-mode-val.kv-ok { color: var(--ok); } .drive-mode-val.kv-warn { color: var(--warn); } .drive-mode-val.kv-stale { color: var(--text-muted); }
.drive-warn { font-size: 0.78rem; color: var(--warn); margin: 4px 0 12px; }
.drive-pad {
  display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px;
  grid-template-areas: ". fwd ." "left . right" ". back ."; max-width: 216px; margin: 0 auto;
}
.drive-fwd { grid-area: fwd; } .drive-back { grid-area: back; }
.drive-left { grid-area: left; } .drive-right { grid-area: right; }
.drive-btn {
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 2px;
  min-height: var(--ctl-h-lg); border: 1px solid var(--border); background: var(--surface-2); color: var(--text);
  border-radius: var(--radius-sm); cursor: pointer; font: inherit; padding: 6px;
  user-select: none; -webkit-user-select: none; touch-action: none;
}
.drive-btn:hover:not(:disabled) { background: var(--surface-3); border-color: var(--accent); }
.drive-btn:active:not(:disabled) { background: var(--accent); border-color: var(--accent); color: #fff; }
.drive-btn:disabled { opacity: 0.45; cursor: not-allowed; }
.drive-glyph { font-size: 1rem; line-height: 1; }
.drive-label { font-size: 0.68rem; }
.drive-card .jt-speed { margin-top: 14px; }

/* ===================== Joint Teach — avatar side-by-side ===================== */
.jt-layout { display: grid; grid-template-columns: minmax(0, 1fr) minmax(300px, 440px); gap: 16px; align-items: start; }
.jt-main { min-width: 0; }
.jt-viewer { position: sticky; top: 62px; }
.jt-viewer-head { margin-bottom: 8px; }
.jt-viewer-stage { height: 460px; }
/* Live avatar on the Status page (same viewer as Joint Teach). */
.status-avatar { padding: 12px; }
.status-viewer-stage { height: 340px; }
@media (max-width: 900px) {
  .jt-layout { grid-template-columns: 1fr; }
  .jt-viewer { position: static; order: -1; }
  .jt-viewer-stage { height: 300px; }
  .status-viewer-stage { height: 280px; }
}

/* ===================== Mobile / responsive polish ===================== */
html, body { overflow-x: hidden; }        /* belt-and-braces: never scroll sideways */
img, canvas, svg, video { max-width: 100%; }

@media (max-width: 720px) {
  .tab-root { padding: 12px; }
  .topbar { padding: 8px 12px; gap: 8px 10px; }
  .topbar-center { order: 3; width: 100%; gap: 8px 16px; }
  .topbar-right { gap: 8px; }
  .rc-status { font-size: 0.8rem; }
  .user-badge { display: none; }           /* role is enforced server-side */
  .robot-list-wrap { padding: 12px; }
  .kv-strip { grid-template-columns: repeat(auto-fit, minmax(120px, 1fr)); }
  .jt-body { max-width: 100%; }
  .stp-target { width: 68px; }
  .led-btns { grid-template-columns: 1fr 1fr; }
}

@media (max-width: 480px) {
  .brand-word { display: none; }           /* keep the logo mark only */
  .topbar { gap: 6px 8px; }
  .topbar-left { gap: 8px; }
  .conn-pill { display: none; }            /* the E-STOP + battery stay */
  /* touch targets: every control is >= 44px on a phone */
  .btn, .btn.cmd, .drive-btn, .stp-btn,
  .jt-limb, .jt-subtab, .ss-subtab, .nav-grid-btn, select { min-height: var(--tap); }
  .stp-btn { width: var(--tap); }
  .tb-estop { min-height: var(--tap); padding: 0 14px; }
  .kv-strip { grid-template-columns: 1fr 1fr; }
  .kv-stat-val { font-size: 1.05rem; }
  .nav-grid { grid-template-columns: repeat(2, 1fr); }
  .cg-cells { grid-template-columns: 1fr; }
  .drive-pad { max-width: 260px; }
  .stp-row { grid-template-columns: 64px 1fr auto; gap: 6px; }
  .jt-actions .btn, .drive-card .btn { flex: 1 1 auto; }
}

@media (max-width: 380px) {
  .kv-strip { grid-template-columns: 1fr; }
  .robot-pill { padding: 3px 8px; }
}

/* --- merged point cloud view (components/cloud-view.mjs) -------------------- */
.cloud-wrap { display: flex; flex-direction: column; width: 100%; height: 100%; min-height: 320px; }
.cloud-bar { display: flex; gap: 14px; align-items: center; flex-wrap: wrap; padding: 6px 8px; }
.cloud-bar label { display: flex; gap: 5px; align-items: center; font-size: 12px; color: var(--muted, #9aa); }
.cloud-select { font: inherit; }
.cloud-host { position: relative; flex: 1; min-height: 280px; background: #0c0c0e; border-radius: 6px; overflow: hidden; }
.cloud-canvas { display: block; width: 100%; height: 100%; cursor: grab; }
.cloud-canvas:active { cursor: grabbing; }
