/* Tokens */
:root {
  --color-primary: #163A5F;
  --color-interact: #2563EB;
  --color-run: #F97360;
  --color-jj: #3157A4;
  --color-trip: #F59E0B;
  --color-success: #16A36A;
  --color-error: #DC3545;
  --color-bg: #F6F8FB;
  --color-surface: #FFFFFF;
  --color-text: #172033;
  --color-muted: #667085;
  --color-border: #E4E8EF;
  --color-primary-soft: color-mix(in srgb, var(--color-primary) 10%, white);
  --color-interact-soft: color-mix(in srgb, var(--color-interact) 12%, white);
  --color-run-soft: color-mix(in srgb, var(--color-run) 16%, white);
  --color-jj-soft: color-mix(in srgb, var(--color-jj) 14%, white);
  --color-trip-soft: color-mix(in srgb, var(--color-trip) 18%, white);
  --color-success-soft: color-mix(in srgb, var(--color-success) 14%, white);
  --color-error-soft: color-mix(in srgb, var(--color-error) 12%, white);
  --app-max: 1240px;
  --space-1: 0.25rem;
  --space-2: 0.5rem;
  --space-3: 0.75rem;
  --space-4: 1rem;
  --space-5: 1.5rem;
  --space-6: 2rem;
  --radius-sm: 8px;
  --radius-md: 12px;
  --radius-lg: 16px;
  --shadow-surface: 0 8px 24px rgba(23, 32, 51, 0.06);
  --shadow-float: 0 16px 40px rgba(23, 32, 51, 0.12);
  --font: Inter, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  --fs-page: 1.75rem;
  --fs-section: 1.125rem;
  --fs-card: 1rem;
  --fs-body: 1rem;
  --fs-caption: 0.8125rem;
  --fs-metric: 1.75rem;
  --lh-tight: 1.25;
  --lh-body: 1.5;
  --control-h: 44px;
  --mobile-nav-height: calc(4.5rem + env(safe-area-inset-bottom, 0px));
  --mobile-nav-clearance: calc(var(--mobile-nav-height) + 1.5rem);
}

* { box-sizing: border-box; }

html, body {
  min-height: 100%;
  font-family: var(--font);
  font-size: var(--fs-body);
  line-height: var(--lh-body);
  color: var(--color-text);
  background: var(--color-bg);
}

h1, h2, h3, h4, .navbar-brand, .display-title {
  font-family: var(--font);
  letter-spacing: -0.02em;
  line-height: var(--lh-tight);
  color: var(--color-text);
}

.display-title { font-size: clamp(1.4rem, 2vw, var(--fs-page)); font-weight: 700; }
h2, .section-title { font-size: var(--fs-section); font-weight: 650; }
.caption, .text-muted { color: var(--color-muted); }
.metric { font-size: var(--fs-metric); font-weight: 700; letter-spacing: -0.03em; }

a { color: var(--color-interact); }
a:hover { color: var(--color-primary); }

:focus-visible {
  outline: 3px solid color-mix(in srgb, var(--color-interact) 55%, white);
  outline-offset: 2px;
}

.app-main { padding: var(--space-4) var(--space-4) var(--space-6); }
.app-authenticated .app-main { padding-bottom: var(--mobile-nav-clearance); }
.app-shell {
  width: min(100%, var(--app-max));
  margin-inline: auto;
}

.app-topnav {
  background: var(--color-primary);
  box-shadow: var(--shadow-surface);
}
.app-topnav-inner {
  display: flex;
  align-items: center;
  width: min(100%, var(--app-max));
  margin-inline: auto;
  padding: 0.65rem 1rem;
  gap: 1rem;
}
.app-topnav .navbar-brand {
  display: inline-flex;
  align-items: center;
  padding: 0;
  line-height: 0;
}
.brand-mark {
  height: 40px;
  width: auto;
  display: block;
}
.brand-logo {
  display: block;
  max-width: min(100%, 22rem);
  height: auto;
}
.app-topnav .navbar-nav { gap: 0.15rem; }
.app-topnav .nav-link {
  color: rgba(255,255,255,0.78);
  font-weight: 550;
  border-radius: 999px;
  padding: 0.45rem 0.85rem;
  min-height: 40px;
  display: inline-flex;
  align-items: center;
}
.app-topnav .nav-link:hover,
.app-topnav .nav-link:focus { color: #fff; }
.app-topnav .nav-link.active {
  color: #fff;
  background: rgba(255,255,255,0.14);
  box-shadow: inset 0 -2px 0 #fff;
}
.btn-cta {
  background: #fff;
  color: var(--color-primary);
  border: 0;
  font-weight: 700;
  min-height: var(--control-h);
  border-radius: 999px;
  padding: 0.5rem 1.1rem;
}
.btn-cta:hover { background: #eef3f8; color: var(--color-primary); }

.profile-menu-toggle {
  display: inline-flex;
  align-items: center;
  gap: 0.55rem;
  color: #fff;
  background: transparent;
  border: 0;
  min-height: 44px;
  padding: 0.2rem 0.35rem 0.2rem 0.2rem;
}
.profile-menu-toggle:hover { color: #fff; }
.avatar,
.avatar-sm,
.avatar-lg {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  border-radius: 50%;
  background: var(--color-jj-soft);
  color: var(--color-jj);
  font-weight: 700;
  overflow: hidden;
  flex-shrink: 0;
}
.avatar, .avatar-sm { width: 36px; height: 36px; font-size: 0.8rem; }
.avatar-lg { width: 96px; height: 96px; font-size: 1.6rem; }
.avatar img, .avatar-sm img, .avatar-lg img { width: 100%; height: 100%; object-fit: cover; }

.card-soft {
  background: var(--color-surface);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-surface);
}
.card-soft.card { border: 1px solid var(--color-border); }

.btn {
  min-height: var(--control-h);
  border-radius: var(--radius-md);
  font-weight: 600;
  padding: 0.5rem 1rem;
}
.btn-sm { min-height: 40px; border-radius: var(--radius-sm); }
.btn-teal,
.btn-primary {
  --bs-btn-bg: var(--color-interact);
  --bs-btn-border-color: var(--color-interact);
  --bs-btn-hover-bg: #1d4fd7;
  --bs-btn-hover-border-color: #1d4fd7;
  --bs-btn-color: #fff;
  --bs-btn-hover-color: #fff;
  background: var(--color-interact);
  border-color: var(--color-interact);
  color: #fff;
}
.btn-teal:hover, .btn-primary:hover { background: #1d4fd7; border-color: #1d4fd7; color: #fff; }
.btn-outline-secondary {
  border-color: var(--color-border);
  color: var(--color-text);
  background: var(--color-surface);
}
.btn-ghost,
.btn-tertiary {
  background: transparent;
  border: 0;
  color: var(--color-muted);
  min-height: 40px;
}
.btn-danger { background: var(--color-error); border-color: var(--color-error); }
.btn-lg-touch { min-height: var(--control-h); }

.form-control, .form-select {
  min-height: var(--control-h);
  border-color: var(--color-border);
  border-radius: var(--radius-md);
}
.form-control:focus, .form-select:focus {
  border-color: var(--color-interact);
  box-shadow: 0 0 0 0.2rem color-mix(in srgb, var(--color-interact) 20%, white);
}
.form-label { font-weight: 600; color: var(--color-text); }

.badge-cat {
  border-radius: 999px;
  font-weight: 650;
  padding: 0.3rem 0.65rem;
  font-size: 0.75rem;
}
.badge-jj { background: var(--color-jj-soft); color: var(--color-jj); }
.badge-run { background: var(--color-run-soft); color: #c2410c; }
.badge-leisure, .badge-trip { background: var(--color-trip-soft); color: #92400e; }
.badge-done { background: var(--color-success-soft); color: #0f7a4d; }
.badge-cancel { background: var(--color-error-soft); color: var(--color-error); }
.badge-goal { background: var(--color-interact-soft); color: var(--color-interact); }

.progress-goal {
  height: 0.7rem;
  border-radius: 999px;
  background: var(--color-primary-soft);
}
.progress-goal .progress-bar {
  background: var(--color-interact);
  border-radius: 999px;
}

.mobile-bottom-nav {
  position: fixed;
  left: 0; right: 0; bottom: 0;
  display: grid;
  grid-template-columns: repeat(5, 1fr);
  background: rgba(255,255,255,0.98);
  backdrop-filter: blur(12px);
  border-top: 1px solid var(--color-border);
  padding: 0.45rem 0.3rem calc(0.4rem + env(safe-area-inset-bottom, 0px));
  z-index: 1040;
}
.mobile-bottom-nav .nav-item {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 0.1rem;
  text-decoration: none;
  color: var(--color-muted);
  font-size: 0.68rem;
  font-weight: 650;
  min-height: 44px;
  border-radius: var(--radius-md);
}
.mobile-bottom-nav .nav-item i { font-size: 1.2rem; }
.mobile-bottom-nav .nav-item.active { color: var(--color-primary); }
.mobile-bottom-nav .nav-item-primary {
  color: #fff;
  background: var(--color-interact);
  border-radius: 1rem;
  margin: 0 0.2rem;
}
.mobile-bottom-nav .nav-item-primary span { color: #fff; }

.form-sticky-actions {
  position: sticky;
  bottom: var(--mobile-nav-height);
  z-index: 20;
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem;
  margin-top: 1.25rem;
  padding: 0.85rem 0 0.15rem;
  background: linear-gradient(180deg, rgba(255,255,255,0) 0%, var(--color-surface) 35%);
}

.calendar-grid {
  display: grid;
  grid-template-columns: repeat(7, 1fr);
  gap: 0.4rem;
}
.calendar-dow {
  text-align: center;
  font-size: 0.72rem;
  font-weight: 700;
  color: var(--color-muted);
  text-transform: uppercase;
}
.calendar-day {
  min-height: 72px;
  background: var(--color-surface);
  border-radius: var(--radius-md);
  padding: 0.4rem;
  border: 1px solid transparent;
  cursor: pointer;
}
.calendar-day.other-month { background: transparent; opacity: 0.45; }
.calendar-day.weekend { background: #f8fafc; }
.calendar-day.today {
  background: var(--color-interact-soft);
  box-shadow: inset 0 0 0 2px var(--color-interact);
}
.calendar-day.selected { box-shadow: inset 0 0 0 2px var(--color-primary); }
.calendar-day .day-num { font-size: 0.8rem; font-weight: 700; }
.cal-dot { width: 8px; height: 8px; border-radius: 50%; display: inline-block; margin: 1px; }
.cal-event-chip {
  display: block;
  font-size: 0.68rem;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  border-radius: 0.4rem;
  padding: 0.12rem 0.3rem;
  margin-top: 0.15rem;
  color: #fff;
}

.filter-chip {
  display: inline-flex;
  align-items: center;
  min-height: 40px;
  padding: 0.3rem 0.8rem;
  border-radius: 999px;
  border: 1px solid var(--color-border);
  background: var(--color-surface);
  color: var(--color-text);
  font-weight: 600;
  font-size: 0.85rem;
  text-decoration: none;
}
.filter-chip.active {
  background: var(--color-primary);
  border-color: var(--color-primary);
  color: #fff;
}

.empty-state {
  text-align: center;
  padding: 2rem 1.25rem;
}
.empty-state i { font-size: 2rem; color: var(--color-muted); }

.athlete-option {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  padding: 0.7rem 0.85rem;
  border: 1px solid var(--color-border);
  border-radius: var(--radius-md);
  background: var(--color-surface);
  min-height: 56px;
}
.athlete-option input { margin-top: 0; }
.athlete-option:has(input:checked) {
  border-color: var(--color-interact);
  box-shadow: 0 0 0 3px var(--color-interact-soft);
}

.event-cancelled { opacity: 0.7; text-decoration: line-through; }

.auth-page {
  min-height: calc(100vh - 2rem);
  display: grid;
  place-items: center;
  padding: 1.5rem 1rem;
}
.auth-shell {
  width: min(100%, 460px);
}
.auth-page-inner {
  display: grid;
  gap: 1.5rem;
}
@media (min-width: 992px) {
  .auth-page-inner {
    width: min(100%, 920px);
    grid-template-columns: 1fr 1fr;
    align-items: center;
  }
}
.hero-brand {
  font-size: clamp(1.8rem, 4vw, 2.3rem);
  font-weight: 750;
  color: var(--color-primary);
}
.stat-tile {
  background: var(--color-surface);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-lg);
  padding: 0.9rem 1rem;
  box-shadow: var(--shadow-surface);
}
.event-wizard { max-width: 56rem; }

.install-banner {
  position: fixed;
  left: 1rem;
  right: 1rem;
  bottom: calc(var(--mobile-nav-height) + 0.75rem);
  background: var(--color-surface);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-float);
  padding: 0.85rem 1rem;
  display: flex;
  gap: 0.75rem;
  align-items: center;
  z-index: 1030;
}
.install-banner .btn-close-banner {
  min-width: 44px;
  min-height: 44px;
}

.wizard-steps { display: flex; gap: 0.5rem; margin-bottom: 1rem; flex-wrap: wrap; }
.wizard-steps .step {
  flex: 1;
  min-width: 70px;
  text-align: center;
  padding: 0.5rem;
  border-radius: 999px;
  background: var(--color-border);
  font-size: 0.8rem;
  font-weight: 650;
}
.wizard-steps .step.active { background: var(--color-primary); color: #fff; }
.wizard-steps .step.done { background: var(--color-interact-soft); color: var(--color-interact); }

.profile-avatar {
  width: 96px; height: 96px; border-radius: 50%;
  object-fit: cover; border: 3px solid #fff; box-shadow: var(--shadow-surface);
  background: var(--color-primary-soft);
}
.filter-bar {
  background: var(--color-surface);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-lg);
  padding: 0.85rem;
  box-shadow: var(--shadow-surface);
}

.settings-section + .settings-section { margin-top: 1.25rem; }
.week-agenda-item {
  display: flex;
  gap: 0.75rem;
  padding: 0.7rem 0;
  border-bottom: 1px solid var(--color-border);
}
.week-agenda-item:last-child { border-bottom: 0; }

.type-option { cursor: pointer; background: #fff; transition: border-color .15s, box-shadow .15s; }
.btn-check:checked + .type-option {
  border-color: var(--color-interact) !important;
  box-shadow: 0 0 0 0.15rem color-mix(in srgb, var(--color-interact) 25%, white);
}

@media (min-width: 768px) {
  :root { --app-max: 720px; }
}
@media (min-width: 992px) {
  :root { --app-max: 1120px; }
  .app-main { padding: 1.75rem 1.5rem 2.5rem; }
  .app-authenticated .app-main { padding-bottom: 2.5rem; }
  .form-sticky-actions {
    position: static;
    background: none;
    border-top: 1px solid var(--color-border);
    padding-top: 1.25rem;
  }
  .calendar-day { min-height: 118px; padding: 0.5rem; }
  .install-banner {
    left: auto;
    right: 1.5rem;
    bottom: 1.5rem;
    max-width: 420px;
  }
}
@media (min-width: 1200px) {
  :root { --app-max: 1240px; }
  .event-wizard { max-width: 64rem; }
}
@media (max-width: 991.98px) {
  .calendar-day { min-height: 52px; }
  .cal-event-chip { display: none; }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    animation-duration: 0.01ms !important;
    transition-duration: 0.01ms !important;
  }
}
