/* קלורי — page: הרגלים (#/habits). Every selector is prefixed .pg-habits (SPEC §3, §9.4).
   Shared components come from components.css; only page layout, the weekday dots,
   habit rows, the 30-day heat grid and the add/edit sheet pieces live here. */

/* ---------- layout: one column on phones, main + side ≥ 1024px ---------- */
.pg-habits__grid {
  display: grid;
  grid-template-columns: minmax(0, 1fr);
  gap: var(--sp-4);
  align-items: start;
}
.pg-habits__col { display: grid; grid-template-columns: minmax(0, 1fr); gap: var(--sp-4); min-inline-size: 0; }
.pg-habits__col > [data-section]:empty { display: none; }
.pg-habits__col--side:empty { display: none; }

@media (min-width: 1024px) {
  .pg-habits__grid {
    grid-template-columns: minmax(0, 1fr) minmax(320px, 420px);
    gap: var(--sp-5);
  }
}

/* ---------- summary card: ring + completion text + weekday dots ---------- */
.pg-habits__summary-body {
  display: flex;
  flex-wrap: wrap; /* the text block drops under the ring when less than 150px is left (≈ 320px screens) */
  align-items: center;
  gap: var(--sp-4);
}
.pg-habits__ring { flex: none; margin: 0; }
.pg-habits__summary-text { flex: 1 1 150px; min-inline-size: 0; display: grid; gap: var(--sp-1); }
.pg-habits__completion {
  margin: 0;
  font-size: var(--fs-lg);
  font-weight: 700;
  line-height: 1.3;
}
.pg-habits__date { margin: 0; }
.pg-habits__dots {
  list-style: none;
  margin: var(--sp-2) 0 0;
  padding: 0;
  display: flex;
  gap: var(--sp-1);
  max-inline-size: min(300px, 100%);
}
.pg-habits__dot {
  --pct: 0%;
  flex: 1 1 0;
  min-inline-size: 0;
  display: grid;
  justify-items: center;
  gap: 4px;
}
.pg-habits__dot-mark {
  inline-size: 100%;
  max-inline-size: 22px;
  aspect-ratio: 1;
  border-radius: var(--r-full);
  border: 2px solid var(--c-border);
  background: var(--c-surface-2);
  box-sizing: border-box;
  position: relative;
}
.pg-habits__dot-label { font-size: var(--fs-xs); color: var(--c-text-2); line-height: 1; }
.pg-habits__dot--done .pg-habits__dot-mark {
  border-color: var(--c-success);
  background: var(--c-success);
}
.pg-habits__dot--done .pg-habits__dot-mark::after {
  content: "";
  position: absolute;
  /* physical sides on purpose: a checkmark is a glyph and must not mirror in RTL (SPEC §12.2) */
  inset: 0;
  margin: auto;
  width: 5px;
  height: 9px;
  border-right: 2px solid var(--c-primary-contrast);
  border-bottom: 2px solid var(--c-primary-contrast);
  transform: translateY(-1px) rotate(45deg);
}
.pg-habits__dot--partial .pg-habits__dot-mark,
.pg-habits__dot--today .pg-habits__dot-mark {
  border-color: var(--c-primary);
  background: conic-gradient(var(--c-primary) var(--pct), var(--c-surface-2) 0);
}
.pg-habits__dot--today .pg-habits__dot-mark { box-shadow: 0 0 0 2px var(--c-surface), 0 0 0 4px var(--c-primary-soft); }
.pg-habits__dot--today .pg-habits__dot-label { color: var(--c-primary-text); font-weight: 700; }
.pg-habits__dot--missed .pg-habits__dot-mark { border-color: var(--c-border); background: var(--c-surface-3); }
.pg-habits__dot--off .pg-habits__dot-mark { border-style: dashed; background: transparent; }
.pg-habits__dot--future .pg-habits__dot-mark { opacity: .45; }

/* ---------- habit rows ---------- */
.pg-habits__shabbat { margin: calc(-1 * var(--sp-1)) 0 var(--sp-2); }
.pg-habits__rows { margin: 0; }
.pg-habits__row {
  align-items: flex-start;
  gap: var(--sp-3);
  padding-block: var(--sp-3);
  min-block-size: 64px;
}
.pg-habits__row--off { opacity: .7; }
.pg-habits__ctrl {
  flex: none;
  display: flex;
  align-items: center;
  justify-content: center;
  min-inline-size: var(--hit-lg);
  min-block-size: var(--hit-lg);
}
.pg-habits__check {
  position: relative;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  inline-size: var(--hit-lg);
  block-size: var(--hit-lg);
  padding: 0;
  border-radius: var(--r-2);
  background: transparent;
  color: var(--c-primary-contrast);
  cursor: pointer;
}
.pg-habits__check::before {
  content: "";
  position: absolute;
  inset: 9px;
  border-radius: var(--r-1);
  border: 2px solid var(--c-border);
  background: var(--c-surface);
  transition: background-color var(--dur-1), border-color var(--dur-1);
}
.pg-habits__check:hover::before { border-color: var(--c-primary); }
.pg-habits__check .icon {
  position: relative;
  inline-size: 20px;
  block-size: 20px;
  opacity: 0;
  transform: scale(.6);
  transition: opacity var(--dur-1), transform var(--dur-1) var(--ease);
}
.pg-habits__check[aria-checked="true"]::before {
  border-color: var(--c-success);
  background: var(--c-success);
}
.pg-habits__check[aria-checked="true"] .icon { opacity: 1; transform: scale(1); }
.pg-habits__check:focus-visible { outline-offset: -2px; }
/* count habits: a mini ring instead of the square box */
.pg-habits__check--count::before { display: none; }
.pg-habits__mini { inline-size: 44px; margin: 0; }
.pg-habits__check--count .icon {
  position: absolute;
  inset: 0;
  margin: auto;
  color: var(--c-success);
}
.pg-habits__check--count[aria-checked="true"] .ring__track { stroke: var(--c-success-soft); }

.pg-habits__main { gap: 4px; padding-block-start: 2px; }
.pg-habits__name {
  display: flex;
  align-items: center;
  gap: var(--sp-2);
  font-size: var(--fs-md);
  white-space: normal;
}
.pg-habits__name .icon--habit {
  flex: none;
  inline-size: 22px;
  block-size: 22px;
  color: var(--c-primary-text);
}
.pg-habits__row--off .pg-habits__name .icon--habit { color: var(--c-text-2); }
.pg-habits__row--done .pg-habits__name > span { text-decoration: none; }
.pg-habits__meta { gap: 4px var(--sp-3); }
.pg-habits__streak,
.pg-habits__best,
.pg-habits__days {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  white-space: nowrap;
}
.pg-habits__streak .icon,
.pg-habits__best .icon { inline-size: 16px; block-size: 16px; }
.pg-habits__flame { color: var(--c-text-2); }
.pg-habits__streak--on { color: var(--c-warning); font-weight: 600; }
.pg-habits__streak--on .pg-habits__flame { color: var(--c-warning); }
.pg-habits__best .icon { color: var(--c-carbs); }
.pg-habits__count {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: var(--sp-2) var(--sp-3);
  margin-block-start: var(--sp-1);
}
.pg-habits__count .stepper { flex: none; }
.pg-habits__count-value { font-weight: 600; color: var(--c-text-2); }
.pg-habits__row--done .pg-habits__count-value { color: var(--c-success); }
.pg-habits__off { align-self: center; }
.pg-habits__menu { align-self: center; }

/* ---------- empty state ---------- */
.pg-habits__empty { padding-block: var(--sp-6); }
.pg-habits__empty-actions { justify-content: center; margin-block-start: var(--sp-2); }

/* ---------- week grid (svg from charts.weekGrid) ---------- */
.pg-habits__week-chart { display: flex; justify-content: flex-start; }
.pg-habits__week-chart > .chart {
  inline-size: 100%;
  max-inline-size: 420px;
}

/* ---------- 30-day heat grid ---------- */
.pg-habits__heat {
  display: grid;
  gap: 4px;
  max-inline-size: 420px;
}
.pg-habits__heat-head,
.pg-habits__heat-row,
.pg-habits__heat-legend {
  display: grid;
  grid-template-columns: 44px repeat(7, minmax(0, 1fr));
  gap: 4px;
  align-items: center;
}
.pg-habits__heat-day {
  text-align: center;
  font-size: var(--fs-xs);
  color: var(--c-text-2);
  line-height: 1;
  padding-block-end: 2px;
}
.pg-habits__heat-week {
  font-size: var(--fs-xs);
  color: var(--c-text-2);
  white-space: nowrap;
}
.pg-habits__heat-cell {
  --heat: 0;
  display: block;
  aspect-ratio: 1;
  min-block-size: 24px;
  border-radius: 6px;
  background: color-mix(in srgb, var(--c-success) calc(var(--heat) * 100%), var(--c-surface-2));
  border: 1px solid transparent;
  box-sizing: border-box;
  cursor: default;
  transition: transform var(--dur-1);
}
.pg-habits__heat-cell[data-level="1"] { --heat: .3; }
.pg-habits__heat-cell[data-level="2"] { --heat: .55; }
.pg-habits__heat-cell[data-level="3"] { --heat: .78; }
.pg-habits__heat-cell[data-level="4"] { --heat: 1; }
.pg-habits__heat-cell[data-state="off"] {
  background: transparent;
  border: 1px dashed var(--c-border);
}
.pg-habits__heat-cell[data-state="future"] { background: var(--c-surface-2); opacity: .4; }
.pg-habits__heat-cell[data-state="today"] { box-shadow: inset 0 0 0 2px var(--c-primary); }
.pg-habits__heat-cell[tabindex]:hover { transform: scale(1.08); }
.pg-habits__heat-cell:focus-visible { outline: 2px solid var(--c-focus); outline-offset: 1px; }
.pg-habits__heat-legend {
  grid-template-columns: auto repeat(5, 18px) auto;
  justify-content: end;
  margin-block-start: var(--sp-2);
  font-size: var(--fs-xs);
  color: var(--c-text-2);
}
.pg-habits__heat-cell--legend { min-block-size: 18px; inline-size: 18px; border-radius: 4px; }

/* ---------- archive ---------- */
.pg-habits__archive > summary .icon { inline-size: 20px; block-size: 20px; }
.pg-habits__archive .list__end .btn--sm .icon { inline-size: 16px; block-size: 16px; }

/* ---------- sheets: add/edit form, presets, overflow menu ---------- */
.pg-habits__form { display: grid; gap: var(--sp-1); }
.pg-habits__count-fields .field--number .input-unit { max-inline-size: none; }
.pg-habits__count-fields[hidden] { display: none; }
.pg-habits__days { display: flex; gap: var(--sp-1); }
.pg-habits__day {
  flex: 1 1 0;
  min-inline-size: 0;
  justify-content: center;
  padding-inline: 0;
  font-weight: 700;
}
.pg-habits__day::before { display: none; }
.pg-habits__icons {
  display: grid;
  grid-template-columns: repeat(6, minmax(0, 1fr));
  gap: var(--sp-2);
}
.pg-habits__icon-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-block-size: var(--hit);
  border: 2px solid var(--c-border);
  border-radius: var(--r-2);
  background: var(--c-surface);
  color: var(--c-text-2);
  cursor: pointer;
  transition: border-color var(--dur-1), background-color var(--dur-1), color var(--dur-1);
}
.pg-habits__icon-btn:hover { border-color: var(--c-primary); color: var(--c-text); }
.pg-habits__icon-btn[aria-checked="true"] {
  border-color: var(--c-primary);
  background: var(--c-primary-soft);
  color: var(--c-primary-text);
}
.pg-habits__icon-btn .icon--habit { inline-size: 24px; block-size: 24px; }

.pg-habits__presets { display: grid; gap: 0; }
.pg-habits__presets-hint { margin: 0 0 var(--sp-2); }
.pg-habits__preset {
  align-items: flex-start;
  padding-block: var(--sp-2);
  border-block-end: 1px solid var(--c-border);
}
.pg-habits__preset:last-child { border-block-end: 0; }
.pg-habits__preset .check__box { margin-block-start: 4px; }
.pg-habits__preset .check__label { display: grid; gap: 2px; }
.pg-habits__preset .pg-habits__name { flex-wrap: wrap; font-weight: 600; }
.pg-habits__preset .pg-habits__name .icon--habit { inline-size: 20px; block-size: 20px; }
.pg-habits__preset--exists { color: var(--c-text-2); }
.pg-habits__preset--exists .pg-habits__name .icon--habit { color: var(--c-text-2); }

.pg-habits__menu-list { margin: calc(-1 * var(--sp-2)) 0; }
.pg-habits__menu-item { min-block-size: 56px; border-radius: var(--r-2); padding-inline: var(--sp-2); }
.pg-habits__menu-item--danger { color: var(--c-danger); }
.pg-habits__menu-item--danger .list__lead { color: var(--c-danger); background: var(--c-danger-soft); }
