/* Period navigator — same instrument as the Agenda range (‹ 09/11 – 15/11 › Hoje),
   preceded by the preset selector. Clicking the dates opens a small panel to type them. */
@scope (.period-filter) {
  :scope {
    --pf-h: 2.5rem;
    --pf-border: var(--color-border);
    display: inline-flex;
    flex-wrap: wrap;
    align-items: stretch;
    gap: var(--space-sm, .5rem);
    max-inline-size: 100%;
    color: var(--color-text-heading);
    font-size: var(--text-body);
  }

  .period-filter__preset,
  .period-filter__range {
    display: inline-flex;
    align-items: stretch;
    min-block-size: var(--pf-h);
    border: 1px solid var(--pf-border);
    border-radius: var(--radius-xl);
    background: var(--color-surface);
    box-shadow: var(--shadow-xs);
  }

  /* Preset */
  .period-filter__preset { position: relative; align-items: center; }
  .period-filter__icon {
    position: absolute;
    inset-inline-start: .8rem;
    inline-size: 1rem;
    block-size: 1rem;
    color: var(--color-text-muted);
    pointer-events: none;
  }
  .period-filter__preset select {
    appearance: none;
    -webkit-appearance: none;
    align-self: stretch;
    padding: 0 2.25rem 0 2.3rem;
    border: 0;
    border-radius: inherit;
    background-color: var(--color-surface);
    background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='24' height='24' fill='%2364748b'%3E%3Cpath d='m12 15.41 5.71-5.7-1.42-1.42-4.29 4.3-4.29-4.3-1.42 1.42z'/%3E%3C/svg%3E");
    background-repeat: no-repeat;
    background-position: right .65rem center;
    background-size: 1.25rem;
    color: inherit;
    font: inherit;
    font-weight: var(--font-semibold, 600);
    cursor: pointer;
  }
  .period-filter__preset select:hover {
    background-color: var(--color-surface-muted, rgb(0 0 0 / .04));
  }

  /* Navigator */
  .period-filter__range { position: relative; }
  .period-filter__step,
  .period-filter__today,
  .period-filter__range-label {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    color: inherit;
    text-decoration: none;
    cursor: pointer;
  }
  .period-filter__step { inline-size: 2.5rem; color: var(--color-text-secondary); }
  .period-filter__step .icon { inline-size: 1rem; block-size: 1rem; }
  .period-filter__step:first-child { border-start-start-radius: calc(var(--radius-xl) - 1px); border-end-start-radius: calc(var(--radius-xl) - 1px); }
  .period-filter__range-label {
    block-size: 100%;
    min-inline-size: 9.5rem;
    padding-inline: var(--space-md, .75rem);
    font-family: var(--font-mono);
    font-variant-numeric: tabular-nums;
    white-space: nowrap;
    list-style: none;
  }
  .period-filter__range-label.period-filter__range-label--prompt {
    min-inline-size: 0;
    padding-inline: var(--space-lg, 1rem);
    font-family: var(--font-body);
    font-weight: var(--font-medium);
    color: var(--color-text-secondary);
  }
  .period-filter__custom:first-child .period-filter__range-label {
    border-start-start-radius: calc(var(--radius-xl) - 1px);
    border-end-start-radius: calc(var(--radius-xl) - 1px);
  }
  .period-filter__custom:last-child .period-filter__range-label {
    border-start-end-radius: calc(var(--radius-xl) - 1px);
    border-end-end-radius: calc(var(--radius-xl) - 1px);
  }
  .period-filter__step + .period-filter__custom .period-filter__range-label {
    border-inline-start: 1px solid var(--pf-border);
  }
  .period-filter__custom:has(+ .period-filter__step) .period-filter__range-label {
    border-inline-end: 1px solid var(--pf-border);
  }
  .period-filter__range-label::-webkit-details-marker { display: none; }
  .period-filter__today {
    padding-inline: var(--space-md, .75rem);
    border-inline-start: 1px solid var(--pf-border);
    border-start-end-radius: calc(var(--radius-xl) - 1px);
    border-end-end-radius: calc(var(--radius-xl) - 1px);
    font-weight: var(--font-semibold, 600);
  }
  :is(.period-filter__step, .period-filter__today, .period-filter__range-label):hover {
    background: var(--color-surface-muted, rgb(0 0 0 / .04));
    color: var(--color-text-heading);
    text-decoration: none;
  }

  /* Custom dates panel */
  .period-filter__custom { display: contents; }
  .period-filter__custom[open] .period-filter__range-label { background: var(--color-surface-muted, rgb(0 0 0 / .04)); }
  .period-filter__panel {
    position: absolute;
    inset-block-start: calc(100% + .4rem);
    inset-inline-start: 0;
    z-index: 20;
    display: flex;
    flex-wrap: wrap;
    align-items: end;
    gap: .75rem;
    inline-size: max-content;
    max-inline-size: min(26rem, 90vw);
    padding: .9rem;
    border: 1px solid var(--pf-border);
    border-radius: var(--radius-xl);
    background: var(--color-surface);
    box-shadow: var(--shadow-md, 0 8px 24px rgb(15 23 42 / .12));
  }
  .period-filter__panel label { display: grid; gap: .3rem; }
  .period-filter__panel label > span { color: var(--color-text-secondary); font-size: var(--text-body-sm); font-weight: 600; }
  .period-filter__panel input {
    block-size: 2.25rem;
    padding: 0 .6rem;
    border: 1px solid var(--pf-border);
    border-radius: var(--radius-lg);
    background: var(--color-surface);
    color: inherit;
    font-family: var(--font-mono);
    font-size: var(--text-body);
    font-variant-numeric: tabular-nums;
  }
  .period-filter__panel input[aria-invalid="true"] { border-color: var(--color-danger, #b42318); }
  .period-filter__apply {
    block-size: 2.25rem;
    padding: 0 1rem;
    border: 0;
    border-radius: var(--radius-lg);
    background: var(--color-text-heading);
    color: var(--color-surface);
    font: inherit;
    font-weight: 600;
    cursor: pointer;
  }
  .period-filter__apply:hover { opacity: .85; }

  .period-filter__hint, .period-filter__error { flex-basis: 100%; margin: 0; font-size: var(--text-body-sm); }
  .period-filter__hint { color: var(--color-text-secondary); }
  .period-filter__error { color: var(--color-danger, #b42318); }

  :is(select, a, summary, input, button):focus-visible { outline: 2px solid var(--color-focus, currentColor); outline-offset: -2px; }
}

@media (width < 600px) {
  @scope (.period-filter) {
    :scope { display: flex; inline-size: 100%; }
    .period-filter__preset, .period-filter__range { inline-size: 100%; }
    .period-filter__preset select { inline-size: 100%; }
    .period-filter__range-label { flex: 1; min-inline-size: 0; }
  }
}

/* Slot that period-placement moves under the page headline. */
.period-filter-slot { display: block; margin-block: .75rem 1rem; }
header .period-filter-slot { flex-basis: 100%; grid-column: 1 / -1; justify-self: start; align-self: start; margin-block: .75rem 0; }
.period-filter-slot > .period-filter-caption { margin: .35rem 0 0 .9rem; color: var(--color-text-muted); font-size: var(--text-body-sm); }
