/* ===== Changing a list's dates =====
   Tap the dates under the title on the List and Meals tabs for a sheet to change them, or the pencil
   on a Home tab list card for the same form on its own page. */

/* The dates under the page title, with a pencil to say they can be changed */
.header-dates-button {
  position: relative;
  display: inline-flex;
  align-items: center;
  gap: 4px;
  min-height: 0;
  margin: 0;
  padding: 0 2px;
  background: none;
  border: none;
  border-radius: var(--border-radius-sm);
  color: var(--color-text-muted);
  font: inherit;
  line-height: 1.2;
  cursor: pointer;
}

/* A 44px tall tap target, reaching up over the title (which does nothing on its own) */
.header-dates-button::before {
  content: "";
  position: absolute;
  inset: -26px -12px -4px;
}

.header-dates-button:hover,
.header-dates-button:active {
  background: none;
  color: var(--color-text-muted);
  transform: none;
}

.header-dates-button:focus-visible {
  outline: 2px solid var(--color-primary);
  outline-offset: 2px;
}

.header-dates-icon {
  flex-shrink: 0;
  color: var(--color-primary-text);
}

/* The sheet: a <dialog> that slides up from the bottom of the screen */
.dates-sheet {
  position: fixed;
  inset: auto 0 0;
  width: 100%;
  max-width: 100%;
  max-height: 85dvh;
  margin: 0;
  padding: 0;
  border: none;
  border-radius: var(--border-radius-xl) var(--border-radius-xl) 0 0;
  background: var(--color-bg-medium);
  color: var(--color-text);
  text-align: left;
  box-shadow: 0 -4px 20px rgba(0, 0, 0, 0.15);
  overflow-y: auto;
  overscroll-behavior: contain;
  transform: translateY(100%);
  transition: transform 300ms cubic-bezier(0.32, 0.72, 0, 1), overlay 300ms allow-discrete, display 300ms allow-discrete;
}

.dates-sheet[open] {
  transform: translateY(0);
}

@starting-style {
  .dates-sheet[open] {
    transform: translateY(100%);
  }
}

.dates-sheet::backdrop {
  background: rgba(0, 0, 0, 0);
  transition: background 300ms ease, overlay 300ms allow-discrete, display 300ms allow-discrete;
}

.dates-sheet[open]::backdrop {
  background: rgba(0, 0, 0, 0.5);
}

@starting-style {
  .dates-sheet[open]::backdrop {
    background: rgba(0, 0, 0, 0);
  }
}

@media (prefers-reduced-motion: reduce) {
  .dates-sheet,
  .dates-sheet::backdrop {
    transition: none;
  }
}

/* The page behind doesn't scroll while the sheet is open */
body:has(.dates-sheet[open]) {
  overflow: hidden;
}

/* Fills the dialog, so a tap on the dialog itself is a tap on the dimmed page outside it */
.dates-sheet-body {
  max-width: 480px;
  margin: 0 auto;
  padding: var(--space-lg) var(--space-lg) calc(var(--space-md) + env(safe-area-inset-bottom));
}

.dates-sheet-cancel,
.dates-sheet-cancel:hover,
.dates-sheet-cancel:active {
  width: 100%;
  min-height: 48px;
  margin-top: var(--space-xs);
  background: transparent;
  border: none;
  color: var(--color-primary-text);
  font-weight: 600;
  transform: none;
}

/* The form, in the sheet and on the edit page */
/* Side by side, each shrinking to half the width (date fields are wider than that by default) */
.list-dates-fields {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: var(--space-sm);
}

.list-dates-fields .sheet-field {
  min-width: 0;
}

.list-dates-fields .sheet-input {
  min-width: 0;
  min-height: 48px;
  padding-inline: 12px;
}

/* iOS centres the date in a date field otherwise */
.list-dates-fields .sheet-input::-webkit-date-and-time-value {
  text-align: left;
}

/* The live region stays in the page for screen readers; while it's empty, it takes back the form's gap */
.list-dates-live:has(> .list-dates-warning[hidden]) {
  margin-top: calc(-1 * var(--space-md));
}

.list-dates-warning {
  padding: var(--space-md);
  border: 1.5px solid rgba(239, 68, 68, 0.3);
  border-radius: var(--border-radius-md);
  background: rgba(239, 68, 68, 0.08);
}

.list-dates-warning[hidden] {
  display: none;
}

.list-dates-warning-title {
  margin: 0 0 var(--space-xs);
  font-weight: 600;
  color: var(--color-danger-text);
}

.list-dates-removals {
  display: flex;
  flex-direction: column;
  gap: 4px;
  margin: 0;
  padding: 0;
  list-style: none;
  color: var(--color-text);
}

.list-dates-removal-day {
  font-weight: 600;
  white-space: nowrap;
}

.list-dates-submit.is-destructive {
  background: var(--color-danger);
}

.list-dates-submit.is-destructive:hover,
.list-dates-submit.is-destructive:active {
  background: var(--color-danger-dark);
}

/* Home tab: each list card has a pencil beside it for changing its dates */
.list-card-row {
  display: flex;
  align-items: stretch;
  background: var(--color-bg-medium);
}

.list-card-row > form {
  display: flex;
  flex: 1;
  min-width: 0;
}

.list-card-edit {
  display: flex;
  flex: 0 0 52px;
  align-items: center;
  justify-content: center;
  border-left: 1px solid var(--color-border);
  color: var(--color-primary-text);
  -webkit-tap-highlight-color: transparent;
}

.list-card-edit:hover,
.list-card-edit:active {
  background: var(--color-bg-light);
  color: var(--color-primary-text-hover);
}
