/* Calm redesign: owned by the Plan screen agent (#screen-device). Loaded after styles-calm.css.
   Plan reads top to bottom: the goal as one big line ("80% by 7 AM"), tonight's night bar with the charging hours and
   the ready-by marker, then When to charge as a three-way choice, the goal rows (native selects fill each row), the
   Autopilot switch, the vehicle row and the electricity prices. Also the Charge controls sheet (#screen-garage). */

/* ---------- Layout: one column, 28px between groups ---------- */
#screen-device.active {
  display: flex;
  flex-direction: column;
  gap: 28px;
}

#screen-device.active > * {
  flex-shrink: 0;
  margin: 0;
}

#screen-device.active > .screen-heading {
  order: 0;
  margin-bottom: -4px;
}

#screen-device > #powerwallPlan { order: 1; }
#screen-device > #chargingPlanTonight { order: 2; }
#screen-device > #chargingPlanCard { order: 3; }
#screen-device > #planAutopilotCard { order: 4; }
#screen-device > #scheduleTargetCard { order: 5; }
#screen-device > #planRateContextCard { order: 6; }

/* "Why this plan": a quiet info button that keeps its 44px hit area. */
#screen-device #scheduleAiButton {
  width: 44px;
  height: 44px;
  background: transparent;
  color: var(--calm-faint);
}

/* The first-visit "Ask Rev" bubble would sit over the info button; on Plan the header button is enough. */
body:has(#screen-device.active) .rev-button.intro .rev-button-label {
  opacity: 0;
}

/* The vehicle's whole name: a long one wraps onto a second line instead of being cut. */
#screen-device #planVehicleKicker {
  max-width: 100%;
  overflow-wrap: anywhere;
}

#screen-device #scheduleAiButton svg {
  width: 22px;
  height: 22px;
  fill: none;
  stroke: currentColor;
  stroke-width: 1.7;
  stroke-linecap: round;
}

/* ---------- Hero: the goal, the night bar, tonight in a line ---------- */
#screen-device .plan-tonight-card {
  display: flex;
  flex-direction: column;
  gap: 22px;
  border: 0 !important;
  border-radius: 0;
  padding: 0;
  background: transparent !important;
}

#screen-device .plan-hero {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

#screen-device #chargingPlanTitle {
  margin: 0;
  color: var(--calm-text);
  font-size: 52px;
  font-weight: 300;
  line-height: 1.05;
  letter-spacing: -0.03em;
  font-variant-numeric: tabular-nums;
}

#screen-device #chargingPlanTitle.is-text {
  font-size: 32px;
  letter-spacing: -0.02em;
  line-height: 1.15;
}

#screen-device .plan-hero .charging-plan-note {
  margin: 0;
  color: var(--calm-muted);
  font-size: 14px;
  font-weight: 400;
  line-height: 1.45;
}

#screen-device .plan-night {
  display: flex;
  flex-direction: column;
  gap: 10px;
}

#screen-device .plan-night:not(:has(> :not(.hidden))) {
  display: none;
}

/* Static night bar: the hours on a 44px track, charging window in accent, ready-by tick in amber. */
#screen-device .plan-night-bar {
  display: flex;
  flex-direction: column;
  gap: 10px;
}

#screen-device .plan-night-track {
  position: relative;
  height: 44px;
  overflow: hidden;
  border-radius: 12px;
  background: var(--calm-surface);
}

#screen-device .plan-night-band {
  position: absolute;
  top: 0;
  bottom: 0;
  background: var(--calm-accent-deep);
}

#screen-device .plan-night-band::after {
  content: "";
  position: absolute;
  left: 0;
  right: 0;
  top: 18px;
  height: 8px;
  border-radius: 4px;
  background: var(--calm-accent);
}

/* Cheapest hours aren't picked yet: no band, only a dashed line, so it doesn't read as a real charging window. */
#screen-device .plan-night-band.soft {
  background: transparent;
}

#screen-device .plan-night-band.soft::after {
  top: 21px;
  height: 2px;
  border-radius: 1px;
  background: repeating-linear-gradient(90deg, rgba(125, 184, 255, 0.45) 0 6px, transparent 6px 12px);
}

#screen-device .plan-night-ready {
  position: absolute;
  top: 8px;
  bottom: 8px;
  width: 2px;
  margin-left: -1px;
  border-radius: 1px;
  background: var(--calm-amber);
}

#screen-device .plan-night-axis,
#screen-device .plan-tonight-timeline .autopilot-timeline-labels {
  display: flex;
  justify-content: space-between;
  color: var(--calm-muted);
  font-size: 11px;
  font-weight: 400;
}

#screen-device .plan-night-axis em,
#screen-device .plan-tonight-timeline .autopilot-timeline-labels em {
  font-style: normal;
}

/* Autopilot's live timeline (one i per hour from now to ready-by, i.on for a planned hour) on the same track. */
#screen-device .plan-tonight-timeline.autopilot-timeline {
  position: relative;
  display: flex;
  gap: 0;
  margin: 0;
  padding: 0 0 26px;
}

#screen-device .plan-tonight-timeline::before {
  content: "";
  position: absolute;
  inset: 0 0 26px;
  border-radius: 12px;
  background: var(--calm-surface);
}

#screen-device .plan-tonight-timeline i {
  position: relative;
  flex: 1;
  height: 44px;
  border-radius: 0;
  background: transparent;
  box-shadow: none;
}

#screen-device .plan-tonight-timeline i.on {
  background: var(--calm-accent-deep);
  box-shadow: none;
}

#screen-device .plan-tonight-timeline i.on::after {
  content: "";
  position: absolute;
  left: 0;
  right: 0;
  top: 18px;
  height: 8px;
  background: var(--calm-accent);
}

#screen-device .plan-tonight-timeline i.on:not(.on + i.on)::after {
  border-top-left-radius: 4px;
  border-bottom-left-radius: 4px;
}

#screen-device .plan-tonight-timeline i.on:not(:has(+ i.on))::after {
  border-top-right-radius: 4px;
  border-bottom-right-radius: 4px;
}

#screen-device .plan-tonight-timeline i:first-of-type {
  border-radius: 12px 0 0 12px;
}

/* Ready-by: the timeline ends at the ready-by hour. */
#screen-device .plan-tonight-timeline::after {
  content: "";
  position: absolute;
  right: 6px;
  top: 8px;
  height: 28px;
  width: 2px;
  border-radius: 1px;
  background: var(--calm-amber);
}

#screen-device .plan-tonight-timeline .autopilot-timeline-labels {
  position: absolute;
  left: 0;
  right: 0;
  bottom: 0;
}

#screen-device .plan-night-legend {
  display: flex;
  flex-wrap: wrap;
  gap: 6px 18px;
  margin: 0;
  color: var(--calm-muted);
  font-size: 12px;
  line-height: 1.4;
}

#screen-device .plan-night-legend span {
  display: inline-flex;
  align-items: center;
  gap: 6px;
}

#screen-device .plan-night-legend .charge.soft i {
  height: 2px;
  border-radius: 1px;
  background: repeating-linear-gradient(90deg, rgba(125, 184, 255, 0.6) 0 3px, transparent 3px 5px);
}

#screen-device .plan-night-legend .charge i {
  width: 10px;
  height: 4px;
  border-radius: 2px;
  background: var(--calm-accent);
}

#screen-device .plan-night-legend .ready i {
  width: 2px;
  height: 10px;
  background: var(--calm-amber);
}

/* Tonight as a short status: a small label, one line, and the details in muted type. */
#screen-device .plan-tonight-status {
  display: flex;
  flex-direction: column;
  gap: 4px;
}

/* Following the Tesla app, the title already names the schedule; the note below says the rest. */
#screen-device #chargingPlanTonight:has(#chargingPlanTitle.is-text) #chargingPlanTonightLabel,
#screen-device #chargingPlanTonight:has(#chargingPlanTitle.is-text) #chargingPlanTonightText {
  display: none;
}

#screen-device #chargingPlanTonight:has(#chargingPlanTitle.is-text) {
  gap: 10px;
}

#screen-device .plan-tonight-status .eyebrow {
  margin: 0 0 2px;
}

#screen-device #chargingPlanTonightText {
  margin: 0;
  color: var(--calm-text);
  font-size: 17px;
  font-weight: 500;
  line-height: 1.35;
  letter-spacing: -0.01em;
}

#screen-device .plan-tonight-meta,
#screen-device .plan-tonight-card small {
  margin: 0;
  color: var(--calm-muted);
  font-size: 13px;
  font-weight: 400;
  line-height: 1.45;
}

#screen-device .plan-tonight-card .primary-action {
  align-self: flex-start;
  min-height: 44px;
  margin: -8px 0 0;
  padding: 0 18px;
  font-weight: 500;
}

/* The Autopilot switch below turns it on (or offers Pro), so the same button here would say it twice. The button
   stays for handing timing over from the Tesla app's own schedule. */
#screen-device #chargingPlanAutopilotButton.calm-dup {
  display: none;
}

/* Tesla app mode: Autopilot isn't used, so its card reads as set aside (it still works). */
#screen-device #planAutopilotCard.is-muted {
  opacity: 0.6;
}

/* ---------- Charging plan: When to charge, then the goal rows ---------- */
#screen-device .charging-plan-card {
  display: flex;
  flex-direction: column;
  gap: 0;
  margin: 0;
  border: 0 !important;
  border-radius: 0;
  padding: 0;
  background: transparent !important;
  box-shadow: none !important;
}

/* The segmented control keeps the real radios: each option label and its inner span flatten into the grid, so the
   option name sits in the track and the chosen option's description shows underneath. */
#screen-device .charging-plan-when {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  column-gap: 2px;
  margin: 0;
  border: 0;
  padding: 0;
  min-width: 0;
}

#screen-device .charging-plan-when::before {
  content: "";
  grid-row: 2;
  grid-column: 1 / -1;
  border-radius: 16px;
  background: var(--calm-surface);
}

#screen-device .charging-plan-when legend {
  float: left;
  grid-row: 1;
  grid-column: 1 / -1;
  width: 100%;
  margin: 0 0 10px;
  padding: 0;
  color: var(--calm-muted);
  font-size: 12px;
  font-weight: 500;
  letter-spacing: 0.08em;
  text-transform: uppercase;
}

/* Each option label is one segment; the radio stays in it, visually hidden. */
#screen-device .charging-plan-option {
  grid-row: 2;
  display: flex;
  align-items: stretch;
  min-width: 0;
  margin: 4px 0;
  border: 0;
  border-radius: 12px;
  padding: 0;
  background: transparent;
  cursor: pointer;
  transition: background-color 160ms ease;
}

#screen-device #chargingPlanCheapestOption { grid-column: 1; margin-left: 4px; }
#screen-device #chargingPlanWindowOption { grid-column: 2; }
#screen-device #chargingPlanTeslaOption { grid-column: 3; margin-right: 4px; }

#screen-device .charging-plan-option > span {
  display: flex;
  flex: 1;
  min-width: 0;
}

#screen-device .charging-plan-option input {
  position: absolute;
  width: 1px;
  height: 1px;
  margin: 0;
  opacity: 0;
  pointer-events: none;
}

#screen-device .charging-plan-option strong {
  display: flex;
  flex: 1;
  align-items: center;
  justify-content: center;
  min-width: 0;
  min-height: 44px;
  padding: 0 6px;
  color: var(--calm-muted);
  font-size: 13px;
  font-weight: 400;
  text-align: center;
  white-space: nowrap;
}

#screen-device .charging-plan-option.selected {
  background: var(--calm-raised);
}

#screen-device .charging-plan-option.selected strong {
  color: var(--calm-text);
  font-weight: 500;
}

#screen-device .charging-plan-option.needs-setup:not(.selected) strong {
  color: var(--calm-faint);
}

#screen-device .charging-plan-option:has(input:focus-visible) {
  outline: 2px solid var(--calm-accent);
  outline-offset: -2px;
}

/* The options' own descriptions are mirrored into one line under the control (#planWhenCopy). */
#screen-device .charging-plan-option small {
  display: none;
}

#screen-device .charging-plan-when-copy {
  grid-row: 3;
  grid-column: 1 / -1;
  margin: 12px 0 0;
  padding: 0 4px;
  color: var(--calm-muted);
  font-size: 13px;
  line-height: 1.45;
}

#screen-device .charging-plan-when-copy:empty {
  display: none;
}

/* ---------- Rows: label left, value and chevron right; the native select fills the row ---------- */
#screen-device .charging-plan-goal {
  display: flex;
  flex-direction: column;
  gap: 0;
}

#screen-device .charging-plan-window {
  grid-row: 4;
  grid-column: 1 / -1;
  margin-top: 14px;
  padding: 0;
}

#screen-device .charging-plan-goal label,
#screen-device .charging-plan-window {
  position: relative;
  display: flex;
  align-items: center;
  gap: 0;
  min-height: 56px;
  border-bottom: 1px solid var(--calm-line);
}

#screen-device .charging-plan-goal label:first-child,
#screen-device .charging-plan-window {
  border-top: 1px solid var(--calm-line);
}

#screen-device .charging-plan-card:has(.charging-plan-window:not(.hidden)) .charging-plan-goal label:first-child {
  border-top: 0;
}

#screen-device .charging-plan-goal {
  margin-top: 14px;
}

#screen-device .charging-plan-card:has(.charging-plan-window:not(.hidden)) .charging-plan-goal {
  margin-top: 0;
}

#screen-device .charging-plan-goal label::after,
#screen-device .charging-plan-window::after {
  content: "\203A";
  position: absolute;
  right: 4px;
  top: 50%;
  transform: translateY(-52%);
  color: var(--calm-faint);
  font-size: 18px;
  line-height: 1;
  pointer-events: none;
}

#screen-device .charging-plan-goal span,
#screen-device .charging-plan-window .plan-row-label {
  padding-left: 4px;
  color: var(--calm-text);
  font-size: 15px;
  font-weight: 400;
  letter-spacing: 0;
  text-transform: none;
  pointer-events: none;
}

#screen-device .charging-plan-goal select,
#screen-device .charging-plan-window select {
  -webkit-appearance: none;
  appearance: none;
  min-height: 48px;
  margin: 0;
  border: 0;
  border-radius: 0;
  padding: 0;
  color: var(--calm-muted);
  background: transparent;
  box-shadow: none;
  font: inherit;
  font-size: 14px;
  font-variant-numeric: tabular-nums;
  cursor: pointer;
}

#screen-device .charging-plan-goal select:focus-visible,
#screen-device .charging-plan-window select:focus-visible {
  outline: none;
  color: var(--calm-text);
}

/* Battery goal and Ready by: the select spans the whole row, its value right-aligned before the chevron. */
#screen-device .charging-plan-goal select {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  padding-right: 22px;
  text-align: right;
  text-align-last: right;
}

/* Hours: two selects ("10 PM" to "6 AM") pushed to the right. */
#screen-device .charging-plan-window .plan-row-label {
  flex: 1;
}

#screen-device .charging-plan-window select {
  width: auto;
  min-width: 0;
  padding: 0 4px;
  text-align: center;
  text-align-last: center;
}

#screen-device .charging-plan-window select:last-of-type {
  margin-right: 18px;
}

#screen-device .charging-plan-window > span:not(.plan-row-label) {
  color: var(--calm-muted);
  font-size: 14px;
  font-weight: 400;
}

/* ---------- Price rules: rows with a switch ---------- */
#screen-device .charging-plan-extras {
  display: flex;
  flex-direction: column;
  gap: 0;
}

/* Tesla app mode hides the goal rows, so the price rules start with their own hairline. */
#screen-device .charging-plan-goal.hidden + .charging-plan-extras {
  margin-top: 8px;
  border-top: 1px solid var(--calm-line);
}

#screen-device .charging-plan-toggle {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 16px;
  align-items: center;
  min-height: 56px;
  border-top: 0;
  border-bottom: 1px solid var(--calm-line);
  padding: 14px 4px;
}

#screen-device .charging-plan-toggle strong {
  color: var(--calm-text);
  font-size: 15px;
  font-weight: 400;
}

#screen-device .charging-plan-toggle small {
  color: var(--calm-muted);
  font-size: 13px;
  line-height: 1.45;
}

#screen-device .charging-plan-toggle .charging-plan-cap-hint {
  color: var(--calm-faint);
  opacity: 1;
}

#screen-device .charging-plan-toggle select {
  min-height: 28px;
  margin: 0 2px;
  border: 0;
  border-radius: 8px;
  padding: 0 8px;
  color: var(--calm-amber);
  background: var(--calm-raised);
  font: inherit;
  font-size: 13px;
  font-weight: 500;
}

/* Switch look for the plan's checkboxes (and the Autopilot switch). */
#screen-device .charging-plan-toggle input[type="checkbox"],
#screen-device .plan-switch input {
  -webkit-appearance: none;
  appearance: none;
  position: relative;
  flex: none;
  width: 52px;
  height: 32px;
  min-height: 0;
  margin: 0;
  border: 0;
  border-radius: 16px;
  background: var(--calm-raised);
  cursor: pointer;
  transition: background-color 180ms ease;
}

#screen-device .charging-plan-toggle input[type="checkbox"]::after,
#screen-device .plan-switch input::after {
  content: "";
  position: absolute;
  top: 4px;
  left: 4px;
  width: 24px;
  height: 24px;
  border-radius: 12px;
  background: var(--calm-muted);
  transition: transform 180ms ease, background-color 180ms ease;
}

#screen-device .charging-plan-toggle input[type="checkbox"]:checked,
#screen-device .plan-switch input:checked {
  background: var(--calm-accent);
}

#screen-device .charging-plan-toggle input[type="checkbox"]:checked::after,
#screen-device .plan-switch input:checked::after {
  background: var(--calm-bg);
  transform: translateX(20px);
}

#screen-device .charging-plan-toggle input[type="checkbox"]:focus-visible,
#screen-device .plan-switch input:focus-visible {
  outline: 2px solid var(--calm-accent);
  outline-offset: 2px;
}

/* ---------- Autopilot card ---------- */
#screen-device .plan-autopilot-card {
  display: flex;
  align-items: center;
  gap: 14px;
  border-radius: var(--calm-radius);
  padding: 16px 18px;
  background: var(--calm-surface);
}

#screen-device .plan-autopilot-card > div {
  display: flex;
  flex: 1;
  flex-direction: column;
  gap: 4px;
  min-width: 0;
}

#screen-device .plan-autopilot-card strong {
  color: var(--calm-text);
  font-size: 15px;
  font-weight: 500;
}

#screen-device .plan-autopilot-card p {
  margin: 0;
  color: var(--calm-muted);
  font-size: 13px;
  line-height: 1.4;
}

/* Free plan: a small Pro tag after the title (tapping the switch offers Pro). */
#screen-device .plan-autopilot-card.is-locked strong::after {
  content: "Pro";
  display: inline-block;
  margin-left: 8px;
  border-radius: 999px;
  padding: 2px 8px;
  color: var(--calm-amber);
  background: var(--calm-amber-soft);
  font-size: 11px;
  font-weight: 500;
  letter-spacing: 0.04em;
  vertical-align: 2px;
}

/* A 52x32 switch inside a 48px-tall tap area. */
#screen-device .plan-switch {
  display: flex;
  align-items: center;
  justify-content: center;
  flex: none;
  min-width: 52px;
  min-height: 48px;
  cursor: pointer;
}

#screen-device .plan-switch > span {
  display: none;
}

/* ---------- Vehicle row ---------- */
#screen-device > .plan-vehicle-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  min-height: 56px;
  margin-top: -8px;
  border: 0 !important;
  border-top: 1px solid var(--calm-line) !important;
  border-bottom: 1px solid var(--calm-line) !important;
  border-radius: 0;
  padding: 4px 0 4px 4px !important;
  background: transparent !important;
}

#screen-device > .plan-vehicle-row > div:first-child {
  display: flex;
  align-items: baseline;
  gap: 12px;
  min-width: 0;
}

#screen-device > .plan-vehicle-row .eyebrow {
  flex: none;
  margin: 0;
  color: var(--calm-text);
  font-size: 15px;
  font-weight: 400;
  letter-spacing: 0;
  text-transform: none;
}

#screen-device > .plan-vehicle-row h2 {
  overflow: hidden;
  margin: 0;
  color: var(--calm-muted);
  font-size: 14px;
  font-weight: 400;
  text-overflow: ellipsis;
  white-space: nowrap;
}

#screen-device .plan-vehicle-row .schedule-target-actions {
  display: flex;
  align-items: center;
  gap: 8px;
  flex: none;
}

#screen-device #scheduleTargetButton {
  min-height: 44px;
  border-radius: 12px;
  padding: 0 4px 0 12px;
  color: var(--calm-accent);
  background: transparent;
  font-size: 14px;
  font-weight: 500;
}

#screen-device #scheduleTargetReadiness {
  border: 0;
  border-radius: 999px;
  padding: 4px 10px;
  color: var(--calm-amber);
  background: var(--calm-amber-soft);
  font-size: 12px;
  font-weight: 500;
}

/* ---------- Electricity prices ---------- */
#screen-device > .plan-rate-context-card {
  display: flex;
  flex-direction: column;
  gap: 14px;
  border-radius: var(--calm-radius);
  padding: 20px;
  background: var(--calm-surface) !important;
}

#screen-device .plan-rate-context-head {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 12px;
}

#screen-device .plan-rate-context-head h2 {
  margin: 0;
  color: var(--calm-text);
  font-size: 17px;
  font-weight: 500;
  letter-spacing: -0.01em;
}

#screen-device .plan-rate-context-head p:not(.eyebrow) {
  margin: 6px 0 0;
  color: var(--calm-muted);
  font-size: 13px;
  font-weight: 400;
  line-height: 1.45;
}

#screen-device #planRateContextChip {
  flex: none;
  border: 0;
  border-radius: 999px;
  padding: 4px 10px;
  color: var(--calm-muted);
  background: var(--calm-raised);
  font-size: 12px;
  font-weight: 500;
}

#screen-device #planRateContextButton {
  align-self: flex-start;
  min-height: 44px;
  border-radius: 12px;
  padding: 0 16px;
  color: var(--calm-bg);
  background: var(--calm-accent);
  font-weight: 500;
}

#screen-device .plan-rate-visual {
  margin: 0;
  border: 0;
  border-radius: 0;
  padding: 0;
  background: transparent;
}

#screen-device .plan-rate-signals {
  display: flex;
  flex-direction: column;
  gap: 0;
  border: 0;
  border-radius: 0;
  padding: 0;
  background: transparent;
}

#screen-device .plan-signal-row {
  display: grid;
  grid-template-columns: 8px minmax(0, 1fr) auto;
  gap: 12px;
  align-items: center;
  min-height: 56px;
  border: 0;
  border-top: 1px solid var(--calm-line);
  border-radius: 0;
  padding: 10px 0;
  background: transparent;
}

#screen-device .plan-signal-dot {
  width: 8px;
  height: 8px;
  border-radius: 4px;
  box-shadow: none;
}

#screen-device .plan-signal-main,
#screen-device .plan-signal-value {
  display: flex;
  flex-direction: column;
  gap: 2px;
  min-width: 0;
}

#screen-device .plan-signal-value {
  align-items: flex-end;
  text-align: right;
}

#screen-device .plan-signal-main strong,
#screen-device .plan-signal-value strong {
  color: var(--calm-text);
  font-size: 15px;
  font-weight: 400;
}

#screen-device .plan-signal-value strong {
  font-size: 17px;
  font-weight: 300;
  letter-spacing: -0.02em;
  font-variant-numeric: tabular-nums;
}

#screen-device .plan-signal-main span,
#screen-device .plan-signal-value span {
  color: var(--calm-muted);
  font-size: 12px;
  font-weight: 400;
}

#screen-device .plan-rate-insight {
  margin: 0;
  color: var(--calm-faint);
  font-size: 13px;
  font-weight: 400;
  line-height: 1.45;
}

#screen-device .plan-secondary-tag {
  display: flex;
  flex-direction: column;
  gap: 4px;
  border: 0;
  border-top: 1px solid var(--calm-line);
  border-radius: 0;
  padding: 14px 0 0;
  background: transparent;
}

#screen-device .plan-secondary-tag span {
  color: var(--calm-amber);
  font-size: 12px;
  font-weight: 500;
  letter-spacing: 0.08em;
  text-transform: uppercase;
}

#screen-device .plan-secondary-tag strong {
  color: var(--calm-muted);
  font-size: 13px;
  font-weight: 400;
  line-height: 1.45;
}

/* ---------- Home-only (no car): the Powerwall plan stands alone ---------- */
body[data-home-only="true"] #planAutopilotCard {
  display: none !important;
}

#screen-device .powerwall-plan {
  border: 0;
  border-radius: var(--calm-radius);
  box-shadow: none;
}

/* =====================================================================================================================
   Charge controls sheet (#screen-garage.charge-sheet, opened from Today). Same DOM order; quieter type, a 300-weight
   battery numeral, a thin accent meter with an amber limit tick, and muted secondary lines.
   ===================================================================================================================== */
#screen-garage .charge-sheet-head h2 {
  color: var(--calm-text);
  font-size: 20px;
  font-weight: 500;
  letter-spacing: -0.01em;
}

#screen-garage #garageStatusChip {
  border: 0;
  border-radius: 999px;
  padding: 4px 10px;
  color: var(--calm-muted);
  background: var(--calm-raised);
  font-size: 12px;
  font-weight: 500;
}

#screen-garage #garageStatusChip.warn,
#screen-garage #garageStatusChip.bad {
  color: var(--calm-amber);
  background: var(--calm-amber-soft);
}

/* Car card: a plain row on the sheet, no inner card. */
#screen-garage .garage-target-card {
  border: 0 !important;
  border-radius: 16px;
  box-shadow: none !important;
  background: transparent !important;
}

#screen-garage .garage-source-grid.has-many-targets .garage-target-card {
  background: var(--calm-bg) !important;
}

#screen-garage .garage-source-grid.has-many-targets .garage-target-card.active {
  background: var(--calm-raised) !important;
}

#screen-garage .garage-source-icon {
  border: 0;
  border-radius: 12px;
  color: var(--calm-accent);
  background: var(--calm-raised);
  box-shadow: none;
}

#screen-garage .garage-hero-copy span {
  color: var(--calm-faint);
  font-size: 12px;
  font-weight: 400;
  letter-spacing: 0;
  text-transform: none;
}

#screen-garage .garage-hero-copy strong {
  color: var(--calm-text);
  font-size: 17px;
  font-weight: 500;
  letter-spacing: -0.01em;
}

#screen-garage .garage-hero-copy small {
  color: var(--calm-muted);
  font-size: 13px;
  font-weight: 400;
}

#screen-garage .garage-target-card em {
  color: var(--calm-muted);
  font-size: 12px;
  font-style: normal;
  font-weight: 500;
}

#screen-garage .garage-target-card[data-source-state="charging"] em {
  color: var(--calm-accent);
}

#screen-garage .charge-control-card {
  border: 0 !important;
  box-shadow: none !important;
  background: transparent !important;
}

#screen-garage .garage-refresh {
  color: var(--calm-muted);
  background: transparent;
}

/* Battery: big light numeral, range in muted type. */
#screen-garage .vehicle-data-card {
  border: 0 !important;
  box-shadow: none !important;
  background: transparent !important;
}

#screen-garage #garageVehicleDataTitle {
  color: var(--calm-text);
  font-size: 48px;
  font-weight: 300;
  line-height: 1.05;
  letter-spacing: -0.03em;
  font-variant-numeric: tabular-nums;
}

#screen-garage .charge-battery-range,
#screen-garage .range-labels,
#screen-garage .range-labels strong {
  color: var(--calm-muted);
  font-size: 13px;
  font-weight: 400;
}

#screen-garage .range-meter {
  height: 8px;
  border: 0;
  border-radius: 4px;
  background: var(--calm-track);
  box-shadow: none;
}

#screen-garage .range-meter > span {
  border-radius: 4px;
  background: var(--calm-accent);
  box-shadow: none;
}

#screen-garage .range-meter-limit {
  width: 2px;
  border-radius: 1px;
  background: var(--calm-amber);
  box-shadow: none;
}

/* Charge limit: a quiet label, the value as an amber chip that opens the limit sheet. */
#screen-garage .charge-level-heading strong {
  color: var(--calm-text);
  font-size: 15px;
  font-weight: 400;
}

#screen-garage .charge-limit-value-button {
  position: relative;
  min-height: 32px;
  border: 0;
  border-radius: 10px;
  padding: 0 12px;
  color: var(--calm-amber);
  background: var(--calm-amber-soft);
  box-shadow: none;
  font-size: 15px;
  font-weight: 500;
  font-variant-numeric: tabular-nums;
}

/* Keep the 32px chip look with a 44px hit area. */
#screen-garage .charge-limit-value-button::before {
  content: "";
  position: absolute;
  inset: -6px -4px;
}

#screen-garage .charge-level-slider-fill {
  background: var(--calm-accent);
  box-shadow: none;
}

#screen-garage .charge-level-slider-thumb {
  border: 0;
  background: var(--calm-text);
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.4);
}

#screen-garage .charge-summary,
#screen-garage .charge-limit-auto-status {
  color: var(--calm-muted);
  font-size: 13px;
  font-weight: 400;
  line-height: 1.45;
}

#screen-garage .charge-port-link {
  min-height: 44px;
  color: var(--calm-accent);
  font-size: 14px;
  font-weight: 500;
}

#screen-garage .garage-command-button {
  min-height: 52px;
  border-radius: var(--calm-radius-control);
  font-size: 16px;
  font-weight: 500;
}

/* Nothing to charge yet. */
#screen-garage .charge-empty-card {
  border: 0 !important;
  box-shadow: none !important;
}

#screen-garage .charge-empty-card h2 {
  color: var(--calm-text);
  font-size: 20px;
  font-weight: 500;
}

#screen-garage .charge-empty-card p:not(.eyebrow) {
  color: var(--calm-muted);
  font-size: 14px;
  font-weight: 400;
}

#screen-garage .charge-empty-symbol {
  border: 0;
  color: var(--calm-accent);
  background: var(--calm-raised);
  box-shadow: none;
}

#screen-garage .charge-empty-checklist {
  gap: 0;
}

#screen-garage .charge-empty-checklist div {
  min-height: 48px;
  border: 0;
  border-bottom: 1px solid var(--calm-line);
  border-radius: 0;
  padding: 0 4px;
  background: transparent;
}

#screen-garage .charge-empty-checklist div:last-child {
  border-bottom: 0;
}

#screen-garage .charge-empty-checklist span {
  color: var(--calm-text);
  font-size: 14px;
  font-weight: 400;
}

#screen-garage .charge-empty-checklist strong {
  color: var(--calm-muted);
  font-size: 13px;
  font-weight: 500;
}

#screen-garage .charge-empty-checklist .ready strong {
  color: var(--calm-accent);
}

#screen-garage .charge-empty-checklist .setup strong,
#screen-garage .charge-empty-checklist .missing strong {
  color: var(--calm-amber);
}

/* =====================================================================================================================
   Fit pass: every line of Plan (and its sheets) fits a 320px phone. Nothing runs off the screen, under an icon or
   into its neighbour; long values wrap instead of being cut, and only a name with its full version elsewhere ellipsizes.
   ===================================================================================================================== */

/* Wrapped copy avoids a lone last word ("Updates every 5 / min"). */
#screen-device :is(p, small, h2, h3, h4, strong, span),
#screen-garage :is(p, small, h2, strong, span) {
  text-wrap: pretty;
}

/* The goal ("100% by 12 PM") stays on one line: the numerals shrink on a narrow phone rather than leave "PM" alone. */
#screen-device #chargingPlanTitle:not(.is-text) {
  font-size: min(52px, calc((100vw - 48px) / 6.8));
  text-wrap: balance;
}

#screen-device #chargingPlanTitle.is-text {
  font-size: min(32px, calc((100vw - 48px) / 9));
  overflow-wrap: anywhere;
}

/* Tonight's line and its details wrap in full; long hours and prices are never cut. */
#screen-device #chargingPlanTonightText,
#screen-device .plan-tonight-meta,
#screen-device .plan-tonight-card small,
#screen-device .plan-night-legend span {
  min-width: 0;
  overflow-wrap: anywhere;
}

#screen-device .plan-night-axis em {
  white-space: nowrap;
}

/* Plan for: the vehicle's full name wraps beside "Plan for". When the name and the actions don't fit on one line,
   the actions move under it, right-aligned. */
#screen-device > .plan-vehicle-row {
  flex-wrap: wrap;
  row-gap: 0;
}

#screen-device > .plan-vehicle-row > div:first-child {
  flex: 1 1 auto;
  padding: 10px 0;
}

#screen-device > .plan-vehicle-row h2 {
  overflow: visible;
  min-width: 0;
  white-space: normal;
  text-overflow: clip;
  overflow-wrap: anywhere;
  line-height: 1.35;
}

#screen-device .plan-vehicle-row .schedule-target-actions {
  margin-left: auto;
}

/* Electricity prices: the chip drops under the title when they don't fit side by side. */
#screen-device .plan-rate-context-head {
  flex-wrap: wrap;
  row-gap: 10px;
}

#screen-device .plan-rate-context-head > div {
  flex: 1 1 160px;
  min-width: 0;
}

#screen-device #planRateContextChip {
  white-space: nowrap;
}

#screen-device .plan-signal-value {
  max-width: 50vw;
}

#screen-device .plan-signal-main span,
#screen-device .plan-signal-value span {
  overflow-wrap: anywhere;
}

/* Skip price spikes: the inline limit select keeps its line, and the copy wraps around it. */
#screen-device .charging-plan-toggle > span {
  min-width: 0;
}

/* ---------- Home-only: the Powerwall plan (Weather plan, ways to save, settings) ---------- */
/* No card around the cards: the Weather plan and each section are cards of their own, full width, so nothing is
   squeezed (the week strip's seven days used to push the Weather plan off a 320px screen). */
#screen-device .powerwall-plan {
  grid-template-columns: minmax(0, 1fr);
  gap: 16px;
  margin-bottom: 0;
  padding: 0 !important;
  background: transparent !important;
}

#screen-device .powerwall-plan > *,
#screen-device .powerwall-plan .weather-plan > *,
#screen-device .powerwall-plan .he-section > * {
  min-width: 0;
}

#screen-device .powerwall-plan .weather-plan,
#screen-device .powerwall-plan .he-section {
  grid-template-columns: minmax(0, 1fr);
  margin: 0;
  border: 0 !important;
  border-radius: var(--calm-radius);
  padding: 18px;
  background: var(--calm-surface) !important;
  box-shadow: none !important;
}

#screen-device .powerwall-plan .weather-plan :is(p, small, label, span, i) {
  font-weight: 400;
}

#screen-device .powerwall-plan .weather-plan :is(strong, b, h3, h4) {
  font-weight: 500;
}

#screen-device .powerwall-plan .weather-plan h3 {
  font-size: 17px;
  line-height: 1.35;
  overflow-wrap: anywhere;
}

#screen-device .powerwall-plan .wp-sub,
#screen-device .powerwall-plan .wp-note,
#screen-device .powerwall-plan .wp-step small {
  overflow-wrap: anywhere;
}

/* "On · reVolt runs it" reads as a muted status that wraps under the label if it must, not a pill off the edge. */
#screen-device .powerwall-plan .wp-head {
  flex-wrap: wrap;
  row-gap: 4px;
}

#screen-device .powerwall-plan .wp-status {
  border: 0;
  padding: 0;
  color: var(--calm-muted) !important;
  background: transparent !important;
  font-size: 13px;
  font-weight: 400;
  letter-spacing: 0;
  text-transform: none;
}

#screen-device .powerwall-plan .wp-status.error {
  color: var(--calm-amber) !important;
}

/* Savings tiles: a large month ($1,234.56) shrinks before it overflows its tile. */
#screen-device .powerwall-plan .wp-tiles div {
  min-width: 0;
  background: var(--calm-raised);
}

#screen-device .powerwall-plan .wp-tiles strong {
  font-size: clamp(16px, 5.4vw, 20px);
  font-weight: 400;
  overflow-wrap: anywhere;
  font-variant-numeric: tabular-nums;
}

/* Both tiles keep their values on one baseline when one label wraps ("This month (est.)"). */
#screen-device .powerwall-plan .wp-tiles div {
  align-content: space-between;
}

/* The chart scales down with the card, so its hour labels and peak get a larger size on a narrow phone to stay
   readable (about 9px on screen at 320px). */
@media (max-width: 400px) {
  #screen-device .powerwall-plan .wp-tick {
    font-size: 12.5px;
  }

  #screen-device .powerwall-plan .wp-peak {
    font-size: 13px;
  }
}

/* The limits: the select keeps its natural width so the label beside it has room. */
#screen-device .powerwall-plan .wp-limit > span {
  flex: 1 1 auto;
  min-width: 0;
}

#screen-device .powerwall-plan .wp-limit select {
  flex: none;
  width: auto;
}

/* The week: seven days fit a 320px phone. */
#screen-device .powerwall-plan .wp-week {
  gap: 3px;
}

#screen-device .powerwall-plan .wp-day {
  min-width: 0;
  padding: 6px 0;
  background: var(--calm-raised);
  font-size: 11px;
  letter-spacing: -0.01em;
}

#screen-device .powerwall-plan .wp-day.storm {
  background: rgba(255, 107, 107, 0.14);
}

#screen-device .powerwall-plan .wp-chips span {
  max-width: 100%;
  border: 0;
  background: var(--calm-raised);
  overflow-wrap: anywhere;
}

#screen-device .powerwall-plan .wp-buttons button {
  min-width: 0;
  min-height: 44px;
  white-space: normal;
  line-height: 1.25;
}

#screen-device .powerwall-plan .he-segment button {
  min-width: 0;
  padding-inline: 4px;
  white-space: normal;
  line-height: 1.2;
}

/* ---------- Charge controls sheet ---------- */
/* The refresh button sits at the bottom right of the car card above the controls; the car's name and status keep
   clear of it. */
#screen-garage:has(#chargeControlCard:not(.hidden)) .garage-target-list:not(:has(> .garage-target-card + .garage-target-card)) > .garage-target-card .garage-hero-copy {
  padding-right: 40px;
}

/* Several cars: the switcher shows each car's whole name, wrapping onto more lines (both halves grow together)
   rather than cutting it to a few letters. */
#screen-garage .garage-target-list:has(> .garage-target-card + .garage-target-card) > .garage-target-card {
  height: auto;
}

#screen-garage .garage-target-list:has(> .garage-target-card + .garage-target-card) .garage-hero-copy strong {
  display: block;
  overflow: visible;
  white-space: normal;
  text-overflow: clip;
  overflow-wrap: anywhere;
  line-height: 1.3;
}

#screen-garage .garage-hero-copy strong {
  overflow-wrap: anywhere;
}

#screen-garage .charge-empty-card .eyebrow {
  margin-bottom: 4px;
  line-height: 1.4;
}

/* "Charge controls" keeps its line: a status chip ("No source", "Last seen 2h ago") that doesn't fit beside it on a
   narrow phone drops under it, and the close button stays in the corner, centred on the title's line. */
#screen-garage .charge-sheet-head {
  position: relative;
  flex-wrap: wrap;
  row-gap: 4px;
  padding-right: 46px;
}

#screen-garage .charge-sheet-head > div:first-child {
  flex: 1 0 auto;
  justify-content: center;
  max-width: 100%;
  min-height: 44px;
}

#screen-garage .charge-sheet-head > .charge-sheet-close {
  position: absolute;
  top: 22px;
  right: 0;
  transform: translateY(-50%);
}

/* ---------- "Why this plan" and the vehicle picker ---------- */
/* Two actions share the row while they fit; a longer label ("Set Up Rate Guard") wraps the row instead of running
   off the sheet. */
:is(#aiAssistantOverlay, #targetPickerOverlay, #chargeLimitOverlay) .sheet-actions {
  flex-wrap: wrap;
}

:is(#aiAssistantOverlay, #targetPickerOverlay, #chargeLimitOverlay) .sheet-actions > button {
  flex: 1 1 auto;
  min-width: 0;
  max-width: 100%;
  white-space: normal;
  line-height: 1.25;
}

:is(#aiAssistantOverlay, #targetPickerOverlay) :is(.ai-detail-card, .assumption-grid > div, .target-option) :is(strong, span, small, p) {
  min-width: 0;
  overflow-wrap: anywhere;
}

/* The night bar's ready-by tick at the very end of the scale stays inside the track. */
#screen-device .plan-night-ready[style*="left:100"] {
  margin-left: -6px;
}

/* Tonight's hours: each run ("6 AM–7 AM") keeps together; the line breaks after a comma. */
#screen-device #chargingPlanTonightText .plan-hours-run {
  white-space: nowrap;
}

/* The picker's add-a-car button sizes to its label ("Connect Vehicle" on one line), not to half the sheet. */
#targetPickerOverlay .target-picker-setup-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
}

#targetPickerOverlay .target-picker-setup-actions > button {
  flex: 0 1 auto;
  max-width: 100%;
  padding-inline: 16px;
}

/* Cancel and Save share the row by proportion; their old minimum widths (96px + 150px) pushed the picker's content
   past the sheet's right padding on a 320px phone. */
#targetPickerOverlay .target-picker-sheet {
  grid-template-columns: minmax(0, 1fr);
}

#targetPickerOverlay .target-picker-actions {
  grid-template-columns: minmax(0, 0.72fr) minmax(0, 1.28fr);
}

/* ---------- Schedule editor (price guard, set hours, ready-by) ---------- */
/* Cancel and Save share the row by proportion; their minimum widths (96px + 158px) ran Save past the sheet's
   padding on a 320px phone. A longer label wraps inside its button. */
#scheduleEditorOverlay .schedule-editor-actions {
  grid-template-columns: minmax(0, 0.72fr) minmax(0, 1.28fr);
}

#scheduleEditorOverlay .schedule-editor-actions > button {
  width: 100%;
  min-width: 0;
  padding-inline: 12px;
  white-space: normal;
  line-height: 1.25;
}

/* On a narrow phone each setting's label sits over its field, so "Target battery" and "Fallback deadline" keep
   their lines instead of squeezing into a few letters beside a 132px field. */
@media (max-width: 380px) {
  #scheduleEditorOverlay .schedule-editor-pane .setting-line {
    grid-template-columns: minmax(0, 1fr);
    gap: 8px;
  }
}

/* ---------- Take control (Plan) ---------- */
/* A row right under When to charge that opens the Take control sheet. */
#screen-device > #planTakeControlButton {
  order: 3;
  margin-top: -12px;
}

#screen-device .plan-take-control {
  display: flex;
  align-items: center;
  gap: 14px;
  width: 100%;
  min-height: 64px;
  border: 0;
  border-radius: var(--calm-radius);
  padding: 14px 14px 14px 16px;
  color: var(--calm-text);
  background: var(--calm-surface);
  box-shadow: none;
  font: inherit;
  text-align: left;
  cursor: pointer;
}

#screen-device .plan-take-control.hidden {
  display: none;
}

#screen-device .plan-take-control:hover,
#screen-device .plan-take-control:focus-visible {
  background: var(--surface-soft);
}

#screen-device .plan-take-control-icon {
  display: grid;
  flex: none;
  place-items: center;
  width: 36px;
  height: 36px;
  border-radius: 50%;
  background: var(--calm-accent-soft);
}

#screen-device .plan-take-control-icon svg,
#screen-device .plan-take-control-chevron {
  fill: none;
  stroke-width: 1.7;
  stroke-linecap: round;
  stroke-linejoin: round;
}

#screen-device .plan-take-control-icon svg {
  width: 18px;
  height: 18px;
  stroke: var(--calm-accent);
}

#screen-device .plan-take-control-copy {
  display: flex;
  flex: 1;
  flex-direction: column;
  gap: 3px;
  min-width: 0;
}

#screen-device .plan-take-control-copy strong {
  color: var(--calm-text);
  font-size: 15px;
  font-weight: 500;
}

#screen-device .plan-take-control-copy small {
  color: var(--calm-muted);
  font-size: 13px;
  line-height: 1.4;
}

#screen-device .plan-take-control-chevron {
  flex: none;
  width: 18px;
  height: 18px;
  stroke: var(--calm-faint);
}

/* reVolt plans: the small tag on a locked control names the plan that adds it (Drive, or One on a Home plan). */
#screen-device .plan-autopilot-card.is-locked strong::after {
  content: var(--plan-tag, "Drive");
}
