:root {
  --bg: #08080c;
  --bg-elevated: #131319;
  --bg-card: #16161e;
  --border: #232330;
  --text: #f2f2f5;
  --text-dim: #8b8b99;
  --text-faint: #55556a;

  --strain-color: #33c1ff;
  --strain-glow: rgba(51, 193, 255, 0.55);
  --sleep-color: #9b7bff;
  --sleep-glow: rgba(155, 123, 255, 0.55);
  --recovery-red: #ff5c5c;
  --recovery-yellow: #ffcc4d;
  --recovery-green: #2fe88f;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  -webkit-font-smoothing: antialiased;
}

.shell {
  max-width: 1080px;
  margin: 0 auto;
  padding: 0 24px 100px;
}

header.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 28px 0 8px;
}

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

.brand .mark {
  font-size: 20px;
  font-weight: 700;
  letter-spacing: -0.02em;
}

.brand .sub {
  font-size: 12px;
  color: var(--text-faint);
  text-transform: uppercase;
  letter-spacing: 0.08em;
}

.logout-btn {
  background: none;
  border: 1px solid var(--border);
  color: var(--text-faint);
  font-size: 12px;
  padding: 6px 12px;
  border-radius: 8px;
  cursor: pointer;
}
.logout-btn:hover { color: var(--text-dim); border-color: var(--text-faint); }

/* --- Bottom tab bar (3-tab structure: Home / Health / Coach) --- */
.tab-bar {
  position: fixed;
  left: 0; right: 0; bottom: 0;
  display: flex;
  background: rgba(19, 19, 25, 0.92);
  backdrop-filter: blur(16px);
  border-top: 1px solid var(--border);
  padding: 6px 0 calc(6px + env(safe-area-inset-bottom));
  z-index: 40;
}

.tab-bar-item {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 2px;
  text-decoration: none;
  color: var(--text-faint);
  font-size: 11px;
  font-weight: 600;
  padding: 6px 0;
}

.tab-bar-icon { font-size: 18px; line-height: 1; }

.tab-bar-item.active {
  color: var(--strain-color);
  text-shadow: 0 0 10px var(--strain-glow);
}

.date-line {
  color: var(--text-faint);
  font-size: 13px;
  margin: 0 0 28px;
  letter-spacing: 0.02em;
}

.gauges {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 20px;
  margin-bottom: 24px;
}

@media (max-width: 720px) {
  .gauges { grid-template-columns: 1fr; }
}

.gauge-card {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: 20px;
  padding: 24px 16px 20px;
  display: flex;
  flex-direction: column;
  align-items: center;
}

.gauge-label {
  font-size: 13px;
  font-weight: 700;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--text-dim);
  margin-bottom: 14px;
}

.gauge-svg-wrap {
  position: relative;
  width: 168px;
  height: 168px;
}

.gauge-svg-wrap svg { width: 100%; height: 100%; transform: rotate(-90deg); }

.gauge-track { fill: none; stroke: #24242f; stroke-width: 12; }

.gauge-arc {
  fill: none;
  stroke-width: 12;
  stroke-linecap: round;
  transition: stroke-dashoffset 1.1s cubic-bezier(.4,0,.2,1), stroke 0.4s ease;
}

.gauge-value-wrap {
  position: absolute;
  inset: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
}

.gauge-value {
  font-size: 40px;
  font-weight: 700;
  letter-spacing: -0.02em;
}

.gauge-unit {
  font-size: 12px;
  color: var(--text-faint);
  margin-top: -2px;
}

.gauge-sub {
  margin-top: 12px;
  font-size: 12px;
  color: var(--text-faint);
  text-align: center;
}

.insight-card {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: 20px;
  padding: 22px 26px;
  margin-bottom: 24px;
}

.insight-card .heading {
  font-size: 12px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--text-dim);
  margin-bottom: 10px;
  display: flex;
  align-items: center;
  gap: 8px;
}

.insight-card .heading .dot {
  width: 7px; height: 7px; border-radius: 50%;
  background: var(--strain-color);
  box-shadow: 0 0 8px var(--strain-glow);
}

.insight-card p {
  margin: 0;
  font-size: 16px;
  line-height: 1.55;
  color: #e6e6ec;
}

.empty-state {
  color: var(--text-faint);
  font-size: 14px;
}

.meta-row {
  display: flex;
  gap: 20px;
  flex-wrap: wrap;
  font-size: 12px;
  color: var(--text-faint);
}

.meta-row span b { color: var(--text-dim); }

.chart-card {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: 20px;
  padding: 22px 24px;
  margin-bottom: 20px;
}

.chart-card h3 {
  margin: 0 0 16px;
  font-size: 13px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--text-dim);
}

.range-toggle {
  display: inline-flex;
  gap: 4px;
  background: var(--bg-elevated);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 3px;
  margin-bottom: 20px;
}

.range-toggle button {
  border: none;
  background: transparent;
  color: var(--text-dim);
  font-size: 12px;
  font-weight: 600;
  padding: 6px 14px;
  border-radius: 6px;
  cursor: pointer;
}

.range-toggle button.active {
  background: #212130;
  color: var(--text);
}

.chart-canvas-wrap {
  position: relative;
  width: 100%;
  height: 260px;
}

.chart-canvas-wrap-small { height: 180px; }

canvas { max-width: 100%; }

/* --- Tappable widgets --- */
.gauge-card, .monitor-card, .quick-stat, [data-detail-metric] {
  cursor: pointer;
  transition: transform 0.12s ease, border-color 0.12s ease;
}
.gauge-card:hover, .monitor-card:hover, .quick-stat:hover {
  border-color: var(--text-faint);
  transform: translateY(-1px);
}
.gauge-card:focus-visible, .monitor-card:focus-visible { outline: 2px solid var(--strain-color); outline-offset: 2px; }

/* --- Quick stats row (Home) --- */
.quick-stats-row {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 14px;
  margin-bottom: 20px;
}

.quick-stat {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: 16px;
  padding: 16px;
  text-align: center;
}

.quick-stat-label {
  font-size: 11px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--text-faint);
  margin-bottom: 6px;
}

.quick-stat-value { font-size: 22px; font-weight: 700; }
.quick-stat-unit { font-size: 12px; color: var(--text-faint); margin-left: 3px; }

/* --- Activities log (Home) --- */
.activities-card {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: 20px;
  padding: 20px 22px;
  margin-bottom: 20px;
}

.activities-header { display: flex; justify-content: space-between; align-items: center; margin-bottom: 12px; }
.activities-header h3 { margin: 0; font-size: 13px; font-weight: 700; text-transform: uppercase; letter-spacing: 0.06em; color: var(--text-dim); }

.add-activity-btn {
  background: var(--bg-elevated);
  border: 1px solid var(--border);
  color: var(--text);
  font-size: 12px;
  font-weight: 600;
  padding: 6px 12px;
  border-radius: 8px;
  cursor: pointer;
}

.activity-row {
  display: flex;
  justify-content: space-between;
  padding: 10px 0;
  border-bottom: 1px solid var(--border);
  font-size: 14px;
}
.activity-row:last-child { border-bottom: none; }
.activity-type { text-transform: capitalize; font-weight: 600; }
.activity-meta { color: var(--text-faint); font-size: 13px; }

/* --- Modals (Add Activity, detail views) --- */
.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(4, 4, 7, 0.72);
  display: flex;
  align-items: flex-end;
  justify-content: center;
  z-index: 60;
}
@media (min-width: 640px) {
  .modal-overlay { align-items: center; }
}
.modal-overlay.hidden { display: none; }

.modal-box {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: 20px 20px 0 0;
  padding: 24px;
  width: 100%;
  max-width: 480px;
  max-height: 85vh;
  overflow-y: auto;
}
@media (min-width: 640px) {
  .modal-box { border-radius: 20px; }
}

.modal-box h3 { margin: 0 0 16px; font-size: 16px; }

.modal-box label {
  display: block;
  font-size: 12px;
  color: var(--text-dim);
  margin-bottom: 14px;
}

.modal-box input {
  display: block;
  width: 100%;
  margin-top: 6px;
  background: var(--bg-elevated);
  border: 1px solid var(--border);
  color: var(--text);
  padding: 10px 12px;
  border-radius: 10px;
  font-size: 14px;
}

.modal-actions { display: flex; justify-content: flex-end; gap: 10px; margin-top: 8px; }

.modal-box button[type="submit"], .modal-box button:not(.modal-cancel):not(.modal-close) {
  background: var(--strain-color);
  color: #08080c;
  border: none;
  font-weight: 700;
  padding: 10px 18px;
  border-radius: 10px;
  cursor: pointer;
}

.modal-cancel {
  background: transparent;
  border: 1px solid var(--border);
  color: var(--text-dim);
  padding: 10px 18px;
  border-radius: 10px;
  cursor: pointer;
}

.modal-header { display: flex; justify-content: space-between; align-items: center; margin-bottom: 16px; }
.modal-header h3 { margin: 0; }
.modal-close {
  background: none; border: none; color: var(--text-faint);
  font-size: 24px; line-height: 1; cursor: pointer; padding: 0 4px;
}

.detail-rows { margin-bottom: 18px; }
.detail-row {
  display: flex; justify-content: space-between;
  padding: 9px 0; border-bottom: 1px solid var(--border);
  font-size: 14px;
}
.detail-row:last-child { border-bottom: none; }
.detail-row span { color: var(--text-faint); }

.detail-latest { font-size: 32px; font-weight: 700; margin-bottom: 16px; }
.detail-unit { font-size: 14px; color: var(--text-faint); font-weight: 400; }

.rating { font-size: 11px; font-weight: 700; padding: 2px 8px; border-radius: 6px; margin-left: 6px; }
.rating-optimal { background: rgba(47, 232, 143, 0.15); color: var(--recovery-green); }
.rating-sufficient { background: rgba(255, 204, 77, 0.15); color: var(--recovery-yellow); }
.rating-poor { background: rgba(255, 92, 92, 0.15); color: var(--recovery-red); }

/* --- Health Monitor grid --- */
.section-heading {
  font-size: 13px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--text-dim);
  margin: 28px 0 14px;
}

.monitor-grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 14px;
  margin-bottom: 20px;
}
@media (max-width: 560px) { .monitor-grid { grid-template-columns: repeat(2, 1fr); } }

.monitor-card {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: 16px;
  padding: 16px;
}

.monitor-label {
  font-size: 11px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--text-faint);
  margin-bottom: 8px;
}

.monitor-value { font-size: 24px; font-weight: 700; }
.monitor-value.no-data { font-size: 14px; color: var(--text-faint); font-weight: 500; }
.monitor-unit { font-size: 12px; color: var(--text-faint); margin-top: 2px; }

/* --- Stress Monitor --- */
.stress-summary { display: flex; justify-content: space-between; align-items: baseline; margin-bottom: 14px; }
.stress-level { font-size: 20px; font-weight: 700; }
.stress-updated { font-size: 12px; color: var(--text-faint); }

/* --- Pace of Aging --- */
.aging-headline { font-size: 32px; font-weight: 700; margin-bottom: 6px; }
.aging-sub { font-size: 13px; color: var(--text-faint); font-weight: 400; margin-left: 6px; }
.aging-detail { font-size: 14px; color: #e6e6ec; margin-bottom: 6px; }

.export-csv-btn {
  display: block;
  text-align: center;
  background: var(--bg-card);
  border: 1px solid var(--border);
  color: var(--text-dim);
  font-size: 13px;
  font-weight: 600;
  padding: 12px;
  border-radius: 14px;
  text-decoration: none;
  margin-bottom: 20px;
}
.export-csv-btn:hover { border-color: var(--text-faint); color: var(--text); }

/* --- Coach tab chat --- */
.coach-header { display: flex; justify-content: space-between; align-items: center; margin-bottom: 16px; }

.thread-picker {
  background: var(--bg-elevated);
  border: 1px solid var(--border);
  color: var(--text);
  font-size: 13px;
  padding: 7px 10px;
  border-radius: 8px;
}

.chat-messages {
  display: flex;
  flex-direction: column;
  gap: 10px;
  min-height: 50vh;
  max-height: 65vh;
  overflow-y: auto;
  padding-bottom: 12px;
}

.chat-bubble {
  max-width: 80%;
  padding: 11px 15px;
  border-radius: 16px;
  font-size: 14px;
  line-height: 1.5;
  white-space: pre-wrap;
}

.chat-bubble-user {
  align-self: flex-end;
  background: var(--strain-color);
  color: #08080c;
  font-weight: 500;
  border-bottom-right-radius: 4px;
}

.chat-bubble-assistant {
  align-self: flex-start;
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-bottom-left-radius: 4px;
}

.chat-bubble-pending { color: var(--text-faint); }

.chat-form {
  position: fixed;
  left: 0; right: 0;
  bottom: calc(58px + env(safe-area-inset-bottom));
  display: flex;
  gap: 10px;
  padding: 10px 24px;
  background: rgba(8, 8, 12, 0.92);
  backdrop-filter: blur(16px);
  border-top: 1px solid var(--border);
  max-width: 1080px;
  margin: 0 auto;
}

.chat-form input {
  flex: 1;
  background: var(--bg-elevated);
  border: 1px solid var(--border);
  color: var(--text);
  padding: 12px 14px;
  border-radius: 12px;
  font-size: 14px;
}

.chat-form button {
  background: var(--strain-color);
  color: #08080c;
  border: none;
  font-weight: 700;
  padding: 0 20px;
  border-radius: 12px;
  cursor: pointer;
}

/* --- Login page --- */
.login-shell {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px;
}

.login-card {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: 20px;
  padding: 32px 28px;
  width: 100%;
  max-width: 360px;
}

.login-mark { font-size: 20px; font-weight: 700; margin-bottom: 4px; }
.login-sub { color: var(--text-faint); font-size: 13px; margin: 0 0 24px; }
.login-error { color: var(--recovery-red); font-size: 13px; margin-bottom: 16px; }

.login-card label {
  display: block;
  font-size: 12px;
  color: var(--text-dim);
  margin-bottom: 16px;
}

.login-card input {
  display: block;
  width: 100%;
  margin-top: 6px;
  background: var(--bg-elevated);
  border: 1px solid var(--border);
  color: var(--text);
  padding: 11px 12px;
  border-radius: 10px;
  font-size: 14px;
}

.login-card button {
  width: 100%;
  background: var(--strain-color);
  color: #08080c;
  border: none;
  font-weight: 700;
  padding: 12px;
  border-radius: 10px;
  cursor: pointer;
  margin-top: 6px;
}
