body:has(.value-dashboard) { background: var(--bg); }
.value-dashboard { gap: clamp(20px, 2.4vw, 32px); }
.value-dashboard__header { padding-block: 4px; }
.value-dashboard__header h1 {
  font-size: clamp(2.05rem, 3.5vw, 2.9rem);
  font-weight: 680;
  line-height: 1.1;
  letter-spacing: -.04em;
}
.value-dashboard__header .value-dashboard__date {
  margin-top: 8px;
  font-size: clamp(.88rem, 1.25vw, 1.04rem);
  line-height: 1.35;
}
.value-dashboard__actions .icon-button {
  width: 44px;
  height: 44px;
  border: 1px solid var(--line);
  border-radius: 999px;
  background: var(--panel-strong);
  color: var(--text);
}
.value-dashboard__actions .value-dashboard__edit {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: auto;
  gap: 8px;
  padding-inline: 16px;
  font-size: .9rem;
  font-weight: 600;
}
.value-dashboard__actions svg { width: 19px; height: 19px; }
.value-dashboard__actions .is-active {
  border-color: var(--accent);
  background: var(--accent-soft);
  color: var(--accent);
}

/* DOM order is profile order at every width. Leave a gap when a wide card
   wraps, so later values never jump ahead of it in the reading order. */
.value-dashboard-grid {
  grid-auto-flow: row;
  gap: clamp(10px, 1.5vw, 18px);
  align-items: stretch;
}
.value-dashboard-grid .value-slot {
  height: auto;
  min-height: 162px;
  border-radius: 16px;
}
.value-dashboard-grid .value-slot:has([data-value-mode="focus"]) {
  grid-column: span 2;
  grid-row: span 2;
  min-height: 300px;
}
.value-dashboard-grid.is-editing .value-slot { min-height: 194px; }
.value-tile {
  --tile-tint: var(--accent-rgb);
  --tile-ink: var(--accent);
  border-color: var(--line);
  background: var(--panel-strong);
  box-shadow: none;
}
[data-theme="light"] .value-tile {
  background: var(--panel-strong);
  box-shadow: none;
  border-color: var(--line);
}
.value-tile[data-card-color]:not([data-card-color=""]) {
  --tile-tint: var(--sensor-rgb);
  --tile-ink: color-mix(in srgb, rgb(var(--sensor-rgb)) 65%, var(--text));
}
.value-tile__body {
  padding: clamp(16px, 1.65vw, 23px);
  gap: 11px;
}
.value-tile__heading {
  display: grid;
  grid-template-columns: auto minmax(0, 1fr);
  grid-template-areas: "icon metric" "icon sensor";
  align-items: center;
  gap: 2px 10px;
  min-width: 0;
}
.value-tile__symbol {
  grid-area: icon;
  display: grid;
  place-items: center;
  width: 36px;
  height: 36px;
  border-radius: 10px;
  color: var(--tile-ink);
  background: rgba(var(--tile-tint),.11);
}
.value-tile__symbol svg { width: 21px; height: 21px; }
.value-tile__metric, .value-tile__sensor {
  display: block;
  margin: 0;
  line-height: 1.25;
  min-height: 0;
  overflow-wrap: anywhere;
  white-space: normal;
}
.value-tile__metric {
  grid-area: metric;
  font-size: 1.05rem;
  font-weight: 650;
  color: var(--text);
}
.value-tile__sensor {
  grid-area: sensor;
  font-size: .84rem;
  font-weight: 450;
  color: var(--muted);
}
.value-tile__reading {
  margin: auto 0 0;
  padding: 0;
  line-height: 1.12;
  font-size: clamp(1.85rem, 2.9vw, 2.7rem);
  overflow-wrap: anywhere;
  white-space: normal;
}
.value-tile__unit {
  color: var(--muted);
  font-size: .55em;
  font-weight: 500;
  letter-spacing: 0;
}
.value-tile__reading--door, .value-tile__reading--long { font-size: clamp(1.35rem, 2.1vw, 2.1rem); }
.value-tile__reading[data-door-state]::before {
  content: "";
  display: inline-block;
  width: .3em;
  height: .3em;
  margin-right: .32em;
  vertical-align: .15em;
  border-radius: 50%;
  background: var(--success);
}
.value-tile__reading[data-door-state="open"]::before { background: var(--warning); }
.value-tile__meta {
  display: flex;
  flex-wrap: wrap;
  align-items: baseline;
  gap: 3px 8px;
}
.value-tile__time, .value-tile__heartbeat, .value-tile__late {
  font-size: .84rem;
  line-height: 1.4;
  color: var(--muted);
  overflow: visible;
  white-space: normal;
}
.value-tile__time time, .value-tile__heartbeat time { font-variant-numeric: tabular-nums; }
.value-tile__late { color: var(--text); font-weight: 600; }
.value-tile__late::before { content: "· "; color: var(--accent); }
.value-tile__heartbeat { border-top: 1px solid var(--line); padding-top: 7px; }
[data-value-mode="focus"] .value-tile__reading {
  margin-top: 6px;
  font-size: clamp(2rem, 3.2vw, 3.2rem);
}
[data-value-mode="focus"]:not(:has(.value-history)) .value-tile__reading { margin-top: auto; }
.value-history {
  display: flex;
  flex-direction: column;
  gap: 3px;
  margin-top: 2px;
  min-width: 0;
}
.value-history__period, .value-history__empty, .value-history__dates, .value-history__scale {
  color: var(--muted);
  font-size: .7rem;
  line-height: 1.2;
  font-variant-numeric: tabular-nums;
}
.value-history__period { align-self: flex-end; }
.value-history__plot { display: grid; height: 35px; min-width: 0; }
.value-history__empty { align-self: center; }
.value-history__graph {
  display: grid;
  grid-template-columns: auto minmax(0, 1fr);
  grid-template-rows: minmax(0, 1fr) auto;
  height: 100%;
  min-width: 0;
  min-height: 0;
}
.value-history__graph svg { grid-column: 2; width: 100%; height: 100%; overflow: visible; }
.value-history__scale { display: flex; flex-direction: column; justify-content: space-between; padding-right: 5px; text-align: end; }
.value-history__graph :is(polyline, path) { vector-effect: non-scaling-stroke; fill: none; }
.value-history__grid { stroke: var(--line); stroke-width: 1; }
.value-history__area { fill: rgba(var(--accent-rgb), .11); }
.value-history__reference { stroke: var(--muted); stroke-width: 1; stroke-dasharray: 4 3; }
.value-history__line, .value-history__point { stroke: var(--accent); stroke-linecap: round; stroke-linejoin: round; }
.value-history__line { stroke-width: 1.6; }
.value-history__point { stroke-width: 4; }
.value-history__dates { grid-column: 2; display: flex; justify-content: space-between; padding-top: 5px; }
[data-value-mode="focus"] .value-history { margin-top: auto; gap: 6px; }
[data-value-mode="focus"] .value-history__period { order: -1; }
[data-value-mode="focus"] .value-history__plot { height: clamp(108px, 12vw, 156px); }
.value-tile--drag-preview {
  position: fixed;
  top: 0;
  left: 0;
  z-index: 20;
  pointer-events: none;
  border-radius: 16px;
  box-shadow: 0 10px 25px rgba(0,0,0,.24);
}
.value-tile--drag-preview .value-tile__body { padding-top: 49px; }
.value-tile.is-dragging { opacity: .33; }
.value-slot.is-drop-target { outline-offset: 2px; }
@media (max-width: 720px) {
  .value-dashboard-grid .value-slot { min-height: 138px; }
  .value-dashboard-grid .value-slot:has([data-value-mode="focus"]) { grid-row: auto; min-height: 218px; }
  .value-dashboard-grid.is-editing .value-slot { min-height: 182px; }
  .value-dashboard__header { align-items: flex-start; }
  .value-dashboard__actions .value-dashboard__edit { width: 44px; padding: 0; }
  .value-dashboard__edit-label { display: none; }
  .value-tile__body { padding: 13px; gap: 7px; }
  .value-tile__heading {
    grid-template-areas: "icon metric" "sensor sensor";
    gap: 4px 6px;
  }
  .value-tile__symbol { width: 18px; height: 19px; background: none; }
  .value-tile__symbol svg { width: 17px; height: 17px; }
  .value-tile__metric { font-size: .88rem; hyphens: auto; }
  .value-tile__sensor { font-size: .8rem; }
  .value-tile__reading { font-size: clamp(1.49rem, 6vw, 2rem); }
  .value-tile__reading--door, .value-tile__reading--long { font-size: clamp(1.02rem, 4.5vw, 1.55rem); }
  .value-tile__time, .value-tile__heartbeat, .value-tile__late { font-size: .77rem; }
  .value-history__plot { height: 28px; }
}
@media (max-width: 340px) {
  .value-dashboard-grid { gap: 8px; }
  .value-tile__body { padding-inline: 10px; }
  .value-tile__metric { font-size: .8rem; }
}
@media (hover: hover) {
  .value-slot .value-tile:has(a.value-tile__body:hover) { border-color: rgba(var(--tile-tint),.55); }
}
@media (prefers-reduced-motion: reduce) {
  .value-dashboard-grid *, .value-tile--drag-preview { transition: none; animation: none; }
}
