/*
 * Every day (views/days.js): the database chapter of Trends.
 * Wide (>= 600px): a table in a bounded box that scrolls on its own, sticky header and
 * date column. Phones: a compact list that scrolls with the page, its header sticky under
 * the chapter switcher. Rows have a fixed height (--days-row-h; days.js reads it).
 * Tokens only (true black dark theme by default, light theme from styles.css).
 */

.days-chapter .chapter-title {
  display: flex;
  align-items: center;
  gap: 10px;
}

.days-chapter-icon {
  display: inline-grid;
  place-items: center;
  flex-shrink: 0;
  color: var(--ink-2);
}

.days-chapter .chapter-head .lead {
  max-width: 38em;
  font-size: clamp(19px, 0.45vw + 15px, 22px);
  line-height: 1.36;
}

.days-chapter .days-bridge {
  margin-top: -10px;
}

/* ---------- panel and toolbar ---------- */

.days-panel {
  --days-row-h: 44px;
  --days-pad: 20px;
  padding: 0;
  min-width: 0;
}

.days-panel.is-list {
  --days-row-h: 64px;
  --days-pad: 16px;
}

.days-tools {
  display: flex;
  flex-direction: column;
  padding: 16px var(--days-pad) 10px;
}

/* Search and the actions share a row; the actions wrap under it when space runs out. */
.days-tools-top {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 12px 16px;
}

.days-search-wrap {
  position: relative;
  flex: 1 1 260px;
  max-width: 460px;
  min-width: 0;
}

.days-search-icon {
  position: absolute;
  top: 50%;
  left: 12px;
  color: var(--ink-3);
  transform: translateY(-50%);
  pointer-events: none;
}

.input.days-search {
  padding-left: 38px;
  border-radius: var(--radius-pill);
}

.days-search::-webkit-search-cancel-button {
  cursor: pointer;
}

.days-actions {
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: 8px;
  min-width: 0;
  margin-left: auto;
}

/* The search help shows while you search. */
.days-hint {
  display: none;
  margin-top: 8px;
  font-size: 13px;
  line-height: 1.45;
  color: var(--ink-3);
}

.days-tools:has(.days-search:focus) .days-hint,
.days-tools:has(.days-search:not(:placeholder-shown)) .days-hint {
  display: block;
}

.days-filters {
  margin-top: 14px;
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 8px;
  min-width: 0;
}

.days-filters > * {
  flex: none;
}

.days-filters .chips {
  flex-wrap: nowrap;
  gap: 8px;
}

.days-filters .chip {
  min-height: 36px;
  padding: 0 14px;
  font-size: 14px;
}

.days-filters .chip .swatch.dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--sw);
}

.days-filters .chip[aria-pressed="true"] .swatch.dot {
  box-shadow: 0 0 0 1.5px var(--bg);
}

.days-workout-chip .icon {
  color: var(--c-strain);
}

.days-workout-chip[aria-pressed="true"] .icon {
  color: currentColor;
}

/* Selects look like the chips beside them. */
.days-select-wrap {
  position: relative;
  display: inline-flex;
  align-items: center;
  max-width: 280px;
}

.days-select-wrap .icon {
  position: absolute;
  right: 12px;
  color: var(--ink-3);
  pointer-events: none;
}

.input.days-select {
  -webkit-appearance: none;
  appearance: none;
  width: auto;
  max-width: 100%;
  height: 36px;
  padding: 0 34px 0 14px;
  border-color: var(--axis);
  border-radius: var(--radius-pill);
  background: transparent;
  color: var(--ink-2);
  font-size: 14px;
  font-weight: 500;
  text-overflow: ellipsis;
  cursor: pointer;
}

.days-select-wrap.is-set .input.days-select {
  border-color: var(--ink);
  background: var(--surface-2);
  color: var(--ink);
}

.days-select-wrap.is-set .icon {
  color: var(--ink);
}

.days-select option,
.days-select optgroup {
  background: var(--surface);
  color: var(--ink);
}

.days-rec-range {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  padding-left: 4px;
  color: var(--ink-2);
  font-size: 14px;
  font-weight: 500;
}

.days-rec-to,
.days-rec-unit {
  color: var(--ink-3);
  font-weight: 400;
}

.input.days-num {
  width: 60px;
  height: 36px;
  padding: 0 6px;
  background: transparent;
  border-radius: var(--radius-control);
  text-align: center;
  font-variant-numeric: tabular-nums;
  -moz-appearance: textfield;
  appearance: textfield;
}

.days-num::-webkit-outer-spin-button,
.days-num::-webkit-inner-spin-button {
  -webkit-appearance: none;
  margin: 0;
}

.days-num:not(:placeholder-shown) {
  border-color: var(--ink);
}

.days-status {
  margin-top: 10px;
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 4px 12px;
  min-width: 0;
  min-height: 30px;
}

.days-count {
  color: var(--ink-2);
  font-size: 14px;
  font-variant-numeric: tabular-nums;
}

.is-filtered .days-count {
  color: var(--ink);
}

.days-clear {
  margin-left: -6px;
}

.days-link.days-show-all {
  font-size: 14px;
}

/* ---------- column picker ---------- */

.days-columns {
  position: relative;
}

.days-columns-btn[aria-expanded="true"] {
  border-color: var(--ink);
}

.days-picker {
  position: absolute;
  top: calc(100% + 8px);
  right: 0;
  z-index: 30;
  display: flex;
  flex-direction: column;
  gap: 14px;
  width: min(620px, calc(100vw - 48px));
  max-height: min(78vh, 660px);
  padding: 16px 18px;
  overflow: auto;
  overscroll-behavior: contain;
  border: 1px solid var(--axis);
  border-radius: var(--radius-panel);
  background: var(--surface-2);
}

.days-pick-title {
  color: var(--ink);
  font-size: 15px;
  font-weight: 600;
}

.days-pick-groups {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(160px, 1fr));
  gap: 12px 20px;
}

.days-pick-group {
  display: flex;
  flex-direction: column;
  min-width: 0;
  margin: 0;
  padding: 0;
  border: 0;
}

.days-pick-legend {
  margin-bottom: 4px;
  padding: 0;
  color: var(--ink-3);
  font-size: 13px;
  font-weight: 500;
}

.days-pick {
  display: flex;
  align-items: center;
  gap: 10px;
  min-height: 34px;
  color: var(--ink);
  font-size: 14px;
  line-height: 1.25;
  cursor: pointer;
}

.days-pick input {
  flex: none;
  width: 16px;
  height: 16px;
  margin: 0;
}

.days-pick-label {
  min-width: 0;
}

.days-pick-unit {
  color: var(--ink-3);
}

.days-pick-note {
  margin-left: auto;
  color: var(--ink-3);
  font-size: 12px;
  white-space: nowrap;
}

.days-pick-foot {
  display: flex;
  justify-content: flex-end;
  gap: 8px;
  padding-top: 12px;
  border-top: 1px solid var(--hairline);
}

/* ---------- table ---------- */

.days-table {
  border-top: 1px solid var(--hairline);
}

.days-scroll {
  position: relative;
  min-width: 0;
}

.days-panel.is-table .days-scroll {
  /* As tall as the screen below the sticky chapter switcher (and above a tab bar). */
  max-height: max(300px, calc(100vh - var(--days-sticky-top, 64px) - var(--days-bottom, 0px) - 24px));
  max-height: max(300px, calc(100dvh - var(--days-sticky-top, 64px) - var(--days-bottom, 0px) - 24px));
  overflow: auto;
  scrollbar-width: thin;
  scrollbar-color: var(--axis) transparent;
}

.days-panel.is-table .days-scroll::-webkit-scrollbar {
  width: 10px;
  height: 10px;
}

.days-panel.is-table .days-scroll::-webkit-scrollbar-thumb {
  border: 3px solid transparent;
  border-radius: 999px;
  background: var(--axis) padding-box;
}

.days-panel.is-table .days-scroll::-webkit-scrollbar-track,
.days-panel.is-table .days-scroll::-webkit-scrollbar-corner {
  background: transparent;
}

.days-grid {
  position: relative;
  min-width: var(--days-minw, 100%);
  font-variant-numeric: tabular-nums;
}

.days-thead {
  position: sticky;
  top: 0;
  z-index: 3;
  background: var(--surface);
}

.days-panel.is-list .days-thead {
  top: var(--days-sticky-top, 0px);
}

.days-row {
  --row-bg: var(--surface);
  display: grid;
  grid-template-columns: var(--days-cols, minmax(0, 1fr));
  align-items: center;
  box-sizing: border-box;
}

.days-head-row {
  height: 44px;
}

.days-tbody {
  position: relative;
}

.days-tbody .days-row {
  position: absolute;
  left: 0;
  right: 0;
  height: var(--days-row-h);
  border-bottom: 1px solid var(--grid);
  background: var(--row-bg);
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
  touch-action: manipulation;
}

.days-tbody .days-row:focus {
  outline: none;
}

/* Drawn over the sticky date cell, so the ring is whole. */
.days-tbody .days-row:focus-visible::after {
  content: "";
  position: absolute;
  inset: 0;
  z-index: 2;
  border: 2px solid var(--focus);
  border-radius: 6px;
  pointer-events: none;
}

.days-tbody .days-row:active {
  --row-bg: var(--surface-2);
}

@media (hover: hover) {
  .days-tbody .days-row:hover {
    --row-bg: var(--surface-2);
  }

  .days-sort:hover {
    color: var(--ink);
  }
}

.days-th,
.days-td {
  min-width: 0;
  padding: 0 10px;
}

.days-th:first-child,
.days-td:first-child {
  padding-left: var(--days-pad);
}

.days-th:last-child,
.days-td:last-child {
  padding-right: var(--days-pad);
}

.days-th {
  display: flex;
  align-self: stretch;
  /* Each header cell draws its share of the line, so the sticky date cell keeps it too. */
  box-shadow: inset 0 -1px 0 var(--hairline);
}

.days-sort {
  display: flex;
  align-items: center;
  gap: 4px;
  width: 100%;
  min-width: 0;
  padding: 0;
  border: 0;
  background: none;
  color: var(--ink-2);
  font-size: 13px;
  font-weight: 500;
  line-height: 1.2;
  text-align: inherit;
  white-space: nowrap;
  cursor: pointer;
}

.days-th.align-right .days-sort {
  justify-content: flex-end;
}

.days-sort-line {
  display: flex;
  align-items: center;
  gap: 4px;
  min-width: 0;
  max-width: 100%;
}

.days-th.align-right .days-sort-mark {
  order: -1;
}

.days-th[aria-sort="ascending"] .days-sort,
.days-th[aria-sort="descending"] .days-sort {
  color: var(--ink);
}

/* Label with its unit underneath, so units never widen a column. */
.days-sort-text {
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  min-width: 0;
}

.days-th.align-right .days-sort-text {
  align-items: flex-end;
}

.days-sort-label {
  max-width: 100%;
  overflow: hidden;
  text-overflow: ellipsis;
}

/* Every label sits on the same line; the unit line is kept even when empty. */
.days-panel.is-table .days-sort-text::after {
  content: "";
  min-height: 14px;
  margin-top: 1px;
}

.days-panel.is-table .days-sort-text:has(.days-sort-unit)::after {
  display: none;
}

.days-sort-unit {
  min-height: 14px;
  margin-top: 1px;
  color: var(--ink-3);
  font-size: 11px;
  font-weight: 400;
}

.days-sort-mark {
  display: inline-grid;
  place-items: center;
  flex: none;
}

.days-sort-mark:empty {
  display: none;
}

.days-sort:focus-visible {
  outline: 2px solid var(--focus);
  outline-offset: -2px;
  border-radius: 6px;
}

.days-td {
  overflow: hidden;
  color: var(--ink);
  font-size: 14px;
  line-height: 1.25;
  white-space: nowrap;
  text-overflow: ellipsis;
}

.days-td.align-right,
.days-th.align-right {
  text-align: right;
  justify-content: flex-end;
}

.days-missing {
  color: var(--ink-3);
}

/* Date: weekday in a fixed slot, then the date. Sticky on the left in the table. */
.days-td.col-date {
  display: flex;
  align-items: center;
  gap: 8px;
  align-self: stretch;
}

.days-dow {
  flex: none;
  width: 30px;
  color: var(--ink-3);
}

.days-date {
  overflow: hidden;
  text-overflow: ellipsis;
}

.days-panel.is-table .days-td.col-date,
.days-panel.is-table .days-th.col-date {
  position: sticky;
  left: 0;
  z-index: 1;
  background: var(--row-bg, var(--surface));
}

.days-panel.is-table .days-th.col-date {
  background: var(--surface);
}

.days-scroll.is-x .days-td.col-date {
  box-shadow: inset -1px 0 0 var(--hairline);
}

.days-scroll.is-x .days-th.col-date {
  box-shadow: inset -1px 0 0 var(--hairline), inset 0 -1px 0 var(--hairline);
}

/* Recovery: zone dot + score. The zone name is in the text for screen readers. */
.days-td.col-recovery {
  display: flex;
  align-items: center;
  align-self: stretch;
}

.days-dot {
  flex: none;
  width: 9px;
  height: 9px;
  margin-right: 10px;
  border-radius: 50%;
  background: var(--z);
}

.days-score {
  min-width: 2ch;
  text-align: right;
}

.days-unit {
  color: var(--ink-2);
}

.days-clip {
  display: block;
  overflow: hidden;
  color: var(--ink-2);
  text-overflow: ellipsis;
}

/* Notes, tags, journal answers and experiments as small chips. The row shows the chips
   that fit whole; the rest wrap onto a hidden second line instead of being cut through
   their edge, and a first chip wider than the cell ends in an ellipsis. Every chip is
   in the day sheet. */
.days-chips {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 12px 6px;
  min-width: 0;
  height: 22px;
  overflow: hidden;
}

.days-chip {
  display: inline-flex;
  align-items: center;
  flex: 0 1 auto;
  gap: 4px;
  min-width: 2.75em;
  max-width: 240px;
  height: 22px;
  padding: 0 8px;
  border: 1px solid var(--hairline);
  border-radius: var(--radius-pill);
  background: var(--surface-2);
  color: var(--ink-2);
  font-size: 12px;
  font-weight: 500;
  line-height: 1;
}

.days-chip-text {
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.days-chip .icon {
  flex: none;
  color: var(--ink-3);
}

.days-chip.is-tag {
  color: var(--ink);
}

.days-chip.is-journal .icon {
  color: var(--status-good);
}

.days-chip.is-experiment {
  border-style: dashed;
  border-color: var(--axis);
  background: transparent;
}

/* ---------- empty result and foot ---------- */

.days-empty {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 8px;
  padding: 44px var(--days-pad);
  text-align: center;
}

.days-empty-title {
  color: var(--ink);
  font-size: 17px;
  font-weight: 600;
}

.days-empty-actions {
  justify-content: center;
}

.days-empty-body {
  max-width: 34em;
  margin-bottom: 8px;
  color: var(--ink-2);
  font-size: 14px;
}

.days-foot {
  display: flex;
  flex-direction: column;
  gap: 4px;
  padding: 12px var(--days-pad) 16px;
  border-top: 1px solid var(--hairline);
}

.days-link {
  display: inline;
  padding: 0;
  border: 0;
  background: none;
  color: var(--ink);
  font: inherit;
  text-decoration: underline;
  text-decoration-color: var(--ink-3);
  text-underline-offset: 3px;
  cursor: pointer;
}

@media (hover: hover) {
  .days-link:hover {
    text-decoration-color: var(--ink);
  }
}

/* ---------- phones: compact list ---------- */

.days-panel.is-list .days-row {
  grid-template-columns: minmax(0, 1fr) 64px 40px 60px 44px;
  column-gap: 8px;
  padding: 0 var(--days-pad);
}

.days-panel.is-list .days-head-row {
  height: 36px;
  box-shadow: inset 0 -1px 0 var(--hairline);
}

.days-panel.is-list .days-th {
  box-shadow: none;
}

.days-panel.is-list .days-th,
.days-panel.is-list .days-td,
.days-panel.is-list .days-th:first-child,
.days-panel.is-list .days-td:first-child,
.days-panel.is-list .days-th:last-child,
.days-panel.is-list .days-td:last-child {
  padding-left: 0;
  padding-right: 0;
}

.days-panel.is-list .days-sort {
  font-size: 12px;
}

/* Narrow columns: a sort arrow may reach into the gap rather than cut the label. */
.days-panel.is-list .days-th,
.days-panel.is-list .days-sort,
.days-panel.is-list .days-sort-label {
  overflow: visible;
}

.days-panel.is-list .days-tbody .days-row {
  align-items: start;
  padding-top: 11px;
}

.days-panel.is-list .days-td {
  font-size: 15px;
  line-height: 20px;
}

.days-panel.is-list .days-td.col-date,
.days-panel.is-list .days-td.col-recovery {
  align-self: start;
}

.days-panel.is-list .days-td.col-date {
  display: block;
}

.days-panel.is-list .days-date {
  display: block;
  font-weight: 500;
}

/* Second line across the whole row: weekday, sports, then notes and journal chips. */
.days-sub {
  display: none;
}

.days-panel.is-list .days-sub {
  position: absolute;
  left: var(--days-pad);
  right: var(--days-pad);
  bottom: 9px;
  display: flex;
  align-items: center;
  gap: 8px;
  height: 20px;
  overflow: hidden;
  color: var(--ink-3);
  font-size: 12.5px;
  font-weight: 400;
}

.days-panel.is-list .days-sub .days-dow {
  width: auto;
}

.days-sports {
  display: inline-flex;
  align-items: center;
  flex: none;
  gap: 4px;
  max-width: 55%;
  overflow: hidden;
  color: var(--ink-2);
  text-overflow: ellipsis;
  white-space: nowrap;
}

.days-sports .icon {
  color: var(--c-strain);
}

.days-panel.is-list .days-sub .days-chips {
  flex: 1 1 auto;
  height: 20px;
}

.days-panel.is-list .days-chip {
  height: 20px;
  padding: 0 7px;
  font-size: 11.5px;
}

.days-panel.is-list .days-dot {
  width: 8px;
  height: 8px;
  margin-right: 7px;
}

.days-panel.is-list .days-td.col-recovery {
  height: 20px;
}

@media (max-width: 599.98px) {
  .days-search-wrap {
    flex-basis: 100%;
    max-width: none;
  }

  .days-actions {
    display: none;
  }

  .days-count {
    flex: 0 1 auto;
  }

  .days-clear {
    margin-left: 0;
  }


  .days-filters {
    flex-wrap: nowrap;
    margin: 14px calc(-1 * var(--days-pad)) 0;
    padding: 2px var(--days-pad);
    overflow-x: auto;
    scrollbar-width: none;
    overscroll-behavior-x: contain;
  }

  .days-filters::-webkit-scrollbar {
    display: none;
  }

  .days-status {
    gap: 10px 8px;
  }

  .days-count,
  .days-link.days-show-all {
    font-size: 13px;
  }
}

/* ---------- touch: 44px targets ---------- */

@media (any-pointer: coarse) {
  .days-filters .chip,
  .input.days-select,
  .input.days-num {
    min-height: 44px;
    height: 44px;
  }

  .input.days-search {
    height: 44px;
    font-size: 16px;
  }

  .days-pick {
    min-height: 44px;
  }

  .days-pick input {
    width: 20px;
    height: 20px;
  }

  .days-panel.is-table {
    --days-row-h: 48px;
  }

  .days-head-row,
  .days-panel.is-list .days-head-row {
    height: 48px;
  }

  .days-panel.is-list .days-sort {
    position: relative;
    align-self: stretch;
  }

  /* Narrow list headings (HRV) still get a 44px-wide target. */
  .days-panel.is-list .days-sort::after {
    content: "";
    position: absolute;
    top: 0;
    right: -4px;
    bottom: 0;
    left: -4px;
  }

  /* Text buttons keep their look; an invisible box gives them a 44px target. */
  .days-link {
    position: relative;
  }

  .days-link::after {
    content: "";
    position: absolute;
    top: 50%;
    right: -6px;
    left: -6px;
    height: 44px;
    transform: translateY(-50%);
  }
}

/* iOS zooms into fields under 16px when they get focus. */
@supports (-webkit-touch-callout: none) {
  .input.days-select,
  .input.days-num,
  .input.days-search {
    font-size: 16px;
  }
}
