/**
 * DatePicker, DateRangePicker, and TimePicker styles
 * @countermeasure/web-components/form/date-picker
 */

/* ==========================================================================
   DatePicker
   ========================================================================== */

.cmm-date-picker {
  position: relative;
  display: inline-block;
  width: 100%;
}

.cmm-date-picker__input-wrap {
  display: flex;
  align-items: center;
  background-color: hsl(var(--background));
  border: 1px solid hsl(var(--border));
  border-radius: var(--radius-md);
  transition: border-color var(--transition-fast),
    box-shadow var(--transition-fast);
}

.cmm-date-picker__input-wrap:focus-within {
  border-color: hsl(var(--ring));
  box-shadow: 0 0 0 2px hsl(var(--focus-ring) / 0.2);
}

.cmm-date-picker__input {
  flex: 1;
  min-width: 0;
  padding: 0.5rem 0.75rem;
  border: none;
  background-color: transparent;
  color: hsl(var(--foreground));
  font-size: 0.875rem;
  line-height: 1.5;
  outline: none;
}

.cmm-date-picker__input::placeholder {
  color: hsl(var(--foreground) / 0.72);
}

.cmm-date-picker__clear,
.cmm-date-picker__toggle {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 2rem;
  height: 2rem;
  padding: 0;
  border: none;
  background-color: transparent;
  color: hsl(var(--foreground) / 0.76);
  cursor: pointer;
  flex-shrink: 0;
  border-radius: var(--radius-sm);
  transition: color var(--transition-fast),
    background-color var(--transition-fast);
}

.cmm-date-picker__clear:hover,
.cmm-date-picker__toggle:hover {
  color: hsl(var(--foreground));
  background-color: hsl(var(--accent));
}

.cmm-date-picker__clear:focus-visible,
.cmm-date-picker__toggle:focus-visible {
  outline: 2px solid hsl(var(--focus-ring));
  outline-offset: 2px;
}

/* Dropdown */

.cmm-date-picker__dropdown {
  position: absolute;
  left: 0;
  z-index: var(--z-dropdown);
  background-color: hsl(var(--popover));
  border: 1px solid hsl(var(--border));
  border-radius: var(--radius-md);
  box-shadow: var(--shadow-lg);
  padding: 0.25rem;
}

.cmm-date-picker__dropdown--below {
  top: calc(100% + 4px);
}

.cmm-date-picker__dropdown--above {
  bottom: calc(100% + 4px);
}

/* ==========================================================================
   DateRangePicker
   ========================================================================== */

.cmm-date-range {
  position: relative;
  display: inline-block;
  width: 100%;
}

.cmm-date-range__input-wrap {
  display: flex;
  align-items: center;
  background-color: hsl(var(--background));
  border: 1px solid hsl(var(--border));
  border-radius: var(--radius-md);
  transition: border-color var(--transition-fast),
    box-shadow var(--transition-fast);
}

.cmm-date-range__input-wrap:focus-within {
  border-color: hsl(var(--ring));
  box-shadow: 0 0 0 2px hsl(var(--focus-ring) / 0.2);
}

.cmm-date-range__input {
  flex: 1;
  min-width: 0;
  padding: 0.5rem 0.75rem;
  border: none;
  background-color: transparent;
  color: hsl(var(--foreground));
  font-size: 0.875rem;
  line-height: 1.5;
  outline: none;
  cursor: pointer;
}

.cmm-date-range__input::placeholder {
  color: hsl(var(--foreground) / 0.72);
}

.cmm-date-range__toggle {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 2rem;
  height: 2rem;
  padding: 0;
  border: none;
  background-color: transparent;
  color: hsl(var(--foreground) / 0.76);
  cursor: pointer;
  flex-shrink: 0;
  border-radius: var(--radius-sm);
  transition: color var(--transition-fast),
    background-color var(--transition-fast);
}

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

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

/* Dropdown */

.cmm-date-range__dropdown {
  position: absolute;
  left: 0;
  z-index: var(--z-dropdown);
  background-color: hsl(var(--popover));
  border: 1px solid hsl(var(--border));
  border-radius: var(--radius-md);
  box-shadow: var(--shadow-lg);
  min-width: 640px;
}

.cmm-date-range__dropdown--below {
  top: calc(100% + 4px);
}

.cmm-date-range__dropdown--above {
  bottom: calc(100% + 4px);
}

/* Body layout */

.cmm-date-range__body {
  display: flex;
}

/* Presets sidebar */

.cmm-date-range__presets {
  display: flex;
  flex-direction: column;
  gap: 0.125rem;
  padding: 0.75rem;
  border-right: 1px solid hsl(var(--border));
  min-width: 140px;
}

.cmm-date-range__preset-btn {
  display: block;
  width: 100%;
  padding: 0.375rem 0.625rem;
  border: none;
  border-radius: var(--radius-sm);
  background-color: transparent;
  color: hsl(var(--foreground));
  font-size: 0.8125rem;
  text-align: left;
  cursor: pointer;
  transition: background-color var(--transition-fast);
  white-space: nowrap;
}

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

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

/* Two calendar layout */

.cmm-date-range__calendars {
  display: flex;
  gap: 0.5rem;
  padding: 0.5rem;
}

.cmm-date-range__calendar-left,
.cmm-date-range__calendar-right {
  flex: 1;
}

.cmm-date-range__calendar-left .cmm-calendar,
.cmm-date-range__calendar-right .cmm-calendar {
  border: none;
  padding: 0.25rem;
  width: 100%;
}

/* Footer with buttons */

.cmm-date-range__footer {
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: 0.5rem;
  padding: 0.625rem 0.75rem;
  border-top: 1px solid hsl(var(--border));
}

.cmm-date-range__cancel-btn {
  padding: 0.375rem 0.875rem;
  border: 1px solid hsl(var(--border));
  border-radius: var(--radius-md);
  background-color: hsl(var(--background));
  color: hsl(var(--foreground));
  font-size: 0.8125rem;
  cursor: pointer;
  transition: background-color var(--transition-fast);
}

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

.cmm-date-range__apply-btn {
  padding: 0.375rem 0.875rem;
  border: none;
  border-radius: var(--radius-md);
  background-color: hsl(var(--primary));
  color: hsl(var(--primary-foreground));
  font-size: 0.8125rem;
  font-weight: 500;
  cursor: pointer;
  transition: opacity var(--transition-fast);
}

.cmm-date-range__apply-btn:hover {
  opacity: 0.9;
}

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

/* ==========================================================================
   TimePicker
   ========================================================================== */

.cmm-time-picker {
  display: inline-flex;
  align-items: stretch;
  gap: 0;
  background-color: hsl(var(--background));
  border: 1px solid hsl(var(--border));
  border-radius: var(--radius-md);
  padding: 0.5rem 0.25rem;
}

.cmm-time-picker__column {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 0.125rem;
  max-height: 10rem;
  overflow-y: auto;
  padding: 0 0.25rem;
  scrollbar-width: thin;
  scrollbar-color: hsl(var(--muted)) transparent;
  outline: none;
}

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

.cmm-time-picker__separator {
  display: flex;
  align-items: center;
  padding: 0 0.125rem;
  font-size: 0.875rem;
  font-weight: 600;
  color: hsl(var(--muted-foreground));
  align-self: flex-start;
  margin-top: 0.25rem;
}

.cmm-time-picker__item {
  display: flex;
  align-items: center;
  justify-content: center;
  min-width: 2.25rem;
  height: 1.75rem;
  padding: 0 0.375rem;
  border: none;
  border-radius: var(--radius-sm);
  background-color: transparent;
  color: hsl(var(--foreground));
  font-size: 0.8125rem;
  font-variant-numeric: tabular-nums;
  cursor: pointer;
  transition: background-color var(--transition-fast),
    color var(--transition-fast);
}

.cmm-time-picker__item:hover:not(.cmm-time-picker__item--selected) {
  background-color: hsl(var(--accent));
}

.cmm-time-picker__item--selected {
  background-color: hsl(var(--primary));
  color: hsl(var(--primary-foreground));
  font-weight: 600;
}

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

.cmm-time-picker__period {
  margin-left: 0.25rem;
  border-left: 1px solid hsl(var(--border));
  padding-left: 0.375rem;
}
