/* ========== Habits ========== */

/* Header — green icon modifier (mirrors --accent and --amber variants) */
.task-list-header-icon--green {
    color: var(--green);
}

/* Header right cluster: mini bar + fraction + settings btn */
.habit-header-right {
    margin-left: auto;
    display: flex;
    align-items: center;
    gap: 0.5rem;
}

.habit-mini-bar {
    width: 48px;
    height: 3px;
    background: var(--border-color);
    border-radius: 2px;
    overflow: hidden;
    flex-shrink: 0;
}

.habit-mini-bar-fill {
    height: 100%;
    background: var(--green);
    border-radius: 2px;
    transition: width 0.3s ease;
}

.habit-progress-fraction {
    font-size: 0.72rem;
    font-weight: 600;
    color: var(--text-muted);
    background: var(--bg-dark);
    border: 1px solid var(--border-color);
    border-radius: 20px;
    padding: 1px 8px;
    transition: color 0.3s, border-color 0.3s, background 0.3s;
    white-space: nowrap;
}

.habit-progress-fraction.all-done {
    color: var(--green);
    border-color: color-mix(in srgb, var(--green) 40%, transparent);
    background: color-mix(in srgb, var(--green) 8%, transparent);
}

/* Skipped habits are excluded from the fraction's denominator entirely —
   this chip discloses why the count looks lower than the habit list. */
.habit-progress-skipped {
    font-size: 0.68rem;
    font-weight: 600;
    color: var(--text-muted);
    border: 1px dashed var(--border-color);
    border-radius: 20px;
    padding: 1px 8px;
    white-space: nowrap;
}

/* ── Habit row ────────────────────────────────────────────────────────────── */
.habit-item {
    display: flex;
    align-items: center;
    padding: 0.45rem 0.85rem;
    border-radius: 8px;
    gap: 8px;
    transition: background 0.2s;
    border-left: 3px solid transparent;
}

.habit-item:hover {
    background: color-mix(in srgb, var(--green) 8%, transparent);
}

.habit-item.habit-item--done {
    border-left-color: var(--green);
    padding-left: calc(0.85rem - 3px);
    background: color-mix(in srgb, var(--green) 5%, transparent);
}

.habit-item.habit-item--done:hover {
    background: color-mix(in srgb, var(--green) 10%, transparent);
}

/* Skipped — neither done nor missed. Same grammar as habit-item--done (3px
   left border, tinted row, muted name), but colourless and dashed: the day
   is settled without claiming credit. Deliberately NOT --clear-red — that's
   the cancelled-task colour, and reads as a negative outcome; an excused
   day is explicitly neutral. No line-through either, since that reads as
   done-then-struck rather than "nothing owed". */
.habit-item.habit-item--skipped {
    border-left: 3px dashed var(--text-muted);
    padding-left: calc(0.85rem - 3px);
    background: color-mix(in srgb, var(--text-secondary) 4%, transparent);
}

.habit-item.habit-item--skipped:hover {
    background: color-mix(in srgb, var(--text-secondary) 8%, transparent);
}

.habit-item.habit-item--skipped .habit-name {
    color: var(--text-muted);
}

/* Per-habit emoji */
.habit-emoji {
    font-size: 1.1rem;
    line-height: 1;
    flex-shrink: 0;
    user-select: none;
}

/* Habit name */
.habit-name {
    font-size: 0.95rem;
    font-weight: 500;
    color: var(--text-primary);
    flex: 1;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    transition: color 0.2s;
}

.habit-item.habit-item--done .habit-name {
    color: var(--text-muted);
}

/* Stats cluster (streak + month + year) */
.habit-stats {
    display: flex;
    align-items: center;
    gap: 0.3rem;
    flex-shrink: 0;
    opacity: 0;
    transition: opacity 0.15s;
}

.habit-item:hover .habit-stats,
.habit-item:focus-within .habit-stats,
.habit-item.habit-item--done .habit-stats {
    opacity: 1;
}

/* Flexible (times-per-period) habits always show their period progress —
   it's not decoration, it's the thing that keeps the checkbox from reading
   as a lost completion the day after it's checked. */
.habit-item--flexible .habit-stats {
    opacity: 1;
}

/* Skipped joins --done and --flexible as an always-visible exception — the
   Skipped badge inside is the state label itself, not decoration. */
.habit-item--skipped .habit-stats {
    opacity: 1;
}

/* Urgent — period target unmet, close to the end of the period. Same
   left-border + tint pattern as habit-item--done, amber instead of green. */
.habit-item.is-urgent {
    border-left-color: var(--amber);
    padding-left: calc(0.85rem - 3px);
    background: color-mix(in srgb, var(--amber) 5%, transparent);
}

.habit-item.is-urgent:hover {
    background: color-mix(in srgb, var(--amber) 10%, transparent);
}

.habit-stat.habit-stat--urgent {
    color: var(--amber);
    border-color: color-mix(in srgb, var(--amber) 40%, transparent);
    background: var(--amber-glow);
}

.habit-stat.habit-stat--done {
    color: var(--green);
    border-color: color-mix(in srgb, var(--green) 40%, transparent);
    background: color-mix(in srgb, var(--green) 12%, transparent);
}

/* Skipped — colour is never the only signal: the badge text itself reads
   "Skipped", the border is dashed (echoing .habit-item--skipped's left
   border), and the icon differs from done/urgent. --text-secondary here
   (not --text-muted) keeps the label at AA contrast on --bg-dark. */
.habit-stat.habit-stat--skipped {
    display: inline-flex;
    align-items: center;
    gap: 0.2rem;
    color: var(--text-secondary);
    border-color: var(--border-color);
    border-style: dashed;
    background: transparent;
}

.habit-stat.habit-stat--skipped .material-icons {
    font-size: 12px;
    flex-shrink: 0;
}

.habit-streak .habit-streak-skip-icon {
    font-size: 11px;
    margin-left: 3px;
    opacity: 0.65;
    vertical-align: -1px;
    flex-shrink: 0;
}

/* Period-progress dots (targets 2–4 per period) */
.habit-period-dots {
    display: flex;
    gap: 3px;
    align-items: center;
    flex-shrink: 0;
}

.habit-period-dot {
    width: 6px;
    height: 6px;
    border-radius: 50%;
    background: var(--border-color);
    transition: background 0.15s;
}

.habit-period-dot.is-filled {
    background: var(--green);
}

.is-urgent .habit-period-dot.is-filled {
    background: var(--amber);
}

.is-urgent .habit-period-dot {
    background: color-mix(in srgb, var(--amber) 20%, transparent);
}

.habit-streak {
    font-size: 0.7rem;
    font-weight: 600;
    color: var(--amber);
    background: var(--amber-glow);
    border: 1px solid color-mix(in srgb, var(--amber) 30%, transparent);
    border-radius: 20px;
    padding: 1px 8px;
    flex-shrink: 0;
}

.habit-stat {
    font-size: 0.7rem;
    font-weight: 500;
    color: var(--text-muted);
    border: 1px solid var(--border-color);
    border-radius: 20px;
    padding: 1px 8px;
    flex-shrink: 0;
    white-space: nowrap;
}

@media (max-width: 480px) {
    .habit-stat { display: none; }
    /* The Skipped badge is the state label, not decoration — it must
       survive the narrow-screen stat cleanup that hides everything else. */
    .habit-stat.habit-stat--skipped { display: inline-flex; }
}

/* Badge for a habit shown on a past day that has since been archived —
   the row itself renders normally (it genuinely was active that day);
   this only clarifies its current state has changed. */
.habit-archived-badge {
    display: inline-flex;
    align-items: center;
    gap: 0.25rem;
    font-size: 0.7rem;
    font-weight: 500;
    color: var(--amber);
    background: var(--amber-glow);
    border: 1px solid color-mix(in srgb, var(--amber) 30%, transparent);
    border-radius: 20px;
    padding: 1px 8px;
    flex-shrink: 0;
    white-space: nowrap;
}

.habit-archived-badge .material-icons {
    font-size: 12px;
}

/* ── Row inline actions: skip + note ─────────────────────────────────────── */
/* Hidden until row hover, same convention as .task-item .icon-btn in
   tasks.css. Width is reserved even when invisible so revealing them on
   hover doesn't shift the stats cluster. */
.habit-row-inline-actions {
    display: flex;
    align-items: center;
    gap: 2px;
    flex-shrink: 0;
}

/* Opacity lives on the buttons themselves, not the wrapping container —
   a parent's opacity:0 would mask a child's opacity:1, which would break
   the --has-note / --invite "stay visible" states below. */
.habit-skip-btn,
.habit-note-btn {
    opacity: 0;
    transition: opacity 0.15s, color 0.2s, background 0.2s;
}

.habit-item:hover .habit-skip-btn,
.habit-item:hover .habit-note-btn,
.habit-item:focus-within .habit-skip-btn,
.habit-item:focus-within .habit-note-btn {
    opacity: 1;
}

@media (hover: none) {
    .habit-skip-btn,
    .habit-note-btn {
        opacity: 1;
    }
}

.habit-note-container {
    width: 28px;
    flex-shrink: 0;
    display: flex;
    justify-content: center;
    position: relative; /* anchors .inline-note-popover — see its own comment */
}

/* A skip already applied stays visible and reads as "active" — same
   pattern as .checkbox-icon-cancelled staying visible on task rows. */
.habit-skip-btn--active {
    opacity: 1 !important;
    color: var(--text-muted);
}

/* A note exists — quiet but permanent. Solid accent rather than a muted
   mix: on a bare 20px glyph with no background, a muted mix reads at
   nearly the same weight as .habit-skip-btn--active and the two states
   become hard to tell apart at a glance. */
.habit-note-btn--has-note {
    opacity: 1 !important;
    color: var(--accent);
}

/* One-render nudge on the row that was just checked or skipped — cleared
   on the next swap, so it never becomes persistent noise. */
.habit-note-btn--invite {
    opacity: 1 !important;
    color: var(--accent);
    background: var(--accent-glow) !important;
}

/* ── Inline note popover — clones .inline-tag-dropdown's shell (tags.css),
   swapping the tag list for a small textarea.

   Anchored via absolute positioning on .habit-note-container (position:
   relative, above) rather than fixed + JS-computed coordinates: an
   absolutely-positioned element moves with the page on scroll for free,
   so it can't drift out of alignment with its row, and since it's
   anchored in-flow, scrolling to see the row also brings the popover
   into view — no scroll listener needed. .popover-flip-up (set once at
   open time by the inline script, when there isn't room below) renders
   it above the row instead. ── */
.inline-note-popover {
    position: absolute;
    top: calc(100% + 4px);
    right: 0;
    z-index: 200;
    width: 280px;
    max-height: min(320px, calc(100vh - 2rem));
    overflow-y: auto;
    background: var(--bg-card);
    border: 1px solid var(--border-color);
    border-radius: 12px;
    padding: 0.6rem;
    box-shadow: var(--shadow-drop);
    animation: pickerFadeIn 0.12s ease;
}

.inline-note-popover.popover-flip-up {
    top: auto;
    bottom: calc(100% + 4px);
}

.inline-note-header {
    display: flex;
    align-items: center;
    gap: 0.35rem;
    font-size: 0.7rem;
    font-weight: 600;
    color: var(--text-muted);
    padding: 0 0.15rem 0.4rem;
}

.inline-note-header .material-icons {
    font-size: 14px;
    flex-shrink: 0;
}

.inline-note-hint {
    margin-left: auto;
    font-weight: 500;
}

/* Shown only when the day is still unresolved (missed) — names the state
   so a note written here reads as an explanation, not a quiet excuse, and
   offers the one promotion that actually changes the streak/target math. */
.inline-note-state {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    padding: 0 0.15rem 0.45rem;
    border-bottom: 1px solid var(--border-color);
    margin-bottom: 0.45rem;
}

.inline-note-state-label {
    display: inline-flex;
    align-items: center;
    gap: 0.25rem;
    font-size: 0.72rem;
    font-weight: 600;
    color: var(--text-secondary);
}

.inline-note-state-label .material-icons {
    font-size: 13px;
    flex-shrink: 0;
}

.inline-note-promote {
    margin-left: auto;
    color: var(--accent);
    background: var(--accent-glow);
    border: 1px solid color-mix(in srgb, var(--accent) 25%, transparent);
    border-radius: 8px;
    padding: 3px 9px;
    font-size: 0.72rem;
    font-weight: 600;
    cursor: pointer;
    transition: background 0.15s, border-color 0.15s;
}

.inline-note-promote:hover {
    background: color-mix(in srgb, var(--accent) 20%, transparent);
}

.inline-note-textarea {
    width: 100%;
    min-height: 74px;
    resize: vertical;
    background: var(--bg-dark);
    border: 1px solid var(--border-color);
    border-radius: 8px;
    color: var(--text-primary);
    font-family: "DM Sans", sans-serif;
    font-size: 0.85rem;
    line-height: 1.5;
    padding: 0.5rem 0.6rem;
    outline: none;
    transition: border-color 0.15s;
}

.inline-note-textarea:focus {
    border-color: var(--accent);
}

.inline-note-textarea::placeholder {
    color: var(--text-muted);
}

.inline-note-actions {
    display: flex;
    gap: 0.4rem;
    justify-content: flex-end;
    margin-top: 0.45rem;
}

.inline-note-save,
.inline-note-delete {
    font-size: 0.78rem;
    font-weight: 600;
    border-radius: 6px;
    padding: 0.3rem 0.7rem;
    cursor: pointer;
    border: 1px solid transparent;
    transition: background 0.15s, color 0.15s, border-color 0.15s;
}

.inline-note-save {
    background: var(--accent);
    color: #fff;
}

.inline-note-save:hover {
    background: color-mix(in srgb, var(--accent) 85%, black);
}

.inline-note-delete {
    background: transparent;
    color: var(--text-secondary);
    border-color: var(--border-color);
    margin-right: auto;
}

.inline-note-delete:hover {
    color: var(--clear-red);
    border-color: color-mix(in srgb, var(--clear-red) 40%, transparent);
}

/* All-done celebration footer */
.habits-all-done-banner {
    display: flex;
    align-items: center;
    gap: 0.4rem;
    padding: 0.55rem 1rem 0.65rem;
    font-size: 0.8rem;
    font-weight: 600;
    color: var(--green);
    border-top: 1px solid color-mix(in srgb, var(--green) 20%, transparent);
    background: color-mix(in srgb, var(--green) 5%, transparent);
}

.habits-all-done-banner .material-icons {
    font-size: 16px;
    flex-shrink: 0;
}

/* ========== Habits management page ========== */

/* Create card */
.habit-create-card {
    background: var(--bg-card);
    border: 1px solid var(--border-color);
    border-radius: 12px;
    padding: 0.85rem 1rem;
    margin-bottom: 1.5rem;
}

/* Emoji trigger button */
.habit-emoji-field {
    position: relative;
    flex-shrink: 0;
}

.habit-emoji-trigger {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 36px;
    height: 36px;
    background: var(--bg-dark);
    border: 1px solid var(--border-color);
    border-radius: 8px;
    cursor: pointer;
    transition: border-color 0.15s, background 0.15s;
    flex-shrink: 0;
}

.habit-emoji-trigger:hover {
    border-color: var(--accent);
    background: var(--accent-glow);
}

.habit-emoji-trigger .habit-emoji-preview {
    font-size: 1.15rem;
    line-height: 1;
    user-select: none;
}

/* Popup container */
.habit-emoji-picker-popup {
    position: absolute;
    top: calc(100% + 6px);
    left: 0;
    z-index: 200;
    border-radius: 12px;
    overflow: hidden;
    box-shadow: var(--shadow-drop);
}

/* emoji-picker-element theming */
emoji-picker {
    --background: var(--bg-card);
    --border-color: var(--border-color);
    --indicator-color: var(--accent);
    --input-border-color: var(--border-color);
    --input-font-color: var(--text-primary);
    --input-placeholder-color: var(--text-muted);
    --outline-color: rgba(76, 141, 202, 0.3);
    --category-font-color: var(--text-muted);
    --emoji-size: 1.5rem;
    --emoji-padding: 0.35rem;
    --num-columns: 8;
    width: 320px;
    height: 340px;
    border: 1px solid var(--border-color);
    border-radius: 12px;
}

/* Create row: emoji trigger + input + button */
.habit-create-row {
    display: flex;
    gap: 8px;
    align-items: center;
    flex-wrap: nowrap;
}

.habit-name-input {
    flex: 1;
    background: var(--bg-dark);
    border: 1px solid var(--border-color);
    border-radius: 8px;
    padding: 0.4rem 0.75rem;
    font-family: 'DM Sans', sans-serif;
    font-size: 0.9rem;
    color: var(--text-primary);
    outline: none;
    transition: border-color 0.2s;
    min-width: 0;
}

.habit-name-input::placeholder { color: var(--text-muted); }
.habit-name-input:focus { border-color: var(--accent); }

.habit-add-btn {
    display: inline-flex;
    align-items: center;
    gap: 4px;
    background: var(--accent);
    color: #fff;
    border: none;
    border-radius: 8px;
    padding: 0.4rem 0.85rem;
    font-family: 'DM Sans', sans-serif;
    font-size: 0.85rem;
    font-weight: 600;
    cursor: pointer;
    flex-shrink: 0;
    transition: opacity 0.15s;
}

.habit-add-btn:hover { opacity: 0.88; }
.habit-add-btn .material-icons { font-size: 18px; }

/* ── Extra fields (frequency + start date) ── */
.habit-create-extras {
    display: flex;
    gap: 1rem;
    align-items: flex-start;
    margin-top: 0.75rem;
    padding-top: 0.75rem;
    border-top: 1px solid var(--border-color);
}

.habit-form-label {
    display: block;
    font-size: 0.72rem;
    font-weight: 600;
    color: var(--text-muted);
    text-transform: uppercase;
    letter-spacing: 0.05em;
    margin-bottom: 0.4rem;
}

/* Frequency field */
.habit-frequency-field {
    flex: 1;
    min-width: 0;
}

.habit-freq-presets {
    display: flex;
    gap: 0.3rem;
    flex-wrap: wrap;
    margin-bottom: 0.5rem;
}

.freq-preset {
    font-size: 0.72rem;
    font-weight: 600;
    padding: 0.2rem 0.6rem;
    border-radius: 20px;
    border: 1px solid var(--border-color);
    background: transparent;
    color: var(--text-muted);
    cursor: pointer;
    font-family: 'DM Sans', sans-serif;
    transition: border-color 0.15s, color 0.15s, background 0.15s;
}

.freq-preset:hover {
    border-color: var(--accent);
    color: var(--accent);
    background: var(--accent-glow);
}

.freq-preset.is-active {
    border-color: var(--accent);
    color: var(--accent);
    background: var(--accent-glow);
}

/* Frequency mode switch (Set days / Flexible) — a joined segmented control,
   deliberately NOT styled like .freq-preset below it: identical pill
   treatment on both rows would read as four pills on one axis instead of a
   mode switch with a body underneath. */
.habit-freq-modes {
    display: inline-flex;
    border: 1px solid var(--border-color);
    border-radius: 20px;
    overflow: hidden;
    margin-bottom: 0.6rem;
}

.freq-mode {
    font-size: 0.72rem;
    font-weight: 600;
    padding: 0.25rem 0.75rem;
    border: none;
    background: transparent;
    color: var(--text-muted);
    cursor: pointer;
    font-family: 'DM Sans', sans-serif;
    transition: color 0.15s, background 0.15s;
}

.freq-mode + .freq-mode {
    border-left: 1px solid var(--border-color);
}

.freq-mode:hover {
    color: var(--accent);
}

.freq-mode.is-active {
    color: #fff;
    background: var(--accent);
}

/* Equal min-height on both mode bodies so switching modes doesn't jump the
   create card's layout. */
.habit-freq-body {
    min-height: 68px;
}

.habit-freq-count-row {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    flex-wrap: wrap;
}

.habit-count-stepper {
    display: flex;
    align-items: center;
    gap: 0.35rem;
}

.habit-count-btn.icon-btn {
    width: 28px;
    height: 28px;
}

.habit-count-value {
    min-width: 1.4rem;
    text-align: center;
    font-size: 0.9rem;
    font-weight: 600;
    color: var(--text-primary);
}

.habit-count-unit {
    font-size: 0.8rem;
    color: var(--text-secondary);
}

.habit-freq-hint {
    font-size: 0.72rem;
    color: var(--text-muted);
    margin-top: 0.5rem;
}

.habit-day-picker {
    display: flex;
    gap: 0.25rem;
}

.day-btn {
    width: 28px;
    height: 28px;
    border-radius: 50%;
    border: 1px solid var(--border-color);
    background: transparent;
    color: var(--text-muted);
    font-family: 'DM Sans', sans-serif;
    font-size: 0.68rem;
    font-weight: 700;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: border-color 0.15s, background 0.15s, color 0.15s;
    flex-shrink: 0;
    padding: 0;
}

.day-btn:hover {
    border-color: var(--accent);
    color: var(--accent);
}

.day-btn.is-selected {
    border-color: var(--accent);
    background: var(--accent);
    color: #fff;
}

/* Start date field */
.habit-startdate-field {
    width: 140px;
    flex-shrink: 0;
}

.habit-date-trigger {
    display: inline-flex;
    align-items: center;
    gap: 5px;
    background: var(--bg-dark);
    border: 1px solid var(--border-color);
    border-radius: 8px;
    padding: 0.3rem 0.6rem;
    cursor: pointer;
    transition: border-color 0.15s, background 0.15s;
    width: 100%;
}

.habit-date-trigger:hover {
    border-color: var(--accent);
    background: var(--accent-glow);
}

.habit-date-icon {
    font-size: 14px;
    color: var(--text-muted);
    flex-shrink: 0;
}

.habit-startdate-label {
    font-size: 0.8rem;
    color: var(--text-secondary);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

/* ── Frequency badge (view mode, management list) ── */
.habit-row-info {
    flex: 1;
    min-width: 0;
    display: flex;
    flex-direction: column;
    gap: 1px;
}

.habit-row-meta {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    flex-wrap: wrap;
}

.habit-frequency-badge {
    font-size: 0.68rem;
    font-weight: 500;
    color: var(--text-muted);
    line-height: 1;
}

.habit-start-date,
.habit-archived-range {
    font-size: 0.68rem;
    color: var(--text-muted);
    line-height: 1;
    display: flex;
    align-items: center;
    gap: 0.2rem;
}

/* ── Edit mode row ── */
.habit-list-item--editing {
    padding: 0;
    background: color-mix(in srgb, var(--accent) 4%, transparent);
    border: 1px solid color-mix(in srgb, var(--accent) 20%, transparent);
    border-radius: 8px;
}

/* Habit list */
.habit-list {
    display: flex;
    flex-direction: column;
    gap: 2px;
    border-radius: 8px;
    transition: background-color 0.15s, box-shadow 0.15s;
}

.habit-list.drag-over {
    background-color: var(--accent-glow);
    box-shadow: inset 0 0 0 2px var(--accent);
}

.habit-list-item-wrap[draggable] {
    cursor: grab;
    -webkit-user-drag: element;
}

.habit-list-item-wrap[draggable].dragging {
    opacity: 0.4;
    background: var(--accent-glow);
    border-radius: 8px;
    cursor: grabbing;
}

.habit-drag-handle {
    font-size: 18px;
    color: var(--text-muted);
    flex-shrink: 0;
    opacity: 0.35;
    user-select: none;
    -webkit-user-select: none;
    -webkit-user-drag: element;
    cursor: grab;
    transition: opacity 0.15s;
}

.habit-list-item:hover .habit-drag-handle {
    opacity: 0.8;
}

/* Individual row */
.habit-list-item {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 0.5rem 0.75rem;
    border-radius: 8px;
    transition: background 0.2s;
}

.habit-list-item:hover { background: var(--accent-glow); }

.habit-row-icon {
    font-size: 1.1rem;
    flex-shrink: 0;
}

.habit-row-name {
    font-size: 0.95rem;
    font-weight: 500;
    color: var(--text-primary);
}

.habit-row-actions {
    display: flex;
    gap: 2px;
    opacity: 0;
    transition: opacity 0.15s;
}

.habit-list-item:hover .habit-row-actions { opacity: 1; }

/* Edit form inline */
.habit-edit-form {
    display: flex;
    flex-direction: column;
    gap: 0.5rem;
    padding: 0.5rem 0.75rem;
    background: color-mix(in srgb, var(--accent) 6%, transparent);
    border-radius: 8px;
    border: 1px solid color-mix(in srgb, var(--accent) 20%, transparent);
}

.habit-edit-form .habit-create-row {
    margin-top: 0;
}

.habit-save-btn:hover {
    color: var(--green) !important;
    background: var(--green-glow) !important;
}

/* Archived section */
.habit-archived-section {
    margin-top: 1.5rem;
    border-top: 1px solid var(--border-color);
    padding-top: 0.75rem;
}

.habit-archived-toggle {
    display: flex;
    align-items: center;
    gap: 6px;
    background: transparent;
    border: none;
    color: var(--text-muted);
    font-family: 'DM Sans', sans-serif;
    font-size: 0.8rem;
    font-weight: 600;
    cursor: pointer;
    padding: 0.25rem 0.5rem;
    border-radius: 6px;
    transition: color 0.15s;
    margin-bottom: 0.25rem;
}

.habit-archived-toggle:hover { color: var(--text-secondary); }

.habit-archived-toggle-icon {
    font-size: 16px;
    transition: transform 0.2s;
}

.habit-archived-section.is-open .habit-archived-toggle-icon {
    transform: rotate(180deg);
}

.habit-archived-list {
    display: none;
}

.habit-archived-section.is-open .habit-archived-list {
    display: flex;
    flex-direction: column;
    gap: 2px;
}

.habit-list-item-wrap--archived .habit-row-name {
    color: var(--text-muted);
}

/* Deleting animation (matches tag pattern) */
.is-deleting {
    opacity: 0;
    transform: translateX(8px);
    transition: opacity 0.3s ease, transform 0.3s ease;
}

/* ── Goal badge on habit item (Today + Habits views) ── */
.habit-name-block {
    flex: 1;
    min-width: 0;
    display: flex;
    flex-direction: column;
    gap: 2px;
}

/* Override: habit-name no longer needs flex:1 when inside habit-name-block */
.habit-name-block .habit-name {
    flex: none;
}

.habit-goal-badge {
    font-size: 0.7rem;
    font-weight: 500;
    color: var(--text-muted);
    display: inline-flex;
    align-items: center;
    gap: 3px;
    line-height: 1;
    transition: color 0.2s;
    text-decoration: none;
}

.habit-goal-badge .material-icons { font-size: 11px; }
.habit-goal-badge:hover { color: var(--text-secondary); }

/* Area-tinted variants */
.habit-goal-badge--blue   { color: color-mix(in srgb, var(--accent) 70%, var(--text-muted)); }
.habit-goal-badge--green  { color: color-mix(in srgb, var(--green) 70%, var(--text-muted)); }
.habit-goal-badge--amber  { color: color-mix(in srgb, var(--amber) 70%, var(--text-muted)); }
.habit-goal-badge--red    { color: color-mix(in srgb, var(--clear-red) 70%, var(--text-muted)); }
.habit-goal-badge--purple { color: color-mix(in srgb, #9b8ecf 70%, var(--text-muted)); }
.habit-goal-badge--teal   { color: color-mix(in srgb, #4db6ac 70%, var(--text-muted)); }
.habit-goal-badge--accent { color: color-mix(in srgb, var(--accent) 70%, var(--text-muted)); }

/* ── Contributing Habits section (goal detail page) ── */
.goal-panel-section {
    border-bottom: 1px solid var(--border-color);
    background: var(--bg-card);
    border: 1px solid var(--border-color);
    border-radius: 12px;
    overflow: hidden;
}

.goal-panel-section:last-child { border-bottom: none; }

/* Section header (<summary>) */
.goal-contributing-section-label {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    padding: 0.7rem 1.25rem;
    font-size: 0.78rem;
    font-weight: 600;
    color: var(--text-secondary);
    text-transform: uppercase;
    letter-spacing: 0.05em;
    cursor: pointer;
    user-select: none;
    background: var(--bg-dark);
    border-bottom: 1px solid var(--border-color);
    list-style: none;
}

.goal-contributing-section-label::-webkit-details-marker { display: none; }

.goal-contributing-section-label .material-icons:first-child {
    font-size: 16px;
    color: var(--green);
}

.goal-contributing-section-label .section-toggle {
    font-size: 16px;
    color: var(--text-muted);
    margin-left: auto;
    transition: transform 0.2s;
}

details:not([open]) .section-toggle { transform: rotate(-90deg); }

.goal-contributing-period-note {
    font-size: 0.72rem;
    font-weight: 400;
    color: var(--text-muted);
    text-transform: none;
    letter-spacing: 0;
}

.goal-contributing-count {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    min-width: 18px;
    height: 18px;
    padding: 0 5px;
    border-radius: 9px;
    background: var(--border-color);
    color: var(--text-muted);
    font-size: 0.65rem;
    font-weight: 700;
    text-transform: none;
    letter-spacing: 0;
}

/* Habit row inside goal detail (active goal) */
.goal-habit-row {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    padding: 0.6rem 1.25rem;
    border-bottom: 1px solid var(--border-color);
    transition: background 0.15s;
}

.goal-habit-row:last-child { border-bottom: none; }

.goal-habit-row:hover {
    background: color-mix(in srgb, var(--green) 6%, transparent);
}

.goal-habit-icon {
    font-size: 18px;
    color: var(--text-muted);
    flex-shrink: 0;
}

.goal-habit-info { flex: 1; min-width: 0; }

.goal-habit-name {
    font-size: 0.875rem;
    font-weight: 500;
    color: var(--text-primary);
}

.goal-habit-sub {
    font-size: 0.72rem;
    color: var(--text-muted);
    margin-top: 1px;
    display: flex;
    align-items: center;
    gap: 0.35rem;
}

.goal-habit-sub .material-icons { font-size: 11px; }

/* Days excused from this habit's contribution to the goal — shrinks the
   denominator (expected_completions), so this discloses why rather than
   letting the target look arbitrarily lower than the frequency implies. */
.goal-habit-skips {
    display: inline-flex;
    align-items: center;
    gap: 0.2rem;
}

.goal-habit-stat-block {
    text-align: right;
    flex-shrink: 0;
    display: flex;
    flex-direction: column;
    align-items: flex-end;
    gap: 4px;
}

.goal-habit-completion-stat {
    font-size: 0.82rem;
    font-weight: 600;
    color: var(--text-primary);
    white-space: nowrap;
}

.goal-habit-completion-stat .stat-denom {
    font-weight: 400;
    color: var(--text-secondary);
}

.goal-habit-mini-bar {
    width: 72px;
    height: 3px;
    background: var(--border-color);
    border-radius: 2px;
    overflow: hidden;
}

.goal-habit-mini-bar-fill {
    height: 100%;
    border-radius: 2px;
}

.goal-habit-mini-bar-fill--strong { background: var(--green); }
.goal-habit-mini-bar-fill--mid    { background: var(--amber); }

.goal-habit-unlink {
    opacity: 0;
    transition: opacity 0.15s;
    flex-shrink: 0;
}

.goal-habit-row:hover .goal-habit-unlink { opacity: 1; }

/* Add habit button row */
.goal-habit-add-row {
    padding: 0.6rem 1.25rem;
    display: flex;
    align-items: center;
    gap: 0.5rem;
    background: var(--bg-card);
}

.goal-habit-add-btn {
    display: inline-flex;
    align-items: center;
    gap: 4px;
    font-size: 0.8rem;
    font-weight: 500;
    color: var(--text-muted);
    background: transparent;
    border: 1px dashed var(--border-color);
    border-radius: 8px;
    padding: 0.3rem 0.75rem;
    cursor: pointer;
    font-family: 'DM Sans', sans-serif;
    transition: all 0.15s;
}

.goal-habit-add-btn .material-icons { font-size: 16px; }

.goal-habit-add-btn:hover {
    border-color: var(--green);
    color: var(--green);
    background: color-mix(in srgb, var(--green) 8%, transparent);
}

/* Habit picker inside goal detail */
.goal-habit-picker-list {
    padding: 0.5rem 1.25rem;
    display: flex;
    flex-direction: column;
    gap: 2px;
    background: var(--bg-card);
    border-top: 1px solid var(--border-color);
}

.goal-habit-picker-item {
    display: flex;
    align-items: center;
    gap: 0.6rem;
    padding: 0.4rem 0.5rem;
    border-radius: 6px;
    cursor: pointer;
    transition: background 0.15s;
    font-size: 0.875rem;
    color: var(--text-secondary);
    border: none;
    background: transparent;
    font-family: 'DM Sans', sans-serif;
    width: 100%;
    text-align: left;
}

.goal-habit-picker-item:hover {
    background: var(--accent-glow);
    color: var(--text-primary);
}

.goal-habit-picker-item.is-linked { color: var(--green); }

.goal-habit-picker-item.is-linked:hover {
    background: color-mix(in srgb, var(--green) 8%, transparent);
}

.goal-habit-picker-item .material-icons { font-size: 16px; flex-shrink: 0; }

/* Retrospective rows (completed goals) */
.goal-habit-retro {
    padding: 0.75rem 1.25rem;
    border-bottom: 1px solid var(--border-color);
    display: flex;
    align-items: center;
    gap: 1rem;
    transition: background 0.15s;
}

.goal-habit-retro:hover {
    background: color-mix(in srgb, var(--green) 4%, transparent);
}

.goal-habit-retro:last-child { border-bottom: none; }

.retro-habit-icon { font-size: 20px; color: var(--text-muted); flex-shrink: 0; }
.retro-habit-info { flex: 1; min-width: 0; }
.retro-habit-name { font-size: 0.875rem; font-weight: 500; color: var(--text-secondary); }
.retro-habit-sub  { font-size: 0.72rem; color: var(--text-muted); margin-top: 1px; }

.retro-stat { text-align: right; flex-shrink: 0; }

.retro-stat-headline {
    font-size: 0.88rem;
    font-weight: 700;
    color: var(--text-primary);
    white-space: nowrap;
}

.retro-stat-sub { font-size: 0.68rem; color: var(--text-muted); margin-top: 1px; }

.retro-mini-bar {
    width: 80px;
    height: 3px;
    background: var(--border-color);
    border-radius: 2px;
    overflow: hidden;
    margin-top: 4px;
    margin-left: auto;
}

.retro-mini-bar-fill { height: 100%; border-radius: 2px; }
.retro-mini-bar-fill--strong { background: var(--green); }
.retro-mini-bar-fill--mid    { background: var(--amber); }
