/**
 * Calendar styles
 * @countermeasure/web-components/form/calendar
 */

/* ==========================================================================
   Calendar Root
   ========================================================================== */

.cmm-calendar {
  display: inline-block;
  background-color: hsl(var(--background));
  border: 1px solid hsl(var(--border));
  border-radius: var(--radius-md);
  padding: 0.75rem;
  user-select: none;
  width: 280px;
}

/* ==========================================================================
   Header - month/year navigation
   ========================================================================== */

.cmm-calendar__header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 0.5rem;
  padding: 0 0.25rem;
}

.cmm-calendar__title {
  font-size: 0.875rem;
  font-weight: 600;
  color: hsl(var(--foreground));
}

.cmm-calendar__nav-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 1.75rem;
  height: 1.75rem;
  padding: 0;
  border: none;
  border-radius: var(--radius-sm);
  background-color: transparent;
  color: hsl(var(--muted-foreground));
  cursor: pointer;
  transition: background-color var(--transition-fast),
    color var(--transition-fast);
}

.cmm-calendar__nav-btn:hover {
  background-color: hsl(var(--accent));
  color: hsl(var(--accent-foreground));
}

.cmm-calendar__nav-btn:focus-visible {
  outline: 2px solid hsl(var(--focus-ring));
  outline-offset: 2px;
}

/* ==========================================================================
   Grid
   ========================================================================== */

.cmm-calendar__grid {
  outline: none;
}

.cmm-calendar__grid:focus-visible {
  outline: 2px solid hsl(var(--focus-ring));
  outline-offset: 2px;
  border-radius: var(--radius-sm);
}

/* ==========================================================================
   Weekday header labels
   ========================================================================== */

.cmm-calendar__weekdays {
  display: grid;
  grid-template-columns: repeat(7, 1fr);
  margin-bottom: 0.25rem;
}

.cmm-calendar__weekday {
  display: flex;
  align-items: center;
  justify-content: center;
  height: 2rem;
  font-size: 0.75rem;
  font-weight: 500;
  color: hsl(var(--muted-foreground));
  text-transform: uppercase;
  letter-spacing: 0.02em;
}

/* ==========================================================================
   Day rows
   ========================================================================== */

.cmm-calendar__row {
  display: grid;
  grid-template-columns: repeat(7, 1fr);
}

/* ==========================================================================
   Day cells
   ========================================================================== */

.cmm-calendar__day {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 100%;
  height: 2rem;
  padding: 0;
  border: none;
  border-radius: var(--radius-sm);
  background-color: transparent;
  color: hsl(var(--foreground));
  font-size: 0.8125rem;
  cursor: pointer;
  transition: background-color var(--transition-fast),
    color var(--transition-fast);
  position: relative;
}

.cmm-calendar__day:hover:not(.cmm-calendar__day--disabled):not(.cmm-calendar__day--selected) {
  background-color: hsl(var(--accent));
  color: hsl(var(--accent-foreground));
}

.cmm-calendar__day:focus-visible {
  outline: 2px solid hsl(var(--focus-ring));
  outline-offset: -2px;
  z-index: 1;
}

/* Today */
.cmm-calendar__day--today {
  font-weight: 700;
  color: hsl(var(--primary));
}

.cmm-calendar__day--today::after {
  content: '';
  position: absolute;
  bottom: 2px;
  left: 50%;
  transform: translateX(-50%);
  width: 4px;
  height: 4px;
  border-radius: 50%;
  background-color: hsl(var(--primary));
}

/* Selected */
.cmm-calendar__day--selected {
  background-color: hsl(var(--primary));
  color: hsl(var(--primary-foreground));
  font-weight: 600;
}

.cmm-calendar__day--selected:hover {
  background-color: hsl(var(--primary));
  color: hsl(var(--primary-foreground));
}

.cmm-calendar__day--selected.cmm-calendar__day--today::after {
  background-color: hsl(var(--primary-foreground));
}

/* Outside days (prev/next month) */
.cmm-calendar__day--outside {
  color: hsl(var(--muted-foreground));
  opacity: 1;
}

/* Disabled */
.cmm-calendar__day--disabled {
  color: hsl(var(--muted-foreground));
  opacity: 0.35;
  cursor: not-allowed;
  pointer-events: none;
}

/* ==========================================================================
   Range selection states
   ========================================================================== */

.cmm-calendar__day--range-start {
  border-radius: var(--radius-sm) 0 0 var(--radius-sm);
}

.cmm-calendar__day--range-end {
  border-radius: 0 var(--radius-sm) var(--radius-sm) 0;
}

.cmm-calendar__day--range-start.cmm-calendar__day--range-end {
  border-radius: var(--radius-sm);
}

.cmm-calendar__day--in-range {
  background-color: hsl(var(--accent));
  color: hsl(var(--accent-foreground));
  border-radius: 0;
}

.cmm-calendar__day--in-range:hover {
  background-color: hsl(var(--accent));
}

/* ==========================================================================
   Touch Device Enhancements (WCAG 2.5.5 - 44px minimum)
   ========================================================================== */

@media (pointer: coarse) {
  .cmm-calendar {
    width: 320px;
    padding: 1rem;
  }

  .cmm-calendar__nav-btn {
    width: 2.75rem;
    height: 2.75rem;
  }

  .cmm-calendar__weekday {
    height: 2.75rem;
    font-size: 0.8125rem;
  }

  .cmm-calendar__day {
    height: 2.75rem;
    font-size: 0.9375rem;
  }
}
