/* Colors are written as light-dark(light, dark); the theme option pins color-scheme. */
.picker {
  color-scheme: light dark;

  /* Customizable (set by the accentColor and radius options) */
  --accent: light-dark(#000000, #ffffff);
  --radius: 8px;

  /* Surface & text */
  --color-surface: light-dark(#ffffff, #171717);
  --color-text: light-dark(#1e1e1e, #fafafa);
  --color-text-muted: light-dark(#000000af, #ffffffa6);
  --color-text-disabled: light-dark(#00000033, #ffffff33);

  /* Neutral fill & border */
  --color-fill-subtle: light-dark(#00000010, #ffffff14);
  --color-border: light-dark(#0000001a, #ffffff1f);

  /* Selection, derived from the accent (stronger on dark, where tints read weaker) */
  --color-range: light-dark(color-mix(in srgb, var(--accent) 6%, transparent), color-mix(in srgb, var(--accent) 12%, transparent));
  --color-selected: light-dark(color-mix(in srgb, var(--accent) 12%, transparent), color-mix(in srgb, var(--accent) 24%, transparent));
  --color-selected-hover: light-dark(color-mix(in srgb, var(--accent) 18%, transparent), color-mix(in srgb, var(--accent) 32%, transparent));
  --color-stroke-selected: light-dark(color-mix(in srgb, var(--accent) 31%, transparent), color-mix(in srgb, var(--accent) 50%, transparent));
  --color-stroke-selected-hover: light-dark(color-mix(in srgb, var(--accent) 45%, transparent), color-mix(in srgb, var(--accent) 65%, transparent));

  /* Focus */
  --color-ring: light-dark(#0000005e, #ffffff66);
  --color-ring-soft: light-dark(#00000030, #ffffff38);

  /* Shadow */
  --color-shadow: light-dark(#0000001a, #00000080);
  --shadow-xs: 0 1px 2px light-dark(#0000000d, #0000004d);
  --shadow-md: 0 4px 6px -1px var(--color-shadow), 0 2px 4px -2px var(--color-shadow);

  /* Sizes */
  --size-control: 36px;
  --size-cell: 40px;
  --size-nav: 32px;
  --size-icon: 16px;

  /* Motion */
  --duration-fast: 0.15s;
  --duration-base: 0.2s;
  --ease-out: cubic-bezier(0.16, 1, 0.3, 1);

  display: flex;
  flex-direction: column;
  align-items: flex-start;
  gap: 4px;
  color: var(--color-text);
  user-select: none;
}

/* Resets use :where() so they never outweigh the component's own rules. */
:where(.picker, .picker *, .picker *::before, .picker *::after) {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

:where(.picker) button {
  font: inherit;
  color: inherit;
  background: none;
  border: none;
  cursor: pointer;
}

/* Trigger (shadcn/ui outline button) */

.picker__trigger {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  min-width: 260px;
  height: var(--size-control);
  padding: 0 12px;
  font-size: 14px;
  background-color: var(--color-surface);
  border: 1px solid var(--color-border);
  border-radius: var(--radius);
  box-shadow: var(--shadow-xs);
  transition:
    background-color var(--duration-fast) ease,
    border-color var(--duration-fast) ease,
    box-shadow var(--duration-fast) ease;
}

.picker__trigger:focus-visible,
.month__nav:focus-visible {
  outline: none;
  border-color: var(--color-ring);
  box-shadow: 0 0 0 3px var(--color-ring-soft);
}

.picker__trigger svg {
  width: var(--size-icon);
  height: var(--size-icon);
  flex-shrink: 0;
}

.month__nav svg {
  width: 20px;
  height: 20px;
}

.picker__chevron {
  margin-left: auto;
  color: var(--color-text-muted);
  transition: transform var(--duration-base) ease;
}

.picker__trigger[aria-expanded="true"] .picker__chevron {
  transform: rotate(180deg);
}

/* Panel */

.picker__panel {
  display: grid;
  grid-auto-flow: column;
  column-gap: 36px;
  padding: 8px 16px 16px;
  background-color: var(--color-surface);
  border: 1px solid var(--color-border);
  border-radius: var(--radius);
  box-shadow: var(--shadow-md);
  opacity: 0;
  visibility: hidden;
  pointer-events: none;
  transform: translateY(-6px);
  transition:
    opacity var(--duration-base) ease,
    transform var(--duration-base) var(--ease-out),
    visibility var(--duration-base);
}

.picker__panel.is-open {
  opacity: 1;
  visibility: visible;
  pointer-events: auto;
  transform: none;
}

/* Month */

.month__header {
  display: flex;
  align-items: center;
  height: 36px;
  margin-bottom: 12px;
}

.month__title {
  flex: 1;
  font-size: 16px;
  font-weight: 700;
  letter-spacing: -0.01em;
  text-align: center;
}

.month__nav {
  display: grid;
  place-items: center;
  width: var(--size-nav);
  height: var(--size-nav);
  border-radius: var(--radius);
  transition: background-color var(--duration-fast) ease;
}

/* Side by side, "<" belongs to the first month and ">" to the last one. */
.month:not(:last-child) .month__nav[data-step="1"],
.month:not(:first-child) .month__nav[data-step="-1"] {
  visibility: hidden;
}

.month__weekdays,
.month__days {
  display: grid;
  grid-template-columns: repeat(7, var(--size-cell));
}

.month__weekdays {
  margin-bottom: 8px;
}

.month__weekday {
  padding: 4px 0;
  font-size: 13px;
  font-weight: 500;
  color: var(--color-text-muted);
  text-align: center;
}

.month__days {
  row-gap: 5px;
}

/* Day */

.day {
  --stroke: var(--color-stroke-selected);
  display: flex;
  height: var(--size-cell);
  font-size: 15px;
  font-weight: 500;
}

.day--outside {
  color: var(--color-text-disabled);
  pointer-events: none;
}

.day__label {
  flex: 1;
  display: grid;
  place-items: center;
  border-radius: var(--radius);
  transition: background-color var(--duration-fast) ease;
}

.day:focus-visible {
  outline: none;
}

.day:focus-visible .day__label {
  outline: 3px solid var(--color-ring-soft);
  outline-offset: -3px;
}

/* Range band: rounded where it starts or ends, and at row and month edges. */
.day:is(.is-start, .is-between, .is-end):not(.is-connected) {
  background-color: var(--color-range);
}

.day:is(.is-start, .day--edge-start) {
  border-top-left-radius: var(--radius);
  border-bottom-left-radius: var(--radius);
}

.day:is(.is-end, .day--edge-end) {
  border-top-right-radius: var(--radius);
  border-bottom-right-radius: var(--radius);
}

.day:is(.is-start, .is-end, .is-single) .day__label {
  font-weight: 600;
  background-color: var(--color-selected);
  box-shadow: inset 0 0 0 1px var(--stroke);
}

/* Two adjacent endpoints merge into one pill. */
.day.is-start.is-connected .day__label {
  border-top-right-radius: 0;
  border-bottom-right-radius: 0;
  box-shadow: inset 1px 1px 0 var(--stroke), inset 0 -1px 0 var(--stroke);
}

.day.is-end.is-connected .day__label {
  border-top-left-radius: 0;
  border-bottom-left-radius: 0;
  box-shadow: inset -1px 1px 0 var(--stroke), inset 0 -1px 0 var(--stroke);
}

/* Hover (pointer devices only, so it doesn't stick after a tap) */

@media (hover: hover) {
  /* Layered over the opaque surface so the trigger stays solid on any page background. */
  .picker__trigger:hover {
    background-image: linear-gradient(var(--color-fill-subtle), var(--color-fill-subtle));
  }

  .month__nav:hover,
  .day:not(.is-start, .is-end, .is-single):hover .day__label {
    background-color: var(--color-fill-subtle);
  }

  .day:is(.is-start, .is-end, .is-single):hover .day__label {
    background-color: var(--color-selected-hover);
  }

  .day.is-editable:hover {
    --stroke: var(--color-stroke-selected-hover);
  }
}

/* Narrow screens: months stacked, both arrows on the first month. */

@media (max-width: 700px) {
  .picker,
  .picker__panel {
    width: 100%;
  }

  .picker__panel {
    grid-auto-flow: row;
    row-gap: 24px;
  }

  .month__weekdays,
  .month__days {
    grid-template-columns: repeat(7, 1fr);
  }

  .month:first-child .month__nav[data-step="1"] {
    visibility: visible;
  }

  .month:not(:first-child) .month__nav {
    display: none;
  }
}
