/* WLOX - Workout Life OX */

:root {
  --bg-primary: #08080d;
  --bg-secondary: #101018;
  --bg-card: #161622;
  --bg-input: #1e1e2e;
  --text-primary: #eaeaf0;
  --text-secondary: #8888a0;
  --text-muted: #555566;
  --accent: #00d4aa;
  --accent-bright: #00ffcc;
  --accent-dim: rgba(0, 212, 170, 0.12);
  --accent-glow: rgba(0, 212, 170, 0.06);
  --border: #222233;
  --border-light: #2a2a3d;
  --danger: #ff4466;
  --color-excellent: #00d4aa;
  --color-good: #4488ff;
  --color-moderate: #ffaa00;
  --color-low: #ff6633;
  --color-verylow: #ff3344;
  --radius: 16px;
  --radius-sm: 10px;
  --safe-bottom: env(safe-area-inset-bottom, 0px);
  --tab-height: 64px;
}

* {
  margin: 0;
  padding: 0;
  box-sizing: border-box;
  -webkit-tap-highlight-color: transparent;
}

html, body {
  height: 100%;
  background: var(--bg-primary);
  color: var(--text-primary);
  font-family: -apple-system, BlinkMacSystemFont, 'SF Pro Display', 'Segoe UI', Roboto, sans-serif;
  font-size: 16px;
  line-height: 1.5;
  overflow: hidden;
  -webkit-font-smoothing: antialiased;
}

#app {
  height: 100%;
  width: 100%;
  max-width: 500px;
  margin: 0 auto;
}

.hidden { display: none !important; }

/* ── Login ─────────────────────────────────────────────────────────────── */

.screen {
  height: 100%;
  width: 100%;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
}

.login-container {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  min-height: 100%;
  padding: 40px 24px;
}

.login-logo {
  font-size: 48px;
  font-weight: 800;
  letter-spacing: 4px;
  color: var(--accent);
  margin-bottom: 4px;
}

.login-subtitle {
  font-size: 14px;
  color: var(--text-secondary);
  margin-bottom: 40px;
  letter-spacing: 1px;
}

form {
  width: 100%;
  max-width: 320px;
}

.form-group {
  margin-bottom: 16px;
}

.form-group label {
  display: block;
  font-size: 13px;
  color: var(--text-secondary);
  margin-bottom: 6px;
  font-weight: 500;
}

.form-group input {
  width: 100%;
  padding: 12px 14px;
  background: var(--bg-input);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  color: var(--text-primary);
  font-size: 16px;
  outline: none;
  transition: border-color 0.2s;
}

.form-group input:focus {
  border-color: var(--accent);
}

.btn-primary {
  width: 100%;
  padding: 14px;
  background: var(--accent);
  color: #000;
  border: none;
  border-radius: var(--radius-sm);
  font-size: 16px;
  font-weight: 600;
  cursor: pointer;
  margin-top: 8px;
  transition: opacity 0.2s;
}

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

.btn-primary:active:not(:disabled) {
  opacity: 0.8;
}

.sync-warning {
  margin: 0 16px 0;
  padding: 10px 14px;
  background: rgba(255, 170, 0, 0.12);
  border: 1px solid var(--color-moderate);
  border-radius: var(--radius-sm);
  color: var(--color-moderate);
  font-size: 13px;
  font-weight: 500;
  line-height: 1.4;
}

.btn-danger {
  width: 100%;
  padding: 14px;
  background: transparent;
  color: var(--danger);
  border: 1px solid var(--danger);
  border-radius: var(--radius-sm);
  font-size: 16px;
  font-weight: 600;
  cursor: pointer;
  margin-top: 16px;
  transition: opacity 0.2s;
}

.btn-danger:active {
  opacity: 0.7;
}

.btn-link {
  background: none;
  border: none;
  color: var(--accent);
  font-size: 14px;
  cursor: pointer;
  text-decoration: underline;
}

.error-msg {
  color: var(--danger);
  font-size: 13px;
  margin-top: 12px;
  text-align: center;
  min-height: 20px;
}

.register-hint {
  text-align: center;
  margin-top: 20px;
  font-size: 14px;
  color: var(--text-secondary);
}

/* ── Main App Layout ───────────────────────────────────────────────────── */

#mainApp {
  height: 100%;
  display: flex;
  flex-direction: column;
}

.tab-screen {
  display: none;
  flex: 1;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  padding-bottom: calc(var(--tab-height) + var(--safe-bottom) + 16px);
}

.tab-screen.active {
  display: flex;
  flex-direction: column;
}

/* ── Screen Header ─────────────────────────────────────────────────────── */

.screen-header {
  padding: 16px 20px 4px;
  position: sticky;
  top: 0;
  background: var(--bg-primary);
  z-index: 10;
}

.greeting {
  font-size: 26px;
  font-weight: 700;
  color: var(--text-primary);
  letter-spacing: -0.3px;
}

.screen-header h2 {
  font-size: 24px;
  font-weight: 700;
  color: var(--text-primary);
}

.header-date {
  font-size: 14px;
  color: var(--text-secondary);
  font-weight: 500;
  margin-top: 2px;
}

/* ── Dashboard Content ─────────────────────────────────────────────────── */

.dashboard-content {
  padding: 12px 16px;
  display: flex;
  flex-direction: column;
  gap: 14px;
}

/* ── Readiness Ring ────────────────────────────────────────────────────── */

.readiness-hero {
  text-align: center;
  padding: 20px 16px 16px;
  background: linear-gradient(180deg, var(--accent-glow) 0%, transparent 100%);
  border-radius: var(--radius);
  border: 1px solid var(--border);
}

.readiness-ring-wrap {
  position: relative;
  display: inline-block;
  width: 160px;
  height: 160px;
  margin-bottom: 12px;
}

.readiness-ring {
  width: 160px;
  height: 160px;
  transform: rotate(-90deg);
}

.ring-bg {
  fill: none;
  stroke: var(--bg-input);
  stroke-width: 8;
}

.ring-fill {
  fill: none;
  stroke-width: 8;
  stroke-linecap: round;
  stroke-dasharray: 364.42;
  stroke-dashoffset: 364.42;
  transition: stroke-dashoffset 1.2s cubic-bezier(0.4, 0, 0.2, 1);
}

.ring-fill.color-excellent { stroke: var(--color-excellent); }
.ring-fill.color-good { stroke: var(--color-good); }
.ring-fill.color-moderate { stroke: var(--color-moderate); }
.ring-fill.color-low { stroke: var(--color-low); }
.ring-fill.color-verylow { stroke: var(--color-verylow); }

.readiness-center {
  position: absolute;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  text-align: center;
}

.readiness-score {
  font-size: 52px;
  font-weight: 800;
  line-height: 1;
  font-variant-numeric: tabular-nums;
}

.readiness-score.color-excellent { color: var(--color-excellent); }
.readiness-score.color-good { color: var(--color-good); }
.readiness-score.color-moderate { color: var(--color-moderate); }
.readiness-score.color-low { color: var(--color-low); }
.readiness-score.color-verylow { color: var(--color-verylow); }

.readiness-status {
  font-size: 11px;
  font-weight: 700;
  letter-spacing: 2px;
  margin-top: 4px;
}

.readiness-status.color-excellent { color: var(--color-excellent); }
.readiness-status.color-good { color: var(--color-good); }
.readiness-status.color-moderate { color: var(--color-moderate); }
.readiness-status.color-low { color: var(--color-low); }
.readiness-status.color-verylow { color: var(--color-verylow); }

/* ── Threshold Bar ──────────────────────────────────────────────────── */

.threshold-bar-wrap {
  padding: 12px 16px 4px;
}

.threshold-bar {
  position: relative;
  display: flex;
  height: 8px;
  border-radius: 4px;
  overflow: visible;
}

.threshold-zone {
  flex: 1;
}

.threshold-zone:first-child { border-radius: 4px 0 0 4px; }
.threshold-zone:last-child { border-radius: 0 4px 4px 0; }

.threshold-recover { background: var(--color-verylow); opacity: 0.6; }
.threshold-low { background: var(--color-low); opacity: 0.6; }
.threshold-moderate { background: var(--color-moderate); opacity: 0.6; }
.threshold-ready { background: var(--color-good); opacity: 0.6; }
.threshold-primed { background: var(--color-excellent); opacity: 0.6; }

.threshold-marker {
  position: absolute;
  top: -4px;
  width: 3px;
  height: 16px;
  background: var(--text-primary);
  border-radius: 2px;
  transform: translateX(-50%);
  box-shadow: 0 0 6px rgba(255,255,255,0.4);
  transition: left 0.6s ease-out;
}

.threshold-labels {
  display: flex;
  justify-content: space-between;
  font-size: 9px;
  color: var(--text-muted);
  padding-top: 4px;
}

/* ── Readiness Components ──────────────────────────────────────────── */

.readiness-context {
  text-align: center;
  font-size: 11px;
  color: var(--text-muted);
  padding: 4px 12px 0;
  line-height: 1.3;
}

.readiness-components {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 6px;
  padding: 8px 4px 0;
}

.component-item {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 2px;
}

.component-donut {
  position: relative;
  width: 52px;
  height: 52px;
}

.component-donut svg {
  width: 52px;
  height: 52px;
  transform: rotate(-90deg);
}

.component-donut .donut-bg {
  fill: none;
  stroke: rgba(255,255,255,0.06);
  stroke-width: 4;
}

.component-donut .donut-fill {
  fill: none;
  stroke-width: 4;
  stroke-linecap: round;
  transition: stroke-dashoffset 0.8s ease-out;
}

.component-donut-value {
  position: absolute;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  font-size: 13px;
  font-weight: 700;
  color: var(--text-primary);
}

.component-label {
  font-size: 10px;
  font-weight: 500;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.5px;
}

.component-context {
  font-size: 9px;
  color: var(--text-muted);
  line-height: 1.2;
  text-align: center;
}

/* ── Sync Timestamp ────────────────────────────────────────────────── */

.sync-timestamp {
  text-align: center;
  font-size: 11px;
  color: var(--text-muted);
  padding: 6px 0 2px;
}

.sync-timestamp.sync-stale {
  color: var(--color-moderate);
}

/* ── Coach Card ────────────────────────────────────────────────────────── */

.coach-card {
  background: linear-gradient(135deg, rgba(0, 212, 170, 0.08) 0%, rgba(0, 212, 170, 0.02) 100%);
  border: 1px solid rgba(0, 212, 170, 0.25);
  border-radius: var(--radius);
  padding: 16px;
}

.coach-header {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-bottom: 12px;
}

.coach-icon-wrap {
  width: 32px;
  height: 32px;
  border-radius: 8px;
  background: var(--accent-dim);
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--accent);
}

.coach-icon {
  width: 18px;
  height: 18px;
}

.coach-title {
  font-size: 14px;
  font-weight: 600;
  color: var(--accent);
  text-transform: uppercase;
  letter-spacing: 1px;
}

.coach-text {
  font-size: 15px;
  line-height: 1.6;
  color: var(--text-primary);
  white-space: pre-wrap;
  min-height: 40px;
}

.coach-loading {
  display: flex;
  gap: 6px;
  padding: 8px 0;
}

.coach-loading .dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--accent);
  animation: dotPulse 1.4s ease-in-out infinite;
}

.coach-loading .dot:nth-child(2) { animation-delay: 0.2s; }
.coach-loading .dot:nth-child(3) { animation-delay: 0.4s; }

@keyframes dotPulse {
  0%, 80%, 100% { opacity: 0.3; transform: scale(0.8); }
  40% { opacity: 1; transform: scale(1); }
}

.btn-chat {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  width: 100%;
  margin-top: 14px;
  padding: 11px 16px;
  background: var(--accent-dim);
  color: var(--accent);
  border: 1px solid rgba(0, 212, 170, 0.3);
  border-radius: var(--radius-sm);
  font-size: 14px;
  font-weight: 600;
  cursor: pointer;
  transition: all 0.2s;
}

.btn-chat:active {
  background: var(--accent);
  color: #000;
}

/* ── Metrics Grid ──────────────────────────────────────────────────────── */

.metrics-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
}

.metric-card {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 14px;
  position: relative;
  overflow: hidden;
}

.metric-card::before {
  content: '';
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  height: 2px;
  opacity: 0.6;
}

.metric-sleep::before { background: linear-gradient(90deg, #4488ff, #6644ff); }
.metric-hrv::before { background: linear-gradient(90deg, #00d4aa, #00ffcc); }
.metric-battery::before { background: linear-gradient(90deg, #ffaa00, #ffcc44); }
.metric-stress::before { background: linear-gradient(90deg, #ff6633, #ff8855); }

.metric-card-icon {
  color: var(--text-muted);
  margin-bottom: 6px;
}

.metric-sleep .metric-card-icon { color: #4488ff; }
.metric-hrv .metric-card-icon { color: #00d4aa; }
.metric-battery .metric-card-icon { color: #ffaa00; }
.metric-stress .metric-card-icon { color: #ff6633; }

.metric-card-label {
  font-size: 12px;
  font-weight: 500;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.5px;
}

.metric-card-value {
  font-size: 24px;
  font-weight: 700;
  color: var(--text-primary);
  font-variant-numeric: tabular-nums;
  margin-top: 2px;
}

.metric-card-sub {
  font-size: 12px;
  color: var(--text-secondary);
  margin-top: 2px;
  min-height: 16px;
}

.metric-card-context {
  font-size: 9px;
  color: var(--text-muted);
  margin-top: 1px;
}

/* ── Cards ─────────────────────────────────────────────────────────────── */

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

.card-title {
  font-size: 12px;
  font-weight: 600;
  color: var(--text-secondary);
  text-transform: uppercase;
  letter-spacing: 1px;
  margin-bottom: 12px;
}

.card-body {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.metric-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
}

.metric-label {
  font-size: 14px;
  color: var(--text-secondary);
}

.metric-value {
  font-size: 15px;
  font-weight: 600;
  color: var(--text-primary);
}

/* ── Activities ────────────────────────────────────────────────────────── */

.activities-card {
  padding-bottom: 12px;
}

.activities-list {
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.activity-item {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 10px 4px;
  border-bottom: 1px solid var(--border);
}

.activity-item:last-child {
  border-bottom: none;
}

.activity-icon {
  width: 36px;
  height: 36px;
  border-radius: 10px;
  background: var(--bg-input);
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--text-secondary);
  flex-shrink: 0;
}

.activity-info {
  flex: 1;
  min-width: 0;
}

.activity-name {
  font-size: 14px;
  font-weight: 600;
  color: var(--text-primary);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.activity-meta {
  font-size: 12px;
  color: var(--text-secondary);
  margin-top: 1px;
}

.empty-activities {
  padding: 20px;
  text-align: center;
  color: var(--text-muted);
  font-size: 14px;
}

/* ── Empty / Placeholder State ─────────────────────────────────────────── */

.empty-state,
.placeholder-content {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 60px 24px;
  text-align: center;
  flex: 1;
}

.empty-icon {
  font-size: 48px;
  margin-bottom: 16px;
  opacity: 0.5;
}

.empty-title {
  font-size: 18px;
  font-weight: 600;
  color: var(--text-primary);
  margin-bottom: 8px;
}

.empty-subtitle {
  font-size: 14px;
  color: var(--text-secondary);
  max-width: 280px;
  line-height: 1.5;
}

/* ── Settings ──────────────────────────────────────────────────────────── */

.settings-content {
  padding: 8px 16px;
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.about-text {
  font-size: 14px;
  color: var(--text-secondary);
  line-height: 1.6;
}

/* ── Chat Overlay ──────────────────────────────────────────────────────── */

.chat-overlay {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background: var(--bg-primary);
  z-index: 200;
  display: flex;
  flex-direction: column;
  max-width: 500px;
  margin: 0 auto;
  transform: translateY(100%);
  transition: transform 0.3s cubic-bezier(0.4, 0, 0.2, 1);
}

.chat-overlay.active {
  transform: translateY(0);
}

.chat-header {
  display: flex;
  align-items: center;
  padding: 12px 16px;
  padding-top: max(12px, env(safe-area-inset-top));
  background: var(--bg-secondary);
  border-bottom: 1px solid var(--border);
  gap: 12px;
}

.chat-back {
  background: none;
  border: none;
  color: var(--accent);
  cursor: pointer;
  padding: 4px;
  display: flex;
  align-items: center;
}

.chat-header-title {
  font-size: 16px;
  font-weight: 600;
  color: var(--text-primary);
  display: flex;
  align-items: center;
  gap: 8px;
}

.coach-icon-sm {
  color: var(--accent);
}

.chat-history-toggle {
  margin-left: auto;
  background: none;
  border: 1px solid var(--border-light);
  color: var(--text-secondary);
  font-size: 12px;
  padding: 4px 12px;
  border-radius: 14px;
  cursor: pointer;
}

.chat-history-toggle:active {
  background: var(--bg-input);
}

.chat-history-header {
  font-size: 13px;
  font-weight: 600;
  color: var(--text-secondary);
  text-align: center;
  padding: 12px 0 8px;
}

.chat-history-item {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 14px;
  margin-bottom: 8px;
  cursor: pointer;
  transition: border-color 0.15s;
}

.chat-history-item:active {
  border-color: var(--accent);
}

.chat-history-date {
  font-size: 13px;
  font-weight: 600;
  color: var(--text-primary);
  margin-bottom: 4px;
}

.chat-history-preview {
  font-size: 12px;
  color: var(--text-secondary);
  line-height: 1.4;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.chat-history-count {
  font-size: 11px;
  color: var(--text-muted);
  margin-top: 4px;
}

.chat-input-wrap.hidden {
  display: none;
}

.chat-messages {
  flex: 1;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  padding: 16px;
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.chat-empty {
  text-align: center;
  color: var(--text-muted);
  font-size: 14px;
  padding: 40px 20px;
  line-height: 1.6;
}

.chat-bubble {
  display: flex;
  gap: 10px;
  max-width: 90%;
  animation: bubbleIn 0.2s ease;
}

@keyframes bubbleIn {
  from { opacity: 0; transform: translateY(8px); }
  to { opacity: 1; transform: translateY(0); }
}

.coach-bubble {
  align-self: flex-start;
}

.user-bubble {
  align-self: flex-end;
  flex-direction: row-reverse;
}

.bubble-icon {
  width: 28px;
  height: 28px;
  border-radius: 14px;
  background: var(--accent-dim);
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--accent);
  flex-shrink: 0;
  margin-top: 2px;
}

.bubble-text {
  padding: 10px 14px;
  border-radius: 16px;
  font-size: 15px;
  line-height: 1.5;
  white-space: pre-wrap;
  word-wrap: break-word;
}

.coach-bubble .bubble-text {
  background: var(--bg-card);
  color: var(--text-primary);
  border-bottom-left-radius: 4px;
}

.user-bubble .bubble-text {
  background: var(--accent);
  color: #000;
  border-bottom-right-radius: 4px;
}

.chat-input-wrap {
  padding: 12px 16px;
  padding-bottom: max(12px, var(--safe-bottom));
  background: var(--bg-secondary);
  border-top: 1px solid var(--border);
}

.chat-input-container {
  display: flex;
  gap: 8px;
  align-items: center;
}

.chat-input {
  flex: 1;
  padding: 10px 16px;
  background: var(--bg-input);
  border: 1px solid var(--border);
  border-radius: 24px;
  color: var(--text-primary);
  font-size: 15px;
  outline: none;
  transition: border-color 0.2s;
}

.chat-input:focus {
  border-color: var(--accent);
}

.chat-send {
  width: 40px;
  height: 40px;
  border-radius: 20px;
  background: var(--accent);
  color: #000;
  border: none;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  transition: opacity 0.2s;
}

.chat-send:disabled {
  opacity: 0.4;
}

.chat-send:active:not(:disabled) {
  opacity: 0.7;
}

/* ── Tab Bar ───────────────────────────────────────────────────────────── */

.tab-bar {
  display: flex;
  justify-content: space-around;
  align-items: center;
  height: var(--tab-height);
  background: var(--bg-secondary);
  border-top: 1px solid var(--border);
  padding-bottom: var(--safe-bottom);
  position: fixed;
  bottom: 0;
  left: 0;
  right: 0;
  max-width: 500px;
  margin: 0 auto;
  z-index: 100;
  transition: transform 0.3s;
}

.tab-bar.chat-open {
  transform: translateY(100%);
}

.tab-btn {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 3px;
  padding: 8px 0;
  background: none;
  border: none;
  color: var(--text-muted);
  cursor: pointer;
  transition: color 0.2s;
  font-size: 10px;
  font-weight: 500;
}

.tab-btn.active {
  color: var(--accent);
}

.tab-icon {
  width: 22px;
  height: 22px;
  fill: currentColor;
}

/* ── HRV Trend Colors ──────────────────────────────────────────────────── */

.trend-up { color: var(--color-excellent); }
.trend-down { color: var(--color-low); }
.trend-stable { color: var(--text-secondary); }

/* ── Responsive ────────────────────────────────────────────────────────── */

@media (min-width: 500px) {
  .tab-bar {
    left: 50%;
    transform: translateX(-50%);
  }
  .tab-bar.chat-open {
    transform: translateX(-50%) translateY(100%);
  }
}

/* PWA standalone mode adjustments */
@media all and (display-mode: standalone) {
  .screen-header {
    padding-top: max(16px, env(safe-area-inset-top));
  }
}
