/*
  booking-calendar.css
  Sailing course booking calendar — BookingCalendar component styles.

  Uses CSS custom properties with sensible fallbacks so the component
  integrates with any Webflow site's Style Guide variables.

  Variable contract:
    --ks-bg          surface / card background
    --ks-fg          primary text colour
    --ks-muted       secondary / muted text
    --ks-border      divider / border colour
    --ks-primary     brand primary (nav, today highlight, popup header)
    --ks-secondary   accent (course bars, links)
    --ks-danger      alert colour (full capacity)
    --ks-radius      corner radius token
    --ks-font        font-family stack
*/

/* ── Root token defaults ────────────────────────────────────────────────────── */

.ks-booking-calendar {
  --ks-bg: var(--color-surface, #ffffff);
  --ks-fg: var(--color-text, #1a1a1a);
  --ks-muted: var(--color-text-muted, #6b7280);
  --ks-border: var(--color-border, #e5e7eb);
  --ks-primary: var(--color-primary, #312783);
  --ks-secondary: var(--color-accent, #009fe3);
  --ks-danger: var(--color-danger, #dc2626);
  --ks-radius: var(--radius-md, 0.375rem);
  --ks-font: var(--font-body, system-ui, -apple-system, sans-serif);

  font-family: var(--ks-font);
  background: var(--ks-bg);
  color: var(--ks-fg);
  border-radius: var(--ks-radius);
  overflow: hidden;
  border: 1px solid var(--ks-border);
  box-shadow:
    0 1px 3px rgba(0, 0, 0, 0.08),
    0 1px 2px rgba(0, 0, 0, 0.04);
}

/* ── Month navigation ───────────────────────────────────────────────────────── */

.ks-nav {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.5rem;
  padding: 0.75rem 1rem;
  background: var(--ks-primary);
  color: #fff;
}

.ks-nav__title {
  flex: 1;
  margin: 0;
  font-size: 1.0625rem;
  font-weight: 600;
  text-align: center;
  letter-spacing: 0.01em;
}

.ks-nav__btn {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 2rem;
  height: 2rem;
  padding: 0;
  background: rgba(255, 255, 255, 0.15);
  border: 1px solid rgba(255, 255, 255, 0.25);
  border-radius: var(--ks-radius);
  color: #fff;
  font-size: 1.25rem;
  line-height: 1;
  cursor: pointer;
  transition: background 0.15s;
  flex-shrink: 0;
}

.ks-nav__btn:hover {
  background: rgba(255, 255, 255, 0.28);
}

.ks-nav__btn:focus-visible {
  outline: 2px solid rgba(255, 255, 255, 0.7);
  outline-offset: 1px;
}

/* ── Course filter badges ───────────────────────────────────────────────────── */

.ks-filters-section {
  border-bottom: 1px solid var(--ks-border);
}

.ks-filters__toggle {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  width: 100%;
  padding: 0.5rem 1rem;
  background: var(--ks-bg);
  border: none;
  text-align: left;
  cursor: pointer;
  font-family: var(--ks-font);
  font-size: 0.8125rem;
  font-weight: 600;
  color: var(--ks-muted);
  transition: background 0.15s, color 0.15s;
}

.ks-filters__toggle:hover {
  background: #f9fafb;
  color: var(--ks-fg);
}

.ks-filters__toggle:focus-visible {
  outline: 2px solid var(--ks-primary);
  outline-offset: -2px;
}

.ks-filters__chevron {
  margin-left: auto;
  font-size: 1rem;
}

.ks-filters__active-count {
  background: var(--ks-primary);
  color: #fff;
  font-size: 0.625rem;
  font-weight: 700;
  padding: 0.1rem 0.45rem;
  border-radius: 999px;
  letter-spacing: 0.03em;
}

.ks-filters {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 0.375rem;
  padding: 0.5rem 1rem;
  background: var(--ks-bg);
  border-top: 1px solid var(--ks-border);
}

.ks-filters__badge {
  padding: 0.25rem 0.75rem;
  border: 1px solid var(--ks-border);
  border-radius: 999px;
  font-family: var(--ks-font);
  font-size: 0.8125rem;
  background: var(--ks-bg);
  color: var(--ks-muted);
  cursor: pointer;
  white-space: nowrap;
  transition: background 0.15s, color 0.15s, border-color 0.15s;
}

.ks-filters__badge:hover {
  border-color: var(--ks-primary);
  color: var(--ks-fg);
}

.ks-filters__badge--active {
  background: var(--ks-primary);
  border-color: var(--ks-primary);
  color: #fff;
}

.ks-filters__badge--active:hover {
  color: #fff;
}

/* ── Loading / error banners ────────────────────────────────────────────────── */

.ks-calendar-wrapper {
  position: relative;
}

.ks-loading,
.ks-error {
  padding: 0.5rem 1rem;
  text-align: center;
  font-size: 0.875rem;
}

.ks-loading {
  color: var(--ks-muted);
  background: rgba(255, 255, 255, 0.9);
}

.ks-error {
  color: var(--ks-danger);
  background: #fef2f2;
}

/* ── Calendar grid ──────────────────────────────────────────────────────────── */

.ks-calendar {
  width: 100%;
  border-left: 1px solid var(--ks-border);
}

/* Weekday header row: Mon – Sun */
.ks-weekday-headers {
  display: grid;
  grid-template-columns: repeat(7, 1fr);
  background: #f9fafb;
  border-bottom: 1px solid var(--ks-border);
}

.ks-weekday-header {
  padding: 0.5rem 0.25rem;
  font-size: 0.6875rem;
  font-weight: 600;
  text-align: center;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--ks-muted);
  border-right: 1px solid var(--ks-border);
}

.ks-weekday-header:last-child {
  border-right: none;
}

/* ── Week row ───────────────────────────────────────────────────────────────── */

.ks-week {
  display: grid;
  grid-template-columns: repeat(7, 1fr);
  position: relative; /* anchor for absolute bars overlay */
  border-bottom: 1px solid var(--ks-border);
}

.ks-week:last-child {
  border-bottom: none;
}

/* ── Day cell ───────────────────────────────────────────────────────────────── */

/*
  --ks-max-bars is set as an inline style on .ks-calendar by the React component.
  Day cell height = date-number area (26px) + bars area (max-bars × 22px) + overflow row (22px).
*/
.ks-day {
  min-height: calc(26px + var(--ks-max-bars, 3) * 22px + 22px);
  border-right: 1px solid var(--ks-border);
  padding: 3px 3px 3px;
  position: relative;
  cursor: pointer;
  transition: background 0.1s;
  box-sizing: border-box;
}

.ks-day:last-child {
  border-right: none;
}

.ks-day:hover {
  background: #f0f4ff;
}

.ks-day--other-month {
  background: #f9fafb;
}

.ks-day--other-month .ks-day__num {
  opacity: 0.4;
}

.ks-day--today .ks-day__num {
  background: var(--ks-primary);
  color: #fff;
  font-weight: 700;
}

/* Date number bubble */
.ks-day__num {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 22px;
  height: 22px;
  border-radius: 50%;
  font-size: 0.78125rem;
  font-weight: 500;
  line-height: 1;
  flex-shrink: 0;
  color: var(--ks-fg);
}

/* "+N more" overflow button — absolutely pinned below bars overlay */
.ks-day__more {
  position: absolute;
  bottom: 3px;
  left: 3px;
  background: none;
  border: none;
  padding: 1px 2px;
  font-family: var(--ks-font);
  font-size: 0.6875rem;
  font-weight: 500;
  color: var(--ks-secondary);
  cursor: pointer;
  text-align: left;
  line-height: 1.2;
  border-radius: 2px;
}

.ks-day__more:hover {
  color: var(--ks-primary);
  text-decoration: underline;
}

.ks-day__more--short {
  display: none;
}

/* ── Bars overlay ───────────────────────────────────────────────────────────── */

/*
  Absolutely positioned on top of the day cells.
  Uses the same 7-column grid so bars snap to day boundaries.
  top: 26px puts bars below the date numbers.
  pointer-events: none lets clicks fall through to day cells;
  individual .ks-bar elements restore pointer-events.
*/
.ks-bars-overlay {
  position: absolute;
  top: 26px;
  left: 0;
  right: 0;
  height: calc(var(--ks-max-bars, 3) * 22px);
  display: grid;
  grid-template-columns: repeat(7, 1fr);
  grid-auto-rows: 20px;
  gap: 2px 0;
  pointer-events: none;
  z-index: 1;
  overflow: hidden;
}

/* ── Course bar ─────────────────────────────────────────────────────────────── */

.ks-bar {
  pointer-events: all;
  display: block;
  width: calc(100% - 4px);
  margin: 0 2px;
  padding: 0 5px;
  height: 20px;
  line-height: 20px;
  background: var(--ks-secondary);
  color: #fff;
  border: none;
  border-radius: 3px;
  font-family: var(--ks-font);
  font-size: 0.6875rem;
  font-weight: 500;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  text-align: left;
  cursor: pointer;
  transition: filter 0.1s;
  box-sizing: border-box;
}

.ks-bar:hover {
  filter: brightness(0.88);
}

/* Location label shown as a small prefix inside the bar */
.ks-bar__location {
  font-size: 0.5625rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  opacity: 0.82;
  margin-left: 4px;
  flex-shrink: 0;
}

.ks-bar:focus-visible {
  outline: 2px solid var(--ks-primary);
  outline-offset: 1px;
}

/* Full / no capacity */
.ks-bar--full {
  background: var(--ks-muted);
}

/* ── Popup ──────────────────────────────────────────────────────────────────── */

.ks-popup-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.48);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 9999;
  padding: 1rem;
}

.ks-popup {
  background: var(--ks-bg);
  border-radius: calc(var(--ks-radius) * 2);
  box-shadow:
    0 20px 60px rgba(0, 0, 0, 0.25),
    0 4px 16px rgba(0, 0, 0, 0.1);
  max-width: 400px;
  width: 100%;
  position: relative;
  overflow: hidden;
  animation: ks-popup-in 0.18s ease;
}

@keyframes ks-popup-in {
  from {
    opacity: 0;
    transform: translateY(8px) scale(0.97);
  }
  to {
    opacity: 1;
    transform: translateY(0) scale(1);
  }
}

.ks-popup__close {
  position: absolute;
  top: 0.75rem;
  right: 0.75rem;
  background: rgba(255, 255, 255, 0.18);
  border: none;
  color: #fff;
  width: 26px;
  height: 26px;
  border-radius: 50%;
  cursor: pointer;
  font-size: 0.8125rem;
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 1;
  transition: background 0.15s;
}

.ks-popup__close:hover {
  background: rgba(255, 255, 255, 0.32);
}

.ks-popup__close:focus-visible {
  outline: 2px solid rgba(255, 255, 255, 0.7);
  outline-offset: 1px;
}

.ks-popup__header {
  background: var(--ks-primary);
  color: #fff;
  padding: 1.25rem 1.25rem 1rem;
}

.ks-popup__type-badge {
  display: inline-block;
  background: rgba(255, 255, 255, 0.2);
  padding: 0.175rem 0.55rem;
  border-radius: 999px;
  font-size: 0.6875rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  margin-bottom: 0.5rem;
}

.ks-popup__title {
  margin: 0 0 0.375rem;
  font-size: 1.0625rem;
  font-weight: 700;
  line-height: 1.3;
}

.ks-popup__dates {
  margin: 0;
  font-size: 0.875rem;
  opacity: 0.88;
}

.ks-popup__details {
  margin: 0;
  padding: 1rem 1.25rem;
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
}

.ks-popup__detail-row {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  gap: 1rem;
}

.ks-popup__detail-row dt {
  font-size: 0.8125rem;
  font-weight: 600;
  color: var(--ks-muted);
  white-space: nowrap;
}

.ks-popup__detail-row dd {
  margin: 0;
  font-size: 0.875rem;
  color: var(--ks-fg);
  text-align: right;
}

.ks-popup__capacity--full {
  color: var(--ks-danger) !important;
  font-weight: 600;
}

.ks-popup__book-btn {
  display: block;
  margin: 0.25rem 1.25rem 1.25rem;
  padding: 0.7rem 1.5rem;
  background: var(--ks-primary);
  color: #fff;
  text-decoration: none;
  text-align: center;
  border-radius: var(--ks-radius);
  font-family: var(--ks-font);
  font-size: 0.9375rem;
  font-weight: 600;
  transition: opacity 0.15s;
}

.ks-popup__book-btn:hover {
  opacity: 0.88;
  text-decoration: none;
  color: #fff;
}

/* ── Day list popup ─────────────────────────────────────────────────────────── */

.ks-day-list {
  max-width: 440px;
}

.ks-day-list__items {
  list-style: none;
  margin: 0;
  padding: 0.5rem 0;
  max-height: 60vh;
  overflow-y: auto;
}

.ks-day-list__item {
  border-bottom: 1px solid var(--ks-border);
}

.ks-day-list__item:last-child {
  border-bottom: none;
}

.ks-day-list__row {
  display: flex;
  flex-direction: column;
  gap: 0.2rem;
  width: 100%;
  padding: 0.75rem 1.25rem;
  background: none;
  border: none;
  text-align: left;
  cursor: pointer;
  font-family: var(--ks-font);
  transition: background 0.1s;
}

.ks-day-list__row:hover {
  background: #f0f4ff;
}

.ks-day-list__row:focus-visible {
  outline: 2px solid var(--ks-primary);
  outline-offset: -2px;
}

.ks-day-list__meta {
  display: flex;
  align-items: center;
  gap: 0.4rem;
}

.ks-day-list__type {
  font-size: 0.6875rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--ks-secondary);
}

.ks-day-list__full-badge {
  font-size: 0.6875rem;
  font-weight: 600;
  color: var(--ks-danger);
  text-transform: uppercase;
  letter-spacing: 0.04em;
}

.ks-day-list__name {
  font-size: 0.9375rem;
  font-weight: 600;
  color: var(--ks-fg);
  line-height: 1.3;
}

.ks-day-list__time {
  font-size: 0.8125rem;
  color: var(--ks-muted);
}

/* ── Responsive ─────────────────────────────────────────────────────────────── */

@media (max-width: 520px) {
  .ks-weekday-header {
    font-size: 0.5625rem;
    padding: 0.375rem 0.0625rem;
    letter-spacing: 0;
  }

  .ks-nav__title {
    font-size: 0.9375rem;
  }

  .ks-bar {
    font-size: 0.5625rem;
    padding: 0 2px;
    height: 16px;
    line-height: 16px;
  }

  .ks-bar__location {
    display: none;
  }

  /* 2 bars × (16px bar + 2px gap) = 36px overlay; date row = 22px; overflow = 18px */
  .ks-bars-overlay {
    top: 22px;
    grid-auto-rows: 16px;
    height: calc(2 * 18px);
  }

  .ks-day {
    min-height: calc(22px + 2 * 18px + 18px);
  }

  .ks-day__more--full {
    display: none;
  }

  .ks-day__more--short {
    display: inline;
  }

  .ks-day__num {
    font-size: 0.6875rem;
    width: 18px;
    height: 18px;
  }

  .ks-popup {
    max-width: 100%;
  }
}

