/* =============================================================
   KoartGo — shared custom CSS
   Loaded in base.html after Bootstrap.
   ============================================================= */

/* --- Design tokens ----------------------------------------- */
:root {
  /* Map / route colours */
  --kg-route-color: #4338CA;
  --kg-node-visited: #16a34a;
  --kg-node-unvisited: #6f42c1;
  --kg-track-color: #F59E0B;
  --kg-map-control-bg: rgba(30, 30, 30, 0.88);

  /* Surface & border */
  --kg-surface: #ffffff;
  --kg-surface-muted: #f8f9fa;
  --kg-border: #dee2e6;

  /* Text */
  --kg-text-primary: #212529;
  --kg-text-muted: #6c757d;

  /* Accent */
  --kg-accent-primary: #0d6efd;
  --kg-accent-danger: #dc3545;

  /* Progress bar gradient */
  --kg-progress-bar: linear-gradient(90deg, #a78bfa 0%, #8b5cf6 50%, #6d28d9 100%);
}

/* --- Touch-safe small icon button --------------------------- */
/* Replaces the per-template .btn-xxs style blocks.
   Targets are increased to 36px min to improve mobile tappability. */
.btn-xxs {
  min-height: 36px;
  min-width: 36px;
  padding: .35rem .5rem;
  font-size: .75rem;
  line-height: 1;
  border-radius: .5rem;
  display: inline-flex;
  align-items: center;
  justify-content: center;
}

/* --- Horizontally scrollable pill tab row ------------------- */
/* Prevents filter tabs from clipping on narrow screens.
   Used in city_detail and activity_detail. */
.kg-pill-tabs {
  display: flex !important;
  gap: .4rem;
  flex-wrap: nowrap;
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
  align-items: center;
}
.kg-pill-tabs::-webkit-scrollbar { display: none; }
.kg-pill-tabs .nav-item { flex: 0 0 auto; }
.kg-pill-tabs .nav-link {
  display: inline-flex;
  align-items: center;
  border-radius: .75rem;
  padding: .35rem .75rem;
  font-size: .85rem;
}
.kg-pill-tabs .nav-link:not(.active) {
  background: var(--bs-light);
  color: var(--bs-body-color);
  border: 1px solid var(--bs-border-color);
}
.kg-pill-tabs .nav-link.active {
  background: var(--bs-primary);
  color: #fff;
  border-color: var(--bs-primary);
}
.kg-pill-tabs .nav-link .badge { margin-left: .4rem; }
.kg-pill-tabs .nav-link.active .badge { background-color: rgba(255,255,255,.25); color: #fff; }
.kg-pill-tabs .nav-link:not(.active) .badge { background-color: var(--bs-secondary); color: #fff; }

/* --- Responsive map height for detail pages ---------------- */
/* Replaces fixed height: 32rem on embedded maps.
   Adapts to viewport height on mobile without consuming too much space. */
.kg-detail-map {
  height: clamp(250px, 45vh, 520px);
}

/* --- Mobile bottom nav touch targets ----------------------- */
/* Guarantees 48px minimum tappable area on all devices. */
.navbar.fixed-bottom .nav-link {
  min-height: 48px;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
}

/* --- Utility: minimum touch target size -------------------- */
.kg-touch-target {
  min-height: 44px;
  min-width: 44px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
}

/* --- Utility: small caption text --------------------------- */
/* Replaces inline style="font-size:.7rem" across templates. */
.kg-caption {
  font-size: 0.7rem;
  line-height: 1.2;
}

/* --- Training Log ------------------------------------------ */

/* Wrapper: two-column flex (content + sidebar) */
.training-log-wrapper {
  display: flex;
  max-width: 1600px;
  margin: 0 auto;
  padding: 20px;
  gap: 20px;
}

.training-log-container {
  flex: 1;
  min-width: 0;
}

.training-log-header {
  margin-bottom: 30px;
}

.training-log-header h1 {
  font-size: 2em;
  margin-bottom: 10px;
  color: #333;
}

/* Filter section */
.filter-section {
  margin: 20px 0;
  background: var(--kg-surface-muted);
  border-radius: 8px;
}

.filter-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 12px 15px;
  cursor: pointer;
  user-select: none;
}

.filter-header:hover {
  background: #e9ecef;
  border-radius: 8px;
}

.filter-section.expanded .filter-header {
  border-radius: 8px 8px 0 0;
}

.filter-header h3 {
  font-size: 0.9em;
  margin: 0;
  color: #555;
  font-weight: 600;
  display: flex;
  align-items: center;
  gap: 8px;
}

.filter-toggle-icon {
  transition: transform 0.2s;
  font-size: 0.8em;
}

.filter-section.expanded .filter-toggle-icon {
  transform: rotate(90deg);
}

.filter-active-summary {
  font-size: 0.8em;
  color: #888;
  font-weight: normal;
}

.filter-content {
  display: none;
  padding: 0 15px 15px 15px;
}

.filter-section.expanded .filter-content {
  display: block;
}

.filter-groups {
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.filter-color-group {
  display: flex;
  align-items: flex-start;
  gap: 12px;
}

.filter-color-indicator {
  width: 20px;
  height: 20px;
  border-radius: 50%;
  flex-shrink: 0;
  margin-top: 2px;
}

.filter-color-items {
  display: flex;
  flex-wrap: wrap;
  gap: 15px;
  flex: 1;
}

.filter-checkbox {
  display: flex;
  align-items: center;
  gap: 6px;
  min-height: 44px; /* touch target */
}

.filter-checkbox input[type="checkbox"] {
  width: 18px;
  height: 18px;
  cursor: pointer;
}

.filter-checkbox label {
  cursor: pointer;
  font-size: 0.9em;
  color: #333;
}

.filter-buttons {
  margin-top: 10px;
  display: flex;
  gap: 10px;
  flex-wrap: wrap;
}

.filter-buttons button {
  padding: 10px 16px;  /* was 6px 12px — now touch-safe */
  background: var(--kg-accent-primary);
  color: white;
  border: none;
  border-radius: 4px;
  cursor: pointer;
  font-size: 0.85em;
  min-height: 44px;
}

.filter-buttons button:hover {
  background: #0056b3;
}

.filter-buttons button.secondary {
  background: var(--kg-text-muted);
}

.filter-buttons button.secondary:hover {
  background: #545b62;
}

/* Empty weeks toggle */
.toggle-section {
  margin: 20px 0;
  padding: 15px;
  background: var(--kg-surface-muted);
  border-radius: 8px;
  display: flex;
  align-items: center;
  gap: 12px;
}

.toggle-switch {
  position: relative;
  display: inline-block;
  width: 50px;
  height: 24px;
  flex-shrink: 0;
}

.toggle-switch input {
  opacity: 0;
  width: 0;
  height: 0;
}

.toggle-slider {
  position: absolute;
  cursor: pointer;
  top: 0; left: 0; right: 0; bottom: 0;
  background-color: #ccc;
  transition: .4s;
  border-radius: 24px;
}

.toggle-slider:before {
  position: absolute;
  content: "";
  height: 18px;
  width: 18px;
  left: 3px;
  bottom: 3px;
  background-color: white;
  transition: .4s;
  border-radius: 50%;
}

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

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

.toggle-label {
  font-size: 0.9em;
  color: #333;
  cursor: pointer;
  user-select: none;
}

/* Activity colour classes */
.activity-run   { background-color: #fc5200; }
.activity-ride  { background-color: #00b894; }
.activity-walk  { background-color: #6c5ce7; }
.activity-swim  { background-color: #0984e3; }
.activity-other { background-color: #636e72; }

/* Week grid */
.kg-week-scroll {
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
}
.kg-week-scroll::-webkit-scrollbar { display: none; }

.weeks-container {
  display: flex;
  flex-direction: column;
  gap: 8px;
  margin-top: 20px;
}

.week-row {
  display: grid;
  grid-template-columns: 160px repeat(7, 1fr);
  gap: 1px;
  background: var(--kg-border);
  padding: 1px;
  border-radius: 4px;
  scroll-margin-top: 20px;
}

.week-label {
  display: flex;
  flex-direction: column;
  justify-content: center;
  align-items: flex-start;
  background: var(--kg-surface-muted);
  padding: 12px;
  border-radius: 3px;
}

.week-date-range {
  font-weight: 600;
  font-size: 0.9em;
  color: #333;
  margin-bottom: 4px;
}

.week-total-distance {
  font-size: 0.85em;
  color: #666;
}

.day-cell {
  background: transparent;
  min-height: 120px;
  padding: 8px 4px;
  position: relative;
  overflow: hidden;
}

.day-header {
  font-size: 0.75em;
  color: #888;
  margin-bottom: 5px;
  font-weight: 500;
  text-align: center;
}

.day-date {
  font-size: 0.7em;
  color: #aaa;
}

.activities-container {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-top: 8px;
  justify-content: center;
}

.activity-bubble-link {
  text-decoration: none;
  display: inline-block;
}

.activity-bubble {
  border-radius: 50%;
  cursor: pointer;
  transition: transform 0.2s, box-shadow 0.2s;
  box-shadow: 0 2px 4px rgba(0,0,0,0.15);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 0.7em;
  font-weight: 600;
  color: white;
  text-shadow: 0 1px 2px rgba(0,0,0,0.3);
  flex-shrink: 0;
}

.activity-bubble-link:hover .activity-bubble {
  transform: scale(1.1);
  box-shadow: 0 4px 8px rgba(0,0,0,0.25);
}

/* Timeline sidebar */
.timeline-sidebar {
  width: 200px;
  position: sticky;
  top: 20px;
  height: fit-content;
  background: var(--kg-surface-muted);
  border-radius: 8px;
  padding: 15px;
  max-height: calc(100vh - 40px);
  overflow-y: auto;
}

.timeline-sidebar h3 {
  font-size: 0.9em;
  margin-bottom: 15px;
  color: #333;
  font-weight: 600;
}

.timeline-mobile-dropdown { display: none; }

.timeline-year-select {
  width: 100%;
  padding: 10px;
  font-size: 1em;
  border: 1px solid var(--kg-border);
  border-radius: 4px;
  background: white;
  cursor: pointer;
  margin-bottom: 10px;
}

.timeline-months-mobile {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

.timeline-month-link {
  padding: 8px 12px;
  color: var(--kg-accent-primary);
  text-decoration: none;
  border-radius: 4px;
  font-size: 0.85em;
  transition: background 0.2s;
  background: white;
  border: 1px solid var(--kg-border);
}

.timeline-month-link:hover { background: #e9ecef; }

.timeline-desktop { display: block; }

.timeline-year { margin-bottom: 15px; }

.timeline-year-label {
  font-weight: 600;
  font-size: 1.1em;
  color: #333;
  padding: 8px 10px;
  cursor: pointer;
  border-radius: 4px;
  transition: background 0.2s;
  user-select: none;
  min-height: 44px;
  display: flex;
  align-items: center;
}

.timeline-year-label:hover { background: #e9ecef; }

.timeline-year-label::before {
  content: '▶';
  display: inline-block;
  margin-right: 8px;
  transition: transform 0.3s;
  font-size: 0.7em;
}

.timeline-year.expanded .timeline-year-label::before {
  transform: rotate(90deg);
}

.timeline-months {
  display: none;
  flex-direction: column;
  gap: 4px;
  margin-top: 5px;
  padding-left: 20px;
}

.timeline-year.expanded .timeline-months { display: flex; }

.timeline-month-button {
  padding: 8px 10px;
  color: var(--kg-accent-primary);
  background: none;
  border: none;
  text-align: left;
  border-radius: 4px;
  font-size: 0.85em;
  transition: background 0.2s;
  cursor: pointer;
  min-height: 44px;
  display: flex;
  align-items: center;
}

.timeline-month-button:hover { background: #e9ecef; }

.no-activities {
  color: #ccc;
  font-size: 0.8em;
  text-align: center;
  padding: 20px 0;
}

/* --- Training Log: responsive ----------------------------- */

@media (max-width: 767.98px) {
  .training-log-wrapper {
    padding: 8px 0;
    gap: 12px;
  }

  .week-row {
    grid-template-columns: 90px repeat(7, minmax(48px, 1fr));
    min-width: 500px;
  }

  .week-label {
    padding: 8px;
  }

  .week-date-range {
    font-size: 0.75rem; /* was 0.75em — explicit rem for WCAG */
  }

  .week-total-distance {
    font-size: 0.75rem; /* was 0.7em (~11px) → ≥12px */
  }

  .day-cell {
    min-height: 80px;
    padding: 4px 2px;
  }

  .day-header {
    font-size: 0.75rem; /* was 0.65em (~10px) → ≥12px */
  }

  .activities-container {
    gap: 4px;
  }

  .filter-color-items {
    flex-direction: column;
    gap: 8px;
  }
}

@media (max-width: 1199.98px) {
  .training-log-wrapper {
    flex-direction: column; /* sidebar staat na content in HTML, dus column = content boven, sidebar onder */
  }

  .timeline-sidebar {
    position: relative;
    width: 100%;
    max-height: none;
  }

  .timeline-desktop { display: none; }
  .timeline-mobile-dropdown { display: block; }

  .week-row {
    grid-template-columns: 140px repeat(7, 1fr);
  }

  .day-cell {
    min-height: 100px;
    padding: 6px 4px;
  }
}
