/* Period toggle -segmented control for picking a time window
   (Today / Week / Month) or any 2–4-option mutually-exclusive nav.
   Used on dashboard, recipes list, and any future surface that needs
   a compact in-page period switcher. See docs/strategy/design-system. */

.period-toggle {
  display: inline-flex;
  padding: 2px;
  background: var(--surface-soft);
  border: 1px solid var(--divider);
  border-radius: var(--radius-sm);
}

.period-toggle-item {
  padding: var(--space-1) var(--space-2);
  border-radius: var(--radius-xs);
  border: 0;
  background: transparent;
  font-family: var(--font);
  font-size: var(--font-size-small);
  font-weight: 700;
  color: var(--muted);
  text-decoration: none;
  cursor: pointer;
  transition: background var(--duration-base) var(--ease-standard), color var(--duration-base) var(--ease-standard);
}

.period-toggle-item:hover:not(.is-active) {
  color: var(--text);
}

.period-toggle-item.is-active {
  background: var(--surface);
  color: var(--text);
  box-shadow: var(--shadow-sm);
}

/* Stretch variant -toggle fills its container, items share equal width.
   Opt-in per surface · use when the toggle owns the row (no sibling CTAs)
   and the page reads better edge-to-edge than as a compact left-aligned
   pill. Cogs analysis is the canonical consumer. */
.period-toggle.is-stretch {
  display: flex;
  width: 100%;
}

.period-toggle.is-stretch .period-toggle-item {
  flex: 1;
  text-align: center;
}

/* Right-aligned toggle row wrapper -used when the toggle is the
   sole content of its own row (no sibling content sharing the line).
   Wraps a <nav class="period-toggle"> in <div class="period-toggle-row">
   so the inline-flex toggle sticks to the right edge of the page
   container. */
.period-toggle-row {
  display: flex;
  justify-content: flex-end;
}

/* ── Custom date-range popover ────────────────────────────────
   <details data-shell-dropdown> wraps the Custom <summary> trigger
   + an absolutely-positioned form panel. Anchored to the right
   edge of the toggle so it stays inside the viewport on mobile.

   Critical fixes so the toggle layout isn't disturbed:
     1. <details> itself is `display: contents` -the wrapper
        contributes nothing to the inline-flex layout; only the
        <summary> child participates as a sibling of the <a>
        toggle items.
     2. <summary> uses `display: inline-flex` (not list-item) and
        the marker is hidden so it sits flush with the <a> items.
     3. The form is `position: absolute` against the .period-toggle
        ancestor (which gets `position: relative` so anchoring
        works).

   Wiring relies on shell topbar-dropdown.js for outside-click +
   Escape + mutual-exclusion. */
.period-toggle {
  position: relative;
}

.period-toggle-custom {
  display: contents;
}

.period-toggle-custom > summary {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  list-style: none;
  cursor: pointer;
}

.period-toggle-custom > summary::-webkit-details-marker,
.period-toggle-custom > summary::marker {
  display: none;
  content: "";
}

.period-toggle-custom-form {
  position: absolute;
  top: calc(100% + var(--space-1));
  /* Mobile-first: anchor to the LEFT edge of the toggle and grow
   * rightward, capped at viewport with a small inset. On desktop
   * (≥1024px) the toggle often sits flush-right of its row so we
   * switch to right-anchored there in the media query below. */
  left: 0;
  right: auto;
  z-index: 50;
  min-width: 17.5rem;
  max-width: calc(100vw - 2 * var(--space-3));
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow-md);
  padding: var(--space-3);
  display: flex;
  flex-direction: column;
  gap: var(--space-3);
}

.period-toggle-custom-form label {
  display: flex;
  flex-direction: column;
  gap: var(--space-1);
  font-size: var(--font-size-nano);
  font-weight: 800;
  text-transform: uppercase;
  letter-spacing: var(--letter-spacing-label);
  color: var(--muted);
}

.period-toggle-custom-form input[type="date"] {
  width: 100%;
  min-width: 0;
  min-height: 2.75rem;
  padding: var(--space-2) var(--space-3);
  border: 1px solid var(--divider);
  border-radius: var(--radius-sm);
  font-family: var(--font);
  font-size: var(--font-size-small);
  font-weight: 600;
  font-variant-numeric: tabular-nums;
  background: var(--surface);
  color: var(--text);
}

.period-toggle-custom-form input[type="date"]:focus {
  outline: 0;
  border-color: var(--primary);
  box-shadow: 0 0 0 2px var(--primary-light);
}

.period-toggle-custom-form button[type="submit"] {
  align-self: stretch;
  min-height: 2.75rem;
}

@media (min-width: 1024px) {
  .period-toggle-custom-form {
    /* Desktop: toggle typically sits right-aligned in its row, so
     * anchor the popover to the right edge of the toggle to keep it
     * inside the page body. */
    left: auto;
    right: 0;
    min-width: 19rem;
    max-width: none;
  }

  .period-toggle-custom-form button[type="submit"] {
    align-self: flex-end;
    min-width: 7rem;
  }
}
