/* check-in.css — the native-tracking check-in grid (check-in.js).
   Colours come from the widget's own tokens (/widgets/css/main.css); the
   read-only day cells deliberately reuse the insights heatmap's visual
   vocabulary (solid fill = done, grey square with a red "x" = missed,
   transparent with a "z" = not due, faint square = no data) so one glyph set
   means one thing across the whole widget.

   Two shapes share every rule below: the full weekly grid (Notion embeds and
   wide viewports) and the compact yesterday/today pair app mode opens into,
   which only adds .checkin-grid--compact on top. */

/* ---------------------------------------------------------------------------
   App shell — the same fixed-header / scrolling-body / pinned-footer layout
   #edit-habits-container gets in styles.css, on this view's own classes.
   Separate classes rather than reusing .editing/.editing-shell: those carry a
   `display: flex !important` for #edit-habits-container, which would force
   the habit editor visible underneath this view.
   --------------------------------------------------------------------------- */

.container.checking-in {
  flex-direction: column;
  align-items: center;
  height: 100%;
  /* .widget-wrapper (the same element) sets min-height: 400px — without the
     override a shallow embed keeps the taller floor and document scroll
     returns. Specificity (0,2,0) already beats .widget-wrapper's (0,1,0). */
  min-height: 0;
}

/* Height anchor: body has its own padding: 10px that a cap on the container
   alone cannot account for. overflow: auto, not hidden — on embeds too short
   for header + save row, hidden would put the save button permanently out of
   reach. See the matching body.editing-shell rules in styles.css. */
body.checkin-shell {
  height: 100vh; /* fallback for browsers without dvh support */
  height: 100dvh;
  box-sizing: border-box;
  overflow: auto;
}

.container.checking-in #streaks-content,
.container.checking-in #leaderboard-content {
  display: none;
}

#widget-wrapper.checking-in ~ .widget-footer {
  display: none;
}

.checkin-container {
  width: 100%;
  max-width: 600px;
  margin: 0 auto;
  box-sizing: border-box;
  flex-direction: column;
  align-items: center;
}

.container.checking-in #checkin-container {
  display: flex !important; /* overrides the inline display:none in index.html */
  flex-direction: column;
  align-items: center;
  width: 100%;
  height: 100%;
  min-height: 0; /* flex items default to min-height:auto and would undo the cap */
}

.container.checking-in #checkin-container > h2,
.container.checking-in #checkin-buttons-container {
  flex: 0 0 auto;
}

.container.checking-in #checkin-container > h2 {
  /* styles.css's max-width:975px media query sets `h2 { font-size: 1.5rem
     !important }`, and the 752px reference embed falls inside it — matching
     the compaction #edit-habits-container's own h2 gets there. */
  font-size: 1.25rem !important;
  margin-bottom: 6px;
}

/* The one flexible child: absorbs what the pinned header/footer leave and
   scrolls its own overflow instead of growing the shell. */
.container.checking-in #checkin-grid-wrap {
  flex: 1 1 auto;
  overflow-y: auto;
  overflow-x: hidden;
  min-height: 0;
  width: 100%;
  scrollbar-width: thin;
}

.checkin-grid-wrap {
  width: 100%;
  box-sizing: border-box;
}

#checkin-buttons-container {
  display: flex;
  flex-direction: row;
  justify-content: center;
  align-items: center;
  flex-wrap: wrap;
  gap: 10px;
  width: 100%;
  margin-top: 10px;
  padding-bottom: 8px;
}

/* ---------------------------------------------------------------------------
   The grid
   --------------------------------------------------------------------------- */

/* The white card the grid and its legend sit on — same treatment as the
   insights heatmap card, so both read as the same kind of surface. */
.checkin-card {
  width: 100%;
  box-sizing: border-box;
  padding: 10px 8px;
  background: #fff;
  border-radius: 10px;
  color: #2b243f;
}

/* Shown inside the card when GET /points/heatmap gave nothing for any month
   the columns touch (check-in.js's heatmapUnavailable): the read-only history
   is missing, but today and yesterday can still be saved, so this is a quiet
   note above the grid rather than an error banner. Sized like the legend and
   tinted with the site's purple, not a warning colour. */
.checkin-notice {
  margin: 0 0 8px;
  padding: 6px 8px;
  border-radius: 6px;
  border-left: 3px solid var(--main-color, #A422EA);
  background: var(--main-color-light, #f0c8ff);
  color: var(--main-color-dark, #500175);
  font-size: 10px;
  line-height: 1.3;
}

.checkin-grid {
  display: grid;
  /* --checkin-day-count is set inline by check-in.js: 7 on most days, 8 on the
     week's first day, when yesterday needs a column of its own, 2 in compact
     mode. */
  grid-template-columns: minmax(72px, 1.3fr) repeat(var(--checkin-day-count, 7), minmax(0, 1fr));
  gap: 4px;
  align-items: center;
  width: 100%;
  box-sizing: border-box;
}

.checkin-weekday {
  display: flex;
  flex-direction: column;
  align-items: center;
  line-height: 1.1;
  font-size: 10px;
  color: rgba(43, 36, 63, 0.55);
}

.checkin-weekday-day {
  font-size: 9px;
  opacity: 0.75;
}

.checkin-weekday--today {
  color: var(--main-color-dark, #500175);
  font-weight: bold;
}

/* The extra yesterday column that belongs to last week — set apart so the
   grid doesn't read as eight days of one week. */
.checkin-weekday--outside {
  font-style: italic;
  opacity: 0.8;
}

.checkin-habit-label {
  display: flex;
  flex-direction: column;
  min-width: 0;
  font-size: 0.8em;
  line-height: 1.2;
  padding-right: 4px;
}

.checkin-habit-name {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.checkin-habit-hint {
  font-size: 0.75em;
  opacity: 0.7;
}

/* ---------------------------------------------------------------------------
   Cells
   --------------------------------------------------------------------------- */

.checkin-cell {
  width: 100%;
  /* Cap + centre, the same reason --insights-heatmap-max-cell exists: with
     free 1fr columns the squares blow up on a wide Notion column instead of
     staying a readable week strip. */
  max-width: 40px;
  justify-self: center;
  aspect-ratio: 1;
  border-radius: 3px;
  box-sizing: border-box;
  position: relative;
  padding: 0;
  margin: 0;
}

/* Read-only day states — same four modifiers, glyphs and rationale as
   .insights-heatmap-cell--* in styles.css. */
.checkin-cell--done {
  background-color: var(--main-color-dark, #500175);
  border: none;
}

.checkin-cell--missed {
  background-color: var(--grey, #e6e6e6);
  border: none;
}

.checkin-cell--missed::after {
  /* Declared twice: the alt-text ("/ ''") form marks the glyph decorative for
     browsers that parse it; older ones drop that line and keep the plain
     fallback above it. */
  content: '\00d7';
  content: '\00d7' / '';
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 10px;
  font-weight: bold;
  line-height: 1;
  color: #c62828;
}

.checkin-cell--not-due {
  background: transparent;
  border: none;
}

.checkin-cell--not-due::after {
  content: 'z';
  content: 'z' / '';
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 10px;
  font-weight: bold;
  line-height: 1;
  color: rgba(43, 36, 63, 0.55);
}

.checkin-cell--no-data {
  background: var(--grey, #e6e6e6);
  opacity: 0.35;
  border: none;
}

/* Editable cells (today + yesterday): an outlined square, so "you can touch
   this" reads before any status does. */
.checkin-cell--edit {
  background: #fff;
  border: 2px solid var(--main-color, #A422EA);
  cursor: pointer;
}

.checkin-cell--edit:focus-visible {
  outline: 2px solid var(--main-color-dark, #500175);
  outline-offset: 1px;
}

.checkin-cell--check:hover {
  background: var(--main-color-light, #f0c8ff);
}

.checkin-cell--checked {
  background: var(--main-color-dark, #500175);
}

.checkin-cell--checked::after {
  content: '\2713';
  content: '\2713' / '';
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 12px;
  font-weight: bold;
  line-height: 1;
  color: #fff;
}

.checkin-qty-input {
  aspect-ratio: auto;
  height: 26px;
  /* A touch wider than a checkbox square — two or three digits have to be
     readable — but still capped so it can't stretch a column. */
  max-width: 56px;
  min-width: 0;
  text-align: center;
  font-size: 11px;
  cursor: text;
  /* Spinners cost horizontal room the narrow embeds don't have. */
  appearance: textfield;
  -moz-appearance: textfield;
}

.checkin-qty-input::-webkit-outer-spin-button,
.checkin-qty-input::-webkit-inner-spin-button {
  -webkit-appearance: none;
  margin: 0;
}

/* ---------------------------------------------------------------------------
   Compact shape — app mode (`?app=1`) only.

   Two named columns instead of a week strip, and cells sized as touch targets
   (44px is the platform minimum on both iOS and Android) rather than as
   calendar squares: this is the home screen of the installed app, where the
   one thing a user came to do is tick today off with a thumb.
   --------------------------------------------------------------------------- */

.checkin-grid--compact {
  grid-template-columns: minmax(0, 1fr) repeat(2, 56px);
  gap: 8px 6px;
}

.checkin-grid--compact .checkin-habit-label {
  font-size: 0.95em;
}

.checkin-weekday--compact {
  font-size: 11px;
}

.checkin-weekday-word {
  white-space: nowrap;
}

.checkin-grid--compact .checkin-cell {
  aspect-ratio: auto;
  max-width: 56px;
  min-height: 44px;
}

.checkin-grid--compact .checkin-qty-input {
  height: 44px;
  font-size: 14px;
}

.checkin-grid--compact .checkin-cell--checked::after {
  font-size: 18px;
}

/* ---------------------------------------------------------------------------
   Legend
   --------------------------------------------------------------------------- */

/* Swatches deliberately do NOT reuse .checkin-cell--*: those rules size a
   grid column (width:100%, fixed height under the narrow-embed media query
   below) and would stretch a swatch into a bar. Same split
   .insights-heatmap-legend-swatch--* makes in styles.css. Compact mode has no
   read-only cells and therefore renders no legend at all (check-in.js). */
.checkin-legend {
  display: flex;
  flex-direction: row;
  justify-content: center;
  flex-wrap: wrap;
  gap: 4px 10px;
  margin-top: 8px;
  font-size: 10px;
  color: rgba(43, 36, 63, 0.7);
}

.checkin-legend-item {
  display: inline-flex;
  align-items: center;
  gap: 4px;
}

.checkin-legend-swatch {
  width: 10px;
  height: 10px;
  flex: 0 0 auto;
  border-radius: 3px;
  box-sizing: border-box;
  position: relative;
  display: inline-block;
}

.checkin-legend-swatch--done {
  background-color: var(--main-color-dark, #500175);
}

.checkin-legend-swatch--missed {
  background-color: var(--grey, #e6e6e6);
}

.checkin-legend-swatch--missed::after {
  content: '\00d7';
  content: '\00d7' / '';
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 8px;
  font-weight: bold;
  line-height: 1;
  color: #c62828;
}

.checkin-legend-swatch--not-due {
  background: transparent;
}

.checkin-legend-swatch--not-due::after {
  content: 'z';
  content: 'z' / '';
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 8px;
  font-weight: bold;
  line-height: 1;
  color: rgba(43, 36, 63, 0.55);
}

.checkin-legend-swatch--no-data {
  background: var(--grey, #e6e6e6);
  opacity: 0.35;
}

/* ---------------------------------------------------------------------------
   Narrow embeds (a 752x595 widget scaled into a phone-width Notion column
   lands around 250-310px wide): the habit name takes a full row of its own so
   all seven or eight day cells get the entire width.

   Scoped away from the compact shape with :not() — compact already fits two
   56px columns plus a name at 250px, and letting this block win on source
   order would re-expand it into the full-width week treatment.
   --------------------------------------------------------------------------- */

@media (max-width: 480px) {
  .checkin-grid:not(.checkin-grid--compact) {
    grid-template-columns: repeat(var(--checkin-day-count, 7), minmax(0, 1fr));
    gap: 3px;
    padding: 8px 6px;
  }

  .checkin-grid:not(.checkin-grid--compact) .checkin-header-spacer {
    display: none;
  }

  .checkin-grid:not(.checkin-grid--compact) .checkin-habit-label {
    grid-column: 1 / -1;
    flex-direction: row;
    align-items: baseline;
    gap: 5px;
    margin-top: 6px;
    padding-right: 0;
  }

  .checkin-grid:not(.checkin-grid--compact) .checkin-cell {
    /* Fixed height instead of square: at eight columns inside ~230px of
       content box a square cell would be ~25px and the row would grow taller
       than it needs to be. */
    aspect-ratio: auto;
    height: 24px;
  }

  .checkin-grid:not(.checkin-grid--compact) .checkin-qty-input {
    height: 24px;
    font-size: 10px;
  }
}
