/* Habits: check-in cards, history strips and the habit pages. Bootstrap does the rest. */

.habits {
    --habit-muted: #6c757d;
    --habit-border: rgba(0, 0, 0, .08);
    --habit-success: #2f8f5b;
    --habit-on-track: #7fbf96;
    --habit-pending: #d9a441;
    --habit-fail: #c0392b;
    --habit-off: rgba(0, 0, 0, .07);
    max-width: 1280px;
    margin: 0 auto;
    padding: 1rem 1rem 3rem;
}

.habits-tabs { border-bottom: 1px solid var(--habit-border); margin-bottom: 1.25rem; }
.habits-header { display: flex; flex-wrap: wrap; align-items: flex-end; justify-content: space-between; gap: .75rem; margin-bottom: 1.25rem; }
.habits-header h1 { font-size: 1.75rem; margin: 0; line-height: 1.2; }
.habits-subtitle { color: var(--habit-muted); margin-top: .25rem; }
.habits-description { max-width: 60rem; }

.habit-daynav { display: flex; align-items: center; gap: .5rem; flex-wrap: wrap; }

.habit-week { max-width: 44rem; }
.habit-week__heading { display: flex; align-items: center; justify-content: space-between; gap: .5rem; margin: .65rem 0 .5rem; }
.habit-week__heading strong { font-size: .95rem; font-variant-numeric: tabular-nums; }
.habit-week__days { display: grid; grid-template-columns: repeat(7, minmax(0, 1fr)); gap: .35rem; }
.habit-week__day { min-height: 3.5rem; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: .05rem; border: 1px solid var(--habit-border); border-radius: .65rem; color: inherit; text-decoration: none; background: #fff; }
.habit-week__day span { color: var(--habit-muted); font-size: .7rem; text-transform: uppercase; }
.habit-week__day strong { font-size: 1.05rem; font-variant-numeric: tabular-nums; }
.habit-week__day small { font-size: .6rem; line-height: 1; color: var(--habit-muted); }
.habit-week__day:hover { border-color: #8492a6; }
.habit-week__day.is-selected { color: #fff; background: #24364b; border-color: #24364b; }
.habit-week__day.is-selected span, .habit-week__day.is-selected small { color: rgba(255, 255, 255, .78); }
.habit-week__day.is-today:not(.is-selected) { border-color: #24364b; }
.habit-week__picker { display: flex; align-items: center; gap: .5rem; margin-top: .65rem; }
.habit-week__picker label { margin: 0; color: var(--habit-muted); font-size: .8rem; }
.habit-week__picker input { width: auto; }
.habit-log-summary { margin: 0 0 1rem; color: var(--habit-muted); font-size: .9rem; }
.habit-log-summary strong { color: #24364b; }

.habits-group { margin-bottom: 2rem; }
.habits-group h2 { font-size: 1.2rem; margin-bottom: .75rem; }
.habits-group h2 small { font-size: .85rem; font-weight: 400; color: var(--habit-muted); margin-left: .5rem; }

.habits-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(18rem, 1fr)); gap: 1rem; }

.habits-empty { text-align: center; padding: 3rem 1rem; border: 1px dashed var(--habit-border); border-radius: .75rem; }
.habits-empty > .bi { font-size: 2.5rem; color: var(--habit-muted); }
.habits-empty p { color: var(--habit-muted); max-width: 32rem; margin: .5rem auto 1rem; }

/* ── Card ─────────────────────────────────────────────────────────── */
.habit-card {
    display: flex;
    flex-direction: column;
    gap: .75rem;
    padding: 1rem;
    background: #fff;
    border: 1px solid var(--habit-border);
    border-left: 4px solid var(--habit-off);
    border-radius: .75rem;
    transition: opacity .15s;
}
.habit-card[data-outcome="success"] { border-left-color: var(--habit-success); }
.habit-card[data-outcome="on_track"] { border-left-color: var(--habit-on-track); }
.habit-card[data-outcome="pending"] { border-left-color: var(--habit-pending); }
.habit-card[data-outcome="fail"] { border-left-color: var(--habit-fail); }
.habit-card[data-due] { box-shadow: 0 0 0 2px rgba(217, 164, 65, .25); }
.habit-card.is-busy { opacity: .6; pointer-events: none; }

.habit-card__head { display: flex; justify-content: space-between; align-items: flex-start; gap: .5rem; }
.habit-card__name { font-weight: 600; font-size: 1.05rem; color: inherit; text-decoration: none; }
.habit-card__name:hover { text-decoration: underline; }
.habit-card__rule { font-size: .85rem; color: var(--habit-muted); }
.habit-card__body { display: flex; align-items: center; gap: 1rem; }

.habit-streak { white-space: nowrap; font-size: .85rem; color: #b25d12; }

.habit-counter { display: flex; align-items: center; gap: .4rem; flex: none; }
/* Large touch targets for the iPad and phone. */
.habit-counter__btn { width: 2.75rem; height: 2.75rem; padding: 0; border-radius: 50%; font-size: 1.1rem; }
.habit-counter__value { min-width: 2.2rem; text-align: center; font-size: 1.6rem; font-weight: 700; font-variant-numeric: tabular-nums; }

.habit-progress { flex: 1; min-width: 0; font-size: .85rem; }
.habit-progress__text { display: flex; flex-wrap: wrap; gap: .25rem .5rem; align-items: center; margin-bottom: .3rem; }
.habit-progress__bar { height: .4rem; border-radius: 1rem; background: var(--habit-off); overflow: hidden; }
.habit-progress__bar span { display: block; height: 100%; background: var(--habit-pending); }
.habit-progress[data-outcome="success"] .habit-progress__bar span { background: var(--habit-success); }
.habit-progress[data-outcome="on_track"] .habit-progress__bar span { background: var(--habit-on-track); }
.habit-progress[data-outcome="fail"] .habit-progress__bar span { background: var(--habit-fail); }

.habit-outcome { display: inline-block; padding: .05rem .45rem; border-radius: 1rem; font-size: .75rem; font-weight: 600; background: var(--habit-off); color: #444; }
.habit-outcome[data-outcome="success"] { background: rgba(47, 143, 91, .15); color: var(--habit-success); }
.habit-outcome[data-outcome="on_track"] { background: rgba(127, 191, 150, .2); color: #3d7a54; }
.habit-outcome[data-outcome="pending"] { background: rgba(217, 164, 65, .18); color: #8a6119; }
.habit-outcome[data-outcome="fail"] { background: rgba(192, 57, 43, .13); color: var(--habit-fail); }

.habit-kind { display: inline-block; padding: .05rem .5rem; border-radius: 1rem; font-size: .75rem; font-weight: 600; background: rgba(47, 143, 91, .12); color: var(--habit-success); }
.habit-kind[data-kind="avoid"] { background: rgba(192, 57, 43, .1); color: var(--habit-fail); }

/* ── History strip ───────────────────────────────────────────────── */
.habit-history { display: flex; gap: .25rem; padding: 0; margin: 0; list-style: none; flex-wrap: wrap; }
.habit-history__cell { width: 1.1rem; height: 1.1rem; border-radius: 4px; background: var(--habit-off); display: inline-flex; align-items: center; justify-content: center; font-size: .7rem; color: #fff; font-weight: 600; }
.habit-history--sm .habit-history__cell { width: .8rem; height: .8rem; border-radius: 3px; }
.habit-history--lg .habit-history__cell { width: 1.9rem; height: 1.9rem; border-radius: 6px; }
.habit-history__cell[data-outcome="success"] { background: var(--habit-success); }
.habit-history__cell[data-outcome="on_track"] { background: var(--habit-on-track); }
.habit-history__cell[data-outcome="pending"] { background: var(--habit-pending); }
.habit-history__cell[data-outcome="fail"] { background: var(--habit-fail); }
.habit-history__cell[data-outcome="off"] { color: #555; }
.habit-history__cell[data-current] { outline: 2px solid rgba(0, 0, 0, .35); outline-offset: 1px; }

.habit-legend { display: flex; flex-wrap: wrap; gap: .5rem 1rem; padding: 0; margin: .75rem 0 0; list-style: none; font-size: .8rem; color: var(--habit-muted); }
.habit-legend li { display: flex; align-items: center; gap: .35rem; }

.habit-note summary { font-size: .85rem; color: var(--habit-muted); cursor: pointer; }
.habit-note textarea { margin-top: .4rem; }
.habit-checklist summary { font-size: .85rem; color: var(--habit-muted); cursor: pointer; }
.habit-checklist__items { margin: .4rem 0 0; padding: 0; list-style: none; display: grid; gap: .3rem; }
.habit-checklist__items .form-check { margin: 0; font-size: .9rem; line-height: 1.35; }
.habit-checklist__items .form-check-input:checked + .form-check-label { color: var(--habit-muted); }
.habit-checklist__hint { margin: .4rem 0 0; font-size: .75rem; color: var(--habit-muted); }

/* Quick logging keeps the selected day and every habit visible together. */
.habits-checkin .habits-grid { grid-template-columns: minmax(0, 1fr); gap: .5rem; }
.habits-checkin .habit-card { display: grid; grid-template-columns: minmax(0, 1fr) auto; align-items: center; gap: .45rem 1rem; padding: .65rem .85rem; }
.habits-checkin .habit-card__head { min-width: 0; align-items: center; }
.habits-checkin .habit-card__name { display: block; overflow-wrap: anywhere; }
.habits-checkin .habit-card__rule { line-height: 1.25; }
.habits-checkin .habit-card__body { justify-content: flex-end; gap: .75rem; }
.habits-checkin .habit-counter__btn { width: 2.75rem; height: 2.75rem; }
.habits-checkin .habit-progress { flex: 0 1 8rem; }
.habits-checkin .habit-card__details { grid-column: 1 / -1; color: var(--habit-muted); font-size: .8rem; }
.habits-checkin .habit-card__details > summary { cursor: pointer; }
.habits-checkin .habit-card__details[open] { display: grid; gap: .65rem; }
.habits-checkin .habit-note, .habits-checkin .habit-checklist { color: inherit; }

@media (max-width: 575.98px) {
    .habit-week__days { gap: .2rem; }
    .habit-week__day { min-height: 3.25rem; border-radius: .5rem; }
    .habit-week__day span { font-size: .62rem; }
    .habit-week__day small { font-size: .55rem; }
    .habit-week__picker { align-items: stretch; }
    .habit-week__picker label { align-self: center; }
    .habit-week__picker input { flex: 1; min-width: 0; }
    .habits-checkin .habit-card { grid-template-columns: minmax(0, 1fr) auto; gap: .35rem .5rem; padding: .6rem; }
    .habits-checkin .habit-card__body { grid-column: 1 / -1; justify-content: space-between; gap: .75rem; }
    .habits-checkin .habit-progress { display: block; flex: 1; }
    .habits-checkin .habit-progress__text { font-size: .75rem; }
    .habits-checkin .habit-card__name { font-size: .95rem; }
    .habits-checkin .habit-card__rule { font-size: .75rem; }
    .habits-checkin .habit-streak { display: none; }
}

/* ── Habit page ──────────────────────────────────────────────────── */
.habit-stats { display: grid; grid-template-columns: repeat(auto-fit, minmax(10rem, 1fr)); gap: 1rem; margin-bottom: 2rem; }
.habit-stats > div { padding: 1rem; border: 1px solid var(--habit-border); border-radius: .75rem; background: #fff; }
.habit-stats strong { display: block; font-size: 1.6rem; }
.habit-stats span { font-size: .85rem; color: var(--habit-muted); }

.habits-table__inactive { opacity: .6; }

/* ── Form ────────────────────────────────────────────────────────── */
.habits-form-card { max-width: 46rem; padding: 1.25rem; border: 1px solid var(--habit-border); border-radius: .75rem; background: #fff; }
.habit-form__kind, .habit-form__days { display: flex; flex-wrap: wrap; gap: .25rem 1.25rem; }
.habit-form__kind .form-check, .habit-form__days .form-check { margin: 0; }
.habits-danger { display: flex; align-items: center; gap: .75rem; margin-top: 2rem; max-width: 46rem; }

.habit-notes { padding-left: 1.1rem; }
.habit-notes li { margin-bottom: .35rem; }
