/* ================================================================
   TrkFit V4 — css/components.css
   Buttons • Cards • Badges • Forms • Modals • Toggles
================================================================ */

/* ================================================================
   BUTTONS
================================================================ */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: var(--sp-2);
  padding: 10px 22px;
  border-radius: var(--r-full);
  font-family: var(--font-head);
  font-size: var(--fs-base);
  font-weight: 700;
  line-height: 1;
  white-space: nowrap;
  cursor: pointer;
  transition: all var(--tr-md);
  border: 2px solid transparent;
  position: relative;
  overflow: hidden;
}

.btn:active { transform: scale(.97); }

/* Ripple */
.btn .ripple {
  position: absolute;
  border-radius: 50%;
  background: rgba(255,255,255,.35);
  transform: scale(0);
  animation: rippleOut .6s linear;
  pointer-events: none;
}
@keyframes rippleOut {
  to { transform: scale(4); opacity: 0; }
}

/* Sizes */
.btn-xs  { padding: 5px 12px;  font-size: var(--fs-xs); }
.btn-sm  { padding: 7px 16px;  font-size: var(--fs-sm); }
.btn-lg  { padding: 14px 32px; font-size: var(--fs-lg); }
.btn-xl  { padding: 18px 40px; font-size: var(--fs-xl); }

/* Full width */
.btn-block { width: 100%; }

/* Variants */
.btn-primary {
  background: var(--grad-accent);
  color: #fff;
  box-shadow: 0 4px 20px rgba(0,201,110,.3);
}
.btn-primary:hover {
  transform: translateY(-2px);
  box-shadow: 0 8px 28px rgba(0,201,110,.45);
}

.btn-blue {
  background: var(--grad-blue);
  color: #fff;
  box-shadow: 0 4px 20px rgba(0,114,255,.3);
}
.btn-blue:hover {
  transform: translateY(-2px);
  box-shadow: 0 8px 28px rgba(0,114,255,.45);
}

.btn-ghost {
  background: transparent;
  color: var(--c-text2);
  border-color: var(--c-border);
}
.btn-ghost:hover {
  border-color: var(--c-accent);
  color: var(--c-accent);
  background: var(--c-accent-lt);
}

.btn-outline {
  background: transparent;
  color: var(--c-accent);
  border-color: var(--c-accent);
}
.btn-outline:hover {
  background: var(--c-accent);
  color: #fff;
}

.btn-danger {
  background: var(--c-red-lt);
  color: var(--c-red);
  border-color: rgba(255,77,109,.2);
}
.btn-danger:hover { background: var(--c-red); color: #fff; }

.btn-loading {
  pointer-events: none;
  opacity: .7;
}
.btn-loading::after {
  content: '';
  display: inline-block;
  width: 14px; height: 14px;
  border: 2px solid currentColor;
  border-right-color: transparent;
  border-radius: 50%;
  animation: spin .7s linear infinite;
  margin-left: var(--sp-2);
}

/* Icon button */
.btn-icon-lg {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 44px; height: 44px;
  border-radius: var(--r-sm);
  background: var(--c-surface2);
  border: 1.5px solid var(--c-border);
  color: var(--c-text2);
  font-size: 18px;
  transition: all var(--tr);
  flex-shrink: 0;
}
.btn-icon-lg:hover {
  border-color: var(--c-accent);
  color: var(--c-accent);
}

/* ================================================================
   CARDS
================================================================ */
.card {
  background: var(--c-surface);
  border: 1px solid var(--c-border);
  border-radius: var(--r);
  padding: var(--sp-6);
  transition: box-shadow var(--tr-md), transform var(--tr-md), border-color var(--tr);
}

.card:hover {
  box-shadow: var(--sh-md);
  transform: translateY(-2px);
  border-color: rgba(0,201,110,.2);
}

.card-sm { padding: var(--sp-4); border-radius: var(--r-sm); }
.card-lg { padding: clamp(24px, 4vw, 40px); border-radius: var(--r-md); }

.card-accent { border-color: var(--c-accent); box-shadow: 0 0 0 3px var(--c-accent-lt); }

/* Feature card */
.feature-card {
  background: var(--c-surface);
  border: 1px solid var(--c-border);
  border-radius: var(--r);
  padding: var(--sp-6) var(--sp-5);
  transition: all var(--tr-md);
  position: relative;
  overflow: hidden;
}

.feature-card::before {
  content: '';
  position: absolute;
  top: 0; left: 0; right: 0;
  height: 3px;
  background: var(--grad-accent);
  transform: scaleX(0);
  transform-origin: left;
  transition: transform var(--tr-md);
}

.feature-card:hover {
  transform: translateY(-4px);
  box-shadow: var(--sh-md);
  border-color: transparent;
}

.feature-card:hover::before { transform: scaleX(1); }

.card-ico {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 48px; height: 48px;
  border-radius: var(--r-sm);
  font-size: 22px;
  margin-bottom: var(--sp-4);
  background: var(--c-accent-lt);
  border: 1px solid var(--c-accent-md);
}

.card-ico.blue   { background: var(--c-blue-lt);   border-color: rgba(0,114,255,.2); }
.card-ico.red    { background: var(--c-red-lt);    border-color: rgba(255,77,109,.2); }
.card-ico.amber  { background: var(--c-amber-lt);  border-color: rgba(255,159,28,.2); }
.card-ico.purple { background: var(--c-purple-lt); border-color: rgba(155,39,175,.2); }
.card-ico.teal   { background: var(--c-teal-lt);   border-color: rgba(0,188,212,.2); }
.card-ico.pink   { background: var(--c-pink-lt);   border-color: rgba(233,30,140,.2); }

.card-title {
  font-family: var(--font-head);
  font-size: var(--fs-lg);
  font-weight: 700;
  color: var(--c-text);
  margin-bottom: var(--sp-2);
}

.card-desc {
  font-size: var(--fs-sm);
  color: var(--c-text3);
  line-height: var(--lh-loose);
}

/* Stat card */
.stat-card {
  background: var(--c-surface);
  border: 1px solid var(--c-border);
  border-radius: var(--r);
  padding: var(--sp-5) var(--sp-4);
  text-align: center;
  transition: all var(--tr-md);
}

.stat-val {
  font-family: var(--font-head);
  font-size: var(--fs-4xl);
  font-weight: 800;
  color: var(--c-accent);
  line-height: 1;
  margin-bottom: var(--sp-1);
}

.stat-label {
  font-size: var(--fs-xs);
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: var(--ls-wide);
  color: var(--c-text3);
}

/* ================================================================
   BADGES & CHIPS
================================================================ */
.badge {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  padding: 3px 10px;
  border-radius: var(--r-full);
  font-size: var(--fs-xs);
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: var(--ls-wide);
  white-space: nowrap;
}

.badge-green  { background: var(--c-accent-lt); color: var(--c-accent-dk); border: 1px solid var(--c-accent-md); }
.badge-blue   { background: var(--c-blue-lt);   color: var(--c-blue);      border: 1px solid rgba(0,114,255,.2); }
.badge-red    { background: var(--c-red-lt);    color: var(--c-red);       border: 1px solid rgba(255,77,109,.2); }
.badge-amber  { background: var(--c-amber-lt);  color: #9a6000;            border: 1px solid rgba(255,159,28,.2); }
.badge-purple { background: var(--c-purple-lt); color: var(--c-purple);    border: 1px solid rgba(155,39,175,.2); }
.badge-grey   { background: var(--c-surface2);  color: var(--c-text3);     border: 1px solid var(--c-border); }

/* Plan chips */
.plan-chip       { @extend .badge; }
.plan-chip.free  { @extend .badge-grey; }
.plan-chip.pro   { @extend .badge-green; }
.plan-chip.annual{ @extend .badge-blue; }

/* ================================================================
   FORM ELEMENTS
================================================================ */
.form-group {
  display: flex;
  flex-direction: column;
  gap: var(--sp-2);
  margin-bottom: var(--sp-5);
}

.form-label {
  font-size: var(--fs-sm);
  font-weight: 700;
  color: var(--c-text2);
  letter-spacing: var(--ls-wide);
}

.form-label span { color: var(--c-red); margin-left: 2px; }

.input, .select, .textarea {
  width: 100%;
  padding: 11px 14px;
  border: 1.5px solid var(--c-border);
  border-radius: var(--r-sm);
  background: var(--c-surface);
  color: var(--c-text);
  font-size: var(--fs-base);
  transition: border var(--tr), box-shadow var(--tr);
}

.input:focus, .select:focus, .textarea:focus {
  border-color: var(--c-accent);
  box-shadow: 0 0 0 3px var(--c-accent-lt);
}

.input::placeholder, .textarea::placeholder {
  color: var(--c-text4);
}

.input-sm { padding: 7px 10px; font-size: var(--fs-sm); }

.input-error {
  border-color: var(--c-red) !important;
  box-shadow: 0 0 0 3px var(--c-red-lt) !important;
}

.form-error {
  font-size: var(--fs-xs);
  color: var(--c-red);
  display: flex;
  align-items: center;
  gap: 4px;
}

.form-hint {
  font-size: var(--fs-xs);
  color: var(--c-text3);
}

/* Input with icon */
.input-wrap {
  position: relative;
}

.input-wrap .input { padding-left: 40px; }
.input-wrap .input-ico {
  position: absolute;
  left: 12px;
  top: 50%;
  transform: translateY(-50%);
  color: var(--c-text3);
  font-size: 16px;
  pointer-events: none;
}

/* Input with suffix button */
.input-wrap .input-suffix {
  position: absolute;
  right: 8px;
  top: 50%;
  transform: translateY(-50%);
}

/* Toggle switch */
.toggle-wrap {
  display: flex;
  align-items: center;
  gap: var(--sp-3);
  cursor: pointer;
}

.toggle-switch {
  position: relative;
  width: 44px;
  height: 24px;
  flex-shrink: 0;
}

.toggle-switch input { display: none; }

.toggle-slider {
  position: absolute;
  inset: 0;
  background: var(--c-border2);
  border-radius: var(--r-full);
  transition: background var(--tr);
}

.toggle-slider::before {
  content: '';
  position: absolute;
  left: 3px;
  top: 3px;
  width: 18px;
  height: 18px;
  border-radius: 50%;
  background: #fff;
  box-shadow: var(--sh-xs);
  transition: transform var(--tr-spring);
}

.toggle-switch input:checked + .toggle-slider {
  background: var(--c-accent);
}

.toggle-switch input:checked + .toggle-slider::before {
  transform: translateX(20px);
}

/* ================================================================
   MODAL
================================================================ */
.modal-overlay {
  display: none;
  position: fixed;
  inset: 0;
  z-index: var(--z-modal);
  background: rgba(0,0,0,.55);
  backdrop-filter: var(--blur-sm);
  -webkit-backdrop-filter: var(--blur-sm);
  padding: 12px;
  overflow-y: auto;
  align-items: flex-start;
  justify-content: center;
  padding-top: calc(var(--nav-h) + 8px);
}

.modal-overlay.open {
  display: flex;
  animation: fadeIn .22s ease;
}

.modal-box {
  background: var(--c-surface);
  border-radius: var(--r-md);
  width: 100%;
  max-width: 520px;
  max-height: calc(100dvh - var(--nav-h) - 20px);
  overflow-y: auto;
  box-shadow: var(--sh-xl);
  animation: scaleIn .25s cubic-bezier(.34,1.3,.64,1);
}

/* On small screens: ensure modal fits entirely */
@media (max-width: 480px) {
  .modal-overlay {
    padding: 8px;
    padding-top: calc(var(--nav-h) + 4px);
    align-items: flex-start;
  }
  .modal-box {
    border-radius: var(--r-sm);
    max-height: calc(100dvh - var(--nav-h) - 12px);
  }
  .modal-body {
    padding: var(--sp-4);
    gap: var(--sp-4);
  }
  .modal-footer {
    padding: var(--sp-3) var(--sp-4);
    flex-wrap: wrap;
  }
  .modal-footer .btn { flex: 1; text-align: center; }
}

.modal-hdr {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: var(--sp-4) var(--sp-5);
  border-bottom: 1px solid var(--c-border);
  position: sticky;
  top: 0;
  background: var(--c-surface);
  z-index: 1;
}

.modal-title {
  font-family: var(--font-head);
  font-size: var(--fs-lg);
  font-weight: 800;
  color: var(--c-text);
}

.modal-close {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 30px; height: 30px;
  border-radius: 50%;
  background: var(--c-surface2);
  color: var(--c-text3);
  font-size: 14px;
  transition: all var(--tr);
}
.modal-close:hover { background: var(--c-red-lt); color: var(--c-red); }

.modal-body {
  padding: var(--sp-5);
  display: flex;
  flex-direction: column;
  gap: var(--sp-5);
}

.modal-footer {
  padding: var(--sp-4) var(--sp-5);
  border-top: 1px solid var(--c-border);
  display: flex;
  gap: var(--sp-2);
  justify-content: flex-end;
}

/* Bottom sheet (mobile modal) */
.bottom-sheet {
  position: fixed;
  bottom: 0; left: 0; right: 0;
  z-index: var(--z-modal);
  background: var(--c-surface);
  border-radius: var(--r-lg) var(--r-lg) 0 0;
  padding: var(--sp-5);
  box-shadow: var(--sh-xl);
  max-height: 80dvh;
  overflow-y: auto;
  transform: translateY(100%);
  transition: transform var(--tr-md);
}

.bottom-sheet.open { transform: translateY(0); }

/* ================================================================
   PROGRESS BAR
================================================================ */
.progress-wrap {
  display: flex;
  flex-direction: column;
  gap: var(--sp-1);
}

.progress-label {
  display: flex;
  justify-content: space-between;
  font-size: var(--fs-xs);
  font-weight: 700;
  color: var(--c-text3);
}

.progress-bar {
  height: 8px;
  background: var(--c-border);
  border-radius: var(--r-full);
  overflow: hidden;
}

.progress-fill {
  height: 100%;
  border-radius: var(--r-full);
  background: var(--grad-accent);
  transition: width var(--tr-slow);
}

.progress-bar.sm { height: 5px; }
.progress-bar.lg { height: 12px; }

/* ================================================================
   AVATAR
================================================================ */
.avatar {
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: 50%;
  background: var(--grad-accent);
  color: #fff;
  font-family: var(--font-head);
  font-weight: 700;
  flex-shrink: 0;
}

.avatar-sm  { width: 28px; height: 28px; font-size: 11px; }
.avatar     { width: 40px; height: 40px; font-size: 15px; }
.avatar-lg  { width: 56px; height: 56px; font-size: 20px; }
.avatar-xl  { width: 80px; height: 80px; font-size: 28px; }

/* ================================================================
   DIVIDER
================================================================ */
.divider {
  height: 1px;
  background: var(--c-border);
  margin-block: var(--sp-4);
}

.divider-text {
  display: flex;
  align-items: center;
  gap: var(--sp-3);
  color: var(--c-text3);
  font-size: var(--fs-sm);
  font-weight: 600;
  margin-block: var(--sp-4);
}
.divider-text::before,
.divider-text::after {
  content: '';
  flex: 1;
  height: 1px;
  background: var(--c-border);
}

/* ================================================================
   TOAST
================================================================ */
#toast-container {
  position: fixed;
  bottom: calc(var(--bot-nav-h, 0px) + 16px);
  left: 50%;
  transform: translateX(-50%);
  z-index: var(--z-toast);
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: var(--sp-2);
  pointer-events: none;
  width: max-content;
  max-width: calc(100vw - 32px);
}

.toast {
  display: inline-flex;
  align-items: center;
  gap: var(--sp-2);
  padding: 10px 20px;
  border-radius: var(--r-full);
  font-size: var(--fs-sm);
  font-weight: 700;
  background: var(--c-text);
  color: var(--c-bg);
  box-shadow: var(--sh-lg);
  animation: toastIn .3s var(--tr-spring) both;
  pointer-events: all;
  white-space: nowrap;
}

.toast.removing { animation: toastOut .2s ease both; }

.toast.success { background: var(--c-accent-dk); color: #fff; }
.toast.error   { background: var(--c-red);       color: #fff; }
.toast.info    { background: var(--c-blue);       color: #fff; }
.toast.warn    { background: var(--c-amber);      color: #fff; }

/* ================================================================
   SKELETON LOADER
================================================================ */
.skeleton {
  background: linear-gradient(90deg, var(--c-surface2) 25%, var(--c-border) 50%, var(--c-surface2) 75%);
  background-size: 200% 100%;
  animation: shimmer 1.5s infinite;
  border-radius: var(--r-sm);
}

/* ================================================================
   SCROLL-TO-TOP BUTTON
================================================================ */
#scroll-top {
  position: fixed;
  bottom: 80px;
  right: 20px;
  z-index: var(--z-sticky);
  width: 40px; height: 40px;
  border-radius: 50%;
  background: var(--c-accent);
  color: #fff;
  font-size: 18px;
  display: flex;
  align-items: center;
  justify-content: center;
  box-shadow: var(--sh-accent);
  opacity: 0;
  pointer-events: none;
  transform: translateY(12px);
  transition: all var(--tr-md);
}

/* On mobile, place above the bottom nav bar */
@media (max-width: 860px) {
  #scroll-top {
    bottom: calc(var(--bot-nav-h, 60px) + 12px);
    right: 12px;
    width: 36px; height: 36px;
    font-size: 16px;
  }
}

#scroll-top.visible {
  opacity: 1;
  pointer-events: all;
  transform: translateY(0);
}

#scroll-top:hover { transform: translateY(-2px); }

/* ================================================================
   PAGE LOADER BAR
================================================================ */
#page-loader {
  position: fixed;
  top: 0; left: 0;
  height: 3px;
  width: 0%;
  background: var(--grad-accent);
  z-index: var(--z-top);
  transition: width .3s ease, opacity .3s ease;
  border-radius: 0 var(--r-full) var(--r-full) 0;
}
