:root {
  --bg: #0f172a;
  --bg-card: #1e293b;
  --bg-input: #0b1120;
  --border: #334155;
  --border-focus: #38bdf8;
  --text: #f8fafc;
  --text-muted: #94a3b8;
  --primary: #0ea5e9;
  --primary-hover: #0284c7;
  --danger: #ef4444;
  --success: #10b981;
  --color-bp-sys: #38bdf8;
  --color-bp-dia: #818cf8;
  --color-hr: #f43f5e;
  --color-weight: #10b981;
  --radius: 14px;
  --radius-sm: 10px;
}

* {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

body {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  background-color: var(--bg);
  color: var(--text);
  line-height: 1.45;
  -webkit-font-smoothing: antialiased;
  padding-bottom: env(safe-area-inset-bottom, 24px);
}

.hidden {
  display: none !important;
}

/* Auth View */
.auth-container {
  min-height: 100dvh;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 20px;
}

.auth-card {
  width: 100%;
  max-width: 380px;
}

.brand-header {
  display: flex;
  align-items: center;
  gap: 14px;
  margin-bottom: 24px;
}

.brand-icon {
  width: 48px;
  height: 48px;
  border-radius: 12px;
}

.brand-icon-sm {
  width: 30px;
  height: 30px;
  border-radius: 8px;
}

.brand-header h1 {
  font-size: 1.35rem;
  font-weight: 700;
}

.subtitle {
  color: var(--text-muted);
  font-size: 0.875rem;
}

/* App Shell */
.app-shell {
  max-width: 980px;
  margin: 0 auto;
  padding: 12px 14px 40px;
}

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 8px 4px 16px;
}

.brand-row {
  display: flex;
  align-items: center;
  gap: 10px;
}

.brand-row h1 {
  font-size: 1.2rem;
  font-weight: 700;
  letter-spacing: -0.01em;
}

.main-grid {
  display: grid;
  grid-template-columns: 1fr;
  gap: 16px;
}

@media (min-width: 820px) {
  .main-grid {
    grid-template-columns: 360px 1fr;
    align-items: start;
  }
  .record-card {
    grid-row: 1 / 3;
    position: sticky;
    top: 16px;
  }
}

.card {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 18px;
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.22);
}

.section-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  margin-bottom: 16px;
}

.section-header h2 {
  font-size: 1.05rem;
  font-weight: 600;
}

.hint-pill,
.count-badge {
  font-size: 0.75rem;
  color: var(--text-muted);
  background: rgba(148, 163, 184, 0.12);
  padding: 4px 9px;
  border-radius: 999px;
}

/* Inputs & Form Controls */
.field-label {
  display: block;
  font-size: 0.875rem;
  font-weight: 500;
  margin-bottom: 8px;
  color: var(--text-muted);
}

.field-label-sm {
  display: block;
  font-size: 0.78rem;
  font-weight: 500;
  margin-bottom: 6px;
  color: var(--text-muted);
}

.metric-group {
  margin-bottom: 14px;
}

.group-label {
  display: flex;
  align-items: center;
  gap: 7px;
  font-size: 0.88rem;
  font-weight: 600;
  margin-bottom: 7px;
}

.unit {
  color: var(--text-muted);
  font-weight: 400;
  font-size: 0.8rem;
}

.dot {
  width: 9px;
  height: 9px;
  border-radius: 50%;
  display: inline-block;
  flex-shrink: 0;
}

.dot-bp {
  background: var(--color-bp-sys);
}

.dot-hr {
  background: var(--color-hr);
}

.dot-weight {
  background: var(--color-weight);
}

input[type="number"],
input[type="password"],
input[type="text"],
input[type="datetime-local"] {
  width: 100%;
  background: var(--bg-input);
  border: 1.5px solid var(--border);
  border-radius: var(--radius-sm);
  color: var(--text);
  font-size: 1.05rem; /* >=16px prevents iOS Safari auto-zoom */
  padding: 12px 13px;
  transition: border-color 0.15s ease, box-shadow 0.15s ease;
  appearance: textfield;
}

input[type="number"]::-webkit-inner-spin-button,
input[type="number"]::-webkit-outer-spin-button {
  -webkit-appearance: none;
  margin: 0;
}

input:focus {
  outline: none;
  border-color: var(--border-focus);
  box-shadow: 0 0 0 3px rgba(56, 189, 248, 0.2);
}

.bp-inputs {
  display: grid;
  grid-template-columns: 1fr auto 1fr;
  align-items: start;
  gap: 8px;
}

.bp-inputs input {
  text-align: center;
  font-size: 1.25rem;
  font-weight: 600;
  padding: 12px 8px;
}

.bp-slash {
  font-size: 1.5rem;
  color: var(--text-muted);
  padding-top: 10px;
  user-select: none;
}

.input-wrap {
  display: flex;
  flex-direction: column;
  align-items: center;
}

.sub-label {
  font-size: 0.72rem;
  color: var(--text-muted);
  margin-top: 4px;
}

.two-col-metrics {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 12px;
}

.two-col-metrics input {
  font-size: 1.2rem;
  font-weight: 600;
  text-align: center;
}

.meta-row {
  display: flex;
  flex-direction: column;
  gap: 12px;
  margin-top: 4px;
  margin-bottom: 16px;
  padding-top: 12px;
  border-top: 1px solid rgba(255, 255, 255, 0.06);
}

.datetime-inline {
  display: flex;
  gap: 8px;
}

.datetime-inline input {
  font-size: 0.95rem;
  padding: 10px 11px;
}

#input-notes {
  font-size: 0.95rem;
  padding: 10px 12px;
}

/* Buttons */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  font-size: 0.95rem;
  font-weight: 600;
  border-radius: var(--radius-sm);
  border: 1px solid transparent;
  padding: 11px 16px;
  cursor: pointer;
  transition: background-color 0.15s ease, transform 0.08s ease, opacity 0.15s ease;
  user-select: none;
}

.btn:active {
  transform: scale(0.99);
}

.btn:disabled {
  opacity: 0.6;
  cursor: not-allowed;
}

.btn-primary {
  background: var(--primary);
  color: #fff;
}

.btn-primary:hover:not(:disabled) {
  background: var(--primary-hover);
}

.btn-secondary {
  background: rgba(56, 189, 248, 0.12);
  color: #38bdf8;
  border-color: rgba(56, 189, 248, 0.3);
}

.btn-secondary:hover:not(:disabled) {
  background: rgba(56, 189, 248, 0.2);
}

.btn-ghost {
  background: transparent;
  color: var(--text-muted);
  border-color: var(--border);
}

.btn-ghost:hover {
  color: var(--text);
  background: rgba(255, 255, 255, 0.05);
}

.btn-block {
  width: 100%;
}

.btn-lg {
  padding: 14px 18px;
  font-size: 1.05rem;
}

.btn-sm {
  padding: 7px 12px;
  font-size: 0.82rem;
}

/* Feedback Messages */
.feedback {
  font-size: 0.86rem;
  padding: 10px 12px;
  border-radius: 8px;
  margin-bottom: 12px;
}

.feedback.error {
  background: rgba(239, 68, 68, 0.15);
  border: 1px solid rgba(239, 68, 68, 0.4);
  color: #fca5a5;
}

.feedback.success {
  background: rgba(16, 185, 129, 0.15);
  border: 1px solid rgba(16, 185, 129, 0.4);
  color: #6ee7b7;
}

/* Controls & Toggles */
.controls-bar {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  margin-bottom: 14px;
}

.metric-toggles {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

.toggle-chip {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  font-size: 0.82rem;
  font-weight: 500;
  padding: 6px 11px;
  border-radius: 999px;
  background: var(--bg-input);
  border: 1px solid var(--border);
  cursor: pointer;
  user-select: none;
}

.toggle-chip input {
  accent-color: var(--primary);
}

.range-pills {
  display: inline-flex;
  background: var(--bg-input);
  border: 1px solid var(--border);
  border-radius: 999px;
  padding: 2px;
}

.range-pill {
  background: transparent;
  border: none;
  color: var(--text-muted);
  font-size: 0.76rem;
  font-weight: 600;
  padding: 5px 10px;
  border-radius: 999px;
  cursor: pointer;
}

.range-pill.active {
  background: var(--primary);
  color: #fff;
}

/* Summary Strip */
.summary-strip {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 8px;
  margin-bottom: 14px;
}

.stat-box {
  background: var(--bg-input);
  border: 1px solid rgba(255, 255, 255, 0.06);
  border-radius: var(--radius-sm);
  padding: 9px 10px;
}

.stat-label {
  display: block;
  font-size: 0.7rem;
  color: var(--text-muted);
  margin-bottom: 3px;
}

.stat-value {
  font-size: 0.9rem;
  font-weight: 700;
}

/* Chart Area */
.chart-wrapper {
  position: relative;
  width: 100%;
  height: 270px;
  background: var(--bg-input);
  border: 1px solid rgba(255, 255, 255, 0.06);
  border-radius: var(--radius-sm);
  padding: 8px;
}

#trends-canvas {
  width: 100%;
  height: 100%;
  display: block;
  touch-action: pan-y;
}

.chart-tooltip {
  position: absolute;
  pointer-events: none;
  background: rgba(15, 23, 42, 0.94);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 8px 10px;
  font-size: 0.76rem;
  box-shadow: 0 4px 14px rgba(0, 0, 0, 0.4);
  z-index: 10;
  white-space: nowrap;
}

.empty-state {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  text-align: center;
  padding: 20px;
  color: var(--text-muted);
  font-size: 0.88rem;
}

/* History List */
.history-list {
  display: flex;
  flex-direction: column;
  gap: 8px;
  max-height: 460px;
  overflow-y: auto;
}

.history-item {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  background: var(--bg-input);
  border: 1px solid rgba(255, 255, 255, 0.06);
  border-radius: var(--radius-sm);
  padding: 11px 13px;
}

.history-main {
  display: flex;
  flex-direction: column;
  gap: 5px;
  min-width: 0;
}

.history-time {
  font-size: 0.76rem;
  color: var(--text-muted);
}

.history-badges {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
}

.metric-badge {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  font-size: 0.84rem;
  font-weight: 600;
  padding: 3px 9px;
  border-radius: 6px;
  background: rgba(255, 255, 255, 0.05);
}

.badge-bp {
  color: #7dd3fc;
  border-left: 3px solid var(--color-bp-sys);
}

.badge-hr {
  color: #fda4af;
  border-left: 3px solid var(--color-hr);
}

.badge-weight {
  color: #6ee7b7;
  border-left: 3px solid var(--color-weight);
}

.history-notes {
  font-size: 0.8rem;
  color: var(--text-muted);
  word-break: break-word;
}

.delete-btn {
  background: transparent;
  border: none;
  color: var(--text-muted);
  font-size: 0.82rem;
  padding: 6px 8px;
  border-radius: 6px;
  cursor: pointer;
  flex-shrink: 0;
}

.delete-btn:hover {
  color: var(--danger);
  background: rgba(239, 68, 68, 0.12);
}

