/* Habits v7 (owner: habits) — counters, streaks on Today's Habits row and the section screen
   ([data-screen="today"] covers both: the section screen draws its body with that attribute), the evening
   "Lie down by" line, and the habit editor in Settings › Habits (.hb-edit, drag to reorder). Prefix .hb- */

/* ---------- a streak: a small flame and the number, after the name ---------- */
[data-screen="today"] .hb-streak {
  flex: none; display: inline-flex; align-items: center; gap: 2px; margin-inline-start: -6px;
  font: 600 12px/1 var(--f-sans); color: var(--muted); font-variant-numeric: tabular-nums;
}
[data-screen="today"] .hb-streak svg { width: 13px; height: 13px; color: var(--orange, #ff9f0a); stroke-width: 2; }

/* ---------- a counter: token · name · − 7 / 20 pages + , a thin bar under it ---------- */
[data-screen="today"] .hb-li { position: relative; }
[data-screen="today"] .td-habit.hb-count { cursor: default; position: relative; gap: 12px; }
[data-screen="today"] .hb-count .td-token.is-on { background: rgb(var(--cta-rgb)); color: #fff; box-shadow: 0 3px 10px -4px rgb(var(--cta-rgb) / 0.8); }   /* today9: the same blue tick as a plain habit (was white) */
[data-screen="today"] .hb-count.is-done .td-habit__name { color: var(--muted); }
[data-screen="today"] .hb-ctl { flex: none; display: inline-flex; align-items: center; gap: 2px; }
[data-screen="today"] .hb-step {
  position: relative; display: grid; place-items: center; width: 36px; height: 36px; padding: 0; border: 0; border-radius: 50%;
  background: rgb(var(--fg-rgb) / 0.07); color: var(--fg); cursor: pointer; -webkit-tap-highlight-color: transparent;
  transition: background var(--dur-fast), transform var(--dur-fast) var(--ease-out), opacity var(--dur-fast);
}
[data-screen="today"] .hb-step::after { content: ''; position: absolute; inset: -4px; }
[data-screen="today"] .hb-step svg { width: 16px; height: 16px; stroke-width: 2.2; }
[data-screen="today"] .hb-step:active { transform: scale(0.88); }
[data-screen="today"] .hb-step:disabled { opacity: 0.35; cursor: default; }
@media (hover: hover) { [data-screen="today"] .hb-step:not(:disabled):hover { background: rgb(var(--fg-rgb) / 0.12); } }
[data-screen="today"] .hb-val {
  min-width: 64px; max-width: 136px; min-height: 36px; padding: 0 6px; border: 0; border-radius: 10px; background: none; cursor: text;
  font: 600 14px/1.15 var(--f-sans); color: var(--fg); font-variant-numeric: tabular-nums; text-align: center;
  overflow-wrap: anywhere; -webkit-tap-highlight-color: transparent;
}
@media (hover: hover) { [data-screen="today"] .hb-val:hover { background: rgb(var(--fg-rgb) / 0.06); } }
[data-screen="today"] .hb-val { display: inline-flex; flex-direction: column; align-items: center; justify-content: center; gap: 1px; }
[data-screen="today"] .hb-val__n { white-space: nowrap; }
[data-screen="today"] .hb-val__u { max-width: 100%; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-size: 11px; font-weight: 500; color: var(--muted); }
[data-screen="today"] .hb-val__input { width: 88px; min-height: 36px; padding: 0 8px; text-align: center; font-size: 16px; font-variant-numeric: tabular-nums; }
[data-screen="today"] .hb-bar {
  position: absolute; left: 42px; right: 0; bottom: 3px; height: 2px; border-radius: 1px; background: rgb(var(--fg-rgb) / 0.07); overflow: hidden; pointer-events: none;
}
[data-screen="today"] .hb-bar::after {
  content: ''; position: absolute; inset: 0; transform-origin: left center; transform: scaleX(var(--p, 0));
  background: rgb(var(--cta-rgb)); transition: transform var(--dur) var(--ease-out);   /* habits10: the app colour (was a grey line) */
}
[dir="rtl"] [data-screen="today"] .hb-bar { left: 0; right: 42px; }
[dir="rtl"] [data-screen="today"] .hb-bar::after { transform-origin: right center; }

/* the counter's circle is a button: one tap closes the counter at once (the number jumps to the goal), a second gives it back */
[data-screen="today"] .hb-tok { position: relative; padding: 0; border: 0; background: none; cursor: pointer; -webkit-tap-highlight-color: transparent; }
[data-screen="today"] .hb-tok::after { content: ''; position: absolute; inset: -8px; border-radius: 50%; }
[data-screen="today"] .hb-tok:active { transform: scale(0.86); }
@media (hover: hover) { [data-screen="today"] .hb-tok:not(.is-on):hover { box-shadow: inset 0 0 0 1.6px var(--muted); } }
[data-screen="today"] .hb-tok:focus-visible { outline: 2px solid var(--fg); outline-offset: 3px; }
/* habits10: the ring is for the keyboard only. After a tap the row is drawn again and the circle gets the focus back by
   script, which some browsers (Safari) show as :focus-visible: a white ring round a done circle. rows.js marks a
   pointer press on <html> (data-hb-ptr) and clears it on Tab / arrows, so a tapped circle looks like any done habit. */
html[data-hb-ptr] [data-screen="today"] .hb-tok:focus-visible { outline: none; }

/* ---------- "Add a habit" at the end of the list (Today and the Habits screen) ---------- */
[data-screen="today"] .hb-add {
  display: flex; align-items: center; gap: 14px; width: 100%; min-height: 52px; padding: 8px 0; border: 0; background: none;
  color: var(--muted); font: inherit; font-size: 16px; font-weight: 500; letter-spacing: -0.01em; text-align: left; cursor: pointer; -webkit-tap-highlight-color: transparent;
}
[data-screen="today"] .hb-add svg { flex: none; width: 18px; height: 18px; margin: 0 5px; stroke-width: 2.2; }
@media (hover: hover) { [data-screen="today"] .hb-add:hover { color: var(--fg); } }
[data-screen="today"] .hb-add:focus-visible { outline: 2px solid var(--fg); outline-offset: 2px; border-radius: 10px; }
/* right under the list it is one more row of it: the same line between, no extra gap */
[data-screen="today"] :is(.td-habits, .hb-none) + .hb-add { margin-top: -16px; border-top: 1px solid var(--line); }

/* ---------- the "New habit" sheet: name, Count it (goal + unit), days ---------- */
.hb-new { display: grid; gap: 18px; }
.hb-new .field > span { font-size: 13px; }
.hb-new__count { display: flex; align-items: center; justify-content: space-between; gap: 14px; }
.hb-new__t { font-size: 15px; font-weight: 550; letter-spacing: -0.01em; }
.hb-new__count .hb-fine { margin-top: 2px; }
.hb-new__goal[hidden] { display: none; }
.hb-new__go { width: 100%; }

[data-screen="today"] .hb-none { margin: -4px 0 4px; }

/* ---------- Sleep: "Lie down by 22:40 to sleep 8 h" ---------- */
[data-screen="today"] .hb-bed { color: var(--fg); font-weight: 500; }

/* ---------- Settings › Habits: what kind, which days, the goal ---------- */
.hb-sum { display: block; margin-top: -6px; padding-bottom: 10px; font-size: 13px; color: var(--muted); font-variant-numeric: tabular-nums; }
.st-habit + .hb-sum { border-bottom: 1px solid var(--line); }
.st-habit:has(+ .hb-sum) { border-bottom: 0; }
.hb-edit { display: flex; flex-direction: column; gap: 14px; padding: 4px 0 16px; border-bottom: 1px solid var(--line); animation: hb-in 220ms var(--ease-out); }
.st-habit:has(+ .hb-edit) { border-bottom: 0; }
@keyframes hb-in { from { opacity: 0; transform: translateY(-4px); } to { opacity: 1; transform: none; } }
.hb-edit__label { display: block; margin-bottom: 8px; font-size: 13px; font-weight: 500; color: var(--muted); }
.hb-edit .segmented { width: 100%; max-width: 420px; }
.hb-edit .segmented > button { flex: 1 1 0; min-width: 0; }
.hb-days { display: flex; flex-wrap: wrap; gap: 6px; }
.hb-days .chip { min-width: 44px; justify-content: center; padding: 0 10px; }
.hb-row { display: flex; flex-wrap: wrap; align-items: center; gap: 8px; }
.hb-row .input { width: auto; min-width: 0; }
.hb-num { width: 112px !important; font-variant-numeric: tabular-nums; }
.hb-unit { flex: 1 1 140px; max-width: 220px; }
.hb-fine { font-size: 13px; line-height: 1.4; color: var(--muted); text-wrap: pretty; }
.st-habit__tool.hb-more[aria-expanded="true"] { color: var(--fg); background: rgb(var(--fg-rgb) / 0.08); }

/* habits10: hold a habit and drag it to change the order (js/ui/tabdrag.js, as the bottom bar); Alt+↑/↓ on the keyboard */
.hb-item { position: relative; transition: transform 180ms var(--ease-out); }
.hb-list.is-arranging .hb-item { -webkit-user-select: none; user-select: none; }
.hb-list.is-arranging .hb-item.is-lifted { transition: none; z-index: 5; border-radius: 14px; background: color-mix(in srgb, rgb(var(--fg-rgb)) 10%, rgb(var(--bg-rgb))); box-shadow: 0 10px 26px rgb(0 0 0 / 0.35); }
.hb-list.is-arranging .hb-item.is-lifted .st-habit { border-bottom-color: transparent; }
.hb-hint { margin: 10px 0 0; font-size: 13px; color: var(--muted); }

@media (prefers-reduced-motion: reduce) {
  .hb-edit { animation: none; }
  [data-screen="today"] .hb-bar::after, [data-screen="today"] .hb-step, .hb-item { transition: none; }
}
