/* === Variables === */
:root {
  --bg-primary: #0a0a0a;
  --bg-secondary: #1a1a1a;
  --bg-card: #1e1e1e;
  --bg-input: #252525;
  --accent: #00f19f;
  --accent-dim: rgba(0, 241, 159, 0.15);
  --text-primary: #ffffff;
  --text-secondary: #999999;
  --text-muted: #666666;
  --danger: #ff4757;
  --danger-dim: rgba(255, 71, 87, 0.15);
  --border: #2a2a2a;
  --rank-bronze: #cd7f32;
  --rank-silver: #c0c0c0;
  --rank-gold: #ffd700;
  --rank-platinum: #e5e4e2;
  --rank-mithril: #7b68ee;
  --radius: 12px;
  --radius-sm: 8px;
  --nav-height: 72px;
  --safe-bottom: env(safe-area-inset-bottom, 0px);
}

/* === Reset === */
*, *::before, *::after {
  margin: 0;
  padding: 0;
  box-sizing: border-box;
}

html, body {
  height: 100%;
  font-family: 'Inter', -apple-system, BlinkMacSystemFont, sans-serif;
  background: var(--bg-primary);
  color: var(--text-primary);
  -webkit-font-smoothing: antialiased;
  overflow-x: hidden;
}

/* === App Shell === */
#app {
  max-width: 480px;
  margin: 0 auto;
  min-height: 100vh;
  padding-bottom: calc(var(--nav-height) + var(--safe-bottom) + 16px);
}

.view {
  padding: 20px 16px;
  animation: fadeIn 0.2s ease;
}

.view.hidden {
  display: none;
}

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

/* === Bottom Nav === */
#bottom-nav {
  position: fixed;
  bottom: 0;
  left: 0;
  right: 0;
  height: calc(var(--nav-height) + var(--safe-bottom));
  padding-bottom: var(--safe-bottom);
  background: var(--bg-secondary);
  border-top: 1px solid var(--border);
  display: flex;
  justify-content: space-around;
  align-items: center;
  z-index: 100;
}

#bottom-nav.hidden {
  display: none;
}

.nav-btn {
  background: none;
  border: none;
  color: var(--text-muted);
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 4px;
  padding: 8px 16px;
  cursor: pointer;
  transition: color 0.2s;
  font-family: inherit;
  font-size: 11px;
  font-weight: 500;
}

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

.nav-btn svg {
  width: 22px;
  height: 22px;
}

/* === Auth Screen === */
.auth-container {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  min-height: 100vh;
  padding: 24px;
}

.auth-logo {
  font-size: 28px;
  font-weight: 800;
  letter-spacing: -0.5px;
  margin-bottom: 4px;
}

.auth-logo span {
  color: var(--accent);
}

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

.auth-form {
  width: 100%;
  max-width: 340px;
}

.auth-tabs {
  display: flex;
  gap: 0;
  margin-bottom: 24px;
  background: var(--bg-secondary);
  border-radius: var(--radius-sm);
  padding: 3px;
}

.auth-tab {
  flex: 1;
  padding: 10px;
  border: none;
  background: none;
  color: var(--text-secondary);
  font-family: inherit;
  font-size: 14px;
  font-weight: 600;
  cursor: pointer;
  border-radius: 6px;
  transition: all 0.2s;
}

.auth-tab.active {
  background: var(--bg-card);
  color: var(--text-primary);
}

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

.form-group label {
  display: block;
  font-size: 12px;
  font-weight: 500;
  color: var(--text-secondary);
  margin-bottom: 6px;
  text-transform: uppercase;
  letter-spacing: 0.5px;
}

.form-input {
  width: 100%;
  max-width: 100%;
  box-sizing: border-box;
  padding: 12px 14px;
  background: var(--bg-input);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  color: var(--text-primary);
  font-family: inherit;
  font-size: 15px;
  outline: none;
  transition: border-color 0.2s;
  -webkit-appearance: none;
  appearance: none;
}

input[type="date"].form-input {
  color-scheme: dark;
}

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

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

.btn {
  width: 100%;
  padding: 14px;
  border: none;
  border-radius: var(--radius-sm);
  font-family: inherit;
  font-size: 15px;
  font-weight: 600;
  cursor: pointer;
  transition: all 0.2s;
}

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

.btn-primary:hover {
  opacity: 0.9;
}

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

.btn-secondary {
  background: var(--bg-input);
  color: var(--text-primary);
  border: 1px solid var(--border);
}

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

.auth-error {
  color: var(--danger);
  font-size: 13px;
  margin-bottom: 12px;
  min-height: 18px;
}

/* === Dashboard === */
.dash-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 24px;
}

.dash-header h1 {
  font-size: 22px;
  font-weight: 700;
  letter-spacing: -0.3px;
}

.dash-header h1 span {
  color: var(--accent);
}

.dash-greeting {
  font-size: 13px;
  color: var(--text-secondary);
}

/* === Progress Ring === */
.progress-card {
  background: var(--bg-card);
  border-radius: var(--radius);
  padding: 28px 20px;
  text-align: center;
  margin-bottom: 16px;
}

.progress-ring-container {
  position: relative;
  width: 180px;
  height: 180px;
  margin: 0 auto 20px;
}

.progress-ring {
  transform: rotate(-90deg);
}

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

.progress-ring-fill {
  fill: none;
  stroke: var(--accent);
  stroke-width: 10;
  stroke-linecap: round;
  transition: stroke-dashoffset 1s ease;
}

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

.progress-percent {
  font-size: 36px;
  font-weight: 800;
  letter-spacing: -1px;
  line-height: 1;
}

.progress-label {
  font-size: 11px;
  color: var(--text-secondary);
  text-transform: uppercase;
  letter-spacing: 1px;
  margin-top: 4px;
}

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

.progress-meters strong {
  color: var(--text-primary);
  font-weight: 600;
}

/* === Pace Card === */
.pace-card {
  background: var(--bg-card);
  border-radius: var(--radius);
  padding: 20px;
  margin-bottom: 16px;
  display: flex;
  justify-content: space-between;
  align-items: center;
}

.pace-info h3 {
  font-size: 12px;
  color: var(--text-secondary);
  text-transform: uppercase;
  letter-spacing: 0.5px;
  margin-bottom: 4px;
  font-weight: 500;
}

.pace-value {
  font-size: 28px;
  font-weight: 700;
  letter-spacing: -0.5px;
}

.pace-value.ahead {
  color: var(--accent);
}

.pace-value.behind {
  color: var(--danger);
}

.pace-detail {
  font-size: 12px;
  color: var(--text-muted);
  margin-top: 2px;
}

.pace-target {
  text-align: right;
}

.pace-target-label {
  font-size: 11px;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.5px;
}

.pace-target-value {
  font-size: 16px;
  font-weight: 600;
  color: var(--text-secondary);
}

/* === Log Workout Card === */
.log-card {
  background: var(--bg-card);
  border-radius: var(--radius);
  padding: 20px;
  margin-bottom: 16px;
  overflow: hidden;
}

.log-card h3 {
  font-size: 15px;
  font-weight: 600;
  margin-bottom: 16px;
}

.log-row {
  display: flex;
  gap: 12px;
  margin-bottom: 12px;
}

.log-row .form-group {
  flex: 1;
  margin-bottom: 0;
}

.time-inputs {
  display: flex;
  gap: 8px;
  align-items: center;
}

.time-inputs .form-input {
  width: 60px;
  text-align: center;
  padding: 12px 8px;
}

.time-sep {
  color: var(--text-muted);
  font-weight: 600;
}

.log-success {
  color: var(--accent);
  font-size: 13px;
  margin-bottom: 8px;
  min-height: 18px;
}

.log-error {
  color: var(--danger);
  font-size: 13px;
  margin-bottom: 8px;
  min-height: 18px;
}

/* === Rank Badge === */
.rank-badge {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  padding: 4px 10px;
  border-radius: 20px;
  font-size: 12px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.5px;
}

.rank-none {
  background: rgba(102, 102, 102, 0.2);
  color: var(--text-muted);
}

.rank-bronze {
  background: rgba(205, 127, 50, 0.2);
  color: var(--rank-bronze);
}

.rank-silver {
  background: rgba(192, 192, 192, 0.2);
  color: var(--rank-silver);
}

.rank-gold {
  background: rgba(255, 215, 0, 0.2);
  color: var(--rank-gold);
}

.rank-platinum {
  background: rgba(229, 228, 226, 0.2);
  color: var(--rank-platinum);
}

.rank-mithril {
  background: rgba(123, 104, 238, 0.2);
  color: var(--rank-mithril);
}

/* === Weekly Chart === */
.chart-card {
  background: var(--bg-card);
  border-radius: var(--radius);
  padding: 20px;
  margin-bottom: 16px;
}

.chart-card h3 {
  font-size: 15px;
  font-weight: 600;
  margin-bottom: 16px;
}

.weekly-chart {
  display: flex;
  align-items: flex-end;
  gap: 8px;
  height: 100px;
}

.chart-bar-container {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 6px;
  height: 100%;
}

.chart-bar-wrapper {
  flex: 1;
  width: 100%;
  display: flex;
  align-items: flex-end;
  justify-content: center;
}

.chart-bar {
  width: 100%;
  max-width: 32px;
  background: var(--accent);
  border-radius: 4px 4px 0 0;
  min-height: 2px;
  transition: height 0.5s ease;
  opacity: 0.8;
}

.chart-bar.today {
  opacity: 1;
}

.chart-bar.empty {
  background: var(--bg-input);
  min-height: 2px;
}

.chart-day {
  font-size: 11px;
  color: var(--text-muted);
  font-weight: 500;
}

.chart-day.today {
  color: var(--accent);
}

/* === Rank Distribution === */
.ranks-card {
  background: var(--bg-card);
  border-radius: var(--radius);
  padding: 20px;
  margin-bottom: 16px;
}

.ranks-card h3 {
  font-size: 15px;
  font-weight: 600;
  margin-bottom: 16px;
}

.rank-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 8px 0;
}

.rank-row + .rank-row {
  border-top: 1px solid var(--border);
}

.rank-count {
  font-size: 18px;
  font-weight: 700;
  min-width: 32px;
  text-align: right;
}

/* === History View === */
.history-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 20px;
}

.history-header h2 {
  font-size: 22px;
  font-weight: 700;
}

.history-total {
  font-size: 13px;
  color: var(--text-secondary);
}

.workout-item {
  background: var(--bg-card);
  border-radius: var(--radius);
  padding: 16px;
  margin-bottom: 10px;
  display: flex;
  justify-content: space-between;
  align-items: center;
}

.workout-left {
  display: flex;
  flex-direction: column;
  gap: 6px;
}

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

.workout-distance {
  font-size: 20px;
  font-weight: 700;
}

.workout-distance span {
  font-size: 13px;
  font-weight: 400;
  color: var(--text-secondary);
}

.workout-pace {
  font-size: 13px;
  color: var(--text-muted);
}

.workout-right {
  display: flex;
  flex-direction: column;
  align-items: flex-end;
  gap: 8px;
}

.workout-time {
  font-size: 14px;
  color: var(--text-secondary);
  font-weight: 500;
}

.workout-actions {
  display: flex;
  gap: 8px;
}

.workout-action-btn {
  background: none;
  border: none;
  color: var(--text-muted);
  cursor: pointer;
  padding: 4px;
  transition: color 0.2s;
}

.workout-action-btn:hover {
  color: var(--text-primary);
}

.workout-action-btn.delete:hover {
  color: var(--danger);
}

.empty-state {
  text-align: center;
  padding: 48px 20px;
  color: var(--text-muted);
}

.empty-state p {
  font-size: 15px;
  margin-bottom: 4px;
}

.empty-state small {
  font-size: 13px;
}

/* === Leaderboard === */
.leaderboard-item {
  background: var(--bg-card);
  border-radius: var(--radius);
  padding: 14px 16px;
  margin-bottom: 8px;
  display: flex;
  align-items: center;
  gap: 12px;
}

.leaderboard-me {
  border: 1px solid var(--accent);
  background: rgba(0, 241, 159, 0.05);
}

.leaderboard-position {
  flex-shrink: 0;
  width: 32px;
  text-align: center;
}

.pos-badge {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 28px;
  height: 28px;
  border-radius: 50%;
  font-size: 13px;
  font-weight: 700;
  background: var(--bg-input);
  color: var(--text-muted);
}

.pos-gold {
  background: rgba(255, 215, 0, 0.2);
  color: var(--rank-gold);
}

.pos-silver {
  background: rgba(192, 192, 192, 0.2);
  color: var(--rank-silver);
}

.pos-bronze {
  background: rgba(205, 127, 50, 0.2);
  color: var(--rank-bronze);
}

.leaderboard-avatar {
  width: 36px;
  height: 36px;
  border-radius: 50%;
  background: var(--bg-input);
  color: var(--text-secondary);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 15px;
  font-weight: 600;
  flex-shrink: 0;
}

.leaderboard-me .leaderboard-avatar {
  background: var(--accent-dim);
  color: var(--accent);
}

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

.leaderboard-name {
  font-size: 14px;
  font-weight: 600;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.leaderboard-you {
  font-size: 11px;
  font-weight: 500;
  color: var(--accent);
  background: var(--accent-dim);
  padding: 1px 6px;
  border-radius: 4px;
  margin-left: 4px;
}

.leaderboard-meta {
  font-size: 12px;
  color: var(--text-muted);
  margin-top: 2px;
}

.leaderboard-stats {
  text-align: right;
  flex-shrink: 0;
}

.leaderboard-meters {
  font-size: 15px;
  font-weight: 700;
}

.leaderboard-pct {
  font-size: 12px;
  color: var(--accent);
  margin-top: 2px;
}

/* === Profile View === */
.profile-header {
  text-align: center;
  margin-bottom: 32px;
  padding-top: 20px;
}

.profile-avatar {
  width: 72px;
  height: 72px;
  border-radius: 50%;
  background: var(--accent-dim);
  color: var(--accent);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 28px;
  font-weight: 700;
  margin: 0 auto 12px;
}

.profile-name {
  font-size: 20px;
  font-weight: 700;
}

.profile-email {
  font-size: 13px;
  color: var(--text-secondary);
  margin-top: 2px;
}

.profile-stats {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 12px;
  margin-bottom: 24px;
}

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

.profile-stat-value {
  font-size: 22px;
  font-weight: 700;
}

.profile-stat-label {
  font-size: 12px;
  color: var(--text-secondary);
  text-transform: uppercase;
  letter-spacing: 0.5px;
  margin-top: 4px;
}

.profile-actions {
  margin-top: 32px;
}

.profile-actions .btn {
  margin-bottom: 12px;
}

/* === Loading === */
.loading {
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 40px;
}

.spinner {
  width: 32px;
  height: 32px;
  border: 3px solid var(--border);
  border-top-color: var(--accent);
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
}

@keyframes spin {
  to { transform: rotate(360deg); }
}

/* === Toast === */
.toast {
  position: fixed;
  bottom: calc(var(--nav-height) + var(--safe-bottom) + 16px);
  left: 50%;
  transform: translateX(-50%) translateY(100px);
  background: var(--bg-card);
  border: 1px solid var(--border);
  color: var(--text-primary);
  padding: 12px 20px;
  border-radius: var(--radius-sm);
  font-size: 14px;
  font-weight: 500;
  z-index: 200;
  transition: transform 0.3s ease;
  pointer-events: none;
}

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

/* === Scrollbar === */
::-webkit-scrollbar {
  width: 4px;
}

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

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

/* === Edit Modal === */
.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.7);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 300;
  padding: 20px;
  animation: fadeIn 0.15s ease;
}

.modal {
  background: var(--bg-card);
  border-radius: var(--radius);
  padding: 24px;
  width: 100%;
  max-width: 400px;
}

.modal h3 {
  font-size: 17px;
  font-weight: 600;
  margin-bottom: 20px;
}

.modal-actions {
  display: flex;
  gap: 12px;
  margin-top: 20px;
}

.modal-actions .btn {
  flex: 1;
}
