* { box-sizing: border-box; }

html, body {
  margin: 0;
  height: 100%;
  background: var(--ob-bg);
  color: var(--ob-text-main);
  font-family: var(--ob-font-ui);
  font-size: 13px;
  -webkit-font-smoothing: antialiased;
  -webkit-text-size-adjust: 100%;
}

/* App shell: header and tabs stay put, each tab pane scrolls on its own.
   dvh, not %, so iOS Safari's collapsing toolbar doesn't cut the bottom off. */
body { display: flex; flex-direction: column; height: 100dvh; overflow: hidden; }

/* Top Bar Header */
header {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 6px var(--ob-pad);
  padding-top: max(6px, env(safe-area-inset-top));
  padding-left: max(var(--ob-pad), env(safe-area-inset-left));
  padding-right: max(var(--ob-pad), env(safe-area-inset-right));
  background: var(--ob-surface);
  border-bottom: 2px solid var(--ob-border);
  min-height: 56px;
  flex-shrink: 0;
}

.brand {
  font-family: var(--ob-font-mono);
  font-weight: 700;
  font-size: 13px;
  letter-spacing: 0.1em;
  color: var(--ob-cyan);
  display: flex;
  align-items: center;
  gap: 10px;
  min-width: 0;
  white-space: nowrap;
}
.brand svg { fill: var(--ob-cyan); width: 22px; height: 22px; flex-shrink: 0; }
.brand span { color: var(--ob-text-dim); font-weight: 400; overflow: hidden; text-overflow: ellipsis; }
.header-tools { margin-left: auto; display: flex; align-items: center; gap: 8px; }

input[type=text], input[type=datetime-local], input[type=number], select, textarea {
  background: var(--ob-bg);
  border: 1px solid var(--ob-border-bright);
  color: var(--ob-text-main);
  font-family: var(--ob-font-mono);
  font-size: 12px;
  padding: 0 10px;
  border-radius: var(--ob-radius);
  outline: none;
  height: 36px;
  min-width: 0;
}
input[type=text] { min-width: 200px; }
textarea { height: auto; padding: 8px 10px; }
select { padding-right: 6px; cursor: pointer; }
input:focus, select:focus, textarea:focus {
  border-color: var(--ob-cyan);
  box-shadow: 0 0 0 1px var(--ob-cyan);
}
input:disabled, select:disabled { opacity: 0.45; cursor: default; }

input[type=checkbox] { accent-color: var(--ob-cyan); width: 16px; height: 16px; margin: 0; }

/* Flat OpenBridge-style range: thin track, square thumb */
input[type=range]:not(.vert-slider) {
  -webkit-appearance: none;
  appearance: none;
  width: 100%;
  height: 28px; /* the hit area; the track is drawn thinner */
  background: transparent;
  cursor: pointer;
  margin: 0;
}
input[type=range]:not(.vert-slider)::-webkit-slider-runnable-track {
  height: 4px; background: var(--ob-border-bright); border-radius: 1px;
}
input[type=range]:not(.vert-slider)::-moz-range-track {
  height: 4px; background: var(--ob-border-bright); border-radius: 1px;
}
input[type=range]:not(.vert-slider)::-moz-range-progress { height: 4px; background: var(--ob-cyan); }
input[type=range]:not(.vert-slider)::-webkit-slider-thumb {
  -webkit-appearance: none;
  width: 18px; height: 18px; margin-top: -7px;
  background: var(--ob-cyan); border: 2px solid var(--ob-bg); border-radius: 2px;
}
input[type=range]:not(.vert-slider)::-moz-range-thumb {
  width: 14px; height: 14px; background: var(--ob-cyan); border: 2px solid var(--ob-bg); border-radius: 2px;
}
input[type=range]:disabled::-webkit-slider-thumb { background: var(--ob-text-muted); }
input[type=range]:disabled::-moz-range-thumb { background: var(--ob-text-muted); }

button {
  background: var(--ob-panel);
  border: 1px solid var(--ob-border-bright);
  color: var(--ob-text-main);
  font-family: var(--ob-font-ui);
  font-weight: 600;
  font-size: 11px;
  letter-spacing: 0.05em;
  text-transform: uppercase;
  padding: 0 16px;
  height: 36px;
  border-radius: var(--ob-radius);
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  flex-shrink: 0;
}
button svg { fill: currentColor; width: 16px; height: 16px; }
button:hover:not(:disabled) {
  background: var(--ob-border);
  border-color: var(--ob-cyan);
  color: var(--ob-cyan);
}
button:disabled { opacity: 0.35; cursor: default; }
:focus-visible { outline: 2px solid var(--ob-focus); outline-offset: 2px; }

.status {
  display: flex;
  align-items: center;
  gap: 8px;
  background: var(--ob-bg);
  border: 1px solid var(--ob-border);
  padding: 0 12px;
  height: 36px;
  border-radius: var(--ob-radius);
  font-family: var(--ob-font-mono);
  font-size: 11px;
  color: var(--ob-text-dim);
  text-transform: uppercase;
  flex-shrink: 0;
}
/* Palette (day / dusk / night / bright), see app.js */
.palette { display: flex; flex-shrink: 0; border: 1px solid var(--ob-border); border-radius: var(--ob-radius); }
.palette button { height: 34px; padding: 0 10px; border: 0; border-radius: 0; background: transparent; color: var(--ob-text-dim); }
.palette button + button { border-left: 1px solid var(--ob-border); }
.palette button[aria-pressed="true"] { background: var(--ob-on-bg); color: var(--ob-on-text); }
.palette svg { width: 18px; height: 18px; }
.palette .palette-label { display: none; }
@media (min-width: 1100px) { .palette .palette-label { display: inline; } }

.dot { width: 10px; height: 10px; border-radius: 1px; background: var(--ob-text-muted); }
.dot.on   { background: var(--ob-green); box-shadow: 0 0 8px var(--ob-green); }
.dot.off  { background: var(--ob-red);   box-shadow: 0 0 8px var(--ob-red); }
.dot.wait { background: var(--ob-amber); box-shadow: 0 0 8px var(--ob-amber); animation: pulse 1s infinite; }
@keyframes pulse { 50% { opacity: 0.3; } }

/* Navigation Tabs: one row that scrolls sideways, never wraps into two */
.tabs-bar {
  display: flex;
  background: var(--ob-surface);
  border-bottom: 1px solid var(--ob-border);
  padding: 0 var(--ob-pad);
  padding-left: max(var(--ob-pad), env(safe-area-inset-left));
  padding-right: max(var(--ob-pad), env(safe-area-inset-right));
  gap: 4px;
  flex-shrink: 0;
  overflow-x: auto;
  scrollbar-width: none;
}
.tabs-bar::-webkit-scrollbar { display: none; }
.tab-btn {
  border: none;
  border-bottom: 3px solid transparent;
  border-radius: 0;
  background: transparent;
  color: var(--ob-text-dim);
  padding: 0 20px;
  font-weight: 700;
  letter-spacing: 0.08em;
  font-size: 11px;
  height: 44px;
  white-space: nowrap;
}
.tab-btn.active {
  color: var(--ob-cyan);
  border-bottom-color: var(--ob-cyan);
  background: var(--ob-panel);
}

/* A phone on its side: the notch and the rounded corners sit left and right. The bars above paint
   under them; the content keeps out. */
main { flex: 1; display: flex; min-height: 0; padding: 0 env(safe-area-inset-right) 0 env(safe-area-inset-left); }
.tab-pane {
  display: none;
  flex: 1;
  min-width: 0;
  min-height: 0;
  overflow-y: auto;
  overscroll-behavior: contain;
  padding-bottom: env(safe-area-inset-bottom);
}
.tab-pane.active { display: flex; }

/* Dashboard View. Sized by its content, not stretched to the pane: stretched,
   its cards (overflow: hidden, so min-height 0) shrank to fit instead of
   letting the pane scroll. */
.dashboard-container {
  flex: 1;
  align-self: flex-start;
  min-width: 0;
  padding: var(--ob-pad);
  display: flex;
  flex-direction: column;
  gap: var(--ob-gap);
}
.dashboard-container > * { flex-shrink: 0; }

.dash-card {
  background: var(--ob-panel);
  border: 1px solid var(--ob-border);
  border-radius: var(--ob-radius);
  overflow: hidden;
  display: flex;
  flex-direction: column;
  min-width: 0;
}
.dash-card-title {
  background: var(--ob-panel-header);
  border-bottom: 1px solid var(--ob-border);
  padding: 0 var(--ob-pad);
  min-height: 44px;
  font-size: 11px;
  font-weight: 700;
  color: var(--ob-text-dim);
  text-transform: uppercase;
  letter-spacing: 0.1em;
  display: flex;
  flex-wrap: wrap;
  justify-content: space-between;
  align-items: center;
  gap: 6px 12px;
}
.dash-card-title > span:first-child { padding: 6px 0; }
/* A card that is only a title (a header over the cards below) needs no divider */
.dash-card-title:last-child { border-bottom: 0; }
.card-body { padding: var(--ob-pad); }
.card-body.tight { padding: 8px; }
/* The small mono readouts and toggles that sit in a card title or footer */
.card-meta {
  font-family: var(--ob-font-mono);
  font-size: 11px;
  font-weight: 400;
  letter-spacing: 0.04em;
  text-transform: none;
  color: var(--ob-text-dim);
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 8px 14px;
}
.card-meta label { display: flex; align-items: center; gap: 6px; cursor: pointer; white-space: nowrap; }
.card-meta select,
.card-meta input[type=datetime-local] { height: 28px; font-size: 11px; }
/* The date and its Now button wrap together */
.time-picker { display: flex; gap: 4px; }
.card-meta button { height: 28px; padding: 0 10px; }
.card-footer {
  border-top: 1px solid var(--ob-border);
  padding: 8px var(--ob-pad);
  min-height: 34px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-top: auto; /* pinned to the bottom when a grid row stretches the card */
}
.card-footer > span + span { color: var(--ob-text-muted); }
.text-error { color: var(--ob-red); }

/* Maximize / fullscreen buttons, added to every card title by card-tools.js.
   Pinned top right, so they stay put when a narrow title wraps its meta onto a second line. */
.dash-card-title { position: relative; }
.dash-card-title:has(> .card-tools) { padding-right: calc(var(--ob-pad) + 34px); }
.dash-card-title:has(> .card-tools > :nth-child(2)) { padding-right: calc(var(--ob-pad) + 68px); }
.card-tools { position: absolute; top: 6px; right: 6px; display: flex; gap: 2px; }
.card-tool {
  width: 32px; height: 32px; padding: 0;
  display: inline-flex; align-items: center; justify-content: center;
  background: transparent; border: 0; border-radius: var(--ob-radius);
  color: var(--ob-text-dim); cursor: pointer;
}
.card-tool svg { width: 18px; height: 18px; fill: currentColor; }
.card-tool:hover { color: var(--ob-cyan); background: var(--ob-cyan-dim); }

/* A maximized card covers the window, its media growing to fill it. Under the
   value editor (z-index 100), which can still open from inside it. */
.dash-card.maximized {
  position: fixed; inset: 0; z-index: 50;
  border: 0; border-radius: 0;
  padding: env(safe-area-inset-top) env(safe-area-inset-right) env(safe-area-inset-bottom) env(safe-area-inset-left);
}
.dash-card.maximized > .card-body { flex: 1; min-height: 0; overflow: auto; }
.dash-card.maximized .media-frame,
.dash-card.maximized .unity-viewport-container { aspect-ratio: auto; max-height: none; height: 100%; }
.dash-card.maximized .graph-container-large { height: 100%; }
/* Short screens (a phone on its side): every row counts, so a maximized card drops its
   footer and slims its title; the media gets the rest */
@media (max-height: 500px) {
  header { min-height: 40px; padding-top: 3px; padding-bottom: 3px; }
  .palette button { height: 30px; }
  .tab-btn { height: 34px; }
  .dash-card.maximized > .card-footer { display: none; }
  .dash-card.maximized > .dash-card-title { min-height: 36px; }
  .dash-card.maximized > .dash-card-title .card-tools { top: 2px; }
  .dash-card.maximized .layout-picker button { height: 24px; }
}
/* A fullscreen frame is the whole screen; the 16:9 box would letterbox it again */
.media-frame:fullscreen,
.unity-viewport-container:fullscreen { aspect-ratio: auto; max-height: none; border: 0; }

/* Two (or more) equal columns that stack once they no longer fit */
.dash-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(min(100%, 420px), 1fr));
  gap: var(--ob-gap);
}

/* Camera viewport (camera-viewport.js): panes laid out in one 16:9 frame, each with its own dropdown */
.layout-picker { display: inline-flex; border: 1px solid var(--ob-border); border-radius: var(--ob-radius); overflow: hidden; }
.layout-picker button { width: 32px; height: 28px; padding: 0; border: 0; border-radius: 0; background: transparent; color: var(--ob-text-dim); display: inline-flex; align-items: center; justify-content: center; }
.layout-picker button + button { border-left: 1px solid var(--ob-border); }
.layout-picker[hidden], .layout-picker button[hidden] { display: none; }
.layout-picker button[aria-pressed="true"] { background: var(--ob-on-bg); color: var(--ob-on-text); }
.layout-picker svg { width: 18px; height: 18px; fill: currentColor; }
/* A full-width viewport would be taller than the window; maximized and fullscreen lift the cap */
.camera-viewport:not(.maximized) .media-frame:not(:fullscreen) { max-height: 75dvh; }
.camera-panes { display: grid; gap: 2px; background: var(--ob-border); }
.camera-panes[data-layout="main3"] > .camera-pane:first-child { grid-column: 1 / -1; }
.camera-pane { position: relative; min-width: 0; min-height: 0; background: #000; }
.camera-pane[hidden] { display: none; }
.camera-pane > video { position: absolute; inset: 0; width: 100%; height: 100%; object-fit: contain; }
/* The pane's camera name, as wide as it is; its select is invisible on top, so a tap opens the picker */
.camera-label {
  position: absolute; top: 6px; left: 6px; z-index: 1;
  display: inline-flex; align-items: center; gap: 4px;
  height: 22px; max-width: calc(100% - 12px); padding: 0 6px;
  font-family: var(--ob-font-mono); font-size: 11px; color: var(--ob-text-main);
  background: color-mix(in srgb, var(--ob-bg) 70%, transparent);
  border: 1px solid var(--ob-border-bright); border-radius: var(--ob-radius);
}
.camera-label[hidden] { display: none; }
.camera-label > span { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.camera-label::after { content: "\25BE"; color: var(--ob-text-dim); }
.camera-label > select {
  position: absolute; inset: 0; width: 100%; height: 100%; max-width: none;
  opacity: 0; font-size: 16px;   /* 16px: under it, iPhone zooms the page on focus */
}
.camera-label:has(> select:focus-visible) { border-color: var(--ob-cyan); }
/* Small panes on phones: a smaller name */
@media (max-width: 600px) { .camera-label { height: 20px; font-size: 10px; top: 4px; left: 4px; max-width: calc(100% - 8px); } }

/* A 16:9 frame for the map and the camera, so side by side they're always the same size */
.media-frame {
  position: relative;
  width: 100%;
  aspect-ratio: 16 / 9;
  background: var(--ob-bg);
  border: 1px solid var(--ob-border);
  overflow: hidden;
  /* Keeps Leaflet's pane z-indices (400+) and the overlays inside, under a maximized card */
  isolation: isolate;
}
.media-frame > video,
.media-frame > .media-fill { position: absolute; inset: 0; width: 100%; height: 100%; }
.media-frame > video { object-fit: contain; background: #000; }
/* Leaflet's default light container shows through as hairlines between tiles */
.media-frame > .leaflet-container { background: var(--ob-bg); font-family: var(--ob-font-ui); }
.media-frame .leaflet-tile-pane { filter: var(--ob-map-filter); }
/* The weather layer stays unfiltered by day; at night bright white cloud would wreck dark adaptation */
:root[data-obc-theme="night"] .media-frame .leaflet-weather-pane { filter: brightness(0.45) sepia(0.7); }

/* Readouts and messages laid over a media frame */
.media-overlay {
  position: absolute;
  z-index: 500; /* above Leaflet's panes and controls */
  left: 8px;
  max-width: calc(100% - 16px);
  padding: 4px 8px;
  background: color-mix(in srgb, var(--ob-bg) 85%, transparent);
  border: 1px solid var(--ob-border);
  font-family: var(--ob-font-mono);
  font-size: 11px;
  color: var(--ob-text-dim);
  pointer-events: none;
}
.media-overlay.top { top: 8px; left: auto; right: 8px; }
.media-overlay.error { color: var(--ob-red); border-color: var(--ob-red); }
.media-overlay[hidden] { display: none; }
/* Clear of Leaflet's zoom buttons on the left */
#env-map-note { max-width: calc(100% - 56px); }
/* Touch screens have no zoom buttons (Environment-view.js) */
@media (pointer: coarse) { #env-map-note { max-width: calc(100% - 16px); } }
/* The overlay lets clicks through to the map; its buttons take them */
.media-overlay button { pointer-events: auto; height: 22px; padding: 0 8px; margin-left: 8px; font-size: 10px; }

.media-placeholder {
  position: absolute;
  inset: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 10px;
  font-family: var(--ob-font-mono);
  font-size: 11px;
  letter-spacing: 0.1em;
  text-transform: uppercase;
  color: var(--ob-text-muted);
  pointer-events: none;
}
.media-placeholder svg { width: 32px; height: 32px; fill: var(--ob-border-bright); }
.media-placeholder[hidden] { display: none; }

/* Labelled form fields laid out in as many columns as fit */
.field-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(min(100%, 240px), 1fr));
  gap: 18px 24px;
}
.field { display: flex; flex-direction: column; gap: 6px; min-width: 0; }
.field-label {
  display: flex;
  align-items: baseline;
  gap: 8px;
  font-size: 11px;
  font-weight: 700;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: var(--ob-text-dim);
}
.field-label small { font-weight: 400; text-transform: none; letter-spacing: 0; color: var(--ob-text-muted); }
.field-value { margin-left: auto; font-family: var(--ob-font-mono); font-weight: 700; color: var(--ob-cyan); letter-spacing: 0; text-transform: none; /* units: m/s, not M/S */ }
.field-row { display: flex; align-items: center; gap: 10px; }
.field-row > input[type=range] { flex: 1; }

/* Standard Open Bridge Push Button */
.toggle-row { display: flex; flex-wrap: wrap; gap: 12px; }
.ob-pbtn {
  font-family: var(--ob-font-ui);
  font-weight: 700;
  font-size: 12px;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  min-height: 52px;
  flex: 0 1 160px;
  min-width: 120px;
  padding: 0 20px;
  border-radius: var(--ob-radius);
  border: 2px solid var(--ob-border-bright);
  background: var(--ob-surface);
  color: var(--ob-text-main);
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 10px;
}
.ob-pbtn svg { width: 22px; height: 22px; fill: currentColor; }
.ob-pbtn.on {
  background: var(--ob-on-bg);
  border-color: var(--ob-on-border);
  color: var(--ob-on-text);
}
.ob-pbtn.off {
  background: var(--ob-surface);
  border-color: var(--ob-border-bright);
  color: var(--ob-text-dim);
}

/* Unity Viewport Sizing */
.unity-viewport-container {
  position: relative;
  width: 100%;
  aspect-ratio: 16 / 10;
  max-height: 70dvh;
  background: var(--ob-bg);
  border: 1px solid var(--ob-border);
  display: flex;
  align-items: center;
  justify-content: center;
}
.unity-viewport-container canvas {
  width: 100% !important;
  height: 100% !important;
  display: block;
}

/* Graph Widget */
.graph-container-large {
  position: relative;
  width: 100%;
  height: 180px;
  background: var(--ob-bg);
  border: 1px solid var(--ob-border);
}
.graph-container-large canvas { position: absolute; inset: 0; width: 100%; height: 100%; display: block; }

/* Cable tension legend (LARS01.js): the cable's colour ramp, the tension marked on it */
.tension-legend { margin-top: 10px; font-family: var(--ob-font-mono); font-size: 11px; color: var(--ob-text-dim); }
.tension-legend[hidden] { display: none; }
.tension-legend-bar { position: relative; height: 10px; border-radius: var(--ob-radius); }
.tension-legend-marker {
  position: absolute; top: -4px; bottom: -4px; width: 3px; margin-left: -1.5px;
  background: var(--ob-text-main); box-shadow: 0 0 0 1px var(--ob-bg);
}
.tension-legend-scale { position: relative; height: 16px; margin: 2px 12px 0 0; }
.tension-legend-scale span { position: absolute; transform: translateX(-50%); }
.tension-legend-scale span:first-child { transform: none; }
.tension-legend-key { display: flex; justify-content: space-between; gap: 12px; }
.tension-legend-key i { display: inline-block; width: 10px; height: 10px; margin-right: 6px; vertical-align: -1px; border-radius: var(--ob-radius); }

/* Environment: the swell was outside what real seas do and got corrected (Environment-view.js) */
.sea-limit { color: var(--ob-amber); }
.sea-limit[hidden] { display: none; }

/* AHC effect readout (LARS01.js), in the System Controls card: reuses the splash rows */
.ahc-effect { display: grid; gap: 6px; padding-top: 0; font-family: var(--ob-font-mono); font-size: 12px; }
.ahc-effect .splash-row { grid-template-columns: 64px minmax(0, 1fr) 44px; }
.ahc-result { color: var(--ob-text-muted); font-size: 11px; }
.ahc-result.good { color: var(--ob-green); }
.ahc-result.weak { color: var(--ob-amber); }
.ahc-result.off { color: var(--ob-text-dim); }

/* AHC requested but the sim's interlock won't allow it: the button flashes red, the reason shows under it.
   Tripped (lost while active, latched until the request drops) stays solid red: it's an alarm, not a wait. */
.ob-pbtn.on.blocked {
  background: var(--ob-red-dim);
  border-color: var(--ob-red);
  color: var(--ob-red);
  animation: ahc-blocked 1s steps(1) infinite;
}
.ob-pbtn.on.blocked.tripped { animation: none; background: var(--ob-red); color: var(--ob-bg); }
@keyframes ahc-blocked { 50% { background: var(--ob-surface); border-color: var(--ob-border-bright); color: var(--ob-text-dim); } }
.ahc-status { display: grid; gap: 3px; padding: 0 var(--ob-pad) 8px; color: var(--ob-red); font-family: var(--ob-font-mono); font-size: 11px; }
.ahc-status.tripped .ahc-why-head { font-weight: 700; }
.ahc-status[hidden] { display: none; }
.ahc-why { display: grid; grid-template-columns: 12px auto minmax(0, 1fr); gap: 6px; align-items: baseline; }
.ahc-why i { font-style: normal; font-weight: 700; }
.ahc-why-val { text-align: right; color: var(--ob-text-main); }
.ahc-why.ok { color: var(--ob-green); }
.ahc-why.ok .ahc-why-val { color: var(--ob-text-muted); }
@media (prefers-reduced-motion: reduce) { .ob-pbtn.on.blocked { animation: none; } }

/* Splash zone card (LARS01.js): the load's state and the water's forces on it */
.splash-body { display: grid; gap: 8px; font-family: var(--ob-font-mono); font-size: 12px; }
.splash-row { display: grid; grid-template-columns: 96px minmax(0, 1fr) 52px; align-items: center; gap: 8px; }
.splash-label { color: var(--ob-text-dim); }
.splash-bar { position: relative; height: 8px; background: var(--ob-bg); border: 1px solid var(--ob-border); }
.splash-bar i { position: absolute; inset: 0 auto 0 0; width: 0; background: var(--ob-cyan); }
.splash-row.alarm .splash-bar i { background: var(--ob-red); }
.splash-row.alarm .splash-val { color: var(--ob-red); }
.splash-val { text-align: right; color: var(--ob-text-main); }
.splash-key { color: var(--ob-text-muted); font-size: 11px; }
.splash-state[data-state="air"] { color: var(--ob-text-dim); }
.splash-state[data-state="splash"] { color: var(--ob-amber); }
.splash-state[data-state="submerged"] { color: var(--ob-cyan); }

/* A dashboard that fits the window on wide screens (class "fit", one grid inside): no scrolling, the
   cameras (.area-view) take whatever height is left, letterboxed. Below 540px of height the pane scrolls. */
@media (min-width: 901px) {
  .dashboard-container.fit { align-self: stretch; min-height: 540px; }
  .dashboard-container.fit > * { flex: 1 1 0; min-height: 0; }
  .dashboard-container.fit .area-view { min-height: 0; }
  .dashboard-container.fit .area-view > .card-body { flex: 1 1 0; min-height: 0; }
  .dashboard-container.fit .area-view .media-frame { aspect-ratio: auto; height: 100%; max-height: none; }
}

/* Vessel dashboard (SkandiSkansen.js): cameras, controls in a slim column on the right */
.vessel-grid {
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(180px, 220px);
  grid-template-rows: minmax(0, 1fr);
  gap: var(--ob-gap);
  align-items: start;
}
.vessel-grid > .area-view { align-self: stretch; }
.vessel-grid .toggle-row { flex-direction: column; gap: 8px; }
.vessel-grid .ob-pbtn { flex: none; width: 100%; min-height: 44px; }
@media (max-width: 900px) {
  .vessel-grid { grid-template-columns: minmax(0, 1fr); }
}

/* LARS dashboard. Wide screens: one window, no scrolling. The cameras take whatever height is left
   (letterboxed), tension graph and splash zone sit side by side under them, the controls run down a
   slim right column. Narrow screens stack, levers straight after the cameras. */
.lars-grid {
  display: grid;
  grid-template-columns: minmax(0, 3fr) minmax(0, 2fr) minmax(260px, 300px);
  grid-template-areas:
    "view     view     controls"
    "view     view     levers"
    "graph    splash   levers";
  grid-template-rows: auto minmax(0, 1fr) auto;
  gap: var(--ob-gap);
}
.lars-grid > .area-view     { grid-area: view; }
.lars-grid > .area-controls { grid-area: controls; }
.lars-grid > .area-levers   { grid-area: levers; }
.lars-grid > .area-graph    { grid-area: graph; }
.lars-grid > .area-splash   { grid-area: splash; }
.lars-grid .graph-container-large { height: 120px; }
.lars-grid .graph-val { color: var(--ob-text-main); }
.lars-grid .graph-val.alarm { color: var(--ob-amber); }
.lars-grid .toggle-row { flex-wrap: nowrap; gap: 8px; }
.lars-grid .ob-pbtn { flex: 1 1 0; min-width: 0; min-height: 44px; padding: 0 10px; }
.lars-grid .lever { height: clamp(120px, 26dvh, 260px); }
.lars-grid .levers-container { grid-template-columns: 1fr 1fr; }
@media (min-width: 901px) {
  .lars-grid > .area-levers { align-self: stretch; }
}
@media (max-width: 900px) {
  .lars-grid {
    grid-template-columns: minmax(0, 1fr);
    grid-template-areas: "view" "levers" "controls" "graph" "splash";
    grid-template-rows: none;
  }
}

/* Machinery 1D levers (spring-loaded, see LARS01.js): the whole box is the
   grab area and drags are relative, so a thumb anywhere on it works. */
.levers-container {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(130px, 1fr));
  gap: 12px;
  padding: var(--ob-pad);
}
.lever-box {
  display: flex;
  flex-direction: column;
  align-items: stretch;
  background: var(--ob-surface);
  border: 1px solid var(--ob-border);
  padding: 12px;
  min-width: 0;
}
.lever-header {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  font-size: 11px;
  font-weight: 700;
  letter-spacing: 0.08em;
  color: var(--ob-text-dim);
  text-transform: uppercase;
  margin-bottom: 10px;
}
.lever-header svg { width: 18px; height: 18px; fill: var(--ob-cyan); }

.lever-val {
  font-family: var(--ob-font-mono);
  font-size: 18px;
  font-weight: 700;
  color: var(--ob-cyan);
  background: var(--ob-bg);
  padding: 6px;
  border: 1px solid var(--ob-border);
  text-align: center;
  margin-bottom: 12px;
  font-variant-numeric: tabular-nums;
}

.lever {
  position: relative;
  display: flex;
  justify-content: center;
  gap: 28px; /* clears the thumb, which is wider than the track */
  height: clamp(180px, 34dvh, 280px);
  padding: 12px 0;
  cursor: grab;
  touch-action: none; /* the finger drives the lever, not the page scroll */
  user-select: none;
  -webkit-user-select: none;
  outline-offset: 4px;
}
.lever.dragging { cursor: grabbing; }
.lever[aria-disabled="true"] { opacity: 0.4; cursor: default; }

.lever-scale {
  display: flex;
  flex-direction: column;
  justify-content: space-between;
  margin: -6px 0; /* labels centre on the track ends */
  font-family: var(--ob-font-mono);
  font-size: 10px;
  color: var(--ob-text-muted);
  text-align: right;
}
.lever-track {
  position: relative;
  width: 10px;
  background: var(--ob-bg);
  border: 1px solid var(--ob-border-bright);
}
.lever-zero {
  position: absolute;
  left: -8px; right: -8px;
  height: 1px;
  background: var(--ob-text-muted);
}
.lever-fill {
  position: absolute;
  left: 0; right: 0;
  background: var(--ob-cyan);
  opacity: 0.55;
}
.lever-thumb {
  position: absolute;
  left: 50%;
  width: 44px;
  height: 20px;
  transform: translate(-50%, -50%);
  background: var(--ob-panel-header);
  border: 2px solid var(--ob-cyan);
  border-radius: var(--ob-radius);
  box-shadow: 0 2px 6px var(--ob-shadow);
}
.lever-thumb::after {
  content: "";
  position: absolute;
  left: 8px; right: 8px; top: 50%;
  height: 2px;
  margin-top: -1px;
  background: var(--ob-cyan);
}
.lever.dragging .lever-thumb { background: var(--ob-cyan-dim); }
.lever.springing .lever-thumb,
.lever.springing .lever-fill { transition: top 160ms ease-out, height 160ms ease-out; }

/* Telemetry Table & Logs Layout */
.col { display: flex; flex-direction: column; min-height: 0; min-width: 0; }
.vars { flex: 1.4; border-right: 1px solid var(--ob-border); }
.log { flex: 1; }
.col-head {
  padding: 8px var(--ob-pad);
  min-height: 44px;
  background: var(--ob-panel-header);
  color: var(--ob-text-dim);
  font-size: 11px;
  font-weight: 700;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  border-bottom: 1px solid var(--ob-border);
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  white-space: nowrap;
}
.col-head input[type=text] {
  height: 28px;
  padding: 0 8px;
  font-size: 11px;
  text-transform: none;
  flex: 0 1 200px;
  min-width: 100px;
}
.col-head button { height: 28px; padding: 0 12px; }
.col-body { flex: 1; overflow: auto; background: var(--ob-bg); }

/* Narrow screens: variables over the log, each with its own scroll */
@media (max-width: 900px) {
  #telemetryTab { flex-direction: column; }
  #telemetryTab .vars { flex: none; height: 65dvh; border-right: 0; border-bottom: 1px solid var(--ob-border); }
  #telemetryTab .log { flex: none; height: 45dvh; }
  #telemetryTab table.resizable { min-width: 720px; }
}

table { width: 100%; border-collapse: collapse; font-family: var(--ob-font-mono); }
thead th {
  position: sticky; top: 0; z-index: 1; background: var(--ob-surface);
  text-align: left; padding: 8px 16px; font-size: 11px; color: var(--ob-text-dim);
  border-bottom: 1px solid var(--ob-border);
}
tbody td { padding: 8px 16px; border-bottom: 1px solid var(--ob-surface); font-size: 12px; }
tbody tr:hover { background: color-mix(in srgb, var(--ob-text-main) 3%, transparent); }
tbody tr.flash { animation: flash 600ms ease-out; }
@keyframes flash { from { background: var(--ob-cyan-dim); } to { background: transparent; } }

.vval { color: var(--ob-cyan); font-weight: 700; white-space: nowrap; }

/* Resizable columns (see makeColumnsResizable in telemetry-view.js) */
table.resizable { table-layout: fixed; }
table.resizable th, table.resizable td { box-sizing: border-box; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
table.resizable th:first-child, table.resizable td:first-child { padding-left: 12px; padding-right: 0; }
.col-resizer { position: absolute; top: 0; right: 0; width: 6px; height: 100%; cursor: col-resize; touch-action: none; }
.col-resizer:hover, .col-resizer.dragging { background: var(--ob-cyan-dim); }

/* Value editor popup (value-editor.js); .editable marks the cells that open it */
td.vval.editable { cursor: pointer; }
td.vval.editable:hover { background: var(--ob-cyan-dim); }
.value-editor {
  position: fixed; z-index: 100; min-width: 220px; max-width: min(360px, calc(100vw - 16px)); padding: 10px 12px;
  background: var(--ob-surface); border: 1px solid var(--ob-border); box-shadow: 0 6px 20px var(--ob-shadow);
  font-family: var(--ob-font-mono); font-size: 12px;
}
.ve-head { display: flex; justify-content: space-between; gap: 12px; margin-bottom: 8px; color: var(--ob-text-dim); font-size: 11px; }
.ve-name { color: var(--ob-cyan); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.ve-row { display: flex; align-items: center; gap: 8px; margin-bottom: 6px; }
.ve-row span { width: 1.5em; color: var(--ob-text-dim); }
.ve-row input[type=number], .ve-row input[type=text], .ve-row textarea { flex: 1; min-width: 0; font-family: inherit; }
.ve-error { color: var(--ob-red); min-height: 1em; margin-bottom: 6px; }
.ve-buttons { display: flex; justify-content: flex-end; gap: 8px; }
#log { padding: 8px 16px; font-family: var(--ob-font-mono); font-size: 12px; }
.logline { border-bottom: 1px solid var(--ob-surface); padding: 4px 0; overflow-wrap: anywhere; }
.logline.recv .tag { color: var(--ob-green); }
.logline.sent .tag { color: var(--ob-text-dim); }
.logline.err .tag { color: var(--ob-red); }

/* Connection tab */
.form-row { display: flex; flex-wrap: wrap; gap: 8px; }
.form-row > input[type=text] { flex: 1 1 320px; }

/* Phones */
@media (max-width: 600px) {
  :root { --ob-gap: 10px; --ob-pad: 10px; }
  header { min-height: 48px; gap: 8px; }
  .brand { font-size: 12px; gap: 8px; }
  .brand span { display: none; }
  .tab-btn { padding: 0 14px; }
  input[type=text] { min-width: 0; }
  .ob-pbtn { flex: 1 1 140px; }
}

/* Run report (LARS01-run.js): the Run button records, the report opens when it stops */
.run-btn.recording { color: var(--ob-red); border-color: var(--ob-red); background: var(--ob-red-dim); }
.run-btn.recording svg { animation: run-blink 1s steps(2, start) infinite; }
@keyframes run-blink { to { visibility: hidden; } }
.run-last { display: flex; justify-content: space-between; align-items: center; padding: 0 var(--ob-pad) 8px;
  font-family: var(--ob-font-mono); font-size: 11px; color: var(--ob-text-dim); }
.run-last[hidden] { display: none; }
.run-link { background: none; border: 0; padding: 0; color: var(--ob-cyan); font: inherit; cursor: pointer; text-decoration: underline; }
.run-report-backdrop { position: fixed; inset: 0; z-index: 1000; display: grid; place-items: center; padding: 16px;
  background: var(--ob-shadow); backdrop-filter: blur(2px); }
.run-report { width: min(960px, 100%); max-height: calc(100dvh - 32px); overflow: auto; box-shadow: 0 12px 40px var(--ob-shadow); }
.run-report .dash-card-title { gap: 12px; }
.run-close { background: none; border: 0; color: var(--ob-text-dim); font-size: 22px; line-height: 1; cursor: pointer; padding: 0 4px; }
.run-close:hover { color: var(--ob-text-main); }
.run-tiles { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 8px; }
@media (max-width: 700px) { .run-tiles { grid-template-columns: repeat(2, minmax(0, 1fr)); } }
.run-tile { border: 1px solid var(--ob-border); border-left: 3px solid var(--ob-border-bright); padding: 8px 10px; min-width: 0; }
.run-tile.good { border-left-color: var(--ob-green); }
.run-tile.warn { border-left-color: var(--ob-amber); }
.run-tile.bad  { border-left-color: var(--ob-red); }
.run-tile-label { font-size: 11px; color: var(--ob-text-dim); text-transform: uppercase; letter-spacing: 0.04em; }
.run-tile-value { font-family: var(--ob-font-mono); font-size: 22px; color: var(--ob-text-main); margin: 2px 0; }
.run-tile.warn .run-tile-value { color: var(--ob-amber); }
.run-tile.bad .run-tile-value  { color: var(--ob-red); }
.run-tile-note { font-size: 11px; color: var(--ob-text-muted); overflow-wrap: anywhere; }
.run-trace-title { display: flex; justify-content: space-between; flex-wrap: wrap; gap: 8px; margin: 14px 0 6px;
  font-size: 11px; color: var(--ob-text-dim); text-transform: uppercase; letter-spacing: 0.04em; }
.run-trace-title span { display: flex; gap: 10px; align-items: center; text-transform: none; }
.run-trace-title i { display: inline-block; width: 10px; height: 10px; margin-right: -6px; }
.run-trace-title i.ahc  { background: var(--ob-green-dim); border: 1px solid var(--ob-green); }
.run-trace-title i.low  { border-left: 2px dashed var(--ob-amber); }
.run-trace-title i.slam { border-left: 2px dashed var(--ob-red); }
.run-trace { height: 200px; border: 1px solid var(--ob-border); }
.run-trace canvas { width: 100%; height: 100%; display: block; }
.run-actions { display: flex; justify-content: space-between; align-items: center; gap: 12px; margin-top: 12px; }
.run-actions .ob-pbtn { min-height: 40px; padding: 0 16px; }
