:root {
  --accent: #5e9fa4;
  --accent-light: #85bfc4;
  --accent-dark: #3d7f84;
  --accent-glow: rgba(94, 159, 164, .18);
  --bg: #09161a;
  --bg-secondary: #0e1e22;
  --bg-card: #112328;
  --text: #dff0f2;
  --text-secondary: #94c4c8;
  --text-muted: #5f8589;
  --border: rgba(133, 191, 196, .16);
  --border-strong: rgba(133, 191, 196, .34);
  --danger: #e46d6d;
  --ok: #74d4a4;
  --shadow-card: 0 24px 80px rgba(0, 0, 0, .28);
}

* { box-sizing: border-box; }
body {
  margin: 0;
  min-height: 100vh;
  font-family: "DM Sans", system-ui, sans-serif;
  color: var(--text);
  background:
    radial-gradient(ellipse at 20% 0%, rgba(94, 159, 164, .22), transparent 42%),
    linear-gradient(135deg, #09161a 0%, #0d1d20 48%, #071014 100%);
}
button, input { font: inherit; }
button { cursor: pointer; }

.shell {
  width: min(1180px, calc(100% - 32px));
  margin: 0 auto;
  min-height: 100vh;
  display: grid;
  align-items: center;
  padding: 28px 0;
}

.auth-view {
  display: grid;
  grid-template-columns: minmax(0, 1.2fr) minmax(330px, .8fr);
  gap: 42px;
  align-items: center;
}

.brand-panel h1, .topbar h1 {
  font-family: "Outfit", sans-serif;
  font-size: clamp(2.6rem, 6vw, 5.5rem);
  line-height: .94;
  letter-spacing: 0;
  margin: 0 0 18px;
}

.lead {
  max-width: 620px;
  color: var(--text-secondary);
  line-height: 1.8;
  font-size: 1.02rem;
}

.eyebrow {
  margin: 0 0 12px;
  color: var(--accent-light);
  text-transform: uppercase;
  letter-spacing: .18em;
  font: 700 .72rem "Outfit", sans-serif;
}

.signal-preview {
  margin-top: 48px;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: rgba(17, 35, 40, .64);
  overflow: hidden;
  box-shadow: var(--shadow-card);
}
.signal-preview svg {
  width: 100%;
  height: 220px;
}
.signal-preview path {
  fill: none;
  stroke: var(--accent-light);
  stroke-width: 5;
  filter: drop-shadow(0 0 18px rgba(94, 159, 164, .5));
}

.auth-card, .metric, .chart-panel, .measure-card {
  border: 1px solid var(--border);
  background: rgba(17, 35, 40, .82);
  box-shadow: var(--shadow-card);
  backdrop-filter: blur(18px);
  border-radius: 8px;
}
.auth-card { padding: 22px; }

.tabs {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 6px;
  padding: 4px;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--bg-secondary);
  margin-bottom: 20px;
}
.tab {
  min-height: 40px;
  border: 0;
  border-radius: 6px;
  background: transparent;
  color: var(--text-muted);
}
.tab.active {
  background: var(--accent);
  color: #fff;
}

.form { display: grid; gap: 14px; }
label {
  display: grid;
  gap: 7px;
  color: var(--text-secondary);
  font-size: .9rem;
}
input {
  width: 100%;
  min-height: 46px;
  color: var(--text);
  background: rgba(9, 22, 26, .7);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 0 13px;
  outline: none;
}
input:focus {
  border-color: var(--accent-light);
  box-shadow: 0 0 0 4px var(--accent-glow);
}
.primary, .ghost {
  min-height: 44px;
  border-radius: 8px;
  border: 1px solid transparent;
  padding: 0 18px;
}
.primary {
  margin-top: 4px;
  color: #fff;
  background: var(--accent);
  font-weight: 700;
}
.primary:hover { background: var(--accent-dark); }
.primary:disabled {
  cursor: not-allowed;
  opacity: .55;
  background: var(--accent-dark);
}
.ghost {
  color: var(--text);
  background: transparent;
  border-color: var(--border-strong);
}
.ghost:hover {
  color: var(--accent-light);
  background: var(--accent-glow);
}
.message {
  min-height: 22px;
  color: var(--danger);
  margin: 16px 0 0;
  font-size: .9rem;
}

.hidden { display: none !important; }

.dashboard {
  width: 100%;
  display: grid;
  gap: 22px;
}
.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 22px;
}
.topbar h1 {
  font-size: clamp(2.2rem, 5vw, 4.2rem);
  margin-bottom: 0;
}
.top-actions {
  display: flex;
  align-items: center;
  gap: 10px;
}
.pill {
  display: inline-flex;
  align-items: center;
  min-height: 34px;
  padding: 0 13px;
  border-radius: 999px;
  color: var(--danger);
  background: rgba(228, 109, 109, .12);
  border: 1px solid rgba(228, 109, 109, .24);
  font-size: .84rem;
}
.pill.online {
  color: var(--ok);
  background: rgba(116, 212, 164, .12);
  border-color: rgba(116, 212, 164, .26);
}

.metrics {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 14px;
}
.metric {
  padding: 18px;
  min-height: 112px;
  display: grid;
  align-content: space-between;
}
.metric span {
  color: var(--text-muted);
  font-size: .86rem;
}
.metric strong {
  font-family: "Outfit", sans-serif;
  font-size: clamp(1.35rem, 2.4vw, 2.25rem);
  font-weight: 800;
}

.chart-panel {
  padding: 20px;
  min-height: 520px;
}
.chart-head {
  display: flex;
  align-items: end;
  justify-content: space-between;
  gap: 18px;
  margin-bottom: 16px;
}
.chart-head h2 {
  font: 800 1.45rem "Outfit", sans-serif;
  margin: 0;
}
.chart-head > span {
  color: var(--text-muted);
  font-size: .9rem;
}
.chart-actions {
  display: flex;
  align-items: center;
  gap: 12px;
  flex-wrap: wrap;
  justify-content: flex-end;
}
.chart-actions span {
  color: var(--text-muted);
  font-size: .9rem;
}
#ecgCanvas {
  width: 100%;
  height: 420px;
  display: block;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: linear-gradient(180deg, rgba(9, 22, 26, .78), rgba(9, 22, 26, .48));
}
#detailCanvas {
  width: 100%;
  height: 360px;
  display: block;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: linear-gradient(180deg, rgba(9, 22, 26, .78), rgba(9, 22, 26, .48));
}

.measurement-grid {
  display: grid;
  grid-template-columns: minmax(260px, .7fr) minmax(0, 1.3fr);
  gap: 16px;
}
.measure-card {
  padding: 18px;
  border-radius: 8px;
}
.measure-card h2 {
  margin: 0;
  font: 800 1.35rem "Outfit", sans-serif;
}
.measure-status {
  display: grid;
  gap: 8px;
  margin-top: 28px;
}
.measure-status strong {
  font: 900 clamp(2.2rem, 5vw, 4rem) "Outfit", sans-serif;
}
.measure-status span {
  color: var(--text-secondary);
}
.history-card {
  min-height: 220px;
}
.history-head {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 14px;
  margin-bottom: 14px;
}
.measurement-list {
  display: grid;
  gap: 8px;
}
.measurement-item {
  width: 100%;
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 12px;
  text-align: left;
  color: var(--text);
  background: rgba(9, 22, 26, .5);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 12px;
}
.measurement-item:hover {
  border-color: var(--accent-light);
  background: var(--accent-glow);
}
.measurement-item strong {
  display: block;
  font: 800 1rem "Outfit", sans-serif;
}
.measurement-item span {
  color: var(--text-muted);
  font-size: .86rem;
}
.measurement-bpm {
  color: var(--accent-light);
  font-weight: 800;
  white-space: nowrap;
}
.empty-state {
  color: var(--text-muted);
  border: 1px dashed var(--border-strong);
  border-radius: 8px;
  padding: 18px;
}
.detail-panel {
  min-height: 460px;
}

@media (max-width: 900px) {
  .auth-view { grid-template-columns: 1fr; }
  .metrics { grid-template-columns: repeat(2, 1fr); }
  .topbar { align-items: flex-start; flex-direction: column; }
  .measurement-grid { grid-template-columns: 1fr; }
}

@media (max-width: 560px) {
  .shell { width: min(100% - 22px, 1180px); }
  .metrics { grid-template-columns: 1fr; }
  .top-actions { width: 100%; justify-content: space-between; }
  .chart-head { align-items: flex-start; flex-direction: column; }
  .chart-actions { width: 100%; justify-content: flex-start; }
  .chart-actions .primary { width: 100%; }
  .history-head { flex-direction: column; }
}
