/* Task list and task form. Also loaded by home and calendar, which both
   render a task list via tasks.js. */

/* ===== Task List ===== */
.task-list {
    display: flex;
    flex-direction: column;
    gap: 0.5rem;
}

.task-summary {
    display: flex;
    flex-wrap: wrap;
    gap: 0.55rem 1.25rem;
    margin-top: 1rem;
    color: var(--text-secondary);
    font-size: 0.85rem;
}

.task-summary strong {
    color: var(--text-primary);
    font-size: 1rem;
    font-variant-numeric: tabular-nums;
}

.task-summary span:nth-child(2) strong,
.task-item.is-overdue .task-due-date {
    color: var(--warning);
}

.task-filters {
    display: flex;
    flex-wrap: wrap;
    gap: 0.5rem;
    margin: 0 0 1.25rem;
}

.task-filter {
    min-height: 44px;
    padding: 0.45rem 1rem;
    border: 1px solid var(--border);
    border-radius: 999px;
    color: var(--text-secondary);
    font-size: 0.85rem;
    font-weight: 600;
    transition: color var(--transition), background-color var(--transition),
        border-color var(--transition);
}

.task-filter:hover {
    border-color: var(--border-strong);
    color: var(--text-primary);
}

.task-filter.is-active {
    border-color: var(--accent);
    background: var(--accent-glow);
    color: var(--accent-light);
}

.task-filter-empty {
    margin: 0 0 1.5rem;
    text-align: center;
}

.task-item {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    padding: 0.85rem 1rem;
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    transition: background-color var(--transition);
}

.task-item[hidden],
section[hidden],
details[hidden],
.task-filter-empty[hidden] {
    display: none;
}

.task-item.is-overdue {
    border-left: 3px solid var(--warning);
}

.task-item.is-due-today {
    border-left: 3px solid var(--accent-light);
}

.task-item:hover {
    background: var(--bg-card-hover);
}

/* 24x24 meets the WCAG 2.2 target-size minimum */
.task-item input[type="checkbox"] {
    appearance: none;
    width: 24px;
    height: 24px;
    border: 2px solid var(--border-strong);
    border-radius: 6px;
    flex-shrink: 0;
    cursor: pointer;
    transition: background-color var(--transition), border-color var(--transition);
    position: relative;
}

/* 24x24 meets the WCAG 2.2 target-size minimum, and the comment above is the
   existing deliberate choice, so the drawn box is left alone. A transparent
   overlay still widens the tappable area to 44px, the same trick the note
   colour swatches use, so finger taps stop missing. */
.task-item input[type="checkbox"]::before {
    content: '';
    position: absolute;
    top: 50%;
    left: 50%;
    width: 44px;
    height: 44px;
    transform: translate(-50%, -50%);
}

.task-item input[type="checkbox"]:checked {
    background: var(--accent);
    border-color: var(--accent);
}

.task-item input[type="checkbox"]:checked::after {
    content: '✓';
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    color: #fff;
    font-size: 0.8rem;
    font-weight: 700;
}

.task-item.completed .task-text {
    text-decoration: line-through;
    color: var(--text-muted);
}

.task-text {
    /* Grows no wider than its text so the status badge sits right after the
       title instead of being pushed to the far edge by the action buttons. */
    flex: 0 1 auto;
    min-width: 0;
    font-size: 0.95rem;
    font-weight: 500;
    line-height: 1.6;
    text-align: left;
    /* Titles hold whatever the user typed, and people paste URLs. A single
       unbroken token has no break opportunity, so without this the task list
       sets the page's min-content width, the document scrolls sideways, and
       every position:fixed layer -- including the tab bar -- is stretched to
       the wider box and runs off the screen. `anywhere` rather than
       `break-word` because it also lowers the min-content contribution, so
       the container can shrink in the first place. */
    overflow-wrap: anywhere;
}

.task-priority {
    font-size: 0.7rem;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.05em;
    padding: 0.2rem 0.5rem;
    border-radius: 999px;
}

.priority-high {
    background: rgba(248, 113, 113, 0.15);
    color: var(--danger-text);
}

.priority-medium {
    background: rgba(251, 191, 36, 0.15);
    color: var(--warning);
}

.priority-low {
    background: rgba(52, 211, 153, 0.15);
    color: var(--success);
}

.task-add {
    display: flex;
    gap: 0.5rem;
    margin-top: 0.75rem;
}

.task-add input {
    /* Same min-width:auto trap as the quick-note field. Currently unused by
       any page, but leaving it would reintroduce the bug if it is ever wired
       back up. */
    flex: 1;
    min-width: 0;
}

/* ===== Enhanced Task Items ===== */
.task-content {
    flex: 1;
    min-width: 0;
}

.task-header {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    margin-bottom: 0.15rem;
    flex-wrap: wrap;
}

.task-description {
    font-size: 0.85rem;
    color: var(--text-secondary);
    line-height: 1.5;
    margin: 0.15rem 0 0 0;
    text-align: left;
    overflow-wrap: anywhere;
}

.task-due-date {
    font-size: 0.75rem;
    color: var(--text-muted);
    margin: 0.2rem 0 0 0;
}

.task-item.is-due-today .task-due-date,
.task-item.is-overdue .task-due-date {
    display: inline-flex;
    align-items: center;
    min-height: 28px;
    padding: 0.15rem 0.55rem;
    border-radius: 999px;
    background: rgba(251, 191, 36, 0.1);
}

.task-item.is-due-today .task-due-date {
    color: var(--accent-light);
    background: var(--accent-glow);
}

.task-due-time {
    color: var(--text-secondary);
    white-space: nowrap;
}

.task-link {
    display: inline-block;
    margin-top: 0.25rem;
    font-size: 0.8rem;
    color: var(--accent);
    overflow-wrap: anywhere;
}

.task-link:hover { text-decoration: underline; }

.task-item.completed .task-link { opacity: 0.6; }

/* ===== Overdue Warning ===== */
.task-overdue {
    display: inline-flex;
    align-items: center;
    gap: 0.3rem;
    flex-shrink: 0;
    white-space: nowrap;
    padding: 0.15rem 0.55rem;
    font-size: 0.72rem;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.05em;
    color: var(--warning);
    background: rgba(251, 191, 36, 0.15);
    border-radius: 999px;
}

.task-actions {
    display: flex;
    gap: 0.5rem;
    align-items: center;
    margin-left: auto;
}

/* ===== Task Form ===== */
.task-form {
    display: flex;
    flex-direction: column;
    gap: 1.25rem;
}

.task-form textarea {
    resize: vertical;
    min-height: 80px;
}

.task-form input[type="date"],
.task-form input[type="time"] {
    color-scheme: light dark;
}

.task-form input:disabled {
    opacity: 0.55;
    cursor: not-allowed;
}

.deadline-row {
    grid-template-columns: repeat(2, minmax(0, 1fr));
}

.completed-disclosure {
    margin-bottom: 2rem;
    border-top: 1px solid var(--border);
}

.completed-disclosure:not([open]) > .task-list {
    display: none;
}

.completed-disclosure > summary {
    display: flex;
    align-items: center;
    gap: 0.6rem;
    min-height: 52px;
    color: var(--text-primary);
    font-size: 1.05rem;
    font-weight: 600;
    cursor: pointer;
    list-style-position: inside;
}

.completed-disclosure > summary::marker {
    color: var(--text-muted);
    font-size: 0.8em;
}

.completed-count {
    color: var(--text-muted);
    font-size: 0.8rem;
    font-variant-numeric: tabular-nums;
}

.completed-disclosure[open] > .task-list {
    padding-bottom: 0.5rem;
}

/* ===== Responsive ===== */
@media (max-width: 768px) {
    .task-item {
        flex-wrap: wrap;
        /* Top-align the checkbox with the first line of the title. Centring it
           (the desktop value) left it floating beside the middle of a
           multi-line title, description and due date. */
        align-items: flex-start;
        gap: 0.65rem 0.75rem;
    }

    /* .task-content keeps flex:1, whose basis of 0 means a width:100% here
       would be ignored anyway. It stays on the first line beside the
       checkbox, which is the correct tap pattern: the control that completes
       the task sits next to the task's name. The old width:100%/order:2 pair
       was intended to push it onto its own row but never took effect. */
    .task-actions {
        order: 3;
        margin-top: 0.5rem;
    }

    /* The link is a standalone element on its own line, not a link inside a
       sentence, so the inline-target exemption does not apply. It measured
       20px, which is under even the 24px WCAG 2.2 AA minimum. */
    .task-link {
        display: inline-flex;
        align-items: center;
        min-height: 44px;
    }
}
