.date-field {
  position: relative;
}

.date-input-wrap {
  position: relative;
}

.date-input-wrap input,
.filterbar .date-input-wrap input {
  min-width: 142px;
  padding-inline-end: 34px;
  font-variant-numeric: tabular-nums;
}

.date-input-wrap .date-trigger {
  position: absolute;
  inset-block: 2px;
  inset-inline-end: 2px;
  width: 30px;
  min-height: 0;
  padding: 5px;
  border: 0;
  background: transparent;
  color: var(--green);
}

.date-input-wrap .date-trigger:hover {
  background: #f6ede7;
}

.date-dialog {
  --date-panel-top: clamp(12px, var(--date-top, 12px), calc(100dvh - var(--date-height, 410px) - 12px));
  position: fixed;
  inset: auto;
  left: clamp(12px, var(--date-left, 12px), calc(100vw - 356px));
  top: var(--date-panel-top);
  margin: 0;
  width: min(344px, calc(100vw - 24px));
  /* Live viewport changes can invalidate the last measured content height.
     Bound the panel by the space remaining below its resolved position. */
  max-height: calc(100dvh - var(--date-panel-top) - 12px);
  padding: 16px;
  border: 1px solid #d6d1cc;
  border-radius: 13px;
  overflow: auto;
  background: var(--surface);
  box-shadow: 0 16px 48px #1f1c192b;
}

.date-dialog::backdrop {
  background: #1d1a180d;
  backdrop-filter: none;
}

.date-dialog-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 12px;
  font-size: 13px;
}

.date-month-controls {
  display: grid;
  grid-template-columns: 30px minmax(0, 1fr) 74px 30px;
  align-items: center;
  gap: 7px;
  margin-bottom: 12px;
}

.date-dialog .date-month,
.date-dialog .date-year {
  width: 100%;
  min-width: 0;
  max-width: none;
  min-height: 34px;
  padding: 6px 8px;
  font-size: 12px;
}

.date-dialog .date-year {
  text-align: center;
  font-variant-numeric: tabular-nums;
}

.date-dialog .date-navigation {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 30px;
  height: 30px;
  min-height: 30px;
  padding: 5px;
  border: 1px solid transparent;
  color: var(--forest);
  background: transparent;
}

.date-dialog .date-navigation:hover {
  border-color: #dad6d2;
  background: #f6ede7;
}

.date-previous svg {
  transform: rotate(180deg);
}

.date-grid {
  width: 100%;
  table-layout: fixed;
  border-collapse: separate;
  border-spacing: 2px;
}

.date-grid th,
.date-grid td {
  padding: 0;
  border: 0;
  text-align: center;
  background: transparent;
}

.date-grid th {
  height: 30px;
  font-size: 11px;
  font-weight: 500;
  color: var(--muted);
}

.date-grid .date-day {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 100%;
  height: 36px;
  min-height: 36px;
  padding: 0;
  border: 1px solid transparent;
  border-radius: 7px;
  background: transparent;
  color: var(--ink);
  font-size: 12px;
  font-weight: 500;
  font-variant-numeric: tabular-nums;
}

.date-grid .date-day:hover {
  border-color: #c1bab2;
  background: #f6ede7;
}

.date-grid .date-day[aria-current="date"] {
  border-color: var(--green);
}

.date-grid td[aria-selected="true"] .date-day {
  border-color: var(--forest);
  background: var(--forest);
  color: white;
}

.date-grid .date-day:focus-visible {
  outline: 2px solid var(--green);
  outline-offset: 1px;
}

.date-footer {
  display: flex;
  justify-content: space-between;
  margin-top: 12px;
  padding-top: 12px;
  border-top: 1px solid var(--line);
}

.date-error {
  display: block;
  max-width: 26em;
  color: #a23c32;
  font-size: 11px;
  line-height: 1.5;
}

.date-error[hidden] {
  display: none;
}

.date-input-wrap input[aria-invalid="true"],
.date-year[aria-invalid="true"] {
  border-color: #a23c32;
}

.date-sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip-path: inset(50%);
  white-space: nowrap;
  border: 0;
}

@media (max-width: 480px) {
  .date-dialog {
    inset: 0;
    margin: auto;
    height: fit-content;
    max-height: calc(100dvh - 24px);
  }

  .date-grid .date-day {
    height: 40px;
  }
}

@media (forced-colors: active) {
  .date-grid td[aria-selected="true"] .date-day {
    background: Highlight;
    color: HighlightText;
    border-color: Highlight;
    forced-color-adjust: none;
  }

  .date-grid .date-day[aria-current="date"] {
    border-color: ButtonText;
  }
}
