/* ==========================================================================
   Stationary Bike Tracker - Mobile-First Stylesheet
   ========================================================================== */

:root {
  --bg-main: #0b0f19;
  --bg-card: #151d30;
  --bg-card-hover: #1c263e;
  --bg-input: #101726;
  --border: #243049;
  --border-focus: #10b981;
  --text-primary: #f8fafc;
  --text-secondary: #94a3b8;
  --text-muted: #64748b;
  --accent-emerald: #10b981;
  --accent-emerald-dark: #059669;
  --accent-cyan: #06b6d4;
  --accent-amber: #f59e0b;
  --accent-rose: #f43f5e;
  --accent-violet: #8b5cf6;
  --radius-sm: 8px;
  --radius-md: 14px;
  --radius-lg: 20px;
  --radius-full: 9999px;
  --shadow-card: 0 4px 20px -2px rgba(0, 0, 0, 0.4);
  --tab-height: 64px;
  --header-height: 58px;
  --safe-bottom: env(safe-area-inset-bottom, 0px);
}

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

html, body {
  height: 100%;
  background-color: #050811;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  color: var(--text-primary);
  line-height: 1.45;
  -webkit-font-smoothing: antialiased;
}

/* Mobile viewport constraint for larger screens */
.app-container {
  max-width: 480px;
  min-height: 100vh;
  margin: 0 auto;
  background-color: var(--bg-main);
  position: relative;
  display: flex;
  flex-direction: column;
  box-shadow: 0 0 50px rgba(0, 0, 0, 0.6);
}

/* ==========================================================================
   Header
   ========================================================================== */
.app-header {
  position: sticky;
  top: 0;
  z-index: 40;
  height: var(--header-height);
  background: rgba(15, 23, 42, 0.85);
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 16px;
}

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

.brand-icon-box {
  width: 34px;
  height: 34px;
  border-radius: var(--radius-sm);
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  overflow: hidden;
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.3);
}

.brand-icon-box img,
.brand-icon-img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  display: block;
}

.brand-title {
  font-size: 1.05rem;
  font-weight: 700;
  letter-spacing: -0.01em;
  color: var(--text-primary);
}

.brand-subtitle {
  font-size: 0.68rem;
  font-weight: 600;
  color: var(--accent-emerald);
  text-transform: uppercase;
  letter-spacing: 0.05em;
  display: block;
  margin-top: -2px;
}

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

/* Status Pill */
.status-pill {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 4px 10px;
  border-radius: var(--radius-full);
  font-size: 0.75rem;
  font-weight: 600;
  background-color: rgba(16, 185, 129, 0.12);
  color: var(--accent-emerald);
  border: 1px solid rgba(16, 185, 129, 0.3);
  transition: all 0.2s ease;
}

.status-dot {
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background-color: var(--accent-emerald);
  box-shadow: 0 0 8px var(--accent-emerald);
}

.status-pill.offline {
  background-color: rgba(245, 158, 11, 0.15);
  color: var(--accent-amber);
  border-color: rgba(245, 158, 11, 0.35);
}

.status-pill.offline .status-dot {
  background-color: var(--accent-amber);
  box-shadow: 0 0 8px var(--accent-amber);
}

.sync-badge {
  display: none;
  background-color: var(--accent-amber);
  color: #000;
  font-size: 0.65rem;
  font-weight: 800;
  padding: 1px 5px;
  border-radius: var(--radius-full);
  margin-left: 2px;
}

.sync-badge.visible {
  display: inline-block;
}

/* Icon Buttons */
.btn-icon {
  background: transparent;
  border: none;
  color: var(--text-secondary);
  padding: 6px;
  border-radius: var(--radius-sm);
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: background 0.15s, color 0.15s;
}

.btn-icon:hover, .btn-icon:active {
  background: var(--border);
  color: var(--text-primary);
}

.btn-icon svg {
  width: 18px;
  height: 18px;
}

/* ==========================================================================
   Main Content Area
   ========================================================================== */
.main-content {
  flex: 1;
  padding: 16px 16px calc(var(--tab-height) + var(--safe-bottom) + 20px) 16px;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
}

.tab-pane {
  display: none;
  animation: fadeIn 0.22s ease-out forwards;
}

.tab-pane.active {
  display: block;
}

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

.page-header {
  margin-bottom: 20px;
}

.page-header h2 {
  font-size: 1.35rem;
  font-weight: 700;
  letter-spacing: -0.02em;
  color: var(--text-primary);
}

.page-header p {
  color: var(--text-secondary);
  font-size: 0.85rem;
  margin-top: 3px;
}

/* ==========================================================================
   Form Styles (Record Workout)
   ========================================================================== */
.workout-form {
  display: flex;
  flex-direction: column;
  gap: 16px;
}

.form-group {
  display: flex;
  flex-direction: column;
  gap: 6px;
}

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

.form-label {
  font-size: 0.8rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: var(--text-secondary);
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.form-label .unit {
  font-size: 0.75rem;
  text-transform: none;
  color: var(--text-muted);
  font-weight: 500;
}

.input-wrapper {
  position: relative;
  display: flex;
  align-items: center;
}

.input-control,
.select-control {
  width: 100%;
  height: 48px;
  background-color: var(--bg-input);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  color: var(--text-primary);
  font-size: 1.05rem;
  font-weight: 600;
  padding: 0 14px;
  outline: none;
  transition: border-color 0.2s, box-shadow 0.2s;
  -webkit-appearance: none;
  appearance: none;
}

.input-control:focus,
.select-control:focus {
  border-color: var(--accent-emerald);
  box-shadow: 0 0 0 3px rgba(16, 185, 129, 0.2);
}

.input-control::placeholder {
  color: var(--text-muted);
  font-weight: 400;
}

/* Select Dropdown */
.select-wrapper {
  position: relative;
}

.select-wrapper::after {
  content: "";
  position: absolute;
  right: 16px;
  top: 50%;
  transform: translateY(-50%);
  width: 8px;
  height: 8px;
  border-right: 2px solid var(--text-secondary);
  border-bottom: 2px solid var(--text-secondary);
  transform: translateY(-70%) rotate(45deg);
  pointer-events: none;
}

.select-control {
  padding-right: 36px;
  cursor: pointer;
}

/* Range Slider Control */
.slider-container {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  padding: 14px 16px;
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.slider-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.slider-badge {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 32px;
  height: 26px;
  padding: 0 8px;
  border-radius: var(--radius-full);
  background-color: rgba(16, 185, 129, 0.15);
  color: var(--accent-emerald);
  font-size: 0.85rem;
  font-weight: 700;
  border: 1px solid rgba(16, 185, 129, 0.3);
}

.slider-badge.load-badge {
  background-color: rgba(6, 182, 212, 0.15);
  color: var(--accent-cyan);
  border-color: rgba(6, 182, 212, 0.3);
}

.slider-controls-row {
  display: flex;
  align-items: center;
  gap: 12px;
}

.step-btn {
  width: 34px;
  height: 34px;
  border-radius: var(--radius-sm);
  background: var(--bg-input);
  border: 1px solid var(--border);
  color: var(--text-primary);
  font-size: 1.15rem;
  font-weight: 600;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  flex-shrink: 0;
  touch-action: manipulation;
}

.step-btn:active {
  background: var(--border);
  transform: scale(0.95);
}

.range-input {
  flex: 1;
  -webkit-appearance: none;
  appearance: none;
  height: 8px;
  border-radius: var(--radius-full);
  background: var(--bg-input);
  outline: none;
  cursor: pointer;
}

/* Range input track & thumb */
.range-input::-webkit-slider-thumb {
  -webkit-appearance: none;
  appearance: none;
  width: 26px;
  height: 26px;
  border-radius: 50%;
  background: var(--accent-emerald);
  border: 3px solid #ffffff;
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.4);
  cursor: pointer;
  transition: transform 0.1s ease;
}

.range-input.load-slider::-webkit-slider-thumb {
  background: var(--accent-cyan);
}

.range-input:active::-webkit-slider-thumb {
  transform: scale(1.15);
}

.range-input::-moz-range-thumb {
  width: 26px;
  height: 26px;
  border-radius: 50%;
  background: var(--accent-emerald);
  border: 3px solid #ffffff;
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.4);
  cursor: pointer;
}

.range-scale-markers {
  display: flex;
  justify-content: space-between;
  padding: 0 4px;
  font-size: 0.68rem;
  font-weight: 600;
  color: var(--text-muted);
}

/* Submit Button */
.btn-submit {
  margin-top: 8px;
  height: 52px;
  border: none;
  border-radius: var(--radius-md);
  background: linear-gradient(135deg, var(--accent-emerald), var(--accent-emerald-dark));
  color: #ffffff;
  font-size: 1.05rem;
  font-weight: 700;
  letter-spacing: 0.01em;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 10px;
  cursor: pointer;
  box-shadow: 0 4px 16px rgba(16, 185, 129, 0.35);
  transition: transform 0.15s, opacity 0.2s, box-shadow 0.2s;
  touch-action: manipulation;
}

.btn-submit:hover {
  box-shadow: 0 6px 20px rgba(16, 185, 129, 0.45);
}

.btn-submit:active {
  transform: scale(0.98);
}

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

.btn-submit .spinner {
  display: none;
  width: 18px;
  height: 18px;
  border: 2px solid rgba(255, 255, 255, 0.3);
  border-top-color: #ffffff;
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
}

.btn-submit.loading .spinner {
  display: inline-block;
}

.btn-submit.loading .btn-text {
  opacity: 0.8;
}

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

/* ==========================================================================
   Tab 2: Stats Page
   ========================================================================== */
.period-switch-container {
  margin-bottom: 18px;
}

.segmented-control {
  display: flex;
  background-color: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  padding: 4px;
  position: relative;
}

.segmented-btn {
  flex: 1;
  height: 38px;
  background: transparent;
  border: none;
  border-radius: var(--radius-sm);
  color: var(--text-secondary);
  font-size: 0.85rem;
  font-weight: 600;
  cursor: pointer;
  transition: all 0.2s ease;
  position: relative;
  z-index: 2;
}

.segmented-btn.active {
  background-color: var(--accent-emerald);
  color: #ffffff;
  box-shadow: 0 2px 8px rgba(16, 185, 129, 0.3);
}

/* Stats Cards Section */
.stats-section-title {
  font-size: 0.78rem;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  font-weight: 700;
  color: var(--text-muted);
  margin: 18px 0 10px 2px;
}

.totals-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 12px;
  margin-bottom: 16px;
}

.totals-grid .stat-card.full-width {
  grid-column: span 2;
}

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

.averages-grid .stat-card.full-width {
  grid-column: span 2;
}

.stat-card {
  background-color: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  padding: 16px;
  display: flex;
  flex-direction: column;
  justify-content: space-between;
  box-shadow: var(--shadow-card);
  position: relative;
  overflow: hidden;
}

.stat-card.highlight {
  background: linear-gradient(145deg, #152238 0%, #151d30 100%);
  border-color: rgba(16, 185, 129, 0.35);
}

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

.stat-card-title {
  font-size: 0.78rem;
  font-weight: 600;
  color: var(--text-secondary);
  text-transform: uppercase;
  letter-spacing: 0.03em;
}

.stat-card-icon {
  width: 28px;
  height: 28px;
  border-radius: var(--radius-sm);
  background: rgba(255, 255, 255, 0.05);
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--accent-emerald);
}

.stat-card-icon.cyan { color: var(--accent-cyan); }
.stat-card-icon.amber { color: var(--accent-amber); }
.stat-card-icon.violet { color: var(--accent-violet); }

.stat-card-icon svg {
  width: 16px;
  height: 16px;
}

.stat-value {
  font-size: 1.6rem;
  font-weight: 800;
  letter-spacing: -0.02em;
  color: var(--text-primary);
  display: flex;
  align-items: baseline;
  gap: 4px;
}

.stat-card.highlight .stat-value {
  color: #ffffff;
  font-size: 1.8rem;
}

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

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

/* ==========================================================================
   Tab 3: Recent Workouts
   ========================================================================== */
.recent-header-bar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 16px;
}

.workouts-list {
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.workout-card {
  background-color: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  padding: 16px;
  box-shadow: var(--shadow-card);
  transition: transform 0.15s, border-color 0.15s;
}

.workout-card:active {
  transform: scale(0.99);
}

.workout-card-top {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 12px;
  padding-bottom: 8px;
  border-bottom: 1px solid rgba(255, 255, 255, 0.05);
}

.workout-date-group {
  display: flex;
  align-items: center;
  gap: 8px;
}

.workout-date-icon {
  color: var(--accent-emerald);
}

.workout-date-icon svg {
  width: 14px;
  height: 14px;
}

.workout-date-text {
  font-size: 0.82rem;
  font-weight: 600;
  color: var(--text-primary);
}

.workout-badges {
  display: flex;
  align-items: center;
  gap: 6px;
}

.badge-tag {
  font-size: 0.7rem;
  font-weight: 700;
  padding: 2px 8px;
  border-radius: var(--radius-full);
}

.badge-tag.type {
  background-color: rgba(255, 255, 255, 0.08);
  color: var(--text-secondary);
}

.badge-tag.sync-pending {
  background-color: rgba(245, 158, 11, 0.2);
  color: var(--accent-amber);
  border: 1px solid rgba(245, 158, 11, 0.4);
}

.workout-metrics-row {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 8px;
  margin-bottom: 12px;
}

.metric-item {
  display: flex;
  flex-direction: column;
}

.metric-label {
  font-size: 0.68rem;
  font-weight: 600;
  text-transform: uppercase;
  color: var(--text-muted);
}

.metric-val {
  font-size: 1.15rem;
  font-weight: 700;
  color: var(--text-primary);
  margin-top: 1px;
}

.metric-val small {
  font-size: 0.72rem;
  font-weight: 500;
  color: var(--text-muted);
  margin-left: 1px;
}

.workout-settings-row {
  display: flex;
  align-items: center;
  gap: 8px;
  background-color: var(--bg-input);
  padding: 8px 12px;
  border-radius: var(--radius-sm);
  font-size: 0.76rem;
  color: var(--text-secondary);
}

.chip-setting {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  font-weight: 600;
}

.chip-setting .chip-val {
  color: var(--accent-emerald);
  font-weight: 700;
}

.chip-setting.load .chip-val {
  color: var(--accent-cyan);
}

.chip-divider {
  width: 3px;
  height: 3px;
  border-radius: 50%;
  background: var(--text-muted);
}

/* Empty State */
.empty-state {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  text-align: center;
  padding: 48px 16px;
  background: var(--bg-card);
  border: 1px dashed var(--border);
  border-radius: var(--radius-lg);
  margin-top: 10px;
}

.empty-icon-box {
  width: 60px;
  height: 60px;
  border-radius: 50%;
  background: rgba(16, 185, 129, 0.1);
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--accent-emerald);
  margin-bottom: 14px;
}

.empty-icon-box svg {
  width: 30px;
  height: 30px;
}

.empty-title {
  font-size: 1.05rem;
  font-weight: 700;
  color: var(--text-primary);
  margin-bottom: 4px;
}

.empty-text {
  font-size: 0.82rem;
  color: var(--text-secondary);
  max-width: 240px;
  margin-bottom: 18px;
}

.btn-secondary {
  background: var(--bg-input);
  border: 1px solid var(--border);
  color: var(--text-primary);
  padding: 8px 18px;
  border-radius: var(--radius-full);
  font-size: 0.85rem;
  font-weight: 600;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  gap: 6px;
}

.btn-secondary:active {
  background: var(--border);
}

/* Loading skeleton */
.skeleton {
  background: linear-gradient(90deg, #151d30 25%, #1e293b 50%, #151d30 75%);
  background-size: 200% 100%;
  animation: loadingSkeleton 1.4s infinite;
  border-radius: var(--radius-sm);
}

@keyframes loadingSkeleton {
  0% { background-position: 200% 0; }
  100% { background-position: -200% 0; }
}

/* ==========================================================================
   Bottom Navigation Tab Bar
   ========================================================================== */
.bottom-tab-bar {
  position: fixed;
  bottom: 0;
  left: 0;
  right: 0;
  max-width: 480px;
  margin: 0 auto;
  height: calc(var(--tab-height) + var(--safe-bottom));
  padding-bottom: var(--safe-bottom);
  background: rgba(15, 23, 42, 0.94);
  backdrop-filter: blur(16px);
  -webkit-backdrop-filter: blur(16px);
  border-top: 1px solid var(--border);
  display: flex;
  align-items: center;
  justify-content: space-around;
  z-index: 50;
}

.tab-btn {
  flex: 1;
  height: 100%;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 4px;
  background: transparent;
  border: none;
  color: var(--text-muted);
  cursor: pointer;
  position: relative;
  transition: color 0.15s ease;
  touch-action: manipulation;
}

.tab-icon-wrapper {
  position: relative;
  display: flex;
  align-items: center;
  justify-content: center;
  width: 26px;
  height: 26px;
}

.tab-btn svg {
  width: 22px;
  height: 22px;
  transition: transform 0.15s ease, stroke 0.15s ease;
}

.tab-label {
  font-size: 0.7rem;
  font-weight: 600;
  letter-spacing: 0.01em;
}

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

.tab-btn.active svg {
  transform: scale(1.08);
}

.tab-btn.active::after {
  content: "";
  position: absolute;
  top: 0;
  width: 32px;
  height: 3px;
  background: var(--accent-emerald);
  border-radius: 0 0 3px 3px;
  box-shadow: 0 0 10px var(--accent-emerald);
}

/* ==========================================================================
   Toast Notifications
   ========================================================================== */
.toast-container {
  position: fixed;
  top: 16px;
  left: 50%;
  transform: translateX(-50%);
  width: calc(100% - 32px);
  max-width: 440px;
  z-index: 100;
  pointer-events: none;
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.toast {
  pointer-events: auto;
  padding: 12px 16px;
  border-radius: var(--radius-md);
  font-size: 0.85rem;
  font-weight: 600;
  display: flex;
  align-items: center;
  gap: 10px;
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.4);
  animation: slideDown 0.25s cubic-bezier(0.16, 1, 0.3, 1) forwards;
}

.toast.success {
  background-color: #064e3b;
  color: #a7f3d0;
  border: 1px solid #059669;
}

.toast.error {
  background-color: #4c0519;
  color: #fecdd3;
  border: 1px solid #e11d48;
}

.toast.info {
  background-color: #0f2744;
  color: #bae6fd;
  border: 1px solid #0284c7;
}

@keyframes slideDown {
  from { opacity: 0; transform: translateY(-16px); }
  to { opacity: 1; transform: translateY(0); }
}

@keyframes fadeOutToast {
  from { opacity: 1; transform: translateY(0); }
  to { opacity: 0; transform: translateY(-12px); }
}

/* ==========================================================================
   Config / Settings Modal
   ========================================================================== */
.modal-overlay {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.75);
  backdrop-filter: blur(6px);
  -webkit-backdrop-filter: blur(6px);
  z-index: 90;
  align-items: center;
  justify-content: center;
  padding: 20px;
}

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

.modal-card {
  width: 100%;
  max-width: 420px;
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 22px;
  box-shadow: 0 10px 40px rgba(0, 0, 0, 0.6);
  animation: popModal 0.2s cubic-bezier(0.16, 1, 0.3, 1) forwards;
}

@keyframes popModal {
  from { opacity: 0; transform: scale(0.95); }
  to { opacity: 1; transform: scale(1); }
}

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

.modal-header h3 {
  font-size: 1.15rem;
  font-weight: 700;
}

.modal-body {
  display: flex;
  flex-direction: column;
  gap: 14px;
  font-size: 0.85rem;
}

.modal-note {
  background: rgba(255, 255, 255, 0.04);
  border-radius: var(--radius-sm);
  padding: 10px;
  color: var(--text-secondary);
  font-size: 0.78rem;
  line-height: 1.4;
}

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

.modal-actions .btn {
  flex: 1;
  height: 44px;
  border-radius: var(--radius-md);
  font-weight: 600;
  font-size: 0.9rem;
  cursor: pointer;
  border: none;
}

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

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