:root {
  --bg: #edf2ef;
  --ink: #111816;
  --muted: #61706a;
  --line: #d9e2dd;
  --panel: #fcfffd;
  --panel-2: #f6faf7;
  --green: #0b7a5b;
  --green-soft: #c8f5de;
  --blue: #2868d8;
  --blue-soft: #d9e7ff;
  --amber: #f0a500;
  --amber-soft: #fff0c2;
  --red: #d64331;
  --red-soft: #ffd9d4;
  --violet: #7252c7;
  --shadow: 0 18px 46px rgba(29, 44, 38, .10);
  --radius: 8px;
}

* {
  box-sizing: border-box;
}

html {
  overflow-x: hidden;
}

body {
  margin: 0;
  color: var(--ink);
  background:
    linear-gradient(140deg, rgba(11, 122, 91, .12), transparent 34%),
    linear-gradient(320deg, rgba(40, 104, 216, .11), transparent 30%),
    radial-gradient(circle at 82% 8%, rgba(240, 165, 0, .18), transparent 22%),
    var(--bg);
  font-family: "Aptos", "Segoe UI", system-ui, sans-serif;
  overflow-x: hidden;
}

.shell {
  width: min(1500px, calc(100% - 32px));
  margin: 0 auto;
  padding: 22px 0 48px;
}

.topbar,
.hero,
.panel,
.metric-card,
.live-card {
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: rgba(252, 255, 253, .94);
  box-shadow: var(--shadow);
}

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  padding: 18px 20px;
}

.top-actions {
  display: flex;
  align-items: center;
  gap: 10px;
  flex-wrap: wrap;
}

.eyebrow {
  margin: 0 0 5px;
  color: var(--green);
  font-size: 12px;
  font-weight: 900;
  letter-spacing: .08em;
  text-transform: uppercase;
}

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

h1 {
  font-size: clamp(30px, 3.5vw, 50px);
  line-height: .95;
}

h2 {
  max-width: 760px;
  font-size: clamp(30px, 3.6vw, 50px);
  line-height: 1.04;
  letter-spacing: 0;
}

h3 {
  font-size: 20px;
}

h4 {
  font-size: 15px;
}

.status-pill,
button {
  min-height: 38px;
  border: 1px solid #17221e;
  border-radius: 999px;
  background: #e9ff74;
  color: var(--ink);
  padding: 9px 14px;
  font-weight: 900;
}

button {
  cursor: pointer;
}

button:disabled {
  cursor: not-allowed;
  border-color: #d5ded8;
  background: #eef4f0;
  color: #82908a;
}

#refreshBtn {
  border-color: var(--line);
  background: #fff;
}

.sync-device {
  min-height: 34px;
  padding: 7px 10px;
  border-color: rgba(11, 122, 91, .35);
  background: var(--green-soft);
  font-size: 12px;
}

.hero {
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(300px, 420px);
  gap: 20px;
  align-items: stretch;
  margin-top: 16px;
  padding: 22px;
}

.hero-copy p:not(.eyebrow) {
  max-width: 780px;
  margin-top: 16px;
  color: var(--muted);
  font-size: 18px;
  line-height: 1.45;
}

.live-card {
  display: flex;
  align-items: center;
  gap: 16px;
  min-height: 138px;
  padding: 22px;
  background:
    linear-gradient(155deg, rgba(11, 122, 91, .10), transparent 58%),
    var(--panel);
}

.live-card strong {
  display: block;
  font-size: 22px;
}

.live-card p {
  margin-top: 8px;
  color: var(--muted);
  overflow-wrap: anywhere;
}

.live-card small {
  display: block;
  margin-top: 8px;
  color: var(--muted);
  line-height: 1.35;
}

.live-dot {
  width: 64px;
  height: 64px;
  flex: 0 0 auto;
  border-radius: 999px;
  background: radial-gradient(circle, #8effc1 0 32%, var(--green) 34% 62%, transparent 64%);
  box-shadow: 0 0 0 10px rgba(11, 122, 91, .08);
}

.sync-panel {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 12px;
  margin-top: 12px;
}

.sync-card {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 18px;
  min-height: 150px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: rgba(252, 255, 253, .96);
  box-shadow: var(--shadow);
  padding: 18px;
}

.sync-card > div > span,
.status-grid span {
  color: var(--muted);
  font-size: 12px;
  font-weight: 900;
  letter-spacing: .04em;
  text-transform: uppercase;
}

.sync-card strong {
  display: block;
  margin-top: 7px;
  font-size: clamp(21px, 2vw, 30px);
  line-height: 1.05;
}

.sync-card p b,
.sync-card p .sync-state {
  display: inline;
  margin: 0;
  font-size: inherit;
  line-height: inherit;
}

.sync-state {
  font-weight: 900;
}

.sync-card p {
  max-width: 520px;
  margin-top: 8px;
  color: var(--muted);
  line-height: 1.38;
}

.sync-card button {
  min-width: 230px;
  border-color: var(--green);
  background: var(--green);
  color: #fff;
  box-shadow: 0 12px 24px rgba(11, 122, 91, .18);
}

.tracker-sync button {
  border-color: var(--blue);
  background: var(--blue);
  box-shadow: 0 12px 24px rgba(40, 104, 216, .18);
}

.sync-card button:disabled {
  border-color: #d5ded8;
  background: #eef4f0;
  color: #82908a;
  box-shadow: none;
}

.metrics-grid {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 12px;
  margin-top: 12px;
}

.metric-card {
  min-height: 142px;
  padding: 16px;
}

.metric-card.primary {
  background:
    linear-gradient(135deg, rgba(200, 245, 222, .70), transparent 60%),
    var(--panel);
}

.metric-card span,
.profile-form label {
  color: var(--muted);
  font-size: 12px;
  font-weight: 900;
  text-transform: uppercase;
}

.metric-card strong {
  display: block;
  margin-top: 13px;
  font-size: clamp(28px, 3vw, 42px);
  line-height: 1;
}

.metric-card small {
  display: block;
  margin-top: 10px;
  color: var(--muted);
  line-height: 1.35;
}

.bar {
  height: 9px;
  overflow: hidden;
  margin-top: 15px;
  border-radius: 999px;
  background: #e4ece7;
}

.bar i {
  display: block;
  width: 0;
  height: 100%;
  border-radius: inherit;
  background: var(--green);
  transition: width .25s ease;
}

.bar.blue i {
  background: var(--blue);
}

.dashboard-grid,
.content-grid,
.profile-row {
  display: grid;
  grid-template-columns: minmax(0, 1.15fr) minmax(340px, .85fr);
  gap: 12px;
  margin-top: 12px;
}

.content-grid {
  grid-template-columns: minmax(0, 1.55fr) minmax(320px, .7fr);
}

.profile-row {
  grid-template-columns: minmax(0, 1fr);
}

.panel {
  padding: 18px;
}

.status-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 10px;
}

.status-grid div {
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--panel-2);
  padding: 14px;
}

.status-grid strong {
  display: block;
  margin-top: 8px;
  font-size: 34px;
}

.panel-head {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 14px;
  margin-bottom: 14px;
}

.panel-head p {
  margin-top: 3px;
  color: var(--muted);
  font-size: 14px;
}

.recommendations {
  display: grid;
  gap: 10px;
}

.advice {
  display: grid;
  grid-template-columns: 34px minmax(0, 1fr);
  gap: 12px;
  align-items: start;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--panel-2);
  padding: 12px;
}

.advice span {
  display: grid;
  place-items: center;
  width: 34px;
  height: 34px;
  border-radius: 999px;
  background: var(--green);
  color: #fff;
  font-weight: 900;
}

.advice p {
  line-height: 1.45;
}

.profile-form {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 10px;
}

.profile-form input,
.profile-form select {
  width: 100%;
  min-height: 42px;
  margin-top: 6px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: #fff;
  color: var(--ink);
  padding: 8px 10px;
  font: inherit;
}

.profile-form select {
  appearance: none;
  background:
    linear-gradient(45deg, transparent 50%, var(--green) 50%) right 14px center / 8px 8px no-repeat,
    #fff;
}

.profile-form button {
  grid-column: 1 / -1;
}

.body-panel {
  margin-top: 12px;
}

.body-grid {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 10px;
}

.body-grid article {
  min-height: 112px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background:
    linear-gradient(155deg, rgba(40, 104, 216, .08), transparent 60%),
    #fff;
  padding: 14px;
}

.body-grid span {
  display: block;
  color: var(--muted);
  font-size: 12px;
  font-weight: 900;
  letter-spacing: .04em;
  text-transform: uppercase;
}

.body-grid strong {
  display: block;
  margin-top: 8px;
  font-size: clamp(24px, 3vw, 34px);
  line-height: 1;
}

.body-grid small {
  display: block;
  margin-top: 9px;
  color: var(--muted);
}

.status-chip {
  align-self: start;
  min-height: 30px;
  border: 1px solid var(--line);
  border-radius: 999px;
  padding: 6px 10px;
  background: var(--amber-soft);
  color: #725100;
  font-size: 12px;
  font-weight: 900;
  white-space: nowrap;
}

.status-chip.ready {
  border-color: rgba(11, 122, 91, .35);
  background: var(--green-soft);
  color: var(--green);
}

.chart {
  min-height: 280px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background:
    linear-gradient(180deg, #fff, #f7fbf8);
  padding: 10px;
  overflow-x: auto;
}

.chart svg {
  width: 100%;
  min-width: 720px;
  height: 260px;
  display: block;
}

.chart .axis {
  stroke: #d5ded8;
  stroke-width: 1;
}

.chart .weight-line {
  fill: none;
  stroke: var(--green);
  stroke-width: 4;
  stroke-linecap: round;
  stroke-linejoin: round;
}

.chart .steps-bar {
  fill: rgba(40, 104, 216, .22);
}

.chart text {
  fill: var(--muted);
  font-size: 11px;
  font-weight: 800;
}

.workout-list {
  margin-top: 10px;
}

.history-table-wrap {
  margin-top: 12px;
  overflow-x: auto;
}

.history-table {
  width: 100%;
  border-collapse: collapse;
  min-width: 680px;
}

.history-table th,
.history-table td {
  border-bottom: 1px solid var(--line);
  padding: 10px 12px;
  text-align: left;
  vertical-align: top;
}

.history-table th {
  color: var(--muted);
  font-size: 12px;
  text-transform: uppercase;
}

.history-table td {
  font-weight: 800;
}

.device-cards,
.measurement-list,
.event-list,
.gatt-list {
  display: grid;
  gap: 8px;
}

.device-card,
.measurement-item,
.event-item,
.gatt-card {
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: #fff;
  padding: 12px;
}

.device-card {
  display: flex;
  justify-content: space-between;
  gap: 10px;
}

.compact-card {
  align-items: center;
  min-height: 0;
  padding: 9px 10px;
}

.device-card > div:first-child {
  min-width: 0;
}

.device-compact {
  display: grid;
  gap: 3px;
  min-width: 0;
}

.device-compact h4,
.device-compact p {
  margin: 0;
}

.device-compact strong,
.device-compact h4 {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.device-compact span,
.device-compact small,
.compact-time {
  display: block;
  min-width: 0;
  color: var(--muted);
  font-size: 12px;
  overflow-wrap: anywhere;
}

.device-card p,
.device-card small,
.measurement-item small {
  color: var(--muted);
  overflow-wrap: anywhere;
}

.connection-side {
  display: flex;
  flex: 0 0 auto;
  align-items: center;
  justify-content: flex-end;
  gap: 8px;
  text-align: right;
}

.connection-side small {
  max-width: 170px;
}

.compact-row td {
  padding-top: 7px;
  padding-bottom: 7px;
  vertical-align: middle;
}

.action-cell {
  width: 42px;
  text-align: right;
}

.action-cell .icon-action {
  margin-left: auto;
}

.compact-row code,
.compact-card code {
  padding: 2px 5px;
  font-size: 11px;
}

.signal-pill {
  display: inline-flex;
  align-items: center;
  border: 1px solid rgba(40, 104, 216, .28);
  border-radius: 999px;
  background: var(--blue-soft);
  color: #173d82;
  padding: 4px 7px;
  font-size: 11px;
  font-weight: 900;
  white-space: nowrap;
}

.icon-action {
  display: inline-grid;
  place-items: center;
  width: 30px;
  min-width: 30px;
  height: 30px;
  min-height: 30px;
  border-radius: 999px;
  padding: 0;
}

.icon-action svg {
  width: 15px;
  height: 15px;
  fill: none;
  stroke: currentColor;
  stroke-width: 2;
  stroke-linecap: round;
  stroke-linejoin: round;
}

.icon-action.danger {
  border-color: rgba(214, 67, 49, .35);
  background: var(--red-soft);
  color: var(--red);
}

/* Legacy dense list fallbacks. */
.connection-side.legacy {
  align-items: flex-end;
  flex-direction: column;
  text-align: right;
}

.measurement-item {
  display: flex;
  justify-content: space-between;
  gap: 12px;
}

.measurement-item span {
  display: block;
  margin-top: 4px;
  font-size: 24px;
  font-weight: 900;
}

.table-wrap {
  overflow-x: auto;
}

.debug-block {
  margin-top: 12px;
}

.debug-block > summary {
  cursor: pointer;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: rgba(252, 255, 253, .94);
  box-shadow: var(--shadow);
  padding: 14px 18px;
  color: var(--muted);
  font-weight: 900;
}

.debug-block[open] > summary {
  border-bottom-color: transparent;
}

table {
  width: 100%;
  min-width: 720px;
  border-collapse: collapse;
}

th,
td {
  border-bottom: 1px solid var(--line);
  padding: 9px 8px;
  text-align: left;
  vertical-align: top;
  font-size: 14px;
}

th {
  color: var(--muted);
  font-size: 12px;
  text-transform: uppercase;
}

code {
  display: inline-block;
  max-width: 210px;
  overflow-wrap: anywhere;
  border: 1px solid #d6ded9;
  border-radius: 7px;
  background: #111816;
  color: #dfffe9;
  padding: 6px 8px;
  font-family: "Cascadia Code", "JetBrains Mono", monospace;
  font-size: 12px;
}

.tag,
.connection {
  display: inline-flex;
  align-items: center;
  border: 1px solid var(--line);
  border-radius: 999px;
  padding: 5px 8px;
  background: #fff;
  font-size: 12px;
  font-weight: 900;
  white-space: nowrap;
}

.tag.band {
  border-color: rgba(40, 104, 216, .34);
  color: var(--blue);
  background: var(--blue-soft);
}

.tag.scale {
  border-color: rgba(11, 122, 91, .34);
  color: var(--green);
  background: var(--green-soft);
}

.tag.xiaomi {
  border-color: rgba(114, 82, 199, .30);
  color: var(--violet);
  background: #eee8ff;
}

.connection.on {
  border-color: rgba(11, 122, 91, .34);
  color: var(--green);
  background: var(--green-soft);
}

.connection.warn {
  border-color: rgba(240, 165, 0, .42);
  color: #7a5200;
  background: var(--amber-soft);
}

.connection.bad {
  border-color: rgba(214, 67, 49, .38);
  color: var(--red);
  background: var(--red-soft);
}

.connection.off {
  color: var(--muted);
  background: #f2f5f3;
}

.muted {
  color: var(--muted);
}

.event-item strong,
.measurement-item strong {
  display: block;
  margin-bottom: 4px;
}

.gatt-service {
  margin-top: 10px;
  border-top: 1px solid var(--line);
  padding-top: 10px;
}

.chars {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(260px, 1fr));
  gap: 8px;
  margin-top: 8px;
}

.char {
  border: 1px solid #e3ebe6;
  border-radius: var(--radius);
  background: #f9fcfa;
  padding: 10px;
}

.char small {
  display: block;
  color: var(--muted);
  overflow-wrap: anywhere;
}

@media (max-width: 1050px) {
  .metrics-grid,
  .body-grid {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  .hero,
  .sync-panel,
  .dashboard-grid,
  .content-grid {
    grid-template-columns: 1fr;
  }
}

@media (max-width: 720px) {
  .shell {
    width: min(100% - 20px, 1500px);
    padding-top: 10px;
  }

  .topbar,
  .panel-head,
  .sync-card,
  .device-card,
  .measurement-item {
    align-items: flex-start;
    flex-direction: column;
  }

  .connection-side {
    width: 100%;
    flex: 0 0 auto;
    align-items: center;
    justify-content: space-between;
    text-align: left;
  }

  .top-actions {
    width: 100%;
  }

  .status-pill,
  button,
  .sync-card button {
    width: 100%;
    text-align: center;
  }

  .icon-action {
    width: 30px;
    min-width: 30px;
  }

  .hero {
    padding: 20px;
  }

  .metrics-grid,
  .body-grid,
  .profile-form {
    grid-template-columns: 1fr;
  }
}
