:root {
  --bg: #f2f3f5;
  --surface: #ffffff;
  --ink: #1c1c1e;
  --secondary: #636366;
  --tertiary: #8e8e93;
  --line: #e6e6eb;
  --fill: #f2f2f7;
  --green: #1f9d55;
  --green-soft: #e7f6ee;
  --red: #e5484d;
  --red-soft: #fdecec;
  --amber: #b7791f;
  --amber-soft: #fff6e5;
  --radius: 22px;
  --shadow: 0 1px 2px rgba(28, 28, 30, 0.04), 0 10px 28px rgba(28, 28, 30, 0.07);
  --shadow-lift: 0 16px 40px rgba(23, 23, 26, 0.16), 0 2px 8px rgba(23, 23, 26, 0.08);
  --font: "PingFang SC", "Hiragino Sans GB", "Noto Sans SC", "HarmonyOS Sans", "Microsoft YaHei", -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  --safe-t: env(safe-area-inset-top, 0px);
  --safe-b: env(safe-area-inset-bottom, 0px);
  --tab: 58px;
  color: var(--ink);
  background: var(--bg);
  font-family: var(--font);
  font-size: 16px;
  line-height: 1.45;
  color-scheme: light;
}

* {
  box-sizing: border-box; -webkit-tap-highlight-color: transparent;
  scrollbar-width: none; -ms-overflow-style: none;
}
*::-webkit-scrollbar { display: none; width: 0; height: 0; }
[hidden] { display: none !important; }
html { touch-action: manipulation; }
body { margin: 0; min-height: 100dvh; background: var(--bg); overflow-x: clip; }
button, input, select, textarea { font: inherit; color: inherit; }
button { cursor: pointer; }
h1, h2, p { margin: 0; }
:focus { outline: none; }
:focus-visible { outline: 2px solid var(--ink); outline-offset: 2px; }

.shell { min-height: 100dvh; display: flex; }
.shell[hidden], .auth-screen[hidden] { display: none !important; }
body:not(.is-admin) .admin-only { display: none !important; }
body.is-admin .non-admin-only { display: none !important; }
body.is-cloud .device-only { display: none !important; }
body:not(.is-cloud) .cloud-only { display: none !important; }
body.is-cloud #view-hooks .edge-managed input:not([type="hidden"]),
body.is-cloud #view-hooks .edge-managed select,
body.is-cloud #view-hooks .edge-managed textarea { cursor: default; }
body.is-cloud #view-hooks .edge-managed.is-readonly { opacity: 1; }
body.is-cloud #view-hooks .edge-managed.is-readonly input,
body.is-cloud #view-hooks .edge-managed.is-readonly select,
body.is-cloud #view-hooks .edge-managed.is-readonly textarea { color: var(--ink); }
.auth-screen { min-height: 100dvh; display: grid; place-items: center; padding: 24px 16px; }
.auth-card {
  width: min(420px, 100%); background: var(--surface); border: 0; border-radius: 28px;
  padding: 28px 26px; display: grid; gap: 14px; box-shadow: var(--shadow-lift);
}
.auth-card h1 { font-size: 28px; letter-spacing: -0.04em; }
.auth-card a.text-btn { display: block; background: transparent; color: var(--secondary); text-align: center; text-decoration: none; }
.captcha-row { display: grid; grid-template-columns: 1fr auto; gap: 10px; align-items: end; }
.captcha { width: 112px; height: 40px; border: 0; padding: 0; background: transparent; }
.captcha svg { display: block; }
.topbar-side { display: flex; align-items: center; gap: 8px; }
.whoami { color: var(--secondary); font-size: 13px; font-weight: 650; }
.sidebar { display: none; }
.main { flex: 1; min-width: 0; }
.workspace { width: min(1080px, 100%); margin: 0 auto; }

.nav svg {
  width: 22px; height: 22px; flex: none;
  fill: none; stroke: currentColor; stroke-width: 1.75;
  stroke-linecap: round; stroke-linejoin: round;
}

.brand { display: flex; gap: 12px; align-items: center; padding: 0 8px; }
.brand strong { display: block; font-size: 16px; letter-spacing: -0.02em; }
.brand small { display: block; margin-top: 2px; color: var(--tertiary); font-size: 12px; }
.mark { width: 36px; height: 36px; display: block; }
.mark svg { width: 36px; height: 36px; display: block; }

.side-nav { display: flex; flex-direction: column; gap: 4px; margin-top: 28px; }
.side-nav button {
  display: flex; align-items: center; gap: 10px;
  border: 0; background: transparent; color: var(--secondary);
  border-radius: 12px; min-height: 44px; padding: 0 12px;
  font-size: 15px; font-weight: 600; text-align: left;
}
.side-nav button.active { background: var(--fill); color: var(--ink); }
.side-note { margin: auto 0 0; padding: 16px 8px 0; color: var(--tertiary); font-size: 12px; line-height: 1.55; }

.topbar {
  display: flex; align-items: flex-end; justify-content: space-between; gap: 12px;
  padding: 8px 0 14px;
}
.product { font-size: 12px; font-weight: 700; color: var(--tertiary); letter-spacing: 0.02em; }
h1 { font-size: 28px; line-height: 1.15; letter-spacing: -0.03em; font-weight: 700; }
.pill {
  display: inline-flex; align-items: center; gap: 6px;
  max-width: 46vw; height: 32px; padding: 0 10px 0 8px;
  border-radius: 999px; background: var(--surface); border: 0;
  box-shadow: 0 4px 14px rgba(28, 28, 30, 0.08);
  color: var(--secondary); font-size: 12px; font-weight: 650; font-weight: 600;
}
#conn-text { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.pill .dot { width: 7px; height: 7px; border-radius: 99px; background: #c7c7cc; flex: none; }
.pill.on { color: var(--green); }
.pill.on .dot { background: #34c759; box-shadow: 0 0 0 3px rgba(52, 199, 89, 0.18); }
.pill.busy { color: var(--amber); }
.pill.busy .dot { background: #f5a524; }
.pill.bad { color: var(--red); }
.pill.bad .dot { background: var(--red); }

.tabbar {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 30;
  display: grid; grid-template-columns: repeat(7, 1fr);
  height: calc(var(--tab) + var(--safe-b));
  padding: 4px 6px var(--safe-b);
  background: rgba(255, 255, 255, 0.94);
  border-top: 0;
  box-shadow: 0 -10px 30px rgba(28, 28, 30, 0.06);
  backdrop-filter: blur(16px) saturate(1.4);
}
.tabbar button {
  border: 0; background: transparent; color: var(--tertiary);
  display: flex; flex-direction: column; align-items: center; justify-content: center;
  gap: 2px; min-height: 48px; border-radius: 12px;
  font-size: 10px; font-weight: 600; padding: 2px 0 4px;
}
.tabbar button.active { color: var(--ink); }
.tabbar.nav svg { width: 22px; height: 22px; flex: none; }

.measure-grid, .side-stack { display: flex; flex-direction: column; gap: 16px; }
.home-plan .plan-meter { margin-top: 14px; }
.plan-meter-top, .plan-meter-scale {
  display: flex; justify-content: space-between; gap: 8px;
  font-size: 13px; font-weight: 600;
}
.plan-meter-top { margin-bottom: 6px; color: var(--ink); }
.plan-meter-scale { margin-top: 6px; color: var(--secondary); }
.plan-track-wrap { position: relative; }
.plan-track { position: relative; height: 10px; border-radius: 99px; background: var(--fill); overflow: hidden; }
.plan-track > i { display: block; height: 100%; width: 0; background: var(--ink); border-radius: 99px; }
.plan-track.time > i { background: #7c6af7; }
.plan-origin {
  position: absolute; top: 0; bottom: 0; z-index: 2; width: 3px; margin-left: -1.5px;
  background: #c98412; border-radius: 2px;
}
.plan-origin-label {
  position: absolute; top: 14px; transform: translateX(-50%);
  font-size: 11px; font-weight: 700; color: #c98412; white-space: nowrap; pointer-events: none;
}
.plan-meter.has-origin .plan-meter-scale { margin-top: 22px; }
.home-plan .story-copy { margin-top: 12px; }
.plan-feedback { display: block; margin-top: 8px; font-weight: 650; }
.plan-status {
  display: inline-flex; align-items: center; margin-left: 8px; padding: 4px 10px;
  border-radius: 999px; font-size: 13px; font-weight: 800; line-height: 1.2; vertical-align: middle;
  letter-spacing: 0.02em;
}
.plan-status.draft { background: #ececee; color: #636366; }
.plan-status.active { background: #ece8ff; color: #5b4cdb; }
.plan-status.succeeded { background: var(--green-soft); color: var(--green); }
.plan-status.failed { background: var(--red-soft); color: var(--red); }
.plan-status.abandoned { background: var(--amber-soft); color: var(--amber); }
.story-heading .plan-status { font-size: 14px; }
.cell.plan-draft { box-shadow: inset 4px 0 0 #c7c7cc; }
.cell.plan-active { box-shadow: inset 4px 0 0 #5b4cdb; }
.cell.plan-succeeded { box-shadow: inset 4px 0 0 var(--green); }
.cell.plan-failed { box-shadow: inset 4px 0 0 var(--red); }
.cell.plan-abandoned { box-shadow: inset 4px 0 0 var(--amber); }
.plan-feedback.good { color: var(--green); }
.plan-feedback.encourage { color: #c98412; }
.home-ai-advice #home-ai-text { margin-top: 8px; font-size: 17px; line-height: 1.55; }
.home-ai-advice #home-ai-status { margin-top: 10px; }
.surface, .group-card, .story-card {
  background: var(--surface);
  border: 0;
  border-radius: 28px;
  box-shadow: var(--shadow);
}
.portrait {
  background: #17171a;
  color: #fff;
  border-radius: 28px;
  padding: 26px 26px 22px;
  box-shadow: var(--shadow-lift);
}
.portrait-top { display: flex; justify-content: space-between; align-items: center; }
.portrait .status-chip.idle { color: rgba(255,255,255,.72); background: rgba(255,255,255,.08); }
.portrait .status-chip.on { color: #b7f0cb; background: rgba(52,199,89,.16); }
.portrait .status-chip.busy { color: #ffd58a; background: rgba(245,165,36,.16); }
.portrait-name { margin-top: 22px; font-size: 15px; font-weight: 650; color: rgba(255,255,255,.62); }
.portrait-name:empty { display: none; }
.portrait #weight-value { color: #fff; }
.portrait .unit { color: rgba(255,255,255,.55); }
.portrait-story { margin-top: 16px; max-width: 40rem; font-size: 17px; line-height: 1.55; font-weight: 560; }
.portrait-facts { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 14px; }
.portrait-facts:empty { display: none; }
.portrait-facts span {
  padding: 6px 10px; border-radius: 999px;
  background: rgba(255,255,255,.08); font-size: 13px; font-weight: 650;
}
.portrait .caption { color: rgba(255,255,255,.5); }
.portrait .field span { color: rgba(255,255,255,.62); }
.portrait .field select { background: rgba(255,255,255,.08); color: #fff; }
.portrait button.primary { background: #fff; color: #17171a; }
.portrait button.ghost { background: rgba(255,255,255,.08); color: #fff; }
.portrait .detail-note { color: rgba(255,255,255,.62); }
.status-chip {
  display: inline-flex; align-items: center; gap: 6px;
  margin: 0; padding: 4px 10px; border-radius: 999px;
  font-size: 12px; font-weight: 700;
}
.status-chip.idle { color: var(--secondary); background: var(--fill); }
.status-chip.on { color: var(--green); background: var(--green-soft); }
.status-chip.busy { color: var(--amber); background: var(--amber-soft); }
.weight-row { display: flex; align-items: flex-end; gap: 6px; margin-top: 12px; }
#weight-value {
  font-size: clamp(56px, 16vw, 92px);
  font-weight: 700; letter-spacing: -0.055em; line-height: 0.9;
  font-variant-numeric: tabular-nums;
}
.unit { font-size: 18px; font-weight: 600; color: var(--secondary); margin-bottom: 6px; }
.who { margin-top: 12px; font-size: 16px; font-weight: 700; }
.who:empty { display: none; }
.caption { margin-top: 6px; color: var(--secondary); font-size: 14px; line-height: 1.5; }
.hero-actions { display: flex; flex-direction: column; gap: 10px; margin-top: 18px; }
.action-row { display: grid; grid-template-columns: 1fr 88px; gap: 8px; }

.field { display: flex; flex-direction: column; gap: 6px; min-width: 0; }
.field span, .kicker { font-size: 13px; font-weight: 600; color: var(--secondary); }
.grow { flex: 1; }
.field input, .field select, .field textarea, .inline-row select, .inline-row input {
  width: 100%; background: var(--fill); border: 1px solid transparent;
  border-radius: 12px; min-height: 48px; padding: 12px 14px; font-size: 16px;
}
.field textarea { resize: vertical; line-height: 1.45; }
.inline-row select, .inline-row input { min-height: 40px; padding: 8px 12px; width: auto; max-width: 58%; }
.field input:focus, .field select:focus, .field textarea:focus,
.inline-row select:focus, .inline-row input:focus {
  background: #fff; box-shadow: 0 0 0 2px var(--ink);
}

button.primary, button.ghost, .text-btn {
  border: 0; border-radius: 12px; min-height: 48px; padding: 0 16px;
  font-size: 16px; font-weight: 650; font-weight: 600;
}
button.primary { background: var(--ink); color: #fff; }
button.primary:disabled { opacity: 0.4; }
button.ghost, .text-btn { background: var(--fill); color: var(--ink); }
button.slim, .text-btn { min-height: 36px; padding: 0 12px; border-radius: 10px; font-size: 14px; }
.text-btn.danger { background: var(--red-soft); color: var(--red); }
.toolbar { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 12px; }
.toolbar button { flex: 1; min-width: 7rem; }

.scale-bind-row {
  display: flex; align-items: center; justify-content: space-between; gap: 14px;
  padding: 14px 16px;
}
.scale-bind-main { min-width: 0; flex: 1; }
.scale-bind-kicker { margin: 0 0 4px; font-size: 13px; font-weight: 600; color: var(--secondary); }
#scale-bound-name {
  display: block; font-size: 17px; font-weight: 700; letter-spacing: -0.02em;
  overflow-wrap: anywhere;
}
#scale-bound-meta { display: block; margin-top: 4px; font-size: 12px; line-height: 1.45; overflow-wrap: anywhere; }
.scale-bind-actions { flex-shrink: 0; display: flex; flex-direction: column; align-items: flex-end; gap: 6px; }
.scale-bind-actions .primary.slim { min-width: 7.5rem; white-space: nowrap; }

.group-card { overflow: hidden; padding: 6px 8px; }
.group-card.plain-card { padding: 0; background: transparent; box-shadow: none; border: 0; }
#device-dialog-form { padding-bottom: calc(16px + env(safe-area-inset-bottom, 0px)); }
.group-card > .field { margin: 0; padding: 14px 16px 6px; }
.group-card > .toolbar { margin: 0; padding: 8px 16px 14px; }
.group-card > .scale-bind-row + .inline-row,
.group-card > .scale-bind-row + .switch-row,
.group-card > .scale-bind-row + .field,
.group-card > .cell + .cell,
.group-card > .inline-row + .inline-row,
.group-card > .switch-row + .switch-row,
.group-card > .switch-row + .field,
.group-card > .inline-row + .field,
.group-card > .field + .field,
.group-card > .field + .toolbar { border-top: 1px solid var(--line); }
.group-card:empty { display: none; }
.group-title { margin: 18px 4px 8px; font-size: 13px; font-weight: 700; color: var(--secondary); }
.view > .measure-grid > div > .group-title:first-child,
.filters + .group-title { margin-top: 4px; }
.cell-head { padding: 12px 14px 0; font-size: 13px; font-weight: 700; color: var(--secondary); }
.cell {
  display: flex; align-items: center; gap: 12px;
  padding: 14px 16px; border-top: 0; background: transparent;
}
.cell-main {
  flex: 1; min-width: 0; border: 0; background: transparent;
  text-align: left; padding: 0; min-height: 44px;
}
.cell-weight { font-size: 20px; font-weight: 700; letter-spacing: -0.03em; font-variant-numeric: tabular-nums; }
.cell-weight small, .trend-now small { font-size: 13px; font-weight: 600; color: var(--secondary); margin-left: 3px; }
.cell-sub { margin-top: 2px; color: var(--secondary); font-size: 13px; line-height: 1.4; }
.cell-actions { display: flex; gap: 6px; flex: none; }
.avatar, .device-ico {
  width: 40px; height: 40px; flex: none; display: grid; place-items: center; font-weight: 700;
}
.avatar { border-radius: 50%; }
.device-ico { border-radius: 12px; background: var(--fill); color: var(--ink); }
.device-ico svg { width: 20px; height: 20px; fill: none; stroke: currentColor; stroke-width: 1.75; stroke-linecap: round; }
.tag {
  display: inline-block; margin-left: 6px; font-size: 11px; font-weight: 700;
  color: var(--green); background: var(--green-soft); border-radius: 999px; padding: 1px 6px;
}
.muted { color: var(--secondary); font-size: 13px; }
.error {
  background: var(--red-soft); color: #c0363a; border-radius: 14px;
  padding: 10px 12px; font-size: 14px;
}
.error[hidden] { display: none !important; }

.story-card { padding: 22px 22px 20px; }
.story-heading { margin-top: 4px; font-size: 22px; letter-spacing: -0.03em; }
.story-copy { margin-top: 8px; color: var(--secondary); font-size: 14px; line-height: 1.55; }
.story-layout { display: grid; grid-template-columns: 56px 1fr; gap: 18px; align-items: center; }
.story-card.is-empty .story-layout { display: none; }
.story-card:not(.is-empty) .compose-empty { display: none; }
.compose-empty { margin: 0; color: var(--secondary); font-size: 14px; line-height: 1.55; }
.body-stack {
  height: 220px; border-radius: 28px; overflow: hidden;
  display: flex; flex-direction: column; background: var(--fill);
}
.story-layout .legend { margin-top: 14px; }
.detail-lead { margin: 0 0 8px; color: var(--ink); font-size: 16px; }
.detail-tiles { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 10px; }
.detail-tile {
  min-height: 88px; padding: 12px 14px; border-radius: 16px; background: var(--fill);
  display: flex; flex-direction: column; align-items: flex-start; gap: 4px;
}
.detail-tile > span { font-size: 13px; font-weight: 700; color: var(--secondary); }
.detail-tile b { font-size: 22px; letter-spacing: -0.03em; line-height: 1.15; font-variant-numeric: tabular-nums; }
.detail-tile b small { font-size: 13px; font-weight: 650; color: var(--secondary); margin-left: 3px; }
.detail-tile .badge { margin-top: auto; }
.detail-tile-sub { font-size: 12px; font-weight: 650; color: var(--secondary); }
#detail .group-title { margin: 16px 0 8px; }
.body-stack i { display: block; min-height: 6px; }
.story-ranges { padding-bottom: 18px; }
.household-list { display: flex; flex-direction: column; gap: 8px; margin-top: 14px; }
.household-row {
  display: flex; align-items: flex-start; gap: 12px; width: 100%;
  border: 0; background: var(--fill); color: inherit; text-align: left;
  border-radius: 18px; padding: 14px 16px; box-shadow: inset 0 0 0 0 transparent;
}
.household-row strong { display: block; font-size: 16px; letter-spacing: -0.02em; }
.household-row .me-tag {
  margin-left: 8px; font-size: 11px; font-weight: 700; color: var(--secondary);
  background: #fff; border-radius: 999px; padding: 2px 7px; vertical-align: 1px;
}
.household-when { margin-top: 4px; font-size: 14px; line-height: 1.45; }
.household-trend { margin-top: 4px; font-size: 13px; line-height: 1.45; font-weight: 650; color: var(--secondary); }
.household-trend.down { color: var(--green); }
.household-trend.up { color: #c98412; }
.household-row .avatar { width: 42px; height: 42px; margin-top: 2px; }
.household-copy { flex: 1; min-width: 0; }
.household-eye {
  flex: none; width: 40px; height: 40px; margin-top: 2px;
  border: 0; border-radius: 12px; background: #fff; color: var(--ink);
  display: grid; place-items: center;
}
.household-eye svg {
  width: 20px; height: 20px; fill: none; stroke: currentColor;
  stroke-width: 1.75; stroke-linecap: round; stroke-linejoin: round;
}
.ranges { margin-top: 8px; }
.range-row { padding: 14px 0 12px; border-top: 1px solid var(--line); }
.range-row:first-child { border-top: 0; }
.range-head { display: flex; align-items: baseline; gap: 8px; }
.range-head .badge { margin-top: 0; }
.range-head span { color: var(--secondary); font-size: 13px; font-weight: 700; }
.range-head b { margin-left: auto; font-size: 22px; letter-spacing: -0.04em; font-variant-numeric: tabular-nums; }
.range-head b small { font-size: 13px; font-weight: 650; color: var(--secondary); margin-left: 3px; }
.range-track { position: relative; height: 8px; margin-top: 10px; border-radius: 99px; background: #ececf1; }
.range-track.ok { background: linear-gradient(90deg, #d8f5e4, #8ed7a8); }
.range-track.warn { background: linear-gradient(90deg, #fff1cc, #f5c15a); }
.range-track.bad { background: linear-gradient(90deg, #ffd9d4, #f08a7e); }
.range-track i {
  position: absolute; top: 50%; width: 14px; height: 14px; border-radius: 50%;
  background: #fff; border: 3px solid #17171a; transform: translate(-50%, -50%);
}
.range-track.ok i { border-color: #1f9d55; }
.range-track.warn i { border-color: #c98412; }
.range-track.bad i { border-color: #e85d4c; }
.range-note { margin: 8px 0 0; color: var(--secondary); font-size: 13px; line-height: 1.5; }
.legend { list-style: none; margin: 0; padding: 0 4px 0 0; display: flex; flex-direction: column; gap: 10px; }
.legend li { display: grid; grid-template-columns: 8px 1fr auto; gap: 8px; align-items: center; font-size: 14px; }
.legend i { width: 8px; height: 8px; border-radius: 99px; }
.legend b { font-variant-numeric: tabular-nums; font-weight: 700; }

.badge {
  margin-top: 4px; font-style: normal; font-size: 12px; font-weight: 700;
  padding: 2px 8px; border-radius: 999px; background: var(--fill); color: var(--secondary);
}
.badge.ok { background: var(--green-soft); color: var(--green); }
.badge.warn { background: var(--amber-soft); color: var(--amber); }
.badge.bad { background: var(--red-soft); color: var(--red); }

.filters { display: flex; gap: 8px; align-items: flex-end; margin-bottom: 12px; flex-wrap: wrap; }
.filters .ghost { flex: none; min-width: 76px; }
.trend-filters, .activity-filters { flex-direction: column; align-items: stretch; }
.trend-filters > .field.grow, .activity-filters > .field.grow { width: 100%; }
.trend-filters > .range-chips, .activity-filters > .range-chips { width: 100%; margin: 0; }
.trend-filters > #trend-granularity { width: 100%; margin: 0; }
.trend-filters > .range-custom-row, .activity-filters > .range-custom-row { width: 100%; }
.range-custom-row {
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(0, 1fr);
  gap: 8px;
  align-items: end;
}
.range-custom-row[hidden] { display: none !important; }
.range-custom-field { min-width: 0; margin: 0; }
.range-custom-field input { min-height: 44px; font-size: 15px; padding: 10px 12px; }
@media (min-width: 700px) {
  .trend-filters, .activity-filters { flex-direction: row; align-items: flex-end; flex-wrap: wrap; }
  .trend-filters > .range-chips, .activity-filters > .range-chips { flex: 1 1 100%; order: 3; }
  .trend-filters > .range-custom-row, .activity-filters > .range-custom-row { flex: 1 1 100%; order: 4; max-width: 22rem; }
  .trend-filters > #trend-granularity { flex: 1 1 100%; order: 5; }
}
.trend-granularity-note { margin: -4px 4px 12px; line-height: 1.5; }
.day { margin-top: 14px; }
.day h3 { margin: 0 4px 8px; font-size: 13px; font-weight: 700; color: var(--secondary); }
.empty {
  text-align: center; color: var(--secondary); background: var(--surface);
  border: 0; border-radius: 22px; padding: 32px 20px; font-size: 14px;
  box-shadow: var(--shadow);
}
.trend-board {
  display: grid;
  gap: 12px;
  grid-template-columns: 1fr;
}
@media (min-width: 520px) {
  .trend-board { grid-template-columns: repeat(2, minmax(0, 1fr)); }
}
@media (min-width: 840px) {
  .trend-board { grid-template-columns: repeat(3, minmax(0, 1fr)); }
}
.trend-panel {
  padding: 14px 14px 12px;
  border-radius: 22px;
  background: var(--surface);
  box-shadow: var(--shadow);
  min-width: 0;
}
.trend-panel-head {
  display: flex;
  flex-wrap: wrap;
  align-items: baseline;
  justify-content: space-between;
  gap: 4px 8px;
  margin-bottom: 4px;
}
.trend-panel-head .kicker { margin: 0; font-size: 13px; }
.trend-panel-now {
  margin: 0;
  font-size: 22px;
  font-weight: 700;
  font-variant-numeric: tabular-nums;
  letter-spacing: -0.03em;
  line-height: 1.1;
}
.trend-panel-now small { font-size: 12px; font-weight: 600; color: var(--secondary); margin-left: 2px; }
.trend-panel-delta { margin: 0; font-size: 12px; padding: 4px 8px; flex: 0 0 auto; }
.trend-panel-chart {
  height: 172px;
  width: 100%;
  max-width: 100%;
  overflow: hidden;
}
.trend-panel-chart.is-hidden { display: none; }
.trend-panel-empty {
  margin: 0;
  padding: 20px 8px;
  font-size: 13px;
  text-align: center;
  box-shadow: none;
  background: var(--fill);
  border-radius: 14px;
}
.trend-panel-empty[hidden] { display: none !important; }
#trend-empty:not([hidden]) { margin-bottom: 12px; }
.scroller { display: flex; gap: 8px; overflow-x: auto; scrollbar-width: none; -webkit-overflow-scrolling: touch; padding-bottom: 2px; }
.scroller::-webkit-scrollbar { display: none; }
.chip {
  flex: none; border: 0; background: var(--fill); color: var(--secondary);
  border-radius: 999px; min-height: 36px; padding: 0 14px; font-size: 14px; font-weight: 600;
}
.chip.active { background: var(--ink); color: #fff; }
.trend-head { display: flex; justify-content: space-between; align-items: flex-end; gap: 12px; margin: 14px 2px 4px; }
.trend-now { margin-top: 2px; font-size: 34px; font-weight: 700; letter-spacing: -0.04em; font-variant-numeric: tabular-nums; line-height: 1; }
.delta {
  margin: 0; font-size: 13px; font-weight: 700; font-variant-numeric: tabular-nums;
  background: var(--fill); color: var(--secondary); border-radius: 999px; padding: 6px 10px; white-space: nowrap;
}
.delta:empty { display: none; }
.delta.good { color: var(--green); background: var(--green-soft); }
.delta.bad { color: var(--red); background: var(--red-soft); }
#activity-home[hidden] { display: none !important; }
.activity-home-embed {
  margin-top: 20px; padding-top: 18px; border-top: 1px solid var(--line);
}
.activity-home-embed .story-heading { margin-bottom: 10px; }
.activity-day-head { padding: 8px 8px 4px; }
.activity-day-head .activity-totals { margin-top: 0; }
.activity-day-head .activity-totals b { font-size: 22px; }
.activity-totals { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; margin-top: 14px; }
.activity-totals div { background: var(--fill); border-radius: 16px; padding: 14px 10px; text-align: center; }
.activity-totals span { display: block; font-size: 12px; color: var(--tertiary); font-weight: 600; }
.activity-totals b { display: block; margin-top: 4px; font-size: 26px; font-weight: 750; letter-spacing: -0.04em; font-variant-numeric: tabular-nums; }
.activity-totals small { font-size: 12px; font-weight: 650; color: var(--secondary); margin-left: 2px; }
#activity-chart { height: 200px; width: 100%; margin-top: 8px; }
#activity-chart:empty, #activity-chart.is-hidden { display: none; }
.activity-run { margin: 0; padding: 8px 0; color: var(--ink); font-size: 15px; }
.activity-run span { color: var(--secondary); }
.mini-stats { display: grid; grid-template-columns: repeat(4, 1fr); gap: 8px; margin-top: 4px; }
.mini-stats div { background: var(--fill); border-radius: 16px; padding: 12px 10px; text-align: center; }
.mini-stats span { display: block; font-size: 11px; color: var(--tertiary); font-weight: 600; }
.mini-stats b { display: block; margin-top: 2px; font-size: 13px; font-variant-numeric: tabular-nums; }

.form-grid { display: grid; grid-template-columns: 1fr; gap: 14px; padding: 22px; }
.span { grid-column: 1 / -1; }
.inline-row, .switch-row {
  display: flex; align-items: center; justify-content: space-between; gap: 12px;
  padding: 14px 16px; border-top: 0; border-radius: 18px;
  min-height: 56px; background: transparent;
}
.switch-row.plain { border: 0; border-radius: 14px; background: var(--fill); padding: 12px; }
.switch-row span, .inline-row > span { font-size: 15px; font-weight: 600; }
.switch-row b { display: block; font-size: 15px; font-weight: 650; font-weight: 600; }
.switch-row small { display: block; margin-top: 2px; font-size: 12px; font-weight: 500; color: var(--tertiary); line-height: 1.4; }
.switch {
  appearance: none; -webkit-appearance: none; width: 48px; height: 28px; border-radius: 999px;
  background: #e5e5ea; position: relative; flex: none; border: 0; transition: background 0.2s ease;
}
.switch::after {
  content: ""; position: absolute; width: 24px; height: 24px; border-radius: 50%;
  background: #fff; top: 2px; left: 2px; box-shadow: 0 1px 2px rgba(0, 0, 0, 0.18); transition: transform 0.2s ease;
}
.switch:checked { background: var(--green); }
.switch:checked::after { transform: translateX(20px); }

.dot-label { display: inline-flex; align-items: center; gap: 6px; font-weight: 700; }
.dot-label i { width: 8px; height: 8px; border-radius: 99px; background: var(--tertiary); }
.dot-label.ok i { background: #34c759; }
.dot-label.bad i { background: var(--red); }

.footnote { margin: 28px 4px 8px; color: var(--tertiary); font-size: 12px; line-height: 1.55; }

dialog {
  border: 0; padding: 0; width: min(520px, calc(100% - 32px));
  border-radius: 28px; background: #fff; color: var(--ink);
  max-height: min(720px, calc(100dvh - 32px)); overflow: auto;
  box-shadow: 0 24px 80px rgba(28, 28, 30, 0.22);
}
dialog::backdrop { background: rgba(28, 28, 30, 0.42); }
dialog form { padding: 12px 22px 22px; }
dialog header {
  display: flex; align-items: center; justify-content: space-between; gap: 12px;
  position: sticky; top: 0; background: #fff; padding: 8px 0 12px; z-index: 1;
}
dialog header strong { font-size: 17px; letter-spacing: -0.02em; }
.grabber { width: 36px; height: 4px; border-radius: 99px; background: #e5e5ea; margin: 8px auto 0; }
.detail-note { margin-top: 12px; color: var(--tertiary); font-size: 12px; }
.assign { margin-top: 8px; padding-top: 4px; border-top: 1px solid var(--line); display: flex; flex-direction: column; gap: 10px; }
.assign .group-title { margin: 8px 0 0; }
.assign .primary, .assign .ghost { width: 100%; }
.form-grid.plain { padding: 0; border: 0; background: transparent; gap: 10px; }
#member-form.form-grid.plain,
#plan-form.form-grid.plain {
  padding: 8px 24px calc(28px + env(safe-area-inset-bottom, 0px));
  gap: 14px;
}
#member-form > .grabber,
#member-form > header,
#plan-form > .grabber,
#plan-form > header,
#plan-form > .detail-note,
#confirm-form > .grabber,
#confirm-form > header,
#confirm-form > .confirm-copy { grid-column: 1 / -1; }
#confirm-form.form-grid.plain,
#plan-checkin-form.form-grid.plain {
  padding: 8px 24px calc(28px + env(safe-area-inset-bottom, 0px));
  gap: 14px;
}
#plan-checkin-form > .grabber,
#plan-checkin-form > header,
#plan-checkin-form > .span { grid-column: 1 / -1; }
.plan-calendar { display: flex; flex-direction: column; gap: 18px; }
.plan-cal-title { margin: 0 0 8px; font-size: 15px; font-weight: 800; }
.plan-cal-grid { display: grid; grid-template-columns: repeat(7, minmax(0, 1fr)); gap: 6px; }
.plan-cal-dow { text-align: center; font-size: 12px; font-weight: 700; color: var(--secondary); padding-bottom: 2px; }
.plan-cal-day {
  min-height: 62px; border-radius: 12px; background: var(--fill);
  padding: 6px 2px 4px; display: flex; flex-direction: column; align-items: center; gap: 2px;
}
.plan-cal-day.is-pad,
.plan-cal-day.is-out { background: transparent; }
.plan-cal-day.is-out .plan-cal-num { color: #c7c7cc; }
.plan-cal-day.is-hit { background: var(--green-soft); }
.plan-cal-num { font-size: 13px; font-weight: 800; line-height: 1.2; }
.plan-cal-value { font-size: 11px; font-weight: 700; color: var(--ink); line-height: 1.2; }
.plan-cal-check { color: var(--green); font-style: normal; font-weight: 800; font-size: 13px; line-height: 1; }
.plan-checkin-chart { height: 280px; width: 100%; }
#plan-checkin-chart[hidden] { display: none !important; }
.confirm-copy { margin: 4px 0 0; font-size: 16px; line-height: 1.55; color: var(--ink); }
button.primary.danger { background: var(--red); }
#trend-range .chip[hidden] { display: none !important; }
.page-actions { display: flex; justify-content: flex-end; margin-bottom: 12px; }
@media (max-width: 560px) {
  .page-actions .primary { width: 100%; }
}
.mono {
  margin-top: 8px; background: var(--fill); border-radius: 12px; padding: 10px 12px;
  font-family: ui-monospace, "SF Mono", monospace; font-size: 12px; word-break: break-all; white-space: pre-wrap;
}
.webhook-copy-fields { display: grid; gap: 12px; margin-top: 10px; }
.webhook-copy-fields input.mono { margin-top: 0; }
.bearer-field {
  display: flex; align-items: center; gap: 8px; width: 100%;
  border: 1px solid var(--border, var(--hairline, #e5e5ea)); border-radius: 14px; background: var(--fill);
  padding: 0 12px; min-height: 44px;
}
.bearer-prefix {
  flex: none; font-family: ui-monospace, "SF Mono", monospace; font-size: 13px; font-weight: 600; color: var(--tertiary);
}
.bearer-field input {
  flex: 1; min-width: 0; border: 0; background: transparent; padding: 10px 0; min-height: 42px; margin-top: 0;
  font-family: ui-monospace, "SF Mono", monospace; font-size: 13px;
}
.bearer-field input:focus { outline: none; box-shadow: none; }

.history-batch-bar {
  display: flex;
  flex-direction: column;
  gap: 10px;
  margin: 0 0 12px;
  padding: 14px;
  border-radius: 16px;
  background: var(--fill);
}
.history-batch-bar[hidden] {
  display: none !important;
}

.history-unmatched-tools {
  display: flex;
  flex-wrap: wrap;
  align-items: flex-end;
  gap: 10px 12px;
  margin: 0 0 12px;
  padding: 12px 14px;
  border-radius: 16px;
  background: var(--fill);
}
.history-unmatched-tools[hidden] {
  display: none !important;
}
.history-weight-field { flex: 1; min-width: 120px; margin: 0; }
.history-unmatched-actions { flex: 1 1 100%; margin: 0; flex-wrap: wrap; }
.history-batch-bar .toolbar { margin: 0; }

#history-assign-form.form-grid.plain {
  padding: 8px 22px calc(22px + env(safe-area-inset-bottom, 0px));
  gap: 14px;
}
#history-assign-form > .grabber,
#history-assign-form > header { grid-column: 1 / -1; }
.cell-pick { display: flex; align-items: stretch; gap: 10px; width: 100%; }
.cell-pick input[type="checkbox"] {
  width: 22px;
  height: 22px;
  margin: auto 0;
  flex: none;
  accent-color: var(--ink);
}
.cell-pick .cell-main { flex: 1; }

.history-pager {
  display: flex;
  flex-wrap: wrap;
  align-items: flex-end;
  gap: 12px;
  margin-top: 14px;
  padding: 0 2px 8px;
}
.history-pager .field { flex: none; min-width: 120px; margin: 0; }
.history-pager #history-page-meta { flex: 1; margin: 0; min-width: 140px; }
.history-page-actions { flex: none; margin: 0; }

.cell.is-disabled .cell-main strong,
.cell.is-disabled .muted { opacity: 0.55; }

.toast {
  position: fixed; left: 50%; z-index: 60; transform: translateX(-50%);
  top: calc(var(--safe-t) + 12px);
  max-width: min(420px, calc(100% - 32px));
  background: var(--ink); color: #fff; border-radius: 999px;
  padding: 10px 16px; font-size: 14px; font-weight: 600; text-align: center;
}
.toast.bad { background: #c0363a; }
.toast[hidden] { display: none; }

@media (max-width: 700px) {
  .cell { flex-wrap: wrap; align-items: flex-start; }
  .cell-main { flex: 1 1 calc(100% - 60px); }
  .cell-actions { flex: 1 1 100%; justify-content: flex-end; }
  .cell-actions .text-btn { flex: none; }
  .muted, .cell-sub { overflow-wrap: anywhere; }
}

@media (max-width: 959px) {
  .shell, .main { width: 100%; max-width: 100%; }
  .workspace { padding: 0 16px calc(var(--tab) + var(--safe-b) + 24px); }
  .topbar {
    position: sticky; top: 0; z-index: 20;
    flex-wrap: wrap; align-items: flex-start; gap: 8px;
    margin: 0 -16px; padding: calc(8px + var(--safe-t)) 16px 10px;
    background: rgba(242, 243, 245, 0.92);
    backdrop-filter: blur(18px) saturate(1.4);
  }
  .topbar-title { flex: 1 1 auto; min-width: 0; }
  .topbar-side {
    flex: 1 1 100%;
    display: flex; flex-wrap: wrap; align-items: center; justify-content: flex-end;
    gap: 6px;
  }
  .product { display: none; }
  #whoami {
    max-width: 46vw;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
  }
  #conn-pill { max-width: min(54vw, 12.5rem); flex-shrink: 1; }
  .filters { flex-direction: column; align-items: stretch; }
  .filters .field { width: 100%; }
  .filters .ghost { width: 100%; min-height: 44px; }
  .inline-row { flex-direction: column; align-items: stretch; }
  .inline-row select, .inline-row input { max-width: none; width: 100%; min-height: 44px; }
  .footnote { margin-bottom: 4px; }
}

@media (max-width: 560px) {
  h1 { font-size: 24px; }
  .portrait { padding: 22px 18px 18px; border-radius: 24px; }
  .story-card { padding: 18px 16px 16px; border-radius: 24px; }
  .story-heading { font-size: 20px; }
  .home-ai-advice #home-ai-text { font-size: 16px; line-height: 1.6; overflow-wrap: anywhere; }
  .story-layout { grid-template-columns: 1fr; }
  .body-stack { width: 100%; height: 18px; flex-direction: row; border-radius: 99px; }
  .legend { display: grid; grid-template-columns: 1fr 1fr; padding: 0 4px; }
  .mini-stats { grid-template-columns: 1fr 1fr; }
  .activity-totals { grid-template-columns: 1fr; }
  .activity-totals b { font-size: 32px; }
  .activity-day-head .activity-totals { grid-template-columns: repeat(3, 1fr); }
  .activity-day-head .activity-totals b { font-size: 18px; }
  .trend-panel-chart { height: 156px; }
  .scale-bind-row { flex-direction: column; align-items: stretch; }
  .scale-bind-actions { flex-direction: row; width: 100%; }
  .scale-bind-actions .primary.slim { flex: 1; min-width: 0; }
  .tabbar { grid-template-columns: repeat(7, minmax(0, 1fr)); padding-inline: 4px; }
  .tabbar button { font-size: 9px; min-height: 46px; gap: 1px; line-height: 1.2; }
  .tabbar.nav svg { width: 20px; height: 20px; }
  dialog {
    width: 100%; max-width: 100%; max-height: 92dvh;
    margin: auto 0 0; border-radius: 20px 20px 0 0;
  }
}

@media (max-width: 380px) {
  #whoami { display: none; }
  .tabbar button { font-size: 8px; }
}

@media (min-width: 700px) {
  .form-grid { grid-template-columns: 1fr 1fr; }
  .grabber { display: none; }
}

@media (min-width: 960px) {
  .sidebar {
    display: flex; flex-direction: column; width: 232px; flex: none;
    position: sticky; top: 0; align-self: flex-start; height: 100dvh;
    padding: 24px 16px 20px; background: #fff;
    box-shadow: 8px 0 32px rgba(28, 28, 30, 0.04);
  }
  .tabbar { display: none; }
  .product { display: none; }
  .workspace { padding: 22px 32px 48px; }
  .topbar { padding-top: 6px; }
  h1 { font-size: 32px; }
  .toast { top: 24px; }
  .measure-grid {
    display: grid; grid-template-columns: minmax(0, 1.05fr) minmax(320px, 0.95fr);
    gap: 16px; align-items: start;
  }
  .portrait {
    grid-column: 1; grid-row: 1;
    display: flex; flex-direction: column; box-sizing: border-box;
  }
  .portrait .hero-actions { margin-top: auto; }
  #compose-card { grid-column: 2; grid-row: 1; align-self: start; }
  .story-ranges, .household, .home-plan, .home-ai-advice, #ble-error { grid-column: 1 / -1; }
  .trend-panel-chart { height: 200px; }
  .mini-stats { grid-template-columns: repeat(4, 1fr); }
}

@media (hover: hover) {
  .side-nav button:hover { background: var(--fill); color: var(--ink); }
  .tabbar button:hover { color: var(--ink); }
  button.primary:hover { background: #000; }
  .portrait button.primary:hover { background: #f2f2f7; }
  button.ghost:hover, .text-btn:hover, .chip:hover { filter: brightness(0.97); }
}

@media (prefers-reduced-motion: reduce) {
  * { transition: none !important; scroll-behavior: auto !important; }
}
