.detail { padding: 0 var(--gutter) 28px; container-type: inline-size; }

/* Phones and tablets: the 3D scene stays pinned as the top band (the camera flies to the unit) and
   the detail is a sheet under it, scrolled on its own. */
@media (max-width: 959px) {
  .app.is-detail .scene-cell { position: fixed; inset: 0 0 auto 0; height: var(--detail-scene-h); margin: 0; border-radius: 0; z-index: 31; }
  .detail { position: fixed; inset: var(--detail-scene-h) 0 0 0; z-index: 30; overflow-y: auto; overscroll-behavior: contain; background: var(--surface); border-radius: 14px 14px 0 0; box-shadow: var(--shadow-sheet); padding-bottom: calc(28px + env(safe-area-inset-bottom)); animation: sheet-in 0.26s ease-out; }
}
:root { --detail-scene-h: 40svh; }
@media (min-width: 560px) and (max-width: 959px) { :root { --detail-scene-h: 46svh; } }
@keyframes sheet-in { from { transform: translateY(24px); opacity: 0; } }
@media (prefers-reduced-motion: reduce) { .detail { animation: none; } }
.detail[hidden], .rail[hidden] { display: none; }
.detail__bar { position: sticky; top: 0; z-index: 3; display: flex; align-items: center; justify-content: space-between; margin: 0 calc(-1 * var(--gutter)); padding: 10px var(--gutter); background: var(--surface); border-bottom: 1px solid var(--rule); }
.detail__back { min-height: 40px; display: inline-flex; align-items: center; gap: 8px; padding: 6px 12px 6px 8px; border: 0; border-radius: var(--radius); background: var(--surface-2); box-shadow: inset 0 0 0 1px var(--rule-strong); cursor: pointer; font-weight: 600; font-size: 14px; }
.detail__back:hover { box-shadow: inset 0 0 0 1px var(--select); }
.detail__chev { width: 8px; height: 8px; border-left: 2px solid currentColor; border-bottom: 2px solid currentColor; transform: rotate(45deg); margin-left: 4px; }
.detail__esc { font-size: 12px; color: var(--ink-3); padding: 2px 6px; border-radius: 4px; box-shadow: inset 0 0 0 1px var(--rule-strong); }
@media (pointer: coarse) { .detail__esc { display: none; } }

.detail__head { display: flex; flex-wrap: wrap; align-items: center; gap: 6px 14px; padding: 18px 0 4px; }
.detail__name { margin: 0; font: 700 40px/1 var(--font-cond); letter-spacing: -0.01em; }
.detail__head .badge { font-size: 14px; }
.detail__mode { flex-basis: 100%; font-size: 13px; color: var(--ink-2); }

.detail__figs { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 0; margin: 12px 0 8px; border-top: 1px solid var(--rule); }
.fig { padding: 10px 12px 10px 0; border-bottom: 1px solid var(--rule); min-width: 0; }
.fig dt { font-size: 12px; color: var(--ink-3); }
.fig dd { margin: 2px 0 0; font: 600 26px/1.1 var(--font-cond); white-space: nowrap; }
.fig dd small { font-size: 13px; color: var(--ink-2); font-weight: 500; margin-left: 3px; }
@container (min-width: 520px) { .detail__figs { grid-template-columns: repeat(4, minmax(0, 1fr)); } .detail__figs--two { grid-template-columns: repeat(2, minmax(0, 1fr)); } }

.detail__charts { display: grid; gap: 22px; padding: 16px 0 8px; }
.detail__grid { display: grid; gap: 0 28px; }
@container (min-width: 600px) { .detail__grid { grid-template-columns: minmax(0, 1fr) minmax(0, 1fr); } }
.detail__block { padding: 16px 0 6px; border-top: 1px solid var(--rule); min-width: 0; }
.detail__h { margin: 0 0 10px; font: 600 16px/1.2 var(--font-cond); }

.events { list-style: none; margin: 0; padding: 0; display: grid; gap: 8px; }
.event { position: relative; display: grid; grid-template-columns: 62px minmax(0, 1fr); gap: 8px; padding-left: 14px; font-size: 13px; color: var(--ink-2); }
.event::before { content: ''; position: absolute; left: 0; top: 6px; width: 7px; height: 7px; border-radius: 50%; background: var(--ink-3); }
.event.is-ok::before { background: var(--st-loaded); }
.event.is-info::before { background: var(--st-running); }
.event.is-warn::before { background: var(--st-unloaded); }
.event.is-danger::before { background: var(--st-alarm); border-radius: 1px; transform: rotate(45deg); }
.event.is-danger span { color: var(--ink); }
.event time { color: var(--ink-3); font-size: 13px; }
.event.is-empty { grid-template-columns: 1fr; }

.io { margin-bottom: 12px; }
.io__title { margin: 0 0 6px; font-size: 12px; font-weight: 500; color: var(--ink-3); }
.io__row { list-style: none; margin: 0; padding: 0; display: grid; grid-template-columns: repeat(auto-fill, minmax(34px, 1fr)); gap: 6px; }
.io__light { display: grid; place-items: center; height: 26px; border-radius: 4px; font: 600 12px/1 var(--font-cond); color: var(--ink-3); box-shadow: inset 0 0 0 1px var(--rule-strong); }
.io__light.is-on { color: var(--on-accent); background: var(--sw, var(--st-running)); box-shadow: none; }
.io__hint { margin: 4px 0 0; font-size: 12px; color: var(--ink-3); }

.limits { list-style: none; margin: 0; padding: 0; display: grid; gap: 10px; }
.limit { display: grid; grid-template-columns: minmax(0, 1fr) auto; gap: 3px 8px; font-size: 13px; }
.limit__name { color: var(--ink); }
.limit__value { font-size: 14px; font-weight: 600; }
.limit__bar { grid-column: 1 / -1; height: 4px; border-radius: 2px; background: var(--rule); overflow: hidden; }
.limit__fill { display: block; height: 100%; background: var(--ink-3); border-radius: 2px; }
.limit__rule { grid-column: 1 / -1; font-size: 12px; color: var(--ink-3); }
.limit.is-breached .limit__fill { background: var(--st-alarm); }
.limit.is-breached .limit__rule { color: var(--st-alarm); font-weight: 600; }

@media (min-width: 960px) { .detail { padding: 0 24px 32px; } .detail__bar { margin: 0 -24px; padding: 10px 24px; } }

/* Offline unit: the notice replaces charts, thresholds and I/O. */
.detail.is-offline .detail__charts, .detail.is-offline .detail__block--live { display: none; }
.offline { margin: 16px 0 8px; padding: 14px 16px; border-left: 3px dashed var(--st-offline); background: var(--surface-2); border-radius: 0 var(--radius) var(--radius) 0; }
.offline[hidden] { display: none; }
.offline__title { margin: 0 0 6px; font: 600 18px/1.2 var(--font-cond); }
.offline__text, .offline__when { margin: 0 0 8px; font-size: 14px; color: var(--ink-2); max-width: 60ch; }
.offline__values { display: flex; flex-wrap: wrap; gap: 8px 24px; margin: 0; }
.offline__values[hidden] { display: none; }
.offline__values dt { font-size: 12px; color: var(--ink-3); }
.offline__values dd { margin: 0; font: 600 18px/1.2 var(--font-cond); }
.fig.is-empty dd small { display: none; }
.detail__seen { flex-basis: 100%; font-size: 13px; color: var(--ink-3); }
.detail__seen.is-stale { color: var(--st-unloaded); }

/* Controller alarm block at the top of the detail. */
.detail__alarm { margin: 8px 0 12px; padding: 12px; border: 1px solid var(--rule-strong); border-left: 4px solid var(--st-warning); border-radius: var(--radius); background: var(--surface-2); grid-template-columns: auto 1fr; }
.detail__alarm.is-stop { border-left-color: var(--st-alarm); }
.detail__alarm[hidden] { display: none; }
.detail__alarm .alarm__since { grid-column: 2; text-align: right; }
@media (min-width: 720px) {
  .detail__alarm { grid-template-columns: auto 1fr; gap: 6px 12px; }
  .detail__alarm .alarm__text, .detail__alarm .alarm__cause, .detail__alarm .alarm__action { grid-column: 1 / -1; }
  .detail__alarm .alarm__since { grid-row: 1; grid-column: 2; }
}
