/* The history tab: the search and insights entrances and the month calendar. */

/* The search entrance takes the row's width, the insights button sits at its right. */
.history-tools {
  display: flex;
  align-items: center;
  gap: var(--space-3);
  margin-top: var(--space-6);
}

/* The search entrance on the calendar reads as a field: tap it and the search page opens. */
.search-entry.ui\:btn {
  flex: 1;
  justify-content: flex-start;
  gap: var(--space-3);
  padding-inline: var(--space-4);
  border: 1px solid color-mix(in srgb, var(--color-border) 55%, transparent);
  border-radius: 999px;
  background: var(--color-surface);
  color: var(--color-muted);
  font-weight: 400;
  box-shadow: var(--shadow-card);
}

.stats-entry.ui\:btn {
  border: 1px solid color-mix(in srgb, var(--color-border) 55%, transparent);
  background: var(--color-surface);
  color: var(--color-primary);
  box-shadow: var(--shadow-card);
}

.calendar {
  --card-p: var(--space-4) var(--space-3) var(--space-3);
  margin-top: var(--space-4);
  gap: 0;
  border-radius: var(--radius-sheet);
  box-shadow: var(--shadow-lift);
}

.month-bar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 var(--space-1);
}

.month-title {
  display: flex;
  flex-direction: column;
  align-items: center;
  margin: 0;
  line-height: 1;
}

.month-title-button {
  display: flex;
  flex-direction: column;
  align-items: center;
  padding: var(--space-1) var(--space-3);
  border: 0;
  border-radius: var(--radius);
  background: none;
  color: inherit;
  font: inherit;
  line-height: 1;
  cursor: pointer;
}

.month-title-button:hover {
  background: var(--color-soft);
}

.month-picker {
  position: fixed;
  inset: 0;
  width: min(100% - 2 * var(--space-4), 20rem);
  height: fit-content;
  margin: auto;
  border: 0;
  color: var(--color-text);
  box-shadow: var(--shadow-card);
}

/* The card's display would otherwise beat the browser's rule that hides a closed popover. */
.month-picker:not(:popover-open) {
  display: none;
}

.month-picker::backdrop {
  background: rgb(31 42 27 / 0.35);
}

.month-picker-grid {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: var(--space-2);
  margin-top: var(--space-3);
}

.month-picker-grid .ui\:btn {
  padding-inline: 0;
  white-space: nowrap;
}

/* Future months exist only in this year; another year in the select brings them back. */
.month-picker:has(option[data-this-year]:checked) [data-future] {
  opacity: 0.4;
  pointer-events: none;
}

.month-picker-grid [aria-current] {
  background: var(--color-primary);
  color: var(--color-primary-contrast);
}

.month-year {
  color: var(--color-muted);
  font-size: var(--font-size-xs);
  font-weight: 700;
  letter-spacing: 0.2em;
}

.month-num {
  color: var(--color-primary);
  font-size: 2.75rem;
  font-weight: 800;
  font-variant-numeric: tabular-nums;
  letter-spacing: -0.03em;
}

.month-num small {
  margin-inline-start: 0.125em;
  color: var(--color-text);
  font-size: var(--font-size-md);
  letter-spacing: 0;
}

.round-button-space {
  width: var(--control-height);
  height: var(--control-height);
}

.round-button {
  background: var(--color-soft);
  color: var(--color-primary);
}

.month-grid {
  display: grid;
  grid-template-columns: repeat(7, minmax(0, 1fr));
  row-gap: var(--space-1);
  margin: var(--space-1) 0 0;
  padding: 0;
  list-style: none;
}

.weekdays {
  display: grid;
  grid-template-columns: repeat(7, minmax(0, 1fr));
  margin: var(--space-3) 0 var(--space-1);
  padding-bottom: var(--space-2);
  border-bottom: 1px solid var(--color-rule);
  color: var(--color-muted);
  font-size: var(--font-size-xs);
  font-weight: 700;
  text-align: center;
}

.day-cell {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 0.125rem;
  padding-block: var(--space-1);
  border-radius: var(--radius);
  color: var(--color-text);
  text-decoration: none;
}

.day-face {
  width: clamp(1.75rem, 6vw, 2.25rem);
  height: clamp(1.75rem, 6vw, 2.25rem);
}

/* The picked day sits in a soft well, so it reads apart from today's filled number. */
.day-cell[aria-current="date"] {
  background: var(--color-selected-bg);
}

.day-disc {
  fill: var(--color-day-0);
  stroke: transparent;
  stroke-width: 2.5;
}

.level-1 .day-disc {
  fill: var(--color-day-1);
}

.level-2 .day-disc {
  fill: var(--color-day-2);
}

.level-3 .day-disc {
  fill: var(--color-day-3);
}

.day-cell[aria-current="date"] .day-disc {
  stroke: var(--color-primary);
}

.day-colors {
  display: flex;
  gap: 2px;
  min-height: 0.375rem;
}

.day-colors .swatch {
  width: 0.375rem;
  height: 0.375rem;
  box-shadow: none;
}

.day-number {
  min-width: 1.75rem;
  padding: 0 var(--space-1);
  border-radius: 999px;
  color: var(--color-muted);
  font-size: var(--font-size-xs);
  font-variant-numeric: tabular-nums;
  line-height: 1.3;
  text-align: center;
}

.is-today .day-number {
  background: var(--color-primary);
  color: var(--color-primary-contrast);
  font-weight: 700;
}

/* The search form is one sheet, like the calendar it is reached from, kept short enough that a
   phone still shows the first results below it. */
.search-form {
  margin-top: var(--space-3);
  padding: var(--space-2) var(--space-3);
  border-radius: var(--radius-sheet);
  background: var(--color-surface);
  box-shadow: var(--shadow-lift);
}

.search-form > .field {
  margin: 0;
}

.search-keyword {
  display: flex;
  align-items: center;
  gap: var(--space-2);
}

.search-keyword > .ui\:btn {
  flex: none;
}

/* A date field's own minimum width would push the second one off a phone's screen. */
.search-period {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto minmax(0, 1fr);
  align-items: center;
  gap: var(--space-1);
}

/* 1rem is the smallest text iOS Safari does not zoom into, and leaves Chrome's picker icon room. */
.search-period > .ui\:input {
  min-width: 0;
  padding-inline: var(--space-2);
  font-size: 1rem;
}
