/* RJK public period navigation (compact week dropdown + calendar).
 * Scoped to .rjk-period*. Colours inherit the public/template variables;
 * selected states use ink-on-surface inversion so contrast never depends
 * on the accent value (accent is only used for rings/markers). */

.rjk-period {
  --rjk-period-ink: var(--rjk-public-ink, #11110f);
  --rjk-period-muted: var(--rjk-public-muted, #68655f);
  --rjk-period-line: var(--rjk-public-line, #d8d4cc);
  --rjk-period-soft: var(--rjk-public-soft, #f3f0e9);
  --rjk-period-accent: var(--rjk-template-accent, var(--rjk-period-ink));
  --rjk-period-surface: var(--rjk-template-background, #fff);
  --rjk-period-selected-bg: var(--rjk-period-ink);
  --rjk-period-selected-ink: var(--rjk-period-surface);
  --rjk-period-radius: min(var(--rjk-template-radius, 12px), 14px);
  box-sizing: border-box;
  display: flex;
  justify-content: center;
  width: 100%;
  min-width: 0;
  margin: 18px 0;
  color: var(--rjk-period-ink);
  font-family: var(--rjk-template-body, inherit);
  font-size: 15px;
  line-height: 1.35;
}

.rjk-period *,
.rjk-period *::before,
.rjk-period *::after {
  box-sizing: border-box;
}

/* Dark families: the page surface is dark, keep the inversion readable. */
.rjk-appearance-contrast .rjk-period {
  --rjk-period-surface: #151512;
}

.rjk-period__sr {
  position: absolute !important;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0 0 0 0);
  white-space: nowrap;
  border: 0;
}

.rjk-period__icon {
  flex: none;
  display: block;
  width: 18px;
  height: 18px;
}

/* ---------- bar: ‹ [ label ▾ ] › ---------- */

.rjk-period__bar {
  display: flex;
  align-items: center;
  gap: 6px;
  max-width: 100%;
  min-width: 0;
}

.rjk-period__arrow,
.rjk-period__summary,
.rjk-period__month-btn {
  min-height: 44px;
  color: var(--rjk-period-ink);
  background: var(--rjk-period-surface);
  border: 1px solid var(--rjk-period-line);
  border-radius: var(--rjk-period-radius);
  font: inherit;
  text-decoration: none;
  cursor: pointer;
}

.rjk-period__arrow {
  display: inline-flex;
  flex: none;
  align-items: center;
  justify-content: center;
  width: 44px;
}

.rjk-period__arrow.is-disabled,
.rjk-period__month-btn:disabled {
  color: var(--rjk-period-muted);
  opacity: .45;
  cursor: not-allowed;
}

.rjk-period__menu {
  position: relative;
  min-width: 0;
}

.rjk-period__summary {
  display: flex;
  align-items: center;
  gap: 8px;
  max-width: min(100%, 22rem);
  padding: 0 12px 0 14px;
  font-weight: 650;
  list-style: none;
  user-select: none;
}

.rjk-period__summary::-webkit-details-marker {
  display: none;
}

.rjk-period__summary-text {
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.rjk-period__caret {
  display: inline-flex;
  color: var(--rjk-period-muted);
  transition: transform .15s ease;
}

.rjk-period__menu[open] > .rjk-period__summary {
  border-color: var(--rjk-period-accent);
  box-shadow: inset 0 0 0 1px var(--rjk-period-accent);
}

.rjk-period__menu[open] .rjk-period__caret {
  transform: rotate(180deg);
}

.rjk-period__arrow:not(.is-disabled):hover,
.rjk-period__summary:hover,
.rjk-period__month-btn:not(:disabled):hover {
  background: var(--rjk-period-soft);
  border-color: var(--rjk-period-accent);
}

.rjk-period :is(a, summary, button):focus-visible {
  outline: 2px solid var(--rjk-period-ink);
  outline-offset: 2px;
  box-shadow: 0 0 0 4px var(--rjk-period-surface);
}

/* ---------- dropdown panel ---------- */

.rjk-period__panel {
  position: absolute;
  z-index: 30;
  top: calc(100% + 6px);
  left: 50%;
  width: max-content;
  min-width: 100%;
  max-width: calc(100vw - 24px);
  padding: 8px;
  color: var(--rjk-period-ink);
  background: var(--rjk-period-surface);
  border: 1px solid var(--rjk-period-line);
  border-radius: var(--rjk-period-radius);
  box-shadow: 0 12px 32px rgb(0 0 0 / 16%);
  transform: translateX(-50%);
}

.rjk-period__panel-title {
  margin: 4px 8px 6px;
  color: var(--rjk-period-muted);
  font-size: 12px;
  font-weight: 700;
  letter-spacing: .08em;
  text-transform: uppercase;
}

.rjk-period__options {
  max-height: min(60vh, 22rem);
  margin: 0;
  padding: 0;
  overflow-y: auto;
  list-style: none;
}

.rjk-period__options li {
  margin: 0;
  padding: 0;
}

.rjk-period__option {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  min-height: 44px;
  padding: 8px 10px;
  color: inherit;
  border-radius: calc(var(--rjk-period-radius) - 4px);
  text-decoration: none;
  white-space: nowrap;
}

.rjk-period__option:hover {
  background: var(--rjk-period-soft);
}

.rjk-period__option.is-selected {
  color: var(--rjk-period-selected-ink);
  background: var(--rjk-period-selected-bg);
  font-weight: 700;
}

.rjk-period__empty {
  margin: 8px;
  color: var(--rjk-period-muted);
}

/* ---------- calendar ---------- */

.rjk-period__calendar {
  width: min(20.5rem, calc(100vw - 42px));
}

.rjk-period__month {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  margin-bottom: 6px;
}

.rjk-period__month-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 40px;
  min-height: 40px;
  padding: 0;
}

.rjk-period__month-title {
  margin: 0;
  font-weight: 700;
  text-align: center;
  text-transform: capitalize;
}

.rjk-period__grid {
  width: 100%;
  margin: 0;
  border: 0;
  border-collapse: separate;
  border-spacing: 2px;
  table-layout: fixed;
}

.rjk-period__grid th {
  padding: 4px 0;
  color: var(--rjk-period-muted);
  font-size: 12px;
  font-weight: 650;
  text-align: center;
  text-transform: capitalize;
  border: 0;
  background: none;
}

.rjk-period__cell {
  padding: 0;
  border: 0;
  background: none;
  text-align: center;
}

.rjk-period__day {
  position: relative;
  display: flex;
  align-items: center;
  justify-content: center;
  width: 100%;
  aspect-ratio: 1;
  min-height: 36px;
  border-radius: calc(var(--rjk-period-radius) - 4px);
  font-variant-numeric: tabular-nums;
  text-decoration: none;
}

.rjk-period__day.is-available {
  color: var(--rjk-period-ink);
  background: var(--rjk-period-soft);
  font-weight: 700;
}

.rjk-period__day.is-available:hover {
  box-shadow: inset 0 0 0 2px var(--rjk-period-accent);
}

.rjk-period__day.is-unavailable {
  color: var(--rjk-period-muted);
  opacity: .6;
  cursor: default;
}

/* Today: accent ring + dot marker (non-text, so accent contrast is not critical). */
.rjk-period__day.is-today {
  box-shadow: inset 0 0 0 2px var(--rjk-period-accent);
}

.rjk-period__day.is-today::after {
  content: "";
  position: absolute;
  bottom: 4px;
  left: 50%;
  width: 4px;
  height: 4px;
  background: currentColor;
  border-radius: 50%;
  transform: translateX(-50%);
}

.rjk-period__day.is-selected {
  color: var(--rjk-period-selected-ink);
  background: var(--rjk-period-selected-bg);
  opacity: 1;
}

.rjk-period__day.is-selected.is-unavailable {
  background: color-mix(in srgb, var(--rjk-period-selected-bg) 55%, transparent);
}

.rjk-period__grid.is-week-mode tr.is-selected-week .rjk-period__day:not(.is-selected) {
  background: var(--rjk-period-soft);
}

.rjk-period__footer {
  display: flex;
  justify-content: center;
  margin-top: 8px;
  padding-top: 8px;
  border-top: 1px solid var(--rjk-period-line);
}

.rjk-period__whole-week {
  display: inline-flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: center;
  gap: 4px 6px;
  min-height: 44px;
  padding: 6px 14px;
  color: var(--rjk-period-ink);
  border: 1px solid var(--rjk-period-line);
  border-radius: var(--rjk-period-radius);
  font-weight: 650;
  text-decoration: none;
}

.rjk-period__whole-week:hover {
  background: var(--rjk-period-soft);
  border-color: var(--rjk-period-accent);
}

.rjk-period__whole-week-range {
  color: var(--rjk-period-muted);
  font-weight: 500;
}

/* Forced colours / high contrast: rely on system colours. */
@media (forced-colors: active) {
  .rjk-period__day.is-selected,
  .rjk-period__option.is-selected {
    forced-color-adjust: none;
    color: HighlightText;
    background: Highlight;
  }

  .rjk-period__day.is-today {
    outline: 2px solid CanvasText;
  }
}

@media (prefers-reduced-motion: reduce) {
  .rjk-period__caret {
    transition: none;
  }
}

@media (max-width: 420px) {
  .rjk-period {
    font-size: 14px;
  }

  .rjk-period__bar {
    width: 100%;
  }

  .rjk-period__menu {
    flex: 1 1 auto;
  }

  .rjk-period__summary {
    justify-content: space-between;
    max-width: none;
    padding: 0 10px;
  }

  .rjk-period__panel {
    position: fixed;
    top: auto;
    right: 12px;
    bottom: 12px;
    left: 12px;
    width: auto;
    min-width: 0; /* Desktop min-width:100% must not widen the fixed mobile sheet. */
    max-width: none;
    max-height: calc(100vh - 24px);
    overflow-y: auto;
    transform: none;
  }

  .rjk-period__calendar {
    width: 100%;
  }
}

/* Admin settings fieldset helpers (inherits rjk-profile-section styling). */
.rjk-period-settings__field {
  display: grid;
  gap: 4px;
  margin-top: 12px;
}

.rjk-period-settings__field select {
  max-width: 100%;
}

.rjk-period-settings__note {
  margin-top: 12px;
}

/* Optional profile footer reuses the selected template’s public navigation tokens. */
.rjk-public-week-pdf__link {
  justify-content: center;
  padding: 12px 18px;
  text-align: center;
  white-space: normal;
  line-height: 1.35;
}
