/* ========================================================================
   Option A — Device page redesign
   "Mission control" header + grouped tabs + scannable vitals
   Scoped to .optA-device to avoid leaking into the rest of the portal.
   ======================================================================== */

.optA-device {
  display: flex;
  flex-direction: column;
  gap: 1.25rem;
  padding: 0.25rem 0.25rem 2rem;
  color: #e2e8f0;
  /* Fill #device-detail flex slot so tab panels get a bounded height and can scroll. */
  flex: 1 1 auto;
  min-height: 0;
  min-width: 0;
  overflow: hidden;
}

.optA-device > .optA-tabs {
  flex-shrink: 0;
}

/* Tab panes share the remaining column under the header + tab bar. */
.optA-device > div[id^='device-tab-'] {
  flex: 1 1 auto;
  min-height: 0;
  min-width: 0;
  overflow: auto;
}

/* Complex tabs manage their own internal scrolling. */
.optA-device > #device-tab-chart,
.optA-device > #device-tab-data,
.optA-device > #device-tab-force-monitor,
.optA-device > #device-tab-well-info,
.optA-device > #device-tab-plug-detail,
.optA-device > #device-tab-custom-chart {
  overflow: hidden;
}

/* ---------- Breadcrumb ---------- */
.optA-crumbs {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  font-size: 0.82rem;
  color: #64748b;
  margin: 0;
}
.optA-crumbs a {
  color: #94a3b8;
  text-decoration: none;
}
.optA-crumbs a:hover { color: #e2e8f0; }
.optA-crumbs .sep { color: #334155; }

/* ---------- Header block ---------- */
.optA-header {
  display: flex;
  flex-direction: column;
  gap: 1rem;
  padding: 1rem 1.25rem 1.125rem;
  background: linear-gradient(180deg, rgba(30, 41, 59, 0.55) 0%, rgba(15, 23, 42, 0.2) 100%);
  border: 1px solid #1e293b;
  border-radius: 10px;
  flex-shrink: 0;
}

.optA-header--collapsed {
  gap: 0.5rem;
  padding: 0.65rem 1rem 0.75rem;
}

.optA-header--collapsed .optA-vitals {
  display: none;
}

.optA-header-toggle-btn {
  flex-shrink: 0;
}

.optA-header-toggle-btn .optA-header-toggle-icon {
  display: inline-block;
  font-size: 0.7rem;
  line-height: 1;
  transform: rotate(0deg);
  transition: transform 0.15s ease;
}

.optA-header--collapsed .optA-header-toggle-btn .optA-header-toggle-icon {
  transform: rotate(180deg);
}

.optA-header-top {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 1.5rem;
  flex-wrap: wrap;
}

.optA-title-group {
  display: flex;
  flex-direction: column;
  gap: 0.35rem;
  min-width: 0;
}

.optA-title-row {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  flex-wrap: wrap;
}

.optA-device-name {
  margin: 0;
  font-size: 1.65rem;
  font-weight: 600;
  color: #f8fafc;
  letter-spacing: -0.01em;
  line-height: 1.1;
}

.optA-status-chip {
  display: inline-flex;
  align-items: center;
  gap: 0.4rem;
  padding: 0.3rem 0.65rem;
  border-radius: 999px;
  font-size: 0.78rem;
  font-weight: 500;
  letter-spacing: 0.02em;
}
.optA-status-chip.online {
  background: rgba(34, 197, 94, 0.12);
  color: #86efac;
  border: 1px solid rgba(34, 197, 94, 0.35);
}
.optA-status-chip.offline {
  /* Phase 4: muted grey variant for offline devices. No pulsing dot. */
  background: rgba(100, 116, 139, 0.12);
  color: #94a3b8;
  border: 1px solid rgba(100, 116, 139, 0.35);
}
.optA-status-chip.offline .dot {
  background: #64748b;
  animation: none;
}
.optA-status-chip.recording {
  background: rgba(59, 130, 246, 0.12);
  color: #93c5fd;
  border: 1px solid rgba(59, 130, 246, 0.35);
}
.optA-status-chip.idle {
  /* Phase 4: inactive (no live job) variant — shown as a subtle idle pill. */
  background: rgba(71, 85, 105, 0.12);
  color: #94a3b8;
  border: 1px solid rgba(71, 85, 105, 0.35);
}
.optA-status-chip.idle .dot {
  background: #475569;
  animation: none;
}
.optA-status-chip .dot {
  width: 7px;
  height: 7px;
  border-radius: 999px;
  background: currentColor;
  box-shadow: 0 0 0 0 currentColor;
}
.optA-status-chip.online .dot {
  animation: optA-pulse 1.8s ease-out infinite;
}
@keyframes optA-pulse {
  0%   { box-shadow: 0 0 0 0 rgba(34, 197, 94, 0.55); }
  70%  { box-shadow: 0 0 0 6px rgba(34, 197, 94, 0); }
  100% { box-shadow: 0 0 0 0 rgba(34, 197, 94, 0); }
}

.optA-subtitle {
  margin: 0;
  font-size: 0.9rem;
  color: #94a3b8;
}
.optA-subtitle strong {
  color: #cbd5e1;
  font-weight: 500;
}

/* Header right: actions */
.optA-header-actions {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  flex-shrink: 0;
}
.optA-btn {
  display: inline-flex;
  align-items: center;
  gap: 0.4rem;
  height: 36px;
  padding: 0 0.9rem;
  border-radius: 6px;
  border: 1px solid #334155;
  background: #1e293b;
  color: #e2e8f0;
  font-size: 0.875rem;
  font-weight: 500;
  cursor: pointer;
  transition: background 120ms ease, border-color 120ms ease;
}
.optA-btn:hover { background: #273449; border-color: #475569; }
.optA-btn.primary {
  background: #2563eb;
  border-color: #2563eb;
  color: #fff;
}
.optA-btn.primary:hover { background: #1d4ed8; border-color: #1d4ed8; }
.optA-btn.icon-only {
  width: 36px;
  padding: 0;
  justify-content: center;
}
.optA-btn svg { width: 15px; height: 15px; }

/* Vital chip row */
.optA-vitals {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(150px, 1fr));
  gap: 0.75rem;
  padding-top: 0.25rem;
  border-top: 1px solid #1e293b;
}
.optA-vital {
  display: flex;
  flex-direction: column;
  gap: 0.2rem;
  padding: 0.65rem 0 0.25rem;
  min-width: 0;
}
.optA-vital-label {
  font-size: 0.7rem;
  letter-spacing: 0.14em;
  text-transform: uppercase;
  color: #64748b;
  font-weight: 600;
}
.optA-vital-value {
  font-size: 0.95rem;
  color: #e2e8f0;
  font-weight: 500;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.optA-vital-value.mono {
  font-family: 'SF Mono', Menlo, Consolas, monospace;
  font-size: 0.85rem;
}
.optA-vital-value.accent { color: #86efac; }
.optA-vital-value.warn   { color: #fbbf24; }
/* Phase 4: alarm variant for the last-sample-age vital (>120s stale).
   Matches the legacy portal.css #device-recording-stats.very-stale spirit. */
.optA-vital-value.alarm  { color: #f87171; }
/* Phase 4: also support data-stale="alarm|warn|fresh|unknown" attribute flips
   so CSS can react to either the class variant or the structural hook. */
.optA-vital-value[data-stale="alarm"] { color: #f87171; }
.optA-vital-value[data-stale="warn"]  { color: #fbbf24; }
.optA-vital-value[data-stale="fresh"] { color: #86efac; }
.optA-vital-sub {
  font-size: 0.75rem;
  color: #64748b;
}

/* ---------- Grouped tabs ---------- */
.optA-tabs {
  display: flex;
  align-items: center;
  gap: 1.25rem;
  border-bottom: 1px solid #1e293b;
  padding: 0 0.25rem;
  overflow-x: auto;
}
.optA-tabs::-webkit-scrollbar { height: 0; }

.optA-tab-group {
  display: flex;
  align-items: center;
  gap: 0;
  position: relative;
}
.optA-tab-group:not(:last-child)::after {
  content: '';
  position: absolute;
  right: -0.625rem;
  top: 18%;
  bottom: 18%;
  width: 1px;
  background: #1e293b;
}

.optA-tab-group-label {
  font-size: 0.65rem;
  letter-spacing: 0.18em;
  text-transform: uppercase;
  color: #475569;
  font-weight: 700;
  padding: 0 0.75rem 0 0.25rem;
  white-space: nowrap;
}

.optA-tab {
  background: transparent;
  border: none;
  padding: 0.75rem 0.75rem;
  font-size: 0.88rem;
  color: #94a3b8;
  cursor: pointer;
  white-space: nowrap;
  border-bottom: 2px solid transparent;
  margin-bottom: -1px;
  transition: color 120ms ease, border-color 120ms ease;
  font-weight: 500;
}
.optA-tab:hover { color: #e2e8f0; }
.optA-tab.active {
  color: #60a5fa;
  border-bottom-color: #3b82f6;
}
.optA-tab .badge {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 18px;
  height: 18px;
  padding: 0 5px;
  margin-left: 0.35rem;
  border-radius: 999px;
  background: rgba(251, 146, 60, 0.18);
  color: #fdba74;
  font-size: 0.68rem;
  font-weight: 600;
  border: 1px solid rgba(251, 146, 60, 0.35);
}

/* ---------- Main content grid ---------- */
.optA-content {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 280px;
  gap: 1rem;
  align-items: flex-start;
}
@media (max-width: 1200px) {
  .optA-content { grid-template-columns: 1fr; }
}

.optA-main {
  display: flex;
  flex-direction: column;
  gap: 1rem;
  min-width: 0;
}

/* ---------- Channels card ---------- */
.optA-card {
  background: #0f172a;
  border: 1px solid #1e293b;
  border-radius: 10px;
  overflow: hidden;
}
.optA-card-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  padding: 0.75rem 1rem;
  border-bottom: 1px solid #1e293b;
}
.optA-card-title {
  margin: 0;
  font-size: 0.95rem;
  font-weight: 600;
  color: #e2e8f0;
}
.optA-card-meta {
  font-size: 0.78rem;
  color: #64748b;
  display: flex;
  align-items: center;
  gap: 0.5rem;
}
.optA-live-pill {
  display: inline-flex;
  align-items: center;
  gap: 0.3rem;
  font-size: 0.7rem;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  color: #86efac;
  font-weight: 600;
}
.optA-live-pill::before {
  content: '';
  width: 6px;
  height: 6px;
  border-radius: 999px;
  background: #22c55e;
  animation: optA-pulse-dot 1.4s ease-in-out infinite;
}
@keyframes optA-pulse-dot {
  0%, 100% { opacity: 1; }
  50% { opacity: 0.35; }
}

.optA-channel-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(200px, 1fr));
  gap: 1px;
  background: #1e293b;
}
.optA-channel {
  background: #0f172a;
  padding: 0.75rem 0.9rem 0.85rem;
  display: flex;
  flex-direction: column;
  gap: 0.3rem;
  min-width: 0;
  position: relative;
}
.optA-channel:hover { background: #131f36; }
.optA-channel-name {
  font-size: 0.78rem;
  color: #94a3b8;
  font-weight: 500;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.optA-channel-value {
  font-family: 'SF Mono', Menlo, Consolas, monospace;
  font-size: 1.25rem;
  color: #f8fafc;
  font-weight: 500;
  font-variant-numeric: tabular-nums;
  line-height: 1.1;
  display: flex;
  align-items: baseline;
  gap: 0.35rem;
}
.optA-channel-value .unit {
  font-size: 0.72rem;
  color: #64748b;
  font-weight: 400;
  letter-spacing: 0.04em;
  font-family: inherit;
}
.optA-channel-value.warn { color: #fbbf24; }
.optA-channel-value.alarm { color: #f87171; }
.optA-channel-value.muted { color: #64748b; }
.optA-channel-spark {
  margin-top: 0.15rem;
  height: 22px;
}
.optA-channel-spark svg { width: 100%; height: 100%; display: block; }

/* Phase 4: channel card derived-state visuals.
   data-channel-state is stamped by device-detail-overview.js on each poll
   based on the extended /api/devices/{id} channel payload (alarm_low/high,
   warn_low/high). Sparkline stroke follows the same derived bucket so the
   card's color language stays consistent. */
.optA-channel[data-channel-state="alarm"] {
  box-shadow: inset 3px 0 0 0 #f87171;
}
.optA-channel[data-channel-state="warn"] {
  box-shadow: inset 3px 0 0 0 #fbbf24;
}
.optA-channel[data-channel-state="muted"] {
  opacity: 0.55;
}
.optA-channel[data-channel-state="alarm"] .optA-channel-value { color: #f87171; }
.optA-channel[data-channel-state="warn"]  .optA-channel-value { color: #fbbf24; }
.optA-channel[data-channel-state="muted"] .optA-channel-value { color: #64748b; }
.optA-channel[data-channel-state="alarm"] .optA-channel-spark path { stroke: #f87171; }
.optA-channel[data-channel-state="warn"]  .optA-channel-spark path { stroke: #fbbf24; }
.optA-channel[data-channel-state="muted"] .optA-channel-spark path { stroke: #64748b; }

.optA-channel-footer {
  padding: 0.5rem 1rem;
  font-size: 0.75rem;
  color: #64748b;
  background: #0b1220;
  border-top: 1px solid #1e293b;
}

/* ---------- Right context panel ---------- */
.optA-aside {
  display: flex;
  flex-direction: column;
  gap: 1rem;
  /* Avoid sticky here: a tall job-context card + CSV CTA made the CTA unreachable
     because the aside was taller than the viewport with no internal scroll. */
}
.optA-aside .optA-card-header { padding: 0.65rem 0.875rem; }
.optA-aside .optA-card-title { font-size: 0.72rem; letter-spacing: 0.14em; text-transform: uppercase; color: #64748b; font-weight: 600; }

.optA-spec-list {
  padding: 0.25rem 0.875rem 0.625rem;
}
.optA-spec {
  padding: 0.55rem 0;
  border-bottom: 1px solid #1e293b;
  display: flex;
  flex-direction: column;
  gap: 0.15rem;
}
.optA-spec:last-child { border-bottom: none; }
.optA-spec-label {
  font-size: 0.72rem;
  color: #64748b;
  letter-spacing: 0.06em;
}
.optA-spec-value {
  font-size: 0.87rem;
  color: #e2e8f0;
  word-break: break-all;
}
.optA-spec-value.mono {
  font-family: 'SF Mono', Menlo, Consolas, monospace;
  font-size: 0.8rem;
}

/* Quick-download CTA block in aside */
.optA-download-card {
  padding: 0.875rem;
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
}
.optA-download-card p {
  margin: 0;
  font-size: 0.8rem;
  color: #94a3b8;
  line-height: 1.45;
}
.optA-download-card .optA-btn { justify-content: center; width: 100%; }

/* ---------- Phase 5: share-mode grouped-tab visibility ----------
   _applyShareTabFilter hides individual .device-tab buttons whose data-tab is
   not in the allowed set (see cloud_portal/static/js/app.js). With Phase 1's
   three .optA-tab-group blocks (LIVE / JOB / DATA), a group whose buttons are
   all hidden would still render its label (e.g. "LIVE") as a lone header.
   The JS marks such groups with the `.share-empty` class; CSS hides them plus
   their separator line. Scoped to body.share-mode so normal-mode layouts and
   future expand/collapse group UX are not affected. */
body.share-mode .optA-tab-group.share-empty { display: none; }
body.share-mode .optA-tab-group.share-empty::after { display: none; }

/* Share viewers see Overview but never the CSV export CTA. The backend
   /api/jobs/{id}/data.csv route is also blocked by the share-link allowlist
   in cloud_portal/backend/_app_deps.py::_is_share_path_allowed. */
body.share-mode .optA-download-card { display: none; }
