:root,
html[data-theme="halo"] {
  color-scheme: light;
  --desk: oklch(0.94 0.005 240);
  --panel: oklch(0.985 0.003 230);
  --theme-color: #f7f8fa;
  --card: #fff;
  --hairline: oklch(0.92 0.005 230);
  --shell-border: oklch(0.9 0.005 230);
  --text: oklch(0.2 0.01 240);
  --text-2: oklch(0.3 0.01 240);
  --muted: oklch(0.55 0.01 240);
  --tertiary: oklch(0.6 0.01 240);
  --accent-soc: oklch(0.7 0.14 230);
  --accent-soc-deep: oklch(0.5 0.13 230);
  --accent-solar: oklch(0.7 0.14 160);
  --accent-solar-deep: oklch(0.45 0.12 160);
  --accent-water: oklch(0.55 0.08 250);
  --accent-fuel: oklch(0.65 0.1 80);
  --accent-load: oklch(0.75 0.06 60);
  --ok: oklch(0.7 0.14 160);
  --ok-bg: oklch(0.94 0.03 160);
  --ok-text: oklch(0.4 0.1 160);
  --warn: oklch(0.65 0.1 80);
  --warn-bg: oklch(0.95 0.04 80);
  --error: oklch(0.6 0.18 25);
  --error-bg: oklch(0.95 0.04 25);
  --insight-bg: oklch(0.94 0.02 230);
  --insight-title: oklch(0.35 0.06 230);
  --insight-text: oklch(0.35 0.04 240);
  --energy-insight-bg: oklch(0.95 0.025 160);
  --energy-insight-title: oklch(0.35 0.09 160);
  --energy-insight-text: oklch(0.35 0.05 160);
  --net-chip-bg: oklch(0.95 0.025 160);
  --net-chip-fg: oklch(0.45 0.12 160);
  --ring-track-soc: oklch(0.93 0.01 230);
  --ring-track-solar: oklch(0.94 0.02 160);
  --ring-track-water: oklch(0.93 0.008 260);
  --shadow: 0 24px 60px oklch(0.3 0.02 240 / 0.12);
  --icon-btn-bg: #fff;
  --flow-arrow: oklch(0.7 0.02 240);
  --bar-track: oklch(0.93 0.005 230);
  --diag-bg: oklch(0.17 0.012 250);
  --diag-panel: oklch(0.21 0.015 250);
  --diag-text: oklch(0.92 0.005 240);
  --diag-muted: oklch(0.65 0.02 250);
  --diag-border: oklch(0.28 0.015 250);
  --accent: var(--accent-solar);
  --panel-border: var(--diag-border);
  --bg: var(--diag-bg);
}

html[data-theme="night"] {
  color-scheme: dark;
  --desk: oklch(0.12 0.01 250);
  --panel: oklch(0.17 0.012 250);
  --theme-color: #0b1020;
  --card: oklch(0.21 0.015 250);
  --hairline: oklch(0.26 0.015 250);
  --shell-border: oklch(0.28 0.015 250);
  --text: oklch(0.96 0.005 240);
  --text-2: oklch(0.9 0.01 240);
  --muted: oklch(0.55 0.02 250);
  --tertiary: oklch(0.6 0.02 250);
  --shadow: 0 24px 60px oklch(0.1 0.02 250 / 0.5);
  --icon-btn-bg: oklch(0.21 0.015 250);
  --bar-track: oklch(0.26 0.015 250);
  --insight-bg: oklch(0.21 0.02 230);
  --ok-bg: oklch(0.25 0.04 160);
  --ok-text: oklch(0.78 0.1 160);
}

* {
  box-sizing: border-box;
}

html,
body {
  margin: 0;
  min-height: 100%;
  overscroll-behavior-y: none;
}

html.modal-open,
html.modal-open body {
  overscroll-behavior: none;
}

body {
  font-family: "Instrument Sans", system-ui, sans-serif;
  background: var(--desk);
  color: var(--text);
  -webkit-font-smoothing: antialiased;
}

h1,
h2,
h3,
p {
  margin: 0;
}

button {
  font: inherit;
  color: inherit;
  background: none;
  border: none;
  cursor: pointer;
  padding: 0;
}

.tabular,
.num,
[data-bind] {
  font-variant-numeric: tabular-nums;
}

.muted {
  color: var(--muted);
  font-size: 11px;
  font-weight: 500;
}

.hidden {
  display: none !important;
}

/* Author display rules (e.g. .card { display:flex }) must not defeat [hidden]. */
[hidden] {
  display: none !important;
}

/* —— Layout shell —— */

.desk {
  min-height: 100vh;
  display: flex;
  justify-content: center;
  align-items: flex-start;
  padding: 24px 16px 48px;
}

.phone-shell {
  width: min(100%, 430px);
  background: var(--panel);
  border-radius: 44px;
  border: 1px solid var(--shell-border);
  box-shadow: var(--shadow);
  padding: 28px 24px 24px;
  display: flex;
  flex-direction: column;
  gap: 22px;
  position: relative;
  overflow: hidden;
}

.view[hidden] {
  display: none !important;
}

.view-home {
  display: contents;
}

html[data-theme="halo"] .night-surface,
html[data-theme="night"] .halo-surface {
  display: none !important;
}

.halo-surface,
.night-surface {
  display: flex;
  flex-direction: column;
  gap: 22px;
}

.view-detail {
  display: flex;
  flex-direction: column;
  gap: 20px;
}

/* —— Typography helpers —— */

.boat-name,
.card-title,
.night-brand,
.detail-header h1,
.runway-huge,
.soc-big,
.num {
  font-family: Sora, sans-serif;
}

.soc-big {
  font-size: 30px;
  font-weight: 300;
  letter-spacing: -0.03em;
  line-height: 1;
  color: var(--text);
  max-width: 92px;
  text-align: center;
  font-variant-numeric: tabular-nums;
}

.runway-label {
  font-size: 11px;
  color: var(--muted);
  font-weight: 500;
  max-width: 84px;
  text-align: center;
  line-height: 1.25;
  margin-top: 4px;
}

.runway-huge {
  font-size: clamp(48px, 14vw, 58px);
  font-weight: 300;
  letter-spacing: -0.03em;
  line-height: 1;
  color: var(--text);
}

.eyebrow {
  font-size: 12px;
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: 0.14em;
}

/* —— Header —— */

.home-header,
.night-header,
.detail-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}

.boat-identity {
  display: flex;
  flex-direction: column;
  gap: 2px;
  text-align: left;
  min-width: 0;
}

.boat-name {
  font-size: 20px;
  font-weight: 700;
  letter-spacing: -0.02em;
  color: var(--text);
}

.boat-model {
  font-size: 12px;
  color: var(--muted);
}

.home-header-actions {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-shrink: 0;
}

.status-pill {
  display: flex;
  align-items: center;
  gap: 6px;
  border: none;
  cursor: pointer;
  font: inherit;
  background: var(--ok-bg);
  color: var(--ok-text);
  font-size: 12px;
  font-weight: 600;
  padding: 6px 12px;
  border-radius: 999px;
  white-space: nowrap;
}

.status-pill:focus-visible {
  outline: 2px solid var(--accent-soc);
  outline-offset: 2px;
}

.status-pill[data-level="attention"] {
  background: var(--warn-bg);
  color: var(--warn);
}

.status-pill[data-level="alarm"] {
  background: var(--error-bg);
  color: var(--error);
}

.status-dot {
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: var(--ok);
  animation: pulse 3s infinite;
  flex-shrink: 0;
}

.status-pill[data-level="attention"] .status-dot {
  background: var(--warn);
}

.status-pill[data-level="alarm"] .status-dot {
  background: var(--error);
  animation: none;
}

@keyframes pulse {
  0%,
  100% {
    opacity: 1;
  }
  50% {
    opacity: 0.35;
  }
}

.icon-btn {
  width: 44px;
  height: 44px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  border-radius: 50%;
  flex-shrink: 0;
}

.icon-btn .moon-icon,
.moon-btn {
  position: relative;
}

.moon-icon {
  width: 34px;
  height: 34px;
  border-radius: 50%;
  background: var(--icon-btn-bg);
  border: 1px solid var(--shell-border);
  display: flex;
  align-items: center;
  justify-content: center;
}

.moon-icon::before {
  content: "";
  width: 14px;
  height: 14px;
  border-radius: 50%;
  background: transparent;
  box-shadow: inset -3px -1px 0 0 oklch(0.45 0.02 250);
  display: block;
}

html[data-theme="night"] .moon-icon::before {
  background: oklch(0.85 0.02 80);
  box-shadow: none;
}

.settings-icon {
  width: 34px;
  height: 34px;
  border-radius: 50%;
  background: var(--icon-btn-bg);
  border: 1px solid var(--shell-border);
  display: flex;
  align-items: center;
  justify-content: center;
  position: relative;
}

.settings-icon::before {
  content: "";
  width: 14px;
  height: 14px;
  border-radius: 50%;
  border: 2px solid oklch(0.45 0.02 250);
  box-sizing: border-box;
}

.settings-icon::after {
  content: "";
  position: absolute;
  width: 18px;
  height: 18px;
  background:
    radial-gradient(circle at 50% 0, oklch(0.45 0.02 250) 1.6px, transparent 1.7px),
    radial-gradient(circle at 50% 100%, oklch(0.45 0.02 250) 1.6px, transparent 1.7px),
    radial-gradient(circle at 0 50%, oklch(0.45 0.02 250) 1.6px, transparent 1.7px),
    radial-gradient(circle at 100% 50%, oklch(0.45 0.02 250) 1.6px, transparent 1.7px),
    radial-gradient(circle at 18% 18%, oklch(0.45 0.02 250) 1.4px, transparent 1.5px),
    radial-gradient(circle at 82% 18%, oklch(0.45 0.02 250) 1.4px, transparent 1.5px),
    radial-gradient(circle at 18% 82%, oklch(0.45 0.02 250) 1.4px, transparent 1.5px),
    radial-gradient(circle at 82% 82%, oklch(0.45 0.02 250) 1.4px, transparent 1.5px);
}

html[data-theme="night"] .settings-icon::before {
  border-color: oklch(0.78 0.02 250);
}

html[data-theme="night"] .settings-icon::after {
  background:
    radial-gradient(circle at 50% 0, oklch(0.78 0.02 250) 1.6px, transparent 1.7px),
    radial-gradient(circle at 50% 100%, oklch(0.78 0.02 250) 1.6px, transparent 1.7px),
    radial-gradient(circle at 0 50%, oklch(0.78 0.02 250) 1.6px, transparent 1.7px),
    radial-gradient(circle at 100% 50%, oklch(0.78 0.02 250) 1.6px, transparent 1.7px),
    radial-gradient(circle at 18% 18%, oklch(0.78 0.02 250) 1.4px, transparent 1.5px),
    radial-gradient(circle at 82% 18%, oklch(0.78 0.02 250) 1.4px, transparent 1.5px),
    radial-gradient(circle at 18% 82%, oklch(0.78 0.02 250) 1.4px, transparent 1.5px),
    radial-gradient(circle at 82% 82%, oklch(0.78 0.02 250) 1.4px, transparent 1.5px);
}

/* Connections sheet */
.connections {
  position: fixed;
  inset: 0;
  z-index: 60;
  background: oklch(0.2 0.01 240 / 0.35);
  display: flex;
  align-items: flex-end;
  justify-content: center;
  padding:
    max(16px, env(safe-area-inset-top, 0px))
    max(16px, env(safe-area-inset-right, 0px))
    max(16px, env(safe-area-inset-bottom, 0px))
    max(16px, env(safe-area-inset-left, 0px));
  overscroll-behavior: contain;
  touch-action: none;
}

.connections[hidden] {
  display: none;
}

.connections-sheet {
  width: min(420px, 100%);
  /* Cap to overlay content box (safe-area padding) — vh alone overflows under the island. */
  max-height: min(
    78vh,
    640px,
    100%,
    calc(
      100dvh - max(16px, env(safe-area-inset-top, 0px)) -
        max(16px, env(safe-area-inset-bottom, 0px))
    )
  );
  overflow: auto;
  -webkit-overflow-scrolling: touch;
  overscroll-behavior: contain;
  touch-action: pan-y;
  background: var(--panel);
  border: 1px solid var(--hairline);
  border-radius: 28px 28px 22px 22px;
  padding: 20px 18px max(18px, env(safe-area-inset-bottom, 0px));
  display: flex;
  flex-direction: column;
  gap: 14px;
  box-shadow: 0 18px 50px oklch(0.3 0.02 240 / 0.2);
}

.connections-header {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 12px;
}

.connections-header h2 {
  margin: 0;
  font-family: Sora, sans-serif;
  font-size: 22px;
  font-weight: 600;
  letter-spacing: -0.02em;
}

.connection-list {
  list-style: none;
  margin: 0;
  padding: 0;
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.connection-row {
  display: grid;
  grid-template-columns: 10px 1fr auto;
  gap: 12px;
  align-items: start;
  padding: 14px 14px;
  border-radius: 18px;
  background: var(--card);
  border: 1px solid var(--hairline);
}

.connection-row .conn-dot {
  width: 10px;
  height: 10px;
  border-radius: 50%;
  margin-top: 5px;
  background: oklch(0.7 0.02 240);
}

.connection-row[data-state="live"] .conn-dot {
  background: var(--ok);
  box-shadow: 0 0 0 4px var(--ok-bg);
}

.connection-row[data-state="stale"] .conn-dot {
  background: var(--warn);
}

.connection-row[data-state="offline"] .conn-dot {
  background: var(--error);
}

.connection-row .conn-label {
  font-weight: 600;
  font-size: 15px;
  color: var(--text);
}

.connection-row .conn-meta {
  font-size: 12px;
  color: var(--muted);
  margin-top: 2px;
  line-height: 1.35;
}

.connection-row .conn-state {
  font-size: 12px;
  font-weight: 700;
  color: var(--text-2);
  font-variant-numeric: tabular-nums;
  text-align: right;
}

.connections-footnote {
  margin: 0;
  font-size: 12px;
  color: var(--muted);
  line-height: 1.4;
}

.connections-footnote:empty {
  display: none;
}

.connections-deep-link {
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  gap: 2px;
  width: 100%;
  text-align: left;
  padding: 14px 16px;
  border-radius: 18px;
  border: 1px solid var(--hairline);
  background: transparent;
  color: var(--text);
  font: inherit;
  font-weight: 600;
  cursor: pointer;
}

.connections-deep-link .muted {
  font-weight: 500;
  font-size: 12px;
}

.connections-build {
  margin: 10px 2px 0;
  font-size: 11px;
  font-weight: 500;
  letter-spacing: 0.02em;
  color: var(--muted);
  opacity: 0.85;
  line-height: 1.35;
  font-variant-numeric: tabular-nums;
}

.connections-build[hidden] {
  display: none;
}

.chart-note {
  margin: 0;
  font-size: 12px;
  color: var(--muted);
  line-height: 1.35;
}

.night-brand {
  font-size: 16px;
  font-weight: 600;
  letter-spacing: 0.06em;
  color: var(--text);
  text-transform: uppercase;
}

.night-meta {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 12px;
  color: var(--muted);
}

.back-btn {
  width: 44px;
  height: 44px;
  border-radius: 50%;
  background: var(--card);
  border: 1px solid var(--shell-border);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  font-size: 22px;
  color: var(--muted);
  line-height: 1;
  flex-shrink: 0;
}

.detail-header h1 {
  font-size: 17px;
  font-weight: 700;
  letter-spacing: -0.02em;
}

.detail-header .sub {
  font-size: 12px;
  color: var(--muted);
  margin-top: 2px;
}

.detail-header > div:last-child {
  min-width: 0;
}

/* —— Hero carousel —— */

.hero-carousel {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 12px;
  width: 100%;
}

.hero-viewport {
  width: 100%;
  overflow: hidden;
  touch-action: pan-y;
}

.hero-track {
  display: flex;
  width: 100%;
  transition: transform 0.35s cubic-bezier(0.22, 1, 0.36, 1);
  will-change: transform;
}

.hero-track.dragging {
  transition: none;
}

.hero-page {
  flex: 0 0 100%;
  min-height: 278px;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 10px;
  padding: 4px 8px 0;
  box-sizing: border-box;
  cursor: pointer;
  user-select: none;
  -webkit-user-select: none;
  background: none;
  border: none;
  color: inherit;
  text-align: center;
}

.hero-page:focus-visible {
  outline: 2px solid var(--accent-soc);
  outline-offset: 4px;
  border-radius: 16px;
}

.hero-page .eyebrow {
  font-size: 11px;
  font-weight: 600;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--muted);
}

.halo-runway {
  color: var(--text);
  line-height: 0.95;
}

.hero-hint {
  font-size: 13px;
  color: var(--muted);
  max-width: 240px;
  line-height: 1.35;
}

.hero-volt-row {
  display: flex;
  gap: 28px;
  margin-top: 8px;
}

.hero-volt {
  display: flex;
  flex-direction: column;
  gap: 2px;
  min-width: 72px;
}

.hero-volt strong {
  font-family: Sora, sans-serif;
  font-size: 22px;
  font-weight: 600;
  font-variant-numeric: tabular-nums;
  color: var(--text-2);
}

.load-hero-num {
  font-family: Sora, sans-serif;
  font-size: 48px;
  font-weight: 300;
  font-variant-numeric: tabular-nums;
  color: var(--text);
  line-height: 1;
}

.hero-sparkline {
  width: min(280px, 88%);
  height: 70px;
  display: block;
}

.card-sparkline {
  width: 100%;
  height: 36px;
  display: block;
  margin-top: 10px;
  margin-bottom: 0;
}

.energy-card-charts {
  display: flex;
  flex-direction: column;
  gap: 0;
  margin: 0;
  padding: 0;
  border: none;
  background: transparent;
  width: 100%;
  min-width: 0;
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
}

.energy-card-charts:focus-visible {
  outline: 2px solid color-mix(in oklab, var(--accent-load) 55%, transparent);
  outline-offset: 4px;
  border-radius: 12px;
}

.rings-wrap {
  position: relative;
  width: 240px;
  height: 240px;
}

.rings-svg {
  width: 240px;
  height: 240px;
  transform: rotate(-90deg);
  display: block;
}

.ring-track {
  fill: none;
  stroke-width: 13;
}

.rings-svg .ring-track:nth-of-type(1) {
  stroke: var(--ring-track-soc);
}
.rings-svg .ring-track:nth-of-type(3) {
  stroke: var(--ring-track-solar);
}
.rings-svg .ring-track:nth-of-type(5) {
  stroke: var(--ring-track-water);
}

.ring-fill {
  fill: none;
  stroke-width: 13;
  stroke-linecap: round;
  transition: stroke-dashoffset 0.6s ease;
}

.ring-soc {
  stroke: var(--accent-soc);
}
.ring-volts {
  stroke: var(--accent-solar);
}
.ring-water {
  stroke: var(--accent-water);
}

.rings-center {
  position: absolute;
  /* Keep type inside the innermost ring hole (~r=48 of 200 viewBox). */
  inset: 28%;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 0;
  pointer-events: none;
  overflow: hidden;
}

.ring-legend {
  display: flex;
  gap: 18px;
  font-size: 11px;
  font-weight: 600;
  flex-wrap: wrap;
  justify-content: center;
}

.leg {
  display: inline-flex;
  align-items: center;
  gap: 5px;
}

.leg i {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  display: inline-block;
}

.leg-soc {
  color: oklch(0.45 0.1 230);
}
.leg-soc i {
  background: var(--accent-soc);
}
.leg-volts {
  color: oklch(0.42 0.1 160);
}
.leg-volts i {
  background: var(--accent-solar);
}
.leg-water {
  color: oklch(0.45 0.06 250);
}
.leg-water i {
  background: var(--accent-water);
}

html[data-theme="night"] .leg-soc,
html[data-theme="night"] .leg-volts,
html[data-theme="night"] .leg-water {
  color: var(--muted);
}

.page-dots {
  display: flex;
  gap: 6px;
  align-items: center;
  justify-content: center;
}

.page-dots .dot {
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: oklch(0.85 0.01 240);
  border: none;
  padding: 0;
  cursor: pointer;
  transition: background 0.2s ease, transform 0.2s ease;
}

.page-dots .dot.active {
  background: oklch(0.3 0.01 240);
  transform: scale(1.15);
}

html[data-theme="night"] .page-dots .dot {
  background: oklch(0.35 0.015 250);
}
html[data-theme="night"] .page-dots .dot.active {
  background: oklch(0.85 0.01 240);
}

/* —— Cards —— */

.card,
button.card {
  background: var(--card);
  border: 1px solid var(--hairline);
  border-radius: 24px;
  padding: 18px;
  display: flex;
  flex-direction: column;
  gap: 14px;
  text-align: left;
  width: 100%;
}

button.card:hover,
button.card:focus-visible,
.card[data-nav]:hover,
.card[data-nav]:focus-visible {
  border-color: oklch(0.7 0.05 230 / 0.45);
  outline: none;
  cursor: pointer;
}

.load-spark-toolbar {
  display: flex;
  justify-content: flex-end;
  margin-top: 14px;
}

.load-spark-ranges {
  flex-shrink: 0;
}

.home-sticky-chrome,
.night-sticky-chrome {
  display: flex;
  flex-direction: column;
  gap: 0;
  min-width: 0;
}

.met-strip {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 8px;
  /* Tight under header in sticky chrome; pull toward rings against surface gap. */
  padding: 8px 4px;
  margin: 0 0 -8px;
  border-top: 1px solid oklch(0.93 0.005 230);
  border-bottom: 1px solid oklch(0.93 0.005 230);
  font-size: 12.5px;
  font-weight: 500;
  letter-spacing: -0.01em;
  color: oklch(0.45 0.01 240);
  font-variant-numeric: tabular-nums;
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
  user-select: none;
}

.met-strip:focus-visible {
  outline: 2px solid oklch(0.7 0.08 230);
  outline-offset: 2px;
  border-radius: 4px;
}

.met-strip[hidden] {
  display: none !important;
}

.met-cell {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  min-width: 0;
  white-space: nowrap;
}

.met-wind {
  flex: 0 1 auto;
}

.met-pressure {
  gap: 4px;
}

.met-trend {
  color: oklch(0.45 0.1 160);
  font-weight: 600;
}

.met-trend[data-trend="rising"] {
  color: oklch(0.48 0.11 160);
}

.met-trend[data-trend="falling"] {
  color: oklch(0.5 0.08 50);
}

.met-trend[hidden] {
  display: none !important;
}

.met-forecast {
  color: oklch(0.5 0.04 230);
  font-weight: 500;
  text-align: right;
  justify-content: flex-end;
}

.met-arrow {
  display: inline-block;
  width: 11px;
  height: 11px;
  flex-shrink: 0;
  background: oklch(0.5 0.01 240);
  /* mockup wind dart; rotate via --wind-deg (degrees FROM which wind blows) */
  -webkit-mask: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 12 12'%3E%3Cpath fill='black' d='M6 1L9 10L6 8L3 10Z'/%3E%3C/svg%3E") center / contain no-repeat;
  mask: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 12 12'%3E%3Cpath fill='black' d='M6 1L9 10L6 8L3 10Z'/%3E%3C/svg%3E") center / contain no-repeat;
  transform: rotate(var(--wind-deg, 0deg));
  transform-origin: 50% 55%;
}

.met-strip-night {
  border-color: oklch(0.28 0.015 250);
  color: oklch(0.84 0.01 240);
}

.met-strip-night .met-arrow {
  background: oklch(0.78 0.01 240);
}

.met-strip-night .met-forecast {
  color: oklch(0.72 0.05 230);
}

.met-strip-night .met-trend {
  color: oklch(0.72 0.09 160);
}

.met-strip-night .met-trend[data-trend="falling"] {
  color: oklch(0.72 0.07 50);
}

.card-head {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 10px;
}

.card-title {
  font-size: 13px;
  font-weight: 600;
  color: var(--text-2);
}

.net-chip {
  font-size: 12px;
  font-weight: 700;
  color: var(--net-chip-fg);
  background: var(--net-chip-bg);
  padding: 3px 10px;
  border-radius: 999px;
}

.net-chip.discharge {
  color: oklch(0.45 0.08 40);
  background: oklch(0.95 0.03 60);
}

.net-chip.charge {
  color: var(--net-chip-fg);
  background: var(--net-chip-bg);
}

.flow-row {
  display: grid;
  grid-template-columns: 1fr auto 1fr auto 1fr;
  align-items: center;
  gap: 4px;
}

.flow-col {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 2px;
  text-align: center;
}

.flow-col .num {
  font-size: 18px;
  font-weight: 700;
}

.flow-col .num.solar {
  color: var(--accent-solar-deep);
}
.flow-col .num.house {
  color: var(--accent-soc-deep);
}
.flow-col .num.load {
  color: var(--text);
}

html[data-theme="night"] .flow-col .num.solar {
  color: oklch(0.78 0.13 160);
}
html[data-theme="night"] .flow-col .num.house {
  color: oklch(0.8 0.11 230);
}

.flow-arrow {
  color: var(--flow-arrow);
  font-size: 16px;
}

.tank-bars {
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.tank-home-summary {
  margin: 2px 0 10px;
  font-size: 12px;
  line-height: 1.35;
  color: var(--muted);
  font-variant-numeric: tabular-nums;
}

.tank-home-summary:empty {
  display: none;
  margin: 0;
}

.tank-row,
.load-row {
  display: grid;
  grid-template-columns: 52px 1fr 40px;
  align-items: center;
  gap: 10px;
  font-size: 12px;
}

.tank-row > span,
.load-row > span {
  color: oklch(0.5 0.01 240);
}

html[data-theme="night"] .tank-row > span,
html[data-theme="night"] .load-row > span {
  color: var(--muted);
}

.tank-row strong,
.load-row strong {
  text-align: right;
  font-weight: 600;
  color: var(--text-2);
  font-variant-numeric: tabular-nums;
}

.bar {
  height: 6px;
  border-radius: 999px;
  background: var(--bar-track);
  overflow: hidden;
}

.bar.thick {
  height: 10px;
}

.bar-fill {
  height: 100%;
  border-radius: 999px;
  width: 0%;
  transition: width 0.5s ease;
}

.bar-fill.water {
  background: oklch(0.7 0.1 230);
}
.bar-fill.fuel {
  background: var(--accent-fuel);
}
.bar-fill.waste {
  background: oklch(0.6 0.02 240);
}
.load-row .bar-fill {
  background: var(--accent-soc);
}

.chip-row-home {
  display: flex;
  gap: 10px;
}

.mini-card {
  flex: 1;
  min-width: 0;
  background: var(--card);
  border: 1px solid var(--hairline);
  border-radius: 20px;
  padding: 14px 12px;
  display: flex;
  flex-direction: column;
  gap: 2px;
  cursor: default;
}

.mini-card[data-nav],
.mini-card[role="button"] {
  cursor: pointer;
}

.mini-card .muted {
  font-size: 11px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.mini-card .num {
  font-size: 15px;
  font-weight: 700;
  color: var(--text-2);
}

/* —— Night Watch —— */

.night-hero {
  display: flex;
  flex-direction: column;
  gap: 4px;
  cursor: pointer;
}

.night-hero .hint {
  font-size: 13px;
  color: oklch(0.65 0.03 160);
  margin-top: 2px;
}

.flow-list {
  display: flex;
  flex-direction: column;
}

.flow-item {
  display: grid;
  grid-template-columns: 1fr auto;
  align-items: center;
  padding: 13px 0;
  border-bottom: 1px solid var(--hairline);
  gap: 12px;
  text-align: left;
  width: 100%;
  background: none;
  border-left: none;
  border-right: none;
  border-top: none;
  color: inherit;
  cursor: default;
}

.flow-item[data-nav] {
  cursor: pointer;
}

.flow-item:last-child {
  border-bottom: none;
}

.flow-left {
  display: flex;
  align-items: center;
  gap: 12px;
  min-width: 0;
}

.flow-name {
  font-size: 14px;
  font-weight: 500;
  color: var(--text-2);
}

.flow-sub {
  font-size: 11px;
  color: var(--muted);
}

.flow-item .num {
  font-size: 18px;
  font-weight: 600;
}

.flow-item .num.solar {
  color: oklch(0.78 0.13 160);
}
.flow-item .num.house {
  color: oklch(0.8 0.11 230);
}
.flow-item .num.load-warm {
  color: oklch(0.85 0.05 60);
}
.flow-item .num.muted-strong {
  color: var(--muted);
}

.flow-line line.animating {
  animation: flowdash 1.2s linear infinite;
}

.flow-line line.animating.slow {
  animation-duration: 1.6s;
}

@keyframes flowdash {
  to {
    stroke-dashoffset: -24;
  }
}

.mini-ring {
  width: 36px;
  height: 36px;
  flex-shrink: 0;
}

.mini-ring svg {
  width: 36px;
  height: 36px;
  transform: rotate(-90deg);
  display: block;
}

.mini-ring .ring-track {
  stroke: oklch(0.28 0.015 250);
  stroke-width: 4;
}

.mini-ring .ring-fill {
  stroke-width: 4;
}

.night-tiles {
  display: flex;
  gap: 8px;
}

.night-tile {
  flex: 1;
  min-width: 0;
  background: var(--card);
  border-radius: 18px;
  padding: 12px 10px;
  display: flex;
  flex-direction: column;
  gap: 2px;
  text-align: left;
  border: none;
  color: inherit;
}

.night-tile .muted {
  font-size: 11px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.night-tile strong {
  font-family: Sora, sans-serif;
  font-size: 15px;
  font-weight: 600;
  color: var(--text);
  font-variant-numeric: tabular-nums;
}

/* —— Detail screens —— */

.stat-trio {
  display: grid;
  grid-template-columns: 1fr 1fr 1fr;
  gap: 8px;
}

.stat {
  background: var(--card);
  border: 1px solid var(--hairline);
  border-radius: 18px;
  padding: 12px 14px;
  display: flex;
  flex-direction: column;
  gap: 1px;
}

.stat .num {
  font-size: 19px;
  font-weight: 700;
  color: var(--text-2);
}

.stat .num.house {
  color: var(--accent-soc-deep);
}

.stat .num.charging {
  color: var(--accent-solar-deep);
}

.seg-tabs {
  display: flex;
  background: oklch(0.94 0.005 230);
  border-radius: 999px;
  padding: 2px;
  font-size: 11px;
  font-weight: 600;
}

html[data-theme="night"] .seg-tabs {
  background: oklch(0.14 0.01 250);
}

.seg {
  padding: 4px 12px;
  border-radius: 999px;
  color: var(--muted);
  border: none;
  background: transparent;
  cursor: pointer;
  font: inherit;
  font-size: 11px;
  font-weight: 600;
}

.seg.active {
  background: var(--card);
  color: var(--text-2);
  box-shadow: 0 1px 3px oklch(0.3 0.02 240 / 0.15);
}

.seg:disabled {
  opacity: 0.45;
  cursor: not-allowed;
}

.area-chart {
  display: block;
  width: 100%;
  height: 110px;
  touch-action: none;
  user-select: none;
  -webkit-user-select: none;
  -webkit-touch-callout: none;
  -webkit-user-drag: none;
  cursor: crosshair;
}

.area-chart-interactive {
  touch-action: none;
}

.chart-axis {
  display: flex;
  justify-content: space-between;
  font-size: 10px;
  color: var(--tertiary);
  font-variant-numeric: tabular-nums;
}

.insight-card {
  border-radius: 24px;
  padding: 18px;
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.insight-card p {
  font-size: 13px;
  line-height: 1.5;
}

.runway-insight {
  background: var(--insight-bg);
}

.runway-insight .card-title {
  color: var(--insight-title);
}

.runway-insight p {
  color: var(--insight-text);
}

.energy-insight {
  background: var(--energy-insight-bg);
}

.energy-insight .card-title {
  color: var(--energy-insight-title);
}

.energy-insight p {
  color: var(--energy-insight-text);
}

.cycle-bar {
  display: flex;
  gap: 6px;
  align-items: center;
}

.cycle {
  height: 8px;
}

.cycle.bulk {
  flex: 3;
  border-radius: 999px 0 0 999px;
  background: var(--accent-solar);
}
.cycle.absorb {
  flex: 2;
  background: oklch(0.8 0.09 160);
}
.cycle.float {
  flex: 4;
  border-radius: 0 999px 999px 0;
  background: oklch(0.92 0.02 160);
}

.cycle-labels,
.health-row,
.tank-meta {
  display: flex;
  justify-content: space-between;
  font-size: 11px;
  color: var(--muted);
  gap: 8px;
}

.health-row {
  padding-top: 8px;
  border-top: 1px solid var(--hairline);
  font-size: 12px;
}

.stub-note {
  font-size: 12px;
  color: var(--muted);
  line-height: 1.4;
}

.load-bars {
  display: flex;
  flex-direction: column;
  gap: 13px;
}

.load-row {
  grid-template-columns: 60px 1fr 44px;
}

.load-row .bar {
  height: 7px;
}

.tank-detail {
  gap: 8px;
}

.tank-detail-head {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
}

.tank-detail-head .num {
  font-size: 22px;
  font-weight: 700;
}

.tank-detail-head .num.fuel {
  color: oklch(0.55 0.09 80);
}

.tank-meta {
  font-size: 12px;
}

.unit-toggle-hint {
  font: inherit;
  color: var(--muted);
  background: none;
  border: none;
  padding: 0;
  cursor: pointer;
  text-decoration: underline;
  text-decoration-style: dotted;
  text-underline-offset: 3px;
}

.unit-toggle {
  cursor: pointer;
  text-decoration: underline;
  text-decoration-style: dotted;
  text-underline-offset: 3px;
}

/* —— Diagnostics —— */

.diagnostics {
  position: fixed;
  inset: 0;
  z-index: 50;
  background: oklch(0.1 0.01 250 / 0.55);
  backdrop-filter: blur(6px);
  overflow: auto;
  -webkit-overflow-scrolling: touch;
  overscroll-behavior: contain;
  touch-action: pan-y;
  padding:
    max(24px, calc(env(safe-area-inset-top, 0px) + 12px))
    max(16px, env(safe-area-inset-right, 0px))
    max(24px, calc(env(safe-area-inset-bottom, 0px) + 12px))
    max(16px, env(safe-area-inset-left, 0px));
}

.diagnostics[hidden] {
  display: none !important;
}

.diagnostics-panel {
  max-width: 1100px;
  margin: 0 auto;
  background: var(--diag-bg);
  color: var(--diag-text);
  border-radius: 24px;
  border: 1px solid var(--diag-border);
  padding: 1.25rem 1.5rem 2rem;
}

.diagnostics-header {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 1rem;
  margin-bottom: 1rem;
}

.diagnostics-header h2 {
  font-family: Sora, sans-serif;
  font-size: 1.25rem;
  font-weight: 700;
}

.diagnostics .icon-btn {
  color: var(--diag-text);
  width: 40px;
  height: 40px;
  border: 1px solid var(--diag-border);
  border-radius: 50%;
  background: var(--diag-panel);
}

.diag-meta {
  display: flex;
  gap: 0.75rem;
  align-items: center;
  flex-wrap: wrap;
  margin-bottom: 1rem;
  color: var(--diag-muted);
  font-size: 0.9rem;
}

.badge {
  display: inline-flex;
  align-items: center;
  padding: 0.2rem 0.55rem;
  border-radius: 999px;
  font-size: 0.75rem;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  background: var(--diag-panel);
  border: 1px solid var(--diag-border);
  color: var(--diag-muted);
}

.badge.online {
  color: #68d391;
  border-color: rgba(104, 211, 145, 0.4);
}

.badge.offline {
  color: #fc8181;
  border-color: rgba(252, 129, 129, 0.4);
}

.badge.demo {
  color: #f6ad55;
  border-color: rgba(246, 173, 85, 0.4);
}

.badge.victron {
  color: #7f9cf5;
}
.badge.renogy {
  color: #68d391;
}
.badge.xanbus {
  color: #f6ad55;
}

.scan-panel,
.history-panel,
.device-grid {
  padding: 0;
  margin-bottom: 1.5rem;
}

.scan-header {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 1rem;
  flex-wrap: wrap;
}

.scan-header h3,
.history-header h3 {
  margin-bottom: 0.35rem;
  font-size: 1rem;
  color: var(--diag-muted);
  font-family: Sora, sans-serif;
}

.scan-help,
.history-help {
  color: var(--diag-muted);
  font-size: 0.9rem;
}

.scan-help code {
  color: var(--diag-text);
}

.scan-actions {
  display: flex;
  gap: 0.5rem;
  flex-wrap: wrap;
}

.scan-actions button,
.diagnostics .chip {
  border: 1px solid var(--diag-border);
  background: var(--diag-panel);
  color: var(--diag-text);
  border-radius: 10px;
  padding: 0.55rem 0.85rem;
  cursor: pointer;
  font: inherit;
}

.scan-actions button.primary {
  background: rgba(79, 209, 197, 0.12);
  border-color: rgba(79, 209, 197, 0.45);
}

.scan-actions button:disabled {
  opacity: 0.6;
  cursor: wait;
}

.scan-status {
  color: var(--diag-muted);
  font-size: 0.9rem;
  margin: 0.75rem 0;
}

.scan-results {
  display: grid;
  gap: 0.75rem;
}

.scan-group h3 {
  font-size: 0.95rem;
  color: var(--diag-muted);
  margin-bottom: 0.5rem;
}

.scan-list {
  display: grid;
  gap: 0.65rem;
}

.scan-item {
  background: var(--diag-panel);
  border: 1px solid var(--diag-border);
  border-radius: 12px;
  padding: 0.85rem 1rem;
}

.scan-item-head {
  display: flex;
  justify-content: space-between;
  gap: 0.75rem;
  align-items: center;
  margin-bottom: 0.35rem;
}

.scan-meta {
  color: var(--diag-muted);
  font-size: 0.85rem;
}

.scan-config {
  margin-top: 0.55rem;
  padding: 0.55rem 0.65rem;
  background: rgba(255, 255, 255, 0.03);
  border-radius: 8px;
  font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
  font-size: 0.78rem;
  white-space: pre-wrap;
  color: #c6d4f5;
}

.scan-empty {
  color: var(--diag-muted);
  font-size: 0.9rem;
}

.scan-hints {
  margin-top: 0.75rem;
  padding: 0.85rem 1rem;
  border-radius: 12px;
  border: 1px solid rgba(246, 173, 85, 0.35);
  background: rgba(246, 173, 85, 0.08);
}

.scan-hints p {
  margin: 0 0 0.45rem;
  color: #f6d9a8;
  font-size: 0.88rem;
}

.device-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(280px, 1fr));
  gap: 1rem;
}

.device-card {
  background: var(--diag-panel);
  border: 1px solid var(--diag-border);
  border-radius: 16px;
  padding: 1rem;
}

.device-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 0.5rem;
  margin-bottom: 0.5rem;
}

.device-status {
  color: var(--diag-muted);
  font-size: 0.85rem;
  margin-bottom: 0.75rem;
  min-height: 1.1rem;
}

.metrics {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 0.65rem;
}

.metric {
  background: rgba(255, 255, 255, 0.03);
  border-radius: 10px;
  padding: 0.65rem 0.75rem;
}

.metric .key {
  display: block;
  color: var(--diag-muted);
  font-size: 0.75rem;
  margin-bottom: 0.2rem;
}

.metric .value {
  font-size: 1.05rem;
  font-weight: 600;
}

.sparkline-wrap {
  margin-top: 0.85rem;
}

.sparkline {
  width: 100%;
  height: 48px;
}

.history-header {
  display: flex;
  justify-content: space-between;
  align-items: flex-end;
  gap: 1rem;
  flex-wrap: wrap;
  margin-bottom: 0.85rem;
}

.history-controls {
  display: flex;
  flex-direction: column;
  align-items: flex-end;
  gap: 0.45rem;
}

.chip-row {
  display: flex;
  gap: 0.4rem;
  flex-wrap: wrap;
  justify-content: flex-end;
}

.diagnostics .chip {
  border-radius: 999px;
  padding: 0.35rem 0.8rem;
  font-size: 0.82rem;
  color: var(--diag-muted);
}

.diagnostics .chip.active {
  background: rgba(79, 209, 197, 0.14);
  border-color: rgba(79, 209, 197, 0.55);
  color: var(--diag-text);
}

.history-sections {
  display: flex;
  flex-direction: column;
  gap: 2rem;
  margin-top: 0.5rem;
}

.history-sections.layout-interesting {
  gap: 0.5rem;
}

.history-device-heading {
  display: flex;
  align-items: center;
  gap: 0.6rem;
  font-size: 0.95rem;
  font-weight: 600;
  color: var(--diag-text);
  margin: 0 0 0.85rem;
  padding-bottom: 0.55rem;
  border-bottom: 1px solid var(--diag-border);
}

.history-charts {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(320px, 1fr));
  gap: 1rem;
  margin-top: 0.5rem;
}

.history-chart {
  background: var(--diag-panel);
  border: 1px solid var(--diag-border);
  border-radius: 16px;
  padding: 0.9rem 1rem 0.6rem;
}

.history-chart.quiet {
  opacity: 0.72;
}

.history-chart header {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  gap: 0.75rem;
  margin-bottom: 0.4rem;
}

.history-chart-title {
  font-size: 0.82rem;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  font-weight: 600;
}

.history-chart-value {
  font-size: 1.15rem;
  font-weight: 650;
  font-variant-numeric: tabular-nums;
}

.history-chart-meta {
  display: flex;
  align-items: center;
  gap: 0.45rem;
  min-width: 0;
}

.history-canvas {
  display: block;
  width: 100%;
  height: 220px;
  touch-action: none;
  cursor: crosshair;
  user-select: none;
  -webkit-user-select: none;
  -webkit-touch-callout: none;
  -webkit-user-drag: none;
}

.history-canvas.chart-zoom-mode {
  cursor: col-resize;
  touch-action: none;
}

.history-empty {
  color: var(--diag-muted);
  font-size: 0.9rem;
  padding: 1.5rem 0;
}

.history-footnote {
  margin-top: 0.85rem;
  color: var(--diag-muted);
  font-size: 0.78rem;
  opacity: 0.8;
}

@media (max-width: 520px) {
  /* clip sideways without creating a sticky-killing scrollport (overflow:hidden would). */
  html {
    background: var(--panel);
    overflow-x: clip;
  }

  body {
    background: var(--panel);
  }

  /* Capacitor: contentInset is never — sticky headers own safe-area (same as PWA).
     Keep html/body/panel solid so the island band matches Halo #f7f8fa / Night #0b1020. */
  html.is-capacitor,
  html.is-capacitor body {
    background: var(--theme-color, var(--panel));
  }

  .desk,
  .phone-shell,
  .halo-surface,
  .night-surface,
  .view-detail,
  .card,
  button.card {
    max-width: 100%;
    min-width: 0;
  }

  .desk {
    padding: 0;
  }

  .phone-shell {
    width: 100%;
    min-height: 100vh;
    min-height: 100dvh;
    border-radius: 0;
    border: none;
    box-shadow: none;
    /* Must stay fully visible — any non-visible overflow axis makes this a
       scrollport and kills position:sticky on the headers. */
    overflow: visible;
    /* Sticky headers own the top safe area so the frosted bar fills under the island. */
    padding:
      8px
      max(18px, env(safe-area-inset-right, 0px))
      max(28px, env(safe-area-inset-bottom, 0px))
      max(18px, env(safe-area-inset-left, 0px));
  }

  /* Header + weather band stick as one unit under the island (safe-area on header). */
  .home-sticky-chrome,
  .night-sticky-chrome {
    position: sticky;
    top: 0;
    z-index: 20;
    box-sizing: border-box;
    margin-left: calc(-1 * max(18px, env(safe-area-inset-left, 0px)));
    margin-right: calc(-1 * max(18px, env(safe-area-inset-right, 0px)));
    background: var(--panel);
    background: color-mix(in oklab, var(--panel) 86%, transparent);
    backdrop-filter: blur(12px);
    -webkit-backdrop-filter: blur(12px);
  }

  .home-header,
  .night-header,
  .detail-header {
    box-sizing: border-box;
    padding:
      max(8px, env(safe-area-inset-top, 0px))
      max(18px, env(safe-area-inset-right, 0px))
      10px
      max(18px, env(safe-area-inset-left, 0px));
  }

  /* Detail views still stick the header alone (no met-strip). */
  .detail-header {
    position: sticky;
    top: 0;
    z-index: 20;
    margin-left: calc(-1 * max(18px, env(safe-area-inset-left, 0px)));
    margin-right: calc(-1 * max(18px, env(safe-area-inset-right, 0px)));
    background: var(--panel);
    background: color-mix(in oklab, var(--panel) 86%, transparent);
    backdrop-filter: blur(12px);
    -webkit-backdrop-filter: blur(12px);
  }

  .home-sticky-chrome .met-strip,
  .night-sticky-chrome .met-strip {
    margin: 0;
    padding:
      8px
      max(22px, calc(env(safe-area-inset-right, 0px) + 4px))
      8px
      max(22px, calc(env(safe-area-inset-left, 0px) + 4px));
  }

  .boat-model {
    display: none;
  }

  .boat-name {
    font-size: 17px;
  }

  .status-pill .status-text {
    max-width: 168px;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
  }

  .energy-sankey,
  .energy-sankey svg,
  .sense-events-wrap,
  .sense-events,
  .events-card,
  .area-chart,
  .card-sparkline,
  .hero-sparkline {
    max-width: 100%;
    min-width: 0;
  }

  #load-chart-card {
    scroll-margin-top: calc(env(safe-area-inset-top, 0px) + 56px);
  }
}

/* —— Tablet / iPad-capped shell (≥768px) —— */
@media (min-width: 768px) {
  .desk {
    padding: 40px 24px 64px;
  }

  .phone-shell {
    width: min(100%, 780px);
    border-radius: 36px;
    padding: 32px 28px 28px;
  }

  .halo-surface,
  .night-surface {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 22px;
    align-items: stretch;
  }

  .halo-surface > .home-sticky-chrome,
  .halo-surface > .hero-carousel,
  .halo-surface > .chip-row-home,
  .night-surface > .night-sticky-chrome,
  .night-surface > .night-hero,
  .night-surface > .flow-list,
  .night-surface > .night-tiles {
    grid-column: 1 / -1;
  }

  .halo-surface > .energy-card,
  .halo-surface > .tanks-card {
    height: 100%;
  }

  .night-tiles {
    gap: 12px;
  }

  .rings-wrap,
  .rings-svg {
    width: 256px;
    height: 256px;
  }

  .area-chart {
    height: 140px;
  }

  .connections-sheet {
    width: min(520px, 100%);
  }

  .view-detail .card .area-chart {
    height: 150px;
  }
}

/* —— Sense-lite: Sankey + load types —— */
.sankey-card .sankey-live {
  color: var(--accent-load-deep, oklch(0.55 0.06 55));
  font-family: Sora, sans-serif;
  font-weight: 600;
}

.energy-sankey {
  width: 100%;
  min-height: 260px;
}

.energy-sankey svg {
  width: 100%;
  height: auto;
  display: block;
}

.energy-sankey .sk-label {
  font-family: Sora, sans-serif;
  font-size: 11px;
  font-weight: 600;
  letter-spacing: -0.02em;
  fill: var(--text);
}

.energy-sankey .sk-watts {
  font-family: Sora, sans-serif;
  font-size: 10px;
  font-weight: 500;
  font-variant-numeric: tabular-nums;
  fill: var(--muted);
}

.energy-sankey .sk-label .sk-watts {
  font-size: 10px;
  font-weight: 500;
  fill: var(--muted);
}

.energy-sankey .sk-label-dead {
  fill: var(--muted);
  font-weight: 500;
}

.energy-sankey .sk-col {
  font-family: "Instrument Sans", system-ui, sans-serif;
  font-size: 9px;
  font-weight: 600;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  fill: var(--muted);
}

.energy-sankey .sk-hub {
  font-family: Sora, sans-serif;
  font-size: 10px;
  font-weight: 600;
  font-variant-numeric: tabular-nums;
  fill: oklch(0.35 0.08 230);
}

html[data-theme="night"] .energy-sankey .sk-hub {
  fill: oklch(0.78 0.08 230);
}

.sankey-balance {
  text-align: center;
  margin-top: 4px;
  overflow-wrap: anywhere;
}

.sense-loads {
  display: flex;
  flex-direction: column;
  gap: 8px;
  margin-bottom: 4px;
}

.sense-loads-head {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 0 4px;
}

.add-event-plus {
  width: 28px;
  height: 28px;
  border-radius: 999px;
  border: 1px solid var(--hairline);
  background: var(--card);
  color: var(--muted);
  font-size: 18px;
  font-weight: 400;
  line-height: 1;
  display: grid;
  place-items: center;
  padding: 0;
}

.add-event-plus:hover {
  color: var(--text-2);
  border-color: oklch(0.82 0.02 230);
}

.text-btn {
  font-size: 12px;
  font-weight: 600;
  color: var(--accent-soc-deep);
  padding: 6px 4px;
}

html[data-theme="night"] .text-btn {
  color: var(--accent-soc);
}

.sense-load-rows {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.sense-load-btn {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 12px 14px;
  border-radius: 18px;
  background: var(--card);
  border: 1px solid var(--hairline);
  text-align: left;
  width: 100%;
  transition: border-color 140ms ease, transform 140ms ease;
}

.sense-load-btn:hover {
  border-color: oklch(0.82 0.02 230);
  transform: translateY(-1px);
}

.sense-swatch {
  width: 10px;
  height: 28px;
  border-radius: 999px;
  flex-shrink: 0;
}

.sense-load-btn .sense-name {
  flex: 1;
  font-family: Sora, sans-serif;
  font-weight: 600;
  font-size: 14px;
  letter-spacing: -0.02em;
}

.sense-load-btn .sense-meta {
  text-align: right;
  max-width: 58%;
  min-width: 0;
}

.sense-load-btn .sense-meta .w {
  font-family: Sora, sans-serif;
  font-variant-numeric: tabular-nums;
  font-weight: 600;
  font-size: 12px;
  line-height: 1.25;
  letter-spacing: -0.01em;
}

.sense-load-btn .sense-meta .sub {
  font-size: 11px;
  color: var(--muted);
  font-weight: 500;
}

.sense-chev {
  color: var(--muted);
  font-size: 16px;
}

.add-event-panel {
  padding: 12px 14px;
  border-radius: 18px;
  background: var(--card);
  border: 1px solid var(--hairline);
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.add-event-panel.hidden {
  display: none;
}

.event-chips {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

.event-chip {
  padding: 8px 12px;
  border-radius: 999px;
  border: 1px solid var(--hairline);
  background: var(--panel);
  font-size: 12px;
  font-weight: 600;
  color: var(--text-2);
}

.event-chip:hover {
  border-color: var(--accent-soc);
}

.event-note {
  font: inherit;
  font-size: 13px;
  padding: 10px 12px;
  border-radius: 12px;
  border: 1px solid var(--hairline);
  background: var(--panel);
  color: var(--text);
}

.sense-events-wrap {
  margin-top: 2px;
  border-radius: 14px;
  padding: 2px 0 4px;
}

.sense-events {
  display: flex;
  flex-direction: column;
  gap: 6px;
  padding: 4px 2px 0;
}

.sense-event {
  display: flex;
  justify-content: space-between;
  gap: 10px;
  font-size: 12px;
  color: var(--text-2);
  padding: 8px 6px;
  border-bottom: 1px solid var(--hairline);
  cursor: pointer;
  border-radius: 10px;
  min-width: 0;
}

.sense-event > span:first-child {
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.sense-event:hover {
  background: oklch(0.97 0.01 230);
}

html[data-theme="night"] .sense-event:hover {
  background: oklch(0.22 0.015 250);
}

.sense-event:last-child {
  border-bottom: none;
}

.sense-event .ev-when {
  color: var(--muted);
  font-variant-numeric: tabular-nums;
  white-space: nowrap;
  flex-shrink: 0;
}

.sense-event .ev-del {
  color: var(--muted);
  font-size: 11px;
  font-weight: 600;
  padding: 2px 4px;
}

.events-card {
  width: 100%;
  text-align: left;
  cursor: pointer;
  font: inherit;
  color: inherit;
}

.events-card .card-head .muted {
  font-size: 12px;
  font-weight: 600;
}

.events-card .sense-events {
  pointer-events: none;
}

.events-card:hover {
  border-color: oklch(0.82 0.02 230);
}

html[data-theme="night"] .events-card:hover {
  border-color: oklch(0.35 0.02 250);
}

.sense-learnings {
  margin-top: 4px;
  padding: 10px 12px;
  border-radius: 16px;
  background: oklch(0.97 0.01 230);
  font-size: 11px;
  color: var(--muted);
  line-height: 1.4;
}

html[data-theme="night"] .sense-learnings {
  background: oklch(0.2 0.015 250);
}

.sense-learnings strong {
  display: block;
  font-family: Sora, sans-serif;
  font-size: 11px;
  font-weight: 600;
  color: var(--text-2);
  margin-bottom: 6px;
}

.sense-learning-row {
  padding: 4px 0;
  border-bottom: 1px solid var(--hairline);
}

.sense-learning-row:last-child {
  border-bottom: none;
}

#event-edit-sheet .card-head {
  align-items: center;
}

.edit-field {
  display: flex;
  flex-direction: column;
  gap: 4px;
  margin-top: 10px;
  font-size: 11px;
  font-weight: 600;
  color: var(--muted);
  letter-spacing: 0.02em;
  text-transform: uppercase;
}

.edit-field input,
.edit-field select {
  font: inherit;
  font-size: 14px;
  font-weight: 500;
  text-transform: none;
  letter-spacing: 0;
  color: var(--text);
  padding: 10px 12px;
  border-radius: 12px;
  border: 1px solid var(--hairline);
  background: var(--panel);
}

.edit-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-top: 14px;
}

.event-chip.danger {
  color: oklch(0.45 0.12 25);
  border-color: oklch(0.85 0.04 25);
  background: oklch(0.97 0.02 25);
}

html[data-theme="night"] .event-chip.danger {
  color: oklch(0.78 0.1 25);
  border-color: oklch(0.35 0.06 25);
  background: oklch(0.22 0.03 25);
}

/* Load detail dig-in sheet (connections overlay + taller sheet) */
.load-detail-sheet {
  max-height: min(
    92vh,
    820px,
    100%,
    calc(
      100dvh - max(16px, env(safe-area-inset-top, 0px)) -
        max(16px, env(safe-area-inset-bottom, 0px))
    )
  );
  gap: 16px;
  /* Keep header controls (esp. ×) from being clipped by sheet scrollport */
  overflow-x: hidden;
}

.load-detail-header {
  align-items: flex-start;
  gap: 10px;
  overflow: visible;
}

.load-detail-header-main {
  min-width: 0;
  flex: 1;
}

.load-detail-title-row {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 12px;
  min-width: 0;
}

.load-detail-title-row h2 {
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.load-detail-header .sub {
  margin: 4px 0 0;
  font-size: 13px;
  color: var(--muted);
  line-height: 1.35;
  overflow-wrap: anywhere;
}

.load-detail-watts {
  font-family: Sora, sans-serif;
  font-size: 20px;
  font-weight: 600;
  letter-spacing: -0.02em;
  line-height: 1.15;
  color: var(--text);
  white-space: nowrap;
  flex-shrink: 0;
  font-variant-numeric: tabular-nums;
}

.load-detail-close {
  position: relative;
  z-index: 2;
  flex-shrink: 0;
  margin-top: -4px;
  margin-right: -6px;
  background: var(--card);
  border: 1px solid var(--shell-border);
  font-size: 18px;
  line-height: 1;
  color: var(--muted);
  touch-action: manipulation;
  -webkit-tap-highlight-color: transparent;
}

.load-detail-chart-card {
  margin: 0;
  padding: 14px 14px 12px;
}

.load-detail-chart-card .card-head {
  gap: 12px;
  min-width: 0;
}

.load-detail-chart-live {
  white-space: nowrap;
  flex-shrink: 0;
  font-variant-numeric: tabular-nums;
}

.load-detail-events-block {
  display: flex;
  flex-direction: column;
  gap: 8px;
  min-height: 0;
}

.load-detail-events-block .card-head {
  margin: 0;
  padding: 0 2px;
}

.load-detail-events-block .sense-events {
  max-height: min(36vh, 280px);
  overflow: auto;
  -webkit-overflow-scrolling: touch;
}

/* Energy history (combined sources + load) */
.energy-history-btn {
  flex-shrink: 0;
  font-size: 13px;
  font-weight: 600;
  padding: 6px 10px;
}

.energy-chart-tap {
  cursor: pointer;
  text-align: left;
  width: 100%;
  border: none;
  font: inherit;
  color: inherit;
  background: var(--card);
  transition: box-shadow 0.15s ease;
}

.energy-chart-tap:active {
  box-shadow: inset 0 0 0 1px oklch(0.7 0.02 240 / 0.25);
}

.energy-history-sheet {
  /* Nearly full-height; must still clear Dynamic Island via overlay safe-area. */
  max-height: min(
    96vh,
    920px,
    100%,
    calc(
      100dvh - max(16px, env(safe-area-inset-top, 0px)) -
        max(16px, env(safe-area-inset-bottom, 0px))
    )
  );
}

.energy-history-header {
  flex-wrap: wrap;
}

.energy-history-title-row {
  flex-wrap: wrap;
  gap: 8px;
}

.energy-history-title-row h2 {
  flex: 1 1 auto;
}

.energy-history-title-row .seg-tabs {
  flex-shrink: 0;
}

.energy-chip-row {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

.energy-chip {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 6px 12px;
  border-radius: 999px;
  border: 1px solid var(--shell-border);
  background: var(--card);
  font: inherit;
  font-size: 12px;
  font-weight: 600;
  cursor: pointer;
  touch-action: manipulation;
  -webkit-tap-highlight-color: transparent;
}

.energy-chip::before {
  content: "";
  width: 8px;
  height: 8px;
  border-radius: 50%;
  flex-shrink: 0;
}

.energy-chip.solar::before { background: oklch(0.65 0.14 150); }
.energy-chip.alternator::before { background: oklch(0.68 0.16 55); }
.energy-chip.usage::before { background: oklch(0.42 0.04 250); }
.energy-chip.net::before { background: oklch(0.62 0.02 240); }

.energy-chip.solar { background: oklch(0.65 0.14 150 / 0.08); border-color: oklch(0.65 0.14 150 / 0.25); color: oklch(0.45 0.12 150); }
.energy-chip.alternator { background: oklch(0.68 0.16 55 / 0.1); border-color: oklch(0.68 0.16 55 / 0.28); color: oklch(0.48 0.14 55); }
.energy-chip.usage { background: oklch(0.42 0.04 250 / 0.08); border-color: oklch(0.42 0.04 250 / 0.2); color: oklch(0.38 0.04 250); }
.energy-chip.net { background: var(--card); color: var(--muted); }

.energy-chip[aria-pressed="false"] {
  opacity: 0.45;
}

.energy-chip[hidden] {
  display: none;
}

.energy-history-chart-card {
  position: relative;
  padding-top: 8px;
}

.energy-dual-chart {
  display: block;
  width: 100%;
  height: 220px;
  touch-action: none;
  cursor: crosshair;
}

.energy-summary-row {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 10px;
}

.energy-summary-card {
  background: var(--card);
  border: 1px solid var(--shell-border);
  border-radius: 18px;
  padding: 12px 10px;
  display: flex;
  flex-direction: column;
  gap: 4px;
  min-width: 0;
}

.energy-summary-label {
  font-size: 11px;
  color: var(--muted);
  font-weight: 600;
}

.energy-summary-value {
  font-family: Sora, sans-serif;
  font-size: 18px;
  font-weight: 700;
  letter-spacing: -0.02em;
  font-variant-numeric: tabular-nums;
  line-height: 1.15;
}

.energy-summary-value.generated { color: oklch(0.55 0.14 150); }
.energy-summary-value.used { color: oklch(0.38 0.04 250); }
.energy-summary-value.net { color: oklch(0.52 0.12 55); }

.energy-reading-card {
  background: oklch(0.94 0.03 230);
  border: 1px solid oklch(0.88 0.04 230);
}

html[data-theme="night"] .energy-reading-card {
  background: oklch(0.18 0.03 250);
  border-color: oklch(0.28 0.04 250);
}

.energy-source-links {
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.energy-source-links .sense-load-btn:last-child {
  margin-bottom: 4px;
}

.energy-source-chart {
  height: 220px;
}

#energy-source-ranges {
  font-size: 10px;
}

#energy-source-ranges .seg {
  padding: 3px 8px;
}
