/* MyGrind · components.css
 * Atoms and molecules, in the same order as js/ui/atoms.js and molecules.js.
 */

/* =========================================================
   ATOMS
   ========================================================= */

/* ---------- Icons & illustrations ---------- */

.icon {
  flex: none;
  width: 22px;
  height: 22px;
  fill: none;
  stroke: currentColor;
  stroke-width: 2;
  stroke-linecap: round;
  stroke-linejoin: round;
}
.illus { flex: none; overflow: visible; }

/* ---------- Buttons ---------- */

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  min-height: var(--tap);
  padding: 0 22px;
  border: 0;
  border-radius: var(--r-pill);
  font-size: var(--fs-sub);
  font-weight: 600;
  letter-spacing: -0.01em;
  text-decoration: none;
  white-space: nowrap;
  cursor: pointer;
  transition: transform 0.15s var(--ease), background-color 0.2s, color 0.2s;
}
.btn:active { transform: scale(0.97); }
/* A <label class="btn"> wrapping a hidden file input shows the input's keyboard focus. */
.btn:has(input:focus-visible) { outline: 3px solid var(--accent); outline-offset: 2px; }
.btn .icon { width: 20px; height: 20px; }

.btn--primary {
  background: var(--accent);
  color: var(--accent-ink);
  box-shadow: 0 10px 24px -12px var(--accent);
}
.btn--primary:hover { background: var(--accent-strong); }
.btn--soft { background: var(--surface-2); color: var(--ink); }
.btn--soft:hover { background: var(--surface-3); }
.btn--danger { background: transparent; color: var(--danger); box-shadow: inset 0 0 0 2px currentColor; }
.btn--sm { min-height: 40px; padding: 0 16px; font-size: 14px; }
.btn--sm .icon { width: 18px; height: 18px; }
.btn--block { width: 100%; }

.btn-row { display: flex; flex-wrap: wrap; gap: 10px; }

.icon-btn {
  display: grid;
  flex: none;
  place-items: center;
  width: var(--tap);
  height: var(--tap);
  padding: 0;
  border: 0;
  border-radius: 50%;
  background: transparent;
  color: var(--ink-2);
  transition: background-color 0.2s, color 0.2s, transform 0.15s;
}
.icon-btn:hover { background: var(--surface-2); color: var(--ink); }
.icon-btn:active { transform: scale(0.94); }
.icon-btn:disabled { opacity: 0.35; background: transparent; }
.icon-btn--surface { background: var(--surface); color: var(--ink); box-shadow: var(--shadow-sm); }
.icon-btn--surface:hover { background: var(--surface); }
.icon-btn--danger:hover { color: var(--danger); }

.link {
  display: inline-flex;
  align-items: center;
  gap: 2px;
  min-height: 40px;
  color: var(--ink-2);
  font-size: 14px;
  font-weight: 600;
  text-decoration: none;
}
.link:hover { color: var(--accent); }
.link .icon { width: 18px; height: 18px; }

/* ---------- Cards ---------- */

.card {
  display: grid;
  gap: 14px;
  padding: 18px;
  border-radius: var(--r-lg);
  background: var(--surface);
  box-shadow: var(--shadow);
}
.card--accent { background: var(--accent-soft); box-shadow: none; }

.card__head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  min-height: 40px;
}
.card__title { font-size: var(--fs-headline); font-weight: 600; letter-spacing: -0.015em; }

/* ---------- Progress, check, tiles ---------- */

.progress {
  height: 12px;
  overflow: hidden;
  border-radius: var(--r-pill);
  background: var(--surface-3);
}
.progress__fill {
  width: calc(var(--p) * 100%);
  height: 100%;
  border-radius: inherit;
  background: var(--accent);
}

.check {
  display: grid;
  flex: none;
  place-items: center;
  width: 28px;
  height: 28px;
  border: 2px solid var(--ink-3);
  border-radius: 50%;
  color: transparent;
  transition: background-color 0.2s, border-color 0.2s, color 0.2s;
}
.check .icon { width: 16px; height: 16px; stroke-width: 3; }

.track-tile {
  display: grid;
  flex: none;
  place-items: center;
  width: 42px;
  height: 42px;
  border-radius: 14px;
  background: var(--tile-bg);
  color: var(--c);
}

.dot {
  flex: none;
  width: 10px;
  height: 10px;
  border-radius: 50%;
  background: var(--c);
}

/* ---------- Form controls ---------- */

.field { display: grid; gap: 8px; }
.field__label { font-size: var(--fs-foot); font-weight: 600; color: var(--ink-2); letter-spacing: 0; }
.field__hint { font-size: 13px; color: var(--ink-3); }

.input {
  width: 100%;
  min-height: 52px;
  padding: 0 16px;
  border: 2px solid transparent;
  border-radius: var(--r-sm);
  background: var(--surface-2);
  font-size: 16px; /* 16px stops mobile browsers zooming on focus */
  transition: border-color 0.2s, background-color 0.2s;
}
.input:focus { outline: none; border-color: var(--accent); background: var(--surface); }
.input::placeholder { color: var(--ink-3); }
textarea.input { min-height: 88px; padding: 12px 14px; line-height: 1.45; resize: vertical; }
.input--time { max-width: 200px; }

.chips { display: flex; flex-wrap: wrap; gap: 8px; }

.chip { position: relative; }
.chip input {
  position: absolute;
  width: 1px;
  height: 1px;
  opacity: 0;
  pointer-events: none;
}
.chip__face {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  min-height: 44px;
  padding: 0 16px;
  border-radius: var(--r-pill);
  background: var(--surface-2);
  font-size: 14px;
  font-weight: 600;
  cursor: pointer;
  user-select: none;
  transition: background-color 0.15s, color 0.15s;
}
.sheet .chip__face { background: var(--surface); box-shadow: var(--shadow-sm); }
.chip input:checked + .chip__face { background: var(--selected); color: var(--on-selected); }
.chip input:focus-visible + .chip__face { outline: 3px solid var(--accent); outline-offset: 2px; }

.daypick {
  display: grid;
  grid-template-columns: repeat(7, 1fr);
  justify-items: center;
  gap: 6px;
}
.chip--round { width: 100%; max-width: 48px; }
.chip--round .chip__face {
  width: 100%;
  aspect-ratio: 1;
  min-height: 0;
  padding: 0;
  border-radius: 50%;
}

.seg {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 4px;
  padding: 4px;
  border-radius: var(--r-pill);
  background: var(--surface-2);
}
.seg button {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  min-height: 44px;
  border: 0;
  border-radius: var(--r-pill);
  background: transparent;
  color: var(--ink-2);
  font-size: 14px;
  font-weight: 600;
}
.seg button[aria-pressed="true"] { background: var(--surface); color: var(--ink); box-shadow: var(--shadow-sm); }
:root[data-theme="dark"] .seg button[aria-pressed="true"] { background: var(--surface-3); }
.seg .icon { width: 18px; height: 18px; }

.switch {
  position: relative;
  flex: none;
  width: 52px;
  height: 32px;
  border-radius: var(--r-pill);
  background: var(--surface-3);
  transition: background-color 0.25s;
}
.switch::after {
  content: "";
  position: absolute;
  top: 4px;
  left: 4px;
  width: 24px;
  height: 24px;
  border-radius: 50%;
  background: #FFFFFF;
  box-shadow: 0 1px 3px rgba(0, 0, 0, 0.25);
  transition: transform 0.25s var(--ease);
}
[aria-checked="true"] > .switch { background: var(--accent); }
[aria-checked="true"] > .switch::after { transform: translateX(20px); }

/* =========================================================
   MOLECULES
   ========================================================= */

/* ---------- Page head ---------- */

.page-head {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 12px;
}
.page-head h1 {
  font-size: var(--fs-large);
  font-weight: 700;
  line-height: 1.08;
  letter-spacing: var(--track-large);
}
.page-head__actions { display: flex; flex: none; align-items: center; gap: 8px; }

/* Small caps-style label above titles, like the date line in Apple's Fitness and News apps. */
.eyebrow {
  margin-bottom: 6px;
  color: var(--ink-3);
  font-size: var(--fs-foot);
  font-weight: 600;
  letter-spacing: 0.04em;
  text-transform: uppercase;
}

.section-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
}
.section-head__actions { display: flex; align-items: center; gap: 2px; }
.section-title { font-size: var(--fs-title3); font-weight: 700; letter-spacing: var(--track-title); }

.streak-pill {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  height: var(--tap);
  padding: 0 16px 0 12px;
  border-radius: var(--r-pill);
  background: var(--surface);
  box-shadow: var(--shadow-sm);
  font-weight: 700;
  text-decoration: none;
}
.streak-pill .icon { color: var(--accent); fill: var(--accent); }

.theme-switch {
  display: flex;
  align-items: center;
  gap: 12px;
  width: 100%;
  min-height: 56px;
  padding: 0 12px 0 16px;
  border: 0;
  border-radius: var(--r-md);
  background: var(--surface);
  box-shadow: var(--shadow-sm);
  font-weight: 600;
  text-align: left;
}
.theme-switch__label { flex: 1; }

.week-nav {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}
.week-nav__label { font-weight: 700; }

/* ---------- Week strip ---------- */

.strip { display: grid; gap: 10px; }

.week {
  display: grid;
  grid-template-columns: repeat(7, 1fr);
  gap: 4px;
}

.day {
  display: grid;
  justify-items: center;
  gap: 6px;
  padding: 4px 0;
  border: 0;
  border-radius: var(--r-sm);
  background: none;
  color: var(--ink-2);
}
.day__name { font-size: 12px; font-weight: 600; }
.day__num {
  display: grid;
  place-items: center;
  width: 40px;
  height: 40px;
  border: 2px solid transparent;
  border-radius: 50%;
  background: var(--surface);
  box-shadow: var(--shadow-sm);
  color: var(--ink);
  font-weight: 700;
  transition: background-color 0.2s, color 0.2s;
}
.day__dot { width: 6px; height: 6px; border-radius: 50%; }
.day[aria-current="date"] .day__num { border-color: var(--accent); }
.day[aria-pressed="true"] .day__name { color: var(--ink); }
.day[aria-pressed="true"] .day__num { background: var(--selected); color: var(--on-selected); }
.day[data-hit="true"] .day__dot { background: var(--accent); }

@media (min-width: 768px) {
  .day__num { width: 46px; height: 46px; }
}

/* ---------- Up next ---------- */

.up-next {
  grid-template-columns: minmax(0, 1fr) auto;
  align-items: center;
}
.up-next__text { display: grid; justify-items: start; gap: 4px; }
.up-next .eyebrow { color: var(--accent-soft-ink); }
.up-next__title { font-size: var(--fs-title); font-weight: 700; line-height: 1.15; letter-spacing: var(--track-title); }
.up-next__meta { margin-bottom: 10px; color: var(--ink-2); font-size: var(--fs-sub); }
.up-next__art { width: 92px; height: 92px; }

/* ---------- Progress card ---------- */

.progress-card__top {
  display: flex;
  align-items: flex-end;
  justify-content: space-between;
  gap: 12px;
}
.progress-card__pct { color: var(--accent); font-size: 34px; font-weight: 700; line-height: 1; }
.progress-card__hint { color: var(--ink-2); font-size: 14px; }
.progress-card__hint[data-hit="true"] { color: var(--accent); font-weight: 600; }

/* ---------- Checklist block ---------- */

.blocks { display: grid; gap: 10px; }

.block {
  border-radius: var(--r-md);
  background: var(--surface);
  box-shadow: var(--shadow);
}

.block__row {
  display: flex;
  align-items: center;
  padding-right: 6px;
}

.block__main {
  display: flex;
  flex: 1;
  align-items: center;
  gap: 12px;
  min-width: 0;
  min-height: 72px;
  padding: 12px 6px 12px 14px;
  border: 0;
  border-radius: var(--r-md);
  background: none;
  text-align: left;
}
.block__main:disabled { opacity: 0.7; }

.block__text { display: grid; gap: 2px; min-width: 0; }
.block__title { font-size: var(--fs-headline); font-weight: 600; line-height: 1.25; overflow-wrap: anywhere; }
.block__meta { color: var(--ink-3); font-size: var(--fs-foot); letter-spacing: 0; }

.block[data-done="true"] .check { border-color: var(--accent); background: var(--accent); color: var(--accent-ink); }
.block[data-done="true"] .block__title {
  color: var(--ink-2);
  text-decoration: line-through;
  text-decoration-color: var(--ink-3);
}

.block__note-btn[data-has-note="true"] { color: var(--accent); }
.block__note-btn[aria-expanded="true"] { background: var(--surface-2); color: var(--ink); }

.block__preview {
  display: block;
  width: calc(100% - 28px);
  margin: 0 14px 14px;
  padding: 10px 12px;
  border: 0;
  border-radius: 12px;
  background: var(--surface-2);
  color: var(--ink-2);
  font-size: 14px;
  text-align: left;
  white-space: pre-wrap;
  overflow-wrap: anywhere;
}

.block__note { padding: 0 14px 14px; }

/* ---------- Streak card ---------- */

.streak-card__top { display: flex; align-items: center; gap: 14px; }
.streak-card__art { width: 68px; height: 68px; }
.streak-card__value { font-size: 15px; font-weight: 600; }
.streak-card__value strong { font-size: 36px; font-weight: 700; line-height: 1.05; }

.streak-week {
  display: grid;
  grid-template-columns: repeat(7, 1fr);
  justify-items: center;
  gap: 4px;
}
.streak-week__dot {
  display: grid;
  place-items: center;
  width: 32px;
  height: 32px;
  border-radius: 50%;
  background: var(--surface-2);
  color: var(--ink-3);
  font-size: 12px;
  font-weight: 700;
}
.streak-week__dot .icon { width: 16px; height: 16px; stroke-width: 3; }
.streak-week__day[data-state="hit"] .streak-week__dot { background: var(--accent); color: var(--accent-ink); }
.streak-week__day[data-state="miss"] .streak-week__dot { background: var(--surface-3); color: var(--ink-2); }
.streak-week__day[data-state="off"] .streak-week__dot { background: transparent; box-shadow: inset 0 0 0 2px var(--line); }
.streak-week__day[aria-current="date"] .streak-week__dot { box-shadow: inset 0 0 0 2px var(--accent); }

/* ---------- Track bars (weekly review) ---------- */

.bars {
  display: grid;
  grid-auto-columns: minmax(0, 1fr);
  grid-auto-flow: column;
  gap: 12px;
}

.bar { display: grid; justify-items: center; gap: 10px; }

.bar__track {
  position: relative;
  width: 100%;
  max-width: 96px;
  height: 260px;
  overflow: hidden;
  border-radius: var(--r-pill);
  background: repeating-linear-gradient(135deg, var(--hatch) 0 2px, transparent 2px 10px), var(--surface-2);
}

.bar__fill {
  position: absolute;
  right: 0;
  bottom: 0;
  left: 0;
  height: calc(var(--p) * 100%);
  border-radius: var(--r-pill);
  background: var(--c);
}
.bars--animate .bar__fill { animation: rise 0.7s var(--ease) both; }

@keyframes rise {
  from { height: 0; }
}

.bar__pct {
  position: absolute;
  bottom: 10px;
  left: 50%;
  padding: 4px 10px;
  border-radius: var(--r-pill);
  background: rgba(255, 255, 255, 0.92);
  color: #2A1A12;
  font-size: 13px;
  font-weight: 700;
  transform: translateX(-50%);
}

.bar__label {
  display: grid;
  justify-items: center;
  color: var(--ink);
  font-size: 14px;
  font-weight: 600;
  text-align: center;
}
.bar__count { color: var(--ink-3); font-size: 12px; font-weight: 600; }

.bars--compact .bar__track { height: 170px; }

/* ---------- Stats ---------- */

.stats {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  border-top: 1px solid var(--line);
}
.stat { display: grid; gap: 2px; padding: 14px 4px 0; text-align: center; }
.stat + .stat { border-left: 1px solid var(--line); }
.stat dt { color: var(--ink-3); font-size: var(--fs-cap); font-weight: 600; letter-spacing: 0.02em; text-transform: uppercase; }
.stat dd { font-size: var(--fs-title3); font-weight: 700; }

/* ---------- Day bars ---------- */

.daybars {
  display: grid;
  grid-template-columns: repeat(7, 1fr);
  gap: 6px;
}
.daybar { display: grid; justify-items: center; gap: 6px; }
.daybar__track {
  position: relative;
  width: 100%;
  max-width: 36px;
  height: 96px;
  overflow: hidden;
  border-radius: 12px;
  background: var(--surface-2);
}
.daybar__track::after { /* the 70% streak line */
  content: "";
  position: absolute;
  right: 0;
  bottom: 70%;
  left: 0;
  border-top: 2px dashed var(--ink-3);
  opacity: 0.5;
}
.daybar__fill {
  position: absolute;
  right: 0;
  bottom: 0;
  left: 0;
  height: calc(var(--p) * 100%);
  background: var(--ink-3);
}
.daybar[data-state="hit"] .daybar__fill { background: var(--accent); }
.daybar__pct { font-size: 12px; font-weight: 700; }
.daybar__day { color: var(--ink-3); font-size: 12px; font-weight: 600; }

/* ---------- Empty state ---------- */

.empty {
  display: grid;
  justify-items: center;
  gap: 6px;
  padding: 24px 16px;
  border-radius: var(--r-md);
  background: var(--surface);
  text-align: center;
}
.empty__art { width: 80px; height: 80px; margin-bottom: 4px; }
.empty h3 { font-size: var(--fs-headline); font-weight: 600; }
.empty .btn { margin-top: 8px; }

/* ---------- Sheet (dialog) ---------- */

.sheet {
  width: 100%;
  max-width: 560px;
  max-height: 92dvh;
  margin: auto auto 0;
  padding: 0;
  overflow-y: auto;
  border: 0;
  border-radius: var(--r-lg) var(--r-lg) 0 0;
  background: var(--bg);
  color: var(--ink);
  box-shadow: var(--shadow-lg);
  overscroll-behavior: contain;
}
.sheet::backdrop { background: var(--scrim); }
.sheet[open] { animation: sheet-up 0.3s var(--ease); }

@keyframes sheet-up {
  from { opacity: 0; transform: translateY(40px); }
}

@media (min-width: 768px) {
  .sheet { margin: auto; border-radius: var(--r-lg); }
}

.sheet__body {
  display: grid;
  gap: 20px;
  padding: 20px 20px calc(24px + env(safe-area-inset-bottom));
}
.sheet__head { display: flex; align-items: center; gap: 12px; }
.sheet__art { width: 52px; height: 52px; }
.sheet__title { flex: 1; font-size: 28px; font-weight: 700; letter-spacing: var(--track-large); }
.sheet .input { background: var(--surface); }

.form-error { margin: -8px 0; color: var(--danger); font-size: 14px; font-weight: 600; }
.form-error:empty { display: none; }
.form-actions { display: grid; gap: 10px; }

/* ---------- Toast ---------- */

.toast {
  position: fixed;
  bottom: calc(var(--tabbar-h) + env(safe-area-inset-bottom) + 24px);
  left: 50%;
  z-index: 50;
  display: flex;
  align-items: center;
  gap: 12px;
  max-width: calc(100vw - 32px);
  min-height: 48px;
  padding: 6px 6px 6px 18px;
  border-radius: var(--r-pill);
  background: var(--selected);
  color: var(--on-selected);
  box-shadow: var(--shadow-lg);
  font-size: 14px;
  font-weight: 600;
  opacity: 0;
  pointer-events: none;
  transform: translate(-50%, 16px);
  transition: opacity 0.25s, transform 0.25s var(--ease);
}
.toast.is-visible { opacity: 1; pointer-events: auto; transform: translate(-50%, 0); }
.toast > span:only-child { padding-right: 12px; }
.toast__btn {
  min-height: 36px;
  padding: 0 14px;
  border: 0;
  border-radius: var(--r-pill);
  background: var(--accent);
  color: var(--accent-ink);
  font-weight: 700;
}

@media (min-width: 768px) {
  .toast { bottom: 28px; }
}

/* ---------- Numbers ----------
 * Figures use SF Pro Rounded on Apple devices (Inter elsewhere) with
 * tabular digits, so values line up and don't shift width as they change. */
.progress-card__pct,
.streak-card__value strong,
.summary__big,
.stat dd,
.bar__pct,
.daybar__pct,
.day__num,
.streak-pill span {
  font-family: var(--font-num);
  font-variant-numeric: tabular-nums;
  letter-spacing: -0.02em;
}

.block__meta,
.tt-block__time,
.bar__count,
.row__meta { font-variant-numeric: tabular-nums; }
