:root {
  color-scheme: dark;
  --bg: #08100d;
  --bg-accent: #0f1d18;
  --bg-glow: rgba(91, 181, 140, 0.12);
  --panel: rgba(13, 22, 18, 0.78);
  --panel-strong: rgba(16, 26, 21, 0.92);
  --text: #edf4ef;
  --muted: #9ab0a3;
  --line: rgba(238, 244, 239, 0.08);
  --shadow: 0 24px 60px rgba(0, 0, 0, 0.42);
  --accent: #5ac48c;
  --accent-2: #7fa8ff;
  --warn: #e7b067;
  --bad: #f08e8e;
  --radius: 24px;
}

* {
  box-sizing: border-box;
}

html,
body {
  min-height: 100%;
}

body {
  margin: 0;
  color: var(--text);
  font-family: "Segoe UI Variable", "Avenir Next", "Helvetica Neue", Arial, sans-serif;
  background:
    radial-gradient(circle at top left, var(--bg-glow), transparent 30%),
    radial-gradient(circle at top right, rgba(127, 168, 255, 0.11), transparent 28%),
    linear-gradient(180deg, var(--bg), var(--bg-accent));
}

button,
input {
  font: inherit;
}

.shell {
  width: min(1120px, calc(100vw - 32px));
  margin: 0 auto;
  padding: 18px 0 28px;
}

.auth-shell {
  width: min(560px, calc(100vw - 32px));
  margin: 64px auto 24px;
  padding: 26px 24px;
  display: grid;
  gap: 22px;
  background:
    linear-gradient(180deg, rgba(255, 255, 255, 0.05), transparent 70%),
    var(--panel-strong);
}

.auth-copy {
  display: grid;
  gap: 10px;
}

.auth-kicker {
  margin: 0;
  color: var(--accent-2);
  font-size: 0.8rem;
  font-weight: 800;
  letter-spacing: 0.12em;
  text-transform: uppercase;
}

.auth-shell h1 {
  margin: 0;
  font-size: 2rem;
  line-height: 1;
  letter-spacing: 0;
}

.auth-lede {
  margin: 0;
  color: var(--muted);
  line-height: 1.5;
  max-width: 40ch;
}

.auth-form {
  display: grid;
  gap: 14px;
}

.auth-field {
  display: grid;
  gap: 8px;
  color: var(--muted);
  font-size: 0.92rem;
  font-weight: 700;
}

.auth-field input {
  width: 100%;
  min-height: 52px;
  border-radius: 14px;
  border: 1px solid rgba(238, 244, 239, 0.12);
  background: rgba(4, 9, 7, 0.68);
  color: var(--text);
  padding: 12px 14px;
  outline: none;
  box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.04);
}

.auth-field input:focus {
  border-color: rgba(90, 196, 140, 0.5);
  box-shadow:
    0 0 0 3px rgba(90, 196, 140, 0.16),
    inset 0 1px 0 rgba(255, 255, 255, 0.04);
}

.auth-button {
  width: 100%;
  min-height: 52px;
  font-size: 1rem;
}

.auth-error {
  margin: 0;
}

body.locked #dashboard-shell {
  display: none;
}

body.authenticated #login-panel {
  display: none;
}

.card {
  background: var(--panel);
  border: 1px solid var(--line);
  box-shadow: var(--shadow);
  backdrop-filter: blur(18px);
  border-radius: var(--radius);
}

.hero {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  align-items: stretch;
  gap: 14px;
  padding: 14px 20px;
  margin-bottom: 18px;
  background:
    linear-gradient(180deg, rgba(255, 255, 255, 0.03), transparent 72%),
    var(--panel-strong);
}

.hero-body {
  flex: 1 1 auto;
  min-width: 0;
  display: flex;
  align-items: center;
}

.hero-row {
  display: flex;
  align-items: center;
  gap: 10px;
  min-width: 0;
  flex-wrap: wrap;
}

.hero-top {
  display: grid;
  grid-template-columns: auto minmax(0, 1fr);
  grid-template-rows: auto auto;
  column-gap: 10px;
  row-gap: 4px;
  align-items: center;
  flex-wrap: initial;
  width: 100%;
}

.hero-meta {
  display: flex;
  align-items: center;
  gap: 10px;
  color: var(--muted);
  font-size: 0.9rem;
  justify-content: flex-start;
  grid-column: 2;
  grid-row: 2;
}

.hero #power-button {
  align-self: center;
  justify-self: end;
  width: 105px;
  height: 72px;
  display: flex;
  align-items: center;
  justify-content: center;
  text-align: center;
  padding: 8px;
  line-height: 1.02;
  border-radius: 16px;
  font-size: 0.9rem;
  font-weight: 800;
  letter-spacing: 0.01em;
}

.bpm-status-badge {
  grid-row: 1 / span 2;
  align-self: stretch;
  justify-self: center;
}

.hero-status-text {
  color: var(--muted);
  font-size: 1.35rem;
  font-weight: 800;
  letter-spacing: 0.02em;
  text-transform: uppercase;
  line-height: 1;
  min-width: 0;
  white-space: nowrap;
  grid-column: 2;
  grid-row: 1;
}

.hero-status-text-awake {
  color: #7fe0a8;
}

.hero-status-text-sleeping {
  color: #9ac8ff;
}

.hero-status-text-charging {
  color: #f3c46b;
}

.hero-status-text-charged {
  color: #7fe0a8;
}

.hero-connection {
  font-size: 0.9rem;
  font-weight: 800;
  letter-spacing: 0.02em;
  line-height: 1.1;
}

.hero-connection-online {
  color: #7fe0a8;
}

.hero-connection-live {
  color: #c0cbd6;
}

.hero-connection-stale {
  color: #f08e8e;
}

.hero-separator {
  color: rgba(237, 244, 239, 0.3);
  font-size: 0.9rem;
  font-weight: 600;
  line-height: 1;
  user-select: none;
}

.hero-top .subtle {
  margin-left: auto;
}

.status-summary {
  color: var(--muted);
  font-size: 0.9rem;
  font-weight: 600;
  line-height: 1.35;
  opacity: 0.96;
}

.button {
  border: 0;
  border-radius: 14px;
  padding: 12px 18px;
  cursor: pointer;
  transition:
    transform 160ms ease,
    opacity 160ms ease,
    background-color 160ms ease,
    box-shadow 160ms ease;
}

.button:hover:not(:disabled) {
  transform: translateY(-1px);
}

.button:disabled {
  cursor: not-allowed;
  opacity: 0.62;
}

.button-primary {
  color: #c6f6dd;
  background: rgba(90, 196, 140, 0.14);
  border: 1px solid rgba(90, 196, 140, 0.22);
  box-shadow: none;
}

.button-off {
  color: var(--muted);
  background: rgba(255, 255, 255, 0.03);
  border: 1px solid rgba(238, 244, 239, 0.08);
  box-shadow: none;
}

.button-secondary {
  color: var(--text);
  background: rgba(255, 255, 255, 0.06);
  border: 1px solid rgba(238, 244, 239, 0.1);
}

.chip {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  min-height: 32px;
  padding: 0 12px;
  border-radius: 12px;
  border: 1px solid transparent;
  font-size: 0.84rem;
  font-weight: 600;
  letter-spacing: 0.01em;
  line-height: 1.15;
  flex-wrap: wrap;
}

.chip-label {
  color: inherit;
}

.chip-secondary {
  color: rgba(237, 244, 239, 0.58);
  font-size: 0.78rem;
  font-weight: 500;
  letter-spacing: 0;
}

.chip-neutral {
  color: var(--muted);
  background: rgba(255, 255, 255, 0.04);
  border-color: var(--line);
}

.chip-good {
  color: #c6f6dd;
  background: rgba(90, 196, 140, 0.14);
  border-color: rgba(90, 196, 140, 0.22);
}

.chip-warn {
  color: #ffe0aa;
  background: rgba(231, 176, 103, 0.14);
  border-color: rgba(231, 176, 103, 0.22);
}

.chip-bad {
  color: #ffd0d0;
  background: rgba(240, 142, 142, 0.13);
  border-color: rgba(240, 142, 142, 0.2);
}

.subtle {
  color: var(--muted);
  font-size: 0.85rem;
  text-align: right;
}

.dashboard {
  display: grid;
  gap: 14px;
}

.dashboard {
  grid-template-columns: 1fr;
  margin-bottom: 14px;
}

.metrics-card {
  position: relative;
  padding: 18px;
  min-width: 0;
  display: flex;
  flex-direction: column;
  gap: 0;
  min-height: 440px;
  background:
    radial-gradient(circle at top left, rgba(90, 196, 140, 0.09), transparent 34%),
    radial-gradient(circle at top right, rgba(127, 168, 255, 0.07), transparent 30%),
    rgba(13, 22, 18, 0.8);
}

.metrics-header {
  display: flex;
  align-items: center;
  justify-content: flex-start;
  gap: 12px;
  min-height: 0;
  margin-bottom: 10px;
}

.metric-stack {
  position: relative;
  display: flex;
  flex-direction: column;
  overflow: hidden;
  border-radius: 18px;
  border: 1px solid rgba(238, 244, 239, 0.06);
  background:
    linear-gradient(rgba(255, 255, 255, 0.03), rgba(255, 255, 255, 0.01)),
    radial-gradient(circle at 0 0, rgba(255, 255, 255, 0.04) 0, transparent 55%),
    linear-gradient(180deg, rgba(255, 255, 255, 0.01), rgba(255, 255, 255, 0));
}

.bpm-status-badge {
  display: inline-flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 3px;
  width: 6rem;
  min-width: 6rem;
  user-select: none;
  filter: drop-shadow(0 8px 18px rgba(0, 0, 0, 0.28));
  text-align: center;
}

.bpm-status-emoji {
  display: block;
  font-size: 4.8rem;
  line-height: 1;
}

.bpm-status-text {
  display: block;
  font-size: 1.02rem;
  line-height: 1;
  font-weight: 700;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  white-space: nowrap;
}

.bpm-status-badge-charging,
.bpm-status-badge-charged {
  flex-direction: row;
  justify-content: flex-start;
  gap: 8px;
  width: auto;
  min-width: 0;
  text-align: left;
}

.bpm-status-badge-awake {
  color: #7fe0a8;
  text-shadow: 0 0 18px rgba(127, 224, 168, 0.22);
}

.bpm-status-badge-awake .bpm-status-text {
  color: #7fe0a8;
}

.bpm-status-badge-sleeping {
  color: #9ac8ff;
  text-shadow: 0 0 18px rgba(154, 200, 255, 0.2);
}

.bpm-status-badge-sleeping .bpm-status-emoji {
  filter: hue-rotate(185deg) saturate(0.82) brightness(0.92);
  opacity: 0.88;
}

.bpm-status-badge-sleeping .bpm-status-text {
  color: #9ac8ff;
}

.bpm-status-badge-charging {
  color: #f3c46b;
  text-shadow: 0 0 18px rgba(243, 196, 107, 0.24);
}

.bpm-status-badge-charged {
  color: #7fe0a8;
  text-shadow: 0 0 18px rgba(127, 224, 168, 0.22);
}

.bpm-status-badge-charging .bpm-status-text,
.bpm-status-badge-charged .bpm-status-text {
  color: currentColor;
}

.metric-chart-wrap {
  position: relative;
  display: block;
  flex: 1 1 auto;
  height: 180px;
  border-radius: 0;
  padding: 8px 10px 4px;
  background:
    linear-gradient(rgba(255, 255, 255, 0.03), rgba(255, 255, 255, 0.01)),
    radial-gradient(circle at 0 0, rgba(255, 255, 255, 0.04) 0, transparent 55%),
    linear-gradient(180deg, rgba(255, 255, 255, 0.01), rgba(255, 255, 255, 0));
  border: 0;
  overflow: hidden;
}

.metric-stack > .metric-chart-wrap + .metric-chart-wrap {
  border-top: 1px solid rgba(238, 244, 239, 0.06);
}

.metric-chart-wrap canvas {
  display: block;
  width: 100% !important;
  height: 100% !important;
  position: relative;
  z-index: 0;
}

.metric-overlay {
  position: absolute;
  inset: 0;
  pointer-events: none;
  display: flex;
  z-index: 1;
}

.metric-overlay-top-right {
  align-items: flex-start;
  justify-content: flex-start;
  padding: 12px 0 0 104px;
}

.metric-overlay-bottom-right {
  align-items: flex-end;
  justify-content: flex-start;
  padding: 0 0 12px 104px;
}

.metric-readout-overlay {
  background: rgba(8, 16, 13, 0.28);
  border: 1px solid rgba(238, 244, 239, 0.08);
  border-radius: 14px;
  padding: 8px 10px;
  backdrop-filter: blur(8px);
  box-shadow: 0 8px 18px rgba(0, 0, 0, 0.18);
}

.metric-footer {
  display: flex;
  justify-content: flex-start;
  margin-top: 10px;
}

.metric-footer .metric-label {
  font-size: 0.88rem;
}

.metrics-actions {
  display: flex;
  justify-content: flex-end;
  margin-top: 12px;
}

.metrics-logout {
  padding: 9px 12px;
  border-radius: 12px;
  font-size: 0.86rem;
  font-weight: 700;
  color: var(--muted);
  background: rgba(255, 255, 255, 0.03);
}

.metrics-logout:hover:not(:disabled) {
  color: var(--text);
  border-color: rgba(238, 244, 239, 0.18);
}

.detail-card {
  padding: 0;
  min-width: 0;
}

.metric-label,
.metric-caption,
.detail-card h2 {
  color: var(--muted);
}

.metric-label {
  font-size: 0.85rem;
  font-weight: 600;
  letter-spacing: 0.08em;
  text-transform: uppercase;
}

.metric-readout {
  display: flex;
  align-items: baseline;
  gap: 12px;
  min-width: 0;
}

.metric-value {
  display: block;
  flex: 0 0 3ch;
  width: 3ch;
  text-align: right;
  font-variant-numeric: tabular-nums;
  font-size: clamp(1.5rem, 4vw, 2.0rem);
  line-height: 0.95;
  letter-spacing: 0;
  color: var(--text);
  transition: color 160ms ease, text-shadow 160ms ease;
}

.metric-value.metric-alert {
  color: #ff6d6d;
  text-shadow: 0 0 18px rgba(240, 142, 142, 0.28);
}

.metric-caption {
  margin-top: 0;
  font-size: 0.95rem;
  white-space: nowrap;
}

.detail-card h2 {
  margin: 0 0 14px;
  font-size: 0.92rem;
  text-transform: uppercase;
  letter-spacing: 0.12em;
}

.detail-card summary {
  display: flex;
  width: 100%;
  padding: 18px 18px 16px;
  list-style: none;
  cursor: pointer;
  color: var(--muted);
  font-size: 0.92rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.12em;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}

.detail-card summary::-webkit-details-marker {
  display: none;
}

.detail-card summary::after {
  content: "+";
  color: var(--text);
  font-size: 1rem;
  line-height: 1;
  opacity: 0.84;
}

.detail-card[open] summary::after {
  content: "–";
}

.detail-body {
  padding: 0 18px 16px;
}

.kv-list {
  margin: 0;
  display: grid;
  grid-template-columns: minmax(0, 0.92fr) minmax(0, 1.08fr);
  gap: 10px 12px;
}

.kv-list dt {
  color: var(--muted);
  font-size: 0.9rem;
  min-width: 0;
}

.kv-list dd {
  margin: 0;
  min-width: 0;
  overflow-wrap: anywhere;
  text-align: right;
  font-weight: 600;
}

.error-banner {
  margin: 14px 0 0;
  padding: 12px 14px;
  border-radius: 14px;
  color: #ffd0d0;
  background: rgba(240, 142, 142, 0.11);
  border: 1px solid rgba(240, 142, 142, 0.16);
}

.is-stale {
  opacity: 0.72;
}

@media (max-width: 840px) {
  .auth-shell {
    margin-top: 20px;
    padding: 22px 18px;
  }

  .shell {
    width: calc(100vw - 20px);
    padding-top: 10px;
  }

  .hero {
    padding: 14px 16px;
    gap: 12px;
  }

  .hero-top {
    column-gap: 10px;
    row-gap: 2px;
  }

  .hero-meta {
    gap: 8px;
  }

  .hero #power-button {
    border-radius: 14px;
  }

  .hero-top .subtle {
    margin-left: 0;
  }

  .hero-title {
    font-size: 1rem;
  }

  .bpm-status-badge {
    gap: 3px;
  }

  .bpm-status-emoji {
    font-size: 4.2rem;
  }

  .dashboard {
    grid-template-columns: 1fr;
  }

  .metrics-card {
    padding: 16px;
    min-height: 390px;
  }

  .metric-stack {
    border-radius: 16px;
  }

  .metric-chart-wrap {
    height: 154px;
  }

  .metric-overlay-top-right {
    padding-left: 72px;
  }

  .metric-overlay-bottom-right {
    padding-left: 72px;
  }

  .metrics-actions {
    margin-top: 10px;
  }

  .detail-card summary {
    padding: 16px;
  }

  .detail-body {
    padding: 0 16px 16px;
  }

  .kv-list {
    grid-template-columns: 1fr;
    gap: 8px;
  }

  .kv-list dd {
    text-align: left;
    margin-top: -4px;
    padding-bottom: 6px;
    border-bottom: 1px solid rgba(238, 244, 239, 0.08);
  }

  .kv-list dt:last-of-type,
  .kv-list dd:last-of-type {
    border-bottom: 0;
    padding-bottom: 0;
  }
}
