/* Undo toast positioning */
.undo-toast {
    position: fixed;
    bottom: 1.5rem;
    right: 1.5rem;
    z-index: 9999;
}

@media (min-width: 768px) {
    .undo-toast {
        bottom: auto;
        right: auto;
        top: 0.75rem;
        left: 50%;
        transform: translateX(-50%);
        white-space: nowrap;
    }
}

/* Tag group headers */
.tag-group-header {
    display: flex;
    align-items: center;
    gap: 0.35rem;
    padding-top: 0.6rem;
    padding-bottom: 0.15rem;
    padding-right: 1rem;
    font-size: 0.7rem;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.05em;
    cursor: pointer;
    user-select: none;
}

.tag-group-header[data-open="false"] {
    color: var(--bs-secondary-color);
    padding-bottom: 0.6rem;
}

.tag-toggle {
    display: inline-block;
    font-size: 0.75rem;
    transition: transform 0.15s ease;
    flex-shrink: 0;
}

.tag-group-header[data-open="false"] .tag-toggle {
    color: var(--bs-secondary-color);
    transform: rotate(-90deg);
}

.tag-count-badge {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    background: var(--bs-secondary-bg);
    color: var(--bs-secondary-color);
    border-radius: 9999px;
    padding: 0 0.35rem;
    font-size: 0.65rem;
    font-weight: 700;
    min-width: 1.1em;
    margin-left: 0.15rem;
}

/* Tag input widget */
.todo-tag-input {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: 0.35rem;
    border: 1px solid var(--bs-border-color);
    border-radius: var(--bs-border-radius);
    padding: 0.2rem 0.65rem;
    background: var(--bs-body-bg);
    cursor: text;
    min-height: 2.5rem;
}

.todo-tag-input:focus-within {
    outline: none;
    box-shadow: 0 0 0 0.25rem rgba(var(--bs-primary-rgb), 0.25);
    border-color: var(--bs-primary);
}

.todo-tag-input--editing {
    border-color: var(--bs-warning);
}

.todo-tag-input--editing:focus-within {
    box-shadow: 0 0 0 0.25rem rgba(var(--bs-warning-rgb), 0.25);
    border-color: var(--bs-warning);
}

/* Editable text segments — inline spans between pills */
.todo-text-seg {
    outline: none;
    line-height: 1.5;
    min-width: 2px;
}

.todo-text-seg.todo-input-empty::before {
    content: attr(data-placeholder);
    color: var(--bs-secondary-color);
    pointer-events: none;
}

.todo-tag-input .todo-tag-pill,
.todo-tag-input .todo-date-pill,
.todo-tag-input .todo-rec-pill,
.todo-tag-input .todo-note-pill {
    margin-left: 0.3em;
    margin-right: 0.3em;
}

/* Pills sit inline between text segments */
.todo-tag-input .todo-tag-pill,
.todo-tag-input .todo-date-pill,
.todo-tag-input .todo-rec-pill,
.todo-tag-input .todo-note-pill {
    user-select: none;
    vertical-align: middle;
}

.todo-tag-pill {
    display: inline-flex;
    align-items: center;
    gap: 0.2rem;
    background: var(--bs-info-bg-subtle);
    color: var(--bs-info-text-emphasis);
    border-radius: 9999px;
    padding: 0.1rem 0.5rem;
    font-size: 0.75rem;
    font-weight: 500;
    white-space: nowrap;
}

.todo-tag-remove {
    background: none;
    border: none;
    cursor: pointer;
    padding: 0;
    font-size: 0.85rem;
    line-height: 1;
    color: var(--bs-info-text-emphasis);
    opacity: 0.6;
}
.todo-tag-remove:hover {
    opacity: 1;
}

.todo-quick-pick-chip {
    background: var(--bs-secondary-bg);
    color: var(--bs-secondary-color);
    border: 1px solid var(--bs-border-color);
    border-radius: 9999px;
    padding: 0.15rem 0.6rem;
    font-size: 0.7rem;
    cursor: pointer;
}
.todo-quick-pick-chip:hover {
    background: var(--bs-info-bg-subtle);
    color: var(--bs-info-text-emphasis);
    border-color: var(--bs-info-border-subtle);
}

.todo-tag-autocomplete {
    position: absolute;
    top: calc(100% + 2px);
    left: 0;
    right: 0;
    background: var(--bs-body-bg);
    border: 1px solid var(--bs-border-color);
    border-radius: var(--bs-border-radius);
    box-shadow: var(--bs-box-shadow);
    z-index: 200;
    max-height: 12rem;
    overflow-y: auto;
}

.todo-ac-item {
    padding: 0.35rem 0.75rem;
    font-size: 0.8rem;
    cursor: pointer;
    color: var(--bs-body-color);
}

.todo-ac-item:hover,
.todo-ac-item.todo-ac-selected {
    background: var(--bs-info-bg-subtle);
    color: var(--bs-info-text-emphasis);
}

/* Edit button visibility */
.todo-edit-btn {
    opacity: 0;
    transition: opacity 0.15s;
}
.todo-item:hover .todo-edit-btn {
    opacity: 1;
}

/* Due date chip — low contrast by default, accent when due */
.todo-due {
    font-size: 0.7rem;
    color: var(--bs-secondary-color);
    white-space: nowrap;
}
.todo-due--today {
    color: var(--bs-primary);
    font-weight: 600;
}
.todo-due--overdue {
    color: var(--bs-danger);
    font-weight: 600;
}
.todo-due--future {
    color: var(--bs-secondary-color);
}

/* Scheduled-list day headers */
.scheduled-day-header {
    padding: 0.6rem 0 0.25rem;
    font-size: 0.85rem;
    color: var(--bs-secondary-color);
    border-bottom: 1px solid var(--bs-border-color);
    margin-bottom: 0.35rem;
}

/* Date picker / postpone palette popover */
.todo-popover {
    position: absolute;
    z-index: 300;
    background: var(--bs-body-bg);
    border: 1px solid var(--bs-border-color);
    border-radius: var(--bs-border-radius);
    box-shadow: var(--bs-box-shadow);
    padding: 0.6rem;
    min-width: 20rem;
    max-width: 24rem;
}
.todo-popover input[type="text"] {
    width: 100%;
    padding: 0.3rem 0.5rem;
    border: 1px solid var(--bs-border-color);
    border-radius: var(--bs-border-radius-sm);
    font-size: 0.85rem;
    margin-bottom: 0.35rem;
}
.todo-popover-preview {
    font-size: 0.75rem;
    color: var(--bs-primary);
    min-height: 1.2em;
    margin-bottom: 0.35rem;
}
.todo-popover-preview--invalid {
    color: var(--bs-danger);
}
.todo-popover-actions {
    display: flex;
    flex-wrap: wrap;
    gap: 0.25rem;
    margin-top: 0.3rem;
}
.todo-popover-actions button {
    flex: 0 0 auto;
    padding: 0.15rem 0.55rem;
    font-size: 0.75rem;
    background: var(--bs-secondary-bg);
    border: 1px solid var(--bs-border-color);
    border-radius: 9999px;
    cursor: pointer;
    color: var(--bs-body-color);
}
.todo-popover-actions button:hover {
    background: var(--bs-info-bg-subtle);
    color: var(--bs-info-text-emphasis);
    border-color: var(--bs-info-border-subtle);
}

/* Mini calendar grid in the date picker */
.todo-mini-cal {
    display: grid;
    grid-template-columns: repeat(7, 1fr);
    gap: 1px;
    margin-top: 0.4rem;
    font-size: 0.75rem;
}
.todo-mini-cal-cell {
    text-align: center;
    padding: 0.25rem 0;
    background: var(--bs-body-bg);
    cursor: pointer;
    border-radius: var(--bs-border-radius-sm);
    color: var(--bs-body-color);
}
.todo-mini-cal-cell.muted {
    color: var(--bs-secondary-color);
    opacity: 0.45;
}
.todo-mini-cal-cell.today {
    background: var(--bs-primary-bg-subtle);
    color: var(--bs-primary);
    font-weight: 600;
}
.todo-mini-cal-cell.selected {
    background: var(--bs-primary);
    color: white;
}
.todo-mini-cal-cell:hover {
    background: var(--bs-info-bg-subtle);
}
.todo-mini-cal-header {
    font-weight: 600;
    color: var(--bs-secondary-color);
    cursor: default;
}
.todo-mini-cal-header:hover {
    background: transparent;
}

/* Linked-protocol badge on todo rows */
.todo-protocol-link {
    color: var(--bs-info);
    text-decoration: none;
    font-size: 1rem;
}
.todo-protocol-link:hover {
    color: var(--bs-info-text-emphasis);
}

/* Protocol run page */
.protocol-run-item {
    transition: background 0.15s ease;
}
.protocol-run-item.status-done,
.protocol-run-item.status-sent_to_todo {
    opacity: 0.55;
}
.protocol-run-item.is-current {
    outline: 2px solid var(--bs-primary);
    outline-offset: 1px;
}
.protocol-run-item-marker {
    width: 1.4em;
    text-align: center;
    color: var(--bs-secondary-color);
}
.protocol-run-item.status-done .protocol-run-item-marker {
    color: var(--bs-success);
}
.protocol-run-item.status-sent_to_todo .protocol-run-item-marker {
    color: var(--bs-primary);
}

/* Reuse swipe visuals for protocol run items, but with different action labels */
.protocol-run-item {
    position: relative;
    touch-action: pan-y;
    overflow: hidden;
}
.protocol-run-item[data-swipe-dir="right"]::before {
    content: "✓";
    position: absolute;
    inset: 0;
    background: var(--bs-success);
    color: white;
    display: flex;
    align-items: center;
    justify-content: flex-start;
    padding-left: 1.25rem;
    font-size: 1.25rem;
    z-index: 0;
}
.protocol-run-item[data-swipe-dir="left"]::after {
    content: "→ todo";
    position: absolute;
    inset: 0;
    background: var(--bs-primary);
    color: white;
    display: flex;
    align-items: center;
    justify-content: flex-end;
    padding-right: 1.25rem;
    font-size: 0.95rem;
    z-index: 0;
}
.protocol-run-item .card-body {
    position: relative;
    z-index: 1;
    background: var(--bs-body-bg);
}

/* Sublime-style protocol palette overlay */
.protocol-palette {
    position: fixed;
    top: 4rem;
    left: 50%;
    transform: translateX(-50%);
    width: 28rem;
    max-width: calc(100vw - 2rem);
    background: var(--bs-body-bg);
    border: 1px solid var(--bs-border-color);
    border-radius: var(--bs-border-radius);
    box-shadow: 0 12px 36px rgba(0, 0, 0, 0.25);
    z-index: 400;
    padding: 0.5rem;
}
.protocol-palette-input {
    width: 100%;
    padding: 0.4rem 0.6rem;
    border: 1px solid var(--bs-border-color);
    border-radius: var(--bs-border-radius-sm);
    font-size: 0.9rem;
}
.protocol-palette-list {
    list-style: none;
    padding: 0;
    margin: 0.4rem 0 0;
    max-height: 22rem;
    overflow-y: auto;
}
.protocol-palette-item {
    padding: 0.4rem 0.6rem;
    font-size: 0.85rem;
    cursor: pointer;
    border-radius: var(--bs-border-radius-sm);
}
.protocol-palette-item.is-selected,
.protocol-palette-item:hover {
    background: var(--bs-info-bg-subtle);
    color: var(--bs-info-text-emphasis);
}
.protocol-palette-empty {
    padding: 0.4rem 0.6rem;
    color: var(--bs-secondary-color);
    font-size: 0.85rem;
    font-style: italic;
}

/* Recurrence badge on rows */
.todo-recurrence {
    color: var(--bs-secondary-color);
    font-size: 0.85rem;
    cursor: help;
    user-select: none;
    white-space: nowrap;
}
.todo-recurrence-label {
    font-size: 0.7rem;
    color: var(--bs-secondary-color);
    margin-right: 0.15rem;
}
.todo-recurrence:hover {
    color: var(--bs-primary);
}
.todo-recurrence:hover .todo-recurrence-label {
    color: var(--bs-primary);
}

/* Repetition pill in composite input */
.todo-rec-pill {
    display: inline-flex;
    align-items: center;
    gap: 0.2rem;
    background: var(--bs-warning-bg-subtle);
    color: var(--bs-warning-text-emphasis);
    border-radius: 9999px;
    padding: 0.1rem 0.5rem;
    font-size: 0.75rem;
    font-weight: 500;
    white-space: nowrap;
}
.todo-rec-remove {
    background: none;
    border: none;
    cursor: pointer;
    padding: 0;
    font-size: 0.85rem;
    line-height: 1;
    color: var(--bs-warning-text-emphasis);
    opacity: 0.6;
}
.todo-rec-remove:hover {
    opacity: 1;
}

/* Repetition history side panel */
.todo-history-panel {
    position: fixed;
    top: 4rem;
    right: 1rem;
    width: 22rem;
    max-width: calc(100vw - 2rem);
    background: var(--bs-body-bg);
    border: 1px solid var(--bs-border-color);
    border-radius: var(--bs-border-radius);
    box-shadow: var(--bs-box-shadow);
    padding: 0.75rem 1rem;
    z-index: 350;
    max-height: calc(100vh - 6rem);
    overflow: auto;
}
.todo-history-header {
    display: flex;
    align-items: center;
    border-bottom: 1px solid var(--bs-border-color);
    padding-bottom: 0.4rem;
    margin-bottom: 0.5rem;
    font-size: 0.85rem;
}
.todo-history-close {
    margin-left: auto;
    background: none;
    border: none;
    font-size: 1.1rem;
    line-height: 1;
    color: var(--bs-secondary-color);
    cursor: pointer;
}
.todo-history-list {
    list-style: none;
    padding: 0;
    margin: 0;
    border-left: 2px solid var(--bs-border-color);
    padding-left: 0.75rem;
}
.todo-history-entry {
    position: relative;
    padding: 0.35rem 0;
    font-size: 0.8rem;
    color: var(--bs-body-color);
}
.todo-history-entry.is-current {
    font-weight: 600;
    color: var(--bs-primary);
}
.todo-history-marker {
    position: absolute;
    left: -1rem;
    top: 0.4rem;
    color: var(--bs-border-color);
    font-size: 0.65rem;
}
.todo-history-entry.is-current .todo-history-marker {
    color: var(--bs-primary);
}
.todo-history-date,
.todo-history-done,
.todo-history-status {
    display: block;
    font-size: 0.7rem;
    color: var(--bs-secondary-color);
    margin-top: 0.1rem;
}

/* Date pill in composite input */
.todo-date-pill {
    display: inline-flex;
    align-items: center;
    gap: 0.2rem;
    background: var(--bs-primary-bg-subtle);
    color: var(--bs-primary);
    border-radius: 9999px;
    padding: 0.1rem 0.5rem;
    font-size: 0.75rem;
    font-weight: 500;
    white-space: nowrap;
}
.todo-date-remove {
    background: none;
    border: none;
    cursor: pointer;
    padding: 0;
    font-size: 0.85rem;
    line-height: 1;
    color: var(--bs-primary);
    opacity: 0.6;
}
.todo-date-remove:hover {
    opacity: 1;
}

.todo-note-pill {
    display: inline-flex;
    align-items: center;
    gap: 0.2rem;
    background: var(--bs-success-bg-subtle);
    color: var(--bs-success-text-emphasis);
    border-radius: 9999px;
    padding: 0.1rem 0.5rem;
    font-size: 0.75rem;
    font-weight: 500;
    white-space: nowrap;
    cursor: pointer;
}
.todo-note-remove {
    background: none;
    border: none;
    cursor: pointer;
    padding: 0;
    font-size: 0.85rem;
    line-height: 1;
    color: var(--bs-success-text-emphasis);
    opacity: 0.6;
}
.todo-note-remove:hover {
    opacity: 1;
}

/* Smooth list refresh */
#todo-list {
    transition: opacity 0.12s ease-out;
}
#todo-list.htmx-swapping {
    opacity: 0;
}

/* Todo swipe gestures */
.todo-item {
    position: relative;
    touch-action: pan-y;
    overflow: hidden;
}

.todo-item:hover .todo-content {
    background: var(--bs-warning-bg-subtle);
}

.todo-content {
    position: relative;
    z-index: 1;
    gap: 0.5rem;
}

.todo-item[data-swipe-dir="right"]::before {
    content: "✓";
    position: absolute;
    inset: 0;
    background: var(--bs-success);
    color: white;
    display: flex;
    align-items: center;
    justify-content: flex-start;
    padding-left: 1.25rem;
    font-size: 1.25rem;
    z-index: 0;
}

.todo-item[data-swipe-dir="left"]::after {
    content: "⏸";
    position: absolute;
    inset: 0;
    background: var(--bs-secondary);
    color: white;
    display: flex;
    align-items: center;
    justify-content: flex-end;
    padding-right: 1.25rem;
    font-size: 1.25rem;
    z-index: 0;
}

/* ── Assignee pills (input) ──────────────────────────────────────────── */
.todo-assignee-pill {
    display: inline-flex;
    align-items: center;
    gap: 0.2em;
    background: #0d9488;
    color: #fff;
    border-radius: 999px;
    padding: 0 0.55em;
    font-size: 0.78em;
    font-weight: 500;
    line-height: 1.6;
    white-space: nowrap;
    cursor: default;
    user-select: none;
}

.todo-assignee-remove {
    background: none;
    border: none;
    color: rgba(255,255,255,0.8);
    padding: 0;
    font-size: 0.9em;
    line-height: 1;
    cursor: pointer;
    display: inline-flex;
    align-items: center;
}

.todo-assignee-remove:hover {
    color: #fff;
}

/* Assignee display on todo list rows */
.todo-assignees {
    font-size: 0.72rem;
    color: #0d9488;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    max-width: 8em;
}

/* Small badge used in protocol item lists */
.todo-assignee-pill-sm {
    background-color: #0d9488;
    color: #fff;
    font-size: 0.68rem;
}
