/* ============================================================
   Task Detail Panel — Properties, Dates, Plan strip, Subtasks
   ============================================================ */

/* ── Sticky header ── */
.td-sticky-header {
    position: sticky;
    top: 0;
    z-index: 20;
    background: rgba(255, 255, 255, 0.92);
    backdrop-filter: saturate(180%) blur(8px);
    -webkit-backdrop-filter: saturate(180%) blur(8px);
    border-bottom: 1px solid transparent;
    transition: border-color 0.15s ease, box-shadow 0.15s ease;
}
.td-sticky-header.is-scrolled {
    border-bottom-color: #e5e7eb;
    box-shadow: 0 1px 0 rgba(15, 23, 42, 0.03);
}
.td-sticky-header-inner {
    padding: 14px 20px 10px;
}
.td-sticky-header-row {
    display: flex;
    align-items: center;
    gap: 8px;
}
.td-title-input {
    flex: 1;
    min-width: 0;
    border: 0;
    padding: 2px 0;
    font-size: 1.05rem;
    font-weight: 600;
    color: #0f172a;
    background: transparent;
    outline: none;
}
.td-title-input:focus {
    background: transparent;
}
.td-title-input:disabled {
    color: #334155;
    -webkit-text-fill-color: #334155;
}
.td-title-input::placeholder { color: #cbd5e1; }

.td-header-actions {
    display: flex;
    align-items: center;
    gap: 2px;
    flex-shrink: 0;
}
.td-header-btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 30px;
    height: 30px;
    border-radius: 7px;
    border: 0;
    background: transparent;
    color: #64748b;
    cursor: pointer;
    transition: background 0.12s ease, color 0.12s ease, transform 0.12s ease;
}
.td-header-btn i { font-size: 1.05rem; line-height: 1; }
.td-header-btn:hover {
    background: #f1f5f9;
    color: #0f172a;
}
.td-header-btn:active { transform: scale(0.94); }
.td-header-btn-danger:hover {
    background: #fef2f2;
    color: #dc2626;
}
.td-header-btn-success {
    background: #ecfdf5 !important;
    color: #059669 !important;
}
.td-header-divider {
    width: 1px;
    height: 18px;
    background: #e5e7eb;
    margin: 0 4px;
}

.td-sticky-meta-row {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 8px;
    margin-top: 4px;
    min-height: 18px;
}
.td-sticky-meta {
    display: flex;
    align-items: center;
    gap: 5px;
    font-size: 0.72rem;
    color: #94a3b8;
    min-width: 0;
}
.td-sticky-meta i { font-size: 0.85rem; }
.td-sticky-meta a {
    color: #475569;
    text-decoration: none;
    font-weight: 500;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}
.td-sticky-meta a:hover {
    color: #2563eb;
    text-decoration: underline;
}

/* ── Save-state pill ── */
.td-save-state {
    display: inline-flex;
    align-items: center;
    gap: 5px;
    padding: 2px 8px;
    border-radius: 9999px;
    font-size: 0.7rem;
    font-weight: 500;
    line-height: 1.4;
    transition: opacity 0.2s ease;
}
.td-save-state[hidden] { display: none; }
.td-save-state-icon { font-size: 0.85rem; line-height: 1; display: inline-flex; }
.td-save-state-saving {
    background: #f1f5f9;
    color: #475569;
}
.td-save-state-saving .td-save-state-icon {
    animation: td-spin 0.9s linear infinite;
}
.td-save-state-saved {
    background: #ecfdf5;
    color: #047857;
}
.td-save-state-error {
    background: #fef2f2;
    color: #b91c1c;
}
.td-save-state-retry {
    margin-left: 4px;
    padding: 0 6px;
    height: 18px;
    border-radius: 9999px;
    border: 1px solid currentColor;
    background: transparent;
    color: inherit;
    font-size: 0.65rem;
    font-weight: 600;
    cursor: pointer;
    transition: background 0.12s ease;
}
.td-save-state-retry:hover { background: rgba(185, 28, 28, 0.08); }
.td-save-state-retry[hidden] { display: none; }

@keyframes td-spin {
    from { transform: rotate(0deg); }
    to   { transform: rotate(360deg); }
}

/* ── Saved field flash ── */
@keyframes td-saved-flash {
    0%   { box-shadow: 0 0 0 0 rgba(16, 185, 129, 0.0); }
    20%  { box-shadow: 0 0 0 3px rgba(16, 185, 129, 0.35); }
    100% { box-shadow: 0 0 0 0 rgba(16, 185, 129, 0.0); }
}
.td-saved-flash {
    animation: td-saved-flash 0.9s ease-out;
    border-radius: 6px;
}

/* ── Keyboard cheat sheet ── */
.td-cheatsheet {
    position: absolute;
    top: 100%;
    right: 12px;
    margin-top: 6px;
    z-index: 40;
    width: 240px;
    background: #ffffff;
    border: 1px solid #e5e7eb;
    border-radius: 10px;
    box-shadow: 0 14px 30px -8px rgba(15, 23, 42, 0.2), 0 4px 10px -4px rgba(15, 23, 42, 0.08);
    overflow: hidden;
}
.td-cheatsheet.hidden { display: none; }
.td-cheatsheet-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 8px 10px 8px 12px;
    border-bottom: 1px solid #f1f5f9;
}
.td-cheatsheet-title {
    font-size: 0.72rem;
    font-weight: 600;
    color: #475569;
    text-transform: uppercase;
    letter-spacing: 0.04em;
}
.td-cheatsheet-close {
    border: 0;
    background: transparent;
    color: #94a3b8;
    cursor: pointer;
    padding: 2px;
    border-radius: 4px;
    display: inline-flex;
}
.td-cheatsheet-close:hover { background: #f1f5f9; color: #0f172a; }
.td-cheatsheet-list {
    list-style: none;
    margin: 0;
    padding: 6px 6px 8px;
}
.td-cheatsheet-list li {
    display: flex;
    align-items: center;
    gap: 6px;
    padding: 6px 8px;
    border-radius: 6px;
    font-size: 0.78rem;
    color: #334155;
}
.td-cheatsheet-list li:hover { background: #f8fafc; }
.td-cheatsheet-list li span {
    margin-left: auto;
    color: #64748b;
    font-size: 0.75rem;
}
.td-cheatsheet-list kbd {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    min-width: 22px;
    height: 22px;
    padding: 0 6px;
    background: #f1f5f9;
    border: 1px solid #e2e8f0;
    border-bottom-width: 2px;
    border-radius: 5px;
    font-family: inherit;
    font-size: 0.72rem;
    font-weight: 600;
    color: #334155;
}

/* ── Compact properties row (Status + Priority pills) ── */
.td-props-compact {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 12px;
    margin-bottom: 16px;
}

.td-prop-pill-wrap {
    position: relative;
}

.td-prop-pill {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    padding: 5px 10px;
    border-radius: 9999px;
    border: 1.5px solid #e2e8f0;
    background: #f8fafc;
    font-size: 0.75rem;
    font-weight: 600;
    color: #475569;
    cursor: pointer;
    transition: all 0.12s ease;
    max-width: 100%;
}
.td-prop-pill:hover:not(:disabled) {
    border-color: #cbd5e1;
    background: #f1f5f9;
}
.td-prop-pill:disabled {
    cursor: default;
    opacity: 0.7;
}
.td-prop-pill.active {
    box-shadow: 0 0 0 3px rgba(59, 130, 246, 0.12);
}
.td-prop-pill .td-status-dot {
    width: 8px;
    height: 8px;
    border-radius: 50%;
    flex-shrink: 0;
}
.td-prop-pill-label {
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}
.td-prop-pill-caret {
    font-size: 0.75rem;
    opacity: 0.55;
    margin-left: 2px;
}

/* Priority pill — tinted by current selection */
.td-priority-pill[data-priority="1"] { color: #6b7280; border-color: #e5e7eb; background: #f9fafb; }
.td-priority-pill[data-priority="2"] { color: #a16207; border-color: #fef08a; background: #fefce8; }
.td-priority-pill[data-priority="3"] { color: #c2410c; border-color: #fed7aa; background: #fff7ed; }
.td-priority-pill[data-priority="4"] { color: #b91c1c; border-color: #fecaca; background: #fef2f2; }

/* Popover under each pill */
.td-prop-popover {
    position: absolute;
    top: calc(100% + 6px);
    left: 0;
    z-index: 30;
    min-width: 220px;
    max-width: 320px;
    padding: 8px;
    border-radius: 10px;
    background: #ffffff;
    border: 1px solid #e5e7eb;
    box-shadow: 0 12px 24px -8px rgba(15, 23, 42, 0.18), 0 4px 8px -4px rgba(15, 23, 42, 0.08);
}
.td-prop-popover.hidden { display: none; }

/* ── Properties grid (legacy — kept for backwards-compat if used elsewhere) ── */
.td-props-grid {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 12px;
    margin-bottom: 16px;
}

.td-prop-label {
    display: flex;
    align-items: center;
    gap: 5px;
    font-size: 0.7rem;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.05em;
    color: #94a3b8;
    margin-bottom: 6px;
}

.td-chip-row {
    display: flex;
    flex-wrap: wrap;
    gap: 5px;
}

/* Status chips */
.td-status-chip {
    display: inline-flex;
    align-items: center;
    gap: 5px;
    padding: 4px 10px;
    border-radius: 9999px;
    border: 1.5px solid #e2e8f0;
    background: #f8fafc;
    font-size: 0.7rem;
    font-weight: 600;
    color: #475569;
    cursor: pointer;
    transition: all 0.12s ease;
    white-space: nowrap;
}
.td-status-chip:hover {
    border-color: #93c5fd;
    background: #eff6ff;
    color: #2563eb;
}
.td-status-chip.active {
    border-color: transparent;
    color: #fff;
}
.td-status-chip .td-status-dot {
    width: 7px;
    height: 7px;
    border-radius: 50%;
    flex-shrink: 0;
}

/* Priority chips */
.td-priority-chip {
    display: inline-flex;
    align-items: center;
    gap: 5px;
    padding: 4px 10px;
    border-radius: 9999px;
    border: 1.5px solid #e2e8f0;
    background: #f8fafc;
    font-size: 0.7rem;
    font-weight: 600;
    color: #475569;
    cursor: pointer;
    transition: all 0.12s ease;
    white-space: nowrap;
}
.td-priority-chip:hover {
    border-color: #cbd5e1;
    background: #f1f5f9;
}
.td-priority-chip.active {
    background: #f1f5f9;
    border-color: transparent;
}
.td-priority-chip.active[data-priority="1"] { color: #6b7280; border-color: #e5e7eb; background: #f9fafb; }
.td-priority-chip.active[data-priority="2"] { color: #a16207; border-color: #fef08a; background: #fefce8; }
.td-priority-chip.active[data-priority="3"] { color: #c2410c; border-color: #fed7aa; background: #fff7ed; }
.td-priority-chip.active[data-priority="4"] { color: #b91c1c; border-color: #fecaca; background: #fef2f2; }
.td-priority-chip.active[data-priority="0"] { color: #94a3b8; border-color: #e2e8f0; background: #f8fafc; }

/* Hidden native selects (still used for save(), kept accessible) */
#td-status, #td-priority {
    position: absolute;
    opacity: 0;
    pointer-events: none;
    width: 0;
    height: 0;
}

/* ── Dates row ── */
.td-dates-row {
    display: flex;
    gap: 12px;
    margin-bottom: 16px;
}

.td-date-field {
    flex: 1;
    background: #f8fafc;
    border: 1px solid #e2e8f0;
    border-radius: 8px;
    padding: 8px 10px;
    transition: border-color 0.15s ease;
}
.td-date-field:focus-within {
    border-color: #93c5fd;
}

.td-date-field label {
    display: flex;
    align-items: center;
    gap: 4px;
    font-size: 0.65rem;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.05em;
    color: #94a3b8;
    margin-bottom: 4px;
}

.td-date-field input[type="date"] {
    width: 100%;
    border: none;
    background: transparent;
    font-size: 0.8rem;
    color: #374151;
    outline: none;
    padding: 0;
}
.td-date-field input[type="date"]:disabled {
    color: #9ca3af;
}

/* ── Plan this week strip ── */
.td-plan-strip {
    background: #f8fafc;
    border: 1px solid #e2e8f0;
    border-radius: 10px;
    padding: 10px 12px;
    margin-bottom: 16px;
}

.td-plan-strip-label {
    display: flex;
    align-items: center;
    gap: 5px;
    font-size: 0.65rem;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.05em;
    color: #94a3b8;
    margin-bottom: 8px;
}

/* ── Read-only banner ── */
.td-readonly-banner {
    display: flex;
    align-items: center;
    gap: 8px;
    margin-bottom: 16px;
    padding: 8px 12px;
    border-radius: 8px;
    border: 1px solid #fde68a;
    background: #fffbeb;
    font-size: 0.75rem;
    color: #92400e;
}
.td-readonly-banner i {
    font-size: 1rem;
    color: #d97706;
    flex-shrink: 0;
}

/* ── Custom field editors in task detail ── */
#td-custom-fields .td-custom-field-editor select,
#td-custom-fields .td-custom-field-editor input[type="text"],
#td-custom-fields .td-custom-field-editor input[type="number"],
#td-custom-fields .td-custom-field-editor input[type="date"] {
    width: 100%;
    appearance: none;
    -webkit-appearance: none;
    background: #f8fafc;
    border: 1px solid #e2e8f0;
    border-radius: 7px;
    padding: 5px 28px 5px 9px;
    font-size: 0.78rem;
    color: #374151;
    outline: none;
    transition: border-color 0.15s ease, box-shadow 0.15s ease;
    cursor: pointer;
}
#td-custom-fields .td-custom-field-editor select:focus,
#td-custom-fields .td-custom-field-editor input:focus {
    border-color: #93c5fd;
    box-shadow: 0 0 0 3px rgba(147, 197, 253, 0.18);
    background: #fff;
}
#td-custom-fields .td-custom-field-editor select:hover,
#td-custom-fields .td-custom-field-editor input:hover {
    border-color: #cbd5e1;
}

/* Custom chevron for selects */
.td-custom-field-editor {
    position: relative;
}
.td-custom-field-editor select ~ .td-cf-chevron,
.td-custom-field-editor:has(select)::after {
    content: '';
    position: absolute;
    right: 9px;
    top: 50%;
    transform: translateY(-50%);
    width: 0;
    height: 0;
    border-left: 4px solid transparent;
    border-right: 4px solid transparent;
    border-top: 5px solid #94a3b8;
    pointer-events: none;
}

/* Checkbox field — row layout */
.td-custom-field-editor input[type="checkbox"] {
    width: 16px;
    height: 16px;
    accent-color: #3b82f6;
    cursor: pointer;
    margin-top: 2px;
}

/* ── Date field — full div is clickable ── */
.td-date-field {
    cursor: pointer;
}

/* ── Subtasks ── */
.td-subtask-list {
    display: flex;
    flex-direction: column;
    gap: 2px;
}

.td-subtask-empty {
    padding: 4px 2px;
    font-size: 0.72rem;
    color: #94a3b8;
}

.td-subtask-row {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 4px 6px;
    border-radius: 6px;
    transition: background 0.12s ease, opacity 0.14s ease, transform 0.14s ease;
}
.td-subtask-row:hover { background: #f8fafc; }
.td-subtask-row.td-subtask-pending { opacity: 0.6; }
.td-subtask-row.td-subtask-removing {
    opacity: 0;
    transform: translateX(6px);
}
.td-subtask-row[draggable="true"] { cursor: grab; }
.td-subtask-drag-handle {
    flex-shrink: 0;
    width: 14px;
    height: 16px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    color: #475569;
    font-size: 14px;
    line-height: 1;
    cursor: grab;
    opacity: 0;
    transition: opacity 0.12s ease;
    margin-right: -2px;
}
.td-subtask-row:hover .td-subtask-drag-handle,
.td-subtask-row.td-subtask-dragging .td-subtask-drag-handle {
    opacity: 1;
}
.td-subtask-drag-handle:active { cursor: grabbing; }
.td-subtask-row.td-subtask-dragging {
    opacity: 0.4;
    cursor: grabbing;
}
.td-subtask-row.td-subtask-drop-before {
    box-shadow: inset 0 2px 0 0 #3b82f6;
}
.td-subtask-row.td-subtask-drop-after {
    box-shadow: inset 0 -2px 0 0 #3b82f6;
}

/* Checkbox button */
.td-subtask-check {
    flex-shrink: 0;
    width: 16px;
    height: 16px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    border: 1.5px solid #cbd5e1;
    background: #ffffff;
    border-radius: 4px;
    color: #ffffff;
    cursor: pointer;
    padding: 0;
    transition: background 0.12s ease, border-color 0.12s ease;
}
.td-subtask-check:hover:not(:disabled) {
    border-color: #3b82f6;
}
.td-subtask-check.is-checked {
    background: #10b981;
    border-color: #10b981;
}
.td-subtask-check.is-checked:hover:not(:disabled) {
    background: #059669;
    border-color: #059669;
}
.td-subtask-check i { font-size: 11px; line-height: 1; }
.td-subtask-check:disabled { cursor: default; opacity: 0.6; }

/* Title */
.td-subtask-title {
    flex: 1;
    min-width: 0;
    font-size: 0.78rem;
    color: #334155;
    cursor: pointer;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    transition: color 0.12s ease;
}
.td-subtask-title:hover { color: #2563eb; }
.td-subtask-row.is-complete .td-subtask-title {
    color: #94a3b8;
    text-decoration: line-through;
}

/* Remove × */
.td-subtask-remove {
    flex-shrink: 0;
    width: 22px;
    height: 22px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    border: 0;
    background: transparent;
    color: #cbd5e1;
    border-radius: 4px;
    cursor: pointer;
    opacity: 0;
    transition: opacity 0.12s ease, background 0.12s ease, color 0.12s ease;
}
.td-subtask-row:hover .td-subtask-remove,
.td-subtask-remove:focus-visible {
    opacity: 1;
}
.td-subtask-remove:hover:not(:disabled) {
    background: #fef2f2;
    color: #dc2626;
}
.td-subtask-remove i { font-size: 12px; line-height: 1; }
.td-subtask-remove:disabled { display: none; }

/* Quick-add row */
.td-subtask-quick-add {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 4px 6px;
    margin-top: 2px;
    border-radius: 6px;
    border: 1px dashed transparent;
    transition: border-color 0.12s ease, background 0.12s ease;
}
.td-subtask-quick-add:hover { background: #f8fafc; }
.td-subtask-quick-add:focus-within {
    background: #ffffff;
    border-color: #93c5fd;
}
.td-subtask-quick-add-icon {
    width: 16px;
    height: 16px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    color: #94a3b8;
    flex-shrink: 0;
}
.td-subtask-quick-add-icon i { font-size: 14px; line-height: 1; }
.td-subtask-quick-add-input {
    flex: 1;
    min-width: 0;
    font-size: 0.78rem;
    color: #334155;
    background: transparent;
    border: 0;
    padding: 0;
    outline: none;
}
.td-subtask-quick-add-input::placeholder { color: #94a3b8; }

/* ── System URLs: 50/50 row with leading favicon icon ── */
.td-url-row {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 8px;
}

.td-url-cell {
    position: relative;
    min-width: 0; /* allow input to shrink inside the grid track */
}

.td-url-cell .input {
    width: 100%;
    padding-left: 36px;
}

.td-url-icon {
    position: absolute;
    top: 50%;
    left: 5px;
    transform: translateY(-50%);
    width: 24px;
    height: 24px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    border-radius: 6px;
    pointer-events: none; /* default: inert when empty */
    color: #cbd5e1;
}
.td-url-icon i { font-size: 14px; line-height: 1; }
.td-url-icon img { width: 14px; height: 14px; border-radius: 2px; }

.td-url-icon-active {
    pointer-events: auto;
    color: #2563eb;
    background: #eff6ff;
    border: 1px solid #bfdbfe;
    box-shadow: 0 1px 2px rgba(37, 99, 235, 0.08);
}
.td-url-icon-link {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 100%;
    height: 100%;
    color: inherit;
    text-decoration: none;
    border-radius: 5px;
    cursor: pointer;
    transition: background 0.12s ease, color 0.12s ease, transform 0.08s ease;
    position: relative;
}
.td-url-icon-active:hover {
    background: #dbeafe;
    border-color: #93c5fd;
    color: #1d4ed8;
}
.td-url-icon-link:hover { background: transparent; }
.td-url-icon-link:active { transform: scale(0.94); }
