:root {
  --bg-primary: #0f0f1a;
  --bg-secondary: #1a1a2e;
  --bg-card: #16213e;
  --bg-input: #1a1a3e;
  --accent: #6c63ff;
  --accent-light: #8b83ff;
  --accent-dark: #4a42d4;
  --green: #00c896;
  --green-dark: #00a87d;
  --orange: #ff8c42;
  --red: #ff5252;
  --yellow: #ffd93d;
  --text-primary: #e8e8f0;
  --text-secondary: #9595a8;
  --text-muted: #6b6b80;
  --border: #2a2a40;
  --shadow: 0 4px 24px rgba(0,0,0,0.4);
  --radius: 12px;
  --radius-sm: 8px;
  --transition: 0.25s ease;
}

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

body {
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', system-ui, sans-serif;
  background: var(--bg-primary);
  color: var(--text-primary);
  min-height: 100vh;
  min-height: 100dvh;
  overflow-x: hidden;
}

/* ── Header ── */
.app-header {
  position: sticky;
  top: 0;
  z-index: 100;
  background: var(--bg-secondary);
  border-bottom: 1px solid var(--border);
  padding: 12px 16px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  backdrop-filter: blur(10px);
}

.app-header h1 {
  font-size: 20px;
  font-weight: 700;
  background: linear-gradient(135deg, var(--accent), var(--green));
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  background-clip: text;
}

.header-actions {
  display: flex;
  gap: 8px;
  align-items: center;
}

.btn-icon {
  width: 36px;
  height: 36px;
  border-radius: 50%;
  border: none;
  background: var(--bg-card);
  color: var(--text-secondary);
  font-size: 18px;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: var(--transition);
}

.btn-icon:hover {
  background: var(--accent);
  color: white;
}

.install-btn {
  display: none;
  padding: 6px 14px;
  border-radius: 20px;
  border: 1px solid var(--accent);
  background: transparent;
  color: var(--accent);
  font-size: 12px;
  font-weight: 600;
  cursor: pointer;
  transition: var(--transition);
}

.install-btn.show { display: block; }
.install-btn:hover {
  background: var(--accent);
  color: white;
}

/* ── Tab Navigation ── */
.tab-nav {
  position: fixed;
  bottom: 0;
  left: 0;
  right: 0;
  z-index: 100;
  background: var(--bg-secondary);
  border-top: 1px solid var(--border);
  display: flex;
  justify-content: space-around;
  padding: 8px 0 max(8px, env(safe-area-inset-bottom));
}

.tab-btn {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 2px;
  padding: 8px 4px;
  border: none;
  background: none;
  color: var(--text-muted);
  font-size: 10px;
  font-weight: 600;
  cursor: pointer;
  transition: var(--transition);
  position: relative;
}

.tab-btn .tab-icon { font-size: 22px; line-height: 1; }

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

.tab-btn.active::before {
  content: '';
  position: absolute;
  top: -1px;
  left: 25%;
  right: 25%;
  height: 2px;
  background: var(--accent);
  border-radius: 1px;
}

/* ── Main Content ── */
.app-content {
  padding: 16px;
  padding-bottom: calc(80px + env(safe-area-inset-bottom));
  max-width: 800px;
  margin: 0 auto;
}

.view { display: none; }
.view.active { display: block; }

/* ── Cards ── */
.card {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 16px;
  margin-bottom: 16px;
  box-shadow: var(--shadow);
}

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

/* ── Stats Grid ── */
.stats-grid {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 12px;
  margin-bottom: 16px;
}

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

.stat-card:hover {
  border-color: var(--accent);
  transform: translateY(-2px);
}

.stat-icon { font-size: 28px; margin-bottom: 4px; }

.stat-value {
  font-size: 28px;
  font-weight: 800;
  color: var(--text-primary);
  line-height: 1.2;
}

.stat-label {
  font-size: 12px;
  color: var(--text-secondary);
  margin-top: 2px;
}

/* ── Workout Type Pills ── */
.type-pills {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-bottom: 16px;
}

.type-pill {
  padding: 8px 16px;
  border-radius: 24px;
  border: 2px solid var(--border);
  background: none;
  color: var(--text-secondary);
  font-size: 13px;
  font-weight: 600;
  cursor: pointer;
  transition: var(--transition);
}

.type-pill.selected {
  border-color: var(--accent);
  background: var(--accent);
  color: white;
}

.type-pill:hover:not(.selected) {
  border-color: var(--accent-light);
}

/* ── Form Elements ── */
.form-group {
  margin-bottom: 16px;
}

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

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

.form-input:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px rgba(108, 99, 255, 0.2);
}

.form-input::placeholder {
  color: var(--text-muted);
}

.form-row {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 12px;
}

textarea.form-input {
  resize: vertical;
  min-height: 80px;
  font-family: inherit;
}

/* ── Buttons ── */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  padding: 12px 24px;
  border-radius: var(--radius-sm);
  border: none;
  font-size: 14px;
  font-weight: 700;
  cursor: pointer;
  transition: var(--transition);
  text-transform: uppercase;
  letter-spacing: 0.5px;
}

.btn-primary {
  background: linear-gradient(135deg, var(--accent), var(--accent-dark));
  color: white;
}

.btn-primary:hover {
  transform: translateY(-1px);
  box-shadow: 0 4px 16px rgba(108, 99, 255, 0.4);
}

.btn-success {
  background: linear-gradient(135deg, var(--green), var(--green-dark));
  color: white;
}

.btn-outline {
  background: transparent;
  border: 1px solid var(--border);
  color: var(--text-secondary);
}

.btn-outline:hover {
  border-color: var(--accent);
  color: var(--accent);
}

.btn-full { width: 100%; }

.btn-sm {
  padding: 8px 14px;
  font-size: 12px;
}

.btn-danger {
  background: var(--red);
  color: white;
}

/* ── Workout History List ── */
.workout-item {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 14px;
  border-radius: var(--radius-sm);
  background: var(--bg-secondary);
  margin-bottom: 10px;
  border: 1px solid var(--border);
  transition: var(--transition);
}

.workout-item:hover {
  border-color: var(--accent);
}

.workout-type-icon {
  width: 44px;
  height: 44px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 22px;
  flex-shrink: 0;
}

.workout-type-icon.running { background: rgba(255, 140, 66, 0.2); }
.workout-type-icon.weightlifting { background: rgba(108, 99, 255, 0.2); }
.workout-type-icon.cycling { background: rgba(0, 200, 150, 0.2); }
.workout-type-icon.swimming { background: rgba(0, 150, 255, 0.2); }
.workout-type-icon.yoga { background: rgba(255, 217, 61, 0.2); }
.workout-type-icon.hiit { background: rgba(255, 82, 82, 0.2); }
.workout-type-icon.other { background: rgba(149, 149, 168, 0.2); }

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

.workout-info h3 {
  font-size: 14px;
  font-weight: 700;
  margin-bottom: 2px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.workout-meta {
  font-size: 12px;
  color: var(--text-secondary);
}

.workout-stats {
  display: flex;
  gap: 12px;
  flex-shrink: 0;
}

.workout-stat {
  text-align: right;
}

.workout-stat-value {
  font-size: 14px;
  font-weight: 700;
  color: var(--accent);
}

.workout-stat-label {
  font-size: 10px;
  color: var(--text-muted);
}

.workout-actions {
  display: flex;
  gap: 4px;
  flex-shrink: 0;
}

/* ── Chart Container ── */
.chart-container {
  position: relative;
  width: 100%;
  height: 250px;
  margin-bottom: 16px;
}

.chart-container canvas {
  width: 100% !important;
  height: 100% !important;
}

/* ── Goals ── */
.goal-card {
  background: var(--bg-secondary);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 16px;
  margin-bottom: 12px;
}

.goal-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 10px;
}

.goal-title {
  font-size: 15px;
  font-weight: 700;
}

.goal-badge {
  font-size: 11px;
  padding: 3px 10px;
  border-radius: 12px;
  font-weight: 700;
}

.goal-badge.active {
  background: rgba(108, 99, 255, 0.2);
  color: var(--accent);
}

.goal-badge.completed {
  background: rgba(0, 200, 150, 0.2);
  color: var(--green);
}

.goal-badge.overdue {
  background: rgba(255, 82, 82, 0.2);
  color: var(--red);
}

.goal-progress-bar {
  width: 100%;
  height: 10px;
  background: var(--bg-primary);
  border-radius: 5px;
  overflow: hidden;
  margin: 10px 0;
}

.goal-progress-fill {
  height: 100%;
  border-radius: 5px;
  background: linear-gradient(90deg, var(--accent), var(--green));
  transition: width 0.6s ease;
}

.goal-milestones {
  display: flex;
  justify-content: space-between;
  margin-top: 8px;
  position: relative;
}

.milestone {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 4px;
  position: relative;
  z-index: 1;
}

.milestone-dot {
  width: 16px;
  height: 16px;
  border-radius: 50%;
  border: 2px solid var(--border);
  background: var(--bg-primary);
  transition: var(--transition);
}

.milestone-dot.reached {
  border-color: var(--green);
  background: var(--green);
  box-shadow: 0 0 8px rgba(0, 200, 150, 0.4);
}

.milestone-dot.current {
  border-color: var(--accent);
  background: var(--accent);
  animation: pulse 2s infinite;
}

@keyframes pulse {
  0%, 100% { box-shadow: 0 0 0 0 rgba(108, 99, 255, 0.4); }
  50% { box-shadow: 0 0 0 8px rgba(108, 99, 255, 0); }
}

.milestone-label {
  font-size: 10px;
  color: var(--text-muted);
  white-space: nowrap;
}

.goal-details {
  font-size: 12px;
  color: var(--text-secondary);
  margin-top: 8px;
}

/* ── Share Card ── */
.share-card-preview {
  background: linear-gradient(135deg, var(--bg-card), var(--bg-secondary));
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 24px;
  text-align: center;
  margin-bottom: 16px;
  position: relative;
  overflow: hidden;
}

.share-card-preview::before {
  content: '';
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  height: 4px;
  background: linear-gradient(90deg, var(--accent), var(--green));
}

.share-card-title {
  font-size: 20px;
  font-weight: 800;
  margin-bottom: 8px;
}

.share-card-type {
  font-size: 13px;
  color: var(--accent);
  font-weight: 600;
  margin-bottom: 16px;
}

.share-card-stats {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 12px;
  margin-bottom: 16px;
}

.share-stat-value {
  font-size: 22px;
  font-weight: 800;
  color: var(--accent);
}

.share-stat-label {
  font-size: 11px;
  color: var(--text-secondary);
}

/* ── Pedometer ── */
.step-counter {
  text-align: center;
  padding: 20px;
}

.step-ring {
  width: 140px;
  height: 140px;
  margin: 0 auto 12px;
  position: relative;
}

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

.step-ring circle {
  fill: none;
  stroke-width: 8;
}

.step-ring-bg {
  stroke: var(--border);
}

.step-ring-fill {
  stroke: var(--green);
  stroke-linecap: round;
  transition: stroke-dashoffset 0.6s ease;
}

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

.step-count-value {
  font-size: 32px;
  font-weight: 800;
  color: var(--text-primary);
  line-height: 1;
}

.step-count-label {
  font-size: 11px;
  color: var(--text-secondary);
}

/* ── Modal ── */
.modal-overlay {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.7);
  z-index: 200;
  align-items: center;
  justify-content: center;
  padding: 16px;
}

.modal-overlay.show {
  display: flex;
}

.modal {
  background: var(--bg-secondary);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 24px;
  width: 100%;
  max-width: 440px;
  max-height: 90vh;
  overflow-y: auto;
  box-shadow: 0 8px 40px rgba(0,0,0,0.6);
}

.modal-title {
  font-size: 18px;
  font-weight: 700;
  margin-bottom: 20px;
}

/* ── Toast ── */
.toast {
  position: fixed;
  bottom: 90px;
  left: 50%;
  transform: translateX(-50%) translateY(100px);
  background: var(--bg-card);
  border: 1px solid var(--border);
  color: var(--text-primary);
  padding: 12px 24px;
  border-radius: 24px;
  font-size: 14px;
  font-weight: 600;
  z-index: 300;
  opacity: 0;
  transition: all 0.3s ease;
  white-space: nowrap;
}

.toast.show {
  transform: translateX(-50%) translateY(0);
  opacity: 1;
}

/* ── Empty State ── */
.empty-state {
  text-align: center;
  padding: 48px 24px;
  color: var(--text-muted);
}

.empty-state-icon {
  font-size: 48px;
  margin-bottom: 12px;
}

.empty-state-text {
  font-size: 14px;
}

/* ── Date Group ── */
.date-group-header {
  font-size: 13px;
  font-weight: 700;
  color: var(--text-muted);
  margin: 16px 0 8px;
  text-transform: uppercase;
  letter-spacing: 0.5px;
}

/* ── Responsive ── */
@media (min-width: 600px) {
  .stats-grid {
    grid-template-columns: repeat(4, 1fr);
  }
  .chart-container {
    height: 300px;
  }
  .share-card-stats {
    grid-template-columns: repeat(4, 1fr);
  }
}

/* ── Scrollbar ── */
::-webkit-scrollbar {
  width: 6px;
}

::-webkit-scrollbar-track {
  background: transparent;
}

::-webkit-scrollbar-thumb {
  background: var(--border);
  border-radius: 3px;
}

/* ── Animations ── */
@keyframes fadeIn {
  from { opacity: 0; transform: translateY(10px); }
  to { opacity: 1; transform: translateY(0); }
}

.view.active {
  animation: fadeIn 0.3s ease;
}

/* ── Offline Indicator ── */
.offline-bar {
  display: none;
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  z-index: 150;
  background: var(--orange);
  color: white;
  text-align: center;
  padding: 4px;
  font-size: 12px;
  font-weight: 600;
}

.offline-bar.show {
  display: block;
}

/* ── Body Weight Input ── */
.weight-input-row {
  display: flex;
  gap: 8px;
  align-items: flex-end;
}

.weight-input-row .form-input {
  flex: 1;
}

/* ── Filter Pills ── */
.filter-pills {
  display: flex;
  gap: 6px;
  overflow-x: auto;
  padding: 4px 0;
  margin-bottom: 12px;
  -webkit-overflow-scrolling: touch;
}

.filter-pill {
  padding: 6px 14px;
  border-radius: 16px;
  border: 1px solid var(--border);
  background: none;
  color: var(--text-secondary);
  font-size: 12px;
  font-weight: 600;
  cursor: pointer;
  white-space: nowrap;
  transition: var(--transition);
}

.filter-pill.active {
  background: var(--accent);
  border-color: var(--accent);
  color: white;
}
