/*
 * components.css — shared component vocabulary for the ToroBio web app
 * (issue #4, Phase 0). Depends on tokens.css. No raw colors here — only
 * semantic tokens, so a theme swap is a tokens.css concern.
 *
 * Vocabulary intentionally mirrors nest-ble-desktop so the two products can
 * converge (FRONTEND_CONVERGENCE.md, Phase 6 back-port):
 *   .app-shell .nav-rail .card .tile .pill .btn .play-btn .summary-tile
 *   .device-tile .chip .progress .status-dot
 */

/* ----------------------------------------------------------------- reset-ish */
*, *::before, *::after { box-sizing: border-box; }

body {
  margin: 0;
  font-family: var(--font-sans);
  font-size: var(--fs-md);
  color: var(--text-body);
  background: var(--surface-page);
  -webkit-font-smoothing: antialiased;
}

a { color: var(--brand); text-decoration: none; }
a:hover { text-decoration: underline; }

/* ---------------------------------------------------------- accessibility
 * Keyboard-visible focus ring on every interactive element (Phase 6 a11y). Uses
 * :focus-visible so mouse clicks don't draw a ring but Tab navigation does.
 */
:focus-visible {
  outline: 2px solid var(--brand);
  outline-offset: 2px;
  border-radius: var(--radius-sm);
}
/* Elements that manage their own focus affordance opt out of the generic ring. */
.text-input:focus-visible, .rename-input:focus-visible,
#main-content:focus-visible { outline: none; }

/* Skip link: off-screen until focused, then pinned top-left over the content. */
.skip-link {
  position: fixed; top: var(--space-2); left: var(--space-2);
  z-index: var(--z-toast);
  transform: translateY(-150%);
  padding: var(--space-2) var(--space-4);
  background: var(--brand); color: var(--text-onbrand);
  border-radius: var(--radius-md); font-weight: var(--fw-medium);
}
.skip-link:focus { transform: translateY(0); text-decoration: none; }

/* Respect users who ask for less motion — kill transitions/animations. */
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    transition-duration: 0.01ms !important;
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
    scroll-behavior: auto !important;
  }
}

/* ------------------------------------------------------------- app shell */
.app-shell {
  display: grid;
  grid-template-columns: var(--nav-rail-w) 1fr;
  min-height: 100vh;
}

.app-main {
  min-width: 0; /* let grid children shrink so tiles can wrap */
  padding: var(--space-6) var(--space-8) var(--space-12);
}

.app-content { max-width: var(--content-max); margin: 0 auto; }

/* --------------------------------------------------------------- nav rail */
.nav-rail {
  position: sticky;
  top: 0;
  align-self: start;
  height: 100vh;
  background: var(--surface-nav);
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: var(--space-2);
  padding: var(--space-4) 0;
  z-index: var(--z-nav);
}

.nav-rail__spacer { flex: 1 1 auto; }

.nav-item {
  width: 60px;
  padding: var(--space-2) 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 4px;
  border-radius: var(--radius-md);
  color: var(--text-muted);
  font-size: var(--fs-xs);
  font-weight: var(--fw-medium);
  text-align: center;
  transition: background 0.12s ease, color 0.12s ease;
}
.nav-item:hover { background: var(--surface-sunken); color: var(--text-body); text-decoration: none; }
.nav-item svg { width: 22px; height: 22px; display: block; }

.nav-item--active {
  background: var(--brand);
  color: var(--text-onbrand);
}
.nav-item--active:hover { background: var(--brand-strong); color: var(--text-onbrand); }

/* --------------------------------------------------------------- page head */
.page-head { text-align: center; margin-bottom: var(--space-6); }
.page-head__title {
  color: var(--brand);
  font-size: var(--fs-2xl);
  font-weight: var(--fw-bold);
  margin: 0;
}
.page-head__subtitle { color: var(--text-muted); font-size: var(--fs-md); margin-top: var(--space-1); }

/* ------------------------------------------------------------------- card */
.card {
  background: var(--surface-card);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-sm);
}

/* ---------------------------------------------------------- summary tiles */
.summary-grid {
  display: grid;
  grid-template-columns: repeat(5, 1fr);
  gap: var(--space-4);
  margin-bottom: var(--space-6);
}
.summary-tile {
  background: var(--surface-card);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-sm);
  padding: var(--space-5) var(--space-6);
  cursor: pointer;
  transition: box-shadow 0.12s ease, border-color 0.12s ease;
}
.summary-tile:hover { box-shadow: var(--shadow-md); }
.summary-tile--active { border-color: var(--brand); box-shadow: 0 0 0 1px var(--brand) inset; }
.summary-tile__value { font-size: var(--fs-3xl); font-weight: var(--fw-bold); line-height: 1; color: var(--text-strong); }
.summary-tile__label { margin-top: var(--space-2); font-size: var(--fs-lg); color: var(--text-body); }
.summary-tile--running .summary-tile__value { color: var(--status-running); }
.summary-tile--paused  .summary-tile__value { color: var(--status-paused); }
.summary-tile--error   .summary-tile__value { color: var(--status-error); }
.summary-tile--disconnected .summary-tile__value { color: var(--text-muted); }

/* -------------------------------------------------------------- filter row */
.filter-row {
  display: flex;
  align-items: center;
  gap: var(--space-4);
  margin-bottom: var(--space-4);
}
.chips { display: flex; gap: var(--space-4); flex-wrap: wrap; }
.chip {
  display: inline-flex; align-items: baseline; gap: 6px;
  font-size: var(--fs-md);
  color: var(--text-muted);
  background: none; border: none; cursor: pointer; padding: 4px 2px;
}
.chip b { color: var(--text-strong); font-weight: var(--fw-semibold); }
.chip--active { color: var(--brand); }
.chip--active b { color: var(--brand); }
.filter-row__spacer { flex: 1 1 auto; }

/* view toggle (list/grid) */
.view-toggle { display: inline-flex; border: 1px solid var(--border); border-radius: var(--radius-md); overflow: hidden; }
.view-toggle button {
  border: none; background: var(--surface-card); color: var(--text-muted);
  padding: 6px 10px; cursor: pointer; display: grid; place-items: center;
}
.view-toggle button.is-active { background: var(--brand); color: var(--text-onbrand); }
.view-toggle svg { width: 16px; height: 16px; }

/* --------------------------------------------------------------- pill/dot */
.status-dot { width: 11px; height: 11px; border-radius: var(--radius-pill); flex: 0 0 auto; display: inline-block; }
.status-dot--running { background: var(--status-running); }
.status-dot--paused { background: var(--status-paused); }
.status-dot--error { background: var(--status-error); }
.status-dot--disconnected { background: var(--status-disconnected); }

.pill {
  display: inline-flex; align-items: center; gap: 6px;
  padding: 2px 10px; border-radius: var(--radius-pill);
  font-size: var(--fs-xs); font-weight: var(--fw-semibold); text-transform: uppercase; letter-spacing: 0.03em;
}
.pill--running { background: var(--status-running-soft); color: var(--status-running); }
.pill--paused { background: var(--status-paused-soft); color: var(--status-paused); }
.pill--error { background: var(--status-error-soft); color: var(--status-error); }
.pill--disconnected { background: var(--status-disconnected-soft); color: var(--text-muted); }

/* ---------------------------------------------------------------- buttons */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  font: inherit; font-weight: var(--fw-medium); white-space: nowrap;
  padding: 8px 14px; border-radius: var(--radius-md);
  border: 1px solid var(--border-strong); background: var(--surface-card); color: var(--text-body);
  cursor: pointer; transition: background 0.12s ease, border-color 0.12s ease;
}
.btn:hover { background: var(--surface-sunken); text-decoration: none; }
.btn svg { width: 16px; height: 16px; flex: 0 0 auto; }
.btn--primary { background: var(--brand); border-color: var(--brand); color: var(--text-onbrand); }
.btn--primary:hover { background: var(--brand-strong); }

.icon-btn {
  width: 38px; height: 38px; display: grid; place-items: center;
  border: 1px solid var(--border); border-radius: var(--radius-md);
  background: var(--surface-card); color: var(--text-muted); cursor: pointer;
}
.icon-btn:hover { background: var(--surface-sunken); color: var(--text-body); text-decoration: none; }
.icon-btn svg { width: 18px; height: 18px; }

/* play/pause control (mockup: solid blue circle) */
.play-btn {
  width: 52px; height: 52px; border-radius: var(--radius-pill);
  border: none; background: var(--brand); color: var(--text-onbrand);
  display: grid; place-items: center; cursor: pointer;
  transition: background 0.12s ease, transform 0.06s ease;
}
.play-btn:hover { background: var(--brand-strong); }
.play-btn:active { transform: scale(0.96); }
.play-btn:disabled { background: var(--status-disconnected); cursor: not-allowed; opacity: 0.7; }
.play-btn svg { width: 22px; height: 22px; }
/* Both glyphs are rendered; show the correct one for the tile's run-state so
 * live polling can flip it with a class change (no SVG injection in JS). */
.play-btn__icon { display: grid; place-items: center; }
.play-btn__icon--pause { display: none; }
/* keyed on data-moving (actual motion), NOT run-state color, so an errored-but-
 * spinning device still shows a pause button. */
.device-tile[data-moving="1"] .play-btn__icon--play { display: none; }
.device-tile[data-moving="1"] .play-btn__icon--pause { display: grid; }
/* Commanded, but the device has not reported the change yet (4-6s on a virtual
 * fleet, up to a publish interval on real hardware). The glyph already shows the
 * commanded action; this pulse says "accepted, not yet confirmed" so the press
 * reads as having landed and nobody presses twice. */
.device-tile[data-pending="1"] .play-btn { animation: play-btn-pending 1.1s ease-in-out infinite; }
@keyframes play-btn-pending {
  0%, 100% { opacity: 1; }
  50%      { opacity: 0.55; }
}
@media (prefers-reduced-motion: reduce) {
  .device-tile[data-pending="1"] .play-btn { animation: none; opacity: 0.7; }
}

/* Spinner inside the play button while the request itself is on the wire. The
 * glyph is replaced (not merely dimmed) so "sending" is never mistaken for
 * "sent". */
.play-btn__icon--busy {
  width: 22px; height: 22px; border-radius: var(--radius-pill);
  border: 3px solid rgba(255, 255, 255, 0.35); border-top-color: var(--text-onbrand);
  animation: chart-spin 0.7s linear infinite;
  display: none;
}
.device-tile[data-busy="1"] .play-btn__icon--play,
.device-tile[data-busy="1"] .play-btn__icon--pause { display: none; }
.device-tile[data-busy="1"] .play-btn__icon--busy { display: block; }

/* ------------------------------------------------- command progress banner */
.cmd-status {
  grid-column: 1 / -1;          /* full tile width, below the control row */
  display: flex; align-items: center; gap: var(--space-3);
  margin-top: var(--space-2);
  font-size: var(--fs-sm); color: var(--text-muted);
}
.cmd-status[hidden] { display: none; }
.cmd-status__text { flex: 0 0 auto; }
.cmd-status .progress { flex: 1 1 auto; min-width: 60px; }
/* Terminal states: the bar is gone, only the outcome remains. */
.cmd-status--warn .cmd-status__text { color: var(--status-error); }
.cmd-status--ok .cmd-status__text { color: var(--status-running); }

/* A speed typed but not yet applied. Marked so it is obvious the number on
 * screen is not what the device has been told. */
.text-input--staged {
  border-color: var(--brand);
  box-shadow: 0 0 0 1px var(--brand) inset;
}

/* -------------------------------------------------------------- text field */
.field-label { font-size: var(--fs-sm); color: var(--text-muted); margin-bottom: 4px; }
.text-input {
  width: 100%; font: inherit; padding: 8px 10px;
  border: 1px solid var(--border-strong); border-radius: var(--radius-md);
  background: var(--surface-card); color: var(--text-strong);
}
.text-input:focus { outline: none; border-color: var(--brand); box-shadow: 0 0 0 3px var(--brand-ring); }

/* --------------------------------------------------------------- progress */
.progress { height: 6px; border-radius: var(--radius-pill); background: var(--surface-sunken); overflow: hidden; }
.progress__bar { height: 100%; background: var(--brand); border-radius: var(--radius-pill); }
/* Indeterminate: we cannot know how long a device will take to acknowledge, so
 * the bar expresses "in progress", never a fake percentage. */
.progress--indeterminate .progress__bar {
  width: 40%;
  animation: progress-slide 1.2s ease-in-out infinite;
}
@keyframes progress-slide {
  0%   { transform: translateX(-100%); }
  100% { transform: translateX(250%); }
}
@media (prefers-reduced-motion: reduce) {
  .progress--indeterminate .progress__bar { animation: none; width: 100%; opacity: 0.5; }
}

/* ----------------------------------------------------------- device tiles */
.device-list { display: flex; flex-direction: column; gap: var(--space-3); }

.device-tile {
  background: var(--surface-card);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-sm);
  padding: var(--space-4) var(--space-5);
  display: grid;
  /* The sensors track is the moldable one: a 2-channel thermometer and a
     6-channel iNest (3 temps + hum + fan + motor) both land here, so it gets
     the largest share and the cluster inside wraps instead of overflowing. */
  grid-template-columns:
    minmax(200px, 1.3fr)   /* identity */
    minmax(120px, 0.85fr)  /* speed input */
    auto                   /* play */
    minmax(88px, 0.6fr)    /* current rpm */
    minmax(168px, 1.9fr)   /* sensors */
    minmax(120px, 0.8fr)   /* elapsed */
    minmax(112px, 0.7fr)   /* last updated */
    auto;                  /* analytics */
  gap: var(--space-4);
  align-items: center;
}
/* Text cells may be squeezed to their track; the round buttons keep their size. */
.device-tile > *:not(.play-btn):not(.icon-btn) { min-width: 0; }
.device-tile--disconnected { opacity: 0.72; }
.device-tile--selected { border-color: var(--brand); box-shadow: 0 0 0 1px var(--brand) inset; }

/* multi-select (Phase 5 bulk edit) */
.tile-select { width: 16px; height: 16px; margin-top: 3px; flex: 0 0 auto; cursor: pointer; accent-color: var(--brand); }

.bulk-bar {
  display: flex; align-items: center; gap: var(--space-3);
  padding: var(--space-3) var(--space-4); margin-bottom: var(--space-4);
  background: var(--brand-soft); border: 1px solid var(--brand);
  border-radius: var(--radius-md);
}
.bulk-bar[hidden] { display: none; }
.bulk-bar__count { color: var(--text-body); }
.bulk-bar__count b { color: var(--brand-strong); font-weight: var(--fw-bold); }
.bulk-bar__spacer { flex: 1 1 auto; }

.device-id-cell { display: flex; align-items: flex-start; gap: var(--space-3); min-width: 0; }
.device-id-cell__body { min-width: 0; }
.device-name { display: flex; align-items: center; gap: 8px; font-weight: var(--fw-bold); color: var(--text-strong); }
.device-name .transport-icon { color: var(--text-faint); width: 14px; height: 14px; }
.device-project { font-size: var(--fs-sm); color: var(--text-body); }
.device-id { font-size: var(--fs-xs); color: var(--text-faint); }

.metric { display: flex; flex-direction: column; gap: 2px; }
.metric__label { font-size: var(--fs-xs); color: var(--text-muted); text-transform: uppercase; letter-spacing: 0.03em; }
.metric__value { font-size: var(--fs-xl); font-weight: var(--fw-bold); color: var(--text-strong); }
.metric__value--error { color: var(--status-error); }
.metric__unit { font-size: var(--fs-xs); color: var(--text-muted); font-weight: var(--fw-medium); }

/* Sensor readouts are driven by the device's capability manifest, so the count
   is unknown at design time: wrap onto extra lines rather than spilling over
   the neighbouring cells. `min-width: 0` keeps the flex content from forcing
   the grid track wider than its share. */
.sensor-pair {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(76px, 1fr));
  gap: var(--space-2) var(--space-3);
  min-width: 0;
}
.sensor { display: flex; flex-direction: column; min-width: 0; }
.sensor__label { font-size: var(--fs-xs); color: var(--text-muted); white-space: nowrap; }
.sensor__value { font-size: var(--fs-md); font-weight: var(--fw-semibold); color: var(--text-strong); white-space: nowrap; }

.elapsed__top { display: flex; justify-content: space-between; font-size: var(--fs-xs); }
.elapsed__time { font-weight: var(--fw-semibold); color: var(--text-strong); }
.elapsed__pct { color: var(--text-muted); }
.elapsed__label { font-size: var(--fs-xs); color: var(--text-muted); margin: 2px 0 4px; }

.updated { text-align: left; }
.updated__label { font-size: var(--fs-xs); color: var(--text-muted); }
.updated__ago { font-size: var(--fs-md); font-weight: var(--fw-bold); }
.updated__ago--stale { color: var(--status-paused); }
.updated__ago--fresh { color: var(--text-strong); }
.updated__via { font-size: var(--fs-xs); color: var(--text-faint); }

/* ----------------------------------------------------------- empty states */
.empty-state {
  text-align: center; padding: var(--space-12) var(--space-6);
  color: var(--text-muted);
}
.empty-state__title { font-size: var(--fs-xl); font-weight: var(--fw-semibold); color: var(--text-body); margin-bottom: var(--space-2); }

/* stub "coming soon" page */
.stub {
  max-width: 520px; margin: 12vh auto 0; text-align: center;
  color: var(--text-muted);
}
.stub__icon { color: var(--text-faint); margin-bottom: var(--space-4); }
.stub__icon svg { width: 48px; height: 48px; }
.stub h1 { color: var(--text-strong); font-size: var(--fs-2xl); margin: 0 0 var(--space-2); }

/* ---------------------------------------------------------------- modal */
.modal-overlay {
  position: fixed; inset: 0; z-index: var(--z-toast);
  background: rgba(17, 24, 39, 0.45);
  display: grid; place-items: center; padding: var(--space-4);
}
.modal-overlay[hidden] { display: none; }
.modal {
  background: var(--surface-card); border-radius: var(--radius-lg);
  box-shadow: var(--shadow-lg); width: 100%; max-width: 420px; overflow: hidden;
}
.modal__header { padding: var(--space-5) var(--space-6) 0; }
.modal__title { margin: 0; font-size: var(--fs-xl); font-weight: var(--fw-semibold); color: var(--text-strong); }
.modal__body { padding: var(--space-4) var(--space-6); color: var(--text-body); }
.modal__body p { margin: 0; }
.modal__body .field-label { margin-top: var(--space-3); }
.modal__body .field-label:first-child { margin-top: 0; }
.modal__footer { display: flex; justify-content: flex-end; gap: var(--space-2); padding: var(--space-3) var(--space-6) var(--space-5); }
textarea.text-input { resize: vertical; min-height: 76px; font-family: inherit; }

/* inline rename affordance */
.device-name__text { cursor: default; }
.device-tile[data-can-control="1"] .device-name__text { cursor: text; }
.device-name__text.is-editing { display: none; }
.rename-input {
  font: inherit; font-weight: var(--fw-bold); color: var(--text-strong);
  border: 1px solid var(--brand); border-radius: var(--radius-sm);
  padding: 1px 6px; max-width: 180px;
}
.rename-input:focus { outline: none; box-shadow: 0 0 0 3px var(--brand-ring); }
.device-edit-btn {
  margin-left: 6px; border: none; background: none; color: var(--text-faint);
  cursor: pointer; padding: 2px; border-radius: var(--radius-sm);
  opacity: 0; transition: opacity 0.12s ease, color 0.12s ease;
}
.device-edit-btn svg { width: 15px; height: 15px; display: block; }
.device-tile:hover .device-edit-btn { opacity: 1; }
.device-edit-btn:hover { color: var(--brand); background: var(--surface-sunken); }

/* ---------------------------------------------------------------- toasts */
.toasts { position: fixed; top: var(--space-4); right: var(--space-4); display: flex; flex-direction: column; gap: var(--space-2); z-index: var(--z-toast); }
.toast {
  background: var(--surface-card); border: 1px solid var(--border); border-left-width: 4px;
  border-radius: var(--radius-md); box-shadow: var(--shadow-lg);
  padding: var(--space-3) var(--space-4); font-size: var(--fs-sm); color: var(--text-body); max-width: 360px;
}
.toast--success { border-left-color: var(--status-running); }
.toast--error { border-left-color: var(--status-error); }
.toast--warning { border-left-color: var(--status-paused); }
.toast--info { border-left-color: var(--brand); }

/* --------------------------------------------------------- analytics page */
.analytics-head {
  display: flex; align-items: center; gap: var(--space-4);
  margin-bottom: var(--space-6);
}
.analytics-close {
  display: inline-flex; align-items: center; gap: 4px;
  color: var(--text-body); font-weight: var(--fw-medium);
}
.analytics-close:hover { color: var(--text-strong); text-decoration: none; }
.analytics-close svg { width: 22px; height: 22px; }
.analytics-head__titles { flex: 1 1 auto; text-align: center; }
.analytics-head__spacer { width: 80px; }

.analytics-cards {
  display: grid; grid-template-columns: repeat(4, 1fr);
  gap: var(--space-4); margin-bottom: var(--space-6);
}
.stat-card { padding: var(--space-4) var(--space-5); }
.stat-card__label { font-size: var(--fs-xs); font-weight: var(--fw-semibold); color: var(--text-muted); letter-spacing: 0.05em; }
.stat-card__value { display: flex; align-items: center; gap: 8px; margin-top: var(--space-2); font-size: var(--fs-2xl); font-weight: var(--fw-bold); color: var(--text-strong); }
.stat-card__value--sm { font-size: var(--fs-lg); }
.stat-card__unit { font-size: var(--fs-sm); font-weight: var(--fw-medium); color: var(--text-muted); }
.stat-card__sub { margin-top: var(--space-1); font-size: var(--fs-xs); color: var(--text-muted); }
.stat-card__sensors { display: flex; flex-wrap: wrap; gap: var(--space-2) var(--space-6); margin-top: var(--space-3); }
.stat-status-text { text-transform: capitalize; }
.stat-status-text--running { color: var(--status-running); }
.stat-status-text--paused { color: var(--status-paused); }
.stat-status-text--error { color: var(--status-error); }
.stat-status-text--disconnected { color: var(--text-muted); }
.stat-card__controls { display: flex; align-items: center; gap: var(--space-2); margin-top: var(--space-3); }
.stat-card__controls .text-input { width: 88px; }

/* tabs */
.tabs { display: flex; gap: var(--space-6); border-bottom: 1px solid var(--border); margin-bottom: var(--space-5); }
.tab {
  border: none; background: none; cursor: pointer; padding: var(--space-3) 2px;
  font: inherit; font-weight: var(--fw-medium); color: var(--text-muted);
  border-bottom: 2px solid transparent; margin-bottom: -1px;
}
.tab:hover { color: var(--text-body); }
.tab--active { color: var(--brand); border-bottom-color: var(--brand); }
.tab-panel { display: none; }
.tab-panel--active { display: block; }

/* range selector */
.range-bar { display: flex; align-items: center; justify-content: flex-end; gap: var(--space-3); margin-bottom: var(--space-4); }
.range-select { display: inline-flex; gap: 2px; }
.range-btn {
  border: 1px solid var(--border); background: var(--surface-card); color: var(--text-body);
  padding: 6px 12px; cursor: pointer; font: inherit; font-size: var(--fs-sm);
}
.range-btn:first-child { border-radius: var(--radius-md) 0 0 var(--radius-md); }
.range-btn:last-child { border-radius: 0 var(--radius-md) var(--radius-md) 0; }
.range-btn:not(:first-child) { margin-left: -1px; }
.range-btn--active { background: var(--brand); border-color: var(--brand); color: var(--text-onbrand); }

/* charts */
.charts-grid { display: grid; grid-template-columns: repeat(3, 1fr); gap: var(--space-4); }
.analytics-chart { padding: var(--space-4); }
.analytics-chart__head { display: flex; align-items: center; justify-content: space-between; margin-bottom: var(--space-2); }
.analytics-chart__title { font-weight: var(--fw-semibold); color: var(--text-strong); }
.analytics-chart__csv { font-size: var(--fs-xs); color: var(--text-muted); }
.analytics-chart__body { position: relative; height: 240px; }
.analytics-chart__empty { color: var(--text-faint); font-size: var(--fs-sm); text-align: center; padding: var(--space-8) 0; }

/* loading spinner overlaid on the chart body while data is fetched */
.chart-spinner {
  position: absolute; inset: 0; display: flex; flex-direction: column;
  align-items: center; justify-content: center; gap: var(--space-2);
  background: var(--surface-card); color: var(--text-muted); font-size: var(--fs-sm);
}
.chart-spinner[hidden] { display: none; }
.chart-spinner__ring {
  width: 28px; height: 28px; border-radius: var(--radius-pill);
  border: 3px solid var(--border); border-top-color: var(--brand);
  animation: chart-spin 0.7s linear infinite;
}
@keyframes chart-spin { to { transform: rotate(360deg); } }

/* logs */
.log-list { list-style: none; margin: 0; padding: 0; }
.log-item { display: flex; align-items: center; gap: var(--space-3); padding: var(--space-3) var(--space-2); border-bottom: 1px solid var(--border); }
.log-item__dot { width: 8px; height: 8px; border-radius: var(--radius-pill); background: var(--text-faint); flex: 0 0 auto; }
.log-item--command .log-item__dot { background: var(--brand); }
.log-item--boot .log-item__dot { background: var(--status-running); }
.log-item--system .log-item__dot { background: var(--status-paused); }
.log-item__msg { flex: 1 1 auto; color: var(--text-body); }
.log-item__when { font-size: var(--fs-xs); color: var(--text-muted); }
.log-note { margin-top: var(--space-4); font-size: var(--fs-xs); color: var(--text-faint); }

/* device info */
.info-card { padding: var(--space-5) var(--space-6); }
.info-grid { display: grid; grid-template-columns: 160px 1fr; gap: var(--space-2) var(--space-4); margin: 0; }
.info-grid dt { color: var(--text-muted); font-size: var(--fs-sm); }
.info-grid dd { margin: 0; color: var(--text-strong); }
.info-manifest { margin-top: var(--space-5); }
.manifest-json {
  margin: var(--space-2) 0 0; padding: var(--space-3) var(--space-4);
  background: var(--surface-sunken); border-radius: var(--radius-md);
  font-family: var(--font-mono); font-size: var(--fs-xs); color: var(--text-body);
  overflow-x: auto;
}

/* --------------------------------------------------------------- auth pages
 * Pre-login screens (login / signup / password reset / etc.) render outside the
 * app shell: a single centered card, no nav rail. Shares tokens + card vocab so
 * it reads as the same product. (issue #4, Phase 1)
 */
.auth-page {
  min-height: 100vh;
  display: flex; flex-direction: column;
  align-items: center; justify-content: center;
  gap: var(--space-4);
  padding: var(--space-6);
  background: var(--surface-page);
}
.auth-card {
  width: 100%; max-width: 400px;
  background: var(--surface-card);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-md);
  padding: var(--space-8);
}
.auth-brand { text-align: center; margin-bottom: var(--space-6); }
.auth-brand__word {
  font-size: var(--fs-2xl); font-weight: var(--fw-bold);
  color: var(--brand); letter-spacing: -0.01em;
}
.auth-brand__tag { margin-top: var(--space-1); font-size: var(--fs-sm); color: var(--text-muted); }
.auth-title { font-size: var(--fs-lg); font-weight: var(--fw-semibold); color: var(--text-strong); text-align: center; margin: 0 0 var(--space-5); }
.auth-intro { font-size: var(--fs-sm); color: var(--text-body); text-align: center; margin: 0 0 var(--space-5); }

.auth-form { display: flex; flex-direction: column; gap: var(--space-4); }
.auth-field { display: flex; flex-direction: column; }
.auth-actions { margin-top: var(--space-2); }
.btn--block { width: 100%; }
.btn--lg { padding: 10px 16px; }

.field-help { font-size: var(--fs-xs); color: var(--text-muted); margin-top: 4px; }
.field-error { font-size: var(--fs-xs); color: var(--status-error); margin-top: 4px; }
.text-input--error { border-color: var(--status-error); }

/* inline alert banner inside a card (form errors, flash messages) */
.alert {
  padding: var(--space-3) var(--space-4); border-radius: var(--radius-md);
  font-size: var(--fs-sm); margin-bottom: var(--space-4);
  border: 1px solid transparent;
}
.alert--error { background: var(--status-error-soft); color: var(--status-error); border-color: var(--status-error); }
.alert--success { background: var(--status-running-soft); color: var(--status-running); border-color: var(--status-running); }
.alert--info { background: var(--brand-soft); color: var(--brand-strong); border-color: var(--brand); }
.alert ul { margin: 0; padding-left: var(--space-5); }

.auth-alt { text-align: center; margin-top: var(--space-5); font-size: var(--fs-sm); color: var(--text-muted); }
.auth-links { display: flex; justify-content: space-between; margin-top: var(--space-3); font-size: var(--fs-sm); }

/* --------------------------------------------------------- account page */
.account-grid { display: flex; flex-direction: column; gap: var(--space-5); max-width: 720px; margin: 0 auto; }
.account-section { padding: var(--space-5) var(--space-6); }
.account-section__head { display: flex; align-items: center; justify-content: space-between; margin-bottom: var(--space-4); }
.account-section__title { font-size: var(--fs-lg); font-weight: var(--fw-semibold); color: var(--text-strong); margin: 0; }
.account-form { display: flex; flex-direction: column; gap: var(--space-4); max-width: 380px; }

.membership-list { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: var(--space-3); }
.membership-item {
  display: flex; align-items: center; justify-content: space-between;
  padding: var(--space-3) var(--space-4);
  border: 1px solid var(--border); border-radius: var(--radius-md);
  background: var(--surface-card);
}
.membership-item__org { font-weight: var(--fw-semibold); color: var(--text-strong); }
.role-badge {
  display: inline-flex; align-items: center; padding: 2px 10px;
  border-radius: var(--radius-pill); font-size: var(--fs-xs);
  font-weight: var(--fw-semibold); text-transform: uppercase; letter-spacing: 0.03em;
  background: var(--brand-soft); color: var(--brand-strong);
}
.role-badge--staff { background: var(--status-paused-soft); color: var(--status-paused); }

/* email-verification state badge (identity slice) */
.verify-badge {
  display: inline-flex; align-items: center; margin-left: var(--space-2);
  padding: 1px 8px; border-radius: var(--radius-pill);
  font-size: var(--fs-xs); font-weight: var(--fw-semibold);
  text-transform: none; letter-spacing: 0;
}
.verify-badge--yes { background: var(--status-running-soft); color: var(--status-running); }
.verify-badge--no { background: var(--status-paused-soft); color: var(--status-paused); }

@media (max-width: 1100px) {
  .analytics-cards { grid-template-columns: repeat(2, 1fr); }
  .charts-grid { grid-template-columns: 1fr; }
}

/* ----------------------------------------------------------- responsive */
@media (max-width: 1100px) {
  .summary-grid { grid-template-columns: repeat(3, 1fr); }
  .device-tile { grid-template-columns: 1fr 1fr; row-gap: var(--space-4); }
  .device-tile > * { min-width: 0; }
}

@media (max-width: 720px) {
  .app-shell { grid-template-columns: 1fr; }
  .app-main { padding: var(--space-4) var(--space-4) 88px; }
  /* nav rail collapses to a bottom bar on mobile */
  .nav-rail {
    position: fixed; bottom: 0; left: 0; right: 0; top: auto;
    height: auto; width: 100%;
    flex-direction: row; justify-content: space-around;
    border-right: none; border-top: 1px solid var(--border);
    padding: var(--space-2) var(--space-2);
    overflow-x: auto;
  }
  .nav-rail__spacer { display: none; }
  .nav-item { width: auto; flex: 1 0 auto; }
  .nav-item span { display: none; } /* icons-only on mobile */
  .summary-grid { grid-template-columns: repeat(2, 1fr); }
  .device-tile { grid-template-columns: 1fr; }
}
